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

Unified Diff: chrome/browser/autocomplete/autocomplete_result_unittest.cc

Issue 22031002: Omnibox: Create DemoteByType Experiment (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix include that caused android build failure Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autocomplete/autocomplete_result_unittest.cc
diff --git a/chrome/browser/autocomplete/autocomplete_result_unittest.cc b/chrome/browser/autocomplete/autocomplete_result_unittest.cc
index 3038c27a017dd8d6ca05996518140d6486edf7cd..d669f60001c4154a819128896d6fb00214d52522 100644
--- a/chrome/browser/autocomplete/autocomplete_result_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_result_unittest.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/autocomplete/autocomplete_result.h"
+#include "base/memory/scoped_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
@@ -13,6 +14,9 @@
#include "chrome/browser/search_engines/template_url_prepopulate_data.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_test_util.h"
+#include "chrome/common/autocomplete_match_type.h"
+#include "chrome/common/metrics/entropy_provider.h"
+#include "chrome/common/metrics/variations/variations_util.h"
#include "chrome/test/base/testing_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -30,7 +34,14 @@ class AutocompleteResultTest : public testing::Test {
int relevance;
};
- AutocompleteResultTest() {}
+ AutocompleteResultTest() {
+ // Destroy the existing FieldTrialList before creating a new one to avoid
+ // a DCHECK.
+ field_trial_list_.reset();
+ field_trial_list_.reset(new base::FieldTrialList(
+ new metrics::SHA1EntropyProvider("foo")));
+ chrome_variations::testing::ClearAllVariationParams();
+ }
virtual void SetUp() OVERRIDE {
#if defined(OS_ANDROID)
@@ -69,6 +80,8 @@ class AutocompleteResultTest : public testing::Test {
TemplateURLServiceTestUtil test_util_;
private:
+ scoped_ptr<base::FieldTrialList> field_trial_list_;
+
DISALLOW_COPY_AND_ASSIGN(AutocompleteResultTest);
};
@@ -148,6 +161,7 @@ TEST_F(AutocompleteResultTest, Swap) {
// Swap with a single match.
ACMatches matches;
AutocompleteMatch match;
+ match.relevance = 1;
AutocompleteInput input(ASCIIToUTF16("a"), string16::npos, string16(), GURL(),
AutocompleteInput::INVALID_SPEC, false, false, false,
AutocompleteInput::ALL_MATCHES);
@@ -292,3 +306,69 @@ TEST_F(AutocompleteResultTest, SortAndCullDuplicateSearchURLs) {
result.match_at(2)->destination_url.spec());
EXPECT_EQ(900, result.match_at(2)->relevance);
}
+
+TEST_F(AutocompleteResultTest, SortAndCullWithDemotionsByType) {
+ // Add some matches.
+ ACMatches matches;
+ {
+ AutocompleteMatch match;
+ match.destination_url = GURL("http://history-url/");
+ match.relevance = 1400;
+ match.type = AutocompleteMatchType::HISTORY_URL;
+ matches.push_back(match);
+ }
+ {
+ AutocompleteMatch match;
+ match.destination_url = GURL("http://search-what-you-typed/");
+ match.relevance = 1300;
+ match.type = AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED;
+ matches.push_back(match);
+ }
+ {
+ AutocompleteMatch match;
+ match.destination_url = GURL("http://history-title/");
+ match.relevance = 1200;
+ match.type = AutocompleteMatchType::HISTORY_TITLE;
+ matches.push_back(match);
+ }
+ {
+ AutocompleteMatch match;
+ match.destination_url = GURL("http://search-history/");
+ match.relevance = 500;
+ match.type = AutocompleteMatchType::SEARCH_HISTORY;
+ matches.push_back(match);
+ }
+
+ // Add a rule demoting history-url and killing history-title.
+ // Must be the same as kBundledExperimentFieldTrialName
+ // defined in omnibox_field_trial.cc.
+ const std::string kTrialName = "OmniboxBundledExperimentV1";
+ // Must be the same as kDemoteByTypeRule defined in
+ // omnibox_field_trial.cc.
+ const std::string kRuleName = "DemoteByType";
+ {
+ std::map<std::string, std::string> params;
+ params[kRuleName + ":3"] = "1:50,7:100,2:0"; // 3 == HOMEPAGE
+ ASSERT_TRUE(chrome_variations::AssociateVariationParams(
+ kTrialName, "A", params));
+ }
+ base::FieldTrialList::CreateFieldTrial(kTrialName, "A");
+
+ AutocompleteResult result;
+ result.AppendMatches(matches);
+ AutocompleteInput input(string16(), string16::npos, string16(), GURL(),
+ AutocompleteInput::HOMEPAGE, false, false, false,
+ AutocompleteInput::ALL_MATCHES);
+ result.SortAndCull(input, test_util_.profile());
+
+ // Check the new ordering. The history-title results should be omitted.
+ // We cannot check relevance scores because the matches are sorted by
+ // demoted relevance but the actual relevance scores are not modified.
+ ASSERT_EQ(3u, result.size());
+ EXPECT_EQ("http://search-what-you-typed/",
+ result.match_at(0)->destination_url.spec());
+ EXPECT_EQ("http://history-url/",
+ result.match_at(1)->destination_url.spec());
+ EXPECT_EQ("http://search-history/",
+ result.match_at(2)->destination_url.spec());
+}
« 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