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" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 NodeIdToString(node_id).c_str(), | 55 NodeIdToString(node_id).c_str(), |
56 NodeIdToString(parent_id).c_str(), | 56 NodeIdToString(parent_id).c_str(), |
57 NodeIdToString(view_id).c_str()); | 57 NodeIdToString(view_id).c_str()); |
58 } | 58 } |
59 | 59 |
60 TransportNodeId parent_id; | 60 TransportNodeId parent_id; |
61 TransportNodeId node_id; | 61 TransportNodeId node_id; |
62 TransportNodeId view_id; | 62 TransportNodeId view_id; |
63 }; | 63 }; |
64 | 64 |
65 void INodesToTestNodes(const mojo::Array<INode>& data, | 65 // Callback that results in a vector of INodes. The INodes are converted to |
66 std::vector<TestNode>* test_nodes) { | 66 // TestNodes. |
| 67 void INodesCallback(std::vector<TestNode>* test_nodes, |
| 68 const mojo::Array<INode>& data) { |
67 for (size_t i = 0; i < data.size(); ++i) { | 69 for (size_t i = 0; i < data.size(); ++i) { |
68 TestNode node; | 70 TestNode node; |
69 node.parent_id = data[i].parent_id(); | 71 node.parent_id = data[i].parent_id(); |
70 node.node_id = data[i].node_id(); | 72 node.node_id = data[i].node_id(); |
71 node.view_id = data[i].view_id(); | 73 node.view_id = data[i].view_id(); |
72 test_nodes->push_back(node); | 74 test_nodes->push_back(node); |
73 } | 75 } |
74 } | |
75 | |
76 // Callback that results in a vector of INodes. The INodes are converted to | |
77 // TestNodes. | |
78 void INodesCallback(std::vector<TestNode>* test_nodes, | |
79 const mojo::Array<INode>& data) { | |
80 INodesToTestNodes(data, test_nodes); | |
81 current_run_loop->Quit(); | 76 current_run_loop->Quit(); |
82 } | 77 } |
83 | 78 |
84 // Creates an id used for transport from the specified parameters. | 79 // Creates an id used for transport from the specified parameters. |
85 TransportNodeId CreateNodeId(TransportConnectionId connection_id, | 80 TransportNodeId CreateNodeId(TransportConnectionId connection_id, |
86 TransportConnectionSpecificNodeId node_id) { | 81 TransportConnectionSpecificNodeId node_id) { |
87 return (connection_id << 16) | node_id; | 82 return (connection_id << 16) | node_id; |
88 } | 83 } |
89 | 84 |
90 // Creates an id used for transport from the specified parameters. | 85 // Creates an id used for transport from the specified parameters. |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 ViewManagerClientImpl() | 173 ViewManagerClientImpl() |
179 : id_(0), | 174 : id_(0), |
180 next_server_change_id_(0), | 175 next_server_change_id_(0), |
181 quit_count_(0) {} | 176 quit_count_(0) {} |
182 | 177 |
183 TransportConnectionId id() const { return id_; } | 178 TransportConnectionId id() const { return id_; } |
184 | 179 |
185 TransportChangeId next_server_change_id() const { | 180 TransportChangeId next_server_change_id() const { |
186 return next_server_change_id_; | 181 return next_server_change_id_; |
187 } | 182 } |
188 const std::vector<TestNode>& initial_nodes() const { | |
189 return initial_nodes_; | |
190 } | |
191 const std::vector<TestNode>& hierarchy_changed_nodes() const { | |
192 return hierarchy_changed_nodes_; | |
193 } | |
194 | 183 |
195 Changes GetAndClearChanges() { | 184 Changes GetAndClearChanges() { |
196 Changes changes; | 185 Changes changes; |
197 changes.swap(changes_); | 186 changes.swap(changes_); |
198 return changes; | 187 return changes; |
199 } | 188 } |
200 | 189 |
201 void WaitForId() { | 190 void WaitForId() { |
202 if (id_ == 0) | 191 if (id_ == 0) |
203 DoRunLoop(); | 192 DoRunLoop(); |
204 } | 193 } |
205 | 194 |
206 void DoRunLoopUntilChangesCount(size_t count) { | 195 void DoRunLoopUntilChangesCount(size_t count) { |
207 if (changes_.size() >= count) | 196 if (changes_.size() >= count) |
208 return; | 197 return; |
209 quit_count_ = count - changes_.size(); | 198 quit_count_ = count - changes_.size(); |
210 DoRunLoop(); | 199 DoRunLoop(); |
211 } | 200 } |
212 | 201 |
213 private: | 202 private: |
214 // IViewManagerClient overrides: | 203 // IViewManagerClient overrides: |
215 virtual void OnConnectionEstablished( | 204 virtual void OnConnectionEstablished( |
216 TransportConnectionId connection_id, | 205 TransportConnectionId connection_id, |
217 TransportChangeId next_server_change_id, | 206 TransportChangeId next_server_change_id) OVERRIDE { |
218 const mojo::Array<INode>& nodes) OVERRIDE { | |
219 id_ = connection_id; | 207 id_ = connection_id; |
220 next_server_change_id_ = next_server_change_id; | 208 next_server_change_id_ = next_server_change_id; |
221 INodesToTestNodes(nodes, &initial_nodes_); | |
222 if (current_run_loop) | 209 if (current_run_loop) |
223 current_run_loop->Quit(); | 210 current_run_loop->Quit(); |
224 } | 211 } |
225 virtual void OnServerChangeIdAdvanced( | |
226 uint32_t next_server_change_id) OVERRIDE { | |
227 changes_.push_back( | |
228 base::StringPrintf( | |
229 "ServerChangeIdAdvanced %d", | |
230 static_cast<int>(next_server_change_id))); | |
231 QuitIfNecessary(); | |
232 } | |
233 virtual void OnNodeHierarchyChanged( | 212 virtual void OnNodeHierarchyChanged( |
234 TransportNodeId node, | 213 TransportNodeId node, |
235 TransportNodeId new_parent, | 214 TransportNodeId new_parent, |
236 TransportNodeId old_parent, | 215 TransportNodeId old_parent, |
237 TransportChangeId server_change_id, | 216 TransportChangeId server_change_id) OVERRIDE { |
238 const mojo::Array<INode>& nodes) OVERRIDE { | |
239 changes_.push_back( | 217 changes_.push_back( |
240 base::StringPrintf( | 218 base::StringPrintf( |
241 "HierarchyChanged change_id=%d node=%s new_parent=%s old_parent=%s", | 219 "HierarchyChanged change_id=%d node=%s new_parent=%s old_parent=%s", |
242 static_cast<int>(server_change_id), | 220 static_cast<int>(server_change_id), |
243 NodeIdToString(node).c_str(), | 221 NodeIdToString(node).c_str(), |
244 NodeIdToString(new_parent).c_str(), | 222 NodeIdToString(new_parent).c_str(), |
245 NodeIdToString(old_parent).c_str())); | 223 NodeIdToString(old_parent).c_str())); |
246 hierarchy_changed_nodes_.clear(); | |
247 INodesToTestNodes(nodes, &hierarchy_changed_nodes_); | |
248 QuitIfNecessary(); | 224 QuitIfNecessary(); |
249 } | 225 } |
250 virtual void OnNodeDeleted(TransportNodeId node, | 226 virtual void OnNodeDeleted(TransportNodeId node, |
251 TransportChangeId server_change_id) OVERRIDE { | 227 TransportChangeId server_change_id) OVERRIDE { |
252 changes_.push_back( | 228 changes_.push_back( |
253 base::StringPrintf( | 229 base::StringPrintf( |
254 "NodeDeleted change_id=%d node=%s", | 230 "NodeDeleted change_id=%d node=%s", |
255 static_cast<int>(server_change_id), | 231 static_cast<int>(server_change_id), |
256 NodeIdToString(node).c_str())); | 232 NodeIdToString(node).c_str())); |
257 QuitIfNecessary(); | 233 QuitIfNecessary(); |
(...skipping 23 matching lines...) Expand all Loading... |
281 } | 257 } |
282 | 258 |
283 TransportConnectionId id_; | 259 TransportConnectionId id_; |
284 TransportChangeId next_server_change_id_; | 260 TransportChangeId next_server_change_id_; |
285 | 261 |
286 // Used to determine when/if to quit the run loop. | 262 // Used to determine when/if to quit the run loop. |
287 size_t quit_count_; | 263 size_t quit_count_; |
288 | 264 |
289 Changes changes_; | 265 Changes changes_; |
290 | 266 |
291 // Set of nodes sent when connection created. | |
292 std::vector<TestNode> initial_nodes_; | |
293 | |
294 // Nodes sent from last OnNodeHierarchyChanged. | |
295 std::vector<TestNode> hierarchy_changed_nodes_; | |
296 | |
297 DISALLOW_COPY_AND_ASSIGN(ViewManagerClientImpl); | 267 DISALLOW_COPY_AND_ASSIGN(ViewManagerClientImpl); |
298 }; | 268 }; |
299 | 269 |
300 class ViewManagerConnectionTest : public testing::Test { | 270 class ViewManagerConnectionTest : public testing::Test { |
301 public: | 271 public: |
302 ViewManagerConnectionTest() {} | 272 ViewManagerConnectionTest() {} |
303 | 273 |
304 virtual void SetUp() OVERRIDE { | 274 virtual void SetUp() OVERRIDE { |
305 test_helper_.Init(); | 275 test_helper_.Init(); |
306 | 276 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 ASSERT_TRUE(AddNode(view_manager_.get(), | 354 ASSERT_TRUE(AddNode(view_manager_.get(), |
385 CreateNodeId(client_.id(), 1), | 355 CreateNodeId(client_.id(), 1), |
386 CreateNodeId(client_.id(), 2), | 356 CreateNodeId(client_.id(), 2), |
387 1)); | 357 1)); |
388 Changes changes(client_.GetAndClearChanges()); | 358 Changes changes(client_.GetAndClearChanges()); |
389 ASSERT_TRUE(changes.empty()); | 359 ASSERT_TRUE(changes.empty()); |
390 | 360 |
391 client2_.DoRunLoopUntilChangesCount(1); | 361 client2_.DoRunLoopUntilChangesCount(1); |
392 changes = client2_.GetAndClearChanges(); | 362 changes = client2_.GetAndClearChanges(); |
393 ASSERT_EQ(1u, changes.size()); | 363 ASSERT_EQ(1u, changes.size()); |
394 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); | 364 EXPECT_EQ( |
| 365 "HierarchyChanged change_id=1 node=1,2 new_parent=1,1 old_parent=null", |
| 366 changes[0]); |
395 } | 367 } |
396 | 368 |
397 // Remove 2 from its parent. | 369 // Remove 2 from its parent. |
398 { | 370 { |
399 AllocationScope scope; | 371 AllocationScope scope; |
400 ASSERT_TRUE(RemoveNodeFromParent(view_manager_.get(), | 372 ASSERT_TRUE(RemoveNodeFromParent(view_manager_.get(), |
401 CreateNodeId(client_.id(), 2), | 373 CreateNodeId(client_.id(), 2), |
402 2)); | 374 2)); |
403 Changes changes(client_.GetAndClearChanges()); | 375 Changes changes(client_.GetAndClearChanges()); |
404 ASSERT_TRUE(changes.empty()); | 376 ASSERT_TRUE(changes.empty()); |
405 | 377 |
406 client2_.DoRunLoopUntilChangesCount(1); | 378 client2_.DoRunLoopUntilChangesCount(1); |
407 changes = client2_.GetAndClearChanges(); | 379 changes = client2_.GetAndClearChanges(); |
408 ASSERT_EQ(1u, changes.size()); | 380 ASSERT_EQ(1u, changes.size()); |
409 EXPECT_EQ("ServerChangeIdAdvanced 3", changes[0]); | 381 EXPECT_EQ( |
| 382 "HierarchyChanged change_id=2 node=1,2 new_parent=null old_parent=1,1", |
| 383 changes[0]); |
410 } | 384 } |
411 } | 385 } |
412 | 386 |
413 // Verifies AddNode fails when node is already in position. | 387 // Verifies AddNode fails when node is already in position. |
414 TEST_F(ViewManagerConnectionTest, AddNodeWithNoChange) { | 388 TEST_F(ViewManagerConnectionTest, AddNodeWithNoChange) { |
415 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | 389 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
416 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); | 390 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); |
417 | 391 |
418 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | 392 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
419 | 393 |
420 EstablishSecondConnection(); | 394 EstablishSecondConnection(); |
421 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); | 395 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); |
422 | 396 |
423 // Make 2 a child of 1. | 397 // Make 2 a child of 1. |
424 { | 398 { |
425 AllocationScope scope; | 399 AllocationScope scope; |
426 ASSERT_TRUE(AddNode(view_manager_.get(), | 400 ASSERT_TRUE(AddNode(view_manager_.get(), |
427 CreateNodeId(client_.id(), 1), | 401 CreateNodeId(client_.id(), 1), |
428 CreateNodeId(client_.id(), 2), | 402 CreateNodeId(client_.id(), 2), |
429 1)); | 403 1)); |
430 Changes changes(client_.GetAndClearChanges()); | 404 Changes changes(client_.GetAndClearChanges()); |
431 ASSERT_TRUE(changes.empty()); | 405 ASSERT_TRUE(changes.empty()); |
432 | 406 |
433 client2_.DoRunLoopUntilChangesCount(1); | 407 client2_.DoRunLoopUntilChangesCount(1); |
434 changes = client2_.GetAndClearChanges(); | 408 changes = client2_.GetAndClearChanges(); |
435 ASSERT_EQ(1u, changes.size()); | 409 ASSERT_EQ(1u, changes.size()); |
436 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); | 410 EXPECT_EQ( |
| 411 "HierarchyChanged change_id=1 node=1,2 new_parent=1,1 old_parent=null", |
| 412 changes[0]); |
437 } | 413 } |
438 | 414 |
439 // Try again, this should fail. | 415 // Try again, this should fail. |
440 { | 416 { |
441 AllocationScope scope; | 417 AllocationScope scope; |
442 EXPECT_FALSE(AddNode(view_manager_.get(), | 418 EXPECT_FALSE(AddNode(view_manager_.get(), |
443 CreateNodeId(client_.id(), 1), | 419 CreateNodeId(client_.id(), 1), |
444 CreateNodeId(client_.id(), 2), | 420 CreateNodeId(client_.id(), 2), |
445 2)); | 421 2)); |
446 Changes changes(client_.GetAndClearChanges()); | 422 Changes changes(client_.GetAndClearChanges()); |
(...skipping 17 matching lines...) Expand all Loading... |
464 ASSERT_TRUE(AddNode(view_manager_.get(), | 440 ASSERT_TRUE(AddNode(view_manager_.get(), |
465 CreateNodeId(client_.id(), 1), | 441 CreateNodeId(client_.id(), 1), |
466 CreateNodeId(client_.id(), 2), | 442 CreateNodeId(client_.id(), 2), |
467 1)); | 443 1)); |
468 Changes changes(client_.GetAndClearChanges()); | 444 Changes changes(client_.GetAndClearChanges()); |
469 ASSERT_TRUE(changes.empty()); | 445 ASSERT_TRUE(changes.empty()); |
470 | 446 |
471 client2_.DoRunLoopUntilChangesCount(1); | 447 client2_.DoRunLoopUntilChangesCount(1); |
472 changes = client2_.GetAndClearChanges(); | 448 changes = client2_.GetAndClearChanges(); |
473 ASSERT_EQ(1u, changes.size()); | 449 ASSERT_EQ(1u, changes.size()); |
474 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); | 450 EXPECT_EQ( |
| 451 "HierarchyChanged change_id=1 node=1,2 new_parent=1,1 old_parent=null", |
| 452 changes[0]); |
475 } | 453 } |
476 | 454 |
477 // Try to make 1 a child of 2, this should fail since 1 is an ancestor of 2. | 455 // Try to make 1 a child of 2, this should fail since 1 is an ancestor of 2. |
478 { | 456 { |
479 AllocationScope scope; | 457 AllocationScope scope; |
480 EXPECT_FALSE(AddNode(view_manager_.get(), | 458 EXPECT_FALSE(AddNode(view_manager_.get(), |
481 CreateNodeId(client_.id(), 2), | 459 CreateNodeId(client_.id(), 2), |
482 CreateNodeId(client_.id(), 1), | 460 CreateNodeId(client_.id(), 1), |
483 2)); | 461 2)); |
484 Changes changes(client_.GetAndClearChanges()); | 462 Changes changes(client_.GetAndClearChanges()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 ASSERT_TRUE(AddNode(view_manager_.get(), | 497 ASSERT_TRUE(AddNode(view_manager_.get(), |
520 CreateNodeId(client_.id(), 21), | 498 CreateNodeId(client_.id(), 21), |
521 CreateNodeId(client_.id(), 3), | 499 CreateNodeId(client_.id(), 3), |
522 1)); | 500 1)); |
523 Changes changes(client_.GetAndClearChanges()); | 501 Changes changes(client_.GetAndClearChanges()); |
524 ASSERT_TRUE(changes.empty()); | 502 ASSERT_TRUE(changes.empty()); |
525 | 503 |
526 client2_.DoRunLoopUntilChangesCount(1); | 504 client2_.DoRunLoopUntilChangesCount(1); |
527 changes = client2_.GetAndClearChanges(); | 505 changes = client2_.GetAndClearChanges(); |
528 ASSERT_EQ(1u, changes.size()); | 506 ASSERT_EQ(1u, changes.size()); |
529 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); | 507 EXPECT_EQ( |
| 508 "HierarchyChanged change_id=1 node=1,3 new_parent=1,21 old_parent=null", |
| 509 changes[0]); |
530 } | 510 } |
531 | 511 |
532 // Make 21 a child of the root. | 512 // Make 21 a child of the root. |
533 { | 513 { |
534 AllocationScope scope; | 514 AllocationScope scope; |
535 ASSERT_TRUE(AddNode(view_manager_.get(), | 515 ASSERT_TRUE(AddNode(view_manager_.get(), |
536 CreateNodeId(0, 1), | 516 CreateNodeId(0, 1), |
537 CreateNodeId(client_.id(), 21), | 517 CreateNodeId(client_.id(), 21), |
538 2)); | 518 2)); |
539 Changes changes(client_.GetAndClearChanges()); | 519 Changes changes(client_.GetAndClearChanges()); |
540 ASSERT_TRUE(changes.empty()); | 520 ASSERT_TRUE(changes.empty()); |
541 | 521 |
542 client2_.DoRunLoopUntilChangesCount(1); | 522 client2_.DoRunLoopUntilChangesCount(1); |
543 changes = client2_.GetAndClearChanges(); | 523 changes = client2_.GetAndClearChanges(); |
544 ASSERT_EQ(1u, changes.size()); | 524 ASSERT_EQ(1u, changes.size()); |
545 EXPECT_EQ( | 525 EXPECT_EQ( |
546 "HierarchyChanged change_id=2 node=1,21 new_parent=0,1 old_parent=null", | 526 "HierarchyChanged change_id=2 node=1,21 new_parent=0,1 old_parent=null", |
547 changes[0]); | 527 changes[0]); |
548 } | 528 } |
549 } | 529 } |
550 | 530 |
551 // Verifies adding to root sends right notifications. | |
552 TEST_F(ViewManagerConnectionTest, NodeHierarchyChangedNodes) { | |
553 // Create nodes 1 and 11 with 1 parented to the root and 11 a child of 1. | |
554 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | |
555 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 11)); | |
556 | |
557 // Make 11 a child of 1. | |
558 { | |
559 AllocationScope scope; | |
560 ASSERT_TRUE(AddNode(view_manager_.get(), | |
561 CreateNodeId(client_.id(), 1), | |
562 CreateNodeId(client_.id(), 11), | |
563 1)); | |
564 ASSERT_TRUE(client_.GetAndClearChanges().empty()); | |
565 } | |
566 | |
567 EstablishSecondConnection(); | |
568 | |
569 // Make 1 a child of the root. | |
570 { | |
571 AllocationScope scope; | |
572 ASSERT_TRUE(AddNode(view_manager_.get(), | |
573 CreateNodeId(0, 1), | |
574 CreateNodeId(client_.id(), 1), | |
575 2)); | |
576 ASSERT_TRUE(client_.GetAndClearChanges().empty()); | |
577 | |
578 // Client 2 should get a hierarchy change that includes the new nodes as it | |
579 // has not yet seen them. | |
580 client2_.DoRunLoopUntilChangesCount(1); | |
581 Changes changes(client2_.GetAndClearChanges()); | |
582 ASSERT_EQ(1u, changes.size()); | |
583 EXPECT_EQ( | |
584 "HierarchyChanged change_id=2 node=1,1 new_parent=0,1 old_parent=null", | |
585 changes[0]); | |
586 const std::vector<TestNode>& nodes(client2_.hierarchy_changed_nodes()); | |
587 ASSERT_EQ(2u, nodes.size()); | |
588 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); | |
589 EXPECT_EQ("node=1,11 parent=1,1 view=null", nodes[1].ToString()); | |
590 } | |
591 | |
592 // Remove 1 from the root. | |
593 { | |
594 AllocationScope scope; | |
595 ASSERT_TRUE(RemoveNodeFromParent(view_manager_.get(), | |
596 CreateNodeId(client_.id(), 1), | |
597 3)); | |
598 ASSERT_TRUE(client_.GetAndClearChanges().empty()); | |
599 | |
600 client2_.DoRunLoopUntilChangesCount(1); | |
601 Changes changes(client2_.GetAndClearChanges()); | |
602 ASSERT_EQ(1u, changes.size()); | |
603 EXPECT_EQ( | |
604 "HierarchyChanged change_id=3 node=1,1 new_parent=null old_parent=0,1", | |
605 changes[0]); | |
606 } | |
607 | |
608 // Create another node, 111, parent it to 11. | |
609 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 111)); | |
610 { | |
611 AllocationScope scope; | |
612 ASSERT_TRUE(AddNode(view_manager_.get(), | |
613 CreateNodeId(client_.id(), 11), | |
614 CreateNodeId(client_.id(), 111), | |
615 4)); | |
616 ASSERT_TRUE(client_.GetAndClearChanges().empty()); | |
617 | |
618 client2_.DoRunLoopUntilChangesCount(1); | |
619 Changes changes(client2_.GetAndClearChanges()); | |
620 ASSERT_EQ(1u, changes.size()); | |
621 // Even though 11 isn't attached to the root client 2 is still notified of | |
622 // the change because it was told about 11. | |
623 EXPECT_EQ( | |
624 "HierarchyChanged change_id=4 node=1,111 new_parent=1,11 " | |
625 "old_parent=null", changes[0]); | |
626 const std::vector<TestNode>& nodes(client2_.hierarchy_changed_nodes()); | |
627 ASSERT_EQ(1u, nodes.size()); | |
628 EXPECT_EQ("node=1,111 parent=1,11 view=null", nodes[0].ToString()); | |
629 } | |
630 | |
631 // Reattach 1 to the root. | |
632 { | |
633 ASSERT_TRUE(AddNode(view_manager_.get(), | |
634 CreateNodeId(0, 1), | |
635 CreateNodeId(client_.id(), 1), | |
636 5)); | |
637 ASSERT_TRUE(client_.GetAndClearChanges().empty()); | |
638 | |
639 client2_.DoRunLoopUntilChangesCount(1); | |
640 Changes changes = client2_.GetAndClearChanges(); | |
641 ASSERT_EQ(1u, changes.size()); | |
642 EXPECT_EQ( | |
643 "HierarchyChanged change_id=5 node=1,1 new_parent=0,1 old_parent=null", | |
644 changes[0]); | |
645 ASSERT_TRUE(client2_.hierarchy_changed_nodes().empty()); | |
646 } | |
647 } | |
648 | |
649 TEST_F(ViewManagerConnectionTest, NodeHierarchyChangedAddingKnownToUnknown) { | |
650 // Create the following structure: root -> 1 -> 11 and 2->21 (2 has no | |
651 // parent). | |
652 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | |
653 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 11)); | |
654 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); | |
655 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 21)); | |
656 | |
657 // Set up the hierarchy. | |
658 { | |
659 AllocationScope scope; | |
660 ASSERT_TRUE(AddNode(view_manager_.get(), | |
661 CreateNodeId(0, 1), | |
662 CreateNodeId(client_.id(), 1), | |
663 1)); | |
664 ASSERT_TRUE(AddNode(view_manager_.get(), | |
665 CreateNodeId(client_.id(), 1), | |
666 CreateNodeId(client_.id(), 11), | |
667 2)); | |
668 ASSERT_TRUE(AddNode(view_manager_.get(), | |
669 CreateNodeId(client_.id(), 2), | |
670 CreateNodeId(client_.id(), 21), | |
671 3)); | |
672 } | |
673 | |
674 EstablishSecondConnection(); | |
675 | |
676 // Remove 11. | |
677 { | |
678 AllocationScope scope; | |
679 ASSERT_TRUE(RemoveNodeFromParent(view_manager_.get(), | |
680 CreateNodeId(client_.id(), 11), | |
681 4)); | |
682 ASSERT_TRUE(client_.GetAndClearChanges().empty()); | |
683 | |
684 client2_.DoRunLoopUntilChangesCount(1); | |
685 Changes changes(client2_.GetAndClearChanges()); | |
686 ASSERT_EQ(1u, changes.size()); | |
687 EXPECT_EQ( | |
688 "HierarchyChanged change_id=4 node=1,11 new_parent=null old_parent=1,1", | |
689 changes[0]); | |
690 EXPECT_TRUE(client2_.hierarchy_changed_nodes().empty()); | |
691 } | |
692 | |
693 // Add 11 to 21. As client2 knows about 11 it should receive the new | |
694 // hierarchy. | |
695 { | |
696 AllocationScope scope; | |
697 ASSERT_TRUE(AddNode(view_manager_.get(), | |
698 CreateNodeId(client_.id(), 21), | |
699 CreateNodeId(client_.id(), 11), | |
700 5)); | |
701 ASSERT_TRUE(client_.GetAndClearChanges().empty()); | |
702 | |
703 client2_.DoRunLoopUntilChangesCount(1); | |
704 Changes changes(client2_.GetAndClearChanges()); | |
705 ASSERT_EQ(1u, changes.size()); | |
706 EXPECT_EQ( | |
707 "HierarchyChanged change_id=5 node=1,11 new_parent=1,21 " | |
708 "old_parent=null", changes[0]); | |
709 const std::vector<TestNode>& nodes(client2_.hierarchy_changed_nodes()); | |
710 ASSERT_EQ(2u, nodes.size()); | |
711 EXPECT_EQ("node=1,2 parent=null view=null", nodes[0].ToString()); | |
712 EXPECT_EQ("node=1,21 parent=1,2 view=null", nodes[1].ToString()); | |
713 } | |
714 } | |
715 | |
716 // Verifies connection on told descendants of the root when connecting. | |
717 TEST_F(ViewManagerConnectionTest, GetInitialNodesOnInit) { | |
718 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 21)); | |
719 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 3)); | |
720 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | |
721 | |
722 // Make 3 a child of 21. | |
723 { | |
724 AllocationScope scope; | |
725 ASSERT_TRUE(AddNode(view_manager_.get(), | |
726 CreateNodeId(client_.id(), 21), | |
727 CreateNodeId(client_.id(), 3), | |
728 1)); | |
729 ASSERT_TRUE(client_.GetAndClearChanges().empty()); | |
730 } | |
731 | |
732 // Make 21 a child of the root. | |
733 { | |
734 AllocationScope scope; | |
735 ASSERT_TRUE(AddNode(view_manager_.get(), | |
736 CreateNodeId(0, 1), | |
737 CreateNodeId(client_.id(), 21), | |
738 2)); | |
739 ASSERT_TRUE(client_.GetAndClearChanges().empty()); | |
740 } | |
741 | |
742 EstablishSecondConnection(); | |
743 // Should get notification of children of the root. | |
744 const std::vector<TestNode>& nodes(client2_.initial_nodes()); | |
745 ASSERT_EQ(3u, nodes.size()); | |
746 EXPECT_EQ("node=0,1 parent=null view=null", nodes[0].ToString()); | |
747 EXPECT_EQ("node=1,21 parent=0,1 view=null", nodes[1].ToString()); | |
748 EXPECT_EQ("node=1,3 parent=1,21 view=null", nodes[2].ToString()); | |
749 } | |
750 | |
751 // Verifies DeleteNode works. | 531 // Verifies DeleteNode works. |
752 TEST_F(ViewManagerConnectionTest, DeleteNode) { | 532 TEST_F(ViewManagerConnectionTest, DeleteNode) { |
753 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | 533 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
754 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); | 534 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); |
755 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | 535 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
756 | 536 |
757 EstablishSecondConnection(); | 537 EstablishSecondConnection(); |
758 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); | 538 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); |
759 | 539 |
760 // Make 2 a child of 1. | 540 // Make 2 a child of 1. |
761 { | 541 { |
762 AllocationScope scope; | 542 AllocationScope scope; |
763 ASSERT_TRUE(AddNode(view_manager_.get(), | 543 ASSERT_TRUE(AddNode(view_manager_.get(), |
764 CreateNodeId(client_.id(), 1), | 544 CreateNodeId(client_.id(), 1), |
765 CreateNodeId(client_.id(), 2), | 545 CreateNodeId(client_.id(), 2), |
766 1)); | 546 1)); |
767 Changes changes(client_.GetAndClearChanges()); | 547 Changes changes(client_.GetAndClearChanges()); |
768 ASSERT_TRUE(changes.empty()); | 548 ASSERT_TRUE(changes.empty()); |
769 | 549 |
770 client2_.DoRunLoopUntilChangesCount(1); | 550 client2_.DoRunLoopUntilChangesCount(1); |
771 changes = client2_.GetAndClearChanges(); | 551 changes = client2_.GetAndClearChanges(); |
772 ASSERT_EQ(1u, changes.size()); | 552 ASSERT_EQ(1u, changes.size()); |
773 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[0]); | 553 EXPECT_EQ( |
| 554 "HierarchyChanged change_id=1 node=1,2 new_parent=1,1 old_parent=null", |
| 555 changes[0]); |
774 } | 556 } |
775 | 557 |
776 // Add 1 to the root | 558 // Add 1 to the root |
777 { | 559 { |
778 AllocationScope scope; | 560 AllocationScope scope; |
779 ASSERT_TRUE(AddNode(view_manager_.get(), | 561 ASSERT_TRUE(AddNode(view_manager_.get(), |
780 CreateNodeId(0, 1), | 562 CreateNodeId(0, 1), |
781 CreateNodeId(client_.id(), 1), | 563 CreateNodeId(client_.id(), 1), |
782 2)); | 564 2)); |
783 Changes changes(client_.GetAndClearChanges()); | 565 Changes changes(client_.GetAndClearChanges()); |
784 ASSERT_TRUE(changes.empty()); | 566 ASSERT_TRUE(changes.empty()); |
785 | 567 |
786 client2_.DoRunLoopUntilChangesCount(1); | 568 client2_.DoRunLoopUntilChangesCount(1); |
787 changes = client2_.GetAndClearChanges(); | 569 changes = client2_.GetAndClearChanges(); |
788 ASSERT_EQ(1u, changes.size()); | 570 ASSERT_EQ(1u, changes.size()); |
789 EXPECT_EQ( | 571 EXPECT_EQ( |
790 "HierarchyChanged change_id=2 node=1,1 new_parent=0,1 old_parent=null", | 572 "HierarchyChanged change_id=2 node=1,1 new_parent=0,1 old_parent=null", |
791 changes[0]); | 573 changes[0]); |
792 } | 574 } |
793 | 575 |
794 // Delete 1. | 576 // Delete 1. Deleting 1 sends out notification of a removal for both nodes (1 |
| 577 // and 2). |
795 { | 578 { |
796 AllocationScope scope; | 579 AllocationScope scope; |
797 ASSERT_TRUE(DeleteNode(view_manager_.get(), CreateNodeId(client_.id(), 1))); | 580 ASSERT_TRUE(DeleteNode(view_manager_.get(), CreateNodeId(client_.id(), 1))); |
798 Changes changes(client_.GetAndClearChanges()); | 581 Changes changes(client_.GetAndClearChanges()); |
799 ASSERT_TRUE(changes.empty()); | 582 ASSERT_TRUE(changes.empty()); |
800 | 583 |
801 client2_.DoRunLoopUntilChangesCount(1); | 584 client2_.DoRunLoopUntilChangesCount(3); |
802 changes = client2_.GetAndClearChanges(); | 585 changes = client2_.GetAndClearChanges(); |
803 ASSERT_EQ(1u, changes.size()); | 586 ASSERT_EQ(3u, changes.size()); |
804 EXPECT_EQ("NodeDeleted change_id=3 node=1,1", changes[0]); | 587 EXPECT_EQ( |
| 588 "HierarchyChanged change_id=3 node=1,1 new_parent=null old_parent=0,1", |
| 589 changes[0]); |
| 590 EXPECT_EQ( |
| 591 "HierarchyChanged change_id=3 node=1,2 new_parent=null old_parent=1,1", |
| 592 changes[1]); |
| 593 EXPECT_EQ("NodeDeleted change_id=3 node=1,1", changes[2]); |
805 } | 594 } |
806 } | 595 } |
807 | 596 |
808 // Verifies if a node was deleted and then reused that other clients are | |
809 // properly notified. | |
810 TEST_F(ViewManagerConnectionTest, ReusedDeletedId) { | |
811 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | |
812 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | |
813 | |
814 EstablishSecondConnection(); | |
815 | |
816 // Make 1 a child of the root. | |
817 { | |
818 AllocationScope scope; | |
819 ASSERT_TRUE(AddNode(view_manager_.get(), | |
820 CreateNodeId(0, 1), | |
821 CreateNodeId(client_.id(), 1), | |
822 1)); | |
823 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | |
824 | |
825 client2_.DoRunLoopUntilChangesCount(1); | |
826 Changes changes = client2_.GetAndClearChanges(); | |
827 EXPECT_EQ( | |
828 "HierarchyChanged change_id=1 node=1,1 new_parent=0,1 old_parent=null", | |
829 changes[0]); | |
830 const std::vector<TestNode>& nodes(client2_.hierarchy_changed_nodes()); | |
831 ASSERT_EQ(1u, nodes.size()); | |
832 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); | |
833 } | |
834 | |
835 // Delete 1. | |
836 { | |
837 AllocationScope scope; | |
838 ASSERT_TRUE(DeleteNode(view_manager_.get(), CreateNodeId(client_.id(), 1))); | |
839 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | |
840 | |
841 client2_.DoRunLoopUntilChangesCount(1); | |
842 Changes changes = client2_.GetAndClearChanges(); | |
843 ASSERT_EQ(1u, changes.size()); | |
844 EXPECT_EQ("NodeDeleted change_id=2 node=1,1", changes[0]); | |
845 } | |
846 | |
847 // Create 1 again, and add it back to the root. Should get the same | |
848 // notification. | |
849 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | |
850 { | |
851 AllocationScope scope; | |
852 ASSERT_TRUE(AddNode(view_manager_.get(), | |
853 CreateNodeId(0, 1), | |
854 CreateNodeId(client_.id(), 1), | |
855 3)); | |
856 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | |
857 | |
858 client2_.DoRunLoopUntilChangesCount(1); | |
859 Changes changes = client2_.GetAndClearChanges(); | |
860 EXPECT_EQ( | |
861 "HierarchyChanged change_id=3 node=1,1 new_parent=0,1 old_parent=null", | |
862 changes[0]); | |
863 const std::vector<TestNode>& nodes(client2_.hierarchy_changed_nodes()); | |
864 ASSERT_EQ(1u, nodes.size()); | |
865 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); | |
866 } | |
867 } | |
868 | |
869 // Assertions around setting a view. | 597 // Assertions around setting a view. |
870 TEST_F(ViewManagerConnectionTest, SetView) { | 598 TEST_F(ViewManagerConnectionTest, SetView) { |
871 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | 599 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
872 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); | 600 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); |
873 ASSERT_TRUE(CreateView(view_manager_.get(), 1, 11)); | 601 ASSERT_TRUE(CreateView(view_manager_.get(), 1, 11)); |
874 EXPECT_TRUE(client_.GetAndClearChanges().empty()); | 602 EXPECT_TRUE(client_.GetAndClearChanges().empty()); |
875 | 603 |
876 EstablishSecondConnection(); | 604 EstablishSecondConnection(); |
877 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); | 605 EXPECT_TRUE(client2_.GetAndClearChanges().empty()); |
878 | 606 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 // Delete node 1. | 657 // Delete node 1. |
930 { | 658 { |
931 ASSERT_TRUE(DeleteNode(view_manager_.get(), CreateNodeId(client_.id(), 1))); | 659 ASSERT_TRUE(DeleteNode(view_manager_.get(), CreateNodeId(client_.id(), 1))); |
932 Changes changes(client_.GetAndClearChanges()); | 660 Changes changes(client_.GetAndClearChanges()); |
933 ASSERT_TRUE(changes.empty()); | 661 ASSERT_TRUE(changes.empty()); |
934 | 662 |
935 client2_.DoRunLoopUntilChangesCount(2); | 663 client2_.DoRunLoopUntilChangesCount(2); |
936 changes = client2_.GetAndClearChanges(); | 664 changes = client2_.GetAndClearChanges(); |
937 ASSERT_EQ(2u, changes.size()); | 665 ASSERT_EQ(2u, changes.size()); |
938 EXPECT_EQ("ViewReplaced node=1,1 new_view=null old_view=1,11", changes[0]); | 666 EXPECT_EQ("ViewReplaced node=1,1 new_view=null old_view=1,11", changes[0]); |
939 EXPECT_EQ("ServerChangeIdAdvanced 2", changes[1]); | 667 EXPECT_EQ("NodeDeleted change_id=1 node=1,1", changes[1]); |
940 } | 668 } |
941 | 669 |
942 // Parent 2 to the root. | |
943 ASSERT_TRUE(AddNode(view_manager_.get(), | |
944 CreateNodeId(0, 1), | |
945 CreateNodeId(client_.id(), 2), | |
946 2)); | |
947 client2_.DoRunLoopUntilChangesCount(1); | |
948 client2_.GetAndClearChanges(); | |
949 | |
950 // Set view 11 on node 2. | 670 // Set view 11 on node 2. |
951 { | 671 { |
952 ASSERT_TRUE(SetView(view_manager_.get(), | 672 ASSERT_TRUE(SetView(view_manager_.get(), |
953 CreateNodeId(client_.id(), 2), | 673 CreateNodeId(client_.id(), 2), |
954 CreateViewId(client_.id(), 11))); | 674 CreateViewId(client_.id(), 11))); |
955 Changes changes(client_.GetAndClearChanges()); | 675 Changes changes(client_.GetAndClearChanges()); |
956 ASSERT_TRUE(changes.empty()); | 676 ASSERT_TRUE(changes.empty()); |
957 | 677 |
958 client2_.DoRunLoopUntilChangesCount(1); | 678 client2_.DoRunLoopUntilChangesCount(1); |
959 changes = client2_.GetAndClearChanges(); | 679 changes = client2_.GetAndClearChanges(); |
960 ASSERT_EQ(1u, changes.size()); | 680 ASSERT_EQ(1u, changes.size()); |
961 EXPECT_EQ("ViewReplaced node=1,2 new_view=1,11 old_view=null", changes[0]); | 681 EXPECT_EQ("ViewReplaced node=1,2 new_view=1,11 old_view=null", changes[0]); |
962 } | 682 } |
963 | |
964 // Delete node. | |
965 { | |
966 ASSERT_TRUE(DeleteNode(view_manager_.get(), CreateNodeId(client_.id(), 2))); | |
967 Changes changes(client_.GetAndClearChanges()); | |
968 ASSERT_TRUE(changes.empty()); | |
969 | |
970 client2_.DoRunLoopUntilChangesCount(2); | |
971 changes = client2_.GetAndClearChanges(); | |
972 ASSERT_EQ(2u, changes.size()); | |
973 EXPECT_EQ("ViewReplaced node=1,2 new_view=null old_view=1,11", changes[0]); | |
974 EXPECT_EQ("NodeDeleted change_id=3 node=1,2", changes[1]); | |
975 } | |
976 } | 683 } |
977 | 684 |
978 // Sets view from one connection on another. | 685 // Sets view from one connection on another. |
979 TEST_F(ViewManagerConnectionTest, SetViewFromSecondConnection) { | 686 TEST_F(ViewManagerConnectionTest, SetViewFromSecondConnection) { |
980 EstablishSecondConnection(); | 687 EstablishSecondConnection(); |
981 | 688 |
982 // Create two nodes in first connection. | 689 // Create two nodes in first connection. |
983 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); | 690 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 1)); |
984 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); | 691 ASSERT_TRUE(CreateNode(view_manager_.get(), 1, 2)); |
985 | 692 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1066 GetNodeTree(view_manager2_.get(), CreateNodeId(1, 1), &nodes); | 773 GetNodeTree(view_manager2_.get(), CreateNodeId(1, 1), &nodes); |
1067 ASSERT_EQ(2u, nodes.size()); | 774 ASSERT_EQ(2u, nodes.size()); |
1068 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); | 775 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); |
1069 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[1].ToString()); | 776 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[1].ToString()); |
1070 } | 777 } |
1071 } | 778 } |
1072 | 779 |
1073 } // namespace service | 780 } // namespace service |
1074 } // namespace view_manager | 781 } // namespace view_manager |
1075 } // namespace mojo | 782 } // namespace mojo |
OLD | NEW |