- add sources.
[platform/framework/web/crosswalk.git] / src / ui / base / cocoa / hover_image_button_unittest.mm
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 "ui/base/cocoa/hover_image_button.h"
6
7 #import "base/mac/scoped_nsobject.h"
8 #import "ui/base/test/ui_cocoa_test_helper.h"
9
10 namespace {
11
12 class HoverImageButtonTest : public ui::CocoaTest {
13  public:
14   HoverImageButtonTest() {
15     NSRect content_frame = [[test_window() contentView] frame];
16     base::scoped_nsobject<HoverImageButton> button(
17         [[HoverImageButton alloc] initWithFrame:content_frame]);
18     button_ = button.get();
19     [[test_window() contentView] addSubview:button_];
20   }
21
22   void DrawRect() {
23     [button_ lockFocus];
24     [button_ drawRect:[button_ bounds]];
25     [button_ unlockFocus];
26   }
27
28   HoverImageButton* button_;
29 };
30
31 // Test mouse events.
32 TEST_F(HoverImageButtonTest, ImageSwap) {
33   NSImage* image = [NSImage imageNamed:NSImageNameStatusAvailable];
34   NSImage* hover = [NSImage imageNamed:NSImageNameStatusNone];
35   [button_ setDefaultImage:image];
36   [button_ setHoverImage:hover];
37
38   [button_ mouseEntered:nil];
39   DrawRect();
40   EXPECT_EQ([button_ image], hover);
41   [button_ mouseExited:nil];
42   DrawRect();
43   EXPECT_NE([button_ image], hover);
44   EXPECT_EQ([button_ image], image);
45 }
46
47 }  // namespace