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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); 877 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
878 878
879 ASSERT_GT(strlen(url::kAboutBlankURL), strlen(kSearchKeyword)); 879 ASSERT_GT(strlen(url::kAboutBlankURL), strlen(kSearchKeyword));
880 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); 880 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
881 881
882 // Make sure nothing DCHECKs. 882 // Make sure nothing DCHECKs.
883 chrome::FocusSearch(browser()); 883 chrome::FocusSearch(browser());
884 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 884 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
885 } 885 }
886 886
887 // Make sure the display text is preserved on a focus search when the display
888 // text is not the permanent text.
889 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, PreserveDisplayTextOnFocusSearch) {
890 OmniboxView* omnibox_view = NULL;
891 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
892
893 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
894 ASSERT_TRUE(popup_model);
895
896 // Input something that can match history items.
897 omnibox_view->SetUserText(ASCIIToUTF16("site.com/p"));
898 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
899 ASSERT_TRUE(popup_model->IsOpen());
900 ASSERT_EQ(ASCIIToUTF16("site.com/path/1"), omnibox_view->GetText());
901 base::string16::size_type start, end;
902 omnibox_view->GetSelectionBounds(&start, &end);
903 ASSERT_EQ(10U, std::min(start, end));
904 ASSERT_EQ(15U, std::max(start, end));
905
906 // Focus searching with autocomplete text should preserve the autocompleted
907 // text, and should select all.
908 chrome::FocusSearch(browser());
909 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
910 ASSERT_EQ(ASCIIToUTF16("site.com/path/1"), omnibox_view->GetText());
911 omnibox_view->GetSelectionBounds(&start, &end);
912 ASSERT_EQ(0U, std::min(start, end));
913 ASSERT_EQ(15U, std::max(start, end));
914
915 // Press backspace twice and the omnibox should be empty.
916 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
917 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
918 EXPECT_EQ(base::string16(), omnibox_view->GetText());
919 omnibox_view->GetSelectionBounds(&start, &end);
920 ASSERT_EQ(0U, start);
921 ASSERT_EQ(0U, end);
922
923 // Focus searching when we select a non-default autocomplete entry should
924 // preserve the suggested text, and should select all.
925 omnibox_view->SetUserText(ASCIIToUTF16("site.com/p"));
926 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
927 ASSERT_TRUE(popup_model->IsOpen());
928 omnibox_view->model()->OnUpOrDownKeyPressed(1);
929 ASSERT_EQ(ASCIIToUTF16("www.site.com/path/2"), omnibox_view->GetText());
930 omnibox_view->GetSelectionBounds(&start, &end);
931 ASSERT_EQ(start, end);
932
933 chrome::FocusSearch(browser());
934 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
935 ASSERT_EQ(ASCIIToUTF16("www.site.com/path/2"), omnibox_view->GetText());
936 omnibox_view->GetSelectionBounds(&start, &end);
937 ASSERT_EQ(0U, std::min(start, end));
938 ASSERT_EQ(19U, std::max(start, end));
939 }
940
887 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, AcceptKeywordByTypingQuestionMark) { 941 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, AcceptKeywordByTypingQuestionMark) {
888 OmniboxView* omnibox_view = NULL; 942 OmniboxView* omnibox_view = NULL;
889 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); 943 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
890 944
891 base::string16 search_keyword(ASCIIToUTF16(kSearchKeyword)); 945 base::string16 search_keyword(ASCIIToUTF16(kSearchKeyword));
892 946
893 // If the user gets into keyword mode by typing '?', they should be put into 947 // If the user gets into keyword mode by typing '?', they should be put into
894 // keyword mode for their default search provider. 948 // keyword mode for their default search provider.
895 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_OEM_2, ui::EF_SHIFT_DOWN)); 949 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_OEM_2, ui::EF_SHIFT_DOWN));
896 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 950 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after
1942 1996
1943 // Now Shift+Right should do nothing, and Shift+Left should reduce. 1997 // Now Shift+Right should do nothing, and Shift+Left should reduce.
1944 // At the end, so Shift+Right should do nothing. 1998 // At the end, so Shift+Right should do nothing.
1945 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RIGHT, ui::EF_SHIFT_DOWN)); 1999 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RIGHT, ui::EF_SHIFT_DOWN));
1946 EXPECT_EQ(2u, GetSelectionSize(omnibox_view)); 2000 EXPECT_EQ(2u, GetSelectionSize(omnibox_view));
1947 2001
1948 // And Left should reduce by one character. 2002 // And Left should reduce by one character.
1949 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, ui::EF_SHIFT_DOWN)); 2003 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, ui::EF_SHIFT_DOWN));
1950 EXPECT_EQ(1u, GetSelectionSize(omnibox_view)); 2004 EXPECT_EQ(1u, GetSelectionSize(omnibox_view));
1951 } 2005 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698