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

Side by Side Diff: chrome/browser/autocomplete/zero_suggest_provider_unittest.cc

Issue 343523003: Remove AutocompleteInput Type and PageClassification. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/zero_suggest_provider.h" 5 #include "chrome/browser/autocomplete/zero_suggest_provider.h"
6 6
7 #include "base/metrics/field_trial.h" 7 #include "base/metrics/field_trial.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 base::FieldTrialList::CreateFieldTrial( 105 base::FieldTrialList::CreateFieldTrial(
106 "AutocompleteDynamicTrial_2", "EnableZeroSuggestPersonalizedExperiment"); 106 "AutocompleteDynamicTrial_2", "EnableZeroSuggestPersonalizedExperiment");
107 107
108 // Ensure the cache is empty. 108 // Ensure the cache is empty.
109 PrefService* prefs = profile_.GetPrefs(); 109 PrefService* prefs = profile_.GetPrefs();
110 prefs->SetString(prefs::kZeroSuggestCachedResults, std::string()); 110 prefs->SetString(prefs::kZeroSuggestCachedResults, std::string());
111 111
112 std::string url("http://www.cnn.com"); 112 std::string url("http://www.cnn.com");
113 AutocompleteInput input( 113 AutocompleteInput input(
114 base::ASCIIToUTF16(url), base::string16::npos, base::string16(), 114 base::ASCIIToUTF16(url), base::string16::npos, base::string16(),
115 GURL(url), AutocompleteInput::INVALID_SPEC, true, false, true, true); 115 GURL(url), metrics::OmniboxEventProto::INVALID_SPEC, true, false, true,
116 true);
116 117
117 provider_->Start(input, false); 118 provider_->Start(input, false);
118 119
119 EXPECT_TRUE(prefs->GetString(prefs::kZeroSuggestCachedResults).empty()); 120 EXPECT_TRUE(prefs->GetString(prefs::kZeroSuggestCachedResults).empty());
120 EXPECT_TRUE(provider_->matches().empty()); 121 EXPECT_TRUE(provider_->matches().empty());
121 122
122 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(1); 123 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(1);
123 ASSERT_TRUE(fetcher); 124 ASSERT_TRUE(fetcher);
124 fetcher->set_response_code(200); 125 fetcher->set_response_code(200);
125 std::string json_response("[\"\",[\"search1\", \"search2\", \"search3\"]," 126 std::string json_response("[\"\",[\"search1\", \"search2\", \"search3\"],"
126 "[],[],{\"google:suggestrelevance\":[602, 601, 600]," 127 "[],[],{\"google:suggestrelevance\":[602, 601, 600],"
127 "\"google:verbatimrelevance\":1300}]"); 128 "\"google:verbatimrelevance\":1300}]");
128 fetcher->SetResponseString(json_response); 129 fetcher->SetResponseString(json_response);
129 fetcher->delegate()->OnURLFetchComplete(fetcher); 130 fetcher->delegate()->OnURLFetchComplete(fetcher);
130 131
131 base::RunLoop().RunUntilIdle(); 132 base::RunLoop().RunUntilIdle();
132 133
133 EXPECT_EQ(4U, provider_->matches().size()); // 3 results + verbatim 134 EXPECT_EQ(4U, provider_->matches().size()); // 3 results + verbatim
134 EXPECT_EQ(json_response, prefs->GetString(prefs::kZeroSuggestCachedResults)); 135 EXPECT_EQ(json_response, prefs->GetString(prefs::kZeroSuggestCachedResults));
135 } 136 }
136 137
137 TEST_F(ZeroSuggestProviderTest, TestPsuggestZeroSuggestHasCachedResults) { 138 TEST_F(ZeroSuggestProviderTest, TestPsuggestZeroSuggestHasCachedResults) {
138 base::FieldTrialList::CreateFieldTrial( 139 base::FieldTrialList::CreateFieldTrial(
139 "AutocompleteDynamicTrial_2", "EnableZeroSuggestPersonalizedExperiment"); 140 "AutocompleteDynamicTrial_2", "EnableZeroSuggestPersonalizedExperiment");
140 141
141 std::string url("http://www.cnn.com"); 142 std::string url("http://www.cnn.com");
142 AutocompleteInput input( 143 AutocompleteInput input(
143 base::ASCIIToUTF16(url), base::string16::npos, base::string16(), 144 base::ASCIIToUTF16(url), base::string16::npos, base::string16(),
144 GURL(url), AutocompleteInput::INVALID_SPEC, true, false, true, true); 145 GURL(url), metrics::OmniboxEventProto::INVALID_SPEC, true, false, true,
146 true);
145 147
146 // Set up the pref to cache the response from the previous run. 148 // Set up the pref to cache the response from the previous run.
147 std::string json_response("[\"\",[\"search1\", \"search2\", \"search3\"]," 149 std::string json_response("[\"\",[\"search1\", \"search2\", \"search3\"],"
148 "[],[],{\"google:suggestrelevance\":[602, 601, 600]," 150 "[],[],{\"google:suggestrelevance\":[602, 601, 600],"
149 "\"google:verbatimrelevance\":1300}]"); 151 "\"google:verbatimrelevance\":1300}]");
150 PrefService* prefs = profile_.GetPrefs(); 152 PrefService* prefs = profile_.GetPrefs();
151 prefs->SetString(prefs::kZeroSuggestCachedResults, json_response); 153 prefs->SetString(prefs::kZeroSuggestCachedResults, json_response);
152 154
153 provider_->Start(input, false); 155 provider_->Start(input, false);
154 156
(...skipping 25 matching lines...) Expand all
180 prefs->GetString(prefs::kZeroSuggestCachedResults)); 182 prefs->GetString(prefs::kZeroSuggestCachedResults));
181 } 183 }
182 184
183 TEST_F(ZeroSuggestProviderTest, TestPsuggestZeroSuggestReceivedEmptyResults) { 185 TEST_F(ZeroSuggestProviderTest, TestPsuggestZeroSuggestReceivedEmptyResults) {
184 base::FieldTrialList::CreateFieldTrial( 186 base::FieldTrialList::CreateFieldTrial(
185 "AutocompleteDynamicTrial_2", "EnableZeroSuggestPersonalizedExperiment"); 187 "AutocompleteDynamicTrial_2", "EnableZeroSuggestPersonalizedExperiment");
186 188
187 std::string url("http://www.cnn.com"); 189 std::string url("http://www.cnn.com");
188 AutocompleteInput input( 190 AutocompleteInput input(
189 base::ASCIIToUTF16(url), base::string16::npos, base::string16(), 191 base::ASCIIToUTF16(url), base::string16::npos, base::string16(),
190 GURL(url), AutocompleteInput::INVALID_SPEC, true, false, true, true); 192 GURL(url), metrics::OmniboxEventProto::INVALID_SPEC, true, false, true,
193 true);
191 194
192 // Set up the pref to cache the response from the previous run. 195 // Set up the pref to cache the response from the previous run.
193 std::string json_response("[\"\",[\"search1\", \"search2\", \"search3\"]," 196 std::string json_response("[\"\",[\"search1\", \"search2\", \"search3\"],"
194 "[],[],{\"google:suggestrelevance\":[602, 601, 600]," 197 "[],[],{\"google:suggestrelevance\":[602, 601, 600],"
195 "\"google:verbatimrelevance\":1300}]"); 198 "\"google:verbatimrelevance\":1300}]");
196 PrefService* prefs = profile_.GetPrefs(); 199 PrefService* prefs = profile_.GetPrefs();
197 prefs->SetString(prefs::kZeroSuggestCachedResults, json_response); 200 prefs->SetString(prefs::kZeroSuggestCachedResults, json_response);
198 201
199 provider_->Start(input, false); 202 provider_->Start(input, false);
200 203
(...skipping 12 matching lines...) Expand all
213 216
214 base::RunLoop().RunUntilIdle(); 217 base::RunLoop().RunUntilIdle();
215 218
216 // Expect that the matches have been cleared. 219 // Expect that the matches have been cleared.
217 ASSERT_TRUE(provider_->matches().empty()); 220 ASSERT_TRUE(provider_->matches().empty());
218 221
219 // Expect the new results have been stored. 222 // Expect the new results have been stored.
220 EXPECT_EQ(empty_response, 223 EXPECT_EQ(empty_response,
221 prefs->GetString(prefs::kZeroSuggestCachedResults)); 224 prefs->GetString(prefs::kZeroSuggestCachedResults));
222 } 225 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698