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

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: 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 public content::NotificationObserver {
25 protected:
26 static void GetOmniboxViewForBrowser(const Browser* browser,
27 OmniboxView** omnibox_view) {
28 BrowserWindow* window = browser->window();
29 ASSERT_TRUE(window);
30 LocationBar* location_bar = window->GetLocationBar();
31 ASSERT_TRUE(location_bar);
32 *omnibox_view = location_bar->GetLocationEntry();
33 ASSERT_TRUE(*omnibox_view);
34 }
35
36 // InProcessBrowserTest:
37 virtual void SetUpOnMainThread() OVERRIDE {
38 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
39 chrome::FocusLocationBar(browser());
40 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
41 }
42
43 // content::NotificationObserver:
Peter Kasting 2013/09/03 21:10:26 Why is this necessary?
tfarina 2013/09/03 22:16:22 I was sure you were going to notice. Yes, it was
44 virtual void Observe(int type,
45 const content::NotificationSource& source,
46 const content::NotificationDetails& details) OVERRIDE {
47 base::MessageLoop::current()->Quit();
48 }
49
50 void GetOmniboxView(OmniboxView** omnibox_view) {
51 GetOmniboxViewForBrowser(browser(), omnibox_view);
52 }
53
54 const BrowserView* GetBrowserView() const {
55 return BrowserView::GetBrowserViewForBrowser(browser());
56 }
57
58 // Move the mouse to the center of the browser window and left-click.
59 void ClickBrowserWindowCenter() {
60 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
61 GetBrowserView()->GetBoundsInScreen().CenterPoint()));
62 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(ui_controls::LEFT,
63 ui_controls::DOWN));
64 ASSERT_TRUE(
65 ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, ui_controls::UP));
66 }
67
68 // Press and release the mouse in the omnibox at an offset from its origin.
69 // If |release_offset| differs from |press_offset|, the mouse will be moved
70 // between the press and release.
71 void ClickOmnibox(ui_controls::MouseButton button,
72 const gfx::Vector2d& press_offset,
73 const gfx::Vector2d& release_offset) {
74 const views::View* omnibox = GetBrowserView()->GetViewByID(VIEW_ID_OMNIBOX);
75 gfx::Point omnibox_origin = omnibox->GetBoundsInScreen().origin();
76 gfx::Point press_point = omnibox_origin + press_offset;
77 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(press_point));
78 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::DOWN));
79
80 gfx::Point release_point = omnibox_origin + release_offset;
81 if (release_point != press_point)
82 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(release_point));
83 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::UP));
84 }
85 };
25 86
26 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, PasteAndGoDoesNotLeavePopupOpen) { 87 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, PasteAndGoDoesNotLeavePopupOpen) {
27 OmniboxView* view = browser()->window()->GetLocationBar()->GetLocationEntry(); 88 OmniboxView* view = browser()->window()->GetLocationBar()->GetLocationEntry();
28 OmniboxViewViews* omnibox_view_views = GetOmniboxViewViews(view); 89 OmniboxViewViews* omnibox_view_views = GetOmniboxViewViews(view);
29 // This test is only relevant when OmniboxViewViews is present and is using 90 // This test is only relevant when OmniboxViewViews is present and is using
30 // the native textfield wrapper. 91 // the native textfield wrapper.
31 if (!omnibox_view_views) 92 if (!omnibox_view_views)
32 return; 93 return;
33 views::NativeTextfieldWrapper* native_textfield_wrapper = 94 views::NativeTextfieldWrapper* native_textfield_wrapper =
34 static_cast<views::NativeTextfieldWrapper*>( 95 static_cast<views::NativeTextfieldWrapper*>(
35 omnibox_view_views->GetNativeWrapperForTesting()); 96 omnibox_view_views->GetNativeWrapperForTesting());
36 if (!native_textfield_wrapper) 97 if (!native_textfield_wrapper)
37 return; 98 return;
38 99
39 // Put an URL on the clipboard. 100 // Put an URL on the clipboard.
40 { 101 {
41 ui::ScopedClipboardWriter clipboard_writer( 102 ui::ScopedClipboardWriter clipboard_writer(
42 ui::Clipboard::GetForCurrentThread(), ui::Clipboard::BUFFER_STANDARD); 103 ui::Clipboard::GetForCurrentThread(), ui::Clipboard::BUFFER_STANDARD);
43 clipboard_writer.WriteURL(ASCIIToUTF16("http://www.example.com/")); 104 clipboard_writer.WriteURL(ASCIIToUTF16("http://www.example.com/"));
44 } 105 }
45 106
46 // Paste and go. 107 // Paste and go.
47 native_textfield_wrapper->ExecuteTextCommand(IDS_PASTE_AND_GO); 108 native_textfield_wrapper->ExecuteTextCommand(IDS_PASTE_AND_GO);
48 109
49 // The popup should not be open. 110 // The popup should not be open.
50 EXPECT_FALSE(view->model()->popup_model()->IsOpen()); 111 EXPECT_FALSE(view->model()->popup_model()->IsOpen());
51 } 112 }
113
114 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, SelectAllOnClick) {
115 OmniboxView* omnibox_view = NULL;
116 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
117 omnibox_view->SetUserText(ASCIIToUTF16("http://www.google.com/"));
118 const gfx::Vector2d click(40, 10);
119
120 // Take the focus away from the omnibox.
121 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter());
122 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
123 EXPECT_FALSE(omnibox_view->IsSelectAll());
124
125 // Clicking in the omnibox should take focus and select all text.
126 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click, click));
127 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
128 EXPECT_TRUE(omnibox_view->IsSelectAll());
129
130 // Clicking in another view should clear focus and the selection.
131 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter());
132 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
133 EXPECT_FALSE(omnibox_view->IsSelectAll());
134
135 // Clicking in the omnibox again should take focus and select all text again.
136 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click, click));
137 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
138 EXPECT_TRUE(omnibox_view->IsSelectAll());
139
140 // Clicking another omnibox spot should keep focus but clear the selection.
141 omnibox_view->SelectAll(false);
142 const gfx::Vector2d click_2(click.x() + 10, click.y());
143 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click_2, click_2));
144 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
145 EXPECT_FALSE(omnibox_view->IsSelectAll());
146
147 // Take the focus away and click in the omnibox again, but drag a bit before
148 // releasing. We should focus the omnibox but not select all of its text.
149 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter());
150 const gfx::Vector2d release(click.x() + 10, click.y());
151 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click, release));
152 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
153 EXPECT_FALSE(omnibox_view->IsSelectAll());
154
155 // Middle-clicking should not be handled by the omnibox.
156 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter());
157 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::MIDDLE, click, click));
158 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
159 EXPECT_FALSE(omnibox_view->IsSelectAll());
160 }
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