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

Side by Side Diff: views/layout/grid_layout_unittest.cc

Issue 7349021: Convert some more view methods to the ui/views style. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
« no previous file with comments | « views/layout/fill_layout.cc ('k') | views/view.h » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/layout/grid_layout.h" 6 #include "views/layout/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;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 virtual void SetUp() { 56 virtual void SetUp() {
57 layout = new GridLayout(&host); 57 layout = new GridLayout(&host);
58 } 58 }
59 59
60 virtual void TearDown() { 60 virtual void TearDown() {
61 delete layout; 61 delete layout;
62 } 62 }
63 63
64 virtual void RemoveAll() { 64 virtual void RemoveAll() {
65 for (int i = host.child_count() - 1; i >= 0; i--) 65 for (int i = host.child_count() - 1; i >= 0; i--)
66 host.RemoveChildView(host.GetChildViewAt(i)); 66 host.RemoveChildView(host.child_at(i));
67 } 67 }
68 68
69 void GetPreferredSize() { 69 void GetPreferredSize() {
70 pref = layout->GetPreferredSize(&host); 70 pref = layout->GetPreferredSize(&host);
71 } 71 }
72 72
73 gfx::Size pref; 73 gfx::Size pref;
74 gfx::Rect bounds; 74 gfx::Rect bounds;
75 View host; 75 View host;
76 GridLayout* layout; 76 GridLayout* layout;
77 }; 77 };
78 78
79 class GridLayoutAlignmentTest : public testing::Test { 79 class GridLayoutAlignmentTest : public testing::Test {
80 public: 80 public:
81 GridLayoutAlignmentTest() : 81 GridLayoutAlignmentTest() :
82 host(), 82 host(),
83 v1(gfx::Size(10, 20)), 83 v1(gfx::Size(10, 20)),
84 layout(new GridLayout(&host)) {} 84 layout(new GridLayout(&host)) {}
85 85
86 virtual void SetUp() { 86 virtual void SetUp() {
87 } 87 }
88 88
89 virtual void TearDown() { 89 virtual void TearDown() {
90 delete layout; 90 delete layout;
91 } 91 }
92 92
93 virtual void RemoveAll() { 93 virtual void RemoveAll() {
94 for (int i = host.child_count() - 1; i >= 0; i--) 94 for (int i = host.child_count() - 1; i >= 0; i--)
95 host.RemoveChildView(host.GetChildViewAt(i)); 95 host.RemoveChildView(host.child_at(i));
96 } 96 }
97 97
98 void TestAlignment(GridLayout::Alignment alignment, gfx::Rect* bounds) { 98 void TestAlignment(GridLayout::Alignment alignment, gfx::Rect* bounds) {
99 ColumnSet* c1 = layout->AddColumnSet(0); 99 ColumnSet* c1 = layout->AddColumnSet(0);
100 c1->AddColumn(alignment, alignment, 1, GridLayout::USE_PREF, 0, 0); 100 c1->AddColumn(alignment, alignment, 1, GridLayout::USE_PREF, 0, 0);
101 layout->StartRow(1, 0); 101 layout->StartRow(1, 0);
102 layout->AddView(&v1); 102 layout->AddView(&v1);
103 gfx::Size pref = layout->GetPreferredSize(&host); 103 gfx::Size pref = layout->GetPreferredSize(&host);
104 EXPECT_EQ(gfx::Size(10, 20), pref); 104 EXPECT_EQ(gfx::Size(10, 20), pref);
105 host.SetBounds(0, 0, 100, 100); 105 host.SetBounds(0, 0, 100, 100);
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 layout->StartRow(0, 0); 395 layout->StartRow(0, 0);
396 for (int col = 0; col < column_count; ++col) { 396 for (int col = 0; col < column_count; ++col) {
397 layout->AddView(new SettableSizeView(gfx::Size(pref_width, pref_height))); 397 layout->AddView(new SettableSizeView(gfx::Size(pref_width, pref_height)));
398 } 398 }
399 } 399 }
400 400
401 layout->Layout(&host); 401 layout->Layout(&host);
402 402
403 for (int i = 0; i < column_count; ++i) { 403 for (int i = 0; i < column_count; ++i) {
404 for (int row = 0; row < row_count; ++row) { 404 for (int row = 0; row < row_count; ++row) {
405 View* view = host.GetChildViewAt(row * column_count + i); 405 View* view = host.child_at(row * column_count + i);
406 ExpectViewBoundsEquals( 406 ExpectViewBoundsEquals(
407 2 + title_width * i + (title_width - pref_width) / 2, 407 2 + title_width * i + (title_width - pref_width) / 2,
408 2 + pref_height * row, 408 2 + pref_height * row,
409 pref_width, 409 pref_width,
410 pref_height, view); 410 pref_height, view);
411 } 411 }
412 } 412 }
413 413
414 GetPreferredSize(); 414 GetPreferredSize();
415 EXPECT_EQ(gfx::Size(column_count * title_width + 4, 415 EXPECT_EQ(gfx::Size(column_count * title_width + 4,
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 // ordering doesn't influence sizing behaviour. 597 // ordering doesn't influence sizing behaviour.
598 layout->StartRow(0, 2); 598 layout->StartRow(0, 2);
599 View* view3 = new FlexibleView(40); 599 View* view3 = new FlexibleView(40);
600 layout->AddView(view3, 1, 1, GridLayout::FILL, GridLayout::LEADING); 600 layout->AddView(view3, 1, 1, GridLayout::FILL, GridLayout::LEADING);
601 601
602 // We expect a height of 50: 30 from the variable width view in the first row 602 // We expect a height of 50: 30 from the variable width view in the first row
603 // plus 20 from the statically sized view in the second row. The flexible 603 // plus 20 from the statically sized view in the second row. The flexible
604 // view in the third row should contribute no height. 604 // view in the third row should contribute no height.
605 EXPECT_EQ(gfx::Size(20, 50), layout->GetPreferredSize(&host)); 605 EXPECT_EQ(gfx::Size(20, 50), layout->GetPreferredSize(&host));
606 } 606 }
OLDNEW
« no previous file with comments | « views/layout/fill_layout.cc ('k') | views/view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698