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

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

Issue 165499: Updates to clean up default theme and add hover states (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/cocoa/gradient_button_cell.mm ('k') | chrome/browser/cocoa/status_bubble_mac.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/gradient_button_cell.h" 8 #import "chrome/browser/cocoa/gradient_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 11
12 @interface GradientButtonCell (HoverValueTesting)
13 - (void)adjustHoverValue;
14 @end
15
12 namespace { 16 namespace {
13 17
14 class GradientButtonCellTest : public testing::Test { 18 class GradientButtonCellTest : public testing::Test {
15 public: 19 public:
16 GradientButtonCellTest() { 20 GradientButtonCellTest() {
17 NSRect frame = NSMakeRect(0, 0, 50, 30); 21 NSRect frame = NSMakeRect(0, 0, 50, 30);
18 view_.reset([[NSButton alloc] initWithFrame:frame]); 22 view_.reset([[NSButton alloc] initWithFrame:frame]);
19 scoped_nsobject<GradientButtonCell> cell([[GradientButtonCell alloc] 23 scoped_nsobject<GradientButtonCell> cell([[GradientButtonCell alloc]
20 initTextCell:@"Testing"]); 24 initTextCell:@"Testing"]);
21 [view_ setCell:cell.get()]; 25 [view_ setCell:cell.get()];
22 [cocoa_helper_.contentView() addSubview:view_.get()]; 26 [cocoa_helper_.contentView() addSubview:view_.get()];
23 } 27 }
24 28
25 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... 29 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc...
26 scoped_nsobject<NSButton> view_; 30 scoped_nsobject<NSButton> view_;
27 }; 31 };
28 32
29 // Test adding/removing from the view hierarchy, mostly to ensure nothing 33 // Test adding/removing from the view hierarchy, mostly to ensure nothing
30 // leaks or crashes. 34 // leaks or crashes.
31 TEST_F(GradientButtonCellTest, AddRemove) { 35 TEST_F(GradientButtonCellTest, AddRemove) {
32 EXPECT_EQ(cocoa_helper_.contentView(), [view_ superview]); 36 EXPECT_EQ(cocoa_helper_.contentView(), [view_ superview]);
33 [view_.get() removeFromSuperview]; 37 [view_.get() removeFromSuperview];
34 EXPECT_FALSE([view_ superview]); 38 EXPECT_FALSE([view_ superview]);
35 } 39 }
36 40
37 // Test drawing, mostly to ensure nothing leaks or crashes. 41 // Test drawing, mostly to ensure nothing leaks or crashes.
38 TEST_F(GradientButtonCellTest, Display) { 42 TEST_F(GradientButtonCellTest, Display) {
43 [[view_ cell] setHoverAlpha:0.0];
39 [view_ display]; 44 [view_ display];
45 [[view_ cell] setHoverAlpha:0.5];
46 [view_ display];
47 [[view_ cell] setHoverAlpha:1.0];
48 [view_ display];
49 }
50
51 // Test drawing, mostly to ensure nothing leaks or crashes.
52 TEST_F(GradientButtonCellTest, Hover) {
53 GradientButtonCell* cell = [view_ cell];
54 [cell setMouseInside:YES animate:NO];
55 EXPECT_EQ([[view_ cell] hoverAlpha], 1.0);
56
57 [cell setMouseInside:NO animate:YES];
58 CGFloat alpha1 = [cell hoverAlpha];
59 [cell adjustHoverValue];
60 CGFloat alpha2 = [cell hoverAlpha];
61 EXPECT_TRUE(alpha2 < alpha1);
40 } 62 }
41 63
42 // Tracking rects 64 // Tracking rects
43 TEST_F(GradientButtonCellTest, TrackingRects) { 65 TEST_F(GradientButtonCellTest, TrackingRects) {
44 GradientButtonCell* cell = [view_ cell]; 66 GradientButtonCell* cell = [view_ cell];
45 EXPECT_FALSE([cell showsBorderOnlyWhileMouseInside]); 67 EXPECT_FALSE([cell showsBorderOnlyWhileMouseInside]);
46 EXPECT_FALSE([cell isMouseInside]); 68 EXPECT_FALSE([cell isMouseInside]);
47 69
48 [cell setShowsBorderOnlyWhileMouseInside:YES]; 70 [cell setShowsBorderOnlyWhileMouseInside:YES];
49 [cell mouseEntered:nil]; 71 [cell mouseEntered:nil];
50 EXPECT_TRUE([cell isMouseInside]); 72 EXPECT_TRUE([cell isMouseInside]);
51 [cell mouseExited:nil]; 73 [cell mouseExited:nil];
52 EXPECT_FALSE([cell isMouseInside]); 74 EXPECT_FALSE([cell isMouseInside]);
53 75
54 [cell setShowsBorderOnlyWhileMouseInside:NO]; 76 [cell setShowsBorderOnlyWhileMouseInside:NO];
55 EXPECT_FALSE([cell isMouseInside]); 77 EXPECT_FALSE([cell isMouseInside]);
56 78
57 [cell setShowsBorderOnlyWhileMouseInside:YES]; 79 [cell setShowsBorderOnlyWhileMouseInside:YES];
58 [cell setShowsBorderOnlyWhileMouseInside:YES]; 80 [cell setShowsBorderOnlyWhileMouseInside:YES];
59 [cell setShowsBorderOnlyWhileMouseInside:NO]; 81 [cell setShowsBorderOnlyWhileMouseInside:NO];
60 [cell setShowsBorderOnlyWhileMouseInside:NO]; 82 [cell setShowsBorderOnlyWhileMouseInside:NO];
61 } 83 }
62 84
63 } // namespace 85 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/gradient_button_cell.mm ('k') | chrome/browser/cocoa/status_bubble_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698