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" |
11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "mojo/common/common_type_converters.h" | 15 #include "mojo/common/common_type_converters.h" |
16 #include "mojo/public/cpp/application/application.h" | 16 #include "mojo/public/cpp/application/application.h" |
17 #include "mojo/public/cpp/application/connect.h" | 17 #include "mojo/public/cpp/application/connect.h" |
18 #include "mojo/public/cpp/bindings/lib/router.h" | 18 #include "mojo/public/cpp/bindings/lib/router.h" |
19 #include "mojo/public/cpp/environment/environment.h" | 19 #include "mojo/public/cpp/environment/environment.h" |
20 #include "mojo/service_manager/service_manager.h" | 20 #include "mojo/service_manager/service_manager.h" |
21 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 21 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
22 #include "mojo/services/public/cpp/view_manager/util.h" | 22 #include "mojo/services/public/cpp/view_manager/util.h" |
23 #include "mojo/services/public/cpp/view_manager/view_manager_types.h" | 23 #include "mojo/services/public/cpp/view_manager/view_manager_types.h" |
24 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" | 24 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" |
| 25 #include "mojo/services/view_manager/ids.h" |
25 #include "mojo/services/view_manager/test_change_tracker.h" | 26 #include "mojo/services/view_manager/test_change_tracker.h" |
26 #include "mojo/shell/shell_test_helper.h" | 27 #include "mojo/shell/shell_test_helper.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
28 #include "ui/gfx/geometry/rect.h" | 29 #include "ui/gfx/geometry/rect.h" |
29 | 30 |
30 namespace mojo { | 31 namespace mojo { |
31 namespace view_manager { | 32 namespace view_manager { |
32 namespace service { | 33 namespace service { |
33 | 34 |
34 namespace { | 35 namespace { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 } | 106 } |
106 bool RemoveNodeFromParent(Id node_id, Id server_change_id) { | 107 bool RemoveNodeFromParent(Id node_id, Id server_change_id) { |
107 changes_.clear(); | 108 changes_.clear(); |
108 bool result = false; | 109 bool result = false; |
109 view_manager_->RemoveNodeFromParent(node_id, server_change_id, | 110 view_manager_->RemoveNodeFromParent(node_id, server_change_id, |
110 base::Bind(&ViewManagerProxy::GotResult, | 111 base::Bind(&ViewManagerProxy::GotResult, |
111 base::Unretained(this), &result)); | 112 base::Unretained(this), &result)); |
112 RunMainLoop(); | 113 RunMainLoop(); |
113 return result; | 114 return result; |
114 } | 115 } |
| 116 bool ReorderNode(Id node_id, |
| 117 Id relative_node_id, |
| 118 OrderDirection direction, |
| 119 Id server_change_id) { |
| 120 changes_.clear(); |
| 121 bool result = false; |
| 122 view_manager_->ReorderNode(node_id, relative_node_id, direction, |
| 123 server_change_id, |
| 124 base::Bind(&ViewManagerProxy::GotResult, |
| 125 base::Unretained(this), &result)); |
| 126 RunMainLoop(); |
| 127 return result; |
| 128 } |
115 bool SetView(Id node_id, Id view_id) { | 129 bool SetView(Id node_id, Id view_id) { |
116 changes_.clear(); | 130 changes_.clear(); |
117 bool result = false; | 131 bool result = false; |
118 view_manager_->SetView(node_id, view_id, | 132 view_manager_->SetView(node_id, view_id, |
119 base::Bind(&ViewManagerProxy::GotResult, | 133 base::Bind(&ViewManagerProxy::GotResult, |
120 base::Unretained(this), &result)); | 134 base::Unretained(this), &result)); |
121 RunMainLoop(); | 135 RunMainLoop(); |
122 return result; | 136 return result; |
123 } | 137 } |
124 bool CreateView(Id view_id) { | 138 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()); | 312 tracker_.OnNodeBoundsChanged(node_id, old_bounds.Pass(), new_bounds.Pass()); |
299 } | 313 } |
300 virtual void OnNodeHierarchyChanged(Id node, | 314 virtual void OnNodeHierarchyChanged(Id node, |
301 Id new_parent, | 315 Id new_parent, |
302 Id old_parent, | 316 Id old_parent, |
303 Id server_change_id, | 317 Id server_change_id, |
304 Array<INodePtr> nodes) OVERRIDE { | 318 Array<INodePtr> nodes) OVERRIDE { |
305 tracker_.OnNodeHierarchyChanged(node, new_parent, old_parent, | 319 tracker_.OnNodeHierarchyChanged(node, new_parent, old_parent, |
306 server_change_id, nodes.Pass()); | 320 server_change_id, nodes.Pass()); |
307 } | 321 } |
| 322 virtual void OnNodeReordered(Id node_id, |
| 323 Id relative_node_id, |
| 324 OrderDirection direction, |
| 325 Id server_change_id) OVERRIDE { |
| 326 tracker_.OnNodeReordered(node_id, relative_node_id, direction, |
| 327 server_change_id); |
| 328 } |
308 virtual void OnNodeDeleted(Id node, Id server_change_id) OVERRIDE { | 329 virtual void OnNodeDeleted(Id node, Id server_change_id) OVERRIDE { |
309 tracker_.OnNodeDeleted(node, server_change_id); | 330 tracker_.OnNodeDeleted(node, server_change_id); |
310 } | 331 } |
311 virtual void OnViewDeleted(Id view) OVERRIDE { | 332 virtual void OnViewDeleted(Id view) OVERRIDE { |
312 tracker_.OnViewDeleted(view); | 333 tracker_.OnViewDeleted(view); |
313 } | 334 } |
314 virtual void OnNodeViewReplaced(Id node, | 335 virtual void OnNodeViewReplaced(Id node, |
315 Id new_view_id, | 336 Id new_view_id, |
316 Id old_view_id) OVERRIDE { | 337 Id old_view_id) OVERRIDE { |
317 tracker_.OnNodeViewReplaced(node, new_view_id, old_view_id); | 338 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()); | 772 ASSERT_EQ(1u, changes.size()); |
752 EXPECT_EQ( | 773 EXPECT_EQ( |
753 "HierarchyChanged change_id=5 node=1,2 new_parent=1,1 old_parent=null", | 774 "HierarchyChanged change_id=5 node=1,2 new_parent=1,1 old_parent=null", |
754 changes[0]); | 775 changes[0]); |
755 EXPECT_EQ("[node=1,2 parent=1,1 view=null]," | 776 EXPECT_EQ("[node=1,2 parent=1,1 view=null]," |
756 "[node=1,21 parent=1,2 view=null]", | 777 "[node=1,21 parent=1,2 view=null]", |
757 ChangeNodeDescription(connection2_->changes())); | 778 ChangeNodeDescription(connection2_->changes())); |
758 } | 779 } |
759 } | 780 } |
760 | 781 |
| 782 TEST_F(ViewManagerConnectionTest, ReorderNode) { |
| 783 Id node1_id = BuildNodeId(1, 1); |
| 784 Id node2_id = BuildNodeId(1, 2); |
| 785 Id node3_id = BuildNodeId(1, 3); |
| 786 Id node4_id = BuildNodeId(1, 4); // Peer to 1,1 |
| 787 Id node5_id = BuildNodeId(1, 5); // Peer to 1,1 |
| 788 Id node6_id = BuildNodeId(1, 6); // Child of 1,2. |
| 789 Id node7_id = BuildNodeId(1, 7); // Unparented. |
| 790 Id node8_id = BuildNodeId(1, 8); // Unparented. |
| 791 ASSERT_TRUE(connection_->CreateNode(node1_id)); |
| 792 ASSERT_TRUE(connection_->CreateNode(node2_id)); |
| 793 ASSERT_TRUE(connection_->CreateNode(node3_id)); |
| 794 ASSERT_TRUE(connection_->CreateNode(node4_id)); |
| 795 ASSERT_TRUE(connection_->CreateNode(node5_id)); |
| 796 ASSERT_TRUE(connection_->CreateNode(node6_id)); |
| 797 ASSERT_TRUE(connection_->CreateNode(node7_id)); |
| 798 ASSERT_TRUE(connection_->CreateNode(node8_id)); |
| 799 ASSERT_TRUE(connection_->AddNode(node1_id, node2_id, 1)); |
| 800 ASSERT_TRUE(connection_->AddNode(node2_id, node6_id, 2)); |
| 801 ASSERT_TRUE(connection_->AddNode(node1_id, node3_id, 3)); |
| 802 ASSERT_TRUE(connection_->AddNode( |
| 803 NodeIdToTransportId(RootNodeId()), node4_id, 4)); |
| 804 ASSERT_TRUE(connection_->AddNode( |
| 805 NodeIdToTransportId(RootNodeId()), node5_id, 5)); |
| 806 |
| 807 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 808 |
| 809 { |
| 810 connection_->ReorderNode(node2_id, node3_id, ORDER_ABOVE, 6); |
| 811 |
| 812 connection2_->DoRunLoopUntilChangesCount(1); |
| 813 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 814 ASSERT_EQ(1u, changes.size()); |
| 815 EXPECT_EQ( |
| 816 "Reordered change_id=6 node=1,2 relative=1,3 direction=above", |
| 817 changes[0]); |
| 818 } |
| 819 |
| 820 { |
| 821 connection_->ReorderNode(node2_id, node3_id, ORDER_BELOW, 7); |
| 822 |
| 823 connection2_->DoRunLoopUntilChangesCount(1); |
| 824 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 825 ASSERT_EQ(1u, changes.size()); |
| 826 EXPECT_EQ( |
| 827 "Reordered change_id=7 node=1,2 relative=1,3 direction=below", |
| 828 changes[0]); |
| 829 } |
| 830 |
| 831 { |
| 832 // node2 is already below node3. |
| 833 EXPECT_FALSE(connection_->ReorderNode(node2_id, node3_id, ORDER_BELOW, 8)); |
| 834 } |
| 835 |
| 836 { |
| 837 // node4 & 5 are unknown to connection2_. |
| 838 EXPECT_FALSE(connection2_->ReorderNode(node4_id, node5_id, ORDER_ABOVE, 8)); |
| 839 } |
| 840 |
| 841 { |
| 842 // node6 & node3 have different parents. |
| 843 EXPECT_FALSE(connection_->ReorderNode(node3_id, node6_id, ORDER_ABOVE, 8)); |
| 844 } |
| 845 |
| 846 { |
| 847 // Non-existent node-ids |
| 848 EXPECT_FALSE(connection_->ReorderNode(BuildNodeId(1, 27), |
| 849 BuildNodeId(1, 28), |
| 850 ORDER_ABOVE, |
| 851 8)); |
| 852 } |
| 853 |
| 854 { |
| 855 // node7 & node8 are un-parented. |
| 856 EXPECT_FALSE(connection_->ReorderNode(node7_id, node8_id, ORDER_ABOVE, 8)); |
| 857 } |
| 858 } |
| 859 |
761 // Verifies DeleteNode works. | 860 // Verifies DeleteNode works. |
762 TEST_F(ViewManagerConnectionTest, DeleteNode) { | 861 TEST_F(ViewManagerConnectionTest, DeleteNode) { |
763 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); | 862 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 2))); |
764 | 863 |
765 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 864 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
766 | 865 |
767 // Make 2 a child of 1. | 866 // Make 2 a child of 1. |
768 { | 867 { |
769 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 1)); | 868 ASSERT_TRUE(connection_->AddNode(BuildNodeId(1, 1), BuildNodeId(1, 2), 1)); |
770 connection2_->DoRunLoopUntilChangesCount(1); | 869 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 | 1326 // TODO(sky): add coverage of test that destroys connections and ensures other |
1228 // connections get deletion notification (or advanced server id). | 1327 // connections get deletion notification (or advanced server id). |
1229 | 1328 |
1230 // TODO(sky): need to better track changes to initial connection. For example, | 1329 // 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 | 1330 // that SetBounsdNodes/AddNode and the like don't result in messages to the |
1232 // originating connection. | 1331 // originating connection. |
1233 | 1332 |
1234 } // namespace service | 1333 } // namespace service |
1235 } // namespace view_manager | 1334 } // namespace view_manager |
1236 } // namespace mojo | 1335 } // namespace mojo |
OLD | NEW |