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

Unified Diff: ui/views/controls/styled_label_unittest.cc

Issue 734923003: Fixed StyledLabel size caching (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: codereview changes Created 6 years 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/styled_label.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/styled_label_unittest.cc
diff --git a/ui/views/controls/styled_label_unittest.cc b/ui/views/controls/styled_label_unittest.cc
index 8944a4708d6a9223d8857007cb33564dcae90a9c..85feb257781f48c6194aec7c1b1d162dc1a1ae54 100644
--- a/ui/views/controls/styled_label_unittest.cc
+++ b/ui/views/controls/styled_label_unittest.cc
@@ -422,4 +422,48 @@ TEST_F(StyledLabelTest, HandleEmptyLayout) {
EXPECT_EQ(0, styled()->child_count());
}
+TEST_F(StyledLabelTest, CacheSize) {
+ const int preferred_height = 50;
+ const int preferred_width = 100;
+ const std::string text("This is a test block of text.");
+ const base::string16 another_text(base::ASCIIToUTF16(
+ "This is a test block of text. This text is much longer than previous"));
+
+ InitStyledLabel(text);
+
+ // we should be able to calculate height without any problem
+ // no controls should be created
+ int precalculated_height = styled()->GetHeightForWidth(preferred_width);
+ EXPECT_GT(precalculated_height, 0);
sky 2014/12/16 16:24:51 For testing assertions you always want expected, a
edjomin 2014/12/16 17:11:20 Done.
+ EXPECT_EQ(0, styled()->child_count());
+
+ styled()->SetBounds(0, 0, preferred_width, preferred_height);
+ styled()->Layout();
+
+ // controls should be created after layout
+ // height should be the same as precalculated
+ int real_height = styled()->GetHeightForWidth(styled()->width());
+ View* first_child_after_layout = styled()->has_children() ?
+ styled()->child_at(0) : nullptr;
+ EXPECT_GT(styled()->child_count(), 0);
sky 2014/12/16 16:24:51 Same comment for assertions for these three.
edjomin 2014/12/16 17:11:20 Done.
+ EXPECT_GT(real_height, 0);
+ EXPECT_EQ(real_height, precalculated_height);
+
+ // another call to Layout should not kill and recreate all controls
+ styled()->Layout();
+ View* first_child_after_second_layout = styled()->has_children() ?
+ styled()->child_at(0) : nullptr;
+ EXPECT_EQ(first_child_after_layout, first_child_after_second_layout);
+
+ // if text is changed:
+ // layout should be recalculated
+ // all controls should be recreated
+ styled()->SetText(another_text);
+ int updated_height = styled()->GetHeightForWidth(styled()->width());
+ EXPECT_NE(updated_height, real_height);
+ View* first_child_after_text_update = styled()->has_children() ?
+ styled()->child_at(0) : nullptr;
+ EXPECT_NE(first_child_after_text_update, first_child_after_layout);
+}
+
} // namespace views
« no previous file with comments | « ui/views/controls/styled_label.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698