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

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

Issue 1898633004: Views: Add new SetFocusBehavior method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 4 years, 7 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/combobox/combobox.cc ('k') | ui/views/controls/link.cc » ('j') | 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 <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"
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 Label label(base::ASCIIToUTF16("Example")); 369 Label label(base::ASCIIToUTF16("Example"));
370 gfx::Size preferred_size = label.GetPreferredSize(); 370 gfx::Size preferred_size = label.GetPreferredSize();
371 371
372 label.SetMultiLine(true); 372 label.SetMultiLine(true);
373 label.SetAllowCharacterBreak(true); 373 label.SetAllowCharacterBreak(true);
374 EXPECT_EQ(preferred_size, label.GetPreferredSize()); 374 EXPECT_EQ(preferred_size, label.GetPreferredSize());
375 } 375 }
376 376
377 TEST_F(LabelTest, MultiLineSizing) { 377 TEST_F(LabelTest, MultiLineSizing) {
378 Label label; 378 Label label;
379 label.SetFocusable(false);
380 label.SetText( 379 label.SetText(
381 ASCIIToUTF16("A random string\nwith multiple lines\nand returns!")); 380 ASCIIToUTF16("A random string\nwith multiple lines\nand returns!"));
382 label.SetMultiLine(true); 381 label.SetMultiLine(true);
383 382
384 // GetPreferredSize 383 // GetPreferredSize
385 gfx::Size required_size = label.GetPreferredSize(); 384 gfx::Size required_size = label.GetPreferredSize();
386 EXPECT_GT(required_size.height(), kMinTextDimension); 385 EXPECT_GT(required_size.height(), kMinTextDimension);
387 EXPECT_GT(required_size.width(), kMinTextDimension); 386 EXPECT_GT(required_size.width(), kMinTextDimension);
388 387
389 // SizeToFit with unlimited width. 388 // SizeToFit with unlimited width.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 EXPECT_EQ(required_size_with_border.width(), 453 EXPECT_EQ(required_size_with_border.width(),
455 required_size.width() + border.width()); 454 required_size.width() + border.width());
456 } 455 }
457 456
458 // Verifies if the combination of text eliding and multiline doesn't cause 457 // Verifies if the combination of text eliding and multiline doesn't cause
459 // any side effects of size / layout calculation. 458 // any side effects of size / layout calculation.
460 TEST_F(LabelTest, MultiLineSizingWithElide) { 459 TEST_F(LabelTest, MultiLineSizingWithElide) {
461 const base::string16 text = 460 const base::string16 text =
462 ASCIIToUTF16("A random string\nwith multiple lines\nand returns!"); 461 ASCIIToUTF16("A random string\nwith multiple lines\nand returns!");
463 Label label; 462 Label label;
464 label.SetFocusable(false);
465 label.SetText(text); 463 label.SetText(text);
466 label.SetMultiLine(true); 464 label.SetMultiLine(true);
467 465
468 gfx::Size required_size = label.GetPreferredSize(); 466 gfx::Size required_size = label.GetPreferredSize();
469 EXPECT_GT(required_size.height(), kMinTextDimension); 467 EXPECT_GT(required_size.height(), kMinTextDimension);
470 EXPECT_GT(required_size.width(), kMinTextDimension); 468 EXPECT_GT(required_size.width(), kMinTextDimension);
471 label.SetBoundsRect(gfx::Rect(required_size)); 469 label.SetBoundsRect(gfx::Rect(required_size));
472 470
473 label.SetElideBehavior(gfx::ELIDE_TAIL); 471 label.SetElideBehavior(gfx::ELIDE_TAIL);
474 EXPECT_EQ(required_size.ToString(), label.GetPreferredSize().ToString()); 472 EXPECT_EQ(required_size.ToString(), label.GetPreferredSize().ToString());
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 603
606 // There's only one 'line', RenderText itself supports multiple lines. 604 // There's only one 'line', RenderText itself supports multiple lines.
607 EXPECT_EQ(1u, label.lines_.size()); 605 EXPECT_EQ(1u, label.lines_.size());
608 } 606 }
609 #endif 607 #endif
610 608
611 TEST_F(LabelFocusTest, FocusBounds) { 609 TEST_F(LabelFocusTest, FocusBounds) {
612 label()->SetText(ASCIIToUTF16("Example")); 610 label()->SetText(ASCIIToUTF16("Example"));
613 gfx::Size normal_size = label()->GetPreferredSize(); 611 gfx::Size normal_size = label()->GetPreferredSize();
614 612
615 label()->SetFocusable(true); 613 label()->SetFocusBehavior(View::FocusBehavior::ALWAYS);
616 label()->RequestFocus(); 614 label()->RequestFocus();
617 gfx::Size focusable_size = label()->GetPreferredSize(); 615 gfx::Size focusable_size = label()->GetPreferredSize();
618 // Focusable label requires larger size to paint the focus rectangle. 616 // Focusable label requires larger size to paint the focus rectangle.
619 EXPECT_GT(focusable_size.width(), normal_size.width()); 617 EXPECT_GT(focusable_size.width(), normal_size.width());
620 EXPECT_GT(focusable_size.height(), normal_size.height()); 618 EXPECT_GT(focusable_size.height(), normal_size.height());
621 619
622 label()->SizeToPreferredSize(); 620 label()->SizeToPreferredSize();
623 gfx::Rect focus_bounds = label()->GetFocusBounds(); 621 gfx::Rect focus_bounds = label()->GetFocusBounds();
624 EXPECT_EQ(label()->GetLocalBounds().ToString(), focus_bounds.ToString()); 622 EXPECT_EQ(label()->GetLocalBounds().ToString(), focus_bounds.ToString());
625 623
(...skipping 16 matching lines...) Expand all
642 640
643 label()->SetHorizontalAlignment(gfx::ALIGN_LEFT); 641 label()->SetHorizontalAlignment(gfx::ALIGN_LEFT);
644 label()->SetElideBehavior(gfx::FADE_TAIL); 642 label()->SetElideBehavior(gfx::FADE_TAIL);
645 label()->SetBounds(0, 0, focusable_size.width() / 2, focusable_size.height()); 643 label()->SetBounds(0, 0, focusable_size.width() / 2, focusable_size.height());
646 focus_bounds = label()->GetFocusBounds(); 644 focus_bounds = label()->GetFocusBounds();
647 EXPECT_EQ(0, focus_bounds.x()); 645 EXPECT_EQ(0, focus_bounds.x());
648 EXPECT_EQ(focusable_size.width() / 2, focus_bounds.width()); 646 EXPECT_EQ(focusable_size.width() / 2, focus_bounds.width());
649 } 647 }
650 648
651 TEST_F(LabelFocusTest, EmptyLabel) { 649 TEST_F(LabelFocusTest, EmptyLabel) {
652 label()->SetFocusable(true); 650 label()->SetFocusBehavior(View::FocusBehavior::ALWAYS);
653 label()->RequestFocus(); 651 label()->RequestFocus();
654 label()->SizeToPreferredSize(); 652 label()->SizeToPreferredSize();
655 653
656 gfx::Rect focus_bounds = label()->GetFocusBounds(); 654 gfx::Rect focus_bounds = label()->GetFocusBounds();
657 EXPECT_FALSE(focus_bounds.IsEmpty()); 655 EXPECT_FALSE(focus_bounds.IsEmpty());
658 EXPECT_LT(label()->font_list().GetHeight(), focus_bounds.height()); 656 EXPECT_LT(label()->font_list().GetHeight(), focus_bounds.height());
659 } 657 }
660 658
661 } // namespace views 659 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/combobox/combobox.cc ('k') | ui/views/controls/link.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698