| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <Carbon/Carbon.h> | 7 #include <Carbon/Carbon.h> |
| 8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
| 9 | 9 |
| 10 #include "base/bind.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 12 #include "chrome/browser/automation/ui_controls.h" | |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
| 15 #include "ui/ui_controls/ui_controls.h" |
| 15 #import "chrome/browser/ui/cocoa/view_id_util.h" | 16 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 16 | 17 |
| 17 namespace ui_test_utils { | 18 namespace ui_test_utils { |
| 18 | 19 |
| 19 bool IsViewFocused(const Browser* browser, ViewID vid) { | 20 bool IsViewFocused(const Browser* browser, ViewID vid) { |
| 20 NSWindow* window = browser->window()->GetNativeHandle(); | 21 NSWindow* window = browser->window()->GetNativeHandle(); |
| 21 DCHECK(window); | 22 DCHECK(window); |
| 22 NSView* view = view_id_util::GetView(window, vid); | 23 NSView* view = view_id_util::GetView(window, vid); |
| 23 if (!view) | 24 if (!view) |
| 24 return false; | 25 return false; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 36 } | 37 } |
| 37 | 38 |
| 38 return false; | 39 return false; |
| 39 } | 40 } |
| 40 | 41 |
| 41 void ClickOnView(const Browser* browser, ViewID vid) { | 42 void ClickOnView(const Browser* browser, ViewID vid) { |
| 42 NSWindow* window = browser->window()->GetNativeHandle(); | 43 NSWindow* window = browser->window()->GetNativeHandle(); |
| 43 DCHECK(window); | 44 DCHECK(window); |
| 44 NSView* view = view_id_util::GetView(window, vid); | 45 NSView* view = view_id_util::GetView(window, vid); |
| 45 DCHECK(view); | 46 DCHECK(view); |
| 46 ui_controls::MoveMouseToCenterAndPress( | 47 MoveMouseToCenterAndPress( |
| 47 view, | 48 view, |
| 48 ui_controls::LEFT, | 49 ui_controls::LEFT, |
| 49 ui_controls::DOWN | ui_controls::UP, | 50 ui_controls::DOWN | ui_controls::UP, |
| 50 MessageLoop::QuitClosure()); | 51 MessageLoop::QuitClosure()); |
| 51 RunMessageLoop(); | 52 RunMessageLoop(); |
| 52 } | 53 } |
| 53 | 54 |
| 54 void HideNativeWindow(gfx::NativeWindow window) { | 55 void HideNativeWindow(gfx::NativeWindow window) { |
| 55 [window orderOut:nil]; | 56 [window orderOut:nil]; |
| 56 } | 57 } |
| 57 | 58 |
| 58 bool ShowAndFocusNativeWindow(gfx::NativeWindow window) { | 59 bool ShowAndFocusNativeWindow(gfx::NativeWindow window) { |
| 59 // Make sure an unbundled program can get the input focus. | 60 // Make sure an unbundled program can get the input focus. |
| 60 ProcessSerialNumber psn = { 0, kCurrentProcess }; | 61 ProcessSerialNumber psn = { 0, kCurrentProcess }; |
| 61 TransformProcessType(&psn,kProcessTransformToForegroundApplication); | 62 TransformProcessType(&psn,kProcessTransformToForegroundApplication); |
| 62 SetFrontProcess(&psn); | 63 SetFrontProcess(&psn); |
| 63 | 64 |
| 64 [window makeKeyAndOrderFront:nil]; | 65 [window makeKeyAndOrderFront:nil]; |
| 65 return true; | 66 return true; |
| 66 } | 67 } |
| 67 | 68 |
| 69 void MoveMouseToCenterAndPress( |
| 70 NSView* view, |
| 71 ui_controls::MouseButton button, |
| 72 int state, |
| 73 const base::Closure& task) { |
| 74 DCHECK(view); |
| 75 NSWindow* window = [view window]; |
| 76 DCHECK(window); |
| 77 NSScreen* screen = [window screen]; |
| 78 DCHECK(screen); |
| 79 |
| 80 // Converts the center position of the view into the coordinates accepted |
| 81 // by SendMouseMoveNotifyWhenDone() method. |
| 82 NSRect bounds = [view bounds]; |
| 83 NSPoint center = NSMakePoint(NSMidX(bounds), NSMidY(bounds)); |
| 84 center = [view convertPoint:center toView:nil]; |
| 85 center = [window convertBaseToScreen:center]; |
| 86 center = NSMakePoint(center.x, [screen frame].size.height - center.y); |
| 87 |
| 88 ui_controls::SendMouseMoveNotifyWhenDone( |
| 89 center.x, center.y, |
| 90 base::Bind(&internal::ClickTask, button, state, task)); |
| 91 } |
| 92 |
| 68 } // namespace ui_test_utils | 93 } // namespace ui_test_utils |
| OLD | NEW |