| OLD | NEW |
| 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 <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "base/memory/scoped_nsobject.h" | 7 #include "base/memory/scoped_nsobject.h" |
| 8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 9 #import "chrome/browser/ui/cocoa/hover_image_button.h" | 9 #import "chrome/browser/ui/cocoa/hover_image_button.h" |
| 10 #include "grit/theme_resources.h" | 10 #include "grit/theme_resources.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 [button_ drawRect:[button_ bounds]]; | 29 [button_ drawRect:[button_ bounds]]; |
| 30 [button_ unlockFocus]; | 30 [button_ unlockFocus]; |
| 31 } | 31 } |
| 32 | 32 |
| 33 HoverImageButton* button_; | 33 HoverImageButton* button_; |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 // Test mouse events. | 36 // Test mouse events. |
| 37 TEST_F(HoverImageButtonTest, ImageSwap) { | 37 TEST_F(HoverImageButtonTest, ImageSwap) { |
| 38 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 38 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 39 NSImage* image = rb.GetNativeImageNamed(IDR_HOME); | 39 NSImage* image = rb.GetNativeImageNamed(IDR_HOME).ToNSImage(); |
| 40 NSImage* hover = rb.GetNativeImageNamed(IDR_BACK); | 40 NSImage* hover = rb.GetNativeImageNamed(IDR_BACK).ToNSImage(); |
| 41 [button_ setDefaultImage:image]; | 41 [button_ setDefaultImage:image]; |
| 42 [button_ setHoverImage:hover]; | 42 [button_ setHoverImage:hover]; |
| 43 | 43 |
| 44 [button_ mouseEntered:nil]; | 44 [button_ mouseEntered:nil]; |
| 45 DrawRect(); | 45 DrawRect(); |
| 46 EXPECT_EQ([button_ image], hover); | 46 EXPECT_EQ([button_ image], hover); |
| 47 [button_ mouseExited:nil]; | 47 [button_ mouseExited:nil]; |
| 48 DrawRect(); | 48 DrawRect(); |
| 49 EXPECT_NE([button_ image], hover); | 49 EXPECT_NE([button_ image], hover); |
| 50 EXPECT_EQ([button_ image], image); | 50 EXPECT_EQ([button_ image], image); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Test mouse events. | 53 // Test mouse events. |
| 54 TEST_F(HoverImageButtonTest, Opacity) { | 54 TEST_F(HoverImageButtonTest, Opacity) { |
| 55 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 55 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 56 NSImage* image = rb.GetNativeImageNamed(IDR_HOME); | 56 NSImage* image = rb.GetNativeImageNamed(IDR_HOME).ToNSImage(); |
| 57 [button_ setDefaultImage:image]; | 57 [button_ setDefaultImage:image]; |
| 58 [button_ setDefaultOpacity:0.5]; | 58 [button_ setDefaultOpacity:0.5]; |
| 59 [button_ setHoverImage:image]; | 59 [button_ setHoverImage:image]; |
| 60 [button_ setHoverOpacity:1.0]; | 60 [button_ setHoverOpacity:1.0]; |
| 61 | 61 |
| 62 [button_ mouseEntered:nil]; | 62 [button_ mouseEntered:nil]; |
| 63 DrawRect(); | 63 DrawRect(); |
| 64 EXPECT_EQ([button_ alphaValue], 1.0); | 64 EXPECT_EQ([button_ alphaValue], 1.0); |
| 65 [button_ mouseExited:nil]; | 65 [button_ mouseExited:nil]; |
| 66 DrawRect(); | 66 DrawRect(); |
| 67 EXPECT_EQ([button_ alphaValue], 0.5); | 67 EXPECT_EQ([button_ alphaValue], 0.5); |
| 68 } | 68 } |
| 69 | 69 |
| 70 } // namespace | 70 } // namespace |
| OLD | NEW |