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

Side by Side Diff: chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm

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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/cocoa/autocomplete_text_field_unittest.mm » ('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 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "base/scoped_nsobject.h" 7 #include "base/scoped_nsobject.h"
8 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h" 8 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h"
9 #import "chrome/browser/cocoa/cocoa_test_helper.h" 9 #import "chrome/browser/cocoa/cocoa_test_helper.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/platform_test.h" 11 #include "testing/platform_test.h"
12 12
13 namespace { 13 namespace {
14 14
15 class AutocompleteTextFieldCellTest : public PlatformTest { 15 class AutocompleteTextFieldCellTest : public PlatformTest {
16 public: 16 public:
17 AutocompleteTextFieldCellTest() { 17 AutocompleteTextFieldCellTest() {
18 // Make sure this is wide enough to play games with the cell 18 // Make sure this is wide enough to play games with the cell
19 // decorations. 19 // decorations.
20 NSRect frame = NSMakeRect(0, 0, 300, 30); 20 const NSRect frame = NSMakeRect(0, 0, 300, 30);
21 view_.reset([[NSTextField alloc] initWithFrame:frame]); 21 view_.reset([[NSTextField alloc] initWithFrame:frame]);
22 scoped_nsobject<AutocompleteTextFieldCell> cell( 22 scoped_nsobject<AutocompleteTextFieldCell> cell(
23 [[AutocompleteTextFieldCell alloc] initTextCell:@"Testing"]); 23 [[AutocompleteTextFieldCell alloc] initTextCell:@"Testing"]);
24 [cell setEditable:YES];
24 [view_ setCell:cell.get()]; 25 [view_ setCell:cell.get()];
25 [cocoa_helper_.contentView() addSubview:view_.get()]; 26 [cocoa_helper_.contentView() addSubview:view_.get()];
26 } 27 }
27 28
28 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... 29 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc...
29 scoped_nsobject<NSTextField> view_; 30 scoped_nsobject<NSTextField> view_;
30 }; 31 };
31 32
32 // Test adding/removing from the view hierarchy, mostly to ensure nothing 33 // Test adding/removing from the view hierarchy, mostly to ensure nothing
33 // leaks or crashes. 34 // leaks or crashes.
34 TEST_F(AutocompleteTextFieldCellTest, AddRemove) { 35 TEST_F(AutocompleteTextFieldCellTest, AddRemove) {
35 EXPECT_EQ(cocoa_helper_.contentView(), [view_ superview]); 36 EXPECT_EQ(cocoa_helper_.contentView(), [view_ superview]);
36 [view_.get() removeFromSuperview]; 37 [view_.get() removeFromSuperview];
37 EXPECT_FALSE([view_ superview]); 38 EXPECT_FALSE([view_ superview]);
38 } 39 }
39 40
40 // Test drawing, mostly to ensure nothing leaks or crashes. 41 // Test drawing, mostly to ensure nothing leaks or crashes.
41 TEST_F(AutocompleteTextFieldCellTest, Display) { 42 TEST_F(AutocompleteTextFieldCellTest, Display) {
42 [view_ display]; 43 [view_ display];
43 44
45 // Test focussed drawing.
46 cocoa_helper_.makeFirstResponder(view_);
47 [view_ display];
48 cocoa_helper_.clearFirstResponder();
49
44 // Test display of various cell configurations. 50 // Test display of various cell configurations.
45 AutocompleteTextFieldCell* cell = 51 AutocompleteTextFieldCell* cell =
46 static_cast<AutocompleteTextFieldCell*>([view_ cell]); 52 static_cast<AutocompleteTextFieldCell*>([view_ cell]);
47 53
48 [cell setSearchHintString:@"Type to search"]; 54 [cell setSearchHintString:@"Type to search"];
49 [view_ display]; 55 [view_ display];
50 56
51 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; 57 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
52 [cell setKeywordHintPrefix:@"prefix" image:image suffix:@"suffix"]; 58 [cell setKeywordHintPrefix:@"prefix" image:image suffix:@"suffix"];
53 [view_ display]; 59 [view_ display];
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 [cell clearKeywordAndHint]; 257 [cell clearKeywordAndHint];
252 textFrame = [cell textFrameForFrame:bounds]; 258 textFrame = [cell textFrameForFrame:bounds];
253 EXPECT_FALSE(NSIsEmptyRect(textFrame)); 259 EXPECT_FALSE(NSIsEmptyRect(textFrame));
254 EXPECT_TRUE(NSContainsRect(bounds, textFrame)); 260 EXPECT_TRUE(NSContainsRect(bounds, textFrame));
255 EXPECT_EQ(NSMinX(bounds), NSMinX(textFrame)); 261 EXPECT_EQ(NSMinX(bounds), NSMinX(textFrame));
256 EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame)); 262 EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame));
257 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); 263 EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame));
258 } 264 }
259 265
260 } // namespace 266 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/cocoa/autocomplete_text_field_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698