| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stdint.h> | 5 #include <stdint.h> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 IntegerAccessorImpl() : integer_(0) {} | 191 IntegerAccessorImpl() : integer_(0) {} |
| 192 ~IntegerAccessorImpl() override {} | 192 ~IntegerAccessorImpl() override {} |
| 193 | 193 |
| 194 int64_t integer() const { return integer_; } | 194 int64_t integer() const { return integer_; } |
| 195 | 195 |
| 196 void set_closure(const base::Closure& closure) { closure_ = closure; } | 196 void set_closure(const base::Closure& closure) { closure_ = closure; } |
| 197 | 197 |
| 198 private: | 198 private: |
| 199 // sample::IntegerAccessor implementation. | 199 // sample::IntegerAccessor implementation. |
| 200 void GetInteger(const GetIntegerCallback& callback) override { | 200 void GetInteger(const GetIntegerCallback& callback) override { |
| 201 callback.Run(integer_, sample::ENUM_VALUE); | 201 callback.Run(integer_, sample::Enum::VALUE); |
| 202 } | 202 } |
| 203 void SetInteger(int64_t data, sample::Enum type) override { | 203 void SetInteger(int64_t data, sample::Enum type) override { |
| 204 integer_ = data; | 204 integer_ = data; |
| 205 if (!closure_.is_null()) { | 205 if (!closure_.is_null()) { |
| 206 closure_.Run(); | 206 closure_.Run(); |
| 207 closure_.Reset(); | 207 closure_.Reset(); |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 | 210 |
| 211 int64_t integer_; | 211 int64_t integer_; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 EXPECT_EQ(0, SelfDestructingMathCalculatorUI::num_instances()); | 414 EXPECT_EQ(0, SelfDestructingMathCalculatorUI::num_instances()); |
| 415 } | 415 } |
| 416 | 416 |
| 417 TEST_F(InterfacePtrTest, ReentrantWaitForIncomingMethodCall) { | 417 TEST_F(InterfacePtrTest, ReentrantWaitForIncomingMethodCall) { |
| 418 sample::ServicePtr proxy; | 418 sample::ServicePtr proxy; |
| 419 ReentrantServiceImpl impl(GetProxy(&proxy)); | 419 ReentrantServiceImpl impl(GetProxy(&proxy)); |
| 420 | 420 |
| 421 base::RunLoop run_loop, run_loop2; | 421 base::RunLoop run_loop, run_loop2; |
| 422 auto called_cb = [&run_loop](int32_t result) { run_loop.Quit(); }; | 422 auto called_cb = [&run_loop](int32_t result) { run_loop.Quit(); }; |
| 423 auto called_cb2 = [&run_loop2](int32_t result) { run_loop2.Quit(); }; | 423 auto called_cb2 = [&run_loop2](int32_t result) { run_loop2.Quit(); }; |
| 424 proxy->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, | 424 proxy->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, |
| 425 called_cb); | 425 called_cb); |
| 426 proxy->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, | 426 proxy->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, |
| 427 called_cb2); | 427 called_cb2); |
| 428 | 428 |
| 429 run_loop.Run(); | 429 run_loop.Run(); |
| 430 run_loop2.Run(); | 430 run_loop2.Run(); |
| 431 | 431 |
| 432 EXPECT_EQ(2, impl.max_call_depth()); | 432 EXPECT_EQ(2, impl.max_call_depth()); |
| 433 } | 433 } |
| 434 | 434 |
| 435 TEST_F(InterfacePtrTest, QueryVersion) { | 435 TEST_F(InterfacePtrTest, QueryVersion) { |
| 436 IntegerAccessorImpl impl; | 436 IntegerAccessorImpl impl; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 455 IntegerAccessorImpl impl; | 455 IntegerAccessorImpl impl; |
| 456 sample::IntegerAccessorPtr ptr; | 456 sample::IntegerAccessorPtr ptr; |
| 457 Binding<sample::IntegerAccessor> binding(&impl, GetProxy(&ptr)); | 457 Binding<sample::IntegerAccessor> binding(&impl, GetProxy(&ptr)); |
| 458 | 458 |
| 459 EXPECT_EQ(0u, ptr.version()); | 459 EXPECT_EQ(0u, ptr.version()); |
| 460 | 460 |
| 461 ptr.RequireVersion(1u); | 461 ptr.RequireVersion(1u); |
| 462 EXPECT_EQ(1u, ptr.version()); | 462 EXPECT_EQ(1u, ptr.version()); |
| 463 base::RunLoop run_loop; | 463 base::RunLoop run_loop; |
| 464 impl.set_closure(run_loop.QuitClosure()); | 464 impl.set_closure(run_loop.QuitClosure()); |
| 465 ptr->SetInteger(123, sample::ENUM_VALUE); | 465 ptr->SetInteger(123, sample::Enum::VALUE); |
| 466 run_loop.Run(); | 466 run_loop.Run(); |
| 467 EXPECT_FALSE(ptr.encountered_error()); | 467 EXPECT_FALSE(ptr.encountered_error()); |
| 468 EXPECT_EQ(123, impl.integer()); | 468 EXPECT_EQ(123, impl.integer()); |
| 469 | 469 |
| 470 ptr.RequireVersion(3u); | 470 ptr.RequireVersion(3u); |
| 471 EXPECT_EQ(3u, ptr.version()); | 471 EXPECT_EQ(3u, ptr.version()); |
| 472 base::RunLoop run_loop2; | 472 base::RunLoop run_loop2; |
| 473 impl.set_closure(run_loop2.QuitClosure()); | 473 impl.set_closure(run_loop2.QuitClosure()); |
| 474 ptr->SetInteger(456, sample::ENUM_VALUE); | 474 ptr->SetInteger(456, sample::Enum::VALUE); |
| 475 run_loop2.Run(); | 475 run_loop2.Run(); |
| 476 EXPECT_FALSE(ptr.encountered_error()); | 476 EXPECT_FALSE(ptr.encountered_error()); |
| 477 EXPECT_EQ(456, impl.integer()); | 477 EXPECT_EQ(456, impl.integer()); |
| 478 | 478 |
| 479 // Require a version that is not supported by the impl side. | 479 // Require a version that is not supported by the impl side. |
| 480 ptr.RequireVersion(4u); | 480 ptr.RequireVersion(4u); |
| 481 // This value is set to the input of RequireVersion() synchronously. | 481 // This value is set to the input of RequireVersion() synchronously. |
| 482 EXPECT_EQ(4u, ptr.version()); | 482 EXPECT_EQ(4u, ptr.version()); |
| 483 base::RunLoop run_loop3; | 483 base::RunLoop run_loop3; |
| 484 ptr.set_connection_error_handler(run_loop3.QuitClosure()); | 484 ptr.set_connection_error_handler(run_loop3.QuitClosure()); |
| 485 ptr->SetInteger(789, sample::ENUM_VALUE); | 485 ptr->SetInteger(789, sample::Enum::VALUE); |
| 486 run_loop3.Run(); | 486 run_loop3.Run(); |
| 487 EXPECT_TRUE(ptr.encountered_error()); | 487 EXPECT_TRUE(ptr.encountered_error()); |
| 488 // The call to SetInteger() after RequireVersion(4u) is ignored. | 488 // The call to SetInteger() after RequireVersion(4u) is ignored. |
| 489 EXPECT_EQ(456, impl.integer()); | 489 EXPECT_EQ(456, impl.integer()); |
| 490 } | 490 } |
| 491 | 491 |
| 492 class StrongMathCalculatorImpl : public math::Calculator { | 492 class StrongMathCalculatorImpl : public math::Calculator { |
| 493 public: | 493 public: |
| 494 StrongMathCalculatorImpl(ScopedMessagePipeHandle handle, | 494 StrongMathCalculatorImpl(ScopedMessagePipeHandle handle, |
| 495 bool* error_received, | 495 bool* error_received, |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 // While B & C have fallen out of scope, the pipes will remain until they are | 710 // While B & C have fallen out of scope, the pipes will remain until they are |
| 711 // flushed. | 711 // flushed. |
| 712 EXPECT_FALSE(a_impl.d_called()); | 712 EXPECT_FALSE(a_impl.d_called()); |
| 713 run_loop.Run(); | 713 run_loop.Run(); |
| 714 EXPECT_TRUE(a_impl.d_called()); | 714 EXPECT_TRUE(a_impl.d_called()); |
| 715 } | 715 } |
| 716 | 716 |
| 717 } // namespace | 717 } // namespace |
| 718 } // namespace test | 718 } // namespace test |
| 719 } // namespace mojo | 719 } // namespace mojo |
| OLD | NEW |