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

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: Add browser tests 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..5e378446190d800f845a66b9c5eed1a75a07ccb8 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 on a focus search 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());
+ ASSERT_TRUE(popup_model->IsOpen());
+ ASSERT_EQ(ASCIIToUTF16("site.com/path/1"), omnibox_view->GetText());
+ base::string16::size_type start, end;
+ omnibox_view->GetSelectionBounds(&start, &end);
+ ASSERT_EQ(10U, std::min(start, end));
+ ASSERT_EQ(15U, std::max(start, end));
+
+ // Focus searching with autocomplete text should preserve the autocompleted
+ // text, and should select all.
+ chrome::FocusSearch(browser());
+ ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
+ ASSERT_EQ(ASCIIToUTF16("site.com/path/1"), omnibox_view->GetText());
+ omnibox_view->GetSelectionBounds(&start, &end);
+ ASSERT_EQ(0U, std::min(start, end));
+ ASSERT_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);
+ ASSERT_EQ(0U, start);
+ ASSERT_EQ(0U, end);
+
+ // Focus searching when we select a non-default autocomplete entry should
+ // preserve the suggested text, and should select all.
+ omnibox_view->SetUserText(ASCIIToUTF16("site.com/p"));
+ ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
+ ASSERT_TRUE(popup_model->IsOpen());
+ omnibox_view->model()->OnUpOrDownKeyPressed(1);
+ ASSERT_EQ(ASCIIToUTF16("www.site.com/path/2"), omnibox_view->GetText());
+ omnibox_view->GetSelectionBounds(&start, &end);
+ ASSERT_EQ(start, end);
+
+ chrome::FocusSearch(browser());
+ ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
+ ASSERT_EQ(ASCIIToUTF16("www.site.com/path/2"), omnibox_view->GetText());
+ omnibox_view->GetSelectionBounds(&start, &end);
+ ASSERT_EQ(0U, std::min(start, end));
+ ASSERT_EQ(19U, std::max(start, end));
+}
+
IN_PROC_BROWSER_TEST_F(OmniboxViewTest, AcceptKeywordByTypingQuestionMark) {
OmniboxView* omnibox_view = NULL;
ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));

Powered by Google App Engine
This is Rietveld 408576698