Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3020)

Unified Diff: chrome/browser/ui/omnibox/omnibox_view_browsertest.cc

Issue 2435103002: Omnibox: Preserve display text and select all on a focus search (Closed)
Patch Set: Use display_text.length() as caret pos for KEYBOARD_SHORTCUT Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/omnibox/omnibox_view_browsertest.cc
diff --git a/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc b/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc
index 23e28df07691b091d7845d493d205a8e7d2d49c5..415b22debcb403e75c818ae430b07a743a5a5a88 100644
--- a/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc
+++ b/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc
@@ -884,6 +884,60 @@ IN_PROC_BROWSER_TEST_F(OmniboxViewTest, FocusSearchLongUrl) {
ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
}
+// Make sure the display text is preserved when calling FocusSearch() when the
+// display text is not the permanent text.
+IN_PROC_BROWSER_TEST_F(OmniboxViewTest, PreserveDisplayTextOnFocusSearch) {
+ OmniboxView* omnibox_view = NULL;
+ ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
+
+ OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
+ ASSERT_TRUE(popup_model);
+
+ // Input something that can match history items.
+ omnibox_view->SetUserText(ASCIIToUTF16("site.com/p"));
+ ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
+ EXPECT_TRUE(popup_model->IsOpen());
+ EXPECT_EQ(ASCIIToUTF16("site.com/path/1"), omnibox_view->GetText());
+ base::string16::size_type start, end;
+ omnibox_view->GetSelectionBounds(&start, &end);
+ EXPECT_EQ(10U, std::min(start, end));
+ EXPECT_EQ(15U, std::max(start, end));
+
+ // Calling FocusSearch() with an inline autocompletion should preserve the
+ // autocompleted text, and should select all.
+ chrome::FocusSearch(browser());
+ ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
+ EXPECT_EQ(ASCIIToUTF16("site.com/path/1"), omnibox_view->GetText());
+ omnibox_view->GetSelectionBounds(&start, &end);
+ EXPECT_EQ(0U, std::min(start, end));
+ EXPECT_EQ(15U, std::max(start, end));
+
+ // Press backspace twice and the omnibox should be empty.
+ ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
+ ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
+ EXPECT_EQ(base::string16(), omnibox_view->GetText());
+ omnibox_view->GetSelectionBounds(&start, &end);
+ EXPECT_EQ(0U, start);
+ EXPECT_EQ(0U, end);
+
+ // Calling FocusSearch() with temporary text showing should preserve the
+ // suggested text, and should select all.
+ omnibox_view->SetUserText(ASCIIToUTF16("site.com/p"));
+ ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
+ EXPECT_TRUE(popup_model->IsOpen());
+ omnibox_view->model()->OnUpOrDownKeyPressed(1);
+ EXPECT_EQ(ASCIIToUTF16("www.site.com/path/2"), omnibox_view->GetText());
+ omnibox_view->GetSelectionBounds(&start, &end);
+ EXPECT_EQ(start, end);
+
+ chrome::FocusSearch(browser());
+ ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
+ EXPECT_EQ(ASCIIToUTF16("www.site.com/path/2"), omnibox_view->GetText());
+ omnibox_view->GetSelectionBounds(&start, &end);
+ EXPECT_EQ(0U, std::min(start, end));
+ EXPECT_EQ(19U, std::max(start, end));
+}
+
IN_PROC_BROWSER_TEST_F(OmniboxViewTest, AcceptKeywordByTypingQuestionMark) {
OmniboxView* omnibox_view = NULL;
ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
« no previous file with comments | « chrome/browser/ui/omnibox/chrome_omnibox_client.cc ('k') | chrome/browser/ui/views/omnibox/omnibox_view_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698