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

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

Issue 23522025: InstantExtended: add a finch flag to disable Instant Extended on SRP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add tests. Created 7 years, 3 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/search/search.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 "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" 7 #include "base/metrics/histogram_base.h"
8 #include "base/metrics/histogram_samples.h" 8 #include "base/metrics/histogram_samples.h"
9 #include "base/metrics/statistics_recorder.h" 9 #include "base/metrics/statistics_recorder.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 "InstantExtended", "Controll1 hide_verbatim:1")); 217 "InstantExtended", "Controll1 hide_verbatim:1"));
218 EXPECT_TRUE(ShouldHideTopVerbatimMatch()); 218 EXPECT_TRUE(ShouldHideTopVerbatimMatch());
219 } 219 }
220 220
221 TEST_F(ShouldHideTopVerbatimTest, DisableByFlag) { 221 TEST_F(ShouldHideTopVerbatimTest, DisableByFlag) {
222 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 222 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
223 "InstantExtended", "Group1 hide_verbatim:0")); 223 "InstantExtended", "Group1 hide_verbatim:0"));
224 EXPECT_FALSE(ShouldHideTopVerbatimMatch()); 224 EXPECT_FALSE(ShouldHideTopVerbatimMatch());
225 } 225 }
226 226
227 typedef InstantExtendedAPIEnabledTest ShouldSuppressInstantExtendedOnSRPTest;
228
229 TEST_F(ShouldSuppressInstantExtendedOnSRPTest, NotSet) {
230 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
231 "InstantExtended", "Group1 espv:2"));
232 EXPECT_FALSE(ShouldSuppressInstantExtendedOnSRP());
233 EXPECT_TRUE(IsInstantExtendedAPIEnabled());
234 EXPECT_TRUE(IsQueryExtractionEnabled());
235 EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
236 }
237
238 TEST_F(ShouldSuppressInstantExtendedOnSRPTest, NotSuppressOnSRP) {
239 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
240 "InstantExtended", "Group1 espv:2 suppress_on_srp:0"));
241 EXPECT_FALSE(ShouldSuppressInstantExtendedOnSRP());
242 EXPECT_TRUE(IsInstantExtendedAPIEnabled());
243 EXPECT_TRUE(IsQueryExtractionEnabled());
244 EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
245 }
246
247 TEST_F(ShouldSuppressInstantExtendedOnSRPTest, SuppressOnSRP) {
248 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
249 "InstantExtended", "Group1 espv:2 suppress_on_srp:1"));
250 EXPECT_TRUE(ShouldSuppressInstantExtendedOnSRP());
251 EXPECT_TRUE(IsInstantExtendedAPIEnabled());
252 EXPECT_FALSE(IsQueryExtractionEnabled());
253 EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
254 }
255
227 class SearchTest : public BrowserWithTestWindowTest { 256 class SearchTest : public BrowserWithTestWindowTest {
228 protected: 257 protected:
229 virtual void SetUp() OVERRIDE { 258 virtual void SetUp() OVERRIDE {
230 BrowserWithTestWindowTest::SetUp(); 259 BrowserWithTestWindowTest::SetUp();
231 field_trial_list_.reset(new base::FieldTrialList( 260 field_trial_list_.reset(new base::FieldTrialList(
232 new metrics::SHA1EntropyProvider("42"))); 261 new metrics::SHA1EntropyProvider("42")));
233 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( 262 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
234 profile(), &TemplateURLServiceFactory::BuildInstanceFor); 263 profile(), &TemplateURLServiceFactory::BuildInstanceFor);
235 TemplateURLService* template_url_service = 264 TemplateURLService* template_url_service =
236 TemplateURLServiceFactory::GetForProfile(profile()); 265 TemplateURLServiceFactory::GetForProfile(profile());
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 }; 374 };
346 375
347 for (size_t i = 0; i < arraysize(kTestCases); ++i) { 376 for (size_t i = 0; i < arraysize(kTestCases); ++i) {
348 const SearchTestCase& test = kTestCases[i]; 377 const SearchTestCase& test = kTestCases[i];
349 EXPECT_EQ(test.expected_result, 378 EXPECT_EQ(test.expected_result,
350 ShouldAssignURLToInstantRenderer(GURL(test.url), profile())) 379 ShouldAssignURLToInstantRenderer(GURL(test.url), profile()))
351 << test.url << " " << test.comment; 380 << test.url << " " << test.comment;
352 } 381 }
353 } 382 }
354 383
384 TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabledNotOnSRP) {
385 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
386 "InstantExtended", "Group1 espv:2 suppress_on_srp:1"));
387
388 const SearchTestCase kTestCases[] = {
389 {chrome::kChromeSearchLocalNtpUrl, true, ""},
390 {"https://foo.com/instant?strk", true, ""},
391 {"https://foo.com/instant#strk", true, ""},
392 {"https://foo.com/instant?strk=0", true, ""},
393 {"https://foo.com/url?strk", false, "Disabled on SRP"},
394 {"https://foo.com/alt?strk", false, "Disabled ON SRP"},
395 {"http://foo.com/instant", false, "Non-HTTPS"},
396 {"http://foo.com/instant?strk", false, "Non-HTTPS"},
397 {"http://foo.com/instant?strk=1", false, "Non-HTTPS"},
398 {"https://foo.com/instant", false, "No search terms replacement"},
399 {"https://foo.com/?strk", false, "Non-exact path"},
400 };
401
402 for (size_t i = 0; i < arraysize(kTestCases); ++i) {
403 const SearchTestCase& test = kTestCases[i];
404 EXPECT_EQ(test.expected_result,
405 ShouldAssignURLToInstantRenderer(GURL(test.url), profile()))
406 << test.url << " " << test.comment;
407 }
408 }
409
355 TEST_F(SearchTest, ShouldUseProcessPerSiteForInstantURL) { 410 TEST_F(SearchTest, ShouldUseProcessPerSiteForInstantURL) {
356 EnableInstantExtendedAPIForTesting(); 411 EnableInstantExtendedAPIForTesting();
357 412
358 const SearchTestCase kTestCases[] = { 413 const SearchTestCase kTestCases[] = {
359 {"chrome-search://local-ntp", true, "Local NTP"}, 414 {"chrome-search://local-ntp", true, "Local NTP"},
360 {"chrome-search://online-ntp", true, "Online NTP"}, 415 {"chrome-search://online-ntp", true, "Online NTP"},
361 {"invalid-scheme://local-ntp", false, "Invalid Local NTP URL"}, 416 {"invalid-scheme://local-ntp", false, "Invalid Local NTP URL"},
362 {"invalid-scheme://online-ntp", false, "Invalid Online NTP URL"}, 417 {"invalid-scheme://online-ntp", false, "Invalid Online NTP URL"},
363 {"chrome-search://foo.com", false, "Search result page"}, 418 {"chrome-search://foo.com", false, "Search result page"},
364 {"https://foo.com/instant?strk", false, ""}, 419 {"https://foo.com/instant?strk", false, ""},
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 EXPECT_TRUE(chrome::IsNTPURL(search_url_without_search_terms, profile())); 770 EXPECT_TRUE(chrome::IsNTPURL(search_url_without_search_terms, profile()));
716 771
717 EXPECT_FALSE(chrome::IsNTPURL(ntp_url, NULL)); 772 EXPECT_FALSE(chrome::IsNTPURL(ntp_url, NULL));
718 EXPECT_FALSE(chrome::IsNTPURL(local_ntp_url, NULL)); 773 EXPECT_FALSE(chrome::IsNTPURL(local_ntp_url, NULL));
719 EXPECT_FALSE(chrome::IsNTPURL(remote_ntp_url, NULL)); 774 EXPECT_FALSE(chrome::IsNTPURL(remote_ntp_url, NULL));
720 EXPECT_FALSE(chrome::IsNTPURL(search_url_with_search_terms, NULL)); 775 EXPECT_FALSE(chrome::IsNTPURL(search_url_with_search_terms, NULL));
721 EXPECT_FALSE(chrome::IsNTPURL(search_url_without_search_terms, NULL)); 776 EXPECT_FALSE(chrome::IsNTPURL(search_url_without_search_terms, NULL));
722 } 777 }
723 778
724 } // namespace chrome 779 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/search/search.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698