OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/callback.h" | 6 #include "base/callback.h" |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "mojo/public/cpp/bindings/binding_set.h" | 10 #include "mojo/public/cpp/bindings/binding_set.h" |
11 #include "mojo/public/cpp/bindings/interface_request.h" | 11 #include "mojo/public/cpp/bindings/interface_request.h" |
12 #include "mojo/public/cpp/bindings/tests/rect_blink.h" | 12 #include "mojo/public/cpp/bindings/tests/rect_blink.h" |
13 #include "mojo/public/cpp/bindings/tests/rect_chromium.h" | 13 #include "mojo/public/cpp/bindings/tests/rect_chromium.h" |
14 #include "mojo/public/cpp/bindings/tests/struct_with_traits_impl.h" | 14 #include "mojo/public/cpp/bindings/tests/struct_with_traits_impl.h" |
15 #include "mojo/public/cpp/bindings/tests/variant_test_util.h" | 15 #include "mojo/public/cpp/bindings/tests/variant_test_util.h" |
16 #include "mojo/public/interfaces/bindings/tests/struct_with_traits.mojom.h" | 16 #include "mojo/public/interfaces/bindings/tests/struct_with_traits.mojom.h" |
17 #include "mojo/public/interfaces/bindings/tests/test_native_types.mojom-wtf.h" | 17 #include "mojo/public/interfaces/bindings/tests/test_native_types.mojom-blink.h" |
18 #include "mojo/public/interfaces/bindings/tests/test_native_types.mojom.h" | 18 #include "mojo/public/interfaces/bindings/tests/test_native_types.mojom.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 namespace mojo { | 21 namespace mojo { |
22 namespace test { | 22 namespace test { |
23 namespace { | 23 namespace { |
24 | 24 |
25 template <typename T> | 25 template <typename T> |
26 void DoExpectResult(const T& expected, | 26 void DoExpectResult(const T& expected, |
27 const base::Closure& callback, | 27 const base::Closure& callback, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 void GetLargestRect(const GetLargestRectCallback& callback) override { | 68 void GetLargestRect(const GetLargestRectCallback& callback) override { |
69 callback.Run(largest_rect_); | 69 callback.Run(largest_rect_); |
70 } | 70 } |
71 | 71 |
72 private: | 72 private: |
73 RectChromium largest_rect_; | 73 RectChromium largest_rect_; |
74 }; | 74 }; |
75 | 75 |
76 // This implements the generated Blink variant of RectService. | 76 // This implements the generated Blink variant of RectService. |
77 class BlinkRectServiceImpl : public wtf::RectService { | 77 class BlinkRectServiceImpl : public blink::RectService { |
78 public: | 78 public: |
79 BlinkRectServiceImpl() {} | 79 BlinkRectServiceImpl() {} |
80 | 80 |
81 // mojo::test::wtf::RectService: | 81 // mojo::test::blink::RectService: |
82 void AddRect(const RectBlink& r) override { | 82 void AddRect(const RectBlink& r) override { |
83 if (r.computeArea() > largest_rect_.computeArea()) { | 83 if (r.computeArea() > largest_rect_.computeArea()) { |
84 largest_rect_.setX(r.x()); | 84 largest_rect_.setX(r.x()); |
85 largest_rect_.setY(r.y()); | 85 largest_rect_.setY(r.y()); |
86 largest_rect_.setWidth(r.width()); | 86 largest_rect_.setWidth(r.width()); |
87 largest_rect_.setHeight(r.height()); | 87 largest_rect_.setHeight(r.height()); |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
91 void GetLargestRect(const GetLargestRectCallback& callback) override { | 91 void GetLargestRect(const GetLargestRectCallback& callback) override { |
92 callback.Run(largest_rect_); | 92 callback.Run(largest_rect_); |
93 } | 93 } |
94 | 94 |
95 private: | 95 private: |
96 RectBlink largest_rect_; | 96 RectBlink largest_rect_; |
97 }; | 97 }; |
98 | 98 |
99 // A test which runs both Chromium and Blink implementations of a RectService. | 99 // A test which runs both Chromium and Blink implementations of a RectService. |
100 class StructTraitsTest : public testing::Test, | 100 class StructTraitsTest : public testing::Test, |
101 public TraitsTestService { | 101 public TraitsTestService { |
102 public: | 102 public: |
103 StructTraitsTest() {} | 103 StructTraitsTest() {} |
104 | 104 |
105 protected: | 105 protected: |
106 void BindToChromiumService(RectServiceRequest request) { | 106 void BindToChromiumService(RectServiceRequest request) { |
107 chromium_bindings_.AddBinding(&chromium_service_, std::move(request)); | 107 chromium_bindings_.AddBinding(&chromium_service_, std::move(request)); |
108 } | 108 } |
109 void BindToChromiumService(wtf::RectServiceRequest request) { | 109 void BindToChromiumService(blink::RectServiceRequest request) { |
110 chromium_bindings_.AddBinding( | 110 chromium_bindings_.AddBinding( |
111 &chromium_service_, | 111 &chromium_service_, |
112 ConvertInterfaceRequest<RectService>(std::move(request))); | 112 ConvertInterfaceRequest<RectService>(std::move(request))); |
113 } | 113 } |
114 | 114 |
115 void BindToBlinkService(wtf::RectServiceRequest request) { | 115 void BindToBlinkService(blink::RectServiceRequest request) { |
116 blink_bindings_.AddBinding(&blink_service_, std::move(request)); | 116 blink_bindings_.AddBinding(&blink_service_, std::move(request)); |
117 } | 117 } |
118 void BindToBlinkService(RectServiceRequest request) { | 118 void BindToBlinkService(RectServiceRequest request) { |
119 blink_bindings_.AddBinding( | 119 blink_bindings_.AddBinding( |
120 &blink_service_, | 120 &blink_service_, |
121 ConvertInterfaceRequest<wtf::RectService>(std::move(request))); | 121 ConvertInterfaceRequest<blink::RectService>(std::move(request))); |
122 } | 122 } |
123 | 123 |
124 TraitsTestServicePtr GetTraitsTestProxy() { | 124 TraitsTestServicePtr GetTraitsTestProxy() { |
125 return traits_test_bindings_.CreateInterfacePtrAndBind(this); | 125 return traits_test_bindings_.CreateInterfacePtrAndBind(this); |
126 } | 126 } |
127 | 127 |
128 private: | 128 private: |
129 // TraitsTestService: | 129 // TraitsTestService: |
130 void PassStructWithTraits( | 130 void PassStructWithTraits( |
131 const StructWithTraitsImpl& s, | 131 const StructWithTraitsImpl& s, |
132 const PassStructWithTraitsCallback& callback) override { | 132 const PassStructWithTraitsCallback& callback) override { |
133 callback.Run(s); | 133 callback.Run(s); |
134 } | 134 } |
135 | 135 |
136 base::MessageLoop loop_; | 136 base::MessageLoop loop_; |
137 | 137 |
138 ChromiumRectServiceImpl chromium_service_; | 138 ChromiumRectServiceImpl chromium_service_; |
139 BindingSet<RectService> chromium_bindings_; | 139 BindingSet<RectService> chromium_bindings_; |
140 | 140 |
141 BlinkRectServiceImpl blink_service_; | 141 BlinkRectServiceImpl blink_service_; |
142 BindingSet<wtf::RectService> blink_bindings_; | 142 BindingSet<blink::RectService> blink_bindings_; |
143 | 143 |
144 BindingSet<TraitsTestService> traits_test_bindings_; | 144 BindingSet<TraitsTestService> traits_test_bindings_; |
145 }; | 145 }; |
146 | 146 |
147 } // namespace | 147 } // namespace |
148 | 148 |
149 TEST_F(StructTraitsTest, ChromiumProxyToChromiumService) { | 149 TEST_F(StructTraitsTest, ChromiumProxyToChromiumService) { |
150 RectServicePtr chromium_proxy; | 150 RectServicePtr chromium_proxy; |
151 BindToChromiumService(GetProxy(&chromium_proxy)); | 151 BindToChromiumService(GetProxy(&chromium_proxy)); |
152 { | 152 { |
(...skipping 23 matching lines...) Expand all Loading... |
176 base::RunLoop loop; | 176 base::RunLoop loop; |
177 ExpectError(&chromium_proxy, loop.QuitClosure()); | 177 ExpectError(&chromium_proxy, loop.QuitClosure()); |
178 chromium_proxy->AddRect(RectChromium(-1, -1, 2, 2)); | 178 chromium_proxy->AddRect(RectChromium(-1, -1, 2, 2)); |
179 chromium_proxy->GetLargestRect( | 179 chromium_proxy->GetLargestRect( |
180 Fail<RectChromium>("The pipe should have been closed.")); | 180 Fail<RectChromium>("The pipe should have been closed.")); |
181 loop.Run(); | 181 loop.Run(); |
182 } | 182 } |
183 } | 183 } |
184 | 184 |
185 TEST_F(StructTraitsTest, BlinkProxyToBlinkService) { | 185 TEST_F(StructTraitsTest, BlinkProxyToBlinkService) { |
186 wtf::RectServicePtr blink_proxy; | 186 blink::RectServicePtr blink_proxy; |
187 BindToBlinkService(GetProxy(&blink_proxy)); | 187 BindToBlinkService(GetProxy(&blink_proxy)); |
188 { | 188 { |
189 base::RunLoop loop; | 189 base::RunLoop loop; |
190 blink_proxy->AddRect(RectBlink(1, 1, 4, 5)); | 190 blink_proxy->AddRect(RectBlink(1, 1, 4, 5)); |
191 blink_proxy->AddRect(RectBlink(10, 10, 20, 20)); | 191 blink_proxy->AddRect(RectBlink(10, 10, 20, 20)); |
192 blink_proxy->GetLargestRect( | 192 blink_proxy->GetLargestRect( |
193 ExpectResult(RectBlink(10, 10, 20, 20), loop.QuitClosure())); | 193 ExpectResult(RectBlink(10, 10, 20, 20), loop.QuitClosure())); |
194 loop.Run(); | 194 loop.Run(); |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
198 TEST_F(StructTraitsTest, BlinkProxyToChromiumService) { | 198 TEST_F(StructTraitsTest, BlinkProxyToChromiumService) { |
199 wtf::RectServicePtr blink_proxy; | 199 blink::RectServicePtr blink_proxy; |
200 BindToChromiumService(GetProxy(&blink_proxy)); | 200 BindToChromiumService(GetProxy(&blink_proxy)); |
201 { | 201 { |
202 base::RunLoop loop; | 202 base::RunLoop loop; |
203 blink_proxy->AddRect(RectBlink(1, 1, 4, 5)); | 203 blink_proxy->AddRect(RectBlink(1, 1, 4, 5)); |
204 blink_proxy->AddRect(RectBlink(10, 10, 2, 2)); | 204 blink_proxy->AddRect(RectBlink(10, 10, 2, 2)); |
205 blink_proxy->GetLargestRect( | 205 blink_proxy->GetLargestRect( |
206 ExpectResult(RectBlink(1, 1, 4, 5), loop.QuitClosure())); | 206 ExpectResult(RectBlink(1, 1, 4, 5), loop.QuitClosure())); |
207 loop.Run(); | 207 loop.Run(); |
208 } | 208 } |
209 } | 209 } |
(...skipping 14 matching lines...) Expand all Loading... |
224 EXPECT_EQ(input.get_uint32(), passed.get_uint32()); | 224 EXPECT_EQ(input.get_uint32(), passed.get_uint32()); |
225 EXPECT_EQ(input.get_uint64(), passed.get_uint64()); | 225 EXPECT_EQ(input.get_uint64(), passed.get_uint64()); |
226 EXPECT_EQ(input.get_string(), passed.get_string()); | 226 EXPECT_EQ(input.get_string(), passed.get_string()); |
227 loop.Quit(); | 227 loop.Quit(); |
228 }); | 228 }); |
229 loop.Run(); | 229 loop.Run(); |
230 } | 230 } |
231 | 231 |
232 } // namespace test | 232 } // namespace test |
233 } // namespace mojo | 233 } // namespace mojo |
OLD | NEW |