Commit 52b4544c authored by Carlos Caballero's avatar Carlos Caballero Committed by Commit Bot

Remove references of MessageLoopForIO in /chrome/test/chromedriver

MessageLoopForIO will go away soon use ScopedTaskEnvironment instead.

ScopedTaskEnvironment will per default start a ThreadPool, which should
be fine in most of the cases. If you believe your test needs to make sure
that no ThreadPool runs let me know and I will update the patch.

BUG=891670
This CL was uploaded by git cl split.

R=johnchen@chromium.org

Change-Id: I1c13ba6ccc98a17abe21e88822fcd786173e7022
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1733594
Auto-Submit: Carlos Caballero <carlscab@google.com>
Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Commit-Queue: John Chen <johnchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684184}
parent 8119ce9e
......@@ -14,9 +14,9 @@
#include "base/compiler_specific.h"
#include "base/location.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/test/scoped_task_environment.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "chrome/test/chromedriver/net/test_http_server.h"
......@@ -31,12 +31,6 @@ void OnConnectFinished(base::RunLoop* run_loop, int* save_error, int error) {
run_loop->Quit();
}
void RunPending(base::MessageLoop* loop) {
base::RunLoop run_loop;
loop->task_runner()->PostTask(FROM_HERE, run_loop.QuitClosure());
run_loop.Run();
}
class Listener : public WebSocketListener {
public:
explicit Listener(const std::vector<std::string>& messages)
......@@ -60,8 +54,7 @@ class Listener : public WebSocketListener {
class CloseListener : public WebSocketListener {
public:
explicit CloseListener(base::RunLoop* run_loop)
: run_loop_(run_loop) {}
explicit CloseListener(base::RunLoop* run_loop) : run_loop_(run_loop) {}
~CloseListener() override { EXPECT_FALSE(run_loop_); }
......@@ -97,8 +90,8 @@ class WebSocketTest : public testing::Test {
: new WebSocket(url, listener, read_buffer_size_));
base::RunLoop run_loop;
sock->Connect(base::BindOnce(&OnConnectFinished, &run_loop, &error));
loop_.task_runner()->PostDelayedTask(FROM_HERE, run_loop.QuitClosure(),
base::TimeDelta::FromSeconds(10));
scoped_task_environment_.GetMainThreadTaskRunner()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromSeconds(10));
run_loop.Run();
if (error == net::OK)
return sock;
......@@ -118,14 +111,15 @@ class WebSocketTest : public testing::Test {
ASSERT_TRUE(sock->Send(messages[i]));
}
base::RunLoop run_loop;
loop_.task_runner()->PostDelayedTask(FROM_HERE, run_loop.QuitClosure(),
base::TimeDelta::FromSeconds(10));
scoped_task_environment_.GetMainThreadTaskRunner()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromSeconds(10));
run_loop.Run();
}
void SetReadBufferSize(size_t size) { read_buffer_size_ = size; }
base::MessageLoopForIO loop_;
base::test::ScopedTaskEnvironment scoped_task_environment_{
base::test::ScopedTaskEnvironment::MainThreadType::IO};
TestHttpServer server_;
size_t read_buffer_size_ = 0;
};
......@@ -140,7 +134,7 @@ TEST_F(WebSocketTest, CreateDestroy) {
TEST_F(WebSocketTest, Connect) {
CloseListener listener(NULL);
ASSERT_TRUE(CreateWebSocket(server_.web_socket_url(), &listener));
RunPending(&loop_);
scoped_task_environment_.RunUntilIdle();
ASSERT_TRUE(server_.WaitForConnectionsToClose());
}
......@@ -153,7 +147,7 @@ TEST_F(WebSocketTest, Connect404) {
server_.SetRequestAction(TestHttpServer::kNotFound);
CloseListener listener(NULL);
ASSERT_FALSE(CreateWebSocket(server_.web_socket_url(), NULL));
RunPending(&loop_);
scoped_task_environment_.RunUntilIdle();
ASSERT_TRUE(server_.WaitForConnectionsToClose());
}
......@@ -170,8 +164,8 @@ TEST_F(WebSocketTest, CloseOnReceive) {
std::unique_ptr<WebSocket> sock(CreateConnectedWebSocket(&listener));
ASSERT_TRUE(sock);
ASSERT_TRUE(sock->Send("hi"));
loop_.task_runner()->PostDelayedTask(FROM_HERE, run_loop.QuitClosure(),
base::TimeDelta::FromSeconds(10));
scoped_task_environment_.GetMainThreadTaskRunner()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromSeconds(10));
run_loop.Run();
}
......@@ -183,8 +177,8 @@ TEST_F(WebSocketTest, CloseOnSend) {
server_.Stop();
sock->Send("hi");
loop_.task_runner()->PostDelayedTask(FROM_HERE, run_loop.QuitClosure(),
base::TimeDelta::FromSeconds(10));
scoped_task_environment_.GetMainThreadTaskRunner()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromSeconds(10));
run_loop.Run();
ASSERT_FALSE(sock->Send("hi"));
}
......
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