Commit 2ae54e32 authored by Tomasz Wiszkowski's avatar Tomasz Wiszkowski Committed by Commit Bot

Enable verbatim match on search results page.

This change allows Search-Ready Omnibox to be shown on SRP
effectively removing the need to manually clear the Omnibox field
ahead of typing in new search query.

Bug: 1118222
Change-Id: Ie36029b38ed54bb63de1db66eef9457dec6d86ea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2364048
Commit-Queue: Tomasz Wiszkowski <ender@google.com>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799845}
parent d47cd7f2
...@@ -12,6 +12,24 @@ namespace { ...@@ -12,6 +12,24 @@ namespace {
// The relevance score for verbatim match. // The relevance score for verbatim match.
// Must outrank the QueryTiles relevance score. // Must outrank the QueryTiles relevance score.
const int kVerbatimMatchRelevanceScore = 1600; const int kVerbatimMatchRelevanceScore = 1600;
// Returns whether specific context is eligible for a verbatim match.
// Only offer verbatim match on a site visit and SRP (no NTP etc).
bool IsVerbatimMatchEligible(
metrics::OmniboxEventProto::PageClassification context) {
// Only offer verbatim match on a site visit and SRP (no NTP etc).
switch (context) {
case metrics::OmniboxEventProto::
SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT:
case metrics::OmniboxEventProto::
SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT:
case metrics::OmniboxEventProto::OTHER:
return true;
default:
return false;
}
}
} // namespace } // namespace
ZeroSuggestVerbatimMatchProvider::ZeroSuggestVerbatimMatchProvider( ZeroSuggestVerbatimMatchProvider::ZeroSuggestVerbatimMatchProvider(
...@@ -23,9 +41,7 @@ ZeroSuggestVerbatimMatchProvider::~ZeroSuggestVerbatimMatchProvider() = default; ...@@ -23,9 +41,7 @@ ZeroSuggestVerbatimMatchProvider::~ZeroSuggestVerbatimMatchProvider() = default;
void ZeroSuggestVerbatimMatchProvider::Start(const AutocompleteInput& input, void ZeroSuggestVerbatimMatchProvider::Start(const AutocompleteInput& input,
bool minimal_changes) { bool minimal_changes) {
Stop(true, false); Stop(true, false);
if (!IsVerbatimMatchEligible(input.current_page_classification()))
// Only offer verbatim match on a site visit (non-SRP, non-NTP).
if (input.current_page_classification() != metrics::OmniboxEventProto::OTHER)
return; return;
// Only offer verbatim match after the user just focused the Omnibox, // Only offer verbatim match after the user just focused the Omnibox,
......
...@@ -16,103 +16,177 @@ ...@@ -16,103 +16,177 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/metrics_proto/omnibox_event.pb.h" #include "third_party/metrics_proto/omnibox_event.pb.h"
class ZeroSuggestVerbatimMatchProviderTest : public testing::Test { class ZeroSuggestVerbatimMatchProviderTest
: public testing::TestWithParam<
metrics::OmniboxEventProto::PageClassification> {
public: public:
ZeroSuggestVerbatimMatchProviderTest() = default; ZeroSuggestVerbatimMatchProviderTest() = default;
void SetUp() override; void SetUp() override;
protected: protected:
bool IsVerbatimMatchEligible() const;
scoped_refptr<ZeroSuggestVerbatimMatchProvider> provider_; scoped_refptr<ZeroSuggestVerbatimMatchProvider> provider_;
MockAutocompleteProviderClient mock_client_; MockAutocompleteProviderClient mock_client_;
}; };
bool ZeroSuggestVerbatimMatchProviderTest::IsVerbatimMatchEligible() const {
switch (GetParam()) {
case metrics::OmniboxEventProto::OTHER:
case metrics::OmniboxEventProto::
SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT:
case metrics::OmniboxEventProto::
SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT:
return true;
default:
return false;
}
}
void ZeroSuggestVerbatimMatchProviderTest::SetUp() { void ZeroSuggestVerbatimMatchProviderTest::SetUp() {
provider_ = new ZeroSuggestVerbatimMatchProvider(&mock_client_); provider_ = new ZeroSuggestVerbatimMatchProvider(&mock_client_);
ON_CALL(mock_client_, IsOffTheRecord()).WillByDefault([] { return false; });
} }
TEST_F(ZeroSuggestVerbatimMatchProviderTest, TEST_P(ZeroSuggestVerbatimMatchProviderTest,
NoVerbatimMatchWhenOmniboxIsOnNTP) { NoVerbatimMatchWithUserTextInOmnibox) {
std::string url("chrome://newtab"); std::string query("user input");
AutocompleteInput input(base::string16(), metrics::OmniboxEventProto::NTP, std::string url("https://google.com/search?q=test");
AutocompleteInput input(base::ASCIIToUTF16(query), GetParam(),
TestSchemeClassifier()); TestSchemeClassifier());
input.set_current_url(GURL(url)); input.set_current_url(GURL(url));
input.set_focus_type(OmniboxFocusType::ON_FOCUS); input.set_focus_type(OmniboxFocusType::DEFAULT);
provider_->Start(input, false); provider_->Start(input, false);
// Clobber state should never generate a verbatim match.
EXPECT_TRUE(provider_->matches().empty()); EXPECT_TRUE(provider_->matches().empty());
} }
TEST_F(ZeroSuggestVerbatimMatchProviderTest, TEST_P(ZeroSuggestVerbatimMatchProviderTest,
NoVerbatimMatchForSearchResultsPage) { NoVerbatimMatchWithUserTextInOmniboxInIncognito) {
std::string query("https://google.com/search?q=test"); std::string query("user input");
AutocompleteInput input( std::string url("https://google.com/search?q=test");
base::ASCIIToUTF16("test"), AutocompleteInput input(base::ASCIIToUTF16(query), GetParam(),
metrics::OmniboxEventProto::SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT, TestSchemeClassifier());
TestSchemeClassifier()); input.set_current_url(GURL(url));
input.set_current_url(GURL(query)); input.set_focus_type(OmniboxFocusType::DEFAULT);
input.set_focus_type(OmniboxFocusType::ON_FOCUS); ON_CALL(mock_client_, IsOffTheRecord()).WillByDefault([] { return true; });
provider_->Start(input, false); provider_->Start(input, false);
// Clobber state should never generate a verbatim match.
EXPECT_TRUE(provider_->matches().empty()); EXPECT_TRUE(provider_->matches().empty());
} }
TEST_F(ZeroSuggestVerbatimMatchProviderTest, TEST_P(ZeroSuggestVerbatimMatchProviderTest, OffersVerbatimMatchOnFocus) {
OffersVerbatimMatchInNonIncognito) {
std::string url("https://www.wired.com/"); std::string url("https://www.wired.com/");
AutocompleteInput input(base::ASCIIToUTF16(url), AutocompleteInput input(base::ASCIIToUTF16(url), GetParam(),
metrics::OmniboxEventProto::OTHER,
TestSchemeClassifier()); TestSchemeClassifier());
input.set_current_url(GURL(url)); input.set_current_url(GURL(url));
input.set_focus_type(OmniboxFocusType::ON_FOCUS); input.set_focus_type(OmniboxFocusType::ON_FOCUS);
provider_->Start(input, false); provider_->Start(input, false);
ASSERT_EQ(1U, provider_->matches().size()); ASSERT_EQ(IsVerbatimMatchEligible(), provider_->matches().size() > 0);
// Note: we intentionally do not validate the match content here. // Note: we intentionally do not validate the match content here.
// The content is populated either by HistoryURLProvider or // The content is populated either by HistoryURLProvider or
// AutocompleteProviderClient both of which we would have to mock for this // AutocompleteProviderClient both of which we would have to mock for this
// test. As a result, the test would validate what the mocks fill in. // test. As a result, the test would validate what the mocks fill in.
} }
TEST_F(ZeroSuggestVerbatimMatchProviderTest, OffersVerbatimMatchInIncognito) { TEST_P(ZeroSuggestVerbatimMatchProviderTest,
std::string url("https://www.theverge.com/"); OffersVerbatimMatchOnFocusInIncognito) {
AutocompleteInput input(base::ASCIIToUTF16(url), std::string url("https://www.wired.com/");
metrics::OmniboxEventProto::OTHER, AutocompleteInput input(base::ASCIIToUTF16(url), GetParam(),
TestSchemeClassifier()); TestSchemeClassifier());
input.set_current_url(GURL(url)); input.set_current_url(GURL(url));
input.set_focus_type(OmniboxFocusType::ON_FOCUS); input.set_focus_type(OmniboxFocusType::ON_FOCUS);
ON_CALL(mock_client_, IsOffTheRecord()).WillByDefault([] { return true; });
provider_->Start(input, false); provider_->Start(input, false);
ASSERT_EQ(1U, provider_->matches().size()); ASSERT_EQ(IsVerbatimMatchEligible(), provider_->matches().size() > 0);
// Note: we intentionally do not validate the match content here. // Note: we intentionally do not validate the match content here.
// The content is populated either by HistoryURLProvider or // The content is populated either by HistoryURLProvider or
// AutocompleteProviderClient both of which we would have to mock for this // AutocompleteProviderClient both of which we would have to mock for this
// test. As a result, the test would validate what the mocks fill in. // test. As a result, the test would validate what the mocks fill in.
} }
TEST_F(ZeroSuggestVerbatimMatchProviderTest, TEST_P(ZeroSuggestVerbatimMatchProviderTest,
OffersVerbatimMatchNonIncognitoWithEmptyOmnibox) { OffersVerbatimMatchWithEmptyInput) {
std::string url("https://www.wired.com/"); std::string url("https://www.wired.com/");
AutocompleteInput input(base::string16(), // Note: empty input. AutocompleteInput input(base::string16(), // Note: empty input.
metrics::OmniboxEventProto::OTHER, GetParam(), TestSchemeClassifier());
TestSchemeClassifier());
input.set_current_url(GURL(url)); input.set_current_url(GURL(url));
input.set_focus_type(OmniboxFocusType::DEFAULT); input.set_focus_type(OmniboxFocusType::DEFAULT);
provider_->Start(input, false); provider_->Start(input, false);
ASSERT_EQ(1U, provider_->matches().size()); ASSERT_EQ(IsVerbatimMatchEligible(), provider_->matches().size() > 0);
// Note: we intentionally do not validate the match content here. // Note: we intentionally do not validate the match content here.
// The content is populated either by HistoryURLProvider or // The content is populated either by HistoryURLProvider or
// AutocompleteProviderClient both of which we would have to mock for this // AutocompleteProviderClient both of which we would have to mock for this
// test. As a result, the test would validate what the mocks fill in. // test. As a result, the test would validate what the mocks fill in.
} }
TEST_F(ZeroSuggestVerbatimMatchProviderTest, TEST_P(ZeroSuggestVerbatimMatchProviderTest,
OffersVerbatimMatchInIncognitoWithEmptyOmnibox) { OffersVerbatimMatchWithEmptyInputInIncognito) {
std::string url("https://www.theverge.com/"); std::string url("https://www.wired.com/");
AutocompleteInput input(base::string16(), // Note: empty input. AutocompleteInput input(base::string16(), // Note: empty input.
metrics::OmniboxEventProto::OTHER, GetParam(), TestSchemeClassifier());
TestSchemeClassifier());
input.set_current_url(GURL(url)); input.set_current_url(GURL(url));
input.set_focus_type(OmniboxFocusType::DEFAULT); input.set_focus_type(OmniboxFocusType::DEFAULT);
ON_CALL(mock_client_, IsOffTheRecord()).WillByDefault([] { return true; });
provider_->Start(input, false);
ASSERT_EQ(IsVerbatimMatchEligible(), provider_->matches().size() > 0);
// Note: we intentionally do not validate the match content here.
// The content is populated either by HistoryURLProvider or
// AutocompleteProviderClient both of which we would have to mock for this
// test. As a result, the test would validate what the mocks fill in.
}
TEST_P(ZeroSuggestVerbatimMatchProviderTest, OffersVerbatimMatchOnClearInput) {
std::string url("https://www.wired.com/");
AutocompleteInput input(base::string16(), // Note: empty input.
GetParam(), TestSchemeClassifier());
input.set_current_url(GURL(url));
input.set_focus_type(OmniboxFocusType::DELETED_PERMANENT_TEXT);
provider_->Start(input, false); provider_->Start(input, false);
ASSERT_EQ(1U, provider_->matches().size()); ASSERT_EQ(IsVerbatimMatchEligible(), provider_->matches().size() > 0);
// Note: we intentionally do not validate the match content here. // Note: we intentionally do not validate the match content here.
// The content is populated either by HistoryURLProvider or // The content is populated either by HistoryURLProvider or
// AutocompleteProviderClient both of which we would have to mock for this // AutocompleteProviderClient both of which we would have to mock for this
// test. As a result, the test would validate what the mocks fill in. // test. As a result, the test would validate what the mocks fill in.
} }
\ No newline at end of file
TEST_P(ZeroSuggestVerbatimMatchProviderTest,
OffersVerbatimMatchOnClearInputInIncognito) {
std::string url("https://www.wired.com/");
AutocompleteInput input(base::string16(), // Note: empty input.
GetParam(), TestSchemeClassifier());
input.set_current_url(GURL(url));
input.set_focus_type(OmniboxFocusType::DELETED_PERMANENT_TEXT);
ON_CALL(mock_client_, IsOffTheRecord()).WillByDefault([] { return true; });
provider_->Start(input, false);
ASSERT_EQ(IsVerbatimMatchEligible(), provider_->matches().size() > 0);
// Note: we intentionally do not validate the match content here.
// The content is populated either by HistoryURLProvider or
// AutocompleteProviderClient both of which we would have to mock for this
// test. As a result, the test would validate what the mocks fill in.
}
INSTANTIATE_TEST_SUITE_P(
ZeroSuggestVerbatimMatchProviderNonIncognitoTests,
ZeroSuggestVerbatimMatchProviderTest,
::testing::Values(
// Variants that should offer verbatim match.
metrics::OmniboxEventProto::OTHER,
metrics::OmniboxEventProto::
SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT,
metrics::OmniboxEventProto::
SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT,
// Variants that should offer no verbatim match.
metrics::OmniboxEventProto::NTP,
metrics::OmniboxEventProto::BLANK,
metrics::OmniboxEventProto::HOME_PAGE,
metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS),
// Ensure clarity when error message is printed out.
+[](const ::testing::TestParamInfo<
metrics::OmniboxEventProto::PageClassification> context)
-> std::string {
return metrics::OmniboxEventProto::PageClassification_Name(context.param);
});
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