OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/frame/caption_buttons/frame_caption_button_container_view.h" | 5 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" |
6 | 6 |
7 #include "ash/common/ash_layout_constants.h" | 7 #include "ash/common/ash_layout_constants.h" |
8 #include "ash/frame/caption_buttons/frame_caption_button.h" | 8 #include "ash/frame/caption_buttons/frame_caption_button.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 bool can_maximize_; | 33 bool can_maximize_; |
34 bool can_minimize_; | 34 bool can_minimize_; |
35 | 35 |
36 DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate); | 36 DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate); |
37 }; | 37 }; |
38 | 38 |
39 } // namespace | 39 } // namespace |
40 | 40 |
41 class FrameCaptionButtonContainerViewTest : public ash::test::AshTestBase { | 41 class FrameCaptionButtonContainerViewTest : public ash::test::AshTestBase { |
42 public: | 42 public: |
43 enum MaximizeAllowed { | 43 enum MaximizeAllowed { MAXIMIZE_ALLOWED, MAXIMIZE_DISALLOWED }; |
44 MAXIMIZE_ALLOWED, | |
45 MAXIMIZE_DISALLOWED | |
46 }; | |
47 | 44 |
48 enum MinimizeAllowed { | 45 enum MinimizeAllowed { MINIMIZE_ALLOWED, MINIMIZE_DISALLOWED }; |
49 MINIMIZE_ALLOWED, | |
50 MINIMIZE_DISALLOWED | |
51 }; | |
52 | 46 |
53 FrameCaptionButtonContainerViewTest() { | 47 FrameCaptionButtonContainerViewTest() {} |
54 } | |
55 | 48 |
56 ~FrameCaptionButtonContainerViewTest() override {} | 49 ~FrameCaptionButtonContainerViewTest() override {} |
57 | 50 |
58 // Creates a widget which allows maximizing based on |maximize_allowed|. | 51 // Creates a widget which allows maximizing based on |maximize_allowed|. |
59 // The caller takes ownership of the returned widget. | 52 // The caller takes ownership of the returned widget. |
60 views::Widget* CreateTestWidget( | 53 views::Widget* CreateTestWidget(MaximizeAllowed maximize_allowed, |
61 MaximizeAllowed maximize_allowed, | 54 MinimizeAllowed minimize_allowed) |
62 MinimizeAllowed minimize_allowed) WARN_UNUSED_RESULT { | 55 WARN_UNUSED_RESULT { |
63 views::Widget* widget = new views::Widget; | 56 views::Widget* widget = new views::Widget; |
64 views::Widget::InitParams params; | 57 views::Widget::InitParams params; |
65 params.delegate = new TestWidgetDelegate( | 58 params.delegate = |
66 maximize_allowed == MAXIMIZE_ALLOWED, | 59 new TestWidgetDelegate(maximize_allowed == MAXIMIZE_ALLOWED, |
67 minimize_allowed == MINIMIZE_ALLOWED); | 60 minimize_allowed == MINIMIZE_ALLOWED); |
68 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 61 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
69 params.context = CurrentContext(); | 62 params.context = CurrentContext(); |
70 widget->Init(params); | 63 widget->Init(params); |
71 return widget; | 64 return widget; |
72 } | 65 } |
73 | 66 |
74 // Sets arbitrary images for the icons and assign the default caption button | 67 // Sets arbitrary images for the icons and assign the default caption button |
75 // size to the buttons in |container|. | 68 // size to the buttons in |container|. |
76 void InitContainer(FrameCaptionButtonContainerView* container) { | 69 void InitContainer(FrameCaptionButtonContainerView* container) { |
77 container->SetButtonSize( | 70 container->SetButtonSize( |
78 GetAshLayoutSize(AshLayoutSize::NON_BROWSER_CAPTION_BUTTON)); | 71 GetAshLayoutSize(AshLayoutSize::NON_BROWSER_CAPTION_BUTTON)); |
79 for (int icon = 0; icon < CAPTION_BUTTON_ICON_COUNT; ++icon) { | 72 for (int icon = 0; icon < CAPTION_BUTTON_ICON_COUNT; ++icon) { |
80 container->SetButtonImage(static_cast<CaptionButtonIcon>(icon), | 73 container->SetButtonImage(static_cast<CaptionButtonIcon>(icon), |
81 gfx::VectorIconId::WINDOW_CONTROL_CLOSE); | 74 gfx::VectorIconId::WINDOW_CONTROL_CLOSE); |
82 } | 75 } |
83 } | 76 } |
84 | 77 |
85 // Tests that |leftmost| and |rightmost| are at |container|'s edges. | 78 // Tests that |leftmost| and |rightmost| are at |container|'s edges. |
86 bool CheckButtonsAtEdges(FrameCaptionButtonContainerView* container, | 79 bool CheckButtonsAtEdges(FrameCaptionButtonContainerView* container, |
87 const ash::FrameCaptionButton& leftmost, | 80 const ash::FrameCaptionButton& leftmost, |
88 const ash::FrameCaptionButton& rightmost) { | 81 const ash::FrameCaptionButton& rightmost) { |
89 gfx::Rect expected(container->GetPreferredSize()); | 82 gfx::Rect expected(container->GetPreferredSize()); |
90 | 83 |
91 gfx::Rect container_size(container->GetPreferredSize()); | 84 gfx::Rect container_size(container->GetPreferredSize()); |
92 if (leftmost.y() == rightmost.y() && | 85 if (leftmost.y() == rightmost.y() && |
93 leftmost.height() == rightmost.height() && | 86 leftmost.height() == rightmost.height() && |
94 leftmost.x() == expected.x() && | 87 leftmost.x() == expected.x() && leftmost.y() == expected.y() && |
95 leftmost.y() == expected.y() && | |
96 leftmost.height() == expected.height() && | 88 leftmost.height() == expected.height() && |
97 rightmost.bounds().right() == expected.right()) { | 89 rightmost.bounds().right() == expected.right()) { |
98 return true; | 90 return true; |
99 } | 91 } |
100 | 92 |
101 LOG(ERROR) << "Buttons " << leftmost.bounds().ToString() << " " | 93 LOG(ERROR) << "Buttons " << leftmost.bounds().ToString() << " " |
102 << rightmost.bounds().ToString() << " not at edges of " | 94 << rightmost.bounds().ToString() << " not at edges of " |
103 << expected.ToString(); | 95 << expected.ToString(); |
104 return false; | 96 return false; |
105 } | 97 } |
106 | 98 |
107 private: | 99 private: |
108 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerViewTest); | 100 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerViewTest); |
109 }; | 101 }; |
110 | 102 |
111 // Test how the allowed actions affect which caption buttons are visible. | 103 // Test how the allowed actions affect which caption buttons are visible. |
112 TEST_F(FrameCaptionButtonContainerViewTest, ButtonVisibility) { | 104 TEST_F(FrameCaptionButtonContainerViewTest, ButtonVisibility) { |
113 // All the buttons should be visible when minimizing and maximizing are | 105 // All the buttons should be visible when minimizing and maximizing are |
114 // allowed. | 106 // allowed. |
115 FrameCaptionButtonContainerView container1( | 107 FrameCaptionButtonContainerView container1( |
116 CreateTestWidget(MAXIMIZE_ALLOWED, MINIMIZE_ALLOWED)); | 108 CreateTestWidget(MAXIMIZE_ALLOWED, MINIMIZE_ALLOWED)); |
117 InitContainer(&container1); | 109 InitContainer(&container1); |
118 container1.Layout(); | 110 container1.Layout(); |
119 FrameCaptionButtonContainerView::TestApi t1(&container1); | 111 FrameCaptionButtonContainerView::TestApi t1(&container1); |
120 EXPECT_TRUE(t1.minimize_button()->visible()); | 112 EXPECT_TRUE(t1.minimize_button()->visible()); |
121 EXPECT_TRUE(t1.size_button()->visible()); | 113 EXPECT_TRUE(t1.size_button()->visible()); |
122 EXPECT_TRUE(t1.close_button()->visible()); | 114 EXPECT_TRUE(t1.close_button()->visible()); |
123 EXPECT_TRUE(CheckButtonsAtEdges( | 115 EXPECT_TRUE(CheckButtonsAtEdges(&container1, *t1.minimize_button(), |
124 &container1, *t1.minimize_button(), *t1.close_button())); | 116 *t1.close_button())); |
125 | 117 |
126 // The minimize button should be visible when minimizing is allowed but | 118 // The minimize button should be visible when minimizing is allowed but |
127 // maximizing is disallowed. | 119 // maximizing is disallowed. |
128 FrameCaptionButtonContainerView container2( | 120 FrameCaptionButtonContainerView container2( |
129 CreateTestWidget(MAXIMIZE_DISALLOWED, MINIMIZE_ALLOWED)); | 121 CreateTestWidget(MAXIMIZE_DISALLOWED, MINIMIZE_ALLOWED)); |
130 InitContainer(&container2); | 122 InitContainer(&container2); |
131 container2.Layout(); | 123 container2.Layout(); |
132 FrameCaptionButtonContainerView::TestApi t2(&container2); | 124 FrameCaptionButtonContainerView::TestApi t2(&container2); |
133 EXPECT_TRUE(t2.minimize_button()->visible()); | 125 EXPECT_TRUE(t2.minimize_button()->visible()); |
134 EXPECT_FALSE(t2.size_button()->visible()); | 126 EXPECT_FALSE(t2.size_button()->visible()); |
135 EXPECT_TRUE(t2.close_button()->visible()); | 127 EXPECT_TRUE(t2.close_button()->visible()); |
136 EXPECT_TRUE(CheckButtonsAtEdges( | 128 EXPECT_TRUE(CheckButtonsAtEdges(&container2, *t2.minimize_button(), |
137 &container2, *t2.minimize_button(), *t2.close_button())); | 129 *t2.close_button())); |
138 | 130 |
139 // Neither the minimize button nor the size button should be visible when | 131 // Neither the minimize button nor the size button should be visible when |
140 // neither minimizing nor maximizing are allowed. | 132 // neither minimizing nor maximizing are allowed. |
141 FrameCaptionButtonContainerView container3( | 133 FrameCaptionButtonContainerView container3( |
142 CreateTestWidget(MAXIMIZE_DISALLOWED, MINIMIZE_DISALLOWED)); | 134 CreateTestWidget(MAXIMIZE_DISALLOWED, MINIMIZE_DISALLOWED)); |
143 InitContainer(&container3); | 135 InitContainer(&container3); |
144 container3.Layout(); | 136 container3.Layout(); |
145 FrameCaptionButtonContainerView::TestApi t3(&container3); | 137 FrameCaptionButtonContainerView::TestApi t3(&container3); |
146 EXPECT_FALSE(t3.minimize_button()->visible()); | 138 EXPECT_FALSE(t3.minimize_button()->visible()); |
147 EXPECT_FALSE(t3.size_button()->visible()); | 139 EXPECT_FALSE(t3.size_button()->visible()); |
148 EXPECT_TRUE(t3.close_button()->visible()); | 140 EXPECT_TRUE(t3.close_button()->visible()); |
149 EXPECT_TRUE(CheckButtonsAtEdges( | 141 EXPECT_TRUE( |
150 &container3, *t3.close_button(), *t3.close_button())); | 142 CheckButtonsAtEdges(&container3, *t3.close_button(), *t3.close_button())); |
151 } | 143 } |
152 | 144 |
153 // Tests that the layout animations trigered by button visibility result in the | 145 // Tests that the layout animations trigered by button visibility result in the |
154 // correct placement of the buttons. | 146 // correct placement of the buttons. |
155 TEST_F(FrameCaptionButtonContainerViewTest, | 147 TEST_F(FrameCaptionButtonContainerViewTest, |
156 TestUpdateSizeButtonVisibilityAnimation) { | 148 TestUpdateSizeButtonVisibilityAnimation) { |
157 FrameCaptionButtonContainerView container( | 149 FrameCaptionButtonContainerView container( |
158 CreateTestWidget(MAXIMIZE_ALLOWED, MINIMIZE_ALLOWED)); | 150 CreateTestWidget(MAXIMIZE_ALLOWED, MINIMIZE_ALLOWED)); |
159 InitContainer(&container); | 151 InitContainer(&container); |
160 container.SetBoundsRect(gfx::Rect(container.GetPreferredSize())); | 152 container.SetBoundsRect(gfx::Rect(container.GetPreferredSize())); |
161 container.Layout(); | 153 container.Layout(); |
162 | 154 |
163 FrameCaptionButtonContainerView::TestApi test(&container); | 155 FrameCaptionButtonContainerView::TestApi test(&container); |
164 gfx::Rect initial_minimize_button_bounds = test.minimize_button()->bounds(); | 156 gfx::Rect initial_minimize_button_bounds = test.minimize_button()->bounds(); |
165 gfx::Rect initial_size_button_bounds = test.size_button()->bounds(); | 157 gfx::Rect initial_size_button_bounds = test.size_button()->bounds(); |
166 gfx::Rect initial_close_button_bounds = test.close_button()->bounds(); | 158 gfx::Rect initial_close_button_bounds = test.close_button()->bounds(); |
167 gfx::Rect initial_container_bounds = container.bounds(); | 159 gfx::Rect initial_container_bounds = container.bounds(); |
168 | 160 |
169 ASSERT_EQ(initial_size_button_bounds.x(), | 161 ASSERT_EQ(initial_size_button_bounds.x(), |
170 initial_minimize_button_bounds.right()); | 162 initial_minimize_button_bounds.right()); |
171 ASSERT_EQ(initial_close_button_bounds.x(), | 163 ASSERT_EQ(initial_close_button_bounds.x(), |
172 initial_size_button_bounds.right()); | 164 initial_size_button_bounds.right()); |
173 | 165 |
174 // Hidden size button should result in minimize button animating to the | 166 // Hidden size button should result in minimize button animating to the |
175 // right. The size button should not be visible, but should not have moved. | 167 // right. The size button should not be visible, but should not have moved. |
176 Shell::GetInstance()->maximize_mode_controller()-> | 168 Shell::GetInstance() |
177 EnableMaximizeModeWindowManager(true); | 169 ->maximize_mode_controller() |
| 170 ->EnableMaximizeModeWindowManager(true); |
178 container.UpdateSizeButtonVisibility(); | 171 container.UpdateSizeButtonVisibility(); |
179 test.EndAnimations(); | 172 test.EndAnimations(); |
180 // Parent needs to layout in response to size change. | 173 // Parent needs to layout in response to size change. |
181 container.Layout(); | 174 container.Layout(); |
182 | 175 |
183 EXPECT_TRUE(test.minimize_button()->visible()); | 176 EXPECT_TRUE(test.minimize_button()->visible()); |
184 EXPECT_FALSE(test.size_button()->visible()); | 177 EXPECT_FALSE(test.size_button()->visible()); |
185 EXPECT_TRUE(test.close_button()->visible()); | 178 EXPECT_TRUE(test.close_button()->visible()); |
186 gfx::Rect minimize_button_bounds = test.minimize_button()->bounds(); | 179 gfx::Rect minimize_button_bounds = test.minimize_button()->bounds(); |
187 gfx::Rect close_button_bounds = test.close_button()->bounds(); | 180 gfx::Rect close_button_bounds = test.close_button()->bounds(); |
188 EXPECT_EQ(close_button_bounds.x(), minimize_button_bounds.right()); | 181 EXPECT_EQ(close_button_bounds.x(), minimize_button_bounds.right()); |
189 EXPECT_EQ(initial_size_button_bounds, test.size_button()->bounds()); | 182 EXPECT_EQ(initial_size_button_bounds, test.size_button()->bounds()); |
190 EXPECT_EQ(initial_close_button_bounds.size(), close_button_bounds.size()); | 183 EXPECT_EQ(initial_close_button_bounds.size(), close_button_bounds.size()); |
191 EXPECT_LT(container.GetPreferredSize().width(), | 184 EXPECT_LT(container.GetPreferredSize().width(), |
192 initial_container_bounds.width()); | 185 initial_container_bounds.width()); |
193 | 186 |
194 // Revealing the size button should cause the minimize button to return to its | 187 // Revealing the size button should cause the minimize button to return to its |
195 // original position. | 188 // original position. |
196 Shell::GetInstance()->maximize_mode_controller()-> | 189 Shell::GetInstance() |
197 EnableMaximizeModeWindowManager(false); | 190 ->maximize_mode_controller() |
| 191 ->EnableMaximizeModeWindowManager(false); |
198 container.UpdateSizeButtonVisibility(); | 192 container.UpdateSizeButtonVisibility(); |
199 // Calling code needs to layout in response to size change. | 193 // Calling code needs to layout in response to size change. |
200 container.Layout(); | 194 container.Layout(); |
201 test.EndAnimations(); | 195 test.EndAnimations(); |
202 EXPECT_TRUE(test.minimize_button()->visible()); | 196 EXPECT_TRUE(test.minimize_button()->visible()); |
203 EXPECT_TRUE(test.size_button()->visible()); | 197 EXPECT_TRUE(test.size_button()->visible()); |
204 EXPECT_TRUE(test.close_button()->visible()); | 198 EXPECT_TRUE(test.close_button()->visible()); |
205 EXPECT_EQ(initial_minimize_button_bounds, test.minimize_button()->bounds()); | 199 EXPECT_EQ(initial_minimize_button_bounds, test.minimize_button()->bounds()); |
206 EXPECT_EQ(initial_size_button_bounds, test.size_button()->bounds()); | 200 EXPECT_EQ(initial_size_button_bounds, test.size_button()->bounds()); |
207 EXPECT_EQ(initial_close_button_bounds, test.close_button()->bounds()); | 201 EXPECT_EQ(initial_close_button_bounds, test.close_button()->bounds()); |
208 EXPECT_EQ(container.GetPreferredSize().width(), | 202 EXPECT_EQ(container.GetPreferredSize().width(), |
209 initial_container_bounds.width()); | 203 initial_container_bounds.width()); |
210 } | 204 } |
211 | 205 |
212 } // namespace ash | 206 } // namespace ash |
OLD | NEW |