Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: ui/views/controls/label_unittest.cc

Issue 1029593004: Do not break lines when width is not specified. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/controls/label.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « ui/views/controls/label.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698