OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "chrome/browser/extensions/extension_service.h" | 6 #include "chrome/browser/extensions/extension_service.h" |
7 #include "chrome/browser/prefs/pref_service.h" | 7 #include "chrome/browser/prefs/pref_service.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_list.h" | 10 #include "chrome/browser/ui/browser_list.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 gfx::Rect(0, 0, 500, 200)); | 147 gfx::Rect(0, 0, 500, 200)); |
148 signal3.Wait(); | 148 signal3.Wait(); |
149 signal4.Wait(); | 149 signal4.Wait(); |
150 ASSERT_EQ(2, panel_manager->num_panels()); | 150 ASSERT_EQ(2, panel_manager->num_panels()); |
151 EXPECT_LT(panel6->GetBounds().right(), panel1->GetBounds().x()); | 151 EXPECT_LT(panel6->GetBounds().right(), panel1->GetBounds().x()); |
152 | 152 |
153 panel1->Close(); | 153 panel1->Close(); |
154 panel6->Close(); | 154 panel6->Close(); |
155 } | 155 } |
156 | 156 |
157 struct DragTestData { | 157 void SetWorkArea(const gfx::Rect& work_area) { |
158 DragTestData(int drag_delta_x, | 158 PanelManager::GetInstance()->SetWorkArea(gfx::Rect(0, 0, 800, 600)); |
159 int drag_delta_y, | 159 } |
160 bool is_big_delta, | |
161 bool should_cancel_drag) | |
162 : drag_delta_x(drag_delta_x), drag_delta_y(drag_delta_y), | |
163 is_big_delta(is_big_delta), should_cancel_drag(should_cancel_drag) {} | |
164 int drag_delta_x; | |
165 int drag_delta_y; | |
166 bool is_big_delta; // Drag big enough to cause shuffling. | |
167 bool should_cancel_drag; | |
168 }; | |
169 | 160 |
170 void TestDragging(std::vector<Panel*>* panels, | 161 int horizontal_spacing() { |
171 const DragTestData& drag_test_data) { | 162 return PanelManager::horizontal_spacing(); |
172 size_t num_panels = panels->size(); | 163 } |
173 | 164 |
174 // Test dragging each panel in the list. | 165 void CloseAllPanels() { |
175 for (size_t drag_index = 0; drag_index < num_panels; ++drag_index) { | 166 std::vector<Panel*> panels = PanelManager::GetInstance()->panels_; |
jennb
2011/08/23 21:26:48
Add a TODO here for dimich. When he makes Close()
jennb
2011/08/23 21:26:48
Can you use the Panels (typedef inside PanelManage
prasadt
2011/08/23 21:39:29
Does it matter? And worse we'd be be relying on t
prasadt
2011/08/23 21:39:29
I'd rather just use the vector so we have it right
| |
176 std::vector<int> expected_delta_x_after_drag(num_panels, 0); | 167 for (size_t i = 0; i < panels.size(); ++i) |
177 std::vector<int> expected_delta_x_after_finish(num_panels, 0); | 168 panels[i]->Close(); |
169 } | |
178 | 170 |
179 for (size_t j = 0; j < num_panels; ++j) { | 171 std::vector<gfx::Rect> GetAllPanelsBounds() { |
180 expected_delta_x_after_drag.push_back(0); | 172 std::vector<gfx::Rect> panels_bounds; |
181 expected_delta_x_after_finish.push_back(0); | 173 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels_; |
182 } | 174 for (size_t i = 0; i < panels.size(); ++i) |
175 panels_bounds.push_back(panels[i]->GetRestoredBounds()); | |
176 return panels_bounds; | |
177 } | |
183 | 178 |
184 expected_delta_x_after_drag[drag_index] = drag_test_data.drag_delta_x; | 179 // Helper function for debugging. |
185 size_t swap_index = drag_index; | 180 void PrintPanelBounds() { |
186 if (drag_test_data.is_big_delta) { | 181 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels_; |
187 if (drag_test_data.drag_delta_x > 0 && drag_index != 0) { | 182 DLOG(WARNING) << "PanelBounds:"; |
188 // Dragged to right. | 183 for (size_t i = 0; i < panels.size(); ++i) { |
189 swap_index = drag_index - 1; | 184 DLOG(WARNING) << "#=" << i |
190 } else if (drag_test_data.drag_delta_x < 0 && | 185 << ", ptr=" << panels[i] |
191 drag_index != num_panels - 1) { | 186 << ", x=" << panels[i]->GetRestoredBounds().x() |
192 // Dragged to left. | 187 << ", y=" << panels[i]->GetRestoredBounds().y() |
193 swap_index = drag_index + 1; | 188 << ", width=" << panels[i]->GetRestoredBounds().width() |
194 } | 189 << ", height" << panels[i]->GetRestoredBounds().height(); |
195 } | |
196 if (swap_index != drag_index) { | |
197 expected_delta_x_after_drag[swap_index] = | |
198 (*panels)[drag_index]->GetRestoredBounds().x() - | |
199 (*panels)[swap_index]->GetRestoredBounds().x(); | |
200 expected_delta_x_after_finish[swap_index] = | |
201 expected_delta_x_after_drag[swap_index]; | |
202 expected_delta_x_after_finish[drag_index] = | |
203 -expected_delta_x_after_drag[swap_index]; | |
204 } | |
205 ValidateDragging(*panels, drag_index, drag_test_data.drag_delta_x, | |
206 drag_test_data.drag_delta_y, expected_delta_x_after_drag, | |
207 expected_delta_x_after_finish, drag_test_data.should_cancel_drag); | |
208 | |
209 if (swap_index != drag_index && !drag_test_data.should_cancel_drag) { | |
210 // Swap the panels in the vector so they reflect their true relative | |
211 // positions. | |
212 Panel* tmp_panel = (*panels)[swap_index]; | |
213 (*panels)[swap_index] = (*panels)[drag_index]; | |
214 (*panels)[drag_index] = tmp_panel; | |
215 } | |
216 } | 190 } |
217 } | 191 } |
218 | 192 |
219 void ValidateDragging(const std::vector<Panel*>& panels, | 193 // This is a bit mask - a set of flags that controls the specific drag actions |
220 int index_to_drag, | 194 // to be carried out by TestDragging function. |
221 int delta_x, | 195 enum DragAction { |
222 int delta_y, | 196 DRAG_ACTION_BEGIN = 1, |
223 const std::vector<int>& expected_delta_x_after_drag, | 197 DRAG_ACTION_FINISH = 2, |
224 const std::vector<int>& expected_delta_x_after_finish, | 198 DRAG_ACTION_CANCEL = 4 |
225 bool should_cancel_drag) { | 199 }; |
226 // Keep track of the initial bounds for comparison. | |
227 std::vector<gfx::Rect> initial_bounds(panels.size()); | |
228 for (size_t i = 0; i < panels.size(); ++i) | |
229 initial_bounds[i] = panels[i]->GetRestoredBounds(); | |
230 | 200 |
231 // Trigger the mouse-pressed event. | 201 void TestDragging(int delta_x, |
232 // All panels should remain in their original positions. | 202 int delta_y, |
233 NativePanel* panel_to_drag = panels[index_to_drag]->native_panel(); | 203 size_t drag_index, |
204 std::vector<int>expected_delta_x_after_drag, | |
205 std::vector<int>expected_delta_x_after_finish, | |
206 std::vector<gfx::Rect> initial_bounds, | |
207 int drag_action) { | |
208 std::vector<Panel*> panels = PanelManager::GetInstance()->panels_; | |
209 | |
210 // These are bounds at the beginning of this test. This would be different | |
211 // from initial_bounds in the case where we're testing for the case of | |
212 // multiple drags before finishing the drag. Here is an example: | |
213 // | |
214 // Test 1 - Create three panels and drag a panel to the right but don't | |
215 // finish or cancel the drag. initial_bounds == test_begin_bounds | |
216 // Test 2 - Do another drag on the same panel. There is no button press | |
217 // in this case as its the same drag that's continuing, this is | |
218 // simulating multiple drag events before button release. | |
219 // initial_bounds is still the same as in Test1. So in this case | |
220 // initial_bounds != test_begin_bounds. | |
221 std::vector<gfx::Rect> test_begin_bounds = GetAllPanelsBounds(); | |
222 | |
223 NativePanel* panel_to_drag = panels[drag_index]->native_panel(); | |
234 scoped_ptr<NativePanelTesting> panel_testing_to_drag( | 224 scoped_ptr<NativePanelTesting> panel_testing_to_drag( |
235 NativePanelTesting::Create(panel_to_drag)); | 225 NativePanelTesting::Create(panel_to_drag)); |
236 | 226 |
237 gfx::Point button_press_point(initial_bounds[index_to_drag].x(), | 227 if (drag_action & DRAG_ACTION_BEGIN) { |
238 initial_bounds[index_to_drag].y()); | 228 // Trigger the mouse-pressed event. |
239 panel_testing_to_drag->PressLeftMouseButtonTitlebar(button_press_point); | 229 // All panels should remain in their original positions. |
240 for (size_t i = 0; i < panels.size(); ++i) | 230 gfx::Point button_press_point( |
241 EXPECT_EQ(initial_bounds[i], panels[i]->GetRestoredBounds()); | 231 panels[drag_index]->GetRestoredBounds().x(), |
232 panels[drag_index]->GetRestoredBounds().y()); | |
233 panel_testing_to_drag->PressLeftMouseButtonTitlebar(button_press_point); | |
234 for (size_t i = 0; i < panels.size(); ++i) | |
235 EXPECT_EQ(test_begin_bounds[i], panels[i]->GetRestoredBounds()); | |
236 } | |
242 | 237 |
243 // Trigger the drag. | 238 // Trigger the drag. |
239 // Compare against expected bounds. | |
244 panel_testing_to_drag->DragTitlebar(delta_x, delta_y); | 240 panel_testing_to_drag->DragTitlebar(delta_x, delta_y); |
245 | |
246 for (size_t i = 0; i < panels.size(); ++i) { | 241 for (size_t i = 0; i < panels.size(); ++i) { |
247 gfx::Rect expected_bounds = initial_bounds[i]; | 242 gfx::Rect expected_bounds = test_begin_bounds[i]; |
248 expected_bounds.Offset(expected_delta_x_after_drag[i], 0); | 243 expected_bounds.Offset(expected_delta_x_after_drag[i], 0); |
249 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds()); | 244 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds()); |
250 } | 245 } |
251 | 246 |
252 // Cancel drag if asked. | 247 if (drag_action & DRAG_ACTION_CANCEL) { |
253 // All panels should stay in their original positions. | 248 // Cancel the drag. |
254 if (should_cancel_drag) { | 249 // All panels should return to their initial positions. |
255 panel_testing_to_drag->CancelDragTitlebar(); | 250 panel_testing_to_drag->CancelDragTitlebar(); |
251 std::vector<gfx::Rect> current_bounds = GetAllPanelsBounds(); | |
256 for (size_t i = 0; i < panels.size(); ++i) | 252 for (size_t i = 0; i < panels.size(); ++i) |
257 EXPECT_EQ(initial_bounds[i], panels[i]->GetRestoredBounds()); | 253 EXPECT_EQ(initial_bounds[i], current_bounds[i]); |
258 return; | 254 } else if (drag_action & DRAG_ACTION_FINISH) { |
259 } | 255 // Finish the drag. |
260 | 256 // Compare against expected bounds. |
261 // Otherwise finish the drag. | 257 panel_testing_to_drag->FinishDragTitlebar(); |
262 panel_testing_to_drag->FinishDragTitlebar(); | 258 for (size_t i = 0; i < panels.size(); ++i) { |
263 for (size_t i = 0; i < panels.size(); ++i) { | 259 gfx::Rect expected_bounds = test_begin_bounds[i]; |
264 gfx::Rect expected_bounds = initial_bounds[i]; | 260 expected_bounds.Offset(expected_delta_x_after_finish[i], 0); |
265 expected_bounds.Offset(expected_delta_x_after_finish[i], 0); | 261 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds()); |
266 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds()); | 262 } |
267 } | 263 } |
268 } | 264 } |
269 }; | 265 }; |
270 | 266 |
271 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { | 267 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { |
272 PanelManager* panel_manager = PanelManager::GetInstance(); | 268 PanelManager* panel_manager = PanelManager::GetInstance(); |
273 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. | 269 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. |
274 | 270 |
275 Panel* panel = CreatePanel("PanelTest", gfx::Rect()); | 271 Panel* panel = CreatePanel("PanelTest", gfx::Rect()); |
276 EXPECT_EQ(1, panel_manager->num_panels()); | 272 EXPECT_EQ(1, panel_manager->num_panels()); |
(...skipping 27 matching lines...) Expand all Loading... | |
304 TestCreatePanelOnOverflow(); | 300 TestCreatePanelOnOverflow(); |
305 } | 301 } |
306 | 302 |
307 #if defined(TOOLKIT_GTK) || defined(OS_WIN) | 303 #if defined(TOOLKIT_GTK) || defined(OS_WIN) |
308 #define MAYBE_DragPanels DragPanels | 304 #define MAYBE_DragPanels DragPanels |
309 #else | 305 #else |
310 #define MAYBE_DragPanels DISABLED_DragPanels | 306 #define MAYBE_DragPanels DISABLED_DragPanels |
311 #endif | 307 #endif |
312 | 308 |
313 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_DragPanels) { | 309 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_DragPanels) { |
314 std::vector<Panel*> panels; | 310 // Set work area to make the test consistent on different monitor sizes. |
315 panels.push_back(CreatePanel("PanelTest0", gfx::Rect())); | 311 SetWorkArea(gfx::Rect(0, 0, 800, 600)); |
316 | 312 |
317 int small_delta = 5; | 313 static const int max_panels = 3; |
318 int big_delta = panels[0]->GetRestoredBounds().width() * 0.5 + 5; | 314 int small_delta = 10; |
319 | 315 int big_delta = 70; |
320 // Setup test data. | 316 int bigger_delta = 120; |
321 // Template - DragTestData(delta_x, delta_y, is_big_delta, should_cancel_drag) | 317 int biggest_delta = 200; |
322 std::vector<DragTestData> drag_test_data; | 318 std::vector<int> zero_delta(max_panels, 0); |
323 drag_test_data.push_back(DragTestData( | 319 std::vector<int> expected_delta_x_after_drag(max_panels, 0); |
324 small_delta, small_delta, false, false)); | 320 std::vector<int> expected_delta_x_after_finish(max_panels, 0); |
325 drag_test_data.push_back(DragTestData( | 321 std::vector<gfx::Rect> current_bounds; |
326 -small_delta, -small_delta, false, false)); | 322 std::vector<gfx::Rect> initial_bounds; |
327 drag_test_data.push_back(DragTestData(big_delta, big_delta, true, false)); | 323 |
328 drag_test_data.push_back(DragTestData(big_delta, small_delta, true, false)); | 324 // Tests with a single panel. |
329 drag_test_data.push_back(DragTestData(-big_delta, -big_delta, true, false)); | 325 { |
330 drag_test_data.push_back(DragTestData(-big_delta, 0, true, false)); | 326 CreatePanel("PanelTest1", gfx::Rect(0, 0, 100, 100)); |
331 drag_test_data.push_back(DragTestData(big_delta, big_delta, true, true)); | 327 |
332 drag_test_data.push_back(DragTestData(-big_delta, -big_delta, true, true)); | 328 // Drag left. |
333 | 329 expected_delta_x_after_drag[0] = -big_delta; |
334 for (int num_panels = 1; num_panels <= 3; ++num_panels) { | 330 expected_delta_x_after_finish = zero_delta; |
335 if (num_panels > 1) | 331 TestDragging(-big_delta, 0, 0, expected_delta_x_after_drag, |
336 panels.push_back(CreatePanel("PanelTest", gfx::Rect())); | 332 zero_delta, GetAllPanelsBounds(), |
337 for (size_t j = 0; j < drag_test_data.size(); ++j) { | 333 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH); |
338 // Test for each combination of drag test data and number of panels. | 334 |
339 TestDragging(&panels, drag_test_data[j]); | 335 // Drag left and cancel. |
336 expected_delta_x_after_drag[0] = -big_delta; | |
337 expected_delta_x_after_finish = zero_delta; | |
338 TestDragging(-big_delta, 0, 0, expected_delta_x_after_drag, | |
339 zero_delta, GetAllPanelsBounds(), | |
340 DRAG_ACTION_BEGIN | DRAG_ACTION_CANCEL); | |
341 | |
342 // Drag right. | |
343 expected_delta_x_after_drag[0] = big_delta; | |
344 TestDragging(big_delta, 0, 0, expected_delta_x_after_drag, | |
345 zero_delta, GetAllPanelsBounds(), | |
346 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH); | |
347 | |
348 // Drag right and up. Expect no vertical movement. | |
349 TestDragging(big_delta, big_delta, 0, expected_delta_x_after_drag, | |
350 zero_delta, GetAllPanelsBounds(), | |
351 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH); | |
352 | |
353 // Drag up. Expect no movement on drag. | |
354 TestDragging(0, -big_delta, 0, zero_delta, zero_delta, | |
355 GetAllPanelsBounds(), DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH); | |
356 | |
357 // Drag down. Expect no movement on drag. | |
358 TestDragging(0, big_delta, 0, zero_delta, zero_delta, | |
359 GetAllPanelsBounds(), DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH); | |
360 } | |
361 | |
362 // Tests with two panels. | |
363 { | |
364 CreatePanel("PanelTest2", gfx::Rect(0, 0, 120, 120)); | |
365 | |
366 // Drag left, small delta, expect no shuffle. | |
367 expected_delta_x_after_drag = zero_delta; | |
368 expected_delta_x_after_drag[0] = -small_delta; | |
369 TestDragging(-small_delta, 1, 0, expected_delta_x_after_drag, zero_delta, | |
370 GetAllPanelsBounds(), DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH); | |
371 | |
372 // Drag right panel i.e index 0, towards left, big delta, expect shuffle. | |
373 initial_bounds = GetAllPanelsBounds(); | |
374 expected_delta_x_after_drag = zero_delta; | |
375 | |
376 // Deltas for panel being dragged. | |
377 expected_delta_x_after_drag[0] = -big_delta; | |
378 expected_delta_x_after_finish[0] = | |
379 -(initial_bounds[1].width() + horizontal_spacing()); | |
380 | |
381 // Deltas for panel being shuffled. | |
382 expected_delta_x_after_drag[1] = | |
383 initial_bounds[0].width() + horizontal_spacing(); | |
384 expected_delta_x_after_finish[1] = expected_delta_x_after_drag[1]; | |
385 | |
386 TestDragging(-big_delta, 0, 0, expected_delta_x_after_drag, | |
387 expected_delta_x_after_finish, initial_bounds, | |
388 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH); | |
389 | |
390 // Drag left panel i.e index 1, towards right, big delta, expect shuffle. | |
391 initial_bounds = GetAllPanelsBounds(); | |
392 expected_delta_x_after_drag = zero_delta; | |
393 expected_delta_x_after_finish = zero_delta; | |
394 | |
395 // Deltas for panel being dragged. | |
396 expected_delta_x_after_drag[1] = big_delta; | |
397 expected_delta_x_after_finish[1] = | |
398 initial_bounds[0].width() + horizontal_spacing(); | |
399 | |
400 // Deltas for panel being shuffled. | |
401 expected_delta_x_after_drag[0] = | |
402 -(initial_bounds[1].width() + horizontal_spacing()); | |
403 expected_delta_x_after_finish[0] = expected_delta_x_after_drag[0]; | |
404 | |
405 TestDragging(big_delta, 0, 1, expected_delta_x_after_drag, | |
406 expected_delta_x_after_finish, initial_bounds, | |
407 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH); | |
408 | |
409 // Drag left panel i.e index 1, towards right, big delta, expect shuffle. | |
410 // Cancel drag. | |
411 initial_bounds = GetAllPanelsBounds(); | |
412 expected_delta_x_after_drag = zero_delta; | |
413 | |
414 // Delta for panel being dragged. | |
415 expected_delta_x_after_drag[1] = big_delta; | |
416 | |
417 // Delta for panel being shuffled. | |
418 expected_delta_x_after_drag[0] = | |
419 -(initial_bounds[1].width() + horizontal_spacing()); | |
420 | |
421 // As the drag is being canceled, we don't need expected_delta_x_after | |
422 // finish. Instead initial_bounds will be used. | |
423 TestDragging(big_delta, 0, 1, expected_delta_x_after_drag, | |
424 zero_delta, initial_bounds, | |
425 DRAG_ACTION_BEGIN | DRAG_ACTION_CANCEL); | |
426 } | |
427 | |
428 // Tests with three panels. | |
429 { | |
430 CreatePanel("PanelTest3", gfx::Rect(0, 0, 110, 110)); | |
431 | |
432 // Drag left most panel to become right most with two shuffles. | |
433 // We test both shuffles. | |
434 { | |
435 // First drag and shuffle. | |
436 initial_bounds = GetAllPanelsBounds(); | |
437 expected_delta_x_after_drag = zero_delta; | |
438 | |
439 // Delta for panel being dragged. | |
440 expected_delta_x_after_drag[2] = big_delta; | |
441 | |
442 // Delta for panel being shuffled. | |
443 expected_delta_x_after_drag[1] = | |
444 -(initial_bounds[2].width() + horizontal_spacing()); | |
445 | |
446 // There is no delta after finish as drag is done yet. | |
447 TestDragging(big_delta, 0, 2, expected_delta_x_after_drag, | |
448 zero_delta, initial_bounds, DRAG_ACTION_BEGIN); | |
449 | |
450 // Second drag and shuffle. We finish the drag here. The drag index | |
451 // changes from 2 to 1 because of the first shuffle above. | |
452 current_bounds = GetAllPanelsBounds(); | |
453 expected_delta_x_after_drag = zero_delta; | |
454 expected_delta_x_after_finish = zero_delta; | |
455 | |
456 // big_delta is not enough to cause the second shuffle as the panel being | |
457 // dragged is in the middle of a drag and big_delta won't go far enough. | |
458 // So we use bigger_delta. | |
459 | |
460 // Deltas for panel being dragged. | |
461 expected_delta_x_after_drag[1] = bigger_delta; | |
462 int x_after_finish = current_bounds[0].x() + | |
463 (current_bounds[0].width() - current_bounds[1].width()); | |
464 expected_delta_x_after_finish[1] = x_after_finish - current_bounds[1].x(); | |
465 | |
466 // Deltas for panel being shuffled. | |
467 expected_delta_x_after_drag[0] = | |
468 -(current_bounds[1].width() + horizontal_spacing()); | |
469 expected_delta_x_after_finish[0] = expected_delta_x_after_drag[0]; | |
470 | |
471 TestDragging(bigger_delta, 0, 1, expected_delta_x_after_drag, | |
472 expected_delta_x_after_finish, initial_bounds, | |
473 DRAG_ACTION_FINISH); | |
340 } | 474 } |
475 | |
476 // Drag right most panel to become left most with two shuffles. | |
477 // And then cancel the drag. | |
478 { | |
479 // First drag and shuffle. | |
480 initial_bounds = GetAllPanelsBounds(); | |
481 expected_delta_x_after_drag = zero_delta; | |
482 | |
483 // Delta for panel being dragged. | |
484 expected_delta_x_after_drag[0] = -big_delta; | |
485 | |
486 // Delta for panel being shuffled. | |
487 expected_delta_x_after_drag[1] = | |
488 (initial_bounds[0].width() + horizontal_spacing()); | |
489 | |
490 // There is no delta after finish as drag is done yet. | |
491 TestDragging(-big_delta, 0, 0, expected_delta_x_after_drag, | |
492 zero_delta, initial_bounds, DRAG_ACTION_BEGIN); | |
493 | |
494 // Second drag and shuffle. We cancel the drag here. The drag index | |
495 // changes from 0 to 1 because of the first shuffle above. | |
496 current_bounds = GetAllPanelsBounds(); | |
497 expected_delta_x_after_drag = zero_delta; | |
498 | |
499 // Delta for panel being dragged. | |
500 expected_delta_x_after_drag[1] = -bigger_delta; | |
501 | |
502 // Deltas for panel being shuffled. | |
503 int x_after_shuffle = current_bounds[0].x() - horizontal_spacing() | |
504 - current_bounds[2].width(); | |
505 expected_delta_x_after_drag[2] = x_after_shuffle - current_bounds[2].x(); | |
506 | |
507 // There is no delta after finish as drag canceled. | |
508 TestDragging(-bigger_delta, 0, 1, expected_delta_x_after_drag, | |
509 zero_delta, initial_bounds, DRAG_ACTION_CANCEL); | |
510 } | |
511 | |
512 // Drag left most panel to become the right most in a single drag. This | |
513 // will shuffle middle panel to left most and right most to middle. | |
514 initial_bounds = GetAllPanelsBounds(); | |
515 expected_delta_x_after_drag = zero_delta; | |
516 expected_delta_x_after_finish = zero_delta; | |
517 | |
518 // Use a delta big enough to go across two panels. | |
519 // Deltas for panel being dragged. | |
520 expected_delta_x_after_drag[2] = biggest_delta; | |
521 expected_delta_x_after_finish[2] = | |
522 initial_bounds[1].width() + horizontal_spacing() + | |
523 initial_bounds[0].width() + horizontal_spacing(); | |
524 | |
525 // Deltas for middle panels being shuffled. | |
526 expected_delta_x_after_drag[1] = | |
527 -(initial_bounds[2].width() + horizontal_spacing()); | |
528 expected_delta_x_after_finish[1] = expected_delta_x_after_drag[1]; | |
529 | |
530 expected_delta_x_after_drag[0] = expected_delta_x_after_drag[1]; | |
531 expected_delta_x_after_finish[0] = expected_delta_x_after_drag[0]; | |
532 | |
533 TestDragging(biggest_delta, 0, 2, expected_delta_x_after_drag, | |
534 expected_delta_x_after_finish, initial_bounds, | |
535 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH); | |
536 | |
537 // Drag right most panel to become the left most in a single drag. This | |
538 // will shuffle middle panel to right most and left most to middle. | |
539 initial_bounds = GetAllPanelsBounds(); | |
540 expected_delta_x_after_drag = zero_delta; | |
541 expected_delta_x_after_finish = zero_delta; | |
542 | |
543 // Deltas for panel being dragged. | |
544 expected_delta_x_after_drag[0] = -biggest_delta; | |
545 expected_delta_x_after_finish[0] = | |
546 -(initial_bounds[1].width() + horizontal_spacing() + | |
547 initial_bounds[2].width() + horizontal_spacing()); | |
548 | |
549 // Deltas for panels being shuffled. | |
550 expected_delta_x_after_drag[1] = | |
551 initial_bounds[0].width() + horizontal_spacing(); | |
552 expected_delta_x_after_finish[1] = expected_delta_x_after_drag[1]; | |
553 | |
554 expected_delta_x_after_drag[2] = expected_delta_x_after_drag[1]; | |
555 expected_delta_x_after_finish[2] = expected_delta_x_after_drag[2]; | |
556 | |
557 TestDragging(-biggest_delta, 0, 0, expected_delta_x_after_drag, | |
558 expected_delta_x_after_finish, initial_bounds, | |
559 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH); | |
560 | |
561 // Drag right most panel to become the left most in a single drag. Then | |
562 // cancel the drag. | |
563 initial_bounds = GetAllPanelsBounds(); | |
564 expected_delta_x_after_drag = zero_delta; | |
565 | |
566 // Deltas for panel being dragged. | |
567 expected_delta_x_after_drag[0] = -biggest_delta; | |
568 | |
569 // Deltas for panels being shuffled. | |
570 expected_delta_x_after_drag[1] = | |
571 initial_bounds[0].width() + horizontal_spacing(); | |
572 expected_delta_x_after_drag[2] = expected_delta_x_after_drag[1]; | |
573 | |
574 // No delta after finish as drag is canceled. | |
575 TestDragging(-biggest_delta, 0, 0, expected_delta_x_after_drag, | |
576 zero_delta, initial_bounds, | |
577 DRAG_ACTION_BEGIN | DRAG_ACTION_CANCEL); | |
341 } | 578 } |
342 | 579 |
343 for (size_t i = 0; i < panels.size(); ++i) | 580 // Close panels. |
344 panels[i]->Close(); | 581 CloseAllPanels(); |
345 } | 582 } |
346 | 583 |
347 class PanelDownloadTest : public PanelBrowserTest { | 584 class PanelDownloadTest : public PanelBrowserTest { |
348 public: | 585 public: |
349 PanelDownloadTest() : PanelBrowserTest() { } | 586 PanelDownloadTest() : PanelBrowserTest() { } |
350 | 587 |
351 // Creates a temporary directory for downloads that is auto-deleted | 588 // Creates a temporary directory for downloads that is auto-deleted |
352 // on destruction. | 589 // on destruction. |
353 bool CreateDownloadDirectory(Profile* profile) { | 590 bool CreateDownloadDirectory(Profile* profile) { |
354 bool created = downloads_directory_.CreateUniqueTempDir(); | 591 bool created = downloads_directory_.CreateUniqueTempDir(); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
501 EXPECT_EQ(1, tabbed_browser->tab_count()); | 738 EXPECT_EQ(1, tabbed_browser->tab_count()); |
502 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); | 739 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); |
503 tabbed_browser->CloseWindow(); | 740 tabbed_browser->CloseWindow(); |
504 #endif | 741 #endif |
505 | 742 |
506 EXPECT_EQ(1, panel_browser->tab_count()); | 743 EXPECT_EQ(1, panel_browser->tab_count()); |
507 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); | 744 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); |
508 | 745 |
509 panel_browser->CloseWindow(); | 746 panel_browser->CloseWindow(); |
510 } | 747 } |
OLD | NEW |