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 <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 18 matching lines...) Expand all Loading... |
29 #include "chrome/common/chrome_notification_types.h" | 29 #include "chrome/common/chrome_notification_types.h" |
30 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
31 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
32 #include "chrome/test/base/in_process_browser_test.h" | 32 #include "chrome/test/base/in_process_browser_test.h" |
33 #include "chrome/test/base/ui_test_utils.h" | 33 #include "chrome/test/base/ui_test_utils.h" |
34 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
35 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
36 #include "net/base/mock_host_resolver.h" | 36 #include "net/base/mock_host_resolver.h" |
37 #include "ui/base/events.h" | 37 #include "ui/base/events.h" |
38 #include "ui/base/keycodes/keyboard_codes.h" | 38 #include "ui/base/keycodes/keyboard_codes.h" |
| 39 #include "ui/gfx/point.h" |
39 | 40 |
40 #if defined(TOOLKIT_GTK) | 41 #if defined(TOOLKIT_GTK) |
41 #include <gdk/gdk.h> | 42 #include <gdk/gdk.h> |
42 #include <gtk/gtk.h> | 43 #include <gtk/gtk.h> |
43 #endif | 44 #endif |
44 | 45 |
45 #if defined(TOOLKIT_VIEWS) | 46 #if defined(USE_AURA) |
46 #include "ui/views/controls/textfield/native_textfield_views.h" | 47 #include "chrome/browser/ui/views/frame/browser_view.h" |
47 #include "ui/views/events/event.h" | |
48 #include "ui/views/widget/widget.h" | |
49 #endif | 48 #endif |
50 | 49 |
51 using base::Time; | 50 using base::Time; |
52 using base::TimeDelta; | 51 using base::TimeDelta; |
53 | 52 |
54 namespace { | 53 namespace { |
55 | 54 |
56 const char kSearchKeyword[] = "foo"; | 55 const char kSearchKeyword[] = "foo"; |
57 const char kSearchKeyword2[] = "footest.com"; | 56 const char kSearchKeyword2[] = "footest.com"; |
58 const wchar_t kSearchKeywordKeys[] = { | 57 const wchar_t kSearchKeywordKeys[] = { |
(...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1263 // Make sure inline autocomplete is triggerred. | 1262 // Make sure inline autocomplete is triggerred. |
1264 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1); | 1263 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1); |
1265 | 1264 |
1266 // Press ctrl key. | 1265 // Press ctrl key. |
1267 omnibox_view->model()->OnControlKeyChanged(true); | 1266 omnibox_view->model()->OnControlKeyChanged(true); |
1268 | 1267 |
1269 // Inline autocomplete should still be there. | 1268 // Inline autocomplete should still be there. |
1270 EXPECT_EQ(old_text, omnibox_view->GetText()); | 1269 EXPECT_EQ(old_text, omnibox_view->GetText()); |
1271 } | 1270 } |
1272 | 1271 |
| 1272 #if defined(USE_AURA) |
| 1273 const BrowserView* GetBrowserView() const { |
| 1274 return static_cast<BrowserView*>(browser()->window()); |
| 1275 } |
| 1276 |
| 1277 const views::View* GetFocusView() const { |
| 1278 return GetBrowserView()->GetViewByID(location_bar_focus_view_id_); |
| 1279 } |
| 1280 |
| 1281 // Move the mouse to the center of the browser window and left-click. |
| 1282 void ClickBrowserWindowCenter() { |
| 1283 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync( |
| 1284 GetBrowserView()->GetScreenBounds().CenterPoint())); |
| 1285 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( |
| 1286 ui_controls::LEFT, ui_controls::DOWN)); |
| 1287 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( |
| 1288 ui_controls::LEFT, ui_controls::UP)); |
| 1289 } |
| 1290 |
| 1291 // Press and release the mouse in the focus view at an offset from its origin. |
| 1292 // If |release_offset| differs from |press_offset|, the mouse will be moved |
| 1293 // between the press and release. |
| 1294 void ClickFocusViewOrigin(ui_controls::MouseButton button, |
| 1295 const gfx::Point& press_offset, |
| 1296 const gfx::Point& release_offset) { |
| 1297 gfx::Point focus_view_origin = GetFocusView()->GetScreenBounds().origin(); |
| 1298 gfx::Point press_point = focus_view_origin; |
| 1299 press_point.Offset(press_offset.x(), press_offset.y()); |
| 1300 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(press_point)); |
| 1301 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::DOWN)); |
| 1302 |
| 1303 gfx::Point release_point = focus_view_origin; |
| 1304 release_point.Offset(release_offset.x(), release_offset.y()); |
| 1305 if (release_point != press_point) |
| 1306 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(release_point)); |
| 1307 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::UP)); |
| 1308 } |
| 1309 #endif // defined(USE_AURA) |
| 1310 |
1273 private: | 1311 private: |
1274 ViewID location_bar_focus_view_id_; | 1312 ViewID location_bar_focus_view_id_; |
1275 }; | 1313 }; |
1276 | 1314 |
1277 // Test if ctrl-* accelerators are workable in omnibox. | 1315 // Test if ctrl-* accelerators are workable in omnibox. |
1278 // See http://crbug.com/19193: omnibox blocks ctrl-* commands | 1316 // See http://crbug.com/19193: omnibox blocks ctrl-* commands |
1279 // | 1317 // |
1280 // Flaky on interactive tests (dbg), http://crbug.com/69433 | 1318 // Flaky on interactive tests (dbg), http://crbug.com/69433 |
1281 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DISABLED_BrowserAccelerators) { | 1319 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DISABLED_BrowserAccelerators) { |
1282 BrowserAcceleratorsTest(); | 1320 BrowserAcceleratorsTest(); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1474 SetClipboardText(kSearchText); | 1512 SetClipboardText(kSearchText); |
1475 | 1513 |
1476 // Paste text. | 1514 // Paste text. |
1477 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN)); | 1515 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN)); |
1478 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | 1516 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
1479 ASSERT_TRUE(popup_model->IsOpen()); | 1517 ASSERT_TRUE(popup_model->IsOpen()); |
1480 | 1518 |
1481 // Inline autocomplete shouldn't be triggered. | 1519 // Inline autocomplete shouldn't be triggered. |
1482 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText()); | 1520 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText()); |
1483 } | 1521 } |
1484 #endif | 1522 #endif // defined(TOOLKIT_GTK) |
| 1523 |
| 1524 // TODO(derat): Enable on Windows: http://crbug.com/128556 |
| 1525 #if defined(USE_AURA) |
| 1526 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, SelectAllOnClick) { |
| 1527 OmniboxView* omnibox_view = NULL; |
| 1528 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); |
| 1529 omnibox_view->SetUserText(ASCIIToUTF16("http://www.google.com/")); |
| 1530 const gfx::Point kClickOffset(2, 2); |
| 1531 |
| 1532 // Take the focus away from the omnibox. |
| 1533 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); |
| 1534 EXPECT_FALSE(omnibox_view->IsSelectAll()); |
| 1535 EXPECT_FALSE(GetFocusView()->HasFocus()); |
| 1536 |
| 1537 // Click in the omnibox. All of its text should be selected. |
| 1538 ASSERT_NO_FATAL_FAILURE( |
| 1539 ClickFocusViewOrigin(ui_controls::LEFT, kClickOffset, kClickOffset)); |
| 1540 EXPECT_TRUE(omnibox_view->IsSelectAll()); |
| 1541 EXPECT_TRUE(GetFocusView()->HasFocus()); |
| 1542 |
| 1543 // Ensure that all of the text is selected and then take the focus away. The |
| 1544 // selection should persist. |
| 1545 omnibox_view->SelectAll(false); |
| 1546 EXPECT_TRUE(omnibox_view->IsSelectAll()); |
| 1547 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); |
| 1548 EXPECT_TRUE(omnibox_view->IsSelectAll()); |
| 1549 EXPECT_FALSE(GetFocusView()->HasFocus()); |
| 1550 |
| 1551 // Clicking in the omnibox while some of its text is already selected should |
| 1552 // have the effect of re-selecting the text. |
| 1553 ASSERT_NO_FATAL_FAILURE( |
| 1554 ClickFocusViewOrigin(ui_controls::LEFT, kClickOffset, kClickOffset)); |
| 1555 EXPECT_TRUE(omnibox_view->IsSelectAll()); |
| 1556 EXPECT_TRUE(GetFocusView()->HasFocus()); |
| 1557 |
| 1558 // Click in a different spot in the omnibox. It should keep the focus but |
| 1559 // lose the selection. |
| 1560 omnibox_view->SelectAll(false); |
| 1561 const gfx::Point kSecondClickOffset(kClickOffset.x() + 10, kClickOffset.y()); |
| 1562 ASSERT_NO_FATAL_FAILURE( |
| 1563 ClickFocusViewOrigin( |
| 1564 ui_controls::LEFT, kSecondClickOffset, kSecondClickOffset)); |
| 1565 EXPECT_FALSE(omnibox_view->IsSelectAll()); |
| 1566 EXPECT_TRUE(GetFocusView()->HasFocus()); |
| 1567 |
| 1568 // Take the focus away and click in the omnibox again, but drag a bit before |
| 1569 // releasing. We should focus the omnibox but not select all of its text. |
| 1570 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); |
| 1571 const gfx::Point kReleaseOffset(kClickOffset.x() + 10, kClickOffset.y()); |
| 1572 ASSERT_NO_FATAL_FAILURE( |
| 1573 ClickFocusViewOrigin(ui_controls::LEFT, kClickOffset, kReleaseOffset)); |
| 1574 EXPECT_FALSE(omnibox_view->IsSelectAll()); |
| 1575 EXPECT_TRUE(GetFocusView()->HasFocus()); |
| 1576 |
| 1577 // Middle-clicking shouldn't select all the text either. |
| 1578 ASSERT_NO_FATAL_FAILURE( |
| 1579 ClickFocusViewOrigin(ui_controls::LEFT, kClickOffset, kClickOffset)); |
| 1580 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); |
| 1581 ASSERT_NO_FATAL_FAILURE( |
| 1582 ClickFocusViewOrigin(ui_controls::MIDDLE, kClickOffset, kClickOffset)); |
| 1583 EXPECT_FALSE(omnibox_view->IsSelectAll()); |
| 1584 } |
| 1585 #endif // defined(USE_AURA) |
OLD | NEW |