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

Side by Side Diff: chrome/browser/cocoa/cocoa_test_helper.h

Issue 259023: [Mac] Window titles for Expose. (Closed)
Patch Set: Fix unit_test expectations for Release. Created 11 years, 2 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/browser/cocoa/chrome_browser_window_unittest.mm ('k') | chrome/chrome.gyp » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #ifndef CHROME_BROWSER_COCOA_COCOA_TEST_HELPER_H_ 5 #ifndef CHROME_BROWSER_COCOA_COCOA_TEST_HELPER_H_
6 #define CHROME_BROWSER_COCOA_COCOA_TEST_HELPER_H_ 6 #define CHROME_BROWSER_COCOA_COCOA_TEST_HELPER_H_
7 7
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 9
10 #include "base/debug_util.h" 10 #include "base/debug_util.h"
(...skipping 29 matching lines...) Expand all
40 // Cocoa controller unit tests. It does several key things: 40 // Cocoa controller unit tests. It does several key things:
41 // - Creates and displays an empty Cocoa window for views to live in 41 // - Creates and displays an empty Cocoa window for views to live in
42 // - Loads the appropriate bundle so nib loading works. When loading the 42 // - Loads the appropriate bundle so nib loading works. When loading the
43 // nib in the class being tested, your must use |mac_util::MainAppBundle()| 43 // nib in the class being tested, your must use |mac_util::MainAppBundle()|
44 // as the bundle. If you do not specify a bundle, your test will likely 44 // as the bundle. If you do not specify a bundle, your test will likely
45 // fail. 45 // fail.
46 // It currently does not create an autorelease pool, though that can easily be 46 // It currently does not create an autorelease pool, though that can easily be
47 // added. If your test wants one, it can derive from PlatformTest instead of 47 // added. If your test wants one, it can derive from PlatformTest instead of
48 // testing::Test. 48 // testing::Test.
49 49
50 class CocoaTestHelper { 50 // Provides the Cocoa goodness without the extraneous window.
51 // TODO(shess): It might make more sense to have CocoaTest as a
52 // PlatformTest subclass which adds the Cocoa magic, then
53 // CocoaViewTest as a further subclass which provides a convenience
54 // window.
55 class CocoaNoWindowTestHelper {
51 public: 56 public:
52 CocoaTestHelper() { 57 CocoaNoWindowTestHelper() {
53 // Look in the framework bundle for resources. 58 // Look in the framework bundle for resources.
54 FilePath path; 59 FilePath path;
55 PathService::Get(base::DIR_EXE, &path); 60 PathService::Get(base::DIR_EXE, &path);
56 path = path.AppendASCII(MAC_BROWSER_APP_NAME); 61 path = path.AppendASCII(MAC_BROWSER_APP_NAME);
57 path = path.AppendASCII("Contents"); 62 path = path.AppendASCII("Contents");
58 path = path.AppendASCII("Frameworks"); 63 path = path.AppendASCII("Frameworks");
59 path = path.AppendASCII(MAC_FRAMEWORK_NAME); 64 path = path.AppendASCII(MAC_FRAMEWORK_NAME);
60 mac_util::SetOverrideAppBundlePath(path); 65 mac_util::SetOverrideAppBundlePath(path);
61 66
62 // Bootstrap Cocoa. It's very unhappy without this. 67 // Bootstrap Cocoa. It's very unhappy without this.
63 [NSApplication sharedApplication]; 68 [NSApplication sharedApplication];
64 69
65 // Create a window. 70 // Set the duration of AppKit-evaluated animations (such as frame changes)
71 // to zero for testing purposes. That way they take effect immediately.
72 [[NSAnimationContext currentContext] setDuration:0.0];
73 }
74 };
75
76 class CocoaTestHelper : public CocoaNoWindowTestHelper {
77 public:
78 CocoaTestHelper() {
66 window_.reset([[CocoaTestHelperWindow alloc] init]); 79 window_.reset([[CocoaTestHelperWindow alloc] init]);
67 if (DebugUtil::BeingDebugged()) { 80 if (DebugUtil::BeingDebugged()) {
68 [window_ orderFront:nil]; 81 [window_ orderFront:nil];
69 } else { 82 } else {
70 [window_ orderBack:nil]; 83 [window_ orderBack:nil];
71 } 84 }
72
73 // Set the duration of AppKit-evaluated animations (such as frame changes)
74 // to zero for testing purposes. That way they take effect immediately.
75 [[NSAnimationContext currentContext] setDuration:0.0];
76 } 85 }
77 86
78 // Access the Cocoa window created for the test. 87 // Access the Cocoa window created for the test.
79 NSWindow* window() const { return window_.get(); } 88 NSWindow* window() const { return window_.get(); }
80 NSView* contentView() const { return [window_ contentView]; } 89 NSView* contentView() const { return [window_ contentView]; }
81 90
82 // Set |window_| to pretend to be key and make |aView| its 91 // Set |window_| to pretend to be key and make |aView| its
83 // firstResponder. 92 // firstResponder.
84 void makeFirstResponder(NSView* aView) { 93 void makeFirstResponder(NSView* aView) {
85 [window_ setPretendIsKeyWindow:YES]; 94 [window_ setPretendIsKeyWindow:YES];
86 [window_ makeFirstResponder:aView]; 95 [window_ makeFirstResponder:aView];
87 } 96 }
88 97
89 // Clear |window_| firstResponder and stop pretending to be key. 98 // Clear |window_| firstResponder and stop pretending to be key.
90 void clearFirstResponder() { 99 void clearFirstResponder() {
91 [window_ makeFirstResponder:nil]; 100 [window_ makeFirstResponder:nil];
92 [window_ setPretendIsKeyWindow:NO]; 101 [window_ setPretendIsKeyWindow:NO];
93 } 102 }
94 103
95 private: 104 private:
96 scoped_nsobject<CocoaTestHelperWindow> window_; 105 scoped_nsobject<CocoaTestHelperWindow> window_;
97 }; 106 };
98 107
99 #endif // CHROME_BROWSER_COCOA_COCOA_TEST_HELPER_H_ 108 #endif // CHROME_BROWSER_COCOA_COCOA_TEST_HELPER_H_
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/chrome_browser_window_unittest.mm ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698