| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 ErrorCode CreateNodeWithErrorCode(Id node_id) { | 110 ErrorCode CreateNodeWithErrorCode(Id node_id) { |
| 111 changes_.clear(); | 111 changes_.clear(); |
| 112 ErrorCode result = ERROR_CODE_NONE; | 112 ErrorCode result = ERROR_CODE_NONE; |
| 113 view_manager_->CreateNode( | 113 view_manager_->CreateNode( |
| 114 node_id, | 114 node_id, |
| 115 base::Bind(&ViewManagerProxy::GotResultWithErrorCode, | 115 base::Bind(&ViewManagerProxy::GotResultWithErrorCode, |
| 116 base::Unretained(this), &result)); | 116 base::Unretained(this), &result)); |
| 117 RunMainLoop(); | 117 RunMainLoop(); |
| 118 return result; | 118 return result; |
| 119 } | 119 } |
| 120 bool AddNode(Id parent, Id child, Id server_change_id) { | 120 bool AddNode(Id parent, Id child) { |
| 121 changes_.clear(); | 121 changes_.clear(); |
| 122 bool result = false; | 122 bool result = false; |
| 123 view_manager_->AddNode(parent, child, server_change_id, | 123 view_manager_->AddNode(parent, child, |
| 124 base::Bind(&ViewManagerProxy::GotResult, | 124 base::Bind(&ViewManagerProxy::GotResult, |
| 125 base::Unretained(this), &result)); | 125 base::Unretained(this), &result)); |
| 126 RunMainLoop(); | 126 RunMainLoop(); |
| 127 return result; | 127 return result; |
| 128 } | 128 } |
| 129 bool RemoveNodeFromParent(Id node_id, Id server_change_id) { | 129 bool RemoveNodeFromParent(Id node_id) { |
| 130 changes_.clear(); | 130 changes_.clear(); |
| 131 bool result = false; | 131 bool result = false; |
| 132 view_manager_->RemoveNodeFromParent(node_id, server_change_id, | 132 view_manager_->RemoveNodeFromParent(node_id, |
| 133 base::Bind(&ViewManagerProxy::GotResult, | 133 base::Bind(&ViewManagerProxy::GotResult, |
| 134 base::Unretained(this), &result)); | 134 base::Unretained(this), &result)); |
| 135 RunMainLoop(); | 135 RunMainLoop(); |
| 136 return result; | 136 return result; |
| 137 } | 137 } |
| 138 bool ReorderNode(Id node_id, | 138 bool ReorderNode(Id node_id, |
| 139 Id relative_node_id, | 139 Id relative_node_id, |
| 140 OrderDirection direction, | 140 OrderDirection direction) { |
| 141 Id server_change_id) { | |
| 142 changes_.clear(); | 141 changes_.clear(); |
| 143 bool result = false; | 142 bool result = false; |
| 144 view_manager_->ReorderNode(node_id, relative_node_id, direction, | 143 view_manager_->ReorderNode(node_id, relative_node_id, direction, |
| 145 server_change_id, | |
| 146 base::Bind(&ViewManagerProxy::GotResult, | 144 base::Bind(&ViewManagerProxy::GotResult, |
| 147 base::Unretained(this), &result)); | 145 base::Unretained(this), &result)); |
| 148 RunMainLoop(); | 146 RunMainLoop(); |
| 149 return result; | 147 return result; |
| 150 } | 148 } |
| 151 bool SetView(Id node_id, Id view_id) { | 149 bool SetView(Id node_id, Id view_id) { |
| 152 changes_.clear(); | 150 changes_.clear(); |
| 153 bool result = false; | 151 bool result = false; |
| 154 view_manager_->SetView(node_id, view_id, | 152 view_manager_->SetView(node_id, view_id, |
| 155 base::Bind(&ViewManagerProxy::GotResult, | 153 base::Bind(&ViewManagerProxy::GotResult, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 176 bool Embed(const Id node_id, const char* url) { | 174 bool Embed(const Id node_id, const char* url) { |
| 177 changes_.clear(); | 175 changes_.clear(); |
| 178 base::AutoReset<bool> auto_reset(&in_embed_, true); | 176 base::AutoReset<bool> auto_reset(&in_embed_, true); |
| 179 bool result = false; | 177 bool result = false; |
| 180 view_manager_->Embed(url, node_id, | 178 view_manager_->Embed(url, node_id, |
| 181 base::Bind(&ViewManagerProxy::GotResult, | 179 base::Bind(&ViewManagerProxy::GotResult, |
| 182 base::Unretained(this), &result)); | 180 base::Unretained(this), &result)); |
| 183 RunMainLoop(); | 181 RunMainLoop(); |
| 184 return result; | 182 return result; |
| 185 } | 183 } |
| 186 bool DeleteNode(Id node_id, Id server_change_id) { | 184 bool DeleteNode(Id node_id) { |
| 187 changes_.clear(); | 185 changes_.clear(); |
| 188 bool result = false; | 186 bool result = false; |
| 189 view_manager_->DeleteNode(node_id, | 187 view_manager_->DeleteNode(node_id, |
| 190 server_change_id, | |
| 191 base::Bind(&ViewManagerProxy::GotResult, | 188 base::Bind(&ViewManagerProxy::GotResult, |
| 192 base::Unretained(this), &result)); | 189 base::Unretained(this), &result)); |
| 193 RunMainLoop(); | 190 RunMainLoop(); |
| 194 return result; | 191 return result; |
| 195 } | 192 } |
| 196 bool DeleteView(Id view_id) { | 193 bool DeleteView(Id view_id) { |
| 197 changes_.clear(); | 194 changes_.clear(); |
| 198 bool result = false; | 195 bool result = false; |
| 199 view_manager_->DeleteView(view_id, | 196 view_manager_->DeleteView(view_id, |
| 200 base::Bind(&ViewManagerProxy::GotResult, | 197 base::Bind(&ViewManagerProxy::GotResult, |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 // InterfaceImp: | 315 // InterfaceImp: |
| 319 virtual void OnConnectionEstablished() OVERRIDE { | 316 virtual void OnConnectionEstablished() OVERRIDE { |
| 320 connection_.set_router(internal_state()->router()); | 317 connection_.set_router(internal_state()->router()); |
| 321 connection_.set_view_manager(client()); | 318 connection_.set_view_manager(client()); |
| 322 } | 319 } |
| 323 | 320 |
| 324 // ViewMangerClient: | 321 // ViewMangerClient: |
| 325 virtual void OnViewManagerConnectionEstablished( | 322 virtual void OnViewManagerConnectionEstablished( |
| 326 ConnectionSpecificId connection_id, | 323 ConnectionSpecificId connection_id, |
| 327 const String& creator_url, | 324 const String& creator_url, |
| 328 Id next_server_change_id, | |
| 329 Array<NodeDataPtr> nodes) OVERRIDE { | 325 Array<NodeDataPtr> nodes) OVERRIDE { |
| 330 tracker_.OnViewManagerConnectionEstablished( | 326 tracker_.OnViewManagerConnectionEstablished( |
| 331 connection_id, creator_url, next_server_change_id, nodes.Pass()); | 327 connection_id, creator_url, nodes.Pass()); |
| 332 } | 328 } |
| 333 virtual void OnRootAdded(Array<NodeDataPtr> nodes) OVERRIDE { | 329 virtual void OnRootAdded(Array<NodeDataPtr> nodes) OVERRIDE { |
| 334 tracker_.OnRootAdded(nodes.Pass()); | 330 tracker_.OnRootAdded(nodes.Pass()); |
| 335 } | 331 } |
| 336 virtual void OnServerChangeIdAdvanced( | |
| 337 Id next_server_change_id) OVERRIDE { | |
| 338 tracker_.OnServerChangeIdAdvanced(next_server_change_id); | |
| 339 } | |
| 340 virtual void OnNodeBoundsChanged(Id node_id, | 332 virtual void OnNodeBoundsChanged(Id node_id, |
| 341 RectPtr old_bounds, | 333 RectPtr old_bounds, |
| 342 RectPtr new_bounds) OVERRIDE { | 334 RectPtr new_bounds) OVERRIDE { |
| 343 tracker_.OnNodeBoundsChanged(node_id, old_bounds.Pass(), new_bounds.Pass()); | 335 tracker_.OnNodeBoundsChanged(node_id, old_bounds.Pass(), new_bounds.Pass()); |
| 344 } | 336 } |
| 345 virtual void OnNodeHierarchyChanged(Id node, | 337 virtual void OnNodeHierarchyChanged(Id node, |
| 346 Id new_parent, | 338 Id new_parent, |
| 347 Id old_parent, | 339 Id old_parent, |
| 348 Id server_change_id, | |
| 349 Array<NodeDataPtr> nodes) OVERRIDE { | 340 Array<NodeDataPtr> nodes) OVERRIDE { |
| 350 tracker_.OnNodeHierarchyChanged(node, new_parent, old_parent, | 341 tracker_.OnNodeHierarchyChanged(node, new_parent, old_parent, nodes.Pass()); |
| 351 server_change_id, nodes.Pass()); | |
| 352 } | 342 } |
| 353 virtual void OnNodeReordered(Id node_id, | 343 virtual void OnNodeReordered(Id node_id, |
| 354 Id relative_node_id, | 344 Id relative_node_id, |
| 355 OrderDirection direction, | 345 OrderDirection direction) OVERRIDE { |
| 356 Id server_change_id) OVERRIDE { | 346 tracker_.OnNodeReordered(node_id, relative_node_id, direction); |
| 357 tracker_.OnNodeReordered(node_id, relative_node_id, direction, | |
| 358 server_change_id); | |
| 359 } | 347 } |
| 360 virtual void OnNodeDeleted(Id node, Id server_change_id) OVERRIDE { | 348 virtual void OnNodeDeleted(Id node) OVERRIDE { |
| 361 tracker_.OnNodeDeleted(node, server_change_id); | 349 tracker_.OnNodeDeleted(node); |
| 362 } | 350 } |
| 363 virtual void OnViewDeleted(Id view) OVERRIDE { | 351 virtual void OnViewDeleted(Id view) OVERRIDE { |
| 364 tracker_.OnViewDeleted(view); | 352 tracker_.OnViewDeleted(view); |
| 365 } | 353 } |
| 366 virtual void OnNodeViewReplaced(Id node, | 354 virtual void OnNodeViewReplaced(Id node, |
| 367 Id new_view_id, | 355 Id new_view_id, |
| 368 Id old_view_id) OVERRIDE { | 356 Id old_view_id) OVERRIDE { |
| 369 tracker_.OnNodeViewReplaced(node, new_view_id, old_view_id); | 357 tracker_.OnNodeViewReplaced(node, new_view_id, old_view_id); |
| 370 } | 358 } |
| 371 virtual void OnViewInputEvent(Id view_id, | 359 virtual void OnViewInputEvent(Id view_id, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 // Verifies client gets a valid id. | 520 // Verifies client gets a valid id. |
| 533 TEST_F(ViewManagerTest, ValidId) { | 521 TEST_F(ViewManagerTest, ValidId) { |
| 534 // TODO(beng): this should really have the URL of the application that | 522 // TODO(beng): this should really have the URL of the application that |
| 535 // connected to ViewManagerInit. | 523 // connected to ViewManagerInit. |
| 536 EXPECT_EQ("OnConnectionEstablished creator=", | 524 EXPECT_EQ("OnConnectionEstablished creator=", |
| 537 ChangesToDescription1(connection_->changes())[0]); | 525 ChangesToDescription1(connection_->changes())[0]); |
| 538 | 526 |
| 539 // All these tests assume 1 for the client id. The only real assertion here is | 527 // All these tests assume 1 for the client id. The only real assertion here is |
| 540 // the client id is not zero, but adding this as rest of code here assumes 1. | 528 // the client id is not zero, but adding this as rest of code here assumes 1. |
| 541 EXPECT_EQ(1, connection_->changes()[0].connection_id); | 529 EXPECT_EQ(1, connection_->changes()[0].connection_id); |
| 542 | |
| 543 // Change ids start at 1 as well. | |
| 544 EXPECT_EQ(static_cast<Id>(1), connection_->changes()[0].change_id); | |
| 545 } | 530 } |
| 546 | 531 |
| 547 // Verifies two clients/connections get different ids. | 532 // Verifies two clients/connections get different ids. |
| 548 TEST_F(ViewManagerTest, TwoClientsGetDifferentConnectionIds) { | 533 TEST_F(ViewManagerTest, TwoClientsGetDifferentConnectionIds) { |
| 549 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 534 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 550 EXPECT_EQ("OnConnectionEstablished creator=mojo:test_url", | 535 EXPECT_EQ("OnConnectionEstablished creator=mojo:test_url", |
| 551 ChangesToDescription1(connection2_->changes())[0]); | 536 ChangesToDescription1(connection2_->changes())[0]); |
| 552 | 537 |
| 553 // It isn't strictly necessary that the second connection gets 2, but these | 538 // It isn't strictly necessary that the second connection gets 2, but these |
| 554 // tests are written assuming that is the case. The key thing is the | 539 // tests are written assuming that is the case. The key thing is the |
| 555 // connection ids of |connection_| and |connection2_| differ. | 540 // connection ids of |connection_| and |connection2_| differ. |
| 556 EXPECT_EQ(2, connection2_->changes()[0].connection_id); | 541 EXPECT_EQ(2, connection2_->changes()[0].connection_id); |
| 557 | |
| 558 // Change ids start at 1 as well. | |
| 559 EXPECT_EQ(static_cast<Id>(1), connection2_->changes()[0].change_id); | |
| 560 } | 542 } |
| 561 | 543 |
| 562 // Verifies client gets a valid id. | 544 // Verifies client gets a valid id. |
| 563 TEST_F(ViewManagerTest, CreateNode) { | 545 TEST_F(ViewManagerTest, CreateNode) { |
| 564 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 546 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| 565 EXPECT_TRUE(connection_->changes().empty()); | 547 EXPECT_TRUE(connection_->changes().empty()); |
| 566 | 548 |
| 567 // Can't create a node with the same id. | 549 // Can't create a node with the same id. |
| 568 ASSERT_EQ(ERROR_CODE_VALUE_IN_USE, | 550 ASSERT_EQ(ERROR_CODE_VALUE_IN_USE, |
| 569 connection_->CreateNodeWithErrorCode(BuildNodeId(1, 1))); | 551 connection_->CreateNodeWithErrorCode(BuildNodeId(1, 1))); |
| 570 EXPECT_TRUE(connection_->changes().empty()); | 552 EXPECT_TRUE(connection_->changes().empty()); |
| 571 | 553 |
| 572 // Can't create a node with a bogus connection id. | 554 // Can't create a node with a bogus connection id. |
| 573 EXPECT_EQ( | 555 EXPECT_EQ(ERROR_CODE_ILLEGAL_ARGUMENT, |
| 574 ERROR_CODE_ILLEGAL_ARGUMENT, | 556 connection_->CreateNodeWithErrorCode(BuildNodeId(2, 1))); |
| 575 connection_->CreateNodeWithErrorCode(BuildNodeId(2, 1))); | |
| 576 EXPECT_TRUE(connection_->changes().empty()); | 557 EXPECT_TRUE(connection_->changes().empty()); |
| 577 } | 558 } |
| 578 | 559 |
| 579 TEST_F(ViewManagerTest, CreateViewFailsWithBogusConnectionId) { | 560 TEST_F(ViewManagerTest, CreateViewFailsWithBogusConnectionId) { |
| 580 EXPECT_FALSE(connection_->CreateView(BuildViewId(2, 1))); | 561 EXPECT_FALSE(connection_->CreateView(BuildViewId(2, 1))); |
| 581 EXPECT_TRUE(connection_->changes().empty()); | 562 EXPECT_TRUE(connection_->changes().empty()); |
| 582 } | 563 } |
| 583 | 564 |
| 584 // Verifies hierarchy changes. | |
| 585 TEST_F(ViewManagerTest, AddRemoveNotify) { | |
| 586 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | |
| 587 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); | |
| 588 | |
| 589 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | |
| 590 | |
| 591 // Make 3 a child of 2. | |
| 592 { | |
| 593 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 3), 2)); | |
| 594 EXPECT_TRUE(connection_->changes().empty()); | |
| 595 | |
| 596 connection2_->DoRunLoopUntilChangesCount(1); | |
| 597 const Changes changes(ChangesToDescription1(connection2_->changes())); | |
| 598 ASSERT_EQ(1u, changes.size()); | |
| 599 EXPECT_EQ("ServerChangeIdAdvanced 3", changes[0]); | |
| 600 } | |
| 601 | |
| 602 // Remove 3 from its parent. | |
| 603 { | |
| 604 ASSERT_TRUE(connection_->RemoveNodeFromParent(BuildNodeId(1, 3), 3)); | |
| 605 EXPECT_TRUE(connection_->changes().empty()); | |
| 606 | |
| 607 connection2_->DoRunLoopUntilChangesCount(1); | |
| 608 const Changes changes(ChangesToDescription1(connection2_->changes())); | |
| 609 ASSERT_EQ(1u, changes.size()); | |
| 610 EXPECT_EQ("ServerChangeIdAdvanced 4", changes[0]); | |
| 611 } | |
| 612 } | |
| 613 | |
| 614 // Verifies AddNode fails when node is already in position. | 565 // Verifies AddNode fails when node is already in position. |
| 615 TEST_F(ViewManagerTest, AddNodeWithNoChange) { | 566 TEST_F(ViewManagerTest, AddNodeWithNoChange) { |
| 616 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 567 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 617 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); | 568 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); |
| 618 | 569 |
| 619 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 570 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 620 | 571 |
| 621 // Make 3 a child of 2. | 572 // Make 3 a child of 2. |
| 622 { | 573 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 3))); |
| 623 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 3), 2)); | |
| 624 | |
| 625 connection2_->DoRunLoopUntilChangesCount(1); | |
| 626 const Changes changes(ChangesToDescription1(connection2_->changes())); | |
| 627 ASSERT_EQ(1u, changes.size()); | |
| 628 EXPECT_EQ("ServerChangeIdAdvanced 3", changes[0]); | |
| 629 } | |
| 630 | 574 |
| 631 // Try again, this should fail. | 575 // Try again, this should fail. |
| 632 { | 576 EXPECT_FALSE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 3))); |
| 633 EXPECT_FALSE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 3), 3)); | |
| 634 } | |
| 635 } | 577 } |
| 636 | 578 |
| 637 // Verifies AddNode fails when node is already in position. | 579 // Verifies AddNode fails when node is already in position. |
| 638 TEST_F(ViewManagerTest, AddAncestorFails) { | 580 TEST_F(ViewManagerTest, AddAncestorFails) { |
| 639 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 581 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 640 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); | 582 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); |
| 641 | 583 |
| 642 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 584 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 643 | 585 |
| 644 // Make 3 a child of 2. | 586 // Make 3 a child of 2. |
| 645 { | 587 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 3))); |
| 646 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 3), 2)); | |
| 647 connection2_->DoRunLoopUntilChangesCount(1); | |
| 648 const Changes changes(ChangesToDescription1(connection2_->changes())); | |
| 649 ASSERT_EQ(1u, changes.size()); | |
| 650 EXPECT_EQ("ServerChangeIdAdvanced 3", changes[0]); | |
| 651 } | |
| 652 | 588 |
| 653 // Try to make 2 a child of 3, this should fail since 2 is an ancestor of 3. | 589 // Try to make 2 a child of 3, this should fail since 2 is an ancestor of 3. |
| 654 { | 590 EXPECT_FALSE(connection_->AddNode(BuildNodeId(1, 3), BuildNodeId(1, 2))); |
| 655 EXPECT_FALSE(connection_->AddNode(BuildNodeId(1, 3), BuildNodeId(1, 2), 3)); | |
| 656 } | |
| 657 } | |
| 658 | |
| 659 // Verifies adding with an invalid id fails. | |
| 660 TEST_F(ViewManagerTest, AddWithInvalidServerId) { | |
| 661 // Create two nodes. | |
| 662 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | |
| 663 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | |
| 664 | |
| 665 // Make 2 a child of 1. Supply an invalid change id, which should fail. | |
| 666 ASSERT_FALSE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 0)); | |
| 667 } | 591 } |
| 668 | 592 |
| 669 // Verifies adding to root sends right notifications. | 593 // Verifies adding to root sends right notifications. |
| 670 TEST_F(ViewManagerTest, AddToRoot) { | 594 TEST_F(ViewManagerTest, AddToRoot) { |
| 671 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 21))); | 595 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 21))); |
| 672 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); | 596 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); |
| 673 | 597 |
| 674 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 598 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 675 | 599 |
| 676 // Make 3 a child of 21. | 600 // Make 3 a child of 21. |
| 601 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 21), BuildNodeId(1, 3))); |
| 602 |
| 603 // Make 21 a child of 1. |
| 677 { | 604 { |
| 678 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 21), BuildNodeId(1, 3), 2)); | 605 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 21))); |
| 679 | 606 |
| 680 connection2_->DoRunLoopUntilChangesCount(1); | 607 connection2_->DoRunLoopUntilChangesCount(1); |
| 681 const Changes changes(ChangesToDescription1(connection2_->changes())); | 608 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 682 ASSERT_EQ(1u, changes.size()); | 609 ASSERT_EQ(1u, changes.size()); |
| 683 EXPECT_EQ("ServerChangeIdAdvanced 3", changes[0]); | 610 EXPECT_EQ("HierarchyChanged node=1,21 new_parent=1,1 old_parent=null", |
| 684 } | 611 changes[0]); |
| 685 | |
| 686 // Make 21 a child of 1. | |
| 687 { | |
| 688 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 21), 3)); | |
| 689 | |
| 690 connection2_->DoRunLoopUntilChangesCount(1); | |
| 691 const Changes changes(ChangesToDescription1(connection2_->changes())); | |
| 692 ASSERT_EQ(1u, changes.size()); | |
| 693 EXPECT_EQ( | |
| 694 "HierarchyChanged change_id=3 node=1,21 new_parent=1,1 old_parent=null", | |
| 695 changes[0]); | |
| 696 } | 612 } |
| 697 } | 613 } |
| 698 | 614 |
| 699 // Verifies HierarchyChanged is correctly sent for various adds/removes. | 615 // Verifies HierarchyChanged is correctly sent for various adds/removes. |
| 700 TEST_F(ViewManagerTest, NodeHierarchyChangedNodes) { | 616 TEST_F(ViewManagerTest, NodeHierarchyChangedNodes) { |
| 701 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 617 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 702 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 11))); | 618 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 11))); |
| 703 // Make 11 a child of 2. | 619 // Make 11 a child of 2. |
| 704 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 11), 1)); | 620 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 11))); |
| 705 | 621 |
| 706 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 622 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 707 | 623 |
| 708 // Make 2 a child of 1. | 624 // Make 2 a child of 1. |
| 709 { | 625 { |
| 710 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 3)); | 626 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2))); |
| 711 | 627 |
| 712 // Client 2 should get a hierarchy change that includes the new nodes as it | 628 // Client 2 should get a hierarchy change that includes the new nodes as it |
| 713 // has not yet seen them. | 629 // has not yet seen them. |
| 714 connection2_->DoRunLoopUntilChangesCount(1); | 630 connection2_->DoRunLoopUntilChangesCount(1); |
| 715 const Changes changes(ChangesToDescription1(connection2_->changes())); | 631 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 716 ASSERT_EQ(1u, changes.size()); | 632 ASSERT_EQ(1u, changes.size()); |
| 717 EXPECT_EQ( | 633 EXPECT_EQ( |
| 718 "HierarchyChanged change_id=3 node=1,2 new_parent=1,1 old_parent=null", | 634 "HierarchyChanged node=1,2 new_parent=1,1 old_parent=null", changes[0]); |
| 719 changes[0]); | |
| 720 EXPECT_EQ("[node=1,2 parent=1,1 view=null]," | 635 EXPECT_EQ("[node=1,2 parent=1,1 view=null]," |
| 721 "[node=1,11 parent=1,2 view=null]", | 636 "[node=1,11 parent=1,2 view=null]", |
| 722 ChangeNodeDescription(connection2_->changes())); | 637 ChangeNodeDescription(connection2_->changes())); |
| 723 } | 638 } |
| 724 | 639 |
| 725 // Add 1 to the root. | 640 // Add 1 to the root. |
| 726 { | 641 { |
| 727 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 4)); | 642 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); |
| 728 | 643 |
| 729 // Client 2 should get a hierarchy change that includes the new nodes as it | 644 // Client 2 should get a hierarchy change that includes the new nodes as it |
| 730 // has not yet seen them. | 645 // has not yet seen them. |
| 731 connection2_->DoRunLoopUntilChangesCount(1); | 646 connection2_->DoRunLoopUntilChangesCount(1); |
| 732 const Changes changes(ChangesToDescription1(connection2_->changes())); | 647 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 733 ASSERT_EQ(1u, changes.size()); | 648 ASSERT_EQ(1u, changes.size()); |
| 734 EXPECT_EQ( | 649 EXPECT_EQ("HierarchyChanged node=1,1 new_parent=null old_parent=null", |
| 735 "HierarchyChanged change_id=4 node=1,1 new_parent=null old_parent=null", | 650 changes[0]); |
| 736 changes[0]); | |
| 737 EXPECT_EQ(std::string(), ChangeNodeDescription(connection2_->changes())); | 651 EXPECT_EQ(std::string(), ChangeNodeDescription(connection2_->changes())); |
| 738 } | 652 } |
| 739 | 653 |
| 740 // Remove 1 from its parent. | 654 // Remove 1 from its parent. |
| 741 { | 655 { |
| 742 ASSERT_TRUE(connection_->RemoveNodeFromParent(BuildNodeId(1, 1), 5)); | 656 ASSERT_TRUE(connection_->RemoveNodeFromParent(BuildNodeId(1, 1))); |
| 743 EXPECT_TRUE(connection_->changes().empty()); | 657 EXPECT_TRUE(connection_->changes().empty()); |
| 744 | 658 |
| 745 connection2_->DoRunLoopUntilChangesCount(1); | 659 connection2_->DoRunLoopUntilChangesCount(1); |
| 746 const Changes changes(ChangesToDescription1(connection2_->changes())); | 660 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 747 ASSERT_EQ(1u, changes.size()); | 661 ASSERT_EQ(1u, changes.size()); |
| 748 EXPECT_EQ( | 662 EXPECT_EQ("HierarchyChanged node=1,1 new_parent=null old_parent=null", |
| 749 "HierarchyChanged change_id=5 node=1,1 new_parent=null old_parent=null", | 663 changes[0]); |
| 750 changes[0]); | |
| 751 } | 664 } |
| 752 | 665 |
| 753 // Create another node, 111, parent it to 11. | 666 // Create another node, 111, parent it to 11. |
| 754 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 111))); | 667 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 111))); |
| 755 { | 668 { |
| 756 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 11), BuildNodeId(1, 111), | 669 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 11), BuildNodeId(1, 111))); |
| 757 6)); | |
| 758 | 670 |
| 759 connection2_->DoRunLoopUntilChangesCount(1); | 671 connection2_->DoRunLoopUntilChangesCount(1); |
| 760 const Changes changes(ChangesToDescription1(connection2_->changes())); | 672 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 761 ASSERT_EQ(1u, changes.size()); | 673 ASSERT_EQ(1u, changes.size()); |
| 762 EXPECT_EQ( | 674 EXPECT_EQ("HierarchyChanged node=1,111 new_parent=1,11 old_parent=null", |
| 763 "HierarchyChanged change_id=6 node=1,111 new_parent=1,11 " | 675 changes[0]); |
| 764 "old_parent=null", changes[0]); | |
| 765 EXPECT_EQ("[node=1,111 parent=1,11 view=null]", | 676 EXPECT_EQ("[node=1,111 parent=1,11 view=null]", |
| 766 ChangeNodeDescription(connection2_->changes())); | 677 ChangeNodeDescription(connection2_->changes())); |
| 767 } | 678 } |
| 768 | 679 |
| 769 // Reattach 1 to the root. | 680 // Reattach 1 to the root. |
| 770 { | 681 { |
| 771 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 7)); | 682 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); |
| 772 | 683 |
| 773 connection2_->DoRunLoopUntilChangesCount(1); | 684 connection2_->DoRunLoopUntilChangesCount(1); |
| 774 const Changes changes(ChangesToDescription1(connection2_->changes())); | 685 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 775 ASSERT_EQ(1u, changes.size()); | 686 ASSERT_EQ(1u, changes.size()); |
| 776 EXPECT_EQ( | 687 EXPECT_EQ("HierarchyChanged node=1,1 new_parent=null old_parent=null", |
| 777 "HierarchyChanged change_id=7 node=1,1 new_parent=null old_parent=null", | 688 changes[0]); |
| 778 changes[0]); | |
| 779 EXPECT_EQ(std::string(), ChangeNodeDescription(connection2_->changes())); | 689 EXPECT_EQ(std::string(), ChangeNodeDescription(connection2_->changes())); |
| 780 } | 690 } |
| 781 } | 691 } |
| 782 | 692 |
| 783 TEST_F(ViewManagerTest, NodeHierarchyChangedAddingKnownToUnknown) { | 693 TEST_F(ViewManagerTest, NodeHierarchyChangedAddingKnownToUnknown) { |
| 784 // Create the following structure: root -> 1 -> 11 and 2->21 (2 has no | 694 // Create the following structure: root -> 1 -> 11 and 2->21 (2 has no |
| 785 // parent). | 695 // parent). |
| 786 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 696 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| 787 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 11))); | 697 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 11))); |
| 788 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 698 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 789 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 21))); | 699 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 21))); |
| 790 | 700 |
| 791 // Set up the hierarchy. | 701 // Set up the hierarchy. |
| 792 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 1)); | 702 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); |
| 793 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 11), 2)); | 703 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 11))); |
| 794 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 21), 3)); | 704 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 21))); |
| 795 | 705 |
| 796 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 706 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 797 { | 707 EXPECT_EQ("[node=1,1 parent=null view=null]," |
| 798 EXPECT_EQ("[node=1,1 parent=null view=null]," | 708 "[node=1,11 parent=1,1 view=null]", |
| 799 "[node=1,11 parent=1,1 view=null]", | 709 ChangeNodeDescription(connection2_->changes())); |
| 800 ChangeNodeDescription(connection2_->changes())); | |
| 801 } | |
| 802 | 710 |
| 803 // Remove 11, should result in a delete (since 11 is no longer in connection | 711 // Remove 11, should result in a delete (since 11 is no longer in connection |
| 804 // 2's root). | 712 // 2's root). |
| 805 { | 713 { |
| 806 ASSERT_TRUE(connection_->RemoveNodeFromParent(BuildNodeId(1, 11), 5)); | 714 ASSERT_TRUE(connection_->RemoveNodeFromParent(BuildNodeId(1, 11))); |
| 807 | 715 |
| 808 connection2_->DoRunLoopUntilChangesCount(1); | 716 connection2_->DoRunLoopUntilChangesCount(1); |
| 809 const Changes changes(ChangesToDescription1(connection2_->changes())); | 717 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 810 ASSERT_EQ(1u, changes.size()); | 718 ASSERT_EQ(1u, changes.size()); |
| 811 EXPECT_EQ("NodeDeleted change_id=5 node=1,11", changes[0]); | 719 EXPECT_EQ("NodeDeleted node=1,11", changes[0]); |
| 812 } | 720 } |
| 813 | 721 |
| 814 // Add 2 to 1. | 722 // Add 2 to 1. |
| 815 { | 723 { |
| 816 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 6)); | 724 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2))); |
| 817 | 725 |
| 818 connection2_->DoRunLoopUntilChangesCount(1); | 726 connection2_->DoRunLoopUntilChangesCount(1); |
| 819 const Changes changes(ChangesToDescription1(connection2_->changes())); | 727 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 820 ASSERT_EQ(1u, changes.size()); | 728 ASSERT_EQ(1u, changes.size()); |
| 821 EXPECT_EQ( | 729 EXPECT_EQ("HierarchyChanged node=1,2 new_parent=1,1 old_parent=null", |
| 822 "HierarchyChanged change_id=6 node=1,2 new_parent=1,1 old_parent=null", | 730 changes[0]); |
| 823 changes[0]); | |
| 824 EXPECT_EQ("[node=1,2 parent=1,1 view=null]," | 731 EXPECT_EQ("[node=1,2 parent=1,1 view=null]," |
| 825 "[node=1,21 parent=1,2 view=null]", | 732 "[node=1,21 parent=1,2 view=null]", |
| 826 ChangeNodeDescription(connection2_->changes())); | 733 ChangeNodeDescription(connection2_->changes())); |
| 827 } | 734 } |
| 828 } | 735 } |
| 829 | 736 |
| 830 TEST_F(ViewManagerTest, ReorderNode) { | 737 TEST_F(ViewManagerTest, ReorderNode) { |
| 831 Id node1_id = BuildNodeId(1, 1); | 738 Id node1_id = BuildNodeId(1, 1); |
| 832 Id node2_id = BuildNodeId(1, 2); | 739 Id node2_id = BuildNodeId(1, 2); |
| 833 Id node3_id = BuildNodeId(1, 3); | 740 Id node3_id = BuildNodeId(1, 3); |
| 834 Id node4_id = BuildNodeId(1, 4); // Peer to 1,1 | 741 Id node4_id = BuildNodeId(1, 4); // Peer to 1,1 |
| 835 Id node5_id = BuildNodeId(1, 5); // Peer to 1,1 | 742 Id node5_id = BuildNodeId(1, 5); // Peer to 1,1 |
| 836 Id node6_id = BuildNodeId(1, 6); // Child of 1,2. | 743 Id node6_id = BuildNodeId(1, 6); // Child of 1,2. |
| 837 Id node7_id = BuildNodeId(1, 7); // Unparented. | 744 Id node7_id = BuildNodeId(1, 7); // Unparented. |
| 838 Id node8_id = BuildNodeId(1, 8); // Unparented. | 745 Id node8_id = BuildNodeId(1, 8); // Unparented. |
| 839 ASSERT_TRUE(connection_->CreateNode(node1_id)); | 746 ASSERT_TRUE(connection_->CreateNode(node1_id)); |
| 840 ASSERT_TRUE(connection_->CreateNode(node2_id)); | 747 ASSERT_TRUE(connection_->CreateNode(node2_id)); |
| 841 ASSERT_TRUE(connection_->CreateNode(node3_id)); | 748 ASSERT_TRUE(connection_->CreateNode(node3_id)); |
| 842 ASSERT_TRUE(connection_->CreateNode(node4_id)); | 749 ASSERT_TRUE(connection_->CreateNode(node4_id)); |
| 843 ASSERT_TRUE(connection_->CreateNode(node5_id)); | 750 ASSERT_TRUE(connection_->CreateNode(node5_id)); |
| 844 ASSERT_TRUE(connection_->CreateNode(node6_id)); | 751 ASSERT_TRUE(connection_->CreateNode(node6_id)); |
| 845 ASSERT_TRUE(connection_->CreateNode(node7_id)); | 752 ASSERT_TRUE(connection_->CreateNode(node7_id)); |
| 846 ASSERT_TRUE(connection_->CreateNode(node8_id)); | 753 ASSERT_TRUE(connection_->CreateNode(node8_id)); |
| 847 ASSERT_TRUE(connection_->AddNode(node1_id, node2_id, 1)); | 754 ASSERT_TRUE(connection_->AddNode(node1_id, node2_id)); |
| 848 ASSERT_TRUE(connection_->AddNode(node2_id, node6_id, 2)); | 755 ASSERT_TRUE(connection_->AddNode(node2_id, node6_id)); |
| 849 ASSERT_TRUE(connection_->AddNode(node1_id, node3_id, 3)); | 756 ASSERT_TRUE(connection_->AddNode(node1_id, node3_id)); |
| 850 ASSERT_TRUE(connection_->AddNode( | 757 ASSERT_TRUE(connection_->AddNode( |
| 851 NodeIdToTransportId(RootNodeId()), node4_id, 4)); | 758 NodeIdToTransportId(RootNodeId()), node4_id)); |
| 852 ASSERT_TRUE(connection_->AddNode( | 759 ASSERT_TRUE(connection_->AddNode( |
| 853 NodeIdToTransportId(RootNodeId()), node5_id, 5)); | 760 NodeIdToTransportId(RootNodeId()), node5_id)); |
| 854 | 761 |
| 855 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 762 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 856 | 763 |
| 857 { | 764 { |
| 858 connection_->ReorderNode(node2_id, node3_id, ORDER_DIRECTION_ABOVE, 7); | 765 connection_->ReorderNode(node2_id, node3_id, ORDER_DIRECTION_ABOVE); |
| 859 | 766 |
| 860 connection2_->DoRunLoopUntilChangesCount(1); | 767 connection2_->DoRunLoopUntilChangesCount(1); |
| 861 const Changes changes(ChangesToDescription1(connection2_->changes())); | 768 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 862 ASSERT_EQ(1u, changes.size()); | 769 ASSERT_EQ(1u, changes.size()); |
| 863 EXPECT_EQ( | 770 EXPECT_EQ("Reordered node=1,2 relative=1,3 direction=above", |
| 864 "Reordered change_id=7 node=1,2 relative=1,3 direction=above", | 771 changes[0]); |
| 865 changes[0]); | |
| 866 } | 772 } |
| 867 | 773 |
| 868 { | 774 { |
| 869 connection_->ReorderNode(node2_id, node3_id, ORDER_DIRECTION_BELOW, 8); | 775 connection_->ReorderNode(node2_id, node3_id, ORDER_DIRECTION_BELOW); |
| 870 | 776 |
| 871 connection2_->DoRunLoopUntilChangesCount(1); | 777 connection2_->DoRunLoopUntilChangesCount(1); |
| 872 const Changes changes(ChangesToDescription1(connection2_->changes())); | 778 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 873 ASSERT_EQ(1u, changes.size()); | 779 ASSERT_EQ(1u, changes.size()); |
| 874 EXPECT_EQ( | 780 EXPECT_EQ("Reordered node=1,2 relative=1,3 direction=below", |
| 875 "Reordered change_id=8 node=1,2 relative=1,3 direction=below", | 781 changes[0]); |
| 876 changes[0]); | |
| 877 } | 782 } |
| 878 | 783 |
| 879 { | 784 // node2 is already below node3. |
| 880 // node2 is already below node3. | 785 EXPECT_FALSE( |
| 881 EXPECT_FALSE( | 786 connection_->ReorderNode(node2_id, node3_id, ORDER_DIRECTION_BELOW)); |
| 882 connection_->ReorderNode(node2_id, node3_id, ORDER_DIRECTION_BELOW, 9)); | |
| 883 } | |
| 884 | 787 |
| 885 { | 788 // node4 & 5 are unknown to connection2_. |
| 886 // node4 & 5 are unknown to connection2_. | 789 EXPECT_FALSE(connection2_->ReorderNode( |
| 887 EXPECT_FALSE(connection2_->ReorderNode( | 790 node4_id, node5_id, ORDER_DIRECTION_ABOVE)); |
| 888 node4_id, node5_id, ORDER_DIRECTION_ABOVE, 9)); | |
| 889 } | |
| 890 | 791 |
| 891 { | 792 // node6 & node3 have different parents. |
| 892 // node6 & node3 have different parents. | 793 EXPECT_FALSE( |
| 893 EXPECT_FALSE( | 794 connection_->ReorderNode(node3_id, node6_id, ORDER_DIRECTION_ABOVE)); |
| 894 connection_->ReorderNode(node3_id, node6_id, ORDER_DIRECTION_ABOVE, 9)); | |
| 895 } | |
| 896 | 795 |
| 897 { | 796 // Non-existent node-ids |
| 898 // Non-existent node-ids | 797 EXPECT_FALSE(connection_->ReorderNode( |
| 899 EXPECT_FALSE(connection_->ReorderNode( | 798 BuildNodeId(1, 27), BuildNodeId(1, 28), ORDER_DIRECTION_ABOVE)); |
| 900 BuildNodeId(1, 27), BuildNodeId(1, 28), ORDER_DIRECTION_ABOVE, 9)); | |
| 901 } | |
| 902 | 799 |
| 903 { | 800 // node7 & node8 are un-parented. |
| 904 // node7 & node8 are un-parented. | 801 EXPECT_FALSE( |
| 905 EXPECT_FALSE( | 802 connection_->ReorderNode(node7_id, node8_id, ORDER_DIRECTION_ABOVE)); |
| 906 connection_->ReorderNode(node7_id, node8_id, ORDER_DIRECTION_ABOVE, 9)); | |
| 907 } | |
| 908 } | 803 } |
| 909 | 804 |
| 910 // Verifies DeleteNode works. | 805 // Verifies DeleteNode works. |
| 911 TEST_F(ViewManagerTest, DeleteNode) { | 806 TEST_F(ViewManagerTest, DeleteNode) { |
| 912 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 807 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 913 | 808 |
| 914 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 809 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 915 | 810 |
| 916 // Make 2 a child of 1. | 811 // Make 2 a child of 1. |
| 917 { | 812 { |
| 918 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 2)); | 813 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2))); |
| 919 connection2_->DoRunLoopUntilChangesCount(1); | 814 connection2_->DoRunLoopUntilChangesCount(1); |
| 920 const Changes changes(ChangesToDescription1(connection2_->changes())); | 815 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 921 ASSERT_EQ(1u, changes.size()); | 816 ASSERT_EQ(1u, changes.size()); |
| 922 EXPECT_EQ("HierarchyChanged change_id=2 node=1,2 new_parent=1,1 " | 817 EXPECT_EQ("HierarchyChanged node=1,2 new_parent=1,1 old_parent=null", |
| 923 "old_parent=null", changes[0]); | 818 changes[0]); |
| 924 } | 819 } |
| 925 | 820 |
| 926 // Delete 2. | 821 // Delete 2. |
| 927 { | 822 { |
| 928 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 2), 3)); | 823 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 2))); |
| 929 EXPECT_TRUE(connection_->changes().empty()); | 824 EXPECT_TRUE(connection_->changes().empty()); |
| 930 | 825 |
| 931 connection2_->DoRunLoopUntilChangesCount(1); | 826 connection2_->DoRunLoopUntilChangesCount(1); |
| 932 const Changes changes(ChangesToDescription1(connection2_->changes())); | 827 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 933 ASSERT_EQ(1u, changes.size()); | 828 ASSERT_EQ(1u, changes.size()); |
| 934 EXPECT_EQ("NodeDeleted change_id=3 node=1,2", changes[0]); | 829 EXPECT_EQ("NodeDeleted node=1,2", changes[0]); |
| 935 } | 830 } |
| 936 } | 831 } |
| 937 | 832 |
| 938 // Verifies DeleteNode isn't allowed from a separate connection. | 833 // Verifies DeleteNode isn't allowed from a separate connection. |
| 939 TEST_F(ViewManagerTest, DeleteNodeFromAnotherConnectionDisallowed) { | 834 TEST_F(ViewManagerTest, DeleteNodeFromAnotherConnectionDisallowed) { |
| 940 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 835 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 941 EXPECT_FALSE(connection2_->DeleteNode(BuildNodeId(1, 1), 1)); | 836 EXPECT_FALSE(connection2_->DeleteNode(BuildNodeId(1, 1))); |
| 942 } | 837 } |
| 943 | 838 |
| 944 // Verifies DeleteView isn't allowed from a separate connection. | 839 // Verifies DeleteView isn't allowed from a separate connection. |
| 945 TEST_F(ViewManagerTest, DeleteViewFromAnotherConnectionDisallowed) { | 840 TEST_F(ViewManagerTest, DeleteViewFromAnotherConnectionDisallowed) { |
| 946 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); | 841 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1))); |
| 947 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 842 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 948 EXPECT_FALSE(connection2_->DeleteView(BuildViewId(1, 1))); | 843 EXPECT_FALSE(connection2_->DeleteView(BuildViewId(1, 1))); |
| 949 } | 844 } |
| 950 | 845 |
| 951 // Verifies if a node was deleted and then reused that other clients are | 846 // Verifies if a node was deleted and then reused that other clients are |
| 952 // properly notified. | 847 // properly notified. |
| 953 TEST_F(ViewManagerTest, ReuseDeletedNodeId) { | 848 TEST_F(ViewManagerTest, ReuseDeletedNodeId) { |
| 954 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 849 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 955 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 850 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 956 | 851 |
| 957 // Add 2 to 1. | 852 // Add 2 to 1. |
| 958 { | 853 { |
| 959 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 2)); | 854 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2))); |
| 960 | 855 |
| 961 connection2_->DoRunLoopUntilChangesCount(1); | 856 connection2_->DoRunLoopUntilChangesCount(1); |
| 962 const Changes changes(ChangesToDescription1(connection2_->changes())); | 857 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 963 EXPECT_EQ( | 858 EXPECT_EQ("HierarchyChanged node=1,2 new_parent=1,1 old_parent=null", |
| 964 "HierarchyChanged change_id=2 node=1,2 new_parent=1,1 old_parent=null", | 859 changes[0]); |
| 965 changes[0]); | |
| 966 EXPECT_EQ("[node=1,2 parent=1,1 view=null]", | 860 EXPECT_EQ("[node=1,2 parent=1,1 view=null]", |
| 967 ChangeNodeDescription(connection2_->changes())); | 861 ChangeNodeDescription(connection2_->changes())); |
| 968 } | 862 } |
| 969 | 863 |
| 970 // Delete 2. | 864 // Delete 2. |
| 971 { | 865 { |
| 972 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 2), 3)); | 866 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 2))); |
| 973 | 867 |
| 974 connection2_->DoRunLoopUntilChangesCount(1); | 868 connection2_->DoRunLoopUntilChangesCount(1); |
| 975 const Changes changes(ChangesToDescription1(connection2_->changes())); | 869 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 976 ASSERT_EQ(1u, changes.size()); | 870 ASSERT_EQ(1u, changes.size()); |
| 977 EXPECT_EQ("NodeDeleted change_id=3 node=1,2", changes[0]); | 871 EXPECT_EQ("NodeDeleted node=1,2", changes[0]); |
| 978 } | 872 } |
| 979 | 873 |
| 980 // Create 2 again, and add it back to 1. Should get the same notification. | 874 // Create 2 again, and add it back to 1. Should get the same notification. |
| 981 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 875 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 982 { | 876 { |
| 983 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 4)); | 877 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2))); |
| 984 | 878 |
| 985 connection2_->DoRunLoopUntilChangesCount(1); | 879 connection2_->DoRunLoopUntilChangesCount(1); |
| 986 const Changes changes(ChangesToDescription1(connection2_->changes())); | 880 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 987 EXPECT_EQ( | 881 EXPECT_EQ("HierarchyChanged node=1,2 new_parent=1,1 old_parent=null", |
| 988 "HierarchyChanged change_id=4 node=1,2 new_parent=1,1 old_parent=null", | 882 changes[0]); |
| 989 changes[0]); | |
| 990 EXPECT_EQ("[node=1,2 parent=1,1 view=null]", | 883 EXPECT_EQ("[node=1,2 parent=1,1 view=null]", |
| 991 ChangeNodeDescription(connection2_->changes())); | 884 ChangeNodeDescription(connection2_->changes())); |
| 992 } | 885 } |
| 993 } | 886 } |
| 994 | 887 |
| 995 // Assertions around setting a view. | 888 // Assertions around setting a view. |
| 996 TEST_F(ViewManagerTest, SetView) { | 889 TEST_F(ViewManagerTest, SetView) { |
| 997 // Create nodes 1, 2 and 3 and the view 11. Nodes 2 and 3 are parented to 1. | 890 // Create nodes 1, 2 and 3 and the view 11. Nodes 2 and 3 are parented to 1. |
| 998 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 891 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| 999 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 892 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 1000 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); | 893 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); |
| 1001 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 11))); | 894 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 11))); |
| 1002 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 1)); | 895 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2))); |
| 1003 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 3), 2)); | 896 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 3))); |
| 1004 | 897 |
| 1005 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 898 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1006 | 899 |
| 1007 // Set view 11 on node 1. | 900 // Set view 11 on node 1. |
| 1008 { | 901 { |
| 1009 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 1), | 902 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 1), |
| 1010 BuildViewId(1, 11))); | 903 BuildViewId(1, 11))); |
| 1011 | 904 |
| 1012 connection2_->DoRunLoopUntilChangesCount(1); | 905 connection2_->DoRunLoopUntilChangesCount(1); |
| 1013 const Changes changes(ChangesToDescription1(connection2_->changes())); | 906 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1037 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); | 930 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); |
| 1038 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 11))); | 931 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 11))); |
| 1039 | 932 |
| 1040 // Set view 11 on node 2. | 933 // Set view 11 on node 2. |
| 1041 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 2), BuildViewId(1, 11))); | 934 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 2), BuildViewId(1, 11))); |
| 1042 | 935 |
| 1043 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 936 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1044 | 937 |
| 1045 // Delete node 2. The second connection should not see this because the node | 938 // Delete node 2. The second connection should not see this because the node |
| 1046 // was not known to it. | 939 // was not known to it. |
| 1047 { | 940 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 2))); |
| 1048 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 2), 2)); | |
| 1049 | |
| 1050 connection2_->DoRunLoopUntilChangesCount(1); | |
| 1051 const Changes changes(ChangesToDescription1(connection2_->changes())); | |
| 1052 ASSERT_EQ(1u, changes.size()); | |
| 1053 EXPECT_EQ("ServerChangeIdAdvanced 3", changes[0]); | |
| 1054 } | |
| 1055 | 941 |
| 1056 // Parent 3 to 1. | 942 // Parent 3 to 1. |
| 1057 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 3), 3)); | 943 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 3))); |
| 1058 connection2_->DoRunLoopUntilChangesCount(1); | 944 connection2_->DoRunLoopUntilChangesCount(1); |
| 1059 | 945 |
| 1060 // Set view 11 on node 3. | 946 // Set view 11 on node 3. |
| 1061 { | 947 { |
| 1062 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 3), BuildViewId(1, 11))); | 948 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 3), BuildViewId(1, 11))); |
| 1063 | 949 |
| 1064 connection2_->DoRunLoopUntilChangesCount(1); | 950 connection2_->DoRunLoopUntilChangesCount(1); |
| 1065 const Changes changes(ChangesToDescription1(connection2_->changes())); | 951 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1066 ASSERT_EQ(1u, changes.size()); | 952 ASSERT_EQ(1u, changes.size()); |
| 1067 EXPECT_EQ("ViewReplaced node=1,3 new_view=1,11 old_view=null", changes[0]); | 953 EXPECT_EQ("ViewReplaced node=1,3 new_view=1,11 old_view=null", changes[0]); |
| 1068 } | 954 } |
| 1069 | 955 |
| 1070 // Delete 3. | 956 // Delete 3. |
| 1071 { | 957 { |
| 1072 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 3), 4)); | 958 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 3))); |
| 1073 | 959 |
| 1074 connection2_->DoRunLoopUntilChangesCount(1); | 960 connection2_->DoRunLoopUntilChangesCount(1); |
| 1075 const Changes changes(ChangesToDescription1(connection2_->changes())); | 961 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1076 ASSERT_EQ(1u, changes.size()); | 962 ASSERT_EQ(1u, changes.size()); |
| 1077 EXPECT_EQ("NodeDeleted change_id=4 node=1,3", changes[0]); | 963 EXPECT_EQ("NodeDeleted node=1,3", changes[0]); |
| 1078 } | 964 } |
| 1079 } | 965 } |
| 1080 | 966 |
| 1081 // Sets view from one connection on another. | 967 // Sets view from one connection on another. |
| 1082 TEST_F(ViewManagerTest, SetViewFromSecondConnection) { | 968 TEST_F(ViewManagerTest, SetViewFromSecondConnection) { |
| 1083 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 969 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 1084 | 970 |
| 1085 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 971 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 1086 | 972 |
| 1087 // Create a view in the second connection. | 973 // Create a view in the second connection. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1106 EXPECT_EQ("ViewDeleted view=2,51", changes[1]); | 992 EXPECT_EQ("ViewDeleted view=2,51", changes[1]); |
| 1107 } | 993 } |
| 1108 } | 994 } |
| 1109 | 995 |
| 1110 // Assertions for GetNodeTree. | 996 // Assertions for GetNodeTree. |
| 1111 TEST_F(ViewManagerTest, GetNodeTree) { | 997 TEST_F(ViewManagerTest, GetNodeTree) { |
| 1112 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 998 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 1113 | 999 |
| 1114 // Create 11 in first connection and make it a child of 1. | 1000 // Create 11 in first connection and make it a child of 1. |
| 1115 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 11))); | 1001 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 11))); |
| 1116 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 2)); | 1002 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); |
| 1117 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 11), 3)); | 1003 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 11))); |
| 1118 | 1004 |
| 1119 // Create two nodes in second connection, 2 and 3, both children of 1. | 1005 // Create two nodes in second connection, 2 and 3, both children of 1. |
| 1120 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2))); | 1006 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 2))); |
| 1121 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 3))); | 1007 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 3))); |
| 1122 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 2), 4)); | 1008 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 2))); |
| 1123 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 3), 5)); | 1009 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(2, 3))); |
| 1124 | 1010 |
| 1125 // Attach view to node 11 in the first connection. | 1011 // Attach view to node 11 in the first connection. |
| 1126 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 51))); | 1012 ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 51))); |
| 1127 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 11), BuildViewId(1, 51))); | 1013 ASSERT_TRUE(connection_->SetView(BuildNodeId(1, 11), BuildViewId(1, 51))); |
| 1128 | 1014 |
| 1129 // Verifies GetNodeTree() on the root. | 1015 // Verifies GetNodeTree() on the root. |
| 1130 { | 1016 { |
| 1131 std::vector<TestNode> nodes; | 1017 std::vector<TestNode> nodes; |
| 1132 connection_->GetNodeTree(BuildNodeId(0, 1), &nodes); | 1018 connection_->GetNodeTree(BuildNodeId(0, 1), &nodes); |
| 1133 ASSERT_EQ(5u, nodes.size()); | 1019 ASSERT_EQ(5u, nodes.size()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1152 // Connection 2 shouldn't be able to get the root tree. | 1038 // Connection 2 shouldn't be able to get the root tree. |
| 1153 { | 1039 { |
| 1154 std::vector<TestNode> nodes; | 1040 std::vector<TestNode> nodes; |
| 1155 connection2_->GetNodeTree(BuildNodeId(0, 1), &nodes); | 1041 connection2_->GetNodeTree(BuildNodeId(0, 1), &nodes); |
| 1156 ASSERT_EQ(0u, nodes.size()); | 1042 ASSERT_EQ(0u, nodes.size()); |
| 1157 } | 1043 } |
| 1158 } | 1044 } |
| 1159 | 1045 |
| 1160 TEST_F(ViewManagerTest, SetNodeBounds) { | 1046 TEST_F(ViewManagerTest, SetNodeBounds) { |
| 1161 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1047 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| 1162 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 1)); | 1048 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); |
| 1163 | 1049 |
| 1164 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1050 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1165 | 1051 |
| 1166 ASSERT_TRUE(connection_->SetNodeBounds(BuildNodeId(1, 1), | 1052 ASSERT_TRUE(connection_->SetNodeBounds(BuildNodeId(1, 1), |
| 1167 gfx::Rect(0, 0, 100, 100))); | 1053 gfx::Rect(0, 0, 100, 100))); |
| 1168 | 1054 |
| 1169 connection2_->DoRunLoopUntilChangesCount(1); | 1055 connection2_->DoRunLoopUntilChangesCount(1); |
| 1170 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1056 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1171 ASSERT_EQ(1u, changes.size()); | 1057 ASSERT_EQ(1u, changes.size()); |
| 1172 EXPECT_EQ("BoundsChanged node=1,1 old_bounds=0,0 0x0 new_bounds=0,0 100x100", | 1058 EXPECT_EQ("BoundsChanged node=1,1 old_bounds=0,0 0x0 new_bounds=0,0 100x100", |
| 1173 changes[0]); | 1059 changes[0]); |
| 1174 | 1060 |
| 1175 // Should not be possible to change the bounds of a node created by another | 1061 // Should not be possible to change the bounds of a node created by another |
| 1176 // connection. | 1062 // connection. |
| 1177 ASSERT_FALSE(connection2_->SetNodeBounds(BuildNodeId(1, 1), | 1063 ASSERT_FALSE(connection2_->SetNodeBounds(BuildNodeId(1, 1), |
| 1178 gfx::Rect(0, 0, 0, 0))); | 1064 gfx::Rect(0, 0, 0, 0))); |
| 1179 } | 1065 } |
| 1180 | 1066 |
| 1181 // Various assertions around SetRoots. | 1067 // Various assertions around SetRoots. |
| 1182 TEST_F(ViewManagerTest, SetRoots) { | 1068 TEST_F(ViewManagerTest, SetRoots) { |
| 1183 // Create 1, 2, and 3 in the first connection. | 1069 // Create 1, 2, and 3 in the first connection. |
| 1184 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1070 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| 1185 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1071 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 1186 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); | 1072 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 3))); |
| 1187 | 1073 |
| 1188 // Parent 1 to the root. | 1074 // Parent 1 to the root. |
| 1189 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 1)); | 1075 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); |
| 1190 | 1076 |
| 1191 // Establish the second connection with roots 1 and 3. | 1077 // Establish the second connection with roots 1 and 3. |
| 1192 { | 1078 { |
| 1193 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1079 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1194 | 1080 |
| 1195 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 3), kTestServiceURL)); | 1081 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 3), kTestServiceURL)); |
| 1196 connection2_->DoRunLoopUntilChangesCount(1); | 1082 connection2_->DoRunLoopUntilChangesCount(1); |
| 1197 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1083 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1198 ASSERT_EQ(1u, changes.size()); | 1084 ASSERT_EQ(1u, changes.size()); |
| 1199 EXPECT_EQ("OnRootAdded", changes[0]); | 1085 EXPECT_EQ("OnRootAdded", changes[0]); |
| 1200 EXPECT_EQ("[node=1,3 parent=null view=null]", | 1086 EXPECT_EQ("[node=1,3 parent=null view=null]", |
| 1201 ChangeNodeDescription(connection2_->changes())); | 1087 ChangeNodeDescription(connection2_->changes())); |
| 1202 } | 1088 } |
| 1203 | 1089 |
| 1204 // Create 4 and add it to the root, connection 2 should only get id advanced. | 1090 // Create 4 and add it to the root, connection 2 should not getting anything. |
| 1205 { | 1091 { |
| 1206 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 4))); | 1092 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 4))); |
| 1207 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 4), 4)); | 1093 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 4))); |
| 1208 | |
| 1209 connection2_->DoRunLoopUntilChangesCount(1); | |
| 1210 const Changes changes(ChangesToDescription1(connection2_->changes())); | |
| 1211 ASSERT_EQ(1u, changes.size()); | |
| 1212 EXPECT_EQ("ServerChangeIdAdvanced 5", changes[0]); | |
| 1213 } | 1094 } |
| 1214 | 1095 |
| 1215 // Move 4 under 3, this should expose 4 to the client. | 1096 // Move 4 under 3, this should expose 4 to the client. |
| 1216 { | 1097 { |
| 1217 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 3), BuildNodeId(1, 4), 5)); | 1098 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 3), BuildNodeId(1, 4))); |
| 1218 connection2_->DoRunLoopUntilChangesCount(1); | 1099 connection2_->DoRunLoopUntilChangesCount(1); |
| 1219 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1100 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1220 ASSERT_EQ(1u, changes.size()); | 1101 ASSERT_EQ(1u, changes.size()); |
| 1221 EXPECT_EQ( | 1102 EXPECT_EQ( |
| 1222 "HierarchyChanged change_id=5 node=1,4 new_parent=1,3 " | 1103 "HierarchyChanged node=1,4 new_parent=1,3 old_parent=null", changes[0]); |
| 1223 "old_parent=null", changes[0]); | |
| 1224 EXPECT_EQ("[node=1,4 parent=1,3 view=null]", | 1104 EXPECT_EQ("[node=1,4 parent=1,3 view=null]", |
| 1225 ChangeNodeDescription(connection2_->changes())); | 1105 ChangeNodeDescription(connection2_->changes())); |
| 1226 } | 1106 } |
| 1227 | 1107 |
| 1228 // Move 4 under 2, since 2 isn't a root client should get a delete. | 1108 // Move 4 under 2, since 2 isn't a root client should get a delete. |
| 1229 { | 1109 { |
| 1230 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 4), 6)); | 1110 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 2), BuildNodeId(1, 4))); |
| 1231 connection2_->DoRunLoopUntilChangesCount(1); | 1111 connection2_->DoRunLoopUntilChangesCount(1); |
| 1232 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1112 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1233 ASSERT_EQ(1u, changes.size()); | 1113 ASSERT_EQ(1u, changes.size()); |
| 1234 EXPECT_EQ("NodeDeleted change_id=6 node=1,4", changes[0]); | 1114 EXPECT_EQ("NodeDeleted node=1,4", changes[0]); |
| 1235 } | 1115 } |
| 1236 | 1116 |
| 1237 // Delete 4, client shouldn't receive a delete since it should no longer know | 1117 // Delete 4, client shouldn't receive a delete since it should no longer know |
| 1238 // about 4. | 1118 // about 4. |
| 1239 { | 1119 { |
| 1240 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 4), 7)); | 1120 ASSERT_TRUE(connection_->DeleteNode(BuildNodeId(1, 4))); |
| 1241 | |
| 1242 connection2_->DoRunLoopUntilChangesCount(1); | |
| 1243 const Changes changes(ChangesToDescription1(connection2_->changes())); | |
| 1244 ASSERT_EQ(1u, changes.size()); | |
| 1245 EXPECT_EQ("ServerChangeIdAdvanced 8", changes[0]); | |
| 1246 } | 1121 } |
| 1247 } | 1122 } |
| 1248 | 1123 |
| 1249 // Verify AddNode fails when trying to manipulate nodes in other roots. | 1124 // Verify AddNode fails when trying to manipulate nodes in other roots. |
| 1250 TEST_F(ViewManagerTest, CantMoveNodesFromOtherRoot) { | 1125 TEST_F(ViewManagerTest, CantMoveNodesFromOtherRoot) { |
| 1251 // Create 1 and 2 in the first connection. | 1126 // Create 1 and 2 in the first connection. |
| 1252 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1127 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| 1253 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1128 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 1254 | 1129 |
| 1255 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1130 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1256 | 1131 |
| 1257 // Try to move 2 to be a child of 1 from connection 2. This should fail as 2 | 1132 // Try to move 2 to be a child of 1 from connection 2. This should fail as 2 |
| 1258 // should not be able to access 1. | 1133 // should not be able to access 1. |
| 1259 ASSERT_FALSE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 1)); | 1134 ASSERT_FALSE(connection2_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2))); |
| 1260 | 1135 |
| 1261 // Try to reparent 1 to the root. A connection is not allowed to reparent its | 1136 // Try to reparent 1 to the root. A connection is not allowed to reparent its |
| 1262 // roots. | 1137 // roots. |
| 1263 ASSERT_FALSE(connection2_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 1)); | 1138 ASSERT_FALSE(connection2_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); |
| 1264 } | 1139 } |
| 1265 | 1140 |
| 1266 // Verify RemoveNodeFromParent fails for nodes that are descendants of the | 1141 // Verify RemoveNodeFromParent fails for nodes that are descendants of the |
| 1267 // roots. | 1142 // roots. |
| 1268 TEST_F(ViewManagerTest, CantRemoveNodesInOtherRoots) { | 1143 TEST_F(ViewManagerTest, CantRemoveNodesInOtherRoots) { |
| 1269 // Create 1 and 2 in the first connection and parent both to the root. | 1144 // Create 1 and 2 in the first connection and parent both to the root. |
| 1270 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1145 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| 1271 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1146 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 1272 | 1147 |
| 1273 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 1)); | 1148 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); |
| 1274 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 2), 2)); | 1149 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 2))); |
| 1275 | 1150 |
| 1276 // Establish the second connection and give it the root 1. | 1151 // Establish the second connection and give it the root 1. |
| 1277 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1152 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1278 | 1153 |
| 1279 // Connection 2 should not be able to remove node 2 or 1 from its parent. | 1154 // Connection 2 should not be able to remove node 2 or 1 from its parent. |
| 1280 ASSERT_FALSE(connection2_->RemoveNodeFromParent(BuildNodeId(1, 2), 4)); | 1155 ASSERT_FALSE(connection2_->RemoveNodeFromParent(BuildNodeId(1, 2))); |
| 1281 ASSERT_FALSE(connection2_->RemoveNodeFromParent(BuildNodeId(1, 1), 4)); | 1156 ASSERT_FALSE(connection2_->RemoveNodeFromParent(BuildNodeId(1, 1))); |
| 1282 | 1157 |
| 1283 // Create nodes 10 and 11 in 2. | 1158 // Create nodes 10 and 11 in 2. |
| 1284 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 10))); | 1159 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 10))); |
| 1285 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 11))); | 1160 ASSERT_TRUE(connection2_->CreateNode(BuildNodeId(2, 11))); |
| 1286 | 1161 |
| 1287 // Parent 11 to 10. | 1162 // Parent 11 to 10. |
| 1288 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(2, 10), BuildNodeId(2, 11), 4)); | 1163 ASSERT_TRUE(connection2_->AddNode(BuildNodeId(2, 10), BuildNodeId(2, 11))); |
| 1289 // Remove 11 from 10. | 1164 // Remove 11 from 10. |
| 1290 ASSERT_TRUE(connection2_->RemoveNodeFromParent( BuildNodeId(2, 11), 5)); | 1165 ASSERT_TRUE(connection2_->RemoveNodeFromParent( BuildNodeId(2, 11))); |
| 1291 | 1166 |
| 1292 // Verify nothing was actually removed. | 1167 // Verify nothing was actually removed. |
| 1293 { | 1168 { |
| 1294 std::vector<TestNode> nodes; | 1169 std::vector<TestNode> nodes; |
| 1295 connection_->GetNodeTree(BuildNodeId(0, 1), &nodes); | 1170 connection_->GetNodeTree(BuildNodeId(0, 1), &nodes); |
| 1296 ASSERT_EQ(3u, nodes.size()); | 1171 ASSERT_EQ(3u, nodes.size()); |
| 1297 EXPECT_EQ("node=0,1 parent=null view=null", nodes[0].ToString()); | 1172 EXPECT_EQ("node=0,1 parent=null view=null", nodes[0].ToString()); |
| 1298 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[1].ToString()); | 1173 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[1].ToString()); |
| 1299 EXPECT_EQ("node=1,2 parent=0,1 view=null", nodes[2].ToString()); | 1174 EXPECT_EQ("node=1,2 parent=0,1 view=null", nodes[2].ToString()); |
| 1300 } | 1175 } |
| 1301 } | 1176 } |
| 1302 | 1177 |
| 1303 // Verify SetView fails for nodes that are not descendants of the roots. | 1178 // Verify SetView fails for nodes that are not descendants of the roots. |
| 1304 TEST_F(ViewManagerTest, CantRemoveSetViewInOtherRoots) { | 1179 TEST_F(ViewManagerTest, CantRemoveSetViewInOtherRoots) { |
| 1305 // Create 1 and 2 in the first connection and parent both to the root. | 1180 // Create 1 and 2 in the first connection and parent both to the root. |
| 1306 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1181 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| 1307 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1182 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 1308 | 1183 |
| 1309 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 1)); | 1184 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); |
| 1310 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 2), 2)); | 1185 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 2))); |
| 1311 | 1186 |
| 1312 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1187 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1313 | 1188 |
| 1314 // Create a view in the second connection. | 1189 // Create a view in the second connection. |
| 1315 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 51))); | 1190 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 51))); |
| 1316 | 1191 |
| 1317 // Connection 2 should be able to set the view on node 1 (it's root), but not | 1192 // Connection 2 should be able to set the view on node 1 (it's root), but not |
| 1318 // on 2. | 1193 // on 2. |
| 1319 ASSERT_TRUE(connection2_->SetView(BuildNodeId(1, 1), BuildViewId(2, 51))); | 1194 ASSERT_TRUE(connection2_->SetView(BuildNodeId(1, 1), BuildViewId(2, 51))); |
| 1320 ASSERT_FALSE(connection2_->SetView(BuildNodeId(1, 2), BuildViewId(2, 51))); | 1195 ASSERT_FALSE(connection2_->SetView(BuildNodeId(1, 2), BuildViewId(2, 51))); |
| 1321 } | 1196 } |
| 1322 | 1197 |
| 1323 // Verify GetNodeTree fails for nodes that are not descendants of the roots. | 1198 // Verify GetNodeTree fails for nodes that are not descendants of the roots. |
| 1324 TEST_F(ViewManagerTest, CantGetNodeTreeOfOtherRoots) { | 1199 TEST_F(ViewManagerTest, CantGetNodeTreeOfOtherRoots) { |
| 1325 // Create 1 and 2 in the first connection and parent both to the root. | 1200 // Create 1 and 2 in the first connection and parent both to the root. |
| 1326 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1201 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| 1327 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1202 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 1328 | 1203 |
| 1329 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1), 1)); | 1204 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 1))); |
| 1330 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 2), 2)); | 1205 ASSERT_TRUE(connection_->AddNode(BuildNodeId(0, 1), BuildNodeId(1, 2))); |
| 1331 | 1206 |
| 1332 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1207 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1333 | 1208 |
| 1334 std::vector<TestNode> nodes; | 1209 std::vector<TestNode> nodes; |
| 1335 | 1210 |
| 1336 // Should get nothing for the root. | 1211 // Should get nothing for the root. |
| 1337 connection2_->GetNodeTree(BuildNodeId(0, 1), &nodes); | 1212 connection2_->GetNodeTree(BuildNodeId(0, 1), &nodes); |
| 1338 ASSERT_TRUE(nodes.empty()); | 1213 ASSERT_TRUE(nodes.empty()); |
| 1339 | 1214 |
| 1340 // Should get nothing for node 2. | 1215 // Should get nothing for node 2. |
| 1341 connection2_->GetNodeTree(BuildNodeId(1, 2), &nodes); | 1216 connection2_->GetNodeTree(BuildNodeId(1, 2), &nodes); |
| 1342 ASSERT_TRUE(nodes.empty()); | 1217 ASSERT_TRUE(nodes.empty()); |
| 1343 | 1218 |
| 1344 // Should get node 1 if asked for. | 1219 // Should get node 1 if asked for. |
| 1345 connection2_->GetNodeTree(BuildNodeId(1, 1), &nodes); | 1220 connection2_->GetNodeTree(BuildNodeId(1, 1), &nodes); |
| 1346 ASSERT_EQ(1u, nodes.size()); | 1221 ASSERT_EQ(1u, nodes.size()); |
| 1347 EXPECT_EQ("node=1,1 parent=null view=null", nodes[0].ToString()); | 1222 EXPECT_EQ("node=1,1 parent=null view=null", nodes[0].ToString()); |
| 1348 } | 1223 } |
| 1349 | 1224 |
| 1350 TEST_F(ViewManagerTest, ConnectTwice) { | 1225 TEST_F(ViewManagerTest, ConnectTwice) { |
| 1351 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1226 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| 1352 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 1227 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
| 1353 | 1228 |
| 1354 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 1)); | 1229 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2))); |
| 1355 | 1230 |
| 1356 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1231 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1357 | 1232 |
| 1358 // Try to connect again to 1,1, this should fail as already connected to that | 1233 // Try to connect again to 1,1, this should fail as already connected to that |
| 1359 // root. | 1234 // root. |
| 1360 { | 1235 ASSERT_FALSE(connection_->Embed(BuildNodeId(1, 1), kTestServiceURL)); |
| 1361 ASSERT_FALSE(connection_->Embed(BuildNodeId(1, 1), kTestServiceURL)); | |
| 1362 } | |
| 1363 | 1236 |
| 1364 // Connecting to 1,2 should succeed and end up in connection2. | 1237 // Connecting to 1,2 should succeed and end up in connection2. |
| 1365 { | 1238 { |
| 1366 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 2), kTestServiceURL)); | 1239 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 2), kTestServiceURL)); |
| 1367 connection2_->DoRunLoopUntilChangesCount(1); | 1240 connection2_->DoRunLoopUntilChangesCount(1); |
| 1368 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1241 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1369 ASSERT_EQ(1u, changes.size()); | 1242 ASSERT_EQ(1u, changes.size()); |
| 1370 EXPECT_EQ("OnRootAdded", changes[0]); | 1243 EXPECT_EQ("OnRootAdded", changes[0]); |
| 1371 EXPECT_EQ("[node=1,2 parent=1,1 view=null]", | 1244 EXPECT_EQ("[node=1,2 parent=1,1 view=null]", |
| 1372 ChangeNodeDescription(connection2_->changes())); | 1245 ChangeNodeDescription(connection2_->changes())); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1407 const Changes changes(ChangesToDescription1(connection3->changes())); | 1280 const Changes changes(ChangesToDescription1(connection3->changes())); |
| 1408 ASSERT_EQ(1u, changes.size()); | 1281 ASSERT_EQ(1u, changes.size()); |
| 1409 EXPECT_EQ("OnConnectionEstablished creator=mojo:test_url", changes[0]); | 1282 EXPECT_EQ("OnConnectionEstablished creator=mojo:test_url", changes[0]); |
| 1410 } | 1283 } |
| 1411 | 1284 |
| 1412 // Connection2 should have been told the node was deleted. | 1285 // Connection2 should have been told the node was deleted. |
| 1413 { | 1286 { |
| 1414 connection2_->DoRunLoopUntilChangesCount(1); | 1287 connection2_->DoRunLoopUntilChangesCount(1); |
| 1415 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1288 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1416 ASSERT_EQ(1u, changes.size()); | 1289 ASSERT_EQ(1u, changes.size()); |
| 1417 EXPECT_EQ("NodeDeleted change_id=2 node=1,1", changes[0]); | 1290 EXPECT_EQ("NodeDeleted node=1,1", changes[0]); |
| 1418 } | 1291 } |
| 1419 | 1292 |
| 1420 // Connection2 has no root. Verify it can't see node 1,1 anymore. | 1293 // Connection2 has no root. Verify it can't see node 1,1 anymore. |
| 1421 { | 1294 { |
| 1422 std::vector<TestNode> nodes; | 1295 std::vector<TestNode> nodes; |
| 1423 connection2_->GetNodeTree(BuildNodeId(1, 1), &nodes); | 1296 connection2_->GetNodeTree(BuildNodeId(1, 1), &nodes); |
| 1424 EXPECT_TRUE(nodes.empty()); | 1297 EXPECT_TRUE(nodes.empty()); |
| 1425 } | 1298 } |
| 1426 | 1299 |
| 1427 connection3->Destroy(); | 1300 connection3->Destroy(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1441 ASSERT_EQ(1u, changes.size()); | 1314 ASSERT_EQ(1u, changes.size()); |
| 1442 EXPECT_EQ("OnConnectionEstablished creator=mojo:test_url", changes[0]); | 1315 EXPECT_EQ("OnConnectionEstablished creator=mojo:test_url", changes[0]); |
| 1443 } | 1316 } |
| 1444 | 1317 |
| 1445 // Connection2 should have been told the node was deleted. | 1318 // Connection2 should have been told the node was deleted. |
| 1446 connection2_->DoRunLoopUntilChangesCount(1); | 1319 connection2_->DoRunLoopUntilChangesCount(1); |
| 1447 connection2_->ClearChanges(); | 1320 connection2_->ClearChanges(); |
| 1448 | 1321 |
| 1449 // Create a node in the third connection and parent it to the root. | 1322 // Create a node in the third connection and parent it to the root. |
| 1450 ASSERT_TRUE(connection3->CreateNode(BuildNodeId(3, 1))); | 1323 ASSERT_TRUE(connection3->CreateNode(BuildNodeId(3, 1))); |
| 1451 ASSERT_TRUE(connection3->AddNode(BuildNodeId(1, 1), BuildNodeId(3, 1), 3)); | 1324 ASSERT_TRUE(connection3->AddNode(BuildNodeId(1, 1), BuildNodeId(3, 1))); |
| 1452 | 1325 |
| 1453 // Connection 1 should have been told about the add (it owns the node). | 1326 // Connection 1 should have been told about the add (it owns the node). |
| 1454 { | 1327 { |
| 1455 connection_->DoRunLoopUntilChangesCount(1); | 1328 connection_->DoRunLoopUntilChangesCount(1); |
| 1456 const Changes changes(ChangesToDescription1(connection_->changes())); | 1329 const Changes changes(ChangesToDescription1(connection_->changes())); |
| 1457 ASSERT_EQ(1u, changes.size()); | 1330 ASSERT_EQ(1u, changes.size()); |
| 1458 EXPECT_EQ( | 1331 EXPECT_EQ("HierarchyChanged node=3,1 new_parent=1,1 old_parent=null", |
| 1459 "HierarchyChanged change_id=3 node=3,1 new_parent=1,1 old_parent=null", | 1332 changes[0]); |
| 1460 changes[0]); | |
| 1461 } | 1333 } |
| 1462 | 1334 |
| 1463 // connection2_ should get an advance. | |
| 1464 connection2_->DoRunLoopUntilChangesCount(1); | |
| 1465 connection2_->ClearChanges(); | |
| 1466 | |
| 1467 // Embed 1,1 back in connection 2. | 1335 // Embed 1,1 back in connection 2. |
| 1468 { | 1336 { |
| 1469 // 2 should be told about the new embed. | 1337 // 2 should be told about the new embed. |
| 1470 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 1), kTestServiceURL)); | 1338 ASSERT_TRUE(connection_->Embed(BuildNodeId(1, 1), kTestServiceURL)); |
| 1471 connection2_->DoRunLoopUntilChangesCount(1); | 1339 connection2_->DoRunLoopUntilChangesCount(1); |
| 1472 const std::vector<Change>& changes(connection2_->changes()); | 1340 const std::vector<Change>& changes(connection2_->changes()); |
| 1473 ASSERT_EQ(1u, changes.size()); | 1341 ASSERT_EQ(1u, changes.size()); |
| 1474 EXPECT_EQ("OnRootAdded", ChangesToDescription1(changes)[0]); | 1342 EXPECT_EQ("OnRootAdded", ChangesToDescription1(changes)[0]); |
| 1475 EXPECT_EQ("[node=1,1 parent=null view=null]", | 1343 EXPECT_EQ("[node=1,1 parent=null view=null]", |
| 1476 ChangeNodeDescription(changes)); | 1344 ChangeNodeDescription(changes)); |
| 1477 | 1345 |
| 1478 // And 3 should get a delete. | 1346 // And 3 should get a delete. |
| 1479 connection3->DoRunLoopUntilChangesCount(1); | 1347 connection3->DoRunLoopUntilChangesCount(1); |
| 1480 ASSERT_EQ(1u, connection3->changes().size()); | 1348 ASSERT_EQ(1u, connection3->changes().size()); |
| 1481 EXPECT_EQ("NodeDeleted change_id=4 node=1,1", | 1349 EXPECT_EQ("NodeDeleted node=1,1", |
| 1482 ChangesToDescription1(connection3->changes())[0]); | 1350 ChangesToDescription1(connection3->changes())[0]); |
| 1483 } | 1351 } |
| 1484 | 1352 |
| 1485 // Connection3 has no root. Verify it can't see node 1,1 anymore. | 1353 // Connection3 has no root. Verify it can't see node 1,1 anymore. |
| 1486 { | 1354 { |
| 1487 std::vector<TestNode> nodes; | 1355 std::vector<TestNode> nodes; |
| 1488 connection3->GetNodeTree(BuildNodeId(1, 1), &nodes); | 1356 connection3->GetNodeTree(BuildNodeId(1, 1), &nodes); |
| 1489 EXPECT_TRUE(nodes.empty()); | 1357 EXPECT_TRUE(nodes.empty()); |
| 1490 } | 1358 } |
| 1491 | 1359 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1503 std::vector<TestNode> nodes; | 1371 std::vector<TestNode> nodes; |
| 1504 connection3->GetNodeTree(BuildNodeId(3, 1), &nodes); | 1372 connection3->GetNodeTree(BuildNodeId(3, 1), &nodes); |
| 1505 ASSERT_EQ(1u, nodes.size()); | 1373 ASSERT_EQ(1u, nodes.size()); |
| 1506 EXPECT_EQ("node=3,1 parent=null view=null", nodes[0].ToString()); | 1374 EXPECT_EQ("node=3,1 parent=null view=null", nodes[0].ToString()); |
| 1507 } | 1375 } |
| 1508 | 1376 |
| 1509 connection3->Destroy(); | 1377 connection3->Destroy(); |
| 1510 } | 1378 } |
| 1511 | 1379 |
| 1512 // TODO(sky): add coverage of test that destroys connections and ensures other | 1380 // TODO(sky): add coverage of test that destroys connections and ensures other |
| 1513 // connections get deletion notification (or advanced server id). | 1381 // connections get deletion notification. |
| 1514 | 1382 |
| 1515 // TODO(sky): need to better track changes to initial connection. For example, | 1383 // TODO(sky): need to better track changes to initial connection. For example, |
| 1516 // that SetBounsdNodes/AddNode and the like don't result in messages to the | 1384 // that SetBounsdNodes/AddNode and the like don't result in messages to the |
| 1517 // originating connection. | 1385 // originating connection. |
| 1518 | 1386 |
| 1519 // TODO(beng): Add tests for focus: | 1387 // TODO(beng): Add tests for focus: |
| 1520 // - focus between two nodes known to a connection | 1388 // - focus between two nodes known to a connection |
| 1521 // - focus between nodes unknown to one of the connections. | 1389 // - focus between nodes unknown to one of the connections. |
| 1522 // - focus between nodes unknown to either connection. | 1390 // - focus between nodes unknown to either connection. |
| 1523 | 1391 |
| 1524 } // namespace service | 1392 } // namespace service |
| 1525 } // namespace view_manager | 1393 } // namespace view_manager |
| 1526 } // namespace mojo | 1394 } // namespace mojo |
| OLD | NEW |