Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/controls/label.h" | 5 #include "ui/views/controls/label.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/accessibility/ax_view_state.h" | 10 #include "ui/accessibility/ax_view_state.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 | 91 |
| 92 TEST(LabelTest, MultiLineProperty) { | 92 TEST(LabelTest, MultiLineProperty) { |
| 93 Label label; | 93 Label label; |
| 94 EXPECT_FALSE(label.is_multi_line()); | 94 EXPECT_FALSE(label.is_multi_line()); |
| 95 label.SetMultiLine(true); | 95 label.SetMultiLine(true); |
| 96 EXPECT_TRUE(label.is_multi_line()); | 96 EXPECT_TRUE(label.is_multi_line()); |
| 97 label.SetMultiLine(false); | 97 label.SetMultiLine(false); |
| 98 EXPECT_FALSE(label.is_multi_line()); | 98 EXPECT_FALSE(label.is_multi_line()); |
| 99 } | 99 } |
| 100 | 100 |
| 101 TEST(LabelTest, ObscuredProperty) { | |
| 102 Label label; | |
| 103 base::string16 test_text(ASCIIToUTF16("Password!")); | |
| 104 label.SetText(test_text); | |
| 105 | |
| 106 // Should be false by default... | |
| 107 EXPECT_FALSE(label.is_obscured()); | |
| 108 EXPECT_EQ(test_text, label.layout_text()); | |
|
msw
2014/04/03 18:27:48
nit: test the value of text() here and elsewhere.
Mike West
2014/04/04 07:05:16
Done.
| |
| 109 | |
| 110 label.SetObscured(true); | |
| 111 EXPECT_TRUE(label.is_obscured()); | |
| 112 EXPECT_EQ(ASCIIToUTF16("*********"), label.layout_text()); | |
| 113 | |
| 114 label.SetObscured(false); | |
| 115 EXPECT_FALSE(label.is_obscured()); | |
| 116 EXPECT_EQ(test_text, label.layout_text()); | |
| 117 } | |
| 118 | |
| 119 TEST(LabelTest, ObscuredSet) { | |
| 120 Label label; | |
| 121 base::string16 test_text(ASCIIToUTF16("Password!")); | |
| 122 label.SetText(test_text); | |
| 123 | |
| 124 label.SetObscured(true); | |
| 125 EXPECT_EQ(ASCIIToUTF16("*********"), label.layout_text()); | |
| 126 | |
| 127 label.SetText(test_text + test_text); | |
|
msw
2014/04/03 18:27:48
nit: this could be part of the test above.
Mike West
2014/04/04 07:05:16
Done.
| |
| 128 EXPECT_EQ(ASCIIToUTF16("******************"), label.layout_text()); | |
| 129 } | |
| 130 | |
| 131 TEST(LabelTest, ObscuredSurrogatePair) { | |
| 132 // 'MUSICAL SYMBOL G CLEF': represented in UTF-16 as two characters | |
| 133 // forming the surrogate pair 0x0001D11E. | |
| 134 Label label(base::UTF8ToUTF16("\xF0\x9D\x84\x9E")); | |
| 135 label.SetObscured(true); | |
| 136 EXPECT_EQ(ASCIIToUTF16("*"), label.layout_text()); | |
| 137 } | |
| 138 | |
| 101 TEST(LabelTest, TooltipProperty) { | 139 TEST(LabelTest, TooltipProperty) { |
| 102 Label label; | 140 Label label; |
| 103 base::string16 test_text(ASCIIToUTF16("My cool string.")); | 141 base::string16 test_text(ASCIIToUTF16("My cool string.")); |
| 104 label.SetText(test_text); | 142 label.SetText(test_text); |
| 105 | 143 |
| 106 base::string16 tooltip; | 144 base::string16 tooltip; |
| 107 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); | 145 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); |
| 108 EXPECT_EQ(test_text, tooltip); | 146 EXPECT_EQ(test_text, tooltip); |
| 109 | 147 |
| 110 base::string16 tooltip_text(ASCIIToUTF16("The tooltip!")); | 148 base::string16 tooltip_text(ASCIIToUTF16("The tooltip!")); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 126 label.SetTooltipText(tooltip_text); | 164 label.SetTooltipText(tooltip_text); |
| 127 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); | 165 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); |
| 128 EXPECT_EQ(tooltip_text, tooltip); | 166 EXPECT_EQ(tooltip_text, tooltip); |
| 129 // Clear out the tooltip. | 167 // Clear out the tooltip. |
| 130 label.SetTooltipText(empty_text); | 168 label.SetTooltipText(empty_text); |
| 131 | 169 |
| 132 // Shrink the bounds and the tooltip should come back. | 170 // Shrink the bounds and the tooltip should come back. |
| 133 label.SetBounds(0, 0, 1, 1); | 171 label.SetBounds(0, 0, 1, 1); |
| 134 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); | 172 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); |
| 135 | 173 |
| 136 // Make the label multiline and there is no tooltip again. | 174 // Make the label obscured and there is no tooltip. |
| 175 label.SetObscured(true); | |
| 176 EXPECT_FALSE(label.GetTooltipText(gfx::Point(), &tooltip)); | |
| 177 label.SetObscured(false); | |
| 178 | |
| 179 // Make the label multiline and there is no tooltip. | |
| 137 label.SetMultiLine(true); | 180 label.SetMultiLine(true); |
| 138 EXPECT_FALSE(label.GetTooltipText(gfx::Point(), &tooltip)); | 181 EXPECT_FALSE(label.GetTooltipText(gfx::Point(), &tooltip)); |
| 139 | 182 |
| 140 // Verify that setting the tooltip still shows it. | 183 // Verify that setting the tooltip still shows it. |
| 141 label.SetTooltipText(tooltip_text); | 184 label.SetTooltipText(tooltip_text); |
| 142 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); | 185 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); |
| 143 EXPECT_EQ(tooltip_text, tooltip); | 186 EXPECT_EQ(tooltip_text, tooltip); |
| 144 // Clear out the tooltip. | 187 // Clear out the tooltip. |
| 145 label.SetTooltipText(empty_text); | 188 label.SetTooltipText(empty_text); |
| 146 } | 189 } |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 913 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(2, 51))); | 956 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(2, 51))); |
| 914 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(-1, 20))); | 957 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(-1, 20))); |
| 915 | 958 |
| 916 // GetTooltipHandlerForPoint works should work in child bounds. | 959 // GetTooltipHandlerForPoint works should work in child bounds. |
| 917 label.SetBounds(2, 2, 10, 10); | 960 label.SetBounds(2, 2, 10, 10); |
| 918 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(1, 5))); | 961 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(1, 5))); |
| 919 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(3, 11))); | 962 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(3, 11))); |
| 920 } | 963 } |
| 921 | 964 |
| 922 } // namespace views | 965 } // namespace views |
| OLD | NEW |