Move ShouldHideTopVerbatimMatch to components/search

To remove chrome/ dependency from AutocompleteResult

BUG=388504
TEST=components_unittest --gtest_filter="ShouldHideTopVerbatimTest.*"

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

Cr-Commit-Position: refs/heads/master@{#288958}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288958 0039d316-1c4b-4281-b951-d872f2087c98
parent 535980d4
......@@ -10,13 +10,13 @@
#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/search/search.h"
#include "components/metrics/proto/omnibox_event.pb.h"
#include "components/metrics/proto/omnibox_input_type.pb.h"
#include "components/omnibox/autocomplete_input.h"
#include "components/omnibox/autocomplete_match.h"
#include "components/omnibox/autocomplete_provider.h"
#include "components/omnibox/omnibox_field_trial.h"
#include "components/search/search.h"
#include "components/url_fixer/url_fixer.h"
using metrics::OmniboxEventProto;
......
......@@ -45,7 +45,6 @@ namespace chrome {
namespace {
const char kHideVerbatimFlagName[] = "hide_verbatim";
const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp";
const char kAllowPrefetchNonDefaultMatch[] = "allow_prefetch_non_default_match";
const char kPrerenderInstantUrlOnOmniboxFocus[] =
......@@ -580,12 +579,6 @@ GURL GetLocalInstantURL(Profile* profile) {
return GURL(chrome::kChromeSearchLocalNtpUrl);
}
bool ShouldHideTopVerbatimMatch() {
FieldTrialFlags flags;
return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault(
kHideVerbatimFlagName, false, flags);
}
DisplaySearchButtonConditions GetDisplaySearchButtonConditions() {
const CommandLine* cl = CommandLine::ForCurrentProcess();
if (cl->HasSwitch(switches::kDisableSearchButtonInOmnibox))
......
......@@ -178,11 +178,6 @@ bool ShouldReuseInstantSearchBasePage();
// TODO(kmadhusu): Remove this function and update the call sites.
GURL GetLocalInstantURL(Profile* profile);
// Returns true if 'hide_verbatim' flag is enabled in field trials
// to hide the top match in the native suggestions dropdown if it is a verbatim
// match. See comments on ShouldHideTopMatch in autocomplete_result.h.
bool ShouldHideTopVerbatimMatch();
// Returns when we should show a search button in the omnibox. This may be any
// of several values, some of which depend on whether the underlying state of
// the page would normally be to perform search term replacement; see also
......
......@@ -849,38 +849,6 @@ TEST_F(IsQueryExtractionEnabledTest, EnabledViaCommandLine) {
EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
}
typedef SearchTest ShouldHideTopVerbatimTest;
TEST_F(ShouldHideTopVerbatimTest, DoNotHideByDefault) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
"Control"));
EXPECT_FALSE(ShouldHideTopVerbatimMatch());
}
TEST_F(ShouldHideTopVerbatimTest, DoNotHideInInstantExtended) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
"Group1"));
EXPECT_FALSE(ShouldHideTopVerbatimMatch());
}
TEST_F(ShouldHideTopVerbatimTest, EnableByFlagInInstantExtended) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
"Group1 hide_verbatim:1"));
EXPECT_TRUE(ShouldHideTopVerbatimMatch());
}
TEST_F(ShouldHideTopVerbatimTest, EnableByFlagOutsideInstantExtended) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"EmbeddedSearch", "Controll1 hide_verbatim:1"));
EXPECT_TRUE(ShouldHideTopVerbatimMatch());
}
TEST_F(ShouldHideTopVerbatimTest, DisableByFlag) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
"Group1 hide_verbatim:0"));
EXPECT_FALSE(ShouldHideTopVerbatimMatch());
}
typedef SearchTest DisplaySearchButtonTest;
TEST_F(DisplaySearchButtonTest, NotSet) {
......
......@@ -35,6 +35,8 @@ const uint64 kEmbeddedSearchEnabledVersion = 2;
const uint64 kEmbeddedPageVersionDefault = 2;
#endif
const char kHideVerbatimFlagName[] = "hide_verbatim";
// Constants for the field trial name and group prefix.
// Note in M30 and below this field trial was named "InstantExtended" and in
// M31 was renamed to EmbeddedSearch for clarity and cleanliness. Since we
......@@ -143,4 +145,10 @@ bool GetBoolValueForFlagWithDefault(const std::string& flag,
return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags);
}
bool ShouldHideTopVerbatimMatch() {
FieldTrialFlags flags;
return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault(
kHideVerbatimFlagName, false, flags);
}
} // namespace chrome
......@@ -54,6 +54,11 @@ bool GetBoolValueForFlagWithDefault(const std::string& flag,
bool default_value,
const FieldTrialFlags& flags);
// Returns true if 'hide_verbatim' flag is enabled in field trials
// to hide the top match in the native suggestions dropdown if it is a verbatim
// match. See comments on ShouldHideTopMatch in autocomplete_result.h.
bool ShouldHideTopVerbatimMatch();
} // namespace chrome
#endif // COMPONENTS_SEARCH_SEARCH_H_
......@@ -130,4 +130,36 @@ TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoControlFlags) {
EXPECT_EQ(3ul, flags.size());
}
typedef EmbeddedSearchFieldTrialTest ShouldHideTopVerbatimTest;
TEST_F(ShouldHideTopVerbatimTest, DoNotHideByDefault) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
"Control"));
EXPECT_FALSE(ShouldHideTopVerbatimMatch());
}
TEST_F(ShouldHideTopVerbatimTest, DoNotHideInInstantExtended) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
"Group1"));
EXPECT_FALSE(ShouldHideTopVerbatimMatch());
}
TEST_F(ShouldHideTopVerbatimTest, EnableByFlagInInstantExtended) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
"Group1 hide_verbatim:1"));
EXPECT_TRUE(ShouldHideTopVerbatimMatch());
}
TEST_F(ShouldHideTopVerbatimTest, EnableByFlagOutsideInstantExtended) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"EmbeddedSearch", "Controll1 hide_verbatim:1"));
EXPECT_TRUE(ShouldHideTopVerbatimMatch());
}
TEST_F(ShouldHideTopVerbatimTest, DisableByFlag) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
"Group1 hide_verbatim:0"));
EXPECT_FALSE(ShouldHideTopVerbatimMatch());
}
} // namespace chrome
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