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 BrowserView* GetBrowserView() { | |
oshima
2012/05/17 00:18:18
can this be const const?
Daniel Erat
2012/05/17 00:28:53
Done.
| |
1274 return static_cast<BrowserView*>(browser()->window()); | |
1275 } | |
1276 | |
1277 views::View* GetFocusView() { | |
oshima
2012/05/17 00:18:18
ditto
Daniel Erat
2012/05/17 00:28:53
Done.
| |
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 #if defined(USE_AURA) | |
1525 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, SelectAllOnClick) { | |
1526 OmniboxView* omnibox_view = NULL; | |
1527 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | |
1528 omnibox_view->SetUserText(ASCIIToUTF16("http://www.google.com/")); | |
1529 const gfx::Point kClickOffset(2, 2); | |
1530 | |
1531 // Take the focus away from the omnibox. | |
1532 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); | |
1533 EXPECT_FALSE(omnibox_view->IsSelectAll()); | |
1534 EXPECT_FALSE(GetFocusView()->HasFocus()); | |
1535 | |
1536 // Click in the omnibox. All of its text should be selected. | |
1537 ASSERT_NO_FATAL_FAILURE( | |
1538 ClickFocusViewOrigin(ui_controls::LEFT, kClickOffset, kClickOffset)); | |
1539 EXPECT_TRUE(omnibox_view->IsSelectAll()); | |
1540 EXPECT_TRUE(GetFocusView()->HasFocus()); | |
1541 | |
1542 // Ensure that all of the text is selected and then take the focus away. The | |
1543 // selection should persist. | |
1544 omnibox_view->SelectAll(false); | |
1545 EXPECT_TRUE(omnibox_view->IsSelectAll()); | |
1546 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); | |
1547 EXPECT_TRUE(omnibox_view->IsSelectAll()); | |
1548 EXPECT_FALSE(GetFocusView()->HasFocus()); | |
1549 | |
1550 // Clicking in the omnibox while some of its text is already selected should | |
1551 // have the effect of re-selecting the text. | |
1552 ASSERT_NO_FATAL_FAILURE( | |
1553 ClickFocusViewOrigin(ui_controls::LEFT, kClickOffset, kClickOffset)); | |
1554 EXPECT_TRUE(omnibox_view->IsSelectAll()); | |
1555 EXPECT_TRUE(GetFocusView()->HasFocus()); | |
1556 | |
1557 // Click in a different spot in the omnibox. It should keep the focus but | |
1558 // lose the selection. | |
1559 omnibox_view->SelectAll(false); | |
1560 const gfx::Point kSecondClickOffset(kClickOffset.x() + 10, kClickOffset.y()); | |
1561 ASSERT_NO_FATAL_FAILURE( | |
1562 ClickFocusViewOrigin( | |
1563 ui_controls::LEFT, kSecondClickOffset, kSecondClickOffset)); | |
1564 EXPECT_FALSE(omnibox_view->IsSelectAll()); | |
1565 EXPECT_TRUE(GetFocusView()->HasFocus()); | |
1566 | |
1567 // Take the focus away and click in the omnibox again, but drag a bit before | |
1568 // releasing. We should focus the omnibox but not select all of its text. | |
1569 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); | |
1570 const gfx::Point kReleaseOffset(kClickOffset.x() + 10, kClickOffset.y()); | |
1571 ASSERT_NO_FATAL_FAILURE( | |
1572 ClickFocusViewOrigin(ui_controls::LEFT, kClickOffset, kReleaseOffset)); | |
1573 EXPECT_FALSE(omnibox_view->IsSelectAll()); | |
1574 EXPECT_TRUE(GetFocusView()->HasFocus()); | |
1575 | |
1576 // Middle-clicking shouldn't select all the text either. | |
1577 ASSERT_NO_FATAL_FAILURE( | |
1578 ClickFocusViewOrigin(ui_controls::LEFT, kClickOffset, kClickOffset)); | |
1579 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); | |
1580 ASSERT_NO_FATAL_FAILURE( | |
1581 ClickFocusViewOrigin(ui_controls::MIDDLE, kClickOffset, kClickOffset)); | |
1582 EXPECT_FALSE(omnibox_view->IsSelectAll()); | |
1583 } | |
1584 #endif // defined(USE_AURA) | |
OLD | NEW |