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 <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/views/border.h" | 17 #include "ui/views/border.h" |
| 18 #include "ui/views/test/focus_manager_test.h" | 18 #include "ui/views/test/focus_manager_test.h" |
| 19 #include "ui/views/test/views_test_base.h" | 19 #include "ui/views/test/views_test_base.h" |
| 20 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 21 | 21 |
| 22 using base::ASCIIToUTF16; | 22 using base::ASCIIToUTF16; |
| 23 | 23 |
| 24 namespace views { | 24 namespace views { |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 // All text sizing measurements (width and height) should be greater than this. | 27 // All text sizing measurements (width and height) should be greater than this. |
| 28 const int kMinTextDimension = 4; | 28 const int kMinTextDimension = 4; |
| 29 | 29 |
| 30 #if defined(OS_MACOSX) | |
| 31 const base::char16 kObscuredCharacter = 0x2022; | |
|
sky
2016/10/21 15:06:41
Use the define in rendertext.
karandeepb
2016/10/24 12:09:54
Done.
| |
| 32 #else | |
| 33 const base::char16 kObscuredCharacter = '*'; | |
| 34 #endif | |
| 35 | |
| 30 using LabelTest = ViewsTestBase; | 36 using LabelTest = ViewsTestBase; |
| 31 | 37 |
| 32 class LabelFocusTest : public FocusManagerTest { | 38 class LabelFocusTest : public FocusManagerTest { |
| 33 public: | 39 public: |
| 34 LabelFocusTest() {} | 40 LabelFocusTest() {} |
| 35 ~LabelFocusTest() override {} | 41 ~LabelFocusTest() override {} |
| 36 | 42 |
| 37 protected: | 43 protected: |
| 38 Label* label() { return label_; } | 44 Label* label() { return label_; } |
| 39 | 45 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 label.SizeToPreferredSize(); | 196 label.SizeToPreferredSize(); |
| 191 | 197 |
| 192 // The text should be unobscured by default. | 198 // The text should be unobscured by default. |
| 193 EXPECT_FALSE(label.obscured()); | 199 EXPECT_FALSE(label.obscured()); |
| 194 EXPECT_EQ(test_text, label.GetDisplayTextForTesting()); | 200 EXPECT_EQ(test_text, label.GetDisplayTextForTesting()); |
| 195 EXPECT_EQ(test_text, label.text()); | 201 EXPECT_EQ(test_text, label.text()); |
| 196 | 202 |
| 197 label.SetObscured(true); | 203 label.SetObscured(true); |
| 198 label.SizeToPreferredSize(); | 204 label.SizeToPreferredSize(); |
| 199 EXPECT_TRUE(label.obscured()); | 205 EXPECT_TRUE(label.obscured()); |
| 200 EXPECT_EQ(ASCIIToUTF16("*********"), label.GetDisplayTextForTesting()); | 206 EXPECT_EQ(base::string16(test_text.size(), kObscuredCharacter), |
| 207 label.GetDisplayTextForTesting()); | |
| 201 EXPECT_EQ(test_text, label.text()); | 208 EXPECT_EQ(test_text, label.text()); |
| 202 | 209 |
| 203 label.SetText(test_text + test_text); | 210 label.SetText(test_text + test_text); |
| 204 label.SizeToPreferredSize(); | 211 label.SizeToPreferredSize(); |
| 205 EXPECT_EQ(ASCIIToUTF16("******************"), | 212 EXPECT_EQ(base::string16(test_text.size() * 2, kObscuredCharacter), |
| 206 label.GetDisplayTextForTesting()); | 213 label.GetDisplayTextForTesting()); |
| 207 EXPECT_EQ(test_text + test_text, label.text()); | 214 EXPECT_EQ(test_text + test_text, label.text()); |
| 208 | 215 |
| 209 label.SetObscured(false); | 216 label.SetObscured(false); |
| 210 label.SizeToPreferredSize(); | 217 label.SizeToPreferredSize(); |
| 211 EXPECT_FALSE(label.obscured()); | 218 EXPECT_FALSE(label.obscured()); |
| 212 EXPECT_EQ(test_text + test_text, label.GetDisplayTextForTesting()); | 219 EXPECT_EQ(test_text + test_text, label.GetDisplayTextForTesting()); |
| 213 EXPECT_EQ(test_text + test_text, label.text()); | 220 EXPECT_EQ(test_text + test_text, label.text()); |
| 214 } | 221 } |
| 215 | 222 |
| 216 TEST_F(LabelTest, ObscuredSurrogatePair) { | 223 TEST_F(LabelTest, ObscuredSurrogatePair) { |
| 217 // 'MUSICAL SYMBOL G CLEF': represented in UTF-16 as two characters | 224 // 'MUSICAL SYMBOL G CLEF': represented in UTF-16 as two characters |
| 218 // forming the surrogate pair 0x0001D11E. | 225 // forming the surrogate pair 0x0001D11E. |
| 219 Label label; | 226 Label label; |
| 220 base::string16 test_text = base::UTF8ToUTF16("\xF0\x9D\x84\x9E"); | 227 base::string16 test_text = base::UTF8ToUTF16("\xF0\x9D\x84\x9E"); |
| 221 label.SetText(test_text); | 228 label.SetText(test_text); |
| 222 label.SetObscured(true); | 229 label.SetObscured(true); |
| 223 label.SizeToPreferredSize(); | 230 label.SizeToPreferredSize(); |
| 224 EXPECT_EQ(ASCIIToUTF16("*"), label.GetDisplayTextForTesting()); | 231 EXPECT_EQ(base::string16(1, kObscuredCharacter), |
| 232 label.GetDisplayTextForTesting()); | |
| 225 EXPECT_EQ(test_text, label.text()); | 233 EXPECT_EQ(test_text, label.text()); |
| 226 } | 234 } |
| 227 | 235 |
| 228 // This test case verifies the label preferred size will change based on the | 236 // 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 | 237 // 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 | 238 // 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 | 239 // with this assumption is fixed. See http://crbug.com/468494 and |
| 232 // http://crbug.com/467526. | 240 // http://crbug.com/467526. |
| 233 // TODO(mukai): fix the code assuming this behavior and then fix Label | 241 // TODO(mukai): fix the code assuming this behavior and then fix Label |
| 234 // implementation, and remove this test case. | 242 // 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); | 727 label()->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
| 720 label()->RequestFocus(); | 728 label()->RequestFocus(); |
| 721 label()->SizeToPreferredSize(); | 729 label()->SizeToPreferredSize(); |
| 722 | 730 |
| 723 gfx::Rect focus_bounds = label()->GetFocusBounds(); | 731 gfx::Rect focus_bounds = label()->GetFocusBounds(); |
| 724 EXPECT_FALSE(focus_bounds.IsEmpty()); | 732 EXPECT_FALSE(focus_bounds.IsEmpty()); |
| 725 EXPECT_LT(label()->font_list().GetHeight(), focus_bounds.height()); | 733 EXPECT_LT(label()->font_list().GetHeight(), focus_bounds.height()); |
| 726 } | 734 } |
| 727 | 735 |
| 728 } // namespace views | 736 } // namespace views |
| OLD | NEW |