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

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

Issue 2480813003: Reduce views::Border creation verbosity by promoting factory functions (Closed)
Patch Set: fix bad merge Created 4 years, 1 month 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
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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 label.SetText(ASCIIToUTF16("A not so random string in one line.")); 377 label.SetText(ASCIIToUTF16("A not so random string in one line."));
378 const gfx::Size size = label.GetPreferredSize(); 378 const gfx::Size size = label.GetPreferredSize();
379 EXPECT_GT(size.height(), kMinTextDimension); 379 EXPECT_GT(size.height(), kMinTextDimension);
380 EXPECT_GT(size.width(), kMinTextDimension); 380 EXPECT_GT(size.width(), kMinTextDimension);
381 381
382 // Setting a size smaller than preferred should not change the preferred size. 382 // Setting a size smaller than preferred should not change the preferred size.
383 label.SetSize(gfx::Size(size.width() / 2, size.height() / 2)); 383 label.SetSize(gfx::Size(size.width() / 2, size.height() / 2));
384 EXPECT_EQ(size, label.GetPreferredSize()); 384 EXPECT_EQ(size, label.GetPreferredSize());
385 385
386 const gfx::Insets border(10, 20, 30, 40); 386 const gfx::Insets border(10, 20, 30, 40);
387 label.SetBorder(Border::CreateEmptyBorder( 387 label.SetBorder(CreateEmptyBorder(border.top(), border.left(),
388 border.top(), border.left(), border.bottom(), border.right())); 388 border.bottom(), border.right()));
389 const gfx::Size size_with_border = label.GetPreferredSize(); 389 const gfx::Size size_with_border = label.GetPreferredSize();
390 EXPECT_EQ(size_with_border.height(), size.height() + border.height()); 390 EXPECT_EQ(size_with_border.height(), size.height() + border.height());
391 EXPECT_EQ(size_with_border.width(), size.width() + border.width()); 391 EXPECT_EQ(size_with_border.width(), size.width() + border.width());
392 EXPECT_EQ(size.height() + border.height(), 392 EXPECT_EQ(size.height() + border.height(),
393 label.GetHeightForWidth(size_with_border.width())); 393 label.GetHeightForWidth(size_with_border.width()));
394 } 394 }
395 395
396 TEST_F(LabelTest, MultilineSmallAvailableWidthSizing) { 396 TEST_F(LabelTest, MultilineSmallAvailableWidthSizing) {
397 Label label; 397 Label label;
398 label.SetMultiLine(true); 398 label.SetMultiLine(true);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 EXPECT_GT(height_for_constrained_width, required_height); 458 EXPECT_GT(height_for_constrained_width, required_height);
459 #endif 459 #endif
460 // Using the constrained width or the required_width - 1 should give the 460 // Using the constrained width or the required_width - 1 should give the
461 // same result for the height because the constrainted width is the tight 461 // same result for the height because the constrainted width is the tight
462 // width when given "required_width - 1" as the max width. 462 // width when given "required_width - 1" as the max width.
463 EXPECT_EQ(height_for_constrained_width, 463 EXPECT_EQ(height_for_constrained_width,
464 label.GetHeightForWidth(required_width - 1)); 464 label.GetHeightForWidth(required_width - 1));
465 465
466 // Test everything with borders. 466 // Test everything with borders.
467 gfx::Insets border(10, 20, 30, 40); 467 gfx::Insets border(10, 20, 30, 40);
468 label.SetBorder(Border::CreateEmptyBorder( 468 label.SetBorder(CreateEmptyBorder(border.top(), border.left(),
469 border.top(), border.left(), border.bottom(), border.right())); 469 border.bottom(), border.right()));
470 470
471 // SizeToFit and borders. 471 // SizeToFit and borders.
472 label.SizeToFit(0); 472 label.SizeToFit(0);
473 int required_width_with_border = label.GetLocalBounds().width(); 473 int required_width_with_border = label.GetLocalBounds().width();
474 EXPECT_EQ(required_width_with_border, required_width + border.width()); 474 EXPECT_EQ(required_width_with_border, required_width + border.width());
475 475
476 // GetHeightForWidth and borders. 476 // GetHeightForWidth and borders.
477 int required_height_with_border = 477 int required_height_with_border =
478 label.GetHeightForWidth(required_width_with_border); 478 label.GetHeightForWidth(required_width_with_border);
479 EXPECT_EQ(required_height_with_border, required_height + border.height()); 479 EXPECT_EQ(required_height_with_border, required_height + border.height());
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 label()->SetFocusBehavior(View::FocusBehavior::ALWAYS); 724 label()->SetFocusBehavior(View::FocusBehavior::ALWAYS);
725 label()->RequestFocus(); 725 label()->RequestFocus();
726 label()->SizeToPreferredSize(); 726 label()->SizeToPreferredSize();
727 727
728 gfx::Rect focus_bounds = label()->GetFocusBounds(); 728 gfx::Rect focus_bounds = label()->GetFocusBounds();
729 EXPECT_FALSE(focus_bounds.IsEmpty()); 729 EXPECT_FALSE(focus_bounds.IsEmpty());
730 EXPECT_LT(label()->font_list().GetHeight(), focus_bounds.height()); 730 EXPECT_LT(label()->font_list().GetHeight(), focus_bounds.height());
731 } 731 }
732 732
733 } // namespace views 733 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/vector_icon_button.cc ('k') | ui/views/controls/menu/menu_scroll_view_container.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698