Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / gradient_button_cell_unittest.mm
blobb9ea960fb7bbb16da0c021991b4fdb7a1a5ec927
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import <Cocoa/Cocoa.h>
7 #include "base/mac/scoped_nsobject.h"
8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
9 #import "chrome/browser/ui/cocoa/gradient_button_cell.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/platform_test.h"
13 @interface GradientButtonCell (HoverValueTesting)
14 - (void)performOnePulseStep;
15 @end
17 namespace {
19 class GradientButtonCellTest : public CocoaTest {
20  public:
21   GradientButtonCellTest() {
22     NSRect frame = NSMakeRect(0, 0, 50, 30);
23     base::scoped_nsobject<NSButton> view(
24         [[NSButton alloc] initWithFrame:frame]);
25     view_ = view.get();
26     base::scoped_nsobject<GradientButtonCell> cell(
27         [[GradientButtonCell alloc] initTextCell:@"Testing"]);
28     [view_ setCell:cell.get()];
29     [[test_window() contentView] addSubview:view_];
30   }
32   NSButton* view_;
35 TEST_VIEW(GradientButtonCellTest, view_)
37 // Test drawing, mostly to ensure nothing leaks or crashes.
38 TEST_F(GradientButtonCellTest, DisplayWithHover) {
39   [[view_ cell] setHoverAlpha:0.0];
40   [view_ display];
41   [[view_ cell] setHoverAlpha:0.5];
42   [view_ display];
43   [[view_ cell] setHoverAlpha:1.0];
44   [view_ display];
47 // Test hover, mostly to ensure nothing leaks or crashes.
48 TEST_F(GradientButtonCellTest, Hover) {
49   GradientButtonCell* cell = [view_ cell];
50   [cell setMouseInside:YES animate:NO];
51   EXPECT_EQ([[view_ cell] hoverAlpha], 1.0);
53   [cell setMouseInside:NO animate:YES];
54   CGFloat alpha1 = [cell hoverAlpha];
55   [cell performOnePulseStep];
56   CGFloat alpha2 = [cell hoverAlpha];
57   EXPECT_TRUE(alpha2 < alpha1);
60 // Tracking rects
61 TEST_F(GradientButtonCellTest, TrackingRects) {
62   GradientButtonCell* cell = [view_ cell];
63   EXPECT_FALSE([cell showsBorderOnlyWhileMouseInside]);
64   EXPECT_FALSE([cell isMouseInside]);
66   [cell setShowsBorderOnlyWhileMouseInside:YES];
67   [cell mouseEntered:nil];
68   EXPECT_TRUE([cell isMouseInside]);
69   [cell mouseExited:nil];
70   EXPECT_FALSE([cell isMouseInside]);
72   [cell setShowsBorderOnlyWhileMouseInside:NO];
73   EXPECT_FALSE([cell isMouseInside]);
75   [cell setShowsBorderOnlyWhileMouseInside:YES];
76   [cell setShowsBorderOnlyWhileMouseInside:YES];
77   [cell setShowsBorderOnlyWhileMouseInside:NO];
78   [cell setShowsBorderOnlyWhileMouseInside:NO];
81 TEST_F(GradientButtonCellTest, ContinuousPulseOnOff) {
82   GradientButtonCell* cell = [view_ cell];
84   // On/off
85   EXPECT_FALSE([cell isContinuousPulsing]);
86   [cell setIsContinuousPulsing:YES];
87   EXPECT_TRUE([cell isContinuousPulsing]);
88   EXPECT_TRUE([cell pulsing]);
89   [cell setIsContinuousPulsing:NO];
90   EXPECT_FALSE([cell isContinuousPulsing]);
92   // On/safeOff
93   [cell setIsContinuousPulsing:YES];
94   EXPECT_TRUE([cell isContinuousPulsing]);
95   [cell safelyStopPulsing];
98 // More for valgrind; we don't confirm state change does anything useful.
99 TEST_F(GradientButtonCellTest, PulseState) {
100   GradientButtonCell* cell = [view_ cell];
102   [cell setMouseInside:YES animate:YES];
103   // Allow for immediate state changes to keep test unflaky
104   EXPECT_TRUE(([cell pulseState] == gradient_button_cell::kPulsingOn) ||
105               ([cell pulseState] == gradient_button_cell::kPulsedOn));
107   [cell setMouseInside:NO animate:YES];
108   // Allow for immediate state changes to keep test unflaky
109   EXPECT_TRUE(([cell pulseState] == gradient_button_cell::kPulsingOff) ||
110               ([cell pulseState] == gradient_button_cell::kPulsedOff));
113 // Test drawing when first responder, mostly to ensure nothing leaks or
114 // crashes.
115 TEST_F(GradientButtonCellTest, FirstResponder) {
116   [test_window() makePretendKeyWindowAndSetFirstResponder:view_];
117   [view_ display];
120 }  // namespace