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

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

Issue 2480813003: Reduce views::Border creation verbosity by promoting factory functions (Closed)
Patch Set: fix bad merge Created 4 years, 1 month 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 "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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 TEST_F(ImageButtonTest, ImagePositionWithBorder) { 99 TEST_F(ImageButtonTest, ImagePositionWithBorder) {
100 ImageButton button(NULL); 100 ImageButton button(NULL);
101 gfx::ImageSkia image = CreateTestImage(20, 30); 101 gfx::ImageSkia image = CreateTestImage(20, 30);
102 button.SetImage(CustomButton::STATE_NORMAL, &image); 102 button.SetImage(CustomButton::STATE_NORMAL, &image);
103 103
104 // The image should be painted at the top-left corner. 104 // The image should be painted at the top-left corner.
105 EXPECT_EQ(gfx::Point().ToString(), 105 EXPECT_EQ(gfx::Point().ToString(),
106 button.ComputeImagePaintPosition(image).ToString()); 106 button.ComputeImagePaintPosition(image).ToString());
107 107
108 button.SetBorder(views::Border::CreateEmptyBorder(10, 5, 0, 0)); 108 button.SetBorder(views::CreateEmptyBorder(10, 5, 0, 0));
109 EXPECT_EQ(gfx::Point(5, 10).ToString(), 109 EXPECT_EQ(gfx::Point(5, 10).ToString(),
110 button.ComputeImagePaintPosition(image).ToString()); 110 button.ComputeImagePaintPosition(image).ToString());
111 111
112 button.SetBorder(Border::NullBorder()); 112 button.SetBorder(NullBorder());
113 button.SetBounds(0, 0, 50, 50); 113 button.SetBounds(0, 0, 50, 50);
114 EXPECT_EQ(gfx::Point().ToString(), 114 EXPECT_EQ(gfx::Point().ToString(),
115 button.ComputeImagePaintPosition(image).ToString()); 115 button.ComputeImagePaintPosition(image).ToString());
116 116
117 button.SetImageAlignment(ImageButton::ALIGN_CENTER, 117 button.SetImageAlignment(ImageButton::ALIGN_CENTER,
118 ImageButton::ALIGN_MIDDLE); 118 ImageButton::ALIGN_MIDDLE);
119 EXPECT_EQ(gfx::Point(15, 10).ToString(), 119 EXPECT_EQ(gfx::Point(15, 10).ToString(),
120 button.ComputeImagePaintPosition(image).ToString()); 120 button.ComputeImagePaintPosition(image).ToString());
121 button.SetBorder(views::Border::CreateEmptyBorder(10, 10, 0, 0)); 121 button.SetBorder(views::CreateEmptyBorder(10, 10, 0, 0));
122 EXPECT_EQ(gfx::Point(20, 15).ToString(), 122 EXPECT_EQ(gfx::Point(20, 15).ToString(),
123 button.ComputeImagePaintPosition(image).ToString()); 123 button.ComputeImagePaintPosition(image).ToString());
124 124
125 // The entire button's size should take the border into account. 125 // The entire button's size should take the border into account.
126 EXPECT_EQ(gfx::Size(30, 40).ToString(), button.GetPreferredSize().ToString()); 126 EXPECT_EQ(gfx::Size(30, 40).ToString(), button.GetPreferredSize().ToString());
127 127
128 // The border should be added on top of the minimum image size. 128 // The border should be added on top of the minimum image size.
129 button.SetMinimumImageSize(gfx::Size(30, 5)); 129 button.SetMinimumImageSize(gfx::Size(30, 5));
130 EXPECT_EQ(gfx::Size(40, 40).ToString(), button.GetPreferredSize().ToString()); 130 EXPECT_EQ(gfx::Size(40, 40).ToString(), button.GetPreferredSize().ToString());
131 } 131 }
(...skipping 22 matching lines...) Expand all
154 ImageButton::ALIGN_BOTTOM); 154 ImageButton::ALIGN_BOTTOM);
155 button.SetDrawImageMirrored(true); 155 button.SetDrawImageMirrored(true);
156 156
157 // Because the coordinates are flipped, we should expect this to draw as if 157 // Because the coordinates are flipped, we should expect this to draw as if
158 // it were ALIGN_LEFT. 158 // it were ALIGN_LEFT.
159 EXPECT_EQ(gfx::Point(0, 0).ToString(), 159 EXPECT_EQ(gfx::Point(0, 0).ToString(),
160 button.ComputeImagePaintPosition(image).ToString()); 160 button.ComputeImagePaintPosition(image).ToString());
161 } 161 }
162 162
163 } // namespace views 163 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/color_chooser/color_chooser_view.cc ('k') | ui/views/controls/button/md_text_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698