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 {
// The relevance score for verbatim match.
// Must outrank the QueryTiles relevance score.
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
ZeroSuggestVerbatimMatchProvider::ZeroSuggestVerbatimMatchProvider(
......@@ -23,9 +41,7 @@ ZeroSuggestVerbatimMatchProvider::~ZeroSuggestVerbatimMatchProvider() = default;
void ZeroSuggestVerbatimMatchProvider::Start(const AutocompleteInput& input,
bool minimal_changes) {
Stop(true, false);
// Only offer verbatim match on a site visit (non-SRP, non-NTP).
if (input.current_page_classification() != metrics::OmniboxEventProto::OTHER)
if (!IsVerbatimMatchEligible(input.current_page_classification()))
return;
// Only offer verbatim match after the user just focused the Omnibox,
......
......@@ -16,103 +16,177 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/metrics_proto/omnibox_event.pb.h"
class ZeroSuggestVerbatimMatchProviderTest : public testing::Test {
class ZeroSuggestVerbatimMatchProviderTest
: public testing::TestWithParam<
metrics::OmniboxEventProto::PageClassification> {
public:
ZeroSuggestVerbatimMatchProviderTest() = default;
void SetUp() override;
protected:
bool IsVerbatimMatchEligible() const;
scoped_refptr<ZeroSuggestVerbatimMatchProvider> provider_;
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() {
provider_ = new ZeroSuggestVerbatimMatchProvider(&mock_client_);
ON_CALL(mock_client_, IsOffTheRecord()).WillByDefault([] { return false; });
}
TEST_F(ZeroSuggestVerbatimMatchProviderTest,
NoVerbatimMatchWhenOmniboxIsOnNTP) {
std::string url("chrome://newtab");
AutocompleteInput input(base::string16(), metrics::OmniboxEventProto::NTP,
TEST_P(ZeroSuggestVerbatimMatchProviderTest,
NoVerbatimMatchWithUserTextInOmnibox) {
std::string query("user input");
std::string url("https://google.com/search?q=test");
AutocompleteInput input(base::ASCIIToUTF16(query), GetParam(),
TestSchemeClassifier());
input.set_current_url(GURL(url));
input.set_focus_type(OmniboxFocusType::ON_FOCUS);
input.set_focus_type(OmniboxFocusType::DEFAULT);
provider_->Start(input, false);
// Clobber state should never generate a verbatim match.
EXPECT_TRUE(provider_->matches().empty());
}
TEST_F(ZeroSuggestVerbatimMatchProviderTest,
NoVerbatimMatchForSearchResultsPage) {
std::string query("https://google.com/search?q=test");
AutocompleteInput input(
base::ASCIIToUTF16("test"),
metrics::OmniboxEventProto::SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT,
TestSchemeClassifier());
input.set_current_url(GURL(query));
input.set_focus_type(OmniboxFocusType::ON_FOCUS);
TEST_P(ZeroSuggestVerbatimMatchProviderTest,
NoVerbatimMatchWithUserTextInOmniboxInIncognito) {
std::string query("user input");
std::string url("https://google.com/search?q=test");
AutocompleteInput input(base::ASCIIToUTF16(query), GetParam(),
TestSchemeClassifier());
input.set_current_url(GURL(url));
input.set_focus_type(OmniboxFocusType::DEFAULT);
ON_CALL(mock_client_, IsOffTheRecord()).WillByDefault([] { return true; });
provider_->Start(input, false);
// Clobber state should never generate a verbatim match.
EXPECT_TRUE(provider_->matches().empty());
}
TEST_F(ZeroSuggestVerbatimMatchProviderTest,
OffersVerbatimMatchInNonIncognito) {
TEST_P(ZeroSuggestVerbatimMatchProviderTest, OffersVerbatimMatchOnFocus) {
std::string url("https://www.wired.com/");
AutocompleteInput input(base::ASCIIToUTF16(url),
metrics::OmniboxEventProto::OTHER,
AutocompleteInput input(base::ASCIIToUTF16(url), GetParam(),
TestSchemeClassifier());
input.set_current_url(GURL(url));
input.set_focus_type(OmniboxFocusType::ON_FOCUS);
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.
// 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_F(ZeroSuggestVerbatimMatchProviderTest, OffersVerbatimMatchInIncognito) {
std::string url("https://www.theverge.com/");
AutocompleteInput input(base::ASCIIToUTF16(url),
metrics::OmniboxEventProto::OTHER,
TEST_P(ZeroSuggestVerbatimMatchProviderTest,
OffersVerbatimMatchOnFocusInIncognito) {
std::string url("https://www.wired.com/");
AutocompleteInput input(base::ASCIIToUTF16(url), GetParam(),
TestSchemeClassifier());
input.set_current_url(GURL(url));
input.set_focus_type(OmniboxFocusType::ON_FOCUS);
ON_CALL(mock_client_, IsOffTheRecord()).WillByDefault([] { return true; });
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.
// 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_F(ZeroSuggestVerbatimMatchProviderTest,
OffersVerbatimMatchNonIncognitoWithEmptyOmnibox) {
TEST_P(ZeroSuggestVerbatimMatchProviderTest,
OffersVerbatimMatchWithEmptyInput) {
std::string url("https://www.wired.com/");
AutocompleteInput input(base::string16(), // Note: empty input.
metrics::OmniboxEventProto::OTHER,
TestSchemeClassifier());
GetParam(), TestSchemeClassifier());
input.set_current_url(GURL(url));
input.set_focus_type(OmniboxFocusType::DEFAULT);
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.
// 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_F(ZeroSuggestVerbatimMatchProviderTest,
OffersVerbatimMatchInIncognitoWithEmptyOmnibox) {
std::string url("https://www.theverge.com/");
TEST_P(ZeroSuggestVerbatimMatchProviderTest,
OffersVerbatimMatchWithEmptyInputInIncognito) {
std::string url("https://www.wired.com/");
AutocompleteInput input(base::string16(), // Note: empty input.
metrics::OmniboxEventProto::OTHER,
TestSchemeClassifier());
GetParam(), TestSchemeClassifier());
input.set_current_url(GURL(url));
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);
ASSERT_EQ(1U, provider_->matches().size());
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.
}
\ 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