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

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

Issue 15008002: Make touch-resizing windows to screen edge possible (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adjust unit tests with final behavior Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/wm/workspace/workspace_window_resizer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/workspace/workspace_window_resizer.h" 5 #include "ash/wm/workspace/workspace_window_resizer.h"
6 6
7 #include "ash/ash_constants.h"
7 #include "ash/ash_switches.h" 8 #include "ash/ash_switches.h"
8 #include "ash/display/display_controller.h" 9 #include "ash/display/display_controller.h"
9 #include "ash/root_window_controller.h" 10 #include "ash/root_window_controller.h"
10 #include "ash/screen_ash.h" 11 #include "ash/screen_ash.h"
11 #include "ash/shelf/shelf_layout_manager.h" 12 #include "ash/shelf/shelf_layout_manager.h"
12 #include "ash/shell.h" 13 #include "ash/shell.h"
13 #include "ash/shell_window_ids.h" 14 #include "ash/shell_window_ids.h"
14 #include "ash/test/ash_test_base.h" 15 #include "ash/test/ash_test_base.h"
15 #include "ash/wm/property_util.h" 16 #include "ash/wm/property_util.h"
16 #include "ash/wm/window_util.h" 17 #include "ash/wm/window_util.h"
17 #include "ash/wm/workspace/phantom_window_controller.h" 18 #include "ash/wm/workspace/phantom_window_controller.h"
18 #include "ash/wm/workspace/snap_sizer.h" 19 #include "ash/wm/workspace/snap_sizer.h"
19 #include "ash/wm/workspace_controller.h" 20 #include "ash/wm/workspace_controller.h"
20 #include "base/command_line.h" 21 #include "base/command_line.h"
21 #include "base/stringprintf.h" 22 #include "base/stringprintf.h"
22 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
23 #include "ui/aura/client/aura_constants.h" 24 #include "ui/aura/client/aura_constants.h"
24 #include "ui/aura/root_window.h" 25 #include "ui/aura/root_window.h"
26 #include "ui/aura/test/event_generator.h"
25 #include "ui/aura/test/test_window_delegate.h" 27 #include "ui/aura/test/test_window_delegate.h"
26 #include "ui/base/hit_test.h" 28 #include "ui/base/hit_test.h"
27 #include "ui/gfx/insets.h" 29 #include "ui/gfx/insets.h"
28 #include "ui/gfx/screen.h" 30 #include "ui/gfx/screen.h"
29 #include "ui/views/widget/widget.h" 31 #include "ui/views/widget/widget.h"
30 32
31 namespace ash { 33 namespace ash {
32 namespace internal { 34 namespace internal {
33 namespace { 35 namespace {
34 36
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 window4_->Init(ui::LAYER_NOT_DRAWN); 108 window4_->Init(ui::LAYER_NOT_DRAWN);
107 SetDefaultParentByPrimaryRootWindow(window4_.get()); 109 SetDefaultParentByPrimaryRootWindow(window4_.get());
108 window4_->set_id(4); 110 window4_->set_id(4);
109 } 111 }
110 112
111 virtual void TearDown() OVERRIDE { 113 virtual void TearDown() OVERRIDE {
112 window_.reset(); 114 window_.reset();
113 window2_.reset(); 115 window2_.reset();
114 window3_.reset(); 116 window3_.reset();
115 window4_.reset(); 117 window4_.reset();
118 touch_resize_window_.reset();
116 AshTestBase::TearDown(); 119 AshTestBase::TearDown();
117 } 120 }
118 121
119 // Returns a string identifying the z-order of each of the known child windows 122 // Returns a string identifying the z-order of each of the known child windows
120 // of |parent|. The returned string constains the id of the known windows and 123 // of |parent|. The returned string constains the id of the known windows and
121 // is ordered from topmost to bottomost windows. 124 // is ordered from topmost to bottomost windows.
122 std::string WindowOrderAsString(aura::Window* parent) const { 125 std::string WindowOrderAsString(aura::Window* parent) const {
123 std::string result; 126 std::string result;
124 const aura::Window::Windows& windows = parent->children(); 127 const aura::Window::Windows& windows = parent->children();
125 for (aura::Window::Windows::const_reverse_iterator i = windows.rbegin(); 128 for (aura::Window::Windows::const_reverse_iterator i = windows.rbegin();
(...skipping 18 matching lines...) Expand all
144 } 147 }
145 148
146 std::vector<aura::Window*> empty_windows() const { 149 std::vector<aura::Window*> empty_windows() const {
147 return std::vector<aura::Window*>(); 150 return std::vector<aura::Window*>();
148 } 151 }
149 152
150 internal::ShelfLayoutManager* shelf_layout_manager() { 153 internal::ShelfLayoutManager* shelf_layout_manager() {
151 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); 154 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
152 } 155 }
153 156
157 void InitTouchResizeWindow(const gfx::Rect& bounds, int window_component) {
158 touch_resize_delegate_.set_window_component(window_component);
159 touch_resize_window_.reset(
160 CreateTestWindowInShellWithDelegate(&touch_resize_delegate_, 0,
161 bounds));
162 gfx::Insets mouse_insets = gfx::Insets(-ash::kResizeOutsideBoundsSize,
163 -ash::kResizeOutsideBoundsSize,
164 -ash::kResizeOutsideBoundsSize,
165 -ash::kResizeOutsideBoundsSize);
166 gfx::Insets touch_insets = mouse_insets.Scale(
167 ash::kResizeOutsideBoundsScaleForTouch);
168 touch_resize_window_->SetHitTestBoundsOverrideOuter(mouse_insets,
169 touch_insets);
170 touch_resize_window_->set_hit_test_bounds_override_inner(mouse_insets);
171 }
172
154 TestWindowDelegate delegate_; 173 TestWindowDelegate delegate_;
155 TestWindowDelegate delegate2_; 174 TestWindowDelegate delegate2_;
156 TestWindowDelegate delegate3_; 175 TestWindowDelegate delegate3_;
157 TestWindowDelegate delegate4_; 176 TestWindowDelegate delegate4_;
158 scoped_ptr<aura::Window> window_; 177 scoped_ptr<aura::Window> window_;
159 scoped_ptr<aura::Window> window2_; 178 scoped_ptr<aura::Window> window2_;
160 scoped_ptr<aura::Window> window3_; 179 scoped_ptr<aura::Window> window3_;
161 scoped_ptr<aura::Window> window4_; 180 scoped_ptr<aura::Window> window4_;
162 181
182 TestWindowDelegate touch_resize_delegate_;
183 scoped_ptr<aura::Window> touch_resize_window_;
184
163 private: 185 private:
164 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest); 186 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest);
165 }; 187 };
166 188
167 class WorkspaceWindowResizerTestSticky : public WorkspaceWindowResizerTest { 189 class WorkspaceWindowResizerTestSticky : public WorkspaceWindowResizerTest {
168 public: 190 public:
169 WorkspaceWindowResizerTestSticky() {} 191 WorkspaceWindowResizerTestSticky() {}
170 virtual ~WorkspaceWindowResizerTestSticky() {} 192 virtual ~WorkspaceWindowResizerTestSticky() {}
171 193
172 virtual void SetUp() OVERRIDE { 194 virtual void SetUp() OVERRIDE {
(...skipping 10 matching lines...) Expand all
183 205
184 // Assertions around attached window resize dragging from the right with 2 206 // Assertions around attached window resize dragging from the right with 2
185 // windows. 207 // windows.
186 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2) { 208 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2) {
187 window_->SetBounds(gfx::Rect(0, 300, 400, 300)); 209 window_->SetBounds(gfx::Rect(0, 300, 400, 300));
188 window2_->SetBounds(gfx::Rect(400, 200, 100, 200)); 210 window2_->SetBounds(gfx::Rect(400, 200, 100, 200));
189 211
190 std::vector<aura::Window*> windows; 212 std::vector<aura::Window*> windows;
191 windows.push_back(window2_.get()); 213 windows.push_back(window2_.get());
192 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 214 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
193 window_.get(), gfx::Point(), HTRIGHT, windows)); 215 window_.get(), gfx::Point(), HTRIGHT,
216 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
194 ASSERT_TRUE(resizer.get()); 217 ASSERT_TRUE(resizer.get());
195 // Move it 100 to the right, which should expand w1 and push w2. 218 // Move it 100 to the right, which should expand w1 and push w2.
196 resizer->Drag(CalculateDragPoint(*resizer, 100, 10), 0); 219 resizer->Drag(CalculateDragPoint(*resizer, 100, 10), 0);
197 EXPECT_EQ("0,300 500x300", window_->bounds().ToString()); 220 EXPECT_EQ("0,300 500x300", window_->bounds().ToString());
198 EXPECT_EQ("500,200 100x200", window2_->bounds().ToString()); 221 EXPECT_EQ("500,200 100x200", window2_->bounds().ToString());
199 222
200 // Push off the screen, w2 should be resized to its min. 223 // Push off the screen, w2 should be resized to its min.
201 delegate2_.set_min_size(gfx::Size(20, 20)); 224 delegate2_.set_min_size(gfx::Size(20, 20));
202 resizer->Drag(CalculateDragPoint(*resizer, 800, 20), 0); 225 resizer->Drag(CalculateDragPoint(*resizer, 800, 20), 0);
203 EXPECT_EQ("0,300 780x300", window_->bounds().ToString()); 226 EXPECT_EQ("0,300 780x300", window_->bounds().ToString());
(...skipping 12 matching lines...) Expand all
216 } 239 }
217 240
218 // Assertions around collapsing and expanding. 241 // Assertions around collapsing and expanding.
219 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_Compress) { 242 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_Compress) {
220 window_->SetBounds(gfx::Rect( 0, 300, 400, 300)); 243 window_->SetBounds(gfx::Rect( 0, 300, 400, 300));
221 window2_->SetBounds(gfx::Rect(400, 200, 100, 200)); 244 window2_->SetBounds(gfx::Rect(400, 200, 100, 200));
222 245
223 std::vector<aura::Window*> windows; 246 std::vector<aura::Window*> windows;
224 windows.push_back(window2_.get()); 247 windows.push_back(window2_.get());
225 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 248 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
226 window_.get(), gfx::Point(), HTRIGHT, windows)); 249 window_.get(), gfx::Point(), HTRIGHT,
250 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
227 ASSERT_TRUE(resizer.get()); 251 ASSERT_TRUE(resizer.get());
228 // Move it 100 to the left, which should expand w2 and collapse w1. 252 // Move it 100 to the left, which should expand w2 and collapse w1.
229 resizer->Drag(CalculateDragPoint(*resizer, -100, 10), 0); 253 resizer->Drag(CalculateDragPoint(*resizer, -100, 10), 0);
230 EXPECT_EQ("0,300 300x300", window_->bounds().ToString()); 254 EXPECT_EQ("0,300 300x300", window_->bounds().ToString());
231 EXPECT_EQ("300,200 200x200", window2_->bounds().ToString()); 255 EXPECT_EQ("300,200 200x200", window2_->bounds().ToString());
232 256
233 // Collapse all the way to w1's min. 257 // Collapse all the way to w1's min.
234 delegate_.set_min_size(gfx::Size(20, 20)); 258 delegate_.set_min_size(gfx::Size(20, 20));
235 resizer->Drag(CalculateDragPoint(*resizer, -800, 20), 0); 259 resizer->Drag(CalculateDragPoint(*resizer, -800, 20), 0);
236 EXPECT_EQ("0,300 20x300", window_->bounds().ToString()); 260 EXPECT_EQ("0,300 20x300", window_->bounds().ToString());
(...skipping 16 matching lines...) Expand all
253 window_->SetBounds(gfx::Rect( 100, 300, 200, 300)); 277 window_->SetBounds(gfx::Rect( 100, 300, 200, 300));
254 window2_->SetBounds(gfx::Rect(300, 300, 150, 200)); 278 window2_->SetBounds(gfx::Rect(300, 300, 150, 200));
255 window3_->SetBounds(gfx::Rect(450, 300, 100, 200)); 279 window3_->SetBounds(gfx::Rect(450, 300, 100, 200));
256 delegate2_.set_min_size(gfx::Size(52, 50)); 280 delegate2_.set_min_size(gfx::Size(52, 50));
257 delegate3_.set_min_size(gfx::Size(38, 50)); 281 delegate3_.set_min_size(gfx::Size(38, 50));
258 282
259 std::vector<aura::Window*> windows; 283 std::vector<aura::Window*> windows;
260 windows.push_back(window2_.get()); 284 windows.push_back(window2_.get());
261 windows.push_back(window3_.get()); 285 windows.push_back(window3_.get());
262 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 286 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
263 window_.get(), gfx::Point(), HTRIGHT, windows)); 287 window_.get(), gfx::Point(), HTRIGHT,
288 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
264 ASSERT_TRUE(resizer.get()); 289 ASSERT_TRUE(resizer.get());
265 // Move it 100 to the right, which should expand w1 and push w2 and w3. 290 // Move it 100 to the right, which should expand w1 and push w2 and w3.
266 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0); 291 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
267 EXPECT_EQ("100,300 300x300", window_->bounds().ToString()); 292 EXPECT_EQ("100,300 300x300", window_->bounds().ToString());
268 EXPECT_EQ("400,300 150x200", window2_->bounds().ToString()); 293 EXPECT_EQ("400,300 150x200", window2_->bounds().ToString());
269 EXPECT_EQ("550,300 100x200", window3_->bounds().ToString()); 294 EXPECT_EQ("550,300 100x200", window3_->bounds().ToString());
270 295
271 // Move it 300, things should compress. 296 // Move it 300, things should compress.
272 resizer->Drag(CalculateDragPoint(*resizer, 300, -10), 0); 297 resizer->Drag(CalculateDragPoint(*resizer, 300, -10), 0);
273 EXPECT_EQ("100,300 500x300", window_->bounds().ToString()); 298 EXPECT_EQ("100,300 500x300", window_->bounds().ToString());
(...skipping 19 matching lines...) Expand all
293 window_->SetBounds(gfx::Rect( 100, 300, 200, 300)); 318 window_->SetBounds(gfx::Rect( 100, 300, 200, 300));
294 window2_->SetBounds(gfx::Rect(300, 300, 200, 200)); 319 window2_->SetBounds(gfx::Rect(300, 300, 200, 200));
295 window3_->SetBounds(gfx::Rect(450, 300, 100, 200)); 320 window3_->SetBounds(gfx::Rect(450, 300, 100, 200));
296 delegate2_.set_min_size(gfx::Size(52, 50)); 321 delegate2_.set_min_size(gfx::Size(52, 50));
297 delegate3_.set_min_size(gfx::Size(38, 50)); 322 delegate3_.set_min_size(gfx::Size(38, 50));
298 323
299 std::vector<aura::Window*> windows; 324 std::vector<aura::Window*> windows;
300 windows.push_back(window2_.get()); 325 windows.push_back(window2_.get());
301 windows.push_back(window3_.get()); 326 windows.push_back(window3_.get());
302 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 327 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
303 window_.get(), gfx::Point(), HTRIGHT, windows)); 328 window_.get(), gfx::Point(), HTRIGHT,
329 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
304 ASSERT_TRUE(resizer.get()); 330 ASSERT_TRUE(resizer.get());
305 // Move it -100 to the right, which should collapse w1 and expand w2 and w3. 331 // Move it -100 to the right, which should collapse w1 and expand w2 and w3.
306 resizer->Drag(CalculateDragPoint(*resizer, -100, -10), 0); 332 resizer->Drag(CalculateDragPoint(*resizer, -100, -10), 0);
307 EXPECT_EQ("100,300 100x300", window_->bounds().ToString()); 333 EXPECT_EQ("100,300 100x300", window_->bounds().ToString());
308 EXPECT_EQ("200,300 266x200", window2_->bounds().ToString()); 334 EXPECT_EQ("200,300 266x200", window2_->bounds().ToString());
309 EXPECT_EQ("466,300 134x200", window3_->bounds().ToString()); 335 EXPECT_EQ("466,300 134x200", window3_->bounds().ToString());
310 336
311 // Move it 100 to the right. 337 // Move it 100 to the right.
312 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0); 338 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
313 EXPECT_EQ("100,300 300x300", window_->bounds().ToString()); 339 EXPECT_EQ("100,300 300x300", window_->bounds().ToString());
314 EXPECT_EQ("400,300 200x200", window2_->bounds().ToString()); 340 EXPECT_EQ("400,300 200x200", window2_->bounds().ToString());
315 EXPECT_EQ("600,300 100x200", window3_->bounds().ToString()); 341 EXPECT_EQ("600,300 100x200", window3_->bounds().ToString());
316 342
317 // 100 to the left again. 343 // 100 to the left again.
318 resizer->Drag(CalculateDragPoint(*resizer, -100, -10), 0); 344 resizer->Drag(CalculateDragPoint(*resizer, -100, -10), 0);
319 EXPECT_EQ("100,300 100x300", window_->bounds().ToString()); 345 EXPECT_EQ("100,300 100x300", window_->bounds().ToString());
320 EXPECT_EQ("200,300 266x200", window2_->bounds().ToString()); 346 EXPECT_EQ("200,300 266x200", window2_->bounds().ToString());
321 EXPECT_EQ("466,300 134x200", window3_->bounds().ToString()); 347 EXPECT_EQ("466,300 134x200", window3_->bounds().ToString());
322 } 348 }
323 349
324 // Assertions around collapsing and expanding from the bottom. 350 // Assertions around collapsing and expanding from the bottom.
325 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_Compress) { 351 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_Compress) {
326 window_->SetBounds(gfx::Rect( 0, 100, 400, 300)); 352 window_->SetBounds(gfx::Rect( 0, 100, 400, 300));
327 window2_->SetBounds(gfx::Rect(400, 400, 100, 200)); 353 window2_->SetBounds(gfx::Rect(400, 400, 100, 200));
328 354
329 std::vector<aura::Window*> windows; 355 std::vector<aura::Window*> windows;
330 windows.push_back(window2_.get()); 356 windows.push_back(window2_.get());
331 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 357 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
332 window_.get(), gfx::Point(), HTBOTTOM, windows)); 358 window_.get(), gfx::Point(), HTBOTTOM,
359 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
333 ASSERT_TRUE(resizer.get()); 360 ASSERT_TRUE(resizer.get());
334 // Move it up 100, which should expand w2 and collapse w1. 361 // Move it up 100, which should expand w2 and collapse w1.
335 resizer->Drag(CalculateDragPoint(*resizer, 10, -100), 0); 362 resizer->Drag(CalculateDragPoint(*resizer, 10, -100), 0);
336 EXPECT_EQ("0,100 400x200", window_->bounds().ToString()); 363 EXPECT_EQ("0,100 400x200", window_->bounds().ToString());
337 EXPECT_EQ("400,300 100x300", window2_->bounds().ToString()); 364 EXPECT_EQ("400,300 100x300", window2_->bounds().ToString());
338 365
339 // Collapse all the way to w1's min. 366 // Collapse all the way to w1's min.
340 delegate_.set_min_size(gfx::Size(20, 20)); 367 delegate_.set_min_size(gfx::Size(20, 20));
341 resizer->Drag(CalculateDragPoint(*resizer, 20, -800), 0); 368 resizer->Drag(CalculateDragPoint(*resizer, 20, -800), 0);
342 EXPECT_EQ("0,100 400x20", window_->bounds().ToString()); 369 EXPECT_EQ("0,100 400x20", window_->bounds().ToString());
(...skipping 12 matching lines...) Expand all
355 382
356 // Assertions around attached window resize dragging from the bottom with 2 383 // Assertions around attached window resize dragging from the bottom with 2
357 // windows. 384 // windows.
358 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_2) { 385 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_2) {
359 window_->SetBounds(gfx::Rect( 0, 50, 400, 200)); 386 window_->SetBounds(gfx::Rect( 0, 50, 400, 200));
360 window2_->SetBounds(gfx::Rect(0, 250, 200, 100)); 387 window2_->SetBounds(gfx::Rect(0, 250, 200, 100));
361 388
362 std::vector<aura::Window*> windows; 389 std::vector<aura::Window*> windows;
363 windows.push_back(window2_.get()); 390 windows.push_back(window2_.get());
364 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 391 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
365 window_.get(), gfx::Point(), HTBOTTOM, windows)); 392 window_.get(), gfx::Point(), HTBOTTOM,
393 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
366 ASSERT_TRUE(resizer.get()); 394 ASSERT_TRUE(resizer.get());
367 // Move it 100 to the bottom, which should expand w1 and push w2. 395 // Move it 100 to the bottom, which should expand w1 and push w2.
368 resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0); 396 resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0);
369 EXPECT_EQ("0,50 400x300", window_->bounds().ToString()); 397 EXPECT_EQ("0,50 400x300", window_->bounds().ToString());
370 EXPECT_EQ("0,350 200x100", window2_->bounds().ToString()); 398 EXPECT_EQ("0,350 200x100", window2_->bounds().ToString());
371 399
372 // Push off the screen, w2 should be resized to its min. 400 // Push off the screen, w2 should be resized to its min.
373 delegate2_.set_min_size(gfx::Size(20, 20)); 401 delegate2_.set_min_size(gfx::Size(20, 20));
374 resizer->Drag(CalculateDragPoint(*resizer, 50, 820), 0); 402 resizer->Drag(CalculateDragPoint(*resizer, 50, 820), 0);
375 EXPECT_EQ("0,50 400x530", window_->bounds().ToString()); 403 EXPECT_EQ("0,50 400x530", window_->bounds().ToString());
(...skipping 28 matching lines...) Expand all
404 window_->SetBounds(gfx::Rect( 300, 100, 300, 200)); 432 window_->SetBounds(gfx::Rect( 300, 100, 300, 200));
405 window2_->SetBounds(gfx::Rect(300, 300, 200, 150)); 433 window2_->SetBounds(gfx::Rect(300, 300, 200, 150));
406 window3_->SetBounds(gfx::Rect(300, 450, 200, 100)); 434 window3_->SetBounds(gfx::Rect(300, 450, 200, 100));
407 delegate2_.set_min_size(gfx::Size(50, 52)); 435 delegate2_.set_min_size(gfx::Size(50, 52));
408 delegate3_.set_min_size(gfx::Size(50, 38)); 436 delegate3_.set_min_size(gfx::Size(50, 38));
409 437
410 std::vector<aura::Window*> windows; 438 std::vector<aura::Window*> windows;
411 windows.push_back(window2_.get()); 439 windows.push_back(window2_.get());
412 windows.push_back(window3_.get()); 440 windows.push_back(window3_.get());
413 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 441 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
414 window_.get(), gfx::Point(), HTBOTTOM, windows)); 442 window_.get(), gfx::Point(), HTBOTTOM,
443 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
415 ASSERT_TRUE(resizer.get()); 444 ASSERT_TRUE(resizer.get());
416 // Move it 100 down, which should expand w1 and push w2 and w3. 445 // Move it 100 down, which should expand w1 and push w2 and w3.
417 resizer->Drag(CalculateDragPoint(*resizer, -10, 100), 0); 446 resizer->Drag(CalculateDragPoint(*resizer, -10, 100), 0);
418 EXPECT_EQ("300,100 300x300", window_->bounds().ToString()); 447 EXPECT_EQ("300,100 300x300", window_->bounds().ToString());
419 EXPECT_EQ("300,400 200x150", window2_->bounds().ToString()); 448 EXPECT_EQ("300,400 200x150", window2_->bounds().ToString());
420 EXPECT_EQ("300,550 200x100", window3_->bounds().ToString()); 449 EXPECT_EQ("300,550 200x100", window3_->bounds().ToString());
421 450
422 // Move it 296 things should compress. 451 // Move it 296 things should compress.
423 resizer->Drag(CalculateDragPoint(*resizer, -10, 296), 0); 452 resizer->Drag(CalculateDragPoint(*resizer, -10, 296), 0);
424 EXPECT_EQ("300,100 300x496", window_->bounds().ToString()); 453 EXPECT_EQ("300,100 300x496", window_->bounds().ToString());
(...skipping 19 matching lines...) Expand all
444 window_->SetBounds(gfx::Rect( 0, 0, 200, 200)); 473 window_->SetBounds(gfx::Rect( 0, 0, 200, 200));
445 window2_->SetBounds(gfx::Rect(10, 200, 200, 200)); 474 window2_->SetBounds(gfx::Rect(10, 200, 200, 200));
446 window3_->SetBounds(gfx::Rect(20, 400, 100, 100)); 475 window3_->SetBounds(gfx::Rect(20, 400, 100, 100));
447 delegate2_.set_min_size(gfx::Size(52, 50)); 476 delegate2_.set_min_size(gfx::Size(52, 50));
448 delegate3_.set_min_size(gfx::Size(38, 50)); 477 delegate3_.set_min_size(gfx::Size(38, 50));
449 478
450 std::vector<aura::Window*> windows; 479 std::vector<aura::Window*> windows;
451 windows.push_back(window2_.get()); 480 windows.push_back(window2_.get());
452 windows.push_back(window3_.get()); 481 windows.push_back(window3_.get());
453 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 482 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
454 window_.get(), gfx::Point(), HTBOTTOM, windows)); 483 window_.get(), gfx::Point(), HTBOTTOM,
484 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
455 ASSERT_TRUE(resizer.get()); 485 ASSERT_TRUE(resizer.get());
456 // Move it 100 up, which should collapse w1 and expand w2 and w3. 486 // Move it 100 up, which should collapse w1 and expand w2 and w3.
457 resizer->Drag(CalculateDragPoint(*resizer, -10, -100), 0); 487 resizer->Drag(CalculateDragPoint(*resizer, -10, -100), 0);
458 EXPECT_EQ("0,0 200x100", window_->bounds().ToString()); 488 EXPECT_EQ("0,0 200x100", window_->bounds().ToString());
459 EXPECT_EQ("10,100 200x266", window2_->bounds().ToString()); 489 EXPECT_EQ("10,100 200x266", window2_->bounds().ToString());
460 EXPECT_EQ("20,366 100x134", window3_->bounds().ToString()); 490 EXPECT_EQ("20,366 100x134", window3_->bounds().ToString());
461 491
462 // Move it 100 down. 492 // Move it 100 down.
463 resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0); 493 resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0);
464 EXPECT_EQ("0,0 200x300", window_->bounds().ToString()); 494 EXPECT_EQ("0,0 200x300", window_->bounds().ToString());
(...skipping 15 matching lines...) Expand all
480 #define MAYBE_Edge Edge 510 #define MAYBE_Edge Edge
481 #endif 511 #endif
482 512
483 // Assertions around dragging to the left/right edge of the screen. 513 // Assertions around dragging to the left/right edge of the screen.
484 TEST_F(WorkspaceWindowResizerTest, MAYBE_Edge) { 514 TEST_F(WorkspaceWindowResizerTest, MAYBE_Edge) {
485 int bottom = 515 int bottom =
486 ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_.get()).bottom(); 516 ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_.get()).bottom();
487 window_->SetBounds(gfx::Rect(20, 30, 50, 60)); 517 window_->SetBounds(gfx::Rect(20, 30, 50, 60));
488 { 518 {
489 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 519 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
490 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 520 window_.get(), gfx::Point(), HTCAPTION,
521 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
491 ASSERT_TRUE(resizer.get()); 522 ASSERT_TRUE(resizer.get());
492 resizer->Drag(CalculateDragPoint(*resizer, 0, 10), 0); 523 resizer->Drag(CalculateDragPoint(*resizer, 0, 10), 0);
493 resizer->CompleteDrag(0); 524 resizer->CompleteDrag(0);
494 EXPECT_EQ("0,0 720x" + base::IntToString(bottom), 525 EXPECT_EQ("0,0 720x" + base::IntToString(bottom),
495 window_->bounds().ToString()); 526 window_->bounds().ToString());
496 ASSERT_TRUE(GetRestoreBoundsInScreen(window_.get())); 527 ASSERT_TRUE(GetRestoreBoundsInScreen(window_.get()));
497 EXPECT_EQ("20,30 50x60", 528 EXPECT_EQ("20,30 50x60",
498 GetRestoreBoundsInScreen(window_.get())->ToString()); 529 GetRestoreBoundsInScreen(window_.get())->ToString());
499 } 530 }
500 // Try the same with the right side. 531 // Try the same with the right side.
501 { 532 {
502 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 533 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
503 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 534 window_.get(), gfx::Point(), HTCAPTION,
535 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
504 ASSERT_TRUE(resizer.get()); 536 ASSERT_TRUE(resizer.get());
505 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0); 537 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0);
506 resizer->CompleteDrag(0); 538 resizer->CompleteDrag(0);
507 EXPECT_EQ("80,0 720x" + base::IntToString(bottom), 539 EXPECT_EQ("80,0 720x" + base::IntToString(bottom),
508 window_->bounds().ToString()); 540 window_->bounds().ToString());
509 ASSERT_TRUE(GetRestoreBoundsInScreen(window_.get())); 541 ASSERT_TRUE(GetRestoreBoundsInScreen(window_.get()));
510 EXPECT_EQ("20,30 50x60", 542 EXPECT_EQ("20,30 50x60",
511 GetRestoreBoundsInScreen(window_.get())->ToString()); 543 GetRestoreBoundsInScreen(window_.get())->ToString());
512 } 544 }
513 545
514 // Test if the restore bounds is correct in multiple displays. 546 // Test if the restore bounds is correct in multiple displays.
515 ClearRestoreBounds(window_.get()); 547 ClearRestoreBounds(window_.get());
516 UpdateDisplay("800x600,200x600"); 548 UpdateDisplay("800x600,200x600");
517 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 549 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
518 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 550 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
519 window_->SetBoundsInScreen(gfx::Rect(800, 10, 50, 60), 551 window_->SetBoundsInScreen(gfx::Rect(800, 10, 50, 60),
520 ScreenAsh::GetSecondaryDisplay()); 552 ScreenAsh::GetSecondaryDisplay());
521 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); 553 EXPECT_EQ(root_windows[1], window_->GetRootWindow());
522 { 554 {
523 bottom = 555 bottom =
524 ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_.get()).bottom(); 556 ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_.get()).bottom();
525 EXPECT_EQ("800,10 50x60", window_->GetBoundsInScreen().ToString()); 557 EXPECT_EQ("800,10 50x60", window_->GetBoundsInScreen().ToString());
526 558
527 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 559 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
528 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 560 window_.get(), gfx::Point(), HTCAPTION,
561 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
529 ASSERT_TRUE(resizer.get()); 562 ASSERT_TRUE(resizer.get());
530 563
531 resizer->Drag(CalculateDragPoint(*resizer, 199, 00), 0); 564 resizer->Drag(CalculateDragPoint(*resizer, 199, 00), 0);
532 resizer->CompleteDrag(0); 565 resizer->CompleteDrag(0);
533 // With the resolution of 200x600 we will hit in this case the 50% screen 566 // With the resolution of 200x600 we will hit in this case the 50% screen
534 // size setting. 567 // size setting.
535 EXPECT_EQ("100,0 100x" + base::IntToString(bottom), 568 EXPECT_EQ("100,0 100x" + base::IntToString(bottom),
536 window_->bounds().ToString()); 569 window_->bounds().ToString());
537 EXPECT_EQ("800,10 50x60", 570 EXPECT_EQ("800,10 50x60",
538 GetRestoreBoundsInScreen(window_.get())->ToString()); 571 GetRestoreBoundsInScreen(window_.get())->ToString());
539 } 572 }
540 } 573 }
541 574
542 // Check that non resizable windows will not get resized. 575 // Check that non resizable windows will not get resized.
543 TEST_F(WorkspaceWindowResizerTest, NonResizableWindows) { 576 TEST_F(WorkspaceWindowResizerTest, NonResizableWindows) {
544 window_->SetBounds(gfx::Rect(20, 30, 50, 60)); 577 window_->SetBounds(gfx::Rect(20, 30, 50, 60));
545 window_->SetProperty(aura::client::kCanResizeKey, false); 578 window_->SetProperty(aura::client::kCanResizeKey, false);
546 579
547 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 580 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
548 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 581 window_.get(), gfx::Point(), HTCAPTION,
582 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
549 ASSERT_TRUE(resizer.get()); 583 ASSERT_TRUE(resizer.get());
550 resizer->Drag(CalculateDragPoint(*resizer, -20, 0), 0); 584 resizer->Drag(CalculateDragPoint(*resizer, -20, 0), 0);
551 resizer->CompleteDrag(0); 585 resizer->CompleteDrag(0);
552 EXPECT_EQ("0,30 50x60", window_->bounds().ToString()); 586 EXPECT_EQ("0,30 50x60", window_->bounds().ToString());
553 } 587 }
554 588
555 #if defined(OS_WIN) 589 #if defined(OS_WIN)
556 // Multiple displays are not supported on Windows Ash. http://crbug.com/165962 590 // Multiple displays are not supported on Windows Ash. http://crbug.com/165962
557 #define MAYBE_CancelSnapPhantom DISABLED_CancelSnapPhantom 591 #define MAYBE_CancelSnapPhantom DISABLED_CancelSnapPhantom
558 #else 592 #else
559 #define MAYBE_CancelSnapPhantom CancelSnapPhantom 593 #define MAYBE_CancelSnapPhantom CancelSnapPhantom
560 #endif 594 #endif
561 595
562 TEST_F(WorkspaceWindowResizerTest, MAYBE_CancelSnapPhantom) { 596 TEST_F(WorkspaceWindowResizerTest, MAYBE_CancelSnapPhantom) {
563 UpdateDisplay("800x600,800x600"); 597 UpdateDisplay("800x600,800x600");
564 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 598 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
565 ASSERT_EQ(2U, root_windows.size()); 599 ASSERT_EQ(2U, root_windows.size());
566 600
567 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), 601 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
568 Shell::GetScreen()->GetPrimaryDisplay()); 602 Shell::GetScreen()->GetPrimaryDisplay());
569 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 603 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
570 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); 604 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
571 { 605 {
572 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 606 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
573 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 607 window_.get(), gfx::Point(), HTCAPTION,
608 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
574 ASSERT_TRUE(resizer.get()); 609 ASSERT_TRUE(resizer.get());
575 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); 610 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get());
576 611
577 // The pointer is on the edge but not shared. The snap phantom window 612 // The pointer is on the edge but not shared. The snap phantom window
578 // controller should be non-NULL. 613 // controller should be non-NULL.
579 resizer->Drag(CalculateDragPoint(*resizer, 799, 0), 0); 614 resizer->Drag(CalculateDragPoint(*resizer, 799, 0), 0);
580 EXPECT_TRUE(resizer->snap_phantom_window_controller_.get()); 615 EXPECT_TRUE(resizer->snap_phantom_window_controller_.get());
581 616
582 // Move the cursor across the edge. Now the snap phantom window controller 617 // Move the cursor across the edge. Now the snap phantom window controller
583 // should be canceled. 618 // should be canceled.
584 resizer->Drag(CalculateDragPoint(*resizer, 800, 0), 0); 619 resizer->Drag(CalculateDragPoint(*resizer, 800, 0), 0);
585 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); 620 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get());
586 } 621 }
587 } 622 }
588 623
589 // Verifies windows are correctly restacked when reordering multiple windows. 624 // Verifies windows are correctly restacked when reordering multiple windows.
590 TEST_F(WorkspaceWindowResizerTest, RestackAttached) { 625 TEST_F(WorkspaceWindowResizerTest, RestackAttached) {
591 window_->SetBounds(gfx::Rect( 0, 0, 200, 300)); 626 window_->SetBounds(gfx::Rect( 0, 0, 200, 300));
592 window2_->SetBounds(gfx::Rect(200, 0, 100, 200)); 627 window2_->SetBounds(gfx::Rect(200, 0, 100, 200));
593 window3_->SetBounds(gfx::Rect(300, 0, 100, 100)); 628 window3_->SetBounds(gfx::Rect(300, 0, 100, 100));
594 629
595 { 630 {
596 std::vector<aura::Window*> windows; 631 std::vector<aura::Window*> windows;
597 windows.push_back(window2_.get()); 632 windows.push_back(window2_.get());
598 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 633 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
599 window_.get(), gfx::Point(), HTRIGHT, windows)); 634 window_.get(), gfx::Point(), HTRIGHT,
635 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
600 ASSERT_TRUE(resizer.get()); 636 ASSERT_TRUE(resizer.get());
601 // Move it 100 to the right, which should expand w1 and push w2 and w3. 637 // Move it 100 to the right, which should expand w1 and push w2 and w3.
602 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0); 638 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
603 639
604 // 2 should be topmost since it's initially the highest in the stack. 640 // 2 should be topmost since it's initially the highest in the stack.
605 EXPECT_EQ("2 1 3", WindowOrderAsString(window_->parent())); 641 EXPECT_EQ("2 1 3", WindowOrderAsString(window_->parent()));
606 } 642 }
607 643
608 { 644 {
609 std::vector<aura::Window*> windows; 645 std::vector<aura::Window*> windows;
610 windows.push_back(window3_.get()); 646 windows.push_back(window3_.get());
611 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 647 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
612 window2_.get(), gfx::Point(), HTRIGHT, windows)); 648 window2_.get(), gfx::Point(), HTRIGHT,
649 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
613 ASSERT_TRUE(resizer.get()); 650 ASSERT_TRUE(resizer.get());
614 // Move it 100 to the right, which should expand w1 and push w2 and w3. 651 // Move it 100 to the right, which should expand w1 and push w2 and w3.
615 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0); 652 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
616 653
617 // 2 should be topmost since it's initially the highest in the stack. 654 // 2 should be topmost since it's initially the highest in the stack.
618 EXPECT_EQ("2 3 1", WindowOrderAsString(window_->parent())); 655 EXPECT_EQ("2 3 1", WindowOrderAsString(window_->parent()));
619 } 656 }
620 } 657 }
621 658
622 // Makes sure we don't allow dragging below the work area. 659 // Makes sure we don't allow dragging below the work area.
623 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottom) { 660 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottom) {
624 Shell::GetInstance()->SetDisplayWorkAreaInsets( 661 Shell::GetInstance()->SetDisplayWorkAreaInsets(
625 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0)); 662 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0));
626 663
627 ASSERT_EQ(1, Shell::GetScreen()->GetNumDisplays()); 664 ASSERT_EQ(1, Shell::GetScreen()->GetNumDisplays());
628 665
629 window_->SetBounds(gfx::Rect(100, 200, 300, 400)); 666 window_->SetBounds(gfx::Rect(100, 200, 300, 400));
630 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 667 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
631 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 668 window_.get(), gfx::Point(), HTCAPTION,
669 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
632 ASSERT_TRUE(resizer.get()); 670 ASSERT_TRUE(resizer.get());
633 resizer->Drag(CalculateDragPoint(*resizer, 0, 600), 0); 671 resizer->Drag(CalculateDragPoint(*resizer, 0, 600), 0);
634 int expected_y = 672 int expected_y =
635 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10; 673 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10;
636 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400", 674 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400",
637 window_->bounds().ToString()); 675 window_->bounds().ToString());
638 } 676 }
639 677
640 #if defined(OS_WIN) 678 #if defined(OS_WIN)
641 // Multiple displays are not supported on Windows Ash. http://crbug.com/165962 679 // Multiple displays are not supported on Windows Ash. http://crbug.com/165962
(...skipping 12 matching lines...) Expand all
654 Shell::GetInstance()->SetDisplayWorkAreaInsets( 692 Shell::GetInstance()->SetDisplayWorkAreaInsets(
655 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0)); 693 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0));
656 694
657 // Positions the secondary display at the bottom the primary display. 695 // Positions the secondary display at the bottom the primary display.
658 Shell::GetInstance()->display_controller()->SetLayoutForCurrentDisplays( 696 Shell::GetInstance()->display_controller()->SetLayoutForCurrentDisplays(
659 ash::DisplayLayout(ash::DisplayLayout::BOTTOM, 0)); 697 ash::DisplayLayout(ash::DisplayLayout::BOTTOM, 0));
660 698
661 { 699 {
662 window_->SetBounds(gfx::Rect(100, 200, 300, 400)); 700 window_->SetBounds(gfx::Rect(100, 200, 300, 400));
663 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 701 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
664 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 702 window_.get(), gfx::Point(), HTCAPTION,
703 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
665 ASSERT_TRUE(resizer.get()); 704 ASSERT_TRUE(resizer.get());
666 resizer->Drag(CalculateDragPoint(*resizer, 0, 400), 0); 705 resizer->Drag(CalculateDragPoint(*resizer, 0, 400), 0);
667 int expected_y = 706 int expected_y =
668 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10; 707 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10;
669 // When the mouse cursor is in the primary display, the window cannot move 708 // When the mouse cursor is in the primary display, the window cannot move
670 // on non-work area with kMinOnscreenHeight margin. 709 // on non-work area with kMinOnscreenHeight margin.
671 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400", 710 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400",
672 window_->bounds().ToString()); 711 window_->bounds().ToString());
673 } 712 }
674 713
675 { 714 {
676 window_->SetBounds(gfx::Rect(100, 200, 300, 400)); 715 window_->SetBounds(gfx::Rect(100, 200, 300, 400));
677 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 716 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
678 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 717 window_.get(), gfx::Point(), HTCAPTION,
718 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
679 ASSERT_TRUE(resizer.get()); 719 ASSERT_TRUE(resizer.get());
680 resizer->Drag(CalculateDragPoint(*resizer, 0, 600), 0); 720 resizer->Drag(CalculateDragPoint(*resizer, 0, 600), 0);
681 // The window can move to the secondary display beyond non-work area of 721 // The window can move to the secondary display beyond non-work area of
682 // the primary display. 722 // the primary display.
683 EXPECT_EQ("100,800 300x400", window_->bounds().ToString()); 723 EXPECT_EQ("100,800 300x400", window_->bounds().ToString());
684 } 724 }
685 } 725 }
686 726
687 // Makes sure we don't allow dragging off the top of the work area. 727 // Makes sure we don't allow dragging off the top of the work area.
688 TEST_F(WorkspaceWindowResizerTest, DontDragOffTop) { 728 TEST_F(WorkspaceWindowResizerTest, DontDragOffTop) {
689 Shell::GetInstance()->SetDisplayWorkAreaInsets( 729 Shell::GetInstance()->SetDisplayWorkAreaInsets(
690 Shell::GetPrimaryRootWindow(), gfx::Insets(10, 0, 0, 0)); 730 Shell::GetPrimaryRootWindow(), gfx::Insets(10, 0, 0, 0));
691 731
692 window_->SetBounds(gfx::Rect(100, 200, 300, 400)); 732 window_->SetBounds(gfx::Rect(100, 200, 300, 400));
693 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 733 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
694 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 734 window_.get(), gfx::Point(), HTCAPTION,
735 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
695 ASSERT_TRUE(resizer.get()); 736 ASSERT_TRUE(resizer.get());
696 resizer->Drag(CalculateDragPoint(*resizer, 0, -600), 0); 737 resizer->Drag(CalculateDragPoint(*resizer, 0, -600), 0);
697 EXPECT_EQ("100,10 300x400", window_->bounds().ToString()); 738 EXPECT_EQ("100,10 300x400", window_->bounds().ToString());
698 } 739 }
699 740
700 TEST_F(WorkspaceWindowResizerTest, ResizeBottomOutsideWorkArea) { 741 TEST_F(WorkspaceWindowResizerTest, ResizeBottomOutsideWorkArea) {
701 Shell::GetInstance()->SetDisplayWorkAreaInsets( 742 Shell::GetInstance()->SetDisplayWorkAreaInsets(
702 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0)); 743 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
703 744
704 window_->SetBounds(gfx::Rect(100, 200, 300, 380)); 745 window_->SetBounds(gfx::Rect(100, 200, 300, 380));
705 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 746 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
706 window_.get(), gfx::Point(), HTTOP, empty_windows())); 747 window_.get(), gfx::Point(), HTTOP,
748 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
707 ASSERT_TRUE(resizer.get()); 749 ASSERT_TRUE(resizer.get());
708 resizer->Drag(CalculateDragPoint(*resizer, 8, 0), 0); 750 resizer->Drag(CalculateDragPoint(*resizer, 8, 0), 0);
709 EXPECT_EQ("100,200 300x380", window_->bounds().ToString()); 751 EXPECT_EQ("100,200 300x380", window_->bounds().ToString());
710 } 752 }
711 753
712 TEST_F(WorkspaceWindowResizerTest, ResizeWindowOutsideLeftWorkArea) { 754 TEST_F(WorkspaceWindowResizerTest, ResizeWindowOutsideLeftWorkArea) {
713 Shell::GetInstance()->SetDisplayWorkAreaInsets( 755 Shell::GetInstance()->SetDisplayWorkAreaInsets(
714 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0)); 756 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
715 int left = ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_.get()).x(); 757 int left = ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_.get()).x();
716 int pixels_to_left_border = 50; 758 int pixels_to_left_border = 50;
717 int window_width = 300; 759 int window_width = 300;
718 int window_x = left - window_width + pixels_to_left_border; 760 int window_x = left - window_width + pixels_to_left_border;
719 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380)); 761 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380));
720 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 762 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
721 window_.get(), gfx::Point(pixels_to_left_border, 0), HTRIGHT, 763 window_.get(), gfx::Point(pixels_to_left_border, 0), HTRIGHT,
722 empty_windows())); 764 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
723 ASSERT_TRUE(resizer.get()); 765 ASSERT_TRUE(resizer.get());
724 resizer->Drag(CalculateDragPoint(*resizer, -window_width, 0), 0); 766 resizer->Drag(CalculateDragPoint(*resizer, -window_width, 0), 0);
725 EXPECT_EQ(base::IntToString(window_x) + ",100 " + 767 EXPECT_EQ(base::IntToString(window_x) + ",100 " +
726 base::IntToString(kMinimumOnScreenArea - window_x) + 768 base::IntToString(kMinimumOnScreenArea - window_x) +
727 "x380", window_->bounds().ToString()); 769 "x380", window_->bounds().ToString());
728 } 770 }
729 771
730 TEST_F(WorkspaceWindowResizerTest, ResizeWindowOutsideRightWorkArea) { 772 TEST_F(WorkspaceWindowResizerTest, ResizeWindowOutsideRightWorkArea) {
731 Shell::GetInstance()->SetDisplayWorkAreaInsets( 773 Shell::GetInstance()->SetDisplayWorkAreaInsets(
732 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0)); 774 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
733 int right = ScreenAsh::GetDisplayWorkAreaBoundsInParent( 775 int right = ScreenAsh::GetDisplayWorkAreaBoundsInParent(
734 window_.get()).right(); 776 window_.get()).right();
735 int pixels_to_right_border = 50; 777 int pixels_to_right_border = 50;
736 int window_width = 300; 778 int window_width = 300;
737 int window_x = right - pixels_to_right_border; 779 int window_x = right - pixels_to_right_border;
738 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380)); 780 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380));
739 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 781 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
740 window_.get(), gfx::Point(window_x, 0), HTLEFT, 782 window_.get(), gfx::Point(window_x, 0), HTLEFT,
741 empty_windows())); 783 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
742 ASSERT_TRUE(resizer.get()); 784 ASSERT_TRUE(resizer.get());
743 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0); 785 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0);
744 EXPECT_EQ(base::IntToString(right - kMinimumOnScreenArea) + 786 EXPECT_EQ(base::IntToString(right - kMinimumOnScreenArea) +
745 ",100 " + 787 ",100 " +
746 base::IntToString(window_width - pixels_to_right_border + 788 base::IntToString(window_width - pixels_to_right_border +
747 kMinimumOnScreenArea) + 789 kMinimumOnScreenArea) +
748 "x380", window_->bounds().ToString()); 790 "x380", window_->bounds().ToString());
749 } 791 }
750 792
751 TEST_F(WorkspaceWindowResizerTest, ResizeWindowOutsideBottomWorkArea) { 793 TEST_F(WorkspaceWindowResizerTest, ResizeWindowOutsideBottomWorkArea) {
752 Shell::GetInstance()->SetDisplayWorkAreaInsets( 794 Shell::GetInstance()->SetDisplayWorkAreaInsets(
753 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0)); 795 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
754 int bottom = ScreenAsh::GetDisplayWorkAreaBoundsInParent( 796 int bottom = ScreenAsh::GetDisplayWorkAreaBoundsInParent(
755 window_.get()).bottom(); 797 window_.get()).bottom();
756 int delta_to_bottom = 50; 798 int delta_to_bottom = 50;
757 int height = 380; 799 int height = 380;
758 window_->SetBounds(gfx::Rect(100, bottom - delta_to_bottom, 300, height)); 800 window_->SetBounds(gfx::Rect(100, bottom - delta_to_bottom, 300, height));
759 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 801 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
760 window_.get(), gfx::Point(0, bottom - delta_to_bottom), HTTOP, 802 window_.get(), gfx::Point(0, bottom - delta_to_bottom), HTTOP,
761 empty_windows())); 803 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
762 ASSERT_TRUE(resizer.get()); 804 ASSERT_TRUE(resizer.get());
763 resizer->Drag(CalculateDragPoint(*resizer, 0, bottom), 0); 805 resizer->Drag(CalculateDragPoint(*resizer, 0, bottom), 0);
764 EXPECT_EQ("100," + 806 EXPECT_EQ("100," +
765 base::IntToString(bottom - kMinimumOnScreenArea) + 807 base::IntToString(bottom - kMinimumOnScreenArea) +
766 " 300x" + 808 " 300x" +
767 base::IntToString(height - (delta_to_bottom - 809 base::IntToString(height - (delta_to_bottom -
768 kMinimumOnScreenArea)), 810 kMinimumOnScreenArea)),
769 window_->bounds().ToString()); 811 window_->bounds().ToString());
770 } 812 }
771 813
(...skipping 15 matching lines...) Expand all
787 Shell::GetInstance()->SetDisplayWorkAreaInsets( 829 Shell::GetInstance()->SetDisplayWorkAreaInsets(
788 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0)); 830 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
789 int right = ScreenAsh::GetDisplayWorkAreaBoundsInParent( 831 int right = ScreenAsh::GetDisplayWorkAreaBoundsInParent(
790 window_.get()).right(); 832 window_.get()).right();
791 int pixels_to_right_border = 50; 833 int pixels_to_right_border = 50;
792 int window_width = 300; 834 int window_width = 300;
793 int window_x = right - pixels_to_right_border; 835 int window_x = right - pixels_to_right_border;
794 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380)); 836 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380));
795 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 837 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
796 window_.get(), gfx::Point(window_x, 0), HTCAPTION, 838 window_.get(), gfx::Point(window_x, 0), HTCAPTION,
797 empty_windows())); 839 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
798 ASSERT_TRUE(resizer.get()); 840 ASSERT_TRUE(resizer.get());
799 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0); 841 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0);
800 EXPECT_EQ(base::IntToString(right - kMinimumOnScreenArea) + 842 EXPECT_EQ(base::IntToString(right - kMinimumOnScreenArea) +
801 ",100 " + 843 ",100 " +
802 base::IntToString(window_width) + 844 base::IntToString(window_width) +
803 "x380", window_->bounds().ToString()); 845 "x380", window_->bounds().ToString());
804 846
805 // With secondary display. Operation itself is same but doesn't change 847 // With secondary display. Operation itself is same but doesn't change
806 // the position because the window is still within the secondary display. 848 // the position because the window is still within the secondary display.
807 UpdateDisplay("1000x600,600x400"); 849 UpdateDisplay("1000x600,600x400");
808 Shell::GetInstance()->SetDisplayWorkAreaInsets( 850 Shell::GetInstance()->SetDisplayWorkAreaInsets(
809 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0)); 851 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
810 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380)); 852 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380));
811 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0); 853 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0);
812 EXPECT_EQ(base::IntToString(window_x + window_width) + 854 EXPECT_EQ(base::IntToString(window_x + window_width) +
813 ",100 " + 855 ",100 " +
814 base::IntToString(window_width) + 856 base::IntToString(window_width) +
815 "x380", window_->bounds().ToString()); 857 "x380", window_->bounds().ToString());
816 } 858 }
817 859
818 // Verifies snapping to edges works. 860 // Verifies snapping to edges works.
819 TEST_F(WorkspaceWindowResizerTest, SnapToEdge) { 861 TEST_F(WorkspaceWindowResizerTest, SnapToEdge) {
820 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()-> 862 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()->
821 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 863 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
822 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); 864 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
823 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 865 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
824 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 866 window_.get(), gfx::Point(), HTCAPTION,
867 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
825 ASSERT_TRUE(resizer.get()); 868 ASSERT_TRUE(resizer.get());
826 // Move to an x-coordinate of 15, which should not snap. 869 // Move to an x-coordinate of 15, which should not snap.
827 resizer->Drag(CalculateDragPoint(*resizer, 15 - 96, 0), 0); 870 resizer->Drag(CalculateDragPoint(*resizer, 15 - 96, 0), 0);
828 // An x-coordinate of 7 should snap. 871 // An x-coordinate of 7 should snap.
829 resizer->Drag(CalculateDragPoint(*resizer, 7 - 96, 0), 0); 872 resizer->Drag(CalculateDragPoint(*resizer, 7 - 96, 0), 0);
830 EXPECT_EQ("0,112 320x160", window_->bounds().ToString()); 873 EXPECT_EQ("0,112 320x160", window_->bounds().ToString());
831 // Move to -15, should still snap to 0. 874 // Move to -15, should still snap to 0.
832 resizer->Drag(CalculateDragPoint(*resizer, -15 - 96, 0), 0); 875 resizer->Drag(CalculateDragPoint(*resizer, -15 - 96, 0), 0);
833 EXPECT_EQ("0,112 320x160", window_->bounds().ToString()); 876 EXPECT_EQ("0,112 320x160", window_->bounds().ToString());
834 // At -32 should move past snap points. 877 // At -32 should move past snap points.
(...skipping 29 matching lines...) Expand all
864 EXPECT_EQ("96,20 320x160", window_->bounds().ToString()); 907 EXPECT_EQ("96,20 320x160", window_->bounds().ToString());
865 resizer->Drag(CalculateDragPoint(*resizer, 0, -112 + 7), 0); 908 resizer->Drag(CalculateDragPoint(*resizer, 0, -112 + 7), 0);
866 EXPECT_EQ("96,0 320x160", window_->bounds().ToString()); 909 EXPECT_EQ("96,0 320x160", window_->bounds().ToString());
867 // No need to test dragging < 0 as we force that to 0. 910 // No need to test dragging < 0 as we force that to 0.
868 } 911 }
869 912
870 // Verifies a resize snap when dragging TOPLEFT. 913 // Verifies a resize snap when dragging TOPLEFT.
871 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_TOPLEFT) { 914 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_TOPLEFT) {
872 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 915 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
873 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 916 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
874 window_.get(), gfx::Point(), HTTOPLEFT, empty_windows())); 917 window_.get(), gfx::Point(), HTTOPLEFT,
918 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
875 ASSERT_TRUE(resizer.get()); 919 ASSERT_TRUE(resizer.get());
876 resizer->Drag(CalculateDragPoint(*resizer, -98, -199), 0); 920 resizer->Drag(CalculateDragPoint(*resizer, -98, -199), 0);
877 EXPECT_EQ("0,0 120x230", window_->bounds().ToString()); 921 EXPECT_EQ("0,0 120x230", window_->bounds().ToString());
878 } 922 }
879 923
880 // Verifies a resize snap when dragging TOPRIGHT. 924 // Verifies a resize snap when dragging TOPRIGHT.
881 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_TOPRIGHT) { 925 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_TOPRIGHT) {
882 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 926 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
883 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( 927 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
884 window_.get())); 928 window_.get()));
885 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 929 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
886 window_.get(), gfx::Point(), HTTOPRIGHT, empty_windows())); 930 window_.get(), gfx::Point(), HTTOPRIGHT,
931 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
887 ASSERT_TRUE(resizer.get()); 932 ASSERT_TRUE(resizer.get());
888 resizer->Drag( 933 resizer->Drag(
889 CalculateDragPoint(*resizer, work_area.right() - 120 - 1, -199), 0); 934 CalculateDragPoint(*resizer, work_area.right() - 120 - 1, -199), 0);
890 EXPECT_EQ(100, window_->bounds().x()); 935 EXPECT_EQ(100, window_->bounds().x());
891 EXPECT_EQ(work_area.y(), window_->bounds().y()); 936 EXPECT_EQ(work_area.y(), window_->bounds().y());
892 EXPECT_EQ(work_area.right() - 100, window_->bounds().width()); 937 EXPECT_EQ(work_area.right() - 100, window_->bounds().width());
893 EXPECT_EQ(230, window_->bounds().height()); 938 EXPECT_EQ(230, window_->bounds().height());
894 } 939 }
895 940
896 // Verifies a resize snap when dragging BOTTOMRIGHT. 941 // Verifies a resize snap when dragging BOTTOMRIGHT.
897 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_BOTTOMRIGHT) { 942 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_BOTTOMRIGHT) {
898 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 943 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
899 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( 944 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
900 window_.get())); 945 window_.get()));
901 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 946 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
902 window_.get(), gfx::Point(), HTBOTTOMRIGHT, empty_windows())); 947 window_.get(), gfx::Point(), HTBOTTOMRIGHT,
948 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
903 ASSERT_TRUE(resizer.get()); 949 ASSERT_TRUE(resizer.get());
904 resizer->Drag( 950 resizer->Drag(
905 CalculateDragPoint(*resizer, work_area.right() - 120 - 1, 951 CalculateDragPoint(*resizer, work_area.right() - 120 - 1,
906 work_area.bottom() - 220 - 2), 0); 952 work_area.bottom() - 220 - 2), 0);
907 EXPECT_EQ(100, window_->bounds().x()); 953 EXPECT_EQ(100, window_->bounds().x());
908 EXPECT_EQ(200, window_->bounds().y()); 954 EXPECT_EQ(200, window_->bounds().y());
909 EXPECT_EQ(work_area.right() - 100, window_->bounds().width()); 955 EXPECT_EQ(work_area.right() - 100, window_->bounds().width());
910 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height()); 956 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
911 } 957 }
912 958
913 // Verifies a resize snap when dragging BOTTOMLEFT. 959 // Verifies a resize snap when dragging BOTTOMLEFT.
914 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_BOTTOMLEFT) { 960 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_BOTTOMLEFT) {
915 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 961 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
916 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( 962 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
917 window_.get())); 963 window_.get()));
918 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 964 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
919 window_.get(), gfx::Point(), HTBOTTOMLEFT, empty_windows())); 965 window_.get(), gfx::Point(), HTBOTTOMLEFT,
966 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
920 ASSERT_TRUE(resizer.get()); 967 ASSERT_TRUE(resizer.get());
921 resizer->Drag( 968 resizer->Drag(
922 CalculateDragPoint(*resizer, -98, work_area.bottom() - 220 - 2), 0); 969 CalculateDragPoint(*resizer, -98, work_area.bottom() - 220 - 2), 0);
923 EXPECT_EQ(0, window_->bounds().x()); 970 EXPECT_EQ(0, window_->bounds().x());
924 EXPECT_EQ(200, window_->bounds().y()); 971 EXPECT_EQ(200, window_->bounds().y());
925 EXPECT_EQ(120, window_->bounds().width()); 972 EXPECT_EQ(120, window_->bounds().width());
926 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height()); 973 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
927 } 974 }
928 975
929 // Verifies sticking to edges works. 976 // Verifies sticking to edges works.
930 TEST_F(WorkspaceWindowResizerTestSticky, StickToEdge) { 977 TEST_F(WorkspaceWindowResizerTestSticky, StickToEdge) {
931 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()-> 978 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()->
932 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 979 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
933 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); 980 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
934 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 981 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
935 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 982 window_.get(), gfx::Point(), HTCAPTION,
983 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
936 ASSERT_TRUE(resizer.get()); 984 ASSERT_TRUE(resizer.get());
937 // Move to an x-coordinate of 15, which should not stick. 985 // Move to an x-coordinate of 15, which should not stick.
938 resizer->Drag(CalculateDragPoint(*resizer, 15 - 96, 0), 0); 986 resizer->Drag(CalculateDragPoint(*resizer, 15 - 96, 0), 0);
939 // Move to -15, should still stick to 0. 987 // Move to -15, should still stick to 0.
940 resizer->Drag(CalculateDragPoint(*resizer, -15 - 96, 0), 0); 988 resizer->Drag(CalculateDragPoint(*resizer, -15 - 96, 0), 0);
941 EXPECT_EQ("0,112 320x160", window_->bounds().ToString()); 989 EXPECT_EQ("0,112 320x160", window_->bounds().ToString());
942 // At -100 should move past edge. 990 // At -100 should move past edge.
943 resizer->Drag(CalculateDragPoint(*resizer, -100 - 96, 0), 0); 991 resizer->Drag(CalculateDragPoint(*resizer, -100 - 96, 0), 0);
944 EXPECT_EQ("-100,112 320x160", window_->bounds().ToString()); 992 EXPECT_EQ("-100,112 320x160", window_->bounds().ToString());
945 resizer->Drag(CalculateDragPoint(*resizer, -101 - 96, 0), 0); 993 resizer->Drag(CalculateDragPoint(*resizer, -101 - 96, 0), 0);
(...skipping 17 matching lines...) Expand all
963 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 2 + 101), 0); 1011 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 2 + 101), 0);
964 EXPECT_EQ("96,539 320x160", window_->bounds().ToString()); 1012 EXPECT_EQ("96,539 320x160", window_->bounds().ToString());
965 1013
966 // No need to test dragging < 0 as we force that to 0. 1014 // No need to test dragging < 0 as we force that to 0.
967 } 1015 }
968 1016
969 // Verifies a resize sticks when dragging TOPLEFT. 1017 // Verifies a resize sticks when dragging TOPLEFT.
970 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_TOPLEFT) { 1018 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_TOPLEFT) {
971 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1019 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
972 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1020 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
973 window_.get(), gfx::Point(), HTTOPLEFT, empty_windows())); 1021 window_.get(), gfx::Point(), HTTOPLEFT,
1022 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
974 ASSERT_TRUE(resizer.get()); 1023 ASSERT_TRUE(resizer.get());
975 resizer->Drag(CalculateDragPoint(*resizer, -15 - 100, -15 -200), 0); 1024 resizer->Drag(CalculateDragPoint(*resizer, -15 - 100, -15 -200), 0);
976 EXPECT_EQ("0,0 120x230", window_->bounds().ToString()); 1025 EXPECT_EQ("0,0 120x230", window_->bounds().ToString());
977 } 1026 }
978 1027
979 // Verifies a resize sticks when dragging TOPRIGHT. 1028 // Verifies a resize sticks when dragging TOPRIGHT.
980 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_TOPRIGHT) { 1029 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_TOPRIGHT) {
981 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1030 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
982 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( 1031 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
983 window_.get())); 1032 window_.get()));
984 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1033 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
985 window_.get(), gfx::Point(), HTTOPRIGHT, empty_windows())); 1034 window_.get(), gfx::Point(), HTTOPRIGHT,
1035 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
986 ASSERT_TRUE(resizer.get()); 1036 ASSERT_TRUE(resizer.get());
987 resizer->Drag(CalculateDragPoint(*resizer, work_area.right() - 100 + 20, 1037 resizer->Drag(CalculateDragPoint(*resizer, work_area.right() - 100 + 20,
988 -200 - 15), 0); 1038 -200 - 15), 0);
989 EXPECT_EQ(100, window_->bounds().x()); 1039 EXPECT_EQ(100, window_->bounds().x());
990 EXPECT_EQ(work_area.y(), window_->bounds().y()); 1040 EXPECT_EQ(work_area.y(), window_->bounds().y());
991 EXPECT_EQ(work_area.right() - 100, window_->bounds().width()); 1041 EXPECT_EQ(work_area.right() - 100, window_->bounds().width());
992 EXPECT_EQ(230, window_->bounds().height()); 1042 EXPECT_EQ(230, window_->bounds().height());
993 } 1043 }
994 1044
995 // Verifies a resize snap when dragging BOTTOMRIGHT. 1045 // Verifies a resize snap when dragging BOTTOMRIGHT.
996 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_BOTTOMRIGHT) { 1046 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_BOTTOMRIGHT) {
997 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1047 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
998 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( 1048 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
999 window_.get())); 1049 window_.get()));
1000 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1050 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1001 window_.get(), gfx::Point(), HTBOTTOMRIGHT, empty_windows())); 1051 window_.get(), gfx::Point(), HTBOTTOMRIGHT,
1052 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1002 ASSERT_TRUE(resizer.get()); 1053 ASSERT_TRUE(resizer.get());
1003 resizer->Drag(CalculateDragPoint(*resizer, work_area.right() - 100 - 20 + 15, 1054 resizer->Drag(CalculateDragPoint(*resizer, work_area.right() - 100 - 20 + 15,
1004 work_area.bottom() - 200 - 30 + 15), 0); 1055 work_area.bottom() - 200 - 30 + 15), 0);
1005 EXPECT_EQ(100, window_->bounds().x()); 1056 EXPECT_EQ(100, window_->bounds().x());
1006 EXPECT_EQ(200, window_->bounds().y()); 1057 EXPECT_EQ(200, window_->bounds().y());
1007 EXPECT_EQ(work_area.right() - 100, window_->bounds().width()); 1058 EXPECT_EQ(work_area.right() - 100, window_->bounds().width());
1008 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height()); 1059 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
1009 } 1060 }
1010 1061
1011 // Verifies a resize snap when dragging BOTTOMLEFT. 1062 // Verifies a resize snap when dragging BOTTOMLEFT.
1012 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_BOTTOMLEFT) { 1063 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_BOTTOMLEFT) {
1013 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1064 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1014 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( 1065 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
1015 window_.get())); 1066 window_.get()));
1016 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1067 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1017 window_.get(), gfx::Point(), HTBOTTOMLEFT, empty_windows())); 1068 window_.get(), gfx::Point(), HTBOTTOMLEFT,
1069 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1018 ASSERT_TRUE(resizer.get()); 1070 ASSERT_TRUE(resizer.get());
1019 resizer->Drag(CalculateDragPoint(*resizer, -15 - 100, 1071 resizer->Drag(CalculateDragPoint(*resizer, -15 - 100,
1020 work_area.bottom() - 200 - 30 + 15), 0); 1072 work_area.bottom() - 200 - 30 + 15), 0);
1021 EXPECT_EQ(0, window_->bounds().x()); 1073 EXPECT_EQ(0, window_->bounds().x());
1022 EXPECT_EQ(200, window_->bounds().y()); 1074 EXPECT_EQ(200, window_->bounds().y());
1023 EXPECT_EQ(120, window_->bounds().width()); 1075 EXPECT_EQ(120, window_->bounds().width());
1024 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height()); 1076 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
1025 } 1077 }
1026 1078
1027 TEST_F(WorkspaceWindowResizerTest, CtrlDragResizeToExactPosition) { 1079 TEST_F(WorkspaceWindowResizerTest, CtrlDragResizeToExactPosition) {
1028 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); 1080 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
1029 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1081 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1030 window_.get(), gfx::Point(), HTBOTTOMRIGHT, empty_windows())); 1082 window_.get(), gfx::Point(), HTBOTTOMRIGHT,
1083 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1031 ASSERT_TRUE(resizer.get()); 1084 ASSERT_TRUE(resizer.get());
1032 // Resize the right bottom to add 10 in width, 12 in height. 1085 // Resize the right bottom to add 10 in width, 12 in height.
1033 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), ui::EF_CONTROL_DOWN); 1086 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), ui::EF_CONTROL_DOWN);
1034 // Both bottom and right sides to resize to exact size requested. 1087 // Both bottom and right sides to resize to exact size requested.
1035 EXPECT_EQ("96,112 330x172", window_->bounds().ToString()); 1088 EXPECT_EQ("96,112 330x172", window_->bounds().ToString());
1036 } 1089 }
1037 1090
1038 TEST_F(WorkspaceWindowResizerTest, CtrlCompleteDragMoveToExactPosition) { 1091 TEST_F(WorkspaceWindowResizerTest, CtrlCompleteDragMoveToExactPosition) {
1039 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); 1092 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
1040 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1093 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1041 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 1094 window_.get(), gfx::Point(), HTCAPTION,
1095 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1042 ASSERT_TRUE(resizer.get()); 1096 ASSERT_TRUE(resizer.get());
1043 // Ctrl + drag the window to new poistion by adding (10, 12) to its origin, 1097 // Ctrl + drag the window to new poistion by adding (10, 12) to its origin,
1044 // the window should move to the exact position. 1098 // the window should move to the exact position.
1045 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0); 1099 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0);
1046 resizer->CompleteDrag(ui::EF_CONTROL_DOWN); 1100 resizer->CompleteDrag(ui::EF_CONTROL_DOWN);
1047 EXPECT_EQ("106,124 320x160", window_->bounds().ToString()); 1101 EXPECT_EQ("106,124 320x160", window_->bounds().ToString());
1048 } 1102 }
1049 1103
1050 // Check that only usable sizes get returned by the resizer. 1104 // Check that only usable sizes get returned by the resizer.
1051 TEST_F(WorkspaceWindowResizerTest, TestProperSizerResolutions) { 1105 TEST_F(WorkspaceWindowResizerTest, TestProperSizerResolutions) {
(...skipping 30 matching lines...) Expand all
1082 EXPECT_EQ("0,0 640x552", rect.ToString()); 1136 EXPECT_EQ("0,0 640x552", rect.ToString());
1083 rect = resizer->GetTargetBoundsForSize(2); 1137 rect = resizer->GetTargetBoundsForSize(2);
1084 EXPECT_EQ("0,0 400x552", rect.ToString()); 1138 EXPECT_EQ("0,0 400x552", rect.ToString());
1085 } 1139 }
1086 1140
1087 // Verifies that a dragged window will restore to its pre-maximized size. 1141 // Verifies that a dragged window will restore to its pre-maximized size.
1088 TEST_F(WorkspaceWindowResizerTest, RestoreToPreMaximizeCoordinates) { 1142 TEST_F(WorkspaceWindowResizerTest, RestoreToPreMaximizeCoordinates) {
1089 window_->SetBounds(gfx::Rect(0, 0, 1000, 1000)); 1143 window_->SetBounds(gfx::Rect(0, 0, 1000, 1000));
1090 SetRestoreBoundsInScreen(window_.get(), gfx::Rect(96, 112, 320, 160)); 1144 SetRestoreBoundsInScreen(window_.get(), gfx::Rect(96, 112, 320, 160));
1091 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1145 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1092 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 1146 window_.get(), gfx::Point(), HTCAPTION,
1147 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1093 ASSERT_TRUE(resizer.get()); 1148 ASSERT_TRUE(resizer.get());
1094 // Drag the window to new position by adding (10, 10) to original point, 1149 // Drag the window to new position by adding (10, 10) to original point,
1095 // the window should get restored. 1150 // the window should get restored.
1096 resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0); 1151 resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0);
1097 resizer->CompleteDrag(0); 1152 resizer->CompleteDrag(0);
1098 EXPECT_EQ("10,10 320x160", window_->bounds().ToString()); 1153 EXPECT_EQ("10,10 320x160", window_->bounds().ToString());
1099 // The restore rectangle should get cleared as well. 1154 // The restore rectangle should get cleared as well.
1100 EXPECT_EQ(NULL, GetRestoreBoundsInScreen(window_.get())); 1155 EXPECT_EQ(NULL, GetRestoreBoundsInScreen(window_.get()));
1101 } 1156 }
1102 1157
1103 // Verifies that a dragged window will restore to its pre-maximized size. 1158 // Verifies that a dragged window will restore to its pre-maximized size.
1104 TEST_F(WorkspaceWindowResizerTest, RevertResizeOperation) { 1159 TEST_F(WorkspaceWindowResizerTest, RevertResizeOperation) {
1105 const gfx::Rect initial_bounds(0, 0, 200, 400); 1160 const gfx::Rect initial_bounds(0, 0, 200, 400);
1106 window_->SetBounds(initial_bounds); 1161 window_->SetBounds(initial_bounds);
1107 SetRestoreBoundsInScreen(window_.get(), gfx::Rect(96, 112, 320, 160)); 1162 SetRestoreBoundsInScreen(window_.get(), gfx::Rect(96, 112, 320, 160));
1108 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1163 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1109 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 1164 window_.get(), gfx::Point(), HTCAPTION,
1165 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1110 ASSERT_TRUE(resizer.get()); 1166 ASSERT_TRUE(resizer.get());
1111 // Drag the window to new poistion by adding (180, 16) to original point, 1167 // Drag the window to new poistion by adding (180, 16) to original point,
1112 // the window should get restored. 1168 // the window should get restored.
1113 resizer->Drag(CalculateDragPoint(*resizer, 180, 16), 0); 1169 resizer->Drag(CalculateDragPoint(*resizer, 180, 16), 0);
1114 resizer->RevertDrag(); 1170 resizer->RevertDrag();
1115 EXPECT_EQ(initial_bounds.ToString(), window_->bounds().ToString()); 1171 EXPECT_EQ(initial_bounds.ToString(), window_->bounds().ToString());
1116 EXPECT_EQ("96,112 320x160", 1172 EXPECT_EQ("96,112 320x160",
1117 GetRestoreBoundsInScreen(window_.get())->ToString()); 1173 GetRestoreBoundsInScreen(window_.get())->ToString());
1118 } 1174 }
1119 1175
1120 // Check that only usable sizes get returned by the resizer. 1176 // Check that only usable sizes get returned by the resizer.
1121 TEST_F(WorkspaceWindowResizerTest, MagneticallyAttach) { 1177 TEST_F(WorkspaceWindowResizerTest, MagneticallyAttach) {
1122 window_->SetBounds(gfx::Rect(10, 10, 20, 30)); 1178 window_->SetBounds(gfx::Rect(10, 10, 20, 30));
1123 window2_->SetBounds(gfx::Rect(150, 160, 25, 20)); 1179 window2_->SetBounds(gfx::Rect(150, 160, 25, 20));
1124 window2_->Show(); 1180 window2_->Show();
1125 1181
1126 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1182 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1127 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 1183 window_.get(), gfx::Point(), HTCAPTION,
1184 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1128 ASSERT_TRUE(resizer.get()); 1185 ASSERT_TRUE(resizer.get());
1129 // Move |window| one pixel to the left of |window2|. Should snap to right and 1186 // Move |window| one pixel to the left of |window2|. Should snap to right and
1130 // top. 1187 // top.
1131 resizer->Drag(CalculateDragPoint(*resizer, 119, 145), 0); 1188 resizer->Drag(CalculateDragPoint(*resizer, 119, 145), 0);
1132 EXPECT_EQ("130,160 20x30", window_->bounds().ToString()); 1189 EXPECT_EQ("130,160 20x30", window_->bounds().ToString());
1133 1190
1134 // Move |window| one pixel to the right of |window2|. Should snap to left and 1191 // Move |window| one pixel to the right of |window2|. Should snap to left and
1135 // top. 1192 // top.
1136 resizer->Drag(CalculateDragPoint(*resizer, 164, 145), 0); 1193 resizer->Drag(CalculateDragPoint(*resizer, 164, 145), 0);
1137 EXPECT_EQ("175,160 20x30", window_->bounds().ToString()); 1194 EXPECT_EQ("175,160 20x30", window_->bounds().ToString());
1138 1195
1139 // Move |window| one pixel above |window2|. Should snap to top and left. 1196 // Move |window| one pixel above |window2|. Should snap to top and left.
1140 resizer->Drag(CalculateDragPoint(*resizer, 142, 119), 0); 1197 resizer->Drag(CalculateDragPoint(*resizer, 142, 119), 0);
1141 EXPECT_EQ("150,130 20x30", window_->bounds().ToString()); 1198 EXPECT_EQ("150,130 20x30", window_->bounds().ToString());
1142 1199
1143 // Move |window| one pixel above the bottom of |window2|. Should snap to 1200 // Move |window| one pixel above the bottom of |window2|. Should snap to
1144 // bottom and left. 1201 // bottom and left.
1145 resizer->Drag(CalculateDragPoint(*resizer, 142, 169), 0); 1202 resizer->Drag(CalculateDragPoint(*resizer, 142, 169), 0);
1146 EXPECT_EQ("150,180 20x30", window_->bounds().ToString()); 1203 EXPECT_EQ("150,180 20x30", window_->bounds().ToString());
1147 } 1204 }
1148 1205
1149 // The following variants verify magnetic snapping during resize when dragging a 1206 // The following variants verify magnetic snapping during resize when dragging a
1150 // particular edge. 1207 // particular edge.
1151 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_TOP) { 1208 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_TOP) {
1152 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1209 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1153 window2_->SetBounds(gfx::Rect(99, 179, 10, 20)); 1210 window2_->SetBounds(gfx::Rect(99, 179, 10, 20));
1154 window2_->Show(); 1211 window2_->Show();
1155 1212
1156 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1213 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1157 window_.get(), gfx::Point(), HTTOP, empty_windows())); 1214 window_.get(), gfx::Point(), HTTOP,
1215 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1158 ASSERT_TRUE(resizer.get()); 1216 ASSERT_TRUE(resizer.get());
1159 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1217 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1160 EXPECT_EQ("100,199 20x31", window_->bounds().ToString()); 1218 EXPECT_EQ("100,199 20x31", window_->bounds().ToString());
1161 } 1219 }
1162 1220
1163 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_TOPLEFT) { 1221 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_TOPLEFT) {
1164 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1222 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1165 window2_->SetBounds(gfx::Rect(99, 179, 10, 20)); 1223 window2_->SetBounds(gfx::Rect(99, 179, 10, 20));
1166 window2_->Show(); 1224 window2_->Show();
1167 1225
1168 { 1226 {
1169 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1227 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1170 window_.get(), gfx::Point(), HTTOPLEFT, empty_windows())); 1228 window_.get(), gfx::Point(), HTTOPLEFT,
1229 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1171 ASSERT_TRUE(resizer.get()); 1230 ASSERT_TRUE(resizer.get());
1172 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1231 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1173 EXPECT_EQ("99,199 21x31", window_->bounds().ToString()); 1232 EXPECT_EQ("99,199 21x31", window_->bounds().ToString());
1174 resizer->RevertDrag(); 1233 resizer->RevertDrag();
1175 } 1234 }
1176 1235
1177 { 1236 {
1178 window2_->SetBounds(gfx::Rect(88, 201, 10, 20)); 1237 window2_->SetBounds(gfx::Rect(88, 201, 10, 20));
1179 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1238 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1180 window_.get(), gfx::Point(), HTTOPLEFT, empty_windows())); 1239 window_.get(), gfx::Point(), HTTOPLEFT,
1240 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1181 ASSERT_TRUE(resizer.get()); 1241 ASSERT_TRUE(resizer.get());
1182 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1242 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1183 EXPECT_EQ("98,201 22x29", window_->bounds().ToString()); 1243 EXPECT_EQ("98,201 22x29", window_->bounds().ToString());
1184 resizer->RevertDrag(); 1244 resizer->RevertDrag();
1185 } 1245 }
1186 } 1246 }
1187 1247
1188 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_TOPRIGHT) { 1248 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_TOPRIGHT) {
1189 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1249 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1190 window2_->Show(); 1250 window2_->Show();
1191 1251
1192 { 1252 {
1193 window2_->SetBounds(gfx::Rect(111, 179, 10, 20)); 1253 window2_->SetBounds(gfx::Rect(111, 179, 10, 20));
1194 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1254 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1195 window_.get(), gfx::Point(), HTTOPRIGHT, empty_windows())); 1255 window_.get(), gfx::Point(), HTTOPRIGHT,
1256 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1196 ASSERT_TRUE(resizer.get()); 1257 ASSERT_TRUE(resizer.get());
1197 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1258 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1198 EXPECT_EQ("100,199 21x31", window_->bounds().ToString()); 1259 EXPECT_EQ("100,199 21x31", window_->bounds().ToString());
1199 resizer->RevertDrag(); 1260 resizer->RevertDrag();
1200 } 1261 }
1201 1262
1202 { 1263 {
1203 window2_->SetBounds(gfx::Rect(121, 199, 10, 20)); 1264 window2_->SetBounds(gfx::Rect(121, 199, 10, 20));
1204 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1265 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1205 window_.get(), gfx::Point(), HTTOPRIGHT, empty_windows())); 1266 window_.get(), gfx::Point(), HTTOPRIGHT,
1267 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1206 ASSERT_TRUE(resizer.get()); 1268 ASSERT_TRUE(resizer.get());
1207 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1269 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1208 EXPECT_EQ("100,199 21x31", window_->bounds().ToString()); 1270 EXPECT_EQ("100,199 21x31", window_->bounds().ToString());
1209 resizer->RevertDrag(); 1271 resizer->RevertDrag();
1210 } 1272 }
1211 } 1273 }
1212 1274
1213 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_RIGHT) { 1275 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_RIGHT) {
1214 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1276 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1215 window2_->SetBounds(gfx::Rect(121, 199, 10, 20)); 1277 window2_->SetBounds(gfx::Rect(121, 199, 10, 20));
1216 window2_->Show(); 1278 window2_->Show();
1217 1279
1218 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1280 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1219 window_.get(), gfx::Point(), HTRIGHT, empty_windows())); 1281 window_.get(), gfx::Point(), HTRIGHT,
1282 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1220 ASSERT_TRUE(resizer.get()); 1283 ASSERT_TRUE(resizer.get());
1221 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1284 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1222 EXPECT_EQ("100,200 21x30", window_->bounds().ToString()); 1285 EXPECT_EQ("100,200 21x30", window_->bounds().ToString());
1223 } 1286 }
1224 1287
1225 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_BOTTOMRIGHT) { 1288 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_BOTTOMRIGHT) {
1226 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1289 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1227 window2_->Show(); 1290 window2_->Show();
1228 1291
1229 { 1292 {
1230 window2_->SetBounds(gfx::Rect(122, 212, 10, 20)); 1293 window2_->SetBounds(gfx::Rect(122, 212, 10, 20));
1231 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1294 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1232 window_.get(), gfx::Point(), HTBOTTOMRIGHT, empty_windows())); 1295 window_.get(), gfx::Point(), HTBOTTOMRIGHT,
1296 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1233 ASSERT_TRUE(resizer.get()); 1297 ASSERT_TRUE(resizer.get());
1234 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1298 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1235 EXPECT_EQ("100,200 22x32", window_->bounds().ToString()); 1299 EXPECT_EQ("100,200 22x32", window_->bounds().ToString());
1236 resizer->RevertDrag(); 1300 resizer->RevertDrag();
1237 } 1301 }
1238 1302
1239 { 1303 {
1240 window2_->SetBounds(gfx::Rect(111, 233, 10, 20)); 1304 window2_->SetBounds(gfx::Rect(111, 233, 10, 20));
1241 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1305 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1242 window_.get(), gfx::Point(), HTBOTTOMRIGHT, empty_windows())); 1306 window_.get(), gfx::Point(), HTBOTTOMRIGHT,
1307 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1243 ASSERT_TRUE(resizer.get()); 1308 ASSERT_TRUE(resizer.get());
1244 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1309 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1245 EXPECT_EQ("100,200 21x33", window_->bounds().ToString()); 1310 EXPECT_EQ("100,200 21x33", window_->bounds().ToString());
1246 resizer->RevertDrag(); 1311 resizer->RevertDrag();
1247 } 1312 }
1248 } 1313 }
1249 1314
1250 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_BOTTOM) { 1315 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_BOTTOM) {
1251 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1316 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1252 window2_->SetBounds(gfx::Rect(111, 233, 10, 20)); 1317 window2_->SetBounds(gfx::Rect(111, 233, 10, 20));
1253 window2_->Show(); 1318 window2_->Show();
1254 1319
1255 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1320 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1256 window_.get(), gfx::Point(), HTBOTTOM, empty_windows())); 1321 window_.get(), gfx::Point(), HTBOTTOM,
1322 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1257 ASSERT_TRUE(resizer.get()); 1323 ASSERT_TRUE(resizer.get());
1258 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1324 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1259 EXPECT_EQ("100,200 20x33", window_->bounds().ToString()); 1325 EXPECT_EQ("100,200 20x33", window_->bounds().ToString());
1260 } 1326 }
1261 1327
1262 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_BOTTOMLEFT) { 1328 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_BOTTOMLEFT) {
1263 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1329 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1264 window2_->Show(); 1330 window2_->Show();
1265 1331
1266 { 1332 {
1267 window2_->SetBounds(gfx::Rect(99, 231, 10, 20)); 1333 window2_->SetBounds(gfx::Rect(99, 231, 10, 20));
1268 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1334 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1269 window_.get(), gfx::Point(), HTBOTTOMLEFT, empty_windows())); 1335 window_.get(), gfx::Point(), HTBOTTOMLEFT,
1336 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1270 ASSERT_TRUE(resizer.get()); 1337 ASSERT_TRUE(resizer.get());
1271 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1338 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1272 EXPECT_EQ("99,200 21x31", window_->bounds().ToString()); 1339 EXPECT_EQ("99,200 21x31", window_->bounds().ToString());
1273 resizer->RevertDrag(); 1340 resizer->RevertDrag();
1274 } 1341 }
1275 1342
1276 { 1343 {
1277 window2_->SetBounds(gfx::Rect(89, 209, 10, 20)); 1344 window2_->SetBounds(gfx::Rect(89, 209, 10, 20));
1278 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1345 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1279 window_.get(), gfx::Point(), HTBOTTOMLEFT, empty_windows())); 1346 window_.get(), gfx::Point(), HTBOTTOMLEFT,
1347 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1280 ASSERT_TRUE(resizer.get()); 1348 ASSERT_TRUE(resizer.get());
1281 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1349 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1282 EXPECT_EQ("99,200 21x29", window_->bounds().ToString()); 1350 EXPECT_EQ("99,200 21x29", window_->bounds().ToString());
1283 resizer->RevertDrag(); 1351 resizer->RevertDrag();
1284 } 1352 }
1285 } 1353 }
1286 1354
1287 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_LEFT) { 1355 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_LEFT) {
1288 window2_->SetBounds(gfx::Rect(89, 209, 10, 20)); 1356 window2_->SetBounds(gfx::Rect(89, 209, 10, 20));
1289 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1357 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1290 window2_->Show(); 1358 window2_->Show();
1291 1359
1292 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1360 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1293 window_.get(), gfx::Point(), HTLEFT, empty_windows())); 1361 window_.get(), gfx::Point(), HTLEFT,
1362 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1294 ASSERT_TRUE(resizer.get()); 1363 ASSERT_TRUE(resizer.get());
1295 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1364 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1296 EXPECT_EQ("99,200 21x30", window_->bounds().ToString()); 1365 EXPECT_EQ("99,200 21x30", window_->bounds().ToString());
1297 } 1366 }
1298 1367
1299 // Test that the user user moved window flag is getting properly set. 1368 // Test that the user user moved window flag is getting properly set.
1300 TEST_F(WorkspaceWindowResizerTest, CheckUserWindowMangedFlags) { 1369 TEST_F(WorkspaceWindowResizerTest, CheckUserWindowMangedFlags) {
1301 window_->SetBounds(gfx::Rect( 0, 50, 400, 200)); 1370 window_->SetBounds(gfx::Rect( 0, 50, 400, 200));
1302 1371
1303 std::vector<aura::Window*> no_attached_windows; 1372 std::vector<aura::Window*> no_attached_windows;
1304 // Check that an abort doesn't change anything. 1373 // Check that an abort doesn't change anything.
1305 { 1374 {
1306 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1375 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1307 window_.get(), gfx::Point(), HTCAPTION, no_attached_windows)); 1376 window_.get(), gfx::Point(), HTCAPTION,
1377 aura::client::WINDOW_MOVE_SOURCE_MOUSE, no_attached_windows));
1308 ASSERT_TRUE(resizer.get()); 1378 ASSERT_TRUE(resizer.get());
1309 // Move it 100 to the bottom. 1379 // Move it 100 to the bottom.
1310 resizer->Drag(CalculateDragPoint(*resizer, 0, 100), 0); 1380 resizer->Drag(CalculateDragPoint(*resizer, 0, 100), 0);
1311 EXPECT_EQ("0,150 400x200", window_->bounds().ToString()); 1381 EXPECT_EQ("0,150 400x200", window_->bounds().ToString());
1312 resizer->RevertDrag(); 1382 resizer->RevertDrag();
1313 1383
1314 EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window_.get())); 1384 EXPECT_FALSE(ash::wm::HasUserChangedWindowPositionOrSize(window_.get()));
1315 } 1385 }
1316 1386
1317 // Check that a completed move / size does change the user coordinates. 1387 // Check that a completed move / size does change the user coordinates.
1318 { 1388 {
1319 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1389 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1320 window_.get(), gfx::Point(), HTCAPTION, no_attached_windows)); 1390 window_.get(), gfx::Point(), HTCAPTION,
1391 aura::client::WINDOW_MOVE_SOURCE_MOUSE, no_attached_windows));
1321 ASSERT_TRUE(resizer.get()); 1392 ASSERT_TRUE(resizer.get());
1322 // Move it 100 to the bottom. 1393 // Move it 100 to the bottom.
1323 resizer->Drag(CalculateDragPoint(*resizer, 0, 100), 0); 1394 resizer->Drag(CalculateDragPoint(*resizer, 0, 100), 0);
1324 EXPECT_EQ("0,150 400x200", window_->bounds().ToString()); 1395 EXPECT_EQ("0,150 400x200", window_->bounds().ToString());
1325 resizer->CompleteDrag(0); 1396 resizer->CompleteDrag(0);
1326 EXPECT_TRUE(ash::wm::HasUserChangedWindowPositionOrSize(window_.get())); 1397 EXPECT_TRUE(ash::wm::HasUserChangedWindowPositionOrSize(window_.get()));
1327 } 1398 }
1328 } 1399 }
1329 1400
1330 // Test that a window with a specified max size doesn't exceed it when dragged. 1401 // Test that a window with a specified max size doesn't exceed it when dragged.
1331 TEST_F(WorkspaceWindowResizerTest, TestMaxSizeEnforced) { 1402 TEST_F(WorkspaceWindowResizerTest, TestMaxSizeEnforced) {
1332 window_->SetBounds(gfx::Rect(0, 0, 400, 300)); 1403 window_->SetBounds(gfx::Rect(0, 0, 400, 300));
1333 delegate_.set_max_size(gfx::Size(401, 301)); 1404 delegate_.set_max_size(gfx::Size(401, 301));
1334 1405
1335 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1406 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1336 window_.get(), gfx::Point(), HTBOTTOMRIGHT, empty_windows())); 1407 window_.get(), gfx::Point(), HTBOTTOMRIGHT,
1408 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1337 resizer->Drag(CalculateDragPoint(*resizer, 2, 2), 0); 1409 resizer->Drag(CalculateDragPoint(*resizer, 2, 2), 0);
1338 EXPECT_EQ(401, window_->bounds().width()); 1410 EXPECT_EQ(401, window_->bounds().width());
1339 EXPECT_EQ(301, window_->bounds().height()); 1411 EXPECT_EQ(301, window_->bounds().height());
1340 } 1412 }
1341 1413
1342 // Test that a window with a specified max width doesn't restrict its height. 1414 // Test that a window with a specified max width doesn't restrict its height.
1343 TEST_F(WorkspaceWindowResizerTest, TestPartialMaxSizeEnforced) { 1415 TEST_F(WorkspaceWindowResizerTest, TestPartialMaxSizeEnforced) {
1344 window_->SetBounds(gfx::Rect(0, 0, 400, 300)); 1416 window_->SetBounds(gfx::Rect(0, 0, 400, 300));
1345 delegate_.set_max_size(gfx::Size(401, 0)); 1417 delegate_.set_max_size(gfx::Size(401, 0));
1346 1418
1347 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1419 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1348 window_.get(), gfx::Point(), HTBOTTOMRIGHT, empty_windows())); 1420 window_.get(), gfx::Point(), HTBOTTOMRIGHT,
1421 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1349 resizer->Drag(CalculateDragPoint(*resizer, 2, 2), 0); 1422 resizer->Drag(CalculateDragPoint(*resizer, 2, 2), 0);
1350 EXPECT_EQ(401, window_->bounds().width()); 1423 EXPECT_EQ(401, window_->bounds().width());
1351 EXPECT_EQ(302, window_->bounds().height()); 1424 EXPECT_EQ(302, window_->bounds().height());
1352 } 1425 }
1353 1426
1354 // Test that a window with a specified max size can't be snapped. 1427 // Test that a window with a specified max size can't be snapped.
1355 TEST_F(WorkspaceWindowResizerTest, PhantomSnapMaxSize) { 1428 TEST_F(WorkspaceWindowResizerTest, PhantomSnapMaxSize) {
1356 { 1429 {
1357 // With max size not set we get a phantom window controller for dragging off 1430 // With max size not set we get a phantom window controller for dragging off
1358 // the right hand side. 1431 // the right hand side.
1359 window_->SetBounds(gfx::Rect(0, 0, 300, 200)); 1432 window_->SetBounds(gfx::Rect(0, 0, 300, 200));
1360 1433
1361 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1434 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1362 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 1435 window_.get(), gfx::Point(), HTCAPTION,
1436 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1363 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); 1437 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get());
1364 resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0); 1438 resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0);
1365 EXPECT_TRUE(resizer->snap_phantom_window_controller_.get()); 1439 EXPECT_TRUE(resizer->snap_phantom_window_controller_.get());
1366 } 1440 }
1367 { 1441 {
1368 // With max size defined, we get no phantom window. 1442 // With max size defined, we get no phantom window.
1369 window_->SetBounds(gfx::Rect(0, 0, 300, 200)); 1443 window_->SetBounds(gfx::Rect(0, 0, 300, 200));
1370 delegate_.set_max_size(gfx::Size(300, 200)); 1444 delegate_.set_max_size(gfx::Size(300, 200));
1371 1445
1372 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1446 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1373 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 1447 window_.get(), gfx::Point(), HTCAPTION,
1448 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1374 resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0); 1449 resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0);
1375 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); 1450 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get());
1376 } 1451 }
1377 } 1452 }
1378 1453
1379 TEST_F(WorkspaceWindowResizerTest, DontRewardRightmostWindowForOverflows) { 1454 TEST_F(WorkspaceWindowResizerTest, DontRewardRightmostWindowForOverflows) {
1380 UpdateDisplay("600x800"); 1455 UpdateDisplay("600x800");
1381 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); 1456 aura::RootWindow* root = Shell::GetPrimaryRootWindow();
1382 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets()); 1457 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1383 1458
1384 // Four 100x100 windows flush against eachother, starting at 100,100. 1459 // Four 100x100 windows flush against eachother, starting at 100,100.
1385 window_->SetBounds(gfx::Rect( 100, 100, 100, 100)); 1460 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1386 window2_->SetBounds(gfx::Rect(200, 100, 100, 100)); 1461 window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
1387 window3_->SetBounds(gfx::Rect(300, 100, 100, 100)); 1462 window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
1388 window4_->SetBounds(gfx::Rect(400, 100, 100, 100)); 1463 window4_->SetBounds(gfx::Rect(400, 100, 100, 100));
1389 delegate2_.set_max_size(gfx::Size(101, 0)); 1464 delegate2_.set_max_size(gfx::Size(101, 0));
1390 1465
1391 std::vector<aura::Window*> windows; 1466 std::vector<aura::Window*> windows;
1392 windows.push_back(window2_.get()); 1467 windows.push_back(window2_.get());
1393 windows.push_back(window3_.get()); 1468 windows.push_back(window3_.get());
1394 windows.push_back(window4_.get()); 1469 windows.push_back(window4_.get());
1395 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1470 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1396 window_.get(), gfx::Point(), HTRIGHT, windows)); 1471 window_.get(), gfx::Point(), HTRIGHT,
1472 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1397 ASSERT_TRUE(resizer.get()); 1473 ASSERT_TRUE(resizer.get());
1398 // Move it 51 to the left, which should contract w1 and expand w2-4. 1474 // Move it 51 to the left, which should contract w1 and expand w2-4.
1399 // w2 will hit its max size straight away, and in doing so will leave extra 1475 // w2 will hit its max size straight away, and in doing so will leave extra
1400 // pixels that a naive implementation may award to the rightmost window. A 1476 // pixels that a naive implementation may award to the rightmost window. A
1401 // fair implementation will give 25 pixels to each of the other windows. 1477 // fair implementation will give 25 pixels to each of the other windows.
1402 resizer->Drag(CalculateDragPoint(*resizer, -51, 0), 0); 1478 resizer->Drag(CalculateDragPoint(*resizer, -51, 0), 0);
1403 EXPECT_EQ("100,100 49x100", window_->bounds().ToString()); 1479 EXPECT_EQ("100,100 49x100", window_->bounds().ToString());
1404 EXPECT_EQ("149,100 101x100", window2_->bounds().ToString()); 1480 EXPECT_EQ("149,100 101x100", window2_->bounds().ToString());
1405 EXPECT_EQ("250,100 125x100", window3_->bounds().ToString()); 1481 EXPECT_EQ("250,100 125x100", window3_->bounds().ToString());
1406 EXPECT_EQ("375,100 125x100", window4_->bounds().ToString()); 1482 EXPECT_EQ("375,100 125x100", window4_->bounds().ToString());
(...skipping 10 matching lines...) Expand all
1417 window3_->SetBounds(gfx::Rect(300, 100, 100, 100)); 1493 window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
1418 window4_->SetBounds(gfx::Rect(400, 100, 100, 100)); 1494 window4_->SetBounds(gfx::Rect(400, 100, 100, 100));
1419 delegate2_.set_max_size(gfx::Size(101, 0)); 1495 delegate2_.set_max_size(gfx::Size(101, 0));
1420 delegate3_.set_max_size(gfx::Size(101, 0)); 1496 delegate3_.set_max_size(gfx::Size(101, 0));
1421 1497
1422 std::vector<aura::Window*> windows; 1498 std::vector<aura::Window*> windows;
1423 windows.push_back(window2_.get()); 1499 windows.push_back(window2_.get());
1424 windows.push_back(window3_.get()); 1500 windows.push_back(window3_.get());
1425 windows.push_back(window4_.get()); 1501 windows.push_back(window4_.get());
1426 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1502 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1427 window_.get(), gfx::Point(), HTRIGHT, windows)); 1503 window_.get(), gfx::Point(), HTRIGHT,
1504 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1428 ASSERT_TRUE(resizer.get()); 1505 ASSERT_TRUE(resizer.get());
1429 // Move it 52 to the left, which should contract w1 and expand w2-4. 1506 // Move it 52 to the left, which should contract w1 and expand w2-4.
1430 resizer->Drag(CalculateDragPoint(*resizer, -52, 0), 0); 1507 resizer->Drag(CalculateDragPoint(*resizer, -52, 0), 0);
1431 EXPECT_EQ("100,100 48x100", window_->bounds().ToString()); 1508 EXPECT_EQ("100,100 48x100", window_->bounds().ToString());
1432 EXPECT_EQ("148,100 101x100", window2_->bounds().ToString()); 1509 EXPECT_EQ("148,100 101x100", window2_->bounds().ToString());
1433 EXPECT_EQ("249,100 101x100", window3_->bounds().ToString()); 1510 EXPECT_EQ("249,100 101x100", window3_->bounds().ToString());
1434 EXPECT_EQ("350,100 150x100", window4_->bounds().ToString()); 1511 EXPECT_EQ("350,100 150x100", window4_->bounds().ToString());
1435 } 1512 }
1436 1513
1437 TEST_F(WorkspaceWindowResizerTest, DontExceedMaxHeight) { 1514 TEST_F(WorkspaceWindowResizerTest, DontExceedMaxHeight) {
1438 UpdateDisplay("600x800"); 1515 UpdateDisplay("600x800");
1439 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); 1516 aura::RootWindow* root = Shell::GetPrimaryRootWindow();
1440 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets()); 1517 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1441 1518
1442 // Four 100x100 windows flush against eachother, starting at 100,100. 1519 // Four 100x100 windows flush against eachother, starting at 100,100.
1443 window_->SetBounds(gfx::Rect( 100, 100, 100, 100)); 1520 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1444 window2_->SetBounds(gfx::Rect(100, 200, 100, 100)); 1521 window2_->SetBounds(gfx::Rect(100, 200, 100, 100));
1445 window3_->SetBounds(gfx::Rect(100, 300, 100, 100)); 1522 window3_->SetBounds(gfx::Rect(100, 300, 100, 100));
1446 window4_->SetBounds(gfx::Rect(100, 400, 100, 100)); 1523 window4_->SetBounds(gfx::Rect(100, 400, 100, 100));
1447 delegate2_.set_max_size(gfx::Size(0, 101)); 1524 delegate2_.set_max_size(gfx::Size(0, 101));
1448 delegate3_.set_max_size(gfx::Size(0, 101)); 1525 delegate3_.set_max_size(gfx::Size(0, 101));
1449 1526
1450 std::vector<aura::Window*> windows; 1527 std::vector<aura::Window*> windows;
1451 windows.push_back(window2_.get()); 1528 windows.push_back(window2_.get());
1452 windows.push_back(window3_.get()); 1529 windows.push_back(window3_.get());
1453 windows.push_back(window4_.get()); 1530 windows.push_back(window4_.get());
1454 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1531 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1455 window_.get(), gfx::Point(), HTBOTTOM, windows)); 1532 window_.get(), gfx::Point(), HTBOTTOM,
1533 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1456 ASSERT_TRUE(resizer.get()); 1534 ASSERT_TRUE(resizer.get());
1457 // Move it 52 up, which should contract w1 and expand w2-4. 1535 // Move it 52 up, which should contract w1 and expand w2-4.
1458 resizer->Drag(CalculateDragPoint(*resizer, 0, -52), 0); 1536 resizer->Drag(CalculateDragPoint(*resizer, 0, -52), 0);
1459 EXPECT_EQ("100,100 100x48", window_->bounds().ToString()); 1537 EXPECT_EQ("100,100 100x48", window_->bounds().ToString());
1460 EXPECT_EQ("100,148 100x101", window2_->bounds().ToString()); 1538 EXPECT_EQ("100,148 100x101", window2_->bounds().ToString());
1461 EXPECT_EQ("100,249 100x101", window3_->bounds().ToString()); 1539 EXPECT_EQ("100,249 100x101", window3_->bounds().ToString());
1462 EXPECT_EQ("100,350 100x150", window4_->bounds().ToString()); 1540 EXPECT_EQ("100,350 100x150", window4_->bounds().ToString());
1463 } 1541 }
1464 1542
1465 #if defined(OS_WIN) 1543 #if defined(OS_WIN)
(...skipping 14 matching lines...) Expand all
1480 window3_->SetBounds(gfx::Rect(100, 300, 100, 100)); 1558 window3_->SetBounds(gfx::Rect(100, 300, 100, 100));
1481 window4_->SetBounds(gfx::Rect(100, 400, 100, 100)); 1559 window4_->SetBounds(gfx::Rect(100, 400, 100, 100));
1482 delegate2_.set_min_size(gfx::Size(0, 99)); 1560 delegate2_.set_min_size(gfx::Size(0, 99));
1483 delegate3_.set_min_size(gfx::Size(0, 99)); 1561 delegate3_.set_min_size(gfx::Size(0, 99));
1484 1562
1485 std::vector<aura::Window*> windows; 1563 std::vector<aura::Window*> windows;
1486 windows.push_back(window2_.get()); 1564 windows.push_back(window2_.get());
1487 windows.push_back(window3_.get()); 1565 windows.push_back(window3_.get());
1488 windows.push_back(window4_.get()); 1566 windows.push_back(window4_.get());
1489 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1567 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1490 window_.get(), gfx::Point(), HTBOTTOM, windows)); 1568 window_.get(), gfx::Point(), HTBOTTOM,
1569 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1491 ASSERT_TRUE(resizer.get()); 1570 ASSERT_TRUE(resizer.get());
1492 // Move it 52 down, which should expand w1 and contract w2-4. 1571 // Move it 52 down, which should expand w1 and contract w2-4.
1493 resizer->Drag(CalculateDragPoint(*resizer, 0, 52), 0); 1572 resizer->Drag(CalculateDragPoint(*resizer, 0, 52), 0);
1494 EXPECT_EQ("100,100 100x152", window_->bounds().ToString()); 1573 EXPECT_EQ("100,100 100x152", window_->bounds().ToString());
1495 EXPECT_EQ("100,252 100x99", window2_->bounds().ToString()); 1574 EXPECT_EQ("100,252 100x99", window2_->bounds().ToString());
1496 EXPECT_EQ("100,351 100x99", window3_->bounds().ToString()); 1575 EXPECT_EQ("100,351 100x99", window3_->bounds().ToString());
1497 EXPECT_EQ("100,450 100x50", window4_->bounds().ToString()); 1576 EXPECT_EQ("100,450 100x50", window4_->bounds().ToString());
1498 } 1577 }
1499 1578
1500 TEST_F(WorkspaceWindowResizerTest, DontExpandRightmostPastMaxWidth) { 1579 TEST_F(WorkspaceWindowResizerTest, DontExpandRightmostPastMaxWidth) {
1501 UpdateDisplay("600x800"); 1580 UpdateDisplay("600x800");
1502 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); 1581 aura::RootWindow* root = Shell::GetPrimaryRootWindow();
1503 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets()); 1582 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1504 1583
1505 // Three 100x100 windows flush against eachother, starting at 100,100. 1584 // Three 100x100 windows flush against eachother, starting at 100,100.
1506 window_->SetBounds(gfx::Rect( 100, 100, 100, 100)); 1585 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1507 window2_->SetBounds(gfx::Rect(200, 100, 100, 100)); 1586 window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
1508 window3_->SetBounds(gfx::Rect(300, 100, 100, 100)); 1587 window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
1509 delegate3_.set_max_size(gfx::Size(101, 0)); 1588 delegate3_.set_max_size(gfx::Size(101, 0));
1510 1589
1511 std::vector<aura::Window*> windows; 1590 std::vector<aura::Window*> windows;
1512 windows.push_back(window2_.get()); 1591 windows.push_back(window2_.get());
1513 windows.push_back(window3_.get()); 1592 windows.push_back(window3_.get());
1514 windows.push_back(window4_.get()); 1593 windows.push_back(window4_.get());
1515 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1594 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1516 window_.get(), gfx::Point(), HTRIGHT, windows)); 1595 window_.get(), gfx::Point(), HTRIGHT,
1596 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1517 ASSERT_TRUE(resizer.get()); 1597 ASSERT_TRUE(resizer.get());
1518 // Move it 51 to the left, which should contract w1 and expand w2-3. 1598 // Move it 51 to the left, which should contract w1 and expand w2-3.
1519 resizer->Drag(CalculateDragPoint(*resizer, -51, 0), 0); 1599 resizer->Drag(CalculateDragPoint(*resizer, -51, 0), 0);
1520 EXPECT_EQ("100,100 49x100", window_->bounds().ToString()); 1600 EXPECT_EQ("100,100 49x100", window_->bounds().ToString());
1521 EXPECT_EQ("149,100 150x100", window2_->bounds().ToString()); 1601 EXPECT_EQ("149,100 150x100", window2_->bounds().ToString());
1522 EXPECT_EQ("299,100 101x100", window3_->bounds().ToString()); 1602 EXPECT_EQ("299,100 101x100", window3_->bounds().ToString());
1523 } 1603 }
1524 1604
1525 TEST_F(WorkspaceWindowResizerTest, MoveAttachedWhenGrownToMaxSize) { 1605 TEST_F(WorkspaceWindowResizerTest, MoveAttachedWhenGrownToMaxSize) {
1526 UpdateDisplay("600x800"); 1606 UpdateDisplay("600x800");
1527 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); 1607 aura::RootWindow* root = Shell::GetPrimaryRootWindow();
1528 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets()); 1608 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1529 1609
1530 // Three 100x100 windows flush against eachother, starting at 100,100. 1610 // Three 100x100 windows flush against eachother, starting at 100,100.
1531 window_->SetBounds(gfx::Rect( 100, 100, 100, 100)); 1611 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1532 window2_->SetBounds(gfx::Rect(200, 100, 100, 100)); 1612 window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
1533 window3_->SetBounds(gfx::Rect(300, 100, 100, 100)); 1613 window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
1534 delegate2_.set_max_size(gfx::Size(101, 0)); 1614 delegate2_.set_max_size(gfx::Size(101, 0));
1535 delegate3_.set_max_size(gfx::Size(101, 0)); 1615 delegate3_.set_max_size(gfx::Size(101, 0));
1536 1616
1537 std::vector<aura::Window*> windows; 1617 std::vector<aura::Window*> windows;
1538 windows.push_back(window2_.get()); 1618 windows.push_back(window2_.get());
1539 windows.push_back(window3_.get()); 1619 windows.push_back(window3_.get());
1540 windows.push_back(window4_.get()); 1620 windows.push_back(window4_.get());
1541 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1621 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1542 window_.get(), gfx::Point(), HTRIGHT, windows)); 1622 window_.get(), gfx::Point(), HTRIGHT,
1623 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1543 ASSERT_TRUE(resizer.get()); 1624 ASSERT_TRUE(resizer.get());
1544 // Move it 52 to the left, which should contract w1 and expand and move w2-3. 1625 // Move it 52 to the left, which should contract w1 and expand and move w2-3.
1545 resizer->Drag(CalculateDragPoint(*resizer, -52, 0), 0); 1626 resizer->Drag(CalculateDragPoint(*resizer, -52, 0), 0);
1546 EXPECT_EQ("100,100 48x100", window_->bounds().ToString()); 1627 EXPECT_EQ("100,100 48x100", window_->bounds().ToString());
1547 EXPECT_EQ("148,100 101x100", window2_->bounds().ToString()); 1628 EXPECT_EQ("148,100 101x100", window2_->bounds().ToString());
1548 EXPECT_EQ("249,100 101x100", window3_->bounds().ToString()); 1629 EXPECT_EQ("249,100 101x100", window3_->bounds().ToString());
1549 } 1630 }
1550 1631
1551 #if defined(OS_WIN) 1632 #if defined(OS_WIN)
1552 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962 1633 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
(...skipping 11 matching lines...) Expand all
1564 window_->SetBounds(gfx::Rect( 100, 100, 100, 100)); 1645 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1565 window2_->SetBounds(gfx::Rect(200, 100, 100, 100)); 1646 window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
1566 window3_->SetBounds(gfx::Rect(300, 100, 100, 100)); 1647 window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
1567 delegate_.set_max_size(gfx::Size(102, 0)); 1648 delegate_.set_max_size(gfx::Size(102, 0));
1568 1649
1569 std::vector<aura::Window*> windows; 1650 std::vector<aura::Window*> windows;
1570 windows.push_back(window2_.get()); 1651 windows.push_back(window2_.get());
1571 windows.push_back(window3_.get()); 1652 windows.push_back(window3_.get());
1572 windows.push_back(window4_.get()); 1653 windows.push_back(window4_.get());
1573 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1654 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1574 window_.get(), gfx::Point(), HTRIGHT, windows)); 1655 window_.get(), gfx::Point(), HTRIGHT,
1656 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1575 ASSERT_TRUE(resizer.get()); 1657 ASSERT_TRUE(resizer.get());
1576 // Move it 50 to the right, which should expand w1 and contract w2-3, as they 1658 // Move it 50 to the right, which should expand w1 and contract w2-3, as they
1577 // won't fit in the root window in their original sizes. 1659 // won't fit in the root window in their original sizes.
1578 resizer->Drag(CalculateDragPoint(*resizer, 50, 0), 0); 1660 resizer->Drag(CalculateDragPoint(*resizer, 50, 0), 0);
1579 EXPECT_EQ("100,100 102x100", window_->bounds().ToString()); 1661 EXPECT_EQ("100,100 102x100", window_->bounds().ToString());
1580 EXPECT_EQ("202,100 99x100", window2_->bounds().ToString()); 1662 EXPECT_EQ("202,100 99x100", window2_->bounds().ToString());
1581 EXPECT_EQ("301,100 99x100", window3_->bounds().ToString()); 1663 EXPECT_EQ("301,100 99x100", window3_->bounds().ToString());
1582 } 1664 }
1583 1665
1584 TEST_F(WorkspaceWindowResizerTest, MainWindowHonoursMinWidth) { 1666 TEST_F(WorkspaceWindowResizerTest, MainWindowHonoursMinWidth) {
1585 UpdateDisplay("400x800"); 1667 UpdateDisplay("400x800");
1586 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); 1668 aura::RootWindow* root = Shell::GetPrimaryRootWindow();
1587 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets()); 1669 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1588 1670
1589 // Three 100x100 windows flush against eachother, starting at 100,100. 1671 // Three 100x100 windows flush against eachother, starting at 100,100.
1590 window_->SetBounds(gfx::Rect( 100, 100, 100, 100)); 1672 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
1591 window2_->SetBounds(gfx::Rect(200, 100, 100, 100)); 1673 window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
1592 window3_->SetBounds(gfx::Rect(300, 100, 100, 100)); 1674 window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
1593 delegate_.set_min_size(gfx::Size(98, 0)); 1675 delegate_.set_min_size(gfx::Size(98, 0));
1594 1676
1595 std::vector<aura::Window*> windows; 1677 std::vector<aura::Window*> windows;
1596 windows.push_back(window2_.get()); 1678 windows.push_back(window2_.get());
1597 windows.push_back(window3_.get()); 1679 windows.push_back(window3_.get());
1598 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1680 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1599 window_.get(), gfx::Point(), HTRIGHT, windows)); 1681 window_.get(), gfx::Point(), HTRIGHT,
1682 aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
1600 ASSERT_TRUE(resizer.get()); 1683 ASSERT_TRUE(resizer.get());
1601 // Move it 50 to the left, which should contract w1 and expand w2-3. 1684 // Move it 50 to the left, which should contract w1 and expand w2-3.
1602 resizer->Drag(CalculateDragPoint(*resizer, -50, 0), 0); 1685 resizer->Drag(CalculateDragPoint(*resizer, -50, 0), 0);
1603 EXPECT_EQ("100,100 98x100", window_->bounds().ToString()); 1686 EXPECT_EQ("100,100 98x100", window_->bounds().ToString());
1604 EXPECT_EQ("198,100 101x100", window2_->bounds().ToString()); 1687 EXPECT_EQ("198,100 101x100", window2_->bounds().ToString());
1605 EXPECT_EQ("299,100 101x100", window3_->bounds().ToString()); 1688 EXPECT_EQ("299,100 101x100", window3_->bounds().ToString());
1606 } 1689 }
1607 1690
1691 // The following variants test that windows are resized correctly to the edges
1692 // of the screen using touch, when touch point is off of the window border.
1693 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_RIGHT) {
1694 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1695
1696 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTRIGHT);
1697 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
1698 touch_resize_window_->bounds().ToString());
1699
1700 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1701 touch_resize_window_.get());
1702
1703 // Drag out of the right border a bit and check if the border is aligned with
1704 // the touch point.
1705 generator.GestureScrollSequence(gfx::Point(715, kRootHeight / 2),
1706 gfx::Point(725, kRootHeight / 2),
1707 base::TimeDelta::FromMilliseconds(100),
1708 1);
1709 EXPECT_EQ(gfx::Rect(100, 100, 625, kRootHeight - 200).ToString(),
1710 touch_resize_window_->bounds().ToString());
1711 // Drag more, but stop before being snapped to the edge.
1712 generator.GestureScrollSequence(gfx::Point(725, kRootHeight / 2),
1713 gfx::Point(760, kRootHeight / 2),
1714 base::TimeDelta::FromMilliseconds(100),
1715 1);
1716 EXPECT_EQ(gfx::Rect(100, 100, 660, kRootHeight - 200).ToString(),
1717 touch_resize_window_->bounds().ToString());
1718 // Drag even more to snap to the edge.
1719 generator.GestureScrollSequence(gfx::Point(760, kRootHeight / 2),
1720 gfx::Point(775, kRootHeight / 2),
1721 base::TimeDelta::FromMilliseconds(100),
1722 1);
1723 EXPECT_EQ(gfx::Rect(100, 100, 700, kRootHeight - 200).ToString(),
1724 touch_resize_window_->bounds().ToString());
1725 }
1726
1727 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_LEFT) {
1728 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1729
1730 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTLEFT);
1731 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
1732 touch_resize_window_->bounds().ToString());
1733
1734 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1735 touch_resize_window_.get());
1736
1737 // Drag out of the left border a bit and check if the border is aligned with
1738 // the touch point.
1739 generator.GestureScrollSequence(gfx::Point(85, kRootHeight / 2),
1740 gfx::Point(75, kRootHeight / 2),
1741 base::TimeDelta::FromMilliseconds(100),
1742 1);
1743 EXPECT_EQ(gfx::Rect(75, 100, 625, kRootHeight - 200).ToString(),
1744 touch_resize_window_->bounds().ToString());
1745 // Drag more, but stop before being snapped to the edge.
1746 generator.GestureScrollSequence(gfx::Point(75, kRootHeight / 2),
1747 gfx::Point(40, kRootHeight / 2),
1748 base::TimeDelta::FromMilliseconds(100),
1749 1);
1750 EXPECT_EQ(gfx::Rect(40, 100, 660, kRootHeight - 200).ToString(),
1751 touch_resize_window_->bounds().ToString());
1752 // Drag even more to snap to the edge.
1753 generator.GestureScrollSequence(gfx::Point(40, kRootHeight / 2),
1754 gfx::Point(25, kRootHeight / 2),
1755 base::TimeDelta::FromMilliseconds(100),
1756 1);
1757 EXPECT_EQ(gfx::Rect(0, 100, 700, kRootHeight - 200).ToString(),
1758 touch_resize_window_->bounds().ToString());
1759 }
1760
1761 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_TOP) {
1762 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1763
1764 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTTOP);
1765 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
1766 touch_resize_window_->bounds().ToString());
1767
1768 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1769 touch_resize_window_.get());
1770
1771 // Drag out of the top border a bit and check if the border is aligned with
1772 // the touch point.
1773 generator.GestureScrollSequence(gfx::Point(400, 85),
1774 gfx::Point(400, 75),
1775 base::TimeDelta::FromMilliseconds(100),
1776 1);
1777 EXPECT_EQ(gfx::Rect(100, 75, 600, kRootHeight - 175).ToString(),
1778 touch_resize_window_->bounds().ToString());
1779 // Drag more, but stop before being snapped to the edge.
1780 generator.GestureScrollSequence(gfx::Point(400, 75),
1781 gfx::Point(400, 40),
1782 base::TimeDelta::FromMilliseconds(100),
1783 1);
1784 EXPECT_EQ(gfx::Rect(100, 40, 600, kRootHeight - 140).ToString(),
1785 touch_resize_window_->bounds().ToString());
1786 // Drag even more to snap to the edge.
1787 generator.GestureScrollSequence(gfx::Point(400, 40),
1788 gfx::Point(400, 25),
1789 base::TimeDelta::FromMilliseconds(100),
1790 1);
1791 EXPECT_EQ(gfx::Rect(100, 0, 600, kRootHeight - 100).ToString(),
1792 touch_resize_window_->bounds().ToString());
1793 }
1794
1795 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_BOTTOM) {
1796 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1797
1798 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTBOTTOM);
1799 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
1800 touch_resize_window_->bounds().ToString());
1801
1802 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1803 touch_resize_window_.get());
1804
1805 // Drag out of the bottom border a bit and check if the border is aligned with
1806 // the touch point.
1807 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 85),
1808 gfx::Point(400, kRootHeight - 75),
1809 base::TimeDelta::FromMilliseconds(100),
1810 1);
1811 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 175).ToString(),
1812 touch_resize_window_->bounds().ToString());
1813 // Drag more, but stop before being snapped to the edge.
1814 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 75),
1815 gfx::Point(400, kRootHeight - 40),
1816 base::TimeDelta::FromMilliseconds(100),
1817 1);
1818 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 140).ToString(),
1819 touch_resize_window_->bounds().ToString());
1820 // Drag even more to snap to the edge.
1821 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 40),
1822 gfx::Point(400, kRootHeight - 25),
1823 base::TimeDelta::FromMilliseconds(100),
1824 1);
1825 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 100).ToString(),
1826 touch_resize_window_->bounds().ToString());
1827 }
1608 } // namespace internal 1828 } // namespace internal
1609 } // namespace ash 1829 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/workspace_window_resizer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698