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

Side by Side Diff: chrome/browser/search/search_unittest.cc

Issue 24733003: Update defaults for InstantExtended. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unused. 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/search/search.cc ('k') | chrome/browser/search_engines/template_url.cc » ('j') | 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/metrics/field_trial.h" 6 #include "base/metrics/field_trial.h"
7 #include "base/metrics/histogram_base.h"
8 #include "base/metrics/histogram_samples.h"
9 #include "base/metrics/statistics_recorder.h" 7 #include "base/metrics/statistics_recorder.h"
10 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
11 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" 9 #include "chrome/browser/managed_mode/managed_mode_url_filter.h"
12 #include "chrome/browser/managed_mode/managed_user_service.h" 10 #include "chrome/browser/managed_mode/managed_user_service.h"
13 #include "chrome/browser/managed_mode/managed_user_service_factory.h" 11 #include "chrome/browser/managed_mode/managed_user_service_factory.h"
14 #include "chrome/browser/search/instant_service.h" 12 #include "chrome/browser/search/instant_service.h"
15 #include "chrome/browser/search/instant_service_factory.h" 13 #include "chrome/browser/search/instant_service_factory.h"
16 #include "chrome/browser/search/search.h" 14 #include "chrome/browser/search/search.h"
17 #include "chrome/browser/search_engines/search_terms_data.h" 15 #include "chrome/browser/search_engines/search_terms_data.h"
18 #include "chrome/browser/search_engines/template_url_service.h" 16 #include "chrome/browser/search_engines/template_url_service.h"
(...skipping 13 matching lines...) Expand all
32 #include "url/gurl.h" 30 #include "url/gurl.h"
33 31
34 namespace chrome { 32 namespace chrome {
35 33
36 class EmbeddedSearchFieldTrialTest : public testing::Test { 34 class EmbeddedSearchFieldTrialTest : public testing::Test {
37 protected: 35 protected:
38 virtual void SetUp() { 36 virtual void SetUp() {
39 field_trial_list_.reset(new base::FieldTrialList( 37 field_trial_list_.reset(new base::FieldTrialList(
40 new metrics::SHA1EntropyProvider("42"))); 38 new metrics::SHA1EntropyProvider("42")));
41 base::StatisticsRecorder::Initialize(); 39 base::StatisticsRecorder::Initialize();
42 ResetInstantExtendedOptInStateGateForTest();
43 } 40 }
44 41
45 private: 42 private:
46 scoped_ptr<base::FieldTrialList> field_trial_list_; 43 scoped_ptr<base::FieldTrialList> field_trial_list_;
47 }; 44 };
48 45
49 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoEmptyAndValid) { 46 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoEmptyAndValid) {
50 FieldTrialFlags flags; 47 FieldTrialFlags flags;
51 uint64 group_number = 0;
52 48
53 EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number)); 49 EXPECT_TRUE(GetFieldTrialInfo(&flags));
54 EXPECT_EQ(0ul, group_number);
55 EXPECT_EQ(0ul, flags.size()); 50 EXPECT_EQ(0ul, flags.size());
56 51
57 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", 52 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
58 "Group77")); 53 "EmbeddedSearch", "Group77"));
59 EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number)); 54 EXPECT_TRUE(GetFieldTrialInfo(&flags));
60 EXPECT_EQ(77ul, group_number);
61 EXPECT_EQ(0ul, flags.size()); 55 EXPECT_EQ(0ul, flags.size());
62 } 56 }
63 57
64 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoInvalidNumber) { 58 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoInvalidNumber) {
65 FieldTrialFlags flags; 59 FieldTrialFlags flags;
66 uint64 group_number = 0;
67 60
68 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", 61 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
69 "Group77.2")); 62 "EmbeddedSearch", "Group77.2"));
70 EXPECT_FALSE(GetFieldTrialInfo(&flags, &group_number)); 63 EXPECT_TRUE(GetFieldTrialInfo(&flags));
71 EXPECT_EQ(0ul, group_number);
72 EXPECT_EQ(0ul, flags.size()); 64 EXPECT_EQ(0ul, flags.size());
73 } 65 }
74 66
75 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoInvalidName) { 67 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoInvalidName) {
76 FieldTrialFlags flags; 68 FieldTrialFlags flags;
77 uint64 group_number = 0;
78 69
79 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", 70 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
80 "Invalid77")); 71 "EmbeddedSearch", "Invalid77"));
81 EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number)); 72 EXPECT_TRUE(GetFieldTrialInfo(&flags));
82 EXPECT_EQ(0ul, group_number);
83 EXPECT_EQ(0ul, flags.size()); 73 EXPECT_EQ(0ul, flags.size());
84 } 74 }
85 75
86 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoValidGroup) { 76 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoValidGroup) {
87 FieldTrialFlags flags; 77 FieldTrialFlags flags;
88 uint64 group_number = 0;
89 78
90 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", 79 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
91 "Group77")); 80 "EmbeddedSearch", "Group77"));
92 EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number)); 81 EXPECT_TRUE(GetFieldTrialInfo(&flags));
93 EXPECT_EQ(77ul, group_number);
94 EXPECT_EQ(0ul, flags.size()); 82 EXPECT_EQ(0ul, flags.size());
95 } 83 }
96 84
97 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoValidFlag) { 85 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoValidFlag) {
98 FieldTrialFlags flags; 86 FieldTrialFlags flags;
99 uint64 group_number = 0;
100 87
101 EXPECT_EQ(9999ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); 88 EXPECT_EQ(9999ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags));
102 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", 89 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
103 "Group77 foo:6")); 90 "EmbeddedSearch", "Group77 foo:6"));
104 EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number)); 91 EXPECT_TRUE(GetFieldTrialInfo(&flags));
105 EXPECT_EQ(77ul, group_number);
106 EXPECT_EQ(1ul, flags.size()); 92 EXPECT_EQ(1ul, flags.size());
107 EXPECT_EQ(6ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); 93 EXPECT_EQ(6ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags));
108 } 94 }
109 95
110 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoNewName) { 96 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoNewName) {
111 FieldTrialFlags flags; 97 FieldTrialFlags flags;
112 uint64 group_number = 0;
113 98
114 EXPECT_EQ(9999ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); 99 EXPECT_EQ(9999ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags));
115 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", 100 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
116 "Group77 foo:6")); 101 "EmbeddedSearch", "Group77 foo:6"));
117 EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number)); 102 EXPECT_TRUE(GetFieldTrialInfo(&flags));
118 EXPECT_EQ(77ul, group_number);
119 EXPECT_EQ(1ul, flags.size()); 103 EXPECT_EQ(1ul, flags.size());
120 EXPECT_EQ(6ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); 104 EXPECT_EQ(6ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags));
121 } 105 }
122 106
123 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoNewNameOverridesOld) { 107 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoNewNameOverridesOld) {
124 FieldTrialFlags flags; 108 FieldTrialFlags flags;
125 uint64 group_number = 0;
126 109
127 EXPECT_EQ(9999ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); 110 EXPECT_EQ(9999ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags));
128 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", 111 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
129 "Group77 foo:6")); 112 "EmbeddedSearch", "Group77 foo:6"));
130 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended", 113 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
131 "Group78 foo:5")); 114 "InstantExtended", "Group78 foo:5"));
132 EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number)); 115 EXPECT_TRUE(GetFieldTrialInfo(&flags));
133 EXPECT_EQ(77ul, group_number);
134 EXPECT_EQ(1ul, flags.size()); 116 EXPECT_EQ(1ul, flags.size());
135 EXPECT_EQ(6ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); 117 EXPECT_EQ(6ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags));
136 } 118 }
137 119
138 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoLotsOfFlags) { 120 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoLotsOfFlags) {
139 FieldTrialFlags flags; 121 FieldTrialFlags flags;
140 uint64 group_number = 0;
141 122
142 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 123 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
143 "EmbeddedSearch", "Group77 bar:1 baz:7 cat:dogs")); 124 "EmbeddedSearch", "Group77 bar:1 baz:7 cat:dogs"));
144 EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number)); 125 EXPECT_TRUE(GetFieldTrialInfo(&flags));
145 EXPECT_EQ(77ul, group_number);
146 EXPECT_EQ(3ul, flags.size()); 126 EXPECT_EQ(3ul, flags.size());
147 EXPECT_EQ(true, GetBoolValueForFlagWithDefault("bar", false, flags)); 127 EXPECT_EQ(true, GetBoolValueForFlagWithDefault("bar", false, flags));
148 EXPECT_EQ(7ul, GetUInt64ValueForFlagWithDefault("baz", 0, flags)); 128 EXPECT_EQ(7ul, GetUInt64ValueForFlagWithDefault("baz", 0, flags));
149 EXPECT_EQ("dogs", 129 EXPECT_EQ("dogs",
150 GetStringValueForFlagWithDefault("cat", std::string(), flags)); 130 GetStringValueForFlagWithDefault("cat", std::string(), flags));
151 EXPECT_EQ("default", 131 EXPECT_EQ("default",
152 GetStringValueForFlagWithDefault("moose", "default", flags)); 132 GetStringValueForFlagWithDefault("moose", "default", flags));
153 } 133 }
154 134
155 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoDisabled) { 135 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoDisabled) {
156 FieldTrialFlags flags; 136 FieldTrialFlags flags;
157 uint64 group_number = 0;
158 137
159 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 138 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
160 "EmbeddedSearch", "Group77 bar:1 baz:7 cat:dogs DISABLED")); 139 "EmbeddedSearch", "Group77 bar:1 baz:7 cat:dogs DISABLED"));
161 EXPECT_FALSE(GetFieldTrialInfo(&flags, &group_number)); 140 EXPECT_FALSE(GetFieldTrialInfo(&flags));
162 EXPECT_EQ(0ul, group_number);
163 EXPECT_EQ(0ul, flags.size()); 141 EXPECT_EQ(0ul, flags.size());
164 } 142 }
165 143
166 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoControlFlags) { 144 TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoControlFlags) {
167 FieldTrialFlags flags; 145 FieldTrialFlags flags;
168 uint64 group_number = 0;
169 146
170 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 147 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
171 "EmbeddedSearch", "Control77 bar:1 baz:7 cat:dogs")); 148 "InstantExtended", "Control77 bar:1 baz:7 cat:dogs"));
172 EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number)); 149 EXPECT_TRUE(GetFieldTrialInfo(&flags));
173 EXPECT_EQ(0ul, group_number);
174 EXPECT_EQ(3ul, flags.size()); 150 EXPECT_EQ(3ul, flags.size());
175 } 151 }
176 152
177 class InstantExtendedAPIEnabledTest : public testing::Test { 153 class SearchTest : public BrowserWithTestWindowTest {
178 public:
179 InstantExtendedAPIEnabledTest() : histogram_(NULL) {
180 }
181 protected: 154 protected:
182 virtual void SetUp() { 155 virtual void SetUp() OVERRIDE {
156 BrowserWithTestWindowTest::SetUp();
183 field_trial_list_.reset(new base::FieldTrialList( 157 field_trial_list_.reset(new base::FieldTrialList(
184 new metrics::SHA1EntropyProvider("42"))); 158 new metrics::SHA1EntropyProvider("42")));
185 base::StatisticsRecorder::Initialize(); 159 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
186 ResetInstantExtendedOptInStateGateForTest(); 160 profile(), &TemplateURLServiceFactory::BuildInstanceFor);
187 previous_metrics_count_.resize(INSTANT_EXTENDED_OPT_IN_STATE_ENUM_COUNT, 0); 161 TemplateURLService* template_url_service =
188 base::HistogramBase* histogram = GetHistogram(); 162 TemplateURLServiceFactory::GetForProfile(profile());
189 if (histogram) { 163 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service);
190 scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); 164 SetSearchProvider(true, false);
191 if (samples.get()) {
192 for (int state = INSTANT_EXTENDED_NOT_SET;
193 state < INSTANT_EXTENDED_OPT_IN_STATE_ENUM_COUNT; ++state) {
194 previous_metrics_count_[state] = samples->GetCount(state);
195 }
196 }
197 }
198 } 165 }
199 166
200 virtual CommandLine* GetCommandLine() const { 167 void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url) {
201 return CommandLine::ForCurrentProcess(); 168 TemplateURLService* template_url_service =
169 TemplateURLServiceFactory::GetForProfile(profile());
170 TemplateURLData data;
171 data.SetURL("http://foo.com/url?bar={searchTerms}");
172 data.instant_url = "http://foo.com/instant?"
173 "{google:omniboxStartMarginParameter}{google:forceInstantResults}"
174 "foo=foo#foo=foo&strk";
175 if (set_ntp_url) {
176 data.new_tab_url = (insecure_ntp_url ? "http" : "https") +
177 std::string("://foo.com/newtab?strk");
178 }
179 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}");
180 data.search_terms_replacement_key = "strk";
181
182 TemplateURL* template_url = new TemplateURL(profile(), data);
183 // Takes ownership of |template_url|.
184 template_url_service->Add(template_url);
185 template_url_service->SetDefaultSearchProvider(template_url);
202 } 186 }
203 187
204 void ValidateMetrics(base::HistogramBase::Sample value) { 188 // Build an Instant URL with or without a valid search terms replacement key
205 base::HistogramBase* histogram = GetHistogram(); 189 // as per |has_search_term_replacement_key|. Set that URL as the instant URL
206 if (histogram) { 190 // for the default search provider.
207 scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); 191 void SetDefaultInstantTemplateUrl(bool has_search_term_replacement_key) {
208 if (samples.get()) { 192 TemplateURLService* template_url_service =
209 for (int state = INSTANT_EXTENDED_NOT_SET; 193 TemplateURLServiceFactory::GetForProfile(profile());
210 state < INSTANT_EXTENDED_OPT_IN_STATE_ENUM_COUNT; ++state) { 194
211 if (state == value) { 195 static const char kInstantURLWithStrk[] =
212 EXPECT_EQ(previous_metrics_count_[state] + 1, 196 "http://foo.com/instant?foo=foo#foo=foo&strk";
213 samples->GetCount(state)); 197 static const char kInstantURLNoStrk[] =
214 } else { 198 "http://foo.com/instant?foo=foo#foo=foo";
215 EXPECT_EQ(previous_metrics_count_[state], samples->GetCount(state)); 199
216 } 200 TemplateURLData data;
217 } 201 data.SetURL("http://foo.com/url?bar={searchTerms}");
218 } 202 data.instant_url = (has_search_term_replacement_key ?
219 } 203 kInstantURLWithStrk : kInstantURLNoStrk);
204 data.search_terms_replacement_key = "strk";
205
206 TemplateURL* template_url = new TemplateURL(profile(), data);
207 // Takes ownership of |template_url|.
208 template_url_service->Add(template_url);
209 template_url_service->SetDefaultSearchProvider(template_url);
220 } 210 }
221 211
222 private: 212 bool InInstantProcess(const content::WebContents* contents) {
223 base::HistogramBase* GetHistogram() { 213 InstantService* instant_service =
224 if (!histogram_) { 214 InstantServiceFactory::GetForProfile(profile());
225 histogram_ = base::StatisticsRecorder::FindHistogram( 215 return instant_service->IsInstantProcess(
226 "InstantExtended.OptInState"); 216 contents->GetRenderProcessHost()->GetID());
227 }
228 return histogram_;
229 } 217 }
230 base::HistogramBase* histogram_; 218
231 scoped_ptr<base::FieldTrialList> field_trial_list_; 219 scoped_ptr<base::FieldTrialList> field_trial_list_;
232 std::vector<int> previous_metrics_count_;
233 }; 220 };
234 221
235 TEST_F(InstantExtendedAPIEnabledTest, EnabledViaCommandLineFlag) { 222 typedef SearchTest ShouldHideTopVerbatimTest;
236 GetCommandLine()->AppendSwitch(switches::kEnableInstantExtendedAPI);
237 EXPECT_TRUE(IsInstantExtendedAPIEnabled());
238 #if defined(OS_IOS) || defined(OS_ANDROID)
239 EXPECT_EQ(1ul, EmbeddedSearchPageVersion());
240 #else
241 EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
242 #endif
243 ValidateMetrics(INSTANT_EXTENDED_OPT_IN);
244 }
245
246 TEST_F(InstantExtendedAPIEnabledTest, EnabledViaFinchFlag) {
247 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
248 "Group1 espv:42"));
249 EXPECT_TRUE(IsInstantExtendedAPIEnabled());
250 EXPECT_EQ(42ul, EmbeddedSearchPageVersion());
251 ValidateMetrics(INSTANT_EXTENDED_NOT_SET);
252 }
253
254 TEST_F(InstantExtendedAPIEnabledTest, DisabledViaCommandLineFlag) {
255 GetCommandLine()->AppendSwitch(switches::kDisableInstantExtendedAPI);
256 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
257 "Group1 espv:2"));
258 EXPECT_FALSE(IsInstantExtendedAPIEnabled());
259 EXPECT_EQ(0ul, EmbeddedSearchPageVersion());
260 ValidateMetrics(INSTANT_EXTENDED_OPT_OUT);
261 }
262
263 typedef InstantExtendedAPIEnabledTest ShouldHideTopVerbatimTest;
264 223
265 TEST_F(ShouldHideTopVerbatimTest, DoNotHideByDefault) { 224 TEST_F(ShouldHideTopVerbatimTest, DoNotHideByDefault) {
266 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", 225 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
267 "Control")); 226 "InstantExtended", "Control"));
268 EXPECT_FALSE(ShouldHideTopVerbatimMatch()); 227 EXPECT_FALSE(ShouldHideTopVerbatimMatch());
269 } 228 }
270 229
271 TEST_F(ShouldHideTopVerbatimTest, DoNotHideInInstantExtended) { 230 TEST_F(ShouldHideTopVerbatimTest, DoNotHideInInstantExtended) {
272 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", 231 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
273 "Group1")); 232 "InstantExtended", "Group1"));
274 EXPECT_FALSE(ShouldHideTopVerbatimMatch()); 233 EXPECT_FALSE(ShouldHideTopVerbatimMatch());
275 } 234 }
276 235
277 TEST_F(ShouldHideTopVerbatimTest, EnableByFlagInInstantExtended) { 236 TEST_F(ShouldHideTopVerbatimTest, EnableByFlagInInstantExtended) {
278 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", 237 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
279 "Group1 hide_verbatim:1")); 238 "InstantExtended", "Group1 hide_verbatim:1"));
280 EXPECT_TRUE(ShouldHideTopVerbatimMatch()); 239 EXPECT_TRUE(ShouldHideTopVerbatimMatch());
281 } 240 }
282 241
283 TEST_F(ShouldHideTopVerbatimTest, EnableByFlagOutsideInstantExtended) { 242 TEST_F(ShouldHideTopVerbatimTest, EnableByFlagOutsideInstantExtended) {
284 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 243 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
285 "EmbeddedSearch", "Controll1 hide_verbatim:1")); 244 "InstantExtended", "Controll1 hide_verbatim:1"));
286 EXPECT_TRUE(ShouldHideTopVerbatimMatch()); 245 EXPECT_TRUE(ShouldHideTopVerbatimMatch());
287 } 246 }
288 247
289 TEST_F(ShouldHideTopVerbatimTest, DisableByFlag) { 248 TEST_F(ShouldHideTopVerbatimTest, DisableByFlag) {
290 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", 249 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
291 "Group1 hide_verbatim:0")); 250 "InstantExtended", "Group1 hide_verbatim:0"));
292 EXPECT_FALSE(ShouldHideTopVerbatimMatch()); 251 EXPECT_FALSE(ShouldHideTopVerbatimMatch());
293 } 252 }
294 253
295 typedef InstantExtendedAPIEnabledTest ShouldSuppressInstantExtendedOnSRPTest; 254 typedef SearchTest IsQueryExtractionEnabledTest;
296 255
297 TEST_F(ShouldSuppressInstantExtendedOnSRPTest, NotSet) { 256 TEST_F(IsQueryExtractionEnabledTest, NotSet) {
298 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", 257 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
299 "Group1 espv:2")); 258 "InstantExtended", "Group1 espv:2"));
300 EXPECT_FALSE(ShouldSuppressInstantExtendedOnSRP()); 259 EXPECT_TRUE(IsInstantExtendedAPIEnabled());
260 EXPECT_FALSE(IsQueryExtractionEnabled());
261 EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
262 }
263
264 TEST_F(IsQueryExtractionEnabledTest, QueryExtractionEnabledViaFinch) {
265 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
266 "InstantExtended", "Group1 espv:2 query_extraction:1"));
301 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); 267 EXPECT_TRUE(IsInstantExtendedAPIEnabled());
302 EXPECT_TRUE(IsQueryExtractionEnabled()); 268 EXPECT_TRUE(IsQueryExtractionEnabled());
303 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); 269 EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
304 } 270 }
305 271
306 TEST_F(ShouldSuppressInstantExtendedOnSRPTest, NotSuppressOnSRP) { 272 TEST_F(IsQueryExtractionEnabledTest, QueryExtractionEnabledViaCommandLine) {
307 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 273 EnableQueryExtractionForTesting();
308 "EmbeddedSearch", "Group1 espv:2 suppress_on_srp:0"));
309 EXPECT_FALSE(ShouldSuppressInstantExtendedOnSRP());
310 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); 274 EXPECT_TRUE(IsInstantExtendedAPIEnabled());
311 EXPECT_TRUE(IsQueryExtractionEnabled()); 275 EXPECT_TRUE(IsQueryExtractionEnabled());
312 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); 276 EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
313 } 277 }
314 278
315 TEST_F(ShouldSuppressInstantExtendedOnSRPTest, SuppressOnSRP) { 279 TEST_F(IsQueryExtractionEnabledTest, QueryExtractionDisabledViaFinch) {
316 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 280 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
317 "EmbeddedSearch", "Group1 espv:2 suppress_on_srp:1")); 281 "InstantExtended", "Group1 espv:2 query_extraction:0"));
318 EXPECT_TRUE(ShouldSuppressInstantExtendedOnSRP());
319 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); 282 EXPECT_TRUE(IsInstantExtendedAPIEnabled());
320 EXPECT_FALSE(IsQueryExtractionEnabled()); 283 EXPECT_FALSE(IsQueryExtractionEnabled());
321 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); 284 EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
322 } 285 }
323 286
324 typedef InstantExtendedAPIEnabledTest DisplaySearchButtonTest; 287 typedef SearchTest DisplaySearchButtonTest;
325 288
326 TEST_F(DisplaySearchButtonTest, NotSet) { 289 TEST_F(DisplaySearchButtonTest, NotSet) {
327 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 290 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
328 "EmbeddedSearch", "Group1 espv:2")); 291 "EmbeddedSearch", "Group1 espv:2"));
329 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions()); 292 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions());
330 } 293 }
331 294
332 TEST_F(DisplaySearchButtonTest, Never) { 295 TEST_F(DisplaySearchButtonTest, Never) {
333 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 296 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
334 "EmbeddedSearch", "Group1 espv:2 display_search_button:0")); 297 "EmbeddedSearch", "Group1 espv:2 display_search_button:0"));
(...skipping 18 matching lines...) Expand all
353 "EmbeddedSearch", "Group1 espv:2 display_search_button:3")); 316 "EmbeddedSearch", "Group1 espv:2 display_search_button:3"));
354 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_ALWAYS, GetDisplaySearchButtonConditions()); 317 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_ALWAYS, GetDisplaySearchButtonConditions());
355 } 318 }
356 319
357 TEST_F(DisplaySearchButtonTest, InvalidValue) { 320 TEST_F(DisplaySearchButtonTest, InvalidValue) {
358 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 321 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
359 "EmbeddedSearch", "Group1 espv:2 display_search_button:4")); 322 "EmbeddedSearch", "Group1 espv:2 display_search_button:4"));
360 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions()); 323 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions());
361 } 324 }
362 325
363 typedef InstantExtendedAPIEnabledTest OriginChipTest; 326 typedef SearchTest OriginChipTest;
364 327
365 TEST_F(OriginChipTest, NotSet) { 328 TEST_F(OriginChipTest, NotSet) {
366 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 329 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
367 "EmbeddedSearch", "Group1 espv:2")); 330 "EmbeddedSearch", "Group1 espv:2"));
368 EXPECT_FALSE(ShouldDisplayOriginChip()); 331 EXPECT_FALSE(ShouldDisplayOriginChip());
369 } 332 }
370 333
371 TEST_F(OriginChipTest, NoOriginChip) { 334 TEST_F(OriginChipTest, NoOriginChip) {
372 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 335 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
373 "EmbeddedSearch", "Group1 espv:2 origin_chip:0")); 336 "EmbeddedSearch", "Group1 espv:2 origin_chip:0"));
374 EXPECT_FALSE(ShouldDisplayOriginChip()); 337 EXPECT_FALSE(ShouldDisplayOriginChip());
375 } 338 }
376 339
377 TEST_F(OriginChipTest, OriginChip) { 340 TEST_F(OriginChipTest, OriginChip) {
378 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 341 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
379 "EmbeddedSearch", "Group1 espv:2 origin_chip:1")); 342 "EmbeddedSearch", "Group1 espv:2 origin_chip:1"));
380 EXPECT_TRUE(ShouldDisplayOriginChip()); 343 EXPECT_TRUE(ShouldDisplayOriginChip());
381 } 344 }
382 345
383 class SearchTest : public BrowserWithTestWindowTest {
384 protected:
385 virtual void SetUp() OVERRIDE {
386 BrowserWithTestWindowTest::SetUp();
387 field_trial_list_.reset(new base::FieldTrialList(
388 new metrics::SHA1EntropyProvider("42")));
389 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
390 profile(), &TemplateURLServiceFactory::BuildInstanceFor);
391 TemplateURLService* template_url_service =
392 TemplateURLServiceFactory::GetForProfile(profile());
393 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service);
394 SetSearchProvider(true, false);
395 }
396
397 void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url) {
398 TemplateURLService* template_url_service =
399 TemplateURLServiceFactory::GetForProfile(profile());
400 TemplateURLData data;
401 data.SetURL("http://foo.com/url?bar={searchTerms}");
402 data.instant_url = "http://foo.com/instant?"
403 "{google:omniboxStartMarginParameter}{google:forceInstantResults}"
404 "foo=foo#foo=foo&strk";
405 if (set_ntp_url) {
406 data.new_tab_url = (insecure_ntp_url ? "http" : "https") +
407 std::string("://foo.com/newtab?strk");
408 }
409 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}");
410 data.search_terms_replacement_key = "strk";
411
412 TemplateURL* template_url = new TemplateURL(profile(), data);
413 // Takes ownership of |template_url|.
414 template_url_service->Add(template_url);
415 template_url_service->SetDefaultSearchProvider(template_url);
416 }
417
418 // Build an Instant URL with or without a valid search terms replacement key
419 // as per |has_search_term_replacement_key|. Set that URL as the instant URL
420 // for the default search provider.
421 void SetDefaultInstantTemplateUrl(bool has_search_term_replacement_key) {
422 TemplateURLService* template_url_service =
423 TemplateURLServiceFactory::GetForProfile(profile());
424
425 static const char kInstantURLWithStrk[] =
426 "http://foo.com/instant?foo=foo#foo=foo&strk";
427 static const char kInstantURLNoStrk[] =
428 "http://foo.com/instant?foo=foo#foo=foo";
429
430 TemplateURLData data;
431 data.SetURL("http://foo.com/url?bar={searchTerms}");
432 data.instant_url = (has_search_term_replacement_key ?
433 kInstantURLWithStrk : kInstantURLNoStrk);
434 data.search_terms_replacement_key = "strk";
435
436 TemplateURL* template_url = new TemplateURL(profile(), data);
437 // Takes ownership of |template_url|.
438 template_url_service->Add(template_url);
439 template_url_service->SetDefaultSearchProvider(template_url);
440 }
441
442 bool InInstantProcess(const content::WebContents* contents) {
443 InstantService* instant_service =
444 InstantServiceFactory::GetForProfile(profile());
445 return instant_service->IsInstantProcess(
446 contents->GetRenderProcessHost()->GetID());
447 }
448
449 scoped_ptr<base::FieldTrialList> field_trial_list_;
450 };
451
452 struct SearchTestCase { 346 struct SearchTestCase {
453 const char* url; 347 const char* url;
454 bool expected_result; 348 bool expected_result;
455 const char* comment; 349 const char* comment;
456 }; 350 };
457 351
458 TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedDisabled) { 352 TEST_F(SearchTest, ShouldAssignURLToInstantRendererSRPEnabled) {
459 DisableInstantExtendedAPIForTesting(); 353 EnableQueryExtractionForTesting();
460
461 const SearchTestCase kTestCases[] = {
462 {"chrome-search://foo/bar", false, ""},
463 {"http://foo.com/instant", false, ""},
464 {"http://foo.com/instant?foo=bar", false, ""},
465 {"https://foo.com/instant", false, ""},
466 {"https://foo.com/instant#foo=bar", false, ""},
467 {"HtTpS://fOo.CoM/instant", false, ""},
468 {"http://foo.com:80/instant", false, ""},
469 {"invalid URL", false, "Invalid URL"},
470 {"unknown://scheme/path", false, "Unknown scheme"},
471 {"ftp://foo.com/instant", false, "Non-HTTP scheme"},
472 {"http://sub.foo.com/instant", false, "Non-exact host"},
473 {"http://foo.com:26/instant", false, "Non-default port"},
474 {"http://foo.com/instant/bar", false, "Non-exact path"},
475 {"http://foo.com/Instant", false, "Case sensitive path"},
476 {"http://foo.com/", false, "Non-exact path"},
477 {"https://foo.com/", false, "Non-exact path"},
478 {"https://foo.com/url?strk", false, "Non-extended mode"},
479 {"https://foo.com/alt?strk", false, "Non-extended mode"},
480 };
481
482 for (size_t i = 0; i < arraysize(kTestCases); ++i) {
483 const SearchTestCase& test = kTestCases[i];
484 EXPECT_EQ(test.expected_result,
485 ShouldAssignURLToInstantRenderer(GURL(test.url), profile()))
486 << test.url << " " << test.comment;
487 }
488 }
489
490 TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabled) {
491 EnableInstantExtendedAPIForTesting();
492 354
493 const SearchTestCase kTestCases[] = { 355 const SearchTestCase kTestCases[] = {
494 {chrome::kChromeSearchLocalNtpUrl, true, ""}, 356 {chrome::kChromeSearchLocalNtpUrl, true, ""},
495 {"https://foo.com/instant?strk", true, ""}, 357 {"https://foo.com/instant?strk", true, ""},
496 {"https://foo.com/instant#strk", true, ""}, 358 {"https://foo.com/instant#strk", true, ""},
497 {"https://foo.com/instant?strk=0", true, ""}, 359 {"https://foo.com/instant?strk=0", true, ""},
498 {"https://foo.com/url?strk", true, ""}, 360 {"https://foo.com/url?strk", true, ""},
499 {"https://foo.com/alt?strk", true, ""}, 361 {"https://foo.com/alt?strk", true, ""},
500 {"http://foo.com/instant", false, "Non-HTTPS"}, 362 {"http://foo.com/instant", false, "Non-HTTPS"},
501 {"http://foo.com/instant?strk", false, "Non-HTTPS"}, 363 {"http://foo.com/instant?strk", false, "Non-HTTPS"},
502 {"http://foo.com/instant?strk=1", false, "Non-HTTPS"}, 364 {"http://foo.com/instant?strk=1", false, "Non-HTTPS"},
503 {"https://foo.com/instant", false, "No search terms replacement"}, 365 {"https://foo.com/instant", false, "No search terms replacement"},
504 {"https://foo.com/?strk", false, "Non-exact path"}, 366 {"https://foo.com/?strk", false, "Non-exact path"},
505 }; 367 };
506 368
507 for (size_t i = 0; i < arraysize(kTestCases); ++i) { 369 for (size_t i = 0; i < arraysize(kTestCases); ++i) {
508 const SearchTestCase& test = kTestCases[i]; 370 const SearchTestCase& test = kTestCases[i];
509 EXPECT_EQ(test.expected_result, 371 EXPECT_EQ(test.expected_result,
510 ShouldAssignURLToInstantRenderer(GURL(test.url), profile())) 372 ShouldAssignURLToInstantRenderer(GURL(test.url), profile()))
511 << test.url << " " << test.comment; 373 << test.url << " " << test.comment;
512 } 374 }
513 } 375 }
514 376
515 TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabledNotOnSRP) { 377 TEST_F(SearchTest, ShouldAssignURLToInstantRenderer) {
516 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
517 "EmbeddedSearch", "Group1 espv:2 suppress_on_srp:1"));
518
519 const SearchTestCase kTestCases[] = { 378 const SearchTestCase kTestCases[] = {
520 {chrome::kChromeSearchLocalNtpUrl, true, ""}, 379 {chrome::kChromeSearchLocalNtpUrl, true, ""},
521 {"https://foo.com/instant?strk", true, ""}, 380 {"https://foo.com/instant?strk", true, ""},
522 {"https://foo.com/instant#strk", true, ""}, 381 {"https://foo.com/instant#strk", true, ""},
523 {"https://foo.com/instant?strk=0", true, ""}, 382 {"https://foo.com/instant?strk=0", true, ""},
524 {"https://foo.com/url?strk", false, "Disabled on SRP"}, 383 {"https://foo.com/url?strk", false, "Disabled on SRP"},
525 {"https://foo.com/alt?strk", false, "Disabled ON SRP"}, 384 {"https://foo.com/alt?strk", false, "Disabled ON SRP"},
526 {"http://foo.com/instant", false, "Non-HTTPS"}, 385 {"http://foo.com/instant", false, "Non-HTTPS"},
527 {"http://foo.com/instant?strk", false, "Non-HTTPS"}, 386 {"http://foo.com/instant?strk", false, "Non-HTTPS"},
528 {"http://foo.com/instant?strk=1", false, "Non-HTTPS"}, 387 {"http://foo.com/instant?strk=1", false, "Non-HTTPS"},
529 {"https://foo.com/instant", false, "No search terms replacement"}, 388 {"https://foo.com/instant", false, "No search terms replacement"},
530 {"https://foo.com/?strk", false, "Non-exact path"}, 389 {"https://foo.com/?strk", false, "Non-exact path"},
531 }; 390 };
532 391
533 for (size_t i = 0; i < arraysize(kTestCases); ++i) { 392 for (size_t i = 0; i < arraysize(kTestCases); ++i) {
534 const SearchTestCase& test = kTestCases[i]; 393 const SearchTestCase& test = kTestCases[i];
535 EXPECT_EQ(test.expected_result, 394 EXPECT_EQ(test.expected_result,
536 ShouldAssignURLToInstantRenderer(GURL(test.url), profile())) 395 ShouldAssignURLToInstantRenderer(GURL(test.url), profile()))
537 << test.url << " " << test.comment; 396 << test.url << " " << test.comment;
538 } 397 }
539 } 398 }
540 399
541 TEST_F(SearchTest, ShouldUseProcessPerSiteForInstantURL) { 400 TEST_F(SearchTest, ShouldUseProcessPerSiteForInstantURL) {
542 EnableInstantExtendedAPIForTesting();
543
544 const SearchTestCase kTestCases[] = { 401 const SearchTestCase kTestCases[] = {
545 {"chrome-search://local-ntp", true, "Local NTP"}, 402 {"chrome-search://local-ntp", true, "Local NTP"},
546 {"chrome-search://online-ntp", true, "Online NTP"}, 403 {"chrome-search://online-ntp", true, "Online NTP"},
547 {"invalid-scheme://local-ntp", false, "Invalid Local NTP URL"}, 404 {"invalid-scheme://local-ntp", false, "Invalid Local NTP URL"},
548 {"invalid-scheme://online-ntp", false, "Invalid Online NTP URL"}, 405 {"invalid-scheme://online-ntp", false, "Invalid Online NTP URL"},
549 {"chrome-search://foo.com", false, "Search result page"}, 406 {"chrome-search://foo.com", false, "Search result page"},
550 {"https://foo.com/instant?strk", false, ""}, 407 {"https://foo.com/instant?strk", false, ""},
551 {"https://foo.com/instant#strk", false, ""}, 408 {"https://foo.com/instant#strk", false, ""},
552 {"https://foo.com/instant?strk=0", false, ""}, 409 {"https://foo.com/instant?strk=0", false, ""},
553 {"https://foo.com/url?strk", false, ""}, 410 {"https://foo.com/url?strk", false, ""},
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 "https://foo.com/url?strk", true, true }, 453 "https://foo.com/url?strk", true, true },
597 {"SRP -> Regular", 454 {"SRP -> Regular",
598 "https://foo.com/url?strk", true, 455 "https://foo.com/url?strk", true,
599 "https://foo.com/other", false, false }, 456 "https://foo.com/other", false, false },
600 {"Regular -> SRP", 457 {"Regular -> SRP",
601 "https://foo.com/other", false, 458 "https://foo.com/other", false,
602 "https://foo.com/url?strk", true, false }, 459 "https://foo.com/url?strk", true, false },
603 }; 460 };
604 461
605 TEST_F(SearchTest, ProcessIsolation) { 462 TEST_F(SearchTest, ProcessIsolation) {
606 EnableInstantExtendedAPIForTesting(); 463 EnableQueryExtractionForTesting();
607 464
608 for (size_t i = 0; i < arraysize(kProcessIsolationTestCases); ++i) { 465 for (size_t i = 0; i < arraysize(kProcessIsolationTestCases); ++i) {
609 const ProcessIsolationTestCase& test = kProcessIsolationTestCases[i]; 466 const ProcessIsolationTestCase& test = kProcessIsolationTestCases[i];
610 AddTab(browser(), GURL("chrome://blank")); 467 AddTab(browser(), GURL("chrome://blank"));
611 const content::WebContents* contents = 468 const content::WebContents* contents =
612 browser()->tab_strip_model()->GetActiveWebContents(); 469 browser()->tab_strip_model()->GetActiveWebContents();
613 470
614 // Navigate to start URL. 471 // Navigate to start URL.
615 NavigateAndCommitActiveTab(GURL(test.start_url)); 472 NavigateAndCommitActiveTab(GURL(test.start_url));
616 EXPECT_EQ(test.start_in_instant_process, InInstantProcess(contents)) 473 EXPECT_EQ(test.start_in_instant_process, InInstantProcess(contents))
(...skipping 18 matching lines...) Expand all
635 EXPECT_EQ(test.same_site_instance, 492 EXPECT_EQ(test.same_site_instance,
636 start_rvh == contents->GetRenderViewHost()) 493 start_rvh == contents->GetRenderViewHost())
637 << test.description; 494 << test.description;
638 EXPECT_EQ(test.same_site_instance, 495 EXPECT_EQ(test.same_site_instance,
639 start_rph == contents->GetRenderProcessHost()) 496 start_rph == contents->GetRenderProcessHost())
640 << test.description; 497 << test.description;
641 } 498 }
642 } 499 }
643 500
644 TEST_F(SearchTest, ProcessIsolation_RendererInitiated) { 501 TEST_F(SearchTest, ProcessIsolation_RendererInitiated) {
645 EnableInstantExtendedAPIForTesting(); 502 EnableQueryExtractionForTesting();
646 503
647 for (size_t i = 0; i < arraysize(kProcessIsolationTestCases); ++i) { 504 for (size_t i = 0; i < arraysize(kProcessIsolationTestCases); ++i) {
648 const ProcessIsolationTestCase& test = kProcessIsolationTestCases[i]; 505 const ProcessIsolationTestCase& test = kProcessIsolationTestCases[i];
649 AddTab(browser(), GURL("chrome://blank")); 506 AddTab(browser(), GURL("chrome://blank"));
650 content::WebContents* contents = 507 content::WebContents* contents =
651 browser()->tab_strip_model()->GetActiveWebContents(); 508 browser()->tab_strip_model()->GetActiveWebContents();
652 509
653 // Navigate to start URL. 510 // Navigate to start URL.
654 NavigateAndCommitActiveTab(GURL(test.start_url)); 511 NavigateAndCommitActiveTab(GURL(test.start_url));
655 EXPECT_EQ(test.start_in_instant_process, InInstantProcess(contents)) 512 EXPECT_EQ(test.start_in_instant_process, InInstantProcess(contents))
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 {"https://foo.com/url?strk&bar=abc", false, "Has query terms"}, 557 {"https://foo.com/url?strk&bar=abc", false, "Has query terms"},
701 {"http://foo.com/instant?strk=1", false, "Insecure URL"}, 558 {"http://foo.com/instant?strk=1", false, "Insecure URL"},
702 {"https://foo.com/instant", false, "No search term replacement"}, 559 {"https://foo.com/instant", false, "No search term replacement"},
703 {"chrome://blank/", false, "Chrome scheme"}, 560 {"chrome://blank/", false, "Chrome scheme"},
704 {"chrome-search://foo", false, "Chrome-search scheme"}, 561 {"chrome-search://foo", false, "Chrome-search scheme"},
705 {chrome::kChromeSearchLocalNtpUrl, true, "Local new tab page"}, 562 {chrome::kChromeSearchLocalNtpUrl, true, "Local new tab page"},
706 {"https://bar.com/instant?strk=1", false, "Random non-search page"}, 563 {"https://bar.com/instant?strk=1", false, "Random non-search page"},
707 }; 564 };
708 565
709 TEST_F(SearchTest, InstantNTPExtendedEnabled) { 566 TEST_F(SearchTest, InstantNTPExtendedEnabled) {
710 EnableInstantExtendedAPIForTesting(); 567 EnableQueryExtractionForTesting();
568 // TODO(samarth): update test cases to use cachable NTP URLs and remove this.
569 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended",
570 "Group1 use_cacheable_ntp:0"));
711 AddTab(browser(), GURL("chrome://blank")); 571 AddTab(browser(), GURL("chrome://blank"));
712 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { 572 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) {
713 const SearchTestCase& test = kInstantNTPTestCases[i]; 573 const SearchTestCase& test = kInstantNTPTestCases[i];
714 NavigateAndCommitActiveTab(GURL(test.url)); 574 NavigateAndCommitActiveTab(GURL(test.url));
715 const content::WebContents* contents = 575 const content::WebContents* contents =
716 browser()->tab_strip_model()->GetWebContentsAt(0); 576 browser()->tab_strip_model()->GetWebContentsAt(0);
717 EXPECT_EQ(test.expected_result, IsInstantNTP(contents)) 577 EXPECT_EQ(test.expected_result, IsInstantNTP(contents))
718 << test.url << " " << test.comment; 578 << test.url << " " << test.comment;
719 } 579 }
720 } 580 }
721 581
722 TEST_F(SearchTest, InstantNTPExtendedDisabled) {
723 AddTab(browser(), GURL("chrome://blank"));
724 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) {
725 const SearchTestCase& test = kInstantNTPTestCases[i];
726 NavigateAndCommitActiveTab(GURL(test.url));
727 const content::WebContents* contents =
728 browser()->tab_strip_model()->GetWebContentsAt(0);
729 EXPECT_FALSE(IsInstantNTP(contents)) << test.url << " " << test.comment;
730 }
731 }
732
733 TEST_F(SearchTest, InstantNTPCustomNavigationEntry) { 582 TEST_F(SearchTest, InstantNTPCustomNavigationEntry) {
734 EnableInstantExtendedAPIForTesting(); 583 EnableQueryExtractionForTesting();
584 // TODO(samarth): update test cases to use cachable NTP URLs and remove this.
585 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended",
586 "Group1 use_cacheable_ntp:0"));
735 AddTab(browser(), GURL("chrome://blank")); 587 AddTab(browser(), GURL("chrome://blank"));
736 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { 588 for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) {
737 const SearchTestCase& test = kInstantNTPTestCases[i]; 589 const SearchTestCase& test = kInstantNTPTestCases[i];
738 NavigateAndCommitActiveTab(GURL(test.url)); 590 NavigateAndCommitActiveTab(GURL(test.url));
739 content::WebContents* contents = 591 content::WebContents* contents =
740 browser()->tab_strip_model()->GetWebContentsAt(0); 592 browser()->tab_strip_model()->GetWebContentsAt(0);
741 content::NavigationController& controller = contents->GetController(); 593 content::NavigationController& controller = contents->GetController();
742 controller.SetTransientEntry( 594 controller.SetTransientEntry(
743 controller.CreateNavigationEntry(GURL("chrome://blank"), 595 controller.CreateNavigationEntry(GURL("chrome://blank"),
744 content::Referrer(), 596 content::Referrer(),
745 content::PAGE_TRANSITION_LINK, 597 content::PAGE_TRANSITION_LINK,
746 false, 598 false,
747 std::string(), 599 std::string(),
748 contents->GetBrowserContext())); 600 contents->GetBrowserContext()));
749 // The active entry is chrome://blank and not an NTP. 601 // The active entry is chrome://blank and not an NTP.
750 EXPECT_FALSE(IsInstantNTP(contents)); 602 EXPECT_FALSE(IsInstantNTP(contents));
751 EXPECT_EQ(test.expected_result, 603 EXPECT_EQ(test.expected_result,
752 NavEntryIsInstantNTP(contents, 604 NavEntryIsInstantNTP(contents,
753 controller.GetLastCommittedEntry())) 605 controller.GetLastCommittedEntry()))
754 << test.url << " " << test.comment; 606 << test.url << " " << test.comment;
755 } 607 }
756 } 608 }
757 609
758 TEST_F(SearchTest, InstantCacheableNTPNavigationEntry) { 610 TEST_F(SearchTest, InstantCacheableNTPNavigationEntry) {
759 EnableInstantExtendedAPIForTesting();
760 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 611 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
761 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); 612 "EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
762 613
763 AddTab(browser(), GURL("chrome://blank")); 614 AddTab(browser(), GURL("chrome://blank"));
764 content::WebContents* contents = 615 content::WebContents* contents =
765 browser()->tab_strip_model()->GetWebContentsAt(0); 616 browser()->tab_strip_model()->GetWebContentsAt(0);
766 content::NavigationController& controller = contents->GetController(); 617 content::NavigationController& controller = contents->GetController();
767 // Local NTP. 618 // Local NTP.
768 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 619 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
769 EXPECT_TRUE(NavEntryIsInstantNTP(contents, 620 EXPECT_TRUE(NavEntryIsInstantNTP(contents,
770 controller.GetLastCommittedEntry())); 621 controller.GetLastCommittedEntry()));
771 // Instant page is not cacheable NTP. 622 // Instant page is not cacheable NTP.
772 NavigateAndCommitActiveTab(GetInstantURL(profile(), kDisableStartMargin, 623 NavigateAndCommitActiveTab(GetInstantURL(profile(), kDisableStartMargin,
773 false)); 624 false));
774 EXPECT_FALSE(NavEntryIsInstantNTP(contents, 625 EXPECT_FALSE(NavEntryIsInstantNTP(contents,
775 controller.GetLastCommittedEntry())); 626 controller.GetLastCommittedEntry()));
776 // Test Cacheable NTP 627 // Test Cacheable NTP
777 NavigateAndCommitActiveTab(chrome::GetNewTabPageURL(profile())); 628 NavigateAndCommitActiveTab(chrome::GetNewTabPageURL(profile()));
778 EXPECT_TRUE(NavEntryIsInstantNTP(contents, 629 EXPECT_TRUE(NavEntryIsInstantNTP(contents,
779 controller.GetLastCommittedEntry())); 630 controller.GetLastCommittedEntry()));
780 } 631 }
781 632
782 TEST_F(SearchTest, UseLocalNTPInIncognito) { 633 TEST_F(SearchTest, UseLocalNTPInIncognito) {
783 EnableInstantExtendedAPIForTesting();
784 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 634 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
785 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); 635 "EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
786 EXPECT_EQ(GURL(), chrome::GetNewTabPageURL( 636 EXPECT_EQ(GURL(), chrome::GetNewTabPageURL(
787 profile()->GetOffTheRecordProfile())); 637 profile()->GetOffTheRecordProfile()));
788 } 638 }
789 639
790 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsInsecure) { 640 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsInsecure) {
791 EnableInstantExtendedAPIForTesting();
792 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 641 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
793 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); 642 "EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
794 // Set an insecure new tab page URL and verify that it's ignored. 643 // Set an insecure new tab page URL and verify that it's ignored.
795 SetSearchProvider(true, true); 644 SetSearchProvider(true, true);
796 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), 645 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl),
797 chrome::GetNewTabPageURL(profile())); 646 chrome::GetNewTabPageURL(profile()));
798 } 647 }
799 648
800 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsNotSet) { 649 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsNotSet) {
801 EnableInstantExtendedAPIForTesting();
802 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 650 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
803 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); 651 "EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
804 // Set an insecure new tab page URL and verify that it's ignored. 652 // Set an insecure new tab page URL and verify that it's ignored.
805 SetSearchProvider(false, true); 653 SetSearchProvider(false, true);
806 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), 654 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl),
807 chrome::GetNewTabPageURL(profile())); 655 chrome::GetNewTabPageURL(profile()));
808 } 656 }
809 657
810 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsBlockedForSupervisedUser) { 658 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsBlockedForSupervisedUser) {
811 EnableInstantExtendedAPIForTesting();
812 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 659 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
813 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); 660 "EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
814 661
815 // Block access to foo.com in the URL filter. 662 // Block access to foo.com in the URL filter.
816 ManagedUserService* managed_user_service = 663 ManagedUserService* managed_user_service =
817 ManagedUserServiceFactory::GetForProfile(profile()); 664 ManagedUserServiceFactory::GetForProfile(profile());
818 ManagedModeURLFilter* url_filter = 665 ManagedModeURLFilter* url_filter =
819 managed_user_service->GetURLFilterForUIThread(); 666 managed_user_service->GetURLFilterForUIThread();
820 std::map<std::string, bool> hosts; 667 std::map<std::string, bool> hosts;
821 hosts["foo.com"] = false; 668 hosts["foo.com"] = false;
822 url_filter->SetManualHosts(&hosts); 669 url_filter->SetManualHosts(&hosts);
823 670
824 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), 671 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl),
825 chrome::GetNewTabPageURL(profile())); 672 chrome::GetNewTabPageURL(profile()));
826 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); 673 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false));
827 } 674 }
828 675
829 TEST_F(SearchTest, GetInstantURLExtendedEnabled) { 676 TEST_F(SearchTest, GetInstantURL) {
830 // Instant is disabled, so no Instant URL. 677 // No Instant URL because "strk" is missing.
831 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false));
832
833 // Enable Instant. Still no Instant URL because "strk" is missing.
834 EnableInstantExtendedAPIForTesting();
835 SetDefaultInstantTemplateUrl(false); 678 SetDefaultInstantTemplateUrl(false);
836 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); 679 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false));
837 680
838 // Set an Instant URL with a valid search terms replacement key. 681 // Set an Instant URL with a valid search terms replacement key.
839 SetDefaultInstantTemplateUrl(true); 682 SetDefaultInstantTemplateUrl(true);
840 683
841 // Now there should be a valid Instant URL. Note the HTTPS "upgrade". 684 // Now there should be a valid Instant URL. Note the HTTPS "upgrade".
842 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), 685 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"),
843 GetInstantURL(profile(), kDisableStartMargin, false)); 686 GetInstantURL(profile(), kDisableStartMargin, false));
844 687
845 // Enable suggest. No difference. 688 // Enable suggest. No difference.
846 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); 689 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true);
847 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), 690 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"),
848 GetInstantURL(profile(), kDisableStartMargin, false)); 691 GetInstantURL(profile(), kDisableStartMargin, false));
849 692
850 // Disable suggest. No Instant URL. 693 // Disable suggest. No Instant URL.
851 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false); 694 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false);
852 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); 695 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false));
853 } 696 }
854 697
855 TEST_F(SearchTest, StartMarginCGI) { 698 TEST_F(SearchTest, StartMarginCGI) {
856 // Instant is disabled, so no Instant URL. 699 // No margin.
857 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false));
858
859 // Enable Instant. No margin.
860 EnableInstantExtendedAPIForTesting();
861 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); 700 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true);
862 701
863 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), 702 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"),
864 GetInstantURL(profile(), kDisableStartMargin, false)); 703 GetInstantURL(profile(), kDisableStartMargin, false));
865 704
866 // With start margin. 705 // With start margin.
867 EXPECT_EQ(GURL("https://foo.com/instant?es_sm=10&foo=foo#foo=foo&strk"), 706 EXPECT_EQ(GURL("https://foo.com/instant?es_sm=10&foo=foo#foo=foo&strk"),
868 GetInstantURL(profile(), 10, false)); 707 GetInstantURL(profile(), 10, false));
869 } 708 }
870 709
871 TEST_F(SearchTest, InstantSearchEnabledCGI) { 710 TEST_F(SearchTest, InstantSearchEnabledCGI) {
872 EnableInstantExtendedAPIForTesting();
873
874 // Disable Instant Search. 711 // Disable Instant Search.
875 // Make sure {google:forceInstantResults} is not set in the Instant URL. 712 // Make sure {google:forceInstantResults} is not set in the Instant URL.
876 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), 713 EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"),
877 GetInstantURL(profile(), kDisableStartMargin, false)); 714 GetInstantURL(profile(), kDisableStartMargin, false));
878 715
879 // Enable Instant Search. 716 // Enable Instant Search.
880 // Make sure {google:forceInstantResults} is set in the Instant URL. 717 // Make sure {google:forceInstantResults} is set in the Instant URL.
881 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"), 718 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"),
882 GetInstantURL(profile(), kDisableStartMargin, true)); 719 GetInstantURL(profile(), kDisableStartMargin, true));
883 } 720 }
884 721
885 TEST_F(SearchTest, CommandLineOverrides) { 722 TEST_F(SearchTest, CommandLineOverrides) {
886 EnableInstantExtendedAPIForTesting(); 723 EnableQueryExtractionForTesting();
887 724
888 GURL local_instant_url(GetLocalInstantURL(profile())); 725 GURL local_instant_url(GetLocalInstantURL(profile()));
889 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), local_instant_url); 726 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), local_instant_url);
890 727
891 TemplateURLService* template_url_service = 728 TemplateURLService* template_url_service =
892 TemplateURLServiceFactory::GetForProfile(profile()); 729 TemplateURLServiceFactory::GetForProfile(profile());
893 TemplateURLData data; 730 TemplateURLData data;
894 data.SetURL("{google:baseURL}search?q={searchTerms}"); 731 data.SetURL("{google:baseURL}search?q={searchTerms}");
895 data.instant_url = "{google:baseURL}webhp?strk"; 732 data.instant_url = "{google:baseURL}webhp?strk";
896 data.search_terms_replacement_key = "strk"; 733 data.search_terms_replacement_key = "strk";
(...skipping 27 matching lines...) Expand all
924 // If we specify extra search query params, they should be inserted into the 761 // If we specify extra search query params, they should be inserted into the
925 // query portion of the instant URL. 762 // query portion of the instant URL.
926 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 763 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
927 switches::kExtraSearchQueryParams, "a=b"); 764 switches::kExtraSearchQueryParams, "a=b");
928 instant_url = GetInstantURL(profile(), kDisableStartMargin, false); 765 instant_url = GetInstantURL(profile(), kDisableStartMargin, false);
929 ASSERT_TRUE(instant_url.is_valid()); 766 ASSERT_TRUE(instant_url.is_valid());
930 EXPECT_EQ("http://www.bar.com/webhp?a=b&strk", instant_url.spec()); 767 EXPECT_EQ("http://www.bar.com/webhp?a=b&strk", instant_url.spec());
931 } 768 }
932 769
933 TEST_F(SearchTest, ShouldShowInstantNTP_Default) { 770 TEST_F(SearchTest, ShouldShowInstantNTP_Default) {
934 EnableInstantExtendedAPIForTesting(); 771 EXPECT_FALSE(ShouldShowInstantNTP());
935 EXPECT_TRUE(ShouldShowInstantNTP());
936 } 772 }
937 773
938 TEST_F(SearchTest, ShouldShowInstantNTP_DisabledViaFinch) { 774 TEST_F(SearchTest, ShouldShowInstantNTP_DisabledViaFinch) {
939 EnableInstantExtendedAPIForTesting();
940 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 775 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
941 "EmbeddedSearch", "Group1 show_ntp:0")); 776 "EmbeddedSearch", "Group1 show_ntp:0"));
942 EXPECT_FALSE(ShouldShowInstantNTP()); 777 EXPECT_FALSE(ShouldShowInstantNTP());
943 } 778 }
944 779
945 TEST_F(SearchTest, ShouldShowInstantNTP_DisabledByUseCacheableNTPFinchFlag) { 780 TEST_F(SearchTest, ShouldShowInstantNTP_DisabledByUseCacheableNTPFinchFlag) {
946 EnableInstantExtendedAPIForTesting();
947 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 781 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
948 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); 782 "EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
949 EXPECT_FALSE(ShouldShowInstantNTP()); 783 EXPECT_FALSE(ShouldShowInstantNTP());
950 } 784 }
951 785
952 TEST_F(SearchTest, ShouldUseCacheableNTP_Default) { 786 TEST_F(SearchTest, ShouldUseCacheableNTP_Default) {
953 EnableInstantExtendedAPIForTesting(); 787 EXPECT_TRUE(ShouldUseCacheableNTP());
954 EXPECT_FALSE(ShouldUseCacheableNTP());
955 } 788 }
956 789
957 TEST_F(SearchTest, ShouldUseCacheableNTP_EnabledViaFinch) { 790 TEST_F(SearchTest, ShouldUseCacheableNTP_EnabledViaFinch) {
958 EnableInstantExtendedAPIForTesting(); 791 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended",
959 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 792 "Group1 use_cacheable_ntp:1"));
960 "EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
961 EXPECT_TRUE(ShouldUseCacheableNTP()); 793 EXPECT_TRUE(ShouldUseCacheableNTP());
962 } 794 }
963 795
964 TEST_F(SearchTest, ShouldUseCacheableNTP_EnabledViaCommandLine) {
965 EnableInstantExtendedAPIForTesting();
966 CommandLine::ForCurrentProcess()->
967 AppendSwitch(switches::kUseCacheableNewTabPage);
968 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
969 "EmbeddedSearch", "Group1 use_cacheable_ntp:0"));
970 EXPECT_TRUE(ShouldUseCacheableNTP());
971 }
972
973 TEST_F(SearchTest, ShouldPrefetchSearchResults_Default) {
974 EXPECT_FALSE(ShouldPrefetchSearchResults());
975 }
976
977 TEST_F(SearchTest, ShouldPrefetchSearchResults_InstantExtendedAPIEnabled) {
978 EnableInstantExtendedAPIForTesting();
979 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
980 "EmbeddedSearch",
981 "Group1 espv:80 use_cacheable_ntp:1 prefetch_results:1"));
982 EXPECT_TRUE(ShouldPrefetchSearchResults());
983 #if defined(OS_IOS) || defined(OS_ANDROID)
984 EXPECT_EQ(1ul, EmbeddedSearchPageVersion());
985 #else
986 EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
987 #endif
988 }
989
990 TEST_F(SearchTest, ShouldPrefetchSearchResults_DisabledViaFinch) {
991 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
992 "EmbeddedSearch",
993 "Group1 use_cacheable_ntp:1 espv:89 prefetch_results:0"));
994 EXPECT_FALSE(ShouldPrefetchSearchResults());
995 EXPECT_EQ(89ul, EmbeddedSearchPageVersion());
996 }
997
998 TEST_F(SearchTest, ShouldPrefetchSearchResults_EnabledViaFinch) {
999 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
1000 "EmbeddedSearch",
1001 "Group1 espv:80 use_cacheable_ntp:1 prefetch_results:1"));
1002 EXPECT_TRUE(ShouldPrefetchSearchResults());
1003 EXPECT_EQ(80ul, EmbeddedSearchPageVersion());
1004 }
1005
1006 TEST_F(SearchTest, IsNTPURL) { 796 TEST_F(SearchTest, IsNTPURL) {
1007 GURL invalid_url; 797 GURL invalid_url;
1008 GURL ntp_url(chrome::kChromeUINewTabURL); 798 GURL ntp_url(chrome::kChromeUINewTabURL);
1009 GURL local_ntp_url(GetLocalInstantURL(profile())); 799 GURL local_ntp_url(GetLocalInstantURL(profile()));
1010 800
1011 EXPECT_FALSE(chrome::IsNTPURL(invalid_url, profile())); 801 EXPECT_FALSE(chrome::IsNTPURL(invalid_url, profile()));
1012 EXPECT_FALSE(chrome::IsNTPURL(local_ntp_url, profile())); 802 EnableQueryExtractionForTesting();
1013
1014 EXPECT_TRUE(chrome::IsNTPURL(ntp_url, NULL));
1015 EXPECT_FALSE(chrome::IsNTPURL(local_ntp_url, NULL));
1016
1017 // Enable Instant. No margin.
1018 EnableInstantExtendedAPIForTesting();
1019 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); 803 profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true);
1020 GURL remote_ntp_url(GetInstantURL(profile(), kDisableStartMargin, false)); 804 GURL remote_ntp_url(GetInstantURL(profile(), kDisableStartMargin, false));
1021 GURL search_url_with_search_terms("https://foo.com/url?strk&bar=abc"); 805 GURL search_url_with_search_terms("https://foo.com/url?strk&bar=abc");
1022 GURL search_url_without_search_terms("https://foo.com/url?strk&bar"); 806 GURL search_url_without_search_terms("https://foo.com/url?strk&bar");
1023 807
1024 EXPECT_FALSE(chrome::IsNTPURL(ntp_url, profile())); 808 EXPECT_FALSE(chrome::IsNTPURL(ntp_url, profile()));
1025 EXPECT_TRUE(chrome::IsNTPURL(local_ntp_url, profile())); 809 EXPECT_TRUE(chrome::IsNTPURL(local_ntp_url, profile()));
1026 EXPECT_TRUE(chrome::IsNTPURL(remote_ntp_url, profile())); 810 EXPECT_TRUE(chrome::IsNTPURL(remote_ntp_url, profile()));
1027 EXPECT_FALSE(chrome::IsNTPURL(search_url_with_search_terms, profile())); 811 EXPECT_FALSE(chrome::IsNTPURL(search_url_with_search_terms, profile()));
1028 EXPECT_TRUE(chrome::IsNTPURL(search_url_without_search_terms, profile())); 812 EXPECT_TRUE(chrome::IsNTPURL(search_url_without_search_terms, profile()));
(...skipping 20 matching lines...) Expand all
1049 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 833 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
1050 "EmbeddedSearch", 834 "EmbeddedSearch",
1051 "Group1 espv:80 use_cacheable_ntp:1 prefetch_results:1")); 835 "Group1 espv:80 use_cacheable_ntp:1 prefetch_results:1"));
1052 EXPECT_TRUE(ShouldPrefetchSearchResults()); 836 EXPECT_TRUE(ShouldPrefetchSearchResults());
1053 837
1054 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"), 838 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"),
1055 GetSearchResultPrefetchBaseURL(profile())); 839 GetSearchResultPrefetchBaseURL(profile()));
1056 } 840 }
1057 841
1058 } // namespace chrome 842 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/search/search.cc ('k') | chrome/browser/search_engines/template_url.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698