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/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" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "mojo/common/common_type_converters.h" | 13 #include "mojo/common/common_type_converters.h" |
| 14 #include "mojo/geometry/geometry_type_converters.h" |
14 #include "mojo/public/cpp/bindings/allocation_scope.h" | 15 #include "mojo/public/cpp/bindings/allocation_scope.h" |
15 #include "mojo/public/cpp/environment/environment.h" | 16 #include "mojo/public/cpp/environment/environment.h" |
16 #include "mojo/public/cpp/shell/connect.h" | 17 #include "mojo/public/cpp/shell/connect.h" |
17 #include "mojo/services/public/cpp/view_manager/util.h" | 18 #include "mojo/services/public/cpp/view_manager/util.h" |
18 #include "mojo/services/public/cpp/view_manager/view_manager_types.h" | 19 #include "mojo/services/public/cpp/view_manager/view_manager_types.h" |
19 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" | 20 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" |
20 #include "mojo/shell/shell_test_helper.h" | 21 #include "mojo/shell/shell_test_helper.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "ui/gfx/geometry/rect.h" |
22 | 24 |
23 namespace mojo { | 25 namespace mojo { |
24 | 26 |
25 // TODO(sky): remove this when Darin is done with cleanup. | 27 // TODO(sky): remove this when Darin is done with cleanup. |
26 template <typename T> | 28 template <typename T> |
27 class MOJO_COMMON_EXPORT TypeConverter<T, T> { | 29 class MOJO_COMMON_EXPORT TypeConverter<T, T> { |
28 public: | 30 public: |
29 static T ConvertFrom(T input, Buffer* buf) { | 31 static T ConvertFrom(T input, Buffer* buf) { |
30 return input; | 32 return input; |
31 } | 33 } |
(...skipping 21 matching lines...) Expand all Loading... |
53 current_run_loop->Run(); | 55 current_run_loop->Run(); |
54 current_run_loop = NULL; | 56 current_run_loop = NULL; |
55 } | 57 } |
56 | 58 |
57 // Converts |id| into a string. | 59 // Converts |id| into a string. |
58 std::string NodeIdToString(TransportNodeId id) { | 60 std::string NodeIdToString(TransportNodeId id) { |
59 return (id == 0) ? "null" : | 61 return (id == 0) ? "null" : |
60 base::StringPrintf("%d,%d", HiWord(id), LoWord(id)); | 62 base::StringPrintf("%d,%d", HiWord(id), LoWord(id)); |
61 } | 63 } |
62 | 64 |
| 65 // Converts |rect| into a string. |
| 66 std::string RectToString(const Rect& rect) { |
| 67 return base::StringPrintf("%d,%d %dx%d", |
| 68 rect.position().x(), |
| 69 rect.position().y(), |
| 70 rect.size().width(), |
| 71 rect.size().height()); |
| 72 } |
| 73 |
63 // Boolean callback. Sets |result_cache| to the value of |result| and quits | 74 // Boolean callback. Sets |result_cache| to the value of |result| and quits |
64 // the run loop. | 75 // the run loop. |
65 void BooleanCallback(bool* result_cache, bool result) { | 76 void BooleanCallback(bool* result_cache, bool result) { |
66 *result_cache = result; | 77 *result_cache = result; |
67 current_run_loop->Quit(); | 78 current_run_loop->Quit(); |
68 } | 79 } |
69 | 80 |
70 struct TestNode { | 81 struct TestNode { |
71 std::string ToString() const { | 82 std::string ToString() const { |
72 return base::StringPrintf("node=%s parent=%s view=%s", | 83 return base::StringPrintf("node=%s parent=%s view=%s", |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 } | 143 } |
133 | 144 |
134 // Deletes a node, blocking until done. | 145 // Deletes a node, blocking until done. |
135 bool DeleteView(IViewManager* view_manager, TransportViewId view_id) { | 146 bool DeleteView(IViewManager* view_manager, TransportViewId view_id) { |
136 bool result = false; | 147 bool result = false; |
137 view_manager->DeleteView(view_id, base::Bind(&BooleanCallback, &result)); | 148 view_manager->DeleteView(view_id, base::Bind(&BooleanCallback, &result)); |
138 DoRunLoop(); | 149 DoRunLoop(); |
139 return result; | 150 return result; |
140 } | 151 } |
141 | 152 |
| 153 bool SetNodeBounds(IViewManager* view_manager, |
| 154 TransportNodeId node_id, |
| 155 const gfx::Rect& bounds) { |
| 156 bool result = false; |
| 157 view_manager->SetNodeBounds(node_id, bounds, |
| 158 base::Bind(&BooleanCallback, &result)); |
| 159 DoRunLoop(); |
| 160 return result; |
| 161 } |
| 162 |
142 // Adds a node, blocking until done. | 163 // Adds a node, blocking until done. |
143 bool AddNode(IViewManager* view_manager, | 164 bool AddNode(IViewManager* view_manager, |
144 TransportNodeId parent, | 165 TransportNodeId parent, |
145 TransportNodeId child, | 166 TransportNodeId child, |
146 TransportChangeId server_change_id) { | 167 TransportChangeId server_change_id) { |
147 bool result = false; | 168 bool result = false; |
148 view_manager->AddNode(parent, child, server_change_id, | 169 view_manager->AddNode(parent, child, server_change_id, |
149 base::Bind(&BooleanCallback, &result)); | 170 base::Bind(&BooleanCallback, &result)); |
150 DoRunLoop(); | 171 DoRunLoop(); |
151 return result; | 172 return result; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 QuitIfNecessary(); | 284 QuitIfNecessary(); |
264 } | 285 } |
265 virtual void OnServerChangeIdAdvanced( | 286 virtual void OnServerChangeIdAdvanced( |
266 uint32_t next_server_change_id) OVERRIDE { | 287 uint32_t next_server_change_id) OVERRIDE { |
267 changes_.push_back( | 288 changes_.push_back( |
268 base::StringPrintf( | 289 base::StringPrintf( |
269 "ServerChangeIdAdvanced %d", | 290 "ServerChangeIdAdvanced %d", |
270 static_cast<int>(next_server_change_id))); | 291 static_cast<int>(next_server_change_id))); |
271 QuitIfNecessary(); | 292 QuitIfNecessary(); |
272 } | 293 } |
| 294 virtual void OnNodeBoundsChanged(TransportNodeId node_id, |
| 295 const Rect& old_bounds, |
| 296 const Rect& new_bounds) { |
| 297 changes_.push_back( |
| 298 base::StringPrintf( |
| 299 "BoundsChanged node=%s old_bounds=%s new_bounds=%s", |
| 300 NodeIdToString(node_id).c_str(), |
| 301 RectToString(old_bounds).c_str(), |
| 302 RectToString(new_bounds).c_str())); |
| 303 QuitIfNecessary(); |
| 304 } |
273 virtual void OnNodeHierarchyChanged( | 305 virtual void OnNodeHierarchyChanged( |
274 TransportNodeId node, | 306 TransportNodeId node, |
275 TransportNodeId new_parent, | 307 TransportNodeId new_parent, |
276 TransportNodeId old_parent, | 308 TransportNodeId old_parent, |
277 TransportChangeId server_change_id, | 309 TransportChangeId server_change_id, |
278 const mojo::Array<INode>& nodes) OVERRIDE { | 310 const mojo::Array<INode>& nodes) OVERRIDE { |
279 changes_.push_back( | 311 changes_.push_back( |
280 base::StringPrintf( | 312 base::StringPrintf( |
281 "HierarchyChanged change_id=%d node=%s new_parent=%s old_parent=%s", | 313 "HierarchyChanged change_id=%d node=%s new_parent=%s old_parent=%s", |
282 static_cast<int>(server_change_id), | 314 static_cast<int>(server_change_id), |
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 { | 1153 { |
1122 AllocationScope scope; | 1154 AllocationScope scope; |
1123 std::vector<TestNode> nodes; | 1155 std::vector<TestNode> nodes; |
1124 GetNodeTree(view_manager2_.get(), CreateNodeId(1, 1), &nodes); | 1156 GetNodeTree(view_manager2_.get(), CreateNodeId(1, 1), &nodes); |
1125 ASSERT_EQ(2u, nodes.size()); | 1157 ASSERT_EQ(2u, nodes.size()); |
1126 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); | 1158 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); |
1127 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[1].ToString()); | 1159 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[1].ToString()); |
1128 } | 1160 } |
1129 } | 1161 } |
1130 | 1162 |
| 1163 TEST_F(ViewManagerConnectionTest, SetNodeBounds) { |
| 1164 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
| 1165 ASSERT_TRUE(AddNode(view_manager_.get(), |
| 1166 CreateNodeId(0, 1), |
| 1167 CreateNodeId(1, 1), |
| 1168 1)); |
| 1169 EstablishSecondConnection(); |
| 1170 |
| 1171 AllocationScope scope; |
| 1172 ASSERT_TRUE(SetNodeBounds(view_manager_.get(), |
| 1173 CreateNodeId(1, 1), |
| 1174 gfx::Rect(0, 0, 100, 100))); |
| 1175 |
| 1176 client2_.DoRunLoopUntilChangesCount(1); |
| 1177 Changes changes(client2_.GetAndClearChanges()); |
| 1178 ASSERT_EQ(1u, changes.size()); |
| 1179 EXPECT_EQ("BoundsChanged node=1,1 old_bounds=0,0 0x0 new_bounds=0,0 100x100", |
| 1180 changes[0]); |
| 1181 } |
| 1182 |
1131 TEST_F(ViewManagerConnectionTest, SetRoots) { | 1183 TEST_F(ViewManagerConnectionTest, SetRoots) { |
1132 // Create 1, 2, and 3 in the first connection. | 1184 // Create 1, 2, and 3 in the first connection. |
1133 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | 1185 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
1134 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); | 1186 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); |
1135 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 3)); | 1187 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 3)); |
1136 | 1188 |
1137 // Parent 1 to the root. | 1189 // Parent 1 to the root. |
1138 ASSERT_TRUE(AddNode(view_manager_.get(), | 1190 ASSERT_TRUE(AddNode(view_manager_.get(), |
1139 CreateNodeId(0, 1), | 1191 CreateNodeId(0, 1), |
1140 CreateNodeId(client_.id(), 1), | 1192 CreateNodeId(client_.id(), 1), |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1213 ASSERT_EQ(1u, changes.size()); | 1265 ASSERT_EQ(1u, changes.size()); |
1214 EXPECT_EQ("ServerChangeIdAdvanced 6", changes[0]); | 1266 EXPECT_EQ("ServerChangeIdAdvanced 6", changes[0]); |
1215 } | 1267 } |
1216 } | 1268 } |
1217 | 1269 |
1218 // TODO: add tests that verify can't manipulate trees of uknown nodes. | 1270 // TODO: add tests that verify can't manipulate trees of uknown nodes. |
1219 | 1271 |
1220 } // namespace service | 1272 } // namespace service |
1221 } // namespace view_manager | 1273 } // namespace view_manager |
1222 } // namespace mojo | 1274 } // namespace mojo |
OLD | NEW |