summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc
diff options
context:
space:
mode:
authoraaron.randolph@gmail.com <aaron.randolph@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-29 05:43:34 +0000
committeraaron.randolph@gmail.com <aaron.randolph@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-29 05:43:34 +0000
commit3cb0f8d92d653f4ff8e6886bf6b3a975bd843212 (patch)
treefcf52413da7d05118f97d1ff3c17c89c72a6664c /chrome/browser/ui/omnibox/omnibox_view_browsertest.cc
parent515face447d10a3095341cc390c8c0274ca62381 (diff)
downloadchromium_src-3cb0f8d92d653f4ff8e6886bf6b3a975bd843212.zip
chromium_src-3cb0f8d92d653f4ff8e6886bf6b3a975bd843212.tar.gz
chromium_src-3cb0f8d92d653f4ff8e6886bf6b3a975bd843212.tar.bz2
Enabled pressing TAB to traverse through the Omnibox results, removed moving the caret to the end of the line with TAB, and filtered out redundant URLs.
This adds the ability to move through Omnibox result matches using TAB in addition to the arrow keys. To enable this, pressing TAB to move the caret to the end of the line was removed and the keyword hint/shortcut logic has been modified. The Omnibox popup now shows keyword markers on the right side of matches that have associated keywords (represented by a right arrow). When this kind of match is selected, and the keyword is accepted, the match changes appearance by animating in the associated keyword match from the right to display the "Search X for <>" message. If multiple matches have the same keyword then only the most relevant match will display the keyword marker and hint. Pressing TAB while a keyword hint is shown will enter keyword mode in place; the results will no longer change when keyword mode is entered. Additionally, substituting keyword provider matches will only be shown if a keyword substitution is available. Finally, results with redundant destination URLs (e.g., "foo.com", "www.foo.com") will have the less relevant URLs filtered out. This also addresses some GTK omnibox browsertest flakiness; see bug 112041. See original change review at http://codereview.chromium.org/6731036 Contributed by aaron.randolph@gmail.com BUG=57748,76278,77662,80934,84420 TEST=Press TAB to move the selection down the list of results, SHIFT+TAB to move up. Review URL: http://codereview.chromium.org/9309099 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124125 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/omnibox/omnibox_view_browsertest.cc')
-rw-r--r--chrome/browser/ui/omnibox/omnibox_view_browsertest.cc153
1 files changed, 119 insertions, 34 deletions
diff --git a/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc b/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc
index db2a2e1..13905f1 100644
--- a/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc
+++ b/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc
@@ -756,7 +756,7 @@ class OmniboxViewTest : public InProcessBrowserTest,
// Keyword should also be accepted by typing an ideographic space.
omnibox_view->OnBeforePossibleChange();
omnibox_view->SetWindowTextAndCaretPos(text + WideToUTF16(L"\x3000"),
- text.length() + 1);
+ text.length() + 1, false, false);
omnibox_view->OnAfterPossibleChange();
ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
ASSERT_EQ(text, omnibox_view->model()->keyword());
@@ -771,7 +771,7 @@ class OmniboxViewTest : public InProcessBrowserTest,
// Keyword shouldn't be accepted by pressing space with a trailing
// whitespace.
omnibox_view->SetWindowTextAndCaretPos(
- text + char16(' '), text.length() + 1);
+ text + char16(' '), text.length() + 1, false, false);
ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
ASSERT_EQ(text, omnibox_view->model()->keyword());
@@ -808,7 +808,7 @@ class OmniboxViewTest : public InProcessBrowserTest,
omnibox_view->OnBeforePossibleChange();
omnibox_view->model()->on_paste();
omnibox_view->SetWindowTextAndCaretPos(text + ASCIIToUTF16(" bar"),
- text.length() + 4);
+ text.length() + 4, false, false);
omnibox_view->OnAfterPossibleChange();
ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
ASSERT_TRUE(omnibox_view->model()->keyword().empty());
@@ -1022,59 +1022,137 @@ class OmniboxViewTest : public InProcessBrowserTest,
ASSERT_TRUE(omnibox_view->IsSelectAll());
}
- void TabMoveCursorToEndTest() {
+ void TabAcceptKeyword() {
OmniboxView* omnibox_view = NULL;
ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
- omnibox_view->SetUserText(ASCIIToUTF16("Hello world"));
+ string16 text = ASCIIToUTF16(kSearchKeyword);
+
+ // Trigger keyword hint mode.
+ ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
+ ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
+ ASSERT_EQ(text, omnibox_view->model()->keyword());
+ ASSERT_EQ(text, omnibox_view->GetText());
+
+ // Trigger keyword mode by tab.
+ ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
+ ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
+ ASSERT_EQ(text, omnibox_view->model()->keyword());
+ ASSERT_TRUE(omnibox_view->GetText().empty());
+
+ // Revert to keyword hint mode.
+ ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
+ ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
+ ASSERT_EQ(text, omnibox_view->model()->keyword());
+ ASSERT_EQ(text, omnibox_view->GetText());
+
+ // The location bar should still have focus.
+ ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(),
+ location_bar_focus_view_id_));
- // Move cursor to the beginning.
+ // Trigger keyword mode by tab.
+ ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
+ ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
+ ASSERT_EQ(text, omnibox_view->model()->keyword());
+ ASSERT_TRUE(omnibox_view->GetText().empty());
+
+ // Revert to keyword hint mode with SHIFT+TAB.
#if defined(OS_MACOSX)
- // Home doesn't work on Mac trybot.
- ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, ui::EF_CONTROL_DOWN));
+ ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACKTAB, 0));
#else
- ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_HOME, 0));
+ ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN));
#endif
+ ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
+ ASSERT_EQ(text, omnibox_view->model()->keyword());
+ ASSERT_EQ(text, omnibox_view->GetText());
- size_t start, end;
- omnibox_view->GetSelectionBounds(&start, &end);
- EXPECT_EQ(0U, start);
- EXPECT_EQ(0U, end);
+ ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(),
+ location_bar_focus_view_id_));
+ }
+
+ void TabTraverseResultsTest() {
+ OmniboxView* omnibox_view = NULL;
+ ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
+ AutocompletePopupModel* popup_model = omnibox_view->model()->popup_model();
+ ASSERT_TRUE(popup_model);
+
+ // Input something to trigger results.
+ ASSERT_NO_FATAL_FAILURE(SendKeySequence(kDesiredTLDKeys));
+ ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
+ ASSERT_TRUE(popup_model->IsOpen());
- // Pressing tab should move cursor to the end.
+ size_t old_selected_line = popup_model->selected_line();
+ EXPECT_EQ(0U, old_selected_line);
+
+ // Move down the results.
+ for (size_t size = popup_model->result().size();
+ popup_model->selected_line() < size - 1;
+ old_selected_line = popup_model->selected_line()) {
+ ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
+ ASSERT_LT(old_selected_line, popup_model->selected_line());
+ }
+
+ // Don't move past the end.
ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
+ ASSERT_EQ(old_selected_line, popup_model->selected_line());
+ ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(),
+ location_bar_focus_view_id_));
- omnibox_view->GetSelectionBounds(&start, &end);
- EXPECT_EQ(omnibox_view->GetText().size(), start);
- EXPECT_EQ(omnibox_view->GetText().size(), end);
+ // Move back up the results.
+ for (; popup_model->selected_line() > 0U;
+ old_selected_line = popup_model->selected_line()) {
+ ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN));
+ ASSERT_GT(old_selected_line, popup_model->selected_line());
+ }
- // The location bar should still have focus.
+ // Don't move past the beginning.
+ ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN));
+ ASSERT_EQ(0U, popup_model->selected_line());
ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(),
location_bar_focus_view_id_));
- // Select all text.
- omnibox_view->SelectAll(true);
- EXPECT_TRUE(omnibox_view->IsSelectAll());
- omnibox_view->GetSelectionBounds(&start, &end);
- EXPECT_EQ(0U, start);
- EXPECT_EQ(omnibox_view->GetText().size(), end);
+ const TestHistoryEntry kHistoryFoo = {
+ "http://foo/", "Page foo", kSearchText, 1, 1, false
+ };
- // Pressing tab should move cursor to the end.
- ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
+ // Add a history entry so "foo" gets multiple matches.
+ ASSERT_NO_FATAL_FAILURE(
+ AddHistoryEntry(kHistoryFoo, Time::Now() - TimeDelta::FromHours(1)));
- omnibox_view->GetSelectionBounds(&start, &end);
- EXPECT_EQ(omnibox_view->GetText().size(), start);
- EXPECT_EQ(omnibox_view->GetText().size(), end);
+ // Load results.
+ ASSERT_NO_FATAL_FAILURE(omnibox_view->SelectAll(false));
+ ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
+ ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
+
+ // Trigger keyword mode by tab.
+ string16 text = ASCIIToUTF16(kSearchKeyword);
+ ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
+ ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
+ ASSERT_EQ(text, omnibox_view->model()->keyword());
+ ASSERT_TRUE(omnibox_view->GetText().empty());
// The location bar should still have focus.
ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(),
location_bar_focus_view_id_));
- // Pressing tab when cursor is at the end should change focus.
+ // Pressing tab again should move to the next result and clear keyword
+ // mode.
ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
+ ASSERT_EQ(1U, omnibox_view->model()->popup_model()->selected_line());
+ ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
+ ASSERT_NE(text, omnibox_view->model()->keyword());
+
+ // The location bar should still have focus.
+ ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(),
+ location_bar_focus_view_id_));
+
+ // Moving back up should not show keyword mode.
+ ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN));
+ ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
+ ASSERT_EQ(text, omnibox_view->model()->keyword());
- ASSERT_FALSE(ui_test_utils::IsViewFocused(browser(),
- location_bar_focus_view_id_));
+ ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(),
+ location_bar_focus_view_id_));
}
void PersistKeywordModeOnTabSwitch() {
@@ -1195,10 +1273,17 @@ IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DeleteItem) {
DeleteItemTest();
}
-IN_PROC_BROWSER_TEST_F(OmniboxViewTest, TabMoveCursorToEnd) {
- TabMoveCursorToEndTest();
+IN_PROC_BROWSER_TEST_F(OmniboxViewTest, TabAcceptKeyword) {
+ TabAcceptKeyword();
}
+#if !defined(OS_MACOSX)
+// Mac intentionally does not support this behavior.
+IN_PROC_BROWSER_TEST_F(OmniboxViewTest, TabTraverseResultsTest) {
+ TabTraverseResultsTest();
+}
+#endif
+
IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
PersistKeywordModeOnTabSwitch) {
PersistKeywordModeOnTabSwitch();