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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/autocomplete/search_provider.h" 5 #include "chrome/browser/autocomplete/search_provider.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 3730 matching lines...) Expand 10 before | Expand all | Expand 10 after
3741 EXPECT_EQ(cases[i].matches[j].contents, UTF16ToUTF8(matches[j].contents)); 3741 EXPECT_EQ(cases[i].matches[j].contents, UTF16ToUTF8(matches[j].contents));
3742 EXPECT_EQ(cases[i].matches[j].allowed_to_be_prefetched, 3742 EXPECT_EQ(cases[i].matches[j].allowed_to_be_prefetched,
3743 SearchProvider::ShouldPrefetch(matches[j])); 3743 SearchProvider::ShouldPrefetch(matches[j]));
3744 EXPECT_EQ(cases[i].matches[j].type, matches[j].type); 3744 EXPECT_EQ(cases[i].matches[j].type, matches[j].type);
3745 EXPECT_EQ(cases[i].matches[j].from_keyword, 3745 EXPECT_EQ(cases[i].matches[j].from_keyword,
3746 matches[j].keyword == ASCIIToUTF16("k")); 3746 matches[j].keyword == ASCIIToUTF16("k"));
3747 } 3747 }
3748 } 3748 }
3749 } 3749 }
3750 3750
3751 TEST_F(SearchProviderTest, XSSIGuardedJSONParsing_InvalidResponse) {
3752 ClearAllResults();
3753
3754 std::string input_str("abc");
3755 QueryForInput(ASCIIToUTF16(input_str), false, false);
3756
3757 // Set up a default fetcher with provided results.
3758 net::TestURLFetcher* fetcher =
3759 test_factory_.GetFetcherByID(
3760 SearchProvider::kDefaultProviderURLFetcherID);
3761 ASSERT_TRUE(fetcher);
3762 fetcher->set_response_code(200);
3763 fetcher->SetResponseString("this is a bad non-json response");
3764 fetcher->delegate()->OnURLFetchComplete(fetcher);
3765
3766 RunTillProviderDone();
3767
3768 const ACMatches& matches = provider_->matches();
3769
3770 // Should have exactly one "search what you typed" match
3771 ASSERT_TRUE(matches.size() == 1);
3772 EXPECT_EQ(input_str, UTF16ToUTF8(matches[0].contents));
3773 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
3774 matches[0].type);
3775 }
3776
3751 // A basic test that verifies that the XSSI guarded JSON response is parsed 3777 // A basic test that verifies that the XSSI guarded JSON response is parsed
3752 // correctly. 3778 // correctly.
3753 TEST_F(SearchProviderTest, XSSIGuardedJSONParsing) { 3779 TEST_F(SearchProviderTest, XSSIGuardedJSONParsing_ValidResponses) {
3754 struct Match { 3780 struct Match {
3755 std::string contents; 3781 std::string contents;
3756 AutocompleteMatchType::Type type; 3782 AutocompleteMatchType::Type type;
3757 }; 3783 };
3758 const Match kEmptyMatch = { kNotApplicable, 3784 const Match kEmptyMatch = { kNotApplicable,
3759 AutocompleteMatchType::NUM_TYPES}; 3785 AutocompleteMatchType::NUM_TYPES};
3760 3786
3761 struct { 3787 struct {
3762 const std::string input_text; 3788 const std::string input_text;
3763 const std::string default_provider_response_json; 3789 const std::string default_provider_response_json;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
3974 AutocompleteInput::OTHER, &profile_)); 4000 AutocompleteInput::OTHER, &profile_));
3975 encrypted_types.Remove(syncer::SESSIONS); 4001 encrypted_types.Remove(syncer::SESSIONS);
3976 service->OnEncryptedTypesChanged(encrypted_types, false); 4002 service->OnEncryptedTypesChanged(encrypted_types, false);
3977 4003
3978 // Check that there were no side effects from previous tests. 4004 // Check that there were no side effects from previous tests.
3979 EXPECT_TRUE(SearchProvider::CanSendURL( 4005 EXPECT_TRUE(SearchProvider::CanSendURL(
3980 GURL("http://www.google.com/search"), 4006 GURL("http://www.google.com/search"),
3981 GURL("https://www.google.com/complete/search"), &google_template_url, 4007 GURL("https://www.google.com/complete/search"), &google_template_url,
3982 AutocompleteInput::OTHER, &profile_)); 4008 AutocompleteInput::OTHER, &profile_));
3983 } 4009 }
OLDNEW
« 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