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"
12 class ImageButtonCellTest : public CocoaTest {
14 ImageButtonCellTest() {
15 NSRect frame = NSMakeRect(0, 0, 50, 30);
16 base::scoped_nsobject<NSButton> view(
17 [[NSButton alloc] initWithFrame:frame]);
19 base::scoped_nsobject<ImageButtonCell> cell(
20 [[ImageButtonCell alloc] initTextCell:@""]);
21 [view_ setCell:cell.get()];
22 [[test_window() contentView] addSubview:view_];
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];
39 // Test drawing, mostly to ensure nothing leaks or crashes.
40 TEST_F(ImageButtonCellTest, DisplayWithHover) {
42 EXPECT_FALSE([[view_ cell] isMouseInside]);
44 [[view_ cell] setIsMouseInside:YES];
47 // Unset the hover image and draw.
48 [[view_ cell] setImageID:0
49 forButtonState:image_button_cell::kHoverState];
53 // Test drawing, mostly to ensure nothing leaks or crashes.
54 TEST_F(ImageButtonCellTest, DisplayWithPressed) {
56 EXPECT_FALSE([[view_ cell] isHighlighted]);
58 [[view_ cell] setHighlighted:YES];
61 // Unset the pressed image and draw.
62 [[view_ cell] setImageID:0
63 forButtonState:image_button_cell::kPressedState];
67 // Test drawing, mostly to ensure nothing leaks or crashes.
68 TEST_F(ImageButtonCellTest, DisplayWithDisabled) {
70 EXPECT_TRUE([[view_ cell] isEnabled]);
72 [[view_ cell] setEnabled:NO];
75 // Unset the disabled image and draw.
76 [[view_ cell] setImageID:0
77 forButtonState:image_button_cell::kDisabledState];
81 TEST_F(ImageButtonCellTest, NewImageCausesDisplay) {
82 [[view_ cell] setImageID:IDR_STOP
83 forButtonState:image_button_cell::kDefaultState];
85 EXPECT_FALSE([view_ needsDisplay]);
87 [[view_ cell] setImageID:IDR_RELOAD
88 forButtonState:image_button_cell::kDefaultState];
89 EXPECT_TRUE([view_ needsDisplay]);