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

Unified Diff: chrome/browser/autocomplete/search_provider_unittest.cc

Issue 54203008: Store xsrf token received with psuggest results. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added test case Created 7 years, 2 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
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 7df13f483b590ec29760d793d150f1570de18fd6..c5c35a7dfa099e48519ed77669338f6b7d15360f 100644
--- a/chrome/browser/autocomplete/search_provider_unittest.cc
+++ b/chrome/browser/autocomplete/search_provider_unittest.cc
@@ -2483,7 +2483,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));
}
@@ -2960,6 +2961,87 @@ TEST_F(SearchProviderTest, XSSIGuardedJSONParsing) {
}
}
+// Test that XSRF token gets set on an AutocompleteMatch when available for a
+// personalized query.
+TEST_F(SearchProviderTest, ParseXsrfToken) {
+ struct Match {
+ std::string contents;
+ std::string xsrf_token;
+ AutocompleteMatchType::Type type;
+ };
+
+ const Match kEmptyMatch = {
+ kNotApplicable, "", AutocompleteMatchType::NUM_TYPES};
+
+ struct {
+ const std::string input_text;
+ const std::string response_json;
+ const Match matches[4];
+ } cases[] = {
+ // Personalized query comes with an XSRF token
+ { "a",
+ "[\"a\",[\"ab\", \"ac\"],[],[],"
+ "{\"google:suggesttype\":[\"PERSONALIZED_QUERY\",\"QUERY\"],"
+ "\"google:suggestrelevance\":[1, 2],"
+ "\"google:suggestdetail\":[{\"x\":\"xsrf123\"}, {}]}]",
+ { { "a", "", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED },
+ { "ac", "", AutocompleteMatchType::SEARCH_SUGGEST },
+ { "ab", "xsrf123", AutocompleteMatchType::SEARCH_SUGGEST },
+ kEmptyMatch,
+ },
+ },
+ // Personalized query, but no xsrf token 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 an xsrf token, this
+ // should be ignored.
+ { "a",
+ "[\"a\",[\"ab\", \"ac\"],[],[],"
+ "{\"google:suggesttype\":[\"PERSONALIZED_QUERY\",\"QUERY\"],"
+ "\"google:suggestrelevance\":[1, 2],"
+ "\"google:suggestdetail\":[{\"x\":\"xsrf123\"}, {\"x\":\"xsrf\"}]}]",
+ { { "a", "", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED },
+ { "ac", "", AutocompleteMatchType::SEARCH_SUGGEST },
+ { "ab", "xsrf123", 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.xsrf_token, matches[j].search_terms_args->xsrf_token);
+ }
+ }
+}
TEST_F(SearchProviderTest, ReflectsBookmarkBarState) {
profile_.GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, false);

Powered by Google App Engine
This is Rietveld 408576698