Commit d8e00974 authored by Carlos Caballero's avatar Carlos Caballero Committed by Commit Bot

Use ScopedTaskEnvironment instead of MessageLoop

MessageLoop will go away, eventually.

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

DO NOT SUBMMIT

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

R=rmcelrath@chromium.org

Change-Id: Iccef22a70c2f7465a6a3da5bb717c18922d8065a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1635517
Auto-Submit: Carlos Caballero <carlscab@google.com>
Reviewed-by: default avatarRobbie McElrath <rmcelrath@chromium.org>
Commit-Queue: Robbie McElrath <rmcelrath@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664700}
parent 66e52c3a
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/test/scoped_task_environment.h"
#include "base/test/test_mock_time_task_runner.h" #include "base/test/test_mock_time_task_runner.h"
#include "net/base/chunked_upload_data_stream.h" #include "net/base/chunked_upload_data_stream.h"
#include "net/base/completion_repeating_callback.h" #include "net/base/completion_repeating_callback.h"
...@@ -58,8 +58,7 @@ class TestCallback { ...@@ -58,8 +58,7 @@ class TestCallback {
class ThrottlingControllerTestHelper { class ThrottlingControllerTestHelper {
public: public:
ThrottlingControllerTestHelper() ThrottlingControllerTestHelper()
: task_runner_(base::MakeRefCounted<base::TestMockTimeTaskRunner>()), : completion_callback_(base::BindRepeating(&TestCallback::Run,
completion_callback_(base::BindRepeating(&TestCallback::Run,
base::Unretained(&callback_))), base::Unretained(&callback_))),
mock_transaction_(kSimpleGET_Transaction), mock_transaction_(kSimpleGET_Transaction),
buffer_(base::MakeRefCounted<net::IOBuffer>(64)), buffer_(base::MakeRefCounted<net::IOBuffer>(64)),
...@@ -77,7 +76,6 @@ class ThrottlingControllerTestHelper { ...@@ -77,7 +76,6 @@ class ThrottlingControllerTestHelper {
&network_transaction); &network_transaction);
transaction_.reset( transaction_.reset(
new ThrottlingNetworkTransaction(std::move(network_transaction))); new ThrottlingNetworkTransaction(std::move(network_transaction)));
message_loop_.SetTaskRunner(task_runner_);
} }
void SetNetworkState(bool offline, double download, double upload) { void SetNetworkState(bool offline, double download, double upload) {
...@@ -145,12 +143,12 @@ class ThrottlingControllerTestHelper { ...@@ -145,12 +143,12 @@ class ThrottlingControllerTestHelper {
ThrottlingNetworkTransaction* transaction() { return transaction_.get(); } ThrottlingNetworkTransaction* transaction() { return transaction_.get(); }
void FastForwardUntilNoTasksRemain() { void FastForwardUntilNoTasksRemain() {
task_runner_->FastForwardUntilNoTasksRemain(); scoped_task_environment_.FastForwardUntilNoTasksRemain();
} }
private: private:
scoped_refptr<base::TestMockTimeTaskRunner> task_runner_; base::test::ScopedTaskEnvironment scoped_task_environment_{
base::MessageLoop message_loop_; base::test::ScopedTaskEnvironment::MainThreadType::MOCK_TIME};
MockNetworkLayer network_layer_; MockNetworkLayer network_layer_;
TestCallback callback_; TestCallback callback_;
net::CompletionRepeatingCallback completion_callback_; net::CompletionRepeatingCallback completion_callback_;
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#include <vector> #include <vector>
#include "base/message_loop/message_loop.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/test/scoped_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace network { namespace network {
...@@ -16,7 +16,7 @@ namespace { ...@@ -16,7 +16,7 @@ namespace {
class WebSocketThrottlerTest : public ::testing::Test { class WebSocketThrottlerTest : public ::testing::Test {
private: private:
base::MessageLoop message_loop_; base::test::ScopedTaskEnvironment scoped_task_environment_;
}; };
TEST(WebSocketPerProcessThrottlerTest, InitialState) { TEST(WebSocketPerProcessThrottlerTest, InitialState) {
......
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