| 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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 label.SetText(ASCIIToUTF16("Too Wide.")); | 351 label.SetText(ASCIIToUTF16("Too Wide.")); |
| 352 | 352 |
| 353 // Check that Label can be laid out at a variety of small sizes, | 353 // Check that Label can be laid out at a variety of small sizes, |
| 354 // splitting the words into up to one character per line if necessary. | 354 // splitting the words into up to one character per line if necessary. |
| 355 // Incorrect word splitting may cause infinite loops in text layout. | 355 // Incorrect word splitting may cause infinite loops in text layout. |
| 356 gfx::Size required_size = label.GetPreferredSize(); | 356 gfx::Size required_size = label.GetPreferredSize(); |
| 357 for (int i = 1; i < required_size.width(); ++i) | 357 for (int i = 1; i < required_size.width(); ++i) |
| 358 EXPECT_GT(label.GetHeightForWidth(i), 0); | 358 EXPECT_GT(label.GetHeightForWidth(i), 0); |
| 359 } | 359 } |
| 360 | 360 |
| 361 // Verifies if SetAllowCharacterBreak(true) doesn't change the preferred size. |
| 362 // See crbug.com/469559 |
| 363 TEST_F(LabelTest, PreferredSizeForAllowCharacterBreak) { |
| 364 Label label(base::ASCIIToUTF16("Example")); |
| 365 gfx::Size preferred_size = label.GetPreferredSize(); |
| 366 |
| 367 label.SetMultiLine(true); |
| 368 label.SetAllowCharacterBreak(true); |
| 369 EXPECT_EQ(preferred_size, label.GetPreferredSize()); |
| 370 } |
| 371 |
| 361 TEST_F(LabelTest, MultiLineSizing) { | 372 TEST_F(LabelTest, MultiLineSizing) { |
| 362 Label label; | 373 Label label; |
| 363 label.SetFocusable(false); | 374 label.SetFocusable(false); |
| 364 label.SetText( | 375 label.SetText( |
| 365 ASCIIToUTF16("A random string\nwith multiple lines\nand returns!")); | 376 ASCIIToUTF16("A random string\nwith multiple lines\nand returns!")); |
| 366 label.SetMultiLine(true); | 377 label.SetMultiLine(true); |
| 367 | 378 |
| 368 // GetPreferredSize | 379 // GetPreferredSize |
| 369 gfx::Size required_size = label.GetPreferredSize(); | 380 gfx::Size required_size = label.GetPreferredSize(); |
| 370 EXPECT_GT(required_size.height(), kMinTextDimension); | 381 EXPECT_GT(required_size.height(), kMinTextDimension); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 label()->SetFocusable(true); | 646 label()->SetFocusable(true); |
| 636 label()->RequestFocus(); | 647 label()->RequestFocus(); |
| 637 label()->SizeToPreferredSize(); | 648 label()->SizeToPreferredSize(); |
| 638 | 649 |
| 639 gfx::Rect focus_bounds = label()->GetFocusBounds(); | 650 gfx::Rect focus_bounds = label()->GetFocusBounds(); |
| 640 EXPECT_FALSE(focus_bounds.IsEmpty()); | 651 EXPECT_FALSE(focus_bounds.IsEmpty()); |
| 641 EXPECT_LT(label()->font_list().GetHeight(), focus_bounds.height()); | 652 EXPECT_LT(label()->font_list().GetHeight(), focus_bounds.height()); |
| 642 } | 653 } |
| 643 | 654 |
| 644 } // namespace views | 655 } // namespace views |
| OLD | NEW |