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

Side by Side Diff: views/grid_layout_unittest.cc

Issue 2812026: Auto-size the views version of the options dialog. (Closed)
Patch Set: Fix autosizing issue with gtk pref pages in chromeos options dialog. Created 10 years, 5 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 | « views/grid_layout.cc ('k') | views/view.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "views/grid_layout.h" 6 #include "views/grid_layout.h"
7 #include "views/view.h" 7 #include "views/view.h"
8 8
9 using views::ColumnSet; 9 using views::ColumnSet;
10 using views::GridLayout; 10 using views::GridLayout;
11 using views::View; 11 using views::View;
(...skipping 13 matching lines...) Expand all
25 } 25 }
26 26
27 virtual gfx::Size GetPreferredSize() { 27 virtual gfx::Size GetPreferredSize() {
28 return pref_; 28 return pref_;
29 } 29 }
30 30
31 private: 31 private:
32 gfx::Size pref_; 32 gfx::Size pref_;
33 }; 33 };
34 34
35 // A view with fixed circumference that trades height for width.
36 class FlexibleView : public View {
37 public:
38 explicit FlexibleView(int circumference) {
39 circumference_ = circumference;
40 }
41
42 virtual gfx::Size GetPreferredSize() {
43 return gfx::Size(0, circumference_ / 2);
44 }
45
46 virtual int GetHeightForWidth(int width) {
47 return std::max(0, circumference_ / 2 - width);
48 }
49
50 private:
51 int circumference_;
52 };
53
35 class GridLayoutTest : public testing::Test { 54 class GridLayoutTest : public testing::Test {
36 public: 55 public:
37 virtual void SetUp() { 56 virtual void SetUp() {
38 layout = new GridLayout(&host); 57 layout = new GridLayout(&host);
39 } 58 }
40 59
41 virtual void TearDown() { 60 virtual void TearDown() {
42 delete layout; 61 delete layout;
43 } 62 }
44 63
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 560
542 // view1 should be 4 pixels wide 561 // view1 should be 4 pixels wide
543 // column_pref + (remaining_width * column_resize / total_column_resize) = 562 // column_pref + (remaining_width * column_resize / total_column_resize) =
544 // 2 + (6 * 2 / 6). 563 // 2 + (6 * 2 / 6).
545 ExpectViewBoundsEquals(0, 40, 4, 40, view1); 564 ExpectViewBoundsEquals(0, 40, 4, 40, view1);
546 565
547 // And view2 should be 8 pixels wide: 566 // And view2 should be 8 pixels wide:
548 // 4 + (6 * 4 / 6). 567 // 4 + (6 * 4 / 6).
549 ExpectViewBoundsEquals(4, 40, 8, 40, view2); 568 ExpectViewBoundsEquals(4, 40, 8, 40, view2);
550 } 569 }
570
571 // Check that GetPreferredSize() takes resizing of columns into account when
572 // there is additional space in the case we have column sets of different
573 // preferred sizes.
574 TEST_F(GridLayoutTest, ColumnResizingOnGetPreferredSize) {
575 views::ColumnSet* set = layout->AddColumnSet(0);
576 set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
577 1, views::GridLayout::USE_PREF, 0, 0);
578
579 set = layout->AddColumnSet(1);
580 set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
581 1, views::GridLayout::USE_PREF, 0, 0);
582
583 set = layout->AddColumnSet(2);
584 set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
585 1, views::GridLayout::USE_PREF, 0, 0);
586
587 // Make a row containing a flexible view that trades width for height.
588 layout->StartRow(0, 0);
589 View* view1 = new FlexibleView(100);
590 layout->AddView(view1, 1, 1, GridLayout::FILL, GridLayout::LEADING);
591
592 // The second row contains a view of fixed size that will enforce a column
593 // width of 20 pixels.
594 layout->StartRow(0, 1);
595 View* view2 = new SettableSizeView(gfx::Size(20, 20));
596 layout->AddView(view2, 1, 1, GridLayout::FILL, GridLayout::LEADING);
597
598 // Add another flexible view in row three in order to ensure column set
599 // ordering doesn't influence sizing behaviour.
600 layout->StartRow(0, 2);
601 View* view3 = new FlexibleView(40);
602 layout->AddView(view3, 1, 1, GridLayout::FILL, GridLayout::LEADING);
603
604 // We expect a height of 50: 30 from the variable width view in the first row
605 // plus 20 from the statically sized view in the second row. The flexible
606 // view in the third row should contribute no height.
607 EXPECT_EQ(gfx::Size(20, 50), layout->GetPreferredSize(&host));
608 }
OLDNEW
« no previous file with comments | « views/grid_layout.cc ('k') | views/view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698