Commit 515a7bd7 authored by Moe Ahmadi's avatar Moe Ahmadi Committed by Commit Bot

[omnibox] Demotes URLs in the NTP Realbox.

Change-Id: I9ea3144f0eb659c8b4bd64be364d056267e6d606
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2099103
Commit-Queue: Moe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarmanuk hovanesian <manukh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749360}
parent 4645f27c
...@@ -523,12 +523,13 @@ ACMatches::iterator AutocompleteResult::FindTopMatch( ...@@ -523,12 +523,13 @@ ACMatches::iterator AutocompleteResult::FindTopMatch(
// expects to see a commonly visited URL as the default match, the URL is not // expects to see a commonly visited URL as the default match, the URL is not
// suppressed by type demotion. // suppressed by type demotion.
// However, we don't care about this URL behavior when the user is using the // However, we don't care about this URL behavior when the user is using the
// fakebox, which is intended to work more like a search-only box. Unless the // fakebox/realbox, which is intended to work more like a search-only box.
// user's input is a URL in which case we still want to ensure they can get a // Unless the user's input is a URL in which case we still want to ensure they
// URL as the default match. // can get a URL as the default match.
if ((input.current_page_classification() != if ((input.current_page_classification() !=
OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS || OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS &&
input.type() == metrics::OmniboxInputType::URL)) { input.current_page_classification() != OmniboxEventProto::NTP_REALBOX) ||
input.type() == metrics::OmniboxInputType::URL) {
auto best = matches->end(); auto best = matches->end();
for (auto it = matches->begin(); it != matches->end(); ++it) { for (auto it = matches->begin(); it != matches->end(); ++it) {
if (it->allowed_to_be_default_match && !it->IsSubMatch() && if (it->allowed_to_be_default_match && !it->IsSubMatch() &&
......
...@@ -145,6 +145,13 @@ class AutocompleteResultTest : public testing::Test { ...@@ -145,6 +145,13 @@ class AutocompleteResultTest : public testing::Test {
const TestData* expected, const TestData* expected,
size_t expected_size); size_t expected_size);
void SortMatchesAndVerfiyOrder(
const std::string& input_text,
OmniboxEventProto::PageClassification page_classification,
const ACMatches& matches,
const std::vector<size_t>& expected_order,
const AutocompleteMatchTestData data[]);
// Returns a (mock) AutocompleteProvider of given |provider_id|. // Returns a (mock) AutocompleteProvider of given |provider_id|.
MockAutocompleteProvider* GetProvider(int provider_id) { MockAutocompleteProvider* GetProvider(int provider_id) {
EXPECT_LT(provider_id, static_cast<int>(mock_provider_list_.size())); EXPECT_LT(provider_id, static_cast<int>(mock_provider_list_.size()));
...@@ -231,6 +238,25 @@ void AutocompleteResultTest::RunTransferOldMatchesTest(const TestData* last, ...@@ -231,6 +238,25 @@ void AutocompleteResultTest::RunTransferOldMatchesTest(const TestData* last,
AssertResultMatches(current_result, expected, expected_size); AssertResultMatches(current_result, expected, expected_size);
} }
void AutocompleteResultTest::SortMatchesAndVerfiyOrder(
const std::string& input_text,
OmniboxEventProto::PageClassification page_classification,
const ACMatches& matches,
const std::vector<size_t>& expected_order,
const AutocompleteMatchTestData data[]) {
AutocompleteInput input(base::ASCIIToUTF16(input_text), page_classification,
TestSchemeClassifier());
AutocompleteResult result;
result.AppendMatches(input, matches);
result.SortAndCull(input, template_url_service_.get());
ASSERT_EQ(expected_order.size(), result.size());
for (size_t i = 0; i < expected_order.size(); ++i) {
EXPECT_EQ(data[expected_order[i]].destination_url,
result.match_at(i)->destination_url.spec());
}
}
// Assertion testing for AutocompleteResult::Swap. // Assertion testing for AutocompleteResult::Swap.
TEST_F(AutocompleteResultTest, Swap) { TEST_F(AutocompleteResultTest, Swap) {
AutocompleteResult r1; AutocompleteResult r1;
...@@ -1040,75 +1066,37 @@ TEST_F(AutocompleteResultTest, DemoteByType) { ...@@ -1040,75 +1066,37 @@ TEST_F(AutocompleteResultTest, DemoteByType) {
base::FieldTrialList::CreateFieldTrial( base::FieldTrialList::CreateFieldTrial(
OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A");
{ // Because we want to ensure the highest naturally scoring
AutocompleteInput input(base::ASCIIToUTF16("a"), // allowed-to-be default suggestion is the default, make sure history-title
OmniboxEventProto::HOME_PAGE, // is the default match despite demotion.
TestSchemeClassifier()); // Make sure history-URL is the last match due to the logic which groups
AutocompleteResult result; // searches and URLs together.
result.AppendMatches(input, matches); SortMatchesAndVerfiyOrder("a", OmniboxEventProto::HOME_PAGE, matches,
result.SortAndCull(input, template_url_service_.get()); {1, 2, 3, 0}, data);
// Because we want to ensure the highest naturally scoring // However, in the fakebox/realbox, we do want to use the demoted score when
// allowed-to-be default suggestion is the default, make sure history-title // selecting the default match because we generally only expect it to be
// is the default match despite demotion. // used for queries and we demote URLs strongly. So here we re-sort with a
// Make sure history-URL is the last match due to the logic which groups // page classification of fakebox/realbox, and make sure history-title is now
// searches and URLs together. // demoted. We also make sure history-URL is the last match due to the logic
size_t expected_order[] = {1, 2, 3, 0}; // which groups searches and URLs together.
SortMatchesAndVerfiyOrder(
ASSERT_EQ(base::size(expected_order), result.size()); "a", OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS,
for (size_t i = 0; i < base::size(expected_order); ++i) { matches, {3, 2, 0, 1}, data);
EXPECT_EQ(data[expected_order[i]].destination_url, SortMatchesAndVerfiyOrder("a", OmniboxEventProto::NTP_REALBOX, matches,
result.match_at(i)->destination_url.spec()); {3, 2, 0, 1}, data);
}
} // Unless, the user's input looks like a URL, in which case we want to use
// the natural scoring again to make sure the user gets a URL if they're
{ // clearly trying to navigate. So here we re-sort with a page classification
// However, in the fakebox, we do want to use the demoted score when // of fakebox/realbox and an input that's a URL, and make sure history-title
// selecting the default match because we generally only expect it to be // is once again the default match.
// used for queries and we demote URLs strongly. So here we re-sort with a SortMatchesAndVerfiyOrder(
// page classification of fake-box, and make sure history-title is now "www.example.com",
// demoted. OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, matches,
AutocompleteInput input( {1, 2, 3, 0}, data);
base::ASCIIToUTF16("a"), SortMatchesAndVerfiyOrder("www.example.com", OmniboxEventProto::NTP_REALBOX,
OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, matches, {1, 2, 3, 0}, data);
TestSchemeClassifier());
AutocompleteResult result;
result.AppendMatches(input, matches);
result.SortAndCull(input, template_url_service_.get());
// Make sure history-URL is the last match due to the logic which groups
// searches and URLs together.
size_t expected_order[] = {3, 2, 0, 1};
ASSERT_EQ(base::size(expected_order), result.size());
for (size_t i = 0; i < base::size(expected_order); ++i) {
EXPECT_EQ(data[expected_order[i]].destination_url,
result.match_at(i)->destination_url.spec());
}
}
{
// Unless, the user's input looks like a URL, in which case we want to use
// the natural scoring again to make sure the user gets a URL if they're
// clearly trying to navigate. So here we re-sort with a page classification
// of fake-box and an input that's a URL, and make sure history-title is
// once again the default match.
AutocompleteInput input(
base::ASCIIToUTF16("www.example.com"),
OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS,
TestSchemeClassifier());
AutocompleteResult result;
result.AppendMatches(input, matches);
result.SortAndCull(input, template_url_service_.get());
size_t expected_order[] = {1, 2, 3, 0};
ASSERT_EQ(base::size(expected_order), result.size());
for (size_t i = 0; i < base::size(expected_order); ++i) {
EXPECT_EQ(data[expected_order[i]].destination_url,
result.match_at(i)->destination_url.spec());
}
}
} }
TEST_F(AutocompleteResultTest, SortAndCullReorderForDefaultMatch) { TEST_F(AutocompleteResultTest, SortAndCullReorderForDefaultMatch) {
......
...@@ -311,8 +311,10 @@ void OmniboxFieldTrial::GetDemotionsByType( ...@@ -311,8 +311,10 @@ void OmniboxFieldTrial::GetDemotionsByType(
demotion_rule = "1:61,2:61,3:61,4:61,16:61,24:61"; demotion_rule = "1:61,2:61,3:61,4:61,16:61,24:61";
#endif #endif
if (current_page_classification == if (current_page_classification ==
OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS) OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS ||
current_page_classification == OmniboxEventProto::NTP_REALBOX) {
demotion_rule = "1:10,2:10,3:10,4:10,5:10,16:10,17:10,24:10"; demotion_rule = "1:10,2:10,3:10,4:10,5:10,16:10,17:10,24:10";
}
} }
// The value of the DemoteByType rule is a comma-separated list of // The value of the DemoteByType rule is a comma-separated list of
......
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