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

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: Code review feedback. Mostly cosmetic. Created 9 years, 3 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 "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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 web_app::GenerateApplicationNameFromExtensionId(extension1->id()), 104 web_app::GenerateApplicationNameFromExtensionId(extension1->id()),
105 gfx::Rect(0, 0, 250, 200)); 105 gfx::Rect(0, 0, 250, 200));
106 Panel* panel2 = CreatePanel( 106 Panel* panel2 = CreatePanel(
107 web_app::GenerateApplicationNameFromExtensionId(extension2->id()), 107 web_app::GenerateApplicationNameFromExtensionId(extension2->id()),
108 gfx::Rect(0, 0, 300, 200)); 108 gfx::Rect(0, 0, 300, 200));
109 Panel* panel3 = CreatePanel( 109 Panel* panel3 = CreatePanel(
110 web_app::GenerateApplicationNameFromExtensionId(extension1->id()), 110 web_app::GenerateApplicationNameFromExtensionId(extension1->id()),
111 gfx::Rect(0, 0, 200, 200)); 111 gfx::Rect(0, 0, 200, 200));
112 ASSERT_EQ(3, panel_manager->num_panels()); 112 ASSERT_EQ(3, panel_manager->num_panels());
113 113
114 // Test closing the left-most panel that is from same extension. 114 // Test closing the leftmost panel that is from same extension.
115 ui_test_utils::WindowedNotificationObserver signal( 115 ui_test_utils::WindowedNotificationObserver signal(
116 chrome::NOTIFICATION_BROWSER_CLOSED, 116 chrome::NOTIFICATION_BROWSER_CLOSED,
117 Source<Browser>(panel2->browser())); 117 Source<Browser>(panel2->browser()));
118 Panel* panel4 = CreatePanel( 118 Panel* panel4 = CreatePanel(
119 web_app::GenerateApplicationNameFromExtensionId(extension2->id()), 119 web_app::GenerateApplicationNameFromExtensionId(extension2->id()),
120 gfx::Rect(0, 0, 280, 200)); 120 gfx::Rect(0, 0, 280, 200));
121 signal.Wait(); 121 signal.Wait();
122 ASSERT_EQ(3, panel_manager->num_panels()); 122 ASSERT_EQ(3, panel_manager->num_panels());
123 EXPECT_LT(panel4->GetBounds().right(), panel3->GetBounds().x()); 123 EXPECT_LT(panel4->GetBounds().right(), panel3->GetBounds().x());
124 EXPECT_LT(panel3->GetBounds().right(), panel1->GetBounds().x()); 124 EXPECT_LT(panel3->GetBounds().right(), panel1->GetBounds().x());
125 125
126 // Test closing the left-most panel. 126 // Test closing the leftmost panel.
127 ui_test_utils::WindowedNotificationObserver signal2( 127 ui_test_utils::WindowedNotificationObserver signal2(
128 chrome::NOTIFICATION_BROWSER_CLOSED, 128 chrome::NOTIFICATION_BROWSER_CLOSED,
129 Source<Browser>(panel4->browser())); 129 Source<Browser>(panel4->browser()));
130 Panel* panel5 = CreatePanel( 130 Panel* panel5 = CreatePanel(
131 web_app::GenerateApplicationNameFromExtensionId(extension3->id()), 131 web_app::GenerateApplicationNameFromExtensionId(extension3->id()),
132 gfx::Rect(0, 0, 300, 200)); 132 gfx::Rect(0, 0, 300, 200));
133 signal2.Wait(); 133 signal2.Wait();
134 ASSERT_EQ(3, panel_manager->num_panels()); 134 ASSERT_EQ(3, panel_manager->num_panels());
135 EXPECT_LT(panel5->GetBounds().right(), panel3->GetBounds().x()); 135 EXPECT_LT(panel5->GetBounds().right(), panel3->GetBounds().x());
136 EXPECT_LT(panel3->GetBounds().right(), panel1->GetBounds().x()); 136 EXPECT_LT(panel3->GetBounds().right(), panel1->GetBounds().x());
137 137
138 // Test closing 2 left-most panels. 138 // Test closing 2 leftmost panels.
139 ui_test_utils::WindowedNotificationObserver signal3( 139 ui_test_utils::WindowedNotificationObserver signal3(
140 chrome::NOTIFICATION_BROWSER_CLOSED, 140 chrome::NOTIFICATION_BROWSER_CLOSED,
141 Source<Browser>(panel3->browser())); 141 Source<Browser>(panel3->browser()));
142 ui_test_utils::WindowedNotificationObserver signal4( 142 ui_test_utils::WindowedNotificationObserver signal4(
143 chrome::NOTIFICATION_BROWSER_CLOSED, 143 chrome::NOTIFICATION_BROWSER_CLOSED,
144 Source<Browser>(panel5->browser())); 144 Source<Browser>(panel5->browser()));
145 Panel* panel6 = CreatePanel( 145 Panel* panel6 = CreatePanel(
146 web_app::GenerateApplicationNameFromExtensionId(extension3->id()), 146 web_app::GenerateApplicationNameFromExtensionId(extension3->id()),
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 std::vector<gfx::Rect> GetAllPanelsBounds() {
175 for (size_t drag_index = 0; drag_index < num_panels; ++drag_index) { 166 std::vector<gfx::Rect> panels_bounds;
176 std::vector<int> expected_delta_x_after_drag(num_panels, 0); 167 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels();
177 std::vector<int> expected_delta_x_after_finish(num_panels, 0); 168 for (size_t i = 0; i < panels.size(); ++i)
169 panels_bounds.push_back(panels[i]->GetRestoredBounds());
170 return panels_bounds;
171 }
178 172
179 for (size_t j = 0; j < num_panels; ++j) { 173 // Helper function for debugging.
180 expected_delta_x_after_drag.push_back(0); 174 void PrintPanelBounds() {
181 expected_delta_x_after_finish.push_back(0); 175 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels();
182 } 176 DLOG(WARNING) << "PanelBounds:";
183 177 for (size_t i = 0; i < panels.size(); ++i) {
184 expected_delta_x_after_drag[drag_index] = drag_test_data.drag_delta_x; 178 DLOG(WARNING) << "#=" << i
185 size_t swap_index = drag_index; 179 << ", ptr=" << panels[i]
186 if (drag_test_data.is_big_delta) { 180 << ", x=" << panels[i]->GetRestoredBounds().x()
187 if (drag_test_data.drag_delta_x > 0 && drag_index != 0) { 181 << ", y=" << panels[i]->GetRestoredBounds().y()
188 // Dragged to right. 182 << ", width=" << panels[i]->GetRestoredBounds().width()
189 swap_index = drag_index - 1; 183 << ", height" << panels[i]->GetRestoredBounds().height();
190 } else if (drag_test_data.drag_delta_x < 0 &&
191 drag_index != num_panels - 1) {
192 // Dragged to left.
193 swap_index = drag_index + 1;
194 }
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 } 184 }
217 } 185 }
218 186
219 void ValidateDragging(const std::vector<Panel*>& panels, 187 // This is a bit mask - a set of flags that controls the specific drag actions
220 int index_to_drag, 188 // to be carried out by TestDragging function.
221 int delta_x, 189 enum DragAction {
222 int delta_y, 190 DRAG_ACTION_BEGIN = 1,
223 const std::vector<int>& expected_delta_x_after_drag, 191 // Can only specify one of FINISH or CANCEL.
224 const std::vector<int>& expected_delta_x_after_finish, 192 DRAG_ACTION_FINISH = 2,
225 bool should_cancel_drag) { 193 DRAG_ACTION_CANCEL = 4
226 // Keep track of the initial bounds for comparison. 194 };
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 195
231 // Trigger the mouse-pressed event. 196 void TestDragging(int delta_x,
232 // All panels should remain in their original positions. 197 int delta_y,
233 NativePanel* panel_to_drag = panels[index_to_drag]->native_panel(); 198 size_t drag_index,
199 std::vector<int> expected_delta_x_after_drag,
200 std::vector<int> expected_delta_x_after_finish,
201 std::vector<gfx::Rect> initial_bounds,
202 int drag_action) {
203 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
204
205 // These are bounds at the beginning of this test. This would be different
206 // from initial_bounds in the case where we're testing for the case of
207 // multiple drags before finishing the drag. Here is an example:
208 //
209 // Test 1 - Create three panels and drag a panel to the right but don't
210 // finish or cancel the drag. initial_bounds == test_begin_bounds
211 // Test 2 - Do another drag on the same panel. There is no button press
212 // in this case as its the same drag that's continuing, this is
213 // simulating multiple drag events before button release.
214 // initial_bounds is still the same as in Test1. So in this case
215 // initial_bounds != test_begin_bounds.
216 std::vector<gfx::Rect> test_begin_bounds = GetAllPanelsBounds();
217
218 NativePanel* panel_to_drag = panels[drag_index]->native_panel();
234 scoped_ptr<NativePanelTesting> panel_testing_to_drag( 219 scoped_ptr<NativePanelTesting> panel_testing_to_drag(
235 NativePanelTesting::Create(panel_to_drag)); 220 NativePanelTesting::Create(panel_to_drag));
236 221
237 gfx::Point button_press_point(initial_bounds[index_to_drag].x(), 222 if (drag_action & DRAG_ACTION_BEGIN) {
238 initial_bounds[index_to_drag].y()); 223 // Trigger the mouse-pressed event.
239 panel_testing_to_drag->PressLeftMouseButtonTitlebar(button_press_point); 224 // All panels should remain in their original positions.
240 for (size_t i = 0; i < panels.size(); ++i) 225 gfx::Point button_press_point(
241 EXPECT_EQ(initial_bounds[i], panels[i]->GetRestoredBounds()); 226 panels[drag_index]->GetRestoredBounds().x(),
227 panels[drag_index]->GetRestoredBounds().y());
228 panel_testing_to_drag->PressLeftMouseButtonTitlebar(button_press_point);
229 for (size_t i = 0; i < panels.size(); ++i)
230 EXPECT_EQ(test_begin_bounds[i], panels[i]->GetRestoredBounds());
231 }
242 232
243 // Trigger the drag. 233 // Trigger the drag.
244 panel_testing_to_drag->DragTitlebar(delta_x, delta_y); 234 panel_testing_to_drag->DragTitlebar(delta_x, delta_y);
245 235
236 // Compare against expected bounds.
246 for (size_t i = 0; i < panels.size(); ++i) { 237 for (size_t i = 0; i < panels.size(); ++i) {
247 gfx::Rect expected_bounds = initial_bounds[i]; 238 gfx::Rect expected_bounds = test_begin_bounds[i];
248 expected_bounds.Offset(expected_delta_x_after_drag[i], 0); 239 expected_bounds.Offset(expected_delta_x_after_drag[i], 0);
249 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds()); 240 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds());
250 } 241 }
251 242
252 // Cancel drag if asked. 243 if (drag_action & DRAG_ACTION_CANCEL) {
253 // All panels should stay in their original positions. 244 // Cancel the drag.
254 if (should_cancel_drag) { 245 // All panels should return to their initial positions.
255 panel_testing_to_drag->CancelDragTitlebar(); 246 panel_testing_to_drag->CancelDragTitlebar();
247 std::vector<gfx::Rect> current_bounds = GetAllPanelsBounds();
256 for (size_t i = 0; i < panels.size(); ++i) 248 for (size_t i = 0; i < panels.size(); ++i)
257 EXPECT_EQ(initial_bounds[i], panels[i]->GetRestoredBounds()); 249 EXPECT_EQ(initial_bounds[i], current_bounds[i]);
258 return; 250 } else if (drag_action & DRAG_ACTION_FINISH) {
259 } 251 // Finish the drag.
260 252 // Compare against expected bounds.
261 // Otherwise finish the drag. 253 panel_testing_to_drag->FinishDragTitlebar();
262 panel_testing_to_drag->FinishDragTitlebar(); 254 for (size_t i = 0; i < panels.size(); ++i) {
263 for (size_t i = 0; i < panels.size(); ++i) { 255 gfx::Rect expected_bounds = test_begin_bounds[i];
264 gfx::Rect expected_bounds = initial_bounds[i]; 256 expected_bounds.Offset(expected_delta_x_after_finish[i], 0);
265 expected_bounds.Offset(expected_delta_x_after_finish[i], 0); 257 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds());
266 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds()); 258 }
267 } 259 }
268 } 260 }
269 }; 261 };
270 262
271 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { 263 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) {
272 PanelManager* panel_manager = PanelManager::GetInstance(); 264 PanelManager* panel_manager = PanelManager::GetInstance();
273 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. 265 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially.
274 266
275 Panel* panel = CreatePanel("PanelTest", gfx::Rect()); 267 Panel* panel = CreatePanel("PanelTest", gfx::Rect());
276 EXPECT_EQ(1, panel_manager->num_panels()); 268 EXPECT_EQ(1, panel_manager->num_panels());
(...skipping 27 matching lines...) Expand all
304 TestCreatePanelOnOverflow(); 296 TestCreatePanelOnOverflow();
305 } 297 }
306 298
307 #if defined(TOOLKIT_GTK) || defined(OS_WIN) 299 #if defined(TOOLKIT_GTK) || defined(OS_WIN)
308 #define MAYBE_DragPanels DragPanels 300 #define MAYBE_DragPanels DragPanels
309 #else 301 #else
310 #define MAYBE_DragPanels DISABLED_DragPanels 302 #define MAYBE_DragPanels DISABLED_DragPanels
311 #endif 303 #endif
312 304
313 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_DragPanels) { 305 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_DragPanels) {
314 std::vector<Panel*> panels; 306 // Set work area to make the test consistent on different monitor sizes.
315 panels.push_back(CreatePanel("PanelTest0", gfx::Rect())); 307 SetWorkArea(gfx::Rect(0, 0, 800, 600));
316 308
317 int small_delta = 5; 309 static const int max_panels = 3;
318 int big_delta = panels[0]->GetRestoredBounds().width() * 0.5 + 5; 310 static const int zero_delta = 0;
319 311 static const int small_delta = 10;
320 // Setup test data. 312 static const int big_delta = 70;
321 // Template - DragTestData(delta_x, delta_y, is_big_delta, should_cancel_drag) 313 static const int bigger_delta = 120;
322 std::vector<DragTestData> drag_test_data; 314 static const int biggest_delta = 200;
323 drag_test_data.push_back(DragTestData( 315 static const std::vector<int> zero_deltas(max_panels, zero_delta);
324 small_delta, small_delta, false, false)); 316
325 drag_test_data.push_back(DragTestData( 317 std::vector<int> expected_delta_x_after_drag(max_panels, zero_delta);
326 -small_delta, -small_delta, false, false)); 318 std::vector<int> expected_delta_x_after_finish(max_panels, zero_delta);
327 drag_test_data.push_back(DragTestData(big_delta, big_delta, true, false)); 319 std::vector<gfx::Rect> current_bounds;
328 drag_test_data.push_back(DragTestData(big_delta, small_delta, true, false)); 320 std::vector<gfx::Rect> initial_bounds;
329 drag_test_data.push_back(DragTestData(-big_delta, -big_delta, true, false)); 321
330 drag_test_data.push_back(DragTestData(-big_delta, 0, true, false)); 322 // Tests with a single panel.
331 drag_test_data.push_back(DragTestData(big_delta, big_delta, true, true)); 323 {
332 drag_test_data.push_back(DragTestData(-big_delta, -big_delta, true, true)); 324 CreatePanel("PanelTest1", gfx::Rect(0, 0, 100, 100));
333 325
334 for (int num_panels = 1; num_panels <= 3; ++num_panels) { 326 // Drag left.
335 if (num_panels > 1) 327 expected_delta_x_after_drag[0] = -big_delta;
336 panels.push_back(CreatePanel("PanelTest", gfx::Rect())); 328 expected_delta_x_after_finish = zero_deltas;
337 for (size_t j = 0; j < drag_test_data.size(); ++j) { 329 TestDragging(-big_delta, zero_delta, 0, expected_delta_x_after_drag,
338 // Test for each combination of drag test data and number of panels. 330 zero_deltas, GetAllPanelsBounds(),
339 TestDragging(&panels, drag_test_data[j]); 331 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH);
332
333 // Drag left and cancel.
334 expected_delta_x_after_drag[0] = -big_delta;
335 expected_delta_x_after_finish = zero_deltas;
336 TestDragging(-big_delta, zero_delta, 0, expected_delta_x_after_drag,
337 zero_deltas, GetAllPanelsBounds(),
338 DRAG_ACTION_BEGIN | DRAG_ACTION_CANCEL);
339
340 // Drag right.
341 expected_delta_x_after_drag[0] = big_delta;
342 TestDragging(big_delta, zero_delta, 0, expected_delta_x_after_drag,
343 zero_deltas, GetAllPanelsBounds(),
344 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH);
345
346 // Drag right and up. Expect no vertical movement.
347 TestDragging(big_delta, big_delta, 0, expected_delta_x_after_drag,
348 zero_deltas, GetAllPanelsBounds(),
349 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH);
350
351 // Drag up. Expect no movement on drag.
352 TestDragging(0, -big_delta, 0, zero_deltas, zero_deltas,
353 GetAllPanelsBounds(), DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH);
354
355 // Drag down. Expect no movement on drag.
356 TestDragging(0, big_delta, 0, zero_deltas, zero_deltas,
357 GetAllPanelsBounds(), DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH);
358 }
359
360 // Tests with two panels.
361 {
362 CreatePanel("PanelTest2", gfx::Rect(0, 0, 120, 120));
363
364 // Drag left, small delta, expect no shuffle.
365 expected_delta_x_after_drag = zero_deltas;
366 expected_delta_x_after_drag[0] = -small_delta;
367 TestDragging(-small_delta, zero_delta, 0, expected_delta_x_after_drag,
368 zero_deltas, GetAllPanelsBounds(),
369 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH);
370
371 // Drag right panel i.e index 0, towards left, big delta, expect shuffle.
372 initial_bounds = GetAllPanelsBounds();
373 expected_delta_x_after_drag = zero_deltas;
374
375 // Deltas for panel being dragged.
376 expected_delta_x_after_drag[0] = -big_delta;
377 expected_delta_x_after_finish[0] =
378 -(initial_bounds[1].width() + horizontal_spacing());
379
380 // Deltas for panel being shuffled.
381 expected_delta_x_after_drag[1] =
382 initial_bounds[0].width() + horizontal_spacing();
383 expected_delta_x_after_finish[1] = expected_delta_x_after_drag[1];
384
385 TestDragging(-big_delta, zero_delta, 0, expected_delta_x_after_drag,
386 expected_delta_x_after_finish, initial_bounds,
387 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH);
388
389 // Drag left panel i.e index 1, towards right, big delta, expect shuffle.
390 initial_bounds = GetAllPanelsBounds();
391 expected_delta_x_after_drag = zero_deltas;
392 expected_delta_x_after_finish = zero_deltas;
393
394 // Deltas for panel being dragged.
395 expected_delta_x_after_drag[1] = big_delta;
396 expected_delta_x_after_finish[1] =
397 initial_bounds[0].width() + horizontal_spacing();
398
399 // Deltas for panel being shuffled.
400 expected_delta_x_after_drag[0] =
401 -(initial_bounds[1].width() + horizontal_spacing());
402 expected_delta_x_after_finish[0] = expected_delta_x_after_drag[0];
403
404 TestDragging(big_delta, zero_delta, 1, expected_delta_x_after_drag,
405 expected_delta_x_after_finish, initial_bounds,
406 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH);
407
408 // Drag left panel i.e index 1, towards right, big delta, expect shuffle.
409 // Cancel drag.
410 initial_bounds = GetAllPanelsBounds();
411 expected_delta_x_after_drag = zero_deltas;
412
413 // Delta for panel being dragged.
414 expected_delta_x_after_drag[1] = big_delta;
415
416 // Delta for panel being shuffled.
417 expected_delta_x_after_drag[0] =
418 -(initial_bounds[1].width() + horizontal_spacing());
419
420 // As the drag is being canceled, we don't need expected_delta_x_after
421 // finish. Instead initial_bounds will be used.
422 TestDragging(big_delta, zero_delta, 1, expected_delta_x_after_drag,
423 zero_deltas, initial_bounds,
424 DRAG_ACTION_BEGIN | DRAG_ACTION_CANCEL);
425 }
426
427 // Tests with three panels.
428 {
429 CreatePanel("PanelTest3", gfx::Rect(0, 0, 110, 110));
430
431 // Drag leftmost panel to become rightmost with two shuffles.
432 // We test both shuffles.
433 {
434 // Drag the left-most panel towards right without ending or cancelling it.
435 // Expect shuffle.
436 initial_bounds = GetAllPanelsBounds();
437 expected_delta_x_after_drag = zero_deltas;
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 not done yet.
447 TestDragging(big_delta, zero_delta, 2, expected_delta_x_after_drag,
448 zero_deltas, initial_bounds, DRAG_ACTION_BEGIN);
449
450 // The drag index changes from 2 to 1 because of the first shuffle above.
451 // Drag the panel further enough to the right to trigger a another
452 // shuffle. We finish the drag here.
453 current_bounds = GetAllPanelsBounds();
454 expected_delta_x_after_drag = zero_deltas;
455 expected_delta_x_after_finish = zero_deltas;
456
457 // big_delta is not enough to cause the second shuffle as the panel being
458 // dragged is in the middle of a drag and big_delta won't go far enough.
459 // So we use bigger_delta.
460
461 // Deltas for panel being dragged.
462 expected_delta_x_after_drag[1] = bigger_delta;
463 int x_after_finish = current_bounds[0].x() +
464 (current_bounds[0].width() - current_bounds[1].width());
465 expected_delta_x_after_finish[1] = x_after_finish - current_bounds[1].x();
466
467 // Deltas for panel being shuffled.
468 expected_delta_x_after_drag[0] =
469 -(current_bounds[1].width() + horizontal_spacing());
470 expected_delta_x_after_finish[0] = expected_delta_x_after_drag[0];
471
472 TestDragging(bigger_delta, zero_delta, 1, expected_delta_x_after_drag,
473 expected_delta_x_after_finish, initial_bounds,
474 DRAG_ACTION_FINISH);
340 } 475 }
476
477 // Drag rightmost panel to become leftmost with two shuffles.
478 // And then cancel the drag.
479 {
480 // First drag and shuffle.
481 initial_bounds = GetAllPanelsBounds();
482 expected_delta_x_after_drag = zero_deltas;
483
484 // Delta for panel being dragged.
485 expected_delta_x_after_drag[0] = -big_delta;
486
487 // Delta for panel being shuffled.
488 expected_delta_x_after_drag[1] =
489 (initial_bounds[0].width() + horizontal_spacing());
490
491 // There is no delta after finish as drag is done yet.
492 TestDragging(-big_delta, zero_delta, 0, expected_delta_x_after_drag,
493 zero_deltas, initial_bounds, DRAG_ACTION_BEGIN);
494
495 // Second drag and shuffle. We cancel the drag here. The drag index
496 // changes from 0 to 1 because of the first shuffle above.
497 current_bounds = GetAllPanelsBounds();
498 expected_delta_x_after_drag = zero_deltas;
499
500 // Delta for panel being dragged.
501 expected_delta_x_after_drag[1] = -bigger_delta;
502
503 // Deltas for panel being shuffled.
504 int x_after_shuffle = current_bounds[0].x() - horizontal_spacing()
505 - current_bounds[2].width();
506 expected_delta_x_after_drag[2] = x_after_shuffle - current_bounds[2].x();
507
508 // There is no delta after finish as drag canceled.
509 TestDragging(-bigger_delta, zero_delta, 1, expected_delta_x_after_drag,
510 zero_deltas, initial_bounds, DRAG_ACTION_CANCEL);
511 }
512
513 // Drag leftmost panel to become the rightmost in a single drag. This
514 // will shuffle middle panel to leftmost and rightmost to middle.
jianli 2011/08/24 22:04:03 Please move all the codes for this case to a neste
prasadt 2011/08/24 23:04:30 Done.
515 initial_bounds = GetAllPanelsBounds();
516 expected_delta_x_after_drag = zero_deltas;
517 expected_delta_x_after_finish = zero_deltas;
518
519 // Use a delta big enough to go across two panels.
520 // Deltas for panel being dragged.
521 expected_delta_x_after_drag[2] = biggest_delta;
522 expected_delta_x_after_finish[2] =
523 initial_bounds[1].width() + horizontal_spacing() +
524 initial_bounds[0].width() + horizontal_spacing();
525
526 // Deltas for middle panels being shuffled.
527 expected_delta_x_after_drag[1] =
528 -(initial_bounds[2].width() + horizontal_spacing());
529 expected_delta_x_after_finish[1] = expected_delta_x_after_drag[1];
530
531 expected_delta_x_after_drag[0] = expected_delta_x_after_drag[1];
532 expected_delta_x_after_finish[0] = expected_delta_x_after_drag[0];
533
534 TestDragging(biggest_delta, zero_delta, 2, expected_delta_x_after_drag,
535 expected_delta_x_after_finish, initial_bounds,
536 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH);
537
538 // Drag rightmost panel to become the leftmost in a single drag. This
jianli 2011/08/24 22:04:03 ditto.
prasadt 2011/08/24 23:04:30 Done.
539 // will shuffle middle panel to rightmost and leftmost to middle.
540 initial_bounds = GetAllPanelsBounds();
541 expected_delta_x_after_drag = zero_deltas;
542 expected_delta_x_after_finish = zero_deltas;
543
544 // Deltas for panel being dragged.
545 expected_delta_x_after_drag[0] = -biggest_delta;
546 expected_delta_x_after_finish[0] =
547 -(initial_bounds[1].width() + horizontal_spacing() +
548 initial_bounds[2].width() + horizontal_spacing());
549
550 // Deltas for panels being shuffled.
551 expected_delta_x_after_drag[1] =
552 initial_bounds[0].width() + horizontal_spacing();
553 expected_delta_x_after_finish[1] = expected_delta_x_after_drag[1];
554
555 expected_delta_x_after_drag[2] = expected_delta_x_after_drag[1];
556 expected_delta_x_after_finish[2] = expected_delta_x_after_drag[2];
557
558 TestDragging(-biggest_delta, zero_delta, 0, expected_delta_x_after_drag,
559 expected_delta_x_after_finish, initial_bounds,
560 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH);
561
562 // Drag rightmost panel to become the leftmost in a single drag. Then
jianli 2011/08/24 22:04:03 ditto.
prasadt 2011/08/24 23:04:30 Done.
563 // cancel the drag.
564 initial_bounds = GetAllPanelsBounds();
565 expected_delta_x_after_drag = zero_deltas;
566
567 // Deltas for panel being dragged.
568 expected_delta_x_after_drag[0] = -biggest_delta;
569
570 // Deltas for panels being shuffled.
571 expected_delta_x_after_drag[1] =
572 initial_bounds[0].width() + horizontal_spacing();
573 expected_delta_x_after_drag[2] = expected_delta_x_after_drag[1];
574
575 // No delta after finish as drag is canceled.
576 TestDragging(-biggest_delta, zero_delta, 0, expected_delta_x_after_drag,
577 zero_deltas, initial_bounds,
578 DRAG_ACTION_BEGIN | DRAG_ACTION_CANCEL);
341 } 579 }
342 580
343 for (size_t i = 0; i < panels.size(); ++i) 581 PanelManager::GetInstance()->RemoveAll();
344 panels[i]->Close();
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698