Commit 2e9e9411 authored by Carlos Caballero's avatar Carlos Caballero Committed by Commit Bot

Use ScopedTaskEnvironment instead of MessageLoop in /components/offline_pages

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.

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

R=chili@chromium.org

Change-Id: Id6421b96347e3bfac890f039bcda4aa8329f27b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1649578
Auto-Submit: Carlos Caballero <carlscab@google.com>
Reviewed-by: default avatarCathy Li <chili@chromium.org>
Commit-Queue: Cathy Li <chili@chromium.org>
Cr-Commit-Position: refs/heads/master@{#667201}
parent 1b914b54
......@@ -7,8 +7,7 @@
#include <utility>
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/test/test_simple_task_runner.h"
#include "base/test/scoped_task_environment.h"
#include "components/gcm_driver/instance_id/instance_id.h"
#include "components/offline_pages/core/prefetch/prefetch_service_test_taco.h"
#include "components/offline_pages/core/prefetch/test_prefetch_dispatcher.h"
......@@ -35,11 +34,7 @@ class TestTokenFactory : public PrefetchGCMAppHandler::TokenFactory {
class PrefetchGCMAppHandlerTest : public testing::Test {
public:
PrefetchGCMAppHandlerTest() : task_runner_(new base::TestSimpleTaskRunner) {
message_loop_.SetTaskRunner(task_runner_);
}
void SetUp() override {
PrefetchGCMAppHandlerTest() {
auto dispatcher = std::make_unique<TestPrefetchDispatcher>();
test_dispatcher_ = dispatcher.get();
......@@ -56,10 +51,10 @@ class PrefetchGCMAppHandlerTest : public testing::Test {
prefetch_service_taco_->CreatePrefetchService();
}
void TearDown() override {
~PrefetchGCMAppHandlerTest() override {
// Ensures that the store is properly disposed off.
prefetch_service_taco_.reset();
task_runner_->RunUntilIdle();
scoped_task_environment_.RunUntilIdle();
}
TestPrefetchDispatcher* dispatcher() { return test_dispatcher_; }
......@@ -67,8 +62,7 @@ class PrefetchGCMAppHandlerTest : public testing::Test {
TestTokenFactory* token_factory() { return token_factory_; }
private:
base::MessageLoop message_loop_;
scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
base::test::ScopedTaskEnvironment scoped_task_environment_;
std::unique_ptr<PrefetchServiceTestTaco> prefetch_service_taco_;
// Owned by the taco.
......
......@@ -5,10 +5,8 @@
#include "components/offline_pages/core/prefetch/suggested_articles_observer.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/test_simple_task_runner.h"
#include "base/test/scoped_task_environment.h"
#include "components/offline_pages/core/client_namespace_constants.h"
#include "components/offline_pages/core/prefetch/prefetch_dispatcher.h"
#include "components/offline_pages/core/prefetch/prefetch_gcm_app_handler.h"
......@@ -41,12 +39,7 @@ ContentSuggestion ContentSuggestionFromTestURL(const GURL& test_url) {
class OfflinePageSuggestedArticlesObserverTest : public testing::Test {
public:
OfflinePageSuggestedArticlesObserverTest()
: task_runner_(new base::TestSimpleTaskRunner) {
message_loop_.SetTaskRunner(task_runner_);
}
void SetUp() override {
OfflinePageSuggestedArticlesObserverTest() {
prefetch_service_test_taco_ = std::make_unique<PrefetchServiceTestTaco>();
test_prefetch_dispatcher_ = new TestPrefetchDispatcher();
prefetch_service_test_taco_->SetPrefetchDispatcher(
......@@ -56,10 +49,10 @@ class OfflinePageSuggestedArticlesObserverTest : public testing::Test {
prefetch_service_test_taco_->CreatePrefetchService();
}
void TearDown() override {
~OfflinePageSuggestedArticlesObserverTest() override {
// Ensure the store can be properly disposed off.
prefetch_service_test_taco_.reset();
task_runner_->RunUntilIdle();
scoped_task_environment_.RunUntilIdle();
}
SuggestedArticlesObserver* observer() {
......@@ -76,8 +69,7 @@ class OfflinePageSuggestedArticlesObserverTest : public testing::Test {
Category::FromKnownCategory(ntp_snippets::KnownCategories::ARTICLES);
private:
base::MessageLoop message_loop_;
scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
base::test::ScopedTaskEnvironment scoped_task_environment_;
std::unique_ptr<PrefetchServiceTestTaco> prefetch_service_test_taco_;
// Owned by the PrefetchServiceTestTaco.
......
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