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

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

Issue 222033002: Add an 'obscured' flag to views::Label. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Feedback Created 6 years, 9 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/label.cc ('k') | ui/views/examples/label_example.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/label_unittest.cc
diff --git a/ui/views/controls/label_unittest.cc b/ui/views/controls/label_unittest.cc
index 42cc0cda47da2728e158f4baedfe1207b54ddc4b..aac99840ddc1f4f74353c771e953fe50fdd716ab 100644
--- a/ui/views/controls/label_unittest.cc
+++ b/ui/views/controls/label_unittest.cc
@@ -98,6 +98,43 @@ TEST(LabelTest, MultiLineProperty) {
EXPECT_FALSE(label.is_multi_line());
}
+TEST(LabelTest, ObscuredProperty) {
+ Label label;
+ base::string16 test_text(ASCIIToUTF16("Password!"));
+ label.SetText(test_text);
+
+ // Should be false by default...
+ EXPECT_FALSE(label.is_obscured());
+ EXPECT_EQ(test_text, label.layout_text());
+ EXPECT_EQ(test_text, label.text());
+
+ label.SetObscured(true);
+ EXPECT_TRUE(label.is_obscured());
+ EXPECT_EQ(ASCIIToUTF16("*********"), label.layout_text());
+ EXPECT_EQ(test_text, label.text());
+
+ label.SetText(test_text + test_text);
+ EXPECT_EQ(ASCIIToUTF16("******************"), label.layout_text());
+ EXPECT_EQ(test_text + test_text, label.text());
+
+ label.SetObscured(false);
+ EXPECT_FALSE(label.is_obscured());
+ EXPECT_EQ(test_text + test_text, label.layout_text());
+ EXPECT_EQ(test_text + test_text, label.text());
+}
+
+TEST(LabelTest, ObscuredSurrogatePair) {
+ // 'MUSICAL SYMBOL G CLEF': represented in UTF-16 as two characters
+ // forming the surrogate pair 0x0001D11E.
+ Label label;
+ base::string16 test_text = base::UTF8ToUTF16("\xF0\x9D\x84\x9E");
+ label.SetText(test_text);
+
+ label.SetObscured(true);
+ EXPECT_EQ(ASCIIToUTF16("*"), label.layout_text());
+ EXPECT_EQ(test_text, label.text());
+}
+
TEST(LabelTest, TooltipProperty) {
Label label;
base::string16 test_text(ASCIIToUTF16("My cool string."));
@@ -133,7 +170,15 @@ TEST(LabelTest, TooltipProperty) {
label.SetBounds(0, 0, 1, 1);
EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip));
- // Make the label multiline and there is no tooltip again.
+ // Make the label obscured and there is no tooltip.
+ label.SetObscured(true);
+ EXPECT_FALSE(label.GetTooltipText(gfx::Point(), &tooltip));
+
+ // Obscuring the text shouldn't permanently clobber the tooltip.
+ label.SetObscured(false);
+ EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip));
+
+ // Make the label multiline and there is no tooltip.
label.SetMultiLine(true);
EXPECT_FALSE(label.GetTooltipText(gfx::Point(), &tooltip));
« no previous file with comments | « ui/views/controls/label.cc ('k') | ui/views/examples/label_example.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698