| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <stdio.h> | 5 #include <stdio.h> |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 const int kCtrlOrCmdMask = ui::EF_COMMAND_DOWN; | 142 const int kCtrlOrCmdMask = ui::EF_COMMAND_DOWN; |
| 143 #else | 143 #else |
| 144 const int kCtrlOrCmdMask = ui::EF_CONTROL_DOWN; | 144 const int kCtrlOrCmdMask = ui::EF_CONTROL_DOWN; |
| 145 #endif | 145 #endif |
| 146 | 146 |
| 147 } // namespace | 147 } // namespace |
| 148 | 148 |
| 149 class OmniboxViewTest : public InProcessBrowserTest, | 149 class OmniboxViewTest : public InProcessBrowserTest, |
| 150 public content::NotificationObserver { | 150 public content::NotificationObserver { |
| 151 protected: | 151 protected: |
| 152 OmniboxViewTest() { | 152 OmniboxViewTest() |
| 153 : location_bar_focus_view_id_(VIEW_ID_LOCATION_BAR) { |
| 153 set_show_window(true); | 154 set_show_window(true); |
| 154 // TODO(mrossetti): HQP does not yet support DeleteMatch. | 155 // TODO(mrossetti): HQP does not yet support DeleteMatch. |
| 155 // http://crbug.com/82335 | 156 // http://crbug.com/82335 |
| 156 HistoryQuickProvider::set_disabled(true); | 157 HistoryQuickProvider::set_disabled(true); |
| 157 } | 158 } |
| 158 | 159 |
| 159 virtual void SetUpOnMainThread() { | 160 virtual void SetUpOnMainThread() { |
| 160 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 161 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 161 ASSERT_NO_FATAL_FAILURE(SetupComponents()); | 162 ASSERT_NO_FATAL_FAILURE(SetupComponents()); |
| 162 browser()->FocusLocationBar(); | 163 browser()->FocusLocationBar(); |
| 164 // Use Textfield's view id on pure views. See crbug.com/71144. |
| 163 #if defined(TOOLKIT_VIEWS) | 165 #if defined(TOOLKIT_VIEWS) |
| 164 if (views::Widget::IsPureViews()) | 166 if (views::Widget::IsPureViews()) |
| 165 return; | 167 location_bar_focus_view_id_ = VIEW_ID_OMNIBOX; |
| 166 #endif | 168 #endif |
| 167 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), | 169 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 168 VIEW_ID_LOCATION_BAR)); | 170 location_bar_focus_view_id_)); |
| 169 } | 171 } |
| 170 | 172 |
| 171 static void GetOmniboxViewForBrowser( | 173 static void GetOmniboxViewForBrowser( |
| 172 const Browser* browser, | 174 const Browser* browser, |
| 173 OmniboxView** omnibox_view) { | 175 OmniboxView** omnibox_view) { |
| 174 BrowserWindow* window = browser->window(); | 176 BrowserWindow* window = browser->window(); |
| 175 ASSERT_TRUE(window); | 177 ASSERT_TRUE(window); |
| 176 LocationBar* loc_bar = window->GetLocationBar(); | 178 LocationBar* loc_bar = window->GetLocationBar(); |
| 177 ASSERT_TRUE(loc_bar); | 179 ASSERT_TRUE(loc_bar); |
| 178 *omnibox_view = loc_bar->location_entry(); | 180 *omnibox_view = loc_bar->location_entry(); |
| (...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 EXPECT_EQ(0U, end); | 1033 EXPECT_EQ(0U, end); |
| 1032 | 1034 |
| 1033 // Pressing tab should move cursor to the end. | 1035 // Pressing tab should move cursor to the end. |
| 1034 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); | 1036 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); |
| 1035 | 1037 |
| 1036 omnibox_view->GetSelectionBounds(&start, &end); | 1038 omnibox_view->GetSelectionBounds(&start, &end); |
| 1037 EXPECT_EQ(omnibox_view->GetText().size(), start); | 1039 EXPECT_EQ(omnibox_view->GetText().size(), start); |
| 1038 EXPECT_EQ(omnibox_view->GetText().size(), end); | 1040 EXPECT_EQ(omnibox_view->GetText().size(), end); |
| 1039 | 1041 |
| 1040 // The location bar should still have focus. | 1042 // The location bar should still have focus. |
| 1041 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR)); | 1043 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 1044 location_bar_focus_view_id_)); |
| 1042 | 1045 |
| 1043 // Select all text. | 1046 // Select all text. |
| 1044 omnibox_view->SelectAll(true); | 1047 omnibox_view->SelectAll(true); |
| 1045 EXPECT_TRUE(omnibox_view->IsSelectAll()); | 1048 EXPECT_TRUE(omnibox_view->IsSelectAll()); |
| 1046 omnibox_view->GetSelectionBounds(&start, &end); | 1049 omnibox_view->GetSelectionBounds(&start, &end); |
| 1047 EXPECT_EQ(0U, start); | 1050 EXPECT_EQ(0U, start); |
| 1048 EXPECT_EQ(omnibox_view->GetText().size(), end); | 1051 EXPECT_EQ(omnibox_view->GetText().size(), end); |
| 1049 | 1052 |
| 1050 // Pressing tab should move cursor to the end. | 1053 // Pressing tab should move cursor to the end. |
| 1051 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); | 1054 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); |
| 1052 | 1055 |
| 1053 omnibox_view->GetSelectionBounds(&start, &end); | 1056 omnibox_view->GetSelectionBounds(&start, &end); |
| 1054 EXPECT_EQ(omnibox_view->GetText().size(), start); | 1057 EXPECT_EQ(omnibox_view->GetText().size(), start); |
| 1055 EXPECT_EQ(omnibox_view->GetText().size(), end); | 1058 EXPECT_EQ(omnibox_view->GetText().size(), end); |
| 1056 | 1059 |
| 1057 // The location bar should still have focus. | 1060 // The location bar should still have focus. |
| 1058 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR)); | 1061 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 1062 location_bar_focus_view_id_)); |
| 1059 | 1063 |
| 1060 // Pressing tab when cursor is at the end should change focus. | 1064 // Pressing tab when cursor is at the end should change focus. |
| 1061 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); | 1065 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); |
| 1062 | 1066 |
| 1063 ASSERT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR)); | 1067 ASSERT_FALSE(ui_test_utils::IsViewFocused(browser(), |
| 1068 location_bar_focus_view_id_)); |
| 1064 } | 1069 } |
| 1065 | 1070 |
| 1066 void PersistKeywordModeOnTabSwitch() { | 1071 void PersistKeywordModeOnTabSwitch() { |
| 1067 OmniboxView* omnibox_view = NULL; | 1072 OmniboxView* omnibox_view = NULL; |
| 1068 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | 1073 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); |
| 1069 | 1074 |
| 1070 // Trigger keyword hint mode. | 1075 // Trigger keyword hint mode. |
| 1071 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); | 1076 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); |
| 1072 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); | 1077 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); |
| 1073 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword())); | 1078 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword())); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1106 // Make sure inline autocomplete is triggerred. | 1111 // Make sure inline autocomplete is triggerred. |
| 1107 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1); | 1112 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1); |
| 1108 | 1113 |
| 1109 // Press ctrl key. | 1114 // Press ctrl key. |
| 1110 omnibox_view->model()->OnControlKeyChanged(true); | 1115 omnibox_view->model()->OnControlKeyChanged(true); |
| 1111 | 1116 |
| 1112 // Inline autocomplete should still be there. | 1117 // Inline autocomplete should still be there. |
| 1113 EXPECT_EQ(old_text, omnibox_view->GetText()); | 1118 EXPECT_EQ(old_text, omnibox_view->GetText()); |
| 1114 } | 1119 } |
| 1115 | 1120 |
| 1121 private: |
| 1122 ViewID location_bar_focus_view_id_; |
| 1116 }; | 1123 }; |
| 1117 | 1124 |
| 1118 // Test if ctrl-* accelerators are workable in omnibox. | 1125 // Test if ctrl-* accelerators are workable in omnibox. |
| 1119 // See http://crbug.com/19193: omnibox blocks ctrl-* commands | 1126 // See http://crbug.com/19193: omnibox blocks ctrl-* commands |
| 1120 // | 1127 // |
| 1121 // Flaky on interactive tests (dbg), http://crbug.com/69433 | 1128 // Flaky on interactive tests (dbg), http://crbug.com/69433 |
| 1122 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, FLAKY_BrowserAccelerators) { | 1129 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, FLAKY_BrowserAccelerators) { |
| 1123 BrowserAcceleratorsTest(); | 1130 BrowserAcceleratorsTest(); |
| 1124 } | 1131 } |
| 1125 | 1132 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1322 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN)); | 1329 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN)); |
| 1323 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | 1330 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
| 1324 ASSERT_TRUE(popup_model->IsOpen()); | 1331 ASSERT_TRUE(popup_model->IsOpen()); |
| 1325 | 1332 |
| 1326 // Inline autocomplete shouldn't be triggered. | 1333 // Inline autocomplete shouldn't be triggered. |
| 1327 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText()); | 1334 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText()); |
| 1328 } | 1335 } |
| 1329 #endif | 1336 #endif |
| 1330 | 1337 |
| 1331 // TODO(beng): enable on windows once it actually works. | 1338 // TODO(beng): enable on windows once it actually works. |
| 1332 #if defined(TOOLKIT_VIEWS) && !defined(OS_WIN) | 1339 // No need to run extra pure views tests on aura. |
| 1340 #if defined(TOOLKIT_VIEWS) && !defined(OS_WIN) && !defined(USE_AURA) |
| 1333 class OmniboxViewViewsTest : public OmniboxViewTest { | 1341 class OmniboxViewViewsTest : public OmniboxViewTest { |
| 1334 public: | 1342 public: |
| 1335 OmniboxViewViewsTest() { | 1343 OmniboxViewViewsTest() { |
| 1336 views::Widget::SetPureViews(true); | 1344 views::Widget::SetPureViews(true); |
| 1337 } | 1345 } |
| 1338 }; | 1346 }; |
| 1339 | 1347 |
| 1340 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, | 1348 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, |
| 1341 FLAKY_BrowserAccelerators) { | 1349 FLAKY_BrowserAccelerators) { |
| 1342 BrowserAcceleratorsTest(); | 1350 BrowserAcceleratorsTest(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1380 | 1388 |
| 1381 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, | 1389 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, |
| 1382 NonSubstitutingKeywordTest) { | 1390 NonSubstitutingKeywordTest) { |
| 1383 NonSubstitutingKeywordTest(); | 1391 NonSubstitutingKeywordTest(); |
| 1384 } | 1392 } |
| 1385 | 1393 |
| 1386 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, DeleteItem) { | 1394 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, DeleteItem) { |
| 1387 DeleteItemTest(); | 1395 DeleteItemTest(); |
| 1388 } | 1396 } |
| 1389 | 1397 |
| 1390 // TODO(suzhe): This test is broken because of broken ViewID support when | 1398 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, TabMoveCursorToEnd) { |
| 1391 // enabling OmniboxViewViews. | |
| 1392 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, | |
| 1393 DISABLED_TabMoveCursorToEnd) { | |
| 1394 TabMoveCursorToEndTest(); | 1399 TabMoveCursorToEndTest(); |
| 1395 } | 1400 } |
| 1396 | 1401 |
| 1397 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, | 1402 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, |
| 1398 PersistKeywordModeOnTabSwitch) { | 1403 PersistKeywordModeOnTabSwitch) { |
| 1399 PersistKeywordModeOnTabSwitch(); | 1404 PersistKeywordModeOnTabSwitch(); |
| 1400 } | 1405 } |
| 1401 | 1406 |
| 1402 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, | 1407 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, |
| 1403 CtrlKeyPressedWithInlineAutocompleteTest) { | 1408 CtrlKeyPressedWithInlineAutocompleteTest) { |
| 1404 CtrlKeyPressedWithInlineAutocompleteTest(); | 1409 CtrlKeyPressedWithInlineAutocompleteTest(); |
| 1405 } | 1410 } |
| 1406 | 1411 |
| 1407 #endif | 1412 #endif |
| OLD | NEW |