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

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

Issue 402066: Moved a whole pile of unittests over to CocoaTest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
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/hyperlink_button_cell.h" 8 #import "chrome/browser/cocoa/hyperlink_button_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 HyperlinkButtonCellTest : public PlatformTest { 15 class HyperlinkButtonCellTest : public CocoaTest {
16 public: 16 public:
17 HyperlinkButtonCellTest() { 17 HyperlinkButtonCellTest() {
18 NSRect frame = NSMakeRect(0, 0, 50, 30); 18 NSRect frame = NSMakeRect(0, 0, 50, 30);
19 view_.reset([[NSButton alloc] initWithFrame:frame]); 19 scoped_nsobject<NSButton> view([[NSButton alloc] initWithFrame:frame]);
20 cell_.reset([[HyperlinkButtonCell alloc] initTextCell:@"Testing"]); 20 view_ = view.get();
21 [view_ setCell:cell_.get()]; 21 scoped_nsobject<HyperlinkButtonCell> cell(
22 [cocoa_helper_.contentView() addSubview:view_.get()]; 22 [[HyperlinkButtonCell alloc] initTextCell:@"Testing"]);
23 cell_ = cell.get();
24 [view_ setCell:cell_];
25 [[test_window() contentView] addSubview:view_];
23 } 26 }
24 27
25 void TestCellCustomization() { 28 void TestCellCustomization(HyperlinkButtonCell* cell) {
26 EXPECT_FALSE([cell_ isBordered]); 29 EXPECT_FALSE([cell isBordered]);
27 EXPECT_EQ(NSNoCellMask, [cell_ highlightsBy]); 30 EXPECT_EQ(NSNoCellMask, [cell_ highlightsBy]);
28 EXPECT_TRUE([cell_ showsBorderOnlyWhileMouseInside]); 31 EXPECT_TRUE([cell showsBorderOnlyWhileMouseInside]);
29 EXPECT_TRUE([cell_ textColor]); 32 EXPECT_TRUE([cell textColor]);
30 } 33 }
31 34
32 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... 35 NSButton* view_;
33 scoped_nsobject<NSButton> view_; 36 HyperlinkButtonCell* cell_;
34 scoped_nsobject<HyperlinkButtonCell> cell_;
35 }; 37 };
36 38
37 // Test adding/removing from the view hierarchy, mostly to ensure nothing 39 TEST_VIEW(HyperlinkButtonCellTest, view_)
38 // leaks or crashes.
39 TEST_F(HyperlinkButtonCellTest, AddRemove) {
40 EXPECT_EQ(cocoa_helper_.contentView(), [view_ superview]);
41 [view_.get() removeFromSuperview];
42 EXPECT_FALSE([view_ superview]);
43 }
44
45 // Test drawing, mostly to ensure nothing leaks or crashes.
46 TEST_F(HyperlinkButtonCellTest, Display) {
47 [view_ display];
48 }
49 40
50 // Tests the three designated intializers. 41 // Tests the three designated intializers.
51 TEST_F(HyperlinkButtonCellTest, Initializers) { 42 TEST_F(HyperlinkButtonCellTest, Initializers) {
52 TestCellCustomization(); // |-initTextFrame:| 43 TestCellCustomization(cell_); // |-initTextFrame:|
53 44 scoped_nsobject<HyperlinkButtonCell> cell([[HyperlinkButtonCell alloc] init]);
54 cell_.reset([[HyperlinkButtonCell alloc] init]); 45 TestCellCustomization(cell.get());
55 TestCellCustomization();
56 46
57 // Need to create a dummy archiver to test |-initWithCoder:|. 47 // Need to create a dummy archiver to test |-initWithCoder:|.
58 NSData* emptyData = [NSKeyedArchiver archivedDataWithRootObject:@""]; 48 NSData* emptyData = [NSKeyedArchiver archivedDataWithRootObject:@""];
59 NSCoder* coder = 49 NSCoder* coder =
60 [[[NSKeyedUnarchiver alloc] initForReadingWithData:emptyData] autorelease]; 50 [[[NSKeyedUnarchiver alloc] initForReadingWithData:emptyData] autorelease];
61 cell_.reset([[HyperlinkButtonCell alloc] initWithCoder:coder]); 51 cell.reset([[HyperlinkButtonCell alloc] initWithCoder:coder]);
62 TestCellCustomization(); 52 TestCellCustomization(cell);
63 } 53 }
64 54
65 // Test set color. 55 // Test set color.
66 TEST_F(HyperlinkButtonCellTest, SetTextColor) { 56 TEST_F(HyperlinkButtonCellTest, SetTextColor) {
67 NSColor* textColor = [NSColor redColor]; 57 NSColor* textColor = [NSColor redColor];
68 EXPECT_NE(textColor, [cell_ textColor]); 58 EXPECT_NE(textColor, [cell_ textColor]);
69 [cell_ setTextColor:textColor]; 59 [cell_ setTextColor:textColor];
70 EXPECT_EQ(textColor, [cell_ textColor]); 60 EXPECT_EQ(textColor, [cell_ textColor]);
71 } 61 }
72 62
73 // Test mouse events. 63 // Test mouse events.
74 // TODO(rsesek): See if we can synthesize mouse events to more accurately 64 // TODO(rsesek): See if we can synthesize mouse events to more accurately
75 // test this. 65 // test this.
76 TEST_F(HyperlinkButtonCellTest, MouseHover) { 66 TEST_F(HyperlinkButtonCellTest, MouseHover) {
77 [[NSCursor disappearingItemCursor] push]; // Set a known state. 67 [[NSCursor disappearingItemCursor] push]; // Set a known state.
78 [cell_ mouseEntered:nil]; 68 [cell_ mouseEntered:nil];
79 EXPECT_EQ([NSCursor pointingHandCursor], [NSCursor currentCursor]); 69 EXPECT_EQ([NSCursor pointingHandCursor], [NSCursor currentCursor]);
80 [cell_ mouseExited:nil]; 70 [cell_ mouseExited:nil];
81 EXPECT_EQ([NSCursor disappearingItemCursor], [NSCursor currentCursor]); 71 EXPECT_EQ([NSCursor disappearingItemCursor], [NSCursor currentCursor]);
82 [NSCursor pop]; 72 [NSCursor pop];
83 } 73 }
84 74
85 } // namespace 75 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/fullscreen_window_unittest.mm ('k') | chrome/browser/cocoa/infobar_container_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698