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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 changes_.clear(); | 194 changes_.clear(); |
195 bool result = false; | 195 bool result = false; |
196 view_manager_->SetViewBounds( | 196 view_manager_->SetViewBounds( |
197 view_id, | 197 view_id, |
198 Rect::From(bounds), | 198 Rect::From(bounds), |
199 base::Bind( | 199 base::Bind( |
200 &ViewManagerProxy::GotResult, base::Unretained(this), &result)); | 200 &ViewManagerProxy::GotResult, base::Unretained(this), &result)); |
201 RunMainLoop(); | 201 RunMainLoop(); |
202 return result; | 202 return result; |
203 } | 203 } |
| 204 bool SetViewVisibility(Id view_id, bool visible) { |
| 205 changes_.clear(); |
| 206 bool result = false; |
| 207 view_manager_->SetViewVisibility( |
| 208 view_id, |
| 209 visible, |
| 210 base::Bind( |
| 211 &ViewManagerProxy::GotResult, base::Unretained(this), &result)); |
| 212 RunMainLoop(); |
| 213 return result; |
| 214 } |
204 | 215 |
205 private: | 216 private: |
206 friend class TestViewManagerClientConnection; | 217 friend class TestViewManagerClientConnection; |
207 | 218 |
208 void set_router(mojo::internal::Router* router) { router_ = router; } | 219 void set_router(mojo::internal::Router* router) { router_ = router; } |
209 | 220 |
210 void set_view_manager(ViewManagerService* view_manager) { | 221 void set_view_manager(ViewManagerService* view_manager) { |
211 view_manager_ = view_manager; | 222 view_manager_ = view_manager; |
212 } | 223 } |
213 | 224 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 Id old_parent, | 333 Id old_parent, |
323 Array<ViewDataPtr> views) OVERRIDE { | 334 Array<ViewDataPtr> views) OVERRIDE { |
324 tracker_.OnViewHierarchyChanged(view, new_parent, old_parent, views.Pass()); | 335 tracker_.OnViewHierarchyChanged(view, new_parent, old_parent, views.Pass()); |
325 } | 336 } |
326 virtual void OnViewReordered(Id view_id, | 337 virtual void OnViewReordered(Id view_id, |
327 Id relative_view_id, | 338 Id relative_view_id, |
328 OrderDirection direction) OVERRIDE { | 339 OrderDirection direction) OVERRIDE { |
329 tracker_.OnViewReordered(view_id, relative_view_id, direction); | 340 tracker_.OnViewReordered(view_id, relative_view_id, direction); |
330 } | 341 } |
331 virtual void OnViewDeleted(Id view) OVERRIDE { tracker_.OnViewDeleted(view); } | 342 virtual void OnViewDeleted(Id view) OVERRIDE { tracker_.OnViewDeleted(view); } |
| 343 virtual void OnViewVisibilityChanged(uint32_t view, bool visible) OVERRIDE { |
| 344 tracker_.OnViewVisibilityChanged(view, visible); |
| 345 } |
| 346 virtual void OnViewDrawnStateChanged(uint32_t view, bool drawn) OVERRIDE { |
| 347 tracker_.OnViewDrawnStateChanged(view, drawn); |
| 348 } |
332 virtual void OnViewInputEvent(Id view_id, | 349 virtual void OnViewInputEvent(Id view_id, |
333 EventPtr event, | 350 EventPtr event, |
334 const Callback<void()>& callback) OVERRIDE { | 351 const Callback<void()>& callback) OVERRIDE { |
335 tracker_.OnViewInputEvent(view_id, event.Pass()); | 352 tracker_.OnViewInputEvent(view_id, event.Pass()); |
336 } | 353 } |
337 virtual void Embed( | 354 virtual void Embed( |
338 const String& url, | 355 const String& url, |
339 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE { | 356 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE { |
340 tracker_.DelegateEmbed(url); | 357 tracker_.DelegateEmbed(url); |
341 } | 358 } |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 // Creates a second connection to the viewmanager. | 489 // Creates a second connection to the viewmanager. |
473 void EstablishSecondConnection(bool create_initial_view) { | 490 void EstablishSecondConnection(bool create_initial_view) { |
474 if (create_initial_view) | 491 if (create_initial_view) |
475 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); | 492 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); |
476 ASSERT_NO_FATAL_FAILURE( | 493 ASSERT_NO_FATAL_FAILURE( |
477 EstablishSecondConnectionWithRoot(BuildViewId(1, 1))); | 494 EstablishSecondConnectionWithRoot(BuildViewId(1, 1))); |
478 const std::vector<Change>& changes(connection2_->changes()); | 495 const std::vector<Change>& changes(connection2_->changes()); |
479 ASSERT_EQ(1u, changes.size()); | 496 ASSERT_EQ(1u, changes.size()); |
480 EXPECT_EQ("OnEmbed creator=mojo:test_url", | 497 EXPECT_EQ("OnEmbed creator=mojo:test_url", |
481 ChangesToDescription1(changes)[0]); | 498 ChangesToDescription1(changes)[0]); |
482 if (create_initial_view) { | 499 if (create_initial_view) |
483 EXPECT_EQ("[view=1,1 parent=null]", ChangeViewDescription(changes)); | 500 EXPECT_EQ("[view=1,1 parent=null]", ChangeViewDescription(changes)); |
484 } | |
485 } | 501 } |
486 | 502 |
487 void EstablishThirdConnection(ViewManagerProxy* owner, Id root_id) { | 503 void EstablishThirdConnection(ViewManagerProxy* owner, Id root_id) { |
488 ASSERT_TRUE(connection3_ == NULL); | 504 ASSERT_TRUE(connection3_ == NULL); |
489 ASSERT_TRUE(owner->Embed(root_id, kTestServiceURL2)); | 505 ASSERT_TRUE(owner->Embed(root_id, kTestServiceURL2)); |
490 connection3_ = ViewManagerProxy::WaitForInstance(); | 506 connection3_ = ViewManagerProxy::WaitForInstance(); |
491 ASSERT_TRUE(connection3_ != NULL); | 507 ASSERT_TRUE(connection3_ != NULL); |
492 connection3_->DoRunLoopUntilChangesCount(1); | 508 connection3_->DoRunLoopUntilChangesCount(1); |
493 ASSERT_EQ(1u, connection3_->changes().size()); | 509 ASSERT_EQ(1u, connection3_->changes().size()); |
494 EXPECT_EQ("OnEmbed creator=mojo:test_url", | 510 EXPECT_EQ("OnEmbed creator=mojo:test_url", |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 // Client 2 should not get anything (1,2 is from another connection). | 789 // Client 2 should not get anything (1,2 is from another connection). |
774 connection2_->ClearChanges(); | 790 connection2_->ClearChanges(); |
775 ASSERT_TRUE(connection_->AddView(BuildViewId(1, 1), BuildViewId(1, 2))); | 791 ASSERT_TRUE(connection_->AddView(BuildViewId(1, 1), BuildViewId(1, 2))); |
776 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 100))); | 792 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 100))); |
777 connection2_->CopyChangesFromTracker(); | 793 connection2_->CopyChangesFromTracker(); |
778 EXPECT_TRUE(connection2_->changes().empty()); | 794 EXPECT_TRUE(connection2_->changes().empty()); |
779 } | 795 } |
780 | 796 |
781 // 0,1->1,1->1,2->1,11. | 797 // 0,1->1,1->1,2->1,11. |
782 { | 798 { |
783 // Again, client 2 should not get anything. | 799 // Client 2 is now connected to the root, so it should have gotten a drawn |
784 connection2_->ClearChanges(); | 800 // notification. |
785 ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1))); | 801 ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1))); |
786 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 101))); | 802 connection2_->DoRunLoopUntilChangesCount(1); |
787 connection2_->CopyChangesFromTracker(); | 803 ASSERT_EQ(1u, connection2_->changes().size()); |
788 EXPECT_TRUE(connection2_->changes().empty()); | 804 EXPECT_EQ("DrawnStateChanged view=1,1 drawn=true", |
| 805 ChangesToDescription1(connection2_->changes())[0]); |
789 } | 806 } |
790 | 807 |
791 // 1,1->1,2->1,11. | 808 // 1,1->1,2->1,11. |
792 { | 809 { |
793 connection2_->ClearChanges(); | 810 // Client 2 is no longer connected to the root, should get drawn state |
| 811 // changed. |
794 ASSERT_TRUE(connection_->RemoveViewFromParent(BuildViewId(1, 1))); | 812 ASSERT_TRUE(connection_->RemoveViewFromParent(BuildViewId(1, 1))); |
795 EXPECT_TRUE(connection_->changes().empty()); | 813 connection2_->DoRunLoopUntilChangesCount(1); |
796 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 102))); | 814 ASSERT_EQ(1u, connection2_->changes().size()); |
797 connection2_->CopyChangesFromTracker(); | 815 EXPECT_EQ("DrawnStateChanged view=1,1 drawn=false", |
798 EXPECT_TRUE(connection2_->changes().empty()); | 816 ChangesToDescription1(connection2_->changes())[0]); |
799 } | 817 } |
800 | 818 |
801 // 1,1->1,2->1,11->1,111. | 819 // 1,1->1,2->1,11->1,111. |
802 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 111))); | 820 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 111))); |
803 { | 821 { |
804 connection2_->ClearChanges(); | 822 connection2_->ClearChanges(); |
805 ASSERT_TRUE(connection_->AddView(BuildViewId(1, 11), BuildViewId(1, 111))); | 823 ASSERT_TRUE(connection_->AddView(BuildViewId(1, 11), BuildViewId(1, 111))); |
806 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 103))); | 824 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 103))); |
807 connection2_->CopyChangesFromTracker(); | 825 connection2_->CopyChangesFromTracker(); |
808 EXPECT_TRUE(connection2_->changes().empty()); | 826 EXPECT_TRUE(connection2_->changes().empty()); |
809 } | 827 } |
810 | 828 |
811 // 0,1->1,1->1,2->1,11->1,111 | 829 // 0,1->1,1->1,2->1,11->1,111 |
812 { | 830 { |
813 connection2_->ClearChanges(); | 831 connection2_->ClearChanges(); |
814 ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1))); | 832 ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1))); |
815 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 104))); | 833 connection2_->DoRunLoopUntilChangesCount(1); |
816 connection2_->CopyChangesFromTracker(); | 834 ASSERT_EQ(1u, connection2_->changes().size()); |
817 EXPECT_TRUE(connection2_->changes().empty()); | 835 EXPECT_EQ("DrawnStateChanged view=1,1 drawn=true", |
| 836 ChangesToDescription1(connection2_->changes())[0]); |
818 } | 837 } |
819 } | 838 } |
820 | 839 |
821 TEST_F(ViewManagerTest, ViewHierarchyChangedAddingKnownToUnknown) { | 840 TEST_F(ViewManagerTest, ViewHierarchyChangedAddingKnownToUnknown) { |
822 // Create the following structure: root -> 1 -> 11 and 2->21 (2 has no | 841 // Create the following structure: root -> 1 -> 11 and 2->21 (2 has no |
823 // parent). | 842 // parent). |
824 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 843 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
825 | 844 |
826 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 11))); | 845 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 11))); |
827 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 2))); | 846 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 2))); |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1271 | 1290 |
1272 // Verify connection3_ can still see the view it created 3,1. | 1291 // Verify connection3_ can still see the view it created 3,1. |
1273 { | 1292 { |
1274 std::vector<TestView> views; | 1293 std::vector<TestView> views; |
1275 connection3_->GetViewTree(BuildViewId(3, 1), &views); | 1294 connection3_->GetViewTree(BuildViewId(3, 1), &views); |
1276 ASSERT_EQ(1u, views.size()); | 1295 ASSERT_EQ(1u, views.size()); |
1277 EXPECT_EQ("view=3,1 parent=null", views[0].ToString()); | 1296 EXPECT_EQ("view=3,1 parent=null", views[0].ToString()); |
1278 } | 1297 } |
1279 } | 1298 } |
1280 | 1299 |
| 1300 // Assertions for SetViewVisibility. |
| 1301 TEST_F(ViewManagerTest, SetViewVisibility) { |
| 1302 // Create 1 and 2 in the first connection and parent both to the root. |
| 1303 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); |
| 1304 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 2))); |
| 1305 |
| 1306 ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1))); |
| 1307 { |
| 1308 std::vector<TestView> views; |
| 1309 connection_->GetViewTree(BuildViewId(0, 1), &views); |
| 1310 ASSERT_EQ(2u, views.size()); |
| 1311 EXPECT_EQ("view=0,1 parent=null visible=true drawn=true", |
| 1312 views[0].ToString2()); |
| 1313 EXPECT_EQ("view=1,1 parent=0,1 visible=true drawn=true", |
| 1314 views[1].ToString2()); |
| 1315 } |
| 1316 |
| 1317 // Hide 1. |
| 1318 ASSERT_TRUE(connection_->SetViewVisibility(BuildViewId(1, 1), false)); |
| 1319 { |
| 1320 std::vector<TestView> views; |
| 1321 connection_->GetViewTree(BuildViewId(1, 1), &views); |
| 1322 ASSERT_EQ(1u, views.size()); |
| 1323 EXPECT_EQ("view=1,1 parent=0,1 visible=false drawn=false", |
| 1324 views[0].ToString2()); |
| 1325 } |
| 1326 |
| 1327 // Attach 2 to 1. |
| 1328 ASSERT_TRUE(connection_->AddView(BuildViewId(1, 1), BuildViewId(1, 2))); |
| 1329 { |
| 1330 std::vector<TestView> views; |
| 1331 connection_->GetViewTree(BuildViewId(1, 1), &views); |
| 1332 ASSERT_EQ(2u, views.size()); |
| 1333 EXPECT_EQ("view=1,1 parent=0,1 visible=false drawn=false", |
| 1334 views[0].ToString2()); |
| 1335 EXPECT_EQ("view=1,2 parent=1,1 visible=true drawn=false", |
| 1336 views[1].ToString2()); |
| 1337 } |
| 1338 |
| 1339 // Show 1. |
| 1340 ASSERT_TRUE(connection_->SetViewVisibility(BuildViewId(1, 1), true)); |
| 1341 { |
| 1342 std::vector<TestView> views; |
| 1343 connection_->GetViewTree(BuildViewId(1, 1), &views); |
| 1344 ASSERT_EQ(2u, views.size()); |
| 1345 EXPECT_EQ("view=1,1 parent=0,1 visible=true drawn=true", |
| 1346 views[0].ToString2()); |
| 1347 EXPECT_EQ("view=1,2 parent=1,1 visible=true drawn=true", |
| 1348 views[1].ToString2()); |
| 1349 } |
| 1350 } |
| 1351 |
| 1352 // Assertions for SetViewVisibility sending notifications. |
| 1353 TEST_F(ViewManagerTest, SetViewVisibilityNotifications) { |
| 1354 // Create 1,1 and 1,2, 1,2 and child of 1,1 and 1,1 a child of the root. |
| 1355 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); |
| 1356 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 2))); |
| 1357 ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1))); |
| 1358 ASSERT_TRUE(connection_->AddView(BuildViewId(1, 1), BuildViewId(1, 2))); |
| 1359 |
| 1360 // Establish the second connection at 1,2. |
| 1361 ASSERT_NO_FATAL_FAILURE( |
| 1362 EstablishSecondConnectionWithRoot(BuildViewId(1, 2))); |
| 1363 |
| 1364 // Add 2,3 as a child of 1,2. |
| 1365 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 3))); |
| 1366 connection_->ClearChanges(); |
| 1367 ASSERT_TRUE(connection2_->AddView(BuildViewId(1, 2), BuildViewId(2, 3))); |
| 1368 connection_->DoRunLoopUntilChangesCount(1); |
| 1369 |
| 1370 // Hide 1,2 from connection 1. Connection 2 should see this. |
| 1371 ASSERT_TRUE(connection_->SetViewVisibility(BuildViewId(1, 2), false)); |
| 1372 { |
| 1373 connection2_->DoRunLoopUntilChangesCount(1); |
| 1374 ASSERT_EQ(1u, connection2_->changes().size()); |
| 1375 EXPECT_EQ("VisibilityChanged view=1,2 visible=false", |
| 1376 ChangesToDescription1(connection2_->changes())[0]); |
| 1377 } |
| 1378 |
| 1379 // Show 1,2 from connection 2, connection 1 should be notified. |
| 1380 ASSERT_TRUE(connection2_->SetViewVisibility(BuildViewId(1, 2), true)); |
| 1381 { |
| 1382 connection_->DoRunLoopUntilChangesCount(1); |
| 1383 ASSERT_EQ(1u, connection_->changes().size()); |
| 1384 EXPECT_EQ("VisibilityChanged view=1,2 visible=true", |
| 1385 ChangesToDescription1(connection_->changes())[0]); |
| 1386 } |
| 1387 |
| 1388 // Hide 1,1, connection 2 should be told the draw state changed. |
| 1389 ASSERT_TRUE(connection_->SetViewVisibility(BuildViewId(1, 1), false)); |
| 1390 { |
| 1391 connection2_->DoRunLoopUntilChangesCount(1); |
| 1392 ASSERT_EQ(1u, connection2_->changes().size()); |
| 1393 EXPECT_EQ("DrawnStateChanged view=1,2 drawn=false", |
| 1394 ChangesToDescription1(connection2_->changes())[0]); |
| 1395 } |
| 1396 |
| 1397 // Show 1,1 from connection 1. Connection 2 should see this. |
| 1398 ASSERT_TRUE(connection_->SetViewVisibility(BuildViewId(1, 1), true)); |
| 1399 { |
| 1400 connection2_->DoRunLoopUntilChangesCount(1); |
| 1401 ASSERT_EQ(1u, connection2_->changes().size()); |
| 1402 EXPECT_EQ("DrawnStateChanged view=1,2 drawn=true", |
| 1403 ChangesToDescription1(connection2_->changes())[0]); |
| 1404 } |
| 1405 |
| 1406 // Change visibility of 2,3, connection 1 should see this. |
| 1407 connection_->ClearChanges(); |
| 1408 ASSERT_TRUE(connection2_->SetViewVisibility(BuildViewId(2, 3), false)); |
| 1409 { |
| 1410 connection_->DoRunLoopUntilChangesCount(1); |
| 1411 ASSERT_EQ(1u, connection_->changes().size()); |
| 1412 EXPECT_EQ("VisibilityChanged view=2,3 visible=false", |
| 1413 ChangesToDescription1(connection_->changes())[0]); |
| 1414 } |
| 1415 |
| 1416 // Remove 1,1 from the root, connection 2 should see drawn state changed. |
| 1417 ASSERT_TRUE(connection_->RemoveViewFromParent(BuildViewId(1, 1))); |
| 1418 { |
| 1419 connection2_->DoRunLoopUntilChangesCount(1); |
| 1420 ASSERT_EQ(1u, connection2_->changes().size()); |
| 1421 EXPECT_EQ("DrawnStateChanged view=1,2 drawn=false", |
| 1422 ChangesToDescription1(connection2_->changes())[0]); |
| 1423 } |
| 1424 |
| 1425 // Add 1,1 back to the root, connection 2 should see drawn state changed. |
| 1426 ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1))); |
| 1427 { |
| 1428 connection2_->DoRunLoopUntilChangesCount(1); |
| 1429 ASSERT_EQ(1u, connection2_->changes().size()); |
| 1430 EXPECT_EQ("DrawnStateChanged view=1,2 drawn=true", |
| 1431 ChangesToDescription1(connection2_->changes())[0]); |
| 1432 } |
| 1433 } |
| 1434 |
1281 // TODO(sky): add coverage of test that destroys connections and ensures other | 1435 // TODO(sky): add coverage of test that destroys connections and ensures other |
1282 // connections get deletion notification. | 1436 // connections get deletion notification. |
1283 | 1437 |
1284 // TODO(sky): need to better track changes to initial connection. For example, | 1438 // TODO(sky): need to better track changes to initial connection. For example, |
1285 // that SetBounsdViews/AddView and the like don't result in messages to the | 1439 // that SetBounsdViews/AddView and the like don't result in messages to the |
1286 // originating connection. | 1440 // originating connection. |
1287 | 1441 |
1288 } // namespace service | 1442 } // namespace service |
1289 } // namespace mojo | 1443 } // namespace mojo |
OLD | NEW |