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

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

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

Powered by Google App Engine
This is Rietveld 408576698