| OLD | NEW |
| 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/border.h" | 7 #include "ui/views/border.h" |
| 8 #include "ui/views/controls/button/image_button.h" | 8 #include "ui/views/controls/button/image_button.h" |
| 9 #include "ui/views/test/views_test_base.h" | 9 #include "ui/views/test/views_test_base.h" |
| 10 | 10 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 109 |
| 110 TEST_F(ImageButtonTest, ImagePositionWithBorder) { | 110 TEST_F(ImageButtonTest, ImagePositionWithBorder) { |
| 111 ImageButton button(NULL); | 111 ImageButton button(NULL); |
| 112 gfx::ImageSkia image = CreateTestImage(20, 30); | 112 gfx::ImageSkia image = CreateTestImage(20, 30); |
| 113 button.SetImage(CustomButton::STATE_NORMAL, &image); | 113 button.SetImage(CustomButton::STATE_NORMAL, &image); |
| 114 | 114 |
| 115 // The image should be painted at the top-left corner. | 115 // The image should be painted at the top-left corner. |
| 116 EXPECT_EQ(gfx::Point().ToString(), | 116 EXPECT_EQ(gfx::Point().ToString(), |
| 117 button.ComputeImagePaintPosition(image).ToString()); | 117 button.ComputeImagePaintPosition(image).ToString()); |
| 118 | 118 |
| 119 button.set_border(views::Border::CreateEmptyBorder(10, 5, 0, 0)); | 119 button.SetBorder(views::Border::CreateEmptyBorder(10, 5, 0, 0)); |
| 120 EXPECT_EQ(gfx::Point(5, 10).ToString(), | 120 EXPECT_EQ(gfx::Point(5, 10).ToString(), |
| 121 button.ComputeImagePaintPosition(image).ToString()); | 121 button.ComputeImagePaintPosition(image).ToString()); |
| 122 | 122 |
| 123 button.set_border(NULL); | 123 button.ClearBorder(); |
| 124 button.SetBounds(0, 0, 50, 50); | 124 button.SetBounds(0, 0, 50, 50); |
| 125 EXPECT_EQ(gfx::Point().ToString(), | 125 EXPECT_EQ(gfx::Point().ToString(), |
| 126 button.ComputeImagePaintPosition(image).ToString()); | 126 button.ComputeImagePaintPosition(image).ToString()); |
| 127 | 127 |
| 128 button.SetImageAlignment(ImageButton::ALIGN_CENTER, | 128 button.SetImageAlignment(ImageButton::ALIGN_CENTER, |
| 129 ImageButton::ALIGN_MIDDLE); | 129 ImageButton::ALIGN_MIDDLE); |
| 130 EXPECT_EQ(gfx::Point(15, 10).ToString(), | 130 EXPECT_EQ(gfx::Point(15, 10).ToString(), |
| 131 button.ComputeImagePaintPosition(image).ToString()); | 131 button.ComputeImagePaintPosition(image).ToString()); |
| 132 button.set_border(views::Border::CreateEmptyBorder(10, 10, 0, 0)); | 132 button.SetBorder(views::Border::CreateEmptyBorder(10, 10, 0, 0)); |
| 133 EXPECT_EQ(gfx::Point(20, 15).ToString(), | 133 EXPECT_EQ(gfx::Point(20, 15).ToString(), |
| 134 button.ComputeImagePaintPosition(image).ToString()); | 134 button.ComputeImagePaintPosition(image).ToString()); |
| 135 } | 135 } |
| 136 | 136 |
| 137 TEST_F(ImageButtonTest, LeftAlignedMirrored) { | 137 TEST_F(ImageButtonTest, LeftAlignedMirrored) { |
| 138 ImageButton button(NULL); | 138 ImageButton button(NULL); |
| 139 gfx::ImageSkia image = CreateTestImage(20, 30); | 139 gfx::ImageSkia image = CreateTestImage(20, 30); |
| 140 button.SetImage(CustomButton::STATE_NORMAL, &image); | 140 button.SetImage(CustomButton::STATE_NORMAL, &image); |
| 141 button.SetBounds(0, 0, 50, 30); | 141 button.SetBounds(0, 0, 50, 30); |
| 142 button.SetImageAlignment(ImageButton::ALIGN_LEFT, | 142 button.SetImageAlignment(ImageButton::ALIGN_LEFT, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 158 ImageButton::ALIGN_BOTTOM); | 158 ImageButton::ALIGN_BOTTOM); |
| 159 button.SetDrawImageMirrored(true); | 159 button.SetDrawImageMirrored(true); |
| 160 | 160 |
| 161 // Because the coordinates are flipped, we should expect this to draw as if | 161 // Because the coordinates are flipped, we should expect this to draw as if |
| 162 // it were ALIGN_LEFT. | 162 // it were ALIGN_LEFT. |
| 163 EXPECT_EQ(gfx::Point(0, 0).ToString(), | 163 EXPECT_EQ(gfx::Point(0, 0).ToString(), |
| 164 button.ComputeImagePaintPosition(image).ToString()); | 164 button.ComputeImagePaintPosition(image).ToString()); |
| 165 } | 165 } |
| 166 | 166 |
| 167 } // namespace views | 167 } // namespace views |
| OLD | NEW |