Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ash / wm / workspace / workspace_window_resizer_unittest.cc
blob9b10e16473f070a8906e3ecefb01fcc062b90c79
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/gestures/gesture_configuration.h"
27 #include "ui/events/test/event_generator.h"
28 #include "ui/gfx/insets.h"
29 #include "ui/gfx/screen.h"
30 #include "ui/views/widget/widget.h"
32 namespace ash {
33 namespace {
35 const int kRootHeight = 600;
37 // A simple window delegate that returns the specified min size.
38 class TestWindowDelegate : public aura::test::TestWindowDelegate {
39 public:
40 TestWindowDelegate() {
42 virtual ~TestWindowDelegate() {}
44 void set_min_size(const gfx::Size& size) {
45 min_size_ = size;
48 void set_max_size(const gfx::Size& size) {
49 max_size_ = size;
52 private:
53 // Overridden from aura::Test::TestWindowDelegate:
54 virtual gfx::Size GetMinimumSize() const OVERRIDE {
55 return min_size_;
58 virtual gfx::Size GetMaximumSize() const OVERRIDE {
59 return max_size_;
62 gfx::Size min_size_;
63 gfx::Size max_size_;
65 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate);
68 } // namespace
70 class WorkspaceWindowResizerTest : public test::AshTestBase {
71 public:
72 WorkspaceWindowResizerTest() : workspace_resizer_(NULL) {}
73 virtual ~WorkspaceWindowResizerTest() {}
75 virtual void SetUp() OVERRIDE {
76 AshTestBase::SetUp();
77 UpdateDisplay(base::StringPrintf("800x%d", kRootHeight));
78 // Ignore the touch slop region.
79 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(0);
81 aura::Window* root = Shell::GetPrimaryRootWindow();
82 gfx::Rect root_bounds(root->bounds());
83 #if defined(OS_WIN)
84 // RootWindow and Display can't resize on Windows Ash.
85 // http://crbug.com/165962
86 EXPECT_EQ(kRootHeight, root_bounds.height());
87 #endif
88 EXPECT_EQ(800, root_bounds.width());
89 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
90 window_.reset(new aura::Window(&delegate_));
91 window_->SetType(ui::wm::WINDOW_TYPE_NORMAL);
92 window_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
93 ParentWindowInPrimaryRootWindow(window_.get());
94 window_->set_id(1);
96 window2_.reset(new aura::Window(&delegate2_));
97 window2_->SetType(ui::wm::WINDOW_TYPE_NORMAL);
98 window2_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
99 ParentWindowInPrimaryRootWindow(window2_.get());
100 window2_->set_id(2);
102 window3_.reset(new aura::Window(&delegate3_));
103 window3_->SetType(ui::wm::WINDOW_TYPE_NORMAL);
104 window3_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
105 ParentWindowInPrimaryRootWindow(window3_.get());
106 window3_->set_id(3);
108 window4_.reset(new aura::Window(&delegate4_));
109 window4_->SetType(ui::wm::WINDOW_TYPE_NORMAL);
110 window4_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
111 ParentWindowInPrimaryRootWindow(window4_.get());
112 window4_->set_id(4);
115 virtual void TearDown() OVERRIDE {
116 window_.reset();
117 window2_.reset();
118 window3_.reset();
119 window4_.reset();
120 touch_resize_window_.reset();
121 AshTestBase::TearDown();
124 // Returns a string identifying the z-order of each of the known child windows
125 // of |parent|. The returned string constains the id of the known windows and
126 // is ordered from topmost to bottomost windows.
127 std::string WindowOrderAsString(aura::Window* parent) const {
128 std::string result;
129 const aura::Window::Windows& windows = parent->children();
130 for (aura::Window::Windows::const_reverse_iterator i = windows.rbegin();
131 i != windows.rend(); ++i) {
132 if (*i == window_ || *i == window2_ || *i == window3_) {
133 if (!result.empty())
134 result += " ";
135 result += base::IntToString((*i)->id());
138 return result;
141 protected:
142 WindowResizer* CreateResizerForTest(
143 aura::Window* window,
144 const gfx::Point& point_in_parent,
145 int window_component) {
146 WindowResizer* resizer = CreateWindowResizer(
147 window,
148 point_in_parent,
149 window_component,
150 aura::client::WINDOW_MOVE_SOURCE_MOUSE).release();
151 workspace_resizer_ = WorkspaceWindowResizer::instance_;
152 return resizer;
154 WorkspaceWindowResizer* CreateWorkspaceResizerForTest(
155 aura::Window* window,
156 const gfx::Point& point_in_parent,
157 int window_component,
158 aura::client::WindowMoveSource source,
159 const std::vector<aura::Window*>& attached_windows) {
160 wm::WindowState* window_state = wm::GetWindowState(window);
161 window_state->CreateDragDetails(
162 window, point_in_parent, window_component, source);
163 return WorkspaceWindowResizer::Create(window_state, attached_windows);
166 PhantomWindowController* snap_phantom_window_controller() const {
167 return workspace_resizer_->snap_phantom_window_controller_.get();
170 gfx::Point CalculateDragPoint(const WindowResizer& resizer,
171 int delta_x,
172 int delta_y) const {
173 gfx::Point location = resizer.GetInitialLocation();
174 location.set_x(location.x() + delta_x);
175 location.set_y(location.y() + delta_y);
176 return location;
179 std::vector<aura::Window*> empty_windows() const {
180 return std::vector<aura::Window*>();
183 ShelfLayoutManager* shelf_layout_manager() {
184 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
187 void InitTouchResizeWindow(const gfx::Rect& bounds, int window_component) {
188 touch_resize_delegate_.set_window_component(window_component);
189 touch_resize_window_.reset(
190 CreateTestWindowInShellWithDelegate(&touch_resize_delegate_, 0,
191 bounds));
194 TestWindowDelegate delegate_;
195 TestWindowDelegate delegate2_;
196 TestWindowDelegate delegate3_;
197 TestWindowDelegate delegate4_;
198 scoped_ptr<aura::Window> window_;
199 scoped_ptr<aura::Window> window2_;
200 scoped_ptr<aura::Window> window3_;
201 scoped_ptr<aura::Window> window4_;
203 TestWindowDelegate touch_resize_delegate_;
204 scoped_ptr<aura::Window> touch_resize_window_;
205 WorkspaceWindowResizer* workspace_resizer_;
207 private:
208 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest);
211 // Assertions around attached window resize dragging from the right with 2
212 // windows.
213 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2) {
214 window_->SetBounds(gfx::Rect(0, 300, 400, 300));
215 window2_->SetBounds(gfx::Rect(400, 200, 100, 200));
217 std::vector<aura::Window*> windows;
218 windows.push_back(window2_.get());
219 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
220 window_.get(), gfx::Point(), HTRIGHT,
221 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
222 ASSERT_TRUE(resizer.get());
223 // Move it 100 to the right, which should expand w1 and push w2.
224 resizer->Drag(CalculateDragPoint(*resizer, 100, 10), 0);
225 EXPECT_EQ("0,300 500x300", window_->bounds().ToString());
226 EXPECT_EQ("500,200 100x200", window2_->bounds().ToString());
228 // Push off the screen, w2 should be resized to its min.
229 delegate2_.set_min_size(gfx::Size(20, 20));
230 resizer->Drag(CalculateDragPoint(*resizer, 800, 20), 0);
231 EXPECT_EQ("0,300 780x300", window_->bounds().ToString());
232 EXPECT_EQ("780,200 20x200", window2_->bounds().ToString());
234 // Move back to 100 and verify w2 gets its original size.
235 resizer->Drag(CalculateDragPoint(*resizer, 100, 10), 0);
236 EXPECT_EQ("0,300 500x300", window_->bounds().ToString());
237 EXPECT_EQ("500,200 100x200", window2_->bounds().ToString());
239 // Revert and make sure everything moves back.
240 resizer->Drag(CalculateDragPoint(*resizer, 800, 20), 0);
241 resizer->RevertDrag();
242 EXPECT_EQ("0,300 400x300", window_->bounds().ToString());
243 EXPECT_EQ("400,200 100x200", window2_->bounds().ToString());
246 // Assertions around collapsing and expanding.
247 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_Compress) {
248 window_->SetBounds(gfx::Rect( 0, 300, 400, 300));
249 window2_->SetBounds(gfx::Rect(400, 200, 100, 200));
251 std::vector<aura::Window*> windows;
252 windows.push_back(window2_.get());
253 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
254 window_.get(), gfx::Point(), HTRIGHT,
255 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
256 ASSERT_TRUE(resizer.get());
257 // Move it 100 to the left, which should expand w2 and collapse w1.
258 resizer->Drag(CalculateDragPoint(*resizer, -100, 10), 0);
259 EXPECT_EQ("0,300 300x300", window_->bounds().ToString());
260 EXPECT_EQ("300,200 200x200", window2_->bounds().ToString());
262 // Collapse all the way to w1's min.
263 delegate_.set_min_size(gfx::Size(20, 20));
264 resizer->Drag(CalculateDragPoint(*resizer, -800, 20), 0);
265 EXPECT_EQ("0,300 20x300", window_->bounds().ToString());
266 EXPECT_EQ("20,200 480x200", window2_->bounds().ToString());
268 // Move 100 to the left.
269 resizer->Drag(CalculateDragPoint(*resizer, 100, 10), 0);
270 EXPECT_EQ("0,300 500x300", window_->bounds().ToString());
271 EXPECT_EQ("500,200 100x200", window2_->bounds().ToString());
273 // Back to -100.
274 resizer->Drag(CalculateDragPoint(*resizer, -100, 20), 0);
275 EXPECT_EQ("0,300 300x300", window_->bounds().ToString());
276 EXPECT_EQ("300,200 200x200", window2_->bounds().ToString());
279 // Assertions around attached window resize dragging from the right with 3
280 // windows.
281 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_3) {
282 window_->SetBounds(gfx::Rect( 100, 300, 200, 300));
283 window2_->SetBounds(gfx::Rect(300, 300, 150, 200));
284 window3_->SetBounds(gfx::Rect(450, 300, 100, 200));
285 delegate2_.set_min_size(gfx::Size(52, 50));
286 delegate3_.set_min_size(gfx::Size(38, 50));
288 std::vector<aura::Window*> windows;
289 windows.push_back(window2_.get());
290 windows.push_back(window3_.get());
291 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
292 window_.get(), gfx::Point(), HTRIGHT,
293 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
294 ASSERT_TRUE(resizer.get());
295 // Move it 100 to the right, which should expand w1 and push w2 and w3.
296 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
297 EXPECT_EQ("100,300 300x300", window_->bounds().ToString());
298 EXPECT_EQ("400,300 150x200", window2_->bounds().ToString());
299 EXPECT_EQ("550,300 100x200", window3_->bounds().ToString());
301 // Move it 300, things should compress.
302 resizer->Drag(CalculateDragPoint(*resizer, 300, -10), 0);
303 EXPECT_EQ("100,300 500x300", window_->bounds().ToString());
304 EXPECT_EQ("600,300 120x200", window2_->bounds().ToString());
305 EXPECT_EQ("720,300 80x200", window3_->bounds().ToString());
307 // Move it so much the last two end up at their min.
308 resizer->Drag(CalculateDragPoint(*resizer, 800, 50), 0);
309 EXPECT_EQ("100,300 610x300", window_->bounds().ToString());
310 EXPECT_EQ("710,300 52x200", window2_->bounds().ToString());
311 EXPECT_EQ("762,300 38x200", window3_->bounds().ToString());
313 // Revert and make sure everything moves back.
314 resizer->RevertDrag();
315 EXPECT_EQ("100,300 200x300", window_->bounds().ToString());
316 EXPECT_EQ("300,300 150x200", window2_->bounds().ToString());
317 EXPECT_EQ("450,300 100x200", window3_->bounds().ToString());
320 // Assertions around attached window resizing (collapsing and expanding) with
321 // 3 windows.
322 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_3_Compress) {
323 window_->SetBounds(gfx::Rect( 100, 300, 200, 300));
324 window2_->SetBounds(gfx::Rect(300, 300, 200, 200));
325 window3_->SetBounds(gfx::Rect(450, 300, 100, 200));
326 delegate2_.set_min_size(gfx::Size(52, 50));
327 delegate3_.set_min_size(gfx::Size(38, 50));
329 std::vector<aura::Window*> windows;
330 windows.push_back(window2_.get());
331 windows.push_back(window3_.get());
332 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
333 window_.get(), gfx::Point(), HTRIGHT,
334 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
335 ASSERT_TRUE(resizer.get());
336 // Move it -100 to the right, which should collapse w1 and expand w2 and w3.
337 resizer->Drag(CalculateDragPoint(*resizer, -100, -10), 0);
338 EXPECT_EQ("100,300 100x300", window_->bounds().ToString());
339 EXPECT_EQ("200,300 266x200", window2_->bounds().ToString());
340 EXPECT_EQ("466,300 134x200", window3_->bounds().ToString());
342 // Move it 100 to the right.
343 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
344 EXPECT_EQ("100,300 300x300", window_->bounds().ToString());
345 EXPECT_EQ("400,300 200x200", window2_->bounds().ToString());
346 EXPECT_EQ("600,300 100x200", window3_->bounds().ToString());
348 // 100 to the left again.
349 resizer->Drag(CalculateDragPoint(*resizer, -100, -10), 0);
350 EXPECT_EQ("100,300 100x300", window_->bounds().ToString());
351 EXPECT_EQ("200,300 266x200", window2_->bounds().ToString());
352 EXPECT_EQ("466,300 134x200", window3_->bounds().ToString());
355 // Assertions around collapsing and expanding from the bottom.
356 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_Compress) {
357 window_->SetBounds(gfx::Rect( 0, 100, 400, 300));
358 window2_->SetBounds(gfx::Rect(400, 400, 100, 200));
360 std::vector<aura::Window*> windows;
361 windows.push_back(window2_.get());
362 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
363 window_.get(), gfx::Point(), HTBOTTOM,
364 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
365 ASSERT_TRUE(resizer.get());
366 // Move it up 100, which should expand w2 and collapse w1.
367 resizer->Drag(CalculateDragPoint(*resizer, 10, -100), 0);
368 EXPECT_EQ("0,100 400x200", window_->bounds().ToString());
369 EXPECT_EQ("400,300 100x300", window2_->bounds().ToString());
371 // Collapse all the way to w1's min.
372 delegate_.set_min_size(gfx::Size(20, 20));
373 resizer->Drag(CalculateDragPoint(*resizer, 20, -800), 0);
374 EXPECT_EQ("0,100 400x20", window_->bounds().ToString());
375 EXPECT_EQ("400,120 100x480", window2_->bounds().ToString());
377 // Move 100 down.
378 resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0);
379 EXPECT_EQ("0,100 400x400", window_->bounds().ToString());
380 EXPECT_EQ("400,500 100x100", window2_->bounds().ToString());
382 // Back to -100.
383 resizer->Drag(CalculateDragPoint(*resizer, 20, -100), 0);
384 EXPECT_EQ("0,100 400x200", window_->bounds().ToString());
385 EXPECT_EQ("400,300 100x300", window2_->bounds().ToString());
388 // Assertions around attached window resize dragging from the bottom with 2
389 // windows.
390 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_2) {
391 window_->SetBounds(gfx::Rect( 0, 50, 400, 200));
392 window2_->SetBounds(gfx::Rect(0, 250, 200, 100));
394 std::vector<aura::Window*> windows;
395 windows.push_back(window2_.get());
396 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
397 window_.get(), gfx::Point(), HTBOTTOM,
398 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
399 ASSERT_TRUE(resizer.get());
400 // Move it 100 to the bottom, which should expand w1 and push w2.
401 resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0);
402 EXPECT_EQ("0,50 400x300", window_->bounds().ToString());
403 EXPECT_EQ("0,350 200x100", window2_->bounds().ToString());
405 // Push off the screen, w2 should be resized to its min.
406 delegate2_.set_min_size(gfx::Size(20, 20));
407 resizer->Drag(CalculateDragPoint(*resizer, 50, 820), 0);
408 EXPECT_EQ("0,50 400x530", window_->bounds().ToString());
409 EXPECT_EQ("0,580 200x20", window2_->bounds().ToString());
411 // Move back to 100 and verify w2 gets its original size.
412 resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0);
413 EXPECT_EQ("0,50 400x300", window_->bounds().ToString());
414 EXPECT_EQ("0,350 200x100", window2_->bounds().ToString());
416 // Revert and make sure everything moves back.
417 resizer->Drag(CalculateDragPoint(*resizer, 800, 20), 0);
418 resizer->RevertDrag();
419 EXPECT_EQ("0,50 400x200", window_->bounds().ToString());
420 EXPECT_EQ("0,250 200x100", window2_->bounds().ToString());
423 #if defined(OS_WIN)
424 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
425 #define MAYBE_AttachedResize_BOTTOM_3 DISABLED_AttachedResize_BOTTOM_3
426 #else
427 #define MAYBE_AttachedResize_BOTTOM_3 AttachedResize_BOTTOM_3
428 #endif
430 // Assertions around attached window resize dragging from the bottom with 3
431 // windows.
432 TEST_F(WorkspaceWindowResizerTest, MAYBE_AttachedResize_BOTTOM_3) {
433 UpdateDisplay("600x800");
434 aura::Window* root = Shell::GetPrimaryRootWindow();
435 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
437 window_->SetBounds(gfx::Rect( 300, 100, 300, 200));
438 window2_->SetBounds(gfx::Rect(300, 300, 200, 150));
439 window3_->SetBounds(gfx::Rect(300, 450, 200, 100));
440 delegate2_.set_min_size(gfx::Size(50, 52));
441 delegate3_.set_min_size(gfx::Size(50, 38));
443 std::vector<aura::Window*> windows;
444 windows.push_back(window2_.get());
445 windows.push_back(window3_.get());
446 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
447 window_.get(), gfx::Point(), HTBOTTOM,
448 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
449 ASSERT_TRUE(resizer.get());
450 // Move it 100 down, which should expand w1 and push w2 and w3.
451 resizer->Drag(CalculateDragPoint(*resizer, -10, 100), 0);
452 EXPECT_EQ("300,100 300x300", window_->bounds().ToString());
453 EXPECT_EQ("300,400 200x150", window2_->bounds().ToString());
454 EXPECT_EQ("300,550 200x100", window3_->bounds().ToString());
456 // Move it 296 things should compress.
457 resizer->Drag(CalculateDragPoint(*resizer, -10, 296), 0);
458 EXPECT_EQ("300,100 300x496", window_->bounds().ToString());
459 EXPECT_EQ("300,596 200x123", window2_->bounds().ToString());
460 EXPECT_EQ("300,719 200x81", window3_->bounds().ToString());
462 // Move it so much everything ends up at its min.
463 resizer->Drag(CalculateDragPoint(*resizer, 50, 798), 0);
464 EXPECT_EQ("300,100 300x610", window_->bounds().ToString());
465 EXPECT_EQ("300,710 200x52", window2_->bounds().ToString());
466 EXPECT_EQ("300,762 200x38", window3_->bounds().ToString());
468 // Revert and make sure everything moves back.
469 resizer->RevertDrag();
470 EXPECT_EQ("300,100 300x200", window_->bounds().ToString());
471 EXPECT_EQ("300,300 200x150", window2_->bounds().ToString());
472 EXPECT_EQ("300,450 200x100", window3_->bounds().ToString());
475 // Assertions around attached window resizing (collapsing and expanding) with
476 // 3 windows.
477 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_3_Compress) {
478 window_->SetBounds(gfx::Rect( 0, 0, 200, 200));
479 window2_->SetBounds(gfx::Rect(10, 200, 200, 200));
480 window3_->SetBounds(gfx::Rect(20, 400, 100, 100));
481 delegate2_.set_min_size(gfx::Size(52, 50));
482 delegate3_.set_min_size(gfx::Size(38, 50));
484 std::vector<aura::Window*> windows;
485 windows.push_back(window2_.get());
486 windows.push_back(window3_.get());
487 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
488 window_.get(), gfx::Point(), HTBOTTOM,
489 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
490 ASSERT_TRUE(resizer.get());
491 // Move it 100 up, which should collapse w1 and expand w2 and w3.
492 resizer->Drag(CalculateDragPoint(*resizer, -10, -100), 0);
493 EXPECT_EQ("0,0 200x100", window_->bounds().ToString());
494 EXPECT_EQ("10,100 200x266", window2_->bounds().ToString());
495 EXPECT_EQ("20,366 100x134", window3_->bounds().ToString());
497 // Move it 100 down.
498 resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0);
499 EXPECT_EQ("0,0 200x300", window_->bounds().ToString());
500 EXPECT_EQ("10,300 200x200", window2_->bounds().ToString());
501 EXPECT_EQ("20,500 100x100", window3_->bounds().ToString());
503 // 100 up again.
504 resizer->Drag(CalculateDragPoint(*resizer, -10, -100), 0);
505 EXPECT_EQ("0,0 200x100", window_->bounds().ToString());
506 EXPECT_EQ("10,100 200x266", window2_->bounds().ToString());
507 EXPECT_EQ("20,366 100x134", window3_->bounds().ToString());
510 // Tests that touch-dragging a window does not lock the mouse cursor
511 // and therefore shows the cursor on a mousemove.
512 TEST_F(WorkspaceWindowResizerTest, MouseMoveWithTouchDrag) {
513 window_->SetBounds(gfx::Rect(0, 300, 400, 300));
514 window2_->SetBounds(gfx::Rect(400, 200, 100, 200));
516 Shell* shell = Shell::GetInstance();
517 ui::test::EventGenerator generator(window_->GetRootWindow());
519 // The cursor should not be locked initially.
520 EXPECT_FALSE(shell->cursor_manager()->IsCursorLocked());
522 std::vector<aura::Window*> windows;
523 windows.push_back(window2_.get());
524 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
525 window_.get(), gfx::Point(), HTRIGHT,
526 aura::client::WINDOW_MOVE_SOURCE_TOUCH, windows));
527 ASSERT_TRUE(resizer.get());
529 // Creating a WorkspaceWindowResizer should not lock the cursor.
530 EXPECT_FALSE(shell->cursor_manager()->IsCursorLocked());
532 // The cursor should be hidden after touching the screen and
533 // starting a drag.
534 EXPECT_TRUE(shell->cursor_manager()->IsCursorVisible());
535 generator.PressTouch();
536 resizer->Drag(CalculateDragPoint(*resizer, 100, 10), 0);
537 EXPECT_FALSE(shell->cursor_manager()->IsCursorVisible());
538 EXPECT_FALSE(shell->cursor_manager()->IsCursorLocked());
540 // Moving the mouse should show the cursor.
541 generator.MoveMouseBy(1, 1);
542 EXPECT_TRUE(shell->cursor_manager()->IsCursorVisible());
543 EXPECT_FALSE(shell->cursor_manager()->IsCursorLocked());
545 resizer->RevertDrag();
548 // Assertions around dragging to the left/right edge of the screen.
549 TEST_F(WorkspaceWindowResizerTest, Edge) {
550 if (!SupportsHostWindowResize())
551 return;
553 // Resize host window to force insets update.
554 UpdateDisplay("800x700");
555 // TODO(varkha): Insets are reset after every drag because of
556 // http://crbug.com/292238.
557 // Window is wide enough not to get docked right away.
558 window_->SetBounds(gfx::Rect(20, 30, 400, 60));
559 wm::WindowState* window_state = wm::GetWindowState(window_.get());
562 gfx::Rect expected_bounds_in_parent(
563 wm::GetDefaultLeftSnappedWindowBoundsInParent(window_.get()));
565 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
566 window_.get(), gfx::Point(), HTCAPTION));
567 ASSERT_TRUE(resizer.get());
568 resizer->Drag(CalculateDragPoint(*resizer, 0, 10), 0);
569 resizer->CompleteDrag();
571 EXPECT_EQ(expected_bounds_in_parent.ToString(),
572 window_->bounds().ToString());
573 ASSERT_TRUE(window_state->HasRestoreBounds());
574 EXPECT_EQ("20,30 400x60",
575 window_state->GetRestoreBoundsInScreen().ToString());
577 // Try the same with the right side.
579 gfx::Rect expected_bounds_in_parent(
580 wm::GetDefaultRightSnappedWindowBoundsInParent(window_.get()));
582 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
583 window_.get(), gfx::Point(), HTCAPTION));
584 ASSERT_TRUE(resizer.get());
585 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0);
586 resizer->CompleteDrag();
587 EXPECT_EQ(expected_bounds_in_parent.ToString(),
588 window_->bounds().ToString());
589 ASSERT_TRUE(window_state->HasRestoreBounds());
590 EXPECT_EQ("20,30 400x60",
591 window_state->GetRestoreBoundsInScreen().ToString());
594 // Test if the restore bounds is correct in multiple displays.
595 if (!SupportsMultipleDisplays())
596 return;
598 // Restore the window to clear snapped state.
599 window_state->Restore();
601 UpdateDisplay("800x600,500x600");
602 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
603 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
604 // Window is wide enough not to get docked right away.
605 window_->SetBoundsInScreen(gfx::Rect(800, 10, 400, 60),
606 ScreenUtil::GetSecondaryDisplay());
607 EXPECT_EQ(root_windows[1], window_->GetRootWindow());
609 EXPECT_EQ("800,10 400x60", window_->GetBoundsInScreen().ToString());
611 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
612 window_.get(), gfx::Point(), HTCAPTION));
613 ASSERT_TRUE(resizer.get());
614 resizer->Drag(CalculateDragPoint(*resizer, 499, 0), 0);
615 int bottom =
616 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_.get()).bottom();
617 resizer->CompleteDrag();
618 // With the resolution of 500x600 we will hit in this case the 50% screen
619 // size setting.
620 // TODO(varkha): Insets are updated because of http://crbug.com/292238
621 EXPECT_EQ("250,0 250x" + base::IntToString(bottom),
622 window_->bounds().ToString());
623 EXPECT_EQ("800,10 400x60",
624 window_state->GetRestoreBoundsInScreen().ToString());
628 // Check that non resizable windows will not get resized.
629 TEST_F(WorkspaceWindowResizerTest, NonResizableWindows) {
630 window_->SetBounds(gfx::Rect(20, 30, 50, 60));
631 window_->SetProperty(aura::client::kCanResizeKey, false);
633 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
634 window_.get(), gfx::Point(), HTCAPTION));
635 ASSERT_TRUE(resizer.get());
636 resizer->Drag(CalculateDragPoint(*resizer, -20, 0), 0);
637 resizer->CompleteDrag();
638 EXPECT_EQ("0,30 50x60", window_->bounds().ToString());
641 TEST_F(WorkspaceWindowResizerTest, CancelSnapPhantom) {
642 if (!SupportsMultipleDisplays())
643 return;
645 UpdateDisplay("800x600,800x600");
646 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
647 ASSERT_EQ(2U, root_windows.size());
649 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
650 Shell::GetScreen()->GetPrimaryDisplay());
651 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
652 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
654 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
655 window_.get(), gfx::Point(), HTCAPTION));
656 ASSERT_TRUE(resizer.get());
657 EXPECT_FALSE(snap_phantom_window_controller());
659 // The pointer is on the edge but not shared. The snap phantom window
660 // controller should be non-NULL.
661 resizer->Drag(CalculateDragPoint(*resizer, 799, 0), 0);
662 EXPECT_TRUE(snap_phantom_window_controller());
664 // Move the cursor across the edge. Now the snap phantom window controller
665 // should be canceled.
666 resizer->Drag(CalculateDragPoint(*resizer, 800, 0), 0);
667 EXPECT_FALSE(snap_phantom_window_controller());
671 // Verifies that dragging a snapped window unsnaps it.
672 TEST_F(WorkspaceWindowResizerTest, DragSnapped) {
673 wm::WindowState* window_state = ash::wm::GetWindowState(window_.get());
675 const gfx::Rect kInitialBounds(100, 100, 100, 100);
676 window_->SetBounds(kInitialBounds);
677 window_->Show();
678 const wm::WMEvent snap_event(wm::WM_EVENT_SNAP_LEFT);
679 window_state->OnWMEvent(&snap_event);
680 EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType());
681 gfx::Rect snapped_bounds = window_->bounds();
682 EXPECT_NE(snapped_bounds.ToString(), kInitialBounds.ToString());
683 EXPECT_EQ(window_state->GetRestoreBoundsInParent().ToString(),
684 kInitialBounds.ToString());
686 // Dragging a side snapped window should unsnap it.
687 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
688 window_.get(), gfx::Point(), HTCAPTION));
689 resizer->Drag(CalculateDragPoint(*resizer, 10, 0), 0);
690 resizer->CompleteDrag();
691 EXPECT_EQ(wm::WINDOW_STATE_TYPE_NORMAL, window_state->GetStateType());
692 EXPECT_EQ("10,0 100x100", window_->bounds().ToString());
693 EXPECT_FALSE(window_state->HasRestoreBounds());
696 // Verifies the behavior of resizing a side snapped window.
697 TEST_F(WorkspaceWindowResizerTest, ResizeSnapped) {
698 wm::WindowState* window_state = ash::wm::GetWindowState(window_.get());
700 const gfx::Rect kInitialBounds(100, 100, 100, 100);
701 window_->SetBounds(kInitialBounds);
702 window_->Show();
704 const wm::WMEvent snap_event(wm::WM_EVENT_SNAP_LEFT);
705 window_state->OnWMEvent(&snap_event);
706 EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType());
707 gfx::Rect snapped_bounds = window_->bounds();
708 EXPECT_NE(snapped_bounds.ToString(), kInitialBounds.ToString());
709 EXPECT_EQ(window_state->GetRestoreBoundsInParent().ToString(),
710 kInitialBounds.ToString());
713 // 1) Resizing a side snapped window to make it wider should not unsnap the
714 // window.
715 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
716 window_.get(), gfx::Point(), HTRIGHT));
717 resizer->Drag(CalculateDragPoint(*resizer, 10, 0), 0);
718 resizer->CompleteDrag();
719 EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType());
720 snapped_bounds.Inset(0, 0, -10, 0);
721 EXPECT_EQ(snapped_bounds.ToString(), window_->bounds().ToString());
722 EXPECT_EQ(window_state->GetRestoreBoundsInParent().ToString(),
723 kInitialBounds.ToString());
727 // 2) Resizing a side snapped window vertically and then undoing the change
728 // should not unsnap.
729 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
730 window_.get(), gfx::Point(), HTBOTTOM));
731 resizer->Drag(CalculateDragPoint(*resizer, 0, -30), 0);
732 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
733 resizer->CompleteDrag();
734 EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType());
735 EXPECT_EQ(snapped_bounds.ToString(), window_->bounds().ToString());
736 EXPECT_EQ(window_state->GetRestoreBoundsInParent().ToString(),
737 kInitialBounds.ToString());
741 // 3) Resizing a side snapped window vertically and then not undoing the
742 // change should unsnap.
743 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
744 window_.get(), gfx::Point(), HTBOTTOM));
745 resizer->Drag(CalculateDragPoint(*resizer, 0, -10), 0);
746 resizer->CompleteDrag();
747 EXPECT_EQ(wm::WINDOW_STATE_TYPE_NORMAL, window_state->GetStateType());
748 gfx::Rect expected_bounds(snapped_bounds);
749 expected_bounds.Inset(0, 0, 0, 10);
750 EXPECT_EQ(expected_bounds.ToString(), window_->bounds().ToString());
751 EXPECT_FALSE(window_state->HasRestoreBounds());
755 // Verifies windows are correctly restacked when reordering multiple windows.
756 TEST_F(WorkspaceWindowResizerTest, RestackAttached) {
757 window_->SetBounds(gfx::Rect( 0, 0, 200, 300));
758 window2_->SetBounds(gfx::Rect(200, 0, 100, 200));
759 window3_->SetBounds(gfx::Rect(300, 0, 100, 100));
762 std::vector<aura::Window*> windows;
763 windows.push_back(window2_.get());
764 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
765 window_.get(), gfx::Point(), HTRIGHT,
766 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
767 ASSERT_TRUE(resizer.get());
768 // Move it 100 to the right, which should expand w1 and push w2 and w3.
769 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
771 // 2 should be topmost since it's initially the highest in the stack.
772 EXPECT_EQ("2 1 3", WindowOrderAsString(window_->parent()));
776 std::vector<aura::Window*> windows;
777 windows.push_back(window3_.get());
778 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
779 window2_.get(), gfx::Point(), HTRIGHT,
780 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
781 ASSERT_TRUE(resizer.get());
782 // Move it 100 to the right, which should expand w1 and push w2 and w3.
783 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
785 // 2 should be topmost since it's initially the highest in the stack.
786 EXPECT_EQ("2 3 1", WindowOrderAsString(window_->parent()));
790 // Makes sure we don't allow dragging below the work area.
791 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottom) {
792 Shell::GetInstance()->SetDisplayWorkAreaInsets(
793 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0));
795 ASSERT_EQ(1, Shell::GetScreen()->GetNumDisplays());
797 window_->SetBounds(gfx::Rect(100, 200, 300, 400));
798 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
799 window_.get(), gfx::Point(), HTCAPTION));
800 ASSERT_TRUE(resizer.get());
801 resizer->Drag(CalculateDragPoint(*resizer, 0, 600), 0);
802 int expected_y =
803 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10;
804 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400",
805 window_->bounds().ToString());
808 // Makes sure we don't allow dragging on the work area with multidisplay.
809 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottomWithMultiDisplay) {
810 if (!SupportsMultipleDisplays())
811 return;
813 UpdateDisplay("800x600,800x600");
814 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
816 Shell::GetInstance()->SetDisplayWorkAreaInsets(
817 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0));
819 // Positions the secondary display at the bottom the primary display.
820 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays(
821 ash::DisplayLayout(ash::DisplayLayout::BOTTOM, 0));
824 window_->SetBounds(gfx::Rect(100, 200, 300, 20));
825 DCHECK_LT(window_->bounds().height(),
826 WorkspaceWindowResizer::kMinOnscreenHeight);
827 // Drag down avoiding dragging along the edge as that would side-snap.
828 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
829 window_.get(), gfx::Point(10, 0), HTCAPTION));
830 ASSERT_TRUE(resizer.get());
831 resizer->Drag(CalculateDragPoint(*resizer, 0, 400), 0);
832 int expected_y = kRootHeight - window_->bounds().height() - 10;
833 // When the mouse cursor is in the primary display, the window cannot move
834 // on non-work area but can get all the way towards the bottom,
835 // restricted only by the window height.
836 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x20",
837 window_->bounds().ToString());
838 // Revert the drag in order to not remember the restore bounds.
839 resizer->RevertDrag();
842 Shell::GetInstance()->SetDisplayWorkAreaInsets(
843 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0));
845 window_->SetBounds(gfx::Rect(100, 200, 300, 400));
846 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
847 window_.get(), gfx::Point(10, 0), HTCAPTION));
848 ASSERT_TRUE(resizer.get());
849 // Drag down avoiding dragging along the edge as that would side-snap.
850 resizer->Drag(CalculateDragPoint(*resizer, 0, 400), 0);
851 int expected_y =
852 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10;
853 // When the mouse cursor is in the primary display, the window cannot move
854 // on non-work area with kMinOnscreenHeight margin.
855 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400",
856 window_->bounds().ToString());
857 resizer->CompleteDrag();
861 window_->SetBounds(gfx::Rect(100, 200, 300, 400));
862 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
863 window_.get(), window_->bounds().origin(), HTCAPTION));
864 ASSERT_TRUE(resizer.get());
865 // Drag down avoiding getting stuck against the shelf on the bottom screen.
866 resizer->Drag(CalculateDragPoint(*resizer, 0, 500), 0);
867 // The window can move to the secondary display beyond non-work area of
868 // the primary display.
869 EXPECT_EQ("100,700 300x400", window_->bounds().ToString());
870 resizer->CompleteDrag();
874 // Makes sure we don't allow dragging off the top of the work area.
875 TEST_F(WorkspaceWindowResizerTest, DontDragOffTop) {
876 Shell::GetInstance()->SetDisplayWorkAreaInsets(
877 Shell::GetPrimaryRootWindow(), gfx::Insets(10, 0, 0, 0));
879 window_->SetBounds(gfx::Rect(100, 200, 300, 400));
880 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
881 window_.get(), gfx::Point(), HTCAPTION));
882 ASSERT_TRUE(resizer.get());
883 resizer->Drag(CalculateDragPoint(*resizer, 0, -600), 0);
884 EXPECT_EQ("100,10 300x400", window_->bounds().ToString());
887 TEST_F(WorkspaceWindowResizerTest, ResizeBottomOutsideWorkArea) {
888 Shell::GetInstance()->SetDisplayWorkAreaInsets(
889 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
891 window_->SetBounds(gfx::Rect(100, 200, 300, 380));
892 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
893 window_.get(), gfx::Point(), HTTOP));
894 ASSERT_TRUE(resizer.get());
895 resizer->Drag(CalculateDragPoint(*resizer, 8, 0), 0);
896 EXPECT_EQ("100,200 300x380", window_->bounds().ToString());
899 TEST_F(WorkspaceWindowResizerTest, ResizeWindowOutsideLeftWorkArea) {
900 Shell::GetInstance()->SetDisplayWorkAreaInsets(
901 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
902 int left = ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_.get()).x();
903 int pixels_to_left_border = 50;
904 int window_width = 300;
905 int window_x = left - window_width + pixels_to_left_border;
906 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380));
907 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
908 window_.get(), gfx::Point(pixels_to_left_border, 0), HTRIGHT));
909 ASSERT_TRUE(resizer.get());
910 resizer->Drag(CalculateDragPoint(*resizer, -window_width, 0), 0);
911 EXPECT_EQ(base::IntToString(window_x) + ",100 " +
912 base::IntToString(kMinimumOnScreenArea - window_x) +
913 "x380", window_->bounds().ToString());
916 TEST_F(WorkspaceWindowResizerTest, ResizeWindowOutsideRightWorkArea) {
917 Shell::GetInstance()->SetDisplayWorkAreaInsets(
918 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
919 int right = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
920 window_.get()).right();
921 int pixels_to_right_border = 50;
922 int window_width = 300;
923 int window_x = right - pixels_to_right_border;
924 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380));
925 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
926 window_.get(), gfx::Point(window_x, 0), HTLEFT));
927 ASSERT_TRUE(resizer.get());
928 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0);
929 EXPECT_EQ(base::IntToString(right - kMinimumOnScreenArea) +
930 ",100 " +
931 base::IntToString(window_width - pixels_to_right_border +
932 kMinimumOnScreenArea) +
933 "x380", window_->bounds().ToString());
936 TEST_F(WorkspaceWindowResizerTest, ResizeWindowOutsideBottomWorkArea) {
937 Shell::GetInstance()->SetDisplayWorkAreaInsets(
938 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
939 int bottom = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
940 window_.get()).bottom();
941 int delta_to_bottom = 50;
942 int height = 380;
943 window_->SetBounds(gfx::Rect(100, bottom - delta_to_bottom, 300, height));
944 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
945 window_.get(), gfx::Point(0, bottom - delta_to_bottom), HTTOP));
946 ASSERT_TRUE(resizer.get());
947 resizer->Drag(CalculateDragPoint(*resizer, 0, bottom), 0);
948 EXPECT_EQ("100," +
949 base::IntToString(bottom - kMinimumOnScreenArea) +
950 " 300x" +
951 base::IntToString(height - (delta_to_bottom -
952 kMinimumOnScreenArea)),
953 window_->bounds().ToString());
956 // Verifies that 'outside' check of the resizer take into account the extended
957 // desktop in case of repositions.
958 TEST_F(WorkspaceWindowResizerTest, DragWindowOutsideRightToSecondaryDisplay) {
959 // Only primary display. Changes the window position to fit within the
960 // display.
961 Shell::GetInstance()->SetDisplayWorkAreaInsets(
962 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
963 int right = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
964 window_.get()).right();
965 int pixels_to_right_border = 50;
966 int window_width = 300;
967 int window_x = right - pixels_to_right_border;
968 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380));
969 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
970 window_.get(), gfx::Point(window_x, 0), HTCAPTION));
971 ASSERT_TRUE(resizer.get());
972 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0);
973 EXPECT_EQ(base::IntToString(right - kMinimumOnScreenArea) +
974 ",100 " +
975 base::IntToString(window_width) +
976 "x380", window_->bounds().ToString());
978 if (!SupportsMultipleDisplays())
979 return;
981 // With secondary display. Operation itself is same but doesn't change
982 // the position because the window is still within the secondary display.
983 UpdateDisplay("1000x600,600x400");
984 Shell::GetInstance()->SetDisplayWorkAreaInsets(
985 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
986 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380));
987 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0);
988 EXPECT_EQ(base::IntToString(window_x + window_width) +
989 ",100 " +
990 base::IntToString(window_width) +
991 "x380", window_->bounds().ToString());
994 // Verifies snapping to edges works.
995 TEST_F(WorkspaceWindowResizerTest, SnapToEdge) {
996 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()->
997 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
998 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
999 // Click 50px to the right so that the mouse pointer does not leave the
1000 // workspace ensuring sticky behavior.
1001 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1002 window_.get(),
1003 window_->bounds().origin() + gfx::Vector2d(50, 0),
1004 HTCAPTION));
1005 ASSERT_TRUE(resizer.get());
1006 // Move to an x-coordinate of 15, which should not snap.
1007 resizer->Drag(CalculateDragPoint(*resizer, 15 - 96, 0), 0);
1008 // An x-coordinate of 7 should snap.
1009 resizer->Drag(CalculateDragPoint(*resizer, 7 - 96, 0), 0);
1010 EXPECT_EQ("0,112 320x160", window_->bounds().ToString());
1011 // Move to -15, should still snap to 0.
1012 resizer->Drag(CalculateDragPoint(*resizer, -15 - 96, 0), 0);
1013 EXPECT_EQ("0,112 320x160", window_->bounds().ToString());
1014 // At -32 should move past snap points.
1015 resizer->Drag(CalculateDragPoint(*resizer, -32 - 96, 0), 0);
1016 EXPECT_EQ("-32,112 320x160", window_->bounds().ToString());
1017 resizer->Drag(CalculateDragPoint(*resizer, -33 - 96, 0), 0);
1018 EXPECT_EQ("-33,112 320x160", window_->bounds().ToString());
1020 // Right side should similarly snap.
1021 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 - 15, 0), 0);
1022 EXPECT_EQ("465,112 320x160", window_->bounds().ToString());
1023 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 - 7, 0), 0);
1024 EXPECT_EQ("480,112 320x160", window_->bounds().ToString());
1025 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 15, 0), 0);
1026 EXPECT_EQ("480,112 320x160", window_->bounds().ToString());
1027 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 32, 0), 0);
1028 EXPECT_EQ("512,112 320x160", window_->bounds().ToString());
1029 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 33, 0), 0);
1030 EXPECT_EQ("513,112 320x160", window_->bounds().ToString());
1032 // And the bottom should snap too.
1033 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 3 - 7), 0);
1034 EXPECT_EQ("96,437 320x160", window_->bounds().ToString());
1035 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 3 + 15), 0);
1036 EXPECT_EQ("96,437 320x160", window_->bounds().ToString());
1037 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 2 + 32), 0);
1038 EXPECT_EQ("96,470 320x160", window_->bounds().ToString());
1039 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 2 + 33), 0);
1040 EXPECT_EQ("96,471 320x160", window_->bounds().ToString());
1042 // And the top should snap too.
1043 resizer->Drag(CalculateDragPoint(*resizer, 0, -112 + 20), 0);
1044 EXPECT_EQ("96,20 320x160", window_->bounds().ToString());
1045 resizer->Drag(CalculateDragPoint(*resizer, 0, -112 + 7), 0);
1046 EXPECT_EQ("96,0 320x160", window_->bounds().ToString());
1048 // And bottom/left should snap too.
1049 resizer->Drag(
1050 CalculateDragPoint(*resizer, 7 - 96, 600 - 160 - 112 - 3 - 7), 0);
1051 EXPECT_EQ("0,437 320x160", window_->bounds().ToString());
1052 resizer->Drag(
1053 CalculateDragPoint(*resizer, -15 - 96, 600 - 160 - 112 - 3 + 15), 0);
1054 EXPECT_EQ("0,437 320x160", window_->bounds().ToString());
1055 // should move past snap points.
1056 resizer->Drag(
1057 CalculateDragPoint(*resizer, -32 - 96, 600 - 160 - 112 - 2 + 32), 0);
1058 EXPECT_EQ("-32,470 320x160", window_->bounds().ToString());
1059 resizer->Drag(
1060 CalculateDragPoint(*resizer, -33 - 96, 600 - 160 - 112 - 2 + 33), 0);
1061 EXPECT_EQ("-33,471 320x160", window_->bounds().ToString());
1063 // No need to test dragging < 0 as we force that to 0.
1066 // Verifies a resize snap when dragging TOPLEFT.
1067 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_TOPLEFT) {
1068 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1069 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1070 window_.get(), gfx::Point(), HTTOPLEFT));
1071 ASSERT_TRUE(resizer.get());
1072 resizer->Drag(CalculateDragPoint(*resizer, -98, -199), 0);
1073 EXPECT_EQ("0,0 120x230", window_->bounds().ToString());
1076 // Verifies a resize snap when dragging TOPRIGHT.
1077 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_TOPRIGHT) {
1078 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1079 gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
1080 window_.get()));
1081 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1082 window_.get(), gfx::Point(), HTTOPRIGHT));
1083 ASSERT_TRUE(resizer.get());
1084 resizer->Drag(
1085 CalculateDragPoint(*resizer, work_area.right() - 120 - 1, -199), 0);
1086 EXPECT_EQ(100, window_->bounds().x());
1087 EXPECT_EQ(work_area.y(), window_->bounds().y());
1088 EXPECT_EQ(work_area.right() - 100, window_->bounds().width());
1089 EXPECT_EQ(230, window_->bounds().height());
1092 // Verifies a resize snap when dragging BOTTOMRIGHT.
1093 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_BOTTOMRIGHT) {
1094 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1095 gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
1096 window_.get()));
1097 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1098 window_.get(), gfx::Point(), HTBOTTOMRIGHT));
1099 ASSERT_TRUE(resizer.get());
1100 resizer->Drag(
1101 CalculateDragPoint(*resizer, work_area.right() - 120 - 1,
1102 work_area.bottom() - 220 - 2), 0);
1103 EXPECT_EQ(100, window_->bounds().x());
1104 EXPECT_EQ(200, window_->bounds().y());
1105 EXPECT_EQ(work_area.right() - 100, window_->bounds().width());
1106 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
1109 // Verifies a resize snap when dragging BOTTOMLEFT.
1110 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_BOTTOMLEFT) {
1111 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1112 gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
1113 window_.get()));
1114 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1115 window_.get(), gfx::Point(), HTBOTTOMLEFT));
1116 ASSERT_TRUE(resizer.get());
1117 resizer->Drag(
1118 CalculateDragPoint(*resizer, -98, work_area.bottom() - 220 - 2), 0);
1119 EXPECT_EQ(0, window_->bounds().x());
1120 EXPECT_EQ(200, window_->bounds().y());
1121 EXPECT_EQ(120, window_->bounds().width());
1122 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
1125 // Verifies window sticks to both window and work area.
1126 TEST_F(WorkspaceWindowResizerTest, StickToBothEdgeAndWindow) {
1127 window_->SetBounds(gfx::Rect(10, 10, 20, 50));
1128 window_->Show();
1129 window2_->SetBounds(gfx::Rect(150, 160, 25, 1000));
1130 window2_->Show();
1132 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1133 window_.get(), gfx::Point(10, 10), HTCAPTION));
1134 ASSERT_TRUE(resizer.get());
1136 // Move |window| one pixel to the left of |window2|. Should snap to right.
1137 resizer->Drag(CalculateDragPoint(*resizer, 119, 145), 0);
1138 gfx::Rect expected(130, 160, 20, 50);
1139 EXPECT_EQ(expected.ToString(), window_->bounds().ToString());
1141 gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
1142 window_.get()));
1144 // The initial y position of |window_|.
1145 int initial_y = 10;
1146 // The drag position where the window is exactly attached to the bottom.
1147 int attach_y = work_area.bottom() - window_->bounds().height() - initial_y;
1149 // Dragging 10px above should not attach to the bottom.
1150 resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y - 10), 0);
1151 expected.set_y(attach_y + initial_y - 10);
1152 EXPECT_EQ(expected.ToString(), window_->bounds().ToString());
1154 // Stick to the work area.
1155 resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y - 1), 0);
1156 expected.set_y(attach_y + initial_y);
1157 EXPECT_EQ(expected.ToString(), window_->bounds().ToString());
1159 resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y), 0);
1160 expected.set_y(attach_y + initial_y);
1161 EXPECT_EQ(expected.ToString(), window_->bounds().ToString());
1163 resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y + 1), 0);
1164 expected.set_y(attach_y + initial_y);
1165 EXPECT_EQ(expected.ToString(), window_->bounds().ToString());
1167 // Moving down further should move the window.
1168 resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y + 18), 0);
1169 expected.set_y(attach_y + initial_y + 18);
1170 EXPECT_EQ(expected.ToString(), window_->bounds().ToString());
1173 TEST_F(WorkspaceWindowResizerTest, CtrlDragResizeToExactPosition) {
1174 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
1175 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1176 window_.get(), gfx::Point(), HTBOTTOMRIGHT));
1177 ASSERT_TRUE(resizer.get());
1178 // Resize the right bottom to add 10 in width, 12 in height.
1179 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), ui::EF_CONTROL_DOWN);
1180 // Both bottom and right sides to resize to exact size requested.
1181 EXPECT_EQ("96,112 330x172", window_->bounds().ToString());
1184 // Verifies that a dragged, non-snapped window will clear restore bounds.
1185 TEST_F(WorkspaceWindowResizerTest, RestoreClearedOnResize) {
1186 window_->SetBounds(gfx::Rect(10, 10, 100, 100));
1187 wm::WindowState* window_state = wm::GetWindowState(window_.get());
1188 window_state->SetRestoreBoundsInScreen(gfx::Rect(50, 50, 50, 50));
1189 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1190 window_.get(), gfx::Point(), HTBOTTOMRIGHT));
1191 ASSERT_TRUE(resizer.get());
1192 // Drag the window to new position by adding (20, 30) to original point,
1193 // the original restore bound should be cleared.
1194 resizer->Drag(CalculateDragPoint(*resizer, 20, 30), 0);
1195 resizer->CompleteDrag();
1196 EXPECT_EQ("10,10 120x130", window_->bounds().ToString());
1197 EXPECT_FALSE(window_state->HasRestoreBounds());
1200 // Verifies that a dragged window will restore to its pre-maximized size.
1201 TEST_F(WorkspaceWindowResizerTest, RestoreToPreMaximizeCoordinates) {
1202 window_->SetBounds(gfx::Rect(0, 0, 1000, 1000));
1203 wm::WindowState* window_state = wm::GetWindowState(window_.get());
1204 window_state->SetRestoreBoundsInScreen(gfx::Rect(96, 112, 320, 160));
1205 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1206 window_.get(), gfx::Point(), HTCAPTION));
1207 ASSERT_TRUE(resizer.get());
1208 // Drag the window to new position by adding (10, 10) to original point,
1209 // the window should get restored.
1210 resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0);
1211 resizer->CompleteDrag();
1212 EXPECT_EQ("10,10 320x160", window_->bounds().ToString());
1213 // The restore rectangle should get cleared as well.
1214 EXPECT_FALSE(window_state->HasRestoreBounds());
1217 // Verifies that a dragged window will restore to its pre-maximized size.
1218 TEST_F(WorkspaceWindowResizerTest, RevertResizeOperation) {
1219 const gfx::Rect initial_bounds(0, 0, 200, 400);
1220 window_->SetBounds(initial_bounds);
1222 wm::WindowState* window_state = wm::GetWindowState(window_.get());
1223 window_state->SetRestoreBoundsInScreen(gfx::Rect(96, 112, 320, 160));
1224 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1225 window_.get(), gfx::Point(), HTCAPTION));
1226 ASSERT_TRUE(resizer.get());
1227 // Drag the window to new poistion by adding (180, 16) to original point,
1228 // the window should get restored.
1229 resizer->Drag(CalculateDragPoint(*resizer, 180, 16), 0);
1230 resizer->RevertDrag();
1231 EXPECT_EQ(initial_bounds.ToString(), window_->bounds().ToString());
1232 EXPECT_EQ("96,112 320x160",
1233 window_state->GetRestoreBoundsInScreen().ToString());
1236 // Check that only usable sizes get returned by the resizer.
1237 TEST_F(WorkspaceWindowResizerTest, MagneticallyAttach) {
1238 window_->SetBounds(gfx::Rect(10, 10, 20, 30));
1239 window2_->SetBounds(gfx::Rect(150, 160, 25, 20));
1240 window2_->Show();
1242 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1243 window_.get(), gfx::Point(), HTCAPTION));
1244 ASSERT_TRUE(resizer.get());
1245 // Move |window| one pixel to the left of |window2|. Should snap to right and
1246 // top.
1247 resizer->Drag(CalculateDragPoint(*resizer, 119, 145), 0);
1248 EXPECT_EQ("130,160 20x30", window_->bounds().ToString());
1250 // Move |window| one pixel to the right of |window2|. Should snap to left and
1251 // top.
1252 resizer->Drag(CalculateDragPoint(*resizer, 164, 145), 0);
1253 EXPECT_EQ("175,160 20x30", window_->bounds().ToString());
1255 // Move |window| one pixel above |window2|. Should snap to top and left.
1256 resizer->Drag(CalculateDragPoint(*resizer, 142, 119), 0);
1257 EXPECT_EQ("150,130 20x30", window_->bounds().ToString());
1259 // Move |window| one pixel above the bottom of |window2|. Should snap to
1260 // bottom and left.
1261 resizer->Drag(CalculateDragPoint(*resizer, 142, 169), 0);
1262 EXPECT_EQ("150,180 20x30", window_->bounds().ToString());
1265 // The following variants verify magnetic snapping during resize when dragging a
1266 // particular edge.
1267 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_TOP) {
1268 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1269 window2_->SetBounds(gfx::Rect(99, 179, 10, 20));
1270 window2_->Show();
1272 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1273 window_.get(), gfx::Point(), HTTOP));
1274 ASSERT_TRUE(resizer.get());
1275 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1276 EXPECT_EQ("100,199 20x31", window_->bounds().ToString());
1279 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_TOPLEFT) {
1280 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1281 window2_->SetBounds(gfx::Rect(99, 179, 10, 20));
1282 window2_->Show();
1285 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1286 window_.get(), gfx::Point(), HTTOPLEFT));
1287 ASSERT_TRUE(resizer.get());
1288 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1289 EXPECT_EQ("99,199 21x31", window_->bounds().ToString());
1290 resizer->RevertDrag();
1294 window2_->SetBounds(gfx::Rect(88, 201, 10, 20));
1295 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1296 window_.get(), gfx::Point(), HTTOPLEFT));
1297 ASSERT_TRUE(resizer.get());
1298 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1299 EXPECT_EQ("98,201 22x29", window_->bounds().ToString());
1300 resizer->RevertDrag();
1304 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_TOPRIGHT) {
1305 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1306 window2_->Show();
1309 window2_->SetBounds(gfx::Rect(111, 179, 10, 20));
1310 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1311 window_.get(), gfx::Point(), HTTOPRIGHT));
1312 ASSERT_TRUE(resizer.get());
1313 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1314 EXPECT_EQ("100,199 21x31", window_->bounds().ToString());
1315 resizer->RevertDrag();
1319 window2_->SetBounds(gfx::Rect(121, 199, 10, 20));
1320 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1321 window_.get(), gfx::Point(), HTTOPRIGHT));
1322 ASSERT_TRUE(resizer.get());
1323 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1324 EXPECT_EQ("100,199 21x31", window_->bounds().ToString());
1325 resizer->RevertDrag();
1329 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_RIGHT) {
1330 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1331 window2_->SetBounds(gfx::Rect(121, 199, 10, 20));
1332 window2_->Show();
1334 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1335 window_.get(), gfx::Point(), HTRIGHT));
1336 ASSERT_TRUE(resizer.get());
1337 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1338 EXPECT_EQ("100,200 21x30", window_->bounds().ToString());
1341 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_BOTTOMRIGHT) {
1342 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1343 window2_->Show();
1346 window2_->SetBounds(gfx::Rect(122, 212, 10, 20));
1347 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1348 window_.get(), gfx::Point(), HTBOTTOMRIGHT));
1349 ASSERT_TRUE(resizer.get());
1350 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1351 EXPECT_EQ("100,200 22x32", window_->bounds().ToString());
1352 resizer->RevertDrag();
1356 window2_->SetBounds(gfx::Rect(111, 233, 10, 20));
1357 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1358 window_.get(), gfx::Point(), HTBOTTOMRIGHT));
1359 ASSERT_TRUE(resizer.get());
1360 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1361 EXPECT_EQ("100,200 21x33", window_->bounds().ToString());
1362 resizer->RevertDrag();
1366 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_BOTTOM) {
1367 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1368 window2_->SetBounds(gfx::Rect(111, 233, 10, 20));
1369 window2_->Show();
1371 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1372 window_.get(), gfx::Point(), HTBOTTOM));
1373 ASSERT_TRUE(resizer.get());
1374 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1375 EXPECT_EQ("100,200 20x33", window_->bounds().ToString());
1378 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_BOTTOMLEFT) {
1379 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1380 window2_->Show();
1383 window2_->SetBounds(gfx::Rect(99, 231, 10, 20));
1384 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1385 window_.get(), gfx::Point(), HTBOTTOMLEFT));
1386 ASSERT_TRUE(resizer.get());
1387 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1388 EXPECT_EQ("99,200 21x31", window_->bounds().ToString());
1389 resizer->RevertDrag();
1393 window2_->SetBounds(gfx::Rect(89, 209, 10, 20));
1394 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1395 window_.get(), gfx::Point(), HTBOTTOMLEFT));
1396 ASSERT_TRUE(resizer.get());
1397 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1398 EXPECT_EQ("99,200 21x29", window_->bounds().ToString());
1399 resizer->RevertDrag();
1403 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_LEFT) {
1404 window2_->SetBounds(gfx::Rect(89, 209, 10, 20));
1405 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1406 window2_->Show();
1408 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1409 window_.get(), gfx::Point(), HTLEFT));
1410 ASSERT_TRUE(resizer.get());
1411 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1412 EXPECT_EQ("99,200 21x30", window_->bounds().ToString());
1415 // Test that the user user moved window flag is getting properly set.
1416 TEST_F(WorkspaceWindowResizerTest, CheckUserWindowManagedFlags) {
1417 window_->SetBounds(gfx::Rect( 0, 50, 400, 200));
1419 std::vector<aura::Window*> no_attached_windows;
1420 // Check that an abort doesn't change anything.
1422 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1423 window_.get(), gfx::Point(), HTCAPTION));
1424 ASSERT_TRUE(resizer.get());
1425 // Move it 100 to the bottom.
1426 resizer->Drag(CalculateDragPoint(*resizer, 0, 100), 0);
1427 EXPECT_EQ("0,150 400x200", window_->bounds().ToString());
1428 resizer->RevertDrag();
1430 EXPECT_FALSE(wm::GetWindowState(window_.get())->bounds_changed_by_user());
1433 // Check that a completed move / size does change the user coordinates.
1435 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1436 window_.get(), gfx::Point(), HTCAPTION));
1437 ASSERT_TRUE(resizer.get());
1438 // Move it 100 to the bottom.
1439 resizer->Drag(CalculateDragPoint(*resizer, 0, 100), 0);
1440 EXPECT_EQ("0,150 400x200", window_->bounds().ToString());
1441 resizer->CompleteDrag();
1442 EXPECT_TRUE(wm::GetWindowState(window_.get())->bounds_changed_by_user());
1446 // Test that a window with a specified max size doesn't exceed it when dragged.
1447 TEST_F(WorkspaceWindowResizerTest, TestMaxSizeEnforced) {
1448 window_->SetBounds(gfx::Rect(0, 0, 400, 300));
1449 delegate_.set_max_size(gfx::Size(401, 301));
1451 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1452 window_.get(), gfx::Point(), HTBOTTOMRIGHT));
1453 resizer->Drag(CalculateDragPoint(*resizer, 2, 2), 0);
1454 EXPECT_EQ(401, window_->bounds().width());
1455 EXPECT_EQ(301, window_->bounds().height());
1458 // Test that a window with a specified max width doesn't restrict its height.
1459 TEST_F(WorkspaceWindowResizerTest, TestPartialMaxSizeEnforced) {
1460 window_->SetBounds(gfx::Rect(0, 0, 400, 300));
1461 delegate_.set_max_size(gfx::Size(401, 0));
1463 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1464 window_.get(), gfx::Point(), HTBOTTOMRIGHT));
1465 resizer->Drag(CalculateDragPoint(*resizer, 2, 2), 0);
1466 EXPECT_EQ(401, window_->bounds().width());
1467 EXPECT_EQ(302, window_->bounds().height());
1470 // Test that a window with a specified max size can't be snapped.
1471 TEST_F(WorkspaceWindowResizerTest, PhantomSnapMaxSize) {
1473 // With max size not set we get a phantom window controller for dragging off
1474 // the right hand side.
1475 // Make the window wider than maximum docked width.
1476 window_->SetBounds(gfx::Rect(0, 0, 400, 200));
1478 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1479 window_.get(), gfx::Point(), HTCAPTION));
1480 EXPECT_FALSE(snap_phantom_window_controller());
1481 resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0);
1482 EXPECT_TRUE(snap_phantom_window_controller());
1483 resizer->RevertDrag();
1486 // With max size defined, we get no phantom window for snapping but we still
1487 // get a phantom window (docking guide).
1488 window_->SetBounds(gfx::Rect(0, 0, 400, 200));
1489 delegate_.set_max_size(gfx::Size(400, 200));
1491 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1492 window_.get(), gfx::Point(), HTCAPTION));
1493 resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0);
1494 EXPECT_TRUE(snap_phantom_window_controller());
1495 resizer->RevertDrag();
1498 // With max size defined, we get no phantom window for snapping.
1499 window_->SetBounds(gfx::Rect(0, 0, 400, 200));
1500 delegate_.set_max_size(gfx::Size(400, 200));
1501 // With min size defined, we get no phantom window for docking.
1502 delegate_.set_min_size(gfx::Size(400, 200));
1504 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1505 window_.get(), gfx::Point(), HTCAPTION));
1506 resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0);
1507 EXPECT_FALSE(snap_phantom_window_controller());
1508 resizer->RevertDrag();
1512 TEST_F(WorkspaceWindowResizerTest, DontRewardRightmostWindowForOverflows) {
1513 UpdateDisplay("600x800");
1514 aura::Window* root = Shell::GetPrimaryRootWindow();
1515 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1517 // Four 100x100 windows flush against eachother, starting at 100,100.
1518 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1519 window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
1520 window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
1521 window4_->SetBounds(gfx::Rect(400, 100, 100, 100));
1522 delegate2_.set_max_size(gfx::Size(101, 0));
1524 std::vector<aura::Window*> windows;
1525 windows.push_back(window2_.get());
1526 windows.push_back(window3_.get());
1527 windows.push_back(window4_.get());
1528 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
1529 window_.get(), gfx::Point(), HTRIGHT,
1530 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1531 ASSERT_TRUE(resizer.get());
1532 // Move it 51 to the left, which should contract w1 and expand w2-4.
1533 // w2 will hit its max size straight away, and in doing so will leave extra
1534 // pixels that a naive implementation may award to the rightmost window. A
1535 // fair implementation will give 25 pixels to each of the other windows.
1536 resizer->Drag(CalculateDragPoint(*resizer, -51, 0), 0);
1537 EXPECT_EQ("100,100 49x100", window_->bounds().ToString());
1538 EXPECT_EQ("149,100 101x100", window2_->bounds().ToString());
1539 EXPECT_EQ("250,100 125x100", window3_->bounds().ToString());
1540 EXPECT_EQ("375,100 125x100", window4_->bounds().ToString());
1543 TEST_F(WorkspaceWindowResizerTest, DontExceedMaxWidth) {
1544 UpdateDisplay("600x800");
1545 aura::Window* root = Shell::GetPrimaryRootWindow();
1546 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1548 // Four 100x100 windows flush against eachother, starting at 100,100.
1549 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1550 window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
1551 window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
1552 window4_->SetBounds(gfx::Rect(400, 100, 100, 100));
1553 delegate2_.set_max_size(gfx::Size(101, 0));
1554 delegate3_.set_max_size(gfx::Size(101, 0));
1556 std::vector<aura::Window*> windows;
1557 windows.push_back(window2_.get());
1558 windows.push_back(window3_.get());
1559 windows.push_back(window4_.get());
1560 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
1561 window_.get(), gfx::Point(), HTRIGHT,
1562 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1563 ASSERT_TRUE(resizer.get());
1564 // Move it 52 to the left, which should contract w1 and expand w2-4.
1565 resizer->Drag(CalculateDragPoint(*resizer, -52, 0), 0);
1566 EXPECT_EQ("100,100 48x100", window_->bounds().ToString());
1567 EXPECT_EQ("148,100 101x100", window2_->bounds().ToString());
1568 EXPECT_EQ("249,100 101x100", window3_->bounds().ToString());
1569 EXPECT_EQ("350,100 150x100", window4_->bounds().ToString());
1572 TEST_F(WorkspaceWindowResizerTest, DontExceedMaxHeight) {
1573 UpdateDisplay("600x800");
1574 aura::Window* root = Shell::GetPrimaryRootWindow();
1575 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1577 // Four 100x100 windows flush against eachother, starting at 100,100.
1578 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1579 window2_->SetBounds(gfx::Rect(100, 200, 100, 100));
1580 window3_->SetBounds(gfx::Rect(100, 300, 100, 100));
1581 window4_->SetBounds(gfx::Rect(100, 400, 100, 100));
1582 delegate2_.set_max_size(gfx::Size(0, 101));
1583 delegate3_.set_max_size(gfx::Size(0, 101));
1585 std::vector<aura::Window*> windows;
1586 windows.push_back(window2_.get());
1587 windows.push_back(window3_.get());
1588 windows.push_back(window4_.get());
1589 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
1590 window_.get(), gfx::Point(), HTBOTTOM,
1591 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1592 ASSERT_TRUE(resizer.get());
1593 // Move it 52 up, which should contract w1 and expand w2-4.
1594 resizer->Drag(CalculateDragPoint(*resizer, 0, -52), 0);
1595 EXPECT_EQ("100,100 100x48", window_->bounds().ToString());
1596 EXPECT_EQ("100,148 100x101", window2_->bounds().ToString());
1597 EXPECT_EQ("100,249 100x101", window3_->bounds().ToString());
1598 EXPECT_EQ("100,350 100x150", window4_->bounds().ToString());
1601 #if defined(OS_WIN)
1602 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
1603 #define MAYBE_DontExceedMinHeight DISABLED_DontExceedMinHeight
1604 #else
1605 #define MAYBE_DontExceedMinHeight DontExceedMinHeight
1606 #endif
1608 TEST_F(WorkspaceWindowResizerTest, MAYBE_DontExceedMinHeight) {
1609 UpdateDisplay("600x500");
1610 aura::Window* root = Shell::GetPrimaryRootWindow();
1611 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1613 // Four 100x100 windows flush against eachother, starting at 100,100.
1614 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1615 window2_->SetBounds(gfx::Rect(100, 200, 100, 100));
1616 window3_->SetBounds(gfx::Rect(100, 300, 100, 100));
1617 window4_->SetBounds(gfx::Rect(100, 400, 100, 100));
1618 delegate2_.set_min_size(gfx::Size(0, 99));
1619 delegate3_.set_min_size(gfx::Size(0, 99));
1621 std::vector<aura::Window*> windows;
1622 windows.push_back(window2_.get());
1623 windows.push_back(window3_.get());
1624 windows.push_back(window4_.get());
1625 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
1626 window_.get(), gfx::Point(), HTBOTTOM,
1627 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1628 ASSERT_TRUE(resizer.get());
1629 // Move it 52 down, which should expand w1 and contract w2-4.
1630 resizer->Drag(CalculateDragPoint(*resizer, 0, 52), 0);
1631 EXPECT_EQ("100,100 100x152", window_->bounds().ToString());
1632 EXPECT_EQ("100,252 100x99", window2_->bounds().ToString());
1633 EXPECT_EQ("100,351 100x99", window3_->bounds().ToString());
1634 EXPECT_EQ("100,450 100x50", window4_->bounds().ToString());
1637 TEST_F(WorkspaceWindowResizerTest, DontExpandRightmostPastMaxWidth) {
1638 UpdateDisplay("600x800");
1639 aura::Window* root = Shell::GetPrimaryRootWindow();
1640 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1642 // Three 100x100 windows flush against eachother, starting at 100,100.
1643 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1644 window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
1645 window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
1646 delegate3_.set_max_size(gfx::Size(101, 0));
1648 std::vector<aura::Window*> windows;
1649 windows.push_back(window2_.get());
1650 windows.push_back(window3_.get());
1651 windows.push_back(window4_.get());
1652 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
1653 window_.get(), gfx::Point(), HTRIGHT,
1654 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1655 ASSERT_TRUE(resizer.get());
1656 // Move it 51 to the left, which should contract w1 and expand w2-3.
1657 resizer->Drag(CalculateDragPoint(*resizer, -51, 0), 0);
1658 EXPECT_EQ("100,100 49x100", window_->bounds().ToString());
1659 EXPECT_EQ("149,100 150x100", window2_->bounds().ToString());
1660 EXPECT_EQ("299,100 101x100", window3_->bounds().ToString());
1663 TEST_F(WorkspaceWindowResizerTest, MoveAttachedWhenGrownToMaxSize) {
1664 UpdateDisplay("600x800");
1665 aura::Window* root = Shell::GetPrimaryRootWindow();
1666 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1668 // Three 100x100 windows flush against eachother, starting at 100,100.
1669 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1670 window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
1671 window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
1672 delegate2_.set_max_size(gfx::Size(101, 0));
1673 delegate3_.set_max_size(gfx::Size(101, 0));
1675 std::vector<aura::Window*> windows;
1676 windows.push_back(window2_.get());
1677 windows.push_back(window3_.get());
1678 windows.push_back(window4_.get());
1679 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
1680 window_.get(), gfx::Point(), HTRIGHT,
1681 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1682 ASSERT_TRUE(resizer.get());
1683 // Move it 52 to the left, which should contract w1 and expand and move w2-3.
1684 resizer->Drag(CalculateDragPoint(*resizer, -52, 0), 0);
1685 EXPECT_EQ("100,100 48x100", window_->bounds().ToString());
1686 EXPECT_EQ("148,100 101x100", window2_->bounds().ToString());
1687 EXPECT_EQ("249,100 101x100", window3_->bounds().ToString());
1690 #if defined(OS_WIN)
1691 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
1692 #define MAYBE_MainWindowHonoursMaxWidth DISABLED_MainWindowHonoursMaxWidth
1693 #else
1694 #define MAYBE_MainWindowHonoursMaxWidth MainWindowHonoursMaxWidth
1695 #endif
1697 TEST_F(WorkspaceWindowResizerTest, MAYBE_MainWindowHonoursMaxWidth) {
1698 UpdateDisplay("400x800");
1699 aura::Window* root = Shell::GetPrimaryRootWindow();
1700 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1702 // Three 100x100 windows flush against eachother, starting at 100,100.
1703 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1704 window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
1705 window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
1706 delegate_.set_max_size(gfx::Size(102, 0));
1708 std::vector<aura::Window*> windows;
1709 windows.push_back(window2_.get());
1710 windows.push_back(window3_.get());
1711 windows.push_back(window4_.get());
1712 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
1713 window_.get(), gfx::Point(), HTRIGHT,
1714 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1715 ASSERT_TRUE(resizer.get());
1716 // Move it 50 to the right, which should expand w1 and contract w2-3, as they
1717 // won't fit in the root window in their original sizes.
1718 resizer->Drag(CalculateDragPoint(*resizer, 50, 0), 0);
1719 EXPECT_EQ("100,100 102x100", window_->bounds().ToString());
1720 EXPECT_EQ("202,100 99x100", window2_->bounds().ToString());
1721 EXPECT_EQ("301,100 99x100", window3_->bounds().ToString());
1724 TEST_F(WorkspaceWindowResizerTest, MainWindowHonoursMinWidth) {
1725 UpdateDisplay("400x800");
1726 aura::Window* root = Shell::GetPrimaryRootWindow();
1727 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1729 // Three 100x100 windows flush against eachother, starting at 100,100.
1730 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1731 window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
1732 window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
1733 delegate_.set_min_size(gfx::Size(98, 0));
1735 std::vector<aura::Window*> windows;
1736 windows.push_back(window2_.get());
1737 windows.push_back(window3_.get());
1738 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
1739 window_.get(), gfx::Point(), HTRIGHT,
1740 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1741 ASSERT_TRUE(resizer.get());
1742 // Move it 50 to the left, which should contract w1 and expand w2-3.
1743 resizer->Drag(CalculateDragPoint(*resizer, -50, 0), 0);
1744 EXPECT_EQ("100,100 98x100", window_->bounds().ToString());
1745 EXPECT_EQ("198,100 101x100", window2_->bounds().ToString());
1746 EXPECT_EQ("299,100 101x100", window3_->bounds().ToString());
1749 // The following variants test that windows are resized correctly to the edges
1750 // of the screen using touch, when touch point is off of the window border.
1751 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_RIGHT) {
1752 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1754 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTRIGHT);
1755 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
1756 touch_resize_window_->bounds().ToString());
1758 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1759 touch_resize_window_.get());
1761 // Drag out of the right border a bit and check if the border is aligned with
1762 // the touch point.
1763 generator.GestureScrollSequence(gfx::Point(715, kRootHeight / 2),
1764 gfx::Point(725, kRootHeight / 2),
1765 base::TimeDelta::FromMilliseconds(10),
1767 EXPECT_EQ(gfx::Rect(100, 100, 625, kRootHeight - 200).ToString(),
1768 touch_resize_window_->bounds().ToString());
1769 // Drag more, but stop before being snapped to the edge.
1770 generator.GestureScrollSequence(gfx::Point(725, kRootHeight / 2),
1771 gfx::Point(760, kRootHeight / 2),
1772 base::TimeDelta::FromMilliseconds(10),
1774 EXPECT_EQ(gfx::Rect(100, 100, 660, kRootHeight - 200).ToString(),
1775 touch_resize_window_->bounds().ToString());
1776 // Drag even more to snap to the edge.
1777 generator.GestureScrollSequence(gfx::Point(760, kRootHeight / 2),
1778 gfx::Point(775, kRootHeight / 2),
1779 base::TimeDelta::FromMilliseconds(10),
1781 EXPECT_EQ(gfx::Rect(100, 100, 700, kRootHeight - 200).ToString(),
1782 touch_resize_window_->bounds().ToString());
1785 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_LEFT) {
1786 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1788 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTLEFT);
1789 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
1790 touch_resize_window_->bounds().ToString());
1792 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1793 touch_resize_window_.get());
1795 // Drag out of the left border a bit and check if the border is aligned with
1796 // the touch point.
1797 generator.GestureScrollSequence(gfx::Point(85, kRootHeight / 2),
1798 gfx::Point(75, kRootHeight / 2),
1799 base::TimeDelta::FromMilliseconds(10),
1801 EXPECT_EQ(gfx::Rect(75, 100, 625, kRootHeight - 200).ToString(),
1802 touch_resize_window_->bounds().ToString());
1803 // Drag more, but stop before being snapped to the edge.
1804 generator.GestureScrollSequence(gfx::Point(75, kRootHeight / 2),
1805 gfx::Point(40, kRootHeight / 2),
1806 base::TimeDelta::FromMilliseconds(10),
1808 EXPECT_EQ(gfx::Rect(40, 100, 660, kRootHeight - 200).ToString(),
1809 touch_resize_window_->bounds().ToString());
1810 // Drag even more to snap to the edge.
1811 generator.GestureScrollSequence(gfx::Point(40, kRootHeight / 2),
1812 gfx::Point(25, kRootHeight / 2),
1813 base::TimeDelta::FromMilliseconds(10),
1815 EXPECT_EQ(gfx::Rect(0, 100, 700, kRootHeight - 200).ToString(),
1816 touch_resize_window_->bounds().ToString());
1819 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_TOP) {
1820 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1822 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTTOP);
1823 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
1824 touch_resize_window_->bounds().ToString());
1826 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1827 touch_resize_window_.get());
1829 // Drag out of the top border a bit and check if the border is aligned with
1830 // the touch point.
1831 generator.GestureScrollSequence(gfx::Point(400, 85),
1832 gfx::Point(400, 75),
1833 base::TimeDelta::FromMilliseconds(10),
1835 EXPECT_EQ(gfx::Rect(100, 75, 600, kRootHeight - 175).ToString(),
1836 touch_resize_window_->bounds().ToString());
1837 // Drag more, but stop before being snapped to the edge.
1838 generator.GestureScrollSequence(gfx::Point(400, 75),
1839 gfx::Point(400, 40),
1840 base::TimeDelta::FromMilliseconds(10),
1842 EXPECT_EQ(gfx::Rect(100, 40, 600, kRootHeight - 140).ToString(),
1843 touch_resize_window_->bounds().ToString());
1844 // Drag even more to snap to the edge.
1845 generator.GestureScrollSequence(gfx::Point(400, 40),
1846 gfx::Point(400, 25),
1847 base::TimeDelta::FromMilliseconds(10),
1849 EXPECT_EQ(gfx::Rect(100, 0, 600, kRootHeight - 100).ToString(),
1850 touch_resize_window_->bounds().ToString());
1853 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_BOTTOM) {
1854 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1856 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTBOTTOM);
1857 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
1858 touch_resize_window_->bounds().ToString());
1860 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1861 touch_resize_window_.get());
1863 // Drag out of the bottom border a bit and check if the border is aligned with
1864 // the touch point.
1865 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 85),
1866 gfx::Point(400, kRootHeight - 75),
1867 base::TimeDelta::FromMilliseconds(10),
1869 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 175).ToString(),
1870 touch_resize_window_->bounds().ToString());
1871 // Drag more, but stop before being snapped to the edge.
1872 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 75),
1873 gfx::Point(400, kRootHeight - 40),
1874 base::TimeDelta::FromMilliseconds(10),
1876 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 140).ToString(),
1877 touch_resize_window_->bounds().ToString());
1878 // Drag even more to snap to the edge.
1879 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 40),
1880 gfx::Point(400, kRootHeight - 25),
1881 base::TimeDelta::FromMilliseconds(10),
1883 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 100).ToString(),
1884 touch_resize_window_->bounds().ToString());
1887 } // namespace ash