| OLD | NEW |
| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 // Duplicate matches. | 81 // Duplicate matches. |
| 82 std::vector<AutocompleteMatch> duplicate_matches; | 82 std::vector<AutocompleteMatch> duplicate_matches; |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 AutocompleteResultTest() { | 85 AutocompleteResultTest() { |
| 86 // Destroy the existing FieldTrialList before creating a new one to avoid | 86 // Destroy the existing FieldTrialList before creating a new one to avoid |
| 87 // a DCHECK. | 87 // a DCHECK. |
| 88 field_trial_list_.reset(); | 88 field_trial_list_.reset(); |
| 89 field_trial_list_.reset(new base::FieldTrialList( | 89 field_trial_list_.reset(new base::FieldTrialList( |
| 90 new metrics::SHA1EntropyProvider("foo"))); | 90 new metrics::SHA1EntropyProvider("foo"))); |
| 91 chrome_variations::testing::ClearAllVariationParams(); | 91 variations::testing::ClearAllVariationParams(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 virtual void SetUp() OVERRIDE { | 94 virtual void SetUp() OVERRIDE { |
| 95 #if defined(OS_ANDROID) | 95 #if defined(OS_ANDROID) |
| 96 TemplateURLPrepopulateData::InitCountryCode( | 96 TemplateURLPrepopulateData::InitCountryCode( |
| 97 std::string() /* unknown country code */); | 97 std::string() /* unknown country code */); |
| 98 #endif | 98 #endif |
| 99 test_util_.VerifyLoad(); | 99 test_util_.VerifyLoad(); |
| 100 } | 100 } |
| 101 | 101 |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 PopulateAutocompleteMatchesFromTestData(data, arraysize(data), &matches); | 438 PopulateAutocompleteMatchesFromTestData(data, arraysize(data), &matches); |
| 439 | 439 |
| 440 // Demote the search history match relevance score. | 440 // Demote the search history match relevance score. |
| 441 matches.back().relevance = 500; | 441 matches.back().relevance = 500; |
| 442 | 442 |
| 443 // Add a rule demoting history-url and killing history-title. | 443 // Add a rule demoting history-url and killing history-title. |
| 444 { | 444 { |
| 445 std::map<std::string, std::string> params; | 445 std::map<std::string, std::string> params; |
| 446 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":3:*"] = | 446 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":3:*"] = |
| 447 "1:50,7:100,2:0"; // 3 == HOME_PAGE | 447 "1:50,7:100,2:0"; // 3 == HOME_PAGE |
| 448 ASSERT_TRUE(chrome_variations::AssociateVariationParams( | 448 ASSERT_TRUE(variations::AssociateVariationParams( |
| 449 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); | 449 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); |
| 450 } | 450 } |
| 451 base::FieldTrialList::CreateFieldTrial( | 451 base::FieldTrialList::CreateFieldTrial( |
| 452 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); | 452 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); |
| 453 | 453 |
| 454 AutocompleteResult result; | 454 AutocompleteResult result; |
| 455 result.AppendMatches(matches); | 455 result.AppendMatches(matches); |
| 456 AutocompleteInput input(base::string16(), base::string16::npos, | 456 AutocompleteInput input(base::string16(), base::string16::npos, |
| 457 base::string16(), GURL(), | 457 base::string16(), GURL(), |
| 458 OmniboxEventProto::HOME_PAGE, false, false, false, | 458 OmniboxEventProto::HOME_PAGE, false, false, false, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 484 { "http://search-url/", AutocompleteMatchType::SEARCH_SUGGEST }, | 484 { "http://search-url/", AutocompleteMatchType::SEARCH_SUGGEST }, |
| 485 { "http://history-url/", AutocompleteMatchType::HISTORY_URL }, | 485 { "http://history-url/", AutocompleteMatchType::HISTORY_URL }, |
| 486 }; | 486 }; |
| 487 PopulateAutocompleteMatchesFromTestData(data, arraysize(data), &matches); | 487 PopulateAutocompleteMatchesFromTestData(data, arraysize(data), &matches); |
| 488 | 488 |
| 489 // Add a rule demoting HISTORY_URL. | 489 // Add a rule demoting HISTORY_URL. |
| 490 { | 490 { |
| 491 std::map<std::string, std::string> params; | 491 std::map<std::string, std::string> params; |
| 492 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":8:*"] = | 492 params[std::string(OmniboxFieldTrial::kDemoteByTypeRule) + ":8:*"] = |
| 493 "1:50"; // 8 == INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS | 493 "1:50"; // 8 == INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS |
| 494 ASSERT_TRUE(chrome_variations::AssociateVariationParams( | 494 ASSERT_TRUE(variations::AssociateVariationParams( |
| 495 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C", params)); | 495 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C", params)); |
| 496 } | 496 } |
| 497 base::FieldTrialList::CreateFieldTrial( | 497 base::FieldTrialList::CreateFieldTrial( |
| 498 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C"); | 498 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "C"); |
| 499 | 499 |
| 500 { | 500 { |
| 501 AutocompleteResult result; | 501 AutocompleteResult result; |
| 502 result.AppendMatches(matches); | 502 result.AppendMatches(matches); |
| 503 AutocompleteInput input( | 503 AutocompleteInput input( |
| 504 base::string16(), base::string16::npos, base::string16(), GURL(), | 504 base::string16(), base::string16::npos, base::string16(), GURL(), |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 ChromeAutocompleteSchemeClassifier( | 597 ChromeAutocompleteSchemeClassifier( |
| 598 test_util_.profile())); | 598 test_util_.profile())); |
| 599 result.SortAndCull(input, test_util_.model()); | 599 result.SortAndCull(input, test_util_.model()); |
| 600 AssertResultMatches(result, data, 4); | 600 AssertResultMatches(result, data, 4); |
| 601 } | 601 } |
| 602 | 602 |
| 603 // Enable the field trial to disable inlining. | 603 // Enable the field trial to disable inlining. |
| 604 { | 604 { |
| 605 std::map<std::string, std::string> params; | 605 std::map<std::string, std::string> params; |
| 606 params[OmniboxFieldTrial::kDisableInliningRule] = "true"; | 606 params[OmniboxFieldTrial::kDisableInliningRule] = "true"; |
| 607 ASSERT_TRUE(chrome_variations::AssociateVariationParams( | 607 ASSERT_TRUE(variations::AssociateVariationParams( |
| 608 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D", params)); | 608 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D", params)); |
| 609 } | 609 } |
| 610 base::FieldTrialList::CreateFieldTrial( | 610 base::FieldTrialList::CreateFieldTrial( |
| 611 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D"); | 611 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D"); |
| 612 | 612 |
| 613 { | 613 { |
| 614 // Now the first match should be demoted past the second. | 614 // Now the first match should be demoted past the second. |
| 615 ACMatches matches; | 615 ACMatches matches; |
| 616 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 616 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 617 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); | 617 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 result.Reset(); | 849 result.Reset(); |
| 850 matches.clear(); | 850 matches.clear(); |
| 851 | 851 |
| 852 // Case 5: Multiple verbatim matches found in AutocompleteResult. | 852 // Case 5: Multiple verbatim matches found in AutocompleteResult. |
| 853 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, | 853 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, |
| 854 arraysize(kVerbatimMatches), | 854 arraysize(kVerbatimMatches), |
| 855 &matches); | 855 &matches); |
| 856 result.AppendMatches(matches); | 856 result.AppendMatches(matches); |
| 857 EXPECT_FALSE(result.ShouldHideTopMatch()); | 857 EXPECT_FALSE(result.ShouldHideTopMatch()); |
| 858 } | 858 } |
| OLD | NEW |