Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(785)

Unified Diff: components/suggestions/suggestions_service_unittest.cc

Issue 527943002: [Most Visited] Check for Sync state when using SuggestionsService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2125
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/suggestions/suggestions_service.cc ('k') | components/suggestions/suggestions_utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/suggestions/suggestions_service_unittest.cc
diff --git a/components/suggestions/suggestions_service_unittest.cc b/components/suggestions/suggestions_service_unittest.cc
index 819e92bdc3f9f42d4394b1aecc1f776de6b80f55..a4d60585866e9e7bc448099af68066cc455a56ed 100644
--- a/components/suggestions/suggestions_service_unittest.cc
+++ b/components/suggestions/suggestions_service_unittest.cc
@@ -18,6 +18,7 @@
#include "components/suggestions/image_manager.h"
#include "components/suggestions/proto/suggestions.pb.h"
#include "components/suggestions/suggestions_store.h"
+#include "components/suggestions/suggestions_utils.h"
#include "components/variations/entropy_provider.h"
#include "components/variations/variations_associated_data.h"
#include "net/http/http_response_headers.h"
@@ -326,6 +327,7 @@ TEST_F(SuggestionsServiceTest, FetchSuggestionsDataRequestError) {
// Send the request. Empty data will be returned to the callback.
suggestions_service->FetchSuggestionsData(
+ INITIALIZED_ENABLED_HISTORY, // Normal mode.
base::Bind(&SuggestionsServiceTest::ExpectEmptySuggestionsProfile,
base::Unretained(this)));
@@ -361,6 +363,7 @@ TEST_F(SuggestionsServiceTest, FetchSuggestionsDataResponseNotOK) {
// Send the request. Empty data will be returned to the callback.
suggestions_service->FetchSuggestionsData(
+ INITIALIZED_ENABLED_HISTORY, // Normal mode.
base::Bind(&SuggestionsServiceTest::ExpectEmptySuggestionsProfile,
base::Unretained(this)));
@@ -371,6 +374,62 @@ TEST_F(SuggestionsServiceTest, FetchSuggestionsDataResponseNotOK) {
EXPECT_EQ(1, suggestions_empty_data_count_);
}
+TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncDisabled) {
+ // Field trial enabled with a specific suggestions URL.
+ EnableFieldTrial(kFakeSuggestionsURL, kFakeSuggestionsCommonParams,
+ kFakeBlacklistPath, kFakeBlacklistUrlParam, false);
+ scoped_ptr<SuggestionsService> suggestions_service(
+ CreateSuggestionsServiceWithMocks());
+ EXPECT_TRUE(suggestions_service != NULL);
+
+ // Set up expectations on the SuggestionsStore.
+ EXPECT_CALL(*mock_suggestions_store_, ClearSuggestions());
+
+ // Send the request. Cache is cleared and empty data will be returned to the
+ // callback.
+ suggestions_service->FetchSuggestionsData(
+ SYNC_OR_HISTORY_SYNC_DISABLED,
+ base::Bind(&SuggestionsServiceTest::ExpectEmptySuggestionsProfile,
+ base::Unretained(this)));
+
+ // Wait for posted task to complete.
+ base::MessageLoop::current()->RunUntilIdle();
+
+ // Ensure that ExpectEmptySuggestionsProfile ran once.
+ EXPECT_EQ(1, suggestions_empty_data_count_);
+}
+
+TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitializedEnabled) {
+ // Field trial enabled with a specific suggestions URL.
+ EnableFieldTrial(kFakeSuggestionsURL, kFakeSuggestionsCommonParams,
+ kFakeBlacklistPath, kFakeBlacklistUrlParam, false);
+ scoped_ptr<SuggestionsService> suggestions_service(
+ CreateSuggestionsServiceWithMocks());
+ EXPECT_TRUE(suggestions_service != NULL);
+ scoped_ptr<SuggestionsProfile> suggestions_profile(
+ CreateSuggestionsProfile());
+
+ // Expectations.
+ EXPECT_CALL(*mock_suggestions_store_, LoadSuggestions(_))
+ .WillOnce(DoAll(SetArgPointee<0>(*suggestions_profile), Return(true)));
+ EXPECT_CALL(*mock_thumbnail_manager_,
+ Initialize(EqualsProto(*suggestions_profile)));
+ EXPECT_CALL(*mock_blacklist_store_, FilterSuggestions(_));
+
+ // Send the request. In this state, cached data will be returned to the
+ // caller.
+ suggestions_service->FetchSuggestionsData(
+ NOT_INITIALIZED_ENABLED,
+ base::Bind(&SuggestionsServiceTest::CheckSuggestionsData,
+ base::Unretained(this)));
+
+ // Wait for posted task to complete.
+ base::MessageLoop::current()->RunUntilIdle();
+
+ // Ensure that CheckSuggestionsData ran once.
+ EXPECT_EQ(1, suggestions_data_check_count_);
+}
+
TEST_F(SuggestionsServiceTest, BlacklistURL) {
EnableFieldTrial(kFakeSuggestionsURL, kFakeSuggestionsCommonParams,
kFakeBlacklistPath, kFakeBlacklistUrlParam, false);
« no previous file with comments | « components/suggestions/suggestions_service.cc ('k') | components/suggestions/suggestions_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698