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

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

Issue 96753004: Ensure zero suggest can handle XSSI-escaped output. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added a unit test for invalid response case Created 7 years 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 bae74a73fa47250bd597ca52fd6e952f8bc8bbe8..6ae49e0c609145e8e30eb8483420feef5a62e319 100644
--- a/chrome/browser/autocomplete/search_provider_unittest.cc
+++ b/chrome/browser/autocomplete/search_provider_unittest.cc
@@ -3748,9 +3748,35 @@ TEST_F(SearchProviderTest, PrefetchMetadataParsing) {
}
}
+TEST_F(SearchProviderTest, XSSIGuardedJSONParsing_InvalidResponse) {
+ ClearAllResults();
+
+ std::string input_str("abc");
+ QueryForInput(ASCIIToUTF16(input_str), false, false);
+
+ // Set up a default fetcher with provided results.
+ net::TestURLFetcher* fetcher =
+ test_factory_.GetFetcherByID(
+ SearchProvider::kDefaultProviderURLFetcherID);
+ ASSERT_TRUE(fetcher);
+ fetcher->set_response_code(200);
+ fetcher->SetResponseString("this is a bad non-json response");
+ fetcher->delegate()->OnURLFetchComplete(fetcher);
+
+ RunTillProviderDone();
+
+ const ACMatches& matches = provider_->matches();
+
+ // Should have exactly one "search what you typed" match
+ ASSERT_TRUE(matches.size() == 1);
+ EXPECT_EQ(input_str, UTF16ToUTF8(matches[0].contents));
+ EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
+ matches[0].type);
+}
+
// A basic test that verifies that the XSSI guarded JSON response is parsed
// correctly.
-TEST_F(SearchProviderTest, XSSIGuardedJSONParsing) {
+TEST_F(SearchProviderTest, XSSIGuardedJSONParsing_ValidResponses) {
struct Match {
std::string contents;
AutocompleteMatchType::Type type;
« no previous file with comments | « chrome/browser/autocomplete/search_provider.cc ('k') | chrome/browser/autocomplete/zero_suggest_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698