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/callback.h" | 9 #include "base/callback.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 double total_; | 52 double total_; |
53 Binding<math::Calculator> binding_; | 53 Binding<math::Calculator> binding_; |
54 }; | 54 }; |
55 | 55 |
56 class MathCalculatorUI { | 56 class MathCalculatorUI { |
57 public: | 57 public: |
58 explicit MathCalculatorUI(math::CalculatorPtr calculator) | 58 explicit MathCalculatorUI(math::CalculatorPtr calculator) |
59 : calculator_(std::move(calculator)), | 59 : calculator_(std::move(calculator)), |
60 output_(0.0) {} | 60 output_(0.0) {} |
61 | 61 |
| 62 bool WaitForIncomingResponse() { |
| 63 return calculator_.WaitForIncomingResponse(); |
| 64 } |
| 65 |
62 bool encountered_error() const { return calculator_.encountered_error(); } | 66 bool encountered_error() const { return calculator_.encountered_error(); } |
63 void set_connection_error_handler(const base::Closure& closure) { | 67 void set_connection_error_handler(const base::Closure& closure) { |
64 calculator_.set_connection_error_handler(closure); | 68 calculator_.set_connection_error_handler(closure); |
65 } | 69 } |
66 | 70 |
67 void Add(double value, const base::Closure& closure) { | 71 void Add(double value, const base::Closure& closure) { |
68 calculator_->Add( | 72 calculator_->Add( |
69 value, | 73 value, |
70 base::Bind(&MathCalculatorUI::Output, base::Unretained(this), closure)); | 74 base::Bind(&MathCalculatorUI::Output, base::Unretained(this), closure)); |
71 } | 75 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 } | 188 } |
185 } | 189 } |
186 | 190 |
187 int64_t integer_; | 191 int64_t integer_; |
188 base::Closure closure_; | 192 base::Closure closure_; |
189 }; | 193 }; |
190 | 194 |
191 class InterfacePtrTest : public testing::Test { | 195 class InterfacePtrTest : public testing::Test { |
192 public: | 196 public: |
193 InterfacePtrTest() {} | 197 InterfacePtrTest() {} |
194 ~InterfacePtrTest() override { base::RunLoop().RunUntilIdle(); } | 198 ~InterfacePtrTest() override { loop_.RunUntilIdle(); } |
195 | 199 |
196 void PumpMessages() { base::RunLoop().RunUntilIdle(); } | 200 void PumpMessages() { loop_.RunUntilIdle(); } |
197 | 201 |
198 private: | 202 private: |
199 base::MessageLoop loop_; | 203 base::MessageLoop loop_; |
200 }; | 204 }; |
201 | 205 |
202 void SetFlagAndRunClosure(bool* flag, const base::Closure& closure) { | 206 void SetFlagAndRunClosure(bool* flag, const base::Closure& closure) { |
203 *flag = true; | 207 *flag = true; |
204 closure.Run(); | 208 closure.Run(); |
205 } | 209 } |
206 | 210 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 244 |
241 TEST_F(InterfacePtrTest, EndToEnd_Synchronous) { | 245 TEST_F(InterfacePtrTest, EndToEnd_Synchronous) { |
242 math::CalculatorPtr calc; | 246 math::CalculatorPtr calc; |
243 MathCalculatorImpl calc_impl(GetProxy(&calc)); | 247 MathCalculatorImpl calc_impl(GetProxy(&calc)); |
244 | 248 |
245 // Suppose this is instantiated in a process that has pipe1_. | 249 // Suppose this is instantiated in a process that has pipe1_. |
246 MathCalculatorUI calculator_ui(std::move(calc)); | 250 MathCalculatorUI calculator_ui(std::move(calc)); |
247 | 251 |
248 EXPECT_EQ(0.0, calculator_ui.GetOutput()); | 252 EXPECT_EQ(0.0, calculator_ui.GetOutput()); |
249 | 253 |
250 base::RunLoop run_loop; | 254 calculator_ui.Add(2.0, base::Closure()); |
251 calculator_ui.Add(2.0, run_loop.QuitClosure()); | |
252 EXPECT_EQ(0.0, calculator_ui.GetOutput()); | 255 EXPECT_EQ(0.0, calculator_ui.GetOutput()); |
253 calc_impl.WaitForIncomingMethodCall(); | 256 calc_impl.WaitForIncomingMethodCall(); |
254 run_loop.Run(); | 257 calculator_ui.WaitForIncomingResponse(); |
255 EXPECT_EQ(2.0, calculator_ui.GetOutput()); | 258 EXPECT_EQ(2.0, calculator_ui.GetOutput()); |
256 | 259 |
257 base::RunLoop run_loop2; | 260 calculator_ui.Multiply(5.0, base::Closure()); |
258 calculator_ui.Multiply(5.0, run_loop2.QuitClosure()); | |
259 EXPECT_EQ(2.0, calculator_ui.GetOutput()); | 261 EXPECT_EQ(2.0, calculator_ui.GetOutput()); |
260 calc_impl.WaitForIncomingMethodCall(); | 262 calc_impl.WaitForIncomingMethodCall(); |
261 run_loop2.Run(); | 263 calculator_ui.WaitForIncomingResponse(); |
262 EXPECT_EQ(10.0, calculator_ui.GetOutput()); | 264 EXPECT_EQ(10.0, calculator_ui.GetOutput()); |
263 } | 265 } |
264 | 266 |
265 TEST_F(InterfacePtrTest, Movable) { | 267 TEST_F(InterfacePtrTest, Movable) { |
266 math::CalculatorPtr a; | 268 math::CalculatorPtr a; |
267 math::CalculatorPtr b; | 269 math::CalculatorPtr b; |
268 MathCalculatorImpl calc_impl(GetProxy(&b)); | 270 MathCalculatorImpl calc_impl(GetProxy(&b)); |
269 | 271 |
270 EXPECT_TRUE(!a); | 272 EXPECT_TRUE(!a); |
271 EXPECT_FALSE(!b); | 273 EXPECT_FALSE(!b); |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 bool called = false; | 733 bool called = false; |
732 base::RunLoop loop; | 734 base::RunLoop loop; |
733 ptr->Ping(base::Bind(&SetFlagAndRunClosure, &called, loop.QuitClosure())); | 735 ptr->Ping(base::Bind(&SetFlagAndRunClosure, &called, loop.QuitClosure())); |
734 loop.Run(); | 736 loop.Run(); |
735 EXPECT_TRUE(called); | 737 EXPECT_TRUE(called); |
736 } | 738 } |
737 | 739 |
738 } // namespace | 740 } // namespace |
739 } // namespace test | 741 } // namespace test |
740 } // namespace mojo | 742 } // namespace mojo |
OLD | NEW |