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 | |
66 bool encountered_error() const { return calculator_.encountered_error(); } | 62 bool encountered_error() const { return calculator_.encountered_error(); } |
67 void set_connection_error_handler(const base::Closure& closure) { | 63 void set_connection_error_handler(const base::Closure& closure) { |
68 calculator_.set_connection_error_handler(closure); | 64 calculator_.set_connection_error_handler(closure); |
69 } | 65 } |
70 | 66 |
71 void Add(double value, const base::Closure& closure) { | 67 void Add(double value, const base::Closure& closure) { |
72 calculator_->Add( | 68 calculator_->Add( |
73 value, | 69 value, |
74 base::Bind(&MathCalculatorUI::Output, base::Unretained(this), closure)); | 70 base::Bind(&MathCalculatorUI::Output, base::Unretained(this), closure)); |
75 } | 71 } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 | 240 |
245 TEST_F(InterfacePtrTest, EndToEnd_Synchronous) { | 241 TEST_F(InterfacePtrTest, EndToEnd_Synchronous) { |
246 math::CalculatorPtr calc; | 242 math::CalculatorPtr calc; |
247 MathCalculatorImpl calc_impl(GetProxy(&calc)); | 243 MathCalculatorImpl calc_impl(GetProxy(&calc)); |
248 | 244 |
249 // Suppose this is instantiated in a process that has pipe1_. | 245 // Suppose this is instantiated in a process that has pipe1_. |
250 MathCalculatorUI calculator_ui(std::move(calc)); | 246 MathCalculatorUI calculator_ui(std::move(calc)); |
251 | 247 |
252 EXPECT_EQ(0.0, calculator_ui.GetOutput()); | 248 EXPECT_EQ(0.0, calculator_ui.GetOutput()); |
253 | 249 |
254 calculator_ui.Add(2.0, base::Closure()); | 250 base::RunLoop run_loop; |
| 251 calculator_ui.Add(2.0, run_loop.QuitClosure()); |
255 EXPECT_EQ(0.0, calculator_ui.GetOutput()); | 252 EXPECT_EQ(0.0, calculator_ui.GetOutput()); |
256 calc_impl.WaitForIncomingMethodCall(); | 253 calc_impl.WaitForIncomingMethodCall(); |
257 calculator_ui.WaitForIncomingResponse(); | 254 run_loop.Run(); |
258 EXPECT_EQ(2.0, calculator_ui.GetOutput()); | 255 EXPECT_EQ(2.0, calculator_ui.GetOutput()); |
259 | 256 |
260 calculator_ui.Multiply(5.0, base::Closure()); | 257 base::RunLoop run_loop2; |
| 258 calculator_ui.Multiply(5.0, run_loop2.QuitClosure()); |
261 EXPECT_EQ(2.0, calculator_ui.GetOutput()); | 259 EXPECT_EQ(2.0, calculator_ui.GetOutput()); |
262 calc_impl.WaitForIncomingMethodCall(); | 260 calc_impl.WaitForIncomingMethodCall(); |
263 calculator_ui.WaitForIncomingResponse(); | 261 run_loop2.Run(); |
264 EXPECT_EQ(10.0, calculator_ui.GetOutput()); | 262 EXPECT_EQ(10.0, calculator_ui.GetOutput()); |
265 } | 263 } |
266 | 264 |
267 TEST_F(InterfacePtrTest, Movable) { | 265 TEST_F(InterfacePtrTest, Movable) { |
268 math::CalculatorPtr a; | 266 math::CalculatorPtr a; |
269 math::CalculatorPtr b; | 267 math::CalculatorPtr b; |
270 MathCalculatorImpl calc_impl(GetProxy(&b)); | 268 MathCalculatorImpl calc_impl(GetProxy(&b)); |
271 | 269 |
272 EXPECT_TRUE(!a); | 270 EXPECT_TRUE(!a); |
273 EXPECT_FALSE(!b); | 271 EXPECT_FALSE(!b); |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 bool called = false; | 731 bool called = false; |
734 base::RunLoop loop; | 732 base::RunLoop loop; |
735 ptr->Ping(base::Bind(&SetFlagAndRunClosure, &called, loop.QuitClosure())); | 733 ptr->Ping(base::Bind(&SetFlagAndRunClosure, &called, loop.QuitClosure())); |
736 loop.Run(); | 734 loop.Run(); |
737 EXPECT_TRUE(called); | 735 EXPECT_TRUE(called); |
738 } | 736 } |
739 | 737 |
740 } // namespace | 738 } // namespace |
741 } // namespace test | 739 } // namespace test |
742 } // namespace mojo | 740 } // namespace mojo |
OLD | NEW |