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/auto_reset.h" | 8 #include "base/auto_reset.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 } | 105 } |
106 bool RemoveNodeFromParent(Id node_id, Id server_change_id) { | 106 bool RemoveNodeFromParent(Id node_id, Id server_change_id) { |
107 changes_.clear(); | 107 changes_.clear(); |
108 bool result = false; | 108 bool result = false; |
109 view_manager_->RemoveNodeFromParent(node_id, server_change_id, | 109 view_manager_->RemoveNodeFromParent(node_id, server_change_id, |
110 base::Bind(&ViewManagerProxy::GotResult, | 110 base::Bind(&ViewManagerProxy::GotResult, |
111 base::Unretained(this), &result)); | 111 base::Unretained(this), &result)); |
112 RunMainLoop(); | 112 RunMainLoop(); |
113 return result; | 113 return result; |
114 } | 114 } |
| 115 bool ReorderNode(Id node_id, |
| 116 Id relative_node_id, |
| 117 OrderDirection direction, |
| 118 Id server_change_id) { |
| 119 changes_.clear(); |
| 120 bool result = false; |
| 121 view_manager_->ReorderNode(node_id, relative_node_id, direction, |
| 122 server_change_id, |
| 123 base::Bind(&ViewManagerProxy::GotResult, |
| 124 base::Unretained(this), &result)); |
| 125 RunMainLoop(); |
| 126 return result; |
| 127 } |
115 bool SetView(Id node_id, Id view_id) { | 128 bool SetView(Id node_id, Id view_id) { |
116 changes_.clear(); | 129 changes_.clear(); |
117 bool result = false; | 130 bool result = false; |
118 view_manager_->SetView(node_id, view_id, | 131 view_manager_->SetView(node_id, view_id, |
119 base::Bind(&ViewManagerProxy::GotResult, | 132 base::Bind(&ViewManagerProxy::GotResult, |
120 base::Unretained(this), &result)); | 133 base::Unretained(this), &result)); |
121 RunMainLoop(); | 134 RunMainLoop(); |
122 return result; | 135 return result; |
123 } | 136 } |
124 bool CreateView(Id view_id) { | 137 bool CreateView(Id view_id) { |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 tracker_.OnNodeBoundsChanged(node_id, old_bounds.Pass(), new_bounds.Pass()); | 311 tracker_.OnNodeBoundsChanged(node_id, old_bounds.Pass(), new_bounds.Pass()); |
299 } | 312 } |
300 virtual void OnNodeHierarchyChanged(Id node, | 313 virtual void OnNodeHierarchyChanged(Id node, |
301 Id new_parent, | 314 Id new_parent, |
302 Id old_parent, | 315 Id old_parent, |
303 Id server_change_id, | 316 Id server_change_id, |
304 Array<INodePtr> nodes) OVERRIDE { | 317 Array<INodePtr> nodes) OVERRIDE { |
305 tracker_.OnNodeHierarchyChanged(node, new_parent, old_parent, | 318 tracker_.OnNodeHierarchyChanged(node, new_parent, old_parent, |
306 server_change_id, nodes.Pass()); | 319 server_change_id, nodes.Pass()); |
307 } | 320 } |
| 321 virtual void OnNodeReordered(Id node_id, |
| 322 Id relative_node_id, |
| 323 OrderDirection direction, |
| 324 Id server_change_id) OVERRIDE { |
| 325 tracker_.OnNodeReordered(node_id, relative_node_id, direction, |
| 326 server_change_id); |
| 327 } |
308 virtual void OnNodeDeleted(Id node, Id server_change_id) OVERRIDE { | 328 virtual void OnNodeDeleted(Id node, Id server_change_id) OVERRIDE { |
309 tracker_.OnNodeDeleted(node, server_change_id); | 329 tracker_.OnNodeDeleted(node, server_change_id); |
310 } | 330 } |
311 virtual void OnViewDeleted(Id view) OVERRIDE { | 331 virtual void OnViewDeleted(Id view) OVERRIDE { |
312 tracker_.OnViewDeleted(view); | 332 tracker_.OnViewDeleted(view); |
313 } | 333 } |
314 virtual void OnNodeViewReplaced(Id node, | 334 virtual void OnNodeViewReplaced(Id node, |
315 Id new_view_id, | 335 Id new_view_id, |
316 Id old_view_id) OVERRIDE { | 336 Id old_view_id) OVERRIDE { |
317 tracker_.OnNodeViewReplaced(node, new_view_id, old_view_id); | 337 tracker_.OnNodeViewReplaced(node, new_view_id, old_view_id); |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 ASSERT_EQ(1u, changes.size()); | 771 ASSERT_EQ(1u, changes.size()); |
752 EXPECT_EQ( | 772 EXPECT_EQ( |
753 "HierarchyChanged change_id=5 node=1,2 new_parent=1,1 old_parent=null", | 773 "HierarchyChanged change_id=5 node=1,2 new_parent=1,1 old_parent=null", |
754 changes[0]); | 774 changes[0]); |
755 EXPECT_EQ("[node=1,2 parent=1,1 view=null]," | 775 EXPECT_EQ("[node=1,2 parent=1,1 view=null]," |
756 "[node=1,21 parent=1,2 view=null]", | 776 "[node=1,21 parent=1,2 view=null]", |
757 ChangeNodeDescription(connection2_->changes())); | 777 ChangeNodeDescription(connection2_->changes())); |
758 } | 778 } |
759 } | 779 } |
760 | 780 |
| 781 TEST_F(ViewManagerConnectionTest, ReorderNode) { |
| 782 Id node1_id = BuildNodeId(1, 1); |
| 783 Id node2_id = BuildNodeId(1, 2); |
| 784 Id node3_id = BuildNodeId(1, 3); |
| 785 ASSERT_TRUE(connection_->CreateNode(node1_id)); |
| 786 ASSERT_TRUE(connection_->CreateNode(node2_id)); |
| 787 ASSERT_TRUE(connection_->CreateNode(node3_id)); |
| 788 ASSERT_TRUE(connection_->AddNode(node1_id, node2_id, 1)); |
| 789 ASSERT_TRUE(connection_->AddNode(node1_id, node3_id, 2)); |
| 790 |
| 791 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 792 |
| 793 { |
| 794 connection_->ReorderNode(node2_id, node3_id, ORDER_ABOVE, 3); |
| 795 |
| 796 connection2_->DoRunLoopUntilChangesCount(1); |
| 797 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 798 ASSERT_EQ(1u, changes.size()); |
| 799 EXPECT_EQ( |
| 800 "Reordered change_id=3 node=1,2 relative=1,3 direction=above", |
| 801 changes[0]); |
| 802 } |
| 803 |
| 804 { |
| 805 connection_->ReorderNode(node2_id, node3_id, ORDER_BELOW, 4); |
| 806 |
| 807 connection2_->DoRunLoopUntilChangesCount(1); |
| 808 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 809 ASSERT_EQ(1u, changes.size()); |
| 810 EXPECT_EQ( |
| 811 "Reordered change_id=4 node=1,2 relative=1,3 direction=below", |
| 812 changes[0]); |
| 813 } |
| 814 } |
| 815 |
761 // Verifies DeleteNode works. | 816 // Verifies DeleteNode works. |
762 TEST_F(ViewManagerConnectionTest, DeleteNode) { | 817 TEST_F(ViewManagerConnectionTest, DeleteNode) { |
763 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 818 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
764 | 819 |
765 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 820 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
766 | 821 |
767 // Make 2 a child of 1. | 822 // Make 2 a child of 1. |
768 { | 823 { |
769 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 1)); | 824 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 1)); |
770 connection2_->DoRunLoopUntilChangesCount(1); | 825 connection2_->DoRunLoopUntilChangesCount(1); |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 // TODO(sky): add coverage of test that destroys connections and ensures other | 1282 // TODO(sky): add coverage of test that destroys connections and ensures other |
1228 // connections get deletion notification (or advanced server id). | 1283 // connections get deletion notification (or advanced server id). |
1229 | 1284 |
1230 // TODO(sky): need to better track changes to initial connection. For example, | 1285 // TODO(sky): need to better track changes to initial connection. For example, |
1231 // that SetBounsdNodes/AddNode and the like don't result in messages to the | 1286 // that SetBounsdNodes/AddNode and the like don't result in messages to the |
1232 // originating connection. | 1287 // originating connection. |
1233 | 1288 |
1234 } // namespace service | 1289 } // namespace service |
1235 } // namespace view_manager | 1290 } // namespace view_manager |
1236 } // namespace mojo | 1291 } // namespace mojo |
OLD | NEW |