Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / components / view_manager / view_tree_unittest.cc
blob0b539d22fb06f57ad8d1af098c8b987024d2e4fe
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <string>
6 #include <vector>
8 #include "base/message_loop/message_loop.h"
9 #include "components/view_manager/client_connection.h"
10 #include "components/view_manager/connection_manager.h"
11 #include "components/view_manager/connection_manager_delegate.h"
12 #include "components/view_manager/display_manager.h"
13 #include "components/view_manager/display_manager_factory.h"
14 #include "components/view_manager/ids.h"
15 #include "components/view_manager/public/cpp/types.h"
16 #include "components/view_manager/public/cpp/util.h"
17 #include "components/view_manager/public/interfaces/view_tree.mojom.h"
18 #include "components/view_manager/server_view.h"
19 #include "components/view_manager/surfaces/surfaces_state.h"
20 #include "components/view_manager/test_change_tracker.h"
21 #include "components/view_manager/view_tree_host_connection.h"
22 #include "components/view_manager/view_tree_impl.h"
23 #include "mojo/application/public/interfaces/service_provider.mojom.h"
24 #include "mojo/converters/geometry/geometry_type_converters.h"
25 #include "testing/gtest/include/gtest/gtest.h"
26 #include "ui/gfx/geometry/rect.h"
28 using mojo::Array;
29 using mojo::ERROR_CODE_NONE;
30 using mojo::InterfaceRequest;
31 using mojo::ServiceProvider;
32 using mojo::ServiceProviderPtr;
33 using mojo::String;
34 using mojo::ViewDataPtr;
36 namespace view_manager {
37 namespace {
39 // -----------------------------------------------------------------------------
41 // ViewTreeClient implementation that logs all calls to a TestChangeTracker.
42 // TODO(sky): refactor so both this and ViewTreeAppTest share code.
43 class TestViewTreeClient : public mojo::ViewTreeClient {
44 public:
45 TestViewTreeClient() {}
46 ~TestViewTreeClient() override {}
48 TestChangeTracker* tracker() { return &tracker_; }
50 private:
51 // ViewTreeClient:
52 void OnEmbed(uint16_t connection_id,
53 ViewDataPtr root,
54 mojo::ViewTreePtr tree,
55 mojo::Id focused_view_id) override {
56 // TODO(sky): add test coverage of |focused_view_id|.
57 tracker_.OnEmbed(connection_id, root.Pass());
59 void OnEmbeddedAppDisconnected(uint32_t view) override {
60 tracker_.OnEmbeddedAppDisconnected(view);
62 void OnUnembed() override { tracker_.OnUnembed(); }
63 void OnViewBoundsChanged(uint32_t view,
64 mojo::RectPtr old_bounds,
65 mojo::RectPtr new_bounds) override {
66 tracker_.OnViewBoundsChanged(view, old_bounds.Pass(), new_bounds.Pass());
68 void OnViewViewportMetricsChanged(
69 mojo::ViewportMetricsPtr old_metrics,
70 mojo::ViewportMetricsPtr new_metrics) override {
71 tracker_.OnViewViewportMetricsChanged(old_metrics.Pass(),
72 new_metrics.Pass());
74 void OnViewHierarchyChanged(uint32_t view,
75 uint32_t new_parent,
76 uint32_t old_parent,
77 Array<ViewDataPtr> views) override {
78 tracker_.OnViewHierarchyChanged(view, new_parent, old_parent, views.Pass());
80 void OnViewReordered(uint32_t view_id,
81 uint32_t relative_view_id,
82 mojo::OrderDirection direction) override {
83 tracker_.OnViewReordered(view_id, relative_view_id, direction);
85 void OnViewDeleted(uint32_t view) override { tracker_.OnViewDeleted(view); }
86 void OnViewVisibilityChanged(uint32_t view, bool visible) override {
87 tracker_.OnViewVisibilityChanged(view, visible);
89 void OnViewDrawnStateChanged(uint32_t view, bool drawn) override {
90 tracker_.OnViewDrawnStateChanged(view, drawn);
92 void OnViewSharedPropertyChanged(uint32_t view,
93 const String& name,
94 Array<uint8_t> new_data) override {
95 tracker_.OnViewSharedPropertyChanged(view, name, new_data.Pass());
97 void OnViewInputEvent(uint32_t view,
98 mojo::EventPtr event,
99 const mojo::Callback<void()>& callback) override {
100 tracker_.OnViewInputEvent(view, event.Pass());
102 void OnViewFocused(uint32_t focused_view_id) override {
103 tracker_.OnViewFocused(focused_view_id);
106 TestChangeTracker tracker_;
108 DISALLOW_COPY_AND_ASSIGN(TestViewTreeClient);
111 // -----------------------------------------------------------------------------
113 // ClientConnection implementation that vends TestViewTreeClient.
114 class TestClientConnection : public ClientConnection {
115 public:
116 explicit TestClientConnection(scoped_ptr<ViewTreeImpl> service_impl)
117 : ClientConnection(service_impl.Pass(), &client_) {}
119 TestViewTreeClient* client() { return &client_; }
121 private:
122 ~TestClientConnection() override {}
124 TestViewTreeClient client_;
126 DISALLOW_COPY_AND_ASSIGN(TestClientConnection);
129 // -----------------------------------------------------------------------------
131 // Empty implementation of ConnectionManagerDelegate.
132 class TestConnectionManagerDelegate : public ConnectionManagerDelegate {
133 public:
134 TestConnectionManagerDelegate() : last_connection_(nullptr) {}
135 ~TestConnectionManagerDelegate() override {}
137 TestViewTreeClient* last_client() {
138 return last_connection_ ? last_connection_->client() : nullptr;
141 TestClientConnection* last_connection() { return last_connection_; }
143 private:
144 // ConnectionManagerDelegate:
145 void OnNoMoreRootConnections() override {}
147 ClientConnection* CreateClientConnectionForEmbedAtView(
148 ConnectionManager* connection_manager,
149 mojo::InterfaceRequest<mojo::ViewTree> service_request,
150 mojo::ConnectionSpecificId creator_id,
151 mojo::URLRequestPtr request,
152 const ViewId& root_id) override {
153 scoped_ptr<ViewTreeImpl> service(
154 new ViewTreeImpl(connection_manager, creator_id, root_id));
155 last_connection_ = new TestClientConnection(service.Pass());
156 return last_connection_;
158 ClientConnection* CreateClientConnectionForEmbedAtView(
159 ConnectionManager* connection_manager,
160 mojo::InterfaceRequest<mojo::ViewTree> service_request,
161 mojo::ConnectionSpecificId creator_id,
162 const ViewId& root_id,
163 mojo::ViewTreeClientPtr client) override {
164 // Used by ConnectionManager::AddRoot.
165 scoped_ptr<ViewTreeImpl> service(
166 new ViewTreeImpl(connection_manager, creator_id, root_id));
167 last_connection_ = new TestClientConnection(service.Pass());
168 return last_connection_;
171 TestClientConnection* last_connection_;
173 DISALLOW_COPY_AND_ASSIGN(TestConnectionManagerDelegate);
176 // -----------------------------------------------------------------------------
178 class TestViewTreeHostConnection : public ViewTreeHostConnection {
179 public:
180 TestViewTreeHostConnection(scoped_ptr<ViewTreeHostImpl> host_impl,
181 ConnectionManager* manager)
182 : ViewTreeHostConnection(host_impl.Pass(), manager) {}
183 ~TestViewTreeHostConnection() override {}
185 private:
186 // ViewTreeHostDelegate:
187 void OnDisplayInitialized() override {
188 connection_manager()->AddHost(this);
189 set_view_tree(connection_manager()->EmbedAtView(
190 kInvalidConnectionId,
191 view_tree_host()->root_view()->id(),
192 mojo::ViewTreeClientPtr()));
194 DISALLOW_COPY_AND_ASSIGN(TestViewTreeHostConnection);
197 // -----------------------------------------------------------------------------
198 // Empty implementation of DisplayManager.
199 class TestDisplayManager : public DisplayManager {
200 public:
201 TestDisplayManager() {}
202 ~TestDisplayManager() override {}
204 // DisplayManager:
205 void Init(DisplayManagerDelegate* delegate) override {
206 // It is necessary to tell the delegate about the ViewportMetrics to make
207 // sure that the ViewTreeHostConnection is correctly initialized (and a
208 // root-view is created).
209 mojo::ViewportMetrics metrics;
210 metrics.size_in_pixels = mojo::Size::From(gfx::Size(400, 300));
211 metrics.device_pixel_ratio = 1.f;
212 delegate->OnViewportMetricsChanged(mojo::ViewportMetrics(), metrics);
214 void SchedulePaint(const ServerView* view, const gfx::Rect& bounds) override {
216 void SetViewportSize(const gfx::Size& size) override {}
217 const mojo::ViewportMetrics& GetViewportMetrics() override {
218 return display_metrices_;
220 void UpdateTextInputState(const ui::TextInputState& state) override {}
221 void SetImeVisibility(bool visible) override {}
223 private:
224 mojo::ViewportMetrics display_metrices_;
226 DISALLOW_COPY_AND_ASSIGN(TestDisplayManager);
229 // Factory that dispenses TestDisplayManagers.
230 class TestDisplayManagerFactory : public DisplayManagerFactory {
231 public:
232 TestDisplayManagerFactory() {}
233 ~TestDisplayManagerFactory() {}
234 DisplayManager* CreateDisplayManager(
235 bool is_headless,
236 mojo::ApplicationImpl* app_impl,
237 const scoped_refptr<gles2::GpuState>& gpu_state,
238 const scoped_refptr<surfaces::SurfacesState>& surfaces_state) override {
239 return new TestDisplayManager();
242 private:
243 DISALLOW_COPY_AND_ASSIGN(TestDisplayManagerFactory);
246 mojo::EventPtr CreatePointerDownEvent(int x, int y) {
247 mojo::EventPtr event(mojo::Event::New());
248 event->action = mojo::EVENT_TYPE_POINTER_DOWN;
249 event->pointer_data = mojo::PointerData::New();
250 event->pointer_data->pointer_id = 1u;
251 event->pointer_data->x = x;
252 event->pointer_data->y = y;
253 return event.Pass();
256 mojo::EventPtr CreatePointerUpEvent(int x, int y) {
257 mojo::EventPtr event(mojo::Event::New());
258 event->action = mojo::EVENT_TYPE_POINTER_UP;
259 event->pointer_data = mojo::PointerData::New();
260 event->pointer_data->pointer_id = 1u;
261 event->pointer_data->x = x;
262 event->pointer_data->y = y;
263 return event.Pass();
266 } // namespace
268 // -----------------------------------------------------------------------------
270 class ViewTreeTest : public testing::Test {
271 public:
272 ViewTreeTest() : wm_client_(nullptr) {}
273 ~ViewTreeTest() override {}
275 // ViewTreeImpl for the window manager.
276 ViewTreeImpl* wm_connection() {
277 return connection_manager_->GetConnection(1);
280 TestViewTreeClient* last_view_tree_client() {
281 return delegate_.last_client();
284 TestClientConnection* last_client_connection() {
285 return delegate_.last_connection();
288 ConnectionManager* connection_manager() { return connection_manager_.get(); }
290 TestViewTreeClient* wm_client() { return wm_client_; }
292 TestViewTreeHostConnection* host_connection() { return host_connection_; }
294 protected:
295 // testing::Test:
296 void SetUp() override {
297 DisplayManager::set_factory_for_testing(&display_manager_factory_);
298 // TODO(fsamuel): This is probably broken. We need a root.
299 connection_manager_.reset(
300 new ConnectionManager(&delegate_,
301 scoped_refptr<surfaces::SurfacesState>()));
302 ViewTreeHostImpl* host = new ViewTreeHostImpl(
303 mojo::ViewTreeHostClientPtr(),
304 connection_manager_.get(), true /* is_headless */, nullptr,
305 scoped_refptr<gles2::GpuState>(),
306 scoped_refptr<surfaces::SurfacesState>());
307 // TODO(fsamuel): This is way too magical. We need to find a better way to
308 // manage lifetime.
309 host_connection_ = new TestViewTreeHostConnection(
310 make_scoped_ptr(host), connection_manager_.get());
311 host->Init(host_connection_);
312 wm_client_ = delegate_.last_client();
315 private:
316 // TestViewTreeClient that is used for the WM connection.
317 TestViewTreeClient* wm_client_;
318 TestDisplayManagerFactory display_manager_factory_;
319 TestConnectionManagerDelegate delegate_;
320 TestViewTreeHostConnection* host_connection_;
321 scoped_ptr<ConnectionManager> connection_manager_;
322 base::MessageLoop message_loop_;
324 DISALLOW_COPY_AND_ASSIGN(ViewTreeTest);
327 namespace {
329 const ServerView* GetFirstCloned(const ServerView* view) {
330 for (const ServerView* child : view->GetChildren()) {
331 if (child->id() == ClonedViewId())
332 return child;
334 return nullptr;
337 // Provides common setup for animation tests. Creates the following views:
338 // 0,1 (the root, provided by view manager)
339 // 1,1 the second connection is embedded here (view owned by wm_connection()).
340 // 2,1 bounds=1,2 11x22
341 // 2,2 bounds=2,3 6x7
342 // 2,3 bounds=3,4 6x7
343 // CloneAndAnimate() is invoked for 2,2.
344 void SetUpAnimate1(ViewTreeTest* test, ViewId* embed_view_id) {
345 *embed_view_id = ViewId(test->wm_connection()->id(), 1);
346 EXPECT_EQ(ERROR_CODE_NONE, test->wm_connection()->CreateView(*embed_view_id));
347 EXPECT_TRUE(test->wm_connection()->SetViewVisibility(*embed_view_id, true));
348 EXPECT_TRUE(test->wm_connection()->AddView(*(test->wm_connection()->root()),
349 *embed_view_id));
350 mojo::URLRequestPtr request(mojo::URLRequest::New());
351 test->wm_connection()->Embed(*embed_view_id, request.Pass());
352 ViewTreeImpl* connection1 =
353 test->connection_manager()->GetConnectionWithRoot(*embed_view_id);
354 ASSERT_TRUE(connection1 != nullptr);
355 ASSERT_NE(connection1, test->wm_connection());
357 const ViewId child1(connection1->id(), 1);
358 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1));
359 const ViewId child2(connection1->id(), 2);
360 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child2));
361 const ViewId child3(connection1->id(), 3);
362 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child3));
364 ServerView* v1 = connection1->GetView(child1);
365 v1->SetVisible(true);
366 v1->SetBounds(gfx::Rect(1, 2, 11, 22));
367 ServerView* v2 = connection1->GetView(child2);
368 v2->SetVisible(true);
369 v2->SetBounds(gfx::Rect(2, 3, 6, 7));
370 ServerView* v3 = connection1->GetView(child3);
371 v3->SetVisible(true);
372 v3->SetBounds(gfx::Rect(3, 4, 6, 7));
374 EXPECT_TRUE(connection1->AddView(*embed_view_id, child1));
375 EXPECT_TRUE(connection1->AddView(child1, child2));
376 EXPECT_TRUE(connection1->AddView(child2, child3));
378 TestViewTreeClient* connection1_client = test->last_view_tree_client();
379 connection1_client->tracker()->changes()->clear();
380 test->wm_client()->tracker()->changes()->clear();
381 EXPECT_TRUE(test->connection_manager()->CloneAndAnimate(child2));
382 EXPECT_TRUE(connection1_client->tracker()->changes()->empty());
383 EXPECT_TRUE(test->wm_client()->tracker()->changes()->empty());
385 // We cloned v2. The cloned view ends up as a sibling of it.
386 const ServerView* cloned_view = GetFirstCloned(connection1->GetView(child1));
387 ASSERT_TRUE(cloned_view);
388 // |cloned_view| should have one and only one cloned child (corresponds to
389 // |child3|).
390 ASSERT_EQ(1u, cloned_view->GetChildren().size());
391 EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId());
393 // Cloned views should match the bounds of the view they were cloned from.
394 EXPECT_EQ(v2->bounds(), cloned_view->bounds());
395 EXPECT_EQ(v3->bounds(), cloned_view->GetChildren()[0]->bounds());
397 // Cloned views are owned by the ConnectionManager and shouldn't be returned
398 // from ViewTreeImpl::GetView.
399 EXPECT_TRUE(connection1->GetView(ClonedViewId()) == nullptr);
400 EXPECT_TRUE(test->wm_connection()->GetView(ClonedViewId()) == nullptr);
403 } // namespace
405 // Verifies ViewTree::GetViewTree() doesn't return cloned views.
406 TEST_F(ViewTreeTest, ConnectionsCantSeeClonedViews) {
407 ViewId embed_view_id;
408 EXPECT_NO_FATAL_FAILURE(SetUpAnimate1(this, &embed_view_id));
410 ViewTreeImpl* connection1 =
411 connection_manager()->GetConnectionWithRoot(embed_view_id);
413 const ViewId child1(connection1->id(), 1);
414 const ViewId child2(connection1->id(), 2);
415 const ViewId child3(connection1->id(), 3);
417 // Verify the root doesn't see any cloned views.
418 std::vector<const ServerView*> views(
419 wm_connection()->GetViewTree(*wm_connection()->root()));
420 ASSERT_EQ(5u, views.size());
421 ASSERT_TRUE(views[0]->id() == *wm_connection()->root());
422 ASSERT_TRUE(views[1]->id() == embed_view_id);
423 ASSERT_TRUE(views[2]->id() == child1);
424 ASSERT_TRUE(views[3]->id() == child2);
425 ASSERT_TRUE(views[4]->id() == child3);
427 // Verify connection1 doesn't see any cloned views.
428 std::vector<const ServerView*> v1_views(
429 connection1->GetViewTree(embed_view_id));
430 ASSERT_EQ(4u, v1_views.size());
431 ASSERT_TRUE(v1_views[0]->id() == embed_view_id);
432 ASSERT_TRUE(v1_views[1]->id() == child1);
433 ASSERT_TRUE(v1_views[2]->id() == child2);
434 ASSERT_TRUE(v1_views[3]->id() == child3);
437 TEST_F(ViewTreeTest, ClonedViewsPromotedOnConnectionClose) {
438 ViewId embed_view_id;
439 EXPECT_NO_FATAL_FAILURE(SetUpAnimate1(this, &embed_view_id));
441 // Destroy connection1, which should force the cloned view to become a child
442 // of where it was embedded (the embedded view still exists).
443 connection_manager()->OnConnectionError(last_client_connection());
445 ServerView* embed_view = wm_connection()->GetView(embed_view_id);
446 ASSERT_TRUE(embed_view != nullptr);
447 const ServerView* cloned_view = GetFirstCloned(embed_view);
448 ASSERT_TRUE(cloned_view);
449 ASSERT_EQ(1u, cloned_view->GetChildren().size());
450 EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId());
452 // Because the cloned view changed parents its bounds should have changed.
453 EXPECT_EQ(gfx::Rect(3, 5, 6, 7), cloned_view->bounds());
454 // The bounds of the cloned child should not have changed though.
455 EXPECT_EQ(gfx::Rect(3, 4, 6, 7), cloned_view->GetChildren()[0]->bounds());
458 TEST_F(ViewTreeTest, ClonedViewsPromotedOnHide) {
459 ViewId embed_view_id;
460 EXPECT_NO_FATAL_FAILURE(SetUpAnimate1(this, &embed_view_id));
462 ViewTreeImpl* connection1 =
463 connection_manager()->GetConnectionWithRoot(embed_view_id);
465 // Hide the parent of the cloned view, which should force the cloned view to
466 // become a sibling of the parent.
467 const ServerView* view_to_hide =
468 connection1->GetView(ViewId(connection1->id(), 1));
469 ASSERT_TRUE(connection1->SetViewVisibility(view_to_hide->id(), false));
471 const ServerView* cloned_view = GetFirstCloned(view_to_hide->parent());
472 ASSERT_TRUE(cloned_view);
473 ASSERT_EQ(1u, cloned_view->GetChildren().size());
474 EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId());
475 EXPECT_EQ(2u, cloned_view->parent()->GetChildren().size());
476 EXPECT_TRUE(cloned_view->parent()->GetChildren()[1] == cloned_view);
479 // Clone and animate on a tree with more depth. Basically that of
480 // SetUpAnimate1() but cloning 2,1.
481 TEST_F(ViewTreeTest, CloneAndAnimateLargerDepth) {
482 const ViewId embed_view_id(wm_connection()->id(), 1);
483 EXPECT_EQ(ERROR_CODE_NONE, wm_connection()->CreateView(embed_view_id));
484 EXPECT_TRUE(wm_connection()->SetViewVisibility(embed_view_id, true));
485 EXPECT_TRUE(
486 wm_connection()->AddView(*(wm_connection()->root()), embed_view_id));
487 mojo::URLRequestPtr request(mojo::URLRequest::New());
488 wm_connection()->Embed(embed_view_id, request.Pass());
489 ViewTreeImpl* connection1 =
490 connection_manager()->GetConnectionWithRoot(embed_view_id);
491 ASSERT_TRUE(connection1 != nullptr);
492 ASSERT_NE(connection1, wm_connection());
494 const ViewId child1(connection1->id(), 1);
495 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1));
496 const ViewId child2(connection1->id(), 2);
497 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child2));
498 const ViewId child3(connection1->id(), 3);
499 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child3));
501 ServerView* v1 = connection1->GetView(child1);
502 v1->SetVisible(true);
503 connection1->GetView(child2)->SetVisible(true);
504 connection1->GetView(child3)->SetVisible(true);
506 EXPECT_TRUE(connection1->AddView(embed_view_id, child1));
507 EXPECT_TRUE(connection1->AddView(child1, child2));
508 EXPECT_TRUE(connection1->AddView(child2, child3));
510 TestViewTreeClient* connection1_client = last_view_tree_client();
511 connection1_client->tracker()->changes()->clear();
512 wm_client()->tracker()->changes()->clear();
513 EXPECT_TRUE(connection_manager()->CloneAndAnimate(child1));
514 EXPECT_TRUE(connection1_client->tracker()->changes()->empty());
515 EXPECT_TRUE(wm_client()->tracker()->changes()->empty());
517 // We cloned v1. The cloned view ends up as a sibling of it.
518 const ServerView* cloned_view = GetFirstCloned(v1->parent());
519 ASSERT_TRUE(cloned_view);
520 // |cloned_view| should have a child and its child should have a child.
521 ASSERT_EQ(1u, cloned_view->GetChildren().size());
522 const ServerView* cloned_view_child = cloned_view->GetChildren()[0];
523 EXPECT_EQ(1u, cloned_view_child->GetChildren().size());
524 EXPECT_TRUE(cloned_view_child->id() == ClonedViewId());
527 // Verifies focus correctly changes on pointer events.
528 TEST_F(ViewTreeTest, FocusOnPointer) {
529 const ViewId embed_view_id(wm_connection()->id(), 1);
530 EXPECT_EQ(ERROR_CODE_NONE, wm_connection()->CreateView(embed_view_id));
531 EXPECT_TRUE(wm_connection()->SetViewVisibility(embed_view_id, true));
532 EXPECT_TRUE(
533 wm_connection()->AddView(*(wm_connection()->root()), embed_view_id));
534 host_connection()->view_tree_host()->root_view()->
535 SetBounds(gfx::Rect(0, 0, 100, 100));
536 mojo::URLRequestPtr request(mojo::URLRequest::New());
537 wm_connection()->Embed(embed_view_id, request.Pass());
538 ViewTreeImpl* connection1 =
539 connection_manager()->GetConnectionWithRoot(embed_view_id);
540 ASSERT_TRUE(connection1 != nullptr);
541 ASSERT_NE(connection1, wm_connection());
543 connection_manager()
544 ->GetView(embed_view_id)
545 ->SetBounds(gfx::Rect(0, 0, 50, 50));
547 const ViewId child1(connection1->id(), 1);
548 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1));
549 EXPECT_TRUE(connection1->AddView(embed_view_id, child1));
550 ServerView* v1 = connection1->GetView(child1);
551 v1->SetVisible(true);
552 v1->SetBounds(gfx::Rect(20, 20, 20, 20));
554 TestViewTreeClient* connection1_client = last_view_tree_client();
555 connection1_client->tracker()->changes()->clear();
556 wm_client()->tracker()->changes()->clear();
558 connection_manager()->OnEvent(host_connection()->view_tree_host(),
559 CreatePointerDownEvent(21, 22));
560 // Focus should go to child1. This results in notifying both the window
561 // manager and client connection being notified.
562 EXPECT_EQ(v1, connection_manager()->GetFocusedView());
563 ASSERT_GE(wm_client()->tracker()->changes()->size(), 1u);
564 EXPECT_EQ("Focused id=2,1",
565 ChangesToDescription1(*wm_client()->tracker()->changes())[0]);
566 ASSERT_GE(connection1_client->tracker()->changes()->size(), 1u);
567 EXPECT_EQ(
568 "Focused id=2,1",
569 ChangesToDescription1(*connection1_client->tracker()->changes())[0]);
571 connection_manager()->OnEvent(host_connection()->view_tree_host(),
572 CreatePointerUpEvent(21, 22));
573 wm_client()->tracker()->changes()->clear();
574 connection1_client->tracker()->changes()->clear();
576 // Press outside of the embedded view. Focus should go to the root. Notice
577 // the client1 doesn't see who has focus as the focused view (root) isn't
578 // visible to it.
579 connection_manager()->OnEvent(host_connection()->view_tree_host(),
580 CreatePointerDownEvent(61, 22));
581 EXPECT_EQ(host_connection()->view_tree_host()->root_view(),
582 connection_manager()->GetFocusedView());
583 ASSERT_GE(wm_client()->tracker()->changes()->size(), 1u);
584 EXPECT_EQ("Focused id=0,2",
585 ChangesToDescription1(*wm_client()->tracker()->changes())[0]);
586 ASSERT_GE(connection1_client->tracker()->changes()->size(), 1u);
587 EXPECT_EQ(
588 "Focused id=null",
589 ChangesToDescription1(*connection1_client->tracker()->changes())[0]);
591 connection_manager()->OnEvent(host_connection()->view_tree_host(),
592 CreatePointerUpEvent(21, 22));
593 wm_client()->tracker()->changes()->clear();
594 connection1_client->tracker()->changes()->clear();
596 // Press in the same location. Should not get a focus change event (only input
597 // event).
598 connection_manager()->OnEvent(host_connection()->view_tree_host(),
599 CreatePointerDownEvent(61, 22));
600 EXPECT_EQ(host_connection()->view_tree_host()->root_view(),
601 connection_manager()->GetFocusedView());
602 ASSERT_EQ(wm_client()->tracker()->changes()->size(), 1u);
603 EXPECT_EQ("InputEvent view=0,2 event_action=4",
604 ChangesToDescription1(*wm_client()->tracker()->changes())[0]);
605 EXPECT_TRUE(connection1_client->tracker()->changes()->empty());
608 } // namespace view_manager