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

Side by Side Diff: ash/frame/caption_buttons/frame_caption_button_container_view_unittest.cc

Issue 316693002: Reland Window Control Animations for TouchView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 6 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
OLDNEW
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/frame/caption_buttons/frame_caption_button.h" 7 #include "ash/frame/caption_buttons/frame_caption_button.h"
8 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 9 #include "ash/test/ash_test_base.h"
10 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
9 #include "grit/ash_resources.h" 11 #include "grit/ash_resources.h"
12 #include "ui/compositor/layer.h"
13 #include "ui/gfx/geometry/rect.h"
10 #include "ui/views/widget/widget.h" 14 #include "ui/views/widget/widget.h"
11 #include "ui/views/widget/widget_delegate.h" 15 #include "ui/views/widget/widget_delegate.h"
12 16
13 namespace ash { 17 namespace ash {
14 18
15 namespace { 19 namespace {
16 20
17 class TestWidgetDelegate : public views::WidgetDelegateView { 21 class TestWidgetDelegate : public views::WidgetDelegateView {
18 public: 22 public:
19 TestWidgetDelegate(bool can_maximize) : can_maximize_(can_maximize) { 23 TestWidgetDelegate(bool can_maximize) : can_maximize_(can_maximize) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 105
102 // Test how the allowed actions affect which caption buttons are visible. 106 // Test how the allowed actions affect which caption buttons are visible.
103 TEST_F(FrameCaptionButtonContainerViewTest, ButtonVisibility) { 107 TEST_F(FrameCaptionButtonContainerViewTest, ButtonVisibility) {
104 // All the buttons should be visible when minimizing and maximizing are 108 // All the buttons should be visible when minimizing and maximizing are
105 // allowed. 109 // allowed.
106 scoped_ptr<views::Widget> widget_can_maximize( 110 scoped_ptr<views::Widget> widget_can_maximize(
107 CreateTestWidget(MAXIMIZE_ALLOWED)); 111 CreateTestWidget(MAXIMIZE_ALLOWED));
108 FrameCaptionButtonContainerView container1(widget_can_maximize.get(), 112 FrameCaptionButtonContainerView container1(widget_can_maximize.get(),
109 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); 113 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED);
110 SetMockImages(&container1); 114 SetMockImages(&container1);
115 container1.SetBoundsRect(gfx::Rect(container1.GetPreferredSize()));
111 container1.Layout(); 116 container1.Layout();
112 FrameCaptionButtonContainerView::TestApi t1(&container1); 117 FrameCaptionButtonContainerView::TestApi t1(&container1);
113 EXPECT_TRUE(t1.minimize_button()->visible()); 118 EXPECT_TRUE(t1.minimize_button()->visible());
114 EXPECT_TRUE(t1.size_button()->visible()); 119 EXPECT_TRUE(t1.size_button()->visible());
115 EXPECT_TRUE(t1.close_button()->visible()); 120 EXPECT_TRUE(t1.close_button()->visible());
116 EXPECT_TRUE(CheckButtonsAtEdges( 121 EXPECT_TRUE(CheckButtonsAtEdges(
117 &container1, *t1.minimize_button(), *t1.close_button())); 122 &container1, *t1.minimize_button(), *t1.close_button()));
118 123
119 // The minimize button should be visible when minimizing is allowed but 124 // The minimize button should be visible when minimizing is allowed but
120 // maximizing is disallowed. 125 // maximizing is disallowed.
121 scoped_ptr<views::Widget> widget_cannot_maximize( 126 scoped_ptr<views::Widget> widget_cannot_maximize(
122 CreateTestWidget(MAXIMIZE_DISALLOWED)); 127 CreateTestWidget(MAXIMIZE_DISALLOWED));
123 FrameCaptionButtonContainerView container2(widget_cannot_maximize.get(), 128 FrameCaptionButtonContainerView container2(widget_cannot_maximize.get(),
124 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); 129 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED);
125 SetMockImages(&container2); 130 SetMockImages(&container2);
131 container2.SetBoundsRect(gfx::Rect(container2.GetPreferredSize()));
126 container2.Layout(); 132 container2.Layout();
127 FrameCaptionButtonContainerView::TestApi t2(&container2); 133 FrameCaptionButtonContainerView::TestApi t2(&container2);
128 EXPECT_TRUE(t2.minimize_button()->visible()); 134 EXPECT_TRUE(t2.minimize_button()->visible());
129 EXPECT_FALSE(t2.size_button()->visible()); 135 EXPECT_FALSE(t2.size_button()->visible());
130 EXPECT_TRUE(t2.close_button()->visible()); 136 EXPECT_TRUE(t2.close_button()->visible());
131 EXPECT_TRUE(CheckButtonsAtEdges( 137 EXPECT_TRUE(CheckButtonsAtEdges(
132 &container2, *t2.minimize_button(), *t2.close_button())); 138 &container2, *t2.minimize_button(), *t2.close_button()));
133 139
134 // Neither the minimize button nor the size button should be visible when 140 // Neither the minimize button nor the size button should be visible when
135 // neither minimizing nor maximizing are allowed. 141 // neither minimizing nor maximizing are allowed.
136 FrameCaptionButtonContainerView container3(widget_cannot_maximize.get(), 142 FrameCaptionButtonContainerView container3(widget_cannot_maximize.get(),
137 FrameCaptionButtonContainerView::MINIMIZE_DISALLOWED); 143 FrameCaptionButtonContainerView::MINIMIZE_DISALLOWED);
138 SetMockImages(&container3); 144 SetMockImages(&container3);
145 container3.SetBoundsRect(gfx::Rect(container3.GetPreferredSize()));
139 container3.Layout(); 146 container3.Layout();
140 FrameCaptionButtonContainerView::TestApi t3(&container3); 147 FrameCaptionButtonContainerView::TestApi t3(&container3);
141 EXPECT_FALSE(t3.minimize_button()->visible()); 148 EXPECT_FALSE(t3.minimize_button()->visible());
142 EXPECT_FALSE(t3.size_button()->visible()); 149 EXPECT_FALSE(t3.size_button()->visible());
143 EXPECT_TRUE(t3.close_button()->visible()); 150 EXPECT_TRUE(t3.close_button()->visible());
144 EXPECT_TRUE(CheckButtonsAtEdges( 151 EXPECT_TRUE(CheckButtonsAtEdges(
145 &container3, *t3.close_button(), *t3.close_button())); 152 &container3, *t3.close_button(), *t3.close_button()));
146 } 153 }
147 154
155 // Tests that the layout animations trigered by button visibilty result in the
156 // correct placement of the buttons.
157 TEST_F(FrameCaptionButtonContainerViewTest,
158 TestUpdateSizeButtonVisibilityAnimation) {
159 scoped_ptr<views::Widget> widget_can_maximize(
160 CreateTestWidget(MAXIMIZE_ALLOWED));
161 FrameCaptionButtonContainerView container(widget_can_maximize.get(),
162 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED);
163 SetMockImages(&container);
164 container.SetBoundsRect(gfx::Rect(container.GetPreferredSize()));
165 container.Layout();
166
167 FrameCaptionButtonContainerView::TestApi test(&container);
168 gfx::Rect initial_minimize_button_bounds = test.minimize_button()->bounds();
169 gfx::Rect initial_size_button_bounds = test.size_button()->bounds();
170 gfx::Rect initial_close_button_bounds = test.close_button()->bounds();
171 gfx::Rect initial_container_bounds = container.bounds();
172
173 ASSERT_EQ(initial_size_button_bounds.x(),
174 initial_minimize_button_bounds.right());
175 ASSERT_EQ(initial_close_button_bounds.x(),
176 initial_size_button_bounds.right());
177
178 // Hidden size button should result in minimize button animating to the
179 // right. The size button should not be visible, but should not have moved.
180 Shell::GetInstance()->maximize_mode_controller()->
181 EnableMaximizeModeWindowManager(true);
182 container.UpdateSizeButtonVisibility();
183 container.Layout();
184
185 EXPECT_TRUE(test.minimize_button()->visible());
186 EXPECT_FALSE(test.size_button()->visible());
187 EXPECT_TRUE(test.close_button()->visible());
188 gfx::Rect minimize_button_bounds = test.minimize_button()->bounds();
189 gfx::Rect close_button_bounds = test.close_button()->bounds();
190 EXPECT_EQ(close_button_bounds.x(), minimize_button_bounds.right());
191 EXPECT_EQ(initial_size_button_bounds, test.size_button()->bounds());
192 EXPECT_EQ(initial_close_button_bounds, close_button_bounds);
193 EXPECT_LT(container.GetPreferredSize().width(),
194 initial_container_bounds.width());
195
196 // Revealing the size button should cause the minimze button to return to its
197 // original position.
198 Shell::GetInstance()->maximize_mode_controller()->
199 EnableMaximizeModeWindowManager(false);
200 container.UpdateSizeButtonVisibility();
201 container.Layout();
202 EXPECT_TRUE(test.minimize_button()->visible());
203 EXPECT_TRUE(test.size_button()->visible());
204 EXPECT_TRUE(test.close_button()->visible());
205 EXPECT_EQ(initial_minimize_button_bounds, test.minimize_button()->bounds());
206 EXPECT_EQ(initial_size_button_bounds, test.size_button()->bounds());
207 EXPECT_EQ(initial_close_button_bounds, test.close_button()->bounds());
208 EXPECT_EQ(container.GetPreferredSize().width(),
209 initial_container_bounds.width());
210 }
211
212 // Tests that after an animation to maximized state, that the layer tree has
213 // been updated to reflect the swapped layers.
214 TEST_F(FrameCaptionButtonContainerViewTest, AnimationUpdatesLayerTree) {
215 scoped_ptr<views::Widget> widget_can_maximize(
216 CreateTestWidget(MAXIMIZE_ALLOWED));
217 FrameCaptionButtonContainerView container(widget_can_maximize.get(),
218 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED);
219 SetMockImages(&container);
220 container.SetBoundsRect(gfx::Rect(container.GetPreferredSize()));
221 container.Layout();
222 ui::Layer* original_layer = container.layer();
223
224 // The container must be a child of the window to be affected by the
225 // animation.
226 widget_can_maximize->non_client_view()->AddChildView(&container);
227 widget_can_maximize->Show();
228 // The original cache of the layer tree must be created before the animation
229 widget_can_maximize->UpdateRootLayers();
230 widget_can_maximize->GetRootLayers();
231
232 // After the maximizing animation has completed, |original_layer| will have
233 // been deleted. Dereferencing it could cause a segfault.
234 widget_can_maximize->Maximize();
235 RunAllPendingInMessageLoop();
236 EXPECT_TRUE(widget_can_maximize->IsMaximized());
237
238 std::vector<ui::Layer*> layers = widget_can_maximize->GetRootLayers();
239
240 EXPECT_GT(layers.size(), 0u);
241 EXPECT_NE(layers.end(),
242 std::find(layers.begin(), layers.end(), container.layer()));
243 EXPECT_EQ(layers.end(),
244 std::find(layers.begin(), layers.end(), original_layer));
245 EXPECT_NE(original_layer, container.layer());
246 }
247
148 } // namespace ash 248 } // namespace ash
OLDNEW
« no previous file with comments | « ash/frame/caption_buttons/frame_caption_button_container_view.cc ('k') | ash/frame/custom_frame_view_ash.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698