summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-05 00:56:56 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-05 00:56:56 +0000
commit3266992f388387cb5f731cb36fa75d5ac65a7901 (patch)
treeb3df8fcd06bae3aa200285aac00b289d111d5da0 /chrome
parent8c96af8431a78412ce6cdec1f5d0cf2c0a2f1e9a (diff)
downloadchromium_src-3266992f388387cb5f731cb36fa75d5ac65a7901.zip
chromium_src-3266992f388387cb5f731cb36fa75d5ac65a7901.tar.gz
chromium_src-3266992f388387cb5f731cb36fa75d5ac65a7901.tar.bz2
[Mac] Add testing code to expose an NSColor memory leak.
AutocompleteTextFieldCell calls -keyboardFocusIndicatorColor when drawing the focus ring, which valgrind considers a leak. While we were testing drawing when not focussed, unit tests could not test drawing when focussed without the window being made key, which is bad for many reasons. This change adds some code to allow faking the key window, then adds tests for drawing when focussed which exposes the memory leak, then adds a suppression for that memory leak. http://crbug.com/21137 TEST=valgrind AutocompleteTextFieldCellTest.Display Review URL: http://codereview.chromium.org/192031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25567 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm8
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_unittest.mm5
-rw-r--r--chrome/browser/cocoa/cocoa_test_helper.h43
-rw-r--r--chrome/browser/cocoa/cocoa_test_helper.mm28
-rw-r--r--chrome/chrome.gyp1
5 files changed, 78 insertions, 7 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm
index fc10168..0f6c801 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm
@@ -17,10 +17,11 @@ class AutocompleteTextFieldCellTest : public PlatformTest {
AutocompleteTextFieldCellTest() {
// Make sure this is wide enough to play games with the cell
// decorations.
- NSRect frame = NSMakeRect(0, 0, 300, 30);
+ const NSRect frame = NSMakeRect(0, 0, 300, 30);
view_.reset([[NSTextField alloc] initWithFrame:frame]);
scoped_nsobject<AutocompleteTextFieldCell> cell(
[[AutocompleteTextFieldCell alloc] initTextCell:@"Testing"]);
+ [cell setEditable:YES];
[view_ setCell:cell.get()];
[cocoa_helper_.contentView() addSubview:view_.get()];
}
@@ -41,6 +42,11 @@ TEST_F(AutocompleteTextFieldCellTest, AddRemove) {
TEST_F(AutocompleteTextFieldCellTest, Display) {
[view_ display];
+ // Test focussed drawing.
+ cocoa_helper_.makeFirstResponder(view_);
+ [view_ display];
+ cocoa_helper_.clearFirstResponder();
+
// Test display of various cell configurations.
AutocompleteTextFieldCell* cell =
static_cast<AutocompleteTextFieldCell*>([view_ cell]);
diff --git a/chrome/browser/cocoa/autocomplete_text_field_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_unittest.mm
index f8db667..2ae0cdf 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_unittest.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_unittest.mm
@@ -85,6 +85,11 @@ TEST_F(AutocompleteTextFieldTest, Cell) {
TEST_F(AutocompleteTextFieldTest, Display) {
[field_ display];
+ // Test focussed drawing.
+ cocoa_helper_.makeFirstResponder(field_);
+ [field_ display];
+ cocoa_helper_.clearFirstResponder();
+
// Test display of various cell configurations.
AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell];
diff --git a/chrome/browser/cocoa/cocoa_test_helper.h b/chrome/browser/cocoa/cocoa_test_helper.h
index 16fdafc..7fdcb45 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
diff --git a/chrome/browser/cocoa/cocoa_test_helper.mm b/chrome/browser/cocoa/cocoa_test_helper.mm
new file mode 100644
index 0000000..efe5c5c
--- /dev/null
+++ b/chrome/browser/cocoa/cocoa_test_helper.mm
@@ -0,0 +1,28 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/cocoa/cocoa_test_helper.h"
+
+@implementation CocoaTestHelperWindow
+
+- (id)initWithContentRect:(NSRect)contentRect {
+ return [self initWithContentRect:contentRect
+ styleMask:NSBorderlessWindowMask
+ backing:NSBackingStoreBuffered
+ defer:NO];
+}
+
+- (id)init {
+ return [self initWithContentRect:NSMakeRect(0, 0, 800, 600)];
+}
+
+- (void)setPretendIsKeyWindow:(BOOL)flag {
+ pretendIsKeyWindow_ = flag;
+}
+
+- (BOOL)isKeyWindow {
+ return pretendIsKeyWindow_;
+}
+
+@end
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 95c587c..aa95491 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -909,6 +909,7 @@
'browser/cocoa/clickhold_button_cell.h',
'browser/cocoa/clickhold_button_cell.mm',
'browser/cocoa/cocoa_test_helper.h',
+ 'browser/cocoa/cocoa_test_helper.mm',
'browser/cocoa/command_observer_bridge.h',
'browser/cocoa/command_observer_bridge.mm',
'browser/cocoa/constrained_window_mac.h',