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

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

Issue 10910164: Removes the grid from ash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix ShelfBrowserTest Created 8 years, 3 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
« no previous file with comments | « ash/wm/workspace/workspace_window_resizer.cc ('k') | ash/wm/workspace_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/display/mouse_cursor_event_filter.h" 7 #include "ash/display/mouse_cursor_event_filter.h"
8 #include "ash/screen_ash.h" 8 #include "ash/screen_ash.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/shell_window_ids.h" 10 #include "ash/shell_window_ids.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 if (*i == window_.get() || *i == window2_.get() || *i == window3_.get()) { 100 if (*i == window_.get() || *i == window2_.get() || *i == window3_.get()) {
101 if (!result.empty()) 101 if (!result.empty())
102 result += " "; 102 result += " ";
103 result += base::IntToString((*i)->id()); 103 result += base::IntToString((*i)->id());
104 } 104 }
105 } 105 }
106 return result; 106 return result;
107 } 107 }
108 108
109 protected: 109 protected:
110 void SetGridSize(int grid_size) {
111 Shell::TestApi shell_test(Shell::GetInstance());
112 shell_test.workspace_controller()->SetGridSize(grid_size);
113 }
114
115 gfx::Point CalculateDragPoint(const WorkspaceWindowResizer& resizer, 110 gfx::Point CalculateDragPoint(const WorkspaceWindowResizer& resizer,
116 int delta_x, 111 int delta_x,
117 int delta_y) const { 112 int delta_y) const {
118 gfx::Point location = resizer.initial_location_in_parent(); 113 gfx::Point location = resizer.initial_location_in_parent();
119 location.set_x(location.x() + delta_x); 114 location.set_x(location.x() + delta_x);
120 location.set_y(location.y() + delta_y); 115 location.set_y(location.y() + delta_y);
121 return location; 116 return location;
122 } 117 }
123 118
124 std::vector<aura::Window*> empty_windows() const { 119 std::vector<aura::Window*> empty_windows() const {
(...skipping 29 matching lines...) Expand all
154 #endif 149 #endif
155 150
156 // Assertions around attached window resize dragging from the right with 2 151 // Assertions around attached window resize dragging from the right with 2
157 // windows. 152 // windows.
158 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2) { 153 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2) {
159 window_->SetBounds(gfx::Rect(0, 300, 400, 300)); 154 window_->SetBounds(gfx::Rect(0, 300, 400, 300));
160 window2_->SetBounds(gfx::Rect(400, 200, 100, 200)); 155 window2_->SetBounds(gfx::Rect(400, 200, 100, 200));
161 156
162 std::vector<aura::Window*> windows; 157 std::vector<aura::Window*> windows;
163 windows.push_back(window2_.get()); 158 windows.push_back(window2_.get());
164 SetGridSize(0);
165 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 159 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
166 window_.get(), gfx::Point(), HTRIGHT, windows)); 160 window_.get(), gfx::Point(), HTRIGHT, windows));
167 ASSERT_TRUE(resizer.get()); 161 ASSERT_TRUE(resizer.get());
168 // Move it 100 to the right, which should expand w1 and push w2. 162 // Move it 100 to the right, which should expand w1 and push w2.
169 resizer->Drag(CalculateDragPoint(*resizer, 100, 10), 0); 163 resizer->Drag(CalculateDragPoint(*resizer, 100, 10), 0);
170 EXPECT_EQ("0,300 500x300", window_->bounds().ToString()); 164 EXPECT_EQ("0,300 500x300", window_->bounds().ToString());
171 EXPECT_EQ("500,200 100x200", window2_->bounds().ToString()); 165 EXPECT_EQ("500,200 100x200", window2_->bounds().ToString());
172 166
173 // Push off the screen, w2 should be resized to its min. 167 // Push off the screen, w2 should be resized to its min.
174 delegate2_.set_min_size(gfx::Size(20, 20)); 168 delegate2_.set_min_size(gfx::Size(20, 20));
(...skipping 13 matching lines...) Expand all
188 EXPECT_EQ("400,200 100x200", window2_->bounds().ToString()); 182 EXPECT_EQ("400,200 100x200", window2_->bounds().ToString());
189 } 183 }
190 184
191 // Assertions around collapsing and expanding. 185 // Assertions around collapsing and expanding.
192 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_Compress) { 186 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_Compress) {
193 window_->SetBounds(gfx::Rect( 0, 300, 400, 300)); 187 window_->SetBounds(gfx::Rect( 0, 300, 400, 300));
194 window2_->SetBounds(gfx::Rect(400, 200, 100, 200)); 188 window2_->SetBounds(gfx::Rect(400, 200, 100, 200));
195 189
196 std::vector<aura::Window*> windows; 190 std::vector<aura::Window*> windows;
197 windows.push_back(window2_.get()); 191 windows.push_back(window2_.get());
198 SetGridSize(0);
199 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 192 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
200 window_.get(), gfx::Point(), HTRIGHT, windows)); 193 window_.get(), gfx::Point(), HTRIGHT, windows));
201 ASSERT_TRUE(resizer.get()); 194 ASSERT_TRUE(resizer.get());
202 // Move it 100 to the left, which should expand w2 and collapse w1. 195 // Move it 100 to the left, which should expand w2 and collapse w1.
203 resizer->Drag(CalculateDragPoint(*resizer, -100, 10), 0); 196 resizer->Drag(CalculateDragPoint(*resizer, -100, 10), 0);
204 EXPECT_EQ("0,300 300x300", window_->bounds().ToString()); 197 EXPECT_EQ("0,300 300x300", window_->bounds().ToString());
205 EXPECT_EQ("300,200 200x200", window2_->bounds().ToString()); 198 EXPECT_EQ("300,200 200x200", window2_->bounds().ToString());
206 199
207 // Collapse all the way to w1's min. 200 // Collapse all the way to w1's min.
208 delegate_.set_min_size(gfx::Size(20, 20)); 201 delegate_.set_min_size(gfx::Size(20, 20));
(...skipping 17 matching lines...) Expand all
226 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_3) { 219 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_3) {
227 window_->SetBounds(gfx::Rect( 100, 300, 200, 300)); 220 window_->SetBounds(gfx::Rect( 100, 300, 200, 300));
228 window2_->SetBounds(gfx::Rect(300, 300, 150, 200)); 221 window2_->SetBounds(gfx::Rect(300, 300, 150, 200));
229 window3_->SetBounds(gfx::Rect(450, 300, 100, 200)); 222 window3_->SetBounds(gfx::Rect(450, 300, 100, 200));
230 delegate2_.set_min_size(gfx::Size(52, 50)); 223 delegate2_.set_min_size(gfx::Size(52, 50));
231 delegate3_.set_min_size(gfx::Size(38, 50)); 224 delegate3_.set_min_size(gfx::Size(38, 50));
232 225
233 std::vector<aura::Window*> windows; 226 std::vector<aura::Window*> windows;
234 windows.push_back(window2_.get()); 227 windows.push_back(window2_.get());
235 windows.push_back(window3_.get()); 228 windows.push_back(window3_.get());
236 SetGridSize(10);
237 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 229 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
238 window_.get(), gfx::Point(), HTRIGHT, windows)); 230 window_.get(), gfx::Point(), HTRIGHT, windows));
239 ASSERT_TRUE(resizer.get()); 231 ASSERT_TRUE(resizer.get());
240 // Move it 100 to the right, which should expand w1 and push w2 and w3. 232 // Move it 100 to the right, which should expand w1 and push w2 and w3.
241 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0); 233 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
242 EXPECT_EQ("100,300 300x300", window_->bounds().ToString()); 234 EXPECT_EQ("100,300 300x300", window_->bounds().ToString());
243 EXPECT_EQ("400,300 150x200", window2_->bounds().ToString()); 235 EXPECT_EQ("400,300 150x200", window2_->bounds().ToString());
244 EXPECT_EQ("550,300 100x200", window3_->bounds().ToString()); 236 EXPECT_EQ("550,300 100x200", window3_->bounds().ToString());
245 237
246 // Move it 296, which should now snap to grid and things should compress. 238 // Move it 300, things should compress.
247 resizer->Drag(CalculateDragPoint(*resizer, 296, -10), 0); 239 resizer->Drag(CalculateDragPoint(*resizer, 300, -10), 0);
248 EXPECT_EQ("100,300 500x300", window_->bounds().ToString()); 240 EXPECT_EQ("100,300 500x300", window_->bounds().ToString());
249 EXPECT_EQ("600,300 120x200", window2_->bounds().ToString()); 241 EXPECT_EQ("600,300 120x200", window2_->bounds().ToString());
250 EXPECT_EQ("720,300 80x200", window3_->bounds().ToString()); 242 EXPECT_EQ("720,300 80x200", window3_->bounds().ToString());
251 243
252 // Move it so much everything ends up at its min. 244 // Move it so much the last two end up at their min.
253 resizer->Drag(CalculateDragPoint(*resizer, 798, 50), 0); 245 resizer->Drag(CalculateDragPoint(*resizer, 800, 50), 0);
254 EXPECT_EQ("100,300 600x300", window_->bounds().ToString()); 246 EXPECT_EQ("100,300 610x300", window_->bounds().ToString());
255 EXPECT_EQ("700,300 60x200", window2_->bounds().ToString()); 247 EXPECT_EQ("710,300 52x200", window2_->bounds().ToString());
256 EXPECT_EQ("760,300 40x200", window3_->bounds().ToString()); 248 EXPECT_EQ("762,300 38x200", window3_->bounds().ToString());
257 249
258 // Revert and make sure everything moves back. 250 // Revert and make sure everything moves back.
259 resizer->RevertDrag(); 251 resizer->RevertDrag();
260 EXPECT_EQ("100,300 200x300", window_->bounds().ToString()); 252 EXPECT_EQ("100,300 200x300", window_->bounds().ToString());
261 EXPECT_EQ("300,300 150x200", window2_->bounds().ToString()); 253 EXPECT_EQ("300,300 150x200", window2_->bounds().ToString());
262 EXPECT_EQ("450,300 100x200", window3_->bounds().ToString()); 254 EXPECT_EQ("450,300 100x200", window3_->bounds().ToString());
263 } 255 }
264 256
265 // Assertions around attached window resizing (collapsing and expanding) with 257 // Assertions around attached window resizing (collapsing and expanding) with
266 // 3 windows. 258 // 3 windows.
267 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_3_Compress) { 259 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_3_Compress) {
268 window_->SetBounds(gfx::Rect( 100, 300, 200, 300)); 260 window_->SetBounds(gfx::Rect( 100, 300, 200, 300));
269 window2_->SetBounds(gfx::Rect(300, 300, 200, 200)); 261 window2_->SetBounds(gfx::Rect(300, 300, 200, 200));
270 window3_->SetBounds(gfx::Rect(450, 300, 100, 200)); 262 window3_->SetBounds(gfx::Rect(450, 300, 100, 200));
271 delegate2_.set_min_size(gfx::Size(52, 50)); 263 delegate2_.set_min_size(gfx::Size(52, 50));
272 delegate3_.set_min_size(gfx::Size(38, 50)); 264 delegate3_.set_min_size(gfx::Size(38, 50));
273 265
274 std::vector<aura::Window*> windows; 266 std::vector<aura::Window*> windows;
275 windows.push_back(window2_.get()); 267 windows.push_back(window2_.get());
276 windows.push_back(window3_.get()); 268 windows.push_back(window3_.get());
277 SetGridSize(10);
278 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 269 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
279 window_.get(), gfx::Point(), HTRIGHT, windows)); 270 window_.get(), gfx::Point(), HTRIGHT, windows));
280 ASSERT_TRUE(resizer.get()); 271 ASSERT_TRUE(resizer.get());
281 // Move it -100 to the right, which should collapse w1 and expand w2 and w3. 272 // Move it -100 to the right, which should collapse w1 and expand w2 and w3.
282 resizer->Drag(CalculateDragPoint(*resizer, -100, -10), 0); 273 resizer->Drag(CalculateDragPoint(*resizer, -100, -10), 0);
283 EXPECT_EQ("100,300 100x300", window_->bounds().ToString()); 274 EXPECT_EQ("100,300 100x300", window_->bounds().ToString());
284 EXPECT_EQ("200,300 270x200", window2_->bounds().ToString()); 275 EXPECT_EQ("200,300 266x200", window2_->bounds().ToString());
285 EXPECT_EQ("470,300 130x200", window3_->bounds().ToString()); 276 EXPECT_EQ("466,300 134x200", window3_->bounds().ToString());
286 277
287 // Move it 100 to the right. 278 // Move it 100 to the right.
288 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0); 279 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
289 EXPECT_EQ("100,300 300x300", window_->bounds().ToString()); 280 EXPECT_EQ("100,300 300x300", window_->bounds().ToString());
290 EXPECT_EQ("400,300 200x200", window2_->bounds().ToString()); 281 EXPECT_EQ("400,300 200x200", window2_->bounds().ToString());
291 EXPECT_EQ("600,300 100x200", window3_->bounds().ToString()); 282 EXPECT_EQ("600,300 100x200", window3_->bounds().ToString());
292 283
293 // 100 to the left again. 284 // 100 to the left again.
294 resizer->Drag(CalculateDragPoint(*resizer, -100, -10), 0); 285 resizer->Drag(CalculateDragPoint(*resizer, -100, -10), 0);
295 EXPECT_EQ("100,300 100x300", window_->bounds().ToString()); 286 EXPECT_EQ("100,300 100x300", window_->bounds().ToString());
296 EXPECT_EQ("200,300 270x200", window2_->bounds().ToString()); 287 EXPECT_EQ("200,300 266x200", window2_->bounds().ToString());
297 EXPECT_EQ("470,300 130x200", window3_->bounds().ToString()); 288 EXPECT_EQ("466,300 134x200", window3_->bounds().ToString());
298 } 289 }
299 290
300 // Assertions around collapsing and expanding from the bottom. 291 // Assertions around collapsing and expanding from the bottom.
301 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_Compress) { 292 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_Compress) {
302 window_->SetBounds(gfx::Rect( 0, 100, 400, 300)); 293 window_->SetBounds(gfx::Rect( 0, 100, 400, 300));
303 window2_->SetBounds(gfx::Rect(400, 400, 100, 200)); 294 window2_->SetBounds(gfx::Rect(400, 400, 100, 200));
304 295
305 std::vector<aura::Window*> windows; 296 std::vector<aura::Window*> windows;
306 windows.push_back(window2_.get()); 297 windows.push_back(window2_.get());
307 SetGridSize(0);
308 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 298 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
309 window_.get(), gfx::Point(), HTBOTTOM, windows)); 299 window_.get(), gfx::Point(), HTBOTTOM, windows));
310 ASSERT_TRUE(resizer.get()); 300 ASSERT_TRUE(resizer.get());
311 // Move it up 100, which should expand w2 and collapse w1. 301 // Move it up 100, which should expand w2 and collapse w1.
312 resizer->Drag(CalculateDragPoint(*resizer, 10, -100), 0); 302 resizer->Drag(CalculateDragPoint(*resizer, 10, -100), 0);
313 EXPECT_EQ("0,100 400x200", window_->bounds().ToString()); 303 EXPECT_EQ("0,100 400x200", window_->bounds().ToString());
314 EXPECT_EQ("400,300 100x300", window2_->bounds().ToString()); 304 EXPECT_EQ("400,300 100x300", window2_->bounds().ToString());
315 305
316 // Collapse all the way to w1's min. 306 // Collapse all the way to w1's min.
317 delegate_.set_min_size(gfx::Size(20, 20)); 307 delegate_.set_min_size(gfx::Size(20, 20));
(...skipping 13 matching lines...) Expand all
331 } 321 }
332 322
333 // Assertions around attached window resize dragging from the bottom with 2 323 // Assertions around attached window resize dragging from the bottom with 2
334 // windows. 324 // windows.
335 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_2) { 325 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_2) {
336 window_->SetBounds(gfx::Rect( 0, 50, 400, 200)); 326 window_->SetBounds(gfx::Rect( 0, 50, 400, 200));
337 window2_->SetBounds(gfx::Rect(0, 250, 200, 100)); 327 window2_->SetBounds(gfx::Rect(0, 250, 200, 100));
338 328
339 std::vector<aura::Window*> windows; 329 std::vector<aura::Window*> windows;
340 windows.push_back(window2_.get()); 330 windows.push_back(window2_.get());
341 SetGridSize(0);
342 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 331 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
343 window_.get(), gfx::Point(), HTBOTTOM, windows)); 332 window_.get(), gfx::Point(), HTBOTTOM, windows));
344 ASSERT_TRUE(resizer.get()); 333 ASSERT_TRUE(resizer.get());
345 // Move it 100 to the bottom, which should expand w1 and push w2. 334 // Move it 100 to the bottom, which should expand w1 and push w2.
346 resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0); 335 resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0);
347 EXPECT_EQ("0,50 400x300", window_->bounds().ToString()); 336 EXPECT_EQ("0,50 400x300", window_->bounds().ToString());
348 EXPECT_EQ("0,350 200x100", window2_->bounds().ToString()); 337 EXPECT_EQ("0,350 200x100", window2_->bounds().ToString());
349 338
350 // Push off the screen, w2 should be resized to its min. 339 // Push off the screen, w2 should be resized to its min.
351 delegate2_.set_min_size(gfx::Size(20, 20)); 340 delegate2_.set_min_size(gfx::Size(20, 20));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 372
384 window_->SetBounds(gfx::Rect( 300, 100, 300, 200)); 373 window_->SetBounds(gfx::Rect( 300, 100, 300, 200));
385 window2_->SetBounds(gfx::Rect(300, 300, 200, 150)); 374 window2_->SetBounds(gfx::Rect(300, 300, 200, 150));
386 window3_->SetBounds(gfx::Rect(300, 450, 200, 100)); 375 window3_->SetBounds(gfx::Rect(300, 450, 200, 100));
387 delegate2_.set_min_size(gfx::Size(50, 52)); 376 delegate2_.set_min_size(gfx::Size(50, 52));
388 delegate3_.set_min_size(gfx::Size(50, 38)); 377 delegate3_.set_min_size(gfx::Size(50, 38));
389 378
390 std::vector<aura::Window*> windows; 379 std::vector<aura::Window*> windows;
391 windows.push_back(window2_.get()); 380 windows.push_back(window2_.get());
392 windows.push_back(window3_.get()); 381 windows.push_back(window3_.get());
393 SetGridSize(10);
394 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 382 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
395 window_.get(), gfx::Point(), HTBOTTOM, windows)); 383 window_.get(), gfx::Point(), HTBOTTOM, windows));
396 ASSERT_TRUE(resizer.get()); 384 ASSERT_TRUE(resizer.get());
397 // Move it 100 to the right, which should expand w1 and push w2 and w3. 385 // Move it 100 to the right, which should expand w1 and push w2 and w3.
398 resizer->Drag(CalculateDragPoint(*resizer, -10, 100), 0); 386 resizer->Drag(CalculateDragPoint(*resizer, -10, 100), 0);
399 EXPECT_EQ("300,100 300x300", window_->bounds().ToString()); 387 EXPECT_EQ("300,100 300x300", window_->bounds().ToString());
400 EXPECT_EQ("300,400 200x150", window2_->bounds().ToString()); 388 EXPECT_EQ("300,400 200x150", window2_->bounds().ToString());
401 EXPECT_EQ("300,550 200x100", window3_->bounds().ToString()); 389 EXPECT_EQ("300,550 200x100", window3_->bounds().ToString());
402 390
403 // Move it 296, which should now snap to grid and things should compress. 391 // Move it 296 things should compress.
404 resizer->Drag(CalculateDragPoint(*resizer, -10, 296), 0); 392 resizer->Drag(CalculateDragPoint(*resizer, -10, 296), 0);
405 EXPECT_EQ("300,100 300x500", window_->bounds().ToString()); 393 EXPECT_EQ("300,100 300x496", window_->bounds().ToString());
406 EXPECT_EQ("300,600 200x120", window2_->bounds().ToString()); 394 EXPECT_EQ("300,596 200x122", window2_->bounds().ToString());
407 EXPECT_EQ("300,720 200x80", window3_->bounds().ToString()); 395 EXPECT_EQ("300,718 200x82", window3_->bounds().ToString());
408 396
409 // Move it so much everything ends up at its min. 397 // Move it so much everything ends up at its min.
410 resizer->Drag(CalculateDragPoint(*resizer, 50, 798), 0); 398 resizer->Drag(CalculateDragPoint(*resizer, 50, 798), 0);
411 EXPECT_EQ("300,100 300x600", window_->bounds().ToString()); 399 EXPECT_EQ("300,100 300x610", window_->bounds().ToString());
412 EXPECT_EQ("300,700 200x60", window2_->bounds().ToString()); 400 EXPECT_EQ("300,710 200x52", window2_->bounds().ToString());
413 EXPECT_EQ("300,760 200x40", window3_->bounds().ToString()); 401 EXPECT_EQ("300,762 200x38", window3_->bounds().ToString());
414 402
415 // Revert and make sure everything moves back. 403 // Revert and make sure everything moves back.
416 resizer->RevertDrag(); 404 resizer->RevertDrag();
417 EXPECT_EQ("300,100 300x200", window_->bounds().ToString()); 405 EXPECT_EQ("300,100 300x200", window_->bounds().ToString());
418 EXPECT_EQ("300,300 200x150", window2_->bounds().ToString()); 406 EXPECT_EQ("300,300 200x150", window2_->bounds().ToString());
419 EXPECT_EQ("300,450 200x100", window3_->bounds().ToString()); 407 EXPECT_EQ("300,450 200x100", window3_->bounds().ToString());
420 } 408 }
421 409
422 // Assertions around attached window resizing (collapsing and expanding) with 410 // Assertions around attached window resizing (collapsing and expanding) with
423 // 3 windows. 411 // 3 windows.
424 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_3_Compress) { 412 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_3_Compress) {
425 window_->SetBounds(gfx::Rect( 0, 0, 200, 200)); 413 window_->SetBounds(gfx::Rect( 0, 0, 200, 200));
426 window2_->SetBounds(gfx::Rect(10, 200, 200, 200)); 414 window2_->SetBounds(gfx::Rect(10, 200, 200, 200));
427 window3_->SetBounds(gfx::Rect(20, 400, 100, 100)); 415 window3_->SetBounds(gfx::Rect(20, 400, 100, 100));
428 delegate2_.set_min_size(gfx::Size(52, 50)); 416 delegate2_.set_min_size(gfx::Size(52, 50));
429 delegate3_.set_min_size(gfx::Size(38, 50)); 417 delegate3_.set_min_size(gfx::Size(38, 50));
430 418
431 std::vector<aura::Window*> windows; 419 std::vector<aura::Window*> windows;
432 windows.push_back(window2_.get()); 420 windows.push_back(window2_.get());
433 windows.push_back(window3_.get()); 421 windows.push_back(window3_.get());
434 SetGridSize(10);
435 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 422 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
436 window_.get(), gfx::Point(), HTBOTTOM, windows)); 423 window_.get(), gfx::Point(), HTBOTTOM, windows));
437 ASSERT_TRUE(resizer.get()); 424 ASSERT_TRUE(resizer.get());
438 // Move it 100 up, which should collapse w1 and expand w2 and w3. 425 // Move it 100 up, which should collapse w1 and expand w2 and w3.
439 resizer->Drag(CalculateDragPoint(*resizer, -10, -100), 0); 426 resizer->Drag(CalculateDragPoint(*resizer, -10, -100), 0);
440 EXPECT_EQ("0,0 200x100", window_->bounds().ToString()); 427 EXPECT_EQ("0,0 200x100", window_->bounds().ToString());
441 EXPECT_EQ("10,100 200x270", window2_->bounds().ToString()); 428 EXPECT_EQ("10,100 200x266", window2_->bounds().ToString());
442 EXPECT_EQ("20,370 100x130", window3_->bounds().ToString()); 429 EXPECT_EQ("20,366 100x134", window3_->bounds().ToString());
443 430
444 // Move it 100 down. 431 // Move it 100 down.
445 resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0); 432 resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0);
446 EXPECT_EQ("0,0 200x300", window_->bounds().ToString()); 433 EXPECT_EQ("0,0 200x300", window_->bounds().ToString());
447 EXPECT_EQ("10,300 200x200", window2_->bounds().ToString()); 434 EXPECT_EQ("10,300 200x200", window2_->bounds().ToString());
448 EXPECT_EQ("20,500 100x100", window3_->bounds().ToString()); 435 EXPECT_EQ("20,500 100x100", window3_->bounds().ToString());
449 436
450 // 100 up again. 437 // 100 up again.
451 resizer->Drag(CalculateDragPoint(*resizer, -10, -100), 0); 438 resizer->Drag(CalculateDragPoint(*resizer, -10, -100), 0);
452 EXPECT_EQ("0,0 200x100", window_->bounds().ToString()); 439 EXPECT_EQ("0,0 200x100", window_->bounds().ToString());
453 EXPECT_EQ("10,100 200x270", window2_->bounds().ToString()); 440 EXPECT_EQ("10,100 200x266", window2_->bounds().ToString());
454 EXPECT_EQ("20,370 100x130", window3_->bounds().ToString()); 441 EXPECT_EQ("20,366 100x134", window3_->bounds().ToString());
455 } 442 }
456 443
457 // Assertions around dragging to the left/right edge of the screen. 444 // Assertions around dragging to the left/right edge of the screen.
458 TEST_F(WorkspaceWindowResizerTest, Edge) { 445 TEST_F(WorkspaceWindowResizerTest, Edge) {
459 int bottom = 446 int bottom =
460 ScreenAsh::GetUnmaximizedWorkAreaBoundsInParent(window_.get()).bottom(); 447 ScreenAsh::GetUnmaximizedWorkAreaBoundsInParent(window_.get()).bottom();
461 window_->SetBounds(gfx::Rect(20, 30, 50, 60)); 448 window_->SetBounds(gfx::Rect(20, 30, 50, 60));
462 { 449 {
463 SetGridSize(0);
464 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 450 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
465 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 451 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
466 ASSERT_TRUE(resizer.get()); 452 ASSERT_TRUE(resizer.get());
467 resizer->Drag(CalculateDragPoint(*resizer, 0, 10), 0); 453 resizer->Drag(CalculateDragPoint(*resizer, 0, 10), 0);
468 resizer->CompleteDrag(0); 454 resizer->CompleteDrag(0);
469 EXPECT_EQ("0,0 720x" + base::IntToString(bottom), 455 EXPECT_EQ("0,0 720x" + base::IntToString(bottom),
470 window_->bounds().ToString()); 456 window_->bounds().ToString());
471 ASSERT_TRUE(GetRestoreBoundsInScreen(window_.get())); 457 ASSERT_TRUE(GetRestoreBoundsInScreen(window_.get()));
472 EXPECT_EQ("20,30 50x60", 458 EXPECT_EQ("20,30 50x60",
473 GetRestoreBoundsInScreen(window_.get())->ToString()); 459 GetRestoreBoundsInScreen(window_.get())->ToString());
474 } 460 }
475 461
476 // Try the same with the right side. 462 // Try the same with the right side.
477 SetGridSize(0);
478 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 463 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
479 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 464 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
480 ASSERT_TRUE(resizer.get()); 465 ASSERT_TRUE(resizer.get());
481 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0); 466 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0);
482 resizer->CompleteDrag(0); 467 resizer->CompleteDrag(0);
483 EXPECT_EQ("80,0 720x" + base::IntToString(bottom), 468 EXPECT_EQ("80,0 720x" + base::IntToString(bottom),
484 window_->bounds().ToString()); 469 window_->bounds().ToString());
485 ASSERT_TRUE(GetRestoreBoundsInScreen(window_.get())); 470 ASSERT_TRUE(GetRestoreBoundsInScreen(window_.get()));
486 EXPECT_EQ("20,30 50x60", GetRestoreBoundsInScreen(window_.get())->ToString()); 471 EXPECT_EQ("20,30 50x60", GetRestoreBoundsInScreen(window_.get())->ToString());
487 } 472 }
488 473
489 // Verifies a window can be moved from the primary display to another. 474 // Verifies a window can be moved from the primary display to another.
490 TEST_F(WorkspaceWindowResizerTest, MAYBE_WindowDragWithMultiMonitors) { 475 TEST_F(WorkspaceWindowResizerTest, MAYBE_WindowDragWithMultiMonitors) {
491 // The secondary display is logically on the right, but on the system (e.g. X) 476 // The secondary display is logically on the right, but on the system (e.g. X)
492 // layer, it's below the primary one. See UpdateDisplay() in ash_test_base.cc. 477 // layer, it's below the primary one. See UpdateDisplay() in ash_test_base.cc.
493 UpdateDisplay("800x600,800x600"); 478 UpdateDisplay("800x600,800x600");
494 Shell::GetInstance()->shelf()->LayoutShelf(); 479 Shell::GetInstance()->shelf()->LayoutShelf();
495 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 480 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
496 ASSERT_EQ(2U, root_windows.size()); 481 ASSERT_EQ(2U, root_windows.size());
497 482
498 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), 483 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
499 gfx::Screen::GetPrimaryDisplay()); 484 gfx::Screen::GetPrimaryDisplay());
500 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 485 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
501 { 486 {
502 SetGridSize(0);
503 // Grab (0, 0) of the window. 487 // Grab (0, 0) of the window.
504 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 488 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
505 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 489 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
506 ASSERT_TRUE(resizer.get()); 490 ASSERT_TRUE(resizer.get());
507 // Drag the pointer to the right. Once it reaches the right edge of the 491 // Drag the pointer to the right. Once it reaches the right edge of the
508 // primary display, it warps to the secondary. Since the secondary root 492 // primary display, it warps to the secondary. Since the secondary root
509 // window's native origin held by aura::RootWindowHost is (0, 600), and a 493 // window's native origin held by aura::RootWindowHost is (0, 600), and a
510 // mouse drag event has a location in the primary root window's coordinates, 494 // mouse drag event has a location in the primary root window's coordinates,
511 // (0, 610) below means (0, 10) in the second root window's coordinates. 495 // (0, 610) below means (0, 10) in the second root window's coordinates.
512 resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0); 496 resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0);
(...skipping 22 matching lines...) Expand all
535 519
536 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), 520 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
537 gfx::Screen::GetPrimaryDisplay()); 521 gfx::Screen::GetPrimaryDisplay());
538 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 522 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
539 { 523 {
540 // Grab the top-right edge of the window and move the pointer to (0, 10) 524 // Grab the top-right edge of the window and move the pointer to (0, 10)
541 // in the secondary root window's coordinates. 525 // in the secondary root window's coordinates.
542 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 526 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
543 window_.get(), gfx::Point(49, 0), HTCAPTION, empty_windows())); 527 window_.get(), gfx::Point(49, 0), HTCAPTION, empty_windows()));
544 ASSERT_TRUE(resizer.get()); 528 ASSERT_TRUE(resizer.get());
545 resizer->Drag(CalculateDragPoint(*resizer, -49, 610), 0); 529 resizer->Drag(CalculateDragPoint(*resizer, -49, 610), ui::EF_CONTROL_DOWN);
546 resizer->CompleteDrag(0); 530 resizer->CompleteDrag(0);
547 // Since the pointer is on the secondary, the parent should not be changed 531 // Since the pointer is on the secondary, the parent should not be changed
548 // even though only small fraction of the window is within the secondary 532 // even though only small fraction of the window is within the secondary
549 // root window's bounds. 533 // root window's bounds.
550 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); 534 EXPECT_EQ(root_windows[1], window_->GetRootWindow());
551 EXPECT_EQ("-49,10 50x60", window_->bounds().ToString()); 535 EXPECT_EQ("-49,10 50x60", window_->bounds().ToString());
552 } 536 }
553 } 537 }
554 538
555 // Verifies a window can be moved from the secondary display to primary. 539 // Verifies a window can be moved from the secondary display to primary.
556 TEST_F(WorkspaceWindowResizerTest, 540 TEST_F(WorkspaceWindowResizerTest,
557 MAYBE_WindowDragWithMultiMonitorsRightToLeft) { 541 MAYBE_WindowDragWithMultiMonitorsRightToLeft) {
558 UpdateDisplay("800x600,800x600"); 542 UpdateDisplay("800x600,800x600");
559 Shell::GetInstance()->shelf()->LayoutShelf(); 543 Shell::GetInstance()->shelf()->LayoutShelf();
560 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 544 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
561 ASSERT_EQ(2U, root_windows.size()); 545 ASSERT_EQ(2U, root_windows.size());
562 546
563 window_->SetBoundsInScreen( 547 window_->SetBoundsInScreen(
564 gfx::Rect(800, 00, 50, 60), 548 gfx::Rect(800, 00, 50, 60),
565 gfx::Screen::GetDisplayNearestWindow(root_windows[1])); 549 gfx::Screen::GetDisplayNearestWindow(root_windows[1]));
566 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); 550 EXPECT_EQ(root_windows[1], window_->GetRootWindow());
567 { 551 {
568 SetGridSize(0);
569 // Grab (0, 0) of the window. 552 // Grab (0, 0) of the window.
570 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 553 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
571 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 554 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
572 ASSERT_TRUE(resizer.get()); 555 ASSERT_TRUE(resizer.get());
573 // Move the mouse near the right edge, (798, 0), of the primary display. 556 // Move the mouse near the right edge, (798, 0), of the primary display.
574 resizer->Drag(CalculateDragPoint(*resizer, 798, -600), 0); 557 resizer->Drag(CalculateDragPoint(*resizer, 798, -600), ui::EF_CONTROL_DOWN);
575 resizer->CompleteDrag(0); 558 resizer->CompleteDrag(0);
576 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 559 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
577 EXPECT_EQ("798,0 50x60", window_->bounds().ToString()); 560 EXPECT_EQ("798,0 50x60", window_->bounds().ToString());
578 } 561 }
579 } 562 }
580 563
581 // Verifies the style of the drag phantom window is correct. 564 // Verifies the style of the drag phantom window is correct.
582 TEST_F(WorkspaceWindowResizerTest, MAYBE_PhantomStyle) { 565 TEST_F(WorkspaceWindowResizerTest, MAYBE_PhantomStyle) {
583 UpdateDisplay("800x600,800x600"); 566 UpdateDisplay("800x600,800x600");
584 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 567 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
585 ASSERT_EQ(2U, root_windows.size()); 568 ASSERT_EQ(2U, root_windows.size());
586 569
587 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), 570 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
588 gfx::Screen::GetPrimaryDisplay()); 571 gfx::Screen::GetPrimaryDisplay());
589 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 572 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
590 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); 573 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
591 { 574 {
592 SetGridSize(0);
593 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 575 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
594 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 576 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
595 ASSERT_TRUE(resizer.get()); 577 ASSERT_TRUE(resizer.get());
596 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); 578 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get());
597 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get()); 579 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get());
598 580
599 // The pointer is inside the primary root. Both phantoms should be NULL. 581 // The pointer is inside the primary root. Both phantoms should be NULL.
600 resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0); 582 resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0);
601 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); 583 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get());
602 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get()); 584 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get());
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 691
710 // Verifies windows are correctly restacked when reordering multiple windows. 692 // Verifies windows are correctly restacked when reordering multiple windows.
711 TEST_F(WorkspaceWindowResizerTest, RestackAttached) { 693 TEST_F(WorkspaceWindowResizerTest, RestackAttached) {
712 window_->SetBounds(gfx::Rect( 0, 0, 200, 300)); 694 window_->SetBounds(gfx::Rect( 0, 0, 200, 300));
713 window2_->SetBounds(gfx::Rect(200, 0, 100, 200)); 695 window2_->SetBounds(gfx::Rect(200, 0, 100, 200));
714 window3_->SetBounds(gfx::Rect(300, 0, 100, 100)); 696 window3_->SetBounds(gfx::Rect(300, 0, 100, 100));
715 697
716 { 698 {
717 std::vector<aura::Window*> windows; 699 std::vector<aura::Window*> windows;
718 windows.push_back(window2_.get()); 700 windows.push_back(window2_.get());
719 SetGridSize(10);
720 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 701 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
721 window_.get(), gfx::Point(), HTRIGHT, windows)); 702 window_.get(), gfx::Point(), HTRIGHT, windows));
722 ASSERT_TRUE(resizer.get()); 703 ASSERT_TRUE(resizer.get());
723 // Move it 100 to the right, which should expand w1 and push w2 and w3. 704 // Move it 100 to the right, which should expand w1 and push w2 and w3.
724 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0); 705 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
725 706
726 // 2 should be topmost since it's initially the highest in the stack. 707 // 2 should be topmost since it's initially the highest in the stack.
727 EXPECT_EQ("2 1 3", WindowOrderAsString(window_->parent())); 708 EXPECT_EQ("2 1 3", WindowOrderAsString(window_->parent()));
728 } 709 }
729 710
730 { 711 {
731 std::vector<aura::Window*> windows; 712 std::vector<aura::Window*> windows;
732 windows.push_back(window3_.get()); 713 windows.push_back(window3_.get());
733 SetGridSize(10);
734 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 714 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
735 window2_.get(), gfx::Point(), HTRIGHT, windows)); 715 window2_.get(), gfx::Point(), HTRIGHT, windows));
736 ASSERT_TRUE(resizer.get()); 716 ASSERT_TRUE(resizer.get());
737 // Move it 100 to the right, which should expand w1 and push w2 and w3. 717 // Move it 100 to the right, which should expand w1 and push w2 and w3.
738 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0); 718 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
739 719
740 // 2 should be topmost since it's initially the highest in the stack. 720 // 2 should be topmost since it's initially the highest in the stack.
741 EXPECT_EQ("2 3 1", WindowOrderAsString(window_->parent())); 721 EXPECT_EQ("2 3 1", WindowOrderAsString(window_->parent()));
742 } 722 }
743 } 723 }
744 724
745 // Makes sure we don't allow dragging below the work area. 725 // Makes sure we don't allow dragging below the work area.
746 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottom) { 726 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottom) {
747 Shell::GetInstance()->SetDisplayWorkAreaInsets( 727 Shell::GetInstance()->SetDisplayWorkAreaInsets(
748 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0)); 728 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0));
749 729
750 ASSERT_EQ(1, gfx::Screen::GetNumDisplays()); 730 ASSERT_EQ(1, gfx::Screen::GetNumDisplays());
751 731
752 window_->SetBounds(gfx::Rect(100, 200, 300, 400)); 732 window_->SetBounds(gfx::Rect(100, 200, 300, 400));
753 SetGridSize(0);
754 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 733 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
755 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 734 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
756 ASSERT_TRUE(resizer.get()); 735 ASSERT_TRUE(resizer.get());
757 resizer->Drag(CalculateDragPoint(*resizer, 0, 600), 0); 736 resizer->Drag(CalculateDragPoint(*resizer, 0, 600), 0);
758 int expected_y = 737 int expected_y =
759 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10; 738 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10;
760 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400", 739 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400",
761 window_->bounds().ToString()); 740 window_->bounds().ToString());
762 } 741 }
763 742
764 // Makes sure we don't allow dragging off the top of the work area. 743 // Makes sure we don't allow dragging off the top of the work area.
765 TEST_F(WorkspaceWindowResizerTest, DontDragOffTop) { 744 TEST_F(WorkspaceWindowResizerTest, DontDragOffTop) {
766 Shell::GetInstance()->SetDisplayWorkAreaInsets( 745 Shell::GetInstance()->SetDisplayWorkAreaInsets(
767 Shell::GetPrimaryRootWindow(), gfx::Insets(10, 0, 0, 0)); 746 Shell::GetPrimaryRootWindow(), gfx::Insets(10, 0, 0, 0));
768 747
769 window_->SetBounds(gfx::Rect(100, 200, 300, 400)); 748 window_->SetBounds(gfx::Rect(100, 200, 300, 400));
770 SetGridSize(0);
771 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 749 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
772 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 750 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
773 ASSERT_TRUE(resizer.get()); 751 ASSERT_TRUE(resizer.get());
774 resizer->Drag(CalculateDragPoint(*resizer, 0, -600), 0); 752 resizer->Drag(CalculateDragPoint(*resizer, 0, -600), 0);
775 EXPECT_EQ("100,10 300x400", window_->bounds().ToString()); 753 EXPECT_EQ("100,10 300x400", window_->bounds().ToString());
776 } 754 }
777 755
778 TEST_F(WorkspaceWindowResizerTest, ResizeBottomOutsideWorkArea) { 756 TEST_F(WorkspaceWindowResizerTest, ResizeBottomOutsideWorkArea) {
779 Shell::GetInstance()->SetDisplayWorkAreaInsets( 757 Shell::GetInstance()->SetDisplayWorkAreaInsets(
780 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0)); 758 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
781 759
782 window_->SetBounds(gfx::Rect(100, 200, 300, 380)); 760 window_->SetBounds(gfx::Rect(100, 200, 300, 380));
783 SetGridSize(10);
784 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 761 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
785 window_.get(), gfx::Point(), HTTOP, empty_windows())); 762 window_.get(), gfx::Point(), HTTOP, empty_windows()));
786 ASSERT_TRUE(resizer.get()); 763 ASSERT_TRUE(resizer.get());
787 resizer->Drag(CalculateDragPoint(*resizer, 8, 0), 0); 764 resizer->Drag(CalculateDragPoint(*resizer, 8, 0), 0);
788 EXPECT_EQ("100,200 300x380", window_->bounds().ToString()); 765 EXPECT_EQ("100,200 300x380", window_->bounds().ToString());
789 } 766 }
790 767
791 // Verifies snapping to edges works. 768 // Verifies snapping to edges works.
792 TEST_F(WorkspaceWindowResizerTest, SnapToEdge) { 769 TEST_F(WorkspaceWindowResizerTest, SnapToEdge) {
793 Shell::GetInstance()->SetShelfAutoHideBehavior( 770 Shell::GetInstance()->SetShelfAutoHideBehavior(
794 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 771 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
795 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); 772 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
796 SetGridSize(16);
797 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 773 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
798 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 774 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
799 ASSERT_TRUE(resizer.get()); 775 ASSERT_TRUE(resizer.get());
800 // Move to an x-coordinate of 15, which should not snap. 776 // Move to an x-coordinate of 15, which should not snap.
801 resizer->Drag(CalculateDragPoint(*resizer, -81, 0), 0); 777 resizer->Drag(CalculateDragPoint(*resizer, -81, 0), 0);
802 // An x-coordinate of 7 should snap. 778 // An x-coordinate of 7 should snap.
803 resizer->Drag(CalculateDragPoint(*resizer, -89, 0), 0); 779 resizer->Drag(CalculateDragPoint(*resizer, -89, 0), 0);
804 EXPECT_EQ("0,112 320x160", window_->bounds().ToString()); 780 EXPECT_EQ("0,112 320x160", window_->bounds().ToString());
805 // Move to -20, should still snap to 0. 781 // Move to -15, should still snap to 0.
806 resizer->Drag(CalculateDragPoint(*resizer, -116, 0), 0); 782 resizer->Drag(CalculateDragPoint(*resizer, -111, 0), 0);
807 EXPECT_EQ("0,112 320x160", window_->bounds().ToString()); 783 EXPECT_EQ("0,112 320x160", window_->bounds().ToString());
808 // At -32 should move past snap points. 784 // At -32 should move past snap points.
809 resizer->Drag(CalculateDragPoint(*resizer, -128, 0), 0); 785 resizer->Drag(CalculateDragPoint(*resizer, -128, 0), 0);
810 EXPECT_EQ("-32,112 320x160", window_->bounds().ToString()); 786 EXPECT_EQ("-32,112 320x160", window_->bounds().ToString());
811 resizer->Drag(CalculateDragPoint(*resizer, -129, 0), 0); 787 resizer->Drag(CalculateDragPoint(*resizer, -129, 0), 0);
812 EXPECT_EQ("-33,112 320x160", window_->bounds().ToString()); 788 EXPECT_EQ("-33,112 320x160", window_->bounds().ToString());
813 789
814 // Right side should similarly snap. 790 // Right side should similarly snap.
815 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 - 15, 0), 0); 791 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 - 15, 0), 0);
816 EXPECT_EQ("465,112 320x160", window_->bounds().ToString()); 792 EXPECT_EQ("465,112 320x160", window_->bounds().ToString());
817 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 - 7, 0), 0); 793 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 - 7, 0), 0);
818 EXPECT_EQ("480,112 320x160", window_->bounds().ToString()); 794 EXPECT_EQ("480,112 320x160", window_->bounds().ToString());
819 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 20, 0), 0); 795 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 15, 0), 0);
820 EXPECT_EQ("480,112 320x160", window_->bounds().ToString()); 796 EXPECT_EQ("480,112 320x160", window_->bounds().ToString());
821 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 32, 0), 0); 797 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 32, 0), 0);
822 EXPECT_EQ("512,112 320x160", window_->bounds().ToString()); 798 EXPECT_EQ("512,112 320x160", window_->bounds().ToString());
823 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 33, 0), 0); 799 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 33, 0), 0);
824 EXPECT_EQ("513,112 320x160", window_->bounds().ToString()); 800 EXPECT_EQ("513,112 320x160", window_->bounds().ToString());
825 801
826 // And the bottom should snap too. 802 // And the bottom should snap too.
827 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 15), 0); 803 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 2 - 7), 0);
828 EXPECT_EQ("96,432 320x160", window_->bounds().ToString()); 804 EXPECT_EQ("96,438 320x160", window_->bounds().ToString());
829 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 + 20), 0); 805 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 2 + 15), 0);
830 EXPECT_EQ("96,432 320x160", window_->bounds().ToString()); 806 EXPECT_EQ("96,438 320x160", window_->bounds().ToString());
831 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 + 32), 0); 807 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 2 + 32), 0);
832 EXPECT_EQ("96,472 320x160", window_->bounds().ToString()); 808 EXPECT_EQ("96,470 320x160", window_->bounds().ToString());
833 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 + 33), 0); 809 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 2 + 33), 0);
834 EXPECT_EQ("96,473 320x160", window_->bounds().ToString()); 810 EXPECT_EQ("96,471 320x160", window_->bounds().ToString());
835 811
836 // And the top should snap too. 812 // And the top should snap too.
837 resizer->Drag(CalculateDragPoint(*resizer, 0, -112 + 20), 0); 813 resizer->Drag(CalculateDragPoint(*resizer, 0, -112 + 20), 0);
838 EXPECT_EQ("96,20 320x160", window_->bounds().ToString()); 814 EXPECT_EQ("96,20 320x160", window_->bounds().ToString());
839 resizer->Drag(CalculateDragPoint(*resizer, 0, -112 + 7), 0); 815 resizer->Drag(CalculateDragPoint(*resizer, 0, -112 + 7), 0);
840 EXPECT_EQ("96,0 320x160", window_->bounds().ToString()); 816 EXPECT_EQ("96,0 320x160", window_->bounds().ToString());
841 // No need to test dragging < 0 as we force that to 0. 817 // No need to test dragging < 0 as we force that to 0.
842 } 818 }
843 819
844 // Verifies a window taller than work area height doesn't snap above the top of 820 // Verifies a window taller than work area height doesn't snap above the top of
845 // the work area. 821 // the work area.
846 TEST_F(WorkspaceWindowResizerTest, TallWindow) { 822 TEST_F(WorkspaceWindowResizerTest, TallWindow) {
847 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); 823 aura::RootWindow* root = Shell::GetPrimaryRootWindow();
848 Shell::GetInstance()->SetDisplayWorkAreaInsets( 824 Shell::GetInstance()->SetDisplayWorkAreaInsets(
849 root, gfx::Insets(0, 0, 50, 0)); 825 root, gfx::Insets(0, 0, 50, 0));
850 window_->SetBounds(gfx::Rect(0, 0, 320, 560)); 826 window_->SetBounds(gfx::Rect(0, 0, 320, 560));
851 SetGridSize(16);
852 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 827 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
853 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 828 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
854 resizer->Drag(CalculateDragPoint(*resizer, 0, 9), 0); 829 resizer->Drag(CalculateDragPoint(*resizer, 0, 9), 0);
855 EXPECT_EQ("0,9 320x560", window_->bounds().ToString()); 830 EXPECT_EQ("0,9 320x560", window_->bounds().ToString());
856 } 831 }
857 832
858 TEST_F(WorkspaceWindowResizerTest, DragResizeSnapToGrid) { 833 TEST_F(WorkspaceWindowResizerTest, CtrlDragResizeToExactPosition) {
859 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); 834 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
860 SetGridSize(16);
861 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 835 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
862 window_.get(), gfx::Point(), HTBOTTOMRIGHT, empty_windows())); 836 window_.get(), gfx::Point(), HTBOTTOMRIGHT, empty_windows()));
863 ASSERT_TRUE(resizer.get()); 837 ASSERT_TRUE(resizer.get());
864 // Resize the right bottom to add 10 in width, 12 in height.
865 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0);
866 // Both bottom and right sides should snap to grids.
867 EXPECT_EQ("96,112 336x176", window_->bounds().ToString());
868 }
869
870 TEST_F(WorkspaceWindowResizerTest, CtrlDragResizeToExactPosition) {
871 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
872 SetGridSize(16);
873 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
874 window_.get(), gfx::Point(), HTBOTTOMRIGHT, empty_windows()));
875 ASSERT_TRUE(resizer.get());
876 // Resize the right bottom to add 10 in width, 12 in height. 838 // Resize the right bottom to add 10 in width, 12 in height.
877 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), ui::EF_CONTROL_DOWN); 839 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), ui::EF_CONTROL_DOWN);
878 // Both bottom and right sides to resize to exact size requested. 840 // Both bottom and right sides to resize to exact size requested.
879 EXPECT_EQ("96,112 330x172", window_->bounds().ToString()); 841 EXPECT_EQ("96,112 330x172", window_->bounds().ToString());
880 } 842 }
881 843
882 TEST_F(WorkspaceWindowResizerTest, CompleteDragMoveSnapToGrid) {
883 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
884 SetGridSize(16);
885 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
886 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
887 ASSERT_TRUE(resizer.get());
888 // Drag the window to new poistion by adding (10, 12) to original point,
889 // the window should snap to the closed grid.
890 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0);
891 resizer->CompleteDrag(0);
892 EXPECT_EQ("112,128 320x160", window_->bounds().ToString());
893 }
894
895 TEST_F(WorkspaceWindowResizerTest, CtrlCompleteDragMoveToExactPosition) { 844 TEST_F(WorkspaceWindowResizerTest, CtrlCompleteDragMoveToExactPosition) {
896 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); 845 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
897 SetGridSize(16);
898 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 846 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
899 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 847 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
900 ASSERT_TRUE(resizer.get()); 848 ASSERT_TRUE(resizer.get());
901 // Ctrl + drag the window to new poistion by adding (10, 12) to its origin, 849 // Ctrl + drag the window to new poistion by adding (10, 12) to its origin,
902 // the window should move to the exact position. 850 // the window should move to the exact position.
903 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0); 851 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0);
904 resizer->CompleteDrag(ui::EF_CONTROL_DOWN); 852 resizer->CompleteDrag(ui::EF_CONTROL_DOWN);
905 EXPECT_EQ("106,124 320x160", window_->bounds().ToString()); 853 EXPECT_EQ("106,124 320x160", window_->bounds().ToString());
906 } 854 }
907 855
908 // Check that only usable sizes get returned by the resizer. 856 // Check that only usable sizes get returned by the resizer.
909 TEST_F(WorkspaceWindowResizerTest, TestProperSizerResolutions) { 857 TEST_F(WorkspaceWindowResizerTest, TestProperSizerResolutions) {
910 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); 858 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
911 SetGridSize(16);
912 scoped_ptr<SnapSizer> resizer(new SnapSizer( 859 scoped_ptr<SnapSizer> resizer(new SnapSizer(
913 window_.get(), gfx::Point(), SnapSizer::LEFT_EDGE, 1)); 860 window_.get(), gfx::Point(), SnapSizer::LEFT_EDGE));
914 ASSERT_TRUE(resizer.get()); 861 ASSERT_TRUE(resizer.get());
915 gfx::Rect rect = resizer->GetTargetBoundsForSize(0); 862 gfx::Rect rect = resizer->GetTargetBoundsForSize(0);
916 EXPECT_EQ("0,0 720x552", rect.ToString()); 863 EXPECT_EQ("0,0 720x552", rect.ToString());
917 rect = resizer->GetTargetBoundsForSize(1); 864 rect = resizer->GetTargetBoundsForSize(1);
918 EXPECT_EQ("0,0 720x552", rect.ToString()); 865 EXPECT_EQ("0,0 720x552", rect.ToString());
919 rect = resizer->GetTargetBoundsForSize(2); 866 rect = resizer->GetTargetBoundsForSize(2);
920 EXPECT_EQ("0,0 720x552", rect.ToString()); 867 EXPECT_EQ("0,0 720x552", rect.ToString());
921 rect = resizer->GetTargetBoundsForSize(3); 868 rect = resizer->GetTargetBoundsForSize(3);
922 EXPECT_EQ("0,0 640x552", rect.ToString()); 869 EXPECT_EQ("0,0 640x552", rect.ToString());
923 } 870 }
924 871
925 } // namespace internal 872 } // namespace internal
926 } // namespace ash 873 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/workspace_window_resizer.cc ('k') | ash/wm/workspace_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698