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

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

Issue 55413002: Don't demote top match for certain match types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Peter's comments Created 7 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/autocomplete_result.h" 5 #include "chrome/browser/autocomplete/autocomplete_result.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 // demoted relevance but the actual relevance scores are not modified. 370 // demoted relevance but the actual relevance scores are not modified.
371 ASSERT_EQ(3u, result.size()); 371 ASSERT_EQ(3u, result.size());
372 EXPECT_EQ("http://search-what-you-typed/", 372 EXPECT_EQ("http://search-what-you-typed/",
373 result.match_at(0)->destination_url.spec()); 373 result.match_at(0)->destination_url.spec());
374 EXPECT_EQ("http://history-url/", 374 EXPECT_EQ("http://history-url/",
375 result.match_at(1)->destination_url.spec()); 375 result.match_at(1)->destination_url.spec());
376 EXPECT_EQ("http://search-history/", 376 EXPECT_EQ("http://search-history/",
377 result.match_at(2)->destination_url.spec()); 377 result.match_at(2)->destination_url.spec());
378 } 378 }
379 379
380 TEST_F(AutocompleteResultTest, SortAndCullWithUndemotableTypes) {
381 // Add some matches.
382 ACMatches matches(3);
383 matches[0].destination_url = GURL("http://top-history-url/");
384 matches[0].relevance = 1400;
385 matches[0].allowed_to_be_default_match = true;
386 matches[0].type = AutocompleteMatchType::HISTORY_URL;
387 matches[1].destination_url = GURL("http://history-url2/");
388 matches[1].relevance = 1300;
389 matches[1].allowed_to_be_default_match = true;
390 matches[1].type = AutocompleteMatchType::HISTORY_URL;
391 matches[2].destination_url = GURL("http://search-what-you-typed/");
392 matches[2].relevance = 1200;
393 matches[2].allowed_to_be_default_match = true;
394 matches[2].type = AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED;
395
396 // Add a rule demoting history-url, but don't demote the top match.
397 {
398 std::map<std::string, std::string> params;
399 // 3 == HOME_PAGE
400 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":3:*"] =
401 "1:50";
402 params[std::string(OmniboxFieldTrial::kUndemotableTopTypeRule) + ":3:*"] =
403 "1,5";
404 ASSERT_TRUE(chrome_variations::AssociateVariationParams(
405 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "B", params));
406 }
407 base::FieldTrialList::CreateFieldTrial(
408 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "B");
409
410 AutocompleteResult result;
411 result.AppendMatches(matches);
412 AutocompleteInput input(string16(), string16::npos, string16(), GURL(),
413 AutocompleteInput::HOME_PAGE, false, false, false,
414 AutocompleteInput::ALL_MATCHES);
415 result.SortAndCull(input, test_util_.profile());
416
417 // Check the new ordering. The first history-url result should not be
418 // demoted, but the second result should be.
419 // We cannot check relevance scores because the matches are sorted by
420 // demoted relevance but the actual relevance scores are not modified.
421 ASSERT_EQ(3u, result.size());
422 EXPECT_EQ("http://top-history-url/",
423 result.match_at(0)->destination_url.spec());
424 EXPECT_EQ("http://search-what-you-typed/",
425 result.match_at(1)->destination_url.spec());
426 EXPECT_EQ("http://history-url2/",
427 result.match_at(2)->destination_url.spec());
428 }
429
380 TEST_F(AutocompleteResultTest, SortAndCullReorderForDefaultMatch) { 430 TEST_F(AutocompleteResultTest, SortAndCullReorderForDefaultMatch) {
381 TestData data[] = { 431 TestData data[] = {
382 { 0, 0, 1300 }, 432 { 0, 0, 1300 },
383 { 1, 0, 1200 }, 433 { 1, 0, 1200 },
384 { 2, 0, 1100 }, 434 { 2, 0, 1100 },
385 { 3, 0, 1000 } 435 { 3, 0, 1000 }
386 }; 436 };
387 437
388 std::map<std::string, std::string> params; 438 std::map<std::string, std::string> params;
389 // Enable reorder for omnibox inputs on the user's home page. 439 // Enable reorder for omnibox inputs on the user's home page.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 AutocompleteInput::HOME_PAGE, false, false, false, 471 AutocompleteInput::HOME_PAGE, false, false, false,
422 AutocompleteInput::ALL_MATCHES); 472 AutocompleteInput::ALL_MATCHES);
423 result.SortAndCull(input, test_util_.profile()); 473 result.SortAndCull(input, test_util_.profile());
424 ASSERT_EQ(4U, result.size()); 474 ASSERT_EQ(4U, result.size());
425 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); 475 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec());
426 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); 476 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec());
427 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); 477 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec());
428 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); 478 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec());
429 } 479 }
430 } 480 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_result.cc ('k') | chrome/browser/omnibox/omnibox_field_trial.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698