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 bae74a73fa47250bd597ca52fd6e952f8bc8bbe8..7c4496d67c69c200c8a8c6dc3ebe35775d8414b8 100644 |
--- a/chrome/browser/autocomplete/search_provider_unittest.cc |
+++ b/chrome/browser/autocomplete/search_provider_unittest.cc |
@@ -3354,7 +3354,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)); |
} |
@@ -3835,6 +3836,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}; |
Peter Kasting
2013/11/27 21:58:19
Nit: "" -> std::string()
Place '}' on the start o
Maria
2013/11/28 00:17:03
Done.
|
+ |
+ 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 |
Peter Kasting
2013/11/27 21:58:19
Nit: How about:
A deletion URL on a personalized
Maria
2013/11/28 00:17:03
Done.
|
+ { "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 |
Peter Kasting
2013/11/27 21:58:19
Nit: How about:
Personalized queries without dele
Maria
2013/11/28 00:17:03
Done.
|
+ { "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. |
Peter Kasting
2013/11/27 21:58:19
Is there any particular reason why we should ignor
Maria
2013/11/28 00:17:03
During results parsing we don't bother looking at
Peter Kasting
2013/11/28 00:44:17
I left a comment on that code.
|
+ { "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); |
@@ -3981,3 +4073,41 @@ TEST_F(SearchProviderTest, CanSendURL) { |
GURL("https://www.google.com/complete/search"), &google_template_url, |
AutocompleteInput::OTHER, &profile_)); |
} |
+ |
+TEST_F(SearchProviderTest, TestDeleteMatch_HasDeletionUrlSuccess) { |
+ AutocompleteMatch m( |
Peter Kasting
2013/11/27 21:58:19
Tiny nit: |match| would be a better name than |m|
Maria
2013/11/28 00:17:03
Done.
|
+ provider_, |
Peter Kasting
2013/11/27 21:58:19
Nit: For an arg list this short, I'd just wrap as:
Maria
2013/11/28 00:17:03
Done.
|
+ 0, |
+ true, |
+ AutocompleteMatchType::SEARCH_SUGGEST); |
+ m.RecordAdditionalInfo(SearchProvider::kDeletionUrlKey, |
+ "https://www.google.com/complete/deleteitem?q=foo"); |
+ provider_->matches_.push_back(m); |
+ provider_->DeleteMatch(m); |
Peter Kasting
2013/11/27 21:58:19
Seems like after this line, we should check that |
Maria
2013/11/28 00:17:03
Done.
|
+ // 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->delegate()->OnURLFetchComplete(fetcher); |
+ ASSERT_TRUE(provider_->deletion_handlers_.empty()); |
+} |
+ |
+TEST_F(SearchProviderTest, TestDeleteMatch_HasDeletionUrlFailure) { |
+ AutocompleteMatch m( |
+ provider_, |
+ 0, |
+ true, |
+ AutocompleteMatchType::SEARCH_SUGGEST); |
+ m.RecordAdditionalInfo(SearchProvider::kDeletionUrlKey, |
+ "https://www.google.com/complete/deleteitem?q=foo"); |
+ provider_->matches_.push_back(m); |
+ 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->delegate()->OnURLFetchComplete(fetcher); |
+ ASSERT_TRUE(provider_->deletion_handlers_.empty()); |
+} |