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

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc

Issue 23494016: views: Move views specific portions out of omnibox_view_browsertest.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rm unnecessary NotificationObserver Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_view_browsertest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chrome/browser/ui/views/omnibox/omnibox_view_views.h" 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
6 6
7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/command_updater.h"
9 #include "chrome/browser/ui/browser.h" 7 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_commands.h" 8 #include "chrome/browser/ui/browser_commands.h"
11 #include "chrome/browser/ui/browser_window.h" 9 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/browser/ui/omnibox/location_bar.h" 10 #include "chrome/browser/ui/omnibox/location_bar.h"
13 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" 11 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
14 #include "chrome/browser/ui/view_ids.h" 12 #include "chrome/browser/ui/view_ids.h"
13 #include "chrome/browser/ui/views/frame/browser_view.h"
15 #include "chrome/browser/ui/views/omnibox/omnibox_views.h" 14 #include "chrome/browser/ui/views/omnibox/omnibox_views.h"
16 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/interactive_test_utils.h" 16 #include "chrome/test/base/interactive_test_utils.h"
18 #include "chrome/test/base/ui_test_utils.h"
19 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
20 #include "ui/base/clipboard/clipboard.h" 18 #include "ui/base/clipboard/clipboard.h"
21 #include "ui/base/clipboard/scoped_clipboard_writer.h" 19 #include "ui/base/clipboard/scoped_clipboard_writer.h"
20 #include "ui/base/test/ui_controls.h"
22 #include "ui/views/controls/textfield/native_textfield_wrapper.h" 21 #include "ui/views/controls/textfield/native_textfield_wrapper.h"
23 22
24 typedef InProcessBrowserTest OmniboxViewViewsTest; 23 class OmniboxViewViewsTest : public InProcessBrowserTest {
24 protected:
25 static void GetOmniboxViewForBrowser(const Browser* browser,
26 OmniboxView** omnibox_view) {
27 BrowserWindow* window = browser->window();
28 ASSERT_TRUE(window);
29 LocationBar* location_bar = window->GetLocationBar();
30 ASSERT_TRUE(location_bar);
31 *omnibox_view = location_bar->GetLocationEntry();
32 ASSERT_TRUE(*omnibox_view);
33 }
34
35 // InProcessBrowserTest:
36 virtual void SetUpOnMainThread() OVERRIDE {
37 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
38 chrome::FocusLocationBar(browser());
39 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
40 }
41
42 void GetOmniboxView(OmniboxView** omnibox_view) {
Peter Kasting 2013/09/04 00:02:23 Nit: Since this is only called once, I'd just inli
tfarina 2013/09/04 01:00:54 Done.
43 GetOmniboxViewForBrowser(browser(), omnibox_view);
44 }
45
46 const BrowserView* GetBrowserView() const {
Peter Kasting 2013/09/04 00:02:23 Inlining this is also possible, but more arguable;
tfarina 2013/09/04 01:00:54 Done.
47 return BrowserView::GetBrowserViewForBrowser(browser());
48 }
49
50 // Move the mouse to the center of the browser window and left-click.
51 void ClickBrowserWindowCenter() {
52 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
53 GetBrowserView()->GetBoundsInScreen().CenterPoint()));
54 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(ui_controls::LEFT,
55 ui_controls::DOWN));
56 ASSERT_TRUE(
57 ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, ui_controls::UP));
58 }
59
60 // Press and release the mouse in the omnibox at an offset from its origin.
61 // If |release_offset| differs from |press_offset|, the mouse will be moved
62 // between the press and release.
63 void ClickOmnibox(ui_controls::MouseButton button,
64 const gfx::Vector2d& press_offset,
65 const gfx::Vector2d& release_offset) {
66 const views::View* omnibox = GetBrowserView()->GetViewByID(VIEW_ID_OMNIBOX);
67 gfx::Point omnibox_origin = omnibox->GetBoundsInScreen().origin();
68 gfx::Point press_point = omnibox_origin + press_offset;
69 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(press_point));
70 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::DOWN));
71
72 gfx::Point release_point = omnibox_origin + release_offset;
73 if (release_point != press_point)
74 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(release_point));
75 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::UP));
76 }
77 };
25 78
26 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, PasteAndGoDoesNotLeavePopupOpen) { 79 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, PasteAndGoDoesNotLeavePopupOpen) {
27 OmniboxView* view = browser()->window()->GetLocationBar()->GetLocationEntry(); 80 OmniboxView* view = browser()->window()->GetLocationBar()->GetLocationEntry();
28 OmniboxViewViews* omnibox_view_views = GetOmniboxViewViews(view); 81 OmniboxViewViews* omnibox_view_views = GetOmniboxViewViews(view);
29 // This test is only relevant when OmniboxViewViews is present and is using 82 // This test is only relevant when OmniboxViewViews is present and is using
30 // the native textfield wrapper. 83 // the native textfield wrapper.
31 if (!omnibox_view_views) 84 if (!omnibox_view_views)
32 return; 85 return;
33 views::NativeTextfieldWrapper* native_textfield_wrapper = 86 views::NativeTextfieldWrapper* native_textfield_wrapper =
34 static_cast<views::NativeTextfieldWrapper*>( 87 static_cast<views::NativeTextfieldWrapper*>(
35 omnibox_view_views->GetNativeWrapperForTesting()); 88 omnibox_view_views->GetNativeWrapperForTesting());
36 if (!native_textfield_wrapper) 89 if (!native_textfield_wrapper)
37 return; 90 return;
38 91
39 // Put an URL on the clipboard. 92 // Put an URL on the clipboard.
40 { 93 {
41 ui::ScopedClipboardWriter clipboard_writer( 94 ui::ScopedClipboardWriter clipboard_writer(
42 ui::Clipboard::GetForCurrentThread(), ui::Clipboard::BUFFER_STANDARD); 95 ui::Clipboard::GetForCurrentThread(), ui::Clipboard::BUFFER_STANDARD);
43 clipboard_writer.WriteURL(ASCIIToUTF16("http://www.example.com/")); 96 clipboard_writer.WriteURL(ASCIIToUTF16("http://www.example.com/"));
44 } 97 }
45 98
46 // Paste and go. 99 // Paste and go.
47 native_textfield_wrapper->ExecuteTextCommand(IDS_PASTE_AND_GO); 100 native_textfield_wrapper->ExecuteTextCommand(IDS_PASTE_AND_GO);
48 101
49 // The popup should not be open. 102 // The popup should not be open.
50 EXPECT_FALSE(view->model()->popup_model()->IsOpen()); 103 EXPECT_FALSE(view->model()->popup_model()->IsOpen());
51 } 104 }
105
106 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, SelectAllOnClick) {
107 OmniboxView* omnibox_view = NULL;
108 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
109 omnibox_view->SetUserText(ASCIIToUTF16("http://www.google.com/"));
110 const gfx::Vector2d click(40, 10);
111
112 // Take the focus away from the omnibox.
113 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter());
114 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
115 EXPECT_FALSE(omnibox_view->IsSelectAll());
116
117 // Clicking in the omnibox should take focus and select all text.
118 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click, click));
119 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
120 EXPECT_TRUE(omnibox_view->IsSelectAll());
121
122 // Clicking in another view should clear focus and the selection.
123 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter());
124 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
125 EXPECT_FALSE(omnibox_view->IsSelectAll());
126
127 // Clicking in the omnibox again should take focus and select all text again.
128 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click, click));
129 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
130 EXPECT_TRUE(omnibox_view->IsSelectAll());
131
132 // Clicking another omnibox spot should keep focus but clear the selection.
133 omnibox_view->SelectAll(false);
134 const gfx::Vector2d click_2(click.x() + 10, click.y());
135 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click_2, click_2));
136 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
137 EXPECT_FALSE(omnibox_view->IsSelectAll());
138
139 // Take the focus away and click in the omnibox again, but drag a bit before
140 // releasing. We should focus the omnibox but not select all of its text.
141 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter());
142 const gfx::Vector2d release(click.x() + 10, click.y());
143 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click, release));
144 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
145 EXPECT_FALSE(omnibox_view->IsSelectAll());
146
147 // Middle-clicking should not be handled by the omnibox.
148 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter());
149 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::MIDDLE, click, click));
150 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
151 EXPECT_FALSE(omnibox_view->IsSelectAll());
152 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_view_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698