Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / ash / wm / workspace / workspace_window_resizer_unittest.cc
blob359d0b67a184d4b507dd139916c4c14f1d9d1ef8
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"
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 ~TestWindowDelegate() override {}
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 gfx::Size GetMinimumSize() const override { return min_size_; }
56 gfx::Size GetMaximumSize() const override { return max_size_; }
58 gfx::Size min_size_;
59 gfx::Size max_size_;
61 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate);
64 } // namespace
66 class WorkspaceWindowResizerTest : public test::AshTestBase {
67 public:
68 WorkspaceWindowResizerTest() : workspace_resizer_(NULL) {}
69 ~WorkspaceWindowResizerTest() override {}
71 void SetUp() override {
72 AshTestBase::SetUp();
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());
80 #if defined(OS_WIN)
81 // RootWindow and Display can't resize on Windows Ash.
82 // http://crbug.com/165962
83 EXPECT_EQ(kRootHeight, root_bounds.height());
84 #endif
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(ui::LAYER_NOT_DRAWN);
90 ParentWindowInPrimaryRootWindow(window_.get());
91 window_->set_id(1);
93 window2_.reset(new aura::Window(&delegate2_));
94 window2_->SetType(ui::wm::WINDOW_TYPE_NORMAL);
95 window2_->Init(ui::LAYER_NOT_DRAWN);
96 ParentWindowInPrimaryRootWindow(window2_.get());
97 window2_->set_id(2);
99 window3_.reset(new aura::Window(&delegate3_));
100 window3_->SetType(ui::wm::WINDOW_TYPE_NORMAL);
101 window3_->Init(ui::LAYER_NOT_DRAWN);
102 ParentWindowInPrimaryRootWindow(window3_.get());
103 window3_->set_id(3);
105 window4_.reset(new aura::Window(&delegate4_));
106 window4_->SetType(ui::wm::WINDOW_TYPE_NORMAL);
107 window4_->Init(ui::LAYER_NOT_DRAWN);
108 ParentWindowInPrimaryRootWindow(window4_.get());
109 window4_->set_id(4);
112 void TearDown() override {
113 window_.reset();
114 window2_.reset();
115 window3_.reset();
116 window4_.reset();
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 {
125 std::string result;
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_) {
130 if (!result.empty())
131 result += " ";
132 result += base::IntToString((*i)->id());
135 return result;
138 protected:
139 WindowResizer* CreateResizerForTest(
140 aura::Window* window,
141 const gfx::Point& point_in_parent,
142 int window_component) {
143 WindowResizer* resizer = CreateWindowResizer(
144 window,
145 point_in_parent,
146 window_component,
147 aura::client::WINDOW_MOVE_SOURCE_MOUSE).release();
148 workspace_resizer_ = WorkspaceWindowResizer::GetInstanceForTest();
149 return resizer;
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,
168 int delta_x,
169 int delta_y) const {
170 gfx::Point location = resizer.GetInitialLocation();
171 location.set_x(location.x() + delta_x);
172 location.set_y(location.y() + delta_y);
173 return location;
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,
188 bounds));
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_;
204 private:
205 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest);
208 // Assertions around attached window resize dragging from the right with 2
209 // windows.
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(25, 25));
261 resizer->Drag(CalculateDragPoint(*resizer, -800, 25), 0);
262 EXPECT_EQ("0,300 25x300", window_->bounds().ToString());
263 EXPECT_EQ("25,200 475x200", window2_->bounds().ToString());
265 // But should keep minimum visible width;
266 resizer->Drag(CalculateDragPoint(*resizer, -800, 20), 0);
267 EXPECT_EQ("0,300 25x300", window_->bounds().ToString());
268 EXPECT_EQ("25,200 475x200", window2_->bounds().ToString());
270 // Move 100 to the left.
271 resizer->Drag(CalculateDragPoint(*resizer, 100, 10), 0);
272 EXPECT_EQ("0,300 500x300", window_->bounds().ToString());
273 EXPECT_EQ("500,200 100x200", window2_->bounds().ToString());
275 // Back to -100.
276 resizer->Drag(CalculateDragPoint(*resizer, -100, 20), 0);
277 EXPECT_EQ("0,300 300x300", window_->bounds().ToString());
278 EXPECT_EQ("300,200 200x200", window2_->bounds().ToString());
281 // Assertions around attached window resize dragging from the right with 3
282 // windows.
283 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_3) {
284 window_->SetBounds(gfx::Rect( 100, 300, 200, 300));
285 window2_->SetBounds(gfx::Rect(300, 300, 150, 200));
286 window3_->SetBounds(gfx::Rect(450, 300, 100, 200));
287 delegate2_.set_min_size(gfx::Size(52, 50));
288 delegate3_.set_min_size(gfx::Size(38, 50));
290 std::vector<aura::Window*> windows;
291 windows.push_back(window2_.get());
292 windows.push_back(window3_.get());
293 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
294 window_.get(), gfx::Point(), HTRIGHT,
295 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
296 ASSERT_TRUE(resizer.get());
297 // Move it 100 to the right, which should expand w1 and push w2 and w3.
298 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
299 EXPECT_EQ("100,300 300x300", window_->bounds().ToString());
300 EXPECT_EQ("400,300 150x200", window2_->bounds().ToString());
301 EXPECT_EQ("550,300 100x200", window3_->bounds().ToString());
303 // Move it 300, things should compress.
304 resizer->Drag(CalculateDragPoint(*resizer, 300, -10), 0);
305 EXPECT_EQ("100,300 500x300", window_->bounds().ToString());
306 EXPECT_EQ("600,300 120x200", window2_->bounds().ToString());
307 EXPECT_EQ("720,300 80x200", window3_->bounds().ToString());
309 // Move it so much the last two end up at their min.
310 resizer->Drag(CalculateDragPoint(*resizer, 800, 50), 0);
311 EXPECT_EQ("100,300 610x300", window_->bounds().ToString());
312 EXPECT_EQ("710,300 52x200", window2_->bounds().ToString());
313 EXPECT_EQ("762,300 38x200", window3_->bounds().ToString());
315 // Revert and make sure everything moves back.
316 resizer->RevertDrag();
317 EXPECT_EQ("100,300 200x300", window_->bounds().ToString());
318 EXPECT_EQ("300,300 150x200", window2_->bounds().ToString());
319 EXPECT_EQ("450,300 100x200", window3_->bounds().ToString());
322 // Assertions around attached window resizing (collapsing and expanding) with
323 // 3 windows.
324 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_3_Compress) {
325 window_->SetBounds(gfx::Rect( 100, 300, 200, 300));
326 window2_->SetBounds(gfx::Rect(300, 300, 200, 200));
327 window3_->SetBounds(gfx::Rect(450, 300, 100, 200));
328 delegate2_.set_min_size(gfx::Size(52, 50));
329 delegate3_.set_min_size(gfx::Size(38, 50));
331 std::vector<aura::Window*> windows;
332 windows.push_back(window2_.get());
333 windows.push_back(window3_.get());
334 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
335 window_.get(), gfx::Point(), HTRIGHT,
336 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
337 ASSERT_TRUE(resizer.get());
338 // Move it -100 to the right, which should collapse w1 and expand w2 and w3.
339 resizer->Drag(CalculateDragPoint(*resizer, -100, -10), 0);
340 EXPECT_EQ("100,300 100x300", window_->bounds().ToString());
341 EXPECT_EQ("200,300 266x200", window2_->bounds().ToString());
342 EXPECT_EQ("466,300 134x200", window3_->bounds().ToString());
344 // Move it 100 to the right.
345 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
346 EXPECT_EQ("100,300 300x300", window_->bounds().ToString());
347 EXPECT_EQ("400,300 200x200", window2_->bounds().ToString());
348 EXPECT_EQ("600,300 100x200", window3_->bounds().ToString());
350 // 100 to the left again.
351 resizer->Drag(CalculateDragPoint(*resizer, -100, -10), 0);
352 EXPECT_EQ("100,300 100x300", window_->bounds().ToString());
353 EXPECT_EQ("200,300 266x200", window2_->bounds().ToString());
354 EXPECT_EQ("466,300 134x200", window3_->bounds().ToString());
357 // Assertions around collapsing and expanding from the bottom.
358 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_Compress) {
359 window_->SetBounds(gfx::Rect( 0, 100, 400, 300));
360 window2_->SetBounds(gfx::Rect(400, 400, 100, 200));
362 std::vector<aura::Window*> windows;
363 windows.push_back(window2_.get());
364 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
365 window_.get(), gfx::Point(), HTBOTTOM,
366 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
367 ASSERT_TRUE(resizer.get());
368 // Move it up 100, which should expand w2 and collapse w1.
369 resizer->Drag(CalculateDragPoint(*resizer, 10, -100), 0);
370 EXPECT_EQ("0,100 400x200", window_->bounds().ToString());
371 EXPECT_EQ("400,300 100x300", window2_->bounds().ToString());
373 // Collapse all the way to w1's min.
374 delegate_.set_min_size(gfx::Size(20, 20));
375 resizer->Drag(CalculateDragPoint(*resizer, 20, -800), 0);
376 EXPECT_EQ("0,100 400x20", window_->bounds().ToString());
377 EXPECT_EQ("400,120 100x480", window2_->bounds().ToString());
379 // Move 100 down.
380 resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0);
381 EXPECT_EQ("0,100 400x400", window_->bounds().ToString());
382 EXPECT_EQ("400,500 100x100", window2_->bounds().ToString());
384 // Back to -100.
385 resizer->Drag(CalculateDragPoint(*resizer, 20, -100), 0);
386 EXPECT_EQ("0,100 400x200", window_->bounds().ToString());
387 EXPECT_EQ("400,300 100x300", window2_->bounds().ToString());
390 // Assertions around attached window resize dragging from the bottom with 2
391 // windows.
392 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_2) {
393 window_->SetBounds(gfx::Rect( 0, 50, 400, 200));
394 window2_->SetBounds(gfx::Rect(0, 250, 200, 100));
396 std::vector<aura::Window*> windows;
397 windows.push_back(window2_.get());
398 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
399 window_.get(), gfx::Point(), HTBOTTOM,
400 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
401 ASSERT_TRUE(resizer.get());
402 // Move it 100 to the bottom, which should expand w1 and push w2.
403 resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0);
404 EXPECT_EQ("0,50 400x300", window_->bounds().ToString());
405 EXPECT_EQ("0,350 200x100", window2_->bounds().ToString());
407 // Push off the screen, w2 should be resized to its min.
408 delegate2_.set_min_size(gfx::Size(20, 20));
409 resizer->Drag(CalculateDragPoint(*resizer, 50, 820), 0);
410 EXPECT_EQ("0,50 400x530", window_->bounds().ToString());
411 EXPECT_EQ("0,580 200x20", window2_->bounds().ToString());
413 // Move back to 100 and verify w2 gets its original size.
414 resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0);
415 EXPECT_EQ("0,50 400x300", window_->bounds().ToString());
416 EXPECT_EQ("0,350 200x100", window2_->bounds().ToString());
418 // Revert and make sure everything moves back.
419 resizer->Drag(CalculateDragPoint(*resizer, 800, 20), 0);
420 resizer->RevertDrag();
421 EXPECT_EQ("0,50 400x200", window_->bounds().ToString());
422 EXPECT_EQ("0,250 200x100", window2_->bounds().ToString());
425 #if defined(OS_WIN)
426 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
427 #define MAYBE_AttachedResize_BOTTOM_3 DISABLED_AttachedResize_BOTTOM_3
428 #else
429 #define MAYBE_AttachedResize_BOTTOM_3 AttachedResize_BOTTOM_3
430 #endif
432 // Assertions around attached window resize dragging from the bottom with 3
433 // windows.
434 TEST_F(WorkspaceWindowResizerTest, MAYBE_AttachedResize_BOTTOM_3) {
435 UpdateDisplay("600x800");
436 aura::Window* root = Shell::GetPrimaryRootWindow();
437 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
439 window_->SetBounds(gfx::Rect( 300, 100, 300, 200));
440 window2_->SetBounds(gfx::Rect(300, 300, 200, 150));
441 window3_->SetBounds(gfx::Rect(300, 450, 200, 100));
442 delegate2_.set_min_size(gfx::Size(50, 52));
443 delegate3_.set_min_size(gfx::Size(50, 38));
445 std::vector<aura::Window*> windows;
446 windows.push_back(window2_.get());
447 windows.push_back(window3_.get());
448 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
449 window_.get(), gfx::Point(), HTBOTTOM,
450 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
451 ASSERT_TRUE(resizer.get());
452 // Move it 100 down, which should expand w1 and push w2 and w3.
453 resizer->Drag(CalculateDragPoint(*resizer, -10, 100), 0);
454 EXPECT_EQ("300,100 300x300", window_->bounds().ToString());
455 EXPECT_EQ("300,400 200x150", window2_->bounds().ToString());
456 EXPECT_EQ("300,550 200x100", window3_->bounds().ToString());
458 // Move it 296 things should compress.
459 resizer->Drag(CalculateDragPoint(*resizer, -10, 296), 0);
460 EXPECT_EQ("300,100 300x496", window_->bounds().ToString());
461 EXPECT_EQ("300,596 200x123", window2_->bounds().ToString());
462 EXPECT_EQ("300,719 200x81", window3_->bounds().ToString());
464 // Move it so much everything ends up at its min.
465 resizer->Drag(CalculateDragPoint(*resizer, 50, 798), 0);
466 EXPECT_EQ("300,100 300x610", window_->bounds().ToString());
467 EXPECT_EQ("300,710 200x52", window2_->bounds().ToString());
468 EXPECT_EQ("300,762 200x38", window3_->bounds().ToString());
470 // Revert and make sure everything moves back.
471 resizer->RevertDrag();
472 EXPECT_EQ("300,100 300x200", window_->bounds().ToString());
473 EXPECT_EQ("300,300 200x150", window2_->bounds().ToString());
474 EXPECT_EQ("300,450 200x100", window3_->bounds().ToString());
477 // Assertions around attached window resizing (collapsing and expanding) with
478 // 3 windows.
479 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_3_Compress) {
480 window_->SetBounds(gfx::Rect( 0, 0, 200, 200));
481 window2_->SetBounds(gfx::Rect(10, 200, 200, 200));
482 window3_->SetBounds(gfx::Rect(20, 400, 100, 100));
483 delegate2_.set_min_size(gfx::Size(52, 50));
484 delegate3_.set_min_size(gfx::Size(38, 50));
486 std::vector<aura::Window*> windows;
487 windows.push_back(window2_.get());
488 windows.push_back(window3_.get());
489 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
490 window_.get(), gfx::Point(), HTBOTTOM,
491 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
492 ASSERT_TRUE(resizer.get());
493 // Move it 100 up, which should collapse w1 and expand w2 and w3.
494 resizer->Drag(CalculateDragPoint(*resizer, -10, -100), 0);
495 EXPECT_EQ("0,0 200x100", window_->bounds().ToString());
496 EXPECT_EQ("10,100 200x266", window2_->bounds().ToString());
497 EXPECT_EQ("20,366 100x134", window3_->bounds().ToString());
499 // Move it 100 down.
500 resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0);
501 EXPECT_EQ("0,0 200x300", window_->bounds().ToString());
502 EXPECT_EQ("10,300 200x200", window2_->bounds().ToString());
503 EXPECT_EQ("20,500 100x100", window3_->bounds().ToString());
505 // 100 up again.
506 resizer->Drag(CalculateDragPoint(*resizer, -10, -100), 0);
507 EXPECT_EQ("0,0 200x100", window_->bounds().ToString());
508 EXPECT_EQ("10,100 200x266", window2_->bounds().ToString());
509 EXPECT_EQ("20,366 100x134", window3_->bounds().ToString());
512 // Tests that touch-dragging a window does not lock the mouse cursor
513 // and therefore shows the cursor on a mousemove.
514 TEST_F(WorkspaceWindowResizerTest, MouseMoveWithTouchDrag) {
515 window_->SetBounds(gfx::Rect(0, 300, 400, 300));
516 window2_->SetBounds(gfx::Rect(400, 200, 100, 200));
518 Shell* shell = Shell::GetInstance();
519 ui::test::EventGenerator generator(window_->GetRootWindow());
521 // The cursor should not be locked initially.
522 EXPECT_FALSE(shell->cursor_manager()->IsCursorLocked());
524 std::vector<aura::Window*> windows;
525 windows.push_back(window2_.get());
526 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
527 window_.get(), gfx::Point(), HTRIGHT,
528 aura::client::WINDOW_MOVE_SOURCE_TOUCH, windows));
529 ASSERT_TRUE(resizer.get());
531 // Creating a WorkspaceWindowResizer should not lock the cursor.
532 EXPECT_FALSE(shell->cursor_manager()->IsCursorLocked());
534 // The cursor should be hidden after touching the screen and
535 // starting a drag.
536 EXPECT_TRUE(shell->cursor_manager()->IsCursorVisible());
537 generator.PressTouch();
538 resizer->Drag(CalculateDragPoint(*resizer, 100, 10), 0);
539 EXPECT_FALSE(shell->cursor_manager()->IsCursorVisible());
540 EXPECT_FALSE(shell->cursor_manager()->IsCursorLocked());
542 // Moving the mouse should show the cursor.
543 generator.MoveMouseBy(1, 1);
544 EXPECT_TRUE(shell->cursor_manager()->IsCursorVisible());
545 EXPECT_FALSE(shell->cursor_manager()->IsCursorLocked());
547 resizer->RevertDrag();
550 // Assertions around dragging to the left/right edge of the screen.
551 TEST_F(WorkspaceWindowResizerTest, Edge) {
552 if (!SupportsHostWindowResize())
553 return;
555 // Resize host window to force insets update.
556 UpdateDisplay("800x700");
557 // TODO(varkha): Insets are reset after every drag because of
558 // http://crbug.com/292238.
559 // Window is wide enough not to get docked right away.
560 window_->SetBounds(gfx::Rect(20, 30, 400, 60));
561 window_->SetProperty(aura::client::kCanMaximizeKey, true);
562 wm::WindowState* window_state = wm::GetWindowState(window_.get());
565 gfx::Rect expected_bounds_in_parent(
566 wm::GetDefaultLeftSnappedWindowBoundsInParent(window_.get()));
568 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
569 window_.get(), gfx::Point(), HTCAPTION));
570 ASSERT_TRUE(resizer.get());
571 resizer->Drag(CalculateDragPoint(*resizer, 0, 10), 0);
572 resizer->CompleteDrag();
574 EXPECT_EQ(expected_bounds_in_parent.ToString(),
575 window_->bounds().ToString());
576 ASSERT_TRUE(window_state->HasRestoreBounds());
577 EXPECT_EQ("20,30 400x60",
578 window_state->GetRestoreBoundsInScreen().ToString());
580 // Try the same with the right side.
582 gfx::Rect expected_bounds_in_parent(
583 wm::GetDefaultRightSnappedWindowBoundsInParent(window_.get()));
585 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
586 window_.get(), gfx::Point(), HTCAPTION));
587 ASSERT_TRUE(resizer.get());
588 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0);
589 resizer->CompleteDrag();
590 EXPECT_EQ(expected_bounds_in_parent.ToString(),
591 window_->bounds().ToString());
592 ASSERT_TRUE(window_state->HasRestoreBounds());
593 EXPECT_EQ("20,30 400x60",
594 window_state->GetRestoreBoundsInScreen().ToString());
597 // Test if the restore bounds is correct in multiple displays.
598 if (!SupportsMultipleDisplays())
599 return;
601 // Restore the window to clear snapped state.
602 window_state->Restore();
604 UpdateDisplay("800x600,500x600");
605 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
606 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
607 // Window is wide enough not to get docked right away.
608 window_->SetBoundsInScreen(gfx::Rect(800, 10, 400, 60),
609 ScreenUtil::GetSecondaryDisplay());
610 EXPECT_EQ(root_windows[1], window_->GetRootWindow());
612 EXPECT_EQ("800,10 400x60", window_->GetBoundsInScreen().ToString());
614 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
615 window_.get(), gfx::Point(), HTCAPTION));
616 ASSERT_TRUE(resizer.get());
617 resizer->Drag(CalculateDragPoint(*resizer, 499, 0), 0);
618 int bottom =
619 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_.get()).bottom();
620 resizer->CompleteDrag();
621 // With the resolution of 500x600 we will hit in this case the 50% screen
622 // size setting.
623 // TODO(varkha): Insets are updated because of http://crbug.com/292238
624 EXPECT_EQ("250,0 250x" + base::IntToString(bottom),
625 window_->bounds().ToString());
626 EXPECT_EQ("800,10 400x60",
627 window_state->GetRestoreBoundsInScreen().ToString());
631 // Check that non resizable windows will not get resized.
632 TEST_F(WorkspaceWindowResizerTest, NonResizableWindows) {
633 window_->SetBounds(gfx::Rect(20, 30, 50, 60));
634 window_->SetProperty(aura::client::kCanResizeKey, false);
636 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
637 window_.get(), gfx::Point(), HTCAPTION));
638 ASSERT_TRUE(resizer.get());
639 resizer->Drag(CalculateDragPoint(*resizer, -20, 0), 0);
640 resizer->CompleteDrag();
641 EXPECT_EQ("0,30 50x60", window_->bounds().ToString());
644 TEST_F(WorkspaceWindowResizerTest, CancelSnapPhantom) {
645 if (!SupportsMultipleDisplays())
646 return;
648 UpdateDisplay("800x600,800x600");
649 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
650 ASSERT_EQ(2U, root_windows.size());
652 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
653 Shell::GetScreen()->GetPrimaryDisplay());
654 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
655 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
657 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
658 window_.get(), gfx::Point(), HTCAPTION));
659 ASSERT_TRUE(resizer.get());
660 EXPECT_FALSE(snap_phantom_window_controller());
662 // The pointer is on the edge but not shared. The snap phantom window
663 // controller should be non-NULL.
664 resizer->Drag(CalculateDragPoint(*resizer, 799, 0), 0);
665 EXPECT_TRUE(snap_phantom_window_controller());
667 // Move the cursor across the edge. Now the snap phantom window controller
668 // should be canceled.
669 resizer->Drag(CalculateDragPoint(*resizer, 800, 0), 0);
670 EXPECT_FALSE(snap_phantom_window_controller());
674 // Verifies that dragging a snapped window unsnaps it.
675 TEST_F(WorkspaceWindowResizerTest, DragSnapped) {
676 wm::WindowState* window_state = ash::wm::GetWindowState(window_.get());
678 const gfx::Rect kInitialBounds(100, 100, 100, 100);
679 window_->SetBounds(kInitialBounds);
680 window_->Show();
681 const wm::WMEvent snap_event(wm::WM_EVENT_SNAP_LEFT);
682 window_state->OnWMEvent(&snap_event);
683 EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType());
684 gfx::Rect snapped_bounds = window_->bounds();
685 EXPECT_NE(snapped_bounds.ToString(), kInitialBounds.ToString());
686 EXPECT_EQ(window_state->GetRestoreBoundsInParent().ToString(),
687 kInitialBounds.ToString());
689 // Dragging a side snapped window should unsnap it.
690 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
691 window_.get(), gfx::Point(), HTCAPTION));
692 resizer->Drag(CalculateDragPoint(*resizer, 10, 0), 0);
693 resizer->CompleteDrag();
694 EXPECT_EQ(wm::WINDOW_STATE_TYPE_NORMAL, window_state->GetStateType());
695 EXPECT_EQ("10,0 100x100", window_->bounds().ToString());
696 EXPECT_FALSE(window_state->HasRestoreBounds());
699 // Verifies the behavior of resizing a side snapped window.
700 TEST_F(WorkspaceWindowResizerTest, ResizeSnapped) {
701 wm::WindowState* window_state = ash::wm::GetWindowState(window_.get());
703 const gfx::Rect kInitialBounds(100, 100, 100, 100);
704 window_->SetBounds(kInitialBounds);
705 window_->Show();
707 const wm::WMEvent snap_event(wm::WM_EVENT_SNAP_LEFT);
708 window_state->OnWMEvent(&snap_event);
709 EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType());
710 gfx::Rect snapped_bounds = window_->bounds();
711 EXPECT_NE(snapped_bounds.ToString(), kInitialBounds.ToString());
712 EXPECT_EQ(window_state->GetRestoreBoundsInParent().ToString(),
713 kInitialBounds.ToString());
716 // 1) Resizing a side snapped window to make it wider should not unsnap the
717 // window.
718 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
719 window_.get(), gfx::Point(), HTRIGHT));
720 resizer->Drag(CalculateDragPoint(*resizer, 10, 0), 0);
721 resizer->CompleteDrag();
722 EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType());
723 snapped_bounds.Inset(0, 0, -10, 0);
724 EXPECT_EQ(snapped_bounds.ToString(), window_->bounds().ToString());
725 EXPECT_EQ(window_state->GetRestoreBoundsInParent().ToString(),
726 kInitialBounds.ToString());
730 // 2) Resizing a side snapped window vertically and then undoing the change
731 // should not unsnap.
732 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
733 window_.get(), gfx::Point(), HTBOTTOM));
734 resizer->Drag(CalculateDragPoint(*resizer, 0, -30), 0);
735 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
736 resizer->CompleteDrag();
737 EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType());
738 EXPECT_EQ(snapped_bounds.ToString(), window_->bounds().ToString());
739 EXPECT_EQ(window_state->GetRestoreBoundsInParent().ToString(),
740 kInitialBounds.ToString());
744 // 3) Resizing a side snapped window vertically and then not undoing the
745 // change should unsnap.
746 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
747 window_.get(), gfx::Point(), HTBOTTOM));
748 resizer->Drag(CalculateDragPoint(*resizer, 0, -10), 0);
749 resizer->CompleteDrag();
750 EXPECT_EQ(wm::WINDOW_STATE_TYPE_NORMAL, window_state->GetStateType());
751 gfx::Rect expected_bounds(snapped_bounds);
752 expected_bounds.Inset(0, 0, 0, 10);
753 EXPECT_EQ(expected_bounds.ToString(), window_->bounds().ToString());
754 EXPECT_FALSE(window_state->HasRestoreBounds());
758 // Verifies windows are correctly restacked when reordering multiple windows.
759 TEST_F(WorkspaceWindowResizerTest, RestackAttached) {
760 window_->SetBounds(gfx::Rect( 0, 0, 200, 300));
761 window2_->SetBounds(gfx::Rect(200, 0, 100, 200));
762 window3_->SetBounds(gfx::Rect(300, 0, 100, 100));
765 std::vector<aura::Window*> windows;
766 windows.push_back(window2_.get());
767 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
768 window_.get(), gfx::Point(), HTRIGHT,
769 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
770 ASSERT_TRUE(resizer.get());
771 // Move it 100 to the right, which should expand w1 and push w2 and w3.
772 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
774 // 2 should be topmost since it's initially the highest in the stack.
775 EXPECT_EQ("2 1 3", WindowOrderAsString(window_->parent()));
779 std::vector<aura::Window*> windows;
780 windows.push_back(window3_.get());
781 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
782 window2_.get(), gfx::Point(), HTRIGHT,
783 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
784 ASSERT_TRUE(resizer.get());
785 // Move it 100 to the right, which should expand w1 and push w2 and w3.
786 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
788 // 2 should be topmost since it's initially the highest in the stack.
789 EXPECT_EQ("2 3 1", WindowOrderAsString(window_->parent()));
793 // Makes sure we don't allow dragging below the work area.
794 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottom) {
795 Shell::GetInstance()->SetDisplayWorkAreaInsets(
796 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0));
798 ASSERT_EQ(1, Shell::GetScreen()->GetNumDisplays());
800 window_->SetBounds(gfx::Rect(100, 200, 300, 400));
801 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
802 window_.get(), gfx::Point(), HTCAPTION));
803 ASSERT_TRUE(resizer.get());
804 resizer->Drag(CalculateDragPoint(*resizer, 0, 600), 0);
805 int expected_y =
806 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10;
807 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400",
808 window_->bounds().ToString());
811 // Makes sure we don't allow dragging on the work area with multidisplay.
812 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottomWithMultiDisplay) {
813 if (!SupportsMultipleDisplays())
814 return;
816 UpdateDisplay("800x600,800x600");
817 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
819 Shell::GetInstance()->SetDisplayWorkAreaInsets(
820 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0));
822 // Positions the secondary display at the bottom the primary display.
823 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays(
824 ash::DisplayLayout(ash::DisplayLayout::BOTTOM, 0));
827 window_->SetBounds(gfx::Rect(100, 200, 300, 20));
828 DCHECK_LT(window_->bounds().height(),
829 WorkspaceWindowResizer::kMinOnscreenHeight);
830 // Drag down avoiding dragging along the edge as that would side-snap.
831 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
832 window_.get(), gfx::Point(10, 0), HTCAPTION));
833 ASSERT_TRUE(resizer.get());
834 resizer->Drag(CalculateDragPoint(*resizer, 0, 400), 0);
835 int expected_y = kRootHeight - window_->bounds().height() - 10;
836 // When the mouse cursor is in the primary display, the window cannot move
837 // on non-work area but can get all the way towards the bottom,
838 // restricted only by the window height.
839 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x20",
840 window_->bounds().ToString());
841 // Revert the drag in order to not remember the restore bounds.
842 resizer->RevertDrag();
845 Shell::GetInstance()->SetDisplayWorkAreaInsets(
846 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0));
848 window_->SetBounds(gfx::Rect(100, 200, 300, 400));
849 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
850 window_.get(), gfx::Point(10, 0), HTCAPTION));
851 ASSERT_TRUE(resizer.get());
852 // Drag down avoiding dragging along the edge as that would side-snap.
853 resizer->Drag(CalculateDragPoint(*resizer, 0, 400), 0);
854 int expected_y =
855 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10;
856 // When the mouse cursor is in the primary display, the window cannot move
857 // on non-work area with kMinOnscreenHeight margin.
858 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400",
859 window_->bounds().ToString());
860 resizer->CompleteDrag();
864 window_->SetBounds(gfx::Rect(100, 200, 300, 400));
865 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
866 window_.get(), window_->bounds().origin(), HTCAPTION));
867 ASSERT_TRUE(resizer.get());
868 // Drag down avoiding getting stuck against the shelf on the bottom screen.
869 resizer->Drag(CalculateDragPoint(*resizer, 0, 500), 0);
870 // The window can move to the secondary display beyond non-work area of
871 // the primary display.
872 EXPECT_EQ("100,700 300x400", window_->bounds().ToString());
873 resizer->CompleteDrag();
877 // Makes sure we don't allow dragging off the top of the work area.
878 TEST_F(WorkspaceWindowResizerTest, DontDragOffTop) {
879 Shell::GetInstance()->SetDisplayWorkAreaInsets(
880 Shell::GetPrimaryRootWindow(), gfx::Insets(10, 0, 0, 0));
882 window_->SetBounds(gfx::Rect(100, 200, 300, 400));
883 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
884 window_.get(), gfx::Point(), HTCAPTION));
885 ASSERT_TRUE(resizer.get());
886 resizer->Drag(CalculateDragPoint(*resizer, 0, -600), 0);
887 EXPECT_EQ("100,10 300x400", window_->bounds().ToString());
890 TEST_F(WorkspaceWindowResizerTest, ResizeBottomOutsideWorkArea) {
891 Shell::GetInstance()->SetDisplayWorkAreaInsets(
892 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
894 window_->SetBounds(gfx::Rect(100, 200, 300, 380));
895 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
896 window_.get(), gfx::Point(), HTTOP));
897 ASSERT_TRUE(resizer.get());
898 resizer->Drag(CalculateDragPoint(*resizer, 8, 0), 0);
899 EXPECT_EQ("100,200 300x380", window_->bounds().ToString());
902 TEST_F(WorkspaceWindowResizerTest, ResizeWindowOutsideLeftWorkArea) {
903 Shell::GetInstance()->SetDisplayWorkAreaInsets(
904 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
905 int left = ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_.get()).x();
906 int pixels_to_left_border = 50;
907 int window_width = 300;
908 int window_x = left - window_width + pixels_to_left_border;
909 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380));
910 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
911 window_.get(), gfx::Point(pixels_to_left_border, 0), HTRIGHT));
912 ASSERT_TRUE(resizer.get());
913 resizer->Drag(CalculateDragPoint(*resizer, -window_width, 0), 0);
914 EXPECT_EQ(base::IntToString(window_x) + ",100 " +
915 base::IntToString(kMinimumOnScreenArea - window_x) +
916 "x380", window_->bounds().ToString());
919 TEST_F(WorkspaceWindowResizerTest, ResizeWindowOutsideRightWorkArea) {
920 Shell::GetInstance()->SetDisplayWorkAreaInsets(
921 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
922 int right = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
923 window_.get()).right();
924 int pixels_to_right_border = 50;
925 int window_width = 300;
926 int window_x = right - pixels_to_right_border;
927 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380));
928 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
929 window_.get(), gfx::Point(window_x, 0), HTLEFT));
930 ASSERT_TRUE(resizer.get());
931 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0);
932 EXPECT_EQ(base::IntToString(right - kMinimumOnScreenArea) +
933 ",100 " +
934 base::IntToString(window_width - pixels_to_right_border +
935 kMinimumOnScreenArea) +
936 "x380", window_->bounds().ToString());
939 TEST_F(WorkspaceWindowResizerTest, ResizeWindowOutsideBottomWorkArea) {
940 Shell::GetInstance()->SetDisplayWorkAreaInsets(
941 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
942 int bottom = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
943 window_.get()).bottom();
944 int delta_to_bottom = 50;
945 int height = 380;
946 window_->SetBounds(gfx::Rect(100, bottom - delta_to_bottom, 300, height));
947 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
948 window_.get(), gfx::Point(0, bottom - delta_to_bottom), HTTOP));
949 ASSERT_TRUE(resizer.get());
950 resizer->Drag(CalculateDragPoint(*resizer, 0, bottom), 0);
951 EXPECT_EQ("100," +
952 base::IntToString(bottom - kMinimumOnScreenArea) +
953 " 300x" +
954 base::IntToString(height - (delta_to_bottom -
955 kMinimumOnScreenArea)),
956 window_->bounds().ToString());
959 // Verifies that 'outside' check of the resizer take into account the extended
960 // desktop in case of repositions.
961 TEST_F(WorkspaceWindowResizerTest, DragWindowOutsideRightToSecondaryDisplay) {
962 // Only primary display. Changes the window position to fit within the
963 // display.
964 Shell::GetInstance()->SetDisplayWorkAreaInsets(
965 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
966 int right = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
967 window_.get()).right();
968 int pixels_to_right_border = 50;
969 int window_width = 300;
970 int window_x = right - pixels_to_right_border;
971 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380));
972 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
973 window_.get(), gfx::Point(window_x, 0), HTCAPTION));
974 ASSERT_TRUE(resizer.get());
975 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0);
976 EXPECT_EQ(base::IntToString(right - kMinimumOnScreenArea) +
977 ",100 " +
978 base::IntToString(window_width) +
979 "x380", window_->bounds().ToString());
981 if (!SupportsMultipleDisplays())
982 return;
984 // With secondary display. Operation itself is same but doesn't change
985 // the position because the window is still within the secondary display.
986 UpdateDisplay("1000x600,600x400");
987 Shell::GetInstance()->SetDisplayWorkAreaInsets(
988 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
989 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380));
990 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0);
991 EXPECT_EQ(base::IntToString(window_x + window_width) +
992 ",100 " +
993 base::IntToString(window_width) +
994 "x380", window_->bounds().ToString());
997 // Verifies snapping to edges works.
998 TEST_F(WorkspaceWindowResizerTest, SnapToEdge) {
999 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()->
1000 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1001 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
1002 // Click 50px to the right so that the mouse pointer does not leave the
1003 // workspace ensuring sticky behavior.
1004 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1005 window_.get(),
1006 window_->bounds().origin() + gfx::Vector2d(50, 0),
1007 HTCAPTION));
1008 ASSERT_TRUE(resizer.get());
1009 // Move to an x-coordinate of 15, which should not snap.
1010 resizer->Drag(CalculateDragPoint(*resizer, 15 - 96, 0), 0);
1011 // An x-coordinate of 7 should snap.
1012 resizer->Drag(CalculateDragPoint(*resizer, 7 - 96, 0), 0);
1013 EXPECT_EQ("0,112 320x160", window_->bounds().ToString());
1014 // Move to -15, should still snap to 0.
1015 resizer->Drag(CalculateDragPoint(*resizer, -15 - 96, 0), 0);
1016 EXPECT_EQ("0,112 320x160", window_->bounds().ToString());
1017 // At -32 should move past snap points.
1018 resizer->Drag(CalculateDragPoint(*resizer, -32 - 96, 0), 0);
1019 EXPECT_EQ("-32,112 320x160", window_->bounds().ToString());
1020 resizer->Drag(CalculateDragPoint(*resizer, -33 - 96, 0), 0);
1021 EXPECT_EQ("-33,112 320x160", window_->bounds().ToString());
1023 // Right side should similarly snap.
1024 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 - 15, 0), 0);
1025 EXPECT_EQ("465,112 320x160", window_->bounds().ToString());
1026 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 - 7, 0), 0);
1027 EXPECT_EQ("480,112 320x160", window_->bounds().ToString());
1028 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 15, 0), 0);
1029 EXPECT_EQ("480,112 320x160", window_->bounds().ToString());
1030 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 32, 0), 0);
1031 EXPECT_EQ("512,112 320x160", window_->bounds().ToString());
1032 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 33, 0), 0);
1033 EXPECT_EQ("513,112 320x160", window_->bounds().ToString());
1035 // And the bottom should snap too.
1036 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 3 - 7), 0);
1037 EXPECT_EQ("96,437 320x160", window_->bounds().ToString());
1038 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 3 + 15), 0);
1039 EXPECT_EQ("96,437 320x160", window_->bounds().ToString());
1040 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 2 + 32), 0);
1041 EXPECT_EQ("96,470 320x160", window_->bounds().ToString());
1042 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 2 + 33), 0);
1043 EXPECT_EQ("96,471 320x160", window_->bounds().ToString());
1045 // And the top should snap too.
1046 resizer->Drag(CalculateDragPoint(*resizer, 0, -112 + 20), 0);
1047 EXPECT_EQ("96,20 320x160", window_->bounds().ToString());
1048 resizer->Drag(CalculateDragPoint(*resizer, 0, -112 + 7), 0);
1049 EXPECT_EQ("96,0 320x160", window_->bounds().ToString());
1051 // And bottom/left should snap too.
1052 resizer->Drag(
1053 CalculateDragPoint(*resizer, 7 - 96, 600 - 160 - 112 - 3 - 7), 0);
1054 EXPECT_EQ("0,437 320x160", window_->bounds().ToString());
1055 resizer->Drag(
1056 CalculateDragPoint(*resizer, -15 - 96, 600 - 160 - 112 - 3 + 15), 0);
1057 EXPECT_EQ("0,437 320x160", window_->bounds().ToString());
1058 // should move past snap points.
1059 resizer->Drag(
1060 CalculateDragPoint(*resizer, -32 - 96, 600 - 160 - 112 - 2 + 32), 0);
1061 EXPECT_EQ("-32,470 320x160", window_->bounds().ToString());
1062 resizer->Drag(
1063 CalculateDragPoint(*resizer, -33 - 96, 600 - 160 - 112 - 2 + 33), 0);
1064 EXPECT_EQ("-33,471 320x160", window_->bounds().ToString());
1066 // No need to test dragging < 0 as we force that to 0.
1069 // Verifies a resize snap when dragging TOPLEFT.
1070 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_TOPLEFT) {
1071 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1072 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1073 window_.get(), gfx::Point(), HTTOPLEFT));
1074 ASSERT_TRUE(resizer.get());
1075 resizer->Drag(CalculateDragPoint(*resizer, -98, -199), 0);
1076 EXPECT_EQ("0,0 120x230", window_->bounds().ToString());
1079 // Verifies a resize snap when dragging TOPRIGHT.
1080 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_TOPRIGHT) {
1081 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1082 gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
1083 window_.get()));
1084 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1085 window_.get(), gfx::Point(), HTTOPRIGHT));
1086 ASSERT_TRUE(resizer.get());
1087 resizer->Drag(
1088 CalculateDragPoint(*resizer, work_area.right() - 120 - 1, -199), 0);
1089 EXPECT_EQ(100, window_->bounds().x());
1090 EXPECT_EQ(work_area.y(), window_->bounds().y());
1091 EXPECT_EQ(work_area.right() - 100, window_->bounds().width());
1092 EXPECT_EQ(230, window_->bounds().height());
1095 // Verifies a resize snap when dragging BOTTOMRIGHT.
1096 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_BOTTOMRIGHT) {
1097 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1098 gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
1099 window_.get()));
1100 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1101 window_.get(), gfx::Point(), HTBOTTOMRIGHT));
1102 ASSERT_TRUE(resizer.get());
1103 resizer->Drag(
1104 CalculateDragPoint(*resizer, work_area.right() - 120 - 1,
1105 work_area.bottom() - 220 - 2), 0);
1106 EXPECT_EQ(100, window_->bounds().x());
1107 EXPECT_EQ(200, window_->bounds().y());
1108 EXPECT_EQ(work_area.right() - 100, window_->bounds().width());
1109 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
1112 // Verifies a resize snap when dragging BOTTOMLEFT.
1113 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_BOTTOMLEFT) {
1114 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1115 gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
1116 window_.get()));
1117 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1118 window_.get(), gfx::Point(), HTBOTTOMLEFT));
1119 ASSERT_TRUE(resizer.get());
1120 resizer->Drag(
1121 CalculateDragPoint(*resizer, -98, work_area.bottom() - 220 - 2), 0);
1122 EXPECT_EQ(0, window_->bounds().x());
1123 EXPECT_EQ(200, window_->bounds().y());
1124 EXPECT_EQ(120, window_->bounds().width());
1125 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
1128 // Verifies window sticks to both window and work area.
1129 TEST_F(WorkspaceWindowResizerTest, StickToBothEdgeAndWindow) {
1130 window_->SetBounds(gfx::Rect(10, 10, 20, 50));
1131 window_->Show();
1132 window2_->SetBounds(gfx::Rect(150, 160, 25, 1000));
1133 window2_->Show();
1135 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1136 window_.get(), gfx::Point(10, 10), HTCAPTION));
1137 ASSERT_TRUE(resizer.get());
1139 // Move |window| one pixel to the left of |window2|. Should snap to right.
1140 resizer->Drag(CalculateDragPoint(*resizer, 119, 145), 0);
1141 gfx::Rect expected(130, 160, 20, 50);
1142 EXPECT_EQ(expected.ToString(), window_->bounds().ToString());
1144 gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
1145 window_.get()));
1147 // The initial y position of |window_|.
1148 int initial_y = 10;
1149 // The drag position where the window is exactly attached to the bottom.
1150 int attach_y = work_area.bottom() - window_->bounds().height() - initial_y;
1152 // Dragging 10px above should not attach to the bottom.
1153 resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y - 10), 0);
1154 expected.set_y(attach_y + initial_y - 10);
1155 EXPECT_EQ(expected.ToString(), window_->bounds().ToString());
1157 // Stick to the work area.
1158 resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y - 1), 0);
1159 expected.set_y(attach_y + initial_y);
1160 EXPECT_EQ(expected.ToString(), window_->bounds().ToString());
1162 resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y), 0);
1163 expected.set_y(attach_y + initial_y);
1164 EXPECT_EQ(expected.ToString(), window_->bounds().ToString());
1166 resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y + 1), 0);
1167 expected.set_y(attach_y + initial_y);
1168 EXPECT_EQ(expected.ToString(), window_->bounds().ToString());
1170 // Moving down further should move the window.
1171 resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y + 18), 0);
1172 expected.set_y(attach_y + initial_y + 18);
1173 EXPECT_EQ(expected.ToString(), window_->bounds().ToString());
1176 TEST_F(WorkspaceWindowResizerTest, CtrlDragResizeToExactPosition) {
1177 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
1178 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1179 window_.get(), gfx::Point(), HTBOTTOMRIGHT));
1180 ASSERT_TRUE(resizer.get());
1181 // Resize the right bottom to add 10 in width, 12 in height.
1182 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), ui::EF_CONTROL_DOWN);
1183 // Both bottom and right sides to resize to exact size requested.
1184 EXPECT_EQ("96,112 330x172", window_->bounds().ToString());
1187 // Verifies that a dragged, non-snapped window will clear restore bounds.
1188 TEST_F(WorkspaceWindowResizerTest, RestoreClearedOnResize) {
1189 window_->SetBounds(gfx::Rect(10, 10, 100, 100));
1190 wm::WindowState* window_state = wm::GetWindowState(window_.get());
1191 window_state->SetRestoreBoundsInScreen(gfx::Rect(50, 50, 50, 50));
1192 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1193 window_.get(), gfx::Point(), HTBOTTOMRIGHT));
1194 ASSERT_TRUE(resizer.get());
1195 // Drag the window to new position by adding (20, 30) to original point,
1196 // the original restore bound should be cleared.
1197 resizer->Drag(CalculateDragPoint(*resizer, 20, 30), 0);
1198 resizer->CompleteDrag();
1199 EXPECT_EQ("10,10 120x130", window_->bounds().ToString());
1200 EXPECT_FALSE(window_state->HasRestoreBounds());
1203 // Verifies that a dragged window will restore to its pre-maximized size.
1204 TEST_F(WorkspaceWindowResizerTest, RestoreToPreMaximizeCoordinates) {
1205 window_->SetBounds(gfx::Rect(0, 0, 1000, 1000));
1206 wm::WindowState* window_state = wm::GetWindowState(window_.get());
1207 window_state->SetRestoreBoundsInScreen(gfx::Rect(96, 112, 320, 160));
1208 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1209 window_.get(), gfx::Point(), HTCAPTION));
1210 ASSERT_TRUE(resizer.get());
1211 // Drag the window to new position by adding (10, 10) to original point,
1212 // the window should get restored.
1213 resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0);
1214 resizer->CompleteDrag();
1215 EXPECT_EQ("10,10 320x160", window_->bounds().ToString());
1216 // The restore rectangle should get cleared as well.
1217 EXPECT_FALSE(window_state->HasRestoreBounds());
1220 // Verifies that a dragged window will restore to its pre-maximized size.
1221 TEST_F(WorkspaceWindowResizerTest, RevertResizeOperation) {
1222 const gfx::Rect initial_bounds(0, 0, 200, 400);
1223 window_->SetBounds(initial_bounds);
1225 wm::WindowState* window_state = wm::GetWindowState(window_.get());
1226 window_state->SetRestoreBoundsInScreen(gfx::Rect(96, 112, 320, 160));
1227 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1228 window_.get(), gfx::Point(), HTCAPTION));
1229 ASSERT_TRUE(resizer.get());
1230 // Drag the window to new poistion by adding (180, 16) to original point,
1231 // the window should get restored.
1232 resizer->Drag(CalculateDragPoint(*resizer, 180, 16), 0);
1233 resizer->RevertDrag();
1234 EXPECT_EQ(initial_bounds.ToString(), window_->bounds().ToString());
1235 EXPECT_EQ("96,112 320x160",
1236 window_state->GetRestoreBoundsInScreen().ToString());
1239 // Check that only usable sizes get returned by the resizer.
1240 TEST_F(WorkspaceWindowResizerTest, MagneticallyAttach) {
1241 window_->SetBounds(gfx::Rect(10, 10, 20, 30));
1242 window2_->SetBounds(gfx::Rect(150, 160, 25, 20));
1243 window2_->Show();
1245 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1246 window_.get(), gfx::Point(), HTCAPTION));
1247 ASSERT_TRUE(resizer.get());
1248 // Move |window| one pixel to the left of |window2|. Should snap to right and
1249 // top.
1250 resizer->Drag(CalculateDragPoint(*resizer, 119, 145), 0);
1251 EXPECT_EQ("130,160 20x30", window_->bounds().ToString());
1253 // Move |window| one pixel to the right of |window2|. Should snap to left and
1254 // top.
1255 resizer->Drag(CalculateDragPoint(*resizer, 164, 145), 0);
1256 EXPECT_EQ("175,160 20x30", window_->bounds().ToString());
1258 // Move |window| one pixel above |window2|. Should snap to top and left.
1259 resizer->Drag(CalculateDragPoint(*resizer, 142, 119), 0);
1260 EXPECT_EQ("150,130 20x30", window_->bounds().ToString());
1262 // Move |window| one pixel above the bottom of |window2|. Should snap to
1263 // bottom and left.
1264 resizer->Drag(CalculateDragPoint(*resizer, 142, 169), 0);
1265 EXPECT_EQ("150,180 20x30", window_->bounds().ToString());
1268 // The following variants verify magnetic snapping during resize when dragging a
1269 // particular edge.
1270 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_TOP) {
1271 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1272 window2_->SetBounds(gfx::Rect(99, 179, 10, 20));
1273 window2_->Show();
1275 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1276 window_.get(), gfx::Point(), HTTOP));
1277 ASSERT_TRUE(resizer.get());
1278 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1279 EXPECT_EQ("100,199 20x31", window_->bounds().ToString());
1282 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_TOPLEFT) {
1283 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1284 window2_->SetBounds(gfx::Rect(99, 179, 10, 20));
1285 window2_->Show();
1288 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1289 window_.get(), gfx::Point(), HTTOPLEFT));
1290 ASSERT_TRUE(resizer.get());
1291 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1292 EXPECT_EQ("99,199 21x31", window_->bounds().ToString());
1293 resizer->RevertDrag();
1297 window2_->SetBounds(gfx::Rect(88, 201, 10, 20));
1298 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1299 window_.get(), gfx::Point(), HTTOPLEFT));
1300 ASSERT_TRUE(resizer.get());
1301 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1302 EXPECT_EQ("98,201 22x29", window_->bounds().ToString());
1303 resizer->RevertDrag();
1307 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_TOPRIGHT) {
1308 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1309 window2_->Show();
1312 window2_->SetBounds(gfx::Rect(111, 179, 10, 20));
1313 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1314 window_.get(), gfx::Point(), HTTOPRIGHT));
1315 ASSERT_TRUE(resizer.get());
1316 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1317 EXPECT_EQ("100,199 21x31", window_->bounds().ToString());
1318 resizer->RevertDrag();
1322 window2_->SetBounds(gfx::Rect(121, 199, 10, 20));
1323 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1324 window_.get(), gfx::Point(), HTTOPRIGHT));
1325 ASSERT_TRUE(resizer.get());
1326 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1327 EXPECT_EQ("100,199 21x31", window_->bounds().ToString());
1328 resizer->RevertDrag();
1332 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_RIGHT) {
1333 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1334 window2_->SetBounds(gfx::Rect(121, 199, 10, 20));
1335 window2_->Show();
1337 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1338 window_.get(), gfx::Point(), HTRIGHT));
1339 ASSERT_TRUE(resizer.get());
1340 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1341 EXPECT_EQ("100,200 21x30", window_->bounds().ToString());
1344 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_BOTTOMRIGHT) {
1345 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1346 window2_->Show();
1349 window2_->SetBounds(gfx::Rect(122, 212, 10, 20));
1350 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1351 window_.get(), gfx::Point(), HTBOTTOMRIGHT));
1352 ASSERT_TRUE(resizer.get());
1353 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1354 EXPECT_EQ("100,200 22x32", window_->bounds().ToString());
1355 resizer->RevertDrag();
1359 window2_->SetBounds(gfx::Rect(111, 233, 10, 20));
1360 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1361 window_.get(), gfx::Point(), HTBOTTOMRIGHT));
1362 ASSERT_TRUE(resizer.get());
1363 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1364 EXPECT_EQ("100,200 21x33", window_->bounds().ToString());
1365 resizer->RevertDrag();
1369 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_BOTTOM) {
1370 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1371 window2_->SetBounds(gfx::Rect(111, 233, 10, 20));
1372 window2_->Show();
1374 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1375 window_.get(), gfx::Point(), HTBOTTOM));
1376 ASSERT_TRUE(resizer.get());
1377 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1378 EXPECT_EQ("100,200 20x33", window_->bounds().ToString());
1381 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_BOTTOMLEFT) {
1382 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1383 window2_->Show();
1386 window2_->SetBounds(gfx::Rect(99, 231, 10, 20));
1387 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1388 window_.get(), gfx::Point(), HTBOTTOMLEFT));
1389 ASSERT_TRUE(resizer.get());
1390 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1391 EXPECT_EQ("99,200 21x31", window_->bounds().ToString());
1392 resizer->RevertDrag();
1396 window2_->SetBounds(gfx::Rect(89, 209, 10, 20));
1397 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1398 window_.get(), gfx::Point(), HTBOTTOMLEFT));
1399 ASSERT_TRUE(resizer.get());
1400 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1401 EXPECT_EQ("99,200 21x29", window_->bounds().ToString());
1402 resizer->RevertDrag();
1406 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_LEFT) {
1407 window2_->SetBounds(gfx::Rect(89, 209, 10, 20));
1408 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1409 window2_->Show();
1411 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1412 window_.get(), gfx::Point(), HTLEFT));
1413 ASSERT_TRUE(resizer.get());
1414 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1415 EXPECT_EQ("99,200 21x30", window_->bounds().ToString());
1418 // Test that the user user moved window flag is getting properly set.
1419 TEST_F(WorkspaceWindowResizerTest, CheckUserWindowManagedFlags) {
1420 window_->SetBounds(gfx::Rect( 0, 50, 400, 200));
1421 window_->SetProperty(aura::client::kCanMaximizeKey, true);
1423 std::vector<aura::Window*> no_attached_windows;
1424 // Check that an abort doesn't change anything.
1426 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1427 window_.get(), gfx::Point(), HTCAPTION));
1428 ASSERT_TRUE(resizer.get());
1429 // Move it 100 to the bottom.
1430 resizer->Drag(CalculateDragPoint(*resizer, 0, 100), 0);
1431 EXPECT_EQ("0,150 400x200", window_->bounds().ToString());
1432 resizer->RevertDrag();
1434 EXPECT_FALSE(wm::GetWindowState(window_.get())->bounds_changed_by_user());
1437 // Check that a completed move / size does change the user coordinates.
1439 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1440 window_.get(), gfx::Point(), HTCAPTION));
1441 ASSERT_TRUE(resizer.get());
1442 // Move it 100 to the bottom.
1443 resizer->Drag(CalculateDragPoint(*resizer, 0, 100), 0);
1444 EXPECT_EQ("0,150 400x200", window_->bounds().ToString());
1445 resizer->CompleteDrag();
1446 EXPECT_TRUE(wm::GetWindowState(window_.get())->bounds_changed_by_user());
1450 // Test that a window with a specified max size doesn't exceed it when dragged.
1451 TEST_F(WorkspaceWindowResizerTest, TestMaxSizeEnforced) {
1452 window_->SetBounds(gfx::Rect(0, 0, 400, 300));
1453 delegate_.set_max_size(gfx::Size(401, 301));
1455 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1456 window_.get(), gfx::Point(), HTBOTTOMRIGHT));
1457 resizer->Drag(CalculateDragPoint(*resizer, 2, 2), 0);
1458 EXPECT_EQ(401, window_->bounds().width());
1459 EXPECT_EQ(301, window_->bounds().height());
1462 // Test that a window with a specified max width doesn't restrict its height.
1463 TEST_F(WorkspaceWindowResizerTest, TestPartialMaxSizeEnforced) {
1464 window_->SetBounds(gfx::Rect(0, 0, 400, 300));
1465 delegate_.set_max_size(gfx::Size(401, 0));
1467 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1468 window_.get(), gfx::Point(), HTBOTTOMRIGHT));
1469 resizer->Drag(CalculateDragPoint(*resizer, 2, 2), 0);
1470 EXPECT_EQ(401, window_->bounds().width());
1471 EXPECT_EQ(302, window_->bounds().height());
1474 // Test that a window with a specified max size can't be snapped.
1475 TEST_F(WorkspaceWindowResizerTest, PhantomSnapMaxSize) {
1477 // With max size not set we get a phantom window controller for dragging off
1478 // the right hand side.
1479 // Make the window wider than maximum docked width.
1480 window_->SetBounds(gfx::Rect(0, 0, 400, 200));
1482 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1483 window_.get(), gfx::Point(), HTCAPTION));
1484 EXPECT_FALSE(snap_phantom_window_controller());
1485 resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0);
1486 EXPECT_TRUE(snap_phantom_window_controller());
1487 resizer->RevertDrag();
1490 // With max size defined, we get no phantom window for snapping but we still
1491 // get a phantom window (docking guide).
1492 window_->SetBounds(gfx::Rect(0, 0, 400, 200));
1493 delegate_.set_max_size(gfx::Size(400, 200));
1495 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1496 window_.get(), gfx::Point(), HTCAPTION));
1497 resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0);
1498 EXPECT_TRUE(snap_phantom_window_controller());
1499 resizer->RevertDrag();
1502 // With max size defined, we get no phantom window for snapping.
1503 window_->SetBounds(gfx::Rect(0, 0, 400, 200));
1504 delegate_.set_max_size(gfx::Size(400, 200));
1505 // With min size defined, we get no phantom window for docking.
1506 delegate_.set_min_size(gfx::Size(400, 200));
1508 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1509 window_.get(), gfx::Point(), HTCAPTION));
1510 resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0);
1511 EXPECT_FALSE(snap_phantom_window_controller());
1512 resizer->RevertDrag();
1516 TEST_F(WorkspaceWindowResizerTest, DontRewardRightmostWindowForOverflows) {
1517 UpdateDisplay("600x800");
1518 aura::Window* root = Shell::GetPrimaryRootWindow();
1519 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1521 // Four 100x100 windows flush against eachother, starting at 100,100.
1522 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1523 window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
1524 window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
1525 window4_->SetBounds(gfx::Rect(400, 100, 100, 100));
1526 delegate2_.set_max_size(gfx::Size(101, 0));
1528 std::vector<aura::Window*> windows;
1529 windows.push_back(window2_.get());
1530 windows.push_back(window3_.get());
1531 windows.push_back(window4_.get());
1532 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
1533 window_.get(), gfx::Point(), HTRIGHT,
1534 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1535 ASSERT_TRUE(resizer.get());
1536 // Move it 51 to the left, which should contract w1 and expand w2-4.
1537 // w2 will hit its max size straight away, and in doing so will leave extra
1538 // pixels that a naive implementation may award to the rightmost window. A
1539 // fair implementation will give 25 pixels to each of the other windows.
1540 resizer->Drag(CalculateDragPoint(*resizer, -51, 0), 0);
1541 EXPECT_EQ("100,100 49x100", window_->bounds().ToString());
1542 EXPECT_EQ("149,100 101x100", window2_->bounds().ToString());
1543 EXPECT_EQ("250,100 125x100", window3_->bounds().ToString());
1544 EXPECT_EQ("375,100 125x100", window4_->bounds().ToString());
1547 TEST_F(WorkspaceWindowResizerTest, DontExceedMaxWidth) {
1548 UpdateDisplay("600x800");
1549 aura::Window* root = Shell::GetPrimaryRootWindow();
1550 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1552 // Four 100x100 windows flush against eachother, starting at 100,100.
1553 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1554 window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
1555 window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
1556 window4_->SetBounds(gfx::Rect(400, 100, 100, 100));
1557 delegate2_.set_max_size(gfx::Size(101, 0));
1558 delegate3_.set_max_size(gfx::Size(101, 0));
1560 std::vector<aura::Window*> windows;
1561 windows.push_back(window2_.get());
1562 windows.push_back(window3_.get());
1563 windows.push_back(window4_.get());
1564 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
1565 window_.get(), gfx::Point(), HTRIGHT,
1566 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1567 ASSERT_TRUE(resizer.get());
1568 // Move it 52 to the left, which should contract w1 and expand w2-4.
1569 resizer->Drag(CalculateDragPoint(*resizer, -52, 0), 0);
1570 EXPECT_EQ("100,100 48x100", window_->bounds().ToString());
1571 EXPECT_EQ("148,100 101x100", window2_->bounds().ToString());
1572 EXPECT_EQ("249,100 101x100", window3_->bounds().ToString());
1573 EXPECT_EQ("350,100 150x100", window4_->bounds().ToString());
1576 TEST_F(WorkspaceWindowResizerTest, DontExceedMaxHeight) {
1577 UpdateDisplay("600x800");
1578 aura::Window* root = Shell::GetPrimaryRootWindow();
1579 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1581 // Four 100x100 windows flush against eachother, starting at 100,100.
1582 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1583 window2_->SetBounds(gfx::Rect(100, 200, 100, 100));
1584 window3_->SetBounds(gfx::Rect(100, 300, 100, 100));
1585 window4_->SetBounds(gfx::Rect(100, 400, 100, 100));
1586 delegate2_.set_max_size(gfx::Size(0, 101));
1587 delegate3_.set_max_size(gfx::Size(0, 101));
1589 std::vector<aura::Window*> windows;
1590 windows.push_back(window2_.get());
1591 windows.push_back(window3_.get());
1592 windows.push_back(window4_.get());
1593 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
1594 window_.get(), gfx::Point(), HTBOTTOM,
1595 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1596 ASSERT_TRUE(resizer.get());
1597 // Move it 52 up, which should contract w1 and expand w2-4.
1598 resizer->Drag(CalculateDragPoint(*resizer, 0, -52), 0);
1599 EXPECT_EQ("100,100 100x48", window_->bounds().ToString());
1600 EXPECT_EQ("100,148 100x101", window2_->bounds().ToString());
1601 EXPECT_EQ("100,249 100x101", window3_->bounds().ToString());
1602 EXPECT_EQ("100,350 100x150", window4_->bounds().ToString());
1605 #if defined(OS_WIN)
1606 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
1607 #define MAYBE_DontExceedMinHeight DISABLED_DontExceedMinHeight
1608 #else
1609 #define MAYBE_DontExceedMinHeight DontExceedMinHeight
1610 #endif
1612 TEST_F(WorkspaceWindowResizerTest, MAYBE_DontExceedMinHeight) {
1613 UpdateDisplay("600x500");
1614 aura::Window* root = Shell::GetPrimaryRootWindow();
1615 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1617 // Four 100x100 windows flush against eachother, starting at 100,100.
1618 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1619 window2_->SetBounds(gfx::Rect(100, 200, 100, 100));
1620 window3_->SetBounds(gfx::Rect(100, 300, 100, 100));
1621 window4_->SetBounds(gfx::Rect(100, 400, 100, 100));
1622 delegate2_.set_min_size(gfx::Size(0, 99));
1623 delegate3_.set_min_size(gfx::Size(0, 99));
1625 std::vector<aura::Window*> windows;
1626 windows.push_back(window2_.get());
1627 windows.push_back(window3_.get());
1628 windows.push_back(window4_.get());
1629 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
1630 window_.get(), gfx::Point(), HTBOTTOM,
1631 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1632 ASSERT_TRUE(resizer.get());
1633 // Move it 52 down, which should expand w1 and contract w2-4.
1634 resizer->Drag(CalculateDragPoint(*resizer, 0, 52), 0);
1635 EXPECT_EQ("100,100 100x152", window_->bounds().ToString());
1636 EXPECT_EQ("100,252 100x99", window2_->bounds().ToString());
1637 EXPECT_EQ("100,351 100x99", window3_->bounds().ToString());
1638 EXPECT_EQ("100,450 100x50", window4_->bounds().ToString());
1641 TEST_F(WorkspaceWindowResizerTest, DontExpandRightmostPastMaxWidth) {
1642 UpdateDisplay("600x800");
1643 aura::Window* root = Shell::GetPrimaryRootWindow();
1644 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1646 // Three 100x100 windows flush against eachother, starting at 100,100.
1647 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1648 window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
1649 window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
1650 delegate3_.set_max_size(gfx::Size(101, 0));
1652 std::vector<aura::Window*> windows;
1653 windows.push_back(window2_.get());
1654 windows.push_back(window3_.get());
1655 windows.push_back(window4_.get());
1656 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
1657 window_.get(), gfx::Point(), HTRIGHT,
1658 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1659 ASSERT_TRUE(resizer.get());
1660 // Move it 51 to the left, which should contract w1 and expand w2-3.
1661 resizer->Drag(CalculateDragPoint(*resizer, -51, 0), 0);
1662 EXPECT_EQ("100,100 49x100", window_->bounds().ToString());
1663 EXPECT_EQ("149,100 150x100", window2_->bounds().ToString());
1664 EXPECT_EQ("299,100 101x100", window3_->bounds().ToString());
1667 TEST_F(WorkspaceWindowResizerTest, MoveAttachedWhenGrownToMaxSize) {
1668 UpdateDisplay("600x800");
1669 aura::Window* root = Shell::GetPrimaryRootWindow();
1670 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1672 // Three 100x100 windows flush against eachother, starting at 100,100.
1673 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1674 window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
1675 window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
1676 delegate2_.set_max_size(gfx::Size(101, 0));
1677 delegate3_.set_max_size(gfx::Size(101, 0));
1679 std::vector<aura::Window*> windows;
1680 windows.push_back(window2_.get());
1681 windows.push_back(window3_.get());
1682 windows.push_back(window4_.get());
1683 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
1684 window_.get(), gfx::Point(), HTRIGHT,
1685 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1686 ASSERT_TRUE(resizer.get());
1687 // Move it 52 to the left, which should contract w1 and expand and move w2-3.
1688 resizer->Drag(CalculateDragPoint(*resizer, -52, 0), 0);
1689 EXPECT_EQ("100,100 48x100", window_->bounds().ToString());
1690 EXPECT_EQ("148,100 101x100", window2_->bounds().ToString());
1691 EXPECT_EQ("249,100 101x100", window3_->bounds().ToString());
1694 #if defined(OS_WIN)
1695 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
1696 #define MAYBE_MainWindowHonoursMaxWidth DISABLED_MainWindowHonoursMaxWidth
1697 #else
1698 #define MAYBE_MainWindowHonoursMaxWidth MainWindowHonoursMaxWidth
1699 #endif
1701 TEST_F(WorkspaceWindowResizerTest, MAYBE_MainWindowHonoursMaxWidth) {
1702 UpdateDisplay("400x800");
1703 aura::Window* root = Shell::GetPrimaryRootWindow();
1704 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1706 // Three 100x100 windows flush against eachother, starting at 100,100.
1707 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1708 window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
1709 window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
1710 delegate_.set_max_size(gfx::Size(102, 0));
1712 std::vector<aura::Window*> windows;
1713 windows.push_back(window2_.get());
1714 windows.push_back(window3_.get());
1715 windows.push_back(window4_.get());
1716 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
1717 window_.get(), gfx::Point(), HTRIGHT,
1718 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1719 ASSERT_TRUE(resizer.get());
1720 // Move it 50 to the right, which should expand w1 and contract w2-3, as they
1721 // won't fit in the root window in their original sizes.
1722 resizer->Drag(CalculateDragPoint(*resizer, 50, 0), 0);
1723 EXPECT_EQ("100,100 102x100", window_->bounds().ToString());
1724 EXPECT_EQ("202,100 99x100", window2_->bounds().ToString());
1725 EXPECT_EQ("301,100 99x100", window3_->bounds().ToString());
1728 TEST_F(WorkspaceWindowResizerTest, MainWindowHonoursMinWidth) {
1729 UpdateDisplay("400x800");
1730 aura::Window* root = Shell::GetPrimaryRootWindow();
1731 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1733 // Three 100x100 windows flush against eachother, starting at 100,100.
1734 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1735 window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
1736 window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
1737 delegate_.set_min_size(gfx::Size(98, 0));
1739 std::vector<aura::Window*> windows;
1740 windows.push_back(window2_.get());
1741 windows.push_back(window3_.get());
1742 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
1743 window_.get(), gfx::Point(), HTRIGHT,
1744 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1745 ASSERT_TRUE(resizer.get());
1746 // Move it 50 to the left, which should contract w1 and expand w2-3.
1747 resizer->Drag(CalculateDragPoint(*resizer, -50, 0), 0);
1748 EXPECT_EQ("100,100 98x100", window_->bounds().ToString());
1749 EXPECT_EQ("198,100 101x100", window2_->bounds().ToString());
1750 EXPECT_EQ("299,100 101x100", window3_->bounds().ToString());
1753 // The following variants test that windows are resized correctly to the edges
1754 // of the screen using touch, when touch point is off of the window border.
1755 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_RIGHT) {
1756 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1758 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTRIGHT);
1759 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
1760 touch_resize_window_->bounds().ToString());
1762 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1763 touch_resize_window_.get());
1765 // Drag out of the right border a bit and check if the border is aligned with
1766 // the touch point.
1767 generator.GestureScrollSequence(gfx::Point(715, kRootHeight / 2),
1768 gfx::Point(725, kRootHeight / 2),
1769 base::TimeDelta::FromMilliseconds(10),
1771 EXPECT_EQ(gfx::Rect(100, 100, 625, kRootHeight - 200).ToString(),
1772 touch_resize_window_->bounds().ToString());
1773 // Drag more, but stop before being snapped to the edge.
1774 generator.GestureScrollSequence(gfx::Point(725, kRootHeight / 2),
1775 gfx::Point(760, kRootHeight / 2),
1776 base::TimeDelta::FromMilliseconds(10),
1778 EXPECT_EQ(gfx::Rect(100, 100, 660, kRootHeight - 200).ToString(),
1779 touch_resize_window_->bounds().ToString());
1780 // Drag even more to snap to the edge.
1781 generator.GestureScrollSequence(gfx::Point(760, kRootHeight / 2),
1782 gfx::Point(775, kRootHeight / 2),
1783 base::TimeDelta::FromMilliseconds(10),
1785 EXPECT_EQ(gfx::Rect(100, 100, 700, kRootHeight - 200).ToString(),
1786 touch_resize_window_->bounds().ToString());
1789 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_LEFT) {
1790 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1792 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTLEFT);
1793 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
1794 touch_resize_window_->bounds().ToString());
1796 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1797 touch_resize_window_.get());
1799 // Drag out of the left border a bit and check if the border is aligned with
1800 // the touch point.
1801 generator.GestureScrollSequence(gfx::Point(85, kRootHeight / 2),
1802 gfx::Point(75, kRootHeight / 2),
1803 base::TimeDelta::FromMilliseconds(10),
1805 EXPECT_EQ(gfx::Rect(75, 100, 625, kRootHeight - 200).ToString(),
1806 touch_resize_window_->bounds().ToString());
1807 // Drag more, but stop before being snapped to the edge.
1808 generator.GestureScrollSequence(gfx::Point(75, kRootHeight / 2),
1809 gfx::Point(40, kRootHeight / 2),
1810 base::TimeDelta::FromMilliseconds(10),
1812 EXPECT_EQ(gfx::Rect(40, 100, 660, kRootHeight - 200).ToString(),
1813 touch_resize_window_->bounds().ToString());
1814 // Drag even more to snap to the edge.
1815 generator.GestureScrollSequence(gfx::Point(40, kRootHeight / 2),
1816 gfx::Point(25, kRootHeight / 2),
1817 base::TimeDelta::FromMilliseconds(10),
1819 EXPECT_EQ(gfx::Rect(0, 100, 700, kRootHeight - 200).ToString(),
1820 touch_resize_window_->bounds().ToString());
1823 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_TOP) {
1824 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1826 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTTOP);
1827 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
1828 touch_resize_window_->bounds().ToString());
1830 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1831 touch_resize_window_.get());
1833 // Drag out of the top border a bit and check if the border is aligned with
1834 // the touch point.
1835 generator.GestureScrollSequence(gfx::Point(400, 85),
1836 gfx::Point(400, 75),
1837 base::TimeDelta::FromMilliseconds(10),
1839 EXPECT_EQ(gfx::Rect(100, 75, 600, kRootHeight - 175).ToString(),
1840 touch_resize_window_->bounds().ToString());
1841 // Drag more, but stop before being snapped to the edge.
1842 generator.GestureScrollSequence(gfx::Point(400, 75),
1843 gfx::Point(400, 40),
1844 base::TimeDelta::FromMilliseconds(10),
1846 EXPECT_EQ(gfx::Rect(100, 40, 600, kRootHeight - 140).ToString(),
1847 touch_resize_window_->bounds().ToString());
1848 // Drag even more to snap to the edge.
1849 generator.GestureScrollSequence(gfx::Point(400, 40),
1850 gfx::Point(400, 25),
1851 base::TimeDelta::FromMilliseconds(10),
1853 EXPECT_EQ(gfx::Rect(100, 0, 600, kRootHeight - 100).ToString(),
1854 touch_resize_window_->bounds().ToString());
1857 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_BOTTOM) {
1858 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1860 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTBOTTOM);
1861 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
1862 touch_resize_window_->bounds().ToString());
1864 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1865 touch_resize_window_.get());
1867 // Drag out of the bottom border a bit and check if the border is aligned with
1868 // the touch point.
1869 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 85),
1870 gfx::Point(400, kRootHeight - 75),
1871 base::TimeDelta::FromMilliseconds(10),
1873 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 175).ToString(),
1874 touch_resize_window_->bounds().ToString());
1875 // Drag more, but stop before being snapped to the edge.
1876 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 75),
1877 gfx::Point(400, kRootHeight - 40),
1878 base::TimeDelta::FromMilliseconds(10),
1880 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 140).ToString(),
1881 touch_resize_window_->bounds().ToString());
1882 // Drag even more to snap to the edge.
1883 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 40),
1884 gfx::Point(400, kRootHeight - 25),
1885 base::TimeDelta::FromMilliseconds(10),
1887 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 100).ToString(),
1888 touch_resize_window_->bounds().ToString());
1891 } // namespace ash