| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 // Destroys the connection, blocking until done. | 87 // Destroys the connection, blocking until done. |
| 88 void Destroy() { | 88 void Destroy() { |
| 89 router_->CloseMessagePipe(); | 89 router_->CloseMessagePipe(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void ClearChanges() { | 92 void ClearChanges() { |
| 93 changes_.clear(); | 93 changes_.clear(); |
| 94 tracker_->changes()->clear(); | 94 tracker_->changes()->clear(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void CopyChangesFromTracker() { |
| 98 std::vector<Change> changes; |
| 99 tracker_->changes()->swap(changes); |
| 100 changes_.swap(changes); |
| 101 } |
| 102 |
| 97 // The following functions are cover methods for ViewManagerService. They | 103 // The following functions are cover methods for ViewManagerService. They |
| 98 // block until the result is received. | 104 // block until the result is received. |
| 99 bool CreateNode(Id node_id) { | 105 bool CreateNode(Id node_id) { |
| 100 changes_.clear(); | 106 changes_.clear(); |
| 101 ErrorCode result = ERROR_CODE_NONE; | 107 ErrorCode result = ERROR_CODE_NONE; |
| 102 view_manager_->CreateNode( | 108 view_manager_->CreateNode( |
| 103 node_id, | 109 node_id, |
| 104 base::Bind(&ViewManagerProxy::GotResultWithErrorCode, | 110 base::Bind(&ViewManagerProxy::GotResultWithErrorCode, |
| 105 base::Unretained(this), &result)); | 111 base::Unretained(this), &result)); |
| 106 RunMainLoop(); | 112 RunMainLoop(); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 main_run_loop_->Run(); | 229 main_run_loop_->Run(); |
| 224 delete main_run_loop_; | 230 delete main_run_loop_; |
| 225 main_run_loop_ = NULL; | 231 main_run_loop_ = NULL; |
| 226 } | 232 } |
| 227 | 233 |
| 228 void QuitCountReached() { | 234 void QuitCountReached() { |
| 229 CopyChangesFromTracker(); | 235 CopyChangesFromTracker(); |
| 230 main_run_loop_->Quit(); | 236 main_run_loop_->Quit(); |
| 231 } | 237 } |
| 232 | 238 |
| 233 void CopyChangesFromTracker() { | |
| 234 std::vector<Change> changes; | |
| 235 tracker_->changes()->swap(changes); | |
| 236 changes_.swap(changes); | |
| 237 } | |
| 238 | |
| 239 static void SetInstance(ViewManagerProxy* instance) { | 239 static void SetInstance(ViewManagerProxy* instance) { |
| 240 DCHECK(!instance_); | 240 DCHECK(!instance_); |
| 241 instance_ = instance; | 241 instance_ = instance; |
| 242 // Embed() runs its own run loop that is quit when the result is | 242 // Embed() runs its own run loop that is quit when the result is |
| 243 // received. Embed() also results in a new instance. If we quit here while | 243 // received. Embed() also results in a new instance. If we quit here while |
| 244 // waiting for a Embed() we would prematurely return before we got the | 244 // waiting for a Embed() we would prematurely return before we got the |
| 245 // result from Embed(). | 245 // result from Embed(). |
| 246 if (!in_embed_ && main_run_loop_) | 246 if (!in_embed_ && main_run_loop_) |
| 247 main_run_loop_->Quit(); | 247 main_run_loop_->Quit(); |
| 248 } | 248 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 | 299 |
| 300 // static | 300 // static |
| 301 base::RunLoop* ViewManagerProxy::main_run_loop_ = NULL; | 301 base::RunLoop* ViewManagerProxy::main_run_loop_ = NULL; |
| 302 | 302 |
| 303 // static | 303 // static |
| 304 bool ViewManagerProxy::in_embed_ = false; | 304 bool ViewManagerProxy::in_embed_ = false; |
| 305 | 305 |
| 306 class TestViewManagerClientConnection | 306 class TestViewManagerClientConnection |
| 307 : public InterfaceImpl<ViewManagerClient> { | 307 : public InterfaceImpl<ViewManagerClient> { |
| 308 public: | 308 public: |
| 309 explicit TestViewManagerClientConnection() : connection_(&tracker_) { | 309 TestViewManagerClientConnection() : connection_(&tracker_) { |
| 310 tracker_.set_delegate(&connection_); | 310 tracker_.set_delegate(&connection_); |
| 311 } | 311 } |
| 312 | 312 |
| 313 // InterfaceImp: | 313 // InterfaceImp: |
| 314 virtual void OnConnectionEstablished() OVERRIDE { | 314 virtual void OnConnectionEstablished() OVERRIDE { |
| 315 connection_.set_router(internal_state()->router()); | 315 connection_.set_router(internal_state()->router()); |
| 316 connection_.set_view_manager(client()); | 316 connection_.set_view_manager(client()); |
| 317 } | 317 } |
| 318 | 318 |
| 319 // ViewManagerClient: | 319 // ViewManagerClient: |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 TEST_F(ViewManagerTest, AddToRoot) { | 771 TEST_F(ViewManagerTest, AddToRoot) { |
| 772 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 21))); | 772 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 21))); |
| 773 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); | 773 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); |
| 774 | 774 |
| 775 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 775 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 776 | 776 |
| 777 // Make 3 a child of 21. | 777 // Make 3 a child of 21. |
| 778 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 21), BuildNodeId(1, 3))); | 778 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 21), BuildNodeId(1, 3))); |
| 779 | 779 |
| 780 // Make 21 a child of 1. | 780 // Make 21 a child of 1. |
| 781 { | 781 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 21))); |
| 782 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 21))); | |
| 783 | 782 |
| 784 connection2_->DoRunLoopUntilChangesCount(1); | 783 // Connection 2 should not be told anything (because the node is from a |
| 785 const Changes changes(ChangesToDescription1(connection2_->changes())); | 784 // different connection). Create a node to ensure we got a response from |
| 786 ASSERT_EQ(1u, changes.size()); | 785 // the server. |
| 787 EXPECT_EQ("HierarchyChanged node=1,21 new_parent=1,1 old_parent=null", | 786 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 100))); |
| 788 changes[0]); | 787 connection2_->CopyChangesFromTracker(); |
| 789 } | 788 EXPECT_TRUE(connection2_->changes().empty()); |
| 790 } | 789 } |
| 791 | 790 |
| 792 // Verifies HierarchyChanged is correctly sent for various adds/removes. | 791 // Verifies HierarchyChanged is correctly sent for various adds/removes. |
| 793 TEST_F(ViewManagerTest, NodeHierarchyChangedNodes) { | 792 TEST_F(ViewManagerTest, NodeHierarchyChangedNodes) { |
| 793 // 1,2->1,11. |
| 794 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 794 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 795 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 11))); | 795 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 11))); |
| 796 // Make 11 a child of 2. | |
| 797 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 11))); | 796 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 11))); |
| 798 | 797 |
| 799 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 798 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 800 | 799 |
| 801 // Make 2 a child of 1. | 800 // 1,1->1,2->1,11 |
| 802 { | 801 { |
| 802 // Client 2 should not get anything (1,2 is from another connection). |
| 803 connection2_->ClearChanges(); |
| 803 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2))); | 804 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2))); |
| 804 | 805 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 100))); |
| 805 // Client 2 should get a hierarchy change that includes the new nodes as it | 806 connection2_->CopyChangesFromTracker(); |
| 806 // has not yet seen them. | 807 EXPECT_TRUE(connection2_->changes().empty()); |
| 807 connection2_->DoRunLoopUntilChangesCount(1); | |
| 808 const Changes changes(ChangesToDescription1(connection2_->changes())); | |
| 809 ASSERT_EQ(1u, changes.size()); | |
| 810 EXPECT_EQ( | |
| 811 "HierarchyChanged node=1,2 new_parent=1,1 old_parent=null", changes[0]); | |
| 812 EXPECT_EQ("[node=1,2 parent=1,1 view=null]," | |
| 813 "[node=1,11 parent=1,2 view=null]", | |
| 814 ChangeNodeDescription(connection2_->changes())); | |
| 815 } | 808 } |
| 816 | 809 |
| 817 // Add 1 to the root. | 810 // 0,1->1,1->1,2->1,11. |
| 818 { | 811 { |
| 812 // Again, client 2 should not get anything. |
| 813 connection2_->ClearChanges(); |
| 819 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); | 814 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); |
| 820 | 815 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 101))); |
| 821 // Client 2 should get a hierarchy change that includes the new nodes as it | 816 connection2_->CopyChangesFromTracker(); |
| 822 // has not yet seen them. | 817 EXPECT_TRUE(connection2_->changes().empty()); |
| 823 connection2_->DoRunLoopUntilChangesCount(1); | |
| 824 const Changes changes(ChangesToDescription1(connection2_->changes())); | |
| 825 ASSERT_EQ(1u, changes.size()); | |
| 826 EXPECT_EQ("HierarchyChanged node=1,1 new_parent=null old_parent=null", | |
| 827 changes[0]); | |
| 828 EXPECT_EQ(std::string(), ChangeNodeDescription(connection2_->changes())); | |
| 829 } | 818 } |
| 830 | 819 |
| 831 // Remove 1 from its parent. | 820 // 1,1->1,2->1,11. |
| 832 { | 821 { |
| 822 connection2_->ClearChanges(); |
| 833 ASSERT_TRUE(connection_->RemoveNodeFromParent(BuildNodeId(1, 1))); | 823 ASSERT_TRUE(connection_->RemoveNodeFromParent(BuildNodeId(1, 1))); |
| 834 EXPECT_TRUE(connection_->changes().empty()); | 824 EXPECT_TRUE(connection_->changes().empty()); |
| 835 | 825 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 102))); |
| 836 connection2_->DoRunLoopUntilChangesCount(1); | 826 connection2_->CopyChangesFromTracker(); |
| 837 const Changes changes(ChangesToDescription1(connection2_->changes())); | 827 EXPECT_TRUE(connection2_->changes().empty()); |
| 838 ASSERT_EQ(1u, changes.size()); | |
| 839 EXPECT_EQ("HierarchyChanged node=1,1 new_parent=null old_parent=null", | |
| 840 changes[0]); | |
| 841 } | 828 } |
| 842 | 829 |
| 843 // Create another node, 111, parent it to 11. | 830 // 1,1->1,2->1,11->1,111. |
| 844 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 111))); | 831 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 111))); |
| 845 { | 832 { |
| 833 connection2_->ClearChanges(); |
| 846 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 11), BuildNodeId(1, 111))); | 834 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 11), BuildNodeId(1, 111))); |
| 847 | 835 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 103))); |
| 848 connection2_->DoRunLoopUntilChangesCount(1); | 836 connection2_->CopyChangesFromTracker(); |
| 849 const Changes changes(ChangesToDescription1(connection2_->changes())); | 837 EXPECT_TRUE(connection2_->changes().empty()); |
| 850 ASSERT_EQ(1u, changes.size()); | |
| 851 EXPECT_EQ("HierarchyChanged node=1,111 new_parent=1,11 old_parent=null", | |
| 852 changes[0]); | |
| 853 EXPECT_EQ("[node=1,111 parent=1,11 view=null]", | |
| 854 ChangeNodeDescription(connection2_->changes())); | |
| 855 } | 838 } |
| 856 | 839 |
| 857 // Reattach 1 to the root. | 840 // 0,1->1,1->1,2->1,11->1,111 |
| 858 { | 841 { |
| 842 connection2_->ClearChanges(); |
| 859 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); | 843 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); |
| 860 | 844 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 104))); |
| 861 connection2_->DoRunLoopUntilChangesCount(1); | 845 connection2_->CopyChangesFromTracker(); |
| 862 const Changes changes(ChangesToDescription1(connection2_->changes())); | 846 EXPECT_TRUE(connection2_->changes().empty()); |
| 863 ASSERT_EQ(1u, changes.size()); | |
| 864 EXPECT_EQ("HierarchyChanged node=1,1 new_parent=null old_parent=null", | |
| 865 changes[0]); | |
| 866 EXPECT_EQ(std::string(), ChangeNodeDescription(connection2_->changes())); | |
| 867 } | 847 } |
| 868 } | 848 } |
| 869 | 849 |
| 870 TEST_F(ViewManagerTest, NodeHierarchyChangedAddingKnownToUnknown) { | 850 TEST_F(ViewManagerTest, NodeHierarchyChangedAddingKnownToUnknown) { |
| 871 // Create the following structure: root -> 1 -> 11 and 2->21 (2 has no | 851 // Create the following structure: root -> 1 -> 11 and 2->21 (2 has no |
| 872 // parent). | 852 // parent). |
| 873 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 853 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 874 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 11))); | 854 |
| 875 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 855 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 11))); |
| 876 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 21))); | 856 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2))); |
| 857 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 21))); |
| 877 | 858 |
| 878 // Set up the hierarchy. | 859 // Set up the hierarchy. |
| 879 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); | 860 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); |
| 880 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 11))); | 861 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 11))); |
| 881 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 21))); | 862 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(2, 2), BuildNodeId(2, 21))); |
| 882 | 863 |
| 883 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 864 // Remove 11, should result in a hierarchy change for the root. |
| 884 EXPECT_EQ("[node=1,1 parent=null view=null]," | 865 { |
| 885 "[node=1,11 parent=1,1 view=null]", | 866 connection_->ClearChanges(); |
| 886 ChangeNodeDescription(connection2_->changes())); | 867 ASSERT_TRUE(connection2_->RemoveNodeFromParent(BuildNodeId(2, 11))); |
| 887 | 868 |
| 888 // Remove 11, should result in a delete (since 11 is no longer in connection | 869 connection_->DoRunLoopUntilChangesCount(1); |
| 889 // 2's root). | 870 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 890 { | |
| 891 ASSERT_TRUE(connection_->RemoveNodeFromParent(BuildNodeId(1, 11))); | |
| 892 | |
| 893 connection2_->DoRunLoopUntilChangesCount(1); | |
| 894 const Changes changes(ChangesToDescription1(connection2_->changes())); | |
| 895 ASSERT_EQ(1u, changes.size()); | 871 ASSERT_EQ(1u, changes.size()); |
| 896 EXPECT_EQ("NodeDeleted node=1,11", changes[0]); | 872 EXPECT_EQ("HierarchyChanged node=2,11 new_parent=null old_parent=1,1", |
| 873 changes[0]); |
| 897 } | 874 } |
| 898 | 875 |
| 899 // Add 2 to 1. | 876 // Add 2 to 1. |
| 900 { | 877 { |
| 901 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2))); | 878 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 2))); |
| 902 | 879 |
| 903 connection2_->DoRunLoopUntilChangesCount(1); | 880 connection_->DoRunLoopUntilChangesCount(1); |
| 904 const Changes changes(ChangesToDescription1(connection2_->changes())); | 881 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 905 ASSERT_EQ(1u, changes.size()); | 882 ASSERT_EQ(1u, changes.size()); |
| 906 EXPECT_EQ("HierarchyChanged node=1,2 new_parent=1,1 old_parent=null", | 883 EXPECT_EQ("HierarchyChanged node=2,2 new_parent=1,1 old_parent=null", |
| 907 changes[0]); | 884 changes[0]); |
| 908 EXPECT_EQ("[node=1,2 parent=1,1 view=null]," | 885 EXPECT_EQ("[node=2,2 parent=1,1 view=null]," |
| 909 "[node=1,21 parent=1,2 view=null]", | 886 "[node=2,21 parent=2,2 view=null]", |
| 910 ChangeNodeDescription(connection2_->changes())); | 887 ChangeNodeDescription(connection_->changes())); |
| 911 } | 888 } |
| 912 } | 889 } |
| 913 | 890 |
| 914 TEST_F(ViewManagerTest, ReorderNode) { | 891 TEST_F(ViewManagerTest, ReorderNode) { |
| 915 Id node1_id = BuildNodeId(1, 1); | 892 Id node1_id = BuildNodeId(1, 1); |
| 916 Id node2_id = BuildNodeId(1, 2); | 893 Id node2_id = BuildNodeId(1, 2); |
| 917 Id node3_id = BuildNodeId(1, 3); | 894 Id node3_id = BuildNodeId(1, 3); |
| 918 Id node4_id = BuildNodeId(1, 4); // Peer to 1,1 | 895 Id node4_id = BuildNodeId(1, 4); // Peer to 1,1 |
| 919 Id node5_id = BuildNodeId(1, 5); // Peer to 1,1 | 896 Id node5_id = BuildNodeId(1, 5); // Peer to 1,1 |
| 920 Id node6_id = BuildNodeId(1, 6); // Child of 1,2. | 897 Id node6_id = BuildNodeId(1, 6); // Child of 1,2. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 EXPECT_FALSE(connection_->ReorderNode( | 951 EXPECT_FALSE(connection_->ReorderNode( |
| 975 BuildNodeId(1, 27), BuildNodeId(1, 28), ORDER_DIRECTION_ABOVE)); | 952 BuildNodeId(1, 27), BuildNodeId(1, 28), ORDER_DIRECTION_ABOVE)); |
| 976 | 953 |
| 977 // node7 & node8 are un-parented. | 954 // node7 & node8 are un-parented. |
| 978 EXPECT_FALSE( | 955 EXPECT_FALSE( |
| 979 connection_->ReorderNode(node7_id, node8_id, ORDER_DIRECTION_ABOVE)); | 956 connection_->ReorderNode(node7_id, node8_id, ORDER_DIRECTION_ABOVE)); |
| 980 } | 957 } |
| 981 | 958 |
| 982 // Verifies DeleteNode works. | 959 // Verifies DeleteNode works. |
| 983 TEST_F(ViewManagerTest, DeleteNode) { | 960 TEST_F(ViewManagerTest, DeleteNode) { |
| 984 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | |
| 985 | |
| 986 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 961 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 962 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2))); |
| 987 | 963 |
| 988 // Make 2 a child of 1. | 964 // Make 2 a child of 1. |
| 989 { | 965 { |
| 990 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2))); | 966 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 2))); |
| 991 connection2_->DoRunLoopUntilChangesCount(1); | 967 connection_->DoRunLoopUntilChangesCount(1); |
| 992 const Changes changes(ChangesToDescription1(connection2_->changes())); | 968 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 993 ASSERT_EQ(1u, changes.size()); | 969 ASSERT_EQ(1u, changes.size()); |
| 994 EXPECT_EQ("HierarchyChanged node=1,2 new_parent=1,1 old_parent=null", | 970 EXPECT_EQ("HierarchyChanged node=2,2 new_parent=1,1 old_parent=null", |
| 995 changes[0]); | 971 changes[0]); |
| 996 } | 972 } |
| 997 | 973 |
| 998 // Delete 2. | 974 // Delete 2. |
| 999 { | 975 { |
| 1000 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 2))); | 976 ASSERT_TRUE(connection2_->DeleteNode(BuildNodeId(2, 2))); |
| 1001 EXPECT_TRUE(connection_->changes().empty()); | 977 EXPECT_TRUE(connection2_->changes().empty()); |
| 1002 | 978 |
| 1003 connection2_->DoRunLoopUntilChangesCount(1); | 979 connection_->DoRunLoopUntilChangesCount(1); |
| 1004 const Changes changes(ChangesToDescription1(connection2_->changes())); | 980 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 1005 ASSERT_EQ(1u, changes.size()); | 981 ASSERT_EQ(1u, changes.size()); |
| 1006 EXPECT_EQ("NodeDeleted node=1,2", changes[0]); | 982 EXPECT_EQ("NodeDeleted node=2,2", changes[0]); |
| 1007 } | 983 } |
| 1008 } | 984 } |
| 1009 | 985 |
| 1010 // Verifies DeleteNode isn't allowed from a separate connection. | 986 // Verifies DeleteNode isn't allowed from a separate connection. |
| 1011 TEST_F(ViewManagerTest, DeleteNodeFromAnotherConnectionDisallowed) { | 987 TEST_F(ViewManagerTest, DeleteNodeFromAnotherConnectionDisallowed) { |
| 1012 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 988 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 1013 EXPECT_FALSE(connection2_->DeleteNode(BuildNodeId(1, 1))); | 989 EXPECT_FALSE(connection2_->DeleteNode(BuildNodeId(1, 1))); |
| 1014 } | 990 } |
| 1015 | 991 |
| 1016 // Verifies DeleteView isn't allowed from a separate connection. | 992 // Verifies DeleteView isn't allowed from a separate connection. |
| 1017 TEST_F(ViewManagerTest, DeleteViewFromAnotherConnectionDisallowed) { | 993 TEST_F(ViewManagerTest, DeleteViewFromAnotherConnectionDisallowed) { |
| 1018 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); | 994 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); |
| 1019 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 995 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 1020 EXPECT_FALSE(connection2_->DeleteView(BuildViewId(1, 1))); | 996 EXPECT_FALSE(connection2_->DeleteView(BuildViewId(1, 1))); |
| 1021 } | 997 } |
| 1022 | 998 |
| 1023 // Verifies if a node was deleted and then reused that other clients are | 999 // Verifies if a node was deleted and then reused that other clients are |
| 1024 // properly notified. | 1000 // properly notified. |
| 1025 TEST_F(ViewManagerTest, ReuseDeletedNodeId) { | 1001 TEST_F(ViewManagerTest, ReuseDeletedNodeId) { |
| 1026 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1002 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 1027 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1003 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2))); |
| 1028 | 1004 |
| 1029 // Add 2 to 1. | 1005 // Add 2 to 1. |
| 1030 { | 1006 { |
| 1031 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2))); | 1007 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 2))); |
| 1032 | 1008 |
| 1033 connection2_->DoRunLoopUntilChangesCount(1); | 1009 connection_->DoRunLoopUntilChangesCount(1); |
| 1034 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1010 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 1035 EXPECT_EQ("HierarchyChanged node=1,2 new_parent=1,1 old_parent=null", | 1011 EXPECT_EQ("HierarchyChanged node=2,2 new_parent=1,1 old_parent=null", |
| 1036 changes[0]); | 1012 changes[0]); |
| 1037 EXPECT_EQ("[node=1,2 parent=1,1 view=null]", | 1013 EXPECT_EQ("[node=2,2 parent=1,1 view=null]", |
| 1038 ChangeNodeDescription(connection2_->changes())); | 1014 ChangeNodeDescription(connection_->changes())); |
| 1039 } | 1015 } |
| 1040 | 1016 |
| 1041 // Delete 2. | 1017 // Delete 2. |
| 1042 { | 1018 { |
| 1043 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 2))); | 1019 ASSERT_TRUE(connection2_->DeleteNode(BuildNodeId(2, 2))); |
| 1044 | 1020 |
| 1045 connection2_->DoRunLoopUntilChangesCount(1); | 1021 connection_->DoRunLoopUntilChangesCount(1); |
| 1046 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1022 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 1047 ASSERT_EQ(1u, changes.size()); | 1023 ASSERT_EQ(1u, changes.size()); |
| 1048 EXPECT_EQ("NodeDeleted node=1,2", changes[0]); | 1024 EXPECT_EQ("NodeDeleted node=2,2", changes[0]); |
| 1049 } | 1025 } |
| 1050 | 1026 |
| 1051 // Create 2 again, and add it back to 1. Should get the same notification. | 1027 // Create 2 again, and add it back to 1. Should get the same notification. |
| 1052 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1028 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2))); |
| 1053 { | 1029 { |
| 1054 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2))); | 1030 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 2))); |
| 1055 | 1031 |
| 1056 connection2_->DoRunLoopUntilChangesCount(1); | 1032 connection_->DoRunLoopUntilChangesCount(1); |
| 1057 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1033 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 1058 EXPECT_EQ("HierarchyChanged node=1,2 new_parent=1,1 old_parent=null", | 1034 EXPECT_EQ("HierarchyChanged node=2,2 new_parent=1,1 old_parent=null", |
| 1059 changes[0]); | 1035 changes[0]); |
| 1060 EXPECT_EQ("[node=1,2 parent=1,1 view=null]", | 1036 EXPECT_EQ("[node=2,2 parent=1,1 view=null]", |
| 1061 ChangeNodeDescription(connection2_->changes())); | 1037 ChangeNodeDescription(connection_->changes())); |
| 1062 } | 1038 } |
| 1063 } | 1039 } |
| 1064 | 1040 |
| 1065 // Assertions around setting a view. | 1041 // Assertions around setting a view. |
| 1066 TEST_F(ViewManagerTest, SetView) { | 1042 TEST_F(ViewManagerTest, SetView) { |
| 1067 // Create nodes 1, 2 and 3 and the view 11. Nodes 2 and 3 are parented to 1. | 1043 // Create nodes 1, 2 and 3 and the view 11. Nodes 2 and 3 are parented to 1. |
| 1068 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1044 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| 1069 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1045 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 1070 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); | 1046 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); |
| 1071 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 11))); | 1047 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 11))); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1095 ASSERT_EQ(2u, changes.size()); | 1071 ASSERT_EQ(2u, changes.size()); |
| 1096 EXPECT_EQ("ViewReplaced node=1,1 new_view=null old_view=1,11", | 1072 EXPECT_EQ("ViewReplaced node=1,1 new_view=null old_view=1,11", |
| 1097 changes[0]); | 1073 changes[0]); |
| 1098 EXPECT_EQ("ViewReplaced node=1,2 new_view=1,11 old_view=null", | 1074 EXPECT_EQ("ViewReplaced node=1,2 new_view=1,11 old_view=null", |
| 1099 changes[1]); | 1075 changes[1]); |
| 1100 } | 1076 } |
| 1101 } | 1077 } |
| 1102 | 1078 |
| 1103 // Verifies deleting a node with a view sends correct notifications. | 1079 // Verifies deleting a node with a view sends correct notifications. |
| 1104 TEST_F(ViewManagerTest, DeleteNodeWithView) { | 1080 TEST_F(ViewManagerTest, DeleteNodeWithView) { |
| 1105 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1081 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 1106 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1082 |
| 1107 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); | 1083 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2))); |
| 1108 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 11))); | 1084 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 3))); |
| 1085 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 11))); |
| 1109 | 1086 |
| 1110 // Set view 11 on node 2. | 1087 // Set view 11 on node 2. |
| 1111 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 2), BuildViewId(1, 11))); | 1088 ASSERT_TRUE(connection2_->SetView(BuildNodeId(2, 2), BuildViewId(2, 11))); |
| 1112 | 1089 |
| 1113 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1090 // Delete node 2. Connection 1 should not see this because the node was not |
| 1114 | 1091 // known to it. |
| 1115 // Delete node 2. The second connection should not see this because the node | 1092 ASSERT_TRUE(connection2_->DeleteNode(BuildNodeId(2, 2))); |
| 1116 // was not known to it. | |
| 1117 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 2))); | |
| 1118 | 1093 |
| 1119 // Parent 3 to 1. | 1094 // Parent 3 to 1. |
| 1120 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 3))); | 1095 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 3))); |
| 1121 connection2_->DoRunLoopUntilChangesCount(1); | 1096 connection_->DoRunLoopUntilChangesCount(1); |
| 1122 | 1097 |
| 1123 // Set view 11 on node 3. | 1098 // Set view 11 on node 3. |
| 1124 { | 1099 { |
| 1125 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 3), BuildViewId(1, 11))); | 1100 ASSERT_TRUE(connection2_->SetView(BuildNodeId(2, 3), BuildViewId(2, 11))); |
| 1126 | 1101 |
| 1127 connection2_->DoRunLoopUntilChangesCount(1); | 1102 connection_->DoRunLoopUntilChangesCount(1); |
| 1128 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1103 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 1129 ASSERT_EQ(1u, changes.size()); | 1104 ASSERT_EQ(1u, changes.size()); |
| 1130 EXPECT_EQ("ViewReplaced node=1,3 new_view=1,11 old_view=null", changes[0]); | 1105 EXPECT_EQ("ViewReplaced node=2,3 new_view=2,11 old_view=null", changes[0]); |
| 1131 } | 1106 } |
| 1132 | 1107 |
| 1133 // Delete 3. | 1108 // Delete 3. |
| 1134 { | 1109 { |
| 1135 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 3))); | 1110 ASSERT_TRUE(connection2_->DeleteNode(BuildNodeId(2, 3))); |
| 1136 | 1111 |
| 1137 connection2_->DoRunLoopUntilChangesCount(1); | 1112 connection_->DoRunLoopUntilChangesCount(1); |
| 1138 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1113 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 1139 ASSERT_EQ(1u, changes.size()); | 1114 ASSERT_EQ(1u, changes.size()); |
| 1140 EXPECT_EQ("NodeDeleted node=1,3", changes[0]); | 1115 EXPECT_EQ("NodeDeleted node=2,3", changes[0]); |
| 1141 } | 1116 } |
| 1142 } | 1117 } |
| 1143 | 1118 |
| 1144 // Sets view from one connection on another. | 1119 // Sets view from one connection on another. |
| 1145 TEST_F(ViewManagerTest, SetViewFromSecondConnection) { | 1120 TEST_F(ViewManagerTest, SetViewFromSecondConnection) { |
| 1146 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1121 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 1147 | 1122 |
| 1148 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1123 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 1149 | 1124 |
| 1150 // Create a view in the second connection. | 1125 // Create a view in the second connection. |
| 1151 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 51))); | 1126 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 51))); |
| 1152 | 1127 |
| 1153 // Attach view to node 1 in the first connection. | 1128 // Attach view to node 1 in the first connection. |
| 1154 { | 1129 { |
| 1155 ASSERT_TRUE(connection2_->SetView(BuildNodeId(1, 1), BuildViewId(2, 51))); | 1130 ASSERT_TRUE(connection2_->SetView(BuildNodeId(1, 1), BuildViewId(2, 51))); |
| 1156 connection_->DoRunLoopUntilChangesCount(1); | 1131 connection_->DoRunLoopUntilChangesCount(1); |
| 1157 const Changes changes(ChangesToDescription1(connection_->changes())); | 1132 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 1158 ASSERT_EQ(1u, changes.size()); | 1133 ASSERT_EQ(1u, changes.size()); |
| 1159 EXPECT_EQ("ViewReplaced node=1,1 new_view=2,51 old_view=null", changes[0]); | 1134 EXPECT_EQ("ViewReplaced node=1,1 new_view=2,51 old_view=null", changes[0]); |
| 1160 } | 1135 } |
| 1161 | 1136 |
| 1162 // Shutdown the second connection and verify view is removed. | 1137 // Shutdown the second connection and verify view is removed. |
| 1163 { | 1138 { |
| 1164 DestroySecondConnection(); | 1139 DestroySecondConnection(); |
| 1165 connection_->DoRunLoopUntilChangesCount(2); | 1140 connection_->DoRunLoopUntilChangesCount(1); |
| 1166 const Changes changes(ChangesToDescription1(connection_->changes())); | 1141 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 1167 ASSERT_EQ(2u, changes.size()); | 1142 ASSERT_EQ(1u, changes.size()); |
| 1168 EXPECT_EQ("ViewReplaced node=1,1 new_view=null old_view=2,51", changes[0]); | 1143 EXPECT_EQ("ViewReplaced node=1,1 new_view=null old_view=2,51", changes[0]); |
| 1169 EXPECT_EQ("ViewDeleted view=2,51", changes[1]); | |
| 1170 } | 1144 } |
| 1171 } | 1145 } |
| 1172 | 1146 |
| 1173 // Assertions for GetNodeTree. | 1147 // Assertions for GetNodeTree. |
| 1174 TEST_F(ViewManagerTest, GetNodeTree) { | 1148 TEST_F(ViewManagerTest, GetNodeTree) { |
| 1175 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1149 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 1176 | 1150 |
| 1177 // Create 11 in first connection and make it a child of 1. | 1151 // Create 11 in first connection and make it a child of 1. |
| 1178 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 11))); | 1152 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 11))); |
| 1179 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); | 1153 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1194 std::vector<TestNode> nodes; | 1168 std::vector<TestNode> nodes; |
| 1195 connection_->GetNodeTree(BuildNodeId(0, 1), &nodes); | 1169 connection_->GetNodeTree(BuildNodeId(0, 1), &nodes); |
| 1196 ASSERT_EQ(5u, nodes.size()); | 1170 ASSERT_EQ(5u, nodes.size()); |
| 1197 EXPECT_EQ("node=0,1 parent=null view=null", nodes[0].ToString()); | 1171 EXPECT_EQ("node=0,1 parent=null view=null", nodes[0].ToString()); |
| 1198 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[1].ToString()); | 1172 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[1].ToString()); |
| 1199 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[2].ToString()); | 1173 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[2].ToString()); |
| 1200 EXPECT_EQ("node=2,2 parent=1,1 view=null", nodes[3].ToString()); | 1174 EXPECT_EQ("node=2,2 parent=1,1 view=null", nodes[3].ToString()); |
| 1201 EXPECT_EQ("node=2,3 parent=1,1 view=null", nodes[4].ToString()); | 1175 EXPECT_EQ("node=2,3 parent=1,1 view=null", nodes[4].ToString()); |
| 1202 } | 1176 } |
| 1203 | 1177 |
| 1204 // Verifies GetNodeTree() on the node 1,1. This does not include 1,11 as it's | 1178 // Verifies GetNodeTree() on the node 1,1. This does not include any children |
| 1205 // from a different connection. | 1179 // as they are not from this connection. |
| 1206 { | 1180 { |
| 1207 std::vector<TestNode> nodes; | 1181 std::vector<TestNode> nodes; |
| 1208 connection2_->GetNodeTree(BuildNodeId(1, 1), &nodes); | 1182 connection2_->GetNodeTree(BuildNodeId(1, 1), &nodes); |
| 1209 ASSERT_EQ(3u, nodes.size()); | 1183 ASSERT_EQ(1u, nodes.size()); |
| 1210 EXPECT_EQ("node=1,1 parent=null view=null", nodes[0].ToString()); | 1184 EXPECT_EQ("node=1,1 parent=null view=null", nodes[0].ToString()); |
| 1211 EXPECT_EQ("node=2,2 parent=1,1 view=null", nodes[1].ToString()); | |
| 1212 EXPECT_EQ("node=2,3 parent=1,1 view=null", nodes[2].ToString()); | |
| 1213 } | 1185 } |
| 1214 | 1186 |
| 1215 // Connection 2 shouldn't be able to get the root tree. | 1187 // Connection 2 shouldn't be able to get the root tree. |
| 1216 { | 1188 { |
| 1217 std::vector<TestNode> nodes; | 1189 std::vector<TestNode> nodes; |
| 1218 connection2_->GetNodeTree(BuildNodeId(0, 1), &nodes); | 1190 connection2_->GetNodeTree(BuildNodeId(0, 1), &nodes); |
| 1219 ASSERT_EQ(0u, nodes.size()); | 1191 ASSERT_EQ(0u, nodes.size()); |
| 1220 } | 1192 } |
| 1221 } | 1193 } |
| 1222 | 1194 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1234 ASSERT_EQ(1u, changes.size()); | 1206 ASSERT_EQ(1u, changes.size()); |
| 1235 EXPECT_EQ("BoundsChanged node=1,1 old_bounds=0,0 0x0 new_bounds=0,0 100x100", | 1207 EXPECT_EQ("BoundsChanged node=1,1 old_bounds=0,0 0x0 new_bounds=0,0 100x100", |
| 1236 changes[0]); | 1208 changes[0]); |
| 1237 | 1209 |
| 1238 // Should not be possible to change the bounds of a node created by another | 1210 // Should not be possible to change the bounds of a node created by another |
| 1239 // connection. | 1211 // connection. |
| 1240 ASSERT_FALSE(connection2_->SetNodeBounds(BuildNodeId(1, 1), | 1212 ASSERT_FALSE(connection2_->SetNodeBounds(BuildNodeId(1, 1), |
| 1241 gfx::Rect(0, 0, 0, 0))); | 1213 gfx::Rect(0, 0, 0, 0))); |
| 1242 } | 1214 } |
| 1243 | 1215 |
| 1244 // Various assertions around SetRoots. | |
| 1245 TEST_F(ViewManagerTest, SetRoots) { | |
| 1246 // Create 1, 2, and 3 in the first connection. | |
| 1247 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | |
| 1248 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | |
| 1249 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); | |
| 1250 | |
| 1251 // Parent 1 to the root. | |
| 1252 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); | |
| 1253 | |
| 1254 // Establish the second connection with roots 1 and 3. | |
| 1255 { | |
| 1256 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | |
| 1257 | |
| 1258 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 3), kTestServiceURL)); | |
| 1259 connection2_->DoRunLoopUntilChangesCount(1); | |
| 1260 const Changes changes(ChangesToDescription1(connection2_->changes())); | |
| 1261 ASSERT_EQ(1u, changes.size()); | |
| 1262 EXPECT_EQ("OnRootAdded", changes[0]); | |
| 1263 EXPECT_EQ("[node=1,3 parent=null view=null]", | |
| 1264 ChangeNodeDescription(connection2_->changes())); | |
| 1265 } | |
| 1266 | |
| 1267 // Create 4 and add it to the root, connection 2 should not getting anything. | |
| 1268 { | |
| 1269 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 4))); | |
| 1270 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 4))); | |
| 1271 } | |
| 1272 | |
| 1273 // Move 4 under 3, this should expose 4 to the client. | |
| 1274 { | |
| 1275 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 3), BuildNodeId(1, 4))); | |
| 1276 connection2_->DoRunLoopUntilChangesCount(1); | |
| 1277 const Changes changes(ChangesToDescription1(connection2_->changes())); | |
| 1278 ASSERT_EQ(1u, changes.size()); | |
| 1279 EXPECT_EQ( | |
| 1280 "HierarchyChanged node=1,4 new_parent=1,3 old_parent=null", changes[0]); | |
| 1281 EXPECT_EQ("[node=1,4 parent=1,3 view=null]", | |
| 1282 ChangeNodeDescription(connection2_->changes())); | |
| 1283 } | |
| 1284 | |
| 1285 // Move 4 under 2, since 2 isn't a root client should get a delete. | |
| 1286 { | |
| 1287 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 4))); | |
| 1288 connection2_->DoRunLoopUntilChangesCount(1); | |
| 1289 const Changes changes(ChangesToDescription1(connection2_->changes())); | |
| 1290 ASSERT_EQ(1u, changes.size()); | |
| 1291 EXPECT_EQ("NodeDeleted node=1,4", changes[0]); | |
| 1292 } | |
| 1293 | |
| 1294 // Delete 4, client shouldn't receive a delete since it should no longer know | |
| 1295 // about 4. | |
| 1296 { | |
| 1297 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 4))); | |
| 1298 } | |
| 1299 } | |
| 1300 | |
| 1301 // Verify AddNode fails when trying to manipulate nodes in other roots. | 1216 // Verify AddNode fails when trying to manipulate nodes in other roots. |
| 1302 TEST_F(ViewManagerTest, CantMoveNodesFromOtherRoot) { | 1217 TEST_F(ViewManagerTest, CantMoveNodesFromOtherRoot) { |
| 1303 // Create 1 and 2 in the first connection. | 1218 // Create 1 and 2 in the first connection. |
| 1304 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1219 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| 1305 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1220 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 1306 | 1221 |
| 1307 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1222 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1308 | 1223 |
| 1309 // Try to move 2 to be a child of 1 from connection 2. This should fail as 2 | 1224 // Try to move 2 to be a child of 1 from connection 2. This should fail as 2 |
| 1310 // should not be able to access 1. | 1225 // should not be able to access 1. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1396 // Should get node 1 if asked for. | 1311 // Should get node 1 if asked for. |
| 1397 connection2_->GetNodeTree(BuildNodeId(1, 1), &nodes); | 1312 connection2_->GetNodeTree(BuildNodeId(1, 1), &nodes); |
| 1398 ASSERT_EQ(1u, nodes.size()); | 1313 ASSERT_EQ(1u, nodes.size()); |
| 1399 EXPECT_EQ("node=1,1 parent=null view=null", nodes[0].ToString()); | 1314 EXPECT_EQ("node=1,1 parent=null view=null", nodes[0].ToString()); |
| 1400 } | 1315 } |
| 1401 | 1316 |
| 1402 TEST_F(ViewManagerTest, ConnectTwice) { | 1317 TEST_F(ViewManagerTest, ConnectTwice) { |
| 1403 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1318 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| 1404 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1319 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 1405 | 1320 |
| 1406 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2))); | |
| 1407 | |
| 1408 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1321 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1409 | 1322 |
| 1410 // Try to connect again to 1,1, this should fail as already connected to that | 1323 // Try to connect again to 1,1, this should fail as already connected to that |
| 1411 // root. | 1324 // root. |
| 1412 ASSERT_FALSE(connection_->Embed(BuildNodeId(1, 1), kTestServiceURL)); | 1325 ASSERT_FALSE(connection_->Embed(BuildNodeId(1, 1), kTestServiceURL)); |
| 1413 | 1326 |
| 1414 // Connecting to 1,2 should succeed and end up in connection2. | 1327 // Connecting to 1,2 should succeed and end up in connection2. |
| 1415 { | 1328 { |
| 1416 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 2), kTestServiceURL)); | 1329 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 2), kTestServiceURL)); |
| 1417 connection2_->DoRunLoopUntilChangesCount(1); | 1330 connection2_->DoRunLoopUntilChangesCount(1); |
| 1418 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1331 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1419 ASSERT_EQ(1u, changes.size()); | 1332 ASSERT_EQ(1u, changes.size()); |
| 1420 EXPECT_EQ("OnRootAdded", changes[0]); | 1333 EXPECT_EQ("OnRootAdded", changes[0]); |
| 1421 EXPECT_EQ("[node=1,2 parent=1,1 view=null]", | 1334 EXPECT_EQ("[node=1,2 parent=null view=null]", |
| 1422 ChangeNodeDescription(connection2_->changes())); | 1335 ChangeNodeDescription(connection2_->changes())); |
| 1423 } | 1336 } |
| 1424 } | 1337 } |
| 1425 | 1338 |
| 1426 TEST_F(ViewManagerTest, OnViewInput) { | 1339 TEST_F(ViewManagerTest, OnViewInput) { |
| 1427 // Create node 1 and assign a view from connection 2 to it. | 1340 // Create node 1 and assign a view from connection 2 to it. |
| 1428 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1341 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| 1429 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1342 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1430 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 11))); | 1343 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 11))); |
| 1431 ASSERT_TRUE(connection2_->SetView(BuildNodeId(1, 1), BuildViewId(2, 11))); | 1344 ASSERT_TRUE(connection2_->SetView(BuildNodeId(1, 1), BuildViewId(2, 11))); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1539 // that SetBounsdNodes/AddNode and the like don't result in messages to the | 1452 // that SetBounsdNodes/AddNode and the like don't result in messages to the |
| 1540 // originating connection. | 1453 // originating connection. |
| 1541 | 1454 |
| 1542 // TODO(beng): Add tests for focus: | 1455 // TODO(beng): Add tests for focus: |
| 1543 // - focus between two nodes known to a connection | 1456 // - focus between two nodes known to a connection |
| 1544 // - focus between nodes unknown to one of the connections. | 1457 // - focus between nodes unknown to one of the connections. |
| 1545 // - focus between nodes unknown to either connection. | 1458 // - focus between nodes unknown to either connection. |
| 1546 | 1459 |
| 1547 } // namespace service | 1460 } // namespace service |
| 1548 } // namespace mojo | 1461 } // namespace mojo |
| OLD | NEW |