Index: chrome/browser/autocomplete/search_provider_unittest.cc |
diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc |
index eafbe745b31b034b08e23aba3a52ac6e8feb8338..7953945f8a8dc62d9e4aa5781a2fb82d3ec7b2a8 100644 |
--- a/chrome/browser/autocomplete/search_provider_unittest.cc |
+++ b/chrome/browser/autocomplete/search_provider_unittest.cc |
@@ -3177,7 +3177,8 @@ TEST_F(SearchProviderTest, RemoveStaleResultsTest) { |
} else { |
provider_->default_results_.suggest_results.push_back( |
SearchProvider::SuggestResult(ASCIIToUTF16(suggestion), string16(), |
- string16(), std::string(), false, |
+ string16(), std::string(), |
+ std::string(), false, |
cases[i].results[j].relevance, |
false, false)); |
} |
@@ -3654,6 +3655,97 @@ TEST_F(SearchProviderTest, XSSIGuardedJSONParsing) { |
} |
} |
+// Test that deletion url gets set on an AutocompleteMatch when available for a |
+// personalized query. |
+TEST_F(SearchProviderTest, ParseDeletionUrl) { |
+ struct Match { |
+ std::string contents; |
+ std::string deletion_url; |
+ AutocompleteMatchType::Type type; |
+ }; |
+ |
+ const Match kEmptyMatch = { |
+ kNotApplicable, "", AutocompleteMatchType::NUM_TYPES}; |
+ |
+ const char url[] = "https://www.google.com/complete/deleteitems" |
+ "?delq=ab&client=chrome&deltok=xsrf123"; |
+ |
+ struct { |
+ const std::string input_text; |
+ const std::string response_json; |
+ const Match matches[4]; |
+ } cases[] = { |
+ // Personalized query comes with a deletion url |
+ { "a", |
+ "[\"a\",[\"ab\", \"ac\"],[],[]," |
+ "{\"google:suggesttype\":[\"PERSONALIZED_QUERY\",\"QUERY\"]," |
+ "\"google:suggestrelevance\":[1, 2]," |
+ "\"google:suggestdetail\":[{\"du\":" |
+ "\"https://www.google.com/complete/deleteitems?delq=ab&client=chrome" |
+ "&deltok=xsrf123\"}, {}]}]", |
+ { { "a", "", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED }, |
+ { "ac", "", AutocompleteMatchType::SEARCH_SUGGEST }, |
+ { "ab", url, AutocompleteMatchType::SEARCH_SUGGEST }, |
+ kEmptyMatch, |
+ }, |
+ }, |
+ // Personalized query, but no deletion url in response -- old server case |
+ { "a", |
+ "[\"a\",[\"ab\", \"ac\"],[],[]," |
+ "{\"google:suggesttype\":[\"PERSONALIZED_QUERY\",\"QUERY\"]," |
+ "\"google:suggestrelevance\":[1, 2]," |
+ "\"google:suggestdetail\":[{}, {}]}]", |
+ { { "a", "", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED }, |
+ { "ac", "", AutocompleteMatchType::SEARCH_SUGGEST }, |
+ { "ab", "", AutocompleteMatchType::SEARCH_SUGGEST }, |
+ kEmptyMatch, |
+ }, |
+ }, |
+ // Unexpected: non-personalized query comes with a deletion url, this |
+ // should be ignored. |
+ { "a", |
+ "[\"a\",[\"ab\", \"ac\"],[],[]," |
+ "{\"google:suggesttype\":[\"PERSONALIZED_QUERY\",\"QUERY\"]," |
+ "\"google:suggestrelevance\":[1, 2]," |
+ "\"google:suggestdetail\":[{\"du\":\"" |
+ "https://www.google.com/complete/deleteitems?delq=ab&" |
+ "client=chrome&deltok=xsrf123\"}, {\"du\":\"" |
+ "https://www.google.com/complete/deleteitems?delq=ab&" |
+ "client=chrome&deltok=xsrf123\"}]}]", |
+ { { "a", "", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED }, |
+ { "ac", "", AutocompleteMatchType::SEARCH_SUGGEST }, |
+ { "ab", url, AutocompleteMatchType::SEARCH_SUGGEST }, |
+ kEmptyMatch, |
+ }, |
+ }, |
+ }; |
+ |
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
+ QueryForInput(ASCIIToUTF16(cases[i].input_text), false, false); |
+ |
+ net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( |
+ SearchProvider::kDefaultProviderURLFetcherID); |
+ ASSERT_TRUE(fetcher); |
+ fetcher->set_response_code(200); |
+ fetcher->SetResponseString(cases[i].response_json); |
+ fetcher->delegate()->OnURLFetchComplete(fetcher); |
+ |
+ RunTillProviderDone(); |
+ |
+ const ACMatches& matches = provider_->matches(); |
+ ASSERT_FALSE(matches.empty()); |
+ |
+ SCOPED_TRACE("for input with json = " + cases[i].response_json); |
+ |
+ for (size_t j = 0; j < matches.size(); ++j) { |
+ const Match& match = cases[i].matches[j]; |
+ SCOPED_TRACE(" and match index: " + base::IntToString(j)); |
+ EXPECT_EQ(match.contents, UTF16ToUTF8(matches[j].contents)); |
+ EXPECT_EQ(match.deletion_url, matches[j].GetAdditionalInfo( |
+ "deletion_url")); |
+ } |
+ } |
+} |
TEST_F(SearchProviderTest, ReflectsBookmarkBarState) { |
profile_.GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, false); |
@@ -3800,3 +3892,55 @@ TEST_F(SearchProviderTest, CanSendURL) { |
GURL("https://www.google.com/complete/search"), &google_template_url, |
AutocompleteInput::OTHER, &profile_)); |
} |
+ |
+TEST_F(SearchProviderTest, TestDeleteMatch_NoDeletionUrl) { |
+ AutocompleteMatch m = AutocompleteMatch( |
+ provider_, |
+ 640, |
+ true, |
+ AutocompleteMatchType::SEARCH_SUGGEST); |
+ provider_->DeleteMatch(m); |
+ net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( |
+ SearchProvider::kDeletionURLFetcherID); |
+ // Ensure that an autocomplete match without a deletion URL does not |
+ // trigger a fetch. |
+ ASSERT_FALSE(fetcher); |
+} |
+ |
+TEST_F(SearchProviderTest, TestDeleteMatch_HasDeletionUrlSuccess) { |
+ AutocompleteMatch m = AutocompleteMatch( |
+ provider_, |
+ 640, |
+ true, |
+ AutocompleteMatchType::SEARCH_SUGGEST); |
+ m.RecordAdditionalInfo(SearchProvider::kDeletionUrlKey, |
+ "https://www.google.com/complete/deleteitem?q=foo"); |
+ provider_->DeleteMatch(m); |
+ // Set up a default fetcher with provided results. |
+ net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( |
+ SearchProvider::kDeletionURLFetcherID); |
+ ASSERT_TRUE(fetcher); |
+ fetcher->set_response_code(200); |
+ fetcher->SetResponseString(""); |
+ fetcher->delegate()->OnURLFetchComplete(fetcher); |
+ ASSERT_TRUE(provider_->deletion_handler_.get() == NULL); |
+} |
+ |
+TEST_F(SearchProviderTest, TestDeleteMatch_HasDeletionUrlFailure) { |
+ AutocompleteMatch m = AutocompleteMatch( |
+ provider_, |
+ 640, |
+ true, |
+ AutocompleteMatchType::SEARCH_SUGGEST); |
+ m.RecordAdditionalInfo(SearchProvider::kDeletionUrlKey, |
+ "https://www.google.com/complete/deleteitem?q=foo"); |
+ provider_->DeleteMatch(m); |
+ // Set up a default fetcher with provided results. |
+ net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( |
+ SearchProvider::kDeletionURLFetcherID); |
+ ASSERT_TRUE(fetcher); |
+ fetcher->set_response_code(500); |
+ fetcher->SetResponseString(""); |
+ fetcher->delegate()->OnURLFetchComplete(fetcher); |
+ ASSERT_TRUE(provider_->deletion_handler_.get() == NULL); |
+} |