| 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 19 matching lines...) Expand all Loading... |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 31 #include "ui/gfx/geometry/rect.h" | 31 #include "ui/gfx/geometry/rect.h" |
| 32 | 32 |
| 33 namespace mojo { | 33 namespace mojo { |
| 34 namespace view_manager { | 34 namespace view_manager { |
| 35 namespace service { | 35 namespace service { |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 const char kTestServiceURL[] = "mojo:test_url"; | 39 const char kTestServiceURL[] = "mojo:test_url"; |
| 40 const char kTestServiceURL2[] = "mojo:test_url2"; |
| 40 | 41 |
| 41 // ViewManagerProxy is a proxy to an ViewManagerService. It handles invoking | 42 // ViewManagerProxy is a proxy to an ViewManagerService. It handles invoking |
| 42 // ViewManagerService functions on the right thread in a synchronous manner | 43 // ViewManagerService functions on the right thread in a synchronous manner |
| 43 // (each ViewManagerService cover function blocks until the response from the | 44 // (each ViewManagerService cover function blocks until the response from the |
| 44 // ViewManagerService is returned). In addition it tracks the set of | 45 // ViewManagerService is returned). In addition it tracks the set of |
| 45 // ViewManagerClient messages received by way of a vector of Changes. Use | 46 // ViewManagerClient messages received by way of a vector of Changes. Use |
| 46 // DoRunLoopUntilChangesCount() to wait for a certain number of messages to be | 47 // DoRunLoopUntilChangesCount() to wait for a certain number of messages to be |
| 47 // received. | 48 // received. |
| 48 class ViewManagerProxy : public TestChangeTracker::Delegate { | 49 class ViewManagerProxy : public TestChangeTracker::Delegate { |
| 49 public: | 50 public: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 return changes_; | 83 return changes_; |
| 83 } | 84 } |
| 84 | 85 |
| 85 const std::vector<Change>& changes() const { return changes_; } | 86 const std::vector<Change>& changes() const { return changes_; } |
| 86 | 87 |
| 87 // Destroys the connection, blocking until done. | 88 // Destroys the connection, blocking until done. |
| 88 void Destroy() { | 89 void Destroy() { |
| 89 router_->CloseMessagePipe(); | 90 router_->CloseMessagePipe(); |
| 90 } | 91 } |
| 91 | 92 |
| 93 void ClearChanges() { |
| 94 changes_.clear(); |
| 95 tracker_->changes()->clear(); |
| 96 } |
| 97 |
| 92 // The following functions are cover methods for ViewManagerService. They | 98 // The following functions are cover methods for ViewManagerService. They |
| 93 // block until the result is received. | 99 // block until the result is received. |
| 94 bool CreateNode(Id node_id) { | 100 bool CreateNode(Id node_id) { |
| 95 changes_.clear(); | 101 changes_.clear(); |
| 96 ErrorCode result = ERROR_CODE_NONE; | 102 ErrorCode result = ERROR_CODE_NONE; |
| 97 view_manager_->CreateNode( | 103 view_manager_->CreateNode( |
| 98 node_id, | 104 node_id, |
| 99 base::Bind(&ViewManagerProxy::GotResultWithErrorCode, | 105 base::Bind(&ViewManagerProxy::GotResultWithErrorCode, |
| 100 base::Unretained(this), &result)); | 106 base::Unretained(this), &result)); |
| 101 RunMainLoop(); | 107 RunMainLoop(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 RunMainLoop(); | 166 RunMainLoop(); |
| 161 return result; | 167 return result; |
| 162 } | 168 } |
| 163 void GetNodeTree(Id node_id, std::vector<TestNode>* nodes) { | 169 void GetNodeTree(Id node_id, std::vector<TestNode>* nodes) { |
| 164 changes_.clear(); | 170 changes_.clear(); |
| 165 view_manager_->GetNodeTree(node_id, | 171 view_manager_->GetNodeTree(node_id, |
| 166 base::Bind(&ViewManagerProxy::GotNodeTree, | 172 base::Bind(&ViewManagerProxy::GotNodeTree, |
| 167 base::Unretained(this), nodes)); | 173 base::Unretained(this), nodes)); |
| 168 RunMainLoop(); | 174 RunMainLoop(); |
| 169 } | 175 } |
| 170 bool Embed(const Id node_id) { | 176 bool Embed(const Id node_id, const char* url) { |
| 171 changes_.clear(); | 177 changes_.clear(); |
| 172 base::AutoReset<bool> auto_reset(&in_embed_, true); | 178 base::AutoReset<bool> auto_reset(&in_embed_, true); |
| 173 bool result = false; | 179 bool result = false; |
| 174 view_manager_->Embed(kTestServiceURL, node_id, | 180 view_manager_->Embed(url, node_id, |
| 175 base::Bind(&ViewManagerProxy::GotResult, | 181 base::Bind(&ViewManagerProxy::GotResult, |
| 176 base::Unretained(this), &result)); | 182 base::Unretained(this), &result)); |
| 177 RunMainLoop(); | 183 RunMainLoop(); |
| 178 return result; | 184 return result; |
| 179 } | 185 } |
| 180 bool DeleteNode(Id node_id, Id server_change_id) { | 186 bool DeleteNode(Id node_id, Id server_change_id) { |
| 181 changes_.clear(); | 187 changes_.clear(); |
| 182 bool result = false; | 188 bool result = false; |
| 183 view_manager_->DeleteNode(node_id, | 189 view_manager_->DeleteNode(node_id, |
| 184 server_change_id, | 190 server_change_id, |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 public: | 459 public: |
| 454 ViewManagerTest() : connection_(NULL), connection2_(NULL) {} | 460 ViewManagerTest() : connection_(NULL), connection2_(NULL) {} |
| 455 | 461 |
| 456 virtual void SetUp() OVERRIDE { | 462 virtual void SetUp() OVERRIDE { |
| 457 test_helper_.Init(); | 463 test_helper_.Init(); |
| 458 | 464 |
| 459 test_helper_.SetLoaderForURL( | 465 test_helper_.SetLoaderForURL( |
| 460 scoped_ptr<ServiceLoader>(new EmbedServiceLoader()), | 466 scoped_ptr<ServiceLoader>(new EmbedServiceLoader()), |
| 461 GURL(kTestServiceURL)); | 467 GURL(kTestServiceURL)); |
| 462 | 468 |
| 469 test_helper_.SetLoaderForURL( |
| 470 scoped_ptr<ServiceLoader>(new EmbedServiceLoader()), |
| 471 GURL(kTestServiceURL2)); |
| 472 |
| 463 test_helper_.service_manager()->ConnectToService( | 473 test_helper_.service_manager()->ConnectToService( |
| 464 GURL("mojo:mojo_view_manager"), | 474 GURL("mojo:mojo_view_manager"), |
| 465 &view_manager_init_); | 475 &view_manager_init_); |
| 466 ASSERT_TRUE(EmbedRoot(view_manager_init_.get(), kTestServiceURL)); | 476 ASSERT_TRUE(EmbedRoot(view_manager_init_.get(), kTestServiceURL)); |
| 467 | 477 |
| 468 connection_ = ViewManagerProxy::WaitForInstance(); | 478 connection_ = ViewManagerProxy::WaitForInstance(); |
| 469 ASSERT_TRUE(connection_ != NULL); | 479 ASSERT_TRUE(connection_ != NULL); |
| 470 connection_->DoRunLoopUntilChangesCount(1); | 480 connection_->DoRunLoopUntilChangesCount(1); |
| 471 } | 481 } |
| 472 | 482 |
| 473 virtual void TearDown() OVERRIDE { | 483 virtual void TearDown() OVERRIDE { |
| 474 if (connection2_) | 484 if (connection2_) |
| 475 connection2_->Destroy(); | 485 connection2_->Destroy(); |
| 476 if (connection_) | 486 if (connection_) |
| 477 connection_->Destroy(); | 487 connection_->Destroy(); |
| 478 } | 488 } |
| 479 | 489 |
| 480 protected: | 490 protected: |
| 481 void EstablishSecondConnectionWithRoot(Id root_id) { | 491 void EstablishSecondConnectionWithRoot(Id root_id) { |
| 482 ASSERT_TRUE(connection_->Embed(root_id)); | 492 ASSERT_TRUE(connection_->Embed(root_id, kTestServiceURL)); |
| 483 connection2_ = ViewManagerProxy::WaitForInstance(); | 493 connection2_ = ViewManagerProxy::WaitForInstance(); |
| 484 ASSERT_TRUE(connection2_ != NULL); | 494 ASSERT_TRUE(connection2_ != NULL); |
| 485 connection2_->DoRunLoopUntilChangesCount(1); | 495 connection2_->DoRunLoopUntilChangesCount(1); |
| 486 ASSERT_EQ(1u, connection2_->changes().size()); | 496 ASSERT_EQ(1u, connection2_->changes().size()); |
| 487 } | 497 } |
| 488 | 498 |
| 489 // Creates a second connection to the viewmanager. | 499 // Creates a second connection to the viewmanager. |
| 490 void EstablishSecondConnection(bool create_initial_node) { | 500 void EstablishSecondConnection(bool create_initial_node) { |
| 491 if (create_initial_node) | 501 if (create_initial_node) |
| 492 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 502 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 | 583 |
| 574 // Verifies hierarchy changes. | 584 // Verifies hierarchy changes. |
| 575 TEST_F(ViewManagerTest, AddRemoveNotify) { | 585 TEST_F(ViewManagerTest, AddRemoveNotify) { |
| 576 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 586 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 577 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); | 587 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); |
| 578 | 588 |
| 579 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 589 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 580 | 590 |
| 581 // Make 3 a child of 2. | 591 // Make 3 a child of 2. |
| 582 { | 592 { |
| 583 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 3), 1)); | 593 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 3), 2)); |
| 584 EXPECT_TRUE(connection_->changes().empty()); | |
| 585 | |
| 586 connection2_->DoRunLoopUntilChangesCount(1); | |
| 587 const Changes changes(ChangesToDescription1(connection2_->changes())); | |
| 588 ASSERT_EQ(1u, changes.size()); | |
| 589 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); | |
| 590 } | |
| 591 | |
| 592 // Remove 3 from its parent. | |
| 593 { | |
| 594 ASSERT_TRUE(connection_->RemoveNodeFromParent(BuildNodeId(1, 3), 2)); | |
| 595 EXPECT_TRUE(connection_->changes().empty()); | 594 EXPECT_TRUE(connection_->changes().empty()); |
| 596 | 595 |
| 597 connection2_->DoRunLoopUntilChangesCount(1); | 596 connection2_->DoRunLoopUntilChangesCount(1); |
| 598 const Changes changes(ChangesToDescription1(connection2_->changes())); | 597 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 599 ASSERT_EQ(1u, changes.size()); | 598 ASSERT_EQ(1u, changes.size()); |
| 600 EXPECT_EQ("ServerChangeIdAdvanced 3", changes[0]); | 599 EXPECT_EQ("ServerChangeIdAdvanced 3", changes[0]); |
| 601 } | 600 } |
| 601 |
| 602 // Remove 3 from its parent. |
| 603 { |
| 604 ASSERT_TRUE(connection_->RemoveNodeFromParent(BuildNodeId(1, 3), 3)); |
| 605 EXPECT_TRUE(connection_->changes().empty()); |
| 606 |
| 607 connection2_->DoRunLoopUntilChangesCount(1); |
| 608 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 609 ASSERT_EQ(1u, changes.size()); |
| 610 EXPECT_EQ("ServerChangeIdAdvanced 4", changes[0]); |
| 611 } |
| 602 } | 612 } |
| 603 | 613 |
| 604 // Verifies AddNode fails when node is already in position. | 614 // Verifies AddNode fails when node is already in position. |
| 605 TEST_F(ViewManagerTest, AddNodeWithNoChange) { | 615 TEST_F(ViewManagerTest, AddNodeWithNoChange) { |
| 606 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 616 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 607 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); | 617 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); |
| 608 | 618 |
| 609 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 619 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 610 | 620 |
| 611 // Make 3 a child of 2. | 621 // Make 3 a child of 2. |
| 612 { | 622 { |
| 613 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 3), 1)); | 623 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 3), 2)); |
| 614 | 624 |
| 615 connection2_->DoRunLoopUntilChangesCount(1); | 625 connection2_->DoRunLoopUntilChangesCount(1); |
| 616 const Changes changes(ChangesToDescription1(connection2_->changes())); | 626 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 617 ASSERT_EQ(1u, changes.size()); | 627 ASSERT_EQ(1u, changes.size()); |
| 618 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); | 628 EXPECT_EQ("ServerChangeIdAdvanced 3", changes[0]); |
| 619 } | 629 } |
| 620 | 630 |
| 621 // Try again, this should fail. | 631 // Try again, this should fail. |
| 622 { | 632 { |
| 623 EXPECT_FALSE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 3), 2)); | 633 EXPECT_FALSE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 3), 3)); |
| 624 } | 634 } |
| 625 } | 635 } |
| 626 | 636 |
| 627 // Verifies AddNode fails when node is already in position. | 637 // Verifies AddNode fails when node is already in position. |
| 628 TEST_F(ViewManagerTest, AddAncestorFails) { | 638 TEST_F(ViewManagerTest, AddAncestorFails) { |
| 629 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 639 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 630 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); | 640 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); |
| 631 | 641 |
| 632 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 642 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 633 | 643 |
| 634 // Make 3 a child of 2. | 644 // Make 3 a child of 2. |
| 635 { | 645 { |
| 636 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 3), 1)); | 646 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 3), 2)); |
| 637 connection2_->DoRunLoopUntilChangesCount(1); | 647 connection2_->DoRunLoopUntilChangesCount(1); |
| 638 const Changes changes(ChangesToDescription1(connection2_->changes())); | 648 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 639 ASSERT_EQ(1u, changes.size()); | 649 ASSERT_EQ(1u, changes.size()); |
| 640 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); | 650 EXPECT_EQ("ServerChangeIdAdvanced 3", changes[0]); |
| 641 } | 651 } |
| 642 | 652 |
| 643 // Try to make 2 a child of 3, this should fail since 2 is an ancestor of 3. | 653 // Try to make 2 a child of 3, this should fail since 2 is an ancestor of 3. |
| 644 { | 654 { |
| 645 EXPECT_FALSE(connection_->AddNode(BuildNodeId(1, 3), BuildNodeId(1, 2), 2)); | 655 EXPECT_FALSE(connection_->AddNode(BuildNodeId(1, 3), BuildNodeId(1, 2), 3)); |
| 646 } | 656 } |
| 647 } | 657 } |
| 648 | 658 |
| 649 // Verifies adding with an invalid id fails. | 659 // Verifies adding with an invalid id fails. |
| 650 TEST_F(ViewManagerTest, AddWithInvalidServerId) { | 660 TEST_F(ViewManagerTest, AddWithInvalidServerId) { |
| 651 // Create two nodes. | 661 // Create two nodes. |
| 652 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 662 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| 653 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 663 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 654 | 664 |
| 655 // Make 2 a child of 1. Supply an invalid change id, which should fail. | 665 // Make 2 a child of 1. Supply an invalid change id, which should fail. |
| 656 ASSERT_FALSE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 0)); | 666 ASSERT_FALSE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 0)); |
| 657 } | 667 } |
| 658 | 668 |
| 659 // Verifies adding to root sends right notifications. | 669 // Verifies adding to root sends right notifications. |
| 660 TEST_F(ViewManagerTest, AddToRoot) { | 670 TEST_F(ViewManagerTest, AddToRoot) { |
| 661 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 21))); | 671 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 21))); |
| 662 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); | 672 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); |
| 663 | 673 |
| 664 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 674 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 665 | 675 |
| 666 // Make 3 a child of 21. | 676 // Make 3 a child of 21. |
| 667 { | 677 { |
| 668 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 21), BuildNodeId(1, 3), 1)); | 678 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 21), BuildNodeId(1, 3), 2)); |
| 669 | 679 |
| 670 connection2_->DoRunLoopUntilChangesCount(1); | 680 connection2_->DoRunLoopUntilChangesCount(1); |
| 671 const Changes changes(ChangesToDescription1(connection2_->changes())); | 681 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 672 ASSERT_EQ(1u, changes.size()); | 682 ASSERT_EQ(1u, changes.size()); |
| 673 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); | 683 EXPECT_EQ("ServerChangeIdAdvanced 3", changes[0]); |
| 674 } | 684 } |
| 675 | 685 |
| 676 // Make 21 a child of 1. | 686 // Make 21 a child of 1. |
| 677 { | 687 { |
| 678 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 21), 2)); | 688 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 21), 3)); |
| 679 | 689 |
| 680 connection2_->DoRunLoopUntilChangesCount(1); | 690 connection2_->DoRunLoopUntilChangesCount(1); |
| 681 const Changes changes(ChangesToDescription1(connection2_->changes())); | 691 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 682 ASSERT_EQ(1u, changes.size()); | 692 ASSERT_EQ(1u, changes.size()); |
| 683 EXPECT_EQ( | 693 EXPECT_EQ( |
| 684 "HierarchyChanged change_id=2 node=1,21 new_parent=1,1 old_parent=null", | 694 "HierarchyChanged change_id=3 node=1,21 new_parent=1,1 old_parent=null", |
| 685 changes[0]); | 695 changes[0]); |
| 686 } | 696 } |
| 687 } | 697 } |
| 688 | 698 |
| 689 // Verifies HierarchyChanged is correctly sent for various adds/removes. | 699 // Verifies HierarchyChanged is correctly sent for various adds/removes. |
| 690 TEST_F(ViewManagerTest, NodeHierarchyChangedNodes) { | 700 TEST_F(ViewManagerTest, NodeHierarchyChangedNodes) { |
| 691 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 701 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 692 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 11))); | 702 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 11))); |
| 693 // Make 11 a child of 2. | 703 // Make 11 a child of 2. |
| 694 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 11), 1)); | 704 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 11), 1)); |
| 695 | 705 |
| 696 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 706 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 697 | 707 |
| 698 // Make 2 a child of 1. | 708 // Make 2 a child of 1. |
| 699 { | 709 { |
| 700 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 2)); | 710 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 3)); |
| 701 | 711 |
| 702 // Client 2 should get a hierarchy change that includes the new nodes as it | 712 // Client 2 should get a hierarchy change that includes the new nodes as it |
| 703 // has not yet seen them. | 713 // has not yet seen them. |
| 704 connection2_->DoRunLoopUntilChangesCount(1); | 714 connection2_->DoRunLoopUntilChangesCount(1); |
| 705 const Changes changes(ChangesToDescription1(connection2_->changes())); | 715 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 706 ASSERT_EQ(1u, changes.size()); | 716 ASSERT_EQ(1u, changes.size()); |
| 707 EXPECT_EQ( | 717 EXPECT_EQ( |
| 708 "HierarchyChanged change_id=2 node=1,2 new_parent=1,1 old_parent=null", | 718 "HierarchyChanged change_id=3 node=1,2 new_parent=1,1 old_parent=null", |
| 709 changes[0]); | 719 changes[0]); |
| 710 EXPECT_EQ("[node=1,2 parent=1,1 view=null]," | 720 EXPECT_EQ("[node=1,2 parent=1,1 view=null]," |
| 711 "[node=1,11 parent=1,2 view=null]", | 721 "[node=1,11 parent=1,2 view=null]", |
| 712 ChangeNodeDescription(connection2_->changes())); | 722 ChangeNodeDescription(connection2_->changes())); |
| 713 } | 723 } |
| 714 | 724 |
| 715 // Add 1 to the root. | 725 // Add 1 to the root. |
| 716 { | 726 { |
| 717 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 3)); | 727 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 4)); |
| 718 | 728 |
| 719 // Client 2 should get a hierarchy change that includes the new nodes as it | 729 // Client 2 should get a hierarchy change that includes the new nodes as it |
| 720 // has not yet seen them. | 730 // has not yet seen them. |
| 721 connection2_->DoRunLoopUntilChangesCount(1); | 731 connection2_->DoRunLoopUntilChangesCount(1); |
| 722 const Changes changes(ChangesToDescription1(connection2_->changes())); | 732 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 723 ASSERT_EQ(1u, changes.size()); | 733 ASSERT_EQ(1u, changes.size()); |
| 724 EXPECT_EQ( | 734 EXPECT_EQ( |
| 725 "HierarchyChanged change_id=3 node=1,1 new_parent=null old_parent=null", | 735 "HierarchyChanged change_id=4 node=1,1 new_parent=null old_parent=null", |
| 726 changes[0]); | 736 changes[0]); |
| 727 EXPECT_EQ(std::string(), ChangeNodeDescription(connection2_->changes())); | 737 EXPECT_EQ(std::string(), ChangeNodeDescription(connection2_->changes())); |
| 728 } | 738 } |
| 729 | 739 |
| 730 // Remove 1 from its parent. | 740 // Remove 1 from its parent. |
| 731 { | 741 { |
| 732 ASSERT_TRUE(connection_->RemoveNodeFromParent(BuildNodeId(1, 1), 4)); | 742 ASSERT_TRUE(connection_->RemoveNodeFromParent(BuildNodeId(1, 1), 5)); |
| 733 EXPECT_TRUE(connection_->changes().empty()); | 743 EXPECT_TRUE(connection_->changes().empty()); |
| 734 | 744 |
| 735 connection2_->DoRunLoopUntilChangesCount(1); | 745 connection2_->DoRunLoopUntilChangesCount(1); |
| 736 const Changes changes(ChangesToDescription1(connection2_->changes())); | 746 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 737 ASSERT_EQ(1u, changes.size()); | 747 ASSERT_EQ(1u, changes.size()); |
| 738 EXPECT_EQ( | 748 EXPECT_EQ( |
| 739 "HierarchyChanged change_id=4 node=1,1 new_parent=null old_parent=null", | 749 "HierarchyChanged change_id=5 node=1,1 new_parent=null old_parent=null", |
| 740 changes[0]); | 750 changes[0]); |
| 741 } | 751 } |
| 742 | 752 |
| 743 // Create another node, 111, parent it to 11. | 753 // Create another node, 111, parent it to 11. |
| 744 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 111))); | 754 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 111))); |
| 745 { | 755 { |
| 746 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 11), BuildNodeId(1, 111), | 756 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 11), BuildNodeId(1, 111), |
| 747 5)); | 757 6)); |
| 748 | 758 |
| 749 connection2_->DoRunLoopUntilChangesCount(1); | 759 connection2_->DoRunLoopUntilChangesCount(1); |
| 750 const Changes changes(ChangesToDescription1(connection2_->changes())); | 760 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 751 ASSERT_EQ(1u, changes.size()); | 761 ASSERT_EQ(1u, changes.size()); |
| 752 EXPECT_EQ( | 762 EXPECT_EQ( |
| 753 "HierarchyChanged change_id=5 node=1,111 new_parent=1,11 " | 763 "HierarchyChanged change_id=6 node=1,111 new_parent=1,11 " |
| 754 "old_parent=null", changes[0]); | 764 "old_parent=null", changes[0]); |
| 755 EXPECT_EQ("[node=1,111 parent=1,11 view=null]", | 765 EXPECT_EQ("[node=1,111 parent=1,11 view=null]", |
| 756 ChangeNodeDescription(connection2_->changes())); | 766 ChangeNodeDescription(connection2_->changes())); |
| 757 } | 767 } |
| 758 | 768 |
| 759 // Reattach 1 to the root. | 769 // Reattach 1 to the root. |
| 760 { | 770 { |
| 761 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 6)); | 771 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 7)); |
| 762 | 772 |
| 763 connection2_->DoRunLoopUntilChangesCount(1); | 773 connection2_->DoRunLoopUntilChangesCount(1); |
| 764 const Changes changes(ChangesToDescription1(connection2_->changes())); | 774 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 765 ASSERT_EQ(1u, changes.size()); | 775 ASSERT_EQ(1u, changes.size()); |
| 766 EXPECT_EQ( | 776 EXPECT_EQ( |
| 767 "HierarchyChanged change_id=6 node=1,1 new_parent=null old_parent=null", | 777 "HierarchyChanged change_id=7 node=1,1 new_parent=null old_parent=null", |
| 768 changes[0]); | 778 changes[0]); |
| 769 EXPECT_EQ(std::string(), ChangeNodeDescription(connection2_->changes())); | 779 EXPECT_EQ(std::string(), ChangeNodeDescription(connection2_->changes())); |
| 770 } | 780 } |
| 771 } | 781 } |
| 772 | 782 |
| 773 TEST_F(ViewManagerTest, NodeHierarchyChangedAddingKnownToUnknown) { | 783 TEST_F(ViewManagerTest, NodeHierarchyChangedAddingKnownToUnknown) { |
| 774 // Create the following structure: root -> 1 -> 11 and 2->21 (2 has no | 784 // Create the following structure: root -> 1 -> 11 and 2->21 (2 has no |
| 775 // parent). | 785 // parent). |
| 776 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 786 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| 777 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 11))); | 787 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 11))); |
| 778 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 788 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 779 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 21))); | 789 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 21))); |
| 780 | 790 |
| 781 // Set up the hierarchy. | 791 // Set up the hierarchy. |
| 782 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 1)); | 792 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 1)); |
| 783 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 11), 2)); | 793 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 11), 2)); |
| 784 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 21), 3)); | 794 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 21), 3)); |
| 785 | 795 |
| 786 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 796 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 787 { | 797 { |
| 788 EXPECT_EQ("[node=1,1 parent=null view=null]," | 798 EXPECT_EQ("[node=1,1 parent=null view=null]," |
| 789 "[node=1,11 parent=1,1 view=null]", | 799 "[node=1,11 parent=1,1 view=null]", |
| 790 ChangeNodeDescription(connection2_->changes())); | 800 ChangeNodeDescription(connection2_->changes())); |
| 791 } | 801 } |
| 792 | 802 |
| 793 // Remove 11, should result in a delete (since 11 is no longer in connection | 803 // Remove 11, should result in a delete (since 11 is no longer in connection |
| 794 // 2's root). | 804 // 2's root). |
| 795 { | 805 { |
| 796 ASSERT_TRUE(connection_->RemoveNodeFromParent(BuildNodeId(1, 11), 4)); | 806 ASSERT_TRUE(connection_->RemoveNodeFromParent(BuildNodeId(1, 11), 5)); |
| 797 | 807 |
| 798 connection2_->DoRunLoopUntilChangesCount(1); | 808 connection2_->DoRunLoopUntilChangesCount(1); |
| 799 const Changes changes(ChangesToDescription1(connection2_->changes())); | 809 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 800 ASSERT_EQ(1u, changes.size()); | 810 ASSERT_EQ(1u, changes.size()); |
| 801 EXPECT_EQ("NodeDeleted change_id=4 node=1,11", changes[0]); | 811 EXPECT_EQ("NodeDeleted change_id=5 node=1,11", changes[0]); |
| 802 } | 812 } |
| 803 | 813 |
| 804 // Add 2 to 1. | 814 // Add 2 to 1. |
| 805 { | 815 { |
| 806 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 5)); | 816 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 6)); |
| 807 | 817 |
| 808 connection2_->DoRunLoopUntilChangesCount(1); | 818 connection2_->DoRunLoopUntilChangesCount(1); |
| 809 const Changes changes(ChangesToDescription1(connection2_->changes())); | 819 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 810 ASSERT_EQ(1u, changes.size()); | 820 ASSERT_EQ(1u, changes.size()); |
| 811 EXPECT_EQ( | 821 EXPECT_EQ( |
| 812 "HierarchyChanged change_id=5 node=1,2 new_parent=1,1 old_parent=null", | 822 "HierarchyChanged change_id=6 node=1,2 new_parent=1,1 old_parent=null", |
| 813 changes[0]); | 823 changes[0]); |
| 814 EXPECT_EQ("[node=1,2 parent=1,1 view=null]," | 824 EXPECT_EQ("[node=1,2 parent=1,1 view=null]," |
| 815 "[node=1,21 parent=1,2 view=null]", | 825 "[node=1,21 parent=1,2 view=null]", |
| 816 ChangeNodeDescription(connection2_->changes())); | 826 ChangeNodeDescription(connection2_->changes())); |
| 817 } | 827 } |
| 818 } | 828 } |
| 819 | 829 |
| 820 TEST_F(ViewManagerTest, ReorderNode) { | 830 TEST_F(ViewManagerTest, ReorderNode) { |
| 821 Id node1_id = BuildNodeId(1, 1); | 831 Id node1_id = BuildNodeId(1, 1); |
| 822 Id node2_id = BuildNodeId(1, 2); | 832 Id node2_id = BuildNodeId(1, 2); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 838 ASSERT_TRUE(connection_->AddNode(node2_id, node6_id, 2)); | 848 ASSERT_TRUE(connection_->AddNode(node2_id, node6_id, 2)); |
| 839 ASSERT_TRUE(connection_->AddNode(node1_id, node3_id, 3)); | 849 ASSERT_TRUE(connection_->AddNode(node1_id, node3_id, 3)); |
| 840 ASSERT_TRUE(connection_->AddNode( | 850 ASSERT_TRUE(connection_->AddNode( |
| 841 NodeIdToTransportId(RootNodeId()), node4_id, 4)); | 851 NodeIdToTransportId(RootNodeId()), node4_id, 4)); |
| 842 ASSERT_TRUE(connection_->AddNode( | 852 ASSERT_TRUE(connection_->AddNode( |
| 843 NodeIdToTransportId(RootNodeId()), node5_id, 5)); | 853 NodeIdToTransportId(RootNodeId()), node5_id, 5)); |
| 844 | 854 |
| 845 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 855 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 846 | 856 |
| 847 { | 857 { |
| 848 connection_->ReorderNode(node2_id, node3_id, ORDER_DIRECTION_ABOVE, 6); | 858 connection_->ReorderNode(node2_id, node3_id, ORDER_DIRECTION_ABOVE, 7); |
| 849 | 859 |
| 850 connection2_->DoRunLoopUntilChangesCount(1); | 860 connection2_->DoRunLoopUntilChangesCount(1); |
| 851 const Changes changes(ChangesToDescription1(connection2_->changes())); | 861 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 852 ASSERT_EQ(1u, changes.size()); | 862 ASSERT_EQ(1u, changes.size()); |
| 853 EXPECT_EQ( | 863 EXPECT_EQ( |
| 854 "Reordered change_id=6 node=1,2 relative=1,3 direction=above", | 864 "Reordered change_id=7 node=1,2 relative=1,3 direction=above", |
| 855 changes[0]); | 865 changes[0]); |
| 856 } | 866 } |
| 857 | 867 |
| 858 { | 868 { |
| 859 connection_->ReorderNode(node2_id, node3_id, ORDER_DIRECTION_BELOW, 7); | 869 connection_->ReorderNode(node2_id, node3_id, ORDER_DIRECTION_BELOW, 8); |
| 860 | 870 |
| 861 connection2_->DoRunLoopUntilChangesCount(1); | 871 connection2_->DoRunLoopUntilChangesCount(1); |
| 862 const Changes changes(ChangesToDescription1(connection2_->changes())); | 872 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 863 ASSERT_EQ(1u, changes.size()); | 873 ASSERT_EQ(1u, changes.size()); |
| 864 EXPECT_EQ( | 874 EXPECT_EQ( |
| 865 "Reordered change_id=7 node=1,2 relative=1,3 direction=below", | 875 "Reordered change_id=8 node=1,2 relative=1,3 direction=below", |
| 866 changes[0]); | 876 changes[0]); |
| 867 } | 877 } |
| 868 | 878 |
| 869 { | 879 { |
| 870 // node2 is already below node3. | 880 // node2 is already below node3. |
| 871 EXPECT_FALSE( | 881 EXPECT_FALSE( |
| 872 connection_->ReorderNode(node2_id, node3_id, ORDER_DIRECTION_BELOW, 8)); | 882 connection_->ReorderNode(node2_id, node3_id, ORDER_DIRECTION_BELOW, 9)); |
| 873 } | 883 } |
| 874 | 884 |
| 875 { | 885 { |
| 876 // node4 & 5 are unknown to connection2_. | 886 // node4 & 5 are unknown to connection2_. |
| 877 EXPECT_FALSE(connection2_->ReorderNode( | 887 EXPECT_FALSE(connection2_->ReorderNode( |
| 878 node4_id, node5_id, ORDER_DIRECTION_ABOVE, 8)); | 888 node4_id, node5_id, ORDER_DIRECTION_ABOVE, 9)); |
| 879 } | 889 } |
| 880 | 890 |
| 881 { | 891 { |
| 882 // node6 & node3 have different parents. | 892 // node6 & node3 have different parents. |
| 883 EXPECT_FALSE( | 893 EXPECT_FALSE( |
| 884 connection_->ReorderNode(node3_id, node6_id, ORDER_DIRECTION_ABOVE, 8)); | 894 connection_->ReorderNode(node3_id, node6_id, ORDER_DIRECTION_ABOVE, 9)); |
| 885 } | 895 } |
| 886 | 896 |
| 887 { | 897 { |
| 888 // Non-existent node-ids | 898 // Non-existent node-ids |
| 889 EXPECT_FALSE(connection_->ReorderNode( | 899 EXPECT_FALSE(connection_->ReorderNode( |
| 890 BuildNodeId(1, 27), BuildNodeId(1, 28), ORDER_DIRECTION_ABOVE, 8)); | 900 BuildNodeId(1, 27), BuildNodeId(1, 28), ORDER_DIRECTION_ABOVE, 9)); |
| 891 } | 901 } |
| 892 | 902 |
| 893 { | 903 { |
| 894 // node7 & node8 are un-parented. | 904 // node7 & node8 are un-parented. |
| 895 EXPECT_FALSE( | 905 EXPECT_FALSE( |
| 896 connection_->ReorderNode(node7_id, node8_id, ORDER_DIRECTION_ABOVE, 8)); | 906 connection_->ReorderNode(node7_id, node8_id, ORDER_DIRECTION_ABOVE, 9)); |
| 897 } | 907 } |
| 898 } | 908 } |
| 899 | 909 |
| 900 // Verifies DeleteNode works. | 910 // Verifies DeleteNode works. |
| 901 TEST_F(ViewManagerTest, DeleteNode) { | 911 TEST_F(ViewManagerTest, DeleteNode) { |
| 902 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 912 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 903 | 913 |
| 904 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 914 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 905 | 915 |
| 906 // Make 2 a child of 1. | 916 // Make 2 a child of 1. |
| 907 { | 917 { |
| 908 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 1)); | 918 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 2)); |
| 909 connection2_->DoRunLoopUntilChangesCount(1); | 919 connection2_->DoRunLoopUntilChangesCount(1); |
| 910 const Changes changes(ChangesToDescription1(connection2_->changes())); | 920 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 911 ASSERT_EQ(1u, changes.size()); | 921 ASSERT_EQ(1u, changes.size()); |
| 912 EXPECT_EQ("HierarchyChanged change_id=1 node=1,2 new_parent=1,1 " | 922 EXPECT_EQ("HierarchyChanged change_id=2 node=1,2 new_parent=1,1 " |
| 913 "old_parent=null", changes[0]); | 923 "old_parent=null", changes[0]); |
| 914 } | 924 } |
| 915 | 925 |
| 916 // Delete 2. | 926 // Delete 2. |
| 917 { | 927 { |
| 918 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 2), 2)); | 928 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 2), 3)); |
| 919 EXPECT_TRUE(connection_->changes().empty()); | 929 EXPECT_TRUE(connection_->changes().empty()); |
| 920 | 930 |
| 921 connection2_->DoRunLoopUntilChangesCount(1); | 931 connection2_->DoRunLoopUntilChangesCount(1); |
| 922 const Changes changes(ChangesToDescription1(connection2_->changes())); | 932 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 923 ASSERT_EQ(1u, changes.size()); | 933 ASSERT_EQ(1u, changes.size()); |
| 924 EXPECT_EQ("NodeDeleted change_id=2 node=1,2", changes[0]); | 934 EXPECT_EQ("NodeDeleted change_id=3 node=1,2", changes[0]); |
| 925 } | 935 } |
| 926 } | 936 } |
| 927 | 937 |
| 928 // Verifies DeleteNode isn't allowed from a separate connection. | 938 // Verifies DeleteNode isn't allowed from a separate connection. |
| 929 TEST_F(ViewManagerTest, DeleteNodeFromAnotherConnectionDisallowed) { | 939 TEST_F(ViewManagerTest, DeleteNodeFromAnotherConnectionDisallowed) { |
| 930 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 940 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 931 EXPECT_FALSE(connection2_->DeleteNode(BuildNodeId(1, 1), 1)); | 941 EXPECT_FALSE(connection2_->DeleteNode(BuildNodeId(1, 1), 1)); |
| 932 } | 942 } |
| 933 | 943 |
| 934 // Verifies DeleteView isn't allowed from a separate connection. | 944 // Verifies DeleteView isn't allowed from a separate connection. |
| 935 TEST_F(ViewManagerTest, DeleteViewFromAnotherConnectionDisallowed) { | 945 TEST_F(ViewManagerTest, DeleteViewFromAnotherConnectionDisallowed) { |
| 936 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); | 946 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); |
| 937 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 947 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 938 EXPECT_FALSE(connection2_->DeleteView(BuildViewId(1, 1))); | 948 EXPECT_FALSE(connection2_->DeleteView(BuildViewId(1, 1))); |
| 939 } | 949 } |
| 940 | 950 |
| 941 // Verifies if a node was deleted and then reused that other clients are | 951 // Verifies if a node was deleted and then reused that other clients are |
| 942 // properly notified. | 952 // properly notified. |
| 943 TEST_F(ViewManagerTest, ReuseDeletedNodeId) { | 953 TEST_F(ViewManagerTest, ReuseDeletedNodeId) { |
| 944 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 954 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 945 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 955 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 946 | 956 |
| 947 // Add 2 to 1. | 957 // Add 2 to 1. |
| 948 { | 958 { |
| 949 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 1)); | 959 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 2)); |
| 950 | 960 |
| 951 connection2_->DoRunLoopUntilChangesCount(1); | 961 connection2_->DoRunLoopUntilChangesCount(1); |
| 952 const Changes changes(ChangesToDescription1(connection2_->changes())); | 962 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 953 EXPECT_EQ( | 963 EXPECT_EQ( |
| 954 "HierarchyChanged change_id=1 node=1,2 new_parent=1,1 old_parent=null", | 964 "HierarchyChanged change_id=2 node=1,2 new_parent=1,1 old_parent=null", |
| 955 changes[0]); | 965 changes[0]); |
| 956 EXPECT_EQ("[node=1,2 parent=1,1 view=null]", | 966 EXPECT_EQ("[node=1,2 parent=1,1 view=null]", |
| 957 ChangeNodeDescription(connection2_->changes())); | 967 ChangeNodeDescription(connection2_->changes())); |
| 958 } | 968 } |
| 959 | 969 |
| 960 // Delete 2. | 970 // Delete 2. |
| 961 { | 971 { |
| 962 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 2), 2)); | 972 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 2), 3)); |
| 963 | 973 |
| 964 connection2_->DoRunLoopUntilChangesCount(1); | 974 connection2_->DoRunLoopUntilChangesCount(1); |
| 965 const Changes changes(ChangesToDescription1(connection2_->changes())); | 975 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 966 ASSERT_EQ(1u, changes.size()); | 976 ASSERT_EQ(1u, changes.size()); |
| 967 EXPECT_EQ("NodeDeleted change_id=2 node=1,2", changes[0]); | 977 EXPECT_EQ("NodeDeleted change_id=3 node=1,2", changes[0]); |
| 968 } | 978 } |
| 969 | 979 |
| 970 // Create 2 again, and add it back to 1. Should get the same notification. | 980 // Create 2 again, and add it back to 1. Should get the same notification. |
| 971 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 981 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 972 { | 982 { |
| 973 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 3)); | 983 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 4)); |
| 974 | 984 |
| 975 connection2_->DoRunLoopUntilChangesCount(1); | 985 connection2_->DoRunLoopUntilChangesCount(1); |
| 976 const Changes changes(ChangesToDescription1(connection2_->changes())); | 986 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 977 EXPECT_EQ( | 987 EXPECT_EQ( |
| 978 "HierarchyChanged change_id=3 node=1,2 new_parent=1,1 old_parent=null", | 988 "HierarchyChanged change_id=4 node=1,2 new_parent=1,1 old_parent=null", |
| 979 changes[0]); | 989 changes[0]); |
| 980 EXPECT_EQ("[node=1,2 parent=1,1 view=null]", | 990 EXPECT_EQ("[node=1,2 parent=1,1 view=null]", |
| 981 ChangeNodeDescription(connection2_->changes())); | 991 ChangeNodeDescription(connection2_->changes())); |
| 982 } | 992 } |
| 983 } | 993 } |
| 984 | 994 |
| 985 // Assertions around setting a view. | 995 // Assertions around setting a view. |
| 986 TEST_F(ViewManagerTest, SetView) { | 996 TEST_F(ViewManagerTest, SetView) { |
| 987 // Create nodes 1, 2 and 3 and the view 11. Nodes 2 and 3 are parented to 1. | 997 // Create nodes 1, 2 and 3 and the view 11. Nodes 2 and 3 are parented to 1. |
| 988 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 998 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 11))); | 1038 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 11))); |
| 1029 | 1039 |
| 1030 // Set view 11 on node 2. | 1040 // Set view 11 on node 2. |
| 1031 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 2), BuildViewId(1, 11))); | 1041 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 2), BuildViewId(1, 11))); |
| 1032 | 1042 |
| 1033 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1043 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1034 | 1044 |
| 1035 // Delete node 2. The second connection should not see this because the node | 1045 // Delete node 2. The second connection should not see this because the node |
| 1036 // was not known to it. | 1046 // was not known to it. |
| 1037 { | 1047 { |
| 1038 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 2), 1)); | 1048 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 2), 2)); |
| 1039 | 1049 |
| 1040 connection2_->DoRunLoopUntilChangesCount(1); | 1050 connection2_->DoRunLoopUntilChangesCount(1); |
| 1041 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1051 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1042 ASSERT_EQ(1u, changes.size()); | 1052 ASSERT_EQ(1u, changes.size()); |
| 1043 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); | 1053 EXPECT_EQ("ServerChangeIdAdvanced 3", changes[0]); |
| 1044 } | 1054 } |
| 1045 | 1055 |
| 1046 // Parent 3 to 1. | 1056 // Parent 3 to 1. |
| 1047 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 3), 2)); | 1057 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 3), 3)); |
| 1048 connection2_->DoRunLoopUntilChangesCount(1); | 1058 connection2_->DoRunLoopUntilChangesCount(1); |
| 1049 | 1059 |
| 1050 // Set view 11 on node 3. | 1060 // Set view 11 on node 3. |
| 1051 { | 1061 { |
| 1052 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 3), BuildViewId(1, 11))); | 1062 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 3), BuildViewId(1, 11))); |
| 1053 | 1063 |
| 1054 connection2_->DoRunLoopUntilChangesCount(1); | 1064 connection2_->DoRunLoopUntilChangesCount(1); |
| 1055 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1065 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1056 ASSERT_EQ(1u, changes.size()); | 1066 ASSERT_EQ(1u, changes.size()); |
| 1057 EXPECT_EQ("ViewReplaced node=1,3 new_view=1,11 old_view=null", changes[0]); | 1067 EXPECT_EQ("ViewReplaced node=1,3 new_view=1,11 old_view=null", changes[0]); |
| 1058 } | 1068 } |
| 1059 | 1069 |
| 1060 // Delete 3. | 1070 // Delete 3. |
| 1061 { | 1071 { |
| 1062 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 3), 3)); | 1072 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 3), 4)); |
| 1063 | 1073 |
| 1064 connection2_->DoRunLoopUntilChangesCount(1); | 1074 connection2_->DoRunLoopUntilChangesCount(1); |
| 1065 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1075 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1066 ASSERT_EQ(1u, changes.size()); | 1076 ASSERT_EQ(1u, changes.size()); |
| 1067 EXPECT_EQ("NodeDeleted change_id=3 node=1,3", changes[0]); | 1077 EXPECT_EQ("NodeDeleted change_id=4 node=1,3", changes[0]); |
| 1068 } | 1078 } |
| 1069 } | 1079 } |
| 1070 | 1080 |
| 1071 // Sets view from one connection on another. | 1081 // Sets view from one connection on another. |
| 1072 TEST_F(ViewManagerTest, SetViewFromSecondConnection) { | 1082 TEST_F(ViewManagerTest, SetViewFromSecondConnection) { |
| 1073 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1083 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 1074 | 1084 |
| 1075 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1085 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 1076 | 1086 |
| 1077 // Create a view in the second connection. | 1087 // Create a view in the second connection. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1096 EXPECT_EQ("ViewDeleted view=2,51", changes[1]); | 1106 EXPECT_EQ("ViewDeleted view=2,51", changes[1]); |
| 1097 } | 1107 } |
| 1098 } | 1108 } |
| 1099 | 1109 |
| 1100 // Assertions for GetNodeTree. | 1110 // Assertions for GetNodeTree. |
| 1101 TEST_F(ViewManagerTest, GetNodeTree) { | 1111 TEST_F(ViewManagerTest, GetNodeTree) { |
| 1102 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1112 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 1103 | 1113 |
| 1104 // Create 11 in first connection and make it a child of 1. | 1114 // Create 11 in first connection and make it a child of 1. |
| 1105 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 11))); | 1115 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 11))); |
| 1106 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 1)); | 1116 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 2)); |
| 1107 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 11), 2)); | 1117 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 11), 3)); |
| 1108 | 1118 |
| 1109 // Create two nodes in second connection, 2 and 3, both children of 1. | 1119 // Create two nodes in second connection, 2 and 3, both children of 1. |
| 1110 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2))); | 1120 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2))); |
| 1111 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 3))); | 1121 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 3))); |
| 1112 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 2), 3)); | 1122 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 2), 4)); |
| 1113 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 3), 4)); | 1123 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 3), 5)); |
| 1114 | 1124 |
| 1115 // Attach view to node 11 in the first connection. | 1125 // Attach view to node 11 in the first connection. |
| 1116 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 51))); | 1126 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 51))); |
| 1117 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 11), BuildViewId(1, 51))); | 1127 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 11), BuildViewId(1, 51))); |
| 1118 | 1128 |
| 1119 // Verifies GetNodeTree() on the root. | 1129 // Verifies GetNodeTree() on the root. |
| 1120 { | 1130 { |
| 1121 std::vector<TestNode> nodes; | 1131 std::vector<TestNode> nodes; |
| 1122 connection_->GetNodeTree(BuildNodeId(0, 1), &nodes); | 1132 connection_->GetNodeTree(BuildNodeId(0, 1), &nodes); |
| 1123 ASSERT_EQ(5u, nodes.size()); | 1133 ASSERT_EQ(5u, nodes.size()); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1175 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1185 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 1176 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); | 1186 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); |
| 1177 | 1187 |
| 1178 // Parent 1 to the root. | 1188 // Parent 1 to the root. |
| 1179 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 1)); | 1189 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 1)); |
| 1180 | 1190 |
| 1181 // Establish the second connection with roots 1 and 3. | 1191 // Establish the second connection with roots 1 and 3. |
| 1182 { | 1192 { |
| 1183 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1193 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1184 | 1194 |
| 1185 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 3))); | 1195 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 3), kTestServiceURL)); |
| 1186 connection2_->DoRunLoopUntilChangesCount(1); | 1196 connection2_->DoRunLoopUntilChangesCount(1); |
| 1187 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1197 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1188 ASSERT_EQ(1u, changes.size()); | 1198 ASSERT_EQ(1u, changes.size()); |
| 1189 EXPECT_EQ("OnRootAdded", changes[0]); | 1199 EXPECT_EQ("OnRootAdded", changes[0]); |
| 1190 EXPECT_EQ("[node=1,3 parent=null view=null]", | 1200 EXPECT_EQ("[node=1,3 parent=null view=null]", |
| 1191 ChangeNodeDescription(connection2_->changes())); | 1201 ChangeNodeDescription(connection2_->changes())); |
| 1192 } | 1202 } |
| 1193 | 1203 |
| 1194 // Create 4 and add it to the root, connection 2 should only get id advanced. | 1204 // Create 4 and add it to the root, connection 2 should only get id advanced. |
| 1195 { | 1205 { |
| 1196 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 4))); | 1206 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 4))); |
| 1197 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 4), 2)); | 1207 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 4), 4)); |
| 1198 | 1208 |
| 1199 connection2_->DoRunLoopUntilChangesCount(1); | 1209 connection2_->DoRunLoopUntilChangesCount(1); |
| 1200 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1210 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1201 ASSERT_EQ(1u, changes.size()); | 1211 ASSERT_EQ(1u, changes.size()); |
| 1202 EXPECT_EQ("ServerChangeIdAdvanced 3", changes[0]); | 1212 EXPECT_EQ("ServerChangeIdAdvanced 5", changes[0]); |
| 1203 } | 1213 } |
| 1204 | 1214 |
| 1205 // Move 4 under 3, this should expose 4 to the client. | 1215 // Move 4 under 3, this should expose 4 to the client. |
| 1206 { | 1216 { |
| 1207 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 3), BuildNodeId(1, 4), 3)); | 1217 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 3), BuildNodeId(1, 4), 5)); |
| 1208 connection2_->DoRunLoopUntilChangesCount(1); | 1218 connection2_->DoRunLoopUntilChangesCount(1); |
| 1209 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1219 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1210 ASSERT_EQ(1u, changes.size()); | 1220 ASSERT_EQ(1u, changes.size()); |
| 1211 EXPECT_EQ( | 1221 EXPECT_EQ( |
| 1212 "HierarchyChanged change_id=3 node=1,4 new_parent=1,3 " | 1222 "HierarchyChanged change_id=5 node=1,4 new_parent=1,3 " |
| 1213 "old_parent=null", changes[0]); | 1223 "old_parent=null", changes[0]); |
| 1214 EXPECT_EQ("[node=1,4 parent=1,3 view=null]", | 1224 EXPECT_EQ("[node=1,4 parent=1,3 view=null]", |
| 1215 ChangeNodeDescription(connection2_->changes())); | 1225 ChangeNodeDescription(connection2_->changes())); |
| 1216 } | 1226 } |
| 1217 | 1227 |
| 1218 // Move 4 under 2, since 2 isn't a root client should get a delete. | 1228 // Move 4 under 2, since 2 isn't a root client should get a delete. |
| 1219 { | 1229 { |
| 1220 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 4), 4)); | 1230 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 4), 6)); |
| 1221 connection2_->DoRunLoopUntilChangesCount(1); | 1231 connection2_->DoRunLoopUntilChangesCount(1); |
| 1222 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1232 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1223 ASSERT_EQ(1u, changes.size()); | 1233 ASSERT_EQ(1u, changes.size()); |
| 1224 EXPECT_EQ("NodeDeleted change_id=4 node=1,4", changes[0]); | 1234 EXPECT_EQ("NodeDeleted change_id=6 node=1,4", changes[0]); |
| 1225 } | 1235 } |
| 1226 | 1236 |
| 1227 // Delete 4, client shouldn't receive a delete since it should no longer know | 1237 // Delete 4, client shouldn't receive a delete since it should no longer know |
| 1228 // about 4. | 1238 // about 4. |
| 1229 { | 1239 { |
| 1230 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 4), 5)); | 1240 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 4), 7)); |
| 1231 | 1241 |
| 1232 connection2_->DoRunLoopUntilChangesCount(1); | 1242 connection2_->DoRunLoopUntilChangesCount(1); |
| 1233 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1243 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1234 ASSERT_EQ(1u, changes.size()); | 1244 ASSERT_EQ(1u, changes.size()); |
| 1235 EXPECT_EQ("ServerChangeIdAdvanced 6", changes[0]); | 1245 EXPECT_EQ("ServerChangeIdAdvanced 8", changes[0]); |
| 1236 } | 1246 } |
| 1237 } | 1247 } |
| 1238 | 1248 |
| 1239 // Verify AddNode fails when trying to manipulate nodes in other roots. | 1249 // Verify AddNode fails when trying to manipulate nodes in other roots. |
| 1240 TEST_F(ViewManagerTest, CantMoveNodesFromOtherRoot) { | 1250 TEST_F(ViewManagerTest, CantMoveNodesFromOtherRoot) { |
| 1241 // Create 1 and 2 in the first connection. | 1251 // Create 1 and 2 in the first connection. |
| 1242 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1252 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| 1243 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1253 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 1244 | 1254 |
| 1245 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1255 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1260 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1270 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| 1261 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1271 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 1262 | 1272 |
| 1263 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 1)); | 1273 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 1)); |
| 1264 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 2), 2)); | 1274 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 2), 2)); |
| 1265 | 1275 |
| 1266 // Establish the second connection and give it the root 1. | 1276 // Establish the second connection and give it the root 1. |
| 1267 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1277 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1268 | 1278 |
| 1269 // Connection 2 should not be able to remove node 2 or 1 from its parent. | 1279 // Connection 2 should not be able to remove node 2 or 1 from its parent. |
| 1270 ASSERT_FALSE(connection2_->RemoveNodeFromParent(BuildNodeId(1, 2), 3)); | 1280 ASSERT_FALSE(connection2_->RemoveNodeFromParent(BuildNodeId(1, 2), 4)); |
| 1271 ASSERT_FALSE(connection2_->RemoveNodeFromParent(BuildNodeId(1, 1), 3)); | 1281 ASSERT_FALSE(connection2_->RemoveNodeFromParent(BuildNodeId(1, 1), 4)); |
| 1272 | 1282 |
| 1273 // Create nodes 10 and 11 in 2. | 1283 // Create nodes 10 and 11 in 2. |
| 1274 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 10))); | 1284 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 10))); |
| 1275 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 11))); | 1285 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 11))); |
| 1276 | 1286 |
| 1277 // Parent 11 to 10. | 1287 // Parent 11 to 10. |
| 1278 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(2, 10), BuildNodeId(2, 11), 3)); | 1288 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(2, 10), BuildNodeId(2, 11), 4)); |
| 1279 // Remove 11 from 10. | 1289 // Remove 11 from 10. |
| 1280 ASSERT_TRUE(connection2_->RemoveNodeFromParent( BuildNodeId(2, 11), 4)); | 1290 ASSERT_TRUE(connection2_->RemoveNodeFromParent( BuildNodeId(2, 11), 5)); |
| 1281 | 1291 |
| 1282 // Verify nothing was actually removed. | 1292 // Verify nothing was actually removed. |
| 1283 { | 1293 { |
| 1284 std::vector<TestNode> nodes; | 1294 std::vector<TestNode> nodes; |
| 1285 connection_->GetNodeTree(BuildNodeId(0, 1), &nodes); | 1295 connection_->GetNodeTree(BuildNodeId(0, 1), &nodes); |
| 1286 ASSERT_EQ(3u, nodes.size()); | 1296 ASSERT_EQ(3u, nodes.size()); |
| 1287 EXPECT_EQ("node=0,1 parent=null view=null", nodes[0].ToString()); | 1297 EXPECT_EQ("node=0,1 parent=null view=null", nodes[0].ToString()); |
| 1288 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[1].ToString()); | 1298 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[1].ToString()); |
| 1289 EXPECT_EQ("node=1,2 parent=0,1 view=null", nodes[2].ToString()); | 1299 EXPECT_EQ("node=1,2 parent=0,1 view=null", nodes[2].ToString()); |
| 1290 } | 1300 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1341 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1351 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| 1342 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1352 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 1343 | 1353 |
| 1344 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 1)); | 1354 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 1)); |
| 1345 | 1355 |
| 1346 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1356 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1347 | 1357 |
| 1348 // Try to connect again to 1,1, this should fail as already connected to that | 1358 // Try to connect again to 1,1, this should fail as already connected to that |
| 1349 // root. | 1359 // root. |
| 1350 { | 1360 { |
| 1351 ASSERT_FALSE(connection_->Embed(BuildNodeId(1, 1))); | 1361 ASSERT_FALSE(connection_->Embed(BuildNodeId(1, 1), kTestServiceURL)); |
| 1352 } | 1362 } |
| 1353 | 1363 |
| 1354 // Connecting to 1,2 should succeed and end up in connection2. | 1364 // Connecting to 1,2 should succeed and end up in connection2. |
| 1355 { | 1365 { |
| 1356 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 2))); | 1366 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 2), kTestServiceURL)); |
| 1357 connection2_->DoRunLoopUntilChangesCount(1); | 1367 connection2_->DoRunLoopUntilChangesCount(1); |
| 1358 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1368 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1359 ASSERT_EQ(1u, changes.size()); | 1369 ASSERT_EQ(1u, changes.size()); |
| 1360 EXPECT_EQ("OnRootAdded", changes[0]); | 1370 EXPECT_EQ("OnRootAdded", changes[0]); |
| 1361 EXPECT_EQ("[node=1,2 parent=1,1 view=null]", | 1371 EXPECT_EQ("[node=1,2 parent=1,1 view=null]", |
| 1362 ChangeNodeDescription(connection2_->changes())); | 1372 ChangeNodeDescription(connection2_->changes())); |
| 1363 } | 1373 } |
| 1364 } | 1374 } |
| 1365 | 1375 |
| 1366 TEST_F(ViewManagerTest, OnViewInput) { | 1376 TEST_F(ViewManagerTest, OnViewInput) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1377 connection_->view_manager()->DispatchOnViewInputEvent( | 1387 connection_->view_manager()->DispatchOnViewInputEvent( |
| 1378 BuildViewId(2, 11), | 1388 BuildViewId(2, 11), |
| 1379 event.Pass()); | 1389 event.Pass()); |
| 1380 connection2_->DoRunLoopUntilChangesCount(1); | 1390 connection2_->DoRunLoopUntilChangesCount(1); |
| 1381 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1391 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1382 ASSERT_EQ(1u, changes.size()); | 1392 ASSERT_EQ(1u, changes.size()); |
| 1383 EXPECT_EQ("InputEvent view=2,11 event_action=1", changes[0]); | 1393 EXPECT_EQ("InputEvent view=2,11 event_action=1", changes[0]); |
| 1384 } | 1394 } |
| 1385 } | 1395 } |
| 1386 | 1396 |
| 1397 TEST_F(ViewManagerTest, EmbedWithSameNodeId) { |
| 1398 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 1399 |
| 1400 // Create a third connection. |
| 1401 ViewManagerProxy* connection3 = NULL; |
| 1402 { |
| 1403 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 1), kTestServiceURL2)); |
| 1404 connection3 = ViewManagerProxy::WaitForInstance(); |
| 1405 ASSERT_TRUE(connection3 != NULL); |
| 1406 connection3->DoRunLoopUntilChangesCount(1); |
| 1407 const Changes changes(ChangesToDescription1(connection3->changes())); |
| 1408 ASSERT_EQ(1u, changes.size()); |
| 1409 EXPECT_EQ("OnConnectionEstablished creator=mojo:test_url", changes[0]); |
| 1410 } |
| 1411 |
| 1412 // Connection2 should have been told the node was deleted. |
| 1413 { |
| 1414 connection2_->DoRunLoopUntilChangesCount(1); |
| 1415 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1416 ASSERT_EQ(1u, changes.size()); |
| 1417 EXPECT_EQ("NodeDeleted change_id=2 node=1,1", changes[0]); |
| 1418 } |
| 1419 |
| 1420 // Connection2 has no root. Verify it can't see node 1,1 anymore. |
| 1421 { |
| 1422 std::vector<TestNode> nodes; |
| 1423 connection2_->GetNodeTree(BuildNodeId(1, 1), &nodes); |
| 1424 EXPECT_TRUE(nodes.empty()); |
| 1425 } |
| 1426 |
| 1427 connection3->Destroy(); |
| 1428 } |
| 1429 |
| 1430 TEST_F(ViewManagerTest, EmbedWithSameNodeId2) { |
| 1431 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 1432 |
| 1433 // Create a third connection. |
| 1434 ViewManagerProxy* connection3 = NULL; |
| 1435 { |
| 1436 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 1), kTestServiceURL2)); |
| 1437 connection3 = ViewManagerProxy::WaitForInstance(); |
| 1438 ASSERT_TRUE(connection3 != NULL); |
| 1439 connection3->DoRunLoopUntilChangesCount(1); |
| 1440 const Changes changes(ChangesToDescription1(connection3->changes())); |
| 1441 ASSERT_EQ(1u, changes.size()); |
| 1442 EXPECT_EQ("OnConnectionEstablished creator=mojo:test_url", changes[0]); |
| 1443 } |
| 1444 |
| 1445 // Connection2 should have been told the node was deleted. |
| 1446 connection2_->DoRunLoopUntilChangesCount(1); |
| 1447 connection2_->ClearChanges(); |
| 1448 |
| 1449 // Create a node in the third connection and parent it to the root. |
| 1450 ASSERT_TRUE(connection3->CreateNode(BuildNodeId(3, 1))); |
| 1451 ASSERT_TRUE(connection3->AddNode(BuildNodeId(1, 1), BuildNodeId(3, 1), 3)); |
| 1452 |
| 1453 // Connection 1 should have been told about the add (it owns the node). |
| 1454 { |
| 1455 connection_->DoRunLoopUntilChangesCount(1); |
| 1456 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 1457 ASSERT_EQ(1u, changes.size()); |
| 1458 EXPECT_EQ( |
| 1459 "HierarchyChanged change_id=3 node=3,1 new_parent=1,1 old_parent=null", |
| 1460 changes[0]); |
| 1461 } |
| 1462 |
| 1463 // connection2_ should get an advance. |
| 1464 connection2_->DoRunLoopUntilChangesCount(1); |
| 1465 connection2_->ClearChanges(); |
| 1466 |
| 1467 // Embed 1,1 back in connection 2. |
| 1468 { |
| 1469 // 2 should be told about the new embed. |
| 1470 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 1), kTestServiceURL)); |
| 1471 connection2_->DoRunLoopUntilChangesCount(1); |
| 1472 const std::vector<Change>& changes(connection2_->changes()); |
| 1473 ASSERT_EQ(1u, changes.size()); |
| 1474 EXPECT_EQ("OnRootAdded", ChangesToDescription1(changes)[0]); |
| 1475 EXPECT_EQ("[node=1,1 parent=null view=null]", |
| 1476 ChangeNodeDescription(changes)); |
| 1477 |
| 1478 // And 3 should get a delete. |
| 1479 connection3->DoRunLoopUntilChangesCount(1); |
| 1480 ASSERT_EQ(1u, connection3->changes().size()); |
| 1481 EXPECT_EQ("NodeDeleted change_id=4 node=1,1", |
| 1482 ChangesToDescription1(connection3->changes())[0]); |
| 1483 } |
| 1484 |
| 1485 // Connection3 has no root. Verify it can't see node 1,1 anymore. |
| 1486 { |
| 1487 std::vector<TestNode> nodes; |
| 1488 connection3->GetNodeTree(BuildNodeId(1, 1), &nodes); |
| 1489 EXPECT_TRUE(nodes.empty()); |
| 1490 } |
| 1491 |
| 1492 // Verify 3,1 is no longer parented to 1,1. We have to do this from 1,1 as |
| 1493 // connection3 can no longer see 1,1. |
| 1494 { |
| 1495 std::vector<TestNode> nodes; |
| 1496 connection_->GetNodeTree(BuildNodeId(1, 1), &nodes); |
| 1497 ASSERT_EQ(1u, nodes.size()); |
| 1498 EXPECT_EQ("node=1,1 parent=null view=null", nodes[0].ToString()); |
| 1499 } |
| 1500 |
| 1501 // Verify connection3 can still see the node it created 3,1. |
| 1502 { |
| 1503 std::vector<TestNode> nodes; |
| 1504 connection3->GetNodeTree(BuildNodeId(3, 1), &nodes); |
| 1505 ASSERT_EQ(1u, nodes.size()); |
| 1506 EXPECT_EQ("node=3,1 parent=null view=null", nodes[0].ToString()); |
| 1507 } |
| 1508 |
| 1509 connection3->Destroy(); |
| 1510 } |
| 1511 |
| 1387 // TODO(sky): add coverage of test that destroys connections and ensures other | 1512 // TODO(sky): add coverage of test that destroys connections and ensures other |
| 1388 // connections get deletion notification (or advanced server id). | 1513 // connections get deletion notification (or advanced server id). |
| 1389 | 1514 |
| 1390 // TODO(sky): need to better track changes to initial connection. For example, | 1515 // TODO(sky): need to better track changes to initial connection. For example, |
| 1391 // that SetBounsdNodes/AddNode and the like don't result in messages to the | 1516 // that SetBounsdNodes/AddNode and the like don't result in messages to the |
| 1392 // originating connection. | 1517 // originating connection. |
| 1393 | 1518 |
| 1394 // TODO(beng): Add tests for focus: | 1519 // TODO(beng): Add tests for focus: |
| 1395 // - focus between two nodes known to a connection | 1520 // - focus between two nodes known to a connection |
| 1396 // - focus between nodes unknown to one of the connections. | 1521 // - focus between nodes unknown to one of the connections. |
| 1397 // - focus between nodes unknown to either connection. | 1522 // - focus between nodes unknown to either connection. |
| 1398 | 1523 |
| 1399 } // namespace service | 1524 } // namespace service |
| 1400 } // namespace view_manager | 1525 } // namespace view_manager |
| 1401 } // namespace mojo | 1526 } // namespace mojo |
| OLD | NEW |