Index: mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc |
diff --git a/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc b/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc |
index 98aa852a5a1dc758ff1bc9803b84d404492a5f9f..2714ce85eca8219b5f92f51d21507fb52861b37b 100644 |
--- a/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc |
+++ b/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc |
@@ -29,10 +29,6 @@ class MathCalculatorImpl : public math::Calculator { |
: total_(0.0), binding_(this, std::move(request)) {} |
~MathCalculatorImpl() override {} |
- void CloseMessagePipe() { binding_.Close(); } |
- |
- void WaitForIncomingMethodCall() { binding_.WaitForIncomingMethodCall(); } |
- |
void Clear(const CalcCallback& callback) override { |
total_ = 0.0; |
callback.Run(total_); |
@@ -48,6 +44,8 @@ class MathCalculatorImpl : public math::Calculator { |
callback.Run(total_); |
} |
+ Binding<math::Calculator>* binding() { return &binding_; } |
+ |
private: |
double total_; |
Binding<math::Calculator> binding_; |
@@ -252,14 +250,14 @@ TEST_F(InterfacePtrTest, EndToEnd_Synchronous) { |
base::RunLoop run_loop; |
calculator_ui.Add(2.0, run_loop.QuitClosure()); |
EXPECT_EQ(0.0, calculator_ui.GetOutput()); |
- calc_impl.WaitForIncomingMethodCall(); |
+ calc_impl.binding()->WaitForIncomingMethodCall(); |
run_loop.Run(); |
EXPECT_EQ(2.0, calculator_ui.GetOutput()); |
base::RunLoop run_loop2; |
calculator_ui.Multiply(5.0, run_loop2.QuitClosure()); |
EXPECT_EQ(2.0, calculator_ui.GetOutput()); |
- calc_impl.WaitForIncomingMethodCall(); |
+ calc_impl.binding()->WaitForIncomingMethodCall(); |
run_loop2.Run(); |
EXPECT_EQ(10.0, calculator_ui.GetOutput()); |
} |
@@ -328,7 +326,7 @@ TEST_F(InterfacePtrTest, EncounteredError) { |
EXPECT_FALSE(calculator_ui.encountered_error()); |
// Close the server. |
- calc_impl.CloseMessagePipe(); |
+ calc_impl.binding()->Close(); |
// The state change isn't picked up locally yet. |
base::RunLoop run_loop2; |
@@ -363,7 +361,7 @@ TEST_F(InterfacePtrTest, EncounteredErrorCallback) { |
EXPECT_FALSE(calculator_ui.encountered_error()); |
// Close the server. |
- calc_impl.CloseMessagePipe(); |
+ calc_impl.binding()->Close(); |
// The state change isn't picked up locally yet. |
EXPECT_FALSE(calculator_ui.encountered_error()); |
@@ -754,6 +752,25 @@ TEST_F(InterfacePtrTest, FlushForTestingWithClosedPeer) { |
calc.FlushForTesting(); |
} |
+TEST_F(InterfacePtrTest, ConnectionErrorWithReason) { |
+ math::CalculatorPtr calc; |
+ MathCalculatorImpl calc_impl(GetProxy(&calc)); |
+ |
+ base::RunLoop run_loop; |
+ calc.set_connection_error_with_reason_handler(base::Bind( |
+ [](const base::Closure& quit_closure, uint32_t custom_reason, |
+ const std::string& description) { |
+ EXPECT_EQ(42u, custom_reason); |
+ EXPECT_EQ("hey", description); |
+ quit_closure.Run(); |
+ }, |
+ run_loop.QuitClosure())); |
+ |
+ calc_impl.binding()->CloseWithReason(42u, "hey"); |
+ |
+ run_loop.Run(); |
+} |
+ |
} // namespace |
} // namespace test |
} // namespace mojo |