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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "mojo/public/cpp/application/application_delegate.h" | 8 #include "mojo/public/cpp/application/application_delegate.h" |
9 #include "mojo/public/cpp/application/application_impl.h" | 9 #include "mojo/public/cpp/application/application_impl.h" |
10 #include "mojo/public/cpp/application/application_test_base.h" | 10 #include "mojo/public/cpp/application/application_test_base.h" |
11 #include "mojo/services/view_manager/public/interfaces/view_manager.mojom.h" | 11 #include "mojo/services/view_manager/public/interfaces/view_manager.mojom.h" |
12 #include "mojo/services/window_manager/public/interfaces/window_manager.mojom.h" | 12 #include "mojo/services/window_manager/public/interfaces/window_manager.mojom.h" |
13 #include "mojo/services/window_manager/public/interfaces/window_manager_internal
.mojom.h" | 13 #include "mojo/services/window_manager/public/interfaces/window_manager_internal
.mojom.h" |
14 #include "services/view_manager/ids.h" | 14 #include "services/view_manager/ids.h" |
15 #include "services/view_manager/test_change_tracker.h" | 15 #include "services/view_manager/test_change_tracker.h" |
16 | 16 |
17 using mojo::ApplicationConnection; | 17 using mojo::ApplicationConnection; |
18 using mojo::ApplicationDelegate; | 18 using mojo::ApplicationDelegate; |
19 using mojo::Array; | 19 using mojo::Array; |
20 using mojo::Callback; | 20 using mojo::Callback; |
21 using mojo::ConnectionSpecificId; | 21 using mojo::ConnectionSpecificId; |
22 using mojo::ERROR_CODE_NONE; | |
23 using mojo::ErrorCode; | 22 using mojo::ErrorCode; |
24 using mojo::EventPtr; | 23 using mojo::EventPtr; |
25 using mojo::Id; | 24 using mojo::Id; |
26 using mojo::InterfaceRequest; | 25 using mojo::InterfaceRequest; |
27 using mojo::ORDER_DIRECTION_ABOVE; | |
28 using mojo::ORDER_DIRECTION_BELOW; | |
29 using mojo::OrderDirection; | 26 using mojo::OrderDirection; |
30 using mojo::RectPtr; | 27 using mojo::RectPtr; |
31 using mojo::ServiceProvider; | 28 using mojo::ServiceProvider; |
32 using mojo::ServiceProviderPtr; | 29 using mojo::ServiceProviderPtr; |
33 using mojo::String; | 30 using mojo::String; |
34 using mojo::ViewDataPtr; | 31 using mojo::ViewDataPtr; |
35 using mojo::ViewManagerClient; | 32 using mojo::ViewManagerClient; |
36 using mojo::ViewManagerService; | 33 using mojo::ViewManagerService; |
37 using mojo::ViewportMetricsPtr; | 34 using mojo::ViewportMetricsPtr; |
38 | 35 |
(...skipping 26 matching lines...) Expand all Loading... |
65 Array<ViewDataPtr> results) { | 62 Array<ViewDataPtr> results) { |
66 ViewDatasToTestViews(results, views); | 63 ViewDatasToTestViews(results, views); |
67 run_loop->Quit(); | 64 run_loop->Quit(); |
68 } | 65 } |
69 | 66 |
70 // ----------------------------------------------------------------------------- | 67 // ----------------------------------------------------------------------------- |
71 | 68 |
72 // The following functions call through to the supplied ViewManagerService. They | 69 // The following functions call through to the supplied ViewManagerService. They |
73 // block until call completes and return the result. | 70 // block until call completes and return the result. |
74 bool CreateView(ViewManagerService* vm, Id view_id) { | 71 bool CreateView(ViewManagerService* vm, Id view_id) { |
75 ErrorCode result = ERROR_CODE_NONE; | 72 ErrorCode result = ErrorCode::NONE; |
76 base::RunLoop run_loop; | 73 base::RunLoop run_loop; |
77 vm->CreateView(view_id, | 74 vm->CreateView(view_id, |
78 base::Bind(&ErrorCodeResultCallback, &run_loop, &result)); | 75 base::Bind(&ErrorCodeResultCallback, &run_loop, &result)); |
79 run_loop.Run(); | 76 run_loop.Run(); |
80 return result == ERROR_CODE_NONE; | 77 return result == ErrorCode::NONE; |
81 } | 78 } |
82 | 79 |
83 bool EmbedUrl(ViewManagerService* vm, const String& url, Id root_id) { | 80 bool EmbedUrl(ViewManagerService* vm, const String& url, Id root_id) { |
84 bool result = false; | 81 bool result = false; |
85 base::RunLoop run_loop; | 82 base::RunLoop run_loop; |
86 { | 83 { |
87 vm->EmbedUrl(url, root_id, nullptr, nullptr, | 84 vm->EmbedUrl(url, root_id, nullptr, nullptr, |
88 base::Bind(&BoolResultCallback, &run_loop, &result)); | 85 base::Bind(&BoolResultCallback, &run_loop, &result)); |
89 } | 86 } |
90 run_loop.Run(); | 87 run_loop.Run(); |
91 return result; | 88 return result; |
92 } | 89 } |
93 | 90 |
94 bool Embed(ViewManagerService* vm, | 91 bool Embed(ViewManagerService* vm, |
95 Id root_id, | 92 Id root_id, |
96 mojo::ViewManagerClientPtr client) { | 93 mojo::ViewManagerClientPtr client) { |
97 bool result = false; | 94 bool result = false; |
98 base::RunLoop run_loop; | 95 base::RunLoop run_loop; |
99 { | 96 { |
100 vm->Embed(root_id, client.Pass(), | 97 vm->Embed(root_id, client.Pass(), |
101 base::Bind(&BoolResultCallback, &run_loop, &result)); | 98 base::Bind(&BoolResultCallback, &run_loop, &result)); |
102 } | 99 } |
103 run_loop.Run(); | 100 run_loop.Run(); |
104 return result; | 101 return result; |
105 } | 102 } |
106 | 103 |
107 ErrorCode CreateViewWithErrorCode(ViewManagerService* vm, Id view_id) { | 104 ErrorCode CreateViewWithErrorCode(ViewManagerService* vm, Id view_id) { |
108 ErrorCode result = ERROR_CODE_NONE; | 105 ErrorCode result = ErrorCode::NONE; |
109 base::RunLoop run_loop; | 106 base::RunLoop run_loop; |
110 vm->CreateView(view_id, | 107 vm->CreateView(view_id, |
111 base::Bind(&ErrorCodeResultCallback, &run_loop, &result)); | 108 base::Bind(&ErrorCodeResultCallback, &run_loop, &result)); |
112 run_loop.Run(); | 109 run_loop.Run(); |
113 return result; | 110 return result; |
114 } | 111 } |
115 | 112 |
116 bool AddView(ViewManagerService* vm, Id parent, Id child) { | 113 bool AddView(ViewManagerService* vm, Id parent, Id child) { |
117 bool result = false; | 114 bool result = false; |
118 base::RunLoop run_loop; | 115 base::RunLoop run_loop; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 run_loop.Run(); | 199 run_loop.Run(); |
203 return result; | 200 return result; |
204 } | 201 } |
205 | 202 |
206 // Utility functions ----------------------------------------------------------- | 203 // Utility functions ----------------------------------------------------------- |
207 | 204 |
208 // Waits for all messages to be received by |vm|. This is done by attempting to | 205 // Waits for all messages to be received by |vm|. This is done by attempting to |
209 // create a bogus view. When we get the response we know all messages have been | 206 // create a bogus view. When we get the response we know all messages have been |
210 // processed. | 207 // processed. |
211 bool WaitForAllMessages(ViewManagerService* vm) { | 208 bool WaitForAllMessages(ViewManagerService* vm) { |
212 ErrorCode result = ERROR_CODE_NONE; | 209 ErrorCode result = ErrorCode::NONE; |
213 base::RunLoop run_loop; | 210 base::RunLoop run_loop; |
214 vm->CreateView(ViewIdToTransportId(InvalidViewId()), | 211 vm->CreateView(ViewIdToTransportId(InvalidViewId()), |
215 base::Bind(&ErrorCodeResultCallback, &run_loop, &result)); | 212 base::Bind(&ErrorCodeResultCallback, &run_loop, &result)); |
216 run_loop.Run(); | 213 run_loop.Run(); |
217 return result != ERROR_CODE_NONE; | 214 return result != ErrorCode::NONE; |
218 } | 215 } |
219 | 216 |
220 bool HasClonedView(const std::vector<TestView>& views) { | 217 bool HasClonedView(const std::vector<TestView>& views) { |
221 for (size_t i = 0; i < views.size(); ++i) | 218 for (size_t i = 0; i < views.size(); ++i) |
222 if (views[i].view_id == ViewIdToTransportId(ClonedViewId())) | 219 if (views[i].view_id == ViewIdToTransportId(ClonedViewId())) |
223 return true; | 220 return true; |
224 return false; | 221 return false; |
225 } | 222 } |
226 | 223 |
227 // ----------------------------------------------------------------------------- | 224 // ----------------------------------------------------------------------------- |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 // Connection 2 shouldn't be able to remove view 3. | 650 // Connection 2 shouldn't be able to remove view 3. |
654 ASSERT_FALSE(RemoveViewFromParent(vm2(), BuildViewId(3, 3))); | 651 ASSERT_FALSE(RemoveViewFromParent(vm2(), BuildViewId(3, 3))); |
655 } | 652 } |
656 | 653 |
657 // Verifies client gets a valid id. | 654 // Verifies client gets a valid id. |
658 TEST_F(ViewManagerServiceAppTest, CreateView) { | 655 TEST_F(ViewManagerServiceAppTest, CreateView) { |
659 ASSERT_TRUE(CreateView(vm1(), BuildViewId(1, 1))); | 656 ASSERT_TRUE(CreateView(vm1(), BuildViewId(1, 1))); |
660 EXPECT_TRUE(changes1()->empty()); | 657 EXPECT_TRUE(changes1()->empty()); |
661 | 658 |
662 // Can't create a view with the same id. | 659 // Can't create a view with the same id. |
663 ASSERT_EQ(mojo::ERROR_CODE_VALUE_IN_USE, | 660 ASSERT_EQ(mojo::ErrorCode::VALUE_IN_USE, |
664 CreateViewWithErrorCode(vm1(), BuildViewId(1, 1))); | 661 CreateViewWithErrorCode(vm1(), BuildViewId(1, 1))); |
665 EXPECT_TRUE(changes1()->empty()); | 662 EXPECT_TRUE(changes1()->empty()); |
666 | 663 |
667 // Can't create a view with a bogus connection id. | 664 // Can't create a view with a bogus connection id. |
668 EXPECT_EQ(mojo::ERROR_CODE_ILLEGAL_ARGUMENT, | 665 EXPECT_EQ(mojo::ErrorCode::ILLEGAL_ARGUMENT, |
669 CreateViewWithErrorCode(vm1(), BuildViewId(2, 1))); | 666 CreateViewWithErrorCode(vm1(), BuildViewId(2, 1))); |
670 EXPECT_TRUE(changes1()->empty()); | 667 EXPECT_TRUE(changes1()->empty()); |
671 } | 668 } |
672 | 669 |
673 // Verifies AddView fails when view is already in position. | 670 // Verifies AddView fails when view is already in position. |
674 TEST_F(ViewManagerServiceAppTest, AddViewWithNoChange) { | 671 TEST_F(ViewManagerServiceAppTest, AddViewWithNoChange) { |
675 ASSERT_TRUE(CreateView(vm1(), BuildViewId(1, 2))); | 672 ASSERT_TRUE(CreateView(vm1(), BuildViewId(1, 2))); |
676 ASSERT_TRUE(CreateView(vm1(), BuildViewId(1, 3))); | 673 ASSERT_TRUE(CreateView(vm1(), BuildViewId(1, 3))); |
677 | 674 |
678 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 675 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 ASSERT_TRUE(CreateView(vm2(), view8_id)); | 840 ASSERT_TRUE(CreateView(vm2(), view8_id)); |
844 ASSERT_TRUE(AddView(vm2(), view1_id, view2_id)); | 841 ASSERT_TRUE(AddView(vm2(), view1_id, view2_id)); |
845 ASSERT_TRUE(AddView(vm2(), view2_id, view6_id)); | 842 ASSERT_TRUE(AddView(vm2(), view2_id, view6_id)); |
846 ASSERT_TRUE(AddView(vm2(), view1_id, view3_id)); | 843 ASSERT_TRUE(AddView(vm2(), view1_id, view3_id)); |
847 ASSERT_TRUE(AddView(vm1(), ViewIdToTransportId(RootViewId()), view4_id)); | 844 ASSERT_TRUE(AddView(vm1(), ViewIdToTransportId(RootViewId()), view4_id)); |
848 ASSERT_TRUE(AddView(vm1(), ViewIdToTransportId(RootViewId()), view5_id)); | 845 ASSERT_TRUE(AddView(vm1(), ViewIdToTransportId(RootViewId()), view5_id)); |
849 ASSERT_TRUE(AddView(vm1(), ViewIdToTransportId(RootViewId()), view1_id)); | 846 ASSERT_TRUE(AddView(vm1(), ViewIdToTransportId(RootViewId()), view1_id)); |
850 | 847 |
851 { | 848 { |
852 changes1()->clear(); | 849 changes1()->clear(); |
853 ASSERT_TRUE(ReorderView(vm2(), view2_id, view3_id, ORDER_DIRECTION_ABOVE)); | 850 ASSERT_TRUE(ReorderView(vm2(), view2_id, view3_id, OrderDirection::ABOVE)); |
854 | 851 |
855 vm_client1_.WaitForChangeCount(1); | 852 vm_client1_.WaitForChangeCount(1); |
856 EXPECT_EQ("Reordered view=2,2 relative=2,3 direction=above", | 853 EXPECT_EQ("Reordered view=2,2 relative=2,3 direction=above", |
857 SingleChangeToDescription(*changes1())); | 854 SingleChangeToDescription(*changes1())); |
858 } | 855 } |
859 | 856 |
860 { | 857 { |
861 changes1()->clear(); | 858 changes1()->clear(); |
862 ASSERT_TRUE(ReorderView(vm2(), view2_id, view3_id, ORDER_DIRECTION_BELOW)); | 859 ASSERT_TRUE(ReorderView(vm2(), view2_id, view3_id, OrderDirection::BELOW)); |
863 | 860 |
864 vm_client1_.WaitForChangeCount(1); | 861 vm_client1_.WaitForChangeCount(1); |
865 EXPECT_EQ("Reordered view=2,2 relative=2,3 direction=below", | 862 EXPECT_EQ("Reordered view=2,2 relative=2,3 direction=below", |
866 SingleChangeToDescription(*changes1())); | 863 SingleChangeToDescription(*changes1())); |
867 } | 864 } |
868 | 865 |
869 // view2 is already below view3. | 866 // view2 is already below view3. |
870 EXPECT_FALSE(ReorderView(vm2(), view2_id, view3_id, ORDER_DIRECTION_BELOW)); | 867 EXPECT_FALSE(ReorderView(vm2(), view2_id, view3_id, OrderDirection::BELOW)); |
871 | 868 |
872 // view4 & 5 are unknown to connection2_. | 869 // view4 & 5 are unknown to connection2_. |
873 EXPECT_FALSE(ReorderView(vm2(), view4_id, view5_id, ORDER_DIRECTION_ABOVE)); | 870 EXPECT_FALSE(ReorderView(vm2(), view4_id, view5_id, OrderDirection::ABOVE)); |
874 | 871 |
875 // view6 & view3 have different parents. | 872 // view6 & view3 have different parents. |
876 EXPECT_FALSE(ReorderView(vm1(), view3_id, view6_id, ORDER_DIRECTION_ABOVE)); | 873 EXPECT_FALSE(ReorderView(vm1(), view3_id, view6_id, OrderDirection::ABOVE)); |
877 | 874 |
878 // Non-existent view-ids | 875 // Non-existent view-ids |
879 EXPECT_FALSE(ReorderView(vm1(), BuildViewId(1, 27), BuildViewId(1, 28), | 876 EXPECT_FALSE(ReorderView(vm1(), BuildViewId(1, 27), BuildViewId(1, 28), |
880 ORDER_DIRECTION_ABOVE)); | 877 OrderDirection::ABOVE)); |
881 | 878 |
882 // view7 & view8 are un-parented. | 879 // view7 & view8 are un-parented. |
883 EXPECT_FALSE(ReorderView(vm1(), view7_id, view8_id, ORDER_DIRECTION_ABOVE)); | 880 EXPECT_FALSE(ReorderView(vm1(), view7_id, view8_id, OrderDirection::ABOVE)); |
884 } | 881 } |
885 | 882 |
886 // Verifies DeleteView works. | 883 // Verifies DeleteView works. |
887 TEST_F(ViewManagerServiceAppTest, DeleteView) { | 884 TEST_F(ViewManagerServiceAppTest, DeleteView) { |
888 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 885 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
889 ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 2))); | 886 ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 2))); |
890 | 887 |
891 // Make 2 a child of 1. | 888 // Make 2 a child of 1. |
892 { | 889 { |
893 changes1()->clear(); | 890 changes1()->clear(); |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1490 // TODO(sky): need to better track changes to initial connection. For example, | 1487 // TODO(sky): need to better track changes to initial connection. For example, |
1491 // that SetBounsdViews/AddView and the like don't result in messages to the | 1488 // that SetBounsdViews/AddView and the like don't result in messages to the |
1492 // originating connection. | 1489 // originating connection. |
1493 | 1490 |
1494 // TODO(sky): make sure coverage of what was | 1491 // TODO(sky): make sure coverage of what was |
1495 // ViewManagerTest.SecondEmbedRoot_InitService and | 1492 // ViewManagerTest.SecondEmbedRoot_InitService and |
1496 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager | 1493 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager |
1497 // tests. | 1494 // tests. |
1498 | 1495 |
1499 } // namespace view_manager | 1496 } // namespace view_manager |
OLD | NEW |