Commit d0df130a authored by kmadhusu@chromium.org's avatar kmadhusu@chromium.org

Adds a field trial flag to control whether to use an alternate Instant search...

Adds a field trial flag to control whether to use an alternate Instant search base page URL for prefetching search results.

BUG=382694
TEST=Run chrome with the following field trial flag and observe the Instant search base page url.
     --force-fieldtrials="EmbeddedSearch/Group1 use_alternate_instant_url:1 /"

Review URL: https://codereview.chromium.org/330653004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278824 0039d316-1c4b-4281-b951-d872f2087c98
parent bcf1b7a1
......@@ -75,6 +75,12 @@ const char kPrerenderInstantUrlOnOmniboxFocus[] =
// search query.
const char kReuseInstantSearchBasePage[] = "reuse_instant_search_base_page";
// Controls whether to use the alternate Instant search base URL. This allows
// experimentation of Instant search.
const char kUseAltInstantURL[] = "use_alternate_instant_url";
const char kAltInstantURLPath[] = "search";
const char kAltInstantURLQueryParams[] = "&qbp=1";
const char kDisplaySearchButtonFlagName[] = "display_search_button";
const char kOriginChipFlagName[] = "origin_chip";
#if !defined(OS_IOS) && !defined(OS_ANDROID)
......@@ -551,6 +557,15 @@ GURL GetInstantURL(Profile* profile, int start_margin,
if (!IsURLAllowedForSupervisedUser(instant_url, profile))
return GURL();
if (ShouldUseAltInstantURL()) {
GURL::Replacements replacements;
const std::string path(kAltInstantURLPath);
replacements.SetPathStr(path);
const std::string query(
instant_url.query() + std::string(kAltInstantURLQueryParams));
replacements.SetQueryStr(query);
instant_url = instant_url.ReplaceComponents(replacements);
}
return instant_url;
}
......@@ -844,4 +859,10 @@ bool GetBoolValueForFlagWithDefault(const std::string& flag,
return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags);
}
bool ShouldUseAltInstantURL() {
FieldTrialFlags flags;
return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault(
kUseAltInstantURL, false, flags);
}
} // namespace chrome
......@@ -289,6 +289,11 @@ bool GetBoolValueForFlagWithDefault(const std::string& flag,
// Returns the Cacheable New Tab Page URL for the given |profile|.
GURL GetNewTabPageURL(Profile* profile);
// Returns true if 'use_alternate_instant_url' flag is set to true in field
// trials to use an alternate Instant search base page URL for prefetching
// search results. This allows experimentation of Instant search.
bool ShouldUseAltInstantURL();
} // namespace chrome
#endif // CHROME_BROWSER_SEARCH_SEARCH_H_
......@@ -589,6 +589,13 @@ TEST_F(SearchTest, GetInstantURL) {
// Disable suggest. No Instant URL.
profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false);
EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false));
// Use alternate Instant search base URL.
profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true);
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"EmbeddedSearch", "Group1 espv:8 use_alternate_instant_url:1"));
EXPECT_EQ(GURL("https://foo.com/search?foo=foo&qbp=1#foo=foo&strk"),
GetInstantURL(profile(), kDisableStartMargin, false));
}
TEST_F(SearchTest, StartMarginCGI) {
......@@ -724,6 +731,18 @@ TEST_F(SearchTest, ShouldAllowPrefetchNonDefaultMatch_EnabledViaFieldTrial) {
EXPECT_EQ(80ul, EmbeddedSearchPageVersion());
}
TEST_F(SearchTest, ShouldUseAltInstantURL_DisabledViaFieldTrial) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"EmbeddedSearch", "Group1 espv:8 use_alternate_instant_url:0"));
EXPECT_FALSE(ShouldUseAltInstantURL());
}
TEST_F(SearchTest, ShouldUseAltInstantURL_EnabledViaFieldTrial) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"EmbeddedSearch", "Group1 espv:8 use_alternate_instant_url:1"));
EXPECT_TRUE(ShouldUseAltInstantURL());
}
TEST_F(SearchTest,
ShouldPrerenderInstantUrlOnOmniboxFocus_PrefetchResultsFlagDisabled) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment