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

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

Issue 2744463002: Add VectorIconButton functionality to ImageButton. (Closed)
Patch Set: WIP: use observer Created 3 years, 9 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
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 "ui/views/controls/button/image_button.h"
6
5 #include "base/macros.h" 7 #include "base/macros.h"
6 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/base/layout.h" 9 #include "ui/base/layout.h"
10 #include "ui/vector_icons/vector_icons.h"
8 #include "ui/views/border.h" 11 #include "ui/views/border.h"
9 #include "ui/views/controls/button/image_button.h"
10 #include "ui/views/test/views_test_base.h" 12 #include "ui/views/test/views_test_base.h"
11 13
12 namespace { 14 namespace {
13 15
14 gfx::ImageSkia CreateTestImage(int width, int height) { 16 gfx::ImageSkia CreateTestImage(int width, int height) {
15 SkBitmap bitmap; 17 SkBitmap bitmap;
16 bitmap.allocN32Pixels(width, height); 18 bitmap.allocN32Pixels(width, height);
17 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); 19 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
18 } 20 }
19 21
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 EXPECT_EQ(0, parent.pref_size_changed_calls()); 194 EXPECT_EQ(0, parent.pref_size_changed_calls());
193 195
194 button.SetImage(CustomButton::STATE_HOVERED, &second_image); 196 button.SetImage(CustomButton::STATE_HOVERED, &second_image);
195 EXPECT_EQ(0, parent.pref_size_changed_calls()); 197 EXPECT_EQ(0, parent.pref_size_changed_calls());
196 198
197 // Changing normal state image size leads to a change in preferred size. 199 // Changing normal state image size leads to a change in preferred size.
198 button.SetImage(CustomButton::STATE_NORMAL, &second_image); 200 button.SetImage(CustomButton::STATE_NORMAL, &second_image);
199 EXPECT_EQ(1, parent.pref_size_changed_calls()); 201 EXPECT_EQ(1, parent.pref_size_changed_calls());
200 } 202 }
201 203
204 TEST_F(ImageButtonTest, Padding) {
205 ImageButton button(nullptr);
206 gfx::ImageSkia image = CreateTestImage(5, 10);
207 button.SetImage(CustomButton::STATE_NORMAL, &image);
208
209 button.SetPadding(gfx::Insets(2, 5, 7, 13));
210 EXPECT_EQ("23x19", button.GetPreferredSize().ToString());
211
212 button.SetPadding(gfx::Insets());
213 EXPECT_EQ("5x10", button.GetPreferredSize().ToString());
214 }
215
202 } // namespace views 216 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698