| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |