| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/accessibility/ax_view_state.h" | 13 #include "ui/accessibility/ax_view_state.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/compositor/canvas_painter.h" | 15 #include "ui/compositor/canvas_painter.h" |
| 16 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 17 #include "ui/gfx/render_text.h" |
| 17 #include "ui/views/border.h" | 18 #include "ui/views/border.h" |
| 18 #include "ui/views/test/focus_manager_test.h" | 19 #include "ui/views/test/focus_manager_test.h" |
| 19 #include "ui/views/test/views_test_base.h" | 20 #include "ui/views/test/views_test_base.h" |
| 20 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 21 | 22 |
| 22 using base::ASCIIToUTF16; | 23 using base::ASCIIToUTF16; |
| 23 | 24 |
| 24 namespace views { | 25 namespace views { |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 label.SizeToPreferredSize(); | 191 label.SizeToPreferredSize(); |
| 191 | 192 |
| 192 // The text should be unobscured by default. | 193 // The text should be unobscured by default. |
| 193 EXPECT_FALSE(label.obscured()); | 194 EXPECT_FALSE(label.obscured()); |
| 194 EXPECT_EQ(test_text, label.GetDisplayTextForTesting()); | 195 EXPECT_EQ(test_text, label.GetDisplayTextForTesting()); |
| 195 EXPECT_EQ(test_text, label.text()); | 196 EXPECT_EQ(test_text, label.text()); |
| 196 | 197 |
| 197 label.SetObscured(true); | 198 label.SetObscured(true); |
| 198 label.SizeToPreferredSize(); | 199 label.SizeToPreferredSize(); |
| 199 EXPECT_TRUE(label.obscured()); | 200 EXPECT_TRUE(label.obscured()); |
| 200 EXPECT_EQ(ASCIIToUTF16("*********"), label.GetDisplayTextForTesting()); | 201 EXPECT_EQ(base::string16(test_text.size(), |
| 202 gfx::RenderText::kPasswordReplacementChar), |
| 203 label.GetDisplayTextForTesting()); |
| 201 EXPECT_EQ(test_text, label.text()); | 204 EXPECT_EQ(test_text, label.text()); |
| 202 | 205 |
| 203 label.SetText(test_text + test_text); | 206 label.SetText(test_text + test_text); |
| 204 label.SizeToPreferredSize(); | 207 label.SizeToPreferredSize(); |
| 205 EXPECT_EQ(ASCIIToUTF16("******************"), | 208 EXPECT_EQ(base::string16(test_text.size() * 2, |
| 209 gfx::RenderText::kPasswordReplacementChar), |
| 206 label.GetDisplayTextForTesting()); | 210 label.GetDisplayTextForTesting()); |
| 207 EXPECT_EQ(test_text + test_text, label.text()); | 211 EXPECT_EQ(test_text + test_text, label.text()); |
| 208 | 212 |
| 209 label.SetObscured(false); | 213 label.SetObscured(false); |
| 210 label.SizeToPreferredSize(); | 214 label.SizeToPreferredSize(); |
| 211 EXPECT_FALSE(label.obscured()); | 215 EXPECT_FALSE(label.obscured()); |
| 212 EXPECT_EQ(test_text + test_text, label.GetDisplayTextForTesting()); | 216 EXPECT_EQ(test_text + test_text, label.GetDisplayTextForTesting()); |
| 213 EXPECT_EQ(test_text + test_text, label.text()); | 217 EXPECT_EQ(test_text + test_text, label.text()); |
| 214 } | 218 } |
| 215 | 219 |
| 216 TEST_F(LabelTest, ObscuredSurrogatePair) { | 220 TEST_F(LabelTest, ObscuredSurrogatePair) { |
| 217 // 'MUSICAL SYMBOL G CLEF': represented in UTF-16 as two characters | 221 // 'MUSICAL SYMBOL G CLEF': represented in UTF-16 as two characters |
| 218 // forming the surrogate pair 0x0001D11E. | 222 // forming the surrogate pair 0x0001D11E. |
| 219 Label label; | 223 Label label; |
| 220 base::string16 test_text = base::UTF8ToUTF16("\xF0\x9D\x84\x9E"); | 224 base::string16 test_text = base::UTF8ToUTF16("\xF0\x9D\x84\x9E"); |
| 221 label.SetText(test_text); | 225 label.SetText(test_text); |
| 222 label.SetObscured(true); | 226 label.SetObscured(true); |
| 223 label.SizeToPreferredSize(); | 227 label.SizeToPreferredSize(); |
| 224 EXPECT_EQ(ASCIIToUTF16("*"), label.GetDisplayTextForTesting()); | 228 EXPECT_EQ(base::string16(1, gfx::RenderText::kPasswordReplacementChar), |
| 229 label.GetDisplayTextForTesting()); |
| 225 EXPECT_EQ(test_text, label.text()); | 230 EXPECT_EQ(test_text, label.text()); |
| 226 } | 231 } |
| 227 | 232 |
| 228 // This test case verifies the label preferred size will change based on the | 233 // This test case verifies the label preferred size will change based on the |
| 229 // current layout, which may seem wrong. However many of our code base assumes | 234 // current layout, which may seem wrong. However many of our code base assumes |
| 230 // this behavior, therefore this behavior will have to be kept until the code | 235 // this behavior, therefore this behavior will have to be kept until the code |
| 231 // with this assumption is fixed. See http://crbug.com/468494 and | 236 // with this assumption is fixed. See http://crbug.com/468494 and |
| 232 // http://crbug.com/467526. | 237 // http://crbug.com/467526. |
| 233 // TODO(mukai): fix the code assuming this behavior and then fix Label | 238 // TODO(mukai): fix the code assuming this behavior and then fix Label |
| 234 // implementation, and remove this test case. | 239 // implementation, and remove this test case. |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 label()->SetFocusBehavior(View::FocusBehavior::ALWAYS); | 724 label()->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
| 720 label()->RequestFocus(); | 725 label()->RequestFocus(); |
| 721 label()->SizeToPreferredSize(); | 726 label()->SizeToPreferredSize(); |
| 722 | 727 |
| 723 gfx::Rect focus_bounds = label()->GetFocusBounds(); | 728 gfx::Rect focus_bounds = label()->GetFocusBounds(); |
| 724 EXPECT_FALSE(focus_bounds.IsEmpty()); | 729 EXPECT_FALSE(focus_bounds.IsEmpty()); |
| 725 EXPECT_LT(label()->font_list().GetHeight(), focus_bounds.height()); | 730 EXPECT_LT(label()->font_list().GetHeight(), focus_bounds.height()); |
| 726 } | 731 } |
| 727 | 732 |
| 728 } // namespace views | 733 } // namespace views |
| OLD | NEW |