1// Copyright (c) 2011 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 "testing/platform_test.h" 13#include "ui/base/resource/resource_bundle.h" 14#include "ui/gfx/image.h" 15 16namespace { 17 18class HoverImageButtonTest : public CocoaTest { 19 public: 20 HoverImageButtonTest() { 21 NSRect content_frame = [[test_window() contentView] frame]; 22 scoped_nsobject<HoverImageButton> button( 23 [[HoverImageButton alloc] initWithFrame:content_frame]); 24 button_ = button.get(); 25 [[test_window() contentView] addSubview:button_]; 26 } 27 28 virtual void SetUp() { 29 CocoaTest::BootstrapCocoa(); 30 } 31 32 HoverImageButton* button_; 33}; 34 35// Test mouse events. 36TEST_F(HoverImageButtonTest, ImageSwap) { 37 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 38 NSImage* image = rb.GetNativeImageNamed(IDR_HOME); 39 NSImage* hover = rb.GetNativeImageNamed(IDR_BACK); 40 [button_ setDefaultImage:image]; 41 [button_ setHoverImage:hover]; 42 43 [button_ mouseEntered:nil]; 44 [button_ drawRect:[button_ frame]]; 45 EXPECT_EQ([button_ image], hover); 46 [button_ mouseExited:nil]; 47 [button_ drawRect:[button_ frame]]; 48 EXPECT_EQ([button_ image], image); 49} 50 51// Test mouse events. 52TEST_F(HoverImageButtonTest, Opacity) { 53 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 54 NSImage* image = rb.GetNativeImageNamed(IDR_HOME); 55 [button_ setDefaultImage:image]; 56 [button_ setDefaultOpacity:0.5]; 57 [button_ setHoverImage:image]; 58 [button_ setHoverOpacity:1.0]; 59 60 [button_ mouseEntered:nil]; 61 [button_ drawRect:[button_ frame]]; 62 EXPECT_EQ([button_ alphaValue], 1.0); 63 [button_ mouseExited:nil]; 64 [button_ drawRect:[button_ frame]]; 65 EXPECT_EQ([button_ alphaValue], 0.5); 66} 67 68} // namespace 69