OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "components/view_manager/ids.h" | 9 #include "components/mus/ids.h" |
10 #include "components/view_manager/public/interfaces/view_tree.mojom.h" | 10 #include "components/mus/public/interfaces/view_tree.mojom.h" |
11 #include "components/view_manager/public/interfaces/view_tree_host.mojom.h" | 11 #include "components/mus/public/interfaces/view_tree_host.mojom.h" |
12 #include "components/view_manager/test_change_tracker.h" | 12 #include "components/mus/test_change_tracker.h" |
13 #include "mojo/application/public/cpp/application_delegate.h" | 13 #include "mojo/application/public/cpp/application_delegate.h" |
14 #include "mojo/application/public/cpp/application_impl.h" | 14 #include "mojo/application/public/cpp/application_impl.h" |
15 #include "mojo/application/public/cpp/application_test_base.h" | 15 #include "mojo/application/public/cpp/application_test_base.h" |
16 | 16 |
17 using mojo::ApplicationConnection; | 17 using mojo::ApplicationConnection; |
18 using mojo::ApplicationDelegate; | 18 using mojo::ApplicationDelegate; |
19 using mojo::Array; | 19 using mojo::Array; |
20 using mojo::Callback; | 20 using mojo::Callback; |
21 using mojo::ConnectionSpecificId; | 21 using mojo::ConnectionSpecificId; |
22 using mojo::ERROR_CODE_NONE; | 22 using mojo::ERROR_CODE_NONE; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 Id relative_view_id, | 140 Id relative_view_id, |
141 OrderDirection direction) { | 141 OrderDirection direction) { |
142 bool result = false; | 142 bool result = false; |
143 base::RunLoop run_loop; | 143 base::RunLoop run_loop; |
144 vm->ReorderView(view_id, relative_view_id, direction, | 144 vm->ReorderView(view_id, relative_view_id, direction, |
145 base::Bind(&BoolResultCallback, &run_loop, &result)); | 145 base::Bind(&BoolResultCallback, &run_loop, &result)); |
146 run_loop.Run(); | 146 run_loop.Run(); |
147 return result; | 147 return result; |
148 } | 148 } |
149 | 149 |
150 void GetViewTree(ViewTree* vm, | 150 void GetViewTree(ViewTree* vm, Id view_id, std::vector<TestView>* views) { |
151 Id view_id, | |
152 std::vector<TestView>* views) { | |
153 base::RunLoop run_loop; | 151 base::RunLoop run_loop; |
154 vm->GetViewTree(view_id, | 152 vm->GetViewTree(view_id, |
155 base::Bind(&ViewTreeResultCallback, &run_loop, views)); | 153 base::Bind(&ViewTreeResultCallback, &run_loop, views)); |
156 run_loop.Run(); | 154 run_loop.Run(); |
157 } | 155 } |
158 | 156 |
159 bool DeleteView(ViewTree* vm, Id view_id) { | 157 bool DeleteView(ViewTree* vm, Id view_id) { |
160 base::RunLoop run_loop; | 158 base::RunLoop run_loop; |
161 bool result = false; | 159 bool result = false; |
162 vm->DeleteView(view_id, base::Bind(&BoolResultCallback, &run_loop, &result)); | 160 vm->DeleteView(view_id, base::Bind(&BoolResultCallback, &run_loop, &result)); |
163 run_loop.Run(); | 161 run_loop.Run(); |
164 return result; | 162 return result; |
165 } | 163 } |
166 | 164 |
167 bool SetViewBounds(ViewTree* vm, | 165 bool SetViewBounds(ViewTree* vm, Id view_id, int x, int y, int w, int h) { |
168 Id view_id, | |
169 int x, | |
170 int y, | |
171 int w, | |
172 int h) { | |
173 base::RunLoop run_loop; | 166 base::RunLoop run_loop; |
174 bool result = false; | 167 bool result = false; |
175 RectPtr rect(mojo::Rect::New()); | 168 RectPtr rect(mojo::Rect::New()); |
176 rect->x = x; | 169 rect->x = x; |
177 rect->y = y; | 170 rect->y = y; |
178 rect->width = w; | 171 rect->width = w; |
179 rect->height = h; | 172 rect->height = h; |
180 vm->SetViewBounds(view_id, rect.Pass(), | 173 vm->SetViewBounds(view_id, rect.Pass(), |
181 base::Bind(&BoolResultCallback, &run_loop, &result)); | 174 base::Bind(&BoolResultCallback, &run_loop, &result)); |
182 run_loop.Run(); | 175 run_loop.Run(); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 tracker()->OnEmbeddedAppDisconnected(view_id); | 317 tracker()->OnEmbeddedAppDisconnected(view_id); |
325 } | 318 } |
326 void OnUnembed() override { tracker()->OnUnembed(); } | 319 void OnUnembed() override { tracker()->OnUnembed(); } |
327 void OnViewBoundsChanged(Id view_id, | 320 void OnViewBoundsChanged(Id view_id, |
328 RectPtr old_bounds, | 321 RectPtr old_bounds, |
329 RectPtr new_bounds) override { | 322 RectPtr new_bounds) override { |
330 // The bounds of the root may change during startup on Android at random | 323 // The bounds of the root may change during startup on Android at random |
331 // times. As this doesn't matter, and shouldn't impact test exepctations, | 324 // times. As this doesn't matter, and shouldn't impact test exepctations, |
332 // it is ignored. | 325 // it is ignored. |
333 if (view_id == root_view_id_) | 326 if (view_id == root_view_id_) |
334 return; | 327 return; |
335 tracker()->OnViewBoundsChanged(view_id, old_bounds.Pass(), | 328 tracker()->OnViewBoundsChanged(view_id, old_bounds.Pass(), |
336 new_bounds.Pass()); | 329 new_bounds.Pass()); |
337 } | 330 } |
338 void OnViewViewportMetricsChanged(ViewportMetricsPtr old_metrics, | 331 void OnViewViewportMetricsChanged(ViewportMetricsPtr old_metrics, |
339 ViewportMetricsPtr new_metrics) override { | 332 ViewportMetricsPtr new_metrics) override { |
340 // Don't track the metrics as they are available at an indeterministic time | 333 // Don't track the metrics as they are available at an indeterministic time |
341 // on Android. | 334 // on Android. |
342 } | 335 } |
343 void OnViewHierarchyChanged(Id view, | 336 void OnViewHierarchyChanged(Id view, |
344 Id new_parent, | 337 Id new_parent, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 mojo::ApplicationImpl* app_; | 417 mojo::ApplicationImpl* app_; |
425 scoped_ptr<ViewTreeClientImpl> client_impl_; | 418 scoped_ptr<ViewTreeClientImpl> client_impl_; |
426 scoped_ptr<base::RunLoop> run_loop_; | 419 scoped_ptr<base::RunLoop> run_loop_; |
427 | 420 |
428 DISALLOW_COPY_AND_ASSIGN(ViewTreeClientFactory); | 421 DISALLOW_COPY_AND_ASSIGN(ViewTreeClientFactory); |
429 }; | 422 }; |
430 | 423 |
431 class ViewTreeAppTest : public mojo::test::ApplicationTestBase, | 424 class ViewTreeAppTest : public mojo::test::ApplicationTestBase, |
432 public ApplicationDelegate { | 425 public ApplicationDelegate { |
433 public: | 426 public: |
434 ViewTreeAppTest() | 427 ViewTreeAppTest() |
435 : connection_id_1_(0), connection_id_2_(0), root_view_id_(0) {} | 428 : connection_id_1_(0), connection_id_2_(0), root_view_id_(0) {} |
436 ~ViewTreeAppTest() override {} | 429 ~ViewTreeAppTest() override {} |
437 | 430 |
438 protected: | 431 protected: |
439 // Returns the changes from the various connections. | 432 // Returns the changes from the various connections. |
440 std::vector<Change>* changes1() { return vm_client1_->tracker()->changes(); } | 433 std::vector<Change>* changes1() { return vm_client1_->tracker()->changes(); } |
441 std::vector<Change>* changes2() { return vm_client2_->tracker()->changes(); } | 434 std::vector<Change>* changes2() { return vm_client2_->tracker()->changes(); } |
442 std::vector<Change>* changes3() { return vm_client3_->tracker()->changes(); } | 435 std::vector<Change>* changes3() { return vm_client3_->tracker()->changes(); } |
443 | 436 |
444 // Various connections. |vm1()|, being the first connection, has special | 437 // Various connections. |vm1()|, being the first connection, has special |
445 // permissions (it's treated as the window manager). | 438 // permissions (it's treated as the window manager). |
446 ViewTree* vm1() { return vm_client1_->tree(); } | 439 ViewTree* vm1() { return vm_client1_->tree(); } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 | 486 |
494 // Establishes a new connection by way of Embed() on the specified | 487 // Establishes a new connection by way of Embed() on the specified |
495 // ViewTree. | 488 // ViewTree. |
496 scoped_ptr<ViewTreeClientImpl> | 489 scoped_ptr<ViewTreeClientImpl> |
497 EstablishConnectionViaEmbed(ViewTree* owner, Id root_id, int* connection_id) { | 490 EstablishConnectionViaEmbed(ViewTree* owner, Id root_id, int* connection_id) { |
498 if (!EmbedUrl(application_impl(), owner, application_impl()->url(), | 491 if (!EmbedUrl(application_impl(), owner, application_impl()->url(), |
499 root_id)) { | 492 root_id)) { |
500 ADD_FAILURE() << "Embed() failed"; | 493 ADD_FAILURE() << "Embed() failed"; |
501 return nullptr; | 494 return nullptr; |
502 } | 495 } |
503 scoped_ptr<ViewTreeClientImpl> client = | 496 scoped_ptr<ViewTreeClientImpl> client = client_factory_->WaitForInstance(); |
504 client_factory_->WaitForInstance(); | |
505 if (!client.get()) { | 497 if (!client.get()) { |
506 ADD_FAILURE() << "WaitForInstance failed"; | 498 ADD_FAILURE() << "WaitForInstance failed"; |
507 return nullptr; | 499 return nullptr; |
508 } | 500 } |
509 client->WaitForOnEmbed(); | 501 client->WaitForOnEmbed(); |
510 | 502 |
511 EXPECT_EQ("OnEmbed", | 503 EXPECT_EQ("OnEmbed", |
512 SingleChangeToDescription(*client->tracker()->changes())); | 504 SingleChangeToDescription(*client->tracker()->changes())); |
513 if (connection_id) | 505 if (connection_id) |
514 *connection_id = (*client->tracker()->changes())[0].connection_id; | 506 *connection_id = (*client->tracker()->changes())[0].connection_id; |
515 return client.Pass(); | 507 return client.Pass(); |
516 } | 508 } |
517 | 509 |
518 // ApplicationTestBase: | 510 // ApplicationTestBase: |
519 ApplicationDelegate* GetApplicationDelegate() override { return this; } | 511 ApplicationDelegate* GetApplicationDelegate() override { return this; } |
520 void SetUp() override { | 512 void SetUp() override { |
521 ApplicationTestBase::SetUp(); | 513 ApplicationTestBase::SetUp(); |
522 client_factory_.reset(new ViewTreeClientFactory(application_impl())); | 514 client_factory_.reset(new ViewTreeClientFactory(application_impl())); |
523 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 515 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
524 request->url = mojo::String::From("mojo:view_manager"); | 516 request->url = mojo::String::From("mojo:view_manager"); |
525 | 517 |
526 mojo::ViewTreeHostFactoryPtr factory; | 518 mojo::ViewTreeHostFactoryPtr factory; |
527 application_impl()->ConnectToService(request.Pass(), &factory); | 519 application_impl()->ConnectToService(request.Pass(), &factory); |
528 | 520 |
529 mojo::ViewTreeClientPtr tree_client_ptr; | 521 mojo::ViewTreeClientPtr tree_client_ptr; |
530 vm_client1_.reset(new ViewTreeClientImpl(application_impl())); | 522 vm_client1_.reset(new ViewTreeClientImpl(application_impl())); |
531 vm_client1_->Bind(GetProxy(&tree_client_ptr)); | 523 vm_client1_->Bind(GetProxy(&tree_client_ptr)); |
532 | 524 |
533 factory->CreateViewTreeHost(GetProxy(&host_), | 525 factory->CreateViewTreeHost(GetProxy(&host_), mojo::ViewTreeHostClientPtr(), |
534 mojo::ViewTreeHostClientPtr(), | |
535 tree_client_ptr.Pass()); | 526 tree_client_ptr.Pass()); |
536 | 527 |
537 // Next we should get an embed call on the "window manager" client. | 528 // Next we should get an embed call on the "window manager" client. |
538 vm_client1_->WaitForIncomingMethodCall(); | 529 vm_client1_->WaitForIncomingMethodCall(); |
539 | 530 |
540 ASSERT_EQ(1u, changes1()->size()); | 531 ASSERT_EQ(1u, changes1()->size()); |
541 EXPECT_EQ(CHANGE_TYPE_EMBED, (*changes1())[0].type); | 532 EXPECT_EQ(CHANGE_TYPE_EMBED, (*changes1())[0].type); |
542 // All these tests assume 1 for the client id. The only real assertion here | 533 // All these tests assume 1 for the client id. The only real assertion here |
543 // is the client id is not zero, but adding this as rest of code here | 534 // is the client id is not zero, but adding this as rest of code here |
544 // assumes 1. | 535 // assumes 1. |
(...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1604 ASSERT_TRUE(view_2_2); | 1595 ASSERT_TRUE(view_2_2); |
1605 ASSERT_TRUE(AddView(vm2(), view_1_1, view_2_2)); | 1596 ASSERT_TRUE(AddView(vm2(), view_1_1, view_2_2)); |
1606 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm2(), view_2_2)); | 1597 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm2(), view_2_2)); |
1607 | 1598 |
1608 Id view_3_3 = vm_client3()->CreateView(3); | 1599 Id view_3_3 = vm_client3()->CreateView(3); |
1609 ASSERT_TRUE(view_3_3); | 1600 ASSERT_TRUE(view_3_3); |
1610 ASSERT_TRUE(AddView(vm3(), view_2_2, view_3_3)); | 1601 ASSERT_TRUE(AddView(vm3(), view_2_2, view_3_3)); |
1611 | 1602 |
1612 // 2 should not be able to embed in view_3_3 as view_3_3 was not created by | 1603 // 2 should not be able to embed in view_3_3 as view_3_3 was not created by |
1613 // 2. | 1604 // 2. |
1614 EXPECT_FALSE(EmbedUrl(application_impl(), vm2(), application_impl()->url(), | 1605 EXPECT_FALSE( |
1615 view_3_3)); | 1606 EmbedUrl(application_impl(), vm2(), application_impl()->url(), view_3_3)); |
1616 } | 1607 } |
1617 | 1608 |
1618 // Verifies Embed() from window manager on another connections view works. | 1609 // Verifies Embed() from window manager on another connections view works. |
1619 TEST_F(ViewTreeAppTest, EmbedFromOtherConnection) { | 1610 TEST_F(ViewTreeAppTest, EmbedFromOtherConnection) { |
1620 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1611 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
1621 | 1612 |
1622 Id view_1_1 = BuildViewId(connection_id_1(), 1); | 1613 Id view_1_1 = BuildViewId(connection_id_1(), 1); |
1623 Id view_2_2 = vm_client2()->CreateView(2); | 1614 Id view_2_2 = vm_client2()->CreateView(2); |
1624 ASSERT_TRUE(view_2_2); | 1615 ASSERT_TRUE(view_2_2); |
1625 ASSERT_TRUE(AddView(vm2(), view_1_1, view_2_2)); | 1616 ASSERT_TRUE(AddView(vm2(), view_1_1, view_2_2)); |
(...skipping 25 matching lines...) Expand all Loading... |
1651 WaitForViewTreeClient(); | 1642 WaitForViewTreeClient(); |
1652 | 1643 |
1653 Id view_1_2 = vm_client1()->CreateView(2); | 1644 Id view_1_2 = vm_client1()->CreateView(2); |
1654 ASSERT_TRUE(view_1_2); | 1645 ASSERT_TRUE(view_1_2); |
1655 ASSERT_TRUE(AddView(vm1(), BuildViewId(connection_id_1(), 1), view_1_2)); | 1646 ASSERT_TRUE(AddView(vm1(), BuildViewId(connection_id_1(), 1), view_1_2)); |
1656 vm1()->SetAccessPolicy(view_1_2, ViewTree::ACCESS_POLICY_EMBED_ROOT); | 1647 vm1()->SetAccessPolicy(view_1_2, ViewTree::ACCESS_POLICY_EMBED_ROOT); |
1657 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm1(), view_1_2)); | 1648 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm1(), view_1_2)); |
1658 | 1649 |
1659 // view_1_2 is vm3's root, so even though v3 is an embed root it should not | 1650 // view_1_2 is vm3's root, so even though v3 is an embed root it should not |
1660 // be able to Embed into itself. | 1651 // be able to Embed into itself. |
1661 ASSERT_FALSE(EmbedUrl(application_impl(), vm3(), application_impl()->url(), | 1652 ASSERT_FALSE( |
1662 view_1_2)); | 1653 EmbedUrl(application_impl(), vm3(), application_impl()->url(), view_1_2)); |
1663 } | 1654 } |
1664 | 1655 |
1665 // TODO(sky): need to better track changes to initial connection. For example, | 1656 // TODO(sky): need to better track changes to initial connection. For example, |
1666 // that SetBounsdViews/AddView and the like don't result in messages to the | 1657 // that SetBounsdViews/AddView and the like don't result in messages to the |
1667 // originating connection. | 1658 // originating connection. |
1668 | 1659 |
1669 // TODO(sky): make sure coverage of what was | 1660 // TODO(sky): make sure coverage of what was |
1670 // ViewManagerTest.SecondEmbedRoot_InitService and | 1661 // ViewManagerTest.SecondEmbedRoot_InitService and |
1671 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager | 1662 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager |
1672 // tests. | 1663 // tests. |
1673 | 1664 |
1674 } // namespace view_manager | 1665 } // namespace view_manager |
OLD | NEW |