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

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

Issue 424533002: Cleans up usage of ViewManagerServiceImpl::roots_ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix attempt 2 Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/services/view_manager/view_manager_service_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/at_exit.h" 8 #include "base/at_exit.h"
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 } 589 }
590 590
591 // Verifies when Embed() is invoked any child nodes are removed. 591 // Verifies when Embed() is invoked any child nodes are removed.
592 TEST_F(ViewManagerTest, NodesRemovedWhenEmbedding) { 592 TEST_F(ViewManagerTest, NodesRemovedWhenEmbedding) {
593 // Two nodes 1 and 2. 2 is parented to 1. 593 // Two nodes 1 and 2. 2 is parented to 1.
594 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); 594 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1)));
595 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); 595 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2)));
596 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2))); 596 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2)));
597 597
598 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); 598 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false));
599 EXPECT_EQ("[node=1,1 parent=null view=null]",
600 ChangeNodeDescription(connection2_->changes()));
599 601
600 // Because |connection_| is the root, the embed call doesn't remove. 602 // Embed() removed node 2.
601 { 603 {
602 std::vector<TestNode> nodes; 604 std::vector<TestNode> nodes;
603 connection_->GetNodeTree(BuildNodeId(1, 2), &nodes); 605 connection_->GetNodeTree(BuildNodeId(1, 2), &nodes);
604 ASSERT_EQ(1u, nodes.size()); 606 ASSERT_EQ(1u, nodes.size());
605 EXPECT_EQ("node=1,2 parent=1,1 view=null", nodes[0].ToString()); 607 EXPECT_EQ("node=1,2 parent=null view=null", nodes[0].ToString());
606 } 608 }
607 609
608 // But |connection2_| should not see node 2. 610 // |connection2_| should not see node 2.
609 { 611 {
610 std::vector<TestNode> nodes; 612 std::vector<TestNode> nodes;
611 connection2_->GetNodeTree(BuildNodeId(1, 1), &nodes); 613 connection2_->GetNodeTree(BuildNodeId(1, 1), &nodes);
612 ASSERT_EQ(1u, nodes.size()); 614 ASSERT_EQ(1u, nodes.size());
613 EXPECT_EQ("node=1,1 parent=null view=null", nodes[0].ToString()); 615 EXPECT_EQ("node=1,1 parent=null view=null", nodes[0].ToString());
614 } 616 }
615 { 617 {
616 std::vector<TestNode> nodes; 618 std::vector<TestNode> nodes;
617 connection2_->GetNodeTree(BuildNodeId(1, 2), &nodes); 619 connection2_->GetNodeTree(BuildNodeId(1, 2), &nodes);
618 EXPECT_TRUE(nodes.empty()); 620 EXPECT_TRUE(nodes.empty());
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 ASSERT_EQ(1u, changes.size()); 884 ASSERT_EQ(1u, changes.size());
883 EXPECT_EQ("HierarchyChanged node=2,2 new_parent=1,1 old_parent=null", 885 EXPECT_EQ("HierarchyChanged node=2,2 new_parent=1,1 old_parent=null",
884 changes[0]); 886 changes[0]);
885 EXPECT_EQ("[node=2,2 parent=1,1 view=null]," 887 EXPECT_EQ("[node=2,2 parent=1,1 view=null],"
886 "[node=2,21 parent=2,2 view=null]", 888 "[node=2,21 parent=2,2 view=null]",
887 ChangeNodeDescription(connection_->changes())); 889 ChangeNodeDescription(connection_->changes()));
888 } 890 }
889 } 891 }
890 892
891 TEST_F(ViewManagerTest, ReorderNode) { 893 TEST_F(ViewManagerTest, ReorderNode) {
892 Id node1_id = BuildNodeId(1, 1); 894 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
893 Id node2_id = BuildNodeId(1, 2); 895
894 Id node3_id = BuildNodeId(1, 3); 896 Id node1_id = BuildNodeId(2, 1);
897 Id node2_id = BuildNodeId(2, 2);
898 Id node3_id = BuildNodeId(2, 3);
895 Id node4_id = BuildNodeId(1, 4); // Peer to 1,1 899 Id node4_id = BuildNodeId(1, 4); // Peer to 1,1
896 Id node5_id = BuildNodeId(1, 5); // Peer to 1,1 900 Id node5_id = BuildNodeId(1, 5); // Peer to 1,1
897 Id node6_id = BuildNodeId(1, 6); // Child of 1,2. 901 Id node6_id = BuildNodeId(2, 6); // Child of 1,2.
898 Id node7_id = BuildNodeId(1, 7); // Unparented. 902 Id node7_id = BuildNodeId(2, 7); // Unparented.
899 Id node8_id = BuildNodeId(1, 8); // Unparented. 903 Id node8_id = BuildNodeId(2, 8); // Unparented.
900 ASSERT_TRUE(connection_->CreateNode(node1_id)); 904 ASSERT_TRUE(connection2_->CreateNode(node1_id));
901 ASSERT_TRUE(connection_->CreateNode(node2_id)); 905 ASSERT_TRUE(connection2_->CreateNode(node2_id));
902 ASSERT_TRUE(connection_->CreateNode(node3_id)); 906 ASSERT_TRUE(connection2_->CreateNode(node3_id));
903 ASSERT_TRUE(connection_->CreateNode(node4_id)); 907 ASSERT_TRUE(connection_->CreateNode(node4_id));
904 ASSERT_TRUE(connection_->CreateNode(node5_id)); 908 ASSERT_TRUE(connection_->CreateNode(node5_id));
905 ASSERT_TRUE(connection_->CreateNode(node6_id)); 909 ASSERT_TRUE(connection2_->CreateNode(node6_id));
906 ASSERT_TRUE(connection_->CreateNode(node7_id)); 910 ASSERT_TRUE(connection2_->CreateNode(node7_id));
907 ASSERT_TRUE(connection_->CreateNode(node8_id)); 911 ASSERT_TRUE(connection2_->CreateNode(node8_id));
908 ASSERT_TRUE(connection_->AddNode(node1_id, node2_id)); 912 ASSERT_TRUE(connection2_->AddNode(node1_id, node2_id));
909 ASSERT_TRUE(connection_->AddNode(node2_id, node6_id)); 913 ASSERT_TRUE(connection2_->AddNode(node2_id, node6_id));
910 ASSERT_TRUE(connection_->AddNode(node1_id, node3_id)); 914 ASSERT_TRUE(connection2_->AddNode(node1_id, node3_id));
911 ASSERT_TRUE(connection_->AddNode( 915 ASSERT_TRUE(connection_->AddNode(
912 NodeIdToTransportId(RootNodeId()), node4_id)); 916 NodeIdToTransportId(RootNodeId()), node4_id));
913 ASSERT_TRUE(connection_->AddNode( 917 ASSERT_TRUE(connection_->AddNode(
914 NodeIdToTransportId(RootNodeId()), node5_id)); 918 NodeIdToTransportId(RootNodeId()), node5_id));
915 919
916 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); 920 ASSERT_TRUE(connection_->AddNode(
921 NodeIdToTransportId(RootNodeId()), node1_id));
917 922
918 { 923 {
919 connection_->ReorderNode(node2_id, node3_id, ORDER_DIRECTION_ABOVE); 924 ASSERT_TRUE(
925 connection2_->ReorderNode(node2_id, node3_id, ORDER_DIRECTION_ABOVE));
920 926
921 connection2_->DoRunLoopUntilChangesCount(1); 927 connection_->DoRunLoopUntilChangesCount(1);
922 const Changes changes(ChangesToDescription1(connection2_->changes())); 928 const Changes changes(ChangesToDescription1(connection_->changes()));
923 ASSERT_EQ(1u, changes.size()); 929 ASSERT_EQ(1u, changes.size());
924 EXPECT_EQ("Reordered node=1,2 relative=1,3 direction=above", 930 EXPECT_EQ("Reordered node=2,2 relative=2,3 direction=above",
925 changes[0]); 931 changes[0]);
926 } 932 }
927 933
928 { 934 {
929 connection_->ReorderNode(node2_id, node3_id, ORDER_DIRECTION_BELOW); 935 ASSERT_TRUE(connection2_->ReorderNode(
936 node2_id, node3_id, ORDER_DIRECTION_BELOW));
930 937
931 connection2_->DoRunLoopUntilChangesCount(1); 938 connection_->DoRunLoopUntilChangesCount(1);
932 const Changes changes(ChangesToDescription1(connection2_->changes())); 939 const Changes changes(ChangesToDescription1(connection_->changes()));
933 ASSERT_EQ(1u, changes.size()); 940 ASSERT_EQ(1u, changes.size());
934 EXPECT_EQ("Reordered node=1,2 relative=1,3 direction=below", 941 EXPECT_EQ("Reordered node=2,2 relative=2,3 direction=below",
935 changes[0]); 942 changes[0]);
936 } 943 }
937 944
938 // node2 is already below node3. 945 // node2 is already below node3.
939 EXPECT_FALSE( 946 EXPECT_FALSE(
940 connection_->ReorderNode(node2_id, node3_id, ORDER_DIRECTION_BELOW)); 947 connection2_->ReorderNode(node2_id, node3_id, ORDER_DIRECTION_BELOW));
941 948
942 // node4 & 5 are unknown to connection2_. 949 // node4 & 5 are unknown to connection2_.
943 EXPECT_FALSE(connection2_->ReorderNode( 950 EXPECT_FALSE(connection2_->ReorderNode(
944 node4_id, node5_id, ORDER_DIRECTION_ABOVE)); 951 node4_id, node5_id, ORDER_DIRECTION_ABOVE));
945 952
946 // node6 & node3 have different parents. 953 // node6 & node3 have different parents.
947 EXPECT_FALSE( 954 EXPECT_FALSE(
948 connection_->ReorderNode(node3_id, node6_id, ORDER_DIRECTION_ABOVE)); 955 connection_->ReorderNode(node3_id, node6_id, ORDER_DIRECTION_ABOVE));
949 956
950 // Non-existent node-ids 957 // Non-existent node-ids
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 const Changes changes(ChangesToDescription1(connection_->changes())); 1040 const Changes changes(ChangesToDescription1(connection_->changes()));
1034 EXPECT_EQ("HierarchyChanged node=2,2 new_parent=1,1 old_parent=null", 1041 EXPECT_EQ("HierarchyChanged node=2,2 new_parent=1,1 old_parent=null",
1035 changes[0]); 1042 changes[0]);
1036 EXPECT_EQ("[node=2,2 parent=1,1 view=null]", 1043 EXPECT_EQ("[node=2,2 parent=1,1 view=null]",
1037 ChangeNodeDescription(connection_->changes())); 1044 ChangeNodeDescription(connection_->changes()));
1038 } 1045 }
1039 } 1046 }
1040 1047
1041 // Assertions around setting a view. 1048 // Assertions around setting a view.
1042 TEST_F(ViewManagerTest, SetView) { 1049 TEST_F(ViewManagerTest, SetView) {
1050 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1051
1043 // Create nodes 1, 2 and 3 and the view 11. Nodes 2 and 3 are parented to 1. 1052 // Create nodes 1, 2 and 3 and the view 11. Nodes 2 and 3 are parented to 1.
1044 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); 1053 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2)));
1045 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); 1054 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 3)));
1046 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); 1055 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 11)));
1047 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 11))); 1056 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 2)));
1048 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2))); 1057 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 3)));
1049 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 3)));
1050 1058
1051 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); 1059 // Do this to clear out the changes conncection_ has seen and ensure it's up
1060 // to date.
1061 connection_->CopyChangesFromTracker();
1062 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 100)));
1052 1063
1053 // Set view 11 on node 1. 1064 // Set view 11 on node 1.
1054 { 1065 {
1055 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 1), 1066 ASSERT_TRUE(connection2_->SetView(BuildNodeId(1, 1), BuildViewId(2, 11)));
1056 BuildViewId(1, 11)));
1057 1067
1058 connection2_->DoRunLoopUntilChangesCount(1); 1068 connection_->DoRunLoopUntilChangesCount(1);
1059 const Changes changes(ChangesToDescription1(connection2_->changes())); 1069 const Changes changes(ChangesToDescription1(connection_->changes()));
1060 ASSERT_EQ(1u, changes.size()); 1070 ASSERT_EQ(1u, changes.size());
1061 EXPECT_EQ("ViewReplaced node=1,1 new_view=1,11 old_view=null", 1071 EXPECT_EQ("ViewReplaced node=1,1 new_view=2,11 old_view=null",
1062 changes[0]); 1072 changes[0]);
1063 } 1073 }
1064 1074
1065 // Set view 11 on node 2. 1075 // Set view 11 on node 2.
1066 { 1076 {
1067 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 2), BuildViewId(1, 11))); 1077 ASSERT_TRUE(connection2_->SetView(BuildNodeId(2, 2), BuildViewId(2, 11)));
1068 1078
1069 connection2_->DoRunLoopUntilChangesCount(2); 1079 connection_->DoRunLoopUntilChangesCount(2);
1070 const Changes changes(ChangesToDescription1(connection2_->changes())); 1080 const Changes changes(ChangesToDescription1(connection_->changes()));
1071 ASSERT_EQ(2u, changes.size()); 1081 ASSERT_EQ(2u, changes.size());
1072 EXPECT_EQ("ViewReplaced node=1,1 new_view=null old_view=1,11", 1082 EXPECT_EQ("ViewReplaced node=1,1 new_view=null old_view=2,11",
1073 changes[0]); 1083 changes[0]);
1074 EXPECT_EQ("ViewReplaced node=1,2 new_view=1,11 old_view=null", 1084 EXPECT_EQ("ViewReplaced node=2,2 new_view=2,11 old_view=null",
1075 changes[1]); 1085 changes[1]);
1076 } 1086 }
1077 } 1087 }
1078 1088
1079 // Verifies deleting a node with a view sends correct notifications. 1089 // Verifies deleting a node with a view sends correct notifications.
1080 TEST_F(ViewManagerTest, DeleteNodeWithView) { 1090 TEST_F(ViewManagerTest, DeleteNodeWithView) {
1081 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 1091 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1082 1092
1083 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2))); 1093 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2)));
1084 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 3))); 1094 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 3)));
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 // that SetBounsdNodes/AddNode and the like don't result in messages to the 1462 // that SetBounsdNodes/AddNode and the like don't result in messages to the
1453 // originating connection. 1463 // originating connection.
1454 1464
1455 // TODO(beng): Add tests for focus: 1465 // TODO(beng): Add tests for focus:
1456 // - focus between two nodes known to a connection 1466 // - focus between two nodes known to a connection
1457 // - focus between nodes unknown to one of the connections. 1467 // - focus between nodes unknown to one of the connections.
1458 // - focus between nodes unknown to either connection. 1468 // - focus between nodes unknown to either connection.
1459 1469
1460 } // namespace service 1470 } // namespace service
1461 } // namespace mojo 1471 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/view_manager/view_manager_service_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698