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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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()); | 195 |
196 void CheckPanelBounds(const std::vector<Panel*>& panels, | |
197 const std::vector<gfx::Rect>& expected_bounds) { | |
228 for (size_t i = 0; i < panels.size(); ++i) | 198 for (size_t i = 0; i < panels.size(); ++i) |
229 initial_bounds[i] = panels[i]->GetRestoredBounds(); | 199 EXPECT_EQ(expected_bounds[i], panels[i]->GetRestoredBounds()); |
200 } | |
230 | 201 |
231 // Trigger the mouse-pressed event. | 202 void CheckPanelBoundsWithDeltas(const std::vector<Panel*>& panels, |
232 // All panels should remain in their original positions. | 203 const std::vector<gfx::Rect>& bounds, |
233 NativePanel* panel_to_drag = panels[index_to_drag]->native_panel(); | 204 const std::vector<int> expected_delta_x) { |
205 for (size_t i = 0; i < panels.size(); ++i) { | |
206 gfx::Rect expected_bounds = bounds[i]; | |
207 expected_bounds.Offset(expected_delta_x[i], 0); | |
208 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds()); | |
209 } | |
210 } | |
jianli
2011/08/25 17:22:26
Please add an empty line.
prasadt
2011/08/25 18:10:30
Done.
| |
211 void TestDragging(int delta_x, | |
212 int delta_y, | |
213 size_t drag_index, | |
214 std::vector<int> expected_delta_x_after_drag, | |
215 std::vector<int> expected_delta_x_after_finish, | |
216 std::vector<gfx::Rect> expected_bounds_after_cancel, | |
217 int drag_action) { | |
218 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); | |
219 | |
220 // These are bounds at the beginning of this test. This would be different | |
221 // from expected_bounds_after_cancel in the case where we're testing for the | |
222 // case of multiple drags before finishing the drag. Here is an example: | |
223 // | |
224 // Test 1 - Create three panels and drag a panel to the right but don't | |
225 // finish or cancel the drag. | |
226 // expected_bounds_after_cancel == test_begin_bounds | |
227 // Test 2 - Do another drag on the same panel. There is no button press | |
228 // in this case as its the same drag that's continuing, this is | |
229 // simulating multiple drag events before button release. | |
230 // expected_bounds_after_cancel is still the same as in Test1. | |
231 // So in this case | |
232 // expected_bounds_after_cancel != test_begin_bounds. | |
233 std::vector<gfx::Rect> test_begin_bounds = GetAllPanelsBounds(); | |
234 | |
235 NativePanel* panel_to_drag = panels[drag_index]->native_panel(); | |
234 scoped_ptr<NativePanelTesting> panel_testing_to_drag( | 236 scoped_ptr<NativePanelTesting> panel_testing_to_drag( |
235 NativePanelTesting::Create(panel_to_drag)); | 237 NativePanelTesting::Create(panel_to_drag)); |
236 | 238 |
237 gfx::Point button_press_point(initial_bounds[index_to_drag].x(), | 239 if (drag_action & DRAG_ACTION_BEGIN) { |
238 initial_bounds[index_to_drag].y()); | 240 // Trigger the mouse-pressed event. |
239 panel_testing_to_drag->PressLeftMouseButtonTitlebar(button_press_point); | 241 // All panels should remain in their original positions. |
240 for (size_t i = 0; i < panels.size(); ++i) | 242 gfx::Point button_press_point( |
241 EXPECT_EQ(initial_bounds[i], panels[i]->GetRestoredBounds()); | 243 panels[drag_index]->GetRestoredBounds().x(), |
244 panels[drag_index]->GetRestoredBounds().y()); | |
245 panel_testing_to_drag->PressLeftMouseButtonTitlebar(button_press_point); | |
246 CheckPanelBounds(panels, test_begin_bounds); | |
247 } | |
242 | 248 |
243 // Trigger the drag. | 249 // Trigger the drag. |
244 panel_testing_to_drag->DragTitlebar(delta_x, delta_y); | 250 panel_testing_to_drag->DragTitlebar(delta_x, delta_y); |
245 | 251 |
246 for (size_t i = 0; i < panels.size(); ++i) { | 252 // Compare against expected bounds. |
247 gfx::Rect expected_bounds = initial_bounds[i]; | 253 CheckPanelBoundsWithDeltas(panels, test_begin_bounds, |
248 expected_bounds.Offset(expected_delta_x_after_drag[i], 0); | 254 expected_delta_x_after_drag); |
249 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds()); | |
250 } | |
251 | 255 |
252 // Cancel drag if asked. | 256 if (drag_action & DRAG_ACTION_CANCEL) { |
253 // All panels should stay in their original positions. | 257 // Cancel the drag. |
254 if (should_cancel_drag) { | 258 // All panels should return to their initial positions. |
255 panel_testing_to_drag->CancelDragTitlebar(); | 259 panel_testing_to_drag->CancelDragTitlebar(); |
256 for (size_t i = 0; i < panels.size(); ++i) | 260 CheckPanelBounds(PanelManager::GetInstance()->panels(), |
257 EXPECT_EQ(initial_bounds[i], panels[i]->GetRestoredBounds()); | 261 expected_bounds_after_cancel); |
258 return; | 262 } else if (drag_action & DRAG_ACTION_FINISH) { |
259 } | 263 // Finish the drag. |
260 | 264 // Compare against expected bounds. |
261 // Otherwise finish the drag. | 265 panel_testing_to_drag->FinishDragTitlebar(); |
262 panel_testing_to_drag->FinishDragTitlebar(); | 266 CheckPanelBoundsWithDeltas(panels, test_begin_bounds, |
263 for (size_t i = 0; i < panels.size(); ++i) { | 267 expected_delta_x_after_finish); |
264 gfx::Rect expected_bounds = initial_bounds[i]; | |
265 expected_bounds.Offset(expected_delta_x_after_finish[i], 0); | |
266 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds()); | |
267 } | 268 } |
268 } | 269 } |
269 }; | 270 }; |
270 | 271 |
271 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { | 272 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { |
272 PanelManager* panel_manager = PanelManager::GetInstance(); | 273 PanelManager* panel_manager = PanelManager::GetInstance(); |
273 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. | 274 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. |
274 | 275 |
275 Panel* panel = CreatePanel("PanelTest", gfx::Rect()); | 276 Panel* panel = CreatePanel("PanelTest", gfx::Rect()); |
276 EXPECT_EQ(1, panel_manager->num_panels()); | 277 EXPECT_EQ(1, panel_manager->num_panels()); |
(...skipping 27 matching lines...) Expand all Loading... | |
304 TestCreatePanelOnOverflow(); | 305 TestCreatePanelOnOverflow(); |
305 } | 306 } |
306 | 307 |
307 #if defined(TOOLKIT_GTK) || defined(OS_WIN) | 308 #if defined(TOOLKIT_GTK) || defined(OS_WIN) |
308 #define MAYBE_DragPanels DragPanels | 309 #define MAYBE_DragPanels DragPanels |
309 #else | 310 #else |
310 #define MAYBE_DragPanels DISABLED_DragPanels | 311 #define MAYBE_DragPanels DISABLED_DragPanels |
311 #endif | 312 #endif |
312 | 313 |
313 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_DragPanels) { | 314 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_DragPanels) { |
314 std::vector<Panel*> panels; | 315 // Set work area to make the test consistent on different monitor sizes. |
315 panels.push_back(CreatePanel("PanelTest0", gfx::Rect())); | 316 SetWorkArea(gfx::Rect(0, 0, 800, 600)); |
316 | 317 |
317 int small_delta = 5; | 318 static const int max_panels = 3; |
318 int big_delta = panels[0]->GetRestoredBounds().width() * 0.5 + 5; | 319 static const int zero_delta = 0; |
319 | 320 static const int small_delta = 10; |
320 // Setup test data. | 321 static const int big_delta = 70; |
321 // Template - DragTestData(delta_x, delta_y, is_big_delta, should_cancel_drag) | 322 static const int bigger_delta = 120; |
322 std::vector<DragTestData> drag_test_data; | 323 static const int biggest_delta = 200; |
323 drag_test_data.push_back(DragTestData( | 324 static const std::vector<int> zero_deltas(max_panels, zero_delta); |
324 small_delta, small_delta, false, false)); | 325 |
325 drag_test_data.push_back(DragTestData( | 326 std::vector<int> expected_delta_x_after_drag(max_panels, zero_delta); |
326 -small_delta, -small_delta, false, false)); | 327 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)); | 328 std::vector<gfx::Rect> current_bounds; |
328 drag_test_data.push_back(DragTestData(big_delta, small_delta, true, false)); | 329 std::vector<gfx::Rect> initial_bounds; |
329 drag_test_data.push_back(DragTestData(-big_delta, -big_delta, true, false)); | 330 |
330 drag_test_data.push_back(DragTestData(-big_delta, 0, true, false)); | 331 // Tests with a single panel. |
331 drag_test_data.push_back(DragTestData(big_delta, big_delta, true, true)); | 332 { |
332 drag_test_data.push_back(DragTestData(-big_delta, -big_delta, true, true)); | 333 CreatePanel("PanelTest1", gfx::Rect(0, 0, 100, 100)); |
333 | 334 |
334 for (int num_panels = 1; num_panels <= 3; ++num_panels) { | 335 // Drag left. |
335 if (num_panels > 1) | 336 expected_delta_x_after_drag[0] = -big_delta; |
336 panels.push_back(CreatePanel("PanelTest", gfx::Rect())); | 337 expected_delta_x_after_finish = zero_deltas; |
337 for (size_t j = 0; j < drag_test_data.size(); ++j) { | 338 TestDragging(-big_delta, zero_delta, 0, expected_delta_x_after_drag, |
338 // Test for each combination of drag test data and number of panels. | 339 zero_deltas, GetAllPanelsBounds(), |
339 TestDragging(&panels, drag_test_data[j]); | 340 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH); |
340 } | 341 |
342 // Drag left and cancel. | |
343 expected_delta_x_after_drag[0] = -big_delta; | |
344 expected_delta_x_after_finish = zero_deltas; | |
345 TestDragging(-big_delta, zero_delta, 0, expected_delta_x_after_drag, | |
346 zero_deltas, GetAllPanelsBounds(), | |
347 DRAG_ACTION_BEGIN | DRAG_ACTION_CANCEL); | |
348 | |
349 // Drag right. | |
350 expected_delta_x_after_drag[0] = big_delta; | |
351 TestDragging(big_delta, zero_delta, 0, expected_delta_x_after_drag, | |
352 zero_deltas, GetAllPanelsBounds(), | |
353 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH); | |
354 | |
355 // Drag right and up. Expect no vertical movement. | |
356 TestDragging(big_delta, big_delta, 0, expected_delta_x_after_drag, | |
357 zero_deltas, GetAllPanelsBounds(), | |
358 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH); | |
359 | |
360 // Drag up. Expect no movement on drag. | |
361 TestDragging(0, -big_delta, 0, zero_deltas, zero_deltas, | |
362 GetAllPanelsBounds(), DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH); | |
363 | |
364 // Drag down. Expect no movement on drag. | |
365 TestDragging(0, big_delta, 0, zero_deltas, zero_deltas, | |
366 GetAllPanelsBounds(), DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH); | |
341 } | 367 } |
342 | 368 |
343 for (size_t i = 0; i < panels.size(); ++i) | 369 // Tests with two panels. |
344 panels[i]->Close(); | 370 { |
371 CreatePanel("PanelTest2", gfx::Rect(0, 0, 120, 120)); | |
372 | |
373 // Drag left, small delta, expect no shuffle. | |
374 { | |
375 expected_delta_x_after_drag = zero_deltas; | |
376 expected_delta_x_after_drag[0] = -small_delta; | |
377 TestDragging(-small_delta, zero_delta, 0, expected_delta_x_after_drag, | |
378 zero_deltas, GetAllPanelsBounds(), | |
379 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH); | |
380 | |
381 // Drag right panel i.e index 0, towards left, big delta, expect shuffle. | |
382 initial_bounds = GetAllPanelsBounds(); | |
383 expected_delta_x_after_drag = zero_deltas; | |
384 | |
385 // Deltas for panel being dragged. | |
386 expected_delta_x_after_drag[0] = -big_delta; | |
387 expected_delta_x_after_finish[0] = | |
388 -(initial_bounds[1].width() + horizontal_spacing()); | |
389 | |
390 // Deltas for panel being shuffled. | |
391 expected_delta_x_after_drag[1] = | |
392 initial_bounds[0].width() + horizontal_spacing(); | |
393 expected_delta_x_after_finish[1] = expected_delta_x_after_drag[1]; | |
394 | |
395 TestDragging(-big_delta, zero_delta, 0, expected_delta_x_after_drag, | |
396 expected_delta_x_after_finish, initial_bounds, | |
397 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH); | |
398 } | |
399 | |
400 // Drag left panel i.e index 1, towards right, big delta, expect shuffle. | |
401 { | |
402 initial_bounds = GetAllPanelsBounds(); | |
403 expected_delta_x_after_drag = zero_deltas; | |
404 expected_delta_x_after_finish = zero_deltas; | |
405 | |
406 // Deltas for panel being dragged. | |
407 expected_delta_x_after_drag[1] = big_delta; | |
408 expected_delta_x_after_finish[1] = | |
409 initial_bounds[0].width() + horizontal_spacing(); | |
410 | |
411 // Deltas for panel being shuffled. | |
412 expected_delta_x_after_drag[0] = | |
413 -(initial_bounds[1].width() + horizontal_spacing()); | |
414 expected_delta_x_after_finish[0] = expected_delta_x_after_drag[0]; | |
415 | |
416 TestDragging(big_delta, zero_delta, 1, expected_delta_x_after_drag, | |
417 expected_delta_x_after_finish, initial_bounds, | |
418 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH); | |
419 } | |
420 | |
421 // Drag left panel i.e index 1, towards right, big delta, expect shuffle. | |
422 // Cancel drag. | |
423 { | |
424 initial_bounds = GetAllPanelsBounds(); | |
425 expected_delta_x_after_drag = zero_deltas; | |
426 | |
427 // Delta for panel being dragged. | |
428 expected_delta_x_after_drag[1] = big_delta; | |
429 | |
430 // Delta for panel being shuffled. | |
431 expected_delta_x_after_drag[0] = | |
432 -(initial_bounds[1].width() + horizontal_spacing()); | |
433 | |
434 // As the drag is being canceled, we don't need expected_delta_x_after | |
435 // finish. Instead initial_bounds will be used. | |
436 TestDragging(big_delta, zero_delta, 1, expected_delta_x_after_drag, | |
437 zero_deltas, initial_bounds, | |
438 DRAG_ACTION_BEGIN | DRAG_ACTION_CANCEL); | |
439 } | |
440 } | |
441 | |
442 // Tests with three panels. | |
443 { | |
444 CreatePanel("PanelTest3", gfx::Rect(0, 0, 110, 110)); | |
445 | |
446 // Drag leftmost panel to become rightmost with two shuffles. | |
447 // We test both shuffles. | |
448 { | |
449 // Drag the left-most panel towards right without ending or cancelling it. | |
450 // Expect shuffle. | |
451 initial_bounds = GetAllPanelsBounds(); | |
452 expected_delta_x_after_drag = zero_deltas; | |
453 | |
454 // Delta for panel being dragged. | |
455 expected_delta_x_after_drag[2] = big_delta; | |
456 | |
457 // Delta for panel being shuffled. | |
458 expected_delta_x_after_drag[1] = | |
459 -(initial_bounds[2].width() + horizontal_spacing()); | |
460 | |
461 // There is no delta after finish as drag is not done yet. | |
462 TestDragging(big_delta, zero_delta, 2, expected_delta_x_after_drag, | |
463 zero_deltas, initial_bounds, DRAG_ACTION_BEGIN); | |
464 | |
465 // The drag index changes from 2 to 1 because of the first shuffle above. | |
466 // Drag the panel further enough to the right to trigger a another | |
467 // shuffle. We finish the drag here. | |
468 current_bounds = GetAllPanelsBounds(); | |
469 expected_delta_x_after_drag = zero_deltas; | |
470 expected_delta_x_after_finish = zero_deltas; | |
471 | |
472 // big_delta is not enough to cause the second shuffle as the panel being | |
473 // dragged is in the middle of a drag and big_delta won't go far enough. | |
474 // So we use bigger_delta. | |
475 | |
476 // Deltas for panel being dragged. | |
477 expected_delta_x_after_drag[1] = bigger_delta; | |
478 int x_after_finish = current_bounds[0].x() + | |
479 (current_bounds[0].width() - current_bounds[1].width()); | |
480 expected_delta_x_after_finish[1] = x_after_finish - current_bounds[1].x(); | |
481 | |
482 // Deltas for panel being shuffled. | |
483 expected_delta_x_after_drag[0] = | |
484 -(current_bounds[1].width() + horizontal_spacing()); | |
485 expected_delta_x_after_finish[0] = expected_delta_x_after_drag[0]; | |
486 | |
487 TestDragging(bigger_delta, zero_delta, 1, expected_delta_x_after_drag, | |
488 expected_delta_x_after_finish, initial_bounds, | |
489 DRAG_ACTION_FINISH); | |
490 } | |
491 | |
492 // Drag rightmost panel to become leftmost with two shuffles. | |
493 // And then cancel the drag. | |
494 { | |
495 // First drag and shuffle. | |
496 initial_bounds = GetAllPanelsBounds(); | |
497 expected_delta_x_after_drag = zero_deltas; | |
498 | |
499 // Delta for panel being dragged. | |
500 expected_delta_x_after_drag[0] = -big_delta; | |
501 | |
502 // Delta for panel being shuffled. | |
503 expected_delta_x_after_drag[1] = | |
504 (initial_bounds[0].width() + horizontal_spacing()); | |
505 | |
506 // There is no delta after finish as drag is done yet. | |
507 TestDragging(-big_delta, zero_delta, 0, expected_delta_x_after_drag, | |
508 zero_deltas, initial_bounds, DRAG_ACTION_BEGIN); | |
509 | |
510 // Second drag and shuffle. We cancel the drag here. The drag index | |
511 // changes from 0 to 1 because of the first shuffle above. | |
512 current_bounds = GetAllPanelsBounds(); | |
513 expected_delta_x_after_drag = zero_deltas; | |
514 | |
515 // Delta for panel being dragged. | |
516 expected_delta_x_after_drag[1] = -bigger_delta; | |
517 | |
518 // Deltas for panel being shuffled. | |
519 int x_after_shuffle = current_bounds[0].x() - horizontal_spacing() | |
520 - current_bounds[2].width(); | |
521 expected_delta_x_after_drag[2] = x_after_shuffle - current_bounds[2].x(); | |
522 | |
523 // There is no delta after finish as drag canceled. | |
524 TestDragging(-bigger_delta, zero_delta, 1, expected_delta_x_after_drag, | |
525 zero_deltas, initial_bounds, DRAG_ACTION_CANCEL); | |
526 } | |
527 | |
528 // Drag leftmost panel to become the rightmost in a single drag. This | |
529 // will shuffle middle panel to leftmost and rightmost to middle. | |
530 { | |
531 initial_bounds = GetAllPanelsBounds(); | |
532 expected_delta_x_after_drag = zero_deltas; | |
533 expected_delta_x_after_finish = zero_deltas; | |
534 | |
535 // Use a delta big enough to go across two panels. | |
536 // Deltas for panel being dragged. | |
537 expected_delta_x_after_drag[2] = biggest_delta; | |
538 expected_delta_x_after_finish[2] = | |
539 initial_bounds[1].width() + horizontal_spacing() + | |
540 initial_bounds[0].width() + horizontal_spacing(); | |
541 | |
542 // Deltas for middle panels being shuffled. | |
543 expected_delta_x_after_drag[1] = | |
544 -(initial_bounds[2].width() + horizontal_spacing()); | |
545 expected_delta_x_after_finish[1] = expected_delta_x_after_drag[1]; | |
546 | |
547 expected_delta_x_after_drag[0] = expected_delta_x_after_drag[1]; | |
548 expected_delta_x_after_finish[0] = expected_delta_x_after_drag[0]; | |
549 | |
550 TestDragging(biggest_delta, zero_delta, 2, expected_delta_x_after_drag, | |
551 expected_delta_x_after_finish, initial_bounds, | |
552 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH); | |
553 } | |
554 | |
555 // Drag rightmost panel to become the leftmost in a single drag. This | |
556 // will shuffle middle panel to rightmost and leftmost to middle. | |
557 { | |
558 initial_bounds = GetAllPanelsBounds(); | |
559 expected_delta_x_after_drag = zero_deltas; | |
560 expected_delta_x_after_finish = zero_deltas; | |
561 | |
562 // Deltas for panel being dragged. | |
563 expected_delta_x_after_drag[0] = -biggest_delta; | |
564 expected_delta_x_after_finish[0] = | |
565 -(initial_bounds[1].width() + horizontal_spacing() + | |
566 initial_bounds[2].width() + horizontal_spacing()); | |
567 | |
568 // Deltas for panels being shuffled. | |
569 expected_delta_x_after_drag[1] = | |
570 initial_bounds[0].width() + horizontal_spacing(); | |
571 expected_delta_x_after_finish[1] = expected_delta_x_after_drag[1]; | |
572 | |
573 expected_delta_x_after_drag[2] = expected_delta_x_after_drag[1]; | |
574 expected_delta_x_after_finish[2] = expected_delta_x_after_drag[2]; | |
575 | |
576 TestDragging(-biggest_delta, zero_delta, 0, expected_delta_x_after_drag, | |
577 expected_delta_x_after_finish, initial_bounds, | |
578 DRAG_ACTION_BEGIN | DRAG_ACTION_FINISH); | |
579 } | |
580 | |
581 // Drag rightmost panel to become the leftmost in a single drag. Then | |
582 // cancel the drag. | |
583 { | |
584 initial_bounds = GetAllPanelsBounds(); | |
585 expected_delta_x_after_drag = zero_deltas; | |
586 | |
587 // Deltas for panel being dragged. | |
588 expected_delta_x_after_drag[0] = -biggest_delta; | |
589 | |
590 // Deltas for panels being shuffled. | |
591 expected_delta_x_after_drag[1] = | |
592 initial_bounds[0].width() + horizontal_spacing(); | |
593 expected_delta_x_after_drag[2] = expected_delta_x_after_drag[1]; | |
594 | |
595 // No delta after finish as drag is canceled. | |
596 TestDragging(-biggest_delta, zero_delta, 0, expected_delta_x_after_drag, | |
597 zero_deltas, initial_bounds, | |
598 DRAG_ACTION_BEGIN | DRAG_ACTION_CANCEL); | |
599 } | |
600 } | |
601 | |
602 PanelManager::GetInstance()->RemoveAll(); | |
345 } | 603 } |
346 | 604 |
347 class PanelDownloadTest : public PanelBrowserTest { | 605 class PanelDownloadTest : public PanelBrowserTest { |
348 public: | 606 public: |
349 PanelDownloadTest() : PanelBrowserTest() { } | 607 PanelDownloadTest() : PanelBrowserTest() { } |
350 | 608 |
351 // Creates a temporary directory for downloads that is auto-deleted | 609 // Creates a temporary directory for downloads that is auto-deleted |
352 // on destruction. | 610 // on destruction. |
353 bool CreateDownloadDirectory(Profile* profile) { | 611 bool CreateDownloadDirectory(Profile* profile) { |
354 bool created = downloads_directory_.CreateUniqueTempDir(); | 612 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()); | 759 EXPECT_EQ(1, tabbed_browser->tab_count()); |
502 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); | 760 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); |
503 tabbed_browser->CloseWindow(); | 761 tabbed_browser->CloseWindow(); |
504 #endif | 762 #endif |
505 | 763 |
506 EXPECT_EQ(1, panel_browser->tab_count()); | 764 EXPECT_EQ(1, panel_browser->tab_count()); |
507 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); | 765 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); |
508 | 766 |
509 panel_browser->CloseWindow(); | 767 panel_browser->CloseWindow(); |
510 } | 768 } |
OLD | NEW |