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

Side by Side Diff: chrome/browser/omnibox/omnibox_field_trial_unittest.cc

Issue 20777006: Omnibox: Create Bundled Field Trial; Convert SearchHistory trial to it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: slightly revise comment 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/omnibox/omnibox_field_trial.h" 5 #include "chrome/browser/omnibox/omnibox_field_trial.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "chrome/common/metrics/entropy_provider.h" 10 #include "chrome/common/metrics/entropy_provider.h"
11 #include "chrome/common/metrics/variations/variations_util.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 class OmniboxFieldTrialTest : public testing::Test { 14 class OmniboxFieldTrialTest : public testing::Test {
14 public: 15 public:
15 OmniboxFieldTrialTest() {} 16 OmniboxFieldTrialTest() {}
16 17
17 static void SetUpTestCase() { 18 static void SetUpTestCase() {
18 ResetFieldTrialList(); 19 ResetFieldTrialList();
Alexei Svitkine (slow) 2013/07/31 20:27:46 Hmm, I think this keeps the field trial list persi
Mark P 2013/07/31 21:59:28 These tests pass as-is. (This isn't the changelis
19 } 20 }
20 21
21 static void TearDownTestCase() { 22 static void TearDownTestCase() {
22 delete field_trial_list_; 23 delete field_trial_list_;
23 field_trial_list_ = NULL; 24 field_trial_list_ = NULL;
24 } 25 }
25 26
26 static void ResetFieldTrialList() { 27 static void ResetFieldTrialList() {
27 // It's important to delete the old pointer first which sets 28 // It's important to delete the old pointer first which sets
28 // FieldTrialList::global_ to NULL. 29 // FieldTrialList::global_ to NULL.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 123
123 ResetFieldTrialList(); 124 ResetFieldTrialList();
124 CreateTestTrial("AutocompleteDynamicTrial_2", "EnableZeroSuggest_Queries"); 125 CreateTestTrial("AutocompleteDynamicTrial_2", "EnableZeroSuggest_Queries");
125 EXPECT_TRUE(OmniboxFieldTrial::InZeroSuggestFieldTrial()); 126 EXPECT_TRUE(OmniboxFieldTrial::InZeroSuggestFieldTrial());
126 127
127 ResetFieldTrialList(); 128 ResetFieldTrialList();
128 CreateTestTrial("AutocompleteDynamicTrial_3", "EnableZeroSuggest_URLs"); 129 CreateTestTrial("AutocompleteDynamicTrial_3", "EnableZeroSuggest_URLs");
129 EXPECT_TRUE(OmniboxFieldTrial::InZeroSuggestFieldTrial()); 130 EXPECT_TRUE(OmniboxFieldTrial::InZeroSuggestFieldTrial());
130 } 131 }
131 } 132 }
133
134 TEST_F(OmniboxFieldTrialTest,
135 GetConsequencesOfRuleInPageClassificationContext) {
136 // Must be the same as kBundledExperimentFieldTrialName
137 // defined in omnibox_field_trial.cc.
Peter Kasting 2013/07/31 20:14:09 Nit: Should we declare this in a .h somewhere, the
Mark P 2013/07/31 21:59:28 I'd rather not have someone reading the .h have to
Alexei Svitkine (slow) 2013/08/01 15:25:35 Fair enough, SGTM.
138 const std::string kTrialName = "OmniboxBundledExperimentV1";
139 {
140 std::map<std::string, std::string> params;
141 params["1:rule1"] = "1-rule1-value";
142 params["3:rule1"] = "3-rule1-value";
143 params["*:rule1"] = "*-rule1-value";
144 params["*:rule2"] = "*-rule2-value";
145 params["4:rule3"] = "4-rule3-value";
146 params["unrecognized"] = "unrecognized-value";
147 ASSERT_TRUE(chrome_variations::AssociateVariationParams(
148 kTrialName, "A", params));
149 }
150
151 base::FieldTrialList::CreateFieldTrial(kTrialName, "A");
152 EXPECT_EQ("1-rule1-value",
153 OmniboxFieldTrial::GetConsequencesOfRuleInPageClassificationContext(
154 AutocompleteInput::NEW_TAB_PAGE, "rule1")); // exact match
155 EXPECT_EQ("*-rule1-value",
156 OmniboxFieldTrial::GetConsequencesOfRuleInPageClassificationContext(
157 AutocompleteInput::BLANK, "rule1")); // fallback to global
158 EXPECT_EQ("3-rule1-value",
159 OmniboxFieldTrial::GetConsequencesOfRuleInPageClassificationContext(
160 AutocompleteInput::HOMEPAGE, "rule1")); // exact match
161 EXPECT_EQ("*-rule1-value",
162 OmniboxFieldTrial::GetConsequencesOfRuleInPageClassificationContext(
163 AutocompleteInput::OTHER, "rule1")); // fallback to global
164 EXPECT_EQ("*-rule2-value",
165 OmniboxFieldTrial::GetConsequencesOfRuleInPageClassificationContext(
166 AutocompleteInput::HOMEPAGE, "rule2")); // fallback to global
167 EXPECT_EQ("*-rule2-value",
168 OmniboxFieldTrial::GetConsequencesOfRuleInPageClassificationContext(
169 AutocompleteInput::OTHER, "rule2")); // fallback to global
170 EXPECT_EQ("",
171 OmniboxFieldTrial::GetConsequencesOfRuleInPageClassificationContext(
172 AutocompleteInput::BLANK, "rule3")); // no global
173 EXPECT_EQ("",
174 OmniboxFieldTrial::GetConsequencesOfRuleInPageClassificationContext(
175 AutocompleteInput::HOMEPAGE, "rule3")); // no global
176 EXPECT_EQ("4-rule3-value",
177 OmniboxFieldTrial::GetConsequencesOfRuleInPageClassificationContext(
178 AutocompleteInput::OTHER, "rule3")); // exact match
179 EXPECT_EQ("",
180 OmniboxFieldTrial::GetConsequencesOfRuleInPageClassificationContext(
181 AutocompleteInput::OTHER, "rule4")); // no rule at all
182 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698