| Index: mojo/public/cpp/bindings/tests/bind_task_runner_unittest.cc
|
| diff --git a/mojo/public/cpp/bindings/tests/bind_task_runner_unittest.cc b/mojo/public/cpp/bindings/tests/bind_task_runner_unittest.cc
|
| index 489f42b4c90ac5c298d8aa5b389891cba4575c4c..7cb782db3562380912f4162102b167aec10392ab 100644
|
| --- a/mojo/public/cpp/bindings/tests/bind_task_runner_unittest.cc
|
| +++ b/mojo/public/cpp/bindings/tests/bind_task_runner_unittest.cc
|
| @@ -2,6 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include "base/bind.h"
|
| #include "base/message_loop/message_loop.h"
|
| #include "base/single_thread_task_runner.h"
|
| #include "base/synchronization/lock.h"
|
| @@ -124,6 +125,7 @@ class IntegerSenderImpl : public IntegerSender {
|
| ~IntegerSenderImpl() override {}
|
|
|
| using EchoHandler = Callback<void(int32_t, const EchoCallback&)>;
|
| +
|
| void set_echo_handler(const EchoHandler& handler) { echo_handler_ = handler; }
|
|
|
| void Echo(int32_t value, const EchoCallback& callback) override {
|
| @@ -216,7 +218,8 @@ class AssociatedBindTaskRunnerTest : public testing::Test {
|
| sender_binding_task_runner_));
|
|
|
| connection_impl_->set_get_sender_notification(
|
| - [this]() { connection_binding_task_runner_->Quit(); });
|
| + base::Bind(&AssociatedBindTaskRunnerTest::QuitTaskRunner,
|
| + base::Unretained(this)));
|
|
|
| connection_ptr_->GetSender(GetProxy(&sender_ptr_,
|
| connection_ptr_.associated_group(),
|
| @@ -224,6 +227,10 @@ class AssociatedBindTaskRunnerTest : public testing::Test {
|
| connection_binding_task_runner_->Run();
|
| }
|
|
|
| + void QuitTaskRunner() {
|
| + connection_binding_task_runner_->Quit();
|
| + }
|
| +
|
| base::MessageLoop loop_;
|
| scoped_refptr<TestTaskRunner> connection_binding_task_runner_;
|
| scoped_refptr<TestTaskRunner> connection_ptr_task_runner_;
|
| @@ -235,22 +242,56 @@ class AssociatedBindTaskRunnerTest : public testing::Test {
|
| IntegerSenderAssociatedPtr sender_ptr_;
|
| };
|
|
|
| +void DoSetFlagAndQuitTaskRunner(bool* flag,
|
| + scoped_refptr<TestTaskRunner> task_runner) {
|
| + *flag = true;
|
| + if (task_runner)
|
| + task_runner->Quit();
|
| +}
|
| +
|
| +void DoExpectValueSetFlagAndQuitTaskRunner(
|
| + int32_t expected_value,
|
| + bool* flag,
|
| + scoped_refptr<TestTaskRunner> task_runner,
|
| + int32_t value) {
|
| + EXPECT_EQ(expected_value, value);
|
| + DoSetFlagAndQuitTaskRunner(flag, task_runner);
|
| +}
|
| +
|
| +void DoExpectValueSetFlagForwardValueAndQuitTaskRunner(
|
| + int32_t expected_value,
|
| + bool* flag,
|
| + scoped_refptr<TestTaskRunner> task_runner,
|
| + int32_t value,
|
| + const IntegerSender::EchoCallback& callback) {
|
| + EXPECT_EQ(expected_value, value);
|
| + *flag = true;
|
| + callback.Run(value);
|
| + task_runner->Quit();
|
| +}
|
| +
|
| +base::Closure SetFlagAndQuitTaskRunner(
|
| + bool* flag,
|
| + scoped_refptr<TestTaskRunner> task_runner) {
|
| + return base::Bind(&DoSetFlagAndQuitTaskRunner, flag, task_runner);
|
| +}
|
| +
|
| +base::Callback<void(int32_t)> ExpectValueSetFlagAndQuitTaskRunner(
|
| + int32_t expected_value,
|
| + bool* flag,
|
| + scoped_refptr<TestTaskRunner> task_runner) {
|
| + return base::Bind(&DoExpectValueSetFlagAndQuitTaskRunner, expected_value,
|
| + flag, task_runner);
|
| +}
|
| +
|
| TEST_F(BindTaskRunnerTest, MethodCall) {
|
| bool echo_called = false;
|
| impl_->set_echo_handler(
|
| - [&, this](int32_t value, const IntegerSender::EchoCallback& callback) {
|
| - EXPECT_EQ(1024, value);
|
| - echo_called = true;
|
| - callback.Run(value);
|
| - binding_task_runner_->Quit();
|
| - });
|
| -
|
| + base::Bind(&DoExpectValueSetFlagForwardValueAndQuitTaskRunner,
|
| + 1024, &echo_called, binding_task_runner_));
|
| bool echo_replied = false;
|
| - ptr_->Echo(1024, [&, this](int32_t value) {
|
| - EXPECT_EQ(1024, value);
|
| - echo_replied = true;
|
| - ptr_task_runner_->Quit();
|
| - });
|
| + ptr_->Echo(1024, ExpectValueSetFlagAndQuitTaskRunner(1024, &echo_replied,
|
| + ptr_task_runner_));
|
| binding_task_runner_->Run();
|
| EXPECT_TRUE(echo_called);
|
| ptr_task_runner_->Run();
|
| @@ -259,11 +300,8 @@ TEST_F(BindTaskRunnerTest, MethodCall) {
|
|
|
| TEST_F(BindTaskRunnerTest, BindingConnectionError) {
|
| bool connection_error_called = false;
|
| - impl_->binding()->set_connection_error_handler([&, this]() {
|
| - connection_error_called = true;
|
| - binding_task_runner_->Quit();
|
| - });
|
| -
|
| + impl_->binding()->set_connection_error_handler(
|
| + SetFlagAndQuitTaskRunner(&connection_error_called, binding_task_runner_));
|
| ptr_.reset();
|
| binding_task_runner_->Run();
|
| EXPECT_TRUE(connection_error_called);
|
| @@ -271,30 +309,30 @@ TEST_F(BindTaskRunnerTest, BindingConnectionError) {
|
|
|
| TEST_F(BindTaskRunnerTest, PtrConnectionError) {
|
| bool connection_error_called = false;
|
| - ptr_.set_connection_error_handler([&, this]() {
|
| - connection_error_called = true;
|
| - ptr_task_runner_->Quit();
|
| - });
|
| -
|
| + ptr_.set_connection_error_handler(
|
| + SetFlagAndQuitTaskRunner(&connection_error_called, ptr_task_runner_));
|
| impl_->binding()->Close();
|
| ptr_task_runner_->Run();
|
| EXPECT_TRUE(connection_error_called);
|
| }
|
|
|
| +void ExpectValueSetFlagAndForward(int32_t expected_value,
|
| + bool* flag,
|
| + int32_t value,
|
| + const IntegerSender::EchoCallback& callback) {
|
| + EXPECT_EQ(expected_value, value);
|
| + *flag = true;
|
| + callback.Run(value);
|
| +}
|
| +
|
| TEST_F(AssociatedBindTaskRunnerTest, MethodCall) {
|
| bool echo_called = false;
|
| connection_impl_->sender_impl()->set_echo_handler(
|
| - [&](int32_t value, const IntegerSender::EchoCallback& callback) {
|
| - EXPECT_EQ(1024, value);
|
| - echo_called = true;
|
| - callback.Run(value);
|
| - });
|
| + base::Bind(&ExpectValueSetFlagAndForward, 1024, &echo_called));
|
|
|
| bool echo_replied = false;
|
| - sender_ptr_->Echo(1024, [&](int32_t value) {
|
| - EXPECT_EQ(1024, value);
|
| - echo_replied = true;
|
| - });
|
| + sender_ptr_->Echo(
|
| + 1024, ExpectValueSetFlagAndQuitTaskRunner(1024, &echo_replied, nullptr));
|
|
|
| // The Echo request first arrives at the master endpoint's task runner, and
|
| // then is forwarded to the associated endpoint's task runner.
|
| @@ -312,22 +350,15 @@ TEST_F(AssociatedBindTaskRunnerTest, MethodCall) {
|
| TEST_F(AssociatedBindTaskRunnerTest, BindingConnectionError) {
|
| bool sender_impl_error = false;
|
| connection_impl_->sender_impl()->binding()->set_connection_error_handler(
|
| - [&, this]() {
|
| - sender_impl_error = true;
|
| - sender_binding_task_runner_->Quit();
|
| - });
|
| -
|
| + SetFlagAndQuitTaskRunner(&sender_impl_error,
|
| + sender_binding_task_runner_));
|
| bool connection_impl_error = false;
|
| - connection_impl_->binding()->set_connection_error_handler([&, this]() {
|
| - connection_impl_error = true;
|
| - connection_binding_task_runner_->Quit();
|
| - });
|
| -
|
| + connection_impl_->binding()->set_connection_error_handler(
|
| + SetFlagAndQuitTaskRunner(&connection_impl_error,
|
| + connection_binding_task_runner_));
|
| bool sender_ptr_error = false;
|
| - sender_ptr_.set_connection_error_handler([&, this]() {
|
| - sender_ptr_error = true;
|
| - sender_ptr_task_runner_->Quit();
|
| - });
|
| + sender_ptr_.set_connection_error_handler(
|
| + SetFlagAndQuitTaskRunner(&sender_ptr_error, sender_ptr_task_runner_));
|
| connection_ptr_.reset();
|
| sender_ptr_task_runner_->Run();
|
| EXPECT_TRUE(sender_ptr_error);
|
| @@ -340,22 +371,15 @@ TEST_F(AssociatedBindTaskRunnerTest, BindingConnectionError) {
|
| TEST_F(AssociatedBindTaskRunnerTest, PtrConnectionError) {
|
| bool sender_impl_error = false;
|
| connection_impl_->sender_impl()->binding()->set_connection_error_handler(
|
| - [&, this]() {
|
| - sender_impl_error = true;
|
| - sender_binding_task_runner_->Quit();
|
| - });
|
| -
|
| + SetFlagAndQuitTaskRunner(&sender_impl_error,
|
| + sender_binding_task_runner_));
|
| bool connection_ptr_error = false;
|
| - connection_ptr_.set_connection_error_handler([&, this]() {
|
| - connection_ptr_error = true;
|
| - connection_ptr_task_runner_->Quit();
|
| - });
|
| -
|
| + connection_ptr_.set_connection_error_handler(
|
| + SetFlagAndQuitTaskRunner(&connection_ptr_error,
|
| + connection_ptr_task_runner_));
|
| bool sender_ptr_error = false;
|
| - sender_ptr_.set_connection_error_handler([&, this]() {
|
| - sender_ptr_error = true;
|
| - sender_ptr_task_runner_->Quit();
|
| - });
|
| + sender_ptr_.set_connection_error_handler(
|
| + SetFlagAndQuitTaskRunner(&sender_ptr_error, sender_ptr_task_runner_));
|
| connection_impl_->binding()->Close();
|
| sender_binding_task_runner_->Run();
|
| EXPECT_TRUE(sender_impl_error);
|
|
|