Commit c01b0308 authored by Orin Jaworski's avatar Orin Jaworski Committed by Commit Bot

[omnibox] Add autocomplete result unit test for Pedal attachment

This CL adds a unit test to ensure AutocompleteResult properly
attaches Pedals to matches.

Bug: 1122622, 893183
Change-Id: I6deff6ae0260a8c286a9538c73f1b319a255ebd6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2407011Reviewed-by: default avatarAngela Yoeurng <yoangela@chromium.org>
Commit-Queue: Orin Jaworski <orinj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806800}
parent 37e23fcb
......@@ -56,10 +56,12 @@ const AutocompleteMatchTestData kNonVerbatimMatches[] = {
};
// Adds |count| AutocompleteMatches to |matches|.
void PopulateAutocompleteMatchesFromTestData(
const AutocompleteMatchTestData* data,
size_t count,
ACMatches* matches) {
template <typename T>
void PopulateAutocompleteMatchesFromTestData(const T* data,
size_t count,
ACMatches* matches) {
static_assert(std::is_base_of<AutocompleteMatchTestData, T>::value,
"T must derive from AutocompleteMatchTestData");
ASSERT_TRUE(matches != nullptr);
for (size_t i = 0; i < count; ++i) {
AutocompleteMatch match;
......@@ -1694,6 +1696,69 @@ TEST_F(AutocompleteResultTest, ConvertsOpenTabsCorrectly) {
EXPECT_FALSE(result.match_at(2)->has_tab_match);
}
TEST_F(AutocompleteResultTest, AttachesPedals) {
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeatures(
{omnibox::kOmniboxPedalSuggestions, omnibox::kOmniboxSuggestionButtonRow},
{});
EXPECT_TRUE(OmniboxFieldTrial::IsPedalSuggestionsEnabled());
FakeAutocompleteProviderClient client;
EXPECT_NE(nullptr, client.GetPedalProvider());
AutocompleteResult result;
// Populate result with test matches.
{
ACMatches matches;
struct TestData : AutocompleteMatchTestData {
std::string contents;
TestData(std::string url,
AutocompleteMatch::Type type,
std::string contents)
: AutocompleteMatchTestData{url, type}, contents(contents) {}
};
const TestData data[] = {
{"http://search-what-you-typed/",
AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, "search what you typed"},
{"http://search-history/", AutocompleteMatchType::SEARCH_HISTORY,
"search history"},
{"http://history-url/", AutocompleteMatchType::HISTORY_URL,
"history url"},
{"http://history-title/", AutocompleteMatchType::HISTORY_TITLE,
"history title"},
{"http://url-what-you-typed/",
AutocompleteMatchType::URL_WHAT_YOU_TYPED, "url what you typed"},
{"http://clipboard-url/", AutocompleteMatchType::CLIPBOARD_URL,
"clipboard url"},
{"http://bookmark-title/", AutocompleteMatchType::BOOKMARK_TITLE,
"bookmark title"},
{"http://entity-clear-history/",
AutocompleteMatchType::SEARCH_SUGGEST_ENTITY, "clear history"},
{"http://clear-history/", AutocompleteMatchType::SEARCH_SUGGEST,
"clear history"},
};
PopulateAutocompleteMatchesFromTestData(data, base::size(data), &matches);
for (size_t i = 0; i < base::size(data); i++) {
matches[i].contents = base::UTF8ToUTF16(data[i].contents);
}
AutocompleteInput input(base::ASCIIToUTF16("a"),
metrics::OmniboxEventProto::OTHER,
TestSchemeClassifier());
result.AppendMatches(input, matches);
}
// Attach |pedal| to result matches where appropriate.
result.ConvertInSuggestionPedalMatches(&client);
// Ensure the entity suggestion doesn't get a pedal even though its contents
// form a concept match.
EXPECT_EQ(nullptr, std::prev(std::prev(result.end()))->pedal);
// The same concept-matching contents on a non-entity suggestion gets a pedal.
EXPECT_NE(nullptr, std::prev(result.end())->pedal);
}
TEST_F(AutocompleteResultTest, DocumentSuggestionsCanMergeButNotToDefault) {
// Types are populated below to avoid introducing a new test data creation
// process.
......
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