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

Unified Diff: ui/views/controls/button/label_button_unittest.cc

Issue 371633002: LabelButton: cache the last computed preferred size (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 5 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/label_button.cc ('k') | ui/views/examples/button_example.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/button/label_button_unittest.cc
diff --git a/ui/views/controls/button/label_button_unittest.cc b/ui/views/controls/button/label_button_unittest.cc
index ea81b22acaf3d26af4205d95980d02b31fd78a78..d62237076b1fc8a3718671123f472b3bd00241df 100644
--- a/ui/views/controls/button/label_button_unittest.cc
+++ b/ui/views/controls/button/label_button_unittest.cc
@@ -69,11 +69,11 @@ TEST_F(LabelButtonTest, Label) {
EXPECT_GT(button.GetPreferredSize().width(), long_text_width);
// Clamp the size to a maximum value.
- button.set_max_size(gfx::Size(long_text_width, 1));
+ button.SetMaxSize(gfx::Size(long_text_width, 1));
EXPECT_EQ(button.GetPreferredSize(), gfx::Size(long_text_width, 1));
// Clear the monotonically increasing minimum size.
- button.set_min_size(gfx::Size());
+ button.SetMinSize(gfx::Size());
EXPECT_GT(button.GetPreferredSize().width(), short_text_width);
EXPECT_LT(button.GetPreferredSize().width(), long_text_width);
}
@@ -101,11 +101,11 @@ TEST_F(LabelButtonTest, Image) {
EXPECT_GT(button.GetPreferredSize().height(), large_size);
// Clamp the size to a maximum value.
- button.set_max_size(gfx::Size(large_size, 1));
+ button.SetMaxSize(gfx::Size(large_size, 1));
EXPECT_EQ(button.GetPreferredSize(), gfx::Size(large_size, 1));
// Clear the monotonically increasing minimum size.
- button.set_min_size(gfx::Size());
+ button.SetMinSize(gfx::Size());
EXPECT_GT(button.GetPreferredSize().width(), small_size);
EXPECT_LT(button.GetPreferredSize().width(), large_size);
}
@@ -157,11 +157,11 @@ TEST_F(LabelButtonTest, LabelAndImage) {
EXPECT_GT(button.GetPreferredSize().height(), image_size);
// Clamp the size to a maximum value.
- button.set_max_size(gfx::Size(image_size, 1));
+ button.SetMaxSize(gfx::Size(image_size, 1));
EXPECT_EQ(button.GetPreferredSize(), gfx::Size(image_size, 1));
// Clear the monotonically increasing minimum size.
- button.set_min_size(gfx::Size());
+ button.SetMinSize(gfx::Size());
EXPECT_LT(button.GetPreferredSize().width(), text_width);
EXPECT_LT(button.GetPreferredSize().width(), image_size);
EXPECT_LT(button.GetPreferredSize().height(), image_size);
@@ -184,10 +184,27 @@ TEST_F(LabelButtonTest, FontList) {
// The button returns to its original size when the minimal size is cleared
// and the original font size is restored.
- button.set_min_size(gfx::Size());
+ button.SetMinSize(gfx::Size());
button.SetFontList(original_font_list);
EXPECT_EQ(original_width, button.GetPreferredSize().width());
EXPECT_EQ(original_height, button.GetPreferredSize().height());
}
+TEST_F(LabelButtonTest, ChangeTextSize) {
+ const base::string16 text(ASCIIToUTF16("abc"));
+ const base::string16 longer_text(ASCIIToUTF16("abcdefghijklm"));
+ LabelButton button(NULL, text);
+
+ const int original_width = button.GetPreferredSize().width();
+
+ // The button size increases when the text size is increased.
+ button.SetText(longer_text);
+ EXPECT_GT(button.GetPreferredSize().width(), original_width);
+
+ // The button returns to its original size when the original text is restored.
+ button.SetMinSize(gfx::Size());
+ button.SetText(text);
+ EXPECT_EQ(original_width, button.GetPreferredSize().width());
+}
+
} // namespace views
« no previous file with comments | « ui/views/controls/button/label_button.cc ('k') | ui/views/examples/button_example.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698