Disable failing PartnerDisableIncognitoModeIntegrationTest#testEnabledParentalControl...
[chromium-blink-merge.git] / components / view_manager / view_manager_service_unittest.cc
blob72a986a315597a5b5b11f3a7f46926ace69e6a4d
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_manager.mojom.h"
18 #include "components/view_manager/server_view.h"
19 #include "components/view_manager/test_change_tracker.h"
20 #include "components/view_manager/view_manager_root_connection.h"
21 #include "components/view_manager/view_manager_service_impl.h"
22 #include "mojo/application/public/interfaces/service_provider.mojom.h"
23 #include "mojo/converters/geometry/geometry_type_converters.h"
24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "ui/gfx/geometry/rect.h"
27 using mojo::Array;
28 using mojo::ERROR_CODE_NONE;
29 using mojo::InterfaceRequest;
30 using mojo::ServiceProvider;
31 using mojo::ServiceProviderPtr;
32 using mojo::String;
33 using mojo::ViewDataPtr;
35 namespace view_manager {
36 namespace {
38 // -----------------------------------------------------------------------------
40 // ViewManagerClient implementation that logs all calls to a TestChangeTracker.
41 // TODO(sky): refactor so both this and ViewManagerServiceAppTest share code.
42 class TestViewManagerClient : public mojo::ViewManagerClient {
43 public:
44 TestViewManagerClient() {}
45 ~TestViewManagerClient() override {}
47 TestChangeTracker* tracker() { return &tracker_; }
49 private:
50 // ViewManagerClient:
51 void OnEmbed(uint16_t connection_id,
52 ViewDataPtr root,
53 mojo::ViewManagerServicePtr view_manager_service,
54 mojo::Id focused_view_id) override {
55 // TODO(sky): add test coverage of |focused_view_id|.
56 tracker_.OnEmbed(connection_id, root.Pass());
58 void OnEmbedForDescendant(
59 uint32_t view,
60 mojo::URLRequestPtr request,
61 const OnEmbedForDescendantCallback& callback) override {}
62 void OnEmbeddedAppDisconnected(uint32_t view) override {
63 tracker_.OnEmbeddedAppDisconnected(view);
65 void OnViewBoundsChanged(uint32_t view,
66 mojo::RectPtr old_bounds,
67 mojo::RectPtr new_bounds) override {
68 tracker_.OnViewBoundsChanged(view, old_bounds.Pass(), new_bounds.Pass());
70 void OnViewViewportMetricsChanged(
71 mojo::ViewportMetricsPtr old_metrics,
72 mojo::ViewportMetricsPtr new_metrics) override {
73 tracker_.OnViewViewportMetricsChanged(old_metrics.Pass(),
74 new_metrics.Pass());
76 void OnViewHierarchyChanged(uint32_t view,
77 uint32_t new_parent,
78 uint32_t old_parent,
79 Array<ViewDataPtr> views) override {
80 tracker_.OnViewHierarchyChanged(view, new_parent, old_parent, views.Pass());
82 void OnViewReordered(uint32_t view_id,
83 uint32_t relative_view_id,
84 mojo::OrderDirection direction) override {
85 tracker_.OnViewReordered(view_id, relative_view_id, direction);
87 void OnViewDeleted(uint32_t view) override { tracker_.OnViewDeleted(view); }
88 void OnViewVisibilityChanged(uint32_t view, bool visible) override {
89 tracker_.OnViewVisibilityChanged(view, visible);
91 void OnViewDrawnStateChanged(uint32_t view, bool drawn) override {
92 tracker_.OnViewDrawnStateChanged(view, drawn);
94 void OnViewSharedPropertyChanged(uint32_t view,
95 const String& name,
96 Array<uint8_t> new_data) override {
97 tracker_.OnViewSharedPropertyChanged(view, name, new_data.Pass());
99 void OnViewInputEvent(uint32_t view,
100 mojo::EventPtr event,
101 const mojo::Callback<void()>& callback) override {
102 tracker_.OnViewInputEvent(view, event.Pass());
104 void OnViewFocused(uint32_t focused_view_id) override {
105 tracker_.OnViewFocused(focused_view_id);
108 TestChangeTracker tracker_;
110 DISALLOW_COPY_AND_ASSIGN(TestViewManagerClient);
113 // -----------------------------------------------------------------------------
115 // ClientConnection implementation that vends TestViewManagerClient.
116 class TestClientConnection : public ClientConnection {
117 public:
118 explicit TestClientConnection(scoped_ptr<ViewManagerServiceImpl> service_impl)
119 : ClientConnection(service_impl.Pass(), &client_) {}
121 TestViewManagerClient* client() { return &client_; }
123 private:
124 ~TestClientConnection() override {}
126 TestViewManagerClient client_;
128 DISALLOW_COPY_AND_ASSIGN(TestClientConnection);
131 // -----------------------------------------------------------------------------
133 // Empty implementation of ConnectionManagerDelegate.
134 class TestConnectionManagerDelegate : public ConnectionManagerDelegate {
135 public:
136 TestConnectionManagerDelegate() : last_connection_(nullptr) {}
137 ~TestConnectionManagerDelegate() override {}
139 TestViewManagerClient* last_client() {
140 return last_connection_ ? last_connection_->client() : nullptr;
143 TestClientConnection* last_connection() { return last_connection_; }
145 private:
146 // ConnectionManagerDelegate:
147 void OnNoMoreRootConnections() override {}
149 ClientConnection* CreateClientConnectionForEmbedAtView(
150 ConnectionManager* connection_manager,
151 mojo::InterfaceRequest<mojo::ViewManagerService> service_request,
152 mojo::ConnectionSpecificId creator_id,
153 mojo::URLRequestPtr request,
154 const ViewId& root_id) override {
155 scoped_ptr<ViewManagerServiceImpl> service(
156 new ViewManagerServiceImpl(connection_manager, creator_id, root_id));
157 last_connection_ = new TestClientConnection(service.Pass());
158 return last_connection_;
160 ClientConnection* CreateClientConnectionForEmbedAtView(
161 ConnectionManager* connection_manager,
162 mojo::InterfaceRequest<mojo::ViewManagerService> service_request,
163 mojo::ConnectionSpecificId creator_id,
164 const ViewId& root_id,
165 mojo::ViewManagerClientPtr client) override {
166 // Used by ConnectionManager::AddRoot.
167 scoped_ptr<ViewManagerServiceImpl> service(
168 new ViewManagerServiceImpl(connection_manager, creator_id, root_id));
169 last_connection_ = new TestClientConnection(service.Pass());
170 return last_connection_;
173 TestClientConnection* last_connection_;
175 DISALLOW_COPY_AND_ASSIGN(TestConnectionManagerDelegate);
178 // -----------------------------------------------------------------------------
180 class TestViewManagerRootConnection : public ViewManagerRootConnection {
181 public:
182 TestViewManagerRootConnection(scoped_ptr<ViewManagerRootImpl> root,
183 ConnectionManager* manager)
184 : ViewManagerRootConnection(root.Pass(), manager) {}
185 ~TestViewManagerRootConnection() override {}
187 private:
188 // ViewManagerRootDelegate:
189 void OnDisplayInitialized() override {
190 connection_manager()->AddRoot(this);
191 set_view_manager_service(connection_manager()->EmbedAtView(
192 kInvalidConnectionId,
193 view_manager_root()->root_view()->id(),
194 mojo::ViewManagerClientPtr()));
196 DISALLOW_COPY_AND_ASSIGN(TestViewManagerRootConnection);
199 // -----------------------------------------------------------------------------
200 // Empty implementation of DisplayManager.
201 class TestDisplayManager : public DisplayManager {
202 public:
203 TestDisplayManager() {}
204 ~TestDisplayManager() override {}
206 // DisplayManager:
207 void Init(DisplayManagerDelegate* delegate) override {
208 // It is necessary to tell the delegate about the ViewportMetrics to make
209 // sure that the ViewManagerRootConnection is correctly initialized (and a
210 // root-view is created).
211 mojo::ViewportMetrics metrics;
212 metrics.size_in_pixels = mojo::Size::From(gfx::Size(400, 300));
213 metrics.device_pixel_ratio = 1.f;
214 delegate->OnViewportMetricsChanged(mojo::ViewportMetrics(), metrics);
216 void SchedulePaint(const ServerView* view, const gfx::Rect& bounds) override {
218 void SetViewportSize(const gfx::Size& size) override {}
219 const mojo::ViewportMetrics& GetViewportMetrics() override {
220 return display_metrices_;
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) override {
238 return new TestDisplayManager();
241 private:
242 DISALLOW_COPY_AND_ASSIGN(TestDisplayManagerFactory);
245 mojo::EventPtr CreatePointerDownEvent(int x, int y) {
246 mojo::EventPtr event(mojo::Event::New());
247 event->action = mojo::EVENT_TYPE_POINTER_DOWN;
248 event->pointer_data = mojo::PointerData::New();
249 event->pointer_data->pointer_id = 1u;
250 event->pointer_data->x = x;
251 event->pointer_data->y = y;
252 return event.Pass();
255 mojo::EventPtr CreatePointerUpEvent(int x, int y) {
256 mojo::EventPtr event(mojo::Event::New());
257 event->action = mojo::EVENT_TYPE_POINTER_UP;
258 event->pointer_data = mojo::PointerData::New();
259 event->pointer_data->pointer_id = 1u;
260 event->pointer_data->x = x;
261 event->pointer_data->y = y;
262 return event.Pass();
265 } // namespace
267 // -----------------------------------------------------------------------------
269 class ViewManagerServiceTest : public testing::Test {
270 public:
271 ViewManagerServiceTest() : wm_client_(nullptr) {}
272 ~ViewManagerServiceTest() override {}
274 // ViewManagerServiceImpl for the window manager.
275 ViewManagerServiceImpl* wm_connection() {
276 return connection_manager_->GetConnection(1);
279 TestViewManagerClient* last_view_manager_client() {
280 return delegate_.last_client();
283 TestClientConnection* last_client_connection() {
284 return delegate_.last_connection();
287 ConnectionManager* connection_manager() { return connection_manager_.get(); }
289 TestViewManagerClient* wm_client() { return wm_client_; }
291 TestViewManagerRootConnection* root_connection() { return root_connection_; }
293 protected:
294 // testing::Test:
295 void SetUp() override {
296 DisplayManager::set_factory_for_testing(&display_manager_factory_);
297 // TODO(fsamuel): This is probably broken. We need a root.
298 connection_manager_.reset(new ConnectionManager(&delegate_));
299 ViewManagerRootImpl* root = new ViewManagerRootImpl(
300 connection_manager_.get(), true /* is_headless */, nullptr,
301 scoped_refptr<gles2::GpuState>());
302 // TODO(fsamuel): This is way too magical. We need to find a better way to
303 // manage lifetime.
304 root_connection_ = new TestViewManagerRootConnection(
305 make_scoped_ptr(root), connection_manager_.get());
306 root->Init(root_connection_);
307 wm_client_ = delegate_.last_client();
310 private:
311 // TestViewManagerClient that is used for the WM connection.
312 TestViewManagerClient* wm_client_;
313 TestDisplayManagerFactory display_manager_factory_;
314 TestConnectionManagerDelegate delegate_;
315 TestViewManagerRootConnection* root_connection_;
316 scoped_ptr<ConnectionManager> connection_manager_;
317 base::MessageLoop message_loop_;
319 DISALLOW_COPY_AND_ASSIGN(ViewManagerServiceTest);
322 namespace {
324 const ServerView* GetFirstCloned(const ServerView* view) {
325 for (const ServerView* child : view->GetChildren()) {
326 if (child->id() == ClonedViewId())
327 return child;
329 return nullptr;
332 // Provides common setup for animation tests. Creates the following views:
333 // 0,1 (the root, provided by view manager)
334 // 1,1 the second connection is embedded here (view owned by wm_connection()).
335 // 2,1 bounds=1,2 11x22
336 // 2,2 bounds=2,3 6x7
337 // 2,3 bounds=3,4 6x7
338 // CloneAndAnimate() is invoked for 2,2.
339 void SetUpAnimate1(ViewManagerServiceTest* test, ViewId* embed_view_id) {
340 *embed_view_id = ViewId(test->wm_connection()->id(), 1);
341 EXPECT_EQ(ERROR_CODE_NONE, test->wm_connection()->CreateView(*embed_view_id));
342 EXPECT_TRUE(test->wm_connection()->SetViewVisibility(*embed_view_id, true));
343 EXPECT_TRUE(test->wm_connection()->AddView(*(test->wm_connection()->root()),
344 *embed_view_id));
345 mojo::URLRequestPtr request(mojo::URLRequest::New());
346 test->wm_connection()->EmbedAllowingReembed(*embed_view_id, request.Pass(),
347 mojo::Callback<void(bool)>());
348 ViewManagerServiceImpl* connection1 =
349 test->connection_manager()->GetConnectionWithRoot(*embed_view_id);
350 ASSERT_TRUE(connection1 != nullptr);
351 ASSERT_NE(connection1, test->wm_connection());
353 const ViewId child1(connection1->id(), 1);
354 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1));
355 const ViewId child2(connection1->id(), 2);
356 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child2));
357 const ViewId child3(connection1->id(), 3);
358 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child3));
360 ServerView* v1 = connection1->GetView(child1);
361 v1->SetVisible(true);
362 v1->SetBounds(gfx::Rect(1, 2, 11, 22));
363 ServerView* v2 = connection1->GetView(child2);
364 v2->SetVisible(true);
365 v2->SetBounds(gfx::Rect(2, 3, 6, 7));
366 ServerView* v3 = connection1->GetView(child3);
367 v3->SetVisible(true);
368 v3->SetBounds(gfx::Rect(3, 4, 6, 7));
370 EXPECT_TRUE(connection1->AddView(*embed_view_id, child1));
371 EXPECT_TRUE(connection1->AddView(child1, child2));
372 EXPECT_TRUE(connection1->AddView(child2, child3));
374 TestViewManagerClient* connection1_client = test->last_view_manager_client();
375 connection1_client->tracker()->changes()->clear();
376 test->wm_client()->tracker()->changes()->clear();
377 EXPECT_TRUE(test->connection_manager()->CloneAndAnimate(child2));
378 EXPECT_TRUE(connection1_client->tracker()->changes()->empty());
379 EXPECT_TRUE(test->wm_client()->tracker()->changes()->empty());
381 // We cloned v2. The cloned view ends up as a sibling of it.
382 const ServerView* cloned_view = GetFirstCloned(connection1->GetView(child1));
383 ASSERT_TRUE(cloned_view);
384 // |cloned_view| should have one and only one cloned child (corresponds to
385 // |child3|).
386 ASSERT_EQ(1u, cloned_view->GetChildren().size());
387 EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId());
389 // Cloned views should match the bounds of the view they were cloned from.
390 EXPECT_EQ(v2->bounds(), cloned_view->bounds());
391 EXPECT_EQ(v3->bounds(), cloned_view->GetChildren()[0]->bounds());
393 // Cloned views are owned by the ConnectionManager and shouldn't be returned
394 // from ViewManagerServiceImpl::GetView.
395 EXPECT_TRUE(connection1->GetView(ClonedViewId()) == nullptr);
396 EXPECT_TRUE(test->wm_connection()->GetView(ClonedViewId()) == nullptr);
399 } // namespace
401 // Verifies ViewManagerService::GetViewTree() doesn't return cloned views.
402 TEST_F(ViewManagerServiceTest, ConnectionsCantSeeClonedViews) {
403 ViewId embed_view_id;
404 EXPECT_NO_FATAL_FAILURE(SetUpAnimate1(this, &embed_view_id));
406 ViewManagerServiceImpl* connection1 =
407 connection_manager()->GetConnectionWithRoot(embed_view_id);
409 const ViewId child1(connection1->id(), 1);
410 const ViewId child2(connection1->id(), 2);
411 const ViewId child3(connection1->id(), 3);
413 // Verify the root doesn't see any cloned views.
414 std::vector<const ServerView*> views(
415 wm_connection()->GetViewTree(*wm_connection()->root()));
416 ASSERT_EQ(5u, views.size());
417 ASSERT_TRUE(views[0]->id() == *wm_connection()->root());
418 ASSERT_TRUE(views[1]->id() == embed_view_id);
419 ASSERT_TRUE(views[2]->id() == child1);
420 ASSERT_TRUE(views[3]->id() == child2);
421 ASSERT_TRUE(views[4]->id() == child3);
423 // Verify connection1 doesn't see any cloned views.
424 std::vector<const ServerView*> v1_views(
425 connection1->GetViewTree(embed_view_id));
426 ASSERT_EQ(4u, v1_views.size());
427 ASSERT_TRUE(v1_views[0]->id() == embed_view_id);
428 ASSERT_TRUE(v1_views[1]->id() == child1);
429 ASSERT_TRUE(v1_views[2]->id() == child2);
430 ASSERT_TRUE(v1_views[3]->id() == child3);
433 TEST_F(ViewManagerServiceTest, ClonedViewsPromotedOnConnectionClose) {
434 ViewId embed_view_id;
435 EXPECT_NO_FATAL_FAILURE(SetUpAnimate1(this, &embed_view_id));
437 // Destroy connection1, which should force the cloned view to become a child
438 // of where it was embedded (the embedded view still exists).
439 connection_manager()->OnConnectionError(last_client_connection());
441 ServerView* embed_view = wm_connection()->GetView(embed_view_id);
442 ASSERT_TRUE(embed_view != nullptr);
443 const ServerView* cloned_view = GetFirstCloned(embed_view);
444 ASSERT_TRUE(cloned_view);
445 ASSERT_EQ(1u, cloned_view->GetChildren().size());
446 EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId());
448 // Because the cloned view changed parents its bounds should have changed.
449 EXPECT_EQ(gfx::Rect(3, 5, 6, 7), cloned_view->bounds());
450 // The bounds of the cloned child should not have changed though.
451 EXPECT_EQ(gfx::Rect(3, 4, 6, 7), cloned_view->GetChildren()[0]->bounds());
454 TEST_F(ViewManagerServiceTest, ClonedViewsPromotedOnHide) {
455 ViewId embed_view_id;
456 EXPECT_NO_FATAL_FAILURE(SetUpAnimate1(this, &embed_view_id));
458 ViewManagerServiceImpl* connection1 =
459 connection_manager()->GetConnectionWithRoot(embed_view_id);
461 // Hide the parent of the cloned view, which should force the cloned view to
462 // become a sibling of the parent.
463 const ServerView* view_to_hide =
464 connection1->GetView(ViewId(connection1->id(), 1));
465 ASSERT_TRUE(connection1->SetViewVisibility(view_to_hide->id(), false));
467 const ServerView* cloned_view = GetFirstCloned(view_to_hide->parent());
468 ASSERT_TRUE(cloned_view);
469 ASSERT_EQ(1u, cloned_view->GetChildren().size());
470 EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId());
471 EXPECT_EQ(2u, cloned_view->parent()->GetChildren().size());
472 EXPECT_TRUE(cloned_view->parent()->GetChildren()[1] == cloned_view);
475 // Clone and animate on a tree with more depth. Basically that of
476 // SetUpAnimate1() but cloning 2,1.
477 TEST_F(ViewManagerServiceTest, CloneAndAnimateLargerDepth) {
478 const ViewId embed_view_id(wm_connection()->id(), 1);
479 EXPECT_EQ(ERROR_CODE_NONE, wm_connection()->CreateView(embed_view_id));
480 EXPECT_TRUE(wm_connection()->SetViewVisibility(embed_view_id, true));
481 EXPECT_TRUE(
482 wm_connection()->AddView(*(wm_connection()->root()), embed_view_id));
483 mojo::URLRequestPtr request(mojo::URLRequest::New());
484 wm_connection()->EmbedAllowingReembed(embed_view_id, request.Pass(),
485 mojo::Callback<void(bool)>());
486 ViewManagerServiceImpl* connection1 =
487 connection_manager()->GetConnectionWithRoot(embed_view_id);
488 ASSERT_TRUE(connection1 != nullptr);
489 ASSERT_NE(connection1, wm_connection());
491 const ViewId child1(connection1->id(), 1);
492 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1));
493 const ViewId child2(connection1->id(), 2);
494 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child2));
495 const ViewId child3(connection1->id(), 3);
496 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child3));
498 ServerView* v1 = connection1->GetView(child1);
499 v1->SetVisible(true);
500 connection1->GetView(child2)->SetVisible(true);
501 connection1->GetView(child3)->SetVisible(true);
503 EXPECT_TRUE(connection1->AddView(embed_view_id, child1));
504 EXPECT_TRUE(connection1->AddView(child1, child2));
505 EXPECT_TRUE(connection1->AddView(child2, child3));
507 TestViewManagerClient* connection1_client = last_view_manager_client();
508 connection1_client->tracker()->changes()->clear();
509 wm_client()->tracker()->changes()->clear();
510 EXPECT_TRUE(connection_manager()->CloneAndAnimate(child1));
511 EXPECT_TRUE(connection1_client->tracker()->changes()->empty());
512 EXPECT_TRUE(wm_client()->tracker()->changes()->empty());
514 // We cloned v1. The cloned view ends up as a sibling of it.
515 const ServerView* cloned_view = GetFirstCloned(v1->parent());
516 ASSERT_TRUE(cloned_view);
517 // |cloned_view| should have a child and its child should have a child.
518 ASSERT_EQ(1u, cloned_view->GetChildren().size());
519 const ServerView* cloned_view_child = cloned_view->GetChildren()[0];
520 EXPECT_EQ(1u, cloned_view_child->GetChildren().size());
521 EXPECT_TRUE(cloned_view_child->id() == ClonedViewId());
524 // Verifies focus correctly changes on pointer events.
525 TEST_F(ViewManagerServiceTest, FocusOnPointer) {
526 const ViewId embed_view_id(wm_connection()->id(), 1);
527 EXPECT_EQ(ERROR_CODE_NONE, wm_connection()->CreateView(embed_view_id));
528 EXPECT_TRUE(wm_connection()->SetViewVisibility(embed_view_id, true));
529 EXPECT_TRUE(
530 wm_connection()->AddView(*(wm_connection()->root()), embed_view_id));
531 root_connection()->view_manager_root()->root_view()->
532 SetBounds(gfx::Rect(0, 0, 100, 100));
533 mojo::URLRequestPtr request(mojo::URLRequest::New());
534 wm_connection()->EmbedAllowingReembed(embed_view_id, request.Pass(),
535 mojo::Callback<void(bool)>());
536 ViewManagerServiceImpl* connection1 =
537 connection_manager()->GetConnectionWithRoot(embed_view_id);
538 ASSERT_TRUE(connection1 != nullptr);
539 ASSERT_NE(connection1, wm_connection());
541 connection_manager()
542 ->GetView(embed_view_id)
543 ->SetBounds(gfx::Rect(0, 0, 50, 50));
545 const ViewId child1(connection1->id(), 1);
546 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1));
547 EXPECT_TRUE(connection1->AddView(embed_view_id, child1));
548 ServerView* v1 = connection1->GetView(child1);
549 v1->SetVisible(true);
550 v1->SetBounds(gfx::Rect(20, 20, 20, 20));
552 TestViewManagerClient* connection1_client = last_view_manager_client();
553 connection1_client->tracker()->changes()->clear();
554 wm_client()->tracker()->changes()->clear();
556 connection_manager()->OnEvent(root_connection()->view_manager_root(),
557 CreatePointerDownEvent(21, 22));
558 // Focus should go to child1. This results in notifying both the window
559 // manager and client connection being notified.
560 EXPECT_EQ(v1, connection_manager()->GetFocusedView());
561 ASSERT_GE(wm_client()->tracker()->changes()->size(), 1u);
562 EXPECT_EQ("Focused id=2,1",
563 ChangesToDescription1(*wm_client()->tracker()->changes())[0]);
564 ASSERT_GE(connection1_client->tracker()->changes()->size(), 1u);
565 EXPECT_EQ(
566 "Focused id=2,1",
567 ChangesToDescription1(*connection1_client->tracker()->changes())[0]);
569 connection_manager()->OnEvent(root_connection()->view_manager_root(),
570 CreatePointerUpEvent(21, 22));
571 wm_client()->tracker()->changes()->clear();
572 connection1_client->tracker()->changes()->clear();
574 // Press outside of the embedded view. Focus should go to the root. Notice
575 // the client1 doesn't see who has focus as the focused view (root) isn't
576 // visible to it.
577 connection_manager()->OnEvent(root_connection()->view_manager_root(),
578 CreatePointerDownEvent(61, 22));
579 EXPECT_EQ(root_connection()->view_manager_root()->root_view(),
580 connection_manager()->GetFocusedView());
581 ASSERT_GE(wm_client()->tracker()->changes()->size(), 1u);
582 EXPECT_EQ("Focused id=0,2",
583 ChangesToDescription1(*wm_client()->tracker()->changes())[0]);
584 ASSERT_GE(connection1_client->tracker()->changes()->size(), 1u);
585 EXPECT_EQ(
586 "Focused id=null",
587 ChangesToDescription1(*connection1_client->tracker()->changes())[0]);
589 connection_manager()->OnEvent(root_connection()->view_manager_root(),
590 CreatePointerUpEvent(21, 22));
591 wm_client()->tracker()->changes()->clear();
592 connection1_client->tracker()->changes()->clear();
594 // Press in the same location. Should not get a focus change event (only input
595 // event).
596 connection_manager()->OnEvent(root_connection()->view_manager_root(),
597 CreatePointerDownEvent(61, 22));
598 EXPECT_EQ(root_connection()->view_manager_root()->root_view(),
599 connection_manager()->GetFocusedView());
600 ASSERT_EQ(wm_client()->tracker()->changes()->size(), 1u);
601 EXPECT_EQ("InputEvent view=0,2 event_action=4",
602 ChangesToDescription1(*wm_client()->tracker()->changes())[0]);
603 EXPECT_TRUE(connection1_client->tracker()->changes()->empty());
606 } // namespace view_manager