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

Side by Side Diff: chrome/test/base/ui_test_utils_win.cc

Issue 9390038: Move automation/ui_controls to ui/ui_controls (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win_aura fix, sync Created 8 years, 9 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/test/base/ui_test_utils_mac.mm ('k') | chrome/test/base/view_event_test_base.cc » ('j') | 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) 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 "chrome/test/base/ui_test_utils.h" 5 #include "chrome/test/base/ui_test_utils.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "chrome/browser/automation/ui_controls.h"
10 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_window.h" 10 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/browser/ui/views/frame/browser_view.h" 11 #include "chrome/browser/ui/views/frame/browser_view.h"
13 #include "ui/base/win/foreground_helper.h" 12 #include "ui/base/win/foreground_helper.h"
13 #include "ui/ui_controls/ui_controls.h"
14 #include "ui/views/focus/focus_manager.h" 14 #include "ui/views/focus/focus_manager.h"
15 15
16 namespace ui_test_utils { 16 namespace ui_test_utils {
17 17
18 bool IsViewFocused(const Browser* browser, ViewID vid) { 18 bool IsViewFocused(const Browser* browser, ViewID vid) {
19 BrowserWindow* browser_window = browser->window(); 19 BrowserWindow* browser_window = browser->window();
20 DCHECK(browser_window); 20 DCHECK(browser_window);
21 gfx::NativeWindow window = browser_window->GetNativeHandle(); 21 gfx::NativeWindow window = browser_window->GetNativeHandle();
22 DCHECK(window); 22 DCHECK(window);
23 const views::Widget* widget = 23 const views::Widget* widget =
24 views::Widget::GetTopLevelWidgetForNativeView(window); 24 views::Widget::GetTopLevelWidgetForNativeView(window);
25 DCHECK(widget); 25 DCHECK(widget);
26 const views::FocusManager* focus_manager = widget->GetFocusManager(); 26 const views::FocusManager* focus_manager = widget->GetFocusManager();
27 DCHECK(focus_manager); 27 DCHECK(focus_manager);
28 return focus_manager->GetFocusedView()->id() == vid; 28 return focus_manager->GetFocusedView()->id() == vid;
29 } 29 }
30 30
31 void ClickOnView(const Browser* browser, ViewID vid) { 31 void ClickOnView(const Browser* browser, ViewID vid) {
32 BrowserWindow* browser_window = browser->window(); 32 BrowserWindow* browser_window = browser->window();
33 DCHECK(browser_window); 33 DCHECK(browser_window);
34 views::View* view = 34 views::View* view =
35 reinterpret_cast<BrowserView*>(browser_window)->GetViewByID(vid); 35 reinterpret_cast<BrowserView*>(browser_window)->GetViewByID(vid);
36 DCHECK(view); 36 DCHECK(view);
37 ui_controls::MoveMouseToCenterAndPress( 37 MoveMouseToCenterAndPress(
38 view, 38 view,
39 ui_controls::LEFT, 39 ui_controls::LEFT,
40 ui_controls::DOWN | ui_controls::UP, 40 ui_controls::DOWN | ui_controls::UP,
41 MessageLoop::QuitClosure()); 41 MessageLoop::QuitClosure());
42 RunMessageLoop(); 42 RunMessageLoop();
43 } 43 }
44 44
45 void HideNativeWindow(gfx::NativeWindow window) { 45 void HideNativeWindow(gfx::NativeWindow window) {
46 // TODO(jcampan): retrieve the NativeWidgetWin and show/hide on it instead of 46 // TODO(jcampan): retrieve the NativeWidgetWin and show/hide on it instead of
47 // using Windows API. 47 // using Windows API.
48 ::ShowWindow(window, SW_HIDE); 48 ::ShowWindow(window, SW_HIDE);
49 } 49 }
50 50
51 bool ShowAndFocusNativeWindow(gfx::NativeWindow window) { 51 bool ShowAndFocusNativeWindow(gfx::NativeWindow window) {
52 // TODO(jcampan): retrieve the NativeWidgetWin and show/hide on it instead of 52 // TODO(jcampan): retrieve the NativeWidgetWin and show/hide on it instead of
53 // using Windows API. 53 // using Windows API.
54 ::ShowWindow(window, SW_SHOW); 54 ::ShowWindow(window, SW_SHOW);
55 55
56 if (GetForegroundWindow() != window) { 56 if (GetForegroundWindow() != window) {
57 VLOG(1) << "Forcefully refocusing front window"; 57 VLOG(1) << "Forcefully refocusing front window";
58 ui::ForegroundHelper::SetForeground(window); 58 ui::ForegroundHelper::SetForeground(window);
59 } 59 }
60 60
61 // ShowWindow does not necessarily activate the window. In particular if a 61 // ShowWindow does not necessarily activate the window. In particular if a
62 // window from another app is the foreground window then the request to 62 // window from another app is the foreground window then the request to
63 // activate the window fails. See SetForegroundWindow for details. 63 // activate the window fails. See SetForegroundWindow for details.
64 return GetForegroundWindow() == window; 64 return GetForegroundWindow() == window;
65 } 65 }
66 66
67 void MoveMouseToCenterAndPress(views::View* view,
68 ui_controls::MouseButton button,
69 int state,
70 const base::Closure& task) {
71 DCHECK(view);
72 DCHECK(view->GetWidget());
73 gfx::Point view_center(view->width() / 2, view->height() / 2);
74 views::View::ConvertPointToScreen(view, &view_center);
75 ui_controls::SendMouseMove(view_center.x(), view_center.y());
76 ui_controls::SendMouseEventsNotifyWhenDone(button, state, task);
77 }
78
67 } // namespace ui_test_utils 79 } // namespace ui_test_utils
OLDNEW
« no previous file with comments | « chrome/test/base/ui_test_utils_mac.mm ('k') | chrome/test/base/view_event_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698