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

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

Issue 17756003: Colors in views::StyledLabel. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Style fix Created 7 years, 6 months 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 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,");
« 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