OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/test/ui_test_utils.h" |
| 6 |
| 7 #include <Carbon/Carbon.h> |
| 8 #import <Cocoa/Cocoa.h> |
| 9 |
| 10 #include "base/logging.h" |
| 11 #include "base/message_loop.h" |
| 12 #include "chrome/browser/automation/ui_controls.h" |
| 13 #include "chrome/browser/browser.h" |
| 14 #include "chrome/browser/browser_window.h" |
| 15 #import "chrome/browser/cocoa/view_id_util.h" |
| 16 |
| 17 namespace ui_test_utils { |
| 18 |
| 19 bool IsViewFocused(const Browser* browser, ViewID vid) { |
| 20 NSWindow* window = browser->window()->GetNativeHandle(); |
| 21 DCHECK(window); |
| 22 NSView* view = view_id_util::GetView(window, vid); |
| 23 if (!view) |
| 24 return false; |
| 25 |
| 26 NSResponder* firstResponder = [window firstResponder]; |
| 27 if (firstResponder == static_cast<NSResponder*>(view)) |
| 28 return true; |
| 29 |
| 30 // Handle the special case of focusing a TextField. |
| 31 if ([firstResponder isKindOfClass:[NSTextView class]]) { |
| 32 NSView* delegate = [(NSTextView*)firstResponder delegate]; |
| 33 if (delegate == view) |
| 34 return true; |
| 35 } |
| 36 |
| 37 return false; |
| 38 } |
| 39 |
| 40 void ClickOnView(const Browser* browser, ViewID vid) { |
| 41 NSWindow* window = browser->window()->GetNativeHandle(); |
| 42 DCHECK(window); |
| 43 NSView* view = view_id_util::GetView(window, vid); |
| 44 DCHECK(view); |
| 45 ui_controls::MoveMouseToCenterAndPress( |
| 46 view, |
| 47 ui_controls::LEFT, |
| 48 ui_controls::DOWN | ui_controls::UP, |
| 49 new MessageLoop::QuitTask()); |
| 50 RunMessageLoop(); |
| 51 } |
| 52 |
| 53 void HideNativeWindow(gfx::NativeWindow window) { |
| 54 [window orderOut:nil]; |
| 55 } |
| 56 |
| 57 void ShowAndFocusNativeWindow(gfx::NativeWindow window) { |
| 58 // Make sure an unbundled program can get the input focus. |
| 59 ProcessSerialNumber psn = { 0, kCurrentProcess }; |
| 60 TransformProcessType(&psn,kProcessTransformToForegroundApplication); |
| 61 SetFrontProcess(&psn); |
| 62 |
| 63 [window makeKeyAndOrderFront:nil]; |
| 64 } |
| 65 |
| 66 } // namespace ui_test_utils |
OLD | NEW |