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

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

Issue 836213002: Assume all providers may give zero suggest responses. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compilation issue in athena Created 5 years, 11 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
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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 std::map<std::string, std::string> params; 212 std::map<std::string, std::string> params;
213 params[std::string(OmniboxFieldTrial::kZeroSuggestRule)] = "true"; 213 params[std::string(OmniboxFieldTrial::kZeroSuggestRule)] = "true";
214 params[std::string(OmniboxFieldTrial::kZeroSuggestVariantRule)] = 214 params[std::string(OmniboxFieldTrial::kZeroSuggestVariantRule)] =
215 "MostVisitedWithoutSERP"; 215 "MostVisitedWithoutSERP";
216 variations::AssociateVariationParams( 216 variations::AssociateVariationParams(
217 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params); 217 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params);
218 base::FieldTrialList::CreateFieldTrial( 218 base::FieldTrialList::CreateFieldTrial(
219 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); 219 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A");
220 } 220 }
221 221
222 TEST_F(ZeroSuggestProviderTest, TestDoesNotReturnMatchesForPrefix) {
223 CreatePersonalizedFieldTrial();
224
225 std::string url("http://www.cnn.com/");
226 AutocompleteInput input(base::ASCIIToUTF16(url), base::string16::npos,
227 std::string(), GURL(url),
228 metrics::OmniboxEventProto::INVALID_SPEC, true, false,
229 true, true,
230 ChromeAutocompleteSchemeClassifier(&profile_));
231
232 // Set up the pref to cache the response from the previous run.
233 std::string json_response("[\"\",[\"search1\", \"search2\", \"search3\"],"
234 "[],[],{\"google:suggestrelevance\":[602, 601, 600],"
235 "\"google:verbatimrelevance\":1300}]");
236 PrefService* prefs = profile_.GetPrefs();
237 prefs->SetString(prefs::kZeroSuggestCachedResults, json_response);
238
239 provider_->Start(input, false, false);
240
241 // Expect that matches don't get populated out of cache because we are not
242 // in zero suggest mode.
243 EXPECT_TRUE(provider_->matches().empty());
244
245 // Expect that fetcher did not get created.
246 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(1);
247 EXPECT_FALSE(fetcher);
248 }
249
222 TEST_F(ZeroSuggestProviderTest, TestMostVisitedCallback) { 250 TEST_F(ZeroSuggestProviderTest, TestMostVisitedCallback) {
223 CreateMostVisitedFieldTrial(); 251 CreateMostVisitedFieldTrial();
224 252
225 std::string current_url("http://www.foxnews.com/"); 253 std::string current_url("http://www.foxnews.com/");
226 std::string input_url("http://www.cnn.com/"); 254 std::string input_url("http://www.cnn.com/");
227 AutocompleteInput input(base::ASCIIToUTF16(input_url), base::string16::npos, 255 AutocompleteInput input(base::ASCIIToUTF16(input_url), base::string16::npos,
228 std::string(), GURL(current_url), 256 std::string(), GURL(current_url),
229 metrics::OmniboxEventProto::OTHER, false, false, 257 metrics::OmniboxEventProto::OTHER, false, false,
230 true, true, 258 true, true,
231 ChromeAutocompleteSchemeClassifier(&profile_)); 259 ChromeAutocompleteSchemeClassifier(&profile_));
232 history::MostVisitedURLList urls; 260 history::MostVisitedURLList urls;
233 history::MostVisitedURL url(GURL("http://foo.com/"), 261 history::MostVisitedURL url(GURL("http://foo.com/"),
234 base::ASCIIToUTF16("Foo")); 262 base::ASCIIToUTF16("Foo"));
235 urls.push_back(url); 263 urls.push_back(url);
236 264
237 provider_->Start(input, false); 265 provider_->Start(input, false, true);
238 EXPECT_TRUE(provider_->matches().empty()); 266 EXPECT_TRUE(provider_->matches().empty());
239 static_cast<FakeEmptyTopSites*>(profile_.GetTopSites())->mv_callback.Run( 267 static_cast<FakeEmptyTopSites*>(profile_.GetTopSites())->mv_callback.Run(
240 urls); 268 urls);
241 // Should have verbatim match + most visited url match. 269 // Should have verbatim match + most visited url match.
242 EXPECT_EQ(2U, provider_->matches().size()); 270 EXPECT_EQ(2U, provider_->matches().size());
243 provider_->Stop(false); 271 provider_->Stop(false);
244 272
245 provider_->Start(input, false); 273 provider_->Start(input, false, true);
246 provider_->Stop(false); 274 provider_->Stop(false);
247 EXPECT_TRUE(provider_->matches().empty()); 275 EXPECT_TRUE(provider_->matches().empty());
248 // Most visited results arriving after Stop() has been called, ensure they 276 // Most visited results arriving after Stop() has been called, ensure they
249 // are not displayed. 277 // are not displayed.
250 static_cast<FakeEmptyTopSites*>(profile_.GetTopSites())->mv_callback.Run( 278 static_cast<FakeEmptyTopSites*>(profile_.GetTopSites())->mv_callback.Run(
251 urls); 279 urls);
252 EXPECT_TRUE(provider_->matches().empty()); 280 EXPECT_TRUE(provider_->matches().empty());
253 } 281 }
254 282
255 TEST_F(ZeroSuggestProviderTest, TestMostVisitedNavigateToSearchPage) { 283 TEST_F(ZeroSuggestProviderTest, TestMostVisitedNavigateToSearchPage) {
256 CreateMostVisitedFieldTrial(); 284 CreateMostVisitedFieldTrial();
257 285
258 std::string current_url("http://www.foxnews.com/"); 286 std::string current_url("http://www.foxnews.com/");
259 std::string input_url("http://www.cnn.com/"); 287 std::string input_url("http://www.cnn.com/");
260 AutocompleteInput input(base::ASCIIToUTF16(input_url), base::string16::npos, 288 AutocompleteInput input(base::ASCIIToUTF16(input_url), base::string16::npos,
261 std::string(), GURL(current_url), 289 std::string(), GURL(current_url),
262 metrics::OmniboxEventProto::OTHER, false, false, 290 metrics::OmniboxEventProto::OTHER, false, false,
263 true, true, 291 true, true,
264 ChromeAutocompleteSchemeClassifier(&profile_)); 292 ChromeAutocompleteSchemeClassifier(&profile_));
265 history::MostVisitedURLList urls; 293 history::MostVisitedURLList urls;
266 history::MostVisitedURL url(GURL("http://foo.com/"), 294 history::MostVisitedURL url(GURL("http://foo.com/"),
267 base::ASCIIToUTF16("Foo")); 295 base::ASCIIToUTF16("Foo"));
268 urls.push_back(url); 296 urls.push_back(url);
269 297
270 provider_->Start(input, false); 298 provider_->Start(input, false, true);
271 EXPECT_TRUE(provider_->matches().empty()); 299 EXPECT_TRUE(provider_->matches().empty());
272 // Stop() doesn't always get called. 300 // Stop() doesn't always get called.
273 301
274 std::string search_url("https://www.google.com/?q=flowers"); 302 std::string search_url("https://www.google.com/?q=flowers");
275 AutocompleteInput srp_input( 303 AutocompleteInput srp_input(
276 base::ASCIIToUTF16(search_url), 304 base::ASCIIToUTF16(search_url),
277 base::string16::npos, 305 base::string16::npos,
278 std::string(), 306 std::string(),
279 GURL(search_url), 307 GURL(search_url),
280 metrics::OmniboxEventProto:: 308 metrics::OmniboxEventProto::
281 SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT, 309 SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT,
282 false, 310 false,
283 false, 311 false,
284 true, 312 true,
285 true, 313 true,
286 ChromeAutocompleteSchemeClassifier(&profile_)); 314 ChromeAutocompleteSchemeClassifier(&profile_));
287 315
288 provider_->Start(srp_input, false); 316 provider_->Start(srp_input, false, true);
289 EXPECT_TRUE(provider_->matches().empty()); 317 EXPECT_TRUE(provider_->matches().empty());
290 // Most visited results arriving after a new request has been started. 318 // Most visited results arriving after a new request has been started.
291 static_cast<FakeEmptyTopSites*>(profile_.GetTopSites())->mv_callback.Run( 319 static_cast<FakeEmptyTopSites*>(profile_.GetTopSites())->mv_callback.Run(
292 urls); 320 urls);
293 EXPECT_TRUE(provider_->matches().empty()); 321 EXPECT_TRUE(provider_->matches().empty());
294 } 322 }
295 323
296 TEST_F(ZeroSuggestProviderTest, TestPsuggestZeroSuggestCachingFirstRun) { 324 TEST_F(ZeroSuggestProviderTest, TestPsuggestZeroSuggestCachingFirstRun) {
297 CreatePersonalizedFieldTrial(); 325 CreatePersonalizedFieldTrial();
298 326
299 // Ensure the cache is empty. 327 // Ensure the cache is empty.
300 PrefService* prefs = profile_.GetPrefs(); 328 PrefService* prefs = profile_.GetPrefs();
301 prefs->SetString(prefs::kZeroSuggestCachedResults, std::string()); 329 prefs->SetString(prefs::kZeroSuggestCachedResults, std::string());
302 330
303 std::string url("http://www.cnn.com/"); 331 std::string url("http://www.cnn.com/");
304 AutocompleteInput input(base::ASCIIToUTF16(url), base::string16::npos, 332 AutocompleteInput input(base::ASCIIToUTF16(url), base::string16::npos,
305 std::string(), GURL(url), 333 std::string(), GURL(url),
306 metrics::OmniboxEventProto::INVALID_SPEC, true, false, 334 metrics::OmniboxEventProto::INVALID_SPEC, true, false,
307 true, true, 335 true, true,
308 ChromeAutocompleteSchemeClassifier(&profile_)); 336 ChromeAutocompleteSchemeClassifier(&profile_));
309 337
310 provider_->Start(input, false); 338 provider_->Start(input, false, true);
311 339
312 EXPECT_TRUE(prefs->GetString(prefs::kZeroSuggestCachedResults).empty()); 340 EXPECT_TRUE(prefs->GetString(prefs::kZeroSuggestCachedResults).empty());
313 EXPECT_TRUE(provider_->matches().empty()); 341 EXPECT_TRUE(provider_->matches().empty());
314 342
315 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(1); 343 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(1);
316 ASSERT_TRUE(fetcher); 344 ASSERT_TRUE(fetcher);
317 fetcher->set_response_code(200); 345 fetcher->set_response_code(200);
318 std::string json_response("[\"\",[\"search1\", \"search2\", \"search3\"]," 346 std::string json_response("[\"\",[\"search1\", \"search2\", \"search3\"],"
319 "[],[],{\"google:suggestrelevance\":[602, 601, 600]," 347 "[],[],{\"google:suggestrelevance\":[602, 601, 600],"
320 "\"google:verbatimrelevance\":1300}]"); 348 "\"google:verbatimrelevance\":1300}]");
(...skipping 16 matching lines...) Expand all
337 true, true, 365 true, true,
338 ChromeAutocompleteSchemeClassifier(&profile_)); 366 ChromeAutocompleteSchemeClassifier(&profile_));
339 367
340 // Set up the pref to cache the response from the previous run. 368 // Set up the pref to cache the response from the previous run.
341 std::string json_response("[\"\",[\"search1\", \"search2\", \"search3\"]," 369 std::string json_response("[\"\",[\"search1\", \"search2\", \"search3\"],"
342 "[],[],{\"google:suggestrelevance\":[602, 601, 600]," 370 "[],[],{\"google:suggestrelevance\":[602, 601, 600],"
343 "\"google:verbatimrelevance\":1300}]"); 371 "\"google:verbatimrelevance\":1300}]");
344 PrefService* prefs = profile_.GetPrefs(); 372 PrefService* prefs = profile_.GetPrefs();
345 prefs->SetString(prefs::kZeroSuggestCachedResults, json_response); 373 prefs->SetString(prefs::kZeroSuggestCachedResults, json_response);
346 374
347 provider_->Start(input, false); 375 provider_->Start(input, false, true);
348 376
349 // Expect that matches get populated synchronously out of the cache. 377 // Expect that matches get populated synchronously out of the cache.
350 ASSERT_EQ(4U, provider_->matches().size()); 378 ASSERT_EQ(4U, provider_->matches().size());
351 EXPECT_EQ(base::ASCIIToUTF16("search1"), provider_->matches()[1].contents); 379 EXPECT_EQ(base::ASCIIToUTF16("search1"), provider_->matches()[1].contents);
352 EXPECT_EQ(base::ASCIIToUTF16("search2"), provider_->matches()[2].contents); 380 EXPECT_EQ(base::ASCIIToUTF16("search2"), provider_->matches()[2].contents);
353 EXPECT_EQ(base::ASCIIToUTF16("search3"), provider_->matches()[3].contents); 381 EXPECT_EQ(base::ASCIIToUTF16("search3"), provider_->matches()[3].contents);
354 382
355 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(1); 383 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(1);
356 ASSERT_TRUE(fetcher); 384 ASSERT_TRUE(fetcher);
357 fetcher->set_response_code(200); 385 fetcher->set_response_code(200);
(...skipping 26 matching lines...) Expand all
384 true, true, 412 true, true,
385 ChromeAutocompleteSchemeClassifier(&profile_)); 413 ChromeAutocompleteSchemeClassifier(&profile_));
386 414
387 // Set up the pref to cache the response from the previous run. 415 // Set up the pref to cache the response from the previous run.
388 std::string json_response("[\"\",[\"search1\", \"search2\", \"search3\"]," 416 std::string json_response("[\"\",[\"search1\", \"search2\", \"search3\"],"
389 "[],[],{\"google:suggestrelevance\":[602, 601, 600]," 417 "[],[],{\"google:suggestrelevance\":[602, 601, 600],"
390 "\"google:verbatimrelevance\":1300}]"); 418 "\"google:verbatimrelevance\":1300}]");
391 PrefService* prefs = profile_.GetPrefs(); 419 PrefService* prefs = profile_.GetPrefs();
392 prefs->SetString(prefs::kZeroSuggestCachedResults, json_response); 420 prefs->SetString(prefs::kZeroSuggestCachedResults, json_response);
393 421
394 provider_->Start(input, false); 422 provider_->Start(input, false, true);
395 423
396 // Expect that matches get populated synchronously out of the cache. 424 // Expect that matches get populated synchronously out of the cache.
397 ASSERT_EQ(4U, provider_->matches().size()); 425 ASSERT_EQ(4U, provider_->matches().size());
398 EXPECT_EQ(base::ASCIIToUTF16("search1"), provider_->matches()[1].contents); 426 EXPECT_EQ(base::ASCIIToUTF16("search1"), provider_->matches()[1].contents);
399 EXPECT_EQ(base::ASCIIToUTF16("search2"), provider_->matches()[2].contents); 427 EXPECT_EQ(base::ASCIIToUTF16("search2"), provider_->matches()[2].contents);
400 EXPECT_EQ(base::ASCIIToUTF16("search3"), provider_->matches()[3].contents); 428 EXPECT_EQ(base::ASCIIToUTF16("search3"), provider_->matches()[3].contents);
401 429
402 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(1); 430 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(1);
403 ASSERT_TRUE(fetcher); 431 ASSERT_TRUE(fetcher);
404 fetcher->set_response_code(200); 432 fetcher->set_response_code(200);
405 std::string empty_response("[\"\",[],[],[],{}]"); 433 std::string empty_response("[\"\",[],[],[],{}]");
406 fetcher->SetResponseString(empty_response); 434 fetcher->SetResponseString(empty_response);
407 fetcher->delegate()->OnURLFetchComplete(fetcher); 435 fetcher->delegate()->OnURLFetchComplete(fetcher);
408 436
409 base::RunLoop().RunUntilIdle(); 437 base::RunLoop().RunUntilIdle();
410 438
411 // Expect that the matches have been cleared. 439 // Expect that the matches have been cleared.
412 ASSERT_TRUE(provider_->matches().empty()); 440 ASSERT_TRUE(provider_->matches().empty());
413 441
414 // Expect the new results have been stored. 442 // Expect the new results have been stored.
415 EXPECT_EQ(empty_response, 443 EXPECT_EQ(empty_response,
416 prefs->GetString(prefs::kZeroSuggestCachedResults)); 444 prefs->GetString(prefs::kZeroSuggestCachedResults));
417 } 445 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/zero_suggest_provider.cc ('k') | components/omnibox/autocomplete_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698