OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #import <Cocoa/Cocoa.h> | |
6 | |
7 #include "base/memory/scoped_nsobject.h" | |
8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | |
9 #import "chrome/browser/ui/cocoa/hover_image_button.h" | |
10 #include "grit/theme_resources.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 #include "ui/base/resource/resource_bundle.h" | |
13 #include "ui/gfx/image/image.h" | |
14 | |
15 namespace { | |
16 | |
17 class HoverImageButtonTest : public CocoaTest { | |
18 public: | |
19 HoverImageButtonTest() { | |
20 NSRect content_frame = [[test_window() contentView] frame]; | |
21 scoped_nsobject<HoverImageButton> button( | |
22 [[HoverImageButton alloc] initWithFrame:content_frame]); | |
23 button_ = button.get(); | |
24 [[test_window() contentView] addSubview:button_]; | |
25 } | |
26 | |
27 void DrawRect() { | |
28 [button_ lockFocus]; | |
29 [button_ drawRect:[button_ bounds]]; | |
30 [button_ unlockFocus]; | |
31 } | |
32 | |
33 HoverImageButton* button_; | |
34 }; | |
35 | |
36 // Test mouse events. | |
37 TEST_F(HoverImageButtonTest, ImageSwap) { | |
38 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
39 NSImage* image = rb.GetNativeImageNamed(IDR_HOME).ToNSImage(); | |
40 NSImage* hover = rb.GetNativeImageNamed(IDR_BACK).ToNSImage(); | |
41 [button_ setDefaultImage:image]; | |
42 [button_ setHoverImage:hover]; | |
43 | |
44 [button_ mouseEntered:nil]; | |
45 DrawRect(); | |
46 EXPECT_EQ([button_ image], hover); | |
47 [button_ mouseExited:nil]; | |
48 DrawRect(); | |
49 EXPECT_NE([button_ image], hover); | |
50 EXPECT_EQ([button_ image], image); | |
51 } | |
52 | |
53 // Test mouse events. | |
54 TEST_F(HoverImageButtonTest, Opacity) { | |
55 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
56 NSImage* image = rb.GetNativeImageNamed(IDR_HOME).ToNSImage(); | |
57 [button_ setDefaultImage:image]; | |
58 [button_ setDefaultOpacity:0.5]; | |
59 [button_ setHoverImage:image]; | |
60 [button_ setHoverOpacity:1.0]; | |
61 | |
62 [button_ mouseEntered:nil]; | |
63 DrawRect(); | |
64 EXPECT_EQ([button_ alphaValue], 1.0); | |
65 [button_ mouseExited:nil]; | |
66 DrawRect(); | |
67 EXPECT_EQ([button_ alphaValue], 0.5); | |
68 } | |
69 | |
70 } // namespace | |
OLD | NEW |