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 e3462b2fb97434e6b61aa41d76b434f6197f04ca..e1cb1c866726a3622921a780a5fa46ff2296df3e 100644 |
| --- a/ui/views/controls/styled_label_unittest.cc |
| +++ b/ui/views/controls/styled_label_unittest.cc |
| @@ -49,6 +49,15 @@ TEST_F(StyledLabelTest, NoWrapping) { |
| StyledLabelContentHeightForWidth(label_preferred_size.width() * 2)); |
| } |
| +TEST_F(StyledLabelTest, TrailingWhitespace) { |
| + const std::string text("This is a test block of text "); |
| + InitStyledLabel(text); |
| + Label label(ASCIIToUTF16(text)); |
| + const gfx::Size label_preferred_size = label.GetPreferredSize(); |
| + EXPECT_EQ(label_preferred_size.height(), |
| + StyledLabelContentHeightForWidth(label_preferred_size.width() * 2)); |
| +} |
| + |
| TEST_F(StyledLabelTest, BasicWrapping) { |
| const std::string text("This is a test block of text"); |
| InitStyledLabel(text); |
| @@ -104,6 +113,98 @@ TEST_F(StyledLabelTest, DontBreakLinks) { |
| EXPECT_EQ(0, styled()->child_at(1)->bounds().x()); |
| } |
| +TEST_F(StyledLabelTest, StyledRangeWithDisabledLineWrapping) { |
| + const std::string text("This is a test block of text, "); |
| + const std::string unbreakable_text("and this should not be breaked"); |
| + InitStyledLabel(text + unbreakable_text); |
| + StyledLabel::RangeStyleInfo style_info; |
| + style_info.disable_line_wrapping = true; |
| + styled()->AddStyleRange( |
| + ui::Range(text.size(), text.size() + unbreakable_text.size()), |
| + style_info); |
| + |
| + Label label(ASCIIToUTF16( |
| + text + unbreakable_text.substr(0, unbreakable_text.size() / 2))); |
| + gfx::Size label_preferred_size = label.GetPreferredSize(); |
| + int pref_height = styled()->GetHeightForWidth(label_preferred_size.width()); |
| + EXPECT_EQ(label_preferred_size.height() * 2, |
| + pref_height - styled()->GetInsets().height()); |
| + |
| + styled()->SetBounds(0, 0, label_preferred_size.width(), pref_height); |
| + styled()->Layout(); |
| + ASSERT_EQ(2, styled()->child_count()); |
| + EXPECT_EQ(0, styled()->child_at(0)->bounds().x()); |
| + EXPECT_EQ(0, styled()->child_at(1)->bounds().x()); |
| +} |
| + |
| +TEST_F(StyledLabelTest, StyledRangeUnderlined) { |
| + const std::string text("This is a test block of text, "); |
| + const std::string underlined_text("and this should be undelined"); |
| + InitStyledLabel(text + underlined_text); |
| + StyledLabel::RangeStyleInfo style_info; |
| + style_info.font_style = gfx::Font::UNDERLINE; |
| + styled()->AddStyleRange( |
| + ui::Range(text.size(), text.size() + underlined_text.size()), |
| + style_info); |
| + |
| + styled()->SetBounds(0, 0, 1000, 1000); |
| + styled()->Layout(); |
| + |
| + ASSERT_EQ(2, styled()->child_count()); |
| + ASSERT_EQ(Label::kViewClassName, styled()->child_at(1)->GetClassName()); |
| + EXPECT_EQ(gfx::Font::UNDERLINE, |
| + static_cast<Label*>(styled()->child_at(1))->font().GetStyle()); |
| +} |
| + |
| +TEST_F(StyledLabelTest, StyledRangeWithTooltip) { |
| + const std::string text("This is a test block of text, "); |
| + const std::string tooltip_text("this should have a tooltip,"); |
| + const std::string normal_text(" this should not have a tooltip, "); |
| + const std::string link_text("and this should be a link"); |
| + |
| + const size_t tooltip_start = text.size(); |
| + const size_t link_start = |
| + text.size() + tooltip_text.size() + normal_text.size(); |
| + |
| + InitStyledLabel(text + tooltip_text + normal_text + link_text); |
| + StyledLabel::RangeStyleInfo tooltip_style; |
| + tooltip_style.tooltip = ASCIIToUTF16("tooltip"); |
| + styled()->AddStyleRange( |
| + ui::Range(tooltip_start, tooltip_start + tooltip_text.size()), |
| + tooltip_style); |
| + styled()->AddLink(ui::Range(link_start, link_start + link_text.size())); |
| + |
| + // Break line inside the range with the tooltip. |
| + Label label(ASCIIToUTF16( |
| + text + tooltip_text.substr(0, tooltip_text.size() - 3))); |
| + gfx::Size label_preferred_size = label.GetPreferredSize(); |
| + int pref_height = styled()->GetHeightForWidth(label_preferred_size.width()); |
| + EXPECT_EQ(label_preferred_size.height() * 3, |
| + pref_height - styled()->GetInsets().height()); |
| + |
| + styled()->SetBounds(0, 0, label_preferred_size.width(), pref_height); |
| + styled()->Layout(); |
| + |
| + EXPECT_EQ(label_preferred_size.width(), styled()->width()); |
| + |
| + ASSERT_EQ(5, styled()->child_count()); |
| + EXPECT_EQ(0, styled()->child_at(0)->bounds().x()); |
| + EXPECT_EQ(styled()->child_at(0)->bounds().right() - 2, |
| + styled()->child_at(1)->bounds().x()); |
| + EXPECT_EQ(0, styled()->child_at(2)->bounds().x()); |
| + EXPECT_EQ(styled()->child_at(2)->bounds().right() - 2, |
| + styled()->child_at(3)->bounds().x()); |
| + EXPECT_EQ(0, styled()->child_at(4)->bounds().x()); |
| + |
| + string16 tooltip; |
| + EXPECT_TRUE( |
| + styled()->child_at(1)->GetTooltipText(gfx::Point(1, 1), &tooltip)); |
| + EXPECT_EQ(ASCIIToUTF16("tooltip"), tooltip); |
| + EXPECT_TRUE( |
| + styled()->child_at(2)->GetTooltipText(gfx::Point(1, 1), &tooltip)); |
| + EXPECT_EQ(ASCIIToUTF16("tooltip"), tooltip); |
| +} |
|
Evan Stade
2013/03/25 22:30:11
please add a test for bolding and how it affects l
tbarzic
2013/03/26 21:32:33
Done.
|
| + |
| TEST_F(StyledLabelTest, HandleEmptyLayout) { |
| const std::string text("This is a test block of text, "); |
| InitStyledLabel(text); |