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

Side by Side Diff: chrome/browser/ui/panels/panel_browsertest.cc

Issue 7706027: Addition testing for panels drag and drop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For testing on windows Created 9 years, 4 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
OLDNEW
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 "base/mac/scoped_nsautorelease_pool.h" 6 #include "base/mac/scoped_nsautorelease_pool.h"
7 #include "chrome/browser/extensions/extension_service.h" 7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/prefs/pref_service.h" 8 #include "chrome/browser/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 web_app::GenerateApplicationNameFromExtensionId(extension1->id()), 126 web_app::GenerateApplicationNameFromExtensionId(extension1->id()),
127 gfx::Rect(0, 0, 250, 200)); 127 gfx::Rect(0, 0, 250, 200));
128 Panel* panel2 = CreatePanel( 128 Panel* panel2 = CreatePanel(
129 web_app::GenerateApplicationNameFromExtensionId(extension2->id()), 129 web_app::GenerateApplicationNameFromExtensionId(extension2->id()),
130 gfx::Rect(0, 0, 300, 200)); 130 gfx::Rect(0, 0, 300, 200));
131 Panel* panel3 = CreatePanel( 131 Panel* panel3 = CreatePanel(
132 web_app::GenerateApplicationNameFromExtensionId(extension1->id()), 132 web_app::GenerateApplicationNameFromExtensionId(extension1->id()),
133 gfx::Rect(0, 0, 200, 200)); 133 gfx::Rect(0, 0, 200, 200));
134 ASSERT_EQ(3, panel_manager->num_panels()); 134 ASSERT_EQ(3, panel_manager->num_panels());
135 135
136 // Test closing the left-most panel that is from same extension. 136 // Test closing the leftmost panel that is from same extension.
137 ui_test_utils::WindowedNotificationObserver signal( 137 ui_test_utils::WindowedNotificationObserver signal(
138 chrome::NOTIFICATION_BROWSER_CLOSED, 138 chrome::NOTIFICATION_BROWSER_CLOSED,
139 Source<Browser>(panel2->browser())); 139 Source<Browser>(panel2->browser()));
140 Panel* panel4 = CreatePanel( 140 Panel* panel4 = CreatePanel(
141 web_app::GenerateApplicationNameFromExtensionId(extension2->id()), 141 web_app::GenerateApplicationNameFromExtensionId(extension2->id()),
142 gfx::Rect(0, 0, 280, 200)); 142 gfx::Rect(0, 0, 280, 200));
143 signal.Wait(); 143 signal.Wait();
144 ASSERT_EQ(3, panel_manager->num_panels()); 144 ASSERT_EQ(3, panel_manager->num_panels());
145 EXPECT_LT(panel4->GetBounds().right(), panel3->GetBounds().x()); 145 EXPECT_LT(panel4->GetBounds().right(), panel3->GetBounds().x());
146 EXPECT_LT(panel3->GetBounds().right(), panel1->GetBounds().x()); 146 EXPECT_LT(panel3->GetBounds().right(), panel1->GetBounds().x());
147 147
148 // Test closing the left-most panel. 148 // Test closing the leftmost panel.
149 ui_test_utils::WindowedNotificationObserver signal2( 149 ui_test_utils::WindowedNotificationObserver signal2(
150 chrome::NOTIFICATION_BROWSER_CLOSED, 150 chrome::NOTIFICATION_BROWSER_CLOSED,
151 Source<Browser>(panel4->browser())); 151 Source<Browser>(panel4->browser()));
152 Panel* panel5 = CreatePanel( 152 Panel* panel5 = CreatePanel(
153 web_app::GenerateApplicationNameFromExtensionId(extension3->id()), 153 web_app::GenerateApplicationNameFromExtensionId(extension3->id()),
154 gfx::Rect(0, 0, 300, 200)); 154 gfx::Rect(0, 0, 300, 200));
155 signal2.Wait(); 155 signal2.Wait();
156 ASSERT_EQ(3, panel_manager->num_panels()); 156 ASSERT_EQ(3, panel_manager->num_panels());
157 EXPECT_LT(panel5->GetBounds().right(), panel3->GetBounds().x()); 157 EXPECT_LT(panel5->GetBounds().right(), panel3->GetBounds().x());
158 EXPECT_LT(panel3->GetBounds().right(), panel1->GetBounds().x()); 158 EXPECT_LT(panel3->GetBounds().right(), panel1->GetBounds().x());
159 159
160 // Test closing 2 left-most panels. 160 // Test closing 2 leftmost panels.
161 ui_test_utils::WindowedNotificationObserver signal3( 161 ui_test_utils::WindowedNotificationObserver signal3(
162 chrome::NOTIFICATION_BROWSER_CLOSED, 162 chrome::NOTIFICATION_BROWSER_CLOSED,
163 Source<Browser>(panel3->browser())); 163 Source<Browser>(panel3->browser()));
164 ui_test_utils::WindowedNotificationObserver signal4( 164 ui_test_utils::WindowedNotificationObserver signal4(
165 chrome::NOTIFICATION_BROWSER_CLOSED, 165 chrome::NOTIFICATION_BROWSER_CLOSED,
166 Source<Browser>(panel5->browser())); 166 Source<Browser>(panel5->browser()));
167 Panel* panel6 = CreatePanel( 167 Panel* panel6 = CreatePanel(
168 web_app::GenerateApplicationNameFromExtensionId(extension3->id()), 168 web_app::GenerateApplicationNameFromExtensionId(extension3->id()),
169 gfx::Rect(0, 0, 500, 200)); 169 gfx::Rect(0, 0, 500, 200));
170 signal3.Wait(); 170 signal3.Wait();
171 signal4.Wait(); 171 signal4.Wait();
172 ASSERT_EQ(2, panel_manager->num_panels()); 172 ASSERT_EQ(2, panel_manager->num_panels());
173 EXPECT_LT(panel6->GetBounds().right(), panel1->GetBounds().x()); 173 EXPECT_LT(panel6->GetBounds().right(), panel1->GetBounds().x());
174 174
175 panel1->Close(); 175 panel1->Close();
176 panel6->Close(); 176 panel6->Close();
177 } 177 }
178 178
179 struct DragTestData { 179 void SetWorkArea(const gfx::Rect& work_area) {
180 DragTestData(int drag_delta_x, 180 PanelManager::GetInstance()->SetWorkArea(gfx::Rect(0, 0, 800, 600));
181 int drag_delta_y, 181 }
182 bool is_big_delta,
183 bool should_cancel_drag)
184 : drag_delta_x(drag_delta_x), drag_delta_y(drag_delta_y),
185 is_big_delta(is_big_delta), should_cancel_drag(should_cancel_drag) {}
186 int drag_delta_x;
187 int drag_delta_y;
188 bool is_big_delta; // Drag big enough to cause shuffling.
189 bool should_cancel_drag;
190 };
191 182
192 void TestDragging(std::vector<Panel*>* panels, 183 int horizontal_spacing() {
193 const DragTestData& drag_test_data) { 184 return PanelManager::horizontal_spacing();
194 size_t num_panels = panels->size(); 185 }
195 186
196 // Test dragging each panel in the list. 187 std::vector<gfx::Rect> GetAllPanelsBounds() {
197 for (size_t drag_index = 0; drag_index < num_panels; ++drag_index) { 188 std::vector<gfx::Rect> panels_bounds;
198 std::vector<int> expected_delta_x_after_drag(num_panels, 0); 189 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels();
199 std::vector<int> expected_delta_x_after_finish(num_panels, 0); 190 for (size_t i = 0; i < panels.size(); ++i)
191 panels_bounds.push_back(panels[i]->GetRestoredBounds());
192 return panels_bounds;
193 }
200 194
201 for (size_t j = 0; j < num_panels; ++j) { 195 // Helper function for debugging.
202 expected_delta_x_after_drag.push_back(0); 196 void PrintPanelBounds() {
203 expected_delta_x_after_finish.push_back(0); 197 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels();
204 } 198 DLOG(WARNING) << "PanelBounds:";
205 199 for (size_t i = 0; i < panels.size(); ++i) {
206 expected_delta_x_after_drag[drag_index] = drag_test_data.drag_delta_x; 200 DLOG(WARNING) << "#=" << i
207 size_t swap_index = drag_index; 201 << ", ptr=" << panels[i]
208 if (drag_test_data.is_big_delta) { 202 << ", x=" << panels[i]->GetRestoredBounds().x()
209 if (drag_test_data.drag_delta_x > 0 && drag_index != 0) { 203 << ", y=" << panels[i]->GetRestoredBounds().y()
210 // Dragged to right. 204 << ", width=" << panels[i]->GetRestoredBounds().width()
211 swap_index = drag_index - 1; 205 << ", height" << panels[i]->GetRestoredBounds().height();
212 } else if (drag_test_data.drag_delta_x < 0 &&
213 drag_index != num_panels - 1) {
214 // Dragged to left.
215 swap_index = drag_index + 1;
216 }
217 }
218 if (swap_index != drag_index) {
219 expected_delta_x_after_drag[swap_index] =
220 (*panels)[drag_index]->GetRestoredBounds().x() -
221 (*panels)[swap_index]->GetRestoredBounds().x();
222 expected_delta_x_after_finish[swap_index] =
223 expected_delta_x_after_drag[swap_index];
224 expected_delta_x_after_finish[drag_index] =
225 -expected_delta_x_after_drag[swap_index];
226 }
227 ValidateDragging(*panels, drag_index, drag_test_data.drag_delta_x,
228 drag_test_data.drag_delta_y, expected_delta_x_after_drag,
229 expected_delta_x_after_finish, drag_test_data.should_cancel_drag);
230
231 if (swap_index != drag_index && !drag_test_data.should_cancel_drag) {
232 // Swap the panels in the vector so they reflect their true relative
233 // positions.
234 Panel* tmp_panel = (*panels)[swap_index];
235 (*panels)[swap_index] = (*panels)[drag_index];
236 (*panels)[drag_index] = tmp_panel;
237 }
238 } 206 }
239 } 207 }
240 208
241 void ValidateDragging(const std::vector<Panel*>& panels, 209 // This is a bit mask - a set of flags that controls the specific drag actions
242 int index_to_drag, 210 // to be carried out by TestDragging function.
243 int delta_x, 211 enum DragAction {
244 int delta_y, 212 DRAG_ACTION_BEGIN = 1,
245 const std::vector<int>& expected_delta_x_after_drag, 213 // Can only specify one of FINISH or CANCEL.
246 const std::vector<int>& expected_delta_x_after_finish, 214 DRAG_ACTION_FINISH = 2,
247 bool should_cancel_drag) { 215 DRAG_ACTION_CANCEL = 4
248 // Keep track of the initial bounds for comparison. 216 };
249 std::vector<gfx::Rect> initial_bounds(panels.size()); 217
218 void CheckPanelBounds(const std::vector<Panel*>& panels,
219 const std::vector<gfx::Rect>& expected_bounds) {
250 for (size_t i = 0; i < panels.size(); ++i) 220 for (size_t i = 0; i < panels.size(); ++i)
251 initial_bounds[i] = panels[i]->GetRestoredBounds(); 221 EXPECT_EQ(expected_bounds[i], panels[i]->GetRestoredBounds());
222 }
252 223
253 // Trigger the mouse-pressed event. 224 void CheckPanelBoundsWithDeltas(const std::vector<Panel*>& panels,
254 // All panels should remain in their original positions. 225 const std::vector<gfx::Rect>& bounds,
255 NativePanel* panel_to_drag = panels[index_to_drag]->native_panel(); 226 const std::vector<int> expected_delta_x) {
227 for (size_t i = 0; i < panels.size(); ++i) {
228 gfx::Rect expected_bounds = bounds[i];
229 expected_bounds.Offset(expected_delta_x[i], 0);
230 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds());
231 }
232 }
233
234 void TestDragging(int delta_x,
235 int delta_y,
236 size_t drag_index,
237 std::vector<int> expected_delta_x_after_drag,
238 std::vector<int> expected_delta_x_after_finish,
239 std::vector<gfx::Rect> expected_bounds_after_cancel,
240 int drag_action) {
241 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
242
243 // These are bounds at the beginning of this test. This would be different
244 // from expected_bounds_after_cancel in the case where we're testing for the
245 // case of multiple drags before finishing the drag. Here is an example:
246 //
247 // Test 1 - Create three panels and drag a panel to the right but don't
248 // finish or cancel the drag.
249 // expected_bounds_after_cancel == test_begin_bounds
250 // Test 2 - Do another drag on the same panel. There is no button press
251 // in this case as its the same drag that's continuing, this is
252 // simulating multiple drag events before button release.
253 // expected_bounds_after_cancel is still the same as in Test1.
254 // So in this case
255 // expected_bounds_after_cancel != test_begin_bounds.
256 std::vector<gfx::Rect> test_begin_bounds = GetAllPanelsBounds();
257
258 NativePanel* panel_to_drag = panels[drag_index]->native_panel();
256 scoped_ptr<NativePanelTesting> panel_testing_to_drag( 259 scoped_ptr<NativePanelTesting> panel_testing_to_drag(
257 NativePanelTesting::Create(panel_to_drag)); 260 NativePanelTesting::Create(panel_to_drag));
258 261
259 gfx::Point button_press_point(initial_bounds[index_to_drag].x(), 262 if (drag_action & DRAG_ACTION_BEGIN) {
260 initial_bounds[index_to_drag].y()); 263 // Trigger the mouse-pressed event.
261 panel_testing_to_drag->PressLeftMouseButtonTitlebar(button_press_point); 264 // All panels should remain in their original positions.
262 for (size_t i = 0; i < panels.size(); ++i) 265 gfx::Point button_press_point(
263 EXPECT_EQ(initial_bounds[i], panels[i]->GetRestoredBounds()); 266 panels[drag_index]->GetRestoredBounds().x(),
267 panels[drag_index]->GetRestoredBounds().y());
268 panel_testing_to_drag->PressLeftMouseButtonTitlebar(button_press_point);
269 CheckPanelBounds(panels, test_begin_bounds);
270 }
264 271
265 // Trigger the drag. 272 // Trigger the drag.
266 panel_testing_to_drag->DragTitlebar(delta_x, delta_y); 273 panel_testing_to_drag->DragTitlebar(delta_x, delta_y);
267 274
268 for (size_t i = 0; i < panels.size(); ++i) { 275 // Compare against expected bounds.
269 gfx::Rect expected_bounds = initial_bounds[i]; 276 CheckPanelBoundsWithDeltas(panels, test_begin_bounds,
270 expected_bounds.Offset(expected_delta_x_after_drag[i], 0); 277 expected_delta_x_after_drag);
271 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds());
272 }
273 278
274 // Cancel drag if asked. 279 if (drag_action & DRAG_ACTION_CANCEL) {
275 // All panels should stay in their original positions. 280 // Cancel the drag.
276 if (should_cancel_drag) { 281 // All panels should return to their initial positions.
277 panel_testing_to_drag->CancelDragTitlebar(); 282 panel_testing_to_drag->CancelDragTitlebar();
278 for (size_t i = 0; i < panels.size(); ++i) 283 CheckPanelBounds(PanelManager::GetInstance()->panels(),
279 EXPECT_EQ(initial_bounds[i], panels[i]->GetRestoredBounds()); 284 expected_bounds_after_cancel);
280 return; 285 } else if (drag_action & DRAG_ACTION_FINISH) {
281 } 286 // Finish the drag.
282 287 // Compare against expected bounds.
283 // Otherwise finish the drag. 288 panel_testing_to_drag->FinishDragTitlebar();
284 panel_testing_to_drag->FinishDragTitlebar(); 289 CheckPanelBoundsWithDeltas(panels, test_begin_bounds,
285 for (size_t i = 0; i < panels.size(); ++i) { 290 expected_delta_x_after_finish);
286 gfx::Rect expected_bounds = initial_bounds[i];
287 expected_bounds.Offset(expected_delta_x_after_finish[i], 0);
288 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds());
289 } 291 }
290 } 292 }
291 }; 293 };
292 294
293 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { 295 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) {
294 PanelManager* panel_manager = PanelManager::GetInstance(); 296 PanelManager* panel_manager = PanelManager::GetInstance();
295 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. 297 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially.
296 298
297 Panel* panel = CreatePanel("PanelTest", gfx::Rect()); 299 Panel* panel = CreatePanel("PanelTest", gfx::Rect());
298 EXPECT_EQ(1, panel_manager->num_panels()); 300 EXPECT_EQ(1, panel_manager->num_panels());
(...skipping 21 matching lines...) Expand all
320 TestCreatePanelOnOverflow(); 322 TestCreatePanelOnOverflow();
321 } 323 }
322 324
323 #if defined(TOOLKIT_GTK) || defined(OS_WIN) 325 #if defined(TOOLKIT_GTK) || defined(OS_WIN)
324 #define MAYBE_DragPanels DragPanels 326 #define MAYBE_DragPanels DragPanels
325 #else 327 #else
326 #define MAYBE_DragPanels DISABLED_DragPanels 328 #define MAYBE_DragPanels DISABLED_DragPanels
327 #endif 329 #endif
328 330
329 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_DragPanels) { 331 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_DragPanels) {
330 std::vector<Panel*> panels; 332 // Set work area to make the test consistent on different monitor sizes.
331 panels.push_back(CreatePanel("PanelTest0", gfx::Rect())); 333 SetWorkArea(gfx::Rect(0, 0, 800, 600));
332 334
333 int small_delta = 5; 335 static const int max_panels = 3;
334 int big_delta = panels[0]->GetRestoredBounds().width() * 0.5 + 5; 336 static const int zero_delta = 0;
335 337 static const int small_delta = 10;
336 // Setup test data. 338 static const int big_delta = 70;
337 // Template - DragTestData(delta_x, delta_y, is_big_delta, should_cancel_drag) 339 static const int bigger_delta = 120;
338 std::vector<DragTestData> drag_test_data; 340 static const int biggest_delta = 200;
339 drag_test_data.push_back(DragTestData( 341 static const std::vector<int> zero_deltas(max_panels, zero_delta);
340 small_delta, small_delta, false, false)); 342
341 drag_test_data.push_back(DragTestData( 343 std::vector<int> expected_delta_x_after_drag(max_panels, zero_delta);
342 -small_delta, -small_delta, false, false)); 344 std::vector<int> expected_delta_x_after_finish(max_panels, zero_delta);
343 drag_test_data.push_back(DragTestData(big_delta, big_delta, true, false)); 345 std::vector<gfx::Rect> current_bounds;
344 drag_test_data.push_back(DragTestData(big_delta, small_delta, true, false)); 346 std::vector<gfx::Rect> initial_bounds;
345 drag_test_data.push_back(DragTestData(-big_delta, -big_delta, true, false)); 347
346 drag_test_data.push_back(DragTestData(-big_delta, 0, true, false)); 348 // Tests with a single panel.
347 drag_test_data.push_back(DragTestData(big_delta, big_delta, true, true)); 349 {
348 drag_test_data.push_back(DragTestData(-big_delta, -big_delta, true, true)); 350 CreatePanel("PanelTest1", gfx::Rect(0, 0, 100, 100));
349 351
350 for (int num_panels = 1; num_panels <= 3; ++num_panels) { 352 // Drag left.
351 if (num_panels > 1) 353 expected_delta_x_after_drag[0] = -big_delta;
352 panels.push_back(CreatePanel("PanelTest", gfx::Rect())); 354 expected_delta_x_after_finish = zero_deltas;
353 for (size_t j = 0; j < drag_test_data.size(); ++j) { 355 TestDragging(-big_delta, zero_delta, 0, expected_delta_x_after_drag,
354 // Test for each combination of drag test data and number of panels. 356 zero_deltas, GetAllPanelsBounds(),
355 TestDragging(&panels, drag_test_data[j]); 357 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH);
356 } 358
359 // Drag left and cancel.
360 expected_delta_x_after_drag[0] = -big_delta;
361 expected_delta_x_after_finish = zero_deltas;
362 TestDragging(-big_delta, zero_delta, 0, expected_delta_x_after_drag,
363 zero_deltas, GetAllPanelsBounds(),
364 DRAG_ACTION_BEGIN | DRAG_ACTION_CANCEL);
365
366 // Drag right.
367 expected_delta_x_after_drag[0] = big_delta;
368 TestDragging(big_delta, zero_delta, 0, expected_delta_x_after_drag,
369 zero_deltas, GetAllPanelsBounds(),
370 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH);
371
372 // Drag right and up. Expect no vertical movement.
373 TestDragging(big_delta, big_delta, 0, expected_delta_x_after_drag,
374 zero_deltas, GetAllPanelsBounds(),
375 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH);
376
377 // Drag up. Expect no movement on drag.
378 TestDragging(0, -big_delta, 0, zero_deltas, zero_deltas,
379 GetAllPanelsBounds(), DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH);
380
381 // Drag down. Expect no movement on drag.
382 TestDragging(0, big_delta, 0, zero_deltas, zero_deltas,
383 GetAllPanelsBounds(), DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH);
357 } 384 }
358 385
359 for (size_t i = 0; i < panels.size(); ++i) 386 // Tests with two panels.
360 panels[i]->Close(); 387 {
388 CreatePanel("PanelTest2", gfx::Rect(0, 0, 120, 120));
389
390 // Drag left, small delta, expect no shuffle.
391 {
392 expected_delta_x_after_drag = zero_deltas;
393 expected_delta_x_after_drag[0] = -small_delta;
394 TestDragging(-small_delta, zero_delta, 0, expected_delta_x_after_drag,
395 zero_deltas, GetAllPanelsBounds(),
396 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH);
397
398 // Drag right panel i.e index 0, towards left, big delta, expect shuffle.
399 initial_bounds = GetAllPanelsBounds();
400 expected_delta_x_after_drag = zero_deltas;
401
402 // Deltas for panel being dragged.
403 expected_delta_x_after_drag[0] = -big_delta;
404 expected_delta_x_after_finish[0] =
405 -(initial_bounds[1].width() + horizontal_spacing());
406
407 // Deltas for panel being shuffled.
408 expected_delta_x_after_drag[1] =
409 initial_bounds[0].width() + horizontal_spacing();
410 expected_delta_x_after_finish[1] = expected_delta_x_after_drag[1];
411
412 TestDragging(-big_delta, zero_delta, 0, expected_delta_x_after_drag,
413 expected_delta_x_after_finish, initial_bounds,
414 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH);
415 }
416
417 // Drag left panel i.e index 1, towards right, big delta, expect shuffle.
418 {
419 initial_bounds = GetAllPanelsBounds();
420 expected_delta_x_after_drag = zero_deltas;
421 expected_delta_x_after_finish = zero_deltas;
422
423 // Deltas for panel being dragged.
424 expected_delta_x_after_drag[1] = big_delta;
425 expected_delta_x_after_finish[1] =
426 initial_bounds[0].width() + horizontal_spacing();
427
428 // Deltas for panel being shuffled.
429 expected_delta_x_after_drag[0] =
430 -(initial_bounds[1].width() + horizontal_spacing());
431 expected_delta_x_after_finish[0] = expected_delta_x_after_drag[0];
432
433 TestDragging(big_delta, zero_delta, 1, expected_delta_x_after_drag,
434 expected_delta_x_after_finish, initial_bounds,
435 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH);
436 }
437
438 // Drag left panel i.e index 1, towards right, big delta, expect shuffle.
439 // Cancel drag.
440 {
441 initial_bounds = GetAllPanelsBounds();
442 expected_delta_x_after_drag = zero_deltas;
443
444 // Delta for panel being dragged.
445 expected_delta_x_after_drag[1] = big_delta;
446
447 // Delta for panel being shuffled.
448 expected_delta_x_after_drag[0] =
449 -(initial_bounds[1].width() + horizontal_spacing());
450
451 // As the drag is being canceled, we don't need expected_delta_x_after
452 // finish. Instead initial_bounds will be used.
453 TestDragging(big_delta, zero_delta, 1, expected_delta_x_after_drag,
454 zero_deltas, initial_bounds,
455 DRAG_ACTION_BEGIN | DRAG_ACTION_CANCEL);
456 }
457 }
458
459 // Tests with three panels.
460 {
461 CreatePanel("PanelTest3", gfx::Rect(0, 0, 110, 110));
462
463 // Drag leftmost panel to become rightmost with two shuffles.
464 // We test both shuffles.
465 {
466 // Drag the left-most panel towards right without ending or cancelling it.
467 // Expect shuffle.
468 initial_bounds = GetAllPanelsBounds();
469 expected_delta_x_after_drag = zero_deltas;
470
471 // Delta for panel being dragged.
472 expected_delta_x_after_drag[2] = big_delta;
473
474 // Delta for panel being shuffled.
475 expected_delta_x_after_drag[1] =
476 -(initial_bounds[2].width() + horizontal_spacing());
477
478 // There is no delta after finish as drag is not done yet.
479 TestDragging(big_delta, zero_delta, 2, expected_delta_x_after_drag,
480 zero_deltas, initial_bounds, DRAG_ACTION_BEGIN);
481
482 // The drag index changes from 2 to 1 because of the first shuffle above.
483 // Drag the panel further enough to the right to trigger a another
484 // shuffle. We finish the drag here.
485 current_bounds = GetAllPanelsBounds();
486 expected_delta_x_after_drag = zero_deltas;
487 expected_delta_x_after_finish = zero_deltas;
488
489 // big_delta is not enough to cause the second shuffle as the panel being
490 // dragged is in the middle of a drag and big_delta won't go far enough.
491 // So we use bigger_delta.
492
493 // Deltas for panel being dragged.
494 expected_delta_x_after_drag[1] = bigger_delta;
495 int x_after_finish = current_bounds[0].x() +
496 (current_bounds[0].width() - current_bounds[1].width());
497 expected_delta_x_after_finish[1] = x_after_finish - current_bounds[1].x();
498
499 // Deltas for panel being shuffled.
500 expected_delta_x_after_drag[0] =
501 -(current_bounds[1].width() + horizontal_spacing());
502 expected_delta_x_after_finish[0] = expected_delta_x_after_drag[0];
503
504 TestDragging(bigger_delta, zero_delta, 1, expected_delta_x_after_drag,
505 expected_delta_x_after_finish, initial_bounds,
506 DRAG_ACTION_FINISH);
507 }
508
509 // Drag rightmost panel to become leftmost with two shuffles.
510 // And then cancel the drag.
511 {
512 // First drag and shuffle.
513 initial_bounds = GetAllPanelsBounds();
514 expected_delta_x_after_drag = zero_deltas;
515
516 // Delta for panel being dragged.
517 expected_delta_x_after_drag[0] = -big_delta;
518
519 // Delta for panel being shuffled.
520 expected_delta_x_after_drag[1] =
521 (initial_bounds[0].width() + horizontal_spacing());
522
523 // There is no delta after finish as drag is done yet.
524 TestDragging(-big_delta, zero_delta, 0, expected_delta_x_after_drag,
525 zero_deltas, initial_bounds, DRAG_ACTION_BEGIN);
526
527 // Second drag and shuffle. We cancel the drag here. The drag index
528 // changes from 0 to 1 because of the first shuffle above.
529 current_bounds = GetAllPanelsBounds();
530 expected_delta_x_after_drag = zero_deltas;
531
532 // Delta for panel being dragged.
533 expected_delta_x_after_drag[1] = -bigger_delta;
534
535 // Deltas for panel being shuffled.
536 int x_after_shuffle = current_bounds[0].x() - horizontal_spacing()
537 - current_bounds[2].width();
538 expected_delta_x_after_drag[2] = x_after_shuffle - current_bounds[2].x();
539
540 // There is no delta after finish as drag canceled.
541 TestDragging(-bigger_delta, zero_delta, 1, expected_delta_x_after_drag,
542 zero_deltas, initial_bounds, DRAG_ACTION_CANCEL);
543 }
544
545 // Drag leftmost panel to become the rightmost in a single drag. This
546 // will shuffle middle panel to leftmost and rightmost to middle.
547 {
548 initial_bounds = GetAllPanelsBounds();
549 expected_delta_x_after_drag = zero_deltas;
550 expected_delta_x_after_finish = zero_deltas;
551
552 // Use a delta big enough to go across two panels.
553 // Deltas for panel being dragged.
554 expected_delta_x_after_drag[2] = biggest_delta;
555 expected_delta_x_after_finish[2] =
556 initial_bounds[1].width() + horizontal_spacing() +
557 initial_bounds[0].width() + horizontal_spacing();
558
559 // Deltas for middle panels being shuffled.
560 expected_delta_x_after_drag[1] =
561 -(initial_bounds[2].width() + horizontal_spacing());
562 expected_delta_x_after_finish[1] = expected_delta_x_after_drag[1];
563
564 expected_delta_x_after_drag[0] = expected_delta_x_after_drag[1];
565 expected_delta_x_after_finish[0] = expected_delta_x_after_drag[0];
566
567 TestDragging(biggest_delta, zero_delta, 2, expected_delta_x_after_drag,
568 expected_delta_x_after_finish, initial_bounds,
569 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH);
570 }
571
572 // Drag rightmost panel to become the leftmost in a single drag. This
573 // will shuffle middle panel to rightmost and leftmost to middle.
574 {
575 initial_bounds = GetAllPanelsBounds();
576 expected_delta_x_after_drag = zero_deltas;
577 expected_delta_x_after_finish = zero_deltas;
578
579 // Deltas for panel being dragged.
580 expected_delta_x_after_drag[0] = -biggest_delta;
581 expected_delta_x_after_finish[0] =
582 -(initial_bounds[1].width() + horizontal_spacing() +
583 initial_bounds[2].width() + horizontal_spacing());
584
585 // Deltas for panels being shuffled.
586 expected_delta_x_after_drag[1] =
587 initial_bounds[0].width() + horizontal_spacing();
588 expected_delta_x_after_finish[1] = expected_delta_x_after_drag[1];
589
590 expected_delta_x_after_drag[2] = expected_delta_x_after_drag[1];
591 expected_delta_x_after_finish[2] = expected_delta_x_after_drag[2];
592
593 TestDragging(-biggest_delta, zero_delta, 0, expected_delta_x_after_drag,
594 expected_delta_x_after_finish, initial_bounds,
595 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH);
596 }
597
598 // Drag rightmost panel to become the leftmost in a single drag. Then
599 // cancel the drag.
600 {
601 initial_bounds = GetAllPanelsBounds();
602 expected_delta_x_after_drag = zero_deltas;
603
604 // Deltas for panel being dragged.
605 expected_delta_x_after_drag[0] = -biggest_delta;
606
607 // Deltas for panels being shuffled.
608 expected_delta_x_after_drag[1] =
609 initial_bounds[0].width() + horizontal_spacing();
610 expected_delta_x_after_drag[2] = expected_delta_x_after_drag[1];
611
612 // No delta after finish as drag is canceled.
613 TestDragging(-biggest_delta, zero_delta, 0, expected_delta_x_after_drag,
614 zero_deltas, initial_bounds,
615 DRAG_ACTION_BEGIN | DRAG_ACTION_CANCEL);
616 }
617 }
618
619 PanelManager::GetInstance()->RemoveAll();
361 } 620 }
362 621
363 class PanelDownloadTest : public PanelBrowserTest { 622 class PanelDownloadTest : public PanelBrowserTest {
364 public: 623 public:
365 PanelDownloadTest() : PanelBrowserTest() { } 624 PanelDownloadTest() : PanelBrowserTest() { }
366 625
367 // Creates a temporary directory for downloads that is auto-deleted 626 // Creates a temporary directory for downloads that is auto-deleted
368 // on destruction. 627 // on destruction.
369 bool CreateDownloadDirectory(Profile* profile) { 628 bool CreateDownloadDirectory(Profile* profile) {
370 bool created = downloads_directory_.CreateUniqueTempDir(); 629 bool created = downloads_directory_.CreateUniqueTempDir();
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 EXPECT_EQ(1, tabbed_browser->tab_count()); 776 EXPECT_EQ(1, tabbed_browser->tab_count());
518 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); 777 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible());
519 tabbed_browser->CloseWindow(); 778 tabbed_browser->CloseWindow();
520 #endif 779 #endif
521 780
522 EXPECT_EQ(1, panel_browser->tab_count()); 781 EXPECT_EQ(1, panel_browser->tab_count());
523 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); 782 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible());
524 783
525 panel_browser->CloseWindow(); 784 panel_browser->CloseWindow();
526 } 785 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/panel_browser_view.cc ('k') | chrome/browser/ui/panels/panel_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698