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