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

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

Issue 331243002: Makes IViewManager::DeleteNode take the server_change_id (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: resolve merge Created 6 years, 6 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 bool Embed(const std::vector<Id>& nodes) { 155 bool Embed(const std::vector<Id>& nodes) {
156 changes_.clear(); 156 changes_.clear();
157 base::AutoReset<bool> auto_reset(&in_embed_, true); 157 base::AutoReset<bool> auto_reset(&in_embed_, true);
158 bool result = false; 158 bool result = false;
159 view_manager_->Embed(kTestServiceURL, Array<Id>::From(nodes), 159 view_manager_->Embed(kTestServiceURL, Array<Id>::From(nodes),
160 base::Bind(&ViewManagerProxy::GotResult, 160 base::Bind(&ViewManagerProxy::GotResult,
161 base::Unretained(this), &result)); 161 base::Unretained(this), &result));
162 RunMainLoop(); 162 RunMainLoop();
163 return result; 163 return result;
164 } 164 }
165 bool DeleteNode(Id node_id) { 165 bool DeleteNode(Id node_id, Id server_change_id) {
166 changes_.clear(); 166 changes_.clear();
167 bool result = false; 167 bool result = false;
168 view_manager_->DeleteNode(node_id, 168 view_manager_->DeleteNode(node_id,
169 server_change_id,
169 base::Bind(&ViewManagerProxy::GotResult, 170 base::Bind(&ViewManagerProxy::GotResult,
170 base::Unretained(this), &result)); 171 base::Unretained(this), &result));
171 RunMainLoop(); 172 RunMainLoop();
172 return result; 173 return result;
173 } 174 }
174 bool DeleteView(Id view_id) { 175 bool DeleteView(Id view_id) {
175 changes_.clear(); 176 changes_.clear();
176 bool result = false; 177 bool result = false;
177 view_manager_->DeleteView(view_id, 178 view_manager_->DeleteView(view_id,
178 base::Bind(&ViewManagerProxy::GotResult, 179 base::Bind(&ViewManagerProxy::GotResult,
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 1)); 872 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 1));
872 connection2_->DoRunLoopUntilChangesCount(1); 873 connection2_->DoRunLoopUntilChangesCount(1);
873 const Changes changes(ChangesToDescription1(connection2_->changes())); 874 const Changes changes(ChangesToDescription1(connection2_->changes()));
874 ASSERT_EQ(1u, changes.size()); 875 ASSERT_EQ(1u, changes.size());
875 EXPECT_EQ("HierarchyChanged change_id=1 node=1,2 new_parent=1,1 " 876 EXPECT_EQ("HierarchyChanged change_id=1 node=1,2 new_parent=1,1 "
876 "old_parent=null", changes[0]); 877 "old_parent=null", changes[0]);
877 } 878 }
878 879
879 // Delete 2. 880 // Delete 2.
880 { 881 {
881 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 2))); 882 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 2), 2));
882 EXPECT_TRUE(connection_->changes().empty()); 883 EXPECT_TRUE(connection_->changes().empty());
883 884
884 connection2_->DoRunLoopUntilChangesCount(1); 885 connection2_->DoRunLoopUntilChangesCount(1);
885 const Changes changes(ChangesToDescription1(connection2_->changes())); 886 const Changes changes(ChangesToDescription1(connection2_->changes()));
886 ASSERT_EQ(1u, changes.size()); 887 ASSERT_EQ(1u, changes.size());
887 EXPECT_EQ("NodeDeleted change_id=2 node=1,2", changes[0]); 888 EXPECT_EQ("NodeDeleted change_id=2 node=1,2", changes[0]);
888 } 889 }
889 } 890 }
890 891
891 // Verifies DeleteNode isn't allowed from a separate connection. 892 // Verifies DeleteNode isn't allowed from a separate connection.
892 TEST_F(ViewManagerTest, DeleteNodeFromAnotherConnectionDisallowed) { 893 TEST_F(ViewManagerTest, DeleteNodeFromAnotherConnectionDisallowed) {
893 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 894 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
894 EXPECT_FALSE(connection2_->DeleteNode(BuildNodeId(1, 1))); 895 EXPECT_FALSE(connection2_->DeleteNode(BuildNodeId(1, 1), 1));
895 } 896 }
896 897
897 // Verifies DeleteView isn't allowed from a separate connection. 898 // Verifies DeleteView isn't allowed from a separate connection.
898 TEST_F(ViewManagerTest, DeleteViewFromAnotherConnectionDisallowed) { 899 TEST_F(ViewManagerTest, DeleteViewFromAnotherConnectionDisallowed) {
899 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); 900 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1)));
900 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 901 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
901 EXPECT_FALSE(connection2_->DeleteView(BuildViewId(1, 1))); 902 EXPECT_FALSE(connection2_->DeleteView(BuildViewId(1, 1)));
902 } 903 }
903 904
904 // Verifies if a node was deleted and then reused that other clients are 905 // Verifies if a node was deleted and then reused that other clients are
(...skipping 10 matching lines...) Expand all
915 const Changes changes(ChangesToDescription1(connection2_->changes())); 916 const Changes changes(ChangesToDescription1(connection2_->changes()));
916 EXPECT_EQ( 917 EXPECT_EQ(
917 "HierarchyChanged change_id=1 node=1,2 new_parent=1,1 old_parent=null", 918 "HierarchyChanged change_id=1 node=1,2 new_parent=1,1 old_parent=null",
918 changes[0]); 919 changes[0]);
919 EXPECT_EQ("[node=1,2 parent=1,1 view=null]", 920 EXPECT_EQ("[node=1,2 parent=1,1 view=null]",
920 ChangeNodeDescription(connection2_->changes())); 921 ChangeNodeDescription(connection2_->changes()));
921 } 922 }
922 923
923 // Delete 2. 924 // Delete 2.
924 { 925 {
925 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 2))); 926 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 2), 2));
926 927
927 connection2_->DoRunLoopUntilChangesCount(1); 928 connection2_->DoRunLoopUntilChangesCount(1);
928 const Changes changes(ChangesToDescription1(connection2_->changes())); 929 const Changes changes(ChangesToDescription1(connection2_->changes()));
929 ASSERT_EQ(1u, changes.size()); 930 ASSERT_EQ(1u, changes.size());
930 EXPECT_EQ("NodeDeleted change_id=2 node=1,2", changes[0]); 931 EXPECT_EQ("NodeDeleted change_id=2 node=1,2", changes[0]);
931 } 932 }
932 933
933 // Create 2 again, and add it back to 1. Should get the same notification. 934 // Create 2 again, and add it back to 1. Should get the same notification.
934 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); 935 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2)));
935 { 936 {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 11))); 992 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 11)));
992 993
993 // Set view 11 on node 2. 994 // Set view 11 on node 2.
994 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 2), BuildViewId(1, 11))); 995 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 2), BuildViewId(1, 11)));
995 996
996 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); 997 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false));
997 998
998 // Delete node 2. The second connection should not see this because the node 999 // Delete node 2. The second connection should not see this because the node
999 // was not known to it. 1000 // was not known to it.
1000 { 1001 {
1001 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 2))); 1002 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 2), 1));
1002 1003
1003 connection2_->DoRunLoopUntilChangesCount(1); 1004 connection2_->DoRunLoopUntilChangesCount(1);
1004 const Changes changes(ChangesToDescription1(connection2_->changes())); 1005 const Changes changes(ChangesToDescription1(connection2_->changes()));
1005 ASSERT_EQ(1u, changes.size()); 1006 ASSERT_EQ(1u, changes.size());
1006 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); 1007 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]);
1007 } 1008 }
1008 1009
1009 // Parent 3 to 1. 1010 // Parent 3 to 1.
1010 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 3), 2)); 1011 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 3), 2));
1011 connection2_->DoRunLoopUntilChangesCount(1); 1012 connection2_->DoRunLoopUntilChangesCount(1);
1012 1013
1013 // Set view 11 on node 3. 1014 // Set view 11 on node 3.
1014 { 1015 {
1015 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 3), BuildViewId(1, 11))); 1016 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 3), BuildViewId(1, 11)));
1016 1017
1017 connection2_->DoRunLoopUntilChangesCount(1); 1018 connection2_->DoRunLoopUntilChangesCount(1);
1018 const Changes changes(ChangesToDescription1(connection2_->changes())); 1019 const Changes changes(ChangesToDescription1(connection2_->changes()));
1019 ASSERT_EQ(1u, changes.size()); 1020 ASSERT_EQ(1u, changes.size());
1020 EXPECT_EQ("ViewReplaced node=1,3 new_view=1,11 old_view=null", changes[0]); 1021 EXPECT_EQ("ViewReplaced node=1,3 new_view=1,11 old_view=null", changes[0]);
1021 } 1022 }
1022 1023
1023 // Delete 3. 1024 // Delete 3.
1024 { 1025 {
1025 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 3))); 1026 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 3), 3));
1026 1027
1027 connection2_->DoRunLoopUntilChangesCount(1); 1028 connection2_->DoRunLoopUntilChangesCount(1);
1028 const Changes changes(ChangesToDescription1(connection2_->changes())); 1029 const Changes changes(ChangesToDescription1(connection2_->changes()));
1029 ASSERT_EQ(1u, changes.size()); 1030 ASSERT_EQ(1u, changes.size());
1030 EXPECT_EQ("NodeDeleted change_id=3 node=1,3", changes[0]); 1031 EXPECT_EQ("NodeDeleted change_id=3 node=1,3", changes[0]);
1031 } 1032 }
1032 } 1033 }
1033 1034
1034 // Sets view from one connection on another. 1035 // Sets view from one connection on another.
1035 TEST_F(ViewManagerTest, SetViewFromSecondConnection) { 1036 TEST_F(ViewManagerTest, SetViewFromSecondConnection) {
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 4), 4)); 1183 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 4), 4));
1183 connection2_->DoRunLoopUntilChangesCount(1); 1184 connection2_->DoRunLoopUntilChangesCount(1);
1184 const Changes changes(ChangesToDescription1(connection2_->changes())); 1185 const Changes changes(ChangesToDescription1(connection2_->changes()));
1185 ASSERT_EQ(1u, changes.size()); 1186 ASSERT_EQ(1u, changes.size());
1186 EXPECT_EQ("NodeDeleted change_id=4 node=1,4", changes[0]); 1187 EXPECT_EQ("NodeDeleted change_id=4 node=1,4", changes[0]);
1187 } 1188 }
1188 1189
1189 // Delete 4, client shouldn't receive a delete since it should no longer know 1190 // Delete 4, client shouldn't receive a delete since it should no longer know
1190 // about 4. 1191 // about 4.
1191 { 1192 {
1192 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 4))); 1193 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 4), 5));
1193 1194
1194 connection2_->DoRunLoopUntilChangesCount(1); 1195 connection2_->DoRunLoopUntilChangesCount(1);
1195 const Changes changes(ChangesToDescription1(connection2_->changes())); 1196 const Changes changes(ChangesToDescription1(connection2_->changes()));
1196 ASSERT_EQ(1u, changes.size()); 1197 ASSERT_EQ(1u, changes.size());
1197 EXPECT_EQ("ServerChangeIdAdvanced 6", changes[0]); 1198 EXPECT_EQ("ServerChangeIdAdvanced 6", changes[0]);
1198 } 1199 }
1199 } 1200 }
1200 1201
1201 // Verify AddNode fails when trying to manipulate nodes in other roots. 1202 // Verify AddNode fails when trying to manipulate nodes in other roots.
1202 TEST_F(ViewManagerTest, CantMoveNodesFromOtherRoot) { 1203 TEST_F(ViewManagerTest, CantMoveNodesFromOtherRoot) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 // TODO(sky): add coverage of test that destroys connections and ensures other 1333 // TODO(sky): add coverage of test that destroys connections and ensures other
1333 // connections get deletion notification (or advanced server id). 1334 // connections get deletion notification (or advanced server id).
1334 1335
1335 // TODO(sky): need to better track changes to initial connection. For example, 1336 // TODO(sky): need to better track changes to initial connection. For example,
1336 // that SetBounsdNodes/AddNode and the like don't result in messages to the 1337 // that SetBounsdNodes/AddNode and the like don't result in messages to the
1337 // originating connection. 1338 // originating connection.
1338 1339
1339 } // namespace service 1340 } // namespace service
1340 } // namespace view_manager 1341 } // namespace view_manager
1341 } // namespace mojo 1342 } // 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