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 "base/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
6 #include "third_party/skia/include/core/SkBitmap.h" | 6 #include "third_party/skia/include/core/SkBitmap.h" |
7 #include "ui/gfx/canvas.h" | 7 #include "ui/gfx/canvas.h" |
8 #include "ui/gfx/font.h" | 8 #include "ui/gfx/font.h" |
9 #include "ui/gfx/size.h" | 9 #include "ui/gfx/size.h" |
10 #include "ui/views/controls/button/label_button.h" | 10 #include "ui/views/controls/button/label_button.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 TEST_F(LabelButtonTest, Init) { | 28 TEST_F(LabelButtonTest, Init) { |
29 const string16 text(ASCIIToUTF16("abc")); | 29 const string16 text(ASCIIToUTF16("abc")); |
30 LabelButton button(NULL, text); | 30 LabelButton button(NULL, text); |
31 | 31 |
32 EXPECT_TRUE(button.GetImage(CustomButton::BS_NORMAL).isNull()); | 32 EXPECT_TRUE(button.GetImage(CustomButton::BS_NORMAL).isNull()); |
33 EXPECT_TRUE(button.GetImage(CustomButton::BS_HOT).isNull()); | 33 EXPECT_TRUE(button.GetImage(CustomButton::BS_HOT).isNull()); |
34 EXPECT_TRUE(button.GetImage(CustomButton::BS_PUSHED).isNull()); | 34 EXPECT_TRUE(button.GetImage(CustomButton::BS_PUSHED).isNull()); |
35 EXPECT_TRUE(button.GetImage(CustomButton::BS_DISABLED).isNull()); | 35 EXPECT_TRUE(button.GetImage(CustomButton::BS_DISABLED).isNull()); |
36 | 36 |
37 EXPECT_EQ(text, button.GetText()); | 37 EXPECT_EQ(text, button.GetText()); |
38 EXPECT_EQ(Label::ALIGN_LEFT, button.GetHorizontalAlignment()); | 38 EXPECT_EQ(gfx::ALIGN_LEFT, button.GetHorizontalAlignment()); |
39 EXPECT_FALSE(button.default_button()); | 39 EXPECT_FALSE(button.default_button()); |
40 EXPECT_FALSE(button.native_theme()); | 40 EXPECT_FALSE(button.native_theme()); |
41 EXPECT_EQ(CustomButton::BS_NORMAL, button.state()); | 41 EXPECT_EQ(CustomButton::BS_NORMAL, button.state()); |
42 | 42 |
43 EXPECT_EQ(button.image_->parent(), &button); | 43 EXPECT_EQ(button.image_->parent(), &button); |
44 EXPECT_EQ(button.label_->parent(), &button); | 44 EXPECT_EQ(button.label_->parent(), &button); |
45 } | 45 } |
46 | 46 |
47 TEST_F(LabelButtonTest, Label) { | 47 TEST_F(LabelButtonTest, Label) { |
48 LabelButton button(NULL, string16()); | 48 LabelButton button(NULL, string16()); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 EXPECT_LT(button.GetPreferredSize().width(), text_width + image_size); | 128 EXPECT_LT(button.GetPreferredSize().width(), text_width + image_size); |
129 EXPECT_LT(button.GetPreferredSize().height(), image_size); | 129 EXPECT_LT(button.GetPreferredSize().height(), image_size); |
130 button.SetImage(CustomButton::BS_NORMAL, image); | 130 button.SetImage(CustomButton::BS_NORMAL, image); |
131 EXPECT_GT(button.GetPreferredSize().width(), text_width + image_size); | 131 EXPECT_GT(button.GetPreferredSize().width(), text_width + image_size); |
132 EXPECT_GT(button.GetPreferredSize().height(), image_size); | 132 EXPECT_GT(button.GetPreferredSize().height(), image_size); |
133 | 133 |
134 // Layout and ensure the image is left of the label except for ALIGN_RIGHT. | 134 // Layout and ensure the image is left of the label except for ALIGN_RIGHT. |
135 // (A proper parent view or layout manager would Layout on its invalidations). | 135 // (A proper parent view or layout manager would Layout on its invalidations). |
136 button.SetSize(button.GetPreferredSize()); | 136 button.SetSize(button.GetPreferredSize()); |
137 button.Layout(); | 137 button.Layout(); |
138 EXPECT_EQ(Label::ALIGN_LEFT, button.GetHorizontalAlignment()); | 138 EXPECT_EQ(gfx::ALIGN_LEFT, button.GetHorizontalAlignment()); |
139 EXPECT_LT(button.image_->bounds().right(), button.label_->bounds().x()); | 139 EXPECT_LT(button.image_->bounds().right(), button.label_->bounds().x()); |
140 button.SetHorizontalAlignment(Label::ALIGN_CENTER); | 140 button.SetHorizontalAlignment(gfx::ALIGN_CENTER); |
141 button.Layout(); | 141 button.Layout(); |
142 EXPECT_EQ(Label::ALIGN_CENTER, button.GetHorizontalAlignment()); | 142 EXPECT_EQ(gfx::ALIGN_CENTER, button.GetHorizontalAlignment()); |
143 EXPECT_LT(button.image_->bounds().right(), button.label_->bounds().x()); | 143 EXPECT_LT(button.image_->bounds().right(), button.label_->bounds().x()); |
144 button.SetHorizontalAlignment(Label::ALIGN_RIGHT); | 144 button.SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
145 button.Layout(); | 145 button.Layout(); |
146 EXPECT_EQ(Label::ALIGN_RIGHT, button.GetHorizontalAlignment()); | 146 EXPECT_EQ(gfx::ALIGN_RIGHT, button.GetHorizontalAlignment()); |
147 EXPECT_LT(button.label_->bounds().right(), button.image_->bounds().x()); | 147 EXPECT_LT(button.label_->bounds().right(), button.image_->bounds().x()); |
148 | 148 |
149 button.SetText(string16()); | 149 button.SetText(string16()); |
150 EXPECT_GT(button.GetPreferredSize().width(), text_width + image_size); | 150 EXPECT_GT(button.GetPreferredSize().width(), text_width + image_size); |
151 EXPECT_GT(button.GetPreferredSize().height(), image_size); | 151 EXPECT_GT(button.GetPreferredSize().height(), image_size); |
152 button.SetImage(CustomButton::BS_NORMAL, gfx::ImageSkia()); | 152 button.SetImage(CustomButton::BS_NORMAL, gfx::ImageSkia()); |
153 EXPECT_GT(button.GetPreferredSize().width(), text_width + image_size); | 153 EXPECT_GT(button.GetPreferredSize().width(), text_width + image_size); |
154 EXPECT_GT(button.GetPreferredSize().height(), image_size); | 154 EXPECT_GT(button.GetPreferredSize().height(), image_size); |
155 | 155 |
156 // Clamp the size to a maximum value. | 156 // Clamp the size to a maximum value. |
(...skipping 23 matching lines...) Expand all Loading... |
180 | 180 |
181 // The button returns to its original size when the minimal size is cleared | 181 // The button returns to its original size when the minimal size is cleared |
182 // and the original font size is restored. | 182 // and the original font size is restored. |
183 button.set_min_size(gfx::Size()); | 183 button.set_min_size(gfx::Size()); |
184 button.SetFont(original_font); | 184 button.SetFont(original_font); |
185 EXPECT_EQ(original_width, button.GetPreferredSize().width()); | 185 EXPECT_EQ(original_width, button.GetPreferredSize().width()); |
186 EXPECT_EQ(original_height, button.GetPreferredSize().height()); | 186 EXPECT_EQ(original_height, button.GetPreferredSize().height()); |
187 } | 187 } |
188 | 188 |
189 } // namespace views | 189 } // namespace views |
OLD | NEW |