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 ecd2955c82160487bf7b9d3468d9264a558bcce6..7bbbcb09465220b4dbf9a04171b55c39a4d65bdd 100644 |
| --- a/ui/views/controls/styled_label_unittest.cc |
| +++ b/ui/views/controls/styled_label_unittest.cc |
| @@ -12,6 +12,11 @@ |
| #include "ui/views/controls/styled_label.h" |
| #include "ui/views/controls/styled_label_listener.h" |
| +namespace { |
| +const SkColor kBlack = SkColorSetRGB(0, 0, 0); |
|
bcwhite
2013/07/02 14:22:13
The "SkColor.h" file has a number of standard colo
fdoray
2013/07/02 16:49:22
Done.
|
| +const SkColor kRed = SkColorSetRGB(255, 0, 0); |
| +} // namespace |
| + |
| namespace views { |
| class StyledLabelTest : public testing::Test, public StyledLabelListener { |
| @@ -256,6 +261,77 @@ TEST_F(StyledLabelTest, StyledRangeBold) { |
| styled()->child_at(2)->bounds().x()); |
| } |
| +TEST_F(StyledLabelTest, Color) { |
| + const std::string text_red("RED"); |
| + const std::string text_link("link"); |
| + const std::string text("word"); |
| + InitStyledLabel(text_red + text_link + text); |
| + |
| + StyledLabel::RangeStyleInfo style_info_red; |
| + style_info_red.color = kRed; |
| + styled()->AddStyleRange(ui::Range(0, text_red.size()), style_info_red); |
| + |
| + StyledLabel::RangeStyleInfo style_info_link = |
| + StyledLabel::RangeStyleInfo::CreateForLink(); |
| + styled()->AddStyleRange(ui::Range(text_red.size(), |
| + text_red.size() + text_link.size()), |
| + style_info_link); |
| + |
| + // Obtain the default text color for a label. |
| + Label label(ASCIIToUTF16(text)); |
| + const SkColor kDefaultTextColor = label.enabled_color(); |
| + |
| + // Obtain the default text color for a link; |
| + Link link(ASCIIToUTF16(text_link)); |
| + const SkColor kDefaultLinkColor = link.enabled_color(); |
| + |
| + styled()->SetBounds(0, 0, 1000, 1000); |
| + styled()->Layout(); |
| + |
| + EXPECT_EQ(kRed, |
| + static_cast<Label*>(styled()->child_at(0))->enabled_color()); |
| + EXPECT_EQ(kDefaultLinkColor, |
| + static_cast<Label*>(styled()->child_at(1))->enabled_color()); |
| + EXPECT_EQ(kDefaultTextColor, |
| + static_cast<Label*>(styled()->child_at(2))->enabled_color()); |
| +} |
| + |
| +TEST_F(StyledLabelTest, ColorReadabilityOn) { |
| + const std::string text( |
| + "This is a block of text that needs color adjustment."); |
| + InitStyledLabel(text); |
| + styled()->SetBackgroundColor(kBlack); |
| + |
| + // Obtain the text color if it were a pure label. |
| + Label label(ASCIIToUTF16(text)); |
| + label.SetBackgroundColor(kBlack); |
| + |
| + styled()->SetBounds(0, 0, 1000, 1000); |
| + styled()->Layout(); |
| + |
| + EXPECT_EQ(label.enabled_color(), |
| + static_cast<Label*>(styled()->child_at(0))->enabled_color()); |
| +} |
| + |
| +TEST_F(StyledLabelTest, ColorReadabilityOff) { |
| + const std::string text( |
| + "This is a block of text that shouldn't change color."); |
| + InitStyledLabel(text); |
| + styled()->SetBackgroundColor(kBlack); |
| + styled()->SetAutoColorReadabilityEnabled(false); |
| + |
| + // Obtain the text color if it were a pure label. |
| + Label label(ASCIIToUTF16(text)); |
| + label.SetBackgroundColor(kBlack); |
| + label.SetAutoColorReadabilityEnabled(false); |
| + |
| + styled()->SetBounds(0, 0, 1000, 1000); |
| + styled()->Layout(); |
| + |
| + EXPECT_EQ(label.enabled_color(), |
| + static_cast<Label*>(styled()->child_at(0))->enabled_color()); |
| +} |
| + |
| 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,"); |