Commit 6d3b0b6a authored by leon.han's avatar leon.han Committed by Commit bot

Use spin runloop instead of WaitForIncomingMethodCall() for test codes.

This CL replaces usage of Binding::WaitForIncomingMethodCall() with
a spin runloop waiting for incoming call or a connection error.
Affected test codes are within:
  components/arc/
  services/shell/

BUG=622438

Review-Url: https://codereview.chromium.org/2135223002
Cr-Commit-Position: refs/heads/master@{#407029}
parent 1beda3d2
......@@ -6,6 +6,8 @@
#include <utility>
#include "base/run_loop.h"
namespace arc {
FakeArcBridgeInstance::FakeArcBridgeInstance() : binding_(this) {}
......@@ -14,6 +16,11 @@ FakeArcBridgeInstance::~FakeArcBridgeInstance() {}
void FakeArcBridgeInstance::Init(mojom::ArcBridgeHostPtr host) {
host_ptr_ = std::move(host);
init_calls_++;
// Wake WaitForInitCall().
if (!quit_closure_.is_null())
quit_closure_.Run();
quit_closure_.Reset();
}
void FakeArcBridgeInstance::Unbind() {
......@@ -28,7 +35,10 @@ void FakeArcBridgeInstance::Bind(
}
void FakeArcBridgeInstance::WaitForInitCall() {
binding_.WaitForIncomingMethodCall();
base::RunLoop run_loop;
quit_closure_ = run_loop.QuitClosure();
binding_.set_connection_error_handler(run_loop.QuitClosure());
run_loop.Run();
}
void FakeArcBridgeInstance::Stop(ArcBridgeService::StopReason reason) {
......
......@@ -5,6 +5,7 @@
#ifndef COMPONENTS_ARC_TEST_FAKE_ARC_BRIDGE_INSTANCE_H_
#define COMPONENTS_ARC_TEST_FAKE_ARC_BRIDGE_INSTANCE_H_
#include "base/callback_forward.h"
#include "base/macros.h"
#include "components/arc/arc_bridge_service.h"
#include "components/arc/common/arc_bridge.mojom.h"
......@@ -47,6 +48,9 @@ class FakeArcBridgeInstance : public mojom::ArcBridgeInstance {
private:
Delegate* delegate_ = nullptr;
// Keeps quit closure to wake the running nested RunLoop.
base::Closure quit_closure_;
// Mojo endpoints.
mojo::Binding<mojom::ArcBridgeInstance> binding_;
mojom::ArcBridgeHostPtr host_ptr_;
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/macros.h"
#include "base/run_loop.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/shell/public/cpp/connector.h"
......@@ -52,7 +53,12 @@ class ShutdownClientApp
service->SetClient(std::move(client_ptr));
client_binding.WaitForIncomingMethodCall();
base::MessageLoop::ScopedNestableTaskAllower nestable_allower(
base::MessageLoop::current());
base::RunLoop run_loop;
client_binding.set_connection_error_handler(run_loop.QuitClosure());
run_loop.Run();
callback.Run();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment