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

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

Issue 287183003: Restricts node/view deletion to creator (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 6 years, 7 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_connection.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/bind.h" 8 #include "base/bind.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 bool CreateNode(IViewManager* view_manager, 98 bool CreateNode(IViewManager* view_manager,
99 TransportConnectionId connection_id, 99 TransportConnectionId connection_id,
100 TransportConnectionSpecificNodeId node_id) { 100 TransportConnectionSpecificNodeId node_id) {
101 bool result = false; 101 bool result = false;
102 view_manager->CreateNode(CreateNodeId(connection_id, node_id), 102 view_manager->CreateNode(CreateNodeId(connection_id, node_id),
103 base::Bind(&BooleanCallback, &result)); 103 base::Bind(&BooleanCallback, &result));
104 DoRunLoop(); 104 DoRunLoop();
105 return result; 105 return result;
106 } 106 }
107 107
108 // Deletes a node, blocking until done. 108 // Deletes a view, blocking until done.
109 bool DeleteNode(IViewManager* view_manager, TransportNodeId node_id) { 109 bool DeleteNode(IViewManager* view_manager, TransportNodeId node_id) {
110 bool result = false; 110 bool result = false;
111 view_manager->DeleteNode(node_id, base::Bind(&BooleanCallback, &result)); 111 view_manager->DeleteNode(node_id, base::Bind(&BooleanCallback, &result));
112 DoRunLoop(); 112 DoRunLoop();
113 return result; 113 return result;
114 } 114 }
115 115
116 // Deletes a node, blocking until done.
117 bool DeleteView(IViewManager* view_manager, TransportViewId view_id) {
118 bool result = false;
119 view_manager->DeleteView(view_id, base::Bind(&BooleanCallback, &result));
120 DoRunLoop();
121 return result;
122 }
123
116 // Adds a node, blocking until done. 124 // Adds a node, blocking until done.
117 bool AddNode(IViewManager* view_manager, 125 bool AddNode(IViewManager* view_manager,
118 TransportNodeId parent, 126 TransportNodeId parent,
119 TransportNodeId child, 127 TransportNodeId child,
120 TransportChangeId server_change_id) { 128 TransportChangeId server_change_id) {
121 bool result = false; 129 bool result = false;
122 view_manager->AddNode(parent, child, server_change_id, 130 view_manager->AddNode(parent, child, server_change_id,
123 base::Bind(&BooleanCallback, &result)); 131 base::Bind(&BooleanCallback, &result));
124 DoRunLoop(); 132 DoRunLoop();
125 return result; 133 return result;
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 Changes changes(client_.GetAndClearChanges()); 804 Changes changes(client_.GetAndClearChanges());
797 ASSERT_TRUE(changes.empty()); 805 ASSERT_TRUE(changes.empty());
798 806
799 client2_.DoRunLoopUntilChangesCount(1); 807 client2_.DoRunLoopUntilChangesCount(1);
800 changes = client2_.GetAndClearChanges(); 808 changes = client2_.GetAndClearChanges();
801 ASSERT_EQ(1u, changes.size()); 809 ASSERT_EQ(1u, changes.size());
802 EXPECT_EQ("NodeDeleted change_id=3 node=1,1", changes[0]); 810 EXPECT_EQ("NodeDeleted change_id=3 node=1,1", changes[0]);
803 } 811 }
804 } 812 }
805 813
814 // Verifies DeleteNode isn't allowed from a separate connection.
815 TEST_F(ViewManagerConnectionTest, DeleteNodeFromAnotherConnectionDisallowed) {
816 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1));
817 EstablishSecondConnection();
818 EXPECT_FALSE(DeleteNode(view_manager2_.get(), CreateNodeId(client_.id(), 1)));
819 }
820
821 // Verifies DeleteView isn't allowed from a separate connection.
822 TEST_F(ViewManagerConnectionTest, DeleteViewFromAnotherConnectionDisallowed) {
823 ASSERT_TRUE(CreateView(view_manager_.get(), 1, 1));
824 EstablishSecondConnection();
825 EXPECT_FALSE(DeleteView(view_manager2_.get(), CreateViewId(client_.id(), 1)));
826 }
827
806 // Verifies if a node was deleted and then reused that other clients are 828 // Verifies if a node was deleted and then reused that other clients are
807 // properly notified. 829 // properly notified.
808 TEST_F(ViewManagerConnectionTest, ReusedDeletedId) { 830 TEST_F(ViewManagerConnectionTest, ReusedDeletedId) {
809 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); 831 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1));
810 EXPECT_TRUE(client_.GetAndClearChanges().empty()); 832 EXPECT_TRUE(client_.GetAndClearChanges().empty());
811 833
812 EstablishSecondConnection(); 834 EstablishSecondConnection();
813 835
814 // Make 1 a child of the root. 836 // Make 1 a child of the root.
815 { 837 {
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 GetNodeTree(view_manager2_.get(), CreateNodeId(1, 1), &nodes); 1086 GetNodeTree(view_manager2_.get(), CreateNodeId(1, 1), &nodes);
1065 ASSERT_EQ(2u, nodes.size()); 1087 ASSERT_EQ(2u, nodes.size());
1066 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); 1088 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString());
1067 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[1].ToString()); 1089 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[1].ToString());
1068 } 1090 }
1069 } 1091 }
1070 1092
1071 } // namespace service 1093 } // namespace service
1072 } // namespace view_manager 1094 } // namespace view_manager
1073 } // namespace mojo 1095 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/view_manager/view_manager_connection.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698