| Index: mojo/public/cpp/bindings/tests/associated_interface_unittest.cc
|
| diff --git a/mojo/public/cpp/bindings/tests/associated_interface_unittest.cc b/mojo/public/cpp/bindings/tests/associated_interface_unittest.cc
|
| index 7cdef583a2a9016f3e342a6fc8bd8d82de98c341..d7b826a24221b5c03da7ccd0a96de3d47cbac899 100644
|
| --- a/mojo/public/cpp/bindings/tests/associated_interface_unittest.cc
|
| +++ b/mojo/public/cpp/bindings/tests/associated_interface_unittest.cc
|
| @@ -67,7 +67,7 @@ class IntegerSenderConnectionImpl : public IntegerSenderConnection {
|
| void GetSender(AssociatedInterfaceRequest<IntegerSender> sender) override {
|
| IntegerSenderImpl* sender_impl = new IntegerSenderImpl(std::move(sender));
|
| sender_impl->set_connection_error_handler(
|
| - [sender_impl]() { delete sender_impl; });
|
| + base::Bind(&DeleteSender, sender_impl));
|
| }
|
|
|
| void AsyncGetSender(const AsyncGetSenderCallback& callback) override {
|
| @@ -82,6 +82,8 @@ class IntegerSenderConnectionImpl : public IntegerSenderConnection {
|
| Binding<IntegerSenderConnection>* binding() { return &binding_; }
|
|
|
| private:
|
| + static void DeleteSender(IntegerSenderImpl* sender) { delete sender; }
|
| +
|
| Binding<IntegerSenderConnection> binding_;
|
| };
|
|
|
| @@ -129,6 +131,31 @@ class AssociatedInterfaceTest : public testing::Test {
|
| base::MessageLoop loop_;
|
| };
|
|
|
| +void DoSetFlagAndRunClosure(bool* flag, const base::Closure& closure) {
|
| + *flag = true;
|
| + closure.Run();
|
| +}
|
| +
|
| +void DoExpectValueSetFlagAndRunClosure(int32_t expected_value,
|
| + bool* flag,
|
| + const base::Closure& closure,
|
| + int32_t value) {
|
| + EXPECT_EQ(expected_value, value);
|
| + DoSetFlagAndRunClosure(flag, closure);
|
| +}
|
| +
|
| +base::Closure SetFlagAndRunClosure(bool* flag, const base::Closure& closure) {
|
| + return base::Bind(&DoSetFlagAndRunClosure, flag, closure);
|
| +}
|
| +
|
| +base::Callback<void(int32_t)> ExpectValueSetFlagAndRunClosure(
|
| + int32_t expected_value,
|
| + bool* flag,
|
| + const base::Closure& closure) {
|
| + return base::Bind(
|
| + &DoExpectValueSetFlagAndRunClosure, expected_value, flag, closure);
|
| +}
|
| +
|
| TEST_F(AssociatedInterfaceTest, InterfacesAtBothEnds) {
|
| // Bind to the same pipe two associated interfaces, whose implementation lives
|
| // at different ends. Test that the two don't interfere with each other.
|
| @@ -160,18 +187,12 @@ TEST_F(AssociatedInterfaceTest, InterfacesAtBothEnds) {
|
|
|
| base::RunLoop run_loop, run_loop2;
|
| bool ptr0_callback_run = false;
|
| - ptr0->Echo(123, [&ptr0_callback_run, &run_loop](int32_t value) {
|
| - EXPECT_EQ(123, value);
|
| - ptr0_callback_run = true;
|
| - run_loop.Quit();
|
| - });
|
| + ptr0->Echo(123, ExpectValueSetFlagAndRunClosure(123, &ptr0_callback_run,
|
| + run_loop.QuitClosure()));
|
|
|
| bool ptr1_callback_run = false;
|
| - ptr1->Echo(456, [&ptr1_callback_run, &run_loop2](int32_t value) {
|
| - EXPECT_EQ(456, value);
|
| - ptr1_callback_run = true;
|
| - run_loop2.Quit();
|
| - });
|
| + ptr1->Echo(456, ExpectValueSetFlagAndRunClosure(456, &ptr1_callback_run,
|
| + run_loop2.QuitClosure()));
|
|
|
| run_loop.Run();
|
| run_loop2.Run();
|
| @@ -180,10 +201,8 @@ TEST_F(AssociatedInterfaceTest, InterfacesAtBothEnds) {
|
|
|
| bool ptr0_error_callback_run = false;
|
| base::RunLoop run_loop3;
|
| - ptr0.set_connection_error_handler([&ptr0_error_callback_run, &run_loop3]() {
|
| - ptr0_error_callback_run = true;
|
| - run_loop3.Quit();
|
| - });
|
| + ptr0.set_connection_error_handler(
|
| + SetFlagAndRunClosure(&ptr0_error_callback_run, run_loop3.QuitClosure()));
|
|
|
| impl0.binding()->Close();
|
| run_loop3.Run();
|
| @@ -192,10 +211,7 @@ TEST_F(AssociatedInterfaceTest, InterfacesAtBothEnds) {
|
| bool impl1_error_callback_run = false;
|
| base::RunLoop run_loop4;
|
| impl1.binding()->set_connection_error_handler(
|
| - [&impl1_error_callback_run, &run_loop4]() {
|
| - impl1_error_callback_run = true;
|
| - run_loop4.Quit();
|
| - });
|
| + SetFlagAndRunClosure(&impl1_error_callback_run, run_loop4.QuitClosure()));
|
|
|
| ptr1.reset();
|
| run_loop4.Run();
|
| @@ -504,6 +520,20 @@ TEST_F(AssociatedInterfaceTest, FIFO) {
|
| }
|
| }
|
|
|
| +void CaptureInt32(int32_t* storage,
|
| + const base::Closure& closure,
|
| + int32_t value) {
|
| + *storage = value;
|
| + closure.Run();
|
| +}
|
| +
|
| +void CaptureSenderPtrInfo(IntegerSenderAssociatedPtr* storage,
|
| + const base::Closure& closure,
|
| + IntegerSenderAssociatedPtrInfo info) {
|
| + storage->Bind(std::move(info));
|
| + closure.Run();
|
| +}
|
| +
|
| TEST_F(AssociatedInterfaceTest, PassAssociatedInterfaces) {
|
| IntegerSenderConnectionPtr connection_ptr;
|
| IntegerSenderConnectionImpl connection(GetProxy(&connection_ptr));
|
| @@ -514,28 +544,21 @@ TEST_F(AssociatedInterfaceTest, PassAssociatedInterfaces) {
|
|
|
| int32_t echoed_value = 0;
|
| base::RunLoop run_loop;
|
| - sender0->Echo(123, [&echoed_value, &run_loop](int32_t value) {
|
| - echoed_value = value;
|
| - run_loop.Quit();
|
| - });
|
| + sender0->Echo(123, base::Bind(&CaptureInt32, &echoed_value,
|
| + run_loop.QuitClosure()));
|
| run_loop.Run();
|
| EXPECT_EQ(123, echoed_value);
|
|
|
| IntegerSenderAssociatedPtr sender1;
|
| base::RunLoop run_loop2;
|
| connection_ptr->AsyncGetSender(
|
| - [&sender1, &run_loop2](IntegerSenderAssociatedPtrInfo ptr_info) {
|
| - sender1.Bind(std::move(ptr_info));
|
| - run_loop2.Quit();
|
| - });
|
| + base::Bind(&CaptureSenderPtrInfo, &sender1, run_loop2.QuitClosure()));
|
| run_loop2.Run();
|
| EXPECT_TRUE(sender1);
|
|
|
| base::RunLoop run_loop3;
|
| - sender1->Echo(456, [&echoed_value, &run_loop3](int32_t value) {
|
| - echoed_value = value;
|
| - run_loop3.Quit();
|
| - });
|
| + sender1->Echo(456, base::Bind(&CaptureInt32, &echoed_value,
|
| + run_loop3.QuitClosure()));
|
| run_loop3.Run();
|
| EXPECT_EQ(456, echoed_value);
|
| }
|
|
|