| Index: components/suggestions/suggestions_service_unittest.cc
|
| diff --git a/chrome/browser/search/suggestions/suggestions_service_unittest.cc b/components/suggestions/suggestions_service_unittest.cc
|
| similarity index 94%
|
| rename from chrome/browser/search/suggestions/suggestions_service_unittest.cc
|
| rename to components/suggestions/suggestions_service_unittest.cc
|
| index 395eb4d50b3455341963039a09718e541155f23f..d69e974fce81397db29c6339c7a0510abaa10c80 100644
|
| --- a/chrome/browser/search/suggestions/suggestions_service_unittest.cc
|
| +++ b/components/suggestions/suggestions_service_unittest.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chrome/browser/search/suggestions/suggestions_service.h"
|
| +#include "components/suggestions/suggestions_service.h"
|
|
|
| #include <map>
|
| #include <sstream>
|
| @@ -10,17 +10,17 @@
|
|
|
| #include "base/bind.h"
|
| #include "base/memory/scoped_ptr.h"
|
| +#include "base/message_loop/message_loop.h"
|
| #include "base/metrics/field_trial.h"
|
| #include "base/prefs/pref_service.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| -#include "chrome/browser/search/suggestions/blacklist_store.h"
|
| -#include "chrome/browser/search/suggestions/image_manager.h"
|
| -#include "chrome/browser/search/suggestions/proto/suggestions.pb.h"
|
| -#include "chrome/browser/search/suggestions/suggestions_service_factory.h"
|
| -#include "chrome/browser/search/suggestions/suggestions_store.h"
|
| +#include "base/test/test_simple_task_runner.h"
|
| +#include "components/suggestions/blacklist_store.h"
|
| +#include "components/suggestions/image_manager.h"
|
| +#include "components/suggestions/proto/suggestions.pb.h"
|
| +#include "components/suggestions/suggestions_store.h"
|
| #include "components/variations/entropy_provider.h"
|
| #include "components/variations/variations_associated_data.h"
|
| -#include "content/public/test/test_browser_thread_bundle.h"
|
| #include "net/http/http_response_headers.h"
|
| #include "net/http/http_status_code.h"
|
| #include "net/url_request/test_url_fetcher_factory.h"
|
| @@ -143,13 +143,14 @@ class SuggestionsServiceTest : public testing::Test {
|
| suggestions_empty_data_count_(0),
|
| factory_(NULL, base::Bind(&CreateURLFetcher)),
|
| mock_suggestions_store_(NULL),
|
| - mock_thumbnail_manager_(NULL) {}
|
| + mock_thumbnail_manager_(NULL),
|
| + task_runner_(new base::TestSimpleTaskRunner()) {}
|
|
|
| virtual ~SuggestionsServiceTest() {}
|
|
|
| virtual void SetUp() OVERRIDE {
|
| - request_context_ =
|
| - new net::TestURLRequestContextGetter(base::MessageLoopProxy::current());
|
| + request_context_ = new net::TestURLRequestContextGetter(
|
| + io_message_loop_.message_loop_proxy());
|
| }
|
|
|
| // Enables the "ChromeSuggestions.Group1" field trial.
|
| @@ -191,7 +192,8 @@ class SuggestionsServiceTest : public testing::Test {
|
| return new SuggestionsService(
|
| request_context_, scoped_ptr<SuggestionsStore>(mock_suggestions_store_),
|
| scoped_ptr<ImageManager>(mock_thumbnail_manager_),
|
| - scoped_ptr<BlacklistStore>(mock_blacklist_store_));
|
| + scoped_ptr<BlacklistStore>(mock_blacklist_store_),
|
| + task_runner_);
|
| }
|
|
|
| void FetchSuggestionsDataNoTimeoutHelper(bool interleaved_requests) {
|
| @@ -233,29 +235,30 @@ class SuggestionsServiceTest : public testing::Test {
|
| &SuggestionsServiceTest::CheckSuggestionsData, base::Unretained(this)));
|
|
|
| if (!interleaved_requests)
|
| - base::MessageLoop::current()->RunUntilIdle(); // Let request complete.
|
| + io_message_loop_.RunUntilIdle(); // Let request complete.
|
|
|
| // Send the request a second time.
|
| suggestions_service->FetchSuggestionsDataNoTimeout(base::Bind(
|
| &SuggestionsServiceTest::CheckSuggestionsData, base::Unretained(this)));
|
|
|
| // (Testing only) wait until suggestion fetch is complete.
|
| - base::MessageLoop::current()->RunUntilIdle();
|
| + io_message_loop_.RunUntilIdle();
|
|
|
| // Ensure that CheckSuggestionsData() ran twice.
|
| EXPECT_EQ(2, suggestions_data_check_count_);
|
| }
|
|
|
| protected:
|
| + base::MessageLoopForIO io_message_loop_;
|
| net::FakeURLFetcherFactory factory_;
|
| // Only used if the SuggestionsService is built with mocks. Not owned.
|
| MockSuggestionsStore* mock_suggestions_store_;
|
| MockImageManager* mock_thumbnail_manager_;
|
| MockBlacklistStore* mock_blacklist_store_;
|
| scoped_refptr<net::TestURLRequestContextGetter> request_context_;
|
| + scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
|
|
|
| private:
|
| - content::TestBrowserThreadBundle thread_bundle_;
|
| scoped_ptr<base::FieldTrialList> field_trial_list_;
|
| scoped_refptr<base::FieldTrial> field_trial_;
|
|
|
| @@ -309,7 +312,7 @@ TEST_F(SuggestionsServiceTest, FetchSuggestionsDataRequestError) {
|
| base::Unretained(this)));
|
|
|
| // (Testing only) wait until suggestion fetch is complete.
|
| - base::MessageLoop::current()->RunUntilIdle();
|
| + io_message_loop_.RunUntilIdle();
|
|
|
| // Ensure that ExpectEmptySuggestionsProfile ran once.
|
| EXPECT_EQ(1, suggestions_empty_data_count_);
|
| @@ -344,7 +347,7 @@ TEST_F(SuggestionsServiceTest, FetchSuggestionsDataResponseNotOK) {
|
| base::Unretained(this)));
|
|
|
| // (Testing only) wait until suggestion fetch is complete.
|
| - base::MessageLoop::current()->RunUntilIdle();
|
| + io_message_loop_.RunUntilIdle();
|
|
|
| // Ensure that ExpectEmptySuggestionsProfile ran once.
|
| EXPECT_EQ(1, suggestions_empty_data_count_);
|
| @@ -385,7 +388,7 @@ TEST_F(SuggestionsServiceTest, BlacklistURL) {
|
| base::Unretained(this)));
|
|
|
| // (Testing only) wait until blacklist request is complete.
|
| - base::MessageLoop::current()->RunUntilIdle();
|
| + io_message_loop_.RunUntilIdle();
|
|
|
| // Ensure that CheckSuggestionsData() ran once.
|
| EXPECT_EQ(1, suggestions_data_check_count_);
|
| @@ -441,7 +444,11 @@ TEST_F(SuggestionsServiceTest, BlacklistURLFails) {
|
| net::HTTP_OK, net::URLRequestStatus::SUCCESS);
|
|
|
| // (Testing only) wait until both requests are complete.
|
| - base::MessageLoop::current()->RunUntilIdle();
|
| + io_message_loop_.RunUntilIdle();
|
| + // ... Other task gets posted to TestSimpleTaskRunner.
|
| + task_runner_->RunUntilIdle();
|
| + // ... And completes.
|
| + io_message_loop_.RunUntilIdle();
|
|
|
| // Ensure that CheckSuggestionsData() ran once.
|
| EXPECT_EQ(1, suggestions_data_check_count_);
|
|
|