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

Unified Diff: chrome/browser/search/suggestions/suggestions_service_unittest.cc

Issue 298703009: SuggestionsService blacklist handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Missed renaming. Created 6 years, 7 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 | « chrome/browser/search/suggestions/suggestions_service.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/search/suggestions/suggestions_service_unittest.cc
diff --git a/chrome/browser/search/suggestions/suggestions_service_unittest.cc b/chrome/browser/search/suggestions/suggestions_service_unittest.cc
index 913927feb67944f43b5632fc1701f53ba18637b1..a5e7b3bf4b91372ec4b9df81cf682bd64640fe72 100644
--- a/chrome/browser/search/suggestions/suggestions_service_unittest.cc
+++ b/chrome/browser/search/suggestions/suggestions_service_unittest.cc
@@ -29,9 +29,12 @@
namespace {
const char kFakeSuggestionsURL[] = "https://mysuggestions.com/proto";
+const char kFakeSuggestionsSuffix[] = "?foo=bar";
+const char kFakeBlacklistSuffix[] = "/blacklist?foo=bar&baz=";
const char kTestTitle[] = "a title";
const char kTestUrl[] = "http://go.com";
+const char kBlacklistUrl[] = "http://blacklist.com";
scoped_ptr<net::FakeURLFetcher> CreateURLFetcher(
const GURL& url, net::URLFetcherDelegate* delegate,
@@ -53,6 +56,18 @@ scoped_ptr<net::FakeURLFetcher> CreateURLFetcher(
namespace suggestions {
+namespace {
+
+scoped_ptr<SuggestionsProfile> CreateSuggestionsProfile() {
+ scoped_ptr<SuggestionsProfile> profile(new SuggestionsProfile());
+ ChromeSuggestion* suggestion = profile->add_suggestions();
+ suggestion->set_title(kTestTitle);
+ suggestion->set_url(kTestUrl);
+ return profile.Pass();
+}
+
+} // namespace
+
class SuggestionsServiceTest : public testing::Test {
public:
void CheckSuggestionsData(const SuggestionsProfile& suggestions_profile) {
@@ -80,7 +95,9 @@ class SuggestionsServiceTest : public testing::Test {
virtual ~SuggestionsServiceTest() {}
// Enables the "ChromeSuggestions.Group1" field trial.
- void EnableFieldTrial(const std::string& url) {
+ void EnableFieldTrial(const std::string& url,
+ const std::string& suggestions_suffix,
+ const std::string& blacklist_suffix) {
// Clear the existing |field_trial_list_| to avoid firing a DCHECK.
field_trial_list_.reset(NULL);
field_trial_list_.reset(
@@ -91,6 +108,8 @@ class SuggestionsServiceTest : public testing::Test {
params[kSuggestionsFieldTrialStateParam] =
kSuggestionsFieldTrialStateEnabled;
params[kSuggestionsFieldTrialURLParam] = url;
+ params[kSuggestionsFieldTrialSuggestionsSuffixParam] = suggestions_suffix;
+ params[kSuggestionsFieldTrialBlacklistSuffixParam] = blacklist_suffix;
chrome_variations::AssociateVariationParams(kSuggestionsFieldTrialName,
"Group1", params);
field_trial_ = base::FieldTrialList::CreateFieldTrial(
@@ -122,22 +141,23 @@ TEST_F(SuggestionsServiceTest, ServiceBeingCreated) {
EXPECT_TRUE(CreateSuggestionsService() == NULL);
// Field trial enabled.
- EnableFieldTrial("");
+ EnableFieldTrial("", "", "");
EXPECT_TRUE(CreateSuggestionsService() != NULL);
}
TEST_F(SuggestionsServiceTest, FetchSuggestionsData) {
// Field trial enabled with a specific suggestions URL.
- EnableFieldTrial(kFakeSuggestionsURL);
+ EnableFieldTrial(kFakeSuggestionsURL, kFakeSuggestionsSuffix,
+ kFakeBlacklistSuffix);
SuggestionsService* suggestions_service = CreateSuggestionsService();
EXPECT_TRUE(suggestions_service != NULL);
- SuggestionsProfile suggestions_profile;
- ChromeSuggestion* suggestion = suggestions_profile.add_suggestions();
- suggestion->set_title(kTestTitle);
- suggestion->set_url(kTestUrl);
- factory_.SetFakeResponse(GURL(kFakeSuggestionsURL),
- suggestions_profile.SerializeAsString(),
+ std::string expected_url = std::string(kFakeSuggestionsURL) +
+ kFakeSuggestionsSuffix;
+ scoped_ptr<SuggestionsProfile> suggestions_profile(
+ CreateSuggestionsProfile());
+ factory_.SetFakeResponse(GURL(expected_url),
+ suggestions_profile->SerializeAsString(),
net::HTTP_OK,
net::URLRequestStatus::SUCCESS);
@@ -160,12 +180,15 @@ TEST_F(SuggestionsServiceTest, FetchSuggestionsData) {
TEST_F(SuggestionsServiceTest, FetchSuggestionsDataRequestError) {
// Field trial enabled with a specific suggestions URL.
- EnableFieldTrial(kFakeSuggestionsURL);
+ EnableFieldTrial(kFakeSuggestionsURL, kFakeSuggestionsSuffix,
+ kFakeBlacklistSuffix);
SuggestionsService* suggestions_service = CreateSuggestionsService();
EXPECT_TRUE(suggestions_service != NULL);
// Fake a request error.
- factory_.SetFakeResponse(GURL(kFakeSuggestionsURL),
+ std::string expected_url = std::string(kFakeSuggestionsURL) +
+ kFakeSuggestionsSuffix;
+ factory_.SetFakeResponse(GURL(expected_url),
"irrelevant",
net::HTTP_OK,
net::URLRequestStatus::FAILED);
@@ -184,12 +207,15 @@ TEST_F(SuggestionsServiceTest, FetchSuggestionsDataRequestError) {
TEST_F(SuggestionsServiceTest, FetchSuggestionsDataResponseNotOK) {
// Field trial enabled with a specific suggestions URL.
- EnableFieldTrial(kFakeSuggestionsURL);
+ EnableFieldTrial(kFakeSuggestionsURL, kFakeSuggestionsSuffix,
+ kFakeBlacklistSuffix);
SuggestionsService* suggestions_service = CreateSuggestionsService();
EXPECT_TRUE(suggestions_service != NULL);
// Response code != 200.
- factory_.SetFakeResponse(GURL(kFakeSuggestionsURL),
+ std::string expected_url = std::string(kFakeSuggestionsURL) +
+ kFakeSuggestionsSuffix;
+ factory_.SetFakeResponse(GURL(expected_url),
"irrelevant",
net::HTTP_BAD_REQUEST,
net::URLRequestStatus::SUCCESS);
@@ -206,4 +232,33 @@ TEST_F(SuggestionsServiceTest, FetchSuggestionsDataResponseNotOK) {
EXPECT_EQ(1, suggestions_empty_data_count_);
}
+TEST_F(SuggestionsServiceTest, BlacklistURL) {
+ EnableFieldTrial(kFakeSuggestionsURL, kFakeSuggestionsSuffix,
+ kFakeBlacklistSuffix);
+ SuggestionsService* suggestions_service = CreateSuggestionsService();
+ EXPECT_TRUE(suggestions_service != NULL);
+
+ std::string expected_url(kFakeSuggestionsURL);
+ expected_url.append(kFakeBlacklistSuffix)
+ .append(net::EscapeQueryParamValue(GURL(kBlacklistUrl).spec(), true));
+ scoped_ptr<SuggestionsProfile> suggestions_profile(
+ CreateSuggestionsProfile());
+ factory_.SetFakeResponse(GURL(expected_url),
+ suggestions_profile->SerializeAsString(),
+ net::HTTP_OK,
+ net::URLRequestStatus::SUCCESS);
+
+ // Send the request. The data will be returned to the callback.
+ suggestions_service->BlacklistURL(
+ GURL(kBlacklistUrl),
+ base::Bind(&SuggestionsServiceTest::CheckSuggestionsData,
+ base::Unretained(this)));
+
+ // (Testing only) wait until blacklist request is complete.
+ base::MessageLoop::current()->RunUntilIdle();
+
+ // Ensure that CheckSuggestionsData() ran once.
+ EXPECT_EQ(1, suggestions_data_check_count_);
+}
+
} // namespace suggestions
« no previous file with comments | « chrome/browser/search/suggestions/suggestions_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698