Chromium Code Reviews| 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..4d6a626f97e865b2a7c11b00cca541fb25c2da0b 100644 |
| --- a/ui/views/controls/styled_label_unittest.cc |
| +++ b/ui/views/controls/styled_label_unittest.cc |
| @@ -89,6 +89,38 @@ TEST_F(StyledLabelTest, RespectLeadingWhitespace) { |
| static_cast<Label*>(styled()->child_at(0))->text()); |
| } |
| +TEST_F(StyledLabelTest, RespectLeadingSpacesInNonFirstLine) { |
| + const std::string indented_line = " indented 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), |
| + static_cast<Label*>(styled()->child_at(1))->text()); |
| +} |
| + |
| +TEST_F(StyledLabelTest, CorrectWrapAtNewline) { |
| + const std::string first_line = "Line one"; |
| + const std::string second_line = " two"; |
| + const std::string multiline_text(first_line + "\n" + second_line); |
| + InitStyledLabel(multiline_text); |
| + Label label(ASCIIToUTF16(first_line)); |
| + gfx::Size label_preferred_size = label.GetPreferredSize(); |
| + // Correct handling of \n and label width limit encountered at the same place |
| + styled()->SetBounds(0, 0, label_preferred_size.width(), 1000); |
| + styled()->Layout(); |
| + ASSERT_EQ(2, styled()->child_count()); |
| + ASSERT_EQ(std::string(Label::kViewClassName), |
| + styled()->child_at(1)->GetClassName()); |
| + EXPECT_EQ(ASCIIToUTF16(" two"), |
| + static_cast<Label*>(styled()->child_at(1))->text()); |
|
Evan Stade
2016/12/06 17:04:47
nit: check contents of first line as well?
|
| + EXPECT_EQ(styled()->GetHeightForWidth(1000), |
| + styled()->child_at(1)->bounds().bottom()); |
| +} |
| + |
| TEST_F(StyledLabelTest, FirstLineNotEmptyWhenLeadingWhitespaceTooLong) { |
| const std::string text(" a"); |
| InitStyledLabel(text); |
| @@ -128,6 +160,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); |