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

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

Issue 10008084: Add ctrl+drag feature for allowing resizing window with exact positioning. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nits. Created 8 years, 8 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/screen_ash.h" 7 #include "ash/screen_ash.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/test/ash_test_base.h" 9 #include "ash/test/ash_test_base.h"
10 #include "ash/wm/property_util.h" 10 #include "ash/wm/property_util.h"
11 #include "ash/wm/workspace_controller.h"
11 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
12 #include "ui/aura/root_window.h" 13 #include "ui/aura/root_window.h"
13 #include "ui/aura/test/test_window_delegate.h" 14 #include "ui/aura/test/test_window_delegate.h"
14 #include "ui/base/hit_test.h" 15 #include "ui/base/hit_test.h"
15 #include "ui/gfx/insets.h" 16 #include "ui/gfx/insets.h"
16 17
17 namespace ash { 18 namespace ash {
18 namespace internal { 19 namespace internal {
19 namespace { 20 namespace {
20 21
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 if (*i == window_.get() || *i == window2_.get() || *i == window3_.get()) { 91 if (*i == window_.get() || *i == window2_.get() || *i == window3_.get()) {
91 if (!result.empty()) 92 if (!result.empty())
92 result += " "; 93 result += " ";
93 result += base::IntToString((*i)->id()); 94 result += base::IntToString((*i)->id());
94 } 95 }
95 } 96 }
96 return result; 97 return result;
97 } 98 }
98 99
99 protected: 100 protected:
101 void SetGridSize(int grid_size) {
102 Shell::TestApi shell_test(Shell::GetInstance());
103 shell_test.workspace_controller()->SetGridSize(grid_size);
104 }
100 gfx::Point CalculateDragPoint(const WorkspaceWindowResizer& resizer, 105 gfx::Point CalculateDragPoint(const WorkspaceWindowResizer& resizer,
101 int delta_x, 106 int delta_x,
102 int delta_y) const { 107 int delta_y) const {
103 gfx::Point location = resizer.initial_location_in_parent(); 108 gfx::Point location = resizer.initial_location_in_parent();
104 location.set_x(location.x() + delta_x); 109 location.set_x(location.x() + delta_x);
105 location.set_y(location.y() + delta_y); 110 location.set_y(location.y() + delta_y);
106 return location; 111 return location;
107 } 112 }
108 113
109 std::vector<aura::Window*> empty_windows() const { 114 std::vector<aura::Window*> empty_windows() const {
(...skipping 18 matching lines...) Expand all
128 #if !defined(OS_WIN) 133 #if !defined(OS_WIN)
129 134
130 // Assertions around attached window resize dragging from the right with 2 135 // Assertions around attached window resize dragging from the right with 2
131 // windows. 136 // windows.
132 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2) { 137 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2) {
133 window_->SetBounds(gfx::Rect(0, 300, 400, 300)); 138 window_->SetBounds(gfx::Rect(0, 300, 400, 300));
134 window2_->SetBounds(gfx::Rect(400, 200, 100, 200)); 139 window2_->SetBounds(gfx::Rect(400, 200, 100, 200));
135 140
136 std::vector<aura::Window*> windows; 141 std::vector<aura::Window*> windows;
137 windows.push_back(window2_.get()); 142 windows.push_back(window2_.get());
143 SetGridSize(0);
138 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 144 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
139 window_.get(), gfx::Point(), HTRIGHT, 0, windows)); 145 window_.get(), gfx::Point(), HTRIGHT, windows));
140 ASSERT_TRUE(resizer.get()); 146 ASSERT_TRUE(resizer.get());
141 // Move it 100 to the right, which should expand w1 and push w2. 147 // Move it 100 to the right, which should expand w1 and push w2.
142 resizer->Drag(CalculateDragPoint(*resizer, 100, 10)); 148 resizer->Drag(CalculateDragPoint(*resizer, 100, 10), 0);
143 EXPECT_EQ("0,300 500x300", window_->bounds().ToString()); 149 EXPECT_EQ("0,300 500x300", window_->bounds().ToString());
144 EXPECT_EQ("500,200 100x200", window2_->bounds().ToString()); 150 EXPECT_EQ("500,200 100x200", window2_->bounds().ToString());
145 151
146 // Push off the screen, w2 should be resized to its min. 152 // Push off the screen, w2 should be resized to its min.
147 delegate2_.set_min_size(gfx::Size(20, 20)); 153 delegate2_.set_min_size(gfx::Size(20, 20));
148 resizer->Drag(CalculateDragPoint(*resizer, 800, 20)); 154 resizer->Drag(CalculateDragPoint(*resizer, 800, 20), 0);
149 EXPECT_EQ("0,300 780x300", window_->bounds().ToString()); 155 EXPECT_EQ("0,300 780x300", window_->bounds().ToString());
150 EXPECT_EQ("780,200 20x200", window2_->bounds().ToString()); 156 EXPECT_EQ("780,200 20x200", window2_->bounds().ToString());
151 157
152 // Move back to 100 and verify w2 gets its original size. 158 // Move back to 100 and verify w2 gets its original size.
153 resizer->Drag(CalculateDragPoint(*resizer, 100, 10)); 159 resizer->Drag(CalculateDragPoint(*resizer, 100, 10), 0);
154 EXPECT_EQ("0,300 500x300", window_->bounds().ToString()); 160 EXPECT_EQ("0,300 500x300", window_->bounds().ToString());
155 EXPECT_EQ("500,200 100x200", window2_->bounds().ToString()); 161 EXPECT_EQ("500,200 100x200", window2_->bounds().ToString());
156 162
157 // Revert and make sure everything moves back. 163 // Revert and make sure everything moves back.
158 resizer->Drag(CalculateDragPoint(*resizer, 800, 20)); 164 resizer->Drag(CalculateDragPoint(*resizer, 800, 20), 0);
159 resizer->RevertDrag(); 165 resizer->RevertDrag();
160 EXPECT_EQ("0,300 400x300", window_->bounds().ToString()); 166 EXPECT_EQ("0,300 400x300", window_->bounds().ToString());
161 EXPECT_EQ("400,200 100x200", window2_->bounds().ToString()); 167 EXPECT_EQ("400,200 100x200", window2_->bounds().ToString());
162 } 168 }
163 169
164 // Assertions around collapsing and expanding. 170 // Assertions around collapsing and expanding.
165 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_Compress) { 171 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_Compress) {
166 window_->SetBounds(gfx::Rect( 0, 300, 400, 300)); 172 window_->SetBounds(gfx::Rect( 0, 300, 400, 300));
167 window2_->SetBounds(gfx::Rect(400, 200, 100, 200)); 173 window2_->SetBounds(gfx::Rect(400, 200, 100, 200));
168 174
169 std::vector<aura::Window*> windows; 175 std::vector<aura::Window*> windows;
170 windows.push_back(window2_.get()); 176 windows.push_back(window2_.get());
177 SetGridSize(0);
171 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 178 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
172 window_.get(), gfx::Point(), HTRIGHT, 0, windows)); 179 window_.get(), gfx::Point(), HTRIGHT, windows));
173 ASSERT_TRUE(resizer.get()); 180 ASSERT_TRUE(resizer.get());
174 // Move it 100 to the left, which should expand w2 and collapse w1. 181 // Move it 100 to the left, which should expand w2 and collapse w1.
175 resizer->Drag(CalculateDragPoint(*resizer, -100, 10)); 182 resizer->Drag(CalculateDragPoint(*resizer, -100, 10), 0);
176 EXPECT_EQ("0,300 300x300", window_->bounds().ToString()); 183 EXPECT_EQ("0,300 300x300", window_->bounds().ToString());
177 EXPECT_EQ("300,200 200x200", window2_->bounds().ToString()); 184 EXPECT_EQ("300,200 200x200", window2_->bounds().ToString());
178 185
179 // Collapse all the way to w1's min. 186 // Collapse all the way to w1's min.
180 delegate_.set_min_size(gfx::Size(20, 20)); 187 delegate_.set_min_size(gfx::Size(20, 20));
181 resizer->Drag(CalculateDragPoint(*resizer, -800, 20)); 188 resizer->Drag(CalculateDragPoint(*resizer, -800, 20), 0);
182 EXPECT_EQ("0,300 20x300", window_->bounds().ToString()); 189 EXPECT_EQ("0,300 20x300", window_->bounds().ToString());
183 EXPECT_EQ("20,200 480x200", window2_->bounds().ToString()); 190 EXPECT_EQ("20,200 480x200", window2_->bounds().ToString());
184 191
185 // Move 100 to the left. 192 // Move 100 to the left.
186 resizer->Drag(CalculateDragPoint(*resizer, 100, 10)); 193 resizer->Drag(CalculateDragPoint(*resizer, 100, 10), 0);
187 EXPECT_EQ("0,300 500x300", window_->bounds().ToString()); 194 EXPECT_EQ("0,300 500x300", window_->bounds().ToString());
188 EXPECT_EQ("500,200 100x200", window2_->bounds().ToString()); 195 EXPECT_EQ("500,200 100x200", window2_->bounds().ToString());
189 196
190 // Back to -100. 197 // Back to -100.
191 resizer->Drag(CalculateDragPoint(*resizer, -100, 20)); 198 resizer->Drag(CalculateDragPoint(*resizer, -100, 20), 0);
192 EXPECT_EQ("0,300 300x300", window_->bounds().ToString()); 199 EXPECT_EQ("0,300 300x300", window_->bounds().ToString());
193 EXPECT_EQ("300,200 200x200", window2_->bounds().ToString()); 200 EXPECT_EQ("300,200 200x200", window2_->bounds().ToString());
194 } 201 }
195 202
196 // Assertions around attached window resize dragging from the right with 3 203 // Assertions around attached window resize dragging from the right with 3
197 // windows. 204 // windows.
198 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_3) { 205 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_3) {
199 window_->SetBounds(gfx::Rect( 100, 300, 200, 300)); 206 window_->SetBounds(gfx::Rect( 100, 300, 200, 300));
200 window2_->SetBounds(gfx::Rect(300, 300, 150, 200)); 207 window2_->SetBounds(gfx::Rect(300, 300, 150, 200));
201 window3_->SetBounds(gfx::Rect(450, 300, 100, 200)); 208 window3_->SetBounds(gfx::Rect(450, 300, 100, 200));
202 delegate2_.set_min_size(gfx::Size(52, 50)); 209 delegate2_.set_min_size(gfx::Size(52, 50));
203 delegate3_.set_min_size(gfx::Size(38, 50)); 210 delegate3_.set_min_size(gfx::Size(38, 50));
204 211
205 std::vector<aura::Window*> windows; 212 std::vector<aura::Window*> windows;
206 windows.push_back(window2_.get()); 213 windows.push_back(window2_.get());
207 windows.push_back(window3_.get()); 214 windows.push_back(window3_.get());
215 SetGridSize(10);
208 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 216 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
209 window_.get(), gfx::Point(), HTRIGHT, 10, windows)); 217 window_.get(), gfx::Point(), HTRIGHT, windows));
210 ASSERT_TRUE(resizer.get()); 218 ASSERT_TRUE(resizer.get());
211 // Move it 100 to the right, which should expand w1 and push w2 and w3. 219 // Move it 100 to the right, which should expand w1 and push w2 and w3.
212 resizer->Drag(CalculateDragPoint(*resizer, 100, -10)); 220 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
213 EXPECT_EQ("100,300 300x300", window_->bounds().ToString()); 221 EXPECT_EQ("100,300 300x300", window_->bounds().ToString());
214 EXPECT_EQ("400,300 150x200", window2_->bounds().ToString()); 222 EXPECT_EQ("400,300 150x200", window2_->bounds().ToString());
215 EXPECT_EQ("550,300 100x200", window3_->bounds().ToString()); 223 EXPECT_EQ("550,300 100x200", window3_->bounds().ToString());
216 224
217 // Move it 296, which should now snap to grid and things should compress. 225 // Move it 296, which should now snap to grid and things should compress.
218 resizer->Drag(CalculateDragPoint(*resizer, 296, -10)); 226 resizer->Drag(CalculateDragPoint(*resizer, 296, -10), 0);
219 EXPECT_EQ("100,300 500x300", window_->bounds().ToString()); 227 EXPECT_EQ("100,300 500x300", window_->bounds().ToString());
220 EXPECT_EQ("600,300 120x200", window2_->bounds().ToString()); 228 EXPECT_EQ("600,300 120x200", window2_->bounds().ToString());
221 EXPECT_EQ("720,300 80x200", window3_->bounds().ToString()); 229 EXPECT_EQ("720,300 80x200", window3_->bounds().ToString());
222 230
223 // Move it so much everything ends up at its min. 231 // Move it so much everything ends up at its min.
224 resizer->Drag(CalculateDragPoint(*resizer, 798, 50)); 232 resizer->Drag(CalculateDragPoint(*resizer, 798, 50), 0);
225 EXPECT_EQ("100,300 600x300", window_->bounds().ToString()); 233 EXPECT_EQ("100,300 600x300", window_->bounds().ToString());
226 EXPECT_EQ("700,300 60x200", window2_->bounds().ToString()); 234 EXPECT_EQ("700,300 60x200", window2_->bounds().ToString());
227 EXPECT_EQ("760,300 40x200", window3_->bounds().ToString()); 235 EXPECT_EQ("760,300 40x200", window3_->bounds().ToString());
228 236
229 // Revert and make sure everything moves back. 237 // Revert and make sure everything moves back.
230 resizer->RevertDrag(); 238 resizer->RevertDrag();
231 EXPECT_EQ("100,300 200x300", window_->bounds().ToString()); 239 EXPECT_EQ("100,300 200x300", window_->bounds().ToString());
232 EXPECT_EQ("300,300 150x200", window2_->bounds().ToString()); 240 EXPECT_EQ("300,300 150x200", window2_->bounds().ToString());
233 EXPECT_EQ("450,300 100x200", window3_->bounds().ToString()); 241 EXPECT_EQ("450,300 100x200", window3_->bounds().ToString());
234 } 242 }
235 243
236 // Assertions around attached window resizing (collapsing and expanding) with 244 // Assertions around attached window resizing (collapsing and expanding) with
237 // 3 windows. 245 // 3 windows.
238 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_3_Compress) { 246 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_3_Compress) {
239 window_->SetBounds(gfx::Rect( 100, 300, 200, 300)); 247 window_->SetBounds(gfx::Rect( 100, 300, 200, 300));
240 window2_->SetBounds(gfx::Rect(300, 300, 200, 200)); 248 window2_->SetBounds(gfx::Rect(300, 300, 200, 200));
241 window3_->SetBounds(gfx::Rect(450, 300, 100, 200)); 249 window3_->SetBounds(gfx::Rect(450, 300, 100, 200));
242 delegate2_.set_min_size(gfx::Size(52, 50)); 250 delegate2_.set_min_size(gfx::Size(52, 50));
243 delegate3_.set_min_size(gfx::Size(38, 50)); 251 delegate3_.set_min_size(gfx::Size(38, 50));
244 252
245 std::vector<aura::Window*> windows; 253 std::vector<aura::Window*> windows;
246 windows.push_back(window2_.get()); 254 windows.push_back(window2_.get());
247 windows.push_back(window3_.get()); 255 windows.push_back(window3_.get());
256 SetGridSize(10);
248 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 257 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
249 window_.get(), gfx::Point(), HTRIGHT, 10, windows)); 258 window_.get(), gfx::Point(), HTRIGHT, windows));
250 ASSERT_TRUE(resizer.get()); 259 ASSERT_TRUE(resizer.get());
251 // Move it -100 to the right, which should collapse w1 and expand w2 and w3. 260 // Move it -100 to the right, which should collapse w1 and expand w2 and w3.
252 resizer->Drag(CalculateDragPoint(*resizer, -100, -10)); 261 resizer->Drag(CalculateDragPoint(*resizer, -100, -10), 0);
253 EXPECT_EQ("100,300 100x300", window_->bounds().ToString()); 262 EXPECT_EQ("100,300 100x300", window_->bounds().ToString());
254 EXPECT_EQ("200,300 270x200", window2_->bounds().ToString()); 263 EXPECT_EQ("200,300 270x200", window2_->bounds().ToString());
255 EXPECT_EQ("470,300 130x200", window3_->bounds().ToString()); 264 EXPECT_EQ("470,300 130x200", window3_->bounds().ToString());
256 265
257 // Move it 100 to the right. 266 // Move it 100 to the right.
258 resizer->Drag(CalculateDragPoint(*resizer, 100, -10)); 267 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
259 EXPECT_EQ("100,300 300x300", window_->bounds().ToString()); 268 EXPECT_EQ("100,300 300x300", window_->bounds().ToString());
260 EXPECT_EQ("400,300 200x200", window2_->bounds().ToString()); 269 EXPECT_EQ("400,300 200x200", window2_->bounds().ToString());
261 EXPECT_EQ("600,300 100x200", window3_->bounds().ToString()); 270 EXPECT_EQ("600,300 100x200", window3_->bounds().ToString());
262 271
263 // 100 to the left again. 272 // 100 to the left again.
264 resizer->Drag(CalculateDragPoint(*resizer, -100, -10)); 273 resizer->Drag(CalculateDragPoint(*resizer, -100, -10), 0);
265 EXPECT_EQ("100,300 100x300", window_->bounds().ToString()); 274 EXPECT_EQ("100,300 100x300", window_->bounds().ToString());
266 EXPECT_EQ("200,300 270x200", window2_->bounds().ToString()); 275 EXPECT_EQ("200,300 270x200", window2_->bounds().ToString());
267 EXPECT_EQ("470,300 130x200", window3_->bounds().ToString()); 276 EXPECT_EQ("470,300 130x200", window3_->bounds().ToString());
268 } 277 }
269 278
270 // Assertions around collapsing and expanding from the bottom. 279 // Assertions around collapsing and expanding from the bottom.
271 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_Compress) { 280 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_Compress) {
272 window_->SetBounds(gfx::Rect( 0, 100, 400, 300)); 281 window_->SetBounds(gfx::Rect( 0, 100, 400, 300));
273 window2_->SetBounds(gfx::Rect(400, 400, 100, 200)); 282 window2_->SetBounds(gfx::Rect(400, 400, 100, 200));
274 283
275 std::vector<aura::Window*> windows; 284 std::vector<aura::Window*> windows;
276 windows.push_back(window2_.get()); 285 windows.push_back(window2_.get());
286 SetGridSize(0);
277 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 287 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
278 window_.get(), gfx::Point(), HTBOTTOM, 0, windows)); 288 window_.get(), gfx::Point(), HTBOTTOM, windows));
279 ASSERT_TRUE(resizer.get()); 289 ASSERT_TRUE(resizer.get());
280 // Move it up 100, which should expand w2 and collapse w1. 290 // Move it up 100, which should expand w2 and collapse w1.
281 resizer->Drag(CalculateDragPoint(*resizer, 10, -100)); 291 resizer->Drag(CalculateDragPoint(*resizer, 10, -100), 0);
282 EXPECT_EQ("0,100 400x200", window_->bounds().ToString()); 292 EXPECT_EQ("0,100 400x200", window_->bounds().ToString());
283 EXPECT_EQ("400,300 100x300", window2_->bounds().ToString()); 293 EXPECT_EQ("400,300 100x300", window2_->bounds().ToString());
284 294
285 // Collapse all the way to w1's min. 295 // Collapse all the way to w1's min.
286 delegate_.set_min_size(gfx::Size(20, 20)); 296 delegate_.set_min_size(gfx::Size(20, 20));
287 resizer->Drag(CalculateDragPoint(*resizer, 20, -800)); 297 resizer->Drag(CalculateDragPoint(*resizer, 20, -800), 0);
288 EXPECT_EQ("0,100 400x20", window_->bounds().ToString()); 298 EXPECT_EQ("0,100 400x20", window_->bounds().ToString());
289 EXPECT_EQ("400,120 100x480", window2_->bounds().ToString()); 299 EXPECT_EQ("400,120 100x480", window2_->bounds().ToString());
290 300
291 // Move 100 down. 301 // Move 100 down.
292 resizer->Drag(CalculateDragPoint(*resizer, 10, 100)); 302 resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0);
293 EXPECT_EQ("0,100 400x400", window_->bounds().ToString()); 303 EXPECT_EQ("0,100 400x400", window_->bounds().ToString());
294 EXPECT_EQ("400,500 100x100", window2_->bounds().ToString()); 304 EXPECT_EQ("400,500 100x100", window2_->bounds().ToString());
295 305
296 // Back to -100. 306 // Back to -100.
297 resizer->Drag(CalculateDragPoint(*resizer, 20, -100)); 307 resizer->Drag(CalculateDragPoint(*resizer, 20, -100), 0);
298 EXPECT_EQ("0,100 400x200", window_->bounds().ToString()); 308 EXPECT_EQ("0,100 400x200", window_->bounds().ToString());
299 EXPECT_EQ("400,300 100x300", window2_->bounds().ToString()); 309 EXPECT_EQ("400,300 100x300", window2_->bounds().ToString());
300 } 310 }
301 311
302 // Assertions around attached window resize dragging from the bottom with 2 312 // Assertions around attached window resize dragging from the bottom with 2
303 // windows. 313 // windows.
304 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_2) { 314 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_2) {
305 window_->SetBounds(gfx::Rect( 0, 50, 400, 200)); 315 window_->SetBounds(gfx::Rect( 0, 50, 400, 200));
306 window2_->SetBounds(gfx::Rect(0, 250, 200, 100)); 316 window2_->SetBounds(gfx::Rect(0, 250, 200, 100));
307 317
308 std::vector<aura::Window*> windows; 318 std::vector<aura::Window*> windows;
309 windows.push_back(window2_.get()); 319 windows.push_back(window2_.get());
320 SetGridSize(0);
310 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 321 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
311 window_.get(), gfx::Point(), HTBOTTOM, 0, windows)); 322 window_.get(), gfx::Point(), HTBOTTOM, windows));
312 ASSERT_TRUE(resizer.get()); 323 ASSERT_TRUE(resizer.get());
313 // Move it 100 to the bottom, which should expand w1 and push w2. 324 // Move it 100 to the bottom, which should expand w1 and push w2.
314 resizer->Drag(CalculateDragPoint(*resizer, 10, 100)); 325 resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0);
315 EXPECT_EQ("0,50 400x300", window_->bounds().ToString()); 326 EXPECT_EQ("0,50 400x300", window_->bounds().ToString());
316 EXPECT_EQ("0,350 200x100", window2_->bounds().ToString()); 327 EXPECT_EQ("0,350 200x100", window2_->bounds().ToString());
317 328
318 // Push off the screen, w2 should be resized to its min. 329 // Push off the screen, w2 should be resized to its min.
319 delegate2_.set_min_size(gfx::Size(20, 20)); 330 delegate2_.set_min_size(gfx::Size(20, 20));
320 resizer->Drag(CalculateDragPoint(*resizer, 50, 820)); 331 resizer->Drag(CalculateDragPoint(*resizer, 50, 820), 0);
321 EXPECT_EQ("0,50 400x530", window_->bounds().ToString()); 332 EXPECT_EQ("0,50 400x530", window_->bounds().ToString());
322 EXPECT_EQ("0,580 200x20", window2_->bounds().ToString()); 333 EXPECT_EQ("0,580 200x20", window2_->bounds().ToString());
323 334
324 // Move back to 100 and verify w2 gets its original size. 335 // Move back to 100 and verify w2 gets its original size.
325 resizer->Drag(CalculateDragPoint(*resizer, 10, 100)); 336 resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0);
326 EXPECT_EQ("0,50 400x300", window_->bounds().ToString()); 337 EXPECT_EQ("0,50 400x300", window_->bounds().ToString());
327 EXPECT_EQ("0,350 200x100", window2_->bounds().ToString()); 338 EXPECT_EQ("0,350 200x100", window2_->bounds().ToString());
328 339
329 // Revert and make sure everything moves back. 340 // Revert and make sure everything moves back.
330 resizer->Drag(CalculateDragPoint(*resizer, 800, 20)); 341 resizer->Drag(CalculateDragPoint(*resizer, 800, 20), 0);
331 resizer->RevertDrag(); 342 resizer->RevertDrag();
332 EXPECT_EQ("0,50 400x200", window_->bounds().ToString()); 343 EXPECT_EQ("0,50 400x200", window_->bounds().ToString());
333 EXPECT_EQ("0,250 200x100", window2_->bounds().ToString()); 344 EXPECT_EQ("0,250 200x100", window2_->bounds().ToString());
334 } 345 }
335 346
336 // Assertions around attached window resize dragging from the bottom with 3 347 // Assertions around attached window resize dragging from the bottom with 3
337 // windows. 348 // windows.
338 // TODO(oshima): Host window doesn't get a resize event after 349 // TODO(oshima): Host window doesn't get a resize event after
339 // SetHostSize on Windows trybot, which gives wrong work/monitor area. 350 // SetHostSize on Windows trybot, which gives wrong work/monitor area.
340 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_3) { 351 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_3) {
341 aura::RootWindow* root = Shell::GetInstance()->GetRootWindow(); 352 aura::RootWindow* root = Shell::GetInstance()->GetRootWindow();
342 root->SetHostSize(gfx::Size(600, 800)); 353 root->SetHostSize(gfx::Size(600, 800));
343 LOG(ERROR) << "=== Calling OnHostResized, 600x800"; 354 LOG(ERROR) << "=== Calling OnHostResized, 600x800";
344 355
345 Shell::GetInstance()->SetMonitorWorkAreaInsets(root, gfx::Insets()); 356 Shell::GetInstance()->SetMonitorWorkAreaInsets(root, gfx::Insets());
346 357
347 window_->SetBounds(gfx::Rect( 300, 100, 300, 200)); 358 window_->SetBounds(gfx::Rect( 300, 100, 300, 200));
348 window2_->SetBounds(gfx::Rect(300, 300, 200, 150)); 359 window2_->SetBounds(gfx::Rect(300, 300, 200, 150));
349 window3_->SetBounds(gfx::Rect(300, 450, 200, 100)); 360 window3_->SetBounds(gfx::Rect(300, 450, 200, 100));
350 delegate2_.set_min_size(gfx::Size(50, 52)); 361 delegate2_.set_min_size(gfx::Size(50, 52));
351 delegate3_.set_min_size(gfx::Size(50, 38)); 362 delegate3_.set_min_size(gfx::Size(50, 38));
352 363
353 std::vector<aura::Window*> windows; 364 std::vector<aura::Window*> windows;
354 windows.push_back(window2_.get()); 365 windows.push_back(window2_.get());
355 windows.push_back(window3_.get()); 366 windows.push_back(window3_.get());
367 SetGridSize(10);
356 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 368 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
357 window_.get(), gfx::Point(), HTBOTTOM, 10, windows)); 369 window_.get(), gfx::Point(), HTBOTTOM, windows));
358 ASSERT_TRUE(resizer.get()); 370 ASSERT_TRUE(resizer.get());
359 // Move it 100 to the right, which should expand w1 and push w2 and w3. 371 // Move it 100 to the right, which should expand w1 and push w2 and w3.
360 resizer->Drag(CalculateDragPoint(*resizer, -10, 100)); 372 resizer->Drag(CalculateDragPoint(*resizer, -10, 100), 0);
361 EXPECT_EQ("300,100 300x300", window_->bounds().ToString()); 373 EXPECT_EQ("300,100 300x300", window_->bounds().ToString());
362 EXPECT_EQ("300,400 200x150", window2_->bounds().ToString()); 374 EXPECT_EQ("300,400 200x150", window2_->bounds().ToString());
363 EXPECT_EQ("300,550 200x100", window3_->bounds().ToString()); 375 EXPECT_EQ("300,550 200x100", window3_->bounds().ToString());
364 376
365 // Move it 296, which should now snap to grid and things should compress. 377 // Move it 296, which should now snap to grid and things should compress.
366 resizer->Drag(CalculateDragPoint(*resizer, -10, 296)); 378 resizer->Drag(CalculateDragPoint(*resizer, -10, 296), 0);
367 EXPECT_EQ("300,100 300x500", window_->bounds().ToString()); 379 EXPECT_EQ("300,100 300x500", window_->bounds().ToString());
368 EXPECT_EQ("300,600 200x120", window2_->bounds().ToString()); 380 EXPECT_EQ("300,600 200x120", window2_->bounds().ToString());
369 EXPECT_EQ("300,720 200x80", window3_->bounds().ToString()); 381 EXPECT_EQ("300,720 200x80", window3_->bounds().ToString());
370 382
371 // Move it so much everything ends up at its min. 383 // Move it so much everything ends up at its min.
372 resizer->Drag(CalculateDragPoint(*resizer, 50, 798)); 384 resizer->Drag(CalculateDragPoint(*resizer, 50, 798), 0);
373 EXPECT_EQ("300,100 300x600", window_->bounds().ToString()); 385 EXPECT_EQ("300,100 300x600", window_->bounds().ToString());
374 EXPECT_EQ("300,700 200x60", window2_->bounds().ToString()); 386 EXPECT_EQ("300,700 200x60", window2_->bounds().ToString());
375 EXPECT_EQ("300,760 200x40", window3_->bounds().ToString()); 387 EXPECT_EQ("300,760 200x40", window3_->bounds().ToString());
376 388
377 // Revert and make sure everything moves back. 389 // Revert and make sure everything moves back.
378 resizer->RevertDrag(); 390 resizer->RevertDrag();
379 EXPECT_EQ("300,100 300x200", window_->bounds().ToString()); 391 EXPECT_EQ("300,100 300x200", window_->bounds().ToString());
380 EXPECT_EQ("300,300 200x150", window2_->bounds().ToString()); 392 EXPECT_EQ("300,300 200x150", window2_->bounds().ToString());
381 EXPECT_EQ("300,450 200x100", window3_->bounds().ToString()); 393 EXPECT_EQ("300,450 200x100", window3_->bounds().ToString());
382 } 394 }
383 395
384 // Assertions around attached window resizing (collapsing and expanding) with 396 // Assertions around attached window resizing (collapsing and expanding) with
385 // 3 windows. 397 // 3 windows.
386 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_3_Compress) { 398 TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_3_Compress) {
387 window_->SetBounds(gfx::Rect( 0, 0, 200, 200)); 399 window_->SetBounds(gfx::Rect( 0, 0, 200, 200));
388 window2_->SetBounds(gfx::Rect(10, 200, 200, 200)); 400 window2_->SetBounds(gfx::Rect(10, 200, 200, 200));
389 window3_->SetBounds(gfx::Rect(20, 400, 100, 100)); 401 window3_->SetBounds(gfx::Rect(20, 400, 100, 100));
390 delegate2_.set_min_size(gfx::Size(52, 50)); 402 delegate2_.set_min_size(gfx::Size(52, 50));
391 delegate3_.set_min_size(gfx::Size(38, 50)); 403 delegate3_.set_min_size(gfx::Size(38, 50));
392 404
393 std::vector<aura::Window*> windows; 405 std::vector<aura::Window*> windows;
394 windows.push_back(window2_.get()); 406 windows.push_back(window2_.get());
395 windows.push_back(window3_.get()); 407 windows.push_back(window3_.get());
408 SetGridSize(10);
396 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 409 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
397 window_.get(), gfx::Point(), HTBOTTOM, 10, windows)); 410 window_.get(), gfx::Point(), HTBOTTOM, windows));
398 ASSERT_TRUE(resizer.get()); 411 ASSERT_TRUE(resizer.get());
399 // Move it 100 up, which should collapse w1 and expand w2 and w3. 412 // Move it 100 up, which should collapse w1 and expand w2 and w3.
400 resizer->Drag(CalculateDragPoint(*resizer, -10, -100)); 413 resizer->Drag(CalculateDragPoint(*resizer, -10, -100), 0);
401 EXPECT_EQ("0,0 200x100", window_->bounds().ToString()); 414 EXPECT_EQ("0,0 200x100", window_->bounds().ToString());
402 EXPECT_EQ("10,100 200x270", window2_->bounds().ToString()); 415 EXPECT_EQ("10,100 200x270", window2_->bounds().ToString());
403 EXPECT_EQ("20,370 100x130", window3_->bounds().ToString()); 416 EXPECT_EQ("20,370 100x130", window3_->bounds().ToString());
404 417
405 // Move it 100 down. 418 // Move it 100 down.
406 resizer->Drag(CalculateDragPoint(*resizer, 10, 100)); 419 resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0);
407 EXPECT_EQ("0,0 200x300", window_->bounds().ToString()); 420 EXPECT_EQ("0,0 200x300", window_->bounds().ToString());
408 EXPECT_EQ("10,300 200x200", window2_->bounds().ToString()); 421 EXPECT_EQ("10,300 200x200", window2_->bounds().ToString());
409 EXPECT_EQ("20,500 100x100", window3_->bounds().ToString()); 422 EXPECT_EQ("20,500 100x100", window3_->bounds().ToString());
410 423
411 // 100 up again. 424 // 100 up again.
412 resizer->Drag(CalculateDragPoint(*resizer, -10, -100)); 425 resizer->Drag(CalculateDragPoint(*resizer, -10, -100), 0);
413 EXPECT_EQ("0,0 200x100", window_->bounds().ToString()); 426 EXPECT_EQ("0,0 200x100", window_->bounds().ToString());
414 EXPECT_EQ("10,100 200x270", window2_->bounds().ToString()); 427 EXPECT_EQ("10,100 200x270", window2_->bounds().ToString());
415 EXPECT_EQ("20,370 100x130", window3_->bounds().ToString()); 428 EXPECT_EQ("20,370 100x130", window3_->bounds().ToString());
416 } 429 }
417 430
418 // Assertions around dragging to the left/right edge of the screen. 431 // Assertions around dragging to the left/right edge of the screen.
419 TEST_F(WorkspaceWindowResizerTest, Edge) { 432 TEST_F(WorkspaceWindowResizerTest, Edge) {
420 int bottom = 433 int bottom =
421 ScreenAsh::GetUnmaximizedWorkAreaBounds(window_.get()).bottom(); 434 ScreenAsh::GetUnmaximizedWorkAreaBounds(window_.get()).bottom();
422 window_->SetBounds(gfx::Rect(20, 30, 50, 60)); 435 window_->SetBounds(gfx::Rect(20, 30, 50, 60));
423 { 436 {
437 SetGridSize(0);
424 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 438 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
425 window_.get(), gfx::Point(), HTCAPTION, 0, empty_windows())); 439 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
426 ASSERT_TRUE(resizer.get()); 440 ASSERT_TRUE(resizer.get());
427 resizer->Drag(CalculateDragPoint(*resizer, 0, 10)); 441 resizer->Drag(CalculateDragPoint(*resizer, 0, 10), 0);
428 resizer->CompleteDrag(); 442 resizer->CompleteDrag(0);
429 EXPECT_EQ("0,0 400x" + base::IntToString(bottom), 443 EXPECT_EQ("0,0 400x" + base::IntToString(bottom),
430 window_->bounds().ToString()); 444 window_->bounds().ToString());
431 ASSERT_TRUE(GetRestoreBounds(window_.get())); 445 ASSERT_TRUE(GetRestoreBounds(window_.get()));
432 EXPECT_EQ("20,30 50x60", GetRestoreBounds(window_.get())->ToString()); 446 EXPECT_EQ("20,30 50x60", GetRestoreBounds(window_.get())->ToString());
433 } 447 }
434 448
435 // Try the same with the right side. 449 // Try the same with the right side.
450 SetGridSize(0);
436 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 451 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
437 window_.get(), gfx::Point(), HTCAPTION, 0, empty_windows())); 452 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
438 ASSERT_TRUE(resizer.get()); 453 ASSERT_TRUE(resizer.get());
439 resizer->Drag(CalculateDragPoint(*resizer, 800, 10)); 454 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0);
440 resizer->CompleteDrag(); 455 resizer->CompleteDrag(0);
441 EXPECT_EQ("400,0 400x" + base::IntToString(bottom), 456 EXPECT_EQ("400,0 400x" + base::IntToString(bottom),
442 window_->bounds().ToString()); 457 window_->bounds().ToString());
443 ASSERT_TRUE(GetRestoreBounds(window_.get())); 458 ASSERT_TRUE(GetRestoreBounds(window_.get()));
444 EXPECT_EQ("20,30 50x60", GetRestoreBounds(window_.get())->ToString()); 459 EXPECT_EQ("20,30 50x60", GetRestoreBounds(window_.get())->ToString());
445 } 460 }
446 461
447 // Verifies windows are correctly restacked when reordering multiple windows. 462 // Verifies windows are correctly restacked when reordering multiple windows.
448 TEST_F(WorkspaceWindowResizerTest, RestackAttached) { 463 TEST_F(WorkspaceWindowResizerTest, RestackAttached) {
449 window_->SetBounds(gfx::Rect( 0, 0, 200, 300)); 464 window_->SetBounds(gfx::Rect( 0, 0, 200, 300));
450 window2_->SetBounds(gfx::Rect(200, 0, 100, 200)); 465 window2_->SetBounds(gfx::Rect(200, 0, 100, 200));
451 window3_->SetBounds(gfx::Rect(300, 0, 100, 100)); 466 window3_->SetBounds(gfx::Rect(300, 0, 100, 100));
452 467
453 { 468 {
454 std::vector<aura::Window*> windows; 469 std::vector<aura::Window*> windows;
455 windows.push_back(window2_.get()); 470 windows.push_back(window2_.get());
471 SetGridSize(10);
456 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 472 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
457 window_.get(), gfx::Point(), HTRIGHT, 10, windows)); 473 window_.get(), gfx::Point(), HTRIGHT, windows));
458 ASSERT_TRUE(resizer.get()); 474 ASSERT_TRUE(resizer.get());
459 // Move it 100 to the right, which should expand w1 and push w2 and w3. 475 // Move it 100 to the right, which should expand w1 and push w2 and w3.
460 resizer->Drag(CalculateDragPoint(*resizer, 100, -10)); 476 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
461 477
462 // 2 should be topmost since it's initially the highest in the stack. 478 // 2 should be topmost since it's initially the highest in the stack.
463 EXPECT_EQ("2 1 3", WindowOrderAsString()); 479 EXPECT_EQ("2 1 3", WindowOrderAsString());
464 } 480 }
465 481
466 { 482 {
467 std::vector<aura::Window*> windows; 483 std::vector<aura::Window*> windows;
468 windows.push_back(window3_.get()); 484 windows.push_back(window3_.get());
485 SetGridSize(10);
469 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 486 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
470 window2_.get(), gfx::Point(), HTRIGHT, 10, windows)); 487 window2_.get(), gfx::Point(), HTRIGHT, windows));
471 ASSERT_TRUE(resizer.get()); 488 ASSERT_TRUE(resizer.get());
472 // Move it 100 to the right, which should expand w1 and push w2 and w3. 489 // Move it 100 to the right, which should expand w1 and push w2 and w3.
473 resizer->Drag(CalculateDragPoint(*resizer, 100, -10)); 490 resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
474 491
475 // 2 should be topmost since it's initially the highest in the stack. 492 // 2 should be topmost since it's initially the highest in the stack.
476 EXPECT_EQ("2 3 1", WindowOrderAsString()); 493 EXPECT_EQ("2 3 1", WindowOrderAsString());
477 } 494 }
478 } 495 }
479 496
480 // Makes sure we don't allow dragging below the work area. 497 // Makes sure we don't allow dragging below the work area.
481 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottom) { 498 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottom) {
482 Shell::GetInstance()->SetMonitorWorkAreaInsets( 499 Shell::GetInstance()->SetMonitorWorkAreaInsets(
483 Shell::GetInstance()->GetRootWindow(), gfx::Insets(0, 0, 10, 0)); 500 Shell::GetInstance()->GetRootWindow(), gfx::Insets(0, 0, 10, 0));
484 501
485 window_->SetBounds(gfx::Rect(100, 200, 300, 400)); 502 window_->SetBounds(gfx::Rect(100, 200, 300, 400));
503 SetGridSize(0);
486 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 504 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
487 window_.get(), gfx::Point(), HTCAPTION, 0, empty_windows())); 505 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
488 ASSERT_TRUE(resizer.get()); 506 ASSERT_TRUE(resizer.get());
489 resizer->Drag(CalculateDragPoint(*resizer, 0, 600)); 507 resizer->Drag(CalculateDragPoint(*resizer, 0, 600), 0);
490 int expected_y = 508 int expected_y =
491 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10; 509 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10;
492 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400", 510 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400",
493 window_->bounds().ToString()); 511 window_->bounds().ToString());
494 } 512 }
495 513
496 // Makes sure we don't allow dragging off the top of the work area. 514 // Makes sure we don't allow dragging off the top of the work area.
497 TEST_F(WorkspaceWindowResizerTest, DontDragOffTop) { 515 TEST_F(WorkspaceWindowResizerTest, DontDragOffTop) {
498 Shell::GetInstance()->SetMonitorWorkAreaInsets( 516 Shell::GetInstance()->SetMonitorWorkAreaInsets(
499 Shell::GetInstance()->GetRootWindow(), gfx::Insets(10, 0, 0, 0)); 517 Shell::GetInstance()->GetRootWindow(), gfx::Insets(10, 0, 0, 0));
500 518
501 window_->SetBounds(gfx::Rect(100, 200, 300, 400)); 519 window_->SetBounds(gfx::Rect(100, 200, 300, 400));
520 SetGridSize(0);
502 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 521 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
503 window_.get(), gfx::Point(), HTCAPTION, 0, empty_windows())); 522 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
504 ASSERT_TRUE(resizer.get()); 523 ASSERT_TRUE(resizer.get());
505 resizer->Drag(CalculateDragPoint(*resizer, 0, -600)); 524 resizer->Drag(CalculateDragPoint(*resizer, 0, -600), 0);
506 EXPECT_EQ("100,10 300x400", window_->bounds().ToString()); 525 EXPECT_EQ("100,10 300x400", window_->bounds().ToString());
507 } 526 }
508 527
509 TEST_F(WorkspaceWindowResizerTest, ResizeBottomOutsideWorkArea) { 528 TEST_F(WorkspaceWindowResizerTest, ResizeBottomOutsideWorkArea) {
510 Shell::GetInstance()->SetMonitorWorkAreaInsets( 529 Shell::GetInstance()->SetMonitorWorkAreaInsets(
511 Shell::GetInstance()->GetRootWindow(), gfx::Insets(0, 0, 50, 0)); 530 Shell::GetInstance()->GetRootWindow(), gfx::Insets(0, 0, 50, 0));
512 531
513 window_->SetBounds(gfx::Rect(100, 200, 300, 380)); 532 window_->SetBounds(gfx::Rect(100, 200, 300, 380));
533 SetGridSize(10);
514 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 534 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
515 window_.get(), gfx::Point(), HTTOP, 10, empty_windows())); 535 window_.get(), gfx::Point(), HTTOP, empty_windows()));
516 ASSERT_TRUE(resizer.get()); 536 ASSERT_TRUE(resizer.get());
517 resizer->Drag(CalculateDragPoint(*resizer, 8, 0)); 537 resizer->Drag(CalculateDragPoint(*resizer, 8, 0), 0);
518 EXPECT_EQ("100,200 300x380", window_->bounds().ToString()); 538 EXPECT_EQ("100,200 300x380", window_->bounds().ToString());
519 } 539 }
520 540
521 // Verifies snapping to edges works. 541 // Verifies snapping to edges works.
522 TEST_F(WorkspaceWindowResizerTest, SnapToEdge) { 542 TEST_F(WorkspaceWindowResizerTest, SnapToEdge) {
523 Shell::GetInstance()->SetShelfAutoHideBehavior( 543 Shell::GetInstance()->SetShelfAutoHideBehavior(
524 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 544 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
525 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); 545 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
546 SetGridSize(16);
526 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 547 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
527 window_.get(), gfx::Point(), HTCAPTION, 16, empty_windows())); 548 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
528 ASSERT_TRUE(resizer.get()); 549 ASSERT_TRUE(resizer.get());
529 // Move to an x-coordinate of 15, which should not snap. 550 // Move to an x-coordinate of 15, which should not snap.
530 resizer->Drag(CalculateDragPoint(*resizer, -81, 0)); 551 resizer->Drag(CalculateDragPoint(*resizer, -81, 0), 0);
531 // An x-coordinate of 7 should snap. 552 // An x-coordinate of 7 should snap.
532 resizer->Drag(CalculateDragPoint(*resizer, -89, 0)); 553 resizer->Drag(CalculateDragPoint(*resizer, -89, 0), 0);
533 EXPECT_EQ("0,112 320x160", window_->bounds().ToString()); 554 EXPECT_EQ("0,112 320x160", window_->bounds().ToString());
534 // Move to -20, should still snap to 0. 555 // Move to -20, should still snap to 0.
535 resizer->Drag(CalculateDragPoint(*resizer, -116, 0)); 556 resizer->Drag(CalculateDragPoint(*resizer, -116, 0), 0);
536 EXPECT_EQ("0,112 320x160", window_->bounds().ToString()); 557 EXPECT_EQ("0,112 320x160", window_->bounds().ToString());
537 // At -32 should move past snap points. 558 // At -32 should move past snap points.
538 resizer->Drag(CalculateDragPoint(*resizer, -128, 0)); 559 resizer->Drag(CalculateDragPoint(*resizer, -128, 0), 0);
539 EXPECT_EQ("-32,112 320x160", window_->bounds().ToString()); 560 EXPECT_EQ("-32,112 320x160", window_->bounds().ToString());
540 resizer->Drag(CalculateDragPoint(*resizer, -129, 0)); 561 resizer->Drag(CalculateDragPoint(*resizer, -129, 0), 0);
541 EXPECT_EQ("-33,112 320x160", window_->bounds().ToString()); 562 EXPECT_EQ("-33,112 320x160", window_->bounds().ToString());
542 563
543 // Right side should similarly snap. 564 // Right side should similarly snap.
544 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 - 15, 0)); 565 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 - 15, 0), 0);
545 EXPECT_EQ("465,112 320x160", window_->bounds().ToString()); 566 EXPECT_EQ("465,112 320x160", window_->bounds().ToString());
546 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 - 7, 0)); 567 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 - 7, 0), 0);
547 EXPECT_EQ("480,112 320x160", window_->bounds().ToString()); 568 EXPECT_EQ("480,112 320x160", window_->bounds().ToString());
548 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 20, 0)); 569 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 20, 0), 0);
549 EXPECT_EQ("480,112 320x160", window_->bounds().ToString()); 570 EXPECT_EQ("480,112 320x160", window_->bounds().ToString());
550 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 32, 0)); 571 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 32, 0), 0);
551 EXPECT_EQ("512,112 320x160", window_->bounds().ToString()); 572 EXPECT_EQ("512,112 320x160", window_->bounds().ToString());
552 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 33, 0)); 573 resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 33, 0), 0);
553 EXPECT_EQ("513,112 320x160", window_->bounds().ToString()); 574 EXPECT_EQ("513,112 320x160", window_->bounds().ToString());
554 575
555 // And the bottom should snap too. 576 // And the bottom should snap too.
556 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 15)); 577 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 15), 0);
557 EXPECT_EQ("96,432 320x160", window_->bounds().ToString()); 578 EXPECT_EQ("96,432 320x160", window_->bounds().ToString());
558 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 + 20)); 579 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 + 20), 0);
559 EXPECT_EQ("96,432 320x160", window_->bounds().ToString()); 580 EXPECT_EQ("96,432 320x160", window_->bounds().ToString());
560 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 + 32)); 581 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 + 32), 0);
561 EXPECT_EQ("96,472 320x160", window_->bounds().ToString()); 582 EXPECT_EQ("96,472 320x160", window_->bounds().ToString());
562 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 + 33)); 583 resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 + 33), 0);
563 EXPECT_EQ("96,473 320x160", window_->bounds().ToString()); 584 EXPECT_EQ("96,473 320x160", window_->bounds().ToString());
564 585
565 // And the top should snap too. 586 // And the top should snap too.
566 resizer->Drag(CalculateDragPoint(*resizer, 0, -112 + 20)); 587 resizer->Drag(CalculateDragPoint(*resizer, 0, -112 + 20), 0);
567 EXPECT_EQ("96,20 320x160", window_->bounds().ToString()); 588 EXPECT_EQ("96,20 320x160", window_->bounds().ToString());
568 resizer->Drag(CalculateDragPoint(*resizer, 0, -112 + 7)); 589 resizer->Drag(CalculateDragPoint(*resizer, 0, -112 + 7), 0);
569 EXPECT_EQ("96,0 320x160", window_->bounds().ToString()); 590 EXPECT_EQ("96,0 320x160", window_->bounds().ToString());
570 // No need to test dragging < 0 as we force that to 0. 591 // No need to test dragging < 0 as we force that to 0.
571 } 592 }
572 593
573 // Verifies a window taller than work area height doesn't snap above the top of 594 // Verifies a window taller than work area height doesn't snap above the top of
574 // the work area. 595 // the work area.
575 TEST_F(WorkspaceWindowResizerTest, TallWindow) { 596 TEST_F(WorkspaceWindowResizerTest, TallWindow) {
576 aura::RootWindow* root = Shell::GetInstance()->GetRootWindow(); 597 aura::RootWindow* root = Shell::GetInstance()->GetRootWindow();
577 Shell::GetInstance()->SetMonitorWorkAreaInsets( 598 Shell::GetInstance()->SetMonitorWorkAreaInsets(
578 root, gfx::Insets(0, 0, 50, 0)); 599 root, gfx::Insets(0, 0, 50, 0));
579 window_->SetBounds(gfx::Rect(0, 0, 320, 560)); 600 window_->SetBounds(gfx::Rect(0, 0, 320, 560));
601 SetGridSize(16);
580 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 602 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
581 window_.get(), gfx::Point(), HTCAPTION, 16, empty_windows())); 603 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
582 resizer->Drag(CalculateDragPoint(*resizer, 0, 9)); 604 resizer->Drag(CalculateDragPoint(*resizer, 0, 9), 0);
583 EXPECT_EQ("0,9 320x560", window_->bounds().ToString()); 605 EXPECT_EQ("0,9 320x560", window_->bounds().ToString());
584 } 606 }
585 607
608 TEST_F(WorkspaceWindowResizerTest, DragResizeSnapToGrid) {
609 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
610 SetGridSize(16);
611 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
612 window_.get(), gfx::Point(), HTBOTTOMRIGHT, empty_windows()));
613 ASSERT_TRUE(resizer.get());
614 // Resize the right bottom to add 10 in width, 12 in height.
615 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0);
616 // Both bottom and right sides should snap to grids.
617 EXPECT_EQ("96,112 336x176", window_->bounds().ToString());
618 }
619
620 TEST_F(WorkspaceWindowResizerTest, CtrlDragResizeToExactPosition) {
621 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
622 SetGridSize(16);
623 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
624 window_.get(), gfx::Point(), HTBOTTOMRIGHT, empty_windows()));
625 ASSERT_TRUE(resizer.get());
626 // Resize the right bottom to add 10 in width, 12 in height.
627 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), ui::EF_CONTROL_DOWN);
628 // Both bottom and right sides to resize to exact size requested.
629 EXPECT_EQ("96,112 330x172", window_->bounds().ToString());
630 }
631
632 TEST_F(WorkspaceWindowResizerTest, CompleteDragMoveSnapToGrid) {
633 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
634 SetGridSize(16);
635 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
636 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
637 ASSERT_TRUE(resizer.get());
638 // Drag the window to new poistion by adding (10, 12) to original point,
639 // the window should snap to the closed grid.
640 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0);
641 resizer->CompleteDrag(0);
642 EXPECT_EQ("112,128 320x160", window_->bounds().ToString());
643 }
644
645 TEST_F(WorkspaceWindowResizerTest, CtrlCompleteDragMoveToExactPosition) {
646 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
647 SetGridSize(16);
648 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
649 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
650 ASSERT_TRUE(resizer.get());
651 // Ctrl + drag the window to new poistion by adding (10, 12) to its origin,
652 // the window should move to the exact position.
653 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0);
654 resizer->CompleteDrag(ui::EF_CONTROL_DOWN);
655 EXPECT_EQ("106,124 320x160", window_->bounds().ToString());
656 }
657
586 #endif 658 #endif
587 659
588 } // namespace 660 } // namespace
589 } // namespace test 661 } // namespace test
590 } // namespace ash 662 } // 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