| 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()); |
| 109 EXPECT_EQ(test_text, label.text()); |
| 110 |
| 111 label.SetObscured(true); |
| 112 EXPECT_TRUE(label.is_obscured()); |
| 113 EXPECT_EQ(ASCIIToUTF16("*********"), label.layout_text()); |
| 114 EXPECT_EQ(test_text, label.text()); |
| 115 |
| 116 label.SetText(test_text + test_text); |
| 117 EXPECT_EQ(ASCIIToUTF16("******************"), label.layout_text()); |
| 118 EXPECT_EQ(test_text + test_text, label.text()); |
| 119 |
| 120 label.SetObscured(false); |
| 121 EXPECT_FALSE(label.is_obscured()); |
| 122 EXPECT_EQ(test_text + test_text, label.layout_text()); |
| 123 EXPECT_EQ(test_text + test_text, label.text()); |
| 124 } |
| 125 |
| 126 TEST(LabelTest, ObscuredSurrogatePair) { |
| 127 // 'MUSICAL SYMBOL G CLEF': represented in UTF-16 as two characters |
| 128 // forming the surrogate pair 0x0001D11E. |
| 129 Label label; |
| 130 base::string16 test_text = base::UTF8ToUTF16("\xF0\x9D\x84\x9E"); |
| 131 label.SetText(test_text); |
| 132 |
| 133 label.SetObscured(true); |
| 134 EXPECT_EQ(ASCIIToUTF16("*"), label.layout_text()); |
| 135 EXPECT_EQ(test_text, label.text()); |
| 136 } |
| 137 |
| 101 TEST(LabelTest, TooltipProperty) { | 138 TEST(LabelTest, TooltipProperty) { |
| 102 Label label; | 139 Label label; |
| 103 base::string16 test_text(ASCIIToUTF16("My cool string.")); | 140 base::string16 test_text(ASCIIToUTF16("My cool string.")); |
| 104 label.SetText(test_text); | 141 label.SetText(test_text); |
| 105 | 142 |
| 106 base::string16 tooltip; | 143 base::string16 tooltip; |
| 107 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); | 144 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); |
| 108 EXPECT_EQ(test_text, tooltip); | 145 EXPECT_EQ(test_text, tooltip); |
| 109 | 146 |
| 110 base::string16 tooltip_text(ASCIIToUTF16("The tooltip!")); | 147 base::string16 tooltip_text(ASCIIToUTF16("The tooltip!")); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 126 label.SetTooltipText(tooltip_text); | 163 label.SetTooltipText(tooltip_text); |
| 127 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); | 164 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); |
| 128 EXPECT_EQ(tooltip_text, tooltip); | 165 EXPECT_EQ(tooltip_text, tooltip); |
| 129 // Clear out the tooltip. | 166 // Clear out the tooltip. |
| 130 label.SetTooltipText(empty_text); | 167 label.SetTooltipText(empty_text); |
| 131 | 168 |
| 132 // Shrink the bounds and the tooltip should come back. | 169 // Shrink the bounds and the tooltip should come back. |
| 133 label.SetBounds(0, 0, 1, 1); | 170 label.SetBounds(0, 0, 1, 1); |
| 134 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); | 171 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); |
| 135 | 172 |
| 136 // Make the label multiline and there is no tooltip again. | 173 // Make the label obscured and there is no tooltip. |
| 174 label.SetObscured(true); |
| 175 EXPECT_FALSE(label.GetTooltipText(gfx::Point(), &tooltip)); |
| 176 |
| 177 // Obscuring the text shouldn't permanently clobber the tooltip. |
| 178 label.SetObscured(false); |
| 179 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); |
| 180 |
| 181 // Make the label multiline and there is no tooltip. |
| 137 label.SetMultiLine(true); | 182 label.SetMultiLine(true); |
| 138 EXPECT_FALSE(label.GetTooltipText(gfx::Point(), &tooltip)); | 183 EXPECT_FALSE(label.GetTooltipText(gfx::Point(), &tooltip)); |
| 139 | 184 |
| 140 // Verify that setting the tooltip still shows it. | 185 // Verify that setting the tooltip still shows it. |
| 141 label.SetTooltipText(tooltip_text); | 186 label.SetTooltipText(tooltip_text); |
| 142 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); | 187 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); |
| 143 EXPECT_EQ(tooltip_text, tooltip); | 188 EXPECT_EQ(tooltip_text, tooltip); |
| 144 // Clear out the tooltip. | 189 // Clear out the tooltip. |
| 145 label.SetTooltipText(empty_text); | 190 label.SetTooltipText(empty_text); |
| 146 } | 191 } |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(2, 51))); | 958 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(2, 51))); |
| 914 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(-1, 20))); | 959 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(-1, 20))); |
| 915 | 960 |
| 916 // GetTooltipHandlerForPoint works should work in child bounds. | 961 // GetTooltipHandlerForPoint works should work in child bounds. |
| 917 label.SetBounds(2, 2, 10, 10); | 962 label.SetBounds(2, 2, 10, 10); |
| 918 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(1, 5))); | 963 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(1, 5))); |
| 919 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(3, 11))); | 964 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(3, 11))); |
| 920 } | 965 } |
| 921 | 966 |
| 922 } // namespace views | 967 } // namespace views |
| OLD | NEW |