Allow intent picker for external schemes
[chromium-blink-merge.git] / components / view_manager / view_manager_service_unittest.cc
blob6bd8ee38196073ceece61b1182026ef1b553f524
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 OnUnembed() override { tracker_.OnUnembed(); }
66 void OnViewBoundsChanged(uint32_t view,
67 mojo::RectPtr old_bounds,
68 mojo::RectPtr new_bounds) override {
69 tracker_.OnViewBoundsChanged(view, old_bounds.Pass(), new_bounds.Pass());
71 void OnViewViewportMetricsChanged(
72 mojo::ViewportMetricsPtr old_metrics,
73 mojo::ViewportMetricsPtr new_metrics) override {
74 tracker_.OnViewViewportMetricsChanged(old_metrics.Pass(),
75 new_metrics.Pass());
77 void OnViewHierarchyChanged(uint32_t view,
78 uint32_t new_parent,
79 uint32_t old_parent,
80 Array<ViewDataPtr> views) override {
81 tracker_.OnViewHierarchyChanged(view, new_parent, old_parent, views.Pass());
83 void OnViewReordered(uint32_t view_id,
84 uint32_t relative_view_id,
85 mojo::OrderDirection direction) override {
86 tracker_.OnViewReordered(view_id, relative_view_id, direction);
88 void OnViewDeleted(uint32_t view) override { tracker_.OnViewDeleted(view); }
89 void OnViewVisibilityChanged(uint32_t view, bool visible) override {
90 tracker_.OnViewVisibilityChanged(view, visible);
92 void OnViewDrawnStateChanged(uint32_t view, bool drawn) override {
93 tracker_.OnViewDrawnStateChanged(view, drawn);
95 void OnViewSharedPropertyChanged(uint32_t view,
96 const String& name,
97 Array<uint8_t> new_data) override {
98 tracker_.OnViewSharedPropertyChanged(view, name, new_data.Pass());
100 void OnViewInputEvent(uint32_t view,
101 mojo::EventPtr event,
102 const mojo::Callback<void()>& callback) override {
103 tracker_.OnViewInputEvent(view, event.Pass());
105 void OnViewFocused(uint32_t focused_view_id) override {
106 tracker_.OnViewFocused(focused_view_id);
109 TestChangeTracker tracker_;
111 DISALLOW_COPY_AND_ASSIGN(TestViewManagerClient);
114 // -----------------------------------------------------------------------------
116 // ClientConnection implementation that vends TestViewManagerClient.
117 class TestClientConnection : public ClientConnection {
118 public:
119 explicit TestClientConnection(scoped_ptr<ViewManagerServiceImpl> service_impl)
120 : ClientConnection(service_impl.Pass(), &client_) {}
122 TestViewManagerClient* client() { return &client_; }
124 private:
125 ~TestClientConnection() override {}
127 TestViewManagerClient client_;
129 DISALLOW_COPY_AND_ASSIGN(TestClientConnection);
132 // -----------------------------------------------------------------------------
134 // Empty implementation of ConnectionManagerDelegate.
135 class TestConnectionManagerDelegate : public ConnectionManagerDelegate {
136 public:
137 TestConnectionManagerDelegate() : last_connection_(nullptr) {}
138 ~TestConnectionManagerDelegate() override {}
140 TestViewManagerClient* last_client() {
141 return last_connection_ ? last_connection_->client() : nullptr;
144 TestClientConnection* last_connection() { return last_connection_; }
146 private:
147 // ConnectionManagerDelegate:
148 void OnNoMoreRootConnections() override {}
150 ClientConnection* CreateClientConnectionForEmbedAtView(
151 ConnectionManager* connection_manager,
152 mojo::InterfaceRequest<mojo::ViewManagerService> service_request,
153 mojo::ConnectionSpecificId creator_id,
154 mojo::URLRequestPtr request,
155 const ViewId& root_id) override {
156 scoped_ptr<ViewManagerServiceImpl> service(
157 new ViewManagerServiceImpl(connection_manager, creator_id, root_id));
158 last_connection_ = new TestClientConnection(service.Pass());
159 return last_connection_;
161 ClientConnection* CreateClientConnectionForEmbedAtView(
162 ConnectionManager* connection_manager,
163 mojo::InterfaceRequest<mojo::ViewManagerService> service_request,
164 mojo::ConnectionSpecificId creator_id,
165 const ViewId& root_id,
166 mojo::ViewManagerClientPtr client) override {
167 // Used by ConnectionManager::AddRoot.
168 scoped_ptr<ViewManagerServiceImpl> service(
169 new ViewManagerServiceImpl(connection_manager, creator_id, root_id));
170 last_connection_ = new TestClientConnection(service.Pass());
171 return last_connection_;
174 TestClientConnection* last_connection_;
176 DISALLOW_COPY_AND_ASSIGN(TestConnectionManagerDelegate);
179 // -----------------------------------------------------------------------------
181 class TestViewManagerRootConnection : public ViewManagerRootConnection {
182 public:
183 TestViewManagerRootConnection(scoped_ptr<ViewManagerRootImpl> root,
184 ConnectionManager* manager)
185 : ViewManagerRootConnection(root.Pass(), manager) {}
186 ~TestViewManagerRootConnection() override {}
188 private:
189 // ViewManagerRootDelegate:
190 void OnDisplayInitialized() override {
191 connection_manager()->AddRoot(this);
192 set_view_manager_service(connection_manager()->EmbedAtView(
193 kInvalidConnectionId,
194 view_manager_root()->root_view()->id(),
195 mojo::ViewManagerClientPtr()));
197 DISALLOW_COPY_AND_ASSIGN(TestViewManagerRootConnection);
200 // -----------------------------------------------------------------------------
201 // Empty implementation of DisplayManager.
202 class TestDisplayManager : public DisplayManager {
203 public:
204 TestDisplayManager() {}
205 ~TestDisplayManager() override {}
207 // DisplayManager:
208 void Init(DisplayManagerDelegate* delegate) override {
209 // It is necessary to tell the delegate about the ViewportMetrics to make
210 // sure that the ViewManagerRootConnection is correctly initialized (and a
211 // root-view is created).
212 mojo::ViewportMetrics metrics;
213 metrics.size_in_pixels = mojo::Size::From(gfx::Size(400, 300));
214 metrics.device_pixel_ratio = 1.f;
215 delegate->OnViewportMetricsChanged(mojo::ViewportMetrics(), metrics);
217 void SchedulePaint(const ServerView* view, const gfx::Rect& bounds) override {
219 void SetViewportSize(const gfx::Size& size) override {}
220 const mojo::ViewportMetrics& GetViewportMetrics() override {
221 return display_metrices_;
223 void UpdateTextInputState(const ui::TextInputState& state) override {}
224 void SetImeVisibility(bool visible) override {}
226 private:
227 mojo::ViewportMetrics display_metrices_;
229 DISALLOW_COPY_AND_ASSIGN(TestDisplayManager);
232 // Factory that dispenses TestDisplayManagers.
233 class TestDisplayManagerFactory : public DisplayManagerFactory {
234 public:
235 TestDisplayManagerFactory() {}
236 ~TestDisplayManagerFactory() {}
237 DisplayManager* CreateDisplayManager(
238 bool is_headless,
239 mojo::ApplicationImpl* app_impl,
240 const scoped_refptr<gles2::GpuState>& gpu_state) override {
241 return new TestDisplayManager();
244 private:
245 DISALLOW_COPY_AND_ASSIGN(TestDisplayManagerFactory);
248 mojo::EventPtr CreatePointerDownEvent(int x, int y) {
249 mojo::EventPtr event(mojo::Event::New());
250 event->action = mojo::EVENT_TYPE_POINTER_DOWN;
251 event->pointer_data = mojo::PointerData::New();
252 event->pointer_data->pointer_id = 1u;
253 event->pointer_data->x = x;
254 event->pointer_data->y = y;
255 return event.Pass();
258 mojo::EventPtr CreatePointerUpEvent(int x, int y) {
259 mojo::EventPtr event(mojo::Event::New());
260 event->action = mojo::EVENT_TYPE_POINTER_UP;
261 event->pointer_data = mojo::PointerData::New();
262 event->pointer_data->pointer_id = 1u;
263 event->pointer_data->x = x;
264 event->pointer_data->y = y;
265 return event.Pass();
268 } // namespace
270 // -----------------------------------------------------------------------------
272 class ViewManagerServiceTest : public testing::Test {
273 public:
274 ViewManagerServiceTest() : wm_client_(nullptr) {}
275 ~ViewManagerServiceTest() override {}
277 // ViewManagerServiceImpl for the window manager.
278 ViewManagerServiceImpl* wm_connection() {
279 return connection_manager_->GetConnection(1);
282 TestViewManagerClient* last_view_manager_client() {
283 return delegate_.last_client();
286 TestClientConnection* last_client_connection() {
287 return delegate_.last_connection();
290 ConnectionManager* connection_manager() { return connection_manager_.get(); }
292 TestViewManagerClient* wm_client() { return wm_client_; }
294 TestViewManagerRootConnection* root_connection() { return root_connection_; }
296 protected:
297 // testing::Test:
298 void SetUp() override {
299 DisplayManager::set_factory_for_testing(&display_manager_factory_);
300 // TODO(fsamuel): This is probably broken. We need a root.
301 connection_manager_.reset(new ConnectionManager(&delegate_));
302 ViewManagerRootImpl* root = new ViewManagerRootImpl(
303 connection_manager_.get(), true /* is_headless */, nullptr,
304 scoped_refptr<gles2::GpuState>());
305 // TODO(fsamuel): This is way too magical. We need to find a better way to
306 // manage lifetime.
307 root_connection_ = new TestViewManagerRootConnection(
308 make_scoped_ptr(root), connection_manager_.get());
309 root->Init(root_connection_);
310 wm_client_ = delegate_.last_client();
313 private:
314 // TestViewManagerClient that is used for the WM connection.
315 TestViewManagerClient* wm_client_;
316 TestDisplayManagerFactory display_manager_factory_;
317 TestConnectionManagerDelegate delegate_;
318 TestViewManagerRootConnection* root_connection_;
319 scoped_ptr<ConnectionManager> connection_manager_;
320 base::MessageLoop message_loop_;
322 DISALLOW_COPY_AND_ASSIGN(ViewManagerServiceTest);
325 namespace {
327 const ServerView* GetFirstCloned(const ServerView* view) {
328 for (const ServerView* child : view->GetChildren()) {
329 if (child->id() == ClonedViewId())
330 return child;
332 return nullptr;
335 // Provides common setup for animation tests. Creates the following views:
336 // 0,1 (the root, provided by view manager)
337 // 1,1 the second connection is embedded here (view owned by wm_connection()).
338 // 2,1 bounds=1,2 11x22
339 // 2,2 bounds=2,3 6x7
340 // 2,3 bounds=3,4 6x7
341 // CloneAndAnimate() is invoked for 2,2.
342 void SetUpAnimate1(ViewManagerServiceTest* test, ViewId* embed_view_id) {
343 *embed_view_id = ViewId(test->wm_connection()->id(), 1);
344 EXPECT_EQ(ERROR_CODE_NONE, test->wm_connection()->CreateView(*embed_view_id));
345 EXPECT_TRUE(test->wm_connection()->SetViewVisibility(*embed_view_id, true));
346 EXPECT_TRUE(test->wm_connection()->AddView(*(test->wm_connection()->root()),
347 *embed_view_id));
348 mojo::URLRequestPtr request(mojo::URLRequest::New());
349 test->wm_connection()->EmbedAllowingReembed(*embed_view_id, request.Pass(),
350 mojo::Callback<void(bool)>());
351 ViewManagerServiceImpl* connection1 =
352 test->connection_manager()->GetConnectionWithRoot(*embed_view_id);
353 ASSERT_TRUE(connection1 != nullptr);
354 ASSERT_NE(connection1, test->wm_connection());
356 const ViewId child1(connection1->id(), 1);
357 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1));
358 const ViewId child2(connection1->id(), 2);
359 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child2));
360 const ViewId child3(connection1->id(), 3);
361 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child3));
363 ServerView* v1 = connection1->GetView(child1);
364 v1->SetVisible(true);
365 v1->SetBounds(gfx::Rect(1, 2, 11, 22));
366 ServerView* v2 = connection1->GetView(child2);
367 v2->SetVisible(true);
368 v2->SetBounds(gfx::Rect(2, 3, 6, 7));
369 ServerView* v3 = connection1->GetView(child3);
370 v3->SetVisible(true);
371 v3->SetBounds(gfx::Rect(3, 4, 6, 7));
373 EXPECT_TRUE(connection1->AddView(*embed_view_id, child1));
374 EXPECT_TRUE(connection1->AddView(child1, child2));
375 EXPECT_TRUE(connection1->AddView(child2, child3));
377 TestViewManagerClient* connection1_client = test->last_view_manager_client();
378 connection1_client->tracker()->changes()->clear();
379 test->wm_client()->tracker()->changes()->clear();
380 EXPECT_TRUE(test->connection_manager()->CloneAndAnimate(child2));
381 EXPECT_TRUE(connection1_client->tracker()->changes()->empty());
382 EXPECT_TRUE(test->wm_client()->tracker()->changes()->empty());
384 // We cloned v2. The cloned view ends up as a sibling of it.
385 const ServerView* cloned_view = GetFirstCloned(connection1->GetView(child1));
386 ASSERT_TRUE(cloned_view);
387 // |cloned_view| should have one and only one cloned child (corresponds to
388 // |child3|).
389 ASSERT_EQ(1u, cloned_view->GetChildren().size());
390 EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId());
392 // Cloned views should match the bounds of the view they were cloned from.
393 EXPECT_EQ(v2->bounds(), cloned_view->bounds());
394 EXPECT_EQ(v3->bounds(), cloned_view->GetChildren()[0]->bounds());
396 // Cloned views are owned by the ConnectionManager and shouldn't be returned
397 // from ViewManagerServiceImpl::GetView.
398 EXPECT_TRUE(connection1->GetView(ClonedViewId()) == nullptr);
399 EXPECT_TRUE(test->wm_connection()->GetView(ClonedViewId()) == nullptr);
402 } // namespace
404 // Verifies ViewManagerService::GetViewTree() doesn't return cloned views.
405 TEST_F(ViewManagerServiceTest, ConnectionsCantSeeClonedViews) {
406 ViewId embed_view_id;
407 EXPECT_NO_FATAL_FAILURE(SetUpAnimate1(this, &embed_view_id));
409 ViewManagerServiceImpl* connection1 =
410 connection_manager()->GetConnectionWithRoot(embed_view_id);
412 const ViewId child1(connection1->id(), 1);
413 const ViewId child2(connection1->id(), 2);
414 const ViewId child3(connection1->id(), 3);
416 // Verify the root doesn't see any cloned views.
417 std::vector<const ServerView*> views(
418 wm_connection()->GetViewTree(*wm_connection()->root()));
419 ASSERT_EQ(5u, views.size());
420 ASSERT_TRUE(views[0]->id() == *wm_connection()->root());
421 ASSERT_TRUE(views[1]->id() == embed_view_id);
422 ASSERT_TRUE(views[2]->id() == child1);
423 ASSERT_TRUE(views[3]->id() == child2);
424 ASSERT_TRUE(views[4]->id() == child3);
426 // Verify connection1 doesn't see any cloned views.
427 std::vector<const ServerView*> v1_views(
428 connection1->GetViewTree(embed_view_id));
429 ASSERT_EQ(4u, v1_views.size());
430 ASSERT_TRUE(v1_views[0]->id() == embed_view_id);
431 ASSERT_TRUE(v1_views[1]->id() == child1);
432 ASSERT_TRUE(v1_views[2]->id() == child2);
433 ASSERT_TRUE(v1_views[3]->id() == child3);
436 TEST_F(ViewManagerServiceTest, ClonedViewsPromotedOnConnectionClose) {
437 ViewId embed_view_id;
438 EXPECT_NO_FATAL_FAILURE(SetUpAnimate1(this, &embed_view_id));
440 // Destroy connection1, which should force the cloned view to become a child
441 // of where it was embedded (the embedded view still exists).
442 connection_manager()->OnConnectionError(last_client_connection());
444 ServerView* embed_view = wm_connection()->GetView(embed_view_id);
445 ASSERT_TRUE(embed_view != nullptr);
446 const ServerView* cloned_view = GetFirstCloned(embed_view);
447 ASSERT_TRUE(cloned_view);
448 ASSERT_EQ(1u, cloned_view->GetChildren().size());
449 EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId());
451 // Because the cloned view changed parents its bounds should have changed.
452 EXPECT_EQ(gfx::Rect(3, 5, 6, 7), cloned_view->bounds());
453 // The bounds of the cloned child should not have changed though.
454 EXPECT_EQ(gfx::Rect(3, 4, 6, 7), cloned_view->GetChildren()[0]->bounds());
457 TEST_F(ViewManagerServiceTest, ClonedViewsPromotedOnHide) {
458 ViewId embed_view_id;
459 EXPECT_NO_FATAL_FAILURE(SetUpAnimate1(this, &embed_view_id));
461 ViewManagerServiceImpl* connection1 =
462 connection_manager()->GetConnectionWithRoot(embed_view_id);
464 // Hide the parent of the cloned view, which should force the cloned view to
465 // become a sibling of the parent.
466 const ServerView* view_to_hide =
467 connection1->GetView(ViewId(connection1->id(), 1));
468 ASSERT_TRUE(connection1->SetViewVisibility(view_to_hide->id(), false));
470 const ServerView* cloned_view = GetFirstCloned(view_to_hide->parent());
471 ASSERT_TRUE(cloned_view);
472 ASSERT_EQ(1u, cloned_view->GetChildren().size());
473 EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId());
474 EXPECT_EQ(2u, cloned_view->parent()->GetChildren().size());
475 EXPECT_TRUE(cloned_view->parent()->GetChildren()[1] == cloned_view);
478 // Clone and animate on a tree with more depth. Basically that of
479 // SetUpAnimate1() but cloning 2,1.
480 TEST_F(ViewManagerServiceTest, CloneAndAnimateLargerDepth) {
481 const ViewId embed_view_id(wm_connection()->id(), 1);
482 EXPECT_EQ(ERROR_CODE_NONE, wm_connection()->CreateView(embed_view_id));
483 EXPECT_TRUE(wm_connection()->SetViewVisibility(embed_view_id, true));
484 EXPECT_TRUE(
485 wm_connection()->AddView(*(wm_connection()->root()), embed_view_id));
486 mojo::URLRequestPtr request(mojo::URLRequest::New());
487 wm_connection()->EmbedAllowingReembed(embed_view_id, request.Pass(),
488 mojo::Callback<void(bool)>());
489 ViewManagerServiceImpl* 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 TestViewManagerClient* connection1_client = last_view_manager_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(ViewManagerServiceTest, 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 root_connection()->view_manager_root()->root_view()->
535 SetBounds(gfx::Rect(0, 0, 100, 100));
536 mojo::URLRequestPtr request(mojo::URLRequest::New());
537 wm_connection()->EmbedAllowingReembed(embed_view_id, request.Pass(),
538 mojo::Callback<void(bool)>());
539 ViewManagerServiceImpl* connection1 =
540 connection_manager()->GetConnectionWithRoot(embed_view_id);
541 ASSERT_TRUE(connection1 != nullptr);
542 ASSERT_NE(connection1, wm_connection());
544 connection_manager()
545 ->GetView(embed_view_id)
546 ->SetBounds(gfx::Rect(0, 0, 50, 50));
548 const ViewId child1(connection1->id(), 1);
549 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1));
550 EXPECT_TRUE(connection1->AddView(embed_view_id, child1));
551 ServerView* v1 = connection1->GetView(child1);
552 v1->SetVisible(true);
553 v1->SetBounds(gfx::Rect(20, 20, 20, 20));
555 TestViewManagerClient* connection1_client = last_view_manager_client();
556 connection1_client->tracker()->changes()->clear();
557 wm_client()->tracker()->changes()->clear();
559 connection_manager()->OnEvent(root_connection()->view_manager_root(),
560 CreatePointerDownEvent(21, 22));
561 // Focus should go to child1. This results in notifying both the window
562 // manager and client connection being notified.
563 EXPECT_EQ(v1, connection_manager()->GetFocusedView());
564 ASSERT_GE(wm_client()->tracker()->changes()->size(), 1u);
565 EXPECT_EQ("Focused id=2,1",
566 ChangesToDescription1(*wm_client()->tracker()->changes())[0]);
567 ASSERT_GE(connection1_client->tracker()->changes()->size(), 1u);
568 EXPECT_EQ(
569 "Focused id=2,1",
570 ChangesToDescription1(*connection1_client->tracker()->changes())[0]);
572 connection_manager()->OnEvent(root_connection()->view_manager_root(),
573 CreatePointerUpEvent(21, 22));
574 wm_client()->tracker()->changes()->clear();
575 connection1_client->tracker()->changes()->clear();
577 // Press outside of the embedded view. Focus should go to the root. Notice
578 // the client1 doesn't see who has focus as the focused view (root) isn't
579 // visible to it.
580 connection_manager()->OnEvent(root_connection()->view_manager_root(),
581 CreatePointerDownEvent(61, 22));
582 EXPECT_EQ(root_connection()->view_manager_root()->root_view(),
583 connection_manager()->GetFocusedView());
584 ASSERT_GE(wm_client()->tracker()->changes()->size(), 1u);
585 EXPECT_EQ("Focused id=0,2",
586 ChangesToDescription1(*wm_client()->tracker()->changes())[0]);
587 ASSERT_GE(connection1_client->tracker()->changes()->size(), 1u);
588 EXPECT_EQ(
589 "Focused id=null",
590 ChangesToDescription1(*connection1_client->tracker()->changes())[0]);
592 connection_manager()->OnEvent(root_connection()->view_manager_root(),
593 CreatePointerUpEvent(21, 22));
594 wm_client()->tracker()->changes()->clear();
595 connection1_client->tracker()->changes()->clear();
597 // Press in the same location. Should not get a focus change event (only input
598 // event).
599 connection_manager()->OnEvent(root_connection()->view_manager_root(),
600 CreatePointerDownEvent(61, 22));
601 EXPECT_EQ(root_connection()->view_manager_root()->root_view(),
602 connection_manager()->GetFocusedView());
603 ASSERT_EQ(wm_client()->tracker()->changes()->size(), 1u);
604 EXPECT_EQ("InputEvent view=0,2 event_action=4",
605 ChangesToDescription1(*wm_client()->tracker()->changes())[0]);
606 EXPECT_TRUE(connection1_client->tracker()->changes()->empty());
609 } // namespace view_manager