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

Side by Side Diff: ash/common/system/tray/size_range_layout_unittest.cc

Issue 2439093002: Reland of "Added common layout framework for system menu rows." (Closed)
Patch Set: Addressed review comments. 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
« no previous file with comments | « ash/common/system/tray/size_range_layout.cc ('k') | ash/common/system/tray/tray_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/common/system/tray/size_range_layout.h"
6 #include "base/memory/ptr_util.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/views/test/test_layout_manager.h"
9 #include "ui/views/view.h"
10
11 namespace ash {
12
13 class SizeRangeLayoutTest : public testing::Test {
14 public:
15 SizeRangeLayoutTest();
16
17 // Wrapper function to access the minimum preferred size of |layout|.
18 gfx::Size GetMinSize(const SizeRangeLayout* layout) const;
19
20 // Wrapper function to access the maximum preferred size of |layout|.
21 gfx::Size GetMaxSize(const SizeRangeLayout* layout) const;
22
23 protected:
24 views::View host_;
25
26 private:
27 DISALLOW_COPY_AND_ASSIGN(SizeRangeLayoutTest);
28 };
29
30 SizeRangeLayoutTest::SizeRangeLayoutTest() {}
31
32 gfx::Size SizeRangeLayoutTest::GetMinSize(const SizeRangeLayout* layout) const {
33 return layout->min_size_;
34 }
35
36 gfx::Size SizeRangeLayoutTest::GetMaxSize(const SizeRangeLayout* layout) const {
37 return layout->max_size_;
38 }
39
40 TEST_F(SizeRangeLayoutTest, SizeRangeForDefaultConstruction) {
41 SizeRangeLayout layout;
42 EXPECT_EQ(SizeRangeLayout::AbsoluteMinSize(), GetMinSize(&layout));
43 EXPECT_EQ(SizeRangeLayout::AbsoluteMaxSize(), GetMaxSize(&layout));
44 }
45
46 TEST_F(SizeRangeLayoutTest, SizeRangeForExplicitConstruction) {
47 const gfx::Size kSmallSize = gfx::Size(13, 14);
48 const gfx::Size kLargeSize = gfx::Size(25, 26);
49
50 SizeRangeLayout layout(kSmallSize, kLargeSize);
51 EXPECT_EQ(kSmallSize, GetMinSize(&layout));
52 EXPECT_EQ(kLargeSize, GetMaxSize(&layout));
53 }
54
55 TEST_F(SizeRangeLayoutTest, InvalidMinSizeForExplicitConstruction) {
56 const gfx::Size kInvalidSmallSize(-1, 2);
57 const gfx::Size kExpectedMinSize(0, 2);
58
59 SizeRangeLayout layout(kInvalidSmallSize, SizeRangeLayout::AbsoluteMaxSize());
60 EXPECT_EQ(kExpectedMinSize, GetMinSize(&layout));
61 }
62
63 TEST_F(SizeRangeLayoutTest, InvalidMaxSizeForExplicitConstruction) {
64 const gfx::Size kInvalidSmallSize(-1, 2);
65 const gfx::Size kExpectedMinSize(0, 2);
66
67 SizeRangeLayout layout(kInvalidSmallSize, SizeRangeLayout::AbsoluteMaxSize());
68 EXPECT_EQ(kExpectedMinSize, GetMinSize(&layout));
69 }
70
71 TEST_F(SizeRangeLayoutTest, MaxSizeSmallerThanMinSizeConstruction) {
72 const gfx::Size kMinSize(10, 11);
73 const gfx::Size kMaxSize(5, 6);
74
75 SizeRangeLayout layout(kMinSize, kMaxSize);
76 EXPECT_EQ(kMaxSize, GetMinSize(&layout));
77 EXPECT_EQ(kMaxSize, GetMaxSize(&layout));
78 }
79
80 TEST_F(SizeRangeLayoutTest, SizeRangeForExplicitSetSize) {
81 const gfx::Size kSize = gfx::Size(13, 14);
82
83 SizeRangeLayout layout;
84 EXPECT_NE(kSize, GetMinSize(&layout));
85 EXPECT_NE(kSize, GetMaxSize(&layout));
86
87 layout.SetSize(kSize);
88 EXPECT_EQ(kSize, GetMinSize(&layout));
89 EXPECT_EQ(kSize, GetMaxSize(&layout));
90 }
91
92 TEST_F(SizeRangeLayoutTest, InvalidSizeRangesForExplicitSetSize) {
93 const gfx::Size kInvalidSize(-7, 8);
94 const gfx::Size kExpectedSize(0, 8);
95
96 SizeRangeLayout layout;
97 layout.SetSize(kInvalidSize);
98 EXPECT_EQ(kExpectedSize, GetMinSize(&layout));
99 EXPECT_EQ(kExpectedSize, GetMaxSize(&layout));
100 }
101
102 TEST_F(SizeRangeLayoutTest, InternalLayoutManagerPreferredSizeIsUsed) {
103 const gfx::Size kSize(7, 8);
104 std::unique_ptr<views::test::TestLayoutManager> child_layout =
105 base::MakeUnique<views::test::TestLayoutManager>();
106 child_layout->set_preferred_size(kSize);
107
108 SizeRangeLayout layout;
109 EXPECT_NE(kSize, layout.GetPreferredSize(&host_));
110
111 layout.SetLayoutManager(std::move(child_layout));
112 EXPECT_EQ(kSize, layout.GetPreferredSize(&host_));
113 }
114
115 TEST_F(SizeRangeLayoutTest, SmallPreferredSizeIsClamped) {
116 const gfx::Size kMinSize(10, 10);
117 const gfx::Size kMaxSize(20, 20);
118 const gfx::Size kLayoutPreferredSize(5, 5);
119 std::unique_ptr<views::test::TestLayoutManager> child_layout =
120 base::MakeUnique<views::test::TestLayoutManager>();
121 child_layout->set_preferred_size(kLayoutPreferredSize);
122
123 SizeRangeLayout layout;
124 layout.SetLayoutManager(std::move(child_layout));
125 layout.SetMinSize(kMinSize);
126 layout.SetMaxSize(kMaxSize);
127 EXPECT_EQ(kMinSize, layout.GetPreferredSize(&host_));
128 }
129
130 TEST_F(SizeRangeLayoutTest, LargePreferredSizeIsClamped) {
131 const gfx::Size kMinSize(10, 10);
132 const gfx::Size kMaxSize(20, 20);
133 const gfx::Size kLayoutPreferredSize(25, 25);
134 std::unique_ptr<views::test::TestLayoutManager> child_layout =
135 base::MakeUnique<views::test::TestLayoutManager>();
136 child_layout->set_preferred_size(kLayoutPreferredSize);
137
138 SizeRangeLayout layout;
139 layout.SetLayoutManager(std::move(child_layout));
140 layout.SetMinSize(kMinSize);
141 layout.SetMaxSize(kMaxSize);
142 EXPECT_EQ(kMaxSize, layout.GetPreferredSize(&host_));
143 }
144
145 TEST_F(SizeRangeLayoutTest, MaxSizeLargerThanMinSizeUpdatesMinSize) {
146 const gfx::Size kMinSize(10, 10);
147 const gfx::Size kMaxSize(5, 5);
148
149 SizeRangeLayout layout;
150 layout.SetMinSize(kMinSize);
151 EXPECT_EQ(kMinSize, GetMinSize(&layout));
152 layout.SetMaxSize(kMaxSize);
153 EXPECT_EQ(kMaxSize, GetMinSize(&layout));
154 }
155
156 TEST_F(SizeRangeLayoutTest, MinSizeSmallerThanMaxSizeUpdatesMaxSize) {
157 const gfx::Size kMinSize(10, 10);
158 const gfx::Size kMaxSize(5, 5);
159
160 SizeRangeLayout layout;
161 layout.SetMaxSize(kMaxSize);
162 EXPECT_EQ(kMaxSize, GetMaxSize(&layout));
163 layout.SetMinSize(kMinSize);
164 EXPECT_EQ(kMinSize, GetMaxSize(&layout));
165 }
166
167 TEST_F(SizeRangeLayoutTest,
168 InternalLayoutManagerPreferredHeightForWidthIsUsed) {
169 const int kWidth = 5;
170 const int kHeight = 9;
171 std::unique_ptr<views::test::TestLayoutManager> child_layout =
172 base::MakeUnique<views::test::TestLayoutManager>();
173 child_layout->set_preferred_height_for_width(kHeight);
174
175 SizeRangeLayout layout;
176 EXPECT_NE(kHeight, layout.GetPreferredHeightForWidth(&host_, kWidth));
177
178 layout.SetLayoutManager(std::move(child_layout));
179 EXPECT_EQ(kHeight, layout.GetPreferredHeightForWidth(&host_, kWidth));
180 }
181
182 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/tray/size_range_layout.cc ('k') | ash/common/system/tray/tray_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698