Commit 150894ed authored by Carlos Caballero's avatar Carlos Caballero Committed by Commit Bot

[scheduling] Use ScopedTaskEnvironment instead of MessageLoop in dom_distiller

MessageLoop will go away, eventually.

BUG=891670

Change-Id: I984e218d26ca92c1f531fbec9267a0de56ea0c57
Reviewed-on: https://chromium-review.googlesource.com/c/1352422Reviewed-by: default avatarBen Greenstein <bengr@chromium.org>
Commit-Queue: Carlos Caballero <carlscab@google.com>
Cr-Commit-Position: refs/heads/master@{#612267}
parent 3d0a07f6
......@@ -7,8 +7,8 @@
#include <utility>
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/test/scoped_task_environment.h"
#include "components/dom_distiller/core/article_entry.h"
#include "components/dom_distiller/core/proto/distilled_article.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -78,7 +78,7 @@ class InMemoryContentStoreTest : public testing::Test {
// Tests whether saving and then loading a single article works as expected.
TEST_F(InMemoryContentStoreTest, SaveAndLoadSingleArticle) {
base::MessageLoop loop;
base::test::ScopedTaskEnvironment task_environment;
const ArticleEntry entry = CreateEntry("test-id", "url1", "url2", "url3");
const DistilledArticleProto stored_proto =
CreateDistilledArticleForEntry(entry);
......@@ -102,7 +102,7 @@ TEST_F(InMemoryContentStoreTest, SaveAndLoadSingleArticle) {
// Tests that loading articles which have never been stored, yields a callback
// where success is false.
TEST_F(InMemoryContentStoreTest, LoadNonExistentArticle) {
base::MessageLoop loop;
base::test::ScopedTaskEnvironment task_environment;
const ArticleEntry entry = CreateEntry("bogus-id", "url1", "url2", "url3");
store_->LoadContent(entry,
base::Bind(&InMemoryContentStoreTest::OnLoadCallback,
......@@ -115,7 +115,7 @@ TEST_F(InMemoryContentStoreTest, LoadNonExistentArticle) {
// of save and store does not matter when the total number of articles does not
// exceed |kDefaultMaxNumCachedEntries|.
TEST_F(InMemoryContentStoreTest, SaveAndLoadMultipleArticles) {
base::MessageLoop loop;
base::test::ScopedTaskEnvironment task_environment;
// Store first article.
const ArticleEntry first_entry = CreateEntry("first", "url1", "url2", "url3");
const DistilledArticleProto first_stored_proto =
......@@ -165,7 +165,7 @@ TEST_F(InMemoryContentStoreTest, SaveAndLoadMultipleArticles) {
// Verifies that the content store does not store unlimited number of articles,
// but expires the oldest ones when the limit for number of articles is reached.
TEST_F(InMemoryContentStoreTest, SaveAndLoadMoreThanMaxArticles) {
base::MessageLoop loop;
base::test::ScopedTaskEnvironment task_environment;
// Create a new store with only |kMaxNumArticles| articles as the limit.
const int kMaxNumArticles = 3;
......@@ -246,7 +246,7 @@ TEST_F(InMemoryContentStoreTest, SaveAndLoadMoreThanMaxArticles) {
// Tests whether saving and then loading a single article works as expected.
TEST_F(InMemoryContentStoreTest, LookupArticleByURL) {
base::MessageLoop loop;
base::test::ScopedTaskEnvironment task_environment;
const ArticleEntry entry = CreateEntry("test-id", "url1", "url2", "url3");
const DistilledArticleProto stored_proto =
CreateDistilledArticleForEntry(entry);
......@@ -283,7 +283,7 @@ TEST_F(InMemoryContentStoreTest, LookupArticleByURL) {
// Verifies that the content store does not store unlimited number of articles,
// but expires the oldest ones when the limit for number of articles is reached.
TEST_F(InMemoryContentStoreTest, LoadArticleByURLAfterExpungedFromCache) {
base::MessageLoop loop;
base::test::ScopedTaskEnvironment task_environment;
// Create a new store with only |kMaxNumArticles| articles as the limit.
const int kMaxNumArticles = 1;
......
......@@ -5,8 +5,8 @@
#include "components/dom_distiller/core/distiller_url_fetcher.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/test/scoped_task_environment.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "services/network/test/test_utils.h"
......@@ -14,10 +14,9 @@
#include "url/gurl.h"
const char kTestPageA[] = "http://www.a.com/";
const char kTestPageAResponse[] = { 1, 2, 3, 4, 5, 6, 7 };
const char kTestPageAResponse[] = {1, 2, 3, 4, 5, 6, 7};
const char kTestPageB[] = "http://www.b.com/";
const char kTestPageBResponse[] = { 'a', 'b', 'c' };
const char kTestPageBResponse[] = {'a', 'b', 'c'};
class DistillerURLFetcherTest : public testing::Test {
public:
......@@ -26,9 +25,7 @@ class DistillerURLFetcherTest : public testing::Test {
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
&test_url_loader_factory_)) {}
void FetcherCallback(const std::string& response) {
response_ = response;
}
void FetcherCallback(const std::string& response) { response_ = response; }
protected:
// testing::Test implementation:
......@@ -45,17 +42,16 @@ class DistillerURLFetcherTest : public testing::Test {
network::URLLoaderCompletionStatus(net::OK));
}
void Fetch(const std::string& url,
const std::string& expected_response) {
base::MessageLoopForUI loop;
url_fetcher_->FetchURL(
url,
base::Bind(&DistillerURLFetcherTest::FetcherCallback,
base::Unretained(this)));
void Fetch(const std::string& url, const std::string& expected_response) {
url_fetcher_->FetchURL(url,
base::Bind(&DistillerURLFetcherTest::FetcherCallback,
base::Unretained(this)));
base::RunLoop().RunUntilIdle();
CHECK_EQ(expected_response, response_);
}
base::test::ScopedTaskEnvironment task_environment_{
base::test::ScopedTaskEnvironment::MainThreadType::UI};
std::unique_ptr<dom_distiller::DistillerURLFetcher> url_fetcher_;
network::TestURLLoaderFactory test_url_loader_factory_;
scoped_refptr<network::SharedURLLoaderFactory>
......
......@@ -9,9 +9,9 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/containers/hash_tables.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/scoped_task_environment.h"
#include "components/dom_distiller/core/article_entry.h"
#include "components/dom_distiller/core/distilled_page_prefs.h"
#include "components/dom_distiller/core/dom_distiller_model.h"
......@@ -82,7 +82,6 @@ std::unique_ptr<DistilledArticleProto> CreateDefaultArticle() {
class DomDistillerServiceTest : public testing::Test {
public:
void SetUp() override {
main_loop_.reset(new base::MessageLoop());
FakeDB<ArticleEntry>* fake_db = new FakeDB<ArticleEntry>(&db_model_);
FakeDB<ArticleEntry>::EntryMap store_model;
store_ =
......@@ -106,12 +105,12 @@ class DomDistillerServiceTest : public testing::Test {
}
protected:
base::test::ScopedTaskEnvironment task_environment_;
// store is owned by service_.
DomDistillerStoreInterface* store_;
MockDistillerFactory* distiller_factory_;
MockDistillerPageFactory* distiller_page_factory_;
std::unique_ptr<DomDistillerService> service_;
std::unique_ptr<base::MessageLoop> main_loop_;
FakeDB<ArticleEntry>::EntryMap db_model_;
};
......
......@@ -13,8 +13,8 @@
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/test/scoped_task_environment.h"
#include "base/time/time.h"
#include "components/dom_distiller/core/article_entry.h"
#include "components/dom_distiller/core/dom_distiller_test_util.h"
......@@ -159,7 +159,7 @@ class DomDistillerStoreTest : public testing::Test {
return data;
}
base::MessageLoop message_loop_;
base::test::ScopedTaskEnvironment task_environment_;
EntryMap db_model_;
EntryMap sync_model_;
......
......@@ -6,8 +6,8 @@
#include <utility>
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/test/scoped_task_environment.h"
#include "components/dom_distiller/core/article_distillation_update.h"
#include "components/dom_distiller/core/article_entry.h"
#include "components/dom_distiller/core/distilled_content_store.h"
......@@ -61,7 +61,6 @@ class MockSaveCallback {
class DomDistillerTaskTrackerTest : public testing::Test {
public:
void SetUp() override {
message_loop_.reset(new base::MessageLoop());
entry_id_ = "id0";
page_0_url_ = GURL("http://www.example.com/1");
page_1_url_ = GURL("http://www.example.com/2");
......@@ -78,7 +77,7 @@ class DomDistillerTaskTrackerTest : public testing::Test {
}
protected:
std::unique_ptr<base::MessageLoop> message_loop_;
base::test::ScopedTaskEnvironment task_environment_;
std::string entry_id_;
GURL page_0_url_;
GURL page_1_url_;
......
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