OLD | NEW |
---|---|
(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::MinSize(), GetMinSize(&layout)); | |
43 EXPECT_EQ(SizeRangeLayout::MaxSize(), 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, InvalidSizeRangeForExplicitConstruction) { | |
56 const gfx::Size kInvalidSmallSize(-1, 2); | |
57 const gfx::Size kExpectedMinSize(0, 2); | |
58 const gfx::Size kInvalidLargeSize(5, -6); | |
59 const gfx::Size kExpectedMaxSize(5, 0); | |
60 | |
61 SizeRangeLayout layout(kInvalidSmallSize, kInvalidLargeSize); | |
62 EXPECT_EQ(kExpectedMinSize, GetMinSize(&layout)); | |
63 EXPECT_EQ(kExpectedMaxSize, GetMaxSize(&layout)); | |
64 } | |
65 | |
66 TEST_F(SizeRangeLayoutTest, SizeRangeForExplicitSetSize) { | |
67 const gfx::Size kSize = gfx::Size(13, 14); | |
68 | |
69 SizeRangeLayout layout; | |
70 EXPECT_NE(kSize, GetMinSize(&layout)); | |
71 EXPECT_NE(kSize, GetMaxSize(&layout)); | |
72 | |
73 layout.SetSize(kSize); | |
74 EXPECT_EQ(kSize, GetMinSize(&layout)); | |
75 EXPECT_EQ(kSize, GetMaxSize(&layout)); | |
76 } | |
77 | |
78 TEST_F(SizeRangeLayoutTest, InvalidSizeRangesForExplicitSetSize) { | |
79 const gfx::Size kInvalidSize(-7, 8); | |
80 const gfx::Size kExpectedSize(0, 8); | |
81 | |
82 SizeRangeLayout layout; | |
83 layout.SetSize(kInvalidSize); | |
84 EXPECT_EQ(kExpectedSize, GetMinSize(&layout)); | |
85 EXPECT_EQ(kExpectedSize, GetMaxSize(&layout)); | |
86 } | |
87 | |
88 TEST_F(SizeRangeLayoutTest, GetPreferredSizeWithoutLayoutManager) { | |
89 SizeRangeLayout layout; | |
90 layout.SetLayoutManager(nullptr); | |
91 EXPECT_EQ(gfx::Size(), layout.GetPreferredSize(&host_)); | |
92 } | |
93 | |
94 TEST_F(SizeRangeLayoutTest, InternalLayoutManagerPreferredSizeIsUsed) { | |
95 const gfx::Size kSize(7, 8); | |
96 std::unique_ptr<views::test::TestLayoutManager> child_layout = | |
97 base::MakeUnique<views::test::TestLayoutManager>(); | |
98 child_layout->set_preferred_size(kSize); | |
99 | |
100 SizeRangeLayout layout; | |
101 EXPECT_NE(kSize, layout.GetPreferredSize(&host_)); | |
102 | |
103 layout.SetLayoutManager(std::move(child_layout)); | |
104 EXPECT_EQ(kSize, layout.GetPreferredSize(&host_)); | |
105 } | |
106 | |
107 TEST_F(SizeRangeLayoutTest, SmallPreferredSizeIsClamped) { | |
108 const gfx::Size kMinSize(10, 10); | |
109 const gfx::Size kMaxSize(20, 20); | |
110 const gfx::Size kLayoutPreferredSize(5, 5); | |
111 std::unique_ptr<views::test::TestLayoutManager> child_layout = | |
112 base::MakeUnique<views::test::TestLayoutManager>(); | |
113 child_layout->set_preferred_size(kLayoutPreferredSize); | |
114 | |
115 SizeRangeLayout layout; | |
116 layout.SetLayoutManager(std::move(child_layout)); | |
117 layout.SetMinSize(kMinSize); | |
118 layout.SetMaxSize(kMaxSize); | |
119 EXPECT_EQ(kMinSize, layout.GetPreferredSize(&host_)); | |
120 } | |
121 | |
122 TEST_F(SizeRangeLayoutTest, LargePreferredSizeIsClamped) { | |
123 const gfx::Size kMinSize(10, 10); | |
124 const gfx::Size kMaxSize(20, 20); | |
125 const gfx::Size kLayoutPreferredSize(25, 25); | |
126 std::unique_ptr<views::test::TestLayoutManager> child_layout = | |
127 base::MakeUnique<views::test::TestLayoutManager>(); | |
128 child_layout->set_preferred_size(kLayoutPreferredSize); | |
129 | |
130 SizeRangeLayout layout; | |
131 layout.SetLayoutManager(std::move(child_layout)); | |
132 layout.SetMinSize(kMinSize); | |
133 layout.SetMaxSize(kMaxSize); | |
134 EXPECT_EQ(kMaxSize, layout.GetPreferredSize(&host_)); | |
135 } | |
136 | |
137 TEST_F(SizeRangeLayoutTest, MaxSizeTakesPrecedenceOverMinSize) { | |
tdanderson
2016/10/19 18:30:59
Does max size win here because it was set after th
bruthig
2016/10/20 04:40:12
MaxSize wins because of the implementation of Size
tdanderson
2016/10/20 18:16:48
Works for me, thanks.
| |
138 const gfx::Size kMinSize(10, 10); | |
139 const gfx::Size kMaxSize(5, 5); | |
140 | |
141 SizeRangeLayout layout; | |
142 layout.SetMinSize(kMinSize); | |
143 layout.SetMaxSize(kMaxSize); | |
144 EXPECT_EQ(kMaxSize, layout.GetPreferredSize(&host_)); | |
145 } | |
146 | |
147 TEST_F(SizeRangeLayoutTest, | |
148 InternalLayoutManagerPreferredHeightForWidthIsUsed) { | |
149 const int kWidth = 5; | |
150 const int kHeight = 9; | |
151 std::unique_ptr<views::test::TestLayoutManager> child_layout = | |
152 base::MakeUnique<views::test::TestLayoutManager>(); | |
153 child_layout->set_preferred_height_for_width(kHeight); | |
154 | |
155 SizeRangeLayout layout; | |
156 EXPECT_NE(kHeight, layout.GetPreferredHeightForWidth(&host_, kWidth)); | |
157 | |
158 layout.SetLayoutManager(std::move(child_layout)); | |
159 EXPECT_EQ(kHeight, layout.GetPreferredHeightForWidth(&host_, kWidth)); | |
160 } | |
161 | |
162 } // namespace ash | |
OLD | NEW |