Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: mojo/services/view_manager/view_manager_unittest.cc

Issue 415793003: Changes access policy for embedded nodes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/services/view_manager/view_manager_service_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 run_loop.Run(); 442 run_loop.Run();
443 return result; 443 return result;
444 } 444 }
445 445
446 } // namespace 446 } // namespace
447 447
448 typedef std::vector<std::string> Changes; 448 typedef std::vector<std::string> Changes;
449 449
450 class ViewManagerTest : public testing::Test { 450 class ViewManagerTest : public testing::Test {
451 public: 451 public:
452 ViewManagerTest() : connection_(NULL), connection2_(NULL) {} 452 ViewManagerTest()
453 : connection_(NULL),
454 connection2_(NULL),
455 connection3_(NULL) {}
453 456
454 virtual void SetUp() OVERRIDE { 457 virtual void SetUp() OVERRIDE {
455 test_helper_.Init(); 458 test_helper_.Init();
456 459
457 test_helper_.SetLoaderForURL( 460 test_helper_.SetLoaderForURL(
458 scoped_ptr<ServiceLoader>(new EmbedServiceLoader()), 461 scoped_ptr<ServiceLoader>(new EmbedServiceLoader()),
459 GURL(kTestServiceURL)); 462 GURL(kTestServiceURL));
460 463
461 test_helper_.SetLoaderForURL( 464 test_helper_.SetLoaderForURL(
462 scoped_ptr<ServiceLoader>(new EmbedServiceLoader()), 465 scoped_ptr<ServiceLoader>(new EmbedServiceLoader()),
463 GURL(kTestServiceURL2)); 466 GURL(kTestServiceURL2));
464 467
465 test_helper_.service_manager()->ConnectToService( 468 test_helper_.service_manager()->ConnectToService(
466 GURL("mojo:mojo_view_manager"), 469 GURL("mojo:mojo_view_manager"),
467 &view_manager_init_); 470 &view_manager_init_);
468 ASSERT_TRUE(InitEmbed(view_manager_init_.get(), kTestServiceURL, 1)); 471 ASSERT_TRUE(InitEmbed(view_manager_init_.get(), kTestServiceURL, 1));
469 472
470 connection_ = ViewManagerProxy::WaitForInstance(); 473 connection_ = ViewManagerProxy::WaitForInstance();
471 ASSERT_TRUE(connection_ != NULL); 474 ASSERT_TRUE(connection_ != NULL);
472 connection_->DoRunLoopUntilChangesCount(1); 475 connection_->DoRunLoopUntilChangesCount(1);
473 } 476 }
474 477
475 virtual void TearDown() OVERRIDE { 478 virtual void TearDown() OVERRIDE {
479 if (connection3_)
480 connection3_->Destroy();
476 if (connection2_) 481 if (connection2_)
477 connection2_->Destroy(); 482 connection2_->Destroy();
478 if (connection_) 483 if (connection_)
479 connection_->Destroy(); 484 connection_->Destroy();
480 } 485 }
481 486
482 protected: 487 protected:
483 void EstablishSecondConnectionWithRoot(Id root_id) { 488 void EstablishSecondConnectionWithRoot(Id root_id) {
484 ASSERT_TRUE(connection_->Embed(root_id, kTestServiceURL)); 489 ASSERT_TRUE(connection_->Embed(root_id, kTestServiceURL));
485 connection2_ = ViewManagerProxy::WaitForInstance(); 490 connection2_ = ViewManagerProxy::WaitForInstance();
(...skipping 11 matching lines...) Expand all
497 const std::vector<Change>& changes(connection2_->changes()); 502 const std::vector<Change>& changes(connection2_->changes());
498 ASSERT_EQ(1u, changes.size()); 503 ASSERT_EQ(1u, changes.size());
499 EXPECT_EQ("OnConnectionEstablished creator=mojo:test_url", 504 EXPECT_EQ("OnConnectionEstablished creator=mojo:test_url",
500 ChangesToDescription1(changes)[0]); 505 ChangesToDescription1(changes)[0]);
501 if (create_initial_node) { 506 if (create_initial_node) {
502 EXPECT_EQ("[node=1,1 parent=null view=null]", 507 EXPECT_EQ("[node=1,1 parent=null view=null]",
503 ChangeNodeDescription(changes)); 508 ChangeNodeDescription(changes));
504 } 509 }
505 } 510 }
506 511
512 void EstablishThirdConnection(ViewManagerProxy* owner, Id root_id) {
513 ASSERT_TRUE(connection3_ == NULL);
514 ASSERT_TRUE(owner->Embed(root_id, kTestServiceURL2));
515 connection3_ = ViewManagerProxy::WaitForInstance();
516 ASSERT_TRUE(connection3_ != NULL);
517 connection3_->DoRunLoopUntilChangesCount(1);
518 ASSERT_EQ(1u, connection3_->changes().size());
519 EXPECT_EQ("OnConnectionEstablished creator=mojo:test_url",
520 ChangesToDescription1(connection3_->changes())[0]);
521 }
522
507 void DestroySecondConnection() { 523 void DestroySecondConnection() {
508 connection2_->Destroy(); 524 connection2_->Destroy();
509 connection2_ = NULL; 525 connection2_ = NULL;
510 } 526 }
511 527
512 base::ShadowingAtExitManager at_exit_; 528 base::ShadowingAtExitManager at_exit_;
513 base::MessageLoop loop_; 529 base::MessageLoop loop_;
514 shell::ShellTestHelper test_helper_; 530 shell::ShellTestHelper test_helper_;
515 531
516 ViewManagerInitServicePtr view_manager_init_; 532 ViewManagerInitServicePtr view_manager_init_;
517 533
534 // NOTE: this connection is the root. As such, it has special permissions.
518 ViewManagerProxy* connection_; 535 ViewManagerProxy* connection_;
519 ViewManagerProxy* connection2_; 536 ViewManagerProxy* connection2_;
537 ViewManagerProxy* connection3_;
520 538
521 DISALLOW_COPY_AND_ASSIGN(ViewManagerTest); 539 DISALLOW_COPY_AND_ASSIGN(ViewManagerTest);
522 }; 540 };
523 541
524 TEST_F(ViewManagerTest, SecondEmbedRoot_InitService) { 542 TEST_F(ViewManagerTest, SecondEmbedRoot_InitService) {
525 ASSERT_TRUE(InitEmbed(view_manager_init_.get(), kTestServiceURL, 1)); 543 ASSERT_TRUE(InitEmbed(view_manager_init_.get(), kTestServiceURL, 1));
526 connection_->DoRunLoopUntilChangesCount(1); 544 connection_->DoRunLoopUntilChangesCount(1);
527 EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url); 545 EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url);
528 } 546 }
529 547
(...skipping 27 matching lines...) Expand all
557 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 575 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
558 EXPECT_EQ("OnConnectionEstablished creator=mojo:test_url", 576 EXPECT_EQ("OnConnectionEstablished creator=mojo:test_url",
559 ChangesToDescription1(connection2_->changes())[0]); 577 ChangesToDescription1(connection2_->changes())[0]);
560 578
561 // It isn't strictly necessary that the second connection gets 2, but these 579 // It isn't strictly necessary that the second connection gets 2, but these
562 // tests are written assuming that is the case. The key thing is the 580 // tests are written assuming that is the case. The key thing is the
563 // connection ids of |connection_| and |connection2_| differ. 581 // connection ids of |connection_| and |connection2_| differ.
564 EXPECT_EQ(2, connection2_->changes()[0].connection_id); 582 EXPECT_EQ(2, connection2_->changes()[0].connection_id);
565 } 583 }
566 584
585 // Verifies when Embed() is invoked any child nodes are removed.
586 TEST_F(ViewManagerTest, NodesRemovedWhenEmbedding) {
587 // Two nodes 1 and 2. 2 is parented to 1.
588 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1)));
589 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2)));
590 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2)));
591
592 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false));
593
594 // Because |connection_| is the root, the embed call doesn't remove.
595 {
596 std::vector<TestNode> nodes;
597 connection_->GetNodeTree(BuildNodeId(1, 2), &nodes);
598 ASSERT_EQ(1u, nodes.size());
599 EXPECT_EQ("node=1,2 parent=1,1 view=null", nodes[0].ToString());
600 }
601
602 // But |connection2_| should not see node 2.
603 {
604 std::vector<TestNode> nodes;
605 connection2_->GetNodeTree(BuildNodeId(1, 1), &nodes);
606 ASSERT_EQ(1u, nodes.size());
607 EXPECT_EQ("node=1,1 parent=null view=null", nodes[0].ToString());
608 }
609 {
610 std::vector<TestNode> nodes;
611 connection2_->GetNodeTree(BuildNodeId(1, 2), &nodes);
612 EXPECT_TRUE(nodes.empty());
613 }
614
615 // Nodes 3 and 4 in connection 2.
616 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 3)));
617 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 4)));
618 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(2, 3), BuildNodeId(2, 4)));
619
620 // Connection 3 rooted at 2.
621 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(connection2_,
622 BuildNodeId(2, 3)));
623
624 // Node 4 should no longer have a parent.
625 {
626 std::vector<TestNode> nodes;
627 connection2_->GetNodeTree(BuildNodeId(2, 3), &nodes);
628 ASSERT_EQ(1u, nodes.size());
629 EXPECT_EQ("node=2,3 parent=null view=null", nodes[0].ToString());
630
631 nodes.clear();
632 connection2_->GetNodeTree(BuildNodeId(2, 4), &nodes);
633 ASSERT_EQ(1u, nodes.size());
634 EXPECT_EQ("node=2,4 parent=null view=null", nodes[0].ToString());
635 }
636
637 // And node 4 should not be visible to connection 3.
638 {
639 std::vector<TestNode> nodes;
640 connection3_->GetNodeTree(BuildNodeId(2, 3), &nodes);
641 ASSERT_EQ(1u, nodes.size());
642 EXPECT_EQ("node=2,3 parent=null view=null", nodes[0].ToString());
643 }
644 }
645
646 // Verifies once Embed() has been invoked the parent connection can't see any
647 // children.
648 TEST_F(ViewManagerTest, CantAccessChildrenOfEmbeddedNode) {
649 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
650
651 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2)));
652 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 2)));
653
654 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(connection2_,
655 BuildNodeId(2, 2)));
656
657 ASSERT_TRUE(connection3_->CreateNode(BuildNodeId(3, 3)));
658 ASSERT_TRUE(connection3_->AddNode(BuildNodeId(2, 2), BuildNodeId(3, 3)));
659
660 // Even though 3 is a child of 2 connection 2 can't see 3 as it's from a
661 // different connection.
662 {
663 std::vector<TestNode> nodes;
664 connection2_->GetNodeTree(BuildNodeId(2, 2), &nodes);
665 ASSERT_EQ(1u, nodes.size());
666 EXPECT_EQ("node=2,2 parent=1,1 view=null", nodes[0].ToString());
667 }
668
669 {
670 std::vector<TestNode> nodes;
671 connection2_->GetNodeTree(BuildNodeId(3, 3), &nodes);
672 EXPECT_TRUE(nodes.empty());
673 }
674
675 // Connection 2 shouldn't be able to get node 3 at all.
676 {
677 std::vector<TestNode> nodes;
678 connection2_->GetNodeTree(BuildNodeId(3, 3), &nodes);
679 EXPECT_TRUE(nodes.empty());
680 }
681
682 // Connection 1 should be able to see it all (its the root).
683 {
684 std::vector<TestNode> nodes;
685 connection_->GetNodeTree(BuildNodeId(1, 1), &nodes);
686 ASSERT_EQ(3u, nodes.size());
687 EXPECT_EQ("node=1,1 parent=null view=null", nodes[0].ToString());
688 EXPECT_EQ("node=2,2 parent=1,1 view=null", nodes[1].ToString());
689 EXPECT_EQ("node=3,3 parent=2,2 view=null", nodes[2].ToString());
690 }
691 }
692
693 // Verifies once Embed() has been invoked the parent can't mutate the children.
694 TEST_F(ViewManagerTest, CantModifyChildrenOfEmbeddedNode) {
695 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
696
697 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2)));
698 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 2)));
699
700 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(connection2_,
701 BuildNodeId(2, 2)));
702
703 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 3)));
704 // Connection 2 shouldn't be able to add anything to the node anymore.
705 ASSERT_FALSE(connection2_->AddNode(BuildNodeId(2, 2), BuildNodeId(2, 3)));
706
707 // Create node 3 in connection 3 and add it to node 3.
708 ASSERT_TRUE(connection3_->CreateNode(BuildNodeId(3, 3)));
709 ASSERT_TRUE(connection3_->AddNode(BuildNodeId(2, 2), BuildNodeId(3, 3)));
710
711 // Connection 2 shouldn't be able to remove node 3.
712 ASSERT_FALSE(connection2_->RemoveNodeFromParent(BuildNodeId(3, 3)));
713 }
714
567 // Verifies client gets a valid id. 715 // Verifies client gets a valid id.
568 TEST_F(ViewManagerTest, CreateNode) { 716 TEST_F(ViewManagerTest, CreateNode) {
569 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); 717 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1)));
570 EXPECT_TRUE(connection_->changes().empty()); 718 EXPECT_TRUE(connection_->changes().empty());
571 719
572 // Can't create a node with the same id. 720 // Can't create a node with the same id.
573 ASSERT_EQ(ERROR_CODE_VALUE_IN_USE, 721 ASSERT_EQ(ERROR_CODE_VALUE_IN_USE,
574 connection_->CreateNodeWithErrorCode(BuildNodeId(1, 1))); 722 connection_->CreateNodeWithErrorCode(BuildNodeId(1, 1)));
575 EXPECT_TRUE(connection_->changes().empty()); 723 EXPECT_TRUE(connection_->changes().empty());
576 724
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 // Create two nodes in second connection, 2 and 3, both children of 1. 1176 // Create two nodes in second connection, 2 and 3, both children of 1.
1029 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2))); 1177 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2)));
1030 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 3))); 1178 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 3)));
1031 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 2))); 1179 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 2)));
1032 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 3))); 1180 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 3)));
1033 1181
1034 // Attach view to node 11 in the first connection. 1182 // Attach view to node 11 in the first connection.
1035 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 51))); 1183 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 51)));
1036 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 11), BuildViewId(1, 51))); 1184 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 11), BuildViewId(1, 51)));
1037 1185
1038 // Verifies GetNodeTree() on the root. 1186 // Verifies GetNodeTree() on the root. The root connection sees all.
1039 { 1187 {
1040 std::vector<TestNode> nodes; 1188 std::vector<TestNode> nodes;
1041 connection_->GetNodeTree(BuildNodeId(0, 1), &nodes); 1189 connection_->GetNodeTree(BuildNodeId(0, 1), &nodes);
1042 ASSERT_EQ(5u, nodes.size()); 1190 ASSERT_EQ(5u, nodes.size());
1043 EXPECT_EQ("node=0,1 parent=null view=null", nodes[0].ToString()); 1191 EXPECT_EQ("node=0,1 parent=null view=null", nodes[0].ToString());
1044 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[1].ToString()); 1192 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[1].ToString());
1045 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[2].ToString()); 1193 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[2].ToString());
1046 EXPECT_EQ("node=2,2 parent=1,1 view=null", nodes[3].ToString()); 1194 EXPECT_EQ("node=2,2 parent=1,1 view=null", nodes[3].ToString());
1047 EXPECT_EQ("node=2,3 parent=1,1 view=null", nodes[4].ToString()); 1195 EXPECT_EQ("node=2,3 parent=1,1 view=null", nodes[4].ToString());
1048 } 1196 }
1049 1197
1050 // Verifies GetNodeTree() on the node 1,1. 1198 // Verifies GetNodeTree() on the node 1,1. This does not include 1,11 as it's
1199 // from a different connection.
1051 { 1200 {
1052 std::vector<TestNode> nodes; 1201 std::vector<TestNode> nodes;
1053 connection2_->GetNodeTree(BuildNodeId(1, 1), &nodes); 1202 connection2_->GetNodeTree(BuildNodeId(1, 1), &nodes);
1054 ASSERT_EQ(4u, nodes.size()); 1203 ASSERT_EQ(3u, nodes.size());
1055 EXPECT_EQ("node=1,1 parent=null view=null", nodes[0].ToString()); 1204 EXPECT_EQ("node=1,1 parent=null view=null", nodes[0].ToString());
1056 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[1].ToString()); 1205 EXPECT_EQ("node=2,2 parent=1,1 view=null", nodes[1].ToString());
1057 EXPECT_EQ("node=2,2 parent=1,1 view=null", nodes[2].ToString()); 1206 EXPECT_EQ("node=2,3 parent=1,1 view=null", nodes[2].ToString());
1058 EXPECT_EQ("node=2,3 parent=1,1 view=null", nodes[3].ToString());
1059 } 1207 }
1060 1208
1061 // Connection 2 shouldn't be able to get the root tree. 1209 // Connection 2 shouldn't be able to get the root tree.
1062 { 1210 {
1063 std::vector<TestNode> nodes; 1211 std::vector<TestNode> nodes;
1064 connection2_->GetNodeTree(BuildNodeId(0, 1), &nodes); 1212 connection2_->GetNodeTree(BuildNodeId(0, 1), &nodes);
1065 ASSERT_EQ(0u, nodes.size()); 1213 ASSERT_EQ(0u, nodes.size());
1066 } 1214 }
1067 } 1215 }
1068 1216
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 connection2_->DoRunLoopUntilChangesCount(1); 1434 connection2_->DoRunLoopUntilChangesCount(1);
1287 const Changes changes(ChangesToDescription1(connection2_->changes())); 1435 const Changes changes(ChangesToDescription1(connection2_->changes()));
1288 ASSERT_EQ(1u, changes.size()); 1436 ASSERT_EQ(1u, changes.size());
1289 EXPECT_EQ("InputEvent view=2,11 event_action=1", changes[0]); 1437 EXPECT_EQ("InputEvent view=2,11 event_action=1", changes[0]);
1290 } 1438 }
1291 } 1439 }
1292 1440
1293 TEST_F(ViewManagerTest, EmbedWithSameNodeId) { 1441 TEST_F(ViewManagerTest, EmbedWithSameNodeId) {
1294 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 1442 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1295 1443
1296 // Create a third connection. 1444 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(connection_,
1297 ViewManagerProxy* connection3 = NULL; 1445 BuildNodeId(1, 1)));
1298 {
1299 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 1), kTestServiceURL2));
1300 connection3 = ViewManagerProxy::WaitForInstance();
1301 ASSERT_TRUE(connection3 != NULL);
1302 connection3->DoRunLoopUntilChangesCount(1);
1303 const Changes changes(ChangesToDescription1(connection3->changes()));
1304 ASSERT_EQ(1u, changes.size());
1305 EXPECT_EQ("OnConnectionEstablished creator=mojo:test_url", changes[0]);
1306 }
1307 1446
1308 // Connection2 should have been told the node was deleted. 1447 // Connection2 should have been told the node was deleted.
1309 { 1448 {
1310 connection2_->DoRunLoopUntilChangesCount(1); 1449 connection2_->DoRunLoopUntilChangesCount(1);
1311 const Changes changes(ChangesToDescription1(connection2_->changes())); 1450 const Changes changes(ChangesToDescription1(connection2_->changes()));
1312 ASSERT_EQ(1u, changes.size()); 1451 ASSERT_EQ(1u, changes.size());
1313 EXPECT_EQ("NodeDeleted node=1,1", changes[0]); 1452 EXPECT_EQ("NodeDeleted node=1,1", changes[0]);
1314 } 1453 }
1315 1454
1316 // Connection2 has no root. Verify it can't see node 1,1 anymore. 1455 // Connection2 has no root. Verify it can't see node 1,1 anymore.
1317 { 1456 {
1318 std::vector<TestNode> nodes; 1457 std::vector<TestNode> nodes;
1319 connection2_->GetNodeTree(BuildNodeId(1, 1), &nodes); 1458 connection2_->GetNodeTree(BuildNodeId(1, 1), &nodes);
1320 EXPECT_TRUE(nodes.empty()); 1459 EXPECT_TRUE(nodes.empty());
1321 } 1460 }
1322
1323 connection3->Destroy();
1324 } 1461 }
1325 1462
1326 TEST_F(ViewManagerTest, EmbedWithSameNodeId2) { 1463 TEST_F(ViewManagerTest, EmbedWithSameNodeId2) {
1327 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 1464 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1328 1465
1329 // Create a third connection. 1466 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(connection_,
1330 ViewManagerProxy* connection3 = NULL; 1467 BuildNodeId(1, 1)));
1331 {
1332 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 1), kTestServiceURL2));
1333 connection3 = ViewManagerProxy::WaitForInstance();
1334 ASSERT_TRUE(connection3 != NULL);
1335 connection3->DoRunLoopUntilChangesCount(1);
1336 const Changes changes(ChangesToDescription1(connection3->changes()));
1337 ASSERT_EQ(1u, changes.size());
1338 EXPECT_EQ("OnConnectionEstablished creator=mojo:test_url", changes[0]);
1339 }
1340 1468
1341 // Connection2 should have been told the node was deleted. 1469 // Connection2 should have been told the node was deleted.
1342 connection2_->DoRunLoopUntilChangesCount(1); 1470 connection2_->DoRunLoopUntilChangesCount(1);
1343 connection2_->ClearChanges(); 1471 connection2_->ClearChanges();
1344 1472
1345 // Create a node in the third connection and parent it to the root. 1473 // Create a node in the third connection and parent it to the root.
1346 ASSERT_TRUE(connection3->CreateNode(BuildNodeId(3, 1))); 1474 ASSERT_TRUE(connection3_->CreateNode(BuildNodeId(3, 1)));
1347 ASSERT_TRUE(connection3->AddNode(BuildNodeId(1, 1), BuildNodeId(3, 1))); 1475 ASSERT_TRUE(connection3_->AddNode(BuildNodeId(1, 1), BuildNodeId(3, 1)));
1348 1476
1349 // Connection 1 should have been told about the add (it owns the node). 1477 // Connection 1 should have been told about the add (it owns the node).
1350 { 1478 {
1351 connection_->DoRunLoopUntilChangesCount(1); 1479 connection_->DoRunLoopUntilChangesCount(1);
1352 const Changes changes(ChangesToDescription1(connection_->changes())); 1480 const Changes changes(ChangesToDescription1(connection_->changes()));
1353 ASSERT_EQ(1u, changes.size()); 1481 ASSERT_EQ(1u, changes.size());
1354 EXPECT_EQ("HierarchyChanged node=3,1 new_parent=1,1 old_parent=null", 1482 EXPECT_EQ("HierarchyChanged node=3,1 new_parent=1,1 old_parent=null",
1355 changes[0]); 1483 changes[0]);
1356 } 1484 }
1357 1485
1358 // Embed 1,1 back in connection 2. 1486 // Embed 1,1 back in connection 2.
1359 { 1487 {
1360 // 2 should be told about the new embed. 1488 // 2 should be told about the new embed.
1361 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 1), kTestServiceURL)); 1489 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 1), kTestServiceURL));
1362 connection2_->DoRunLoopUntilChangesCount(1); 1490 connection2_->DoRunLoopUntilChangesCount(1);
1363 const std::vector<Change>& changes(connection2_->changes()); 1491 const std::vector<Change>& changes(connection2_->changes());
1364 ASSERT_EQ(1u, changes.size()); 1492 ASSERT_EQ(1u, changes.size());
1365 EXPECT_EQ("OnRootAdded", ChangesToDescription1(changes)[0]); 1493 EXPECT_EQ("OnRootAdded", ChangesToDescription1(changes)[0]);
1366 EXPECT_EQ("[node=1,1 parent=null view=null]", 1494 EXPECT_EQ("[node=1,1 parent=null view=null]",
1367 ChangeNodeDescription(changes)); 1495 ChangeNodeDescription(changes));
1368 1496
1369 // And 3 should get a delete. 1497 // And 3 should get a delete.
1370 connection3->DoRunLoopUntilChangesCount(1); 1498 connection3_->DoRunLoopUntilChangesCount(1);
1371 ASSERT_EQ(1u, connection3->changes().size()); 1499 ASSERT_EQ(1u, connection3_->changes().size());
1372 EXPECT_EQ("NodeDeleted node=1,1", 1500 EXPECT_EQ("NodeDeleted node=1,1",
1373 ChangesToDescription1(connection3->changes())[0]); 1501 ChangesToDescription1(connection3_->changes())[0]);
1374 } 1502 }
1375 1503
1376 // Connection3 has no root. Verify it can't see node 1,1 anymore. 1504 // Connection3_ has no root. Verify it can't see node 1,1 anymore.
1377 { 1505 {
1378 std::vector<TestNode> nodes; 1506 std::vector<TestNode> nodes;
1379 connection3->GetNodeTree(BuildNodeId(1, 1), &nodes); 1507 connection3_->GetNodeTree(BuildNodeId(1, 1), &nodes);
1380 EXPECT_TRUE(nodes.empty()); 1508 EXPECT_TRUE(nodes.empty());
1381 } 1509 }
1382 1510
1383 // Verify 3,1 is no longer parented to 1,1. We have to do this from 1,1 as 1511 // Verify 3,1 is no longer parented to 1,1. We have to do this from 1,1 as
1384 // connection3 can no longer see 1,1. 1512 // connection3_ can no longer see 1,1.
1385 { 1513 {
1386 std::vector<TestNode> nodes; 1514 std::vector<TestNode> nodes;
1387 connection_->GetNodeTree(BuildNodeId(1, 1), &nodes); 1515 connection_->GetNodeTree(BuildNodeId(1, 1), &nodes);
1388 ASSERT_EQ(1u, nodes.size()); 1516 ASSERT_EQ(1u, nodes.size());
1389 EXPECT_EQ("node=1,1 parent=null view=null", nodes[0].ToString()); 1517 EXPECT_EQ("node=1,1 parent=null view=null", nodes[0].ToString());
1390 } 1518 }
1391 1519
1392 // Verify connection3 can still see the node it created 3,1. 1520 // Verify connection3_ can still see the node it created 3,1.
1393 { 1521 {
1394 std::vector<TestNode> nodes; 1522 std::vector<TestNode> nodes;
1395 connection3->GetNodeTree(BuildNodeId(3, 1), &nodes); 1523 connection3_->GetNodeTree(BuildNodeId(3, 1), &nodes);
1396 ASSERT_EQ(1u, nodes.size()); 1524 ASSERT_EQ(1u, nodes.size());
1397 EXPECT_EQ("node=3,1 parent=null view=null", nodes[0].ToString()); 1525 EXPECT_EQ("node=3,1 parent=null view=null", nodes[0].ToString());
1398 } 1526 }
1399
1400 connection3->Destroy();
1401 } 1527 }
1402 1528
1403 // TODO(sky): add coverage of test that destroys connections and ensures other 1529 // TODO(sky): add coverage of test that destroys connections and ensures other
1404 // connections get deletion notification. 1530 // connections get deletion notification.
1405 1531
1406 // TODO(sky): need to better track changes to initial connection. For example, 1532 // TODO(sky): need to better track changes to initial connection. For example,
1407 // that SetBounsdNodes/AddNode and the like don't result in messages to the 1533 // that SetBounsdNodes/AddNode and the like don't result in messages to the
1408 // originating connection. 1534 // originating connection.
1409 1535
1410 // TODO(beng): Add tests for focus: 1536 // TODO(beng): Add tests for focus:
1411 // - focus between two nodes known to a connection 1537 // - focus between two nodes known to a connection
1412 // - focus between nodes unknown to one of the connections. 1538 // - focus between nodes unknown to one of the connections.
1413 // - focus between nodes unknown to either connection. 1539 // - focus between nodes unknown to either connection.
1414 1540
1415 } // namespace service 1541 } // namespace service
1416 } // namespace view_manager 1542 } // namespace view_manager
1417 } // namespace mojo 1543 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/view_manager/view_manager_service_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698