Commit f901d5bf authored by Angela Yoeurng's avatar Angela Yoeurng Committed by Commit Bot

[omnibox] Added unit test for stepping through button row selection

Bug: 1046523
Change-Id: Ifa9950ffb2495775b567239d931e8a39dbe69e5b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2339998
Commit-Queue: Angela Yoeurng <yoangela@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Reviewed-by: default avatarOrin Jaworski <orinj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795648}
parent 8b00fe86
...@@ -197,6 +197,8 @@ class AutocompleteController : public AutocompleteProviderListener, ...@@ -197,6 +197,8 @@ class AutocompleteController : public AutocompleteProviderListener,
PopupStepSelectionWithHiddenGroupIds); PopupStepSelectionWithHiddenGroupIds);
FRIEND_TEST_ALL_PREFIXES(OmniboxPopupModelTest, FRIEND_TEST_ALL_PREFIXES(OmniboxPopupModelTest,
PopupInlineAutocompleteAndTemporaryText); PopupInlineAutocompleteAndTemporaryText);
FRIEND_TEST_ALL_PREFIXES(OmniboxPopupModelSuggestionButtonRowTest,
PopupStepSelectionWithButtonRow);
FRIEND_TEST_ALL_PREFIXES(OmniboxPopupContentsViewTest, FRIEND_TEST_ALL_PREFIXES(OmniboxPopupContentsViewTest,
EmitSelectedChildrenChangedAccessibilityEvent); EmitSelectedChildrenChangedAccessibilityEvent);
......
...@@ -99,6 +99,27 @@ class OmniboxPopupModelTest : public ::testing::Test { ...@@ -99,6 +99,27 @@ class OmniboxPopupModelTest : public ::testing::Test {
OmniboxPopupModel popup_model_; OmniboxPopupModel popup_model_;
}; };
// A test fixture that enables the #omnibox-suggestion-button-row field trial.
class OmniboxPopupModelSuggestionButtonRowTest : public OmniboxPopupModelTest {
public:
OmniboxPopupModelSuggestionButtonRowTest() = default;
OmniboxPopupModelSuggestionButtonRowTest(
const OmniboxPopupModelSuggestionButtonRowTest&) = delete;
OmniboxPopupModelSuggestionButtonRowTest& operator=(
const OmniboxPopupModelSuggestionButtonRowTest&) = delete;
protected:
// testing::Test:
void SetUp() override {
scoped_feature_list_.InitAndEnableFeature(
omnibox::kOmniboxSuggestionButtonRow);
OmniboxPopupModelTest::SetUp();
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
// This verifies that the new treatment of the user's selected match in // This verifies that the new treatment of the user's selected match in
// |SetSelectedLine()| with removed |AutocompleteResult::Selection::empty()| // |SetSelectedLine()| with removed |AutocompleteResult::Selection::empty()|
// is correct in the face of various replacement versions of |empty()|. // is correct in the face of various replacement versions of |empty()|.
...@@ -343,6 +364,107 @@ TEST_F(OmniboxPopupModelTest, PopupStepSelectionWithHiddenGroupIds) { ...@@ -343,6 +364,107 @@ TEST_F(OmniboxPopupModelTest, PopupStepSelectionWithHiddenGroupIds) {
} }
} }
TEST_F(OmniboxPopupModelSuggestionButtonRowTest,
PopupStepSelectionWithButtonRow) {
ACMatches matches;
for (size_t i = 0; i < 5; ++i) {
AutocompleteMatch match(nullptr, 1000, false,
AutocompleteMatchType::URL_WHAT_YOU_TYPED);
match.keyword = base::ASCIIToUTF16("match");
match.allowed_to_be_default_match = true;
matches.push_back(match);
}
// Make match index 1 deletable to verify we can step to that.
matches[1].deletable = true;
matches[2].associated_keyword =
std::make_unique<AutocompleteMatch>(matches.back());
matches[2].has_tab_match = true;
// Make match index 3 have an associated keyword, tab match, and deletable to
// verify keyword mode doesn't override tab match and remove suggestion
// buttons (as it does with button row disabled)
matches[3].associated_keyword =
std::make_unique<AutocompleteMatch>(matches.back());
matches[3].has_tab_match = true;
matches[3].deletable = true;
// Make match index 4 have a suggestion_group_id to test header behavior.
matches[4].suggestion_group_id = 7;
auto* result = &model()->autocomplete_controller()->result_;
AutocompleteInput input(base::UTF8ToUTF16("match"),
metrics::OmniboxEventProto::NTP,
TestSchemeClassifier());
result->AppendMatches(input, matches);
result->SortAndCull(input, nullptr);
popup_model()->OnResultChanged();
EXPECT_EQ(0u, model()->popup_model()->selected_line());
// Step by lines forward.
for (size_t n : {1, 2, 3, 4, 0}) {
popup_model()->StepSelection(OmniboxPopupModel::kForward,
OmniboxPopupModel::kWholeLine);
EXPECT_EQ(n, model()->popup_model()->selected_line());
}
// Step by lines backward.
for (size_t n : {4, 3, 2, 1, 0}) {
popup_model()->StepSelection(OmniboxPopupModel::kBackward,
OmniboxPopupModel::kWholeLine);
EXPECT_EQ(n, model()->popup_model()->selected_line());
}
// Step by states forward.
for (auto selection : {
Selection(1, OmniboxPopupModel::NORMAL),
Selection(1, OmniboxPopupModel::FOCUSED_BUTTON_REMOVE_SUGGESTION),
Selection(2, OmniboxPopupModel::NORMAL),
Selection(2, OmniboxPopupModel::FOCUSED_BUTTON_KEYWORD),
Selection(2, OmniboxPopupModel::FOCUSED_BUTTON_TAB_SWITCH),
Selection(3, OmniboxPopupModel::NORMAL),
Selection(3, OmniboxPopupModel::FOCUSED_BUTTON_KEYWORD),
Selection(3, OmniboxPopupModel::FOCUSED_BUTTON_TAB_SWITCH),
Selection(3, OmniboxPopupModel::FOCUSED_BUTTON_REMOVE_SUGGESTION),
Selection(4, OmniboxPopupModel::FOCUSED_BUTTON_HEADER),
Selection(4, OmniboxPopupModel::NORMAL),
Selection(0, OmniboxPopupModel::NORMAL),
}) {
popup_model()->StepSelection(OmniboxPopupModel::kForward,
OmniboxPopupModel::kStateOrLine);
EXPECT_EQ(selection, model()->popup_model()->selection());
}
// Step by states backward. Unlike without suggestion button row, there is no
// difference in behavior for KEYWORD mode moving forward or backward.
for (auto selection : {
Selection(4, OmniboxPopupModel::NORMAL),
Selection(4, OmniboxPopupModel::FOCUSED_BUTTON_HEADER),
Selection(3, OmniboxPopupModel::FOCUSED_BUTTON_REMOVE_SUGGESTION),
Selection(3, OmniboxPopupModel::FOCUSED_BUTTON_TAB_SWITCH),
Selection(3, OmniboxPopupModel::FOCUSED_BUTTON_KEYWORD),
Selection(3, OmniboxPopupModel::NORMAL),
Selection(2, OmniboxPopupModel::FOCUSED_BUTTON_TAB_SWITCH),
Selection(2, OmniboxPopupModel::FOCUSED_BUTTON_KEYWORD),
Selection(2, OmniboxPopupModel::NORMAL),
Selection(1, OmniboxPopupModel::FOCUSED_BUTTON_REMOVE_SUGGESTION),
Selection(1, OmniboxPopupModel::NORMAL),
Selection(0, OmniboxPopupModel::NORMAL),
Selection(4, OmniboxPopupModel::NORMAL),
Selection(4, OmniboxPopupModel::FOCUSED_BUTTON_HEADER),
Selection(3, OmniboxPopupModel::FOCUSED_BUTTON_REMOVE_SUGGESTION),
}) {
popup_model()->StepSelection(OmniboxPopupModel::kBackward,
OmniboxPopupModel::kStateOrLine);
EXPECT_EQ(selection, model()->popup_model()->selection());
}
// Try the kAllLines step behavior.
popup_model()->StepSelection(OmniboxPopupModel::kBackward,
OmniboxPopupModel::kAllLines);
EXPECT_EQ(Selection(0, OmniboxPopupModel::NORMAL),
model()->popup_model()->selection());
popup_model()->StepSelection(OmniboxPopupModel::kForward,
OmniboxPopupModel::kAllLines);
EXPECT_EQ(Selection(4, OmniboxPopupModel::NORMAL),
model()->popup_model()->selection());
}
TEST_F(OmniboxPopupModelTest, PopupInlineAutocompleteAndTemporaryText) { TEST_F(OmniboxPopupModelTest, PopupInlineAutocompleteAndTemporaryText) {
// Create a set of three matches "a|1" (inline autocompleted), "a2", "a3". // Create a set of three matches "a|1" (inline autocompleted), "a2", "a3".
// The third match has a suggestion group ID. // The third match has a suggestion group ID.
......
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