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

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