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

Unified Diff: chrome/browser/cocoa/cocoa_test_helper.h

Issue 192031: [Mac] Add testing code to expose an NSColor memory leak. (Closed)
Patch Set: Remove egregious s/private/public/ leftover from prototyping. Created 11 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/cocoa/autocomplete_text_field_unittest.mm ('k') | chrome/browser/cocoa/cocoa_test_helper.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/cocoa/cocoa_test_helper.h
diff --git a/chrome/browser/cocoa/cocoa_test_helper.h b/chrome/browser/cocoa/cocoa_test_helper.h
index 16fdafcde69491b58cb592ed40171a584459d587..7fdcb45bb71c921ea3130ee5e277ba2746cc7e8b 100644
--- a/chrome/browser/cocoa/cocoa_test_helper.h
+++ b/chrome/browser/cocoa/cocoa_test_helper.h
@@ -14,6 +14,28 @@
#import "base/scoped_nsobject.h"
#include "chrome/common/mac_app_names.h"
+// Background windows normally will not display things such as focus
+// rings. This class allows -isKeyWindow to be manipulated to test
+// such things.
+
+@interface CocoaTestHelperWindow : NSWindow {
+ @private
+ BOOL pretendIsKeyWindow_;
+}
+
+// Init a borderless non-defered window with backing store.
+- (id)initWithContentRect:(NSRect)contentRect;
+
+// Init with a default frame.
+- (id)init;
+
+// Set value to return for -isKeyWindow.
+- (void)setPretendIsKeyWindow:(BOOL)isKeyWindow;
+
+- (BOOL)isKeyWindow;
+
+@end
+
// A class that initializes Cocoa and sets up resources for many of our
// Cocoa controller unit tests. It does several key things:
// - Creates and displays an empty Cocoa window for views to live in
@@ -38,11 +60,7 @@ class CocoaTestHelper {
[NSApplication sharedApplication];
// Create a window.
- NSRect frame = NSMakeRect(0, 0, 800, 600);
- window_.reset([[NSWindow alloc] initWithContentRect:frame
- styleMask:0
- backing:NSBackingStoreBuffered
- defer:NO]);
+ window_.reset([[CocoaTestHelperWindow alloc] init]);
if (DebugUtil::BeingDebugged()) {
[window_ orderFront:nil];
} else {
@@ -58,8 +76,21 @@ class CocoaTestHelper {
NSWindow* window() const { return window_.get(); }
NSView* contentView() const { return [window_ contentView]; }
+ // Set |window_| to pretend to be key and make |aView| its
+ // firstResponder.
+ void makeFirstResponder(NSView* aView) {
+ [window_ setPretendIsKeyWindow:YES];
+ [window_ makeFirstResponder:aView];
+ }
+
+ // Clear |window_| firstResponder and stop pretending to be key.
+ void clearFirstResponder() {
+ [window_ makeFirstResponder:nil];
+ [window_ setPretendIsKeyWindow:NO];
+ }
+
private:
- scoped_nsobject<NSWindow> window_;
+ scoped_nsobject<CocoaTestHelperWindow> window_;
};
#endif // CHROME_BROWSER_COCOA_COCOA_TEST_HELPER
« no previous file with comments | « chrome/browser/cocoa/autocomplete_text_field_unittest.mm ('k') | chrome/browser/cocoa/cocoa_test_helper.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698