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

Side by Side Diff: chrome/test/ui_test_utils_mac.mm

Issue 2986004: [Mac]Port browser_keyevents_browsertest.cc and browser_focus_uitest.cc to Mac. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Enable BrowserFocusTest and BrowserKeyEventsTests on Mac. Created 10 years, 5 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
« no previous file with comments | « chrome/test/ui_test_utils_mac.cc ('k') | chrome/test/ui_test_utils_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « chrome/test/ui_test_utils_mac.cc ('k') | chrome/test/ui_test_utils_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698