Commit f2300892 authored by samarth@chromium.org's avatar samarth@chromium.org

InstantExtended: add a finch flag to disable Instant Extended on SRP.

BUG=286446

Review URL: https://chromiumcodereview.appspot.com/23522025

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221885 0039d316-1c4b-4281-b951-d872f2087c98
parent ab083585
...@@ -64,6 +64,7 @@ const char kShowNtpFlagName[] = "show_ntp"; ...@@ -64,6 +64,7 @@ const char kShowNtpFlagName[] = "show_ntp";
const char kRecentTabsOnNTPFlagName[] = "show_recent_tabs"; const char kRecentTabsOnNTPFlagName[] = "show_recent_tabs";
const char kUseCacheableNTP[] = "use_cacheable_ntp"; const char kUseCacheableNTP[] = "use_cacheable_ntp";
const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp"; const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp";
const char kSuppressInstantExtendedOnSRPFlagName[] = "suppress_on_srp";
// Constants for the field trial name and group prefix. // Constants for the field trial name and group prefix.
const char kInstantExtendedFieldTrialName[] = "InstantExtended"; const char kInstantExtendedFieldTrialName[] = "InstantExtended";
...@@ -230,9 +231,14 @@ bool IsInstantURL(const GURL& url, Profile* profile) { ...@@ -230,9 +231,14 @@ bool IsInstantURL(const GURL& url, Profile* profile) {
const TemplateURLRef& instant_url_ref = template_url->instant_url_ref(); const TemplateURLRef& instant_url_ref = template_url->instant_url_ref();
const GURL instant_url = const GURL instant_url =
TemplateURLRefToGURL(instant_url_ref, kDisableStartMargin, false); TemplateURLRefToGURL(instant_url_ref, kDisableStartMargin, false);
return instant_url.is_valid() && if (!instant_url.is_valid())
(MatchesOriginAndPath(url, instant_url) || return false;
MatchesAnySearchURL(url, template_url));
if (MatchesOriginAndPath(url, instant_url))
return true;
return !ShouldSuppressInstantExtendedOnSRP() &&
MatchesAnySearchURL(url, template_url);
} }
string16 GetSearchTermsImpl(const content::WebContents* contents, string16 GetSearchTermsImpl(const content::WebContents* contents,
...@@ -273,10 +279,8 @@ bool IsInstantExtendedAPIEnabled() { ...@@ -273,10 +279,8 @@ bool IsInstantExtendedAPIEnabled() {
#if defined(OS_IOS) || defined(OS_ANDROID) #if defined(OS_IOS) || defined(OS_ANDROID)
return false; return false;
#else #else
// On desktop, query extraction is part of Instant extended, so if one is
// enabled, the other is too.
RecordInstantExtendedOptInState(); RecordInstantExtendedOptInState();
return IsQueryExtractionEnabled(); return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled;
#endif // defined(OS_IOS) || defined(OS_ANDROID) #endif // defined(OS_IOS) || defined(OS_ANDROID)
} }
...@@ -311,7 +315,8 @@ uint64 EmbeddedSearchPageVersion() { ...@@ -311,7 +315,8 @@ uint64 EmbeddedSearchPageVersion() {
} }
bool IsQueryExtractionEnabled() { bool IsQueryExtractionEnabled() {
return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled; return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled &&
!ShouldSuppressInstantExtendedOnSRP();
} }
string16 GetSearchTermsFromURL(Profile* profile, const GURL& url) { string16 GetSearchTermsFromURL(Profile* profile, const GURL& url) {
...@@ -508,6 +513,18 @@ bool ShouldShowRecentTabsOnNTP() { ...@@ -508,6 +513,18 @@ bool ShouldShowRecentTabsOnNTP() {
return false; return false;
} }
bool ShouldSuppressInstantExtendedOnSRP() {
FieldTrialFlags flags;
if (GetFieldTrialInfo(
base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName),
&flags, NULL)) {
return GetBoolValueForFlagWithDefault(
kSuppressInstantExtendedOnSRPFlagName, false, flags);
}
return false;
}
bool MatchesOriginAndPath(const GURL& my_url, const GURL& other_url) { bool MatchesOriginAndPath(const GURL& my_url, const GURL& other_url) {
return MatchesOrigin(my_url, other_url) && my_url.path() == other_url.path(); return MatchesOrigin(my_url, other_url) && my_url.path() == other_url.path();
} }
......
...@@ -137,6 +137,10 @@ bool ShouldShowInstantNTP(); ...@@ -137,6 +137,10 @@ bool ShouldShowInstantNTP();
// field trials. // field trials.
bool ShouldShowRecentTabsOnNTP(); bool ShouldShowRecentTabsOnNTP();
// Returns true if Instant Extended should be disabled on the search results
// page.
bool ShouldSuppressInstantExtendedOnSRP();
// Returns true if |my_url| matches |other_url|. // Returns true if |my_url| matches |other_url|.
bool MatchesOriginAndPath(const GURL& my_url, const GURL& other_url); bool MatchesOriginAndPath(const GURL& my_url, const GURL& other_url);
......
...@@ -224,6 +224,35 @@ TEST_F(ShouldHideTopVerbatimTest, DisableByFlag) { ...@@ -224,6 +224,35 @@ TEST_F(ShouldHideTopVerbatimTest, DisableByFlag) {
EXPECT_FALSE(ShouldHideTopVerbatimMatch()); EXPECT_FALSE(ShouldHideTopVerbatimMatch());
} }
typedef InstantExtendedAPIEnabledTest ShouldSuppressInstantExtendedOnSRPTest;
TEST_F(ShouldSuppressInstantExtendedOnSRPTest, NotSet) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"InstantExtended", "Group1 espv:2"));
EXPECT_FALSE(ShouldSuppressInstantExtendedOnSRP());
EXPECT_TRUE(IsInstantExtendedAPIEnabled());
EXPECT_TRUE(IsQueryExtractionEnabled());
EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
}
TEST_F(ShouldSuppressInstantExtendedOnSRPTest, NotSuppressOnSRP) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"InstantExtended", "Group1 espv:2 suppress_on_srp:0"));
EXPECT_FALSE(ShouldSuppressInstantExtendedOnSRP());
EXPECT_TRUE(IsInstantExtendedAPIEnabled());
EXPECT_TRUE(IsQueryExtractionEnabled());
EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
}
TEST_F(ShouldSuppressInstantExtendedOnSRPTest, SuppressOnSRP) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"InstantExtended", "Group1 espv:2 suppress_on_srp:1"));
EXPECT_TRUE(ShouldSuppressInstantExtendedOnSRP());
EXPECT_TRUE(IsInstantExtendedAPIEnabled());
EXPECT_FALSE(IsQueryExtractionEnabled());
EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
}
class SearchTest : public BrowserWithTestWindowTest { class SearchTest : public BrowserWithTestWindowTest {
protected: protected:
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
...@@ -352,6 +381,32 @@ TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabled) { ...@@ -352,6 +381,32 @@ TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabled) {
} }
} }
TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabledNotOnSRP) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"InstantExtended", "Group1 espv:2 suppress_on_srp:1"));
const SearchTestCase kTestCases[] = {
{chrome::kChromeSearchLocalNtpUrl, true, ""},
{"https://foo.com/instant?strk", true, ""},
{"https://foo.com/instant#strk", true, ""},
{"https://foo.com/instant?strk=0", true, ""},
{"https://foo.com/url?strk", false, "Disabled on SRP"},
{"https://foo.com/alt?strk", false, "Disabled ON SRP"},
{"http://foo.com/instant", false, "Non-HTTPS"},
{"http://foo.com/instant?strk", false, "Non-HTTPS"},
{"http://foo.com/instant?strk=1", false, "Non-HTTPS"},
{"https://foo.com/instant", false, "No search terms replacement"},
{"https://foo.com/?strk", false, "Non-exact path"},
};
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, ShouldUseProcessPerSiteForInstantURL) { TEST_F(SearchTest, ShouldUseProcessPerSiteForInstantURL) {
EnableInstantExtendedAPIForTesting(); EnableInstantExtendedAPIForTesting();
......
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