Index: third_party/mojo/src/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc |
diff --git a/third_party/mojo/src/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc b/third_party/mojo/src/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc |
index ded5888c2a975cb282e7f3d65091121b8088c78b..3fcade67fd823a2c1259de54df96ddc7841a9f30 100644 |
--- a/third_party/mojo/src/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc |
+++ b/third_party/mojo/src/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc |
@@ -49,11 +49,15 @@ RunnableImpl<Method, Class> MakeRunnable(Method method, Class object) { |
typedef mojo::Callback<void(double)> CalcCallback; |
-class MathCalculatorImpl : public InterfaceImpl<math::Calculator> { |
+class MathCalculatorImpl : public math::Calculator { |
public: |
+ explicit MathCalculatorImpl(InterfaceRequest<math::Calculator> request) |
+ : total_(0.0), binding_(this, request.Pass()) {} |
~MathCalculatorImpl() override {} |
- MathCalculatorImpl() : total_(0.0) {} |
+ void CloseMessagePipe() { binding_.Close(); } |
+ |
+ void WaitForIncomingMethodCall() { binding_.WaitForIncomingMethodCall(); } |
void Clear(const CalcCallback& callback) override { |
total_ = 0.0; |
@@ -72,6 +76,7 @@ class MathCalculatorImpl : public InterfaceImpl<math::Calculator> { |
private: |
double total_; |
+ Binding<math::Calculator> binding_; |
}; |
class MathCalculatorUI { |
@@ -142,22 +147,25 @@ class SelfDestructingMathCalculatorUI { |
// static |
int SelfDestructingMathCalculatorUI::num_instances_ = 0; |
-class ReentrantServiceImpl : public InterfaceImpl<sample::Service> { |
+class ReentrantServiceImpl : public sample::Service { |
public: |
~ReentrantServiceImpl() override {} |
- ReentrantServiceImpl() : call_depth_(0), max_call_depth_(0) {} |
+ explicit ReentrantServiceImpl(InterfaceRequest<sample::Service> request) |
+ : call_depth_(0), max_call_depth_(0), binding_(this, request.Pass()) {} |
int max_call_depth() { return max_call_depth_; } |
void Frobinate(sample::FooPtr foo, |
sample::Service::BazOptions baz, |
- sample::PortPtr port) override { |
+ sample::PortPtr port, |
+ const sample::Service::FrobinateCallback& callback) override { |
max_call_depth_ = std::max(++call_depth_, max_call_depth_); |
if (call_depth_ == 1) { |
- EXPECT_TRUE(WaitForIncomingMethodCall()); |
+ EXPECT_TRUE(binding_.WaitForIncomingMethodCall()); |
} |
call_depth_--; |
+ callback.Run(5); |
} |
void GetPort(mojo::InterfaceRequest<sample::Port> port) override {} |
@@ -165,6 +173,7 @@ class ReentrantServiceImpl : public InterfaceImpl<sample::Service> { |
private: |
int call_depth_; |
int max_call_depth_; |
+ Binding<sample::Service> binding_; |
}; |
class InterfacePtrTest : public testing::Test { |
@@ -180,7 +189,7 @@ class InterfacePtrTest : public testing::Test { |
TEST_F(InterfacePtrTest, EndToEnd) { |
math::CalculatorPtr calc; |
- BindToProxy(new MathCalculatorImpl(), &calc); |
+ MathCalculatorImpl calc_impl(GetProxy(&calc)); |
// Suppose this is instantiated in a process that has pipe1_. |
MathCalculatorUI calculator_ui(calc.Pass()); |
@@ -195,7 +204,7 @@ TEST_F(InterfacePtrTest, EndToEnd) { |
TEST_F(InterfacePtrTest, EndToEnd_Synchronous) { |
math::CalculatorPtr calc; |
- MathCalculatorImpl* impl = BindToProxy(new MathCalculatorImpl(), &calc); |
+ MathCalculatorImpl calc_impl(GetProxy(&calc)); |
// Suppose this is instantiated in a process that has pipe1_. |
MathCalculatorUI calculator_ui(calc.Pass()); |
@@ -204,13 +213,13 @@ TEST_F(InterfacePtrTest, EndToEnd_Synchronous) { |
calculator_ui.Add(2.0); |
EXPECT_EQ(0.0, calculator_ui.GetOutput()); |
- impl->WaitForIncomingMethodCall(); |
+ calc_impl.WaitForIncomingMethodCall(); |
calculator_ui.WaitForIncomingMethodCall(); |
EXPECT_EQ(2.0, calculator_ui.GetOutput()); |
calculator_ui.Multiply(5.0); |
EXPECT_EQ(2.0, calculator_ui.GetOutput()); |
- impl->WaitForIncomingMethodCall(); |
+ calc_impl.WaitForIncomingMethodCall(); |
calculator_ui.WaitForIncomingMethodCall(); |
EXPECT_EQ(10.0, calculator_ui.GetOutput()); |
} |
@@ -218,7 +227,7 @@ TEST_F(InterfacePtrTest, EndToEnd_Synchronous) { |
TEST_F(InterfacePtrTest, Movable) { |
math::CalculatorPtr a; |
math::CalculatorPtr b; |
- BindToProxy(new MathCalculatorImpl(), &b); |
+ MathCalculatorImpl calc_impl(GetProxy(&b)); |
EXPECT_TRUE(!a); |
EXPECT_FALSE(!b); |
@@ -254,7 +263,7 @@ TEST_F(InterfacePtrTest, Resettable) { |
TEST_F(InterfacePtrTest, EncounteredError) { |
math::CalculatorPtr proxy; |
- MathCalculatorImpl* server = BindToProxy(new MathCalculatorImpl(), &proxy); |
+ MathCalculatorImpl calc_impl(GetProxy(&proxy)); |
MathCalculatorUI calculator_ui(proxy.Pass()); |
@@ -267,7 +276,7 @@ TEST_F(InterfacePtrTest, EncounteredError) { |
EXPECT_FALSE(calculator_ui.encountered_error()); |
// Close the server. |
- server->internal_router()->CloseMessagePipe(); |
+ calc_impl.CloseMessagePipe(); |
// The state change isn't picked up locally yet. |
EXPECT_FALSE(calculator_ui.encountered_error()); |
@@ -280,7 +289,7 @@ TEST_F(InterfacePtrTest, EncounteredError) { |
TEST_F(InterfacePtrTest, EncounteredErrorCallback) { |
math::CalculatorPtr proxy; |
- MathCalculatorImpl* server = BindToProxy(new MathCalculatorImpl(), &proxy); |
+ MathCalculatorImpl calc_impl(GetProxy(&proxy)); |
ErrorObserver error_observer; |
proxy.set_error_handler(&error_observer); |
@@ -296,7 +305,7 @@ TEST_F(InterfacePtrTest, EncounteredErrorCallback) { |
EXPECT_FALSE(calculator_ui.encountered_error()); |
// Close the server. |
- server->internal_router()->CloseMessagePipe(); |
+ calc_impl.CloseMessagePipe(); |
// The state change isn't picked up locally yet. |
EXPECT_FALSE(calculator_ui.encountered_error()); |
@@ -311,17 +320,9 @@ TEST_F(InterfacePtrTest, EncounteredErrorCallback) { |
EXPECT_TRUE(error_observer.encountered_error()); |
} |
-TEST_F(InterfacePtrTest, NoClientAttribute) { |
- // This is a test to ensure the following compiles. The sample::Port interface |
- // does not have an explicit Client attribute. |
- sample::PortPtr port; |
- MessagePipe pipe; |
- port.Bind(pipe.handle0.Pass()); |
-} |
- |
-TEST_F(InterfacePtrTest, DestroyInterfacePtrOnClientMethod) { |
+TEST_F(InterfacePtrTest, DestroyInterfacePtrOnMethodResponse) { |
math::CalculatorPtr proxy; |
- BindToProxy(new MathCalculatorImpl(), &proxy); |
+ MathCalculatorImpl calc_impl(GetProxy(&proxy)); |
EXPECT_EQ(0, SelfDestructingMathCalculatorUI::num_instances()); |
@@ -334,9 +335,9 @@ TEST_F(InterfacePtrTest, DestroyInterfacePtrOnClientMethod) { |
EXPECT_EQ(0, SelfDestructingMathCalculatorUI::num_instances()); |
} |
-TEST_F(InterfacePtrTest, NestedDestroyInterfacePtrOnClientMethod) { |
+TEST_F(InterfacePtrTest, NestedDestroyInterfacePtrOnMethodResponse) { |
math::CalculatorPtr proxy; |
- BindToProxy(new MathCalculatorImpl(), &proxy); |
+ MathCalculatorImpl calc_impl(GetProxy(&proxy)); |
EXPECT_EQ(0, SelfDestructingMathCalculatorUI::num_instances()); |
@@ -351,14 +352,16 @@ TEST_F(InterfacePtrTest, NestedDestroyInterfacePtrOnClientMethod) { |
TEST_F(InterfacePtrTest, ReentrantWaitForIncomingMethodCall) { |
sample::ServicePtr proxy; |
- ReentrantServiceImpl* impl = BindToProxy(new ReentrantServiceImpl(), &proxy); |
+ ReentrantServiceImpl impl(GetProxy(&proxy)); |
- proxy->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr); |
- proxy->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr); |
+ proxy->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, |
+ sample::Service::FrobinateCallback()); |
+ proxy->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, |
+ sample::Service::FrobinateCallback()); |
PumpMessages(); |
- EXPECT_EQ(2, impl->max_call_depth()); |
+ EXPECT_EQ(2, impl.max_call_depth()); |
} |
class StrongMathCalculatorImpl : public math::Calculator, public ErrorHandler { |