Commit f9f21b68 authored by Ayu Ishii's avatar Ayu Ishii Committed by Commit Bot

Convert base::Bind and base::Callback in chrome/test to Once/Repeating

Fix
- SyncWebsocketFactory
- MessageCallback
- ConditionalWaitCallback

Change-Id: I9bf3e90df4a4217e158857dc90d4d7356dabcfa4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2298264Reviewed-by: default avatarTakumi Fujimoto <takumif@chromium.org>
Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Commit-Queue: Ayu Ishii <ayui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789200}
parent f9b1820a
...@@ -245,7 +245,7 @@ std::unique_ptr<SyncWebSocket> CreateMockSyncWebSocket( ...@@ -245,7 +245,7 @@ std::unique_ptr<SyncWebSocket> CreateMockSyncWebSocket(
TEST(CreateChild, MultiLevel) { TEST(CreateChild, MultiLevel) {
SyncWebSocketFactory factory = SyncWebSocketFactory factory =
base::Bind(&CreateMockSyncWebSocket, SyncWebSocket::kOk); base::BindRepeating(&CreateMockSyncWebSocket, SyncWebSocket::kOk);
// CreateChild relies on client_ being a DevToolsClientImpl, so no mocking // CreateChild relies on client_ being a DevToolsClientImpl, so no mocking
std::unique_ptr<DevToolsClientImpl> client_uptr = std::unique_ptr<DevToolsClientImpl> client_uptr =
std::make_unique<DevToolsClientImpl>(factory, "http://url", "id"); std::make_unique<DevToolsClientImpl>(factory, "http://url", "id");
...@@ -266,7 +266,7 @@ TEST(CreateChild, MultiLevel) { ...@@ -266,7 +266,7 @@ TEST(CreateChild, MultiLevel) {
TEST(CreateChild, IsNonBlocking_NoErrors) { TEST(CreateChild, IsNonBlocking_NoErrors) {
SyncWebSocketFactory factory = SyncWebSocketFactory factory =
base::Bind(&CreateMockSyncWebSocket, SyncWebSocket::kOk); base::BindRepeating(&CreateMockSyncWebSocket, SyncWebSocket::kOk);
// CreateChild relies on client_ being a DevToolsClientImpl, so no mocking // CreateChild relies on client_ being a DevToolsClientImpl, so no mocking
std::unique_ptr<DevToolsClientImpl> client_uptr = std::unique_ptr<DevToolsClientImpl> client_uptr =
std::make_unique<DevToolsClientImpl>(factory, "http://url", "id"); std::make_unique<DevToolsClientImpl>(factory, "http://url", "id");
...@@ -286,7 +286,7 @@ TEST(CreateChild, IsNonBlocking_NoErrors) { ...@@ -286,7 +286,7 @@ TEST(CreateChild, IsNonBlocking_NoErrors) {
TEST(CreateChild, Load_NoErrors) { TEST(CreateChild, Load_NoErrors) {
SyncWebSocketFactory factory = SyncWebSocketFactory factory =
base::Bind(&CreateMockSyncWebSocket, SyncWebSocket::kOk); base::BindRepeating(&CreateMockSyncWebSocket, SyncWebSocket::kOk);
// CreateChild relies on client_ being a DevToolsClientImpl, so no mocking // CreateChild relies on client_ being a DevToolsClientImpl, so no mocking
std::unique_ptr<DevToolsClientImpl> client_uptr = std::unique_ptr<DevToolsClientImpl> client_uptr =
std::make_unique<DevToolsClientImpl>(factory, "http://url", "id"); std::make_unique<DevToolsClientImpl>(factory, "http://url", "id");
...@@ -304,7 +304,7 @@ TEST(CreateChild, Load_NoErrors) { ...@@ -304,7 +304,7 @@ TEST(CreateChild, Load_NoErrors) {
TEST(CreateChild, WaitForPendingNavigations_NoErrors) { TEST(CreateChild, WaitForPendingNavigations_NoErrors) {
SyncWebSocketFactory factory = SyncWebSocketFactory factory =
base::Bind(&CreateMockSyncWebSocket, SyncWebSocket::kTimeout); base::BindRepeating(&CreateMockSyncWebSocket, SyncWebSocket::kTimeout);
// CreateChild relies on client_ being a DevToolsClientImpl, so no mocking // CreateChild relies on client_ being a DevToolsClientImpl, so no mocking
std::unique_ptr<DevToolsClientImpl> client_uptr = std::unique_ptr<DevToolsClientImpl> client_uptr =
std::make_unique<DevToolsClientImpl>(factory, "http://url", "id"); std::make_unique<DevToolsClientImpl>(factory, "http://url", "id");
...@@ -324,7 +324,7 @@ TEST(CreateChild, WaitForPendingNavigations_NoErrors) { ...@@ -324,7 +324,7 @@ TEST(CreateChild, WaitForPendingNavigations_NoErrors) {
TEST(CreateChild, IsPendingNavigation_NoErrors) { TEST(CreateChild, IsPendingNavigation_NoErrors) {
SyncWebSocketFactory factory = SyncWebSocketFactory factory =
base::Bind(&CreateMockSyncWebSocket, SyncWebSocket::kOk); base::BindRepeating(&CreateMockSyncWebSocket, SyncWebSocket::kOk);
// CreateChild relies on client_ being a DevToolsClientImpl, so no mocking // CreateChild relies on client_ being a DevToolsClientImpl, so no mocking
std::unique_ptr<DevToolsClientImpl> client_uptr = std::unique_ptr<DevToolsClientImpl> client_uptr =
std::make_unique<DevToolsClientImpl>(factory, "http://url", "id"); std::make_unique<DevToolsClientImpl>(factory, "http://url", "id");
......
...@@ -111,7 +111,7 @@ TEST_F(SyncWebSocketImplTest, SendReceiveTimeout) { ...@@ -111,7 +111,7 @@ TEST_F(SyncWebSocketImplTest, SendReceiveTimeout) {
base::WaitableEvent server_reply_allowed( base::WaitableEvent server_reply_allowed(
base::WaitableEvent::ResetPolicy::AUTOMATIC, base::WaitableEvent::ResetPolicy::AUTOMATIC,
base::WaitableEvent::InitialState::NOT_SIGNALED); base::WaitableEvent::InitialState::NOT_SIGNALED);
server_.SetMessageCallback(base::Bind( server_.SetMessageCallback(base::BindOnce(
&base::WaitableEvent::Wait, base::Unretained(&server_reply_allowed))); &base::WaitableEvent::Wait, base::Unretained(&server_reply_allowed)));
ASSERT_TRUE(sock.Connect(server_.web_socket_url())); ASSERT_TRUE(sock.Connect(server_.web_socket_url()));
......
...@@ -25,9 +25,7 @@ const int kBufferSize = 100 * 1024 * 1024; // 100 MB ...@@ -25,9 +25,7 @@ const int kBufferSize = 100 * 1024 * 1024; // 100 MB
TestHttpServer::TestHttpServer() TestHttpServer::TestHttpServer()
: thread_("ServerThread"), : thread_("ServerThread"),
all_closed_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, all_closed_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
base::WaitableEvent::InitialState::SIGNALED), base::WaitableEvent::InitialState::SIGNALED) {}
request_action_(kAccept),
message_action_(kEchoMessage) {}
TestHttpServer::~TestHttpServer() { TestHttpServer::~TestHttpServer() {
} }
...@@ -74,9 +72,9 @@ void TestHttpServer::SetMessageAction(WebSocketMessageAction action) { ...@@ -74,9 +72,9 @@ void TestHttpServer::SetMessageAction(WebSocketMessageAction action) {
message_action_ = action; message_action_ = action;
} }
void TestHttpServer::SetMessageCallback(const base::Closure& callback) { void TestHttpServer::SetMessageCallback(base::OnceClosure callback) {
base::AutoLock lock(action_lock_); base::AutoLock lock(action_lock_);
message_callback_ = callback; message_callback_ = std::move(callback);
} }
GURL TestHttpServer::web_socket_url() const { GURL TestHttpServer::web_socket_url() const {
...@@ -116,14 +114,12 @@ void TestHttpServer::OnWebSocketRequest( ...@@ -116,14 +114,12 @@ void TestHttpServer::OnWebSocketRequest(
void TestHttpServer::OnWebSocketMessage(int connection_id, std::string data) { void TestHttpServer::OnWebSocketMessage(int connection_id, std::string data) {
WebSocketMessageAction action; WebSocketMessageAction action;
base::Closure callback;
{ {
base::AutoLock lock(action_lock_); base::AutoLock lock(action_lock_);
action = message_action_; action = message_action_;
callback = std::move(message_callback_);
} }
if (!callback.is_null()) if (!message_callback_.is_null())
callback.Run(); std::move(message_callback_).Run();
switch (action) { switch (action) {
case kEchoMessage: case kEchoMessage:
server_->SendOverWebSocket(connection_id, data, server_->SendOverWebSocket(connection_id, data,
......
...@@ -58,7 +58,7 @@ class TestHttpServer : public net::HttpServer::Delegate { ...@@ -58,7 +58,7 @@ class TestHttpServer : public net::HttpServer::Delegate {
void SetMessageAction(WebSocketMessageAction action); void SetMessageAction(WebSocketMessageAction action);
// Sets a callback to be called once when receiving next WebSocket message. // Sets a callback to be called once when receiving next WebSocket message.
void SetMessageCallback(const base::Closure& callback); void SetMessageCallback(base::OnceClosure callback);
// Returns the web socket URL that points to the server. // Returns the web socket URL that points to the server.
GURL web_socket_url() const; GURL web_socket_url() const;
...@@ -92,9 +92,9 @@ class TestHttpServer : public net::HttpServer::Delegate { ...@@ -92,9 +92,9 @@ class TestHttpServer : public net::HttpServer::Delegate {
// Protects the action flags and |message_callback_|. // Protects the action flags and |message_callback_|.
base::Lock action_lock_; base::Lock action_lock_;
WebSocketRequestAction request_action_; WebSocketRequestAction request_action_ = kAccept;
WebSocketMessageAction message_action_; WebSocketMessageAction message_action_ = kEchoMessage;
base::Closure message_callback_; base::OnceClosure message_callback_;
DISALLOW_COPY_AND_ASSIGN(TestHttpServer); DISALLOW_COPY_AND_ASSIGN(TestHttpServer);
}; };
......
...@@ -80,7 +80,7 @@ void MediaRouterBaseBrowserTest::UninstallMRExtension() { ...@@ -80,7 +80,7 @@ void MediaRouterBaseBrowserTest::UninstallMRExtension() {
bool MediaRouterBaseBrowserTest::ConditionalWait( bool MediaRouterBaseBrowserTest::ConditionalWait(
base::TimeDelta timeout, base::TimeDelta timeout,
base::TimeDelta interval, base::TimeDelta interval,
const base::Callback<bool(void)>& callback) { const base::RepeatingCallback<bool(void)>& callback) {
base::ElapsedTimer timer; base::ElapsedTimer timer;
do { do {
if (callback.Run()) if (callback.Run())
......
...@@ -57,7 +57,7 @@ class MediaRouterBaseBrowserTest : public extensions::ExtensionBrowserTest, ...@@ -57,7 +57,7 @@ class MediaRouterBaseBrowserTest : public extensions::ExtensionBrowserTest,
// TODO(leilei): Replace this method with WaitableEvent class. // TODO(leilei): Replace this method with WaitableEvent class.
bool ConditionalWait(base::TimeDelta timeout, bool ConditionalWait(base::TimeDelta timeout,
base::TimeDelta interval, base::TimeDelta interval,
const base::Callback<bool(void)>& callback); const base::RepeatingCallback<bool(void)>& callback);
// Wait for a specific time. // Wait for a specific time.
void Wait(base::TimeDelta timeout); void Wait(base::TimeDelta timeout);
......
...@@ -83,8 +83,8 @@ void MediaRouterE2EBrowserTest::CreateMediaRoute( ...@@ -83,8 +83,8 @@ void MediaRouterE2EBrowserTest::CreateMediaRoute(
// Wait for MediaSinks compatible with |source| to be discovered. // Wait for MediaSinks compatible with |source| to be discovered.
ASSERT_TRUE(ConditionalWait( ASSERT_TRUE(ConditionalWait(
base::TimeDelta::FromSeconds(30), base::TimeDelta::FromSeconds(1), base::TimeDelta::FromSeconds(30), base::TimeDelta::FromSeconds(1),
base::Bind(&MediaRouterE2EBrowserTest::IsSinkDiscovered, base::BindRepeating(&MediaRouterE2EBrowserTest::IsSinkDiscovered,
base::Unretained(this)))); base::Unretained(this))));
const auto& sink_map = observer_->sink_map; const auto& sink_map = observer_->sink_map;
const auto it = sink_map.find(receiver_); const auto it = sink_map.find(receiver_);
...@@ -100,8 +100,8 @@ void MediaRouterE2EBrowserTest::CreateMediaRoute( ...@@ -100,8 +100,8 @@ void MediaRouterE2EBrowserTest::CreateMediaRoute(
// Wait for the route request to be fulfilled (and route to be started). // Wait for the route request to be fulfilled (and route to be started).
ASSERT_TRUE(ConditionalWait( ASSERT_TRUE(ConditionalWait(
base::TimeDelta::FromSeconds(30), base::TimeDelta::FromSeconds(1), base::TimeDelta::FromSeconds(30), base::TimeDelta::FromSeconds(1),
base::Bind(&MediaRouterE2EBrowserTest::IsRouteCreated, base::BindRepeating(&MediaRouterE2EBrowserTest::IsRouteCreated,
base::Unretained(this)))); base::Unretained(this))));
} }
void MediaRouterE2EBrowserTest::StopMediaRoute() { void MediaRouterE2EBrowserTest::StopMediaRoute() {
......
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