OLD | NEW |
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 #include "testing/platform_test.h" | 11 #include "testing/platform_test.h" |
12 | 12 |
13 @interface GradientButtonCell (HoverValueTesting) | 13 @interface GradientButtonCell (HoverValueTesting) |
14 - (void)adjustHoverValue; | 14 - (void)performOnePulseStep; |
15 @end | 15 @end |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 class GradientButtonCellTest : public CocoaTest { | 19 class GradientButtonCellTest : public CocoaTest { |
20 public: | 20 public: |
21 GradientButtonCellTest() { | 21 GradientButtonCellTest() { |
22 NSRect frame = NSMakeRect(0, 0, 50, 30); | 22 NSRect frame = NSMakeRect(0, 0, 50, 30); |
23 scoped_nsobject<NSButton>view([[NSButton alloc] initWithFrame:frame]); | 23 scoped_nsobject<NSButton>view([[NSButton alloc] initWithFrame:frame]); |
24 view_ = view.get(); | 24 view_ = view.get(); |
(...skipping 19 matching lines...) Expand all Loading... |
44 } | 44 } |
45 | 45 |
46 // Test hover, mostly to ensure nothing leaks or crashes. | 46 // Test hover, mostly to ensure nothing leaks or crashes. |
47 TEST_F(GradientButtonCellTest, Hover) { | 47 TEST_F(GradientButtonCellTest, Hover) { |
48 GradientButtonCell* cell = [view_ cell]; | 48 GradientButtonCell* cell = [view_ cell]; |
49 [cell setMouseInside:YES animate:NO]; | 49 [cell setMouseInside:YES animate:NO]; |
50 EXPECT_EQ([[view_ cell] hoverAlpha], 1.0); | 50 EXPECT_EQ([[view_ cell] hoverAlpha], 1.0); |
51 | 51 |
52 [cell setMouseInside:NO animate:YES]; | 52 [cell setMouseInside:NO animate:YES]; |
53 CGFloat alpha1 = [cell hoverAlpha]; | 53 CGFloat alpha1 = [cell hoverAlpha]; |
54 [cell adjustHoverValue]; | 54 [cell performOnePulseStep]; |
55 CGFloat alpha2 = [cell hoverAlpha]; | 55 CGFloat alpha2 = [cell hoverAlpha]; |
56 EXPECT_TRUE(alpha2 < alpha1); | 56 EXPECT_TRUE(alpha2 < alpha1); |
57 } | 57 } |
58 | 58 |
59 // Tracking rects | 59 // Tracking rects |
60 TEST_F(GradientButtonCellTest, TrackingRects) { | 60 TEST_F(GradientButtonCellTest, TrackingRects) { |
61 GradientButtonCell* cell = [view_ cell]; | 61 GradientButtonCell* cell = [view_ cell]; |
62 EXPECT_FALSE([cell showsBorderOnlyWhileMouseInside]); | 62 EXPECT_FALSE([cell showsBorderOnlyWhileMouseInside]); |
63 EXPECT_FALSE([cell isMouseInside]); | 63 EXPECT_FALSE([cell isMouseInside]); |
64 | 64 |
65 [cell setShowsBorderOnlyWhileMouseInside:YES]; | 65 [cell setShowsBorderOnlyWhileMouseInside:YES]; |
66 [cell mouseEntered:nil]; | 66 [cell mouseEntered:nil]; |
67 EXPECT_TRUE([cell isMouseInside]); | 67 EXPECT_TRUE([cell isMouseInside]); |
68 [cell mouseExited:nil]; | 68 [cell mouseExited:nil]; |
69 EXPECT_FALSE([cell isMouseInside]); | 69 EXPECT_FALSE([cell isMouseInside]); |
70 | 70 |
71 [cell setShowsBorderOnlyWhileMouseInside:NO]; | 71 [cell setShowsBorderOnlyWhileMouseInside:NO]; |
72 EXPECT_FALSE([cell isMouseInside]); | 72 EXPECT_FALSE([cell isMouseInside]); |
73 | 73 |
74 [cell setShowsBorderOnlyWhileMouseInside:YES]; | 74 [cell setShowsBorderOnlyWhileMouseInside:YES]; |
75 [cell setShowsBorderOnlyWhileMouseInside:YES]; | 75 [cell setShowsBorderOnlyWhileMouseInside:YES]; |
76 [cell setShowsBorderOnlyWhileMouseInside:NO]; | 76 [cell setShowsBorderOnlyWhileMouseInside:NO]; |
77 [cell setShowsBorderOnlyWhileMouseInside:NO]; | 77 [cell setShowsBorderOnlyWhileMouseInside:NO]; |
78 } | 78 } |
79 | 79 |
| 80 TEST_F(GradientButtonCellTest, ContinuousPulseOnOff) { |
| 81 GradientButtonCell* cell = [view_ cell]; |
| 82 |
| 83 // On/off |
| 84 EXPECT_FALSE([cell isContinuousPulsing]); |
| 85 [cell setIsContinuousPulsing:YES]; |
| 86 EXPECT_TRUE([cell isContinuousPulsing]); |
| 87 EXPECT_TRUE([cell pulsing]); |
| 88 [cell setIsContinuousPulsing:NO]; |
| 89 EXPECT_FALSE([cell isContinuousPulsing]); |
| 90 |
| 91 // On/safeOff |
| 92 [cell setIsContinuousPulsing:YES]; |
| 93 EXPECT_TRUE([cell isContinuousPulsing]); |
| 94 [cell safelyStopPulsing]; |
| 95 } |
| 96 |
| 97 // More for valgrind; we don't confirm state change does anything useful. |
| 98 TEST_F(GradientButtonCellTest, PulseState) { |
| 99 GradientButtonCell* cell = [view_ cell]; |
| 100 |
| 101 [cell setMouseInside:YES animate:YES]; |
| 102 // Allow for immediate state changes to keep test unflaky |
| 103 EXPECT_TRUE(([cell pulseState] == gradient_button_cell::kPulsingOn) || |
| 104 ([cell pulseState] == gradient_button_cell::kPulsedOn)); |
| 105 |
| 106 [cell setMouseInside:NO animate:YES]; |
| 107 // Allow for immediate state changes to keep test unflaky |
| 108 EXPECT_TRUE(([cell pulseState] == gradient_button_cell::kPulsingOff) || |
| 109 ([cell pulseState] == gradient_button_cell::kPulsedOff)); |
| 110 } |
| 111 |
80 } // namespace | 112 } // namespace |
OLD | NEW |