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(ASCIIToUTF16("Password!"), label.display_text()); | |
|
msw
2014/04/03 01:38:48
nit: re-use test_text here and below.
| |
| 109 | |
| 110 label.SetObscured(true); | |
| 111 EXPECT_TRUE(label.is_obscured()); | |
| 112 EXPECT_EQ(base::WideToUTF16( | |
| 113 L"\x2022\x2022\x2022\x2022\x2022\x2022\x2022\x2022\x2022"), | |
| 114 label.display_text()); | |
| 115 | |
|
msw
2014/04/03 01:38:48
nit: test that a SetText call while the Label is o
| |
| 116 label.SetObscured(false); | |
| 117 EXPECT_FALSE(label.is_obscured()); | |
| 118 EXPECT_EQ(ASCIIToUTF16("Password!"), label.display_text()); | |
| 119 } | |
| 120 | |
| 101 TEST(LabelTest, TooltipProperty) { | 121 TEST(LabelTest, TooltipProperty) { |
| 102 Label label; | 122 Label label; |
| 103 base::string16 test_text(ASCIIToUTF16("My cool string.")); | 123 base::string16 test_text(ASCIIToUTF16("My cool string.")); |
| 104 label.SetText(test_text); | 124 label.SetText(test_text); |
| 105 | 125 |
| 106 base::string16 tooltip; | 126 base::string16 tooltip; |
| 107 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); | 127 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); |
| 108 EXPECT_EQ(test_text, tooltip); | 128 EXPECT_EQ(test_text, tooltip); |
| 109 | 129 |
| 110 base::string16 tooltip_text(ASCIIToUTF16("The tooltip!")); | 130 base::string16 tooltip_text(ASCIIToUTF16("The tooltip!")); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 126 label.SetTooltipText(tooltip_text); | 146 label.SetTooltipText(tooltip_text); |
| 127 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); | 147 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); |
| 128 EXPECT_EQ(tooltip_text, tooltip); | 148 EXPECT_EQ(tooltip_text, tooltip); |
| 129 // Clear out the tooltip. | 149 // Clear out the tooltip. |
| 130 label.SetTooltipText(empty_text); | 150 label.SetTooltipText(empty_text); |
| 131 | 151 |
| 132 // Shrink the bounds and the tooltip should come back. | 152 // Shrink the bounds and the tooltip should come back. |
| 133 label.SetBounds(0, 0, 1, 1); | 153 label.SetBounds(0, 0, 1, 1); |
| 134 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); | 154 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); |
| 135 | 155 |
| 136 // Make the label multiline and there is no tooltip again. | 156 // Make the label obscured and there is no tooltip. |
| 157 label.SetObscured(true); | |
| 158 EXPECT_FALSE(label.GetTooltipText(gfx::Point(), &tooltip)); | |
| 159 label.SetObscured(false); | |
|
msw
2014/04/03 01:38:48
nit: after this call, EXPECT_TRUE(label.GetTooltip
msw
2014/04/03 18:27:48
ping.
Mike West
2014/04/04 07:05:15
Done.
| |
| 160 | |
| 161 // Make the label multiline and there is no tooltip. | |
| 137 label.SetMultiLine(true); | 162 label.SetMultiLine(true); |
| 138 EXPECT_FALSE(label.GetTooltipText(gfx::Point(), &tooltip)); | 163 EXPECT_FALSE(label.GetTooltipText(gfx::Point(), &tooltip)); |
| 139 | 164 |
| 140 // Verify that setting the tooltip still shows it. | 165 // Verify that setting the tooltip still shows it. |
| 141 label.SetTooltipText(tooltip_text); | 166 label.SetTooltipText(tooltip_text); |
| 142 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); | 167 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); |
| 143 EXPECT_EQ(tooltip_text, tooltip); | 168 EXPECT_EQ(tooltip_text, tooltip); |
| 144 // Clear out the tooltip. | 169 // Clear out the tooltip. |
| 145 label.SetTooltipText(empty_text); | 170 label.SetTooltipText(empty_text); |
| 146 } | 171 } |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 913 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(2, 51))); | 938 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(2, 51))); |
| 914 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(-1, 20))); | 939 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(-1, 20))); |
| 915 | 940 |
| 916 // GetTooltipHandlerForPoint works should work in child bounds. | 941 // GetTooltipHandlerForPoint works should work in child bounds. |
| 917 label.SetBounds(2, 2, 10, 10); | 942 label.SetBounds(2, 2, 10, 10); |
| 918 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(1, 5))); | 943 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(1, 5))); |
| 919 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(3, 11))); | 944 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(3, 11))); |
| 920 } | 945 } |
| 921 | 946 |
| 922 } // namespace views | 947 } // namespace views |
| OLD | NEW |