Extensions cleanup: Merge IsSyncableApp+Extension, ShouldSyncApp+Extension
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / image_button_cell_unittest.mm
blob84d1191e4899590f42b2dcbb680ea1298cf59bfa
1 // Copyright (c) 2012 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 #include "base/mac/scoped_nsobject.h"
6 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
7 #import "chrome/browser/ui/cocoa/image_button_cell.h"
8 #include "grit/theme_resources.h"
10 namespace {
12 class ImageButtonCellTest : public CocoaTest {
13  public:
14   ImageButtonCellTest() {
15     NSRect frame = NSMakeRect(0, 0, 50, 30);
16     base::scoped_nsobject<NSButton> view(
17         [[NSButton alloc] initWithFrame:frame]);
18     view_ = view.get();
19     base::scoped_nsobject<ImageButtonCell> cell(
20         [[ImageButtonCell alloc] initTextCell:@""]);
21     [view_ setCell:cell.get()];
22     [[test_window() contentView] addSubview:view_];
23   }
25   void SetImages() {
26     [[view_ cell] setImageID:IDR_BACK
27               forButtonState:image_button_cell::kDefaultState];
28     [[view_ cell] setImageID:IDR_BACK_H
29               forButtonState:image_button_cell::kHoverState];
30     [[view_ cell] setImageID:IDR_BACK_P
31               forButtonState:image_button_cell::kPressedState];
32     [[view_ cell] setImageID:IDR_BACK_D
33               forButtonState:image_button_cell::kDisabledState];
34   }
36   NSButton* view_;
39 // Test drawing, mostly to ensure nothing leaks or crashes.
40 TEST_F(ImageButtonCellTest, DisplayWithHover) {
41   SetImages();
42   EXPECT_FALSE([[view_ cell] isMouseInside]);
43   [view_ display];
44   [[view_ cell] setIsMouseInside:YES];
45   [view_ display];
47   // Unset the hover image and draw.
48   [[view_ cell] setImageID:0
49             forButtonState:image_button_cell::kHoverState];
50   [view_ display];
53 // Test drawing, mostly to ensure nothing leaks or crashes.
54 TEST_F(ImageButtonCellTest, DisplayWithPressed) {
55   SetImages();
56   EXPECT_FALSE([[view_ cell] isHighlighted]);
57   [view_ display];
58   [[view_ cell] setHighlighted:YES];
59   [view_ display];
61   // Unset the pressed image and draw.
62   [[view_ cell] setImageID:0
63             forButtonState:image_button_cell::kPressedState];
64   [view_ display];
67 // Test drawing, mostly to ensure nothing leaks or crashes.
68 TEST_F(ImageButtonCellTest, DisplayWithDisabled) {
69   SetImages();
70   EXPECT_TRUE([[view_ cell] isEnabled]);
71   [view_ display];
72   [[view_ cell] setEnabled:NO];
73   [view_ display];
75   // Unset the disabled image and draw.
76   [[view_ cell] setImageID:0
77             forButtonState:image_button_cell::kDisabledState];
78   [view_ display];
81 TEST_F(ImageButtonCellTest, NewImageCausesDisplay) {
82   [[view_ cell] setImageID:IDR_STOP
83             forButtonState:image_button_cell::kDefaultState];
84   [view_ display];
85   EXPECT_FALSE([view_ needsDisplay]);
87   [[view_ cell] setImageID:IDR_RELOAD
88             forButtonState:image_button_cell::kDefaultState];
89   EXPECT_TRUE([view_ needsDisplay]);
92 } // namespace