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
3 // found in the LICENSE file.
5 #include "ash/wm/workspace/workspace_window_resizer.h"
7 #include "ash/display/display_manager.h"
8 #include "ash/root_window_controller.h"
9 #include "ash/screen_util.h"
10 #include "ash/shelf/shelf_layout_manager.h"
11 #include "ash/shell.h"
12 #include "ash/shell_window_ids.h"
13 #include "ash/test/ash_test_base.h"
14 #include "ash/wm/window_state.h"
15 #include "ash/wm/window_util.h"
16 #include "ash/wm/wm_event.h"
17 #include "ash/wm/workspace/phantom_window_controller.h"
18 #include "ash/wm/workspace_controller.h"
19 #include "base/command_line.h"
20 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/stringprintf.h"
22 #include "ui/aura/client/aura_constants.h"
23 #include "ui/aura/test/test_window_delegate.h"
24 #include "ui/aura/window_event_dispatcher.h"
25 #include "ui/base/hit_test.h"
26 #include "ui/events/gesture_detection/gesture_configuration.h"
27 #include "ui/events/test/event_generator.h"
28 #include "ui/gfx/geometry/insets.h"
29 #include "ui/gfx/screen.h"
30 #include "ui/views/widget/widget.h"
35 const int kRootHeight
= 600;
37 // A simple window delegate that returns the specified min size.
38 class TestWindowDelegate
: public aura::test::TestWindowDelegate
{
40 TestWindowDelegate() {
42 ~TestWindowDelegate() override
{}
44 void set_min_size(const gfx::Size
& size
) {
48 void set_max_size(const gfx::Size
& size
) {
53 // Overridden from aura::Test::TestWindowDelegate:
54 gfx::Size
GetMinimumSize() const override
{ return min_size_
; }
56 gfx::Size
GetMaximumSize() const override
{ return max_size_
; }
61 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate
);
66 class WorkspaceWindowResizerTest
: public test::AshTestBase
{
68 WorkspaceWindowResizerTest() : workspace_resizer_(NULL
) {}
69 ~WorkspaceWindowResizerTest() override
{}
71 void SetUp() override
{
73 UpdateDisplay(base::StringPrintf("800x%d", kRootHeight
));
74 // Ignore the touch slop region.
75 ui::GestureConfiguration::GetInstance()
76 ->set_max_touch_move_in_pixels_for_click(0);
78 aura::Window
* root
= Shell::GetPrimaryRootWindow();
79 gfx::Rect
root_bounds(root
->bounds());
81 // RootWindow and Display can't resize on Windows Ash.
82 // http://crbug.com/165962
83 EXPECT_EQ(kRootHeight
, root_bounds
.height());
85 EXPECT_EQ(800, root_bounds
.width());
86 Shell::GetInstance()->SetDisplayWorkAreaInsets(root
, gfx::Insets());
87 window_
.reset(new aura::Window(&delegate_
));
88 window_
->SetType(ui::wm::WINDOW_TYPE_NORMAL
);
89 window_
->Init(aura::WINDOW_LAYER_NOT_DRAWN
);
90 ParentWindowInPrimaryRootWindow(window_
.get());
93 window2_
.reset(new aura::Window(&delegate2_
));
94 window2_
->SetType(ui::wm::WINDOW_TYPE_NORMAL
);
95 window2_
->Init(aura::WINDOW_LAYER_NOT_DRAWN
);
96 ParentWindowInPrimaryRootWindow(window2_
.get());
99 window3_
.reset(new aura::Window(&delegate3_
));
100 window3_
->SetType(ui::wm::WINDOW_TYPE_NORMAL
);
101 window3_
->Init(aura::WINDOW_LAYER_NOT_DRAWN
);
102 ParentWindowInPrimaryRootWindow(window3_
.get());
105 window4_
.reset(new aura::Window(&delegate4_
));
106 window4_
->SetType(ui::wm::WINDOW_TYPE_NORMAL
);
107 window4_
->Init(aura::WINDOW_LAYER_NOT_DRAWN
);
108 ParentWindowInPrimaryRootWindow(window4_
.get());
112 void TearDown() override
{
117 touch_resize_window_
.reset();
118 AshTestBase::TearDown();
121 // Returns a string identifying the z-order of each of the known child windows
122 // of |parent|. The returned string constains the id of the known windows and
123 // is ordered from topmost to bottomost windows.
124 std::string
WindowOrderAsString(aura::Window
* parent
) const {
126 const aura::Window::Windows
& windows
= parent
->children();
127 for (aura::Window::Windows::const_reverse_iterator i
= windows
.rbegin();
128 i
!= windows
.rend(); ++i
) {
129 if (*i
== window_
|| *i
== window2_
|| *i
== window3_
) {
132 result
+= base::IntToString((*i
)->id());
139 WindowResizer
* CreateResizerForTest(
140 aura::Window
* window
,
141 const gfx::Point
& point_in_parent
,
142 int window_component
) {
143 WindowResizer
* resizer
= CreateWindowResizer(
147 aura::client::WINDOW_MOVE_SOURCE_MOUSE
).release();
148 workspace_resizer_
= WorkspaceWindowResizer::GetInstanceForTest();
151 WorkspaceWindowResizer
* CreateWorkspaceResizerForTest(
152 aura::Window
* window
,
153 const gfx::Point
& point_in_parent
,
154 int window_component
,
155 aura::client::WindowMoveSource source
,
156 const std::vector
<aura::Window
*>& attached_windows
) {
157 wm::WindowState
* window_state
= wm::GetWindowState(window
);
158 window_state
->CreateDragDetails(
159 window
, point_in_parent
, window_component
, source
);
160 return WorkspaceWindowResizer::Create(window_state
, attached_windows
);
163 PhantomWindowController
* snap_phantom_window_controller() const {
164 return workspace_resizer_
->snap_phantom_window_controller_
.get();
167 gfx::Point
CalculateDragPoint(const WindowResizer
& resizer
,
170 gfx::Point location
= resizer
.GetInitialLocation();
171 location
.set_x(location
.x() + delta_x
);
172 location
.set_y(location
.y() + delta_y
);
176 std::vector
<aura::Window
*> empty_windows() const {
177 return std::vector
<aura::Window
*>();
180 ShelfLayoutManager
* shelf_layout_manager() {
181 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
184 void InitTouchResizeWindow(const gfx::Rect
& bounds
, int window_component
) {
185 touch_resize_delegate_
.set_window_component(window_component
);
186 touch_resize_window_
.reset(
187 CreateTestWindowInShellWithDelegate(&touch_resize_delegate_
, 0,
191 TestWindowDelegate delegate_
;
192 TestWindowDelegate delegate2_
;
193 TestWindowDelegate delegate3_
;
194 TestWindowDelegate delegate4_
;
195 scoped_ptr
<aura::Window
> window_
;
196 scoped_ptr
<aura::Window
> window2_
;
197 scoped_ptr
<aura::Window
> window3_
;
198 scoped_ptr
<aura::Window
> window4_
;
200 TestWindowDelegate touch_resize_delegate_
;
201 scoped_ptr
<aura::Window
> touch_resize_window_
;
202 WorkspaceWindowResizer
* workspace_resizer_
;
205 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest
);
208 // Assertions around attached window resize dragging from the right with 2
210 TEST_F(WorkspaceWindowResizerTest
, AttachedResize_RIGHT_2
) {
211 window_
->SetBounds(gfx::Rect(0, 300, 400, 300));
212 window2_
->SetBounds(gfx::Rect(400, 200, 100, 200));
214 std::vector
<aura::Window
*> windows
;
215 windows
.push_back(window2_
.get());
216 scoped_ptr
<WorkspaceWindowResizer
> resizer(CreateWorkspaceResizerForTest(
217 window_
.get(), gfx::Point(), HTRIGHT
,
218 aura::client::WINDOW_MOVE_SOURCE_MOUSE
, windows
));
219 ASSERT_TRUE(resizer
.get());
220 // Move it 100 to the right, which should expand w1 and push w2.
221 resizer
->Drag(CalculateDragPoint(*resizer
, 100, 10), 0);
222 EXPECT_EQ("0,300 500x300", window_
->bounds().ToString());
223 EXPECT_EQ("500,200 100x200", window2_
->bounds().ToString());
225 // Push off the screen, w2 should be resized to its min.
226 delegate2_
.set_min_size(gfx::Size(20, 20));
227 resizer
->Drag(CalculateDragPoint(*resizer
, 800, 20), 0);
228 EXPECT_EQ("0,300 780x300", window_
->bounds().ToString());
229 EXPECT_EQ("780,200 20x200", window2_
->bounds().ToString());
231 // Move back to 100 and verify w2 gets its original size.
232 resizer
->Drag(CalculateDragPoint(*resizer
, 100, 10), 0);
233 EXPECT_EQ("0,300 500x300", window_
->bounds().ToString());
234 EXPECT_EQ("500,200 100x200", window2_
->bounds().ToString());
236 // Revert and make sure everything moves back.
237 resizer
->Drag(CalculateDragPoint(*resizer
, 800, 20), 0);
238 resizer
->RevertDrag();
239 EXPECT_EQ("0,300 400x300", window_
->bounds().ToString());
240 EXPECT_EQ("400,200 100x200", window2_
->bounds().ToString());
243 // Assertions around collapsing and expanding.
244 TEST_F(WorkspaceWindowResizerTest
, AttachedResize_RIGHT_Compress
) {
245 window_
->SetBounds(gfx::Rect( 0, 300, 400, 300));
246 window2_
->SetBounds(gfx::Rect(400, 200, 100, 200));
248 std::vector
<aura::Window
*> windows
;
249 windows
.push_back(window2_
.get());
250 scoped_ptr
<WorkspaceWindowResizer
> resizer(CreateWorkspaceResizerForTest(
251 window_
.get(), gfx::Point(), HTRIGHT
,
252 aura::client::WINDOW_MOVE_SOURCE_MOUSE
, windows
));
253 ASSERT_TRUE(resizer
.get());
254 // Move it 100 to the left, which should expand w2 and collapse w1.
255 resizer
->Drag(CalculateDragPoint(*resizer
, -100, 10), 0);
256 EXPECT_EQ("0,300 300x300", window_
->bounds().ToString());
257 EXPECT_EQ("300,200 200x200", window2_
->bounds().ToString());
259 // Collapse all the way to w1's min.
260 delegate_
.set_min_size(gfx::Size(20, 20));
261 resizer
->Drag(CalculateDragPoint(*resizer
, -800, 20), 0);
262 EXPECT_EQ("0,300 20x300", window_
->bounds().ToString());
263 EXPECT_EQ("20,200 480x200", window2_
->bounds().ToString());
265 // Move 100 to the left.
266 resizer
->Drag(CalculateDragPoint(*resizer
, 100, 10), 0);
267 EXPECT_EQ("0,300 500x300", window_
->bounds().ToString());
268 EXPECT_EQ("500,200 100x200", window2_
->bounds().ToString());
271 resizer
->Drag(CalculateDragPoint(*resizer
, -100, 20), 0);
272 EXPECT_EQ("0,300 300x300", window_
->bounds().ToString());
273 EXPECT_EQ("300,200 200x200", window2_
->bounds().ToString());
276 // Assertions around attached window resize dragging from the right with 3
278 TEST_F(WorkspaceWindowResizerTest
, AttachedResize_RIGHT_3
) {
279 window_
->SetBounds(gfx::Rect( 100, 300, 200, 300));
280 window2_
->SetBounds(gfx::Rect(300, 300, 150, 200));
281 window3_
->SetBounds(gfx::Rect(450, 300, 100, 200));
282 delegate2_
.set_min_size(gfx::Size(52, 50));
283 delegate3_
.set_min_size(gfx::Size(38, 50));
285 std::vector
<aura::Window
*> windows
;
286 windows
.push_back(window2_
.get());
287 windows
.push_back(window3_
.get());
288 scoped_ptr
<WorkspaceWindowResizer
> resizer(CreateWorkspaceResizerForTest(
289 window_
.get(), gfx::Point(), HTRIGHT
,
290 aura::client::WINDOW_MOVE_SOURCE_MOUSE
, windows
));
291 ASSERT_TRUE(resizer
.get());
292 // Move it 100 to the right, which should expand w1 and push w2 and w3.
293 resizer
->Drag(CalculateDragPoint(*resizer
, 100, -10), 0);
294 EXPECT_EQ("100,300 300x300", window_
->bounds().ToString());
295 EXPECT_EQ("400,300 150x200", window2_
->bounds().ToString());
296 EXPECT_EQ("550,300 100x200", window3_
->bounds().ToString());
298 // Move it 300, things should compress.
299 resizer
->Drag(CalculateDragPoint(*resizer
, 300, -10), 0);
300 EXPECT_EQ("100,300 500x300", window_
->bounds().ToString());
301 EXPECT_EQ("600,300 120x200", window2_
->bounds().ToString());
302 EXPECT_EQ("720,300 80x200", window3_
->bounds().ToString());
304 // Move it so much the last two end up at their min.
305 resizer
->Drag(CalculateDragPoint(*resizer
, 800, 50), 0);
306 EXPECT_EQ("100,300 610x300", window_
->bounds().ToString());
307 EXPECT_EQ("710,300 52x200", window2_
->bounds().ToString());
308 EXPECT_EQ("762,300 38x200", window3_
->bounds().ToString());
310 // Revert and make sure everything moves back.
311 resizer
->RevertDrag();
312 EXPECT_EQ("100,300 200x300", window_
->bounds().ToString());
313 EXPECT_EQ("300,300 150x200", window2_
->bounds().ToString());
314 EXPECT_EQ("450,300 100x200", window3_
->bounds().ToString());
317 // Assertions around attached window resizing (collapsing and expanding) with
319 TEST_F(WorkspaceWindowResizerTest
, AttachedResize_RIGHT_3_Compress
) {
320 window_
->SetBounds(gfx::Rect( 100, 300, 200, 300));
321 window2_
->SetBounds(gfx::Rect(300, 300, 200, 200));
322 window3_
->SetBounds(gfx::Rect(450, 300, 100, 200));
323 delegate2_
.set_min_size(gfx::Size(52, 50));
324 delegate3_
.set_min_size(gfx::Size(38, 50));
326 std::vector
<aura::Window
*> windows
;
327 windows
.push_back(window2_
.get());
328 windows
.push_back(window3_
.get());
329 scoped_ptr
<WorkspaceWindowResizer
> resizer(CreateWorkspaceResizerForTest(
330 window_
.get(), gfx::Point(), HTRIGHT
,
331 aura::client::WINDOW_MOVE_SOURCE_MOUSE
, windows
));
332 ASSERT_TRUE(resizer
.get());
333 // Move it -100 to the right, which should collapse w1 and expand w2 and w3.
334 resizer
->Drag(CalculateDragPoint(*resizer
, -100, -10), 0);
335 EXPECT_EQ("100,300 100x300", window_
->bounds().ToString());
336 EXPECT_EQ("200,300 266x200", window2_
->bounds().ToString());
337 EXPECT_EQ("466,300 134x200", window3_
->bounds().ToString());
339 // Move it 100 to the right.
340 resizer
->Drag(CalculateDragPoint(*resizer
, 100, -10), 0);
341 EXPECT_EQ("100,300 300x300", window_
->bounds().ToString());
342 EXPECT_EQ("400,300 200x200", window2_
->bounds().ToString());
343 EXPECT_EQ("600,300 100x200", window3_
->bounds().ToString());
345 // 100 to the left again.
346 resizer
->Drag(CalculateDragPoint(*resizer
, -100, -10), 0);
347 EXPECT_EQ("100,300 100x300", window_
->bounds().ToString());
348 EXPECT_EQ("200,300 266x200", window2_
->bounds().ToString());
349 EXPECT_EQ("466,300 134x200", window3_
->bounds().ToString());
352 // Assertions around collapsing and expanding from the bottom.
353 TEST_F(WorkspaceWindowResizerTest
, AttachedResize_BOTTOM_Compress
) {
354 window_
->SetBounds(gfx::Rect( 0, 100, 400, 300));
355 window2_
->SetBounds(gfx::Rect(400, 400, 100, 200));
357 std::vector
<aura::Window
*> windows
;
358 windows
.push_back(window2_
.get());
359 scoped_ptr
<WorkspaceWindowResizer
> resizer(CreateWorkspaceResizerForTest(
360 window_
.get(), gfx::Point(), HTBOTTOM
,
361 aura::client::WINDOW_MOVE_SOURCE_MOUSE
, windows
));
362 ASSERT_TRUE(resizer
.get());
363 // Move it up 100, which should expand w2 and collapse w1.
364 resizer
->Drag(CalculateDragPoint(*resizer
, 10, -100), 0);
365 EXPECT_EQ("0,100 400x200", window_
->bounds().ToString());
366 EXPECT_EQ("400,300 100x300", window2_
->bounds().ToString());
368 // Collapse all the way to w1's min.
369 delegate_
.set_min_size(gfx::Size(20, 20));
370 resizer
->Drag(CalculateDragPoint(*resizer
, 20, -800), 0);
371 EXPECT_EQ("0,100 400x20", window_
->bounds().ToString());
372 EXPECT_EQ("400,120 100x480", window2_
->bounds().ToString());
375 resizer
->Drag(CalculateDragPoint(*resizer
, 10, 100), 0);
376 EXPECT_EQ("0,100 400x400", window_
->bounds().ToString());
377 EXPECT_EQ("400,500 100x100", window2_
->bounds().ToString());
380 resizer
->Drag(CalculateDragPoint(*resizer
, 20, -100), 0);
381 EXPECT_EQ("0,100 400x200", window_
->bounds().ToString());
382 EXPECT_EQ("400,300 100x300", window2_
->bounds().ToString());
385 // Assertions around attached window resize dragging from the bottom with 2
387 TEST_F(WorkspaceWindowResizerTest
, AttachedResize_BOTTOM_2
) {
388 window_
->SetBounds(gfx::Rect( 0, 50, 400, 200));
389 window2_
->SetBounds(gfx::Rect(0, 250, 200, 100));
391 std::vector
<aura::Window
*> windows
;
392 windows
.push_back(window2_
.get());
393 scoped_ptr
<WorkspaceWindowResizer
> resizer(CreateWorkspaceResizerForTest(
394 window_
.get(), gfx::Point(), HTBOTTOM
,
395 aura::client::WINDOW_MOVE_SOURCE_MOUSE
, windows
));
396 ASSERT_TRUE(resizer
.get());
397 // Move it 100 to the bottom, which should expand w1 and push w2.
398 resizer
->Drag(CalculateDragPoint(*resizer
, 10, 100), 0);
399 EXPECT_EQ("0,50 400x300", window_
->bounds().ToString());
400 EXPECT_EQ("0,350 200x100", window2_
->bounds().ToString());
402 // Push off the screen, w2 should be resized to its min.
403 delegate2_
.set_min_size(gfx::Size(20, 20));
404 resizer
->Drag(CalculateDragPoint(*resizer
, 50, 820), 0);
405 EXPECT_EQ("0,50 400x530", window_
->bounds().ToString());
406 EXPECT_EQ("0,580 200x20", window2_
->bounds().ToString());
408 // Move back to 100 and verify w2 gets its original size.
409 resizer
->Drag(CalculateDragPoint(*resizer
, 10, 100), 0);
410 EXPECT_EQ("0,50 400x300", window_
->bounds().ToString());
411 EXPECT_EQ("0,350 200x100", window2_
->bounds().ToString());
413 // Revert and make sure everything moves back.
414 resizer
->Drag(CalculateDragPoint(*resizer
, 800, 20), 0);
415 resizer
->RevertDrag();
416 EXPECT_EQ("0,50 400x200", window_
->bounds().ToString());
417 EXPECT_EQ("0,250 200x100", window2_
->bounds().ToString());
421 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
422 #define MAYBE_AttachedResize_BOTTOM_3 DISABLED_AttachedResize_BOTTOM_3
424 #define MAYBE_AttachedResize_BOTTOM_3 AttachedResize_BOTTOM_3
427 // Assertions around attached window resize dragging from the bottom with 3
429 TEST_F(WorkspaceWindowResizerTest
, MAYBE_AttachedResize_BOTTOM_3
) {
430 UpdateDisplay("600x800");
431 aura::Window
* root
= Shell::GetPrimaryRootWindow();
432 Shell::GetInstance()->SetDisplayWorkAreaInsets(root
, gfx::Insets());
434 window_
->SetBounds(gfx::Rect( 300, 100, 300, 200));
435 window2_
->SetBounds(gfx::Rect(300, 300, 200, 150));
436 window3_
->SetBounds(gfx::Rect(300, 450, 200, 100));
437 delegate2_
.set_min_size(gfx::Size(50, 52));
438 delegate3_
.set_min_size(gfx::Size(50, 38));
440 std::vector
<aura::Window
*> windows
;
441 windows
.push_back(window2_
.get());
442 windows
.push_back(window3_
.get());
443 scoped_ptr
<WorkspaceWindowResizer
> resizer(CreateWorkspaceResizerForTest(
444 window_
.get(), gfx::Point(), HTBOTTOM
,
445 aura::client::WINDOW_MOVE_SOURCE_MOUSE
, windows
));
446 ASSERT_TRUE(resizer
.get());
447 // Move it 100 down, which should expand w1 and push w2 and w3.
448 resizer
->Drag(CalculateDragPoint(*resizer
, -10, 100), 0);
449 EXPECT_EQ("300,100 300x300", window_
->bounds().ToString());
450 EXPECT_EQ("300,400 200x150", window2_
->bounds().ToString());
451 EXPECT_EQ("300,550 200x100", window3_
->bounds().ToString());
453 // Move it 296 things should compress.
454 resizer
->Drag(CalculateDragPoint(*resizer
, -10, 296), 0);
455 EXPECT_EQ("300,100 300x496", window_
->bounds().ToString());
456 EXPECT_EQ("300,596 200x123", window2_
->bounds().ToString());
457 EXPECT_EQ("300,719 200x81", window3_
->bounds().ToString());
459 // Move it so much everything ends up at its min.
460 resizer
->Drag(CalculateDragPoint(*resizer
, 50, 798), 0);
461 EXPECT_EQ("300,100 300x610", window_
->bounds().ToString());
462 EXPECT_EQ("300,710 200x52", window2_
->bounds().ToString());
463 EXPECT_EQ("300,762 200x38", window3_
->bounds().ToString());
465 // Revert and make sure everything moves back.
466 resizer
->RevertDrag();
467 EXPECT_EQ("300,100 300x200", window_
->bounds().ToString());
468 EXPECT_EQ("300,300 200x150", window2_
->bounds().ToString());
469 EXPECT_EQ("300,450 200x100", window3_
->bounds().ToString());
472 // Assertions around attached window resizing (collapsing and expanding) with
474 TEST_F(WorkspaceWindowResizerTest
, AttachedResize_BOTTOM_3_Compress
) {
475 window_
->SetBounds(gfx::Rect( 0, 0, 200, 200));
476 window2_
->SetBounds(gfx::Rect(10, 200, 200, 200));
477 window3_
->SetBounds(gfx::Rect(20, 400, 100, 100));
478 delegate2_
.set_min_size(gfx::Size(52, 50));
479 delegate3_
.set_min_size(gfx::Size(38, 50));
481 std::vector
<aura::Window
*> windows
;
482 windows
.push_back(window2_
.get());
483 windows
.push_back(window3_
.get());
484 scoped_ptr
<WorkspaceWindowResizer
> resizer(CreateWorkspaceResizerForTest(
485 window_
.get(), gfx::Point(), HTBOTTOM
,
486 aura::client::WINDOW_MOVE_SOURCE_MOUSE
, windows
));
487 ASSERT_TRUE(resizer
.get());
488 // Move it 100 up, which should collapse w1 and expand w2 and w3.
489 resizer
->Drag(CalculateDragPoint(*resizer
, -10, -100), 0);
490 EXPECT_EQ("0,0 200x100", window_
->bounds().ToString());
491 EXPECT_EQ("10,100 200x266", window2_
->bounds().ToString());
492 EXPECT_EQ("20,366 100x134", window3_
->bounds().ToString());
495 resizer
->Drag(CalculateDragPoint(*resizer
, 10, 100), 0);
496 EXPECT_EQ("0,0 200x300", window_
->bounds().ToString());
497 EXPECT_EQ("10,300 200x200", window2_
->bounds().ToString());
498 EXPECT_EQ("20,500 100x100", window3_
->bounds().ToString());
501 resizer
->Drag(CalculateDragPoint(*resizer
, -10, -100), 0);
502 EXPECT_EQ("0,0 200x100", window_
->bounds().ToString());
503 EXPECT_EQ("10,100 200x266", window2_
->bounds().ToString());
504 EXPECT_EQ("20,366 100x134", window3_
->bounds().ToString());
507 // Tests that touch-dragging a window does not lock the mouse cursor
508 // and therefore shows the cursor on a mousemove.
509 TEST_F(WorkspaceWindowResizerTest
, MouseMoveWithTouchDrag
) {
510 window_
->SetBounds(gfx::Rect(0, 300, 400, 300));
511 window2_
->SetBounds(gfx::Rect(400, 200, 100, 200));
513 Shell
* shell
= Shell::GetInstance();
514 ui::test::EventGenerator
generator(window_
->GetRootWindow());
516 // The cursor should not be locked initially.
517 EXPECT_FALSE(shell
->cursor_manager()->IsCursorLocked());
519 std::vector
<aura::Window
*> windows
;
520 windows
.push_back(window2_
.get());
521 scoped_ptr
<WorkspaceWindowResizer
> resizer(CreateWorkspaceResizerForTest(
522 window_
.get(), gfx::Point(), HTRIGHT
,
523 aura::client::WINDOW_MOVE_SOURCE_TOUCH
, windows
));
524 ASSERT_TRUE(resizer
.get());
526 // Creating a WorkspaceWindowResizer should not lock the cursor.
527 EXPECT_FALSE(shell
->cursor_manager()->IsCursorLocked());
529 // The cursor should be hidden after touching the screen and
531 EXPECT_TRUE(shell
->cursor_manager()->IsCursorVisible());
532 generator
.PressTouch();
533 resizer
->Drag(CalculateDragPoint(*resizer
, 100, 10), 0);
534 EXPECT_FALSE(shell
->cursor_manager()->IsCursorVisible());
535 EXPECT_FALSE(shell
->cursor_manager()->IsCursorLocked());
537 // Moving the mouse should show the cursor.
538 generator
.MoveMouseBy(1, 1);
539 EXPECT_TRUE(shell
->cursor_manager()->IsCursorVisible());
540 EXPECT_FALSE(shell
->cursor_manager()->IsCursorLocked());
542 resizer
->RevertDrag();
545 // Assertions around dragging to the left/right edge of the screen.
546 TEST_F(WorkspaceWindowResizerTest
, Edge
) {
547 if (!SupportsHostWindowResize())
550 // Resize host window to force insets update.
551 UpdateDisplay("800x700");
552 // TODO(varkha): Insets are reset after every drag because of
553 // http://crbug.com/292238.
554 // Window is wide enough not to get docked right away.
555 window_
->SetBounds(gfx::Rect(20, 30, 400, 60));
556 window_
->SetProperty(aura::client::kCanMaximizeKey
, true);
557 wm::WindowState
* window_state
= wm::GetWindowState(window_
.get());
560 gfx::Rect
expected_bounds_in_parent(
561 wm::GetDefaultLeftSnappedWindowBoundsInParent(window_
.get()));
563 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
564 window_
.get(), gfx::Point(), HTCAPTION
));
565 ASSERT_TRUE(resizer
.get());
566 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 10), 0);
567 resizer
->CompleteDrag();
569 EXPECT_EQ(expected_bounds_in_parent
.ToString(),
570 window_
->bounds().ToString());
571 ASSERT_TRUE(window_state
->HasRestoreBounds());
572 EXPECT_EQ("20,30 400x60",
573 window_state
->GetRestoreBoundsInScreen().ToString());
575 // Try the same with the right side.
577 gfx::Rect
expected_bounds_in_parent(
578 wm::GetDefaultRightSnappedWindowBoundsInParent(window_
.get()));
580 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
581 window_
.get(), gfx::Point(), HTCAPTION
));
582 ASSERT_TRUE(resizer
.get());
583 resizer
->Drag(CalculateDragPoint(*resizer
, 800, 10), 0);
584 resizer
->CompleteDrag();
585 EXPECT_EQ(expected_bounds_in_parent
.ToString(),
586 window_
->bounds().ToString());
587 ASSERT_TRUE(window_state
->HasRestoreBounds());
588 EXPECT_EQ("20,30 400x60",
589 window_state
->GetRestoreBoundsInScreen().ToString());
592 // Test if the restore bounds is correct in multiple displays.
593 if (!SupportsMultipleDisplays())
596 // Restore the window to clear snapped state.
597 window_state
->Restore();
599 UpdateDisplay("800x600,500x600");
600 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
601 EXPECT_EQ(root_windows
[0], window_
->GetRootWindow());
602 // Window is wide enough not to get docked right away.
603 window_
->SetBoundsInScreen(gfx::Rect(800, 10, 400, 60),
604 ScreenUtil::GetSecondaryDisplay());
605 EXPECT_EQ(root_windows
[1], window_
->GetRootWindow());
607 EXPECT_EQ("800,10 400x60", window_
->GetBoundsInScreen().ToString());
609 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
610 window_
.get(), gfx::Point(), HTCAPTION
));
611 ASSERT_TRUE(resizer
.get());
612 resizer
->Drag(CalculateDragPoint(*resizer
, 499, 0), 0);
614 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_
.get()).bottom();
615 resizer
->CompleteDrag();
616 // With the resolution of 500x600 we will hit in this case the 50% screen
618 // TODO(varkha): Insets are updated because of http://crbug.com/292238
619 EXPECT_EQ("250,0 250x" + base::IntToString(bottom
),
620 window_
->bounds().ToString());
621 EXPECT_EQ("800,10 400x60",
622 window_state
->GetRestoreBoundsInScreen().ToString());
626 // Check that non resizable windows will not get resized.
627 TEST_F(WorkspaceWindowResizerTest
, NonResizableWindows
) {
628 window_
->SetBounds(gfx::Rect(20, 30, 50, 60));
629 window_
->SetProperty(aura::client::kCanResizeKey
, false);
631 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
632 window_
.get(), gfx::Point(), HTCAPTION
));
633 ASSERT_TRUE(resizer
.get());
634 resizer
->Drag(CalculateDragPoint(*resizer
, -20, 0), 0);
635 resizer
->CompleteDrag();
636 EXPECT_EQ("0,30 50x60", window_
->bounds().ToString());
639 TEST_F(WorkspaceWindowResizerTest
, CancelSnapPhantom
) {
640 if (!SupportsMultipleDisplays())
643 UpdateDisplay("800x600,800x600");
644 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
645 ASSERT_EQ(2U, root_windows
.size());
647 window_
->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
648 Shell::GetScreen()->GetPrimaryDisplay());
649 EXPECT_EQ(root_windows
[0], window_
->GetRootWindow());
650 EXPECT_FLOAT_EQ(1.0f
, window_
->layer()->opacity());
652 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
653 window_
.get(), gfx::Point(), HTCAPTION
));
654 ASSERT_TRUE(resizer
.get());
655 EXPECT_FALSE(snap_phantom_window_controller());
657 // The pointer is on the edge but not shared. The snap phantom window
658 // controller should be non-NULL.
659 resizer
->Drag(CalculateDragPoint(*resizer
, 799, 0), 0);
660 EXPECT_TRUE(snap_phantom_window_controller());
662 // Move the cursor across the edge. Now the snap phantom window controller
663 // should be canceled.
664 resizer
->Drag(CalculateDragPoint(*resizer
, 800, 0), 0);
665 EXPECT_FALSE(snap_phantom_window_controller());
669 // Verifies that dragging a snapped window unsnaps it.
670 TEST_F(WorkspaceWindowResizerTest
, DragSnapped
) {
671 wm::WindowState
* window_state
= ash::wm::GetWindowState(window_
.get());
673 const gfx::Rect
kInitialBounds(100, 100, 100, 100);
674 window_
->SetBounds(kInitialBounds
);
676 const wm::WMEvent
snap_event(wm::WM_EVENT_SNAP_LEFT
);
677 window_state
->OnWMEvent(&snap_event
);
678 EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED
, window_state
->GetStateType());
679 gfx::Rect snapped_bounds
= window_
->bounds();
680 EXPECT_NE(snapped_bounds
.ToString(), kInitialBounds
.ToString());
681 EXPECT_EQ(window_state
->GetRestoreBoundsInParent().ToString(),
682 kInitialBounds
.ToString());
684 // Dragging a side snapped window should unsnap it.
685 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
686 window_
.get(), gfx::Point(), HTCAPTION
));
687 resizer
->Drag(CalculateDragPoint(*resizer
, 10, 0), 0);
688 resizer
->CompleteDrag();
689 EXPECT_EQ(wm::WINDOW_STATE_TYPE_NORMAL
, window_state
->GetStateType());
690 EXPECT_EQ("10,0 100x100", window_
->bounds().ToString());
691 EXPECT_FALSE(window_state
->HasRestoreBounds());
694 // Verifies the behavior of resizing a side snapped window.
695 TEST_F(WorkspaceWindowResizerTest
, ResizeSnapped
) {
696 wm::WindowState
* window_state
= ash::wm::GetWindowState(window_
.get());
698 const gfx::Rect
kInitialBounds(100, 100, 100, 100);
699 window_
->SetBounds(kInitialBounds
);
702 const wm::WMEvent
snap_event(wm::WM_EVENT_SNAP_LEFT
);
703 window_state
->OnWMEvent(&snap_event
);
704 EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED
, window_state
->GetStateType());
705 gfx::Rect snapped_bounds
= window_
->bounds();
706 EXPECT_NE(snapped_bounds
.ToString(), kInitialBounds
.ToString());
707 EXPECT_EQ(window_state
->GetRestoreBoundsInParent().ToString(),
708 kInitialBounds
.ToString());
711 // 1) Resizing a side snapped window to make it wider should not unsnap the
713 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
714 window_
.get(), gfx::Point(), HTRIGHT
));
715 resizer
->Drag(CalculateDragPoint(*resizer
, 10, 0), 0);
716 resizer
->CompleteDrag();
717 EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED
, window_state
->GetStateType());
718 snapped_bounds
.Inset(0, 0, -10, 0);
719 EXPECT_EQ(snapped_bounds
.ToString(), window_
->bounds().ToString());
720 EXPECT_EQ(window_state
->GetRestoreBoundsInParent().ToString(),
721 kInitialBounds
.ToString());
725 // 2) Resizing a side snapped window vertically and then undoing the change
726 // should not unsnap.
727 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
728 window_
.get(), gfx::Point(), HTBOTTOM
));
729 resizer
->Drag(CalculateDragPoint(*resizer
, 0, -30), 0);
730 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 0), 0);
731 resizer
->CompleteDrag();
732 EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED
, window_state
->GetStateType());
733 EXPECT_EQ(snapped_bounds
.ToString(), window_
->bounds().ToString());
734 EXPECT_EQ(window_state
->GetRestoreBoundsInParent().ToString(),
735 kInitialBounds
.ToString());
739 // 3) Resizing a side snapped window vertically and then not undoing the
740 // change should unsnap.
741 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
742 window_
.get(), gfx::Point(), HTBOTTOM
));
743 resizer
->Drag(CalculateDragPoint(*resizer
, 0, -10), 0);
744 resizer
->CompleteDrag();
745 EXPECT_EQ(wm::WINDOW_STATE_TYPE_NORMAL
, window_state
->GetStateType());
746 gfx::Rect
expected_bounds(snapped_bounds
);
747 expected_bounds
.Inset(0, 0, 0, 10);
748 EXPECT_EQ(expected_bounds
.ToString(), window_
->bounds().ToString());
749 EXPECT_FALSE(window_state
->HasRestoreBounds());
753 // Verifies windows are correctly restacked when reordering multiple windows.
754 TEST_F(WorkspaceWindowResizerTest
, RestackAttached
) {
755 window_
->SetBounds(gfx::Rect( 0, 0, 200, 300));
756 window2_
->SetBounds(gfx::Rect(200, 0, 100, 200));
757 window3_
->SetBounds(gfx::Rect(300, 0, 100, 100));
760 std::vector
<aura::Window
*> windows
;
761 windows
.push_back(window2_
.get());
762 scoped_ptr
<WorkspaceWindowResizer
> resizer(CreateWorkspaceResizerForTest(
763 window_
.get(), gfx::Point(), HTRIGHT
,
764 aura::client::WINDOW_MOVE_SOURCE_MOUSE
, windows
));
765 ASSERT_TRUE(resizer
.get());
766 // Move it 100 to the right, which should expand w1 and push w2 and w3.
767 resizer
->Drag(CalculateDragPoint(*resizer
, 100, -10), 0);
769 // 2 should be topmost since it's initially the highest in the stack.
770 EXPECT_EQ("2 1 3", WindowOrderAsString(window_
->parent()));
774 std::vector
<aura::Window
*> windows
;
775 windows
.push_back(window3_
.get());
776 scoped_ptr
<WorkspaceWindowResizer
> resizer(CreateWorkspaceResizerForTest(
777 window2_
.get(), gfx::Point(), HTRIGHT
,
778 aura::client::WINDOW_MOVE_SOURCE_MOUSE
, windows
));
779 ASSERT_TRUE(resizer
.get());
780 // Move it 100 to the right, which should expand w1 and push w2 and w3.
781 resizer
->Drag(CalculateDragPoint(*resizer
, 100, -10), 0);
783 // 2 should be topmost since it's initially the highest in the stack.
784 EXPECT_EQ("2 3 1", WindowOrderAsString(window_
->parent()));
788 // Makes sure we don't allow dragging below the work area.
789 TEST_F(WorkspaceWindowResizerTest
, DontDragOffBottom
) {
790 Shell::GetInstance()->SetDisplayWorkAreaInsets(
791 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0));
793 ASSERT_EQ(1, Shell::GetScreen()->GetNumDisplays());
795 window_
->SetBounds(gfx::Rect(100, 200, 300, 400));
796 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
797 window_
.get(), gfx::Point(), HTCAPTION
));
798 ASSERT_TRUE(resizer
.get());
799 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 600), 0);
801 kRootHeight
- WorkspaceWindowResizer::kMinOnscreenHeight
- 10;
802 EXPECT_EQ("100," + base::IntToString(expected_y
) + " 300x400",
803 window_
->bounds().ToString());
806 // Makes sure we don't allow dragging on the work area with multidisplay.
807 TEST_F(WorkspaceWindowResizerTest
, DontDragOffBottomWithMultiDisplay
) {
808 if (!SupportsMultipleDisplays())
811 UpdateDisplay("800x600,800x600");
812 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
814 Shell::GetInstance()->SetDisplayWorkAreaInsets(
815 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0));
817 // Positions the secondary display at the bottom the primary display.
818 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays(
819 ash::DisplayLayout(ash::DisplayLayout::BOTTOM
, 0));
822 window_
->SetBounds(gfx::Rect(100, 200, 300, 20));
823 DCHECK_LT(window_
->bounds().height(),
824 WorkspaceWindowResizer::kMinOnscreenHeight
);
825 // Drag down avoiding dragging along the edge as that would side-snap.
826 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
827 window_
.get(), gfx::Point(10, 0), HTCAPTION
));
828 ASSERT_TRUE(resizer
.get());
829 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 400), 0);
830 int expected_y
= kRootHeight
- window_
->bounds().height() - 10;
831 // When the mouse cursor is in the primary display, the window cannot move
832 // on non-work area but can get all the way towards the bottom,
833 // restricted only by the window height.
834 EXPECT_EQ("100," + base::IntToString(expected_y
) + " 300x20",
835 window_
->bounds().ToString());
836 // Revert the drag in order to not remember the restore bounds.
837 resizer
->RevertDrag();
840 Shell::GetInstance()->SetDisplayWorkAreaInsets(
841 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0));
843 window_
->SetBounds(gfx::Rect(100, 200, 300, 400));
844 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
845 window_
.get(), gfx::Point(10, 0), HTCAPTION
));
846 ASSERT_TRUE(resizer
.get());
847 // Drag down avoiding dragging along the edge as that would side-snap.
848 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 400), 0);
850 kRootHeight
- WorkspaceWindowResizer::kMinOnscreenHeight
- 10;
851 // When the mouse cursor is in the primary display, the window cannot move
852 // on non-work area with kMinOnscreenHeight margin.
853 EXPECT_EQ("100," + base::IntToString(expected_y
) + " 300x400",
854 window_
->bounds().ToString());
855 resizer
->CompleteDrag();
859 window_
->SetBounds(gfx::Rect(100, 200, 300, 400));
860 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
861 window_
.get(), window_
->bounds().origin(), HTCAPTION
));
862 ASSERT_TRUE(resizer
.get());
863 // Drag down avoiding getting stuck against the shelf on the bottom screen.
864 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 500), 0);
865 // The window can move to the secondary display beyond non-work area of
866 // the primary display.
867 EXPECT_EQ("100,700 300x400", window_
->bounds().ToString());
868 resizer
->CompleteDrag();
872 // Makes sure we don't allow dragging off the top of the work area.
873 TEST_F(WorkspaceWindowResizerTest
, DontDragOffTop
) {
874 Shell::GetInstance()->SetDisplayWorkAreaInsets(
875 Shell::GetPrimaryRootWindow(), gfx::Insets(10, 0, 0, 0));
877 window_
->SetBounds(gfx::Rect(100, 200, 300, 400));
878 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
879 window_
.get(), gfx::Point(), HTCAPTION
));
880 ASSERT_TRUE(resizer
.get());
881 resizer
->Drag(CalculateDragPoint(*resizer
, 0, -600), 0);
882 EXPECT_EQ("100,10 300x400", window_
->bounds().ToString());
885 TEST_F(WorkspaceWindowResizerTest
, ResizeBottomOutsideWorkArea
) {
886 Shell::GetInstance()->SetDisplayWorkAreaInsets(
887 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
889 window_
->SetBounds(gfx::Rect(100, 200, 300, 380));
890 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
891 window_
.get(), gfx::Point(), HTTOP
));
892 ASSERT_TRUE(resizer
.get());
893 resizer
->Drag(CalculateDragPoint(*resizer
, 8, 0), 0);
894 EXPECT_EQ("100,200 300x380", window_
->bounds().ToString());
897 TEST_F(WorkspaceWindowResizerTest
, ResizeWindowOutsideLeftWorkArea
) {
898 Shell::GetInstance()->SetDisplayWorkAreaInsets(
899 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
900 int left
= ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_
.get()).x();
901 int pixels_to_left_border
= 50;
902 int window_width
= 300;
903 int window_x
= left
- window_width
+ pixels_to_left_border
;
904 window_
->SetBounds(gfx::Rect(window_x
, 100, window_width
, 380));
905 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
906 window_
.get(), gfx::Point(pixels_to_left_border
, 0), HTRIGHT
));
907 ASSERT_TRUE(resizer
.get());
908 resizer
->Drag(CalculateDragPoint(*resizer
, -window_width
, 0), 0);
909 EXPECT_EQ(base::IntToString(window_x
) + ",100 " +
910 base::IntToString(kMinimumOnScreenArea
- window_x
) +
911 "x380", window_
->bounds().ToString());
914 TEST_F(WorkspaceWindowResizerTest
, ResizeWindowOutsideRightWorkArea
) {
915 Shell::GetInstance()->SetDisplayWorkAreaInsets(
916 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
917 int right
= ScreenUtil::GetDisplayWorkAreaBoundsInParent(
918 window_
.get()).right();
919 int pixels_to_right_border
= 50;
920 int window_width
= 300;
921 int window_x
= right
- pixels_to_right_border
;
922 window_
->SetBounds(gfx::Rect(window_x
, 100, window_width
, 380));
923 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
924 window_
.get(), gfx::Point(window_x
, 0), HTLEFT
));
925 ASSERT_TRUE(resizer
.get());
926 resizer
->Drag(CalculateDragPoint(*resizer
, window_width
, 0), 0);
927 EXPECT_EQ(base::IntToString(right
- kMinimumOnScreenArea
) +
929 base::IntToString(window_width
- pixels_to_right_border
+
930 kMinimumOnScreenArea
) +
931 "x380", window_
->bounds().ToString());
934 TEST_F(WorkspaceWindowResizerTest
, ResizeWindowOutsideBottomWorkArea
) {
935 Shell::GetInstance()->SetDisplayWorkAreaInsets(
936 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
937 int bottom
= ScreenUtil::GetDisplayWorkAreaBoundsInParent(
938 window_
.get()).bottom();
939 int delta_to_bottom
= 50;
941 window_
->SetBounds(gfx::Rect(100, bottom
- delta_to_bottom
, 300, height
));
942 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
943 window_
.get(), gfx::Point(0, bottom
- delta_to_bottom
), HTTOP
));
944 ASSERT_TRUE(resizer
.get());
945 resizer
->Drag(CalculateDragPoint(*resizer
, 0, bottom
), 0);
947 base::IntToString(bottom
- kMinimumOnScreenArea
) +
949 base::IntToString(height
- (delta_to_bottom
-
950 kMinimumOnScreenArea
)),
951 window_
->bounds().ToString());
954 // Verifies that 'outside' check of the resizer take into account the extended
955 // desktop in case of repositions.
956 TEST_F(WorkspaceWindowResizerTest
, DragWindowOutsideRightToSecondaryDisplay
) {
957 // Only primary display. Changes the window position to fit within the
959 Shell::GetInstance()->SetDisplayWorkAreaInsets(
960 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
961 int right
= ScreenUtil::GetDisplayWorkAreaBoundsInParent(
962 window_
.get()).right();
963 int pixels_to_right_border
= 50;
964 int window_width
= 300;
965 int window_x
= right
- pixels_to_right_border
;
966 window_
->SetBounds(gfx::Rect(window_x
, 100, window_width
, 380));
967 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
968 window_
.get(), gfx::Point(window_x
, 0), HTCAPTION
));
969 ASSERT_TRUE(resizer
.get());
970 resizer
->Drag(CalculateDragPoint(*resizer
, window_width
, 0), 0);
971 EXPECT_EQ(base::IntToString(right
- kMinimumOnScreenArea
) +
973 base::IntToString(window_width
) +
974 "x380", window_
->bounds().ToString());
976 if (!SupportsMultipleDisplays())
979 // With secondary display. Operation itself is same but doesn't change
980 // the position because the window is still within the secondary display.
981 UpdateDisplay("1000x600,600x400");
982 Shell::GetInstance()->SetDisplayWorkAreaInsets(
983 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
984 window_
->SetBounds(gfx::Rect(window_x
, 100, window_width
, 380));
985 resizer
->Drag(CalculateDragPoint(*resizer
, window_width
, 0), 0);
986 EXPECT_EQ(base::IntToString(window_x
+ window_width
) +
988 base::IntToString(window_width
) +
989 "x380", window_
->bounds().ToString());
992 // Verifies snapping to edges works.
993 TEST_F(WorkspaceWindowResizerTest
, SnapToEdge
) {
994 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()->
995 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
996 window_
->SetBounds(gfx::Rect(96, 112, 320, 160));
997 // Click 50px to the right so that the mouse pointer does not leave the
998 // workspace ensuring sticky behavior.
999 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1001 window_
->bounds().origin() + gfx::Vector2d(50, 0),
1003 ASSERT_TRUE(resizer
.get());
1004 // Move to an x-coordinate of 15, which should not snap.
1005 resizer
->Drag(CalculateDragPoint(*resizer
, 15 - 96, 0), 0);
1006 // An x-coordinate of 7 should snap.
1007 resizer
->Drag(CalculateDragPoint(*resizer
, 7 - 96, 0), 0);
1008 EXPECT_EQ("0,112 320x160", window_
->bounds().ToString());
1009 // Move to -15, should still snap to 0.
1010 resizer
->Drag(CalculateDragPoint(*resizer
, -15 - 96, 0), 0);
1011 EXPECT_EQ("0,112 320x160", window_
->bounds().ToString());
1012 // At -32 should move past snap points.
1013 resizer
->Drag(CalculateDragPoint(*resizer
, -32 - 96, 0), 0);
1014 EXPECT_EQ("-32,112 320x160", window_
->bounds().ToString());
1015 resizer
->Drag(CalculateDragPoint(*resizer
, -33 - 96, 0), 0);
1016 EXPECT_EQ("-33,112 320x160", window_
->bounds().ToString());
1018 // Right side should similarly snap.
1019 resizer
->Drag(CalculateDragPoint(*resizer
, 800 - 320 - 96 - 15, 0), 0);
1020 EXPECT_EQ("465,112 320x160", window_
->bounds().ToString());
1021 resizer
->Drag(CalculateDragPoint(*resizer
, 800 - 320 - 96 - 7, 0), 0);
1022 EXPECT_EQ("480,112 320x160", window_
->bounds().ToString());
1023 resizer
->Drag(CalculateDragPoint(*resizer
, 800 - 320 - 96 + 15, 0), 0);
1024 EXPECT_EQ("480,112 320x160", window_
->bounds().ToString());
1025 resizer
->Drag(CalculateDragPoint(*resizer
, 800 - 320 - 96 + 32, 0), 0);
1026 EXPECT_EQ("512,112 320x160", window_
->bounds().ToString());
1027 resizer
->Drag(CalculateDragPoint(*resizer
, 800 - 320 - 96 + 33, 0), 0);
1028 EXPECT_EQ("513,112 320x160", window_
->bounds().ToString());
1030 // And the bottom should snap too.
1031 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 600 - 160 - 112 - 3 - 7), 0);
1032 EXPECT_EQ("96,437 320x160", window_
->bounds().ToString());
1033 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 600 - 160 - 112 - 3 + 15), 0);
1034 EXPECT_EQ("96,437 320x160", window_
->bounds().ToString());
1035 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 600 - 160 - 112 - 2 + 32), 0);
1036 EXPECT_EQ("96,470 320x160", window_
->bounds().ToString());
1037 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 600 - 160 - 112 - 2 + 33), 0);
1038 EXPECT_EQ("96,471 320x160", window_
->bounds().ToString());
1040 // And the top should snap too.
1041 resizer
->Drag(CalculateDragPoint(*resizer
, 0, -112 + 20), 0);
1042 EXPECT_EQ("96,20 320x160", window_
->bounds().ToString());
1043 resizer
->Drag(CalculateDragPoint(*resizer
, 0, -112 + 7), 0);
1044 EXPECT_EQ("96,0 320x160", window_
->bounds().ToString());
1046 // And bottom/left should snap too.
1048 CalculateDragPoint(*resizer
, 7 - 96, 600 - 160 - 112 - 3 - 7), 0);
1049 EXPECT_EQ("0,437 320x160", window_
->bounds().ToString());
1051 CalculateDragPoint(*resizer
, -15 - 96, 600 - 160 - 112 - 3 + 15), 0);
1052 EXPECT_EQ("0,437 320x160", window_
->bounds().ToString());
1053 // should move past snap points.
1055 CalculateDragPoint(*resizer
, -32 - 96, 600 - 160 - 112 - 2 + 32), 0);
1056 EXPECT_EQ("-32,470 320x160", window_
->bounds().ToString());
1058 CalculateDragPoint(*resizer
, -33 - 96, 600 - 160 - 112 - 2 + 33), 0);
1059 EXPECT_EQ("-33,471 320x160", window_
->bounds().ToString());
1061 // No need to test dragging < 0 as we force that to 0.
1064 // Verifies a resize snap when dragging TOPLEFT.
1065 TEST_F(WorkspaceWindowResizerTest
, SnapToWorkArea_TOPLEFT
) {
1066 window_
->SetBounds(gfx::Rect(100, 200, 20, 30));
1067 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1068 window_
.get(), gfx::Point(), HTTOPLEFT
));
1069 ASSERT_TRUE(resizer
.get());
1070 resizer
->Drag(CalculateDragPoint(*resizer
, -98, -199), 0);
1071 EXPECT_EQ("0,0 120x230", window_
->bounds().ToString());
1074 // Verifies a resize snap when dragging TOPRIGHT.
1075 TEST_F(WorkspaceWindowResizerTest
, SnapToWorkArea_TOPRIGHT
) {
1076 window_
->SetBounds(gfx::Rect(100, 200, 20, 30));
1077 gfx::Rect
work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
1079 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1080 window_
.get(), gfx::Point(), HTTOPRIGHT
));
1081 ASSERT_TRUE(resizer
.get());
1083 CalculateDragPoint(*resizer
, work_area
.right() - 120 - 1, -199), 0);
1084 EXPECT_EQ(100, window_
->bounds().x());
1085 EXPECT_EQ(work_area
.y(), window_
->bounds().y());
1086 EXPECT_EQ(work_area
.right() - 100, window_
->bounds().width());
1087 EXPECT_EQ(230, window_
->bounds().height());
1090 // Verifies a resize snap when dragging BOTTOMRIGHT.
1091 TEST_F(WorkspaceWindowResizerTest
, SnapToWorkArea_BOTTOMRIGHT
) {
1092 window_
->SetBounds(gfx::Rect(100, 200, 20, 30));
1093 gfx::Rect
work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
1095 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1096 window_
.get(), gfx::Point(), HTBOTTOMRIGHT
));
1097 ASSERT_TRUE(resizer
.get());
1099 CalculateDragPoint(*resizer
, work_area
.right() - 120 - 1,
1100 work_area
.bottom() - 220 - 2), 0);
1101 EXPECT_EQ(100, window_
->bounds().x());
1102 EXPECT_EQ(200, window_
->bounds().y());
1103 EXPECT_EQ(work_area
.right() - 100, window_
->bounds().width());
1104 EXPECT_EQ(work_area
.bottom() - 200, window_
->bounds().height());
1107 // Verifies a resize snap when dragging BOTTOMLEFT.
1108 TEST_F(WorkspaceWindowResizerTest
, SnapToWorkArea_BOTTOMLEFT
) {
1109 window_
->SetBounds(gfx::Rect(100, 200, 20, 30));
1110 gfx::Rect
work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
1112 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1113 window_
.get(), gfx::Point(), HTBOTTOMLEFT
));
1114 ASSERT_TRUE(resizer
.get());
1116 CalculateDragPoint(*resizer
, -98, work_area
.bottom() - 220 - 2), 0);
1117 EXPECT_EQ(0, window_
->bounds().x());
1118 EXPECT_EQ(200, window_
->bounds().y());
1119 EXPECT_EQ(120, window_
->bounds().width());
1120 EXPECT_EQ(work_area
.bottom() - 200, window_
->bounds().height());
1123 // Verifies window sticks to both window and work area.
1124 TEST_F(WorkspaceWindowResizerTest
, StickToBothEdgeAndWindow
) {
1125 window_
->SetBounds(gfx::Rect(10, 10, 20, 50));
1127 window2_
->SetBounds(gfx::Rect(150, 160, 25, 1000));
1130 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1131 window_
.get(), gfx::Point(10, 10), HTCAPTION
));
1132 ASSERT_TRUE(resizer
.get());
1134 // Move |window| one pixel to the left of |window2|. Should snap to right.
1135 resizer
->Drag(CalculateDragPoint(*resizer
, 119, 145), 0);
1136 gfx::Rect
expected(130, 160, 20, 50);
1137 EXPECT_EQ(expected
.ToString(), window_
->bounds().ToString());
1139 gfx::Rect
work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
1142 // The initial y position of |window_|.
1144 // The drag position where the window is exactly attached to the bottom.
1145 int attach_y
= work_area
.bottom() - window_
->bounds().height() - initial_y
;
1147 // Dragging 10px above should not attach to the bottom.
1148 resizer
->Drag(CalculateDragPoint(*resizer
, 119, attach_y
- 10), 0);
1149 expected
.set_y(attach_y
+ initial_y
- 10);
1150 EXPECT_EQ(expected
.ToString(), window_
->bounds().ToString());
1152 // Stick to the work area.
1153 resizer
->Drag(CalculateDragPoint(*resizer
, 119, attach_y
- 1), 0);
1154 expected
.set_y(attach_y
+ initial_y
);
1155 EXPECT_EQ(expected
.ToString(), window_
->bounds().ToString());
1157 resizer
->Drag(CalculateDragPoint(*resizer
, 119, attach_y
), 0);
1158 expected
.set_y(attach_y
+ initial_y
);
1159 EXPECT_EQ(expected
.ToString(), window_
->bounds().ToString());
1161 resizer
->Drag(CalculateDragPoint(*resizer
, 119, attach_y
+ 1), 0);
1162 expected
.set_y(attach_y
+ initial_y
);
1163 EXPECT_EQ(expected
.ToString(), window_
->bounds().ToString());
1165 // Moving down further should move the window.
1166 resizer
->Drag(CalculateDragPoint(*resizer
, 119, attach_y
+ 18), 0);
1167 expected
.set_y(attach_y
+ initial_y
+ 18);
1168 EXPECT_EQ(expected
.ToString(), window_
->bounds().ToString());
1171 TEST_F(WorkspaceWindowResizerTest
, CtrlDragResizeToExactPosition
) {
1172 window_
->SetBounds(gfx::Rect(96, 112, 320, 160));
1173 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1174 window_
.get(), gfx::Point(), HTBOTTOMRIGHT
));
1175 ASSERT_TRUE(resizer
.get());
1176 // Resize the right bottom to add 10 in width, 12 in height.
1177 resizer
->Drag(CalculateDragPoint(*resizer
, 10, 12), ui::EF_CONTROL_DOWN
);
1178 // Both bottom and right sides to resize to exact size requested.
1179 EXPECT_EQ("96,112 330x172", window_
->bounds().ToString());
1182 // Verifies that a dragged, non-snapped window will clear restore bounds.
1183 TEST_F(WorkspaceWindowResizerTest
, RestoreClearedOnResize
) {
1184 window_
->SetBounds(gfx::Rect(10, 10, 100, 100));
1185 wm::WindowState
* window_state
= wm::GetWindowState(window_
.get());
1186 window_state
->SetRestoreBoundsInScreen(gfx::Rect(50, 50, 50, 50));
1187 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1188 window_
.get(), gfx::Point(), HTBOTTOMRIGHT
));
1189 ASSERT_TRUE(resizer
.get());
1190 // Drag the window to new position by adding (20, 30) to original point,
1191 // the original restore bound should be cleared.
1192 resizer
->Drag(CalculateDragPoint(*resizer
, 20, 30), 0);
1193 resizer
->CompleteDrag();
1194 EXPECT_EQ("10,10 120x130", window_
->bounds().ToString());
1195 EXPECT_FALSE(window_state
->HasRestoreBounds());
1198 // Verifies that a dragged window will restore to its pre-maximized size.
1199 TEST_F(WorkspaceWindowResizerTest
, RestoreToPreMaximizeCoordinates
) {
1200 window_
->SetBounds(gfx::Rect(0, 0, 1000, 1000));
1201 wm::WindowState
* window_state
= wm::GetWindowState(window_
.get());
1202 window_state
->SetRestoreBoundsInScreen(gfx::Rect(96, 112, 320, 160));
1203 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1204 window_
.get(), gfx::Point(), HTCAPTION
));
1205 ASSERT_TRUE(resizer
.get());
1206 // Drag the window to new position by adding (10, 10) to original point,
1207 // the window should get restored.
1208 resizer
->Drag(CalculateDragPoint(*resizer
, 10, 10), 0);
1209 resizer
->CompleteDrag();
1210 EXPECT_EQ("10,10 320x160", window_
->bounds().ToString());
1211 // The restore rectangle should get cleared as well.
1212 EXPECT_FALSE(window_state
->HasRestoreBounds());
1215 // Verifies that a dragged window will restore to its pre-maximized size.
1216 TEST_F(WorkspaceWindowResizerTest
, RevertResizeOperation
) {
1217 const gfx::Rect
initial_bounds(0, 0, 200, 400);
1218 window_
->SetBounds(initial_bounds
);
1220 wm::WindowState
* window_state
= wm::GetWindowState(window_
.get());
1221 window_state
->SetRestoreBoundsInScreen(gfx::Rect(96, 112, 320, 160));
1222 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1223 window_
.get(), gfx::Point(), HTCAPTION
));
1224 ASSERT_TRUE(resizer
.get());
1225 // Drag the window to new poistion by adding (180, 16) to original point,
1226 // the window should get restored.
1227 resizer
->Drag(CalculateDragPoint(*resizer
, 180, 16), 0);
1228 resizer
->RevertDrag();
1229 EXPECT_EQ(initial_bounds
.ToString(), window_
->bounds().ToString());
1230 EXPECT_EQ("96,112 320x160",
1231 window_state
->GetRestoreBoundsInScreen().ToString());
1234 // Check that only usable sizes get returned by the resizer.
1235 TEST_F(WorkspaceWindowResizerTest
, MagneticallyAttach
) {
1236 window_
->SetBounds(gfx::Rect(10, 10, 20, 30));
1237 window2_
->SetBounds(gfx::Rect(150, 160, 25, 20));
1240 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1241 window_
.get(), gfx::Point(), HTCAPTION
));
1242 ASSERT_TRUE(resizer
.get());
1243 // Move |window| one pixel to the left of |window2|. Should snap to right and
1245 resizer
->Drag(CalculateDragPoint(*resizer
, 119, 145), 0);
1246 EXPECT_EQ("130,160 20x30", window_
->bounds().ToString());
1248 // Move |window| one pixel to the right of |window2|. Should snap to left and
1250 resizer
->Drag(CalculateDragPoint(*resizer
, 164, 145), 0);
1251 EXPECT_EQ("175,160 20x30", window_
->bounds().ToString());
1253 // Move |window| one pixel above |window2|. Should snap to top and left.
1254 resizer
->Drag(CalculateDragPoint(*resizer
, 142, 119), 0);
1255 EXPECT_EQ("150,130 20x30", window_
->bounds().ToString());
1257 // Move |window| one pixel above the bottom of |window2|. Should snap to
1259 resizer
->Drag(CalculateDragPoint(*resizer
, 142, 169), 0);
1260 EXPECT_EQ("150,180 20x30", window_
->bounds().ToString());
1263 // The following variants verify magnetic snapping during resize when dragging a
1265 TEST_F(WorkspaceWindowResizerTest
, MagneticallyResize_TOP
) {
1266 window_
->SetBounds(gfx::Rect(100, 200, 20, 30));
1267 window2_
->SetBounds(gfx::Rect(99, 179, 10, 20));
1270 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1271 window_
.get(), gfx::Point(), HTTOP
));
1272 ASSERT_TRUE(resizer
.get());
1273 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 0), 0);
1274 EXPECT_EQ("100,199 20x31", window_
->bounds().ToString());
1277 TEST_F(WorkspaceWindowResizerTest
, MagneticallyResize_TOPLEFT
) {
1278 window_
->SetBounds(gfx::Rect(100, 200, 20, 30));
1279 window2_
->SetBounds(gfx::Rect(99, 179, 10, 20));
1283 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1284 window_
.get(), gfx::Point(), HTTOPLEFT
));
1285 ASSERT_TRUE(resizer
.get());
1286 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 0), 0);
1287 EXPECT_EQ("99,199 21x31", window_
->bounds().ToString());
1288 resizer
->RevertDrag();
1292 window2_
->SetBounds(gfx::Rect(88, 201, 10, 20));
1293 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1294 window_
.get(), gfx::Point(), HTTOPLEFT
));
1295 ASSERT_TRUE(resizer
.get());
1296 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 0), 0);
1297 EXPECT_EQ("98,201 22x29", window_
->bounds().ToString());
1298 resizer
->RevertDrag();
1302 TEST_F(WorkspaceWindowResizerTest
, MagneticallyResize_TOPRIGHT
) {
1303 window_
->SetBounds(gfx::Rect(100, 200, 20, 30));
1307 window2_
->SetBounds(gfx::Rect(111, 179, 10, 20));
1308 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1309 window_
.get(), gfx::Point(), HTTOPRIGHT
));
1310 ASSERT_TRUE(resizer
.get());
1311 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 0), 0);
1312 EXPECT_EQ("100,199 21x31", window_
->bounds().ToString());
1313 resizer
->RevertDrag();
1317 window2_
->SetBounds(gfx::Rect(121, 199, 10, 20));
1318 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1319 window_
.get(), gfx::Point(), HTTOPRIGHT
));
1320 ASSERT_TRUE(resizer
.get());
1321 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 0), 0);
1322 EXPECT_EQ("100,199 21x31", window_
->bounds().ToString());
1323 resizer
->RevertDrag();
1327 TEST_F(WorkspaceWindowResizerTest
, MagneticallyResize_RIGHT
) {
1328 window_
->SetBounds(gfx::Rect(100, 200, 20, 30));
1329 window2_
->SetBounds(gfx::Rect(121, 199, 10, 20));
1332 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1333 window_
.get(), gfx::Point(), HTRIGHT
));
1334 ASSERT_TRUE(resizer
.get());
1335 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 0), 0);
1336 EXPECT_EQ("100,200 21x30", window_
->bounds().ToString());
1339 TEST_F(WorkspaceWindowResizerTest
, MagneticallyResize_BOTTOMRIGHT
) {
1340 window_
->SetBounds(gfx::Rect(100, 200, 20, 30));
1344 window2_
->SetBounds(gfx::Rect(122, 212, 10, 20));
1345 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1346 window_
.get(), gfx::Point(), HTBOTTOMRIGHT
));
1347 ASSERT_TRUE(resizer
.get());
1348 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 0), 0);
1349 EXPECT_EQ("100,200 22x32", window_
->bounds().ToString());
1350 resizer
->RevertDrag();
1354 window2_
->SetBounds(gfx::Rect(111, 233, 10, 20));
1355 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1356 window_
.get(), gfx::Point(), HTBOTTOMRIGHT
));
1357 ASSERT_TRUE(resizer
.get());
1358 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 0), 0);
1359 EXPECT_EQ("100,200 21x33", window_
->bounds().ToString());
1360 resizer
->RevertDrag();
1364 TEST_F(WorkspaceWindowResizerTest
, MagneticallyResize_BOTTOM
) {
1365 window_
->SetBounds(gfx::Rect(100, 200, 20, 30));
1366 window2_
->SetBounds(gfx::Rect(111, 233, 10, 20));
1369 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1370 window_
.get(), gfx::Point(), HTBOTTOM
));
1371 ASSERT_TRUE(resizer
.get());
1372 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 0), 0);
1373 EXPECT_EQ("100,200 20x33", window_
->bounds().ToString());
1376 TEST_F(WorkspaceWindowResizerTest
, MagneticallyResize_BOTTOMLEFT
) {
1377 window_
->SetBounds(gfx::Rect(100, 200, 20, 30));
1381 window2_
->SetBounds(gfx::Rect(99, 231, 10, 20));
1382 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1383 window_
.get(), gfx::Point(), HTBOTTOMLEFT
));
1384 ASSERT_TRUE(resizer
.get());
1385 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 0), 0);
1386 EXPECT_EQ("99,200 21x31", window_
->bounds().ToString());
1387 resizer
->RevertDrag();
1391 window2_
->SetBounds(gfx::Rect(89, 209, 10, 20));
1392 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1393 window_
.get(), gfx::Point(), HTBOTTOMLEFT
));
1394 ASSERT_TRUE(resizer
.get());
1395 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 0), 0);
1396 EXPECT_EQ("99,200 21x29", window_
->bounds().ToString());
1397 resizer
->RevertDrag();
1401 TEST_F(WorkspaceWindowResizerTest
, MagneticallyResize_LEFT
) {
1402 window2_
->SetBounds(gfx::Rect(89, 209, 10, 20));
1403 window_
->SetBounds(gfx::Rect(100, 200, 20, 30));
1406 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1407 window_
.get(), gfx::Point(), HTLEFT
));
1408 ASSERT_TRUE(resizer
.get());
1409 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 0), 0);
1410 EXPECT_EQ("99,200 21x30", window_
->bounds().ToString());
1413 // Test that the user user moved window flag is getting properly set.
1414 TEST_F(WorkspaceWindowResizerTest
, CheckUserWindowManagedFlags
) {
1415 window_
->SetBounds(gfx::Rect( 0, 50, 400, 200));
1416 window_
->SetProperty(aura::client::kCanMaximizeKey
, true);
1418 std::vector
<aura::Window
*> no_attached_windows
;
1419 // Check that an abort doesn't change anything.
1421 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1422 window_
.get(), gfx::Point(), HTCAPTION
));
1423 ASSERT_TRUE(resizer
.get());
1424 // Move it 100 to the bottom.
1425 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 100), 0);
1426 EXPECT_EQ("0,150 400x200", window_
->bounds().ToString());
1427 resizer
->RevertDrag();
1429 EXPECT_FALSE(wm::GetWindowState(window_
.get())->bounds_changed_by_user());
1432 // Check that a completed move / size does change the user coordinates.
1434 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1435 window_
.get(), gfx::Point(), HTCAPTION
));
1436 ASSERT_TRUE(resizer
.get());
1437 // Move it 100 to the bottom.
1438 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 100), 0);
1439 EXPECT_EQ("0,150 400x200", window_
->bounds().ToString());
1440 resizer
->CompleteDrag();
1441 EXPECT_TRUE(wm::GetWindowState(window_
.get())->bounds_changed_by_user());
1445 // Test that a window with a specified max size doesn't exceed it when dragged.
1446 TEST_F(WorkspaceWindowResizerTest
, TestMaxSizeEnforced
) {
1447 window_
->SetBounds(gfx::Rect(0, 0, 400, 300));
1448 delegate_
.set_max_size(gfx::Size(401, 301));
1450 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1451 window_
.get(), gfx::Point(), HTBOTTOMRIGHT
));
1452 resizer
->Drag(CalculateDragPoint(*resizer
, 2, 2), 0);
1453 EXPECT_EQ(401, window_
->bounds().width());
1454 EXPECT_EQ(301, window_
->bounds().height());
1457 // Test that a window with a specified max width doesn't restrict its height.
1458 TEST_F(WorkspaceWindowResizerTest
, TestPartialMaxSizeEnforced
) {
1459 window_
->SetBounds(gfx::Rect(0, 0, 400, 300));
1460 delegate_
.set_max_size(gfx::Size(401, 0));
1462 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1463 window_
.get(), gfx::Point(), HTBOTTOMRIGHT
));
1464 resizer
->Drag(CalculateDragPoint(*resizer
, 2, 2), 0);
1465 EXPECT_EQ(401, window_
->bounds().width());
1466 EXPECT_EQ(302, window_
->bounds().height());
1469 // Test that a window with a specified max size can't be snapped.
1470 TEST_F(WorkspaceWindowResizerTest
, PhantomSnapMaxSize
) {
1472 // With max size not set we get a phantom window controller for dragging off
1473 // the right hand side.
1474 // Make the window wider than maximum docked width.
1475 window_
->SetBounds(gfx::Rect(0, 0, 400, 200));
1477 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1478 window_
.get(), gfx::Point(), HTCAPTION
));
1479 EXPECT_FALSE(snap_phantom_window_controller());
1480 resizer
->Drag(CalculateDragPoint(*resizer
, 801, 0), 0);
1481 EXPECT_TRUE(snap_phantom_window_controller());
1482 resizer
->RevertDrag();
1485 // With max size defined, we get no phantom window for snapping but we still
1486 // get a phantom window (docking guide).
1487 window_
->SetBounds(gfx::Rect(0, 0, 400, 200));
1488 delegate_
.set_max_size(gfx::Size(400, 200));
1490 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1491 window_
.get(), gfx::Point(), HTCAPTION
));
1492 resizer
->Drag(CalculateDragPoint(*resizer
, 801, 0), 0);
1493 EXPECT_TRUE(snap_phantom_window_controller());
1494 resizer
->RevertDrag();
1497 // With max size defined, we get no phantom window for snapping.
1498 window_
->SetBounds(gfx::Rect(0, 0, 400, 200));
1499 delegate_
.set_max_size(gfx::Size(400, 200));
1500 // With min size defined, we get no phantom window for docking.
1501 delegate_
.set_min_size(gfx::Size(400, 200));
1503 scoped_ptr
<WindowResizer
> resizer(CreateResizerForTest(
1504 window_
.get(), gfx::Point(), HTCAPTION
));
1505 resizer
->Drag(CalculateDragPoint(*resizer
, 801, 0), 0);
1506 EXPECT_FALSE(snap_phantom_window_controller());
1507 resizer
->RevertDrag();
1511 TEST_F(WorkspaceWindowResizerTest
, DontRewardRightmostWindowForOverflows
) {
1512 UpdateDisplay("600x800");
1513 aura::Window
* root
= Shell::GetPrimaryRootWindow();
1514 Shell::GetInstance()->SetDisplayWorkAreaInsets(root
, gfx::Insets());
1516 // Four 100x100 windows flush against eachother, starting at 100,100.
1517 window_
->SetBounds(gfx::Rect( 100, 100, 100, 100));
1518 window2_
->SetBounds(gfx::Rect(200, 100, 100, 100));
1519 window3_
->SetBounds(gfx::Rect(300, 100, 100, 100));
1520 window4_
->SetBounds(gfx::Rect(400, 100, 100, 100));
1521 delegate2_
.set_max_size(gfx::Size(101, 0));
1523 std::vector
<aura::Window
*> windows
;
1524 windows
.push_back(window2_
.get());
1525 windows
.push_back(window3_
.get());
1526 windows
.push_back(window4_
.get());
1527 scoped_ptr
<WorkspaceWindowResizer
> resizer(CreateWorkspaceResizerForTest(
1528 window_
.get(), gfx::Point(), HTRIGHT
,
1529 aura::client::WINDOW_MOVE_SOURCE_MOUSE
, windows
));
1530 ASSERT_TRUE(resizer
.get());
1531 // Move it 51 to the left, which should contract w1 and expand w2-4.
1532 // w2 will hit its max size straight away, and in doing so will leave extra
1533 // pixels that a naive implementation may award to the rightmost window. A
1534 // fair implementation will give 25 pixels to each of the other windows.
1535 resizer
->Drag(CalculateDragPoint(*resizer
, -51, 0), 0);
1536 EXPECT_EQ("100,100 49x100", window_
->bounds().ToString());
1537 EXPECT_EQ("149,100 101x100", window2_
->bounds().ToString());
1538 EXPECT_EQ("250,100 125x100", window3_
->bounds().ToString());
1539 EXPECT_EQ("375,100 125x100", window4_
->bounds().ToString());
1542 TEST_F(WorkspaceWindowResizerTest
, DontExceedMaxWidth
) {
1543 UpdateDisplay("600x800");
1544 aura::Window
* root
= Shell::GetPrimaryRootWindow();
1545 Shell::GetInstance()->SetDisplayWorkAreaInsets(root
, gfx::Insets());
1547 // Four 100x100 windows flush against eachother, starting at 100,100.
1548 window_
->SetBounds(gfx::Rect( 100, 100, 100, 100));
1549 window2_
->SetBounds(gfx::Rect(200, 100, 100, 100));
1550 window3_
->SetBounds(gfx::Rect(300, 100, 100, 100));
1551 window4_
->SetBounds(gfx::Rect(400, 100, 100, 100));
1552 delegate2_
.set_max_size(gfx::Size(101, 0));
1553 delegate3_
.set_max_size(gfx::Size(101, 0));
1555 std::vector
<aura::Window
*> windows
;
1556 windows
.push_back(window2_
.get());
1557 windows
.push_back(window3_
.get());
1558 windows
.push_back(window4_
.get());
1559 scoped_ptr
<WorkspaceWindowResizer
> resizer(CreateWorkspaceResizerForTest(
1560 window_
.get(), gfx::Point(), HTRIGHT
,
1561 aura::client::WINDOW_MOVE_SOURCE_MOUSE
, windows
));
1562 ASSERT_TRUE(resizer
.get());
1563 // Move it 52 to the left, which should contract w1 and expand w2-4.
1564 resizer
->Drag(CalculateDragPoint(*resizer
, -52, 0), 0);
1565 EXPECT_EQ("100,100 48x100", window_
->bounds().ToString());
1566 EXPECT_EQ("148,100 101x100", window2_
->bounds().ToString());
1567 EXPECT_EQ("249,100 101x100", window3_
->bounds().ToString());
1568 EXPECT_EQ("350,100 150x100", window4_
->bounds().ToString());
1571 TEST_F(WorkspaceWindowResizerTest
, DontExceedMaxHeight
) {
1572 UpdateDisplay("600x800");
1573 aura::Window
* root
= Shell::GetPrimaryRootWindow();
1574 Shell::GetInstance()->SetDisplayWorkAreaInsets(root
, gfx::Insets());
1576 // Four 100x100 windows flush against eachother, starting at 100,100.
1577 window_
->SetBounds(gfx::Rect( 100, 100, 100, 100));
1578 window2_
->SetBounds(gfx::Rect(100, 200, 100, 100));
1579 window3_
->SetBounds(gfx::Rect(100, 300, 100, 100));
1580 window4_
->SetBounds(gfx::Rect(100, 400, 100, 100));
1581 delegate2_
.set_max_size(gfx::Size(0, 101));
1582 delegate3_
.set_max_size(gfx::Size(0, 101));
1584 std::vector
<aura::Window
*> windows
;
1585 windows
.push_back(window2_
.get());
1586 windows
.push_back(window3_
.get());
1587 windows
.push_back(window4_
.get());
1588 scoped_ptr
<WorkspaceWindowResizer
> resizer(CreateWorkspaceResizerForTest(
1589 window_
.get(), gfx::Point(), HTBOTTOM
,
1590 aura::client::WINDOW_MOVE_SOURCE_MOUSE
, windows
));
1591 ASSERT_TRUE(resizer
.get());
1592 // Move it 52 up, which should contract w1 and expand w2-4.
1593 resizer
->Drag(CalculateDragPoint(*resizer
, 0, -52), 0);
1594 EXPECT_EQ("100,100 100x48", window_
->bounds().ToString());
1595 EXPECT_EQ("100,148 100x101", window2_
->bounds().ToString());
1596 EXPECT_EQ("100,249 100x101", window3_
->bounds().ToString());
1597 EXPECT_EQ("100,350 100x150", window4_
->bounds().ToString());
1601 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
1602 #define MAYBE_DontExceedMinHeight DISABLED_DontExceedMinHeight
1604 #define MAYBE_DontExceedMinHeight DontExceedMinHeight
1607 TEST_F(WorkspaceWindowResizerTest
, MAYBE_DontExceedMinHeight
) {
1608 UpdateDisplay("600x500");
1609 aura::Window
* root
= Shell::GetPrimaryRootWindow();
1610 Shell::GetInstance()->SetDisplayWorkAreaInsets(root
, gfx::Insets());
1612 // Four 100x100 windows flush against eachother, starting at 100,100.
1613 window_
->SetBounds(gfx::Rect( 100, 100, 100, 100));
1614 window2_
->SetBounds(gfx::Rect(100, 200, 100, 100));
1615 window3_
->SetBounds(gfx::Rect(100, 300, 100, 100));
1616 window4_
->SetBounds(gfx::Rect(100, 400, 100, 100));
1617 delegate2_
.set_min_size(gfx::Size(0, 99));
1618 delegate3_
.set_min_size(gfx::Size(0, 99));
1620 std::vector
<aura::Window
*> windows
;
1621 windows
.push_back(window2_
.get());
1622 windows
.push_back(window3_
.get());
1623 windows
.push_back(window4_
.get());
1624 scoped_ptr
<WorkspaceWindowResizer
> resizer(CreateWorkspaceResizerForTest(
1625 window_
.get(), gfx::Point(), HTBOTTOM
,
1626 aura::client::WINDOW_MOVE_SOURCE_MOUSE
, windows
));
1627 ASSERT_TRUE(resizer
.get());
1628 // Move it 52 down, which should expand w1 and contract w2-4.
1629 resizer
->Drag(CalculateDragPoint(*resizer
, 0, 52), 0);
1630 EXPECT_EQ("100,100 100x152", window_
->bounds().ToString());
1631 EXPECT_EQ("100,252 100x99", window2_
->bounds().ToString());
1632 EXPECT_EQ("100,351 100x99", window3_
->bounds().ToString());
1633 EXPECT_EQ("100,450 100x50", window4_
->bounds().ToString());
1636 TEST_F(WorkspaceWindowResizerTest
, DontExpandRightmostPastMaxWidth
) {
1637 UpdateDisplay("600x800");
1638 aura::Window
* root
= Shell::GetPrimaryRootWindow();
1639 Shell::GetInstance()->SetDisplayWorkAreaInsets(root
, gfx::Insets());
1641 // Three 100x100 windows flush against eachother, starting at 100,100.
1642 window_
->SetBounds(gfx::Rect( 100, 100, 100, 100));
1643 window2_
->SetBounds(gfx::Rect(200, 100, 100, 100));
1644 window3_
->SetBounds(gfx::Rect(300, 100, 100, 100));
1645 delegate3_
.set_max_size(gfx::Size(101, 0));
1647 std::vector
<aura::Window
*> windows
;
1648 windows
.push_back(window2_
.get());
1649 windows
.push_back(window3_
.get());
1650 windows
.push_back(window4_
.get());
1651 scoped_ptr
<WorkspaceWindowResizer
> resizer(CreateWorkspaceResizerForTest(
1652 window_
.get(), gfx::Point(), HTRIGHT
,
1653 aura::client::WINDOW_MOVE_SOURCE_MOUSE
, windows
));
1654 ASSERT_TRUE(resizer
.get());
1655 // Move it 51 to the left, which should contract w1 and expand w2-3.
1656 resizer
->Drag(CalculateDragPoint(*resizer
, -51, 0), 0);
1657 EXPECT_EQ("100,100 49x100", window_
->bounds().ToString());
1658 EXPECT_EQ("149,100 150x100", window2_
->bounds().ToString());
1659 EXPECT_EQ("299,100 101x100", window3_
->bounds().ToString());
1662 TEST_F(WorkspaceWindowResizerTest
, MoveAttachedWhenGrownToMaxSize
) {
1663 UpdateDisplay("600x800");
1664 aura::Window
* root
= Shell::GetPrimaryRootWindow();
1665 Shell::GetInstance()->SetDisplayWorkAreaInsets(root
, gfx::Insets());
1667 // Three 100x100 windows flush against eachother, starting at 100,100.
1668 window_
->SetBounds(gfx::Rect( 100, 100, 100, 100));
1669 window2_
->SetBounds(gfx::Rect(200, 100, 100, 100));
1670 window3_
->SetBounds(gfx::Rect(300, 100, 100, 100));
1671 delegate2_
.set_max_size(gfx::Size(101, 0));
1672 delegate3_
.set_max_size(gfx::Size(101, 0));
1674 std::vector
<aura::Window
*> windows
;
1675 windows
.push_back(window2_
.get());
1676 windows
.push_back(window3_
.get());
1677 windows
.push_back(window4_
.get());
1678 scoped_ptr
<WorkspaceWindowResizer
> resizer(CreateWorkspaceResizerForTest(
1679 window_
.get(), gfx::Point(), HTRIGHT
,
1680 aura::client::WINDOW_MOVE_SOURCE_MOUSE
, windows
));
1681 ASSERT_TRUE(resizer
.get());
1682 // Move it 52 to the left, which should contract w1 and expand and move w2-3.
1683 resizer
->Drag(CalculateDragPoint(*resizer
, -52, 0), 0);
1684 EXPECT_EQ("100,100 48x100", window_
->bounds().ToString());
1685 EXPECT_EQ("148,100 101x100", window2_
->bounds().ToString());
1686 EXPECT_EQ("249,100 101x100", window3_
->bounds().ToString());
1690 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
1691 #define MAYBE_MainWindowHonoursMaxWidth DISABLED_MainWindowHonoursMaxWidth
1693 #define MAYBE_MainWindowHonoursMaxWidth MainWindowHonoursMaxWidth
1696 TEST_F(WorkspaceWindowResizerTest
, MAYBE_MainWindowHonoursMaxWidth
) {
1697 UpdateDisplay("400x800");
1698 aura::Window
* root
= Shell::GetPrimaryRootWindow();
1699 Shell::GetInstance()->SetDisplayWorkAreaInsets(root
, gfx::Insets());
1701 // Three 100x100 windows flush against eachother, starting at 100,100.
1702 window_
->SetBounds(gfx::Rect( 100, 100, 100, 100));
1703 window2_
->SetBounds(gfx::Rect(200, 100, 100, 100));
1704 window3_
->SetBounds(gfx::Rect(300, 100, 100, 100));
1705 delegate_
.set_max_size(gfx::Size(102, 0));
1707 std::vector
<aura::Window
*> windows
;
1708 windows
.push_back(window2_
.get());
1709 windows
.push_back(window3_
.get());
1710 windows
.push_back(window4_
.get());
1711 scoped_ptr
<WorkspaceWindowResizer
> resizer(CreateWorkspaceResizerForTest(
1712 window_
.get(), gfx::Point(), HTRIGHT
,
1713 aura::client::WINDOW_MOVE_SOURCE_MOUSE
, windows
));
1714 ASSERT_TRUE(resizer
.get());
1715 // Move it 50 to the right, which should expand w1 and contract w2-3, as they
1716 // won't fit in the root window in their original sizes.
1717 resizer
->Drag(CalculateDragPoint(*resizer
, 50, 0), 0);
1718 EXPECT_EQ("100,100 102x100", window_
->bounds().ToString());
1719 EXPECT_EQ("202,100 99x100", window2_
->bounds().ToString());
1720 EXPECT_EQ("301,100 99x100", window3_
->bounds().ToString());
1723 TEST_F(WorkspaceWindowResizerTest
, MainWindowHonoursMinWidth
) {
1724 UpdateDisplay("400x800");
1725 aura::Window
* root
= Shell::GetPrimaryRootWindow();
1726 Shell::GetInstance()->SetDisplayWorkAreaInsets(root
, gfx::Insets());
1728 // Three 100x100 windows flush against eachother, starting at 100,100.
1729 window_
->SetBounds(gfx::Rect( 100, 100, 100, 100));
1730 window2_
->SetBounds(gfx::Rect(200, 100, 100, 100));
1731 window3_
->SetBounds(gfx::Rect(300, 100, 100, 100));
1732 delegate_
.set_min_size(gfx::Size(98, 0));
1734 std::vector
<aura::Window
*> windows
;
1735 windows
.push_back(window2_
.get());
1736 windows
.push_back(window3_
.get());
1737 scoped_ptr
<WorkspaceWindowResizer
> resizer(CreateWorkspaceResizerForTest(
1738 window_
.get(), gfx::Point(), HTRIGHT
,
1739 aura::client::WINDOW_MOVE_SOURCE_MOUSE
, windows
));
1740 ASSERT_TRUE(resizer
.get());
1741 // Move it 50 to the left, which should contract w1 and expand w2-3.
1742 resizer
->Drag(CalculateDragPoint(*resizer
, -50, 0), 0);
1743 EXPECT_EQ("100,100 98x100", window_
->bounds().ToString());
1744 EXPECT_EQ("198,100 101x100", window2_
->bounds().ToString());
1745 EXPECT_EQ("299,100 101x100", window3_
->bounds().ToString());
1748 // The following variants test that windows are resized correctly to the edges
1749 // of the screen using touch, when touch point is off of the window border.
1750 TEST_F(WorkspaceWindowResizerTest
, TouchResizeToEdge_RIGHT
) {
1751 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN
);
1753 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight
- 200), HTRIGHT
);
1754 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight
- 200).ToString(),
1755 touch_resize_window_
->bounds().ToString());
1757 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow(),
1758 touch_resize_window_
.get());
1760 // Drag out of the right border a bit and check if the border is aligned with
1762 generator
.GestureScrollSequence(gfx::Point(715, kRootHeight
/ 2),
1763 gfx::Point(725, kRootHeight
/ 2),
1764 base::TimeDelta::FromMilliseconds(10),
1766 EXPECT_EQ(gfx::Rect(100, 100, 625, kRootHeight
- 200).ToString(),
1767 touch_resize_window_
->bounds().ToString());
1768 // Drag more, but stop before being snapped to the edge.
1769 generator
.GestureScrollSequence(gfx::Point(725, kRootHeight
/ 2),
1770 gfx::Point(760, kRootHeight
/ 2),
1771 base::TimeDelta::FromMilliseconds(10),
1773 EXPECT_EQ(gfx::Rect(100, 100, 660, kRootHeight
- 200).ToString(),
1774 touch_resize_window_
->bounds().ToString());
1775 // Drag even more to snap to the edge.
1776 generator
.GestureScrollSequence(gfx::Point(760, kRootHeight
/ 2),
1777 gfx::Point(775, kRootHeight
/ 2),
1778 base::TimeDelta::FromMilliseconds(10),
1780 EXPECT_EQ(gfx::Rect(100, 100, 700, kRootHeight
- 200).ToString(),
1781 touch_resize_window_
->bounds().ToString());
1784 TEST_F(WorkspaceWindowResizerTest
, TouchResizeToEdge_LEFT
) {
1785 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN
);
1787 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight
- 200), HTLEFT
);
1788 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight
- 200).ToString(),
1789 touch_resize_window_
->bounds().ToString());
1791 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow(),
1792 touch_resize_window_
.get());
1794 // Drag out of the left border a bit and check if the border is aligned with
1796 generator
.GestureScrollSequence(gfx::Point(85, kRootHeight
/ 2),
1797 gfx::Point(75, kRootHeight
/ 2),
1798 base::TimeDelta::FromMilliseconds(10),
1800 EXPECT_EQ(gfx::Rect(75, 100, 625, kRootHeight
- 200).ToString(),
1801 touch_resize_window_
->bounds().ToString());
1802 // Drag more, but stop before being snapped to the edge.
1803 generator
.GestureScrollSequence(gfx::Point(75, kRootHeight
/ 2),
1804 gfx::Point(40, kRootHeight
/ 2),
1805 base::TimeDelta::FromMilliseconds(10),
1807 EXPECT_EQ(gfx::Rect(40, 100, 660, kRootHeight
- 200).ToString(),
1808 touch_resize_window_
->bounds().ToString());
1809 // Drag even more to snap to the edge.
1810 generator
.GestureScrollSequence(gfx::Point(40, kRootHeight
/ 2),
1811 gfx::Point(25, kRootHeight
/ 2),
1812 base::TimeDelta::FromMilliseconds(10),
1814 EXPECT_EQ(gfx::Rect(0, 100, 700, kRootHeight
- 200).ToString(),
1815 touch_resize_window_
->bounds().ToString());
1818 TEST_F(WorkspaceWindowResizerTest
, TouchResizeToEdge_TOP
) {
1819 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN
);
1821 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight
- 200), HTTOP
);
1822 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight
- 200).ToString(),
1823 touch_resize_window_
->bounds().ToString());
1825 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow(),
1826 touch_resize_window_
.get());
1828 // Drag out of the top border a bit and check if the border is aligned with
1830 generator
.GestureScrollSequence(gfx::Point(400, 85),
1831 gfx::Point(400, 75),
1832 base::TimeDelta::FromMilliseconds(10),
1834 EXPECT_EQ(gfx::Rect(100, 75, 600, kRootHeight
- 175).ToString(),
1835 touch_resize_window_
->bounds().ToString());
1836 // Drag more, but stop before being snapped to the edge.
1837 generator
.GestureScrollSequence(gfx::Point(400, 75),
1838 gfx::Point(400, 40),
1839 base::TimeDelta::FromMilliseconds(10),
1841 EXPECT_EQ(gfx::Rect(100, 40, 600, kRootHeight
- 140).ToString(),
1842 touch_resize_window_
->bounds().ToString());
1843 // Drag even more to snap to the edge.
1844 generator
.GestureScrollSequence(gfx::Point(400, 40),
1845 gfx::Point(400, 25),
1846 base::TimeDelta::FromMilliseconds(10),
1848 EXPECT_EQ(gfx::Rect(100, 0, 600, kRootHeight
- 100).ToString(),
1849 touch_resize_window_
->bounds().ToString());
1852 TEST_F(WorkspaceWindowResizerTest
, TouchResizeToEdge_BOTTOM
) {
1853 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN
);
1855 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight
- 200), HTBOTTOM
);
1856 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight
- 200).ToString(),
1857 touch_resize_window_
->bounds().ToString());
1859 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow(),
1860 touch_resize_window_
.get());
1862 // Drag out of the bottom border a bit and check if the border is aligned with
1864 generator
.GestureScrollSequence(gfx::Point(400, kRootHeight
- 85),
1865 gfx::Point(400, kRootHeight
- 75),
1866 base::TimeDelta::FromMilliseconds(10),
1868 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight
- 175).ToString(),
1869 touch_resize_window_
->bounds().ToString());
1870 // Drag more, but stop before being snapped to the edge.
1871 generator
.GestureScrollSequence(gfx::Point(400, kRootHeight
- 75),
1872 gfx::Point(400, kRootHeight
- 40),
1873 base::TimeDelta::FromMilliseconds(10),
1875 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight
- 140).ToString(),
1876 touch_resize_window_
->bounds().ToString());
1877 // Drag even more to snap to the edge.
1878 generator
.GestureScrollSequence(gfx::Point(400, kRootHeight
- 40),
1879 gfx::Point(400, kRootHeight
- 25),
1880 base::TimeDelta::FromMilliseconds(10),
1882 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight
- 100).ToString(),
1883 touch_resize_window_
->bounds().ToString());