| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/macros.h" | 7 #include "base/macros.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 "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 78 } |
| 79 | 79 |
| 80 Binding<TestSync>* binding() { return &binding_; } | 80 Binding<TestSync>* binding() { return &binding_; } |
| 81 | 81 |
| 82 private: | 82 private: |
| 83 Binding<TestSync> binding_; | 83 Binding<TestSync> binding_; |
| 84 | 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(TestSyncImpl); | 85 DISALLOW_COPY_AND_ASSIGN(TestSyncImpl); |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 class TestSyncMasterImpl : public TestSyncMaster, public TestSyncCommonImpl { |
| 89 public: |
| 90 explicit TestSyncMasterImpl(TestSyncMasterRequest request) |
| 91 : binding_(this, std::move(request)) {} |
| 92 |
| 93 // TestSyncMaster implementation: |
| 94 void Ping(const PingCallback& callback) override { PingImpl(callback); } |
| 95 void Echo(int32_t value, const EchoCallback& callback) override { |
| 96 EchoImpl(value, callback); |
| 97 } |
| 98 void AsyncEcho(int32_t value, const AsyncEchoCallback& callback) override { |
| 99 AsyncEchoImpl(value, callback); |
| 100 } |
| 101 void SendInterface(TestSyncAssociatedPtrInfo ptr) override {} |
| 102 |
| 103 Binding<TestSyncMaster>* binding() { return &binding_; } |
| 104 |
| 105 private: |
| 106 Binding<TestSyncMaster> binding_; |
| 107 |
| 108 DISALLOW_COPY_AND_ASSIGN(TestSyncMasterImpl); |
| 109 }; |
| 110 |
| 88 template <typename Interface> | 111 template <typename Interface> |
| 89 struct ImplTraits; | 112 struct ImplTraits; |
| 90 | 113 |
| 91 template <> | 114 template <> |
| 92 struct ImplTraits<TestSync> { | 115 struct ImplTraits<TestSync> { |
| 93 using Type = TestSyncImpl; | 116 using Type = TestSyncImpl; |
| 94 }; | 117 }; |
| 95 | 118 |
| 119 template <> |
| 120 struct ImplTraits<TestSyncMaster> { |
| 121 using Type = TestSyncMasterImpl; |
| 122 }; |
| 123 |
| 96 template <typename Interface> | 124 template <typename Interface> |
| 97 class TestSyncServiceThread { | 125 class TestSyncServiceThread { |
| 98 public: | 126 public: |
| 99 TestSyncServiceThread() | 127 TestSyncServiceThread() |
| 100 : thread_("TestSyncServiceThread"), ping_called_(false) { | 128 : thread_("TestSyncServiceThread"), ping_called_(false) { |
| 101 base::Thread::Options thread_options; | 129 base::Thread::Options thread_options; |
| 102 thread_options.message_pump_factory = | 130 thread_options.message_pump_factory = |
| 103 base::Bind(&common::MessagePumpMojo::Create); | 131 base::Bind(&common::MessagePumpMojo::Create); |
| 104 thread_.StartWithOptions(thread_options); | 132 thread_.StartWithOptions(thread_options); |
| 105 } | 133 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 template <typename T> | 169 template <typename T> |
| 142 class SyncMethodCommonTest : public testing::Test { | 170 class SyncMethodCommonTest : public testing::Test { |
| 143 public: | 171 public: |
| 144 SyncMethodCommonTest() : loop_(common::MessagePumpMojo::Create()) {} | 172 SyncMethodCommonTest() : loop_(common::MessagePumpMojo::Create()) {} |
| 145 ~SyncMethodCommonTest() override { loop_.RunUntilIdle(); } | 173 ~SyncMethodCommonTest() override { loop_.RunUntilIdle(); } |
| 146 | 174 |
| 147 private: | 175 private: |
| 148 base::MessageLoop loop_; | 176 base::MessageLoop loop_; |
| 149 }; | 177 }; |
| 150 | 178 |
| 151 using InterfaceTypes = testing::Types<TestSync>; | 179 // TestSync and TestSyncMaster exercise Router and MultiplexRouter, |
| 180 // respectively. |
| 181 using InterfaceTypes = testing::Types<TestSync, TestSyncMaster>; |
| 152 TYPED_TEST_CASE(SyncMethodCommonTest, InterfaceTypes); | 182 TYPED_TEST_CASE(SyncMethodCommonTest, InterfaceTypes); |
| 153 | 183 |
| 154 TYPED_TEST(SyncMethodCommonTest, CallSyncMethodAsynchronously) { | 184 TYPED_TEST(SyncMethodCommonTest, CallSyncMethodAsynchronously) { |
| 155 InterfacePtr<TypeParam> ptr; | 185 InterfacePtr<TypeParam> ptr; |
| 156 typename ImplTraits<TypeParam>::Type impl(GetProxy(&ptr)); | 186 typename ImplTraits<TypeParam>::Type impl(GetProxy(&ptr)); |
| 157 | 187 |
| 158 base::RunLoop run_loop; | 188 base::RunLoop run_loop; |
| 159 ptr->Echo(123, [&run_loop](int32_t result) { | 189 ptr->Echo(123, [&run_loop](int32_t result) { |
| 160 EXPECT_EQ(123, result); | 190 EXPECT_EQ(123, result); |
| 161 run_loop.Quit(); | 191 run_loop.Quit(); |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 EXPECT_EQ(-1, result_value); | 522 EXPECT_EQ(-1, result_value); |
| 493 ASSERT_FALSE(connection_error_dispatched); | 523 ASSERT_FALSE(connection_error_dispatched); |
| 494 | 524 |
| 495 run_loop.Run(); | 525 run_loop.Run(); |
| 496 ASSERT_TRUE(connection_error_dispatched); | 526 ASSERT_TRUE(connection_error_dispatched); |
| 497 } | 527 } |
| 498 | 528 |
| 499 } // namespace | 529 } // namespace |
| 500 } // namespace test | 530 } // namespace test |
| 501 } // namespace mojo | 531 } // namespace mojo |
| OLD | NEW |