| 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" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 // mojo::test::RectService: | 63 // mojo::test::RectService: |
| 64 void AddRect(const RectChromium& r) override { | 64 void AddRect(const RectChromium& r) override { |
| 65 if (r.GetArea() > largest_rect_.GetArea()) | 65 if (r.GetArea() > largest_rect_.GetArea()) |
| 66 largest_rect_ = r; | 66 largest_rect_ = r; |
| 67 } | 67 } |
| 68 | 68 |
| 69 void GetLargestRect(const GetLargestRectCallback& callback) override { | 69 void GetLargestRect(const GetLargestRectCallback& callback) override { |
| 70 callback.Run(largest_rect_); | 70 callback.Run(largest_rect_); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void PassSharedRect(const SharedRect& r, |
| 74 const PassSharedRectCallback& callback) override { |
| 75 callback.Run(r); |
| 76 } |
| 77 |
| 73 private: | 78 private: |
| 74 RectChromium largest_rect_; | 79 RectChromium largest_rect_; |
| 75 }; | 80 }; |
| 76 | 81 |
| 77 // This implements the generated Blink variant of RectService. | 82 // This implements the generated Blink variant of RectService. |
| 78 class BlinkRectServiceImpl : public blink::RectService { | 83 class BlinkRectServiceImpl : public blink::RectService { |
| 79 public: | 84 public: |
| 80 BlinkRectServiceImpl() {} | 85 BlinkRectServiceImpl() {} |
| 81 | 86 |
| 82 // mojo::test::blink::RectService: | 87 // mojo::test::blink::RectService: |
| 83 void AddRect(const RectBlink& r) override { | 88 void AddRect(const RectBlink& r) override { |
| 84 if (r.computeArea() > largest_rect_.computeArea()) { | 89 if (r.computeArea() > largest_rect_.computeArea()) { |
| 85 largest_rect_.setX(r.x()); | 90 largest_rect_.setX(r.x()); |
| 86 largest_rect_.setY(r.y()); | 91 largest_rect_.setY(r.y()); |
| 87 largest_rect_.setWidth(r.width()); | 92 largest_rect_.setWidth(r.width()); |
| 88 largest_rect_.setHeight(r.height()); | 93 largest_rect_.setHeight(r.height()); |
| 89 } | 94 } |
| 90 } | 95 } |
| 91 | 96 |
| 92 void GetLargestRect(const GetLargestRectCallback& callback) override { | 97 void GetLargestRect(const GetLargestRectCallback& callback) override { |
| 93 callback.Run(largest_rect_); | 98 callback.Run(largest_rect_); |
| 94 } | 99 } |
| 95 | 100 |
| 101 void PassSharedRect(const SharedRect& r, |
| 102 const PassSharedRectCallback& callback) override { |
| 103 callback.Run(r); |
| 104 } |
| 105 |
| 96 private: | 106 private: |
| 97 RectBlink largest_rect_; | 107 RectBlink largest_rect_; |
| 98 }; | 108 }; |
| 99 | 109 |
| 100 // A test which runs both Chromium and Blink implementations of a RectService. | 110 // A test which runs both Chromium and Blink implementations of a RectService. |
| 101 class StructTraitsTest : public testing::Test, | 111 class StructTraitsTest : public testing::Test, |
| 102 public TraitsTestService { | 112 public TraitsTestService { |
| 103 public: | 113 public: |
| 104 StructTraitsTest() {} | 114 StructTraitsTest() {} |
| 105 | 115 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 RectServicePtr chromium_proxy; | 203 RectServicePtr chromium_proxy; |
| 194 BindToChromiumService(GetProxy(&chromium_proxy)); | 204 BindToChromiumService(GetProxy(&chromium_proxy)); |
| 195 { | 205 { |
| 196 base::RunLoop loop; | 206 base::RunLoop loop; |
| 197 chromium_proxy->AddRect(RectChromium(1, 1, 4, 5)); | 207 chromium_proxy->AddRect(RectChromium(1, 1, 4, 5)); |
| 198 chromium_proxy->AddRect(RectChromium(-1, -1, 2, 2)); | 208 chromium_proxy->AddRect(RectChromium(-1, -1, 2, 2)); |
| 199 chromium_proxy->GetLargestRect( | 209 chromium_proxy->GetLargestRect( |
| 200 ExpectResult(RectChromium(1, 1, 4, 5), loop.QuitClosure())); | 210 ExpectResult(RectChromium(1, 1, 4, 5), loop.QuitClosure())); |
| 201 loop.Run(); | 211 loop.Run(); |
| 202 } | 212 } |
| 213 { |
| 214 base::RunLoop loop; |
| 215 chromium_proxy->PassSharedRect( |
| 216 {1, 2, 3, 4}, |
| 217 ExpectResult(SharedRect({1, 2, 3, 4}), loop.QuitClosure())); |
| 218 loop.Run(); |
| 219 } |
| 203 } | 220 } |
| 204 | 221 |
| 205 TEST_F(StructTraitsTest, ChromiumToBlinkService) { | 222 TEST_F(StructTraitsTest, ChromiumToBlinkService) { |
| 206 RectServicePtr chromium_proxy; | 223 RectServicePtr chromium_proxy; |
| 207 BindToBlinkService(GetProxy(&chromium_proxy)); | 224 BindToBlinkService(GetProxy(&chromium_proxy)); |
| 208 { | 225 { |
| 209 base::RunLoop loop; | 226 base::RunLoop loop; |
| 210 chromium_proxy->AddRect(RectChromium(1, 1, 4, 5)); | 227 chromium_proxy->AddRect(RectChromium(1, 1, 4, 5)); |
| 211 chromium_proxy->AddRect(RectChromium(2, 2, 5, 5)); | 228 chromium_proxy->AddRect(RectChromium(2, 2, 5, 5)); |
| 212 chromium_proxy->GetLargestRect( | 229 chromium_proxy->GetLargestRect( |
| 213 ExpectResult(RectChromium(2, 2, 5, 5), loop.QuitClosure())); | 230 ExpectResult(RectChromium(2, 2, 5, 5), loop.QuitClosure())); |
| 214 loop.Run(); | 231 loop.Run(); |
| 215 } | 232 } |
| 233 { |
| 234 base::RunLoop loop; |
| 235 chromium_proxy->PassSharedRect( |
| 236 {1, 2, 3, 4}, |
| 237 ExpectResult(SharedRect({1, 2, 3, 4}), loop.QuitClosure())); |
| 238 loop.Run(); |
| 239 } |
| 216 // The Blink service should drop our connection because RectBlink's | 240 // The Blink service should drop our connection because RectBlink's |
| 217 // deserializer rejects negative origins. | 241 // deserializer rejects negative origins. |
| 218 { | 242 { |
| 219 base::RunLoop loop; | 243 base::RunLoop loop; |
| 220 ExpectError(&chromium_proxy, loop.QuitClosure()); | 244 ExpectError(&chromium_proxy, loop.QuitClosure()); |
| 221 chromium_proxy->AddRect(RectChromium(-1, -1, 2, 2)); | 245 chromium_proxy->AddRect(RectChromium(-1, -1, 2, 2)); |
| 222 chromium_proxy->GetLargestRect( | 246 chromium_proxy->GetLargestRect( |
| 223 Fail<RectChromium>("The pipe should have been closed.")); | 247 Fail<RectChromium>("The pipe should have been closed.")); |
| 224 loop.Run(); | 248 loop.Run(); |
| 225 } | 249 } |
| 226 } | 250 } |
| 227 | 251 |
| 228 TEST_F(StructTraitsTest, BlinkProxyToBlinkService) { | 252 TEST_F(StructTraitsTest, BlinkProxyToBlinkService) { |
| 229 blink::RectServicePtr blink_proxy; | 253 blink::RectServicePtr blink_proxy; |
| 230 BindToBlinkService(GetProxy(&blink_proxy)); | 254 BindToBlinkService(GetProxy(&blink_proxy)); |
| 231 { | 255 { |
| 232 base::RunLoop loop; | 256 base::RunLoop loop; |
| 233 blink_proxy->AddRect(RectBlink(1, 1, 4, 5)); | 257 blink_proxy->AddRect(RectBlink(1, 1, 4, 5)); |
| 234 blink_proxy->AddRect(RectBlink(10, 10, 20, 20)); | 258 blink_proxy->AddRect(RectBlink(10, 10, 20, 20)); |
| 235 blink_proxy->GetLargestRect( | 259 blink_proxy->GetLargestRect( |
| 236 ExpectResult(RectBlink(10, 10, 20, 20), loop.QuitClosure())); | 260 ExpectResult(RectBlink(10, 10, 20, 20), loop.QuitClosure())); |
| 237 loop.Run(); | 261 loop.Run(); |
| 238 } | 262 } |
| 263 { |
| 264 base::RunLoop loop; |
| 265 blink_proxy->PassSharedRect( |
| 266 {4, 3, 2, 1}, |
| 267 ExpectResult(SharedRect({4, 3, 2, 1}), loop.QuitClosure())); |
| 268 loop.Run(); |
| 269 } |
| 239 } | 270 } |
| 240 | 271 |
| 241 TEST_F(StructTraitsTest, BlinkProxyToChromiumService) { | 272 TEST_F(StructTraitsTest, BlinkProxyToChromiumService) { |
| 242 blink::RectServicePtr blink_proxy; | 273 blink::RectServicePtr blink_proxy; |
| 243 BindToChromiumService(GetProxy(&blink_proxy)); | 274 BindToChromiumService(GetProxy(&blink_proxy)); |
| 244 { | 275 { |
| 245 base::RunLoop loop; | 276 base::RunLoop loop; |
| 246 blink_proxy->AddRect(RectBlink(1, 1, 4, 5)); | 277 blink_proxy->AddRect(RectBlink(1, 1, 4, 5)); |
| 247 blink_proxy->AddRect(RectBlink(10, 10, 2, 2)); | 278 blink_proxy->AddRect(RectBlink(10, 10, 2, 2)); |
| 248 blink_proxy->GetLargestRect( | 279 blink_proxy->GetLargestRect( |
| 249 ExpectResult(RectBlink(1, 1, 4, 5), loop.QuitClosure())); | 280 ExpectResult(RectBlink(1, 1, 4, 5), loop.QuitClosure())); |
| 250 loop.Run(); | 281 loop.Run(); |
| 251 } | 282 } |
| 283 { |
| 284 base::RunLoop loop; |
| 285 blink_proxy->PassSharedRect( |
| 286 {4, 3, 2, 1}, |
| 287 ExpectResult(SharedRect({4, 3, 2, 1}), loop.QuitClosure())); |
| 288 loop.Run(); |
| 289 } |
| 252 } | 290 } |
| 253 | 291 |
| 254 void ExpectStructWithTraits(const StructWithTraitsImpl& expected, | 292 void ExpectStructWithTraits(const StructWithTraitsImpl& expected, |
| 255 const base::Closure& closure, | 293 const base::Closure& closure, |
| 256 const StructWithTraitsImpl& passed) { | 294 const StructWithTraitsImpl& passed) { |
| 257 EXPECT_EQ(expected.get_enum(), passed.get_enum()); | 295 EXPECT_EQ(expected.get_enum(), passed.get_enum()); |
| 258 EXPECT_EQ(expected.get_bool(), passed.get_bool()); | 296 EXPECT_EQ(expected.get_bool(), passed.get_bool()); |
| 259 EXPECT_EQ(expected.get_uint32(), passed.get_uint32()); | 297 EXPECT_EQ(expected.get_uint32(), passed.get_uint32()); |
| 260 EXPECT_EQ(expected.get_uint64(), passed.get_uint64()); | 298 EXPECT_EQ(expected.get_uint64(), passed.get_uint64()); |
| 261 EXPECT_EQ(expected.get_string(), passed.get_string()); | 299 EXPECT_EQ(expected.get_string(), passed.get_string()); |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 quit_closure.Run(); | 543 quit_closure.Run(); |
| 506 | 544 |
| 507 }, | 545 }, |
| 508 loop.QuitClosure())); | 546 loop.QuitClosure())); |
| 509 loop.Run(); | 547 loop.Run(); |
| 510 } | 548 } |
| 511 } | 549 } |
| 512 | 550 |
| 513 } // namespace test | 551 } // namespace test |
| 514 } // namespace mojo | 552 } // namespace mojo |
| OLD | NEW |