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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/button/image_button_unittest.cc
diff --git a/ui/views/controls/button/image_button_unittest.cc b/ui/views/controls/button/image_button_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9d9a9b1ee01ba9b138e94b1512a91d9b7b172705
--- /dev/null
+++ b/ui/views/controls/button/image_button_unittest.cc
@@ -0,0 +1,82 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/views/controls/button/image_button.h"
+#include "ui/views/test/views_test_base.h"
+
+namespace {
+
+SkBitmap CreateTestBitmap(int width, int height) {
+ SkBitmap bitmap;
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
+ bitmap.allocPixels();
+ return bitmap;
+}
+
+} // namespace
+
+namespace views {
+
+typedef ViewsTestBase ImageButtonTest;
+
+TEST_F(ImageButtonTest, Basics) {
+ ImageButton button(NULL);
+
+ // Our image to paint starts empty.
+ EXPECT_TRUE(button.GetImageToPaint().empty());
+
+ // Without a theme, buttons are 16x14 by default.
+ EXPECT_EQ("16x14", button.GetPreferredSize().ToString());
+
+ // We can set a preferred size when we have no image.
+ button.SetPreferredSize(gfx::Size(5, 15));
+ EXPECT_EQ("5x15", button.GetPreferredSize().ToString());
+
+ // Set a normal image.
+ SkBitmap normal_bitmap = CreateTestBitmap(10, 20);
+ button.SetImage(CustomButton::BS_NORMAL, &normal_bitmap);
+
+ // Image uses normal image for painting.
+ EXPECT_FALSE(button.GetImageToPaint().empty());
+ EXPECT_EQ(10, button.GetImageToPaint().width());
+ EXPECT_EQ(20, button.GetImageToPaint().height());
+
+ // Preferred size is the normal button size.
+ EXPECT_EQ("10x20", button.GetPreferredSize().ToString());
+
+ // Set a pushed image.
+ SkBitmap pushed_bitmap = CreateTestBitmap(11, 21);
+ button.SetImage(CustomButton::BS_PUSHED, &pushed_bitmap);
+
+ // By convention, preferred size doesn't change, even though pushed image
+ // is bigger.
+ EXPECT_EQ("10x20", button.GetPreferredSize().ToString());
+
+ // We're still painting the normal image.
+ EXPECT_FALSE(button.GetImageToPaint().empty());
+ EXPECT_EQ(10, button.GetImageToPaint().width());
+ EXPECT_EQ(20, button.GetImageToPaint().height());
+
+ // Set an overlay bitmap.
+ SkBitmap overlay_bitmap = CreateTestBitmap(12, 22);
+ button.SetOverlayImage(&overlay_bitmap);
+ EXPECT_EQ(12, button.overlay_image_.width());
+ EXPECT_EQ(22, button.overlay_image_.height());
+
+ // By convention, preferred size doesn't change, even though pushed image
+ // is bigger.
+ EXPECT_EQ("10x20", button.GetPreferredSize().ToString());
+
+ // We're still painting the normal image.
+ EXPECT_FALSE(button.GetImageToPaint().empty());
+ EXPECT_EQ(10, button.GetImageToPaint().width());
+ EXPECT_EQ(20, button.GetImageToPaint().height());
+
+ // Reset the overlay bitmap.
+ button.SetOverlayImage(NULL);
+ EXPECT_TRUE(button.overlay_image_.empty());
+}
+
+} // namespace views
« 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