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

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: rebase 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
« no previous file with comments | « chrome/browser/omnibox/omnibox_field_trial.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
19 } 20 }
20 21
(...skipping 101 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, GetValueForRuleInContext) {
135 // Must be the same as kBundledExperimentFieldTrialName
136 // defined in omnibox_field_trial.cc.
137 const std::string kTrialName = "OmniboxBundledExperimentV1";
138 {
139 std::map<std::string, std::string> params;
140 // Rule 1 has some exact matches and a global fallback.
141 params["rule1:1"] = "rule1-1-value"; // NEW_TAB_PAGE
142 params["rule1:3"] = "rule1-3-value"; // HOMEPAGE
143 params["rule1:*"] = "rule1-*-value"; // global
144 // Rule 2 has no exact matches but has a global fallback.
145 params["rule2:*"] = "rule2-*-value"; // global
146 // Rule 3 has an exact match but no global fallback.
147 params["rule3:4"] = "rule3-4-value"; // OTHER
148 // Add a malformed rule to make sure it doesn't screw things up.
149 params["unrecognized"] = "unrecognized-value";
150 ASSERT_TRUE(chrome_variations::AssociateVariationParams(
151 kTrialName, "A", params));
152 }
153
154 base::FieldTrialList::CreateFieldTrial(kTrialName, "A");
155
156 // Tests for rule 1.
157 EXPECT_EQ(
158 "rule1-1-value",
159 OmniboxFieldTrial::GetValueForRuleInContext(
160 "rule1", AutocompleteInput::NEW_TAB_PAGE)); // exact match
161 EXPECT_EQ(
162 "rule1-*-value",
163 OmniboxFieldTrial::GetValueForRuleInContext(
164 "rule1", AutocompleteInput::BLANK)); // fallback to global
165 EXPECT_EQ(
166 "rule1-3-value",
167 OmniboxFieldTrial::GetValueForRuleInContext(
168 "rule1", AutocompleteInput::HOMEPAGE)); // exact match
169 EXPECT_EQ(
170 "rule1-*-value",
171 OmniboxFieldTrial::GetValueForRuleInContext(
172 "rule1", AutocompleteInput::OTHER)); // fallback to global
173
174 // Tests for rule 2.
175 EXPECT_EQ(
176 "rule2-*-value",
177 OmniboxFieldTrial::GetValueForRuleInContext(
178 "rule2", AutocompleteInput::HOMEPAGE)); // fallback to global
179 EXPECT_EQ(
180 "rule2-*-value",
181 OmniboxFieldTrial::GetValueForRuleInContext(
182 "rule2", AutocompleteInput::OTHER)); // fallback to global
183
184 // Tests for rule 3.
185 EXPECT_EQ(
186 "",
187 OmniboxFieldTrial::GetValueForRuleInContext(
188 "rule3", AutocompleteInput::BLANK)); // no global fallback
189 EXPECT_EQ(
190 "",
191 OmniboxFieldTrial::GetValueForRuleInContext(
192 "rule3", AutocompleteInput::HOMEPAGE)); // no global fallback
193 EXPECT_EQ(
194 "rule3-4-value",
195 OmniboxFieldTrial::GetValueForRuleInContext(
196 "rule3", AutocompleteInput::OTHER)); // exact match
197
198 // Tests for rule 4 (a missing rule).
199 EXPECT_EQ(
200 "",
201 OmniboxFieldTrial::GetValueForRuleInContext(
202 "rule4", AutocompleteInput::OTHER)); // no rule at all
203 }
OLDNEW
« no previous file with comments | « chrome/browser/omnibox/omnibox_field_trial.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698