Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: ui/base/cocoa/hover_image_button_unittest.mm

Issue 12937008: Move HoverButton and HoverImageButton from chrome/browser/ui/cocoa/ to ui/base/cocoa. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/base/cocoa/hover_image_button.mm ('k') | ui/ui.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "ui/base/cocoa/hover_image_button.h"
6 6
7 #include "base/memory/scoped_nsobject.h" 7 #import "base/memory/scoped_nsobject.h"
8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" 8 #import "ui/base/test/ui_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 9
15 namespace { 10 namespace {
16 11
17 class HoverImageButtonTest : public CocoaTest { 12 class HoverImageButtonTest : public ui::CocoaTest {
18 public: 13 public:
19 HoverImageButtonTest() { 14 HoverImageButtonTest() {
20 NSRect content_frame = [[test_window() contentView] frame]; 15 NSRect content_frame = [[test_window() contentView] frame];
21 scoped_nsobject<HoverImageButton> button( 16 scoped_nsobject<HoverImageButton> button(
22 [[HoverImageButton alloc] initWithFrame:content_frame]); 17 [[HoverImageButton alloc] initWithFrame:content_frame]);
23 button_ = button.get(); 18 button_ = button.get();
24 [[test_window() contentView] addSubview:button_]; 19 [[test_window() contentView] addSubview:button_];
25 } 20 }
26 21
27 void DrawRect() { 22 void DrawRect() {
28 [button_ lockFocus]; 23 [button_ lockFocus];
29 [button_ drawRect:[button_ bounds]]; 24 [button_ drawRect:[button_ bounds]];
30 [button_ unlockFocus]; 25 [button_ unlockFocus];
31 } 26 }
32 27
33 HoverImageButton* button_; 28 HoverImageButton* button_;
34 }; 29 };
35 30
36 // Test mouse events. 31 // Test mouse events.
37 TEST_F(HoverImageButtonTest, ImageSwap) { 32 TEST_F(HoverImageButtonTest, ImageSwap) {
38 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 33 NSImage* image = [NSImage imageNamed:NSImageNameStatusAvailable];
39 NSImage* image = rb.GetNativeImageNamed(IDR_HOME).ToNSImage(); 34 NSImage* hover = [NSImage imageNamed:NSImageNameStatusNone];
40 NSImage* hover = rb.GetNativeImageNamed(IDR_BACK).ToNSImage();
41 [button_ setDefaultImage:image]; 35 [button_ setDefaultImage:image];
42 [button_ setHoverImage:hover]; 36 [button_ setHoverImage:hover];
43 37
44 [button_ mouseEntered:nil]; 38 [button_ mouseEntered:nil];
45 DrawRect(); 39 DrawRect();
46 EXPECT_EQ([button_ image], hover); 40 EXPECT_EQ([button_ image], hover);
47 [button_ mouseExited:nil]; 41 [button_ mouseExited:nil];
48 DrawRect(); 42 DrawRect();
49 EXPECT_NE([button_ image], hover); 43 EXPECT_NE([button_ image], hover);
50 EXPECT_EQ([button_ image], image); 44 EXPECT_EQ([button_ image], image);
51 } 45 }
52 46
53 // Test mouse events. 47 // Test mouse events.
54 TEST_F(HoverImageButtonTest, Opacity) { 48 TEST_F(HoverImageButtonTest, Opacity) {
55 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 49 NSImage* image = [NSImage imageNamed:NSImageNameStatusAvailable];
56 NSImage* image = rb.GetNativeImageNamed(IDR_HOME).ToNSImage();
57 [button_ setDefaultImage:image]; 50 [button_ setDefaultImage:image];
58 [button_ setDefaultOpacity:0.5]; 51 [button_ setDefaultOpacity:0.5];
59 [button_ setHoverImage:image]; 52 [button_ setHoverImage:image];
60 [button_ setHoverOpacity:1.0]; 53 [button_ setHoverOpacity:1.0];
61 54
62 [button_ mouseEntered:nil]; 55 [button_ mouseEntered:nil];
63 DrawRect(); 56 DrawRect();
64 EXPECT_EQ([button_ alphaValue], 1.0); 57 EXPECT_EQ([button_ alphaValue], 1.0);
65 [button_ mouseExited:nil]; 58 [button_ mouseExited:nil];
66 DrawRect(); 59 DrawRect();
67 EXPECT_EQ([button_ alphaValue], 0.5); 60 EXPECT_EQ([button_ alphaValue], 0.5);
68 } 61 }
69 62
70 } // namespace 63 } // namespace
OLDNEW
« no previous file with comments | « ui/base/cocoa/hover_image_button.mm ('k') | ui/ui.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698