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

Side by Side Diff: ash/wm/workspace/workspace_window_resizer_unittest.cc

Issue 9609016: Initial cut at multi-window resize code. There's still some TODOs, but (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 8 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/wm/workspace/workspace_window_resizer.h" 5 #include "ash/wm/workspace/workspace_window_resizer.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 8 #include "ash/test/ash_test_base.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "ui/aura/root_window.h" 10 #include "ui/aura/root_window.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 protected: 75 protected:
76 gfx::Point CalculateDragPoint(const WorkspaceWindowResizer& resizer, 76 gfx::Point CalculateDragPoint(const WorkspaceWindowResizer& resizer,
77 int delta_x, 77 int delta_x,
78 int delta_y) const { 78 int delta_y) const {
79 gfx::Point location = resizer.initial_location_in_parent(); 79 gfx::Point location = resizer.initial_location_in_parent();
80 location.set_x(location.x() + delta_x); 80 location.set_x(location.x() + delta_x);
81 location.set_y(location.y() + delta_y); 81 location.set_y(location.y() + delta_y);
82 return location; 82 return location;
83 } 83 }
84 84
85 std::vector<aura::Window*> empty_windows() const {
86 return std::vector<aura::Window*>();
87 }
88
85 TestWindowDelegate delegate_; 89 TestWindowDelegate delegate_;
86 TestWindowDelegate delegate2_; 90 TestWindowDelegate delegate2_;
87 TestWindowDelegate delegate3_; 91 TestWindowDelegate delegate3_;
88 scoped_ptr<aura::Window> window_; 92 scoped_ptr<aura::Window> window_;
89 scoped_ptr<aura::Window> window2_; 93 scoped_ptr<aura::Window> window2_;
90 scoped_ptr<aura::Window> window3_; 94 scoped_ptr<aura::Window> window3_;
91 95
92 private: 96 private:
93 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest); 97 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest);
94 }; 98 };
95 99
96 // Assertions around making sure dragging shrinks when appropriate. 100 // Assertions around making sure dragging shrinks when appropriate.
97 TEST_F(WorkspaceWindowResizerTest, ShrinkOnDrag) { 101 TEST_F(WorkspaceWindowResizerTest, ShrinkOnDrag) {
98 int initial_y = 300; 102 int initial_y = 300;
99 window_->SetBounds(gfx::Rect(0, initial_y, 400, 296)); 103 window_->SetBounds(gfx::Rect(0, initial_y, 400, 296));
100 104
101 // Drag down past the bottom of the screen, height should stop when it hits 105 // Drag down past the bottom of the screen, height should stop when it hits
102 // the bottom. 106 // the bottom.
103 { 107 {
104 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 108 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
105 window_.get(), gfx::Point(), HTBOTTOM, 0)); 109 window_.get(), gfx::Point(), HTBOTTOM, 0, empty_windows()));
106 ASSERT_TRUE(resizer.get()); 110 ASSERT_TRUE(resizer.get());
107 resizer->Drag(CalculateDragPoint(*resizer, 0, 600)); 111 resizer->Drag(CalculateDragPoint(*resizer, 0, 600));
108 EXPECT_EQ(kRootHeight - initial_y, window_->bounds().height()); 112 EXPECT_EQ(kRootHeight - initial_y, window_->bounds().height());
109 113
110 // Drag up 10 and make sure height is the same. 114 // Drag up 10 and make sure height is the same.
111 resizer->Drag(CalculateDragPoint(*resizer, 0, 590)); 115 resizer->Drag(CalculateDragPoint(*resizer, 0, 590));
112 EXPECT_EQ(kRootHeight - initial_y, window_->bounds().height()); 116 EXPECT_EQ(kRootHeight - initial_y, window_->bounds().height());
113 } 117 }
114 118
115 { 119 {
116 // Move the window down 10 pixels, the height should change. 120 // Move the window down 10 pixels, the height should change.
117 int initial_height = window_->bounds().height(); 121 int initial_height = window_->bounds().height();
118 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 122 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
119 window_.get(), gfx::Point(), HTCAPTION, 0)); 123 window_.get(), gfx::Point(), HTCAPTION, 0, empty_windows()));
120 ASSERT_TRUE(resizer.get()); 124 ASSERT_TRUE(resizer.get());
121 resizer->Drag(CalculateDragPoint(*resizer, 0, 10)); 125 resizer->Drag(CalculateDragPoint(*resizer, 0, 10));
122 EXPECT_EQ(initial_height - 10, window_->bounds().height()); 126 EXPECT_EQ(initial_height - 10, window_->bounds().height());
123 127
124 // Move up 10, height should grow. 128 // Move up 10, height should grow.
125 resizer->Drag(CalculateDragPoint(*resizer, 0, 0)); 129 resizer->Drag(CalculateDragPoint(*resizer, 0, 0));
126 EXPECT_EQ(initial_height, window_->bounds().height()); 130 EXPECT_EQ(initial_height, window_->bounds().height());
127 131
128 // Move up another 10, height shouldn't change. 132 // Move up another 10, height shouldn't change.
129 resizer->Drag(CalculateDragPoint(*resizer, 0, -10)); 133 resizer->Drag(CalculateDragPoint(*resizer, 0, -10));
130 EXPECT_EQ(initial_height, window_->bounds().height()); 134 EXPECT_EQ(initial_height, window_->bounds().height());
131 } 135 }
132 } 136 }
133 137
134 // More assertions around making sure dragging shrinks when appropriate. 138 // More assertions around making sure dragging shrinks when appropriate.
135 TEST_F(WorkspaceWindowResizerTest, ShrinkOnDrag2) { 139 TEST_F(WorkspaceWindowResizerTest, ShrinkOnDrag2) {
136 window_->SetBounds(gfx::Rect(0, 300, 400, 300)); 140 window_->SetBounds(gfx::Rect(0, 300, 400, 300));
137 141
138 // Drag down past the bottom of the screen, height should stop when it hits 142 // Drag down past the bottom of the screen, height should stop when it hits
139 // the bottom. 143 // the bottom.
140 { 144 {
141 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 145 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
142 window_.get(), gfx::Point(), HTCAPTION, 0)); 146 window_.get(), gfx::Point(), HTCAPTION, 0, empty_windows()));
143 ASSERT_TRUE(resizer.get()); 147 ASSERT_TRUE(resizer.get());
144 resizer->Drag(CalculateDragPoint(*resizer, 0, 200)); 148 resizer->Drag(CalculateDragPoint(*resizer, 0, 200));
145 EXPECT_EQ(500, window_->bounds().y()); 149 EXPECT_EQ(500, window_->bounds().y());
146 EXPECT_EQ(100, window_->bounds().height()); 150 EXPECT_EQ(100, window_->bounds().height());
147 // End and start a new drag session. 151 // End and start a new drag session.
148 } 152 }
149 153
150 { 154 {
151 // Drag up 400. 155 // Drag up 400.
152 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 156 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
153 window_.get(), gfx::Point(), HTCAPTION, 0)); 157 window_.get(), gfx::Point(), HTCAPTION, 0, empty_windows()));
154 ASSERT_TRUE(resizer.get()); 158 ASSERT_TRUE(resizer.get());
155 resizer->Drag(CalculateDragPoint(*resizer, 0, -400)); 159 resizer->Drag(CalculateDragPoint(*resizer, 0, -400));
156 EXPECT_EQ(100, window_->bounds().y()); 160 EXPECT_EQ(100, window_->bounds().y());
157 EXPECT_EQ(300, window_->bounds().height()); 161 EXPECT_EQ(300, window_->bounds().height());
158 } 162 }
159 } 163 }
160 164
161 // Moves enough to shrink, then moves up twice to expose more than was initially 165 // Moves enough to shrink, then moves up twice to expose more than was initially
162 // exposed. 166 // exposed.
163 TEST_F(WorkspaceWindowResizerTest, ShrinkMoveThanMoveUp) { 167 TEST_F(WorkspaceWindowResizerTest, ShrinkMoveThanMoveUp) {
164 window_->SetBounds(gfx::Rect(0, 300, 400, 300)); 168 window_->SetBounds(gfx::Rect(0, 300, 400, 300));
165 169
166 // Drag down past the bottom of the screen, height should stop when it hits 170 // Drag down past the bottom of the screen, height should stop when it hits
167 // the bottom. 171 // the bottom.
168 { 172 {
169 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 173 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
170 window_.get(), gfx::Point(), HTCAPTION, 0)); 174 window_.get(), gfx::Point(), HTCAPTION, 0, empty_windows()));
171 ASSERT_TRUE(resizer.get()); 175 ASSERT_TRUE(resizer.get());
172 resizer->Drag(CalculateDragPoint(*resizer, 0, 200)); 176 resizer->Drag(CalculateDragPoint(*resizer, 0, 200));
173 EXPECT_EQ(500, window_->bounds().y()); 177 EXPECT_EQ(500, window_->bounds().y());
174 EXPECT_EQ(100, window_->bounds().height()); 178 EXPECT_EQ(100, window_->bounds().height());
175 // End and start a new drag session. 179 // End and start a new drag session.
176 } 180 }
177 181
178 { 182 {
179 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 183 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
180 window_.get(), gfx::Point(), HTCAPTION, 0)); 184 window_.get(), gfx::Point(), HTCAPTION, 0, empty_windows()));
181 ASSERT_TRUE(resizer.get()); 185 ASSERT_TRUE(resizer.get());
182 resizer->Drag(CalculateDragPoint(*resizer, 0, -400)); 186 resizer->Drag(CalculateDragPoint(*resizer, 0, -400));
183 resizer->Drag(CalculateDragPoint(*resizer, 0, -450)); 187 resizer->Drag(CalculateDragPoint(*resizer, 0, -450));
184 EXPECT_EQ(50, window_->bounds().y()); 188 EXPECT_EQ(50, window_->bounds().y());
185 EXPECT_EQ(300, window_->bounds().height()); 189 EXPECT_EQ(300, window_->bounds().height());
186 } 190 }
187 } 191 }
188 192
189 // Makes sure shrinking honors the grid appropriately. 193 // Makes sure shrinking honors the grid appropriately.
190 TEST_F(WorkspaceWindowResizerTest, ShrinkWithGrid) { 194 TEST_F(WorkspaceWindowResizerTest, ShrinkWithGrid) {
191 window_->SetBounds(gfx::Rect(0, 300, 400, 296)); 195 window_->SetBounds(gfx::Rect(0, 300, 400, 296));
192 196
193 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 197 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
194 window_.get(), gfx::Point(), HTCAPTION, 5)); 198 window_.get(), gfx::Point(), HTCAPTION, 5, empty_windows()));
195 ASSERT_TRUE(resizer.get()); 199 ASSERT_TRUE(resizer.get());
196 // Drag down 8 pixels. 200 // Drag down 8 pixels.
197 resizer->Drag(CalculateDragPoint(*resizer, 0, 8)); 201 resizer->Drag(CalculateDragPoint(*resizer, 0, 8));
198 resizer->CompleteDrag(); 202 resizer->CompleteDrag();
199 EXPECT_EQ(310, window_->bounds().y()); 203 EXPECT_EQ(310, window_->bounds().y());
200 EXPECT_EQ(kRootHeight - 310, window_->bounds().height()); 204 EXPECT_EQ(kRootHeight - 310, window_->bounds().height());
201 } 205 }
202 206
203 // Makes sure once a window has been shrunk it can grow bigger than obscured 207 // Makes sure once a window has been shrunk it can grow bigger than obscured
204 // height 208 // height
205 TEST_F(WorkspaceWindowResizerTest, ShrinkThanGrow) { 209 TEST_F(WorkspaceWindowResizerTest, ShrinkThanGrow) {
206 int initial_y = 400; 210 int initial_y = 400;
207 int initial_height = 150; 211 int initial_height = 150;
208 window_->SetBounds(gfx::Rect(0, initial_y, 400, initial_height)); 212 window_->SetBounds(gfx::Rect(0, initial_y, 400, initial_height));
209 213
210 // Most past the bottom of the screen, height should stop when it hits the 214 // Most past the bottom of the screen, height should stop when it hits the
211 // bottom. 215 // bottom.
212 { 216 {
213 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 217 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
214 window_.get(), gfx::Point(), HTCAPTION, 0)); 218 window_.get(), gfx::Point(), HTCAPTION, 0, empty_windows()));
215 ASSERT_TRUE(resizer.get()); 219 ASSERT_TRUE(resizer.get());
216 resizer->Drag(CalculateDragPoint(*resizer, 0, 150)); 220 resizer->Drag(CalculateDragPoint(*resizer, 0, 150));
217 EXPECT_EQ(550, window_->bounds().y()); 221 EXPECT_EQ(550, window_->bounds().y());
218 EXPECT_EQ(50, window_->bounds().height()); 222 EXPECT_EQ(50, window_->bounds().height());
219 } 223 }
220 224
221 // Resize the window 500 pixels up. 225 // Resize the window 500 pixels up.
222 { 226 {
223 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 227 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
224 window_.get(), gfx::Point(), HTTOP, 0)); 228 window_.get(), gfx::Point(), HTTOP, 0, empty_windows()));
225 ASSERT_TRUE(resizer.get()); 229 ASSERT_TRUE(resizer.get());
226 resizer->Drag(CalculateDragPoint(*resizer, 0, -500)); 230 resizer->Drag(CalculateDragPoint(*resizer, 0, -500));
227 EXPECT_EQ(50, window_->bounds().y()); 231 EXPECT_EQ(50, window_->bounds().y());
228 EXPECT_EQ(550, window_->bounds().height()); 232 EXPECT_EQ(550, window_->bounds().height());
229 } 233 }
230 } 234 }
231 235
232 // Makes sure once a window has been shrunk it can grow bigger than obscured 236 // Makes sure once a window has been shrunk it can grow bigger than obscured
233 // height 237 // height
234 TEST_F(WorkspaceWindowResizerTest, DontRememberAfterMove) { 238 TEST_F(WorkspaceWindowResizerTest, DontRememberAfterMove) {
235 window_->SetBounds(gfx::Rect(0, 300, 400, 300)); 239 window_->SetBounds(gfx::Rect(0, 300, 400, 300));
236 240
237 // Most past the bottom of the screen, height should stop when it hits the 241 // Most past the bottom of the screen, height should stop when it hits the
238 // bottom. 242 // bottom.
239 { 243 {
240 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 244 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
241 window_.get(), gfx::Point(), HTCAPTION, 0)); 245 window_.get(), gfx::Point(), HTCAPTION, 0, empty_windows()));
242 ASSERT_TRUE(resizer.get()); 246 ASSERT_TRUE(resizer.get());
243 resizer->Drag(CalculateDragPoint(*resizer, 0, 150)); 247 resizer->Drag(CalculateDragPoint(*resizer, 0, 150));
244 EXPECT_EQ(450, window_->bounds().y()); 248 EXPECT_EQ(450, window_->bounds().y());
245 EXPECT_EQ(150, window_->bounds().height()); 249 EXPECT_EQ(150, window_->bounds().height());
246 resizer->Drag(CalculateDragPoint(*resizer, 0, -150)); 250 resizer->Drag(CalculateDragPoint(*resizer, 0, -150));
247 EXPECT_EQ(150, window_->bounds().y()); 251 EXPECT_EQ(150, window_->bounds().y());
248 EXPECT_EQ(300, window_->bounds().height()); 252 EXPECT_EQ(300, window_->bounds().height());
249 } 253 }
250 254
251 // Resize it slightly. 255 // Resize it slightly.
252 { 256 {
253 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 257 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
254 window_.get(), gfx::Point(), HTBOTTOM, 0)); 258 window_.get(), gfx::Point(), HTBOTTOM, 0, empty_windows()));
255 ASSERT_TRUE(resizer.get()); 259 ASSERT_TRUE(resizer.get());
256 resizer->Drag(CalculateDragPoint(*resizer, 0, -100)); 260 resizer->Drag(CalculateDragPoint(*resizer, 0, -100));
257 EXPECT_EQ(150, window_->bounds().y()); 261 EXPECT_EQ(150, window_->bounds().y());
258 EXPECT_EQ(200, window_->bounds().height()); 262 EXPECT_EQ(200, window_->bounds().height());
259 } 263 }
260 264
261 { 265 {
262 // Move it down then back up. 266 // Move it down then back up.
263 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 267 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
264 window_.get(), gfx::Point(), HTCAPTION, 0)); 268 window_.get(), gfx::Point(), HTCAPTION, 0, empty_windows()));
265 ASSERT_TRUE(resizer.get()); 269 ASSERT_TRUE(resizer.get());
266 resizer->Drag(CalculateDragPoint(*resizer, 0, 400)); 270 resizer->Drag(CalculateDragPoint(*resizer, 0, 400));
267 EXPECT_EQ(550, window_->bounds().y()); 271 EXPECT_EQ(550, window_->bounds().y());
268 EXPECT_EQ(50, window_->bounds().height()); 272 EXPECT_EQ(50, window_->bounds().height());
269 273
270 resizer->Drag(CalculateDragPoint(*resizer, 0, 0)); 274 resizer->Drag(CalculateDragPoint(*resizer, 0, 0));
271 EXPECT_EQ(150, window_->bounds().y()); 275 EXPECT_EQ(150, window_->bounds().y());
272 EXPECT_EQ(200, window_->bounds().height()); 276 EXPECT_EQ(200, window_->bounds().height());
273 } 277 }
274 } 278 }
275 279
276 // Makes sure we honor the min size. 280 // Makes sure we honor the min size.
277 TEST_F(WorkspaceWindowResizerTest, HonorMin) { 281 TEST_F(WorkspaceWindowResizerTest, HonorMin) {
278 delegate_.set_min_size(gfx::Size(50, 100)); 282 delegate_.set_min_size(gfx::Size(50, 100));
279 window_->SetBounds(gfx::Rect(0, 300, 400, 300)); 283 window_->SetBounds(gfx::Rect(0, 300, 400, 300));
280 284
281 // Most past the bottom of the screen, height should stop when it hits the 285 // Most past the bottom of the screen, height should stop when it hits the
282 // bottom. 286 // bottom.
283 { 287 {
284 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 288 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
285 window_.get(), gfx::Point(), HTCAPTION, 0)); 289 window_.get(), gfx::Point(), HTCAPTION, 0, empty_windows()));
286 ASSERT_TRUE(resizer.get()); 290 ASSERT_TRUE(resizer.get());
287 resizer->Drag(CalculateDragPoint(*resizer, 0, 350)); 291 resizer->Drag(CalculateDragPoint(*resizer, 0, 350));
288 EXPECT_EQ(500, window_->bounds().y()); 292 EXPECT_EQ(500, window_->bounds().y());
289 EXPECT_EQ(100, window_->bounds().height()); 293 EXPECT_EQ(100, window_->bounds().height());
290 294
291 resizer->Drag(CalculateDragPoint(*resizer, 0, 300)); 295 resizer->Drag(CalculateDragPoint(*resizer, 0, 300));
292 EXPECT_EQ(500, window_->bounds().y()); 296 EXPECT_EQ(500, window_->bounds().y());
293 EXPECT_EQ(100, window_->bounds().height()); 297 EXPECT_EQ(100, window_->bounds().height());
294 298
295 resizer->Drag(CalculateDragPoint(*resizer, 0, 250)); 299 resizer->Drag(CalculateDragPoint(*resizer, 0, 250));
296 EXPECT_EQ(500, window_->bounds().y()); 300 EXPECT_EQ(500, window_->bounds().y());
297 EXPECT_EQ(100, window_->bounds().height()); 301 EXPECT_EQ(100, window_->bounds().height());
298 302
299 resizer->Drag(CalculateDragPoint(*resizer, 0, 100)); 303 resizer->Drag(CalculateDragPoint(*resizer, 0, 100));
300 EXPECT_EQ(400, window_->bounds().y()); 304 EXPECT_EQ(400, window_->bounds().y());
301 EXPECT_EQ(200, window_->bounds().height()); 305 EXPECT_EQ(200, window_->bounds().height());
302 306
303 resizer->Drag(CalculateDragPoint(*resizer, 0, -100)); 307 resizer->Drag(CalculateDragPoint(*resizer, 0, -100));
304 EXPECT_EQ(200, window_->bounds().y()); 308 EXPECT_EQ(200, window_->bounds().y());
305 EXPECT_EQ(300, window_->bounds().height()); 309 EXPECT_EQ(300, window_->bounds().height());
306 } 310 }
307 } 311 }
308 312
313 // Assertions around attached window resize dragging from the right with 2
314 // windows.
315 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2) {
316 window_->SetBounds(gfx::Rect(0, 300, 400, 300));
317 window2_->SetBounds(gfx::Rect(400, 200, 100, 200));
318
319 std::vector<aura::Window*> windows;
320 windows.push_back(window2_.get());
321 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
322 window_.get(), gfx::Point(), HTRIGHT, 0, windows));
323 ASSERT_TRUE(resizer.get());
324 // Move it 100 to the right, which should expand w1 and push w2.
325 resizer->Drag(CalculateDragPoint(*resizer, 100, 10));
326 EXPECT_EQ("0,300 500x300", window_->bounds().ToString());
327 EXPECT_EQ("500,200 100x200", window2_->bounds().ToString());
328
329 // Push off the screen, w2 should be resized to its min.
330 delegate2_.set_min_size(gfx::Size(20, 20));
331 resizer->Drag(CalculateDragPoint(*resizer, 800, 20));
332 EXPECT_EQ("0,300 780x300", window_->bounds().ToString());
333 EXPECT_EQ("780,200 20x200", window2_->bounds().ToString());
334
335 // Move back to 100 and verify w2 gets its original size.
336 resizer->Drag(CalculateDragPoint(*resizer, 100, 10));
337 EXPECT_EQ("0,300 500x300", window_->bounds().ToString());
338 EXPECT_EQ("500,200 100x200", window2_->bounds().ToString());
339
340 // Revert and make sure everything moves back.
341 resizer->Drag(CalculateDragPoint(*resizer, 800, 20));
342 resizer->RevertDrag();
343 EXPECT_EQ("0,300 400x300", window_->bounds().ToString());
344 EXPECT_EQ("400,200 100x200", window2_->bounds().ToString());
345 }
346
347 // Makes sure we remember the size of an attached window across drags when
348 // compressing.
349 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2_REMEMBER) {
350 window_->SetBounds(gfx::Rect(0, 300, 400, 300));
351 window2_->SetBounds(gfx::Rect(400, 200, 100, 200));
352
353 std::vector<aura::Window*> windows;
354 windows.push_back(window2_.get());
355
356 {
357 delegate2_.set_min_size(gfx::Size(20, 20));
358 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
359 window_.get(), gfx::Point(), HTRIGHT, 0, windows));
360 ASSERT_TRUE(resizer.get());
361 // Resize enough to slightly compress w2.
362 resizer->Drag(CalculateDragPoint(*resizer, 350, 10));
363 EXPECT_EQ("0,300 750x300", window_->bounds().ToString());
364 EXPECT_EQ("750,200 50x200", window2_->bounds().ToString());
365
366 // Compress w2 a bit more.
367 resizer->Drag(CalculateDragPoint(*resizer, 400, 10));
368 EXPECT_EQ("0,300 780x300", window_->bounds().ToString());
369 EXPECT_EQ("780,200 20x200", window2_->bounds().ToString());
370
371 resizer->CompleteDrag();
372 }
373
374 // Restart drag and drag back 200, making sure window2 goes back to 200.
375 {
376 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
377 window_.get(), gfx::Point(), HTRIGHT, 0, windows));
378 ASSERT_TRUE(resizer.get());
379 resizer->Drag(CalculateDragPoint(*resizer, -200, 10));
380 EXPECT_EQ("0,300 580x300", window_->bounds().ToString());
381 EXPECT_EQ("580,200 100x200", window2_->bounds().ToString());
382 }
383 }
384
385 // Assertions around attached window resize dragging from the right with 3
386 // windows.
387 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_3) {
388 window_->SetBounds(gfx::Rect( 100, 300, 200, 300));
389 window2_->SetBounds(gfx::Rect(300, 300, 150, 200));
390 window3_->SetBounds(gfx::Rect(450, 300, 100, 200));
391 delegate2_.set_min_size(gfx::Size(52, 50));
392 delegate3_.set_min_size(gfx::Size(38, 50));
393
394 std::vector<aura::Window*> windows;
395 windows.push_back(window2_.get());
396 windows.push_back(window3_.get());
397 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
398 window_.get(), gfx::Point(), HTRIGHT, 10, windows));
399 ASSERT_TRUE(resizer.get());
400 // Move it 100 to the right, which should expand w1 and push w2 and w3.
401 resizer->Drag(CalculateDragPoint(*resizer, 100, -10));
402 EXPECT_EQ("100,300 300x300", window_->bounds().ToString());
403 EXPECT_EQ("400,300 150x200", window2_->bounds().ToString());
404 EXPECT_EQ("550,300 100x200", window3_->bounds().ToString());
405
406 // Move it 296, which should now snap to grid and things should compress.
407 resizer->Drag(CalculateDragPoint(*resizer, 296, -10));
408 EXPECT_EQ("100,300 500x300", window_->bounds().ToString());
409 EXPECT_EQ("600,300 120x200", window2_->bounds().ToString());
410 EXPECT_EQ("720,300 80x200", window3_->bounds().ToString());
411
412 // Move it so much everything ends up at it's min.
413 resizer->Drag(CalculateDragPoint(*resizer, 798, 50));
414 EXPECT_EQ("100,300 600x300", window_->bounds().ToString());
415 EXPECT_EQ("700,300 60x200", window2_->bounds().ToString());
416 EXPECT_EQ("760,300 40x200", window3_->bounds().ToString());
417
418 // Revert and make sure everything moves back.
419 resizer->RevertDrag();
420 EXPECT_EQ("100,300 200x300", window_->bounds().ToString());
421 EXPECT_EQ("300,300 150x200", window2_->bounds().ToString());
422 EXPECT_EQ("450,300 100x200", window3_->bounds().ToString());
423 }
424
425 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_RememberWidth) {
426 window_->SetBounds(gfx::Rect( 100, 300, 200, 300));
427 window2_->SetBounds(gfx::Rect(300, 300, 150, 200));
428 window3_->SetBounds(gfx::Rect(450, 300, 100, 200));
429 delegate2_.set_min_size(gfx::Size(52, 50));
430 delegate3_.set_min_size(gfx::Size(38, 50));
431
432 std::vector<aura::Window*> windows;
433 windows.push_back(window2_.get());
434 windows.push_back(window3_.get());
435
436 {
437 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
438 window_.get(), gfx::Point(), HTRIGHT, 10, windows));
439 ASSERT_TRUE(resizer.get());
440 // Move it 100 to the right, which should expand w1 and push w2 and w3.
441 resizer->Drag(CalculateDragPoint(*resizer, 100, -10));
442 EXPECT_EQ("100,300 300x300", window_->bounds().ToString());
443 EXPECT_EQ("400,300 150x200", window2_->bounds().ToString());
444 EXPECT_EQ("550,300 100x200", window3_->bounds().ToString());
445
446 // Move it so much everything ends up at it's min.
447 resizer->Drag(CalculateDragPoint(*resizer, 798, 50));
448 EXPECT_EQ("100,300 600x300", window_->bounds().ToString());
449 EXPECT_EQ("700,300 60x200", window2_->bounds().ToString());
450 EXPECT_EQ("760,300 40x200", window3_->bounds().ToString());
451 }
452
453 {
454 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
455 window_.get(), gfx::Point(), HTRIGHT, 10, windows));
456 ASSERT_TRUE(resizer.get());
457
458 resizer->Drag(CalculateDragPoint(*resizer, -100, 50));
459 EXPECT_EQ("100,300 500x300", window_->bounds().ToString());
460 EXPECT_EQ("600,300 120x200", window2_->bounds().ToString());
461 EXPECT_EQ("720,300 80x200", window3_->bounds().ToString());
462
463 // Move it 300 to the left.
464 resizer->Drag(CalculateDragPoint(*resizer, -300, 50));
465 EXPECT_EQ("100,300 300x300", window_->bounds().ToString());
466 EXPECT_EQ("400,300 150x200", window2_->bounds().ToString());
467 EXPECT_EQ("550,300 100x200", window3_->bounds().ToString());
468 }
469
470 }
471
472 // Assertions around attached window resize dragging from the bottom with 2
473 // windows.
474 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_2) {
475 window_->SetBounds(gfx::Rect( 0, 50, 400, 200));
476 window2_->SetBounds(gfx::Rect(0, 250, 200, 100));
477
478 std::vector<aura::Window*> windows;
479 windows.push_back(window2_.get());
480 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
481 window_.get(), gfx::Point(), HTBOTTOM, 0, windows));
482 ASSERT_TRUE(resizer.get());
483 // Move it 100 to the bottom, which should expand w1 and push w2.
484 resizer->Drag(CalculateDragPoint(*resizer, 10, 100));
485 EXPECT_EQ("0,50 400x300", window_->bounds().ToString());
486 EXPECT_EQ("0,350 200x100", window2_->bounds().ToString());
487
488 // Push off the screen, w2 should be resized to its min.
489 delegate2_.set_min_size(gfx::Size(20, 20));
490 resizer->Drag(CalculateDragPoint(*resizer, 50, 820));
491 EXPECT_EQ("0,50 400x530", window_->bounds().ToString());
492 EXPECT_EQ("0,580 200x20", window2_->bounds().ToString());
493
494 // Move back to 100 and verify w2 gets its original size.
495 resizer->Drag(CalculateDragPoint(*resizer, 10, 100));
496 EXPECT_EQ("0,50 400x300", window_->bounds().ToString());
497 EXPECT_EQ("0,350 200x100", window2_->bounds().ToString());
498
499 // Revert and make sure everything moves back.
500 resizer->Drag(CalculateDragPoint(*resizer, 800, 20));
501 resizer->RevertDrag();
502 EXPECT_EQ("0,50 400x200", window_->bounds().ToString());
503 EXPECT_EQ("0,250 200x100", window2_->bounds().ToString());
504 }
505
506 // Makes sure we remember the size of an attached window across drags when
507 // compressing.
508 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_2_REMEMBER) {
509 window_->SetBounds(gfx::Rect( 0, 0, 400, 300));
510 window2_->SetBounds(gfx::Rect(40, 300, 100, 200));
511
512 std::vector<aura::Window*> windows;
513 windows.push_back(window2_.get());
514
515 {
516 delegate2_.set_min_size(gfx::Size(20, 20));
517 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
518 window_.get(), gfx::Point(), HTBOTTOM, 0, windows));
519 ASSERT_TRUE(resizer.get());
520 // Resize enough to slightly compress w2.
521 resizer->Drag(CalculateDragPoint(*resizer, 10, 150));
522 EXPECT_EQ("0,0 400x450", window_->bounds().ToString());
523 EXPECT_EQ("40,450 100x150", window2_->bounds().ToString());
524
525 // Compress w2 a bit more.
526 resizer->Drag(CalculateDragPoint(*resizer, 5, 400));
527 EXPECT_EQ("0,0 400x580", window_->bounds().ToString());
528 EXPECT_EQ("40,580 100x20", window2_->bounds().ToString());
529
530 resizer->CompleteDrag();
531 }
532
533 // Restart drag and drag back 200, making sure window2 goes back to 200.
534 {
535 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
536 window_.get(), gfx::Point(), HTBOTTOM, 0, windows));
537 ASSERT_TRUE(resizer.get());
538 resizer->Drag(CalculateDragPoint(*resizer, -10, -200));
539 EXPECT_EQ("0,0 400x380", window_->bounds().ToString());
540 EXPECT_EQ("40,380 100x200", window2_->bounds().ToString());
541 }
542 }
543
544 // Assertions around attached window resize dragging from the bottom with 3
545 // windows.
546 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_3) {
547 aura::RootWindow* root = Shell::GetInstance()->GetRootWindow();
548 root->SetBounds(gfx::Rect(0, 0, 600, 800));
549 root->SetScreenWorkAreaInsets(gfx::Insets());
550
551 window_->SetBounds(gfx::Rect( 300, 100, 300, 200));
552 window2_->SetBounds(gfx::Rect(300, 300, 200, 150));
553 window3_->SetBounds(gfx::Rect(300, 450, 200, 100));
554 delegate2_.set_min_size(gfx::Size(50, 52));
555 delegate3_.set_min_size(gfx::Size(50, 38));
556
557 std::vector<aura::Window*> windows;
558 windows.push_back(window2_.get());
559 windows.push_back(window3_.get());
560 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
561 window_.get(), gfx::Point(), HTBOTTOM, 10, windows));
562 ASSERT_TRUE(resizer.get());
563 // Move it 100 to the right, which should expand w1 and push w2 and w3.
564 resizer->Drag(CalculateDragPoint(*resizer, -10, 100));
565 EXPECT_EQ("300,100 300x300", window_->bounds().ToString());
566 EXPECT_EQ("300,400 200x150", window2_->bounds().ToString());
567 EXPECT_EQ("300,550 200x100", window3_->bounds().ToString());
568
569 // Move it 296, which should now snap to grid and things should compress.
570 resizer->Drag(CalculateDragPoint(*resizer, -10, 296));
571 EXPECT_EQ("300,100 300x500", window_->bounds().ToString());
572 EXPECT_EQ("300,600 200x120", window2_->bounds().ToString());
573 EXPECT_EQ("300,720 200x80", window3_->bounds().ToString());
574
575 // Move it so much everything ends up at it's min.
576 resizer->Drag(CalculateDragPoint(*resizer, 50, 798));
577 EXPECT_EQ("300,100 300x600", window_->bounds().ToString());
578 EXPECT_EQ("300,700 200x60", window2_->bounds().ToString());
579 EXPECT_EQ("300,760 200x40", window3_->bounds().ToString());
580
581 // Revert and make sure everything moves back.
582 resizer->RevertDrag();
583 EXPECT_EQ("300,100 300x200", window_->bounds().ToString());
584 EXPECT_EQ("300,300 200x150", window2_->bounds().ToString());
585 EXPECT_EQ("300,450 200x100", window3_->bounds().ToString());
586 }
587
588 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_RememberHeight) {
589 aura::RootWindow* root = Shell::GetInstance()->GetRootWindow();
590 root->SetBounds(gfx::Rect(0, 0, 600, 800));
591 root->SetScreenWorkAreaInsets(gfx::Insets());
592
593 window_->SetBounds(gfx::Rect( 300, 100, 300, 200));
594 window2_->SetBounds(gfx::Rect(300, 300, 200, 150));
595 window3_->SetBounds(gfx::Rect(300, 450, 200, 100));
596 delegate2_.set_min_size(gfx::Size(50, 52));
597 delegate3_.set_min_size(gfx::Size(50, 38));
598
599 std::vector<aura::Window*> windows;
600 windows.push_back(window2_.get());
601 windows.push_back(window3_.get());
602
603 {
604 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
605 window_.get(), gfx::Point(), HTBOTTOM, 10, windows));
606 ASSERT_TRUE(resizer.get());
607 // Move it 100 to the bottom, which should expand w1 and push w2 and w3.
608 resizer->Drag(CalculateDragPoint(*resizer, -10, 100));
609 EXPECT_EQ("300,100 300x300", window_->bounds().ToString());
610 EXPECT_EQ("300,400 200x150", window2_->bounds().ToString());
611 EXPECT_EQ("300,550 200x100", window3_->bounds().ToString());
612
613 // Move it so much everything ends up at it's min.
614 resizer->Drag(CalculateDragPoint(*resizer, 50, 798));
615 EXPECT_EQ("300,100 300x600", window_->bounds().ToString());
616 EXPECT_EQ("300,700 200x60", window2_->bounds().ToString());
617 EXPECT_EQ("300,760 200x40", window3_->bounds().ToString());
618 }
619
620 {
621 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
622 window_.get(), gfx::Point(), HTBOTTOM, 10, windows));
623 ASSERT_TRUE(resizer.get());
624
625 resizer->Drag(CalculateDragPoint(*resizer, 50, -100));
626 EXPECT_EQ("300,100 300x500", window_->bounds().ToString());
627 EXPECT_EQ("300,600 200x120", window2_->bounds().ToString());
628 EXPECT_EQ("300,720 200x80", window3_->bounds().ToString());
629
630 // Move it 300 up.
631 resizer->Drag(CalculateDragPoint(*resizer, 50, -300));
632 EXPECT_EQ("300,100 300x300", window_->bounds().ToString());
633 EXPECT_EQ("300,400 200x150", window2_->bounds().ToString());
634 EXPECT_EQ("300,550 200x100", window3_->bounds().ToString());
635 }
636
637 }
638
309 } // namespace 639 } // namespace
310 } // namespace test 640 } // namespace test
311 } // namespace aura 641 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698