| 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 4849c617bcec4588e7bcd754937b0caa3ab673b0..a8391ed68408a6f28af61b3202c17d2dc42f6972 100644
|
| --- a/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
|
| +++ b/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
|
| @@ -7,13 +7,16 @@
|
|
|
| #include "base/bind.h"
|
| #include "base/callback.h"
|
| +#include "base/callback_helpers.h"
|
| #include "base/memory/ptr_util.h"
|
| #include "base/message_loop/message_loop.h"
|
| #include "base/run_loop.h"
|
| #include "base/threading/sequenced_task_runner_handle.h"
|
| #include "base/threading/thread.h"
|
| +#include "base/threading/thread_task_runner_handle.h"
|
| #include "mojo/public/cpp/bindings/binding.h"
|
| #include "mojo/public/cpp/bindings/strong_binding.h"
|
| +#include "mojo/public/cpp/bindings/tests/thread_per_task_sequenced_task_runner.h"
|
| #include "mojo/public/cpp/bindings/thread_safe_interface_ptr.h"
|
| #include "mojo/public/interfaces/bindings/tests/math_calculator.mojom.h"
|
| #include "mojo/public/interfaces/bindings/tests/sample_interfaces.mojom.h"
|
| @@ -226,44 +229,53 @@ TEST_F(InterfacePtrTest, IsBound) {
|
| EXPECT_TRUE(calc.is_bound());
|
| }
|
|
|
| -TEST_F(InterfacePtrTest, EndToEnd) {
|
| - math::CalculatorPtr calc;
|
| - MathCalculatorImpl calc_impl(MakeRequest(&calc));
|
| -
|
| - // Suppose this is instantiated in a process that has pipe1_.
|
| - MathCalculatorUI calculator_ui(std::move(calc));
|
| -
|
| - base::RunLoop run_loop, run_loop2;
|
| - calculator_ui.Add(2.0, run_loop.QuitClosure());
|
| - calculator_ui.Multiply(5.0, run_loop2.QuitClosure());
|
| - run_loop.Run();
|
| - run_loop2.Run();
|
| +class EndToEndInterfacePtrTest : public InterfacePtrTest {
|
| + public:
|
| + void RunTest(const scoped_refptr<base::SequencedTaskRunner> runner) {
|
| + base::RunLoop run_loop;
|
| + done_closure_ = run_loop.QuitClosure();
|
| + done_runner_ = base::ThreadTaskRunnerHandle::Get();
|
| + runner->PostTask(FROM_HERE,
|
| + base::Bind(&EndToEndInterfacePtrTest::RunTestImpl,
|
| + base::Unretained(this)));
|
| + run_loop.Run();
|
| + }
|
|
|
| - EXPECT_EQ(10.0, calculator_ui.GetOutput());
|
| -}
|
| + private:
|
| + void RunTestImpl() {
|
| + math::CalculatorPtr calc;
|
| + calc_impl_ = base::MakeUnique<MathCalculatorImpl>(MakeRequest(&calc));
|
| + calculator_ui_ = base::MakeUnique<MathCalculatorUI>(std::move(calc));
|
| + calculator_ui_->Add(2.0, base::Bind(&EndToEndInterfacePtrTest::AddDone,
|
| + base::Unretained(this)));
|
| + calculator_ui_->Multiply(5.0,
|
| + base::Bind(&EndToEndInterfacePtrTest::MultiplyDone,
|
| + base::Unretained(this)));
|
| + EXPECT_EQ(0.0, calculator_ui_->GetOutput());
|
| + }
|
|
|
| -TEST_F(InterfacePtrTest, EndToEnd_Synchronous) {
|
| - math::CalculatorPtr calc;
|
| - MathCalculatorImpl calc_impl(MakeRequest(&calc));
|
| + void AddDone() { EXPECT_EQ(2.0, calculator_ui_->GetOutput()); }
|
|
|
| - // Suppose this is instantiated in a process that has pipe1_.
|
| - MathCalculatorUI calculator_ui(std::move(calc));
|
| + void MultiplyDone() {
|
| + EXPECT_EQ(10.0, calculator_ui_->GetOutput());
|
| + calculator_ui_.reset();
|
| + calc_impl_.reset();
|
| + done_runner_->PostTask(FROM_HERE, base::ResetAndReturn(&done_closure_));
|
| + }
|
|
|
| - EXPECT_EQ(0.0, calculator_ui.GetOutput());
|
| + base::Closure done_closure_;
|
| + scoped_refptr<base::SingleThreadTaskRunner> done_runner_;
|
| + std::unique_ptr<MathCalculatorUI> calculator_ui_;
|
| + std::unique_ptr<MathCalculatorImpl> calc_impl_;
|
| +};
|
|
|
| - base::RunLoop run_loop;
|
| - calculator_ui.Add(2.0, run_loop.QuitClosure());
|
| - EXPECT_EQ(0.0, calculator_ui.GetOutput());
|
| - calc_impl.binding()->WaitForIncomingMethodCall();
|
| - run_loop.Run();
|
| - EXPECT_EQ(2.0, calculator_ui.GetOutput());
|
| +TEST_F(EndToEndInterfacePtrTest, EndToEnd) {
|
| + RunTest(base::ThreadTaskRunnerHandle::Get());
|
| +}
|
|
|
| - base::RunLoop run_loop2;
|
| - calculator_ui.Multiply(5.0, run_loop2.QuitClosure());
|
| - EXPECT_EQ(2.0, calculator_ui.GetOutput());
|
| - calc_impl.binding()->WaitForIncomingMethodCall();
|
| - run_loop2.Run();
|
| - EXPECT_EQ(10.0, calculator_ui.GetOutput());
|
| +TEST_F(EndToEndInterfacePtrTest, EndToEndOnSequence) {
|
| + ThreadPerTaskSequencedTaskRunnerOwner runner;
|
| + RunTest(runner.GetSequencedTaskRunner());
|
| }
|
|
|
| TEST_F(InterfacePtrTest, Movable) {
|
|
|