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

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

Issue 2348433002: Make styled-label trimming less agressive, allowing whitespace (Closed)
Patch Set: Added test coverage, fixed empty line output for styled_label Created 4 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 c12a08d370276361672cab960438c41b8d8aed07..189f75872a6a6b5829701abe95e640925413faab 100644
--- a/ui/views/controls/styled_label_unittest.cc
+++ b/ui/views/controls/styled_label_unittest.cc
@@ -89,6 +89,19 @@ TEST_F(StyledLabelTest, RespectLeadingWhitespace) {
static_cast<Label*>(styled()->child_at(0))->text());
}
+TEST_F(StyledLabelTest, RespectLeadingSpacesInNonFirstLine) {
+ const std::string indented_line = " indented with space line";
+ const std::string text(std::string("First line\n") + indented_line);
+ InitStyledLabel(text);
+ styled()->SetBounds(0, 0, 1000, 1000);
+ styled()->Layout();
+ ASSERT_EQ(2, styled()->child_count());
+ ASSERT_EQ(std::string(Label::kViewClassName),
+ styled()->child_at(0)->GetClassName());
+ EXPECT_EQ(ASCIIToUTF16(indented_line),
Evan Stade 2016/12/05 17:12:14 can you test what would happen if we naturally wra
+ static_cast<Label*>(styled()->child_at(1))->text());
+}
+
TEST_F(StyledLabelTest, FirstLineNotEmptyWhenLeadingWhitespaceTooLong) {
const std::string text(" a");
InitStyledLabel(text);
@@ -128,6 +141,20 @@ TEST_F(StyledLabelTest, BasicWrapping) {
EXPECT_EQ(styled()->height() - 3, styled()->child_at(1)->bounds().bottom());
}
+TEST_F(StyledLabelTest, AllowEmptyLines) {
+ const std::string text("one");
+ InitStyledLabel(text);
+ int default_height = styled()->GetHeightForWidth(1000);
+ const std::string multiline_text("one\n\nthree");
+ InitStyledLabel(multiline_text);
+ styled()->SetBounds(0, 0, 1000, 1000);
+ styled()->Layout();
+ EXPECT_EQ(3 * default_height, styled()->GetHeightForWidth(1000));
+ ASSERT_EQ(2, styled()->child_count());
+ EXPECT_EQ(styled()->GetHeightForWidth(1000),
+ styled()->child_at(1)->bounds().bottom());
+}
+
TEST_F(StyledLabelTest, WrapLongWords) {
const std::string text("ThisIsTextAsASingleWord");
InitStyledLabel(text);
« 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