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

Side by Side Diff: ui/views/controls/button/image_button_unittest.cc

Issue 10174014: views: Add optional overlay image to ImageButton (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove debugging tweak Created 8 years, 8 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/views/controls/button/image_button.cc ('k') | ui/views/examples/button_example.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "testing/gtest/include/gtest/gtest.h"
6 #include "ui/views/controls/button/image_button.h"
7 #include "ui/views/test/views_test_base.h"
8
9 namespace {
10
11 SkBitmap CreateTestBitmap(int width, int height) {
12 SkBitmap bitmap;
13 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
14 bitmap.allocPixels();
15 return bitmap;
16 }
17
18 } // namespace
19
20 namespace views {
21
22 typedef ViewsTestBase ImageButtonTest;
23
24 TEST_F(ImageButtonTest, Basics) {
25 ImageButton button(NULL);
26
27 // Our image to paint starts empty.
28 EXPECT_TRUE(button.GetImageToPaint().empty());
29
30 // Without a theme, buttons are 16x14 by default.
31 EXPECT_EQ("16x14", button.GetPreferredSize().ToString());
32
33 // We can set a preferred size when we have no image.
34 button.SetPreferredSize(gfx::Size(5, 15));
35 EXPECT_EQ("5x15", button.GetPreferredSize().ToString());
36
37 // Set a normal image.
38 SkBitmap normal_bitmap = CreateTestBitmap(10, 20);
39 button.SetImage(CustomButton::BS_NORMAL, &normal_bitmap);
40
41 // Image uses normal image for painting.
42 EXPECT_FALSE(button.GetImageToPaint().empty());
43 EXPECT_EQ(10, button.GetImageToPaint().width());
44 EXPECT_EQ(20, button.GetImageToPaint().height());
45
46 // Preferred size is the normal button size.
47 EXPECT_EQ("10x20", button.GetPreferredSize().ToString());
48
49 // Set a pushed image.
50 SkBitmap pushed_bitmap = CreateTestBitmap(11, 21);
51 button.SetImage(CustomButton::BS_PUSHED, &pushed_bitmap);
52
53 // By convention, preferred size doesn't change, even though pushed image
54 // is bigger.
55 EXPECT_EQ("10x20", button.GetPreferredSize().ToString());
56
57 // We're still painting the normal image.
58 EXPECT_FALSE(button.GetImageToPaint().empty());
59 EXPECT_EQ(10, button.GetImageToPaint().width());
60 EXPECT_EQ(20, button.GetImageToPaint().height());
61
62 // Set an overlay bitmap.
63 SkBitmap overlay_bitmap = CreateTestBitmap(12, 22);
64 button.SetOverlayImage(&overlay_bitmap);
65 EXPECT_EQ(12, button.overlay_image_.width());
66 EXPECT_EQ(22, button.overlay_image_.height());
67
68 // By convention, preferred size doesn't change, even though pushed image
69 // is bigger.
70 EXPECT_EQ("10x20", button.GetPreferredSize().ToString());
71
72 // We're still painting the normal image.
73 EXPECT_FALSE(button.GetImageToPaint().empty());
74 EXPECT_EQ(10, button.GetImageToPaint().width());
75 EXPECT_EQ(20, button.GetImageToPaint().height());
76
77 // Reset the overlay bitmap.
78 button.SetOverlayImage(NULL);
79 EXPECT_TRUE(button.overlay_image_.empty());
80 }
81
82 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/image_button.cc ('k') | ui/views/examples/button_example.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698