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

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: Rebase Created 7 years, 5 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..3e2b15354b62c2da3c53a00d92e1e8826454e57d 100644
--- a/ui/views/controls/styled_label_unittest.cc
+++ b/ui/views/controls/styled_label_unittest.cc
@@ -8,6 +8,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/skia/include/core/SkColor.h"
#include "ui/views/controls/link.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/controls/styled_label_listener.h"
@@ -256,6 +257,58 @@ 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 = SK_ColorRED;
+ 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(SK_ColorRED,
+ 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, ColorReadability) {
+ const std::string text(
+ "This is a block of text that needs color adjustment.");
+ InitStyledLabel(text);
+ styled()->SetDisplayedOnBackgroundColor(SK_ColorBLACK);
+
+ // Obtain the text color if it were a pure label.
+ Label label(ASCIIToUTF16(text));
+ label.SetBackgroundColor(SK_ColorBLACK);
+
+ 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