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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 RunMainLoop(); | 160 RunMainLoop(); |
161 return result; | 161 return result; |
162 } | 162 } |
163 void GetNodeTree(Id node_id, std::vector<TestNode>* nodes) { | 163 void GetNodeTree(Id node_id, std::vector<TestNode>* nodes) { |
164 changes_.clear(); | 164 changes_.clear(); |
165 view_manager_->GetNodeTree(node_id, | 165 view_manager_->GetNodeTree(node_id, |
166 base::Bind(&ViewManagerProxy::GotNodeTree, | 166 base::Bind(&ViewManagerProxy::GotNodeTree, |
167 base::Unretained(this), nodes)); | 167 base::Unretained(this), nodes)); |
168 RunMainLoop(); | 168 RunMainLoop(); |
169 } | 169 } |
170 bool Embed(const std::vector<Id>& nodes) { | 170 bool Embed(const Id node_id) { |
171 changes_.clear(); | 171 changes_.clear(); |
172 base::AutoReset<bool> auto_reset(&in_embed_, true); | 172 base::AutoReset<bool> auto_reset(&in_embed_, true); |
173 bool result = false; | 173 bool result = false; |
174 view_manager_->Embed(kTestServiceURL, Array<Id>::From(nodes), | 174 view_manager_->Embed(kTestServiceURL, node_id, |
175 base::Bind(&ViewManagerProxy::GotResult, | 175 base::Bind(&ViewManagerProxy::GotResult, |
176 base::Unretained(this), &result)); | 176 base::Unretained(this), &result)); |
177 RunMainLoop(); | 177 RunMainLoop(); |
178 return result; | 178 return result; |
179 } | 179 } |
180 bool DeleteNode(Id node_id, Id server_change_id) { | 180 bool DeleteNode(Id node_id, Id server_change_id) { |
181 changes_.clear(); | 181 changes_.clear(); |
182 bool result = false; | 182 bool result = false; |
183 view_manager_->DeleteNode(node_id, | 183 view_manager_->DeleteNode(node_id, |
184 server_change_id, | 184 server_change_id, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 | 317 |
318 // ViewMangerClient: | 318 // ViewMangerClient: |
319 virtual void OnViewManagerConnectionEstablished( | 319 virtual void OnViewManagerConnectionEstablished( |
320 ConnectionSpecificId connection_id, | 320 ConnectionSpecificId connection_id, |
321 const String& creator_url, | 321 const String& creator_url, |
322 Id next_server_change_id, | 322 Id next_server_change_id, |
323 Array<NodeDataPtr> nodes) OVERRIDE { | 323 Array<NodeDataPtr> nodes) OVERRIDE { |
324 tracker_.OnViewManagerConnectionEstablished( | 324 tracker_.OnViewManagerConnectionEstablished( |
325 connection_id, creator_url, next_server_change_id, nodes.Pass()); | 325 connection_id, creator_url, next_server_change_id, nodes.Pass()); |
326 } | 326 } |
327 virtual void OnRootsAdded(Array<NodeDataPtr> nodes) OVERRIDE { | 327 virtual void OnRootAdded(Array<NodeDataPtr> nodes) OVERRIDE { |
328 tracker_.OnRootsAdded(nodes.Pass()); | 328 tracker_.OnRootAdded(nodes.Pass()); |
329 } | 329 } |
330 virtual void OnServerChangeIdAdvanced( | 330 virtual void OnServerChangeIdAdvanced( |
331 Id next_server_change_id) OVERRIDE { | 331 Id next_server_change_id) OVERRIDE { |
332 tracker_.OnServerChangeIdAdvanced(next_server_change_id); | 332 tracker_.OnServerChangeIdAdvanced(next_server_change_id); |
333 } | 333 } |
334 virtual void OnNodeBoundsChanged(Id node_id, | 334 virtual void OnNodeBoundsChanged(Id node_id, |
335 RectPtr old_bounds, | 335 RectPtr old_bounds, |
336 RectPtr new_bounds) OVERRIDE { | 336 RectPtr new_bounds) OVERRIDE { |
337 tracker_.OnNodeBoundsChanged(node_id, old_bounds.Pass(), new_bounds.Pass()); | 337 tracker_.OnNodeBoundsChanged(node_id, old_bounds.Pass(), new_bounds.Pass()); |
338 } | 338 } |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 } | 471 } |
472 | 472 |
473 virtual void TearDown() OVERRIDE { | 473 virtual void TearDown() OVERRIDE { |
474 if (connection2_) | 474 if (connection2_) |
475 connection2_->Destroy(); | 475 connection2_->Destroy(); |
476 if (connection_) | 476 if (connection_) |
477 connection_->Destroy(); | 477 connection_->Destroy(); |
478 } | 478 } |
479 | 479 |
480 protected: | 480 protected: |
481 void EstablishSecondConnectionWithRoots(Id id1, Id id2) { | 481 void EstablishSecondConnectionWithRoot(Id root_id) { |
482 std::vector<Id> node_ids; | 482 ASSERT_TRUE(connection_->Embed(root_id)); |
483 node_ids.push_back(id1); | |
484 if (id2 != 0) | |
485 node_ids.push_back(id2); | |
486 ASSERT_TRUE(connection_->Embed(node_ids)); | |
487 connection2_ = ViewManagerProxy::WaitForInstance(); | 483 connection2_ = ViewManagerProxy::WaitForInstance(); |
488 ASSERT_TRUE(connection2_ != NULL); | 484 ASSERT_TRUE(connection2_ != NULL); |
489 connection2_->DoRunLoopUntilChangesCount(1); | 485 connection2_->DoRunLoopUntilChangesCount(1); |
490 ASSERT_EQ(1u, connection2_->changes().size()); | 486 ASSERT_EQ(1u, connection2_->changes().size()); |
491 } | 487 } |
492 | 488 |
493 // Creates a second connection to the viewmanager. | 489 // Creates a second connection to the viewmanager. |
494 void EstablishSecondConnection(bool create_initial_node) { | 490 void EstablishSecondConnection(bool create_initial_node) { |
495 if (create_initial_node) | 491 if (create_initial_node) |
496 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 492 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
497 ASSERT_NO_FATAL_FAILURE( | 493 ASSERT_NO_FATAL_FAILURE( |
498 EstablishSecondConnectionWithRoots(BuildNodeId(1, 1), 0)); | 494 EstablishSecondConnectionWithRoot(BuildNodeId(1, 1))); |
499 const std::vector<Change>& changes(connection2_->changes()); | 495 const std::vector<Change>& changes(connection2_->changes()); |
500 ASSERT_EQ(1u, changes.size()); | 496 ASSERT_EQ(1u, changes.size()); |
501 EXPECT_EQ("OnConnectionEstablished creator=mojo:test_url", | 497 EXPECT_EQ("OnConnectionEstablished creator=mojo:test_url", |
502 ChangesToDescription1(changes)[0]); | 498 ChangesToDescription1(changes)[0]); |
503 if (create_initial_node) { | 499 if (create_initial_node) { |
504 EXPECT_EQ("[node=1,1 parent=null view=null]", | 500 EXPECT_EQ("[node=1,1 parent=null view=null]", |
505 ChangeNodeDescription(changes)); | 501 ChangeNodeDescription(changes)); |
506 } | 502 } |
507 } | 503 } |
508 | 504 |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 // Various assertions around SetRoots. | 1169 // Various assertions around SetRoots. |
1174 TEST_F(ViewManagerTest, SetRoots) { | 1170 TEST_F(ViewManagerTest, SetRoots) { |
1175 // Create 1, 2, and 3 in the first connection. | 1171 // Create 1, 2, and 3 in the first connection. |
1176 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1172 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
1177 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1173 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
1178 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); | 1174 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); |
1179 | 1175 |
1180 // Parent 1 to the root. | 1176 // Parent 1 to the root. |
1181 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 1)); | 1177 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 1)); |
1182 | 1178 |
1183 // Establish the second connection and give it the roots 1 and 3. | 1179 // Establish the second connection with roots 1 and 3. |
1184 { | 1180 { |
1185 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnectionWithRoots( | 1181 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
1186 BuildNodeId(1, 1), BuildNodeId(1, 3))); | 1182 |
| 1183 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 3))); |
| 1184 connection2_->DoRunLoopUntilChangesCount(1); |
1187 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1185 const Changes changes(ChangesToDescription1(connection2_->changes())); |
1188 ASSERT_EQ(1u, changes.size()); | 1186 ASSERT_EQ(1u, changes.size()); |
1189 EXPECT_EQ("OnConnectionEstablished creator=mojo:test_url", changes[0]); | 1187 EXPECT_EQ("OnRootAdded", changes[0]); |
1190 EXPECT_EQ("[node=1,1 parent=null view=null]," | 1188 EXPECT_EQ("[node=1,3 parent=null view=null]", |
1191 "[node=1,3 parent=null view=null]", | |
1192 ChangeNodeDescription(connection2_->changes())); | 1189 ChangeNodeDescription(connection2_->changes())); |
1193 } | 1190 } |
1194 | 1191 |
1195 // Create 4 and add it to the root, connection 2 should only get id advanced. | 1192 // Create 4 and add it to the root, connection 2 should only get id advanced. |
1196 { | 1193 { |
1197 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 4))); | 1194 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 4))); |
1198 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 4), 2)); | 1195 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 4), 2)); |
1199 | 1196 |
1200 connection2_->DoRunLoopUntilChangesCount(1); | 1197 connection2_->DoRunLoopUntilChangesCount(1); |
1201 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1198 const Changes changes(ChangesToDescription1(connection2_->changes())); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1342 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1339 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
1343 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1340 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
1344 | 1341 |
1345 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 1)); | 1342 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 1)); |
1346 | 1343 |
1347 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1344 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
1348 | 1345 |
1349 // Try to connect again to 1,1, this should fail as already connected to that | 1346 // Try to connect again to 1,1, this should fail as already connected to that |
1350 // root. | 1347 // root. |
1351 { | 1348 { |
1352 std::vector<Id> node_ids; | 1349 ASSERT_FALSE(connection_->Embed(BuildNodeId(1, 1))); |
1353 node_ids.push_back(BuildNodeId(1, 1)); | |
1354 ASSERT_FALSE(connection_->Embed(node_ids)); | |
1355 } | 1350 } |
1356 | 1351 |
1357 // Connecting to 1,2 should succeed and end up in connection2. | 1352 // Connecting to 1,2 should succeed and end up in connection2. |
1358 { | 1353 { |
1359 std::vector<Id> node_ids; | 1354 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 2))); |
1360 node_ids.push_back(BuildNodeId(1, 2)); | |
1361 ASSERT_TRUE(connection_->Embed(node_ids)); | |
1362 connection2_->DoRunLoopUntilChangesCount(1); | 1355 connection2_->DoRunLoopUntilChangesCount(1); |
1363 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1356 const Changes changes(ChangesToDescription1(connection2_->changes())); |
1364 ASSERT_EQ(1u, changes.size()); | 1357 ASSERT_EQ(1u, changes.size()); |
1365 EXPECT_EQ("OnRootsAdded", changes[0]); | 1358 EXPECT_EQ("OnRootAdded", changes[0]); |
1366 EXPECT_EQ("[node=1,2 parent=1,1 view=null]", | 1359 EXPECT_EQ("[node=1,2 parent=1,1 view=null]", |
1367 ChangeNodeDescription(connection2_->changes())); | 1360 ChangeNodeDescription(connection2_->changes())); |
1368 } | 1361 } |
1369 } | 1362 } |
1370 | 1363 |
1371 TEST_F(ViewManagerTest, OnViewInput) { | 1364 TEST_F(ViewManagerTest, OnViewInput) { |
1372 // Create node 1 and assign a view from connection 2 to it. | 1365 // Create node 1 and assign a view from connection 2 to it. |
1373 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1366 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
1374 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1367 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
1375 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 11))); | 1368 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 11))); |
(...skipping 21 matching lines...) Expand all Loading... |
1397 // originating connection. | 1390 // originating connection. |
1398 | 1391 |
1399 // TODO(beng): Add tests for focus: | 1392 // TODO(beng): Add tests for focus: |
1400 // - focus between two nodes known to a connection | 1393 // - focus between two nodes known to a connection |
1401 // - focus between nodes unknown to one of the connections. | 1394 // - focus between nodes unknown to one of the connections. |
1402 // - focus between nodes unknown to either connection. | 1395 // - focus between nodes unknown to either connection. |
1403 | 1396 |
1404 } // namespace service | 1397 } // namespace service |
1405 } // namespace view_manager | 1398 } // namespace view_manager |
1406 } // namespace mojo | 1399 } // namespace mojo |
OLD | NEW |