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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/search/search.cc ('k') | chrome/browser/search_engines/template_url.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/search/search_unittest.cc
diff --git a/chrome/browser/search/search_unittest.cc b/chrome/browser/search/search_unittest.cc
index 2375a77e53f337a08505214cff75fb81fa566aa3..0687f4a0aa8c10486517811374e22d93853ec0b9 100644
--- a/chrome/browser/search/search_unittest.cc
+++ b/chrome/browser/search/search_unittest.cc
@@ -4,8 +4,6 @@
#include "base/command_line.h"
#include "base/metrics/field_trial.h"
-#include "base/metrics/histogram_base.h"
-#include "base/metrics/histogram_samples.h"
#include "base/metrics/statistics_recorder.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/managed_mode/managed_mode_url_filter.h"
@@ -39,7 +37,6 @@ class EmbeddedSearchFieldTrialTest : public testing::Test {
field_trial_list_.reset(new base::FieldTrialList(
new metrics::SHA1EntropyProvider("42")));
base::StatisticsRecorder::Initialize();
- ResetInstantExtendedOptInStateGateForTest();
}
private:
@@ -48,101 +45,84 @@ class EmbeddedSearchFieldTrialTest : public testing::Test {
TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoEmptyAndValid) {
FieldTrialFlags flags;
- uint64 group_number = 0;
- EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number));
- EXPECT_EQ(0ul, group_number);
+ EXPECT_TRUE(GetFieldTrialInfo(&flags));
EXPECT_EQ(0ul, flags.size());
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
- "Group77"));
- EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number));
- EXPECT_EQ(77ul, group_number);
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Group77"));
+ EXPECT_TRUE(GetFieldTrialInfo(&flags));
EXPECT_EQ(0ul, flags.size());
}
TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoInvalidNumber) {
FieldTrialFlags flags;
- uint64 group_number = 0;
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
- "Group77.2"));
- EXPECT_FALSE(GetFieldTrialInfo(&flags, &group_number));
- EXPECT_EQ(0ul, group_number);
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Group77.2"));
+ EXPECT_TRUE(GetFieldTrialInfo(&flags));
EXPECT_EQ(0ul, flags.size());
}
TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoInvalidName) {
FieldTrialFlags flags;
- uint64 group_number = 0;
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
- "Invalid77"));
- EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number));
- EXPECT_EQ(0ul, group_number);
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Invalid77"));
+ EXPECT_TRUE(GetFieldTrialInfo(&flags));
EXPECT_EQ(0ul, flags.size());
}
TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoValidGroup) {
FieldTrialFlags flags;
- uint64 group_number = 0;
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
- "Group77"));
- EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number));
- EXPECT_EQ(77ul, group_number);
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Group77"));
+ EXPECT_TRUE(GetFieldTrialInfo(&flags));
EXPECT_EQ(0ul, flags.size());
}
TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoValidFlag) {
FieldTrialFlags flags;
- uint64 group_number = 0;
EXPECT_EQ(9999ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags));
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
- "Group77 foo:6"));
- EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number));
- EXPECT_EQ(77ul, group_number);
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Group77 foo:6"));
+ EXPECT_TRUE(GetFieldTrialInfo(&flags));
EXPECT_EQ(1ul, flags.size());
EXPECT_EQ(6ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags));
}
TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoNewName) {
FieldTrialFlags flags;
- uint64 group_number = 0;
EXPECT_EQ(9999ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags));
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
- "Group77 foo:6"));
- EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number));
- EXPECT_EQ(77ul, group_number);
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Group77 foo:6"));
+ EXPECT_TRUE(GetFieldTrialInfo(&flags));
EXPECT_EQ(1ul, flags.size());
EXPECT_EQ(6ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags));
}
TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoNewNameOverridesOld) {
FieldTrialFlags flags;
- uint64 group_number = 0;
EXPECT_EQ(9999ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags));
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
- "Group77 foo:6"));
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended",
- "Group78 foo:5"));
- EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number));
- EXPECT_EQ(77ul, group_number);
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Group77 foo:6"));
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "InstantExtended", "Group78 foo:5"));
+ EXPECT_TRUE(GetFieldTrialInfo(&flags));
EXPECT_EQ(1ul, flags.size());
EXPECT_EQ(6ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags));
}
TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoLotsOfFlags) {
FieldTrialFlags flags;
- uint64 group_number = 0;
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"EmbeddedSearch", "Group77 bar:1 baz:7 cat:dogs"));
- EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number));
- EXPECT_EQ(77ul, group_number);
+ EXPECT_TRUE(GetFieldTrialInfo(&flags));
EXPECT_EQ(3ul, flags.size());
EXPECT_EQ(true, GetBoolValueForFlagWithDefault("bar", false, flags));
EXPECT_EQ(7ul, GetUInt64ValueForFlagWithDefault("baz", 0, flags));
@@ -154,174 +134,157 @@ TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoLotsOfFlags) {
TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoDisabled) {
FieldTrialFlags flags;
- uint64 group_number = 0;
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"EmbeddedSearch", "Group77 bar:1 baz:7 cat:dogs DISABLED"));
- EXPECT_FALSE(GetFieldTrialInfo(&flags, &group_number));
- EXPECT_EQ(0ul, group_number);
+ EXPECT_FALSE(GetFieldTrialInfo(&flags));
EXPECT_EQ(0ul, flags.size());
}
TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoControlFlags) {
FieldTrialFlags flags;
- uint64 group_number = 0;
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Control77 bar:1 baz:7 cat:dogs"));
- EXPECT_TRUE(GetFieldTrialInfo(&flags, &group_number));
- EXPECT_EQ(0ul, group_number);
+ "InstantExtended", "Control77 bar:1 baz:7 cat:dogs"));
+ EXPECT_TRUE(GetFieldTrialInfo(&flags));
EXPECT_EQ(3ul, flags.size());
}
-class InstantExtendedAPIEnabledTest : public testing::Test {
- public:
- InstantExtendedAPIEnabledTest() : histogram_(NULL) {
- }
+class SearchTest : public BrowserWithTestWindowTest {
protected:
- virtual void SetUp() {
+ virtual void SetUp() OVERRIDE {
+ BrowserWithTestWindowTest::SetUp();
field_trial_list_.reset(new base::FieldTrialList(
new metrics::SHA1EntropyProvider("42")));
- base::StatisticsRecorder::Initialize();
- ResetInstantExtendedOptInStateGateForTest();
- previous_metrics_count_.resize(INSTANT_EXTENDED_OPT_IN_STATE_ENUM_COUNT, 0);
- base::HistogramBase* histogram = GetHistogram();
- if (histogram) {
- scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples());
- if (samples.get()) {
- for (int state = INSTANT_EXTENDED_NOT_SET;
- state < INSTANT_EXTENDED_OPT_IN_STATE_ENUM_COUNT; ++state) {
- previous_metrics_count_[state] = samples->GetCount(state);
- }
- }
- }
+ TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
+ profile(), &TemplateURLServiceFactory::BuildInstanceFor);
+ TemplateURLService* template_url_service =
+ TemplateURLServiceFactory::GetForProfile(profile());
+ ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service);
+ SetSearchProvider(true, false);
}
- virtual CommandLine* GetCommandLine() const {
- return CommandLine::ForCurrentProcess();
+ void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url) {
+ TemplateURLService* template_url_service =
+ TemplateURLServiceFactory::GetForProfile(profile());
+ TemplateURLData data;
+ data.SetURL("http://foo.com/url?bar={searchTerms}");
+ data.instant_url = "http://foo.com/instant?"
+ "{google:omniboxStartMarginParameter}{google:forceInstantResults}"
+ "foo=foo#foo=foo&strk";
+ if (set_ntp_url) {
+ data.new_tab_url = (insecure_ntp_url ? "http" : "https") +
+ std::string("://foo.com/newtab?strk");
+ }
+ data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}");
+ data.search_terms_replacement_key = "strk";
+
+ TemplateURL* template_url = new TemplateURL(profile(), data);
+ // Takes ownership of |template_url|.
+ template_url_service->Add(template_url);
+ template_url_service->SetDefaultSearchProvider(template_url);
}
- void ValidateMetrics(base::HistogramBase::Sample value) {
- base::HistogramBase* histogram = GetHistogram();
- if (histogram) {
- scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples());
- if (samples.get()) {
- for (int state = INSTANT_EXTENDED_NOT_SET;
- state < INSTANT_EXTENDED_OPT_IN_STATE_ENUM_COUNT; ++state) {
- if (state == value) {
- EXPECT_EQ(previous_metrics_count_[state] + 1,
- samples->GetCount(state));
- } else {
- EXPECT_EQ(previous_metrics_count_[state], samples->GetCount(state));
- }
- }
- }
- }
+ // Build an Instant URL with or without a valid search terms replacement key
+ // as per |has_search_term_replacement_key|. Set that URL as the instant URL
+ // for the default search provider.
+ void SetDefaultInstantTemplateUrl(bool has_search_term_replacement_key) {
+ TemplateURLService* template_url_service =
+ TemplateURLServiceFactory::GetForProfile(profile());
+
+ static const char kInstantURLWithStrk[] =
+ "http://foo.com/instant?foo=foo#foo=foo&strk";
+ static const char kInstantURLNoStrk[] =
+ "http://foo.com/instant?foo=foo#foo=foo";
+
+ TemplateURLData data;
+ data.SetURL("http://foo.com/url?bar={searchTerms}");
+ data.instant_url = (has_search_term_replacement_key ?
+ kInstantURLWithStrk : kInstantURLNoStrk);
+ data.search_terms_replacement_key = "strk";
+
+ TemplateURL* template_url = new TemplateURL(profile(), data);
+ // Takes ownership of |template_url|.
+ template_url_service->Add(template_url);
+ template_url_service->SetDefaultSearchProvider(template_url);
}
- private:
- base::HistogramBase* GetHistogram() {
- if (!histogram_) {
- histogram_ = base::StatisticsRecorder::FindHistogram(
- "InstantExtended.OptInState");
- }
- return histogram_;
+ bool InInstantProcess(const content::WebContents* contents) {
+ InstantService* instant_service =
+ InstantServiceFactory::GetForProfile(profile());
+ return instant_service->IsInstantProcess(
+ contents->GetRenderProcessHost()->GetID());
}
- base::HistogramBase* histogram_;
+
scoped_ptr<base::FieldTrialList> field_trial_list_;
- std::vector<int> previous_metrics_count_;
};
-TEST_F(InstantExtendedAPIEnabledTest, EnabledViaCommandLineFlag) {
- GetCommandLine()->AppendSwitch(switches::kEnableInstantExtendedAPI);
- EXPECT_TRUE(IsInstantExtendedAPIEnabled());
-#if defined(OS_IOS) || defined(OS_ANDROID)
- EXPECT_EQ(1ul, EmbeddedSearchPageVersion());
-#else
- EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
-#endif
- ValidateMetrics(INSTANT_EXTENDED_OPT_IN);
-}
-
-TEST_F(InstantExtendedAPIEnabledTest, EnabledViaFinchFlag) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
- "Group1 espv:42"));
- EXPECT_TRUE(IsInstantExtendedAPIEnabled());
- EXPECT_EQ(42ul, EmbeddedSearchPageVersion());
- ValidateMetrics(INSTANT_EXTENDED_NOT_SET);
-}
-
-TEST_F(InstantExtendedAPIEnabledTest, DisabledViaCommandLineFlag) {
- GetCommandLine()->AppendSwitch(switches::kDisableInstantExtendedAPI);
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
- "Group1 espv:2"));
- EXPECT_FALSE(IsInstantExtendedAPIEnabled());
- EXPECT_EQ(0ul, EmbeddedSearchPageVersion());
- ValidateMetrics(INSTANT_EXTENDED_OPT_OUT);
-}
-
-typedef InstantExtendedAPIEnabledTest ShouldHideTopVerbatimTest;
+typedef SearchTest ShouldHideTopVerbatimTest;
TEST_F(ShouldHideTopVerbatimTest, DoNotHideByDefault) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
- "Control"));
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "InstantExtended", "Control"));
EXPECT_FALSE(ShouldHideTopVerbatimMatch());
}
TEST_F(ShouldHideTopVerbatimTest, DoNotHideInInstantExtended) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
- "Group1"));
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "InstantExtended", "Group1"));
EXPECT_FALSE(ShouldHideTopVerbatimMatch());
}
TEST_F(ShouldHideTopVerbatimTest, EnableByFlagInInstantExtended) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
- "Group1 hide_verbatim:1"));
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "InstantExtended", "Group1 hide_verbatim:1"));
EXPECT_TRUE(ShouldHideTopVerbatimMatch());
}
TEST_F(ShouldHideTopVerbatimTest, EnableByFlagOutsideInstantExtended) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Controll1 hide_verbatim:1"));
+ "InstantExtended", "Controll1 hide_verbatim:1"));
EXPECT_TRUE(ShouldHideTopVerbatimMatch());
}
TEST_F(ShouldHideTopVerbatimTest, DisableByFlag) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
- "Group1 hide_verbatim:0"));
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "InstantExtended", "Group1 hide_verbatim:0"));
EXPECT_FALSE(ShouldHideTopVerbatimMatch());
}
-typedef InstantExtendedAPIEnabledTest ShouldSuppressInstantExtendedOnSRPTest;
+typedef SearchTest IsQueryExtractionEnabledTest;
-TEST_F(ShouldSuppressInstantExtendedOnSRPTest, NotSet) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
- "Group1 espv:2"));
- EXPECT_FALSE(ShouldSuppressInstantExtendedOnSRP());
+TEST_F(IsQueryExtractionEnabledTest, NotSet) {
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "InstantExtended", "Group1 espv:2"));
EXPECT_TRUE(IsInstantExtendedAPIEnabled());
- EXPECT_TRUE(IsQueryExtractionEnabled());
+ EXPECT_FALSE(IsQueryExtractionEnabled());
EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
}
-TEST_F(ShouldSuppressInstantExtendedOnSRPTest, NotSuppressOnSRP) {
+TEST_F(IsQueryExtractionEnabledTest, QueryExtractionEnabledViaFinch) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 espv:2 suppress_on_srp:0"));
- EXPECT_FALSE(ShouldSuppressInstantExtendedOnSRP());
+ "InstantExtended", "Group1 espv:2 query_extraction:1"));
+ EXPECT_TRUE(IsInstantExtendedAPIEnabled());
+ EXPECT_TRUE(IsQueryExtractionEnabled());
+ EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
+}
+
+TEST_F(IsQueryExtractionEnabledTest, QueryExtractionEnabledViaCommandLine) {
+ EnableQueryExtractionForTesting();
EXPECT_TRUE(IsInstantExtendedAPIEnabled());
EXPECT_TRUE(IsQueryExtractionEnabled());
EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
}
-TEST_F(ShouldSuppressInstantExtendedOnSRPTest, SuppressOnSRP) {
+TEST_F(IsQueryExtractionEnabledTest, QueryExtractionDisabledViaFinch) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 espv:2 suppress_on_srp:1"));
- EXPECT_TRUE(ShouldSuppressInstantExtendedOnSRP());
+ "InstantExtended", "Group1 espv:2 query_extraction:0"));
EXPECT_TRUE(IsInstantExtendedAPIEnabled());
EXPECT_FALSE(IsQueryExtractionEnabled());
EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
}
-typedef InstantExtendedAPIEnabledTest DisplaySearchButtonTest;
+typedef SearchTest DisplaySearchButtonTest;
TEST_F(DisplaySearchButtonTest, NotSet) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
@@ -360,7 +323,7 @@ TEST_F(DisplaySearchButtonTest, InvalidValue) {
EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions());
}
-typedef InstantExtendedAPIEnabledTest OriginChipTest;
+typedef SearchTest OriginChipTest;
TEST_F(OriginChipTest, NotSet) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
@@ -380,115 +343,14 @@ TEST_F(OriginChipTest, OriginChip) {
EXPECT_TRUE(ShouldDisplayOriginChip());
}
-class SearchTest : public BrowserWithTestWindowTest {
- protected:
- virtual void SetUp() OVERRIDE {
- BrowserWithTestWindowTest::SetUp();
- field_trial_list_.reset(new base::FieldTrialList(
- new metrics::SHA1EntropyProvider("42")));
- TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
- profile(), &TemplateURLServiceFactory::BuildInstanceFor);
- TemplateURLService* template_url_service =
- TemplateURLServiceFactory::GetForProfile(profile());
- ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service);
- SetSearchProvider(true, false);
- }
-
- void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url) {
- TemplateURLService* template_url_service =
- TemplateURLServiceFactory::GetForProfile(profile());
- TemplateURLData data;
- data.SetURL("http://foo.com/url?bar={searchTerms}");
- data.instant_url = "http://foo.com/instant?"
- "{google:omniboxStartMarginParameter}{google:forceInstantResults}"
- "foo=foo#foo=foo&strk";
- if (set_ntp_url) {
- data.new_tab_url = (insecure_ntp_url ? "http" : "https") +
- std::string("://foo.com/newtab?strk");
- }
- data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}");
- data.search_terms_replacement_key = "strk";
-
- TemplateURL* template_url = new TemplateURL(profile(), data);
- // Takes ownership of |template_url|.
- template_url_service->Add(template_url);
- template_url_service->SetDefaultSearchProvider(template_url);
- }
-
- // Build an Instant URL with or without a valid search terms replacement key
- // as per |has_search_term_replacement_key|. Set that URL as the instant URL
- // for the default search provider.
- void SetDefaultInstantTemplateUrl(bool has_search_term_replacement_key) {
- TemplateURLService* template_url_service =
- TemplateURLServiceFactory::GetForProfile(profile());
-
- static const char kInstantURLWithStrk[] =
- "http://foo.com/instant?foo=foo#foo=foo&strk";
- static const char kInstantURLNoStrk[] =
- "http://foo.com/instant?foo=foo#foo=foo";
-
- TemplateURLData data;
- data.SetURL("http://foo.com/url?bar={searchTerms}");
- data.instant_url = (has_search_term_replacement_key ?
- kInstantURLWithStrk : kInstantURLNoStrk);
- data.search_terms_replacement_key = "strk";
-
- TemplateURL* template_url = new TemplateURL(profile(), data);
- // Takes ownership of |template_url|.
- template_url_service->Add(template_url);
- template_url_service->SetDefaultSearchProvider(template_url);
- }
-
- bool InInstantProcess(const content::WebContents* contents) {
- InstantService* instant_service =
- InstantServiceFactory::GetForProfile(profile());
- return instant_service->IsInstantProcess(
- contents->GetRenderProcessHost()->GetID());
- }
-
- scoped_ptr<base::FieldTrialList> field_trial_list_;
-};
-
struct SearchTestCase {
const char* url;
bool expected_result;
const char* comment;
};
-TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedDisabled) {
- DisableInstantExtendedAPIForTesting();
-
- const SearchTestCase kTestCases[] = {
- {"chrome-search://foo/bar", false, ""},
- {"http://foo.com/instant", false, ""},
- {"http://foo.com/instant?foo=bar", false, ""},
- {"https://foo.com/instant", false, ""},
- {"https://foo.com/instant#foo=bar", false, ""},
- {"HtTpS://fOo.CoM/instant", false, ""},
- {"http://foo.com:80/instant", false, ""},
- {"invalid URL", false, "Invalid URL"},
- {"unknown://scheme/path", false, "Unknown scheme"},
- {"ftp://foo.com/instant", false, "Non-HTTP scheme"},
- {"http://sub.foo.com/instant", false, "Non-exact host"},
- {"http://foo.com:26/instant", false, "Non-default port"},
- {"http://foo.com/instant/bar", false, "Non-exact path"},
- {"http://foo.com/Instant", false, "Case sensitive path"},
- {"http://foo.com/", false, "Non-exact path"},
- {"https://foo.com/", false, "Non-exact path"},
- {"https://foo.com/url?strk", false, "Non-extended mode"},
- {"https://foo.com/alt?strk", false, "Non-extended mode"},
- };
-
- for (size_t i = 0; i < arraysize(kTestCases); ++i) {
- const SearchTestCase& test = kTestCases[i];
- EXPECT_EQ(test.expected_result,
- ShouldAssignURLToInstantRenderer(GURL(test.url), profile()))
- << test.url << " " << test.comment;
- }
-}
-
-TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabled) {
- EnableInstantExtendedAPIForTesting();
+TEST_F(SearchTest, ShouldAssignURLToInstantRendererSRPEnabled) {
+ EnableQueryExtractionForTesting();
const SearchTestCase kTestCases[] = {
{chrome::kChromeSearchLocalNtpUrl, true, ""},
@@ -512,10 +374,7 @@ TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabled) {
}
}
-TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabledNotOnSRP) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 espv:2 suppress_on_srp:1"));
-
+TEST_F(SearchTest, ShouldAssignURLToInstantRenderer) {
const SearchTestCase kTestCases[] = {
{chrome::kChromeSearchLocalNtpUrl, true, ""},
{"https://foo.com/instant?strk", true, ""},
@@ -539,8 +398,6 @@ TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabledNotOnSRP) {
}
TEST_F(SearchTest, ShouldUseProcessPerSiteForInstantURL) {
- EnableInstantExtendedAPIForTesting();
-
const SearchTestCase kTestCases[] = {
{"chrome-search://local-ntp", true, "Local NTP"},
{"chrome-search://online-ntp", true, "Online NTP"},
@@ -603,7 +460,7 @@ const struct ProcessIsolationTestCase {
};
TEST_F(SearchTest, ProcessIsolation) {
- EnableInstantExtendedAPIForTesting();
+ EnableQueryExtractionForTesting();
for (size_t i = 0; i < arraysize(kProcessIsolationTestCases); ++i) {
const ProcessIsolationTestCase& test = kProcessIsolationTestCases[i];
@@ -642,7 +499,7 @@ TEST_F(SearchTest, ProcessIsolation) {
}
TEST_F(SearchTest, ProcessIsolation_RendererInitiated) {
- EnableInstantExtendedAPIForTesting();
+ EnableQueryExtractionForTesting();
for (size_t i = 0; i < arraysize(kProcessIsolationTestCases); ++i) {
const ProcessIsolationTestCase& test = kProcessIsolationTestCases[i];
@@ -707,7 +564,10 @@ const SearchTestCase kInstantNTPTestCases[] = {
};
TEST_F(SearchTest, InstantNTPExtendedEnabled) {
- EnableInstantExtendedAPIForTesting();
+ EnableQueryExtractionForTesting();
+ // TODO(samarth): update test cases to use cachable NTP URLs and remove this.
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended",
+ "Group1 use_cacheable_ntp:0"));
AddTab(browser(), GURL("chrome://blank"));
for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) {
const SearchTestCase& test = kInstantNTPTestCases[i];
@@ -719,19 +579,11 @@ TEST_F(SearchTest, InstantNTPExtendedEnabled) {
}
}
-TEST_F(SearchTest, InstantNTPExtendedDisabled) {
- AddTab(browser(), GURL("chrome://blank"));
- for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) {
- const SearchTestCase& test = kInstantNTPTestCases[i];
- NavigateAndCommitActiveTab(GURL(test.url));
- const content::WebContents* contents =
- browser()->tab_strip_model()->GetWebContentsAt(0);
- EXPECT_FALSE(IsInstantNTP(contents)) << test.url << " " << test.comment;
- }
-}
-
TEST_F(SearchTest, InstantNTPCustomNavigationEntry) {
- EnableInstantExtendedAPIForTesting();
+ EnableQueryExtractionForTesting();
+ // TODO(samarth): update test cases to use cachable NTP URLs and remove this.
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended",
+ "Group1 use_cacheable_ntp:0"));
AddTab(browser(), GURL("chrome://blank"));
for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) {
const SearchTestCase& test = kInstantNTPTestCases[i];
@@ -756,7 +608,6 @@ TEST_F(SearchTest, InstantNTPCustomNavigationEntry) {
}
TEST_F(SearchTest, InstantCacheableNTPNavigationEntry) {
- EnableInstantExtendedAPIForTesting();
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
@@ -780,7 +631,6 @@ TEST_F(SearchTest, InstantCacheableNTPNavigationEntry) {
}
TEST_F(SearchTest, UseLocalNTPInIncognito) {
- EnableInstantExtendedAPIForTesting();
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
EXPECT_EQ(GURL(), chrome::GetNewTabPageURL(
@@ -788,7 +638,6 @@ TEST_F(SearchTest, UseLocalNTPInIncognito) {
}
TEST_F(SearchTest, UseLocalNTPIfNTPURLIsInsecure) {
- EnableInstantExtendedAPIForTesting();
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
// Set an insecure new tab page URL and verify that it's ignored.
@@ -798,7 +647,6 @@ TEST_F(SearchTest, UseLocalNTPIfNTPURLIsInsecure) {
}
TEST_F(SearchTest, UseLocalNTPIfNTPURLIsNotSet) {
- EnableInstantExtendedAPIForTesting();
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
// Set an insecure new tab page URL and verify that it's ignored.
@@ -808,7 +656,6 @@ TEST_F(SearchTest, UseLocalNTPIfNTPURLIsNotSet) {
}
TEST_F(SearchTest, UseLocalNTPIfNTPURLIsBlockedForSupervisedUser) {
- EnableInstantExtendedAPIForTesting();
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
@@ -826,12 +673,8 @@ TEST_F(SearchTest, UseLocalNTPIfNTPURLIsBlockedForSupervisedUser) {
EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false));
}
-TEST_F(SearchTest, GetInstantURLExtendedEnabled) {
- // Instant is disabled, so no Instant URL.
- EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false));
-
- // Enable Instant. Still no Instant URL because "strk" is missing.
- EnableInstantExtendedAPIForTesting();
+TEST_F(SearchTest, GetInstantURL) {
+ // No Instant URL because "strk" is missing.
SetDefaultInstantTemplateUrl(false);
EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false));
@@ -853,11 +696,7 @@ TEST_F(SearchTest, GetInstantURLExtendedEnabled) {
}
TEST_F(SearchTest, StartMarginCGI) {
- // Instant is disabled, so no Instant URL.
- EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false));
-
- // Enable Instant. No margin.
- EnableInstantExtendedAPIForTesting();
+ // No margin.
profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true);
EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"),
@@ -869,8 +708,6 @@ TEST_F(SearchTest, StartMarginCGI) {
}
TEST_F(SearchTest, InstantSearchEnabledCGI) {
- EnableInstantExtendedAPIForTesting();
-
// Disable Instant Search.
// Make sure {google:forceInstantResults} is not set in the Instant URL.
EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"),
@@ -883,7 +720,7 @@ TEST_F(SearchTest, InstantSearchEnabledCGI) {
}
TEST_F(SearchTest, CommandLineOverrides) {
- EnableInstantExtendedAPIForTesting();
+ EnableQueryExtractionForTesting();
GURL local_instant_url(GetLocalInstantURL(profile()));
EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), local_instant_url);
@@ -931,91 +768,38 @@ TEST_F(SearchTest, CommandLineOverrides) {
}
TEST_F(SearchTest, ShouldShowInstantNTP_Default) {
- EnableInstantExtendedAPIForTesting();
- EXPECT_TRUE(ShouldShowInstantNTP());
+ EXPECT_FALSE(ShouldShowInstantNTP());
}
TEST_F(SearchTest, ShouldShowInstantNTP_DisabledViaFinch) {
- EnableInstantExtendedAPIForTesting();
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"EmbeddedSearch", "Group1 show_ntp:0"));
EXPECT_FALSE(ShouldShowInstantNTP());
}
TEST_F(SearchTest, ShouldShowInstantNTP_DisabledByUseCacheableNTPFinchFlag) {
- EnableInstantExtendedAPIForTesting();
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
EXPECT_FALSE(ShouldShowInstantNTP());
}
TEST_F(SearchTest, ShouldUseCacheableNTP_Default) {
- EnableInstantExtendedAPIForTesting();
- EXPECT_FALSE(ShouldUseCacheableNTP());
-}
-
-TEST_F(SearchTest, ShouldUseCacheableNTP_EnabledViaFinch) {
- EnableInstantExtendedAPIForTesting();
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
EXPECT_TRUE(ShouldUseCacheableNTP());
}
-TEST_F(SearchTest, ShouldUseCacheableNTP_EnabledViaCommandLine) {
- EnableInstantExtendedAPIForTesting();
- CommandLine::ForCurrentProcess()->
- AppendSwitch(switches::kUseCacheableNewTabPage);
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 use_cacheable_ntp:0"));
+TEST_F(SearchTest, ShouldUseCacheableNTP_EnabledViaFinch) {
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended",
+ "Group1 use_cacheable_ntp:1"));
EXPECT_TRUE(ShouldUseCacheableNTP());
}
-TEST_F(SearchTest, ShouldPrefetchSearchResults_Default) {
- EXPECT_FALSE(ShouldPrefetchSearchResults());
-}
-
-TEST_F(SearchTest, ShouldPrefetchSearchResults_InstantExtendedAPIEnabled) {
- EnableInstantExtendedAPIForTesting();
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch",
- "Group1 espv:80 use_cacheable_ntp:1 prefetch_results:1"));
- EXPECT_TRUE(ShouldPrefetchSearchResults());
-#if defined(OS_IOS) || defined(OS_ANDROID)
- EXPECT_EQ(1ul, EmbeddedSearchPageVersion());
-#else
- EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
-#endif
-}
-
-TEST_F(SearchTest, ShouldPrefetchSearchResults_DisabledViaFinch) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch",
- "Group1 use_cacheable_ntp:1 espv:89 prefetch_results:0"));
- EXPECT_FALSE(ShouldPrefetchSearchResults());
- EXPECT_EQ(89ul, EmbeddedSearchPageVersion());
-}
-
-TEST_F(SearchTest, ShouldPrefetchSearchResults_EnabledViaFinch) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch",
- "Group1 espv:80 use_cacheable_ntp:1 prefetch_results:1"));
- EXPECT_TRUE(ShouldPrefetchSearchResults());
- EXPECT_EQ(80ul, EmbeddedSearchPageVersion());
-}
-
TEST_F(SearchTest, IsNTPURL) {
GURL invalid_url;
GURL ntp_url(chrome::kChromeUINewTabURL);
GURL local_ntp_url(GetLocalInstantURL(profile()));
EXPECT_FALSE(chrome::IsNTPURL(invalid_url, profile()));
- EXPECT_FALSE(chrome::IsNTPURL(local_ntp_url, profile()));
-
- EXPECT_TRUE(chrome::IsNTPURL(ntp_url, NULL));
- EXPECT_FALSE(chrome::IsNTPURL(local_ntp_url, NULL));
-
- // Enable Instant. No margin.
- EnableInstantExtendedAPIForTesting();
+ EnableQueryExtractionForTesting();
profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true);
GURL remote_ntp_url(GetInstantURL(profile(), kDisableStartMargin, false));
GURL search_url_with_search_terms("https://foo.com/url?strk&bar=abc");
« 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