OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/message_loop/message_loop.h" | |
6 #include "build/build_config.h" | |
7 #include "chrome/browser/chrome_notification_types.h" | |
8 #include "chrome/browser/ui/panels/base_panel_browser_test.h" | |
9 #include "chrome/browser/ui/panels/detached_panel_collection.h" | |
10 #include "chrome/browser/ui/panels/docked_panel_collection.h" | |
11 #include "chrome/browser/ui/panels/native_panel.h" | |
12 #include "chrome/browser/ui/panels/panel.h" | |
13 #include "chrome/browser/ui/panels/panel_drag_controller.h" | |
14 #include "chrome/browser/ui/panels/panel_manager.h" | |
15 #include "chrome/browser/ui/panels/stacked_panel_collection.h" | |
16 #include "chrome/browser/ui/panels/test_panel_collection_squeeze_observer.h" | |
17 #include "content/public/browser/notification_service.h" | |
18 #include "content/public/test/test_utils.h" | |
19 | |
20 class PanelDragBrowserTest : public BasePanelBrowserTest { | |
21 public: | |
22 void SetUpOnMainThread() override { | |
23 BasePanelBrowserTest::SetUpOnMainThread(); | |
24 | |
25 // All the tests here assume using mocked 800x600 display area for the | |
26 // primary monitor. Do the check now. | |
27 gfx::Rect primary_display_area = PanelManager::GetInstance()-> | |
28 display_settings_provider()->GetPrimaryDisplayArea(); | |
29 DCHECK(primary_display_area.width() == 800); | |
30 DCHECK(primary_display_area.height() == 600); | |
31 } | |
32 | |
33 // Drag |panel| from its origin by the offset |delta|. | |
34 void DragPanelByDelta(Panel* panel, const gfx::Vector2d& delta) { | |
35 std::unique_ptr<NativePanelTesting> panel_testing( | |
36 CreateNativePanelTesting(panel)); | |
37 gfx::Point mouse_location(panel->GetBounds().origin()); | |
38 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
39 panel_testing->DragTitlebar(mouse_location + delta); | |
40 panel_testing->FinishDragTitlebar(); | |
41 } | |
42 | |
43 // Drag |panel| from its origin to |new_mouse_location|. | |
44 void DragPanelToMouseLocation(Panel* panel, | |
45 const gfx::Point& new_mouse_location) { | |
46 std::unique_ptr<NativePanelTesting> panel_testing( | |
47 CreateNativePanelTesting(panel)); | |
48 panel_testing->PressLeftMouseButtonTitlebar(panel->GetBounds().origin()); | |
49 panel_testing->DragTitlebar(new_mouse_location); | |
50 panel_testing->FinishDragTitlebar(); | |
51 } | |
52 | |
53 // Return the bounds of a panel given its initial bounds and the bounds of the | |
54 // panel above it. | |
55 static gfx::Rect GetStackedAtBottomPanelBounds( | |
56 const gfx::Rect& initial_bounds, | |
57 const gfx::Rect& above_bounds) { | |
58 return gfx::Rect(above_bounds.x(), | |
59 above_bounds.bottom(), | |
60 above_bounds.width(), | |
61 initial_bounds.height()); | |
62 } | |
63 | |
64 // Return the bounds of a panel given its initial bounds and the bounds of the | |
65 // panel below it. | |
66 static gfx::Rect GetStackedAtTopPanelBounds( | |
67 const gfx::Rect& initial_bounds, | |
68 const gfx::Rect& below_bounds) { | |
69 return gfx::Rect(below_bounds.x(), | |
70 below_bounds.y() - initial_bounds.height(), | |
71 initial_bounds.width(), | |
72 initial_bounds.height()); | |
73 } | |
74 | |
75 static gfx::Vector2d GetDragDeltaToRemainDocked() { | |
76 return gfx::Vector2d( | |
77 -5, | |
78 -(PanelDragController::GetDetachDockedPanelThresholdForTesting() / 2)); | |
79 } | |
80 | |
81 static gfx::Vector2d GetDragDeltaToDetach() { | |
82 return gfx::Vector2d( | |
83 -20, | |
84 -(PanelDragController::GetDetachDockedPanelThresholdForTesting() + 20)); | |
85 } | |
86 | |
87 static gfx::Vector2d GetDragDeltaToRemainDetached(Panel* panel) { | |
88 int distance = | |
89 panel->manager()->docked_collection()->work_area().bottom() - | |
90 panel->GetBounds().bottom(); | |
91 return gfx::Vector2d( | |
92 -5, | |
93 distance - | |
94 PanelDragController::GetDockDetachedPanelThresholdForTesting() * 2); | |
95 } | |
96 | |
97 static gfx::Vector2d GetDragDeltaToAttach(Panel* panel) { | |
98 int distance = | |
99 panel->manager()->docked_collection()->work_area().bottom() - | |
100 panel->GetBounds().bottom(); | |
101 return gfx::Vector2d( | |
102 -20, | |
103 distance - | |
104 PanelDragController::GetDockDetachedPanelThresholdForTesting() / 2); | |
105 } | |
106 | |
107 // Return the delta needed to drag |panel1| to stack to the bottom of | |
108 // |panel2|. | |
109 static gfx::Vector2d GetDragDeltaToStackToBottom(Panel* panel1, | |
110 Panel* panel2) { | |
111 gfx::Rect bounds1 = panel1->GetBounds(); | |
112 gfx::Rect bounds2 = panel2->GetBounds(); | |
113 return gfx::Vector2d( | |
114 bounds2.x() - bounds1.x(), | |
115 bounds2.bottom() - bounds1.y() + | |
116 PanelDragController::GetGluePanelDistanceThresholdForTesting() / 2); | |
117 } | |
118 | |
119 // Return the delta needed to drag |panel1| to unstack from the bottom of | |
120 // |panel2|. | |
121 static gfx::Vector2d GetDragDeltaToUnstackFromBottom(Panel* panel1, | |
122 Panel* panel2) { | |
123 return gfx::Vector2d( | |
124 0, PanelDragController::GetGluePanelDistanceThresholdForTesting() * 2); | |
125 } | |
126 | |
127 // Return the delta needed to drag |panel1| to stack to the top of |panel2|. | |
128 static gfx::Vector2d GetDragDeltaToStackToTop(Panel* panel1, Panel* panel2) { | |
129 gfx::Rect bounds1 = panel1->GetBounds(); | |
130 gfx::Rect bounds2 = panel2->GetBounds(); | |
131 StackedPanelCollection* stack1 = panel1->stack(); | |
132 int bottom = stack1 ? stack1->bottom_panel()->GetBounds().bottom() | |
133 : bounds1.bottom(); | |
134 return gfx::Vector2d( | |
135 bounds2.x() - bounds1.x(), | |
136 bounds2.y() - bottom - | |
137 PanelDragController::GetGluePanelDistanceThresholdForTesting() / 2); | |
138 } | |
139 | |
140 // Return the delta needed to drag |panel1| to unstack from the top of | |
141 // |panel2|. | |
142 static gfx::Vector2d GetDragDeltaToUnstackFromTop(Panel* panel1, | |
143 Panel* panel2) { | |
144 return gfx::Vector2d( | |
145 0, -PanelDragController::GetGluePanelDistanceThresholdForTesting() * 2); | |
146 } | |
147 | |
148 // Return the delta needed to drag |panel1| to snap to the left of |panel2|. | |
149 static gfx::Vector2d GetDragDeltaToSnapToLeft(Panel* panel1, | |
150 Panel* panel2) { | |
151 gfx::Rect bounds1 = panel1->GetBounds(); | |
152 gfx::Rect bounds2 = panel2->GetBounds(); | |
153 return gfx::Vector2d( | |
154 bounds2.x() - bounds1.width() - bounds1.x() - | |
155 PanelDragController::GetGluePanelDistanceThresholdForTesting() / 2, | |
156 bounds2.y() - bounds1.y() + | |
157 PanelDragController::GetGluePanelDistanceThresholdForTesting() * 2); | |
158 } | |
159 | |
160 // Return the delta needed to drag |panel1| to snap to the right of |panel2|. | |
161 static gfx::Vector2d GetDragDeltaToSnapToRight(Panel* panel1, | |
162 Panel* panel2) { | |
163 gfx::Rect bounds1 = panel1->GetBounds(); | |
164 gfx::Rect bounds2 = panel2->GetBounds(); | |
165 return gfx::Vector2d( | |
166 bounds2.right() - bounds1.x() + | |
167 PanelDragController::GetGluePanelDistanceThresholdForTesting() / 2, | |
168 bounds2.y() - bounds1.y() + | |
169 PanelDragController::GetGluePanelDistanceThresholdForTesting() * 2); | |
170 } | |
171 | |
172 // Return the delta needed to drag |panel| to unsnap from its current | |
173 // position. | |
174 static gfx::Vector2d GetDragDeltaToUnsnap(Panel* panel) { | |
175 return gfx::Vector2d( | |
176 PanelDragController::GetGluePanelDistanceThresholdForTesting() * 2, 0); | |
177 } | |
178 }; | |
179 | |
180 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragOneDockedPanel) { | |
181 static const int big_delta_x = 70; | |
182 static const int big_delta_y = 30; // Do not exceed the threshold to detach. | |
183 | |
184 Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100)); | |
185 std::unique_ptr<NativePanelTesting> panel_testing( | |
186 CreateNativePanelTesting(panel)); | |
187 gfx::Rect panel_old_bounds = panel->GetBounds(); | |
188 | |
189 // Drag left. | |
190 gfx::Point mouse_location = panel_old_bounds.origin(); | |
191 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
192 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); | |
193 | |
194 mouse_location.Offset(-big_delta_x, 0); | |
195 panel_testing->DragTitlebar(mouse_location); | |
196 gfx::Rect panel_new_bounds = panel_old_bounds; | |
197 panel_new_bounds.Offset(-big_delta_x, 0); | |
198 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); | |
199 | |
200 panel_testing->FinishDragTitlebar(); | |
201 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); | |
202 | |
203 // Drag left and cancel. | |
204 mouse_location = panel_old_bounds.origin(); | |
205 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
206 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); | |
207 | |
208 mouse_location.Offset(-big_delta_x, 0); | |
209 panel_testing->DragTitlebar(mouse_location); | |
210 panel_new_bounds = panel_old_bounds; | |
211 panel_new_bounds.Offset(-big_delta_x, 0); | |
212 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); | |
213 | |
214 panel_testing->CancelDragTitlebar(); | |
215 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); | |
216 | |
217 // Drag right. | |
218 mouse_location = panel_old_bounds.origin(); | |
219 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
220 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); | |
221 | |
222 mouse_location.Offset(big_delta_x, 0); | |
223 panel_testing->DragTitlebar(mouse_location); | |
224 panel_new_bounds = panel_old_bounds; | |
225 panel_new_bounds.Offset(big_delta_x, 0); | |
226 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); | |
227 | |
228 panel_testing->FinishDragTitlebar(); | |
229 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); | |
230 | |
231 // Drag right and up. Expect no vertical movement. | |
232 mouse_location = panel_old_bounds.origin(); | |
233 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
234 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); | |
235 | |
236 mouse_location.Offset(big_delta_x, big_delta_y); | |
237 panel_testing->DragTitlebar(mouse_location); | |
238 panel_new_bounds = panel_old_bounds; | |
239 panel_new_bounds.Offset(big_delta_x, 0); | |
240 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); | |
241 | |
242 panel_testing->FinishDragTitlebar(); | |
243 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); | |
244 | |
245 // Drag up. Expect no movement on drag. | |
246 mouse_location = panel_old_bounds.origin(); | |
247 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
248 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); | |
249 | |
250 mouse_location.Offset(0, -big_delta_y); | |
251 panel_testing->DragTitlebar(mouse_location); | |
252 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); | |
253 | |
254 panel_testing->FinishDragTitlebar(); | |
255 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); | |
256 | |
257 // Drag down. Expect no movement on drag. | |
258 mouse_location = panel_old_bounds.origin(); | |
259 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
260 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); | |
261 | |
262 mouse_location.Offset(0, big_delta_y); | |
263 panel_testing->DragTitlebar(mouse_location); | |
264 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); | |
265 | |
266 panel_testing->FinishDragTitlebar(); | |
267 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); | |
268 | |
269 PanelManager::GetInstance()->CloseAll(); | |
270 } | |
271 | |
272 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragTwoDockedPanels) { | |
273 static const gfx::Vector2d small_delta(10, 0); | |
274 | |
275 Panel* panel1 = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100)); | |
276 Panel* panel2 = CreateDockedPanel("2", gfx::Rect(0, 0, 100, 100)); | |
277 std::unique_ptr<NativePanelTesting> panel1_testing( | |
278 CreateNativePanelTesting(panel1)); | |
279 std::unique_ptr<NativePanelTesting> panel2_testing( | |
280 CreateNativePanelTesting(panel2)); | |
281 gfx::Point position1 = panel1->GetBounds().origin(); | |
282 gfx::Point position2 = panel2->GetBounds().origin(); | |
283 | |
284 // Drag right panel towards left with small delta. | |
285 // Expect no shuffle: P1 P2 | |
286 gfx::Point mouse_location = position1; | |
287 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
288 EXPECT_EQ(position1, panel1->GetBounds().origin()); | |
289 EXPECT_EQ(position2, panel2->GetBounds().origin()); | |
290 | |
291 mouse_location = mouse_location - small_delta; | |
292 panel1_testing->DragTitlebar(mouse_location); | |
293 EXPECT_EQ(mouse_location, panel1->GetBounds().origin()); | |
294 EXPECT_EQ(position2, panel2->GetBounds().origin()); | |
295 | |
296 panel1_testing->FinishDragTitlebar(); | |
297 EXPECT_EQ(position1, panel1->GetBounds().origin()); | |
298 EXPECT_EQ(position2, panel2->GetBounds().origin()); | |
299 | |
300 // Drag right panel towards left with big delta. | |
301 // Expect shuffle: P2 P1 | |
302 mouse_location = position1; | |
303 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
304 EXPECT_EQ(position1, panel1->GetBounds().origin()); | |
305 EXPECT_EQ(position2, panel2->GetBounds().origin()); | |
306 | |
307 mouse_location = position2 + gfx::Vector2d(1, 0); | |
308 panel1_testing->DragTitlebar(mouse_location); | |
309 EXPECT_EQ(mouse_location, panel1->GetBounds().origin()); | |
310 EXPECT_EQ(position1, panel2->GetBounds().origin()); | |
311 | |
312 panel1_testing->FinishDragTitlebar(); | |
313 EXPECT_EQ(position2, panel1->GetBounds().origin()); | |
314 EXPECT_EQ(position1, panel2->GetBounds().origin()); | |
315 | |
316 // Drag left panel towards right with small delta. | |
317 // Expect no shuffle: P2 P1 | |
318 mouse_location = position2; | |
319 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
320 EXPECT_EQ(position2, panel1->GetBounds().origin()); | |
321 EXPECT_EQ(position1, panel2->GetBounds().origin()); | |
322 | |
323 mouse_location += small_delta; | |
324 panel1_testing->DragTitlebar(mouse_location); | |
325 EXPECT_EQ(mouse_location, panel1->GetBounds().origin()); | |
326 EXPECT_EQ(position1, panel2->GetBounds().origin()); | |
327 | |
328 panel1_testing->FinishDragTitlebar(); | |
329 EXPECT_EQ(position2, panel1->GetBounds().origin()); | |
330 EXPECT_EQ(position1, panel2->GetBounds().origin()); | |
331 | |
332 // Drag left panel towards right with big delta. | |
333 // Expect shuffle: P1 P2 | |
334 mouse_location = position2; | |
335 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
336 EXPECT_EQ(position2, panel1->GetBounds().origin()); | |
337 EXPECT_EQ(position1, panel2->GetBounds().origin()); | |
338 | |
339 mouse_location = position1 + gfx::Vector2d(1, 0); | |
340 panel1_testing->DragTitlebar(mouse_location); | |
341 EXPECT_EQ(mouse_location, panel1->GetBounds().origin()); | |
342 EXPECT_EQ(position2, panel2->GetBounds().origin()); | |
343 | |
344 panel1_testing->FinishDragTitlebar(); | |
345 EXPECT_EQ(position1, panel1->GetBounds().origin()); | |
346 EXPECT_EQ(position2, panel2->GetBounds().origin()); | |
347 | |
348 // Drag right panel towards left with big delta and then cancel the drag. | |
349 // Expect shuffle after drag: P2 P1 | |
350 // Expect shuffle after cancel: P1 P2 | |
351 mouse_location = position1; | |
352 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
353 EXPECT_EQ(position1, panel1->GetBounds().origin()); | |
354 EXPECT_EQ(position2, panel2->GetBounds().origin()); | |
355 | |
356 mouse_location = position2 + gfx::Vector2d(1, 0); | |
357 panel1_testing->DragTitlebar(mouse_location); | |
358 EXPECT_EQ(mouse_location, panel1->GetBounds().origin()); | |
359 EXPECT_EQ(position1, panel2->GetBounds().origin()); | |
360 | |
361 panel1_testing->CancelDragTitlebar(); | |
362 EXPECT_EQ(position1, panel1->GetBounds().origin()); | |
363 EXPECT_EQ(position2, panel2->GetBounds().origin()); | |
364 | |
365 PanelManager::GetInstance()->CloseAll(); | |
366 } | |
367 | |
368 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragThreeDockedPanels) { | |
369 Panel* panel1 = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100)); | |
370 Panel* panel2 = CreateDockedPanel("2", gfx::Rect(0, 0, 100, 100)); | |
371 Panel* panel3 = CreateDockedPanel("3", gfx::Rect(0, 0, 100, 100)); | |
372 std::unique_ptr<NativePanelTesting> panel2_testing( | |
373 CreateNativePanelTesting(panel2)); | |
374 std::unique_ptr<NativePanelTesting> panel3_testing( | |
375 CreateNativePanelTesting(panel3)); | |
376 gfx::Point position1 = panel1->GetBounds().origin(); | |
377 gfx::Point position2 = panel2->GetBounds().origin(); | |
378 gfx::Point position3 = panel3->GetBounds().origin(); | |
379 | |
380 // Drag leftmost panel to become the rightmost in 2 drags. Each drag will | |
381 // shuffle one panel. | |
382 // Expect shuffle after 1st drag: P1 P3 P2 | |
383 // Expect shuffle after 2nd drag: P3 P1 P2 | |
384 gfx::Point mouse_location = position3; | |
385 panel3_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
386 EXPECT_EQ(position1, panel1->GetBounds().origin()); | |
387 EXPECT_EQ(position2, panel2->GetBounds().origin()); | |
388 EXPECT_EQ(position3, panel3->GetBounds().origin()); | |
389 | |
390 mouse_location = position2 + gfx::Vector2d(1, 0); | |
391 panel3_testing->DragTitlebar(mouse_location); | |
392 EXPECT_EQ(position1, panel1->GetBounds().origin()); | |
393 EXPECT_EQ(position3, panel2->GetBounds().origin()); | |
394 EXPECT_EQ(mouse_location, panel3->GetBounds().origin()); | |
395 | |
396 mouse_location = position1 + gfx::Vector2d(1, 0); | |
397 panel3_testing->DragTitlebar(mouse_location); | |
398 EXPECT_EQ(position2, panel1->GetBounds().origin()); | |
399 EXPECT_EQ(position3, panel2->GetBounds().origin()); | |
400 EXPECT_EQ(mouse_location, panel3->GetBounds().origin()); | |
401 | |
402 panel3_testing->FinishDragTitlebar(); | |
403 EXPECT_EQ(position2, panel1->GetBounds().origin()); | |
404 EXPECT_EQ(position3, panel2->GetBounds().origin()); | |
405 EXPECT_EQ(position1, panel3->GetBounds().origin()); | |
406 | |
407 // Drag rightmost panel to become the leftmost in 2 drags and then cancel the | |
408 // drag. Each drag will shuffle one panel and the cancellation will restore | |
409 // all panels. | |
410 // Expect shuffle after 1st drag: P1 P3 P2 | |
411 // Expect shuffle after 2nd drag: P1 P2 P3 | |
412 // Expect shuffle after cancel: P3 P1 P2 | |
413 mouse_location = position1; | |
414 panel3_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
415 EXPECT_EQ(position2, panel1->GetBounds().origin()); | |
416 EXPECT_EQ(position3, panel2->GetBounds().origin()); | |
417 EXPECT_EQ(position1, panel3->GetBounds().origin()); | |
418 | |
419 mouse_location = position2 + gfx::Vector2d(1, 0); | |
420 panel3_testing->DragTitlebar(mouse_location); | |
421 EXPECT_EQ(position1, panel1->GetBounds().origin()); | |
422 EXPECT_EQ(position3, panel2->GetBounds().origin()); | |
423 EXPECT_EQ(mouse_location, panel3->GetBounds().origin()); | |
424 | |
425 mouse_location = position3 + gfx::Vector2d(1, 0); | |
426 panel3_testing->DragTitlebar(mouse_location); | |
427 EXPECT_EQ(position1, panel1->GetBounds().origin()); | |
428 EXPECT_EQ(position2, panel2->GetBounds().origin()); | |
429 EXPECT_EQ(mouse_location, panel3->GetBounds().origin()); | |
430 | |
431 panel3_testing->CancelDragTitlebar(); | |
432 EXPECT_EQ(position2, panel1->GetBounds().origin()); | |
433 EXPECT_EQ(position3, panel2->GetBounds().origin()); | |
434 EXPECT_EQ(position1, panel3->GetBounds().origin()); | |
435 | |
436 // Drag leftmost panel to become the rightmost in a single drag. The drag will | |
437 // shuffle 2 panels at a time. | |
438 // Expect shuffle: P2 P3 P1 | |
439 mouse_location = position3; | |
440 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
441 EXPECT_EQ(position2, panel1->GetBounds().origin()); | |
442 EXPECT_EQ(position3, panel2->GetBounds().origin()); | |
443 EXPECT_EQ(position1, panel3->GetBounds().origin()); | |
444 | |
445 mouse_location = position1 + gfx::Vector2d(1, 0); | |
446 panel2_testing->DragTitlebar(mouse_location); | |
447 EXPECT_EQ(position3, panel1->GetBounds().origin()); | |
448 EXPECT_EQ(mouse_location, panel2->GetBounds().origin()); | |
449 EXPECT_EQ(position2, panel3->GetBounds().origin()); | |
450 | |
451 panel2_testing->FinishDragTitlebar(); | |
452 EXPECT_EQ(position3, panel1->GetBounds().origin()); | |
453 EXPECT_EQ(position1, panel2->GetBounds().origin()); | |
454 EXPECT_EQ(position2, panel3->GetBounds().origin()); | |
455 | |
456 // Drag rightmost panel to become the leftmost in a single drag. The drag will | |
457 // shuffle 2 panels at a time. | |
458 // Expect shuffle: P3 P1 P2 | |
459 mouse_location = position1; | |
460 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
461 EXPECT_EQ(position3, panel1->GetBounds().origin()); | |
462 EXPECT_EQ(position1, panel2->GetBounds().origin()); | |
463 EXPECT_EQ(position2, panel3->GetBounds().origin()); | |
464 | |
465 mouse_location = position3 + gfx::Vector2d(1, 0); | |
466 panel2_testing->DragTitlebar(mouse_location); | |
467 EXPECT_EQ(position2, panel1->GetBounds().origin()); | |
468 EXPECT_EQ(mouse_location, panel2->GetBounds().origin()); | |
469 EXPECT_EQ(position1, panel3->GetBounds().origin()); | |
470 | |
471 panel2_testing->FinishDragTitlebar(); | |
472 EXPECT_EQ(position2, panel1->GetBounds().origin()); | |
473 EXPECT_EQ(position3, panel2->GetBounds().origin()); | |
474 EXPECT_EQ(position1, panel3->GetBounds().origin()); | |
475 | |
476 // Drag rightmost panel to become the leftmost in a single drag and then | |
477 // cancel the drag. The drag will shuffle 2 panels and the cancellation will | |
478 // restore all panels. | |
479 // Expect shuffle after drag: P1 P2 P3 | |
480 // Expect shuffle after cancel: P3 P1 P2 | |
481 mouse_location = position1; | |
482 panel3_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
483 EXPECT_EQ(position2, panel1->GetBounds().origin()); | |
484 EXPECT_EQ(position3, panel2->GetBounds().origin()); | |
485 EXPECT_EQ(position1, panel3->GetBounds().origin()); | |
486 | |
487 mouse_location = position3 + gfx::Vector2d(1, 0); | |
488 panel3_testing->DragTitlebar(mouse_location); | |
489 EXPECT_EQ(position1, panel1->GetBounds().origin()); | |
490 EXPECT_EQ(position2, panel2->GetBounds().origin()); | |
491 EXPECT_EQ(mouse_location, panel3->GetBounds().origin()); | |
492 | |
493 panel3_testing->CancelDragTitlebar(); | |
494 EXPECT_EQ(position2, panel1->GetBounds().origin()); | |
495 EXPECT_EQ(position3, panel2->GetBounds().origin()); | |
496 EXPECT_EQ(position1, panel3->GetBounds().origin()); | |
497 | |
498 PanelManager::GetInstance()->CloseAll(); | |
499 } | |
500 | |
501 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragMinimizedPanel) { | |
502 Panel* panel = CreatePanel("panel1"); | |
503 std::unique_ptr<NativePanelTesting> panel_testing( | |
504 CreateNativePanelTesting(panel)); | |
505 | |
506 panel->Minimize(); | |
507 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); | |
508 | |
509 // Hover over minimized panel to bring up titlebar. | |
510 gfx::Point hover_point(panel->GetBounds().origin()); | |
511 MoveMouseAndWaitForExpansionStateChange(panel, hover_point); | |
512 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); | |
513 | |
514 // Verify we can drag a minimized panel. | |
515 gfx::Rect panel_old_bounds = panel->GetBounds(); | |
516 gfx::Point mouse_location = panel_old_bounds.origin(); | |
517 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
518 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); | |
519 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); | |
520 | |
521 mouse_location.Offset(-70, 0); | |
522 panel_testing->DragTitlebar(mouse_location); | |
523 gfx::Rect panel_new_bounds = panel_old_bounds; | |
524 panel_new_bounds.Offset(-70, 0); | |
525 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); | |
526 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); | |
527 | |
528 // Verify panel returns to fully minimized state after dragging ends once | |
529 // mouse moves away from panel. | |
530 panel_testing->FinishDragTitlebar(); | |
531 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); | |
532 | |
533 MoveMouseAndWaitForExpansionStateChange(panel, mouse_location); | |
534 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); | |
535 | |
536 panel->Close(); | |
537 } | |
538 | |
539 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, | |
540 DragMinimizedPanelWhileDrawingAttention) { | |
541 Panel* panel = CreatePanel("panel1"); | |
542 std::unique_ptr<NativePanelTesting> panel_testing( | |
543 CreateNativePanelTesting(panel)); | |
544 CreatePanel("panel2"); | |
545 | |
546 panel->Minimize(); | |
547 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); | |
548 | |
549 panel->FlashFrame(true); | |
550 EXPECT_TRUE(panel->IsDrawingAttention()); | |
551 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); | |
552 | |
553 // Drag the panel. Verify panel stays in title-only state after attention is | |
554 // cleared because it is being dragged. | |
555 gfx::Rect panel_old_bounds = panel->GetBounds(); | |
556 gfx::Point mouse_location = panel_old_bounds.origin(); | |
557 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
558 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); | |
559 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); | |
560 | |
561 mouse_location.Offset(-70, 0); | |
562 panel_testing->DragTitlebar(mouse_location); | |
563 gfx::Rect panel_new_bounds = panel_old_bounds; | |
564 panel_new_bounds.Offset(-70, 0); | |
565 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); | |
566 | |
567 panel->FlashFrame(false); | |
568 EXPECT_FALSE(panel->IsDrawingAttention()); | |
569 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); | |
570 | |
571 // Typical user scenario will detect the mouse in the panel | |
572 // after attention is cleared, causing titles to pop up, so | |
573 // we simulate that here. | |
574 MoveMouse(mouse_location); | |
575 | |
576 // Verify panel returns to fully minimized state after dragging ends once | |
577 // mouse moves away from the panel. | |
578 panel_testing->FinishDragTitlebar(); | |
579 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); | |
580 | |
581 mouse_location.Offset(0, -50); | |
582 MoveMouseAndWaitForExpansionStateChange(panel, mouse_location); | |
583 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); | |
584 | |
585 PanelManager::GetInstance()->CloseAll(); | |
586 } | |
587 | |
588 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, CloseDockedPanelOnDrag) { | |
589 PanelManager* panel_manager = PanelManager::GetInstance(); | |
590 PanelDragController* drag_controller = panel_manager->drag_controller(); | |
591 DockedPanelCollection* docked_collection = panel_manager->docked_collection(); | |
592 | |
593 // Create 4 docked panels. | |
594 // We have: P4 P3 P2 P1 | |
595 Panel* panel1 = CreatePanelWithBounds("Panel1", gfx::Rect(0, 0, 100, 100)); | |
596 Panel* panel2 = CreatePanelWithBounds("Panel2", gfx::Rect(0, 0, 100, 100)); | |
597 Panel* panel3 = CreatePanelWithBounds("Panel3", gfx::Rect(0, 0, 100, 100)); | |
598 Panel* panel4 = CreatePanelWithBounds("Panel4", gfx::Rect(0, 0, 100, 100)); | |
599 ASSERT_EQ(4, docked_collection->num_panels()); | |
600 | |
601 std::unique_ptr<NativePanelTesting> panel1_testing( | |
602 CreateNativePanelTesting(panel1)); | |
603 gfx::Point position1 = panel1->GetBounds().origin(); | |
604 gfx::Point position2 = panel2->GetBounds().origin(); | |
605 gfx::Point position3 = panel3->GetBounds().origin(); | |
606 | |
607 // Test the scenario: drag a panel, close another panel, cancel the drag. | |
608 { | |
609 std::vector<Panel*> panels; | |
610 gfx::Point panel1_new_position = position1; | |
611 panel1_new_position.Offset(-500, 0); | |
612 | |
613 // Start dragging a panel. | |
614 // We have: P1* P4 P3 P2 | |
615 gfx::Point mouse_location = panel1->GetBounds().origin(); | |
616 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
617 mouse_location.Offset(-500, -5); | |
618 panel1_testing->DragTitlebar(mouse_location); | |
619 EXPECT_TRUE(drag_controller->is_dragging()); | |
620 EXPECT_EQ(panel1, drag_controller->dragging_panel()); | |
621 | |
622 ASSERT_EQ(4, docked_collection->num_panels()); | |
623 panels = PanelManager::GetInstance()->panels(); | |
624 EXPECT_EQ(panel2, panels[0]); | |
625 EXPECT_EQ(panel3, panels[1]); | |
626 EXPECT_EQ(panel4, panels[2]); | |
627 EXPECT_EQ(panel1, panels[3]); | |
628 EXPECT_EQ(position1, panel2->GetBounds().origin()); | |
629 EXPECT_EQ(position2, panel3->GetBounds().origin()); | |
630 EXPECT_EQ(position3, panel4->GetBounds().origin()); | |
631 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); | |
632 | |
633 // Closing another panel while dragging in progress will keep the dragging | |
634 // panel intact. | |
635 // We have: P1* P4 P3 | |
636 CloseWindowAndWait(panel2); | |
637 EXPECT_TRUE(drag_controller->is_dragging()); | |
638 EXPECT_EQ(panel1, drag_controller->dragging_panel()); | |
639 | |
640 ASSERT_EQ(3, docked_collection->num_panels()); | |
641 panels = PanelManager::GetInstance()->panels(); | |
642 EXPECT_EQ(panel3, panels[0]); | |
643 EXPECT_EQ(panel4, panels[1]); | |
644 EXPECT_EQ(panel1, panels[2]); | |
645 EXPECT_EQ(position1, panel3->GetBounds().origin()); | |
646 EXPECT_EQ(position2, panel4->GetBounds().origin()); | |
647 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); | |
648 | |
649 // Cancel the drag. | |
650 // We have: P4 P3 P1 | |
651 panel1_testing->CancelDragTitlebar(); | |
652 EXPECT_FALSE(drag_controller->is_dragging()); | |
653 | |
654 ASSERT_EQ(3, docked_collection->num_panels()); | |
655 panels = PanelManager::GetInstance()->panels(); | |
656 EXPECT_EQ(panel1, panels[0]); | |
657 EXPECT_EQ(panel3, panels[1]); | |
658 EXPECT_EQ(panel4, panels[2]); | |
659 EXPECT_EQ(position1, panel1->GetBounds().origin()); | |
660 EXPECT_EQ(position2, panel3->GetBounds().origin()); | |
661 EXPECT_EQ(position3, panel4->GetBounds().origin()); | |
662 } | |
663 | |
664 // Test the scenario: drag a panel, close another panel, end the drag. | |
665 { | |
666 std::vector<Panel*> panels; | |
667 gfx::Point panel1_new_position = position1; | |
668 panel1_new_position.Offset(-500, 0); | |
669 | |
670 // Start dragging a panel. | |
671 // We have: P1* P4 P3 | |
672 gfx::Point mouse_location = panel1->GetBounds().origin(); | |
673 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
674 mouse_location.Offset(-500, -5); | |
675 panel1_testing->DragTitlebar(mouse_location); | |
676 EXPECT_TRUE(drag_controller->is_dragging()); | |
677 EXPECT_EQ(panel1, drag_controller->dragging_panel()); | |
678 | |
679 ASSERT_EQ(3, docked_collection->num_panels()); | |
680 panels = PanelManager::GetInstance()->panels(); | |
681 EXPECT_EQ(panel3, panels[0]); | |
682 EXPECT_EQ(panel4, panels[1]); | |
683 EXPECT_EQ(panel1, panels[2]); | |
684 EXPECT_EQ(position1, panel3->GetBounds().origin()); | |
685 EXPECT_EQ(position2, panel4->GetBounds().origin()); | |
686 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); | |
687 | |
688 // Closing another panel while dragging in progress will keep the dragging | |
689 // panel intact. | |
690 // We have: P1* P4 | |
691 CloseWindowAndWait(panel3); | |
692 EXPECT_TRUE(drag_controller->is_dragging()); | |
693 EXPECT_EQ(panel1, drag_controller->dragging_panel()); | |
694 | |
695 ASSERT_EQ(2, docked_collection->num_panels()); | |
696 panels = PanelManager::GetInstance()->panels(); | |
697 EXPECT_EQ(panel4, panels[0]); | |
698 EXPECT_EQ(panel1, panels[1]); | |
699 EXPECT_EQ(position1, panel4->GetBounds().origin()); | |
700 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); | |
701 | |
702 // Finish the drag. | |
703 // We have: P1 P4 | |
704 panel1_testing->FinishDragTitlebar(); | |
705 EXPECT_FALSE(drag_controller->is_dragging()); | |
706 | |
707 ASSERT_EQ(2, docked_collection->num_panels()); | |
708 panels = PanelManager::GetInstance()->panels(); | |
709 EXPECT_EQ(panel4, panels[0]); | |
710 EXPECT_EQ(panel1, panels[1]); | |
711 EXPECT_EQ(position1, panel4->GetBounds().origin()); | |
712 EXPECT_EQ(position2, panel1->GetBounds().origin()); | |
713 } | |
714 | |
715 // Test the scenario: drag a panel and close the dragging panel. | |
716 { | |
717 std::vector<Panel*> panels; | |
718 gfx::Point panel1_new_position = position2; | |
719 panel1_new_position.Offset(-500, 0); | |
720 | |
721 // Start dragging a panel again. | |
722 // We have: P1* P4 | |
723 gfx::Point mouse_location = panel1->GetBounds().origin(); | |
724 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
725 mouse_location.Offset(-500, -5); | |
726 panel1_testing->DragTitlebar(mouse_location); | |
727 EXPECT_TRUE(drag_controller->is_dragging()); | |
728 EXPECT_EQ(panel1, drag_controller->dragging_panel()); | |
729 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); | |
730 | |
731 ASSERT_EQ(2, docked_collection->num_panels()); | |
732 panels = PanelManager::GetInstance()->panels(); | |
733 EXPECT_EQ(panel4, panels[0]); | |
734 EXPECT_EQ(panel1, panels[1]); | |
735 EXPECT_EQ(position1, panel4->GetBounds().origin()); | |
736 | |
737 // Closing the dragging panel should make the drag controller abort. | |
738 // We have: P4 | |
739 content::WindowedNotificationObserver signal( | |
740 chrome::NOTIFICATION_PANEL_CLOSED, content::Source<Panel>(panel1)); | |
741 panel1->Close(); | |
742 EXPECT_FALSE(drag_controller->is_dragging()); | |
743 | |
744 // Continue the drag to ensure the drag controller does not crash. | |
745 panel1_new_position.Offset(20, 30); | |
746 panel1_testing->DragTitlebar(panel1_new_position); | |
747 panel1_testing->FinishDragTitlebar(); | |
748 | |
749 // Wait till the panel is fully closed. | |
750 signal.Wait(); | |
751 ASSERT_EQ(1, docked_collection->num_panels()); | |
752 panels = PanelManager::GetInstance()->panels(); | |
753 EXPECT_EQ(panel4, panels[0]); | |
754 EXPECT_EQ(position1, panel4->GetBounds().origin()); | |
755 } | |
756 | |
757 panel_manager->CloseAll(); | |
758 } | |
759 | |
760 // http://crbug.com/175760; several panel tests failing regularly on mac. | |
761 #if defined(OS_MACOSX) | |
762 #define MAYBE_DragOneDetachedPanel DISABLED_DragOneDetachedPanel | |
763 #else | |
764 #define MAYBE_DragOneDetachedPanel DragOneDetachedPanel | |
765 #endif | |
766 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, MAYBE_DragOneDetachedPanel) { | |
767 Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200)); | |
768 | |
769 // Test that the detached panel can be dragged almost anywhere except getting | |
770 // close to the bottom of the docked area to trigger the attach. | |
771 std::unique_ptr<NativePanelTesting> panel_testing( | |
772 CreateNativePanelTesting(panel)); | |
773 gfx::Point origin = panel->GetBounds().origin(); | |
774 | |
775 panel_testing->PressLeftMouseButtonTitlebar(origin); | |
776 EXPECT_EQ(origin, panel->GetBounds().origin()); | |
777 | |
778 origin.Offset(-51, -102); | |
779 panel_testing->DragTitlebar(origin); | |
780 EXPECT_EQ(origin, panel->GetBounds().origin()); | |
781 | |
782 origin.Offset(37, 45); | |
783 panel_testing->DragTitlebar(origin); | |
784 EXPECT_EQ(origin, panel->GetBounds().origin()); | |
785 | |
786 panel_testing->FinishDragTitlebar(); | |
787 EXPECT_EQ(origin, panel->GetBounds().origin()); | |
788 | |
789 // Test that cancelling the drag will return the panel the the original | |
790 // position. | |
791 gfx::Point original_position = panel->GetBounds().origin(); | |
792 origin = original_position; | |
793 | |
794 panel_testing->PressLeftMouseButtonTitlebar(origin); | |
795 EXPECT_EQ(origin, panel->GetBounds().origin()); | |
796 | |
797 origin.Offset(-51, -102); | |
798 panel_testing->DragTitlebar(origin); | |
799 EXPECT_EQ(origin, panel->GetBounds().origin()); | |
800 | |
801 origin.Offset(37, 45); | |
802 panel_testing->DragTitlebar(origin); | |
803 EXPECT_EQ(origin, panel->GetBounds().origin()); | |
804 | |
805 panel_testing->CancelDragTitlebar(); | |
806 WaitForBoundsAnimationFinished(panel); | |
807 EXPECT_EQ(original_position, panel->GetBounds().origin()); | |
808 | |
809 PanelManager::GetInstance()->CloseAll(); | |
810 } | |
811 | |
812 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, CloseDetachedPanelOnDrag) { | |
813 PanelManager* panel_manager = PanelManager::GetInstance(); | |
814 PanelDragController* drag_controller = panel_manager->drag_controller(); | |
815 DetachedPanelCollection* detached_collection = | |
816 panel_manager->detached_collection(); | |
817 | |
818 // Create 1 detached panel. | |
819 Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(100, 200, 100, 100)); | |
820 ASSERT_EQ(1, detached_collection->num_panels()); | |
821 | |
822 std::unique_ptr<NativePanelTesting> panel1_testing( | |
823 CreateNativePanelTesting(panel1)); | |
824 gfx::Point panel1_old_position = panel1->GetBounds().origin(); | |
825 | |
826 // Test the scenario: drag a panel, close another panel, cancel the drag. | |
827 { | |
828 // Create a panel to be closed. | |
829 Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(300, 210, 110, 110)); | |
830 | |
831 // Start dragging a panel. | |
832 panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); | |
833 gfx::Point panel1_new_position = panel1_old_position; | |
834 panel1_new_position.Offset(-51, -102); | |
835 panel1_testing->DragTitlebar(panel1_new_position); | |
836 EXPECT_TRUE(drag_controller->is_dragging()); | |
837 EXPECT_EQ(panel1, drag_controller->dragging_panel()); | |
838 | |
839 ASSERT_EQ(2, detached_collection->num_panels()); | |
840 EXPECT_TRUE(detached_collection->HasPanel(panel1)); | |
841 EXPECT_TRUE(detached_collection->HasPanel(panel2)); | |
842 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); | |
843 | |
844 // Closing another panel while dragging in progress will keep the dragging | |
845 // panel intact. | |
846 CloseWindowAndWait(panel2); | |
847 EXPECT_TRUE(drag_controller->is_dragging()); | |
848 EXPECT_EQ(panel1, drag_controller->dragging_panel()); | |
849 | |
850 ASSERT_EQ(1, detached_collection->num_panels()); | |
851 EXPECT_TRUE(detached_collection->HasPanel(panel1)); | |
852 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); | |
853 | |
854 // Cancel the drag. | |
855 panel1_testing->CancelDragTitlebar(); | |
856 WaitForBoundsAnimationFinished(panel1); | |
857 EXPECT_FALSE(drag_controller->is_dragging()); | |
858 EXPECT_EQ(panel1_old_position, panel1->GetBounds().origin()); | |
859 } | |
860 | |
861 // Test the scenario: drag a panel, close another panel, end the drag. | |
862 { | |
863 // Create a panel to be closed. | |
864 Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(300, 210, 110, 110)); | |
865 | |
866 // Start dragging a panel. | |
867 panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); | |
868 gfx::Point panel1_new_position = panel1_old_position; | |
869 panel1_new_position.Offset(-51, -102); | |
870 panel1_testing->DragTitlebar(panel1_new_position); | |
871 EXPECT_TRUE(drag_controller->is_dragging()); | |
872 EXPECT_EQ(panel1, drag_controller->dragging_panel()); | |
873 | |
874 ASSERT_EQ(2, detached_collection->num_panels()); | |
875 EXPECT_TRUE(detached_collection->HasPanel(panel1)); | |
876 EXPECT_TRUE(detached_collection->HasPanel(panel2)); | |
877 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); | |
878 | |
879 // Closing another panel while dragging in progress will keep the dragging | |
880 // panel intact. | |
881 CloseWindowAndWait(panel2); | |
882 EXPECT_TRUE(drag_controller->is_dragging()); | |
883 EXPECT_EQ(panel1, drag_controller->dragging_panel()); | |
884 | |
885 ASSERT_EQ(1, detached_collection->num_panels()); | |
886 EXPECT_TRUE(detached_collection->HasPanel(panel1)); | |
887 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); | |
888 | |
889 // Finish the drag. | |
890 panel1_testing->FinishDragTitlebar(); | |
891 EXPECT_FALSE(drag_controller->is_dragging()); | |
892 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); | |
893 } | |
894 | |
895 // Test the scenario: drag a panel and close the dragging panel. | |
896 { | |
897 // Start dragging a panel again. | |
898 panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); | |
899 gfx::Point panel1_new_position = panel1->GetBounds().origin(); | |
900 panel1_new_position.Offset(45, 67); | |
901 panel1_testing->DragTitlebar(panel1_new_position); | |
902 EXPECT_TRUE(drag_controller->is_dragging()); | |
903 EXPECT_EQ(panel1, drag_controller->dragging_panel()); | |
904 | |
905 ASSERT_EQ(1, detached_collection->num_panels()); | |
906 EXPECT_TRUE(detached_collection->HasPanel(panel1)); | |
907 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); | |
908 | |
909 // Closing the dragging panel should make the drag controller abort. | |
910 content::WindowedNotificationObserver signal( | |
911 chrome::NOTIFICATION_PANEL_CLOSED, content::Source<Panel>(panel1)); | |
912 panel1->Close(); | |
913 EXPECT_FALSE(drag_controller->is_dragging()); | |
914 | |
915 // Continue the drag to ensure the drag controller does not crash. | |
916 panel1_new_position.Offset(20, 30); | |
917 panel1_testing->DragTitlebar(panel1_new_position); | |
918 panel1_testing->FinishDragTitlebar(); | |
919 | |
920 // Wait till the panel is fully closed. | |
921 signal.Wait(); | |
922 ASSERT_EQ(0, detached_collection->num_panels()); | |
923 } | |
924 } | |
925 | |
926 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, Detach) { | |
927 PanelManager* panel_manager = PanelManager::GetInstance(); | |
928 DockedPanelCollection* docked_collection = panel_manager->docked_collection(); | |
929 DetachedPanelCollection* detached_collection = | |
930 panel_manager->detached_collection(); | |
931 | |
932 // Create one docked panel. | |
933 Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100)); | |
934 ASSERT_EQ(1, docked_collection->num_panels()); | |
935 ASSERT_EQ(0, detached_collection->num_panels()); | |
936 | |
937 gfx::Rect panel_old_bounds = panel->GetBounds(); | |
938 | |
939 // Press on title-bar. | |
940 std::unique_ptr<NativePanelTesting> panel_testing( | |
941 CreateNativePanelTesting(panel)); | |
942 gfx::Point mouse_location(panel->GetBounds().origin()); | |
943 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
944 | |
945 // Drag up the panel in a small offset that does not trigger the detach. | |
946 // Expect that the panel is still docked and only x coordinate of its position | |
947 // is changed. | |
948 gfx::Vector2d drag_delta_to_remain_docked = GetDragDeltaToRemainDocked(); | |
949 mouse_location += drag_delta_to_remain_docked; | |
950 panel_testing->DragTitlebar(mouse_location); | |
951 ASSERT_EQ(1, docked_collection->num_panels()); | |
952 ASSERT_EQ(0, detached_collection->num_panels()); | |
953 EXPECT_EQ(PanelCollection::DOCKED, panel->collection()->type()); | |
954 gfx::Rect panel_new_bounds = panel_old_bounds; | |
955 panel_new_bounds.Offset(drag_delta_to_remain_docked.x(), 0); | |
956 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); | |
957 | |
958 // Continue dragging up the panel in big offset that triggers the detach. | |
959 // Expect that the panel is previewed as detached. | |
960 gfx::Vector2d drag_delta_to_detach = GetDragDeltaToDetach(); | |
961 mouse_location += drag_delta_to_detach; | |
962 panel_testing->DragTitlebar(mouse_location); | |
963 ASSERT_EQ(0, docked_collection->num_panels()); | |
964 ASSERT_EQ(1, detached_collection->num_panels()); | |
965 EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type()); | |
966 panel_new_bounds.Offset( | |
967 drag_delta_to_detach.x(), | |
968 drag_delta_to_detach.y() + drag_delta_to_remain_docked.y()); | |
969 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); | |
970 | |
971 // Finish the drag. | |
972 // Expect that the panel stays as detached. | |
973 panel_testing->FinishDragTitlebar(); | |
974 ASSERT_EQ(0, docked_collection->num_panels()); | |
975 ASSERT_EQ(1, detached_collection->num_panels()); | |
976 EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type()); | |
977 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); | |
978 | |
979 panel_manager->CloseAll(); | |
980 } | |
981 | |
982 // http://crbug.com/175760; several panel tests failing regularly on mac. | |
983 #if defined(OS_MACOSX) | |
984 #define MAYBE_DetachAndCancel DISABLED_DetachAndCancel | |
985 #else | |
986 #define MAYBE_DetachAndCancel DetachAndCancel | |
987 #endif | |
988 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, MAYBE_DetachAndCancel) { | |
989 PanelManager* panel_manager = PanelManager::GetInstance(); | |
990 DockedPanelCollection* docked_collection = panel_manager->docked_collection(); | |
991 DetachedPanelCollection* detached_collection = | |
992 panel_manager->detached_collection(); | |
993 | |
994 // Create one docked panel. | |
995 Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100)); | |
996 ASSERT_EQ(1, docked_collection->num_panels()); | |
997 ASSERT_EQ(0, detached_collection->num_panels()); | |
998 | |
999 gfx::Rect panel_old_bounds = panel->GetBounds(); | |
1000 | |
1001 // Press on title-bar. | |
1002 std::unique_ptr<NativePanelTesting> panel_testing( | |
1003 CreateNativePanelTesting(panel)); | |
1004 gfx::Point mouse_location(panel->GetBounds().origin()); | |
1005 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
1006 | |
1007 // Drag up the panel in a small offset that does not trigger the detach. | |
1008 // Expect that the panel is still docked and only x coordinate of its position | |
1009 // is changed. | |
1010 gfx::Vector2d drag_delta_to_remain_docked = GetDragDeltaToRemainDocked(); | |
1011 mouse_location += drag_delta_to_remain_docked; | |
1012 panel_testing->DragTitlebar(mouse_location); | |
1013 ASSERT_EQ(1, docked_collection->num_panels()); | |
1014 ASSERT_EQ(0, detached_collection->num_panels()); | |
1015 EXPECT_EQ(PanelCollection::DOCKED, panel->collection()->type()); | |
1016 gfx::Rect panel_new_bounds = panel_old_bounds; | |
1017 panel_new_bounds.Offset(drag_delta_to_remain_docked.x(), 0); | |
1018 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); | |
1019 | |
1020 // Continue dragging up the panel in big offset that triggers the detach. | |
1021 // Expect that the panel is previewed as detached. | |
1022 gfx::Vector2d drag_delta_to_detach = GetDragDeltaToDetach(); | |
1023 mouse_location += drag_delta_to_detach; | |
1024 panel_testing->DragTitlebar(mouse_location); | |
1025 ASSERT_EQ(0, docked_collection->num_panels()); | |
1026 ASSERT_EQ(1, detached_collection->num_panels()); | |
1027 EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type()); | |
1028 panel_new_bounds.Offset( | |
1029 drag_delta_to_detach.x(), | |
1030 drag_delta_to_detach.y() + drag_delta_to_remain_docked.y()); | |
1031 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); | |
1032 | |
1033 // Cancel the drag. | |
1034 // Expect that the panel is back as docked. | |
1035 panel_testing->CancelDragTitlebar(); | |
1036 ASSERT_EQ(1, docked_collection->num_panels()); | |
1037 ASSERT_EQ(0, detached_collection->num_panels()); | |
1038 EXPECT_EQ(PanelCollection::DOCKED, panel->collection()->type()); | |
1039 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); | |
1040 | |
1041 panel_manager->CloseAll(); | |
1042 } | |
1043 | |
1044 // http://crbug.com/175760; several panel tests failing regularly on mac. | |
1045 #if defined(OS_MACOSX) | |
1046 #define MAYBE_Attach DISABLED_Attach | |
1047 #else | |
1048 #define MAYBE_Attach Attach | |
1049 #endif | |
1050 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, MAYBE_Attach) { | |
1051 PanelManager* panel_manager = PanelManager::GetInstance(); | |
1052 DockedPanelCollection* docked_collection = panel_manager->docked_collection(); | |
1053 DetachedPanelCollection* detached_collection = | |
1054 panel_manager->detached_collection(); | |
1055 | |
1056 // Create one detached panel. | |
1057 Panel* panel = CreateDetachedPanel("1", gfx::Rect(400, 300, 100, 100)); | |
1058 ASSERT_EQ(0, docked_collection->num_panels()); | |
1059 ASSERT_EQ(1, detached_collection->num_panels()); | |
1060 EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type()); | |
1061 | |
1062 gfx::Rect panel_old_bounds = panel->GetBounds(); | |
1063 | |
1064 // Press on title-bar. | |
1065 std::unique_ptr<NativePanelTesting> panel_testing( | |
1066 CreateNativePanelTesting(panel)); | |
1067 gfx::Point mouse_location(panel->GetBounds().origin()); | |
1068 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
1069 | |
1070 // Drag down the panel but not close enough to the bottom of work area. | |
1071 // Expect that the panel is still detached. | |
1072 gfx::Vector2d drag_delta_to_remain_detached = | |
1073 GetDragDeltaToRemainDetached(panel); | |
1074 mouse_location += drag_delta_to_remain_detached; | |
1075 panel_testing->DragTitlebar(mouse_location); | |
1076 ASSERT_EQ(0, docked_collection->num_panels()); | |
1077 ASSERT_EQ(1, detached_collection->num_panels()); | |
1078 EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type()); | |
1079 gfx::Rect panel_new_bounds = panel_old_bounds; | |
1080 panel_new_bounds.Offset(drag_delta_to_remain_detached); | |
1081 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); | |
1082 | |
1083 // Continue dragging down the panel to make it close enough to the bottom of | |
1084 // work area. | |
1085 // Expect that the panel is previewed as docked. | |
1086 gfx::Vector2d drag_delta_to_attach = GetDragDeltaToAttach(panel); | |
1087 mouse_location += drag_delta_to_attach; | |
1088 panel_testing->DragTitlebar(mouse_location); | |
1089 ASSERT_EQ(1, docked_collection->num_panels()); | |
1090 ASSERT_EQ(0, detached_collection->num_panels()); | |
1091 EXPECT_EQ(PanelCollection::DOCKED, panel->collection()->type()); | |
1092 panel_new_bounds.Offset(drag_delta_to_attach); | |
1093 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); | |
1094 | |
1095 // Finish the drag. | |
1096 // Expect that the panel stays as docked and moves to the final position. | |
1097 panel_testing->FinishDragTitlebar(); | |
1098 ASSERT_EQ(1, docked_collection->num_panels()); | |
1099 ASSERT_EQ(0, detached_collection->num_panels()); | |
1100 EXPECT_EQ(PanelCollection::DOCKED, panel->collection()->type()); | |
1101 panel_new_bounds.set_x( | |
1102 docked_collection->StartingRightPosition() - panel_new_bounds.width()); | |
1103 panel_new_bounds.set_y( | |
1104 docked_collection->work_area().bottom() - panel_new_bounds.height()); | |
1105 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); | |
1106 | |
1107 panel_manager->CloseAll(); | |
1108 } | |
1109 | |
1110 // http://crbug.com/175760; several panel tests failing regularly on mac. | |
1111 #if defined(OS_MACOSX) | |
1112 #define MAYBE_AttachAndCancel DISABLED_AttachAndCancel | |
1113 #else | |
1114 #define MAYBE_AttachAndCancel AttachAndCancel | |
1115 #endif | |
1116 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, MAYBE_AttachAndCancel) { | |
1117 PanelManager* panel_manager = PanelManager::GetInstance(); | |
1118 DockedPanelCollection* docked_collection = panel_manager->docked_collection(); | |
1119 DetachedPanelCollection* detached_collection = | |
1120 panel_manager->detached_collection(); | |
1121 | |
1122 // Create one detached panel. | |
1123 Panel* panel = CreateDetachedPanel("1", gfx::Rect(400, 300, 100, 100)); | |
1124 ASSERT_EQ(0, docked_collection->num_panels()); | |
1125 ASSERT_EQ(1, detached_collection->num_panels()); | |
1126 EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type()); | |
1127 | |
1128 gfx::Rect panel_old_bounds = panel->GetBounds(); | |
1129 | |
1130 // Press on title-bar. | |
1131 std::unique_ptr<NativePanelTesting> panel_testing( | |
1132 CreateNativePanelTesting(panel)); | |
1133 gfx::Point mouse_location(panel->GetBounds().origin()); | |
1134 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
1135 | |
1136 // Drag down the panel but not close enough to the bottom of work area. | |
1137 // Expect that the panel is still detached. | |
1138 gfx::Vector2d drag_delta_to_remain_detached = | |
1139 GetDragDeltaToRemainDetached(panel); | |
1140 mouse_location += drag_delta_to_remain_detached; | |
1141 panel_testing->DragTitlebar(mouse_location); | |
1142 ASSERT_EQ(0, docked_collection->num_panels()); | |
1143 ASSERT_EQ(1, detached_collection->num_panels()); | |
1144 EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type()); | |
1145 gfx::Rect panel_new_bounds = panel_old_bounds; | |
1146 panel_new_bounds.Offset(drag_delta_to_remain_detached); | |
1147 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); | |
1148 | |
1149 // Continue dragging down the panel to make it close enough to the bottom of | |
1150 // work area. | |
1151 // Expect that the panel is previewed as docked. | |
1152 gfx::Vector2d drag_delta_to_attach = GetDragDeltaToAttach(panel); | |
1153 mouse_location += drag_delta_to_attach; | |
1154 panel_testing->DragTitlebar(mouse_location); | |
1155 ASSERT_EQ(1, docked_collection->num_panels()); | |
1156 ASSERT_EQ(0, detached_collection->num_panels()); | |
1157 EXPECT_EQ(PanelCollection::DOCKED, panel->collection()->type()); | |
1158 panel_new_bounds.Offset(drag_delta_to_attach); | |
1159 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); | |
1160 | |
1161 // Cancel the drag. | |
1162 // Expect that the panel is back as detached. | |
1163 panel_testing->CancelDragTitlebar(); | |
1164 ASSERT_EQ(0, docked_collection->num_panels()); | |
1165 ASSERT_EQ(1, detached_collection->num_panels()); | |
1166 EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type()); | |
1167 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); | |
1168 | |
1169 panel_manager->CloseAll(); | |
1170 } | |
1171 | |
1172 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DetachAttachAndCancel) { | |
1173 PanelManager* panel_manager = PanelManager::GetInstance(); | |
1174 DockedPanelCollection* docked_collection = panel_manager->docked_collection(); | |
1175 DetachedPanelCollection* detached_collection = | |
1176 panel_manager->detached_collection(); | |
1177 | |
1178 // Create one docked panel. | |
1179 Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100)); | |
1180 ASSERT_EQ(1, docked_collection->num_panels()); | |
1181 ASSERT_EQ(0, detached_collection->num_panels()); | |
1182 | |
1183 gfx::Rect panel_old_bounds = panel->GetBounds(); | |
1184 | |
1185 // Press on title-bar. | |
1186 std::unique_ptr<NativePanelTesting> panel_testing( | |
1187 CreateNativePanelTesting(panel)); | |
1188 gfx::Point mouse_location(panel->GetBounds().origin()); | |
1189 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
1190 | |
1191 // Drag up the panel to trigger the detach. | |
1192 // Expect that the panel is previewed as detached. | |
1193 gfx::Vector2d drag_delta_to_detach = GetDragDeltaToDetach(); | |
1194 mouse_location += drag_delta_to_detach; | |
1195 panel_testing->DragTitlebar(mouse_location); | |
1196 ASSERT_EQ(0, docked_collection->num_panels()); | |
1197 ASSERT_EQ(1, detached_collection->num_panels()); | |
1198 EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type()); | |
1199 gfx::Rect panel_new_bounds = panel_old_bounds; | |
1200 panel_new_bounds.Offset(drag_delta_to_detach); | |
1201 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); | |
1202 | |
1203 // Continue dragging down the panel to trigger the re-attach. | |
1204 gfx::Vector2d drag_delta_to_reattach = GetDragDeltaToAttach(panel); | |
1205 mouse_location += drag_delta_to_reattach; | |
1206 panel_testing->DragTitlebar(mouse_location); | |
1207 ASSERT_EQ(1, docked_collection->num_panels()); | |
1208 ASSERT_EQ(0, detached_collection->num_panels()); | |
1209 EXPECT_EQ(PanelCollection::DOCKED, panel->collection()->type()); | |
1210 panel_new_bounds.Offset(drag_delta_to_reattach); | |
1211 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); | |
1212 | |
1213 // Continue dragging up the panel to trigger the detach again. | |
1214 gfx::Vector2d drag_delta_to_detach_again = GetDragDeltaToDetach(); | |
1215 mouse_location += drag_delta_to_detach_again; | |
1216 panel_testing->DragTitlebar(mouse_location); | |
1217 ASSERT_EQ(0, docked_collection->num_panels()); | |
1218 ASSERT_EQ(1, detached_collection->num_panels()); | |
1219 EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type()); | |
1220 panel_new_bounds.Offset(drag_delta_to_detach_again); | |
1221 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); | |
1222 | |
1223 // Cancel the drag. | |
1224 // Expect that the panel stays as docked. | |
1225 panel_testing->CancelDragTitlebar(); | |
1226 ASSERT_EQ(1, docked_collection->num_panels()); | |
1227 ASSERT_EQ(0, detached_collection->num_panels()); | |
1228 EXPECT_EQ(PanelCollection::DOCKED, panel->collection()->type()); | |
1229 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); | |
1230 | |
1231 panel_manager->CloseAll(); | |
1232 } | |
1233 | |
1234 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DetachWithSqueeze) { | |
1235 PanelManager* panel_manager = PanelManager::GetInstance(); | |
1236 DockedPanelCollection* docked_collection = panel_manager->docked_collection(); | |
1237 DetachedPanelCollection* detached_collection = | |
1238 panel_manager->detached_collection(); | |
1239 | |
1240 // Create some docked panels. | |
1241 // docked: P1 P2 P3 P4 P5 | |
1242 Panel* panel1 = CreateDockedPanel("1", gfx::Rect(0, 0, 200, 100)); | |
1243 Panel* panel2 = CreateDockedPanel("2", gfx::Rect(0, 0, 200, 100)); | |
1244 Panel* panel3 = CreateDockedPanel("3", gfx::Rect(0, 0, 200, 100)); | |
1245 Panel* panel4 = CreateDockedPanel("4", gfx::Rect(0, 0, 200, 100)); | |
1246 Panel* panel5 = CreateDockedPanel("5", gfx::Rect(0, 0, 200, 100)); | |
1247 ASSERT_EQ(0, detached_collection->num_panels()); | |
1248 ASSERT_EQ(5, docked_collection->num_panels()); | |
1249 | |
1250 // Drag to detach the middle docked panel. | |
1251 // Expect to have: | |
1252 // detached: P2 | |
1253 // docked: P1 P3 P4 P5 | |
1254 gfx::Point panel2_docked_position = panel2->GetBounds().origin(); | |
1255 gfx::Vector2d drag_delta_to_detach_panel2(-20, -100); | |
1256 DragPanelByDelta(panel2, drag_delta_to_detach_panel2); | |
1257 ASSERT_EQ(1, detached_collection->num_panels()); | |
1258 ASSERT_EQ(4, docked_collection->num_panels()); | |
1259 EXPECT_EQ(PanelCollection::DOCKED, panel1->collection()->type()); | |
1260 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type()); | |
1261 EXPECT_EQ(PanelCollection::DOCKED, panel3->collection()->type()); | |
1262 EXPECT_EQ(PanelCollection::DOCKED, panel4->collection()->type()); | |
1263 EXPECT_EQ(PanelCollection::DOCKED, panel5->collection()->type()); | |
1264 gfx::Point panel2_new_position = | |
1265 panel2_docked_position + drag_delta_to_detach_panel2; | |
1266 EXPECT_EQ(panel2_new_position, panel2->GetBounds().origin()); | |
1267 | |
1268 // Drag to detach the left-most docked panel. | |
1269 // Expect to have: | |
1270 // detached: P2 P4 | |
1271 // docked: P1 P3 P5 | |
1272 gfx::Point panel4_docked_position = panel4->GetBounds().origin(); | |
1273 gfx::Vector2d drag_delta_to_detach_panel4(-40, -250); | |
1274 DragPanelByDelta(panel4, drag_delta_to_detach_panel4); | |
1275 ASSERT_EQ(2, detached_collection->num_panels()); | |
1276 ASSERT_EQ(3, docked_collection->num_panels()); | |
1277 EXPECT_EQ(PanelCollection::DOCKED, panel1->collection()->type()); | |
1278 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type()); | |
1279 EXPECT_EQ(PanelCollection::DOCKED, panel3->collection()->type()); | |
1280 EXPECT_EQ(PanelCollection::DETACHED, panel4->collection()->type()); | |
1281 EXPECT_EQ(PanelCollection::DOCKED, panel5->collection()->type()); | |
1282 EXPECT_EQ(panel2_new_position, panel2->GetBounds().origin()); | |
1283 gfx::Point panel4_new_position = | |
1284 panel4_docked_position + drag_delta_to_detach_panel4; | |
1285 EXPECT_EQ(panel4_new_position, panel4->GetBounds().origin()); | |
1286 | |
1287 // Drag to detach the right-most docked panel. | |
1288 // Expect to have: | |
1289 // detached: P1 P2 P4 | |
1290 // docked: P3 P5 | |
1291 gfx::Point docked_position1 = panel1->GetBounds().origin(); | |
1292 gfx::Point docked_position2 = panel3->GetBounds().origin(); | |
1293 gfx::Vector2d drag_delta_to_detach_panel1(-60, -400); | |
1294 DragPanelByDelta(panel1, drag_delta_to_detach_panel1); | |
1295 ASSERT_EQ(3, detached_collection->num_panels()); | |
1296 ASSERT_EQ(2, docked_collection->num_panels()); | |
1297 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); | |
1298 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type()); | |
1299 EXPECT_EQ(PanelCollection::DOCKED, panel3->collection()->type()); | |
1300 EXPECT_EQ(PanelCollection::DETACHED, panel4->collection()->type()); | |
1301 EXPECT_EQ(PanelCollection::DOCKED, panel5->collection()->type()); | |
1302 gfx::Point panel1_new_position = | |
1303 docked_position1 + drag_delta_to_detach_panel1; | |
1304 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); | |
1305 EXPECT_EQ(panel2_new_position, panel2->GetBounds().origin()); | |
1306 EXPECT_EQ(panel4_new_position, panel4->GetBounds().origin()); | |
1307 | |
1308 // No more squeeze, docked panels should stay put. | |
1309 EXPECT_EQ(docked_position1, panel3->GetBounds().origin()); | |
1310 EXPECT_EQ(panel1->GetBounds().width(), panel1->GetRestoredBounds().width()); | |
1311 EXPECT_EQ(docked_position2, panel5->GetBounds().origin()); | |
1312 EXPECT_EQ(panel2->GetBounds().width(), panel2->GetRestoredBounds().width()); | |
1313 | |
1314 panel_manager->CloseAll(); | |
1315 } | |
1316 | |
1317 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, AttachWithSqueeze) { | |
1318 PanelManager* panel_manager = PanelManager::GetInstance(); | |
1319 DockedPanelCollection* docked_collection = panel_manager->docked_collection(); | |
1320 DetachedPanelCollection* detached_collection = | |
1321 panel_manager->detached_collection(); | |
1322 | |
1323 // Create some detached, docked panels. | |
1324 // detached: P1 P2 P3 | |
1325 // docked: P4 P5 P6 P7 | |
1326 Panel* panel1 = CreateInactiveDetachedPanel( | |
1327 "1", gfx::Rect(100, 300, 200, 100)); | |
1328 Panel* panel2 = CreateInactiveDetachedPanel( | |
1329 "2", gfx::Rect(200, 300, 200, 100)); | |
1330 Panel* panel3 = CreateInactiveDetachedPanel( | |
1331 "3", gfx::Rect(400, 300, 200, 100)); | |
1332 Panel* panel4 = CreateInactiveDockedPanel("4", gfx::Rect(0, 0, 200, 100)); | |
1333 Panel* panel5 = CreateInactiveDockedPanel("5", gfx::Rect(0, 0, 200, 100)); | |
1334 Panel* panel6 = CreateInactiveDockedPanel("6", gfx::Rect(0, 0, 200, 100)); | |
1335 Panel* panel7 = CreateDockedPanel("7", gfx::Rect(0, 0, 200, 100)); | |
1336 ASSERT_EQ(3, detached_collection->num_panels()); | |
1337 ASSERT_EQ(4, docked_collection->num_panels()); | |
1338 | |
1339 // Wait for active states to settle. | |
1340 PanelCollectionSqueezeObserver panel7_settled(docked_collection, panel7); | |
1341 panel7_settled.Wait(); | |
1342 | |
1343 gfx::Point detached_position1 = panel1->GetBounds().origin(); | |
1344 gfx::Point detached_position2 = panel2->GetBounds().origin(); | |
1345 gfx::Point docked_position4 = panel4->GetBounds().origin(); | |
1346 gfx::Point docked_position5 = panel5->GetBounds().origin(); | |
1347 gfx::Point docked_position6 = panel6->GetBounds().origin(); | |
1348 gfx::Point docked_position7 = panel7->GetBounds().origin(); | |
1349 | |
1350 // Drag to attach a detached panel between 2 docked panels. | |
1351 // Expect to have: | |
1352 // detached: P1 P2 | |
1353 // docked: P4 P3 P5 P6 P7 | |
1354 gfx::Point drag_to_location(panel5->GetBounds().x() + 10, | |
1355 panel5->GetBounds().y()); | |
1356 DragPanelToMouseLocation(panel3, drag_to_location); | |
1357 ASSERT_EQ(2, detached_collection->num_panels()); | |
1358 ASSERT_EQ(5, docked_collection->num_panels()); | |
1359 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); | |
1360 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type()); | |
1361 EXPECT_EQ(PanelCollection::DOCKED, panel3->collection()->type()); | |
1362 EXPECT_EQ(PanelCollection::DOCKED, panel4->collection()->type()); | |
1363 EXPECT_EQ(PanelCollection::DOCKED, panel5->collection()->type()); | |
1364 EXPECT_EQ(PanelCollection::DOCKED, panel6->collection()->type()); | |
1365 EXPECT_EQ(PanelCollection::DOCKED, panel7->collection()->type()); | |
1366 EXPECT_EQ(detached_position1, panel1->GetBounds().origin()); | |
1367 EXPECT_EQ(detached_position2, panel2->GetBounds().origin()); | |
1368 | |
1369 // Wait for active states to settle. | |
1370 base::MessageLoopForUI::current()->RunUntilIdle(); | |
1371 | |
1372 // Panel positions should have shifted because of the "squeeze" mode. | |
1373 EXPECT_NE(docked_position4, panel4->GetBounds().origin()); | |
1374 EXPECT_LT(panel4->GetBounds().width(), panel4->GetRestoredBounds().width()); | |
1375 EXPECT_NE(docked_position5, panel5->GetBounds().origin()); | |
1376 EXPECT_LT(panel5->GetBounds().width(), panel5->GetRestoredBounds().width()); | |
1377 | |
1378 #if defined(OS_WIN) | |
1379 // The panel we dragged becomes the active one. | |
1380 EXPECT_EQ(true, panel3->IsActive()); | |
1381 EXPECT_EQ(panel3->GetBounds().width(), panel3->GetRestoredBounds().width()); | |
1382 | |
1383 EXPECT_NE(docked_position6, panel6->GetBounds().origin()); | |
1384 #else | |
1385 // The last panel is active so these positions do not change. | |
1386 // TODO (ABurago) this is wrong behavior, a panel should activate | |
1387 // when it is dragged (it does in real usage, but not when drag is | |
1388 // simulated in a test). Change this test when the behavior is fixed. | |
1389 EXPECT_EQ(true, panel7->IsActive()); | |
1390 EXPECT_EQ(panel7->GetBounds().width(), panel7->GetRestoredBounds().width()); | |
1391 | |
1392 EXPECT_EQ(docked_position6, panel6->GetBounds().origin()); | |
1393 #endif | |
1394 EXPECT_EQ(docked_position7, panel7->GetBounds().origin()); | |
1395 | |
1396 // Drag to attach a detached panel to most-right. | |
1397 // Expect to have: | |
1398 // detached: P1 | |
1399 // docked: P2 P4 P3 P5 P6 P7 | |
1400 gfx::Point drag_to_location2(panel4->GetBounds().right() + 10, | |
1401 panel4->GetBounds().y()); | |
1402 DragPanelToMouseLocation(panel2, drag_to_location2); | |
1403 ASSERT_EQ(1, detached_collection->num_panels()); | |
1404 ASSERT_EQ(6, docked_collection->num_panels()); | |
1405 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); | |
1406 EXPECT_EQ(PanelCollection::DOCKED, panel2->collection()->type()); | |
1407 EXPECT_EQ(PanelCollection::DOCKED, panel3->collection()->type()); | |
1408 EXPECT_EQ(PanelCollection::DOCKED, panel4->collection()->type()); | |
1409 EXPECT_EQ(PanelCollection::DOCKED, panel5->collection()->type()); | |
1410 EXPECT_EQ(PanelCollection::DOCKED, panel6->collection()->type()); | |
1411 EXPECT_EQ(PanelCollection::DOCKED, panel7->collection()->type()); | |
1412 EXPECT_EQ(detached_position1, panel1->GetBounds().origin()); | |
1413 | |
1414 // Drag to attach a detached panel to most-left. | |
1415 // Expect to have: | |
1416 // docked: P2 P4 P1 P3 P5 P6 P7 | |
1417 gfx::Point drag_to_location3(panel3->GetBounds().x() - 10, | |
1418 panel3->GetBounds().y()); | |
1419 DragPanelToMouseLocation(panel1, drag_to_location3); | |
1420 ASSERT_EQ(0, detached_collection->num_panels()); | |
1421 ASSERT_EQ(7, docked_collection->num_panels()); | |
1422 EXPECT_EQ(PanelCollection::DOCKED, panel1->collection()->type()); | |
1423 EXPECT_EQ(PanelCollection::DOCKED, panel2->collection()->type()); | |
1424 EXPECT_EQ(PanelCollection::DOCKED, panel3->collection()->type()); | |
1425 EXPECT_EQ(PanelCollection::DOCKED, panel4->collection()->type()); | |
1426 EXPECT_EQ(PanelCollection::DOCKED, panel5->collection()->type()); | |
1427 EXPECT_EQ(PanelCollection::DOCKED, panel6->collection()->type()); | |
1428 EXPECT_EQ(PanelCollection::DOCKED, panel7->collection()->type()); | |
1429 | |
1430 panel_manager->CloseAll(); | |
1431 } | |
1432 | |
1433 // http://crbug.com/175760; several panel tests failing regularly on mac. | |
1434 #if defined(OS_MACOSX) | |
1435 #define MAYBE_DragDetachedPanelToTop DISABLED_DragDetachedPanelToTop | |
1436 #else | |
1437 #define MAYBE_DragDetachedPanelToTop DragDetachedPanelToTop | |
1438 #endif | |
1439 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, MAYBE_DragDetachedPanelToTop) { | |
1440 // Setup the test areas to have top-aligned bar excluded from work area. | |
1441 const gfx::Rect primary_display_area(0, 0, 800, 600); | |
1442 const gfx::Rect primary_work_area(0, 10, 800, 590); | |
1443 mock_display_settings_provider()->SetPrimaryDisplay( | |
1444 primary_display_area, primary_work_area); | |
1445 | |
1446 PanelManager* panel_manager = PanelManager::GetInstance(); | |
1447 Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200)); | |
1448 | |
1449 // Drag up the panel. Expect that the panel should not go outside the top of | |
1450 // the work area. | |
1451 gfx::Point drag_to_location(250, 0); | |
1452 DragPanelToMouseLocation(panel, drag_to_location); | |
1453 EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type()); | |
1454 EXPECT_EQ(drag_to_location.x(), panel->GetBounds().origin().x()); | |
1455 EXPECT_EQ(primary_work_area.y(), panel->GetBounds().origin().y()); | |
1456 | |
1457 // Drag down the panel. Expect that the panel can be dragged without | |
1458 // constraint. | |
1459 drag_to_location = gfx::Point(280, 150); | |
1460 DragPanelToMouseLocation(panel, drag_to_location); | |
1461 EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type()); | |
1462 EXPECT_EQ(drag_to_location, panel->GetBounds().origin()); | |
1463 | |
1464 panel_manager->CloseAll(); | |
1465 } | |
1466 | |
1467 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, | |
1468 DragDockedPanelToSecondaryDisplay) { | |
1469 // Setup 2 displays with secondary display on the right side of primary | |
1470 // display. | |
1471 mock_display_settings_provider()->SetPrimaryDisplay( | |
1472 gfx::Rect(0, 0, 400, 600), gfx::Rect(0, 0, 400, 560)); | |
1473 gfx::Rect secondary_display_area(400, 100, 400, 500); | |
1474 mock_display_settings_provider()->SetSecondaryDisplay( | |
1475 secondary_display_area, secondary_display_area); | |
1476 | |
1477 // Create a docked panel. | |
1478 gfx::Size panel_size(100, 100); | |
1479 Panel* panel = CreateDockedPanel("1", gfx::Rect(gfx::Point(), panel_size)); | |
1480 EXPECT_EQ(PanelCollection::DOCKED, panel->collection()->type()); | |
1481 | |
1482 // Drag the panel to the secondary display horizontally. | |
1483 // Expected that the panel should become detached. | |
1484 gfx::Point drag_to_location(secondary_display_area.x() + 100, | |
1485 panel->GetBounds().y()); | |
1486 DragPanelToMouseLocation(panel, drag_to_location); | |
1487 EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type()); | |
1488 gfx::Rect expected_bounds(drag_to_location, panel_size); | |
1489 EXPECT_EQ(expected_bounds, panel->GetBounds()); | |
1490 | |
1491 PanelManager::GetInstance()->CloseAll(); | |
1492 } | |
1493 | |
1494 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, | |
1495 DragDetachedPanelToSecondaryDisplay) { | |
1496 // Setup 2 displays with secondary display at the bottom of primary display. | |
1497 mock_display_settings_provider()->SetPrimaryDisplay( | |
1498 gfx::Rect(0, 0, 800, 300), gfx::Rect(0, 0, 800, 260)); | |
1499 gfx::Rect secondary_display_area(100, 300, 700, 250); | |
1500 mock_display_settings_provider()->SetSecondaryDisplay( | |
1501 secondary_display_area, secondary_display_area); | |
1502 | |
1503 // Create a detached panel on the primary display. | |
1504 gfx::Rect initial_panel_bounds(300, 50, 100, 100); | |
1505 Panel* panel = CreateDetachedPanel("1", initial_panel_bounds); | |
1506 EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type()); | |
1507 EXPECT_EQ(initial_panel_bounds, panel->GetBounds()); | |
1508 | |
1509 // Drag down the panel to the secondary display vertically. | |
1510 // Expected that the panel should remain detached. | |
1511 gfx::Point drag_to_location(initial_panel_bounds.x(), | |
1512 secondary_display_area.y() + 100); | |
1513 DragPanelToMouseLocation(panel, drag_to_location); | |
1514 EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type()); | |
1515 gfx::Rect expected_bounds(drag_to_location, initial_panel_bounds.size()); | |
1516 EXPECT_EQ(expected_bounds, panel->GetBounds()); | |
1517 | |
1518 PanelManager::GetInstance()->CloseAll(); | |
1519 } | |
1520 | |
1521 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupPanelAndPanelFromBottom) { | |
1522 PanelManager* panel_manager = PanelManager::GetInstance(); | |
1523 DetachedPanelCollection* detached_collection = | |
1524 panel_manager->detached_collection(); | |
1525 | |
1526 // Create two detached panels. | |
1527 Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(300, 200, 200, 100)); | |
1528 Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(100, 100, 150, 150)); | |
1529 ASSERT_EQ(2, detached_collection->num_panels()); | |
1530 ASSERT_EQ(0, panel_manager->num_stacks()); | |
1531 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); | |
1532 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type()); | |
1533 | |
1534 gfx::Rect panel1_old_bounds = panel1->GetBounds(); | |
1535 gfx::Rect panel2_old_bounds = panel2->GetBounds(); | |
1536 | |
1537 // Press on title-bar of P2. | |
1538 std::unique_ptr<NativePanelTesting> panel2_testing( | |
1539 CreateNativePanelTesting(panel2)); | |
1540 gfx::Point mouse_location(panel2->GetBounds().origin()); | |
1541 gfx::Point original_mouse_location = mouse_location; | |
1542 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
1543 | |
1544 // Drag P2 close to the bottom of P1 to trigger the stacking. Expect: | |
1545 // 1) P1 and P2 form a stack. | |
1546 // 2) P2 jumps vertcially to align to the bottom edge of P1. | |
1547 // 3) P2 moves horizontally by the dragging delta. | |
1548 // 4) The width of P2 remains unchanged. | |
1549 gfx::Vector2d drag_delta_to_stack = | |
1550 GetDragDeltaToStackToBottom(panel2, panel1); | |
1551 mouse_location += drag_delta_to_stack; | |
1552 panel2_testing->DragTitlebar(mouse_location); | |
1553 ASSERT_EQ(0, detached_collection->num_panels()); | |
1554 ASSERT_EQ(1, panel_manager->num_stacks()); | |
1555 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type()); | |
1556 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type()); | |
1557 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds()); | |
1558 gfx::Rect panel2_new_bounds(panel2_old_bounds.x() + drag_delta_to_stack.x(), | |
1559 panel1_old_bounds.bottom(), | |
1560 panel2_old_bounds.width(), | |
1561 panel2_old_bounds.height()); | |
1562 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds()); | |
1563 | |
1564 // Drag P2 somewhat away from the bottom of P1 to trigger the unstacking. | |
1565 // Expect P1 and P2 become detached. | |
1566 gfx::Vector2d drag_delta_to_unstack = | |
1567 GetDragDeltaToUnstackFromBottom(panel2, panel1); | |
1568 mouse_location += drag_delta_to_unstack; | |
1569 panel2_testing->DragTitlebar(mouse_location); | |
1570 ASSERT_EQ(2, detached_collection->num_panels()); | |
1571 ASSERT_EQ(0, panel_manager->num_stacks()); | |
1572 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); | |
1573 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type()); | |
1574 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds()); | |
1575 panel2_new_bounds.set_origin(panel2_old_bounds.origin()); | |
1576 panel2_new_bounds.Offset(mouse_location - original_mouse_location); | |
1577 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds()); | |
1578 | |
1579 // Drag P2 close to the bottom of P1 to trigger the stacking again. Expect: | |
1580 // 1) P1 and P2 form a stack. | |
1581 // 2) P2 jumps vertcially to align to the bottom edge of P1. | |
1582 // 3) P2 moves horizontally by the dragging delta. | |
1583 // 4) The width of P2 remains unchanged. | |
1584 drag_delta_to_stack = GetDragDeltaToStackToBottom(panel2, panel1); | |
1585 mouse_location += drag_delta_to_stack; | |
1586 panel2_testing->DragTitlebar(mouse_location); | |
1587 ASSERT_EQ(0, detached_collection->num_panels()); | |
1588 ASSERT_EQ(1, panel_manager->num_stacks()); | |
1589 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type()); | |
1590 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type()); | |
1591 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds()); | |
1592 panel2_new_bounds.set_x(panel2_new_bounds.x() + drag_delta_to_stack.x()); | |
1593 panel2_new_bounds.set_y(panel1_old_bounds.bottom()); | |
1594 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds()); | |
1595 | |
1596 // Move the mouse a little bit. Expect P2 only moves horizontally. P2 should | |
1597 // not move vertically since its top edge already glues to the bottom edge | |
1598 // of P1. | |
1599 gfx::Vector2d small_delta(1, -1); | |
1600 mouse_location += small_delta; | |
1601 panel2_testing->DragTitlebar(mouse_location); | |
1602 ASSERT_EQ(0, detached_collection->num_panels()); | |
1603 ASSERT_EQ(1, panel_manager->num_stacks()); | |
1604 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type()); | |
1605 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type()); | |
1606 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds()); | |
1607 panel2_new_bounds.set_x(panel2_new_bounds.x() + small_delta.x()); | |
1608 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds()); | |
1609 | |
1610 // Finish the drag. Expect: | |
1611 // 1) P1 and P2 remain stacked. | |
1612 // 2) P2 moves horizontally to align with P1. | |
1613 // 3) The width of P2 is adjusted to be same as the one of P1. | |
1614 panel2_testing->FinishDragTitlebar(); | |
1615 WaitForBoundsAnimationFinished(panel2); | |
1616 ASSERT_EQ(0, detached_collection->num_panels()); | |
1617 ASSERT_EQ(1, panel_manager->num_stacks()); | |
1618 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type()); | |
1619 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type()); | |
1620 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds()); | |
1621 panel2_new_bounds.set_x(panel1_old_bounds.x()); | |
1622 panel2_new_bounds.set_width(panel1_old_bounds.width()); | |
1623 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds()); | |
1624 | |
1625 panel_manager->CloseAll(); | |
1626 } | |
1627 | |
1628 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupPanelAndPanelFromTop) { | |
1629 PanelManager* panel_manager = PanelManager::GetInstance(); | |
1630 DetachedPanelCollection* detached_collection = | |
1631 panel_manager->detached_collection(); | |
1632 | |
1633 // Create two detached panels. | |
1634 Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(300, 300, 200, 100)); | |
1635 Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(100, 200, 150, 150)); | |
1636 ASSERT_EQ(2, detached_collection->num_panels()); | |
1637 ASSERT_EQ(0, panel_manager->num_stacks()); | |
1638 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); | |
1639 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type()); | |
1640 | |
1641 gfx::Rect panel1_old_bounds = panel1->GetBounds(); | |
1642 gfx::Rect panel2_old_bounds = panel2->GetBounds(); | |
1643 | |
1644 // Press on title-bar of P2. | |
1645 std::unique_ptr<NativePanelTesting> panel2_testing( | |
1646 CreateNativePanelTesting(panel2)); | |
1647 gfx::Point mouse_location(panel2->GetBounds().origin()); | |
1648 gfx::Point original_mouse_location = mouse_location; | |
1649 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
1650 | |
1651 // Drag P2 close to the top of P1 to trigger the stacking. Expect: | |
1652 // 1) P2 and P1 form a stack. | |
1653 // 2) P2 jumps vertcially to align to the top edge of P1. | |
1654 // 3) P2 moves horizontally by the dragging delta. | |
1655 // 4) The width of both P1 and P2 remains unchanged. | |
1656 gfx::Vector2d drag_delta_to_stack = GetDragDeltaToStackToTop(panel2, panel1); | |
1657 mouse_location += drag_delta_to_stack; | |
1658 panel2_testing->DragTitlebar(mouse_location); | |
1659 ASSERT_EQ(0, detached_collection->num_panels()); | |
1660 ASSERT_EQ(1, panel_manager->num_stacks()); | |
1661 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type()); | |
1662 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type()); | |
1663 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds()); | |
1664 gfx::Rect panel2_new_bounds( | |
1665 panel2_old_bounds.x() + drag_delta_to_stack.x(), | |
1666 panel1_old_bounds.y() - panel2_old_bounds.height(), | |
1667 panel2_old_bounds.width(), | |
1668 panel2_old_bounds.height()); | |
1669 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds()); | |
1670 | |
1671 // Drag P2 somewhat away from the top of P1 to trigger the unstacking. | |
1672 // Expect P1 and P2 become detached. | |
1673 gfx::Vector2d drag_delta_to_unstack = | |
1674 GetDragDeltaToUnstackFromTop(panel2, panel1); | |
1675 mouse_location += drag_delta_to_unstack; | |
1676 panel2_testing->DragTitlebar(mouse_location); | |
1677 ASSERT_EQ(2, detached_collection->num_panels()); | |
1678 ASSERT_EQ(0, panel_manager->num_stacks()); | |
1679 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); | |
1680 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type()); | |
1681 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds()); | |
1682 panel2_new_bounds.set_origin(panel2_old_bounds.origin()); | |
1683 panel2_new_bounds.Offset(mouse_location - original_mouse_location); | |
1684 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds()); | |
1685 | |
1686 // Drag P2 close to the top of P1 to trigger the stacking again. Expect: | |
1687 // 1) P2 and P1 form a stack. | |
1688 // 2) P2 jumps vertcially to align to the top edge of P1. | |
1689 // 3) P2 moves horizontally by the dragging delta. | |
1690 // 4) The width of both P1 and P2 remains unchanged. | |
1691 drag_delta_to_stack = GetDragDeltaToStackToTop(panel2, panel1); | |
1692 mouse_location += drag_delta_to_stack; | |
1693 panel2_testing->DragTitlebar(mouse_location); | |
1694 ASSERT_EQ(0, detached_collection->num_panels()); | |
1695 ASSERT_EQ(1, panel_manager->num_stacks()); | |
1696 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type()); | |
1697 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type()); | |
1698 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds()); | |
1699 panel2_new_bounds.set_x(panel2_new_bounds.x() + drag_delta_to_stack.x()); | |
1700 panel2_new_bounds.set_y(panel1_old_bounds.y() - panel2_old_bounds.height()); | |
1701 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds()); | |
1702 | |
1703 // Move the mouse a little bit. Expect only P2 moves horizontally. P2 should | |
1704 // not move vertically because its bottom edge already glues to the top edge | |
1705 // of P1. | |
1706 gfx::Vector2d small_delta(1, -1); | |
1707 mouse_location += small_delta; | |
1708 panel2_testing->DragTitlebar(mouse_location); | |
1709 ASSERT_EQ(0, detached_collection->num_panels()); | |
1710 ASSERT_EQ(1, panel_manager->num_stacks()); | |
1711 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type()); | |
1712 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type()); | |
1713 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds()); | |
1714 panel2_new_bounds.set_x(panel2_new_bounds.x() + small_delta.x()); | |
1715 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds()); | |
1716 | |
1717 // Finish the drag. Expect: | |
1718 // 1) P2 and P1 remain stacked. | |
1719 // 2) P2 moves horizontally to align with P1. | |
1720 // 3) The width of P1 is adjusted to be same as the one of P2. | |
1721 panel2_testing->FinishDragTitlebar(); | |
1722 WaitForBoundsAnimationFinished(panel1); | |
1723 ASSERT_EQ(0, detached_collection->num_panels()); | |
1724 ASSERT_EQ(1, panel_manager->num_stacks()); | |
1725 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type()); | |
1726 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type()); | |
1727 gfx::Rect panel1_new_bounds = panel1_old_bounds; | |
1728 panel1_new_bounds.set_width(panel2_new_bounds.width()); | |
1729 EXPECT_EQ(panel1_new_bounds, panel1->GetBounds()); | |
1730 panel2_new_bounds.set_x(panel1_new_bounds.x()); | |
1731 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds()); | |
1732 | |
1733 panel_manager->CloseAll(); | |
1734 } | |
1735 | |
1736 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupAndCancel) { | |
1737 PanelManager* panel_manager = PanelManager::GetInstance(); | |
1738 DetachedPanelCollection* detached_collection = | |
1739 panel_manager->detached_collection(); | |
1740 | |
1741 // Create two detached panels. | |
1742 Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(300, 200, 200, 100)); | |
1743 Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(100, 100, 150, 150)); | |
1744 ASSERT_EQ(2, detached_collection->num_panels()); | |
1745 ASSERT_EQ(0, panel_manager->num_stacks()); | |
1746 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); | |
1747 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type()); | |
1748 | |
1749 gfx::Rect panel1_old_bounds = panel1->GetBounds(); | |
1750 gfx::Rect panel2_old_bounds = panel2->GetBounds(); | |
1751 | |
1752 // Press on title-bar. | |
1753 std::unique_ptr<NativePanelTesting> panel2_testing( | |
1754 CreateNativePanelTesting(panel2)); | |
1755 gfx::Point mouse_location(panel2->GetBounds().origin()); | |
1756 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
1757 | |
1758 // Drag P2 close to the bottom of P1 to trigger the stacking. | |
1759 // Expect that P2 stacks to P1 and P2's width remains unchanged. | |
1760 gfx::Vector2d drag_delta_to_stack = | |
1761 GetDragDeltaToStackToBottom(panel2, panel1); | |
1762 mouse_location += drag_delta_to_stack; | |
1763 panel2_testing->DragTitlebar(mouse_location); | |
1764 ASSERT_EQ(0, detached_collection->num_panels()); | |
1765 ASSERT_EQ(1, panel_manager->num_stacks()); | |
1766 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type()); | |
1767 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type()); | |
1768 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds()); | |
1769 gfx::Rect panel2_new_bounds(panel1_old_bounds.x(), | |
1770 panel1_old_bounds.bottom(), | |
1771 panel2_old_bounds.width(), | |
1772 panel2_old_bounds.height()); | |
1773 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds()); | |
1774 | |
1775 // Cancel the drag. | |
1776 // Expect that the P1 and P2 become detached. | |
1777 panel2_testing->CancelDragTitlebar(); | |
1778 ASSERT_EQ(2, detached_collection->num_panels()); | |
1779 ASSERT_EQ(0, panel_manager->num_stacks()); | |
1780 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); | |
1781 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type()); | |
1782 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds()); | |
1783 EXPECT_EQ(panel2_old_bounds, panel2->GetBounds()); | |
1784 | |
1785 panel_manager->CloseAll(); | |
1786 } | |
1787 | |
1788 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupPanelAndStackFromBottom) { | |
1789 PanelManager* panel_manager = PanelManager::GetInstance(); | |
1790 DetachedPanelCollection* detached_collection = | |
1791 panel_manager->detached_collection(); | |
1792 | |
1793 // Create 2 stacked panels. | |
1794 StackedPanelCollection* stack = panel_manager->CreateStack(); | |
1795 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 100, 200, 150); | |
1796 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack); | |
1797 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100); | |
1798 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack); | |
1799 ASSERT_EQ(0, detached_collection->num_panels()); | |
1800 ASSERT_EQ(1, panel_manager->num_stacks()); | |
1801 ASSERT_EQ(2, stack->num_panels()); | |
1802 EXPECT_EQ(stack, panel1->collection()); | |
1803 EXPECT_EQ(stack, panel2->collection()); | |
1804 | |
1805 gfx::Rect panel1_expected_bounds(panel1_initial_bounds); | |
1806 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
1807 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds( | |
1808 panel2_initial_bounds, panel1_expected_bounds); | |
1809 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
1810 | |
1811 // Create 1 detached panel. | |
1812 gfx::Rect panel3_initial_bounds = gfx::Rect(300, 200, 100, 100); | |
1813 Panel* panel3 = CreateDetachedPanel("3", panel3_initial_bounds); | |
1814 ASSERT_EQ(1, detached_collection->num_panels()); | |
1815 gfx::Rect panel3_expected_bounds(panel3_initial_bounds); | |
1816 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
1817 | |
1818 // Drag P3 close to the bottom edge of P1 that is not the bottom panel. | |
1819 // Expect no stacking. | |
1820 gfx::Vector2d drag_delta_to_stack = | |
1821 GetDragDeltaToStackToBottom(panel3, panel1); | |
1822 DragPanelByDelta(panel3, drag_delta_to_stack); | |
1823 ASSERT_EQ(1, detached_collection->num_panels()); | |
1824 ASSERT_EQ(2, stack->num_panels()); | |
1825 ASSERT_EQ(1, panel_manager->num_stacks()); | |
1826 | |
1827 // Drag P3 close to the bottom edge of P2 that is the bottom panel. | |
1828 // Expect that P3 becomes the bottom panel of the stack. | |
1829 drag_delta_to_stack = GetDragDeltaToStackToBottom(panel3, panel2); | |
1830 DragPanelByDelta(panel3, drag_delta_to_stack); | |
1831 WaitForBoundsAnimationFinished(panel3); | |
1832 ASSERT_EQ(0, detached_collection->num_panels()); | |
1833 ASSERT_EQ(3, stack->num_panels()); | |
1834 ASSERT_EQ(1, panel_manager->num_stacks()); | |
1835 EXPECT_EQ(stack, panel1->collection()); | |
1836 EXPECT_EQ(stack, panel2->collection()); | |
1837 EXPECT_EQ(stack, panel3->collection()); | |
1838 EXPECT_EQ(panel3, stack->bottom_panel()); | |
1839 | |
1840 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
1841 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
1842 panel3_expected_bounds = GetStackedAtBottomPanelBounds( | |
1843 panel3_initial_bounds, panel2_expected_bounds); | |
1844 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
1845 | |
1846 panel_manager->CloseAll(); | |
1847 } | |
1848 | |
1849 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupPanelAndStackFromTop) { | |
1850 PanelManager* panel_manager = PanelManager::GetInstance(); | |
1851 DetachedPanelCollection* detached_collection = | |
1852 panel_manager->detached_collection(); | |
1853 | |
1854 // Create 2 stacked panels. | |
1855 StackedPanelCollection* stack = panel_manager->CreateStack(); | |
1856 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 300, 200, 150); | |
1857 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack); | |
1858 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100); | |
1859 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack); | |
1860 ASSERT_EQ(0, detached_collection->num_panels()); | |
1861 ASSERT_EQ(1, panel_manager->num_stacks()); | |
1862 ASSERT_EQ(2, stack->num_panels()); | |
1863 EXPECT_EQ(stack, panel1->collection()); | |
1864 EXPECT_EQ(stack, panel2->collection()); | |
1865 | |
1866 gfx::Rect panel1_expected_bounds(panel1_initial_bounds); | |
1867 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
1868 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds( | |
1869 panel2_initial_bounds, panel1_expected_bounds); | |
1870 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
1871 | |
1872 // Create 1 detached panel. | |
1873 gfx::Rect panel3_initial_bounds = gfx::Rect(300, 200, 100, 100); | |
1874 Panel* panel3 = CreateDetachedPanel("3", panel3_initial_bounds); | |
1875 ASSERT_EQ(1, detached_collection->num_panels()); | |
1876 gfx::Rect panel3_expected_bounds(panel3_initial_bounds); | |
1877 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
1878 | |
1879 // Drag P3 close to the top edge of P2 that is not the top panel. | |
1880 // Expect no stacking. | |
1881 gfx::Vector2d drag_delta_to_stack = GetDragDeltaToStackToTop(panel3, panel2); | |
1882 DragPanelByDelta(panel3, drag_delta_to_stack); | |
1883 ASSERT_EQ(1, detached_collection->num_panels()); | |
1884 ASSERT_EQ(2, stack->num_panels()); | |
1885 ASSERT_EQ(1, panel_manager->num_stacks()); | |
1886 | |
1887 // Drag P3 close to the top edge of P1 that is the top panel. | |
1888 // Expect that P3 becomes the top panel of the stack. | |
1889 drag_delta_to_stack = GetDragDeltaToStackToTop(panel3, panel1); | |
1890 DragPanelByDelta(panel3, drag_delta_to_stack); | |
1891 WaitForBoundsAnimationFinished(panel1); | |
1892 WaitForBoundsAnimationFinished(panel2); | |
1893 ASSERT_EQ(0, detached_collection->num_panels()); | |
1894 ASSERT_EQ(3, stack->num_panels()); | |
1895 ASSERT_EQ(1, panel_manager->num_stacks()); | |
1896 EXPECT_EQ(stack, panel1->collection()); | |
1897 EXPECT_EQ(stack, panel2->collection()); | |
1898 EXPECT_EQ(stack, panel3->collection()); | |
1899 EXPECT_EQ(panel3, stack->top_panel()); | |
1900 | |
1901 panel3_expected_bounds = GetStackedAtTopPanelBounds( | |
1902 panel3_initial_bounds, panel1_expected_bounds); | |
1903 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
1904 panel1_expected_bounds.set_width(panel3_expected_bounds.width()); | |
1905 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
1906 panel2_expected_bounds.set_width(panel3_expected_bounds.width()); | |
1907 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
1908 | |
1909 panel_manager->CloseAll(); | |
1910 } | |
1911 | |
1912 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupStackAndPanelFromBottom) { | |
1913 PanelManager* panel_manager = PanelManager::GetInstance(); | |
1914 DetachedPanelCollection* detached_collection = | |
1915 panel_manager->detached_collection(); | |
1916 | |
1917 // Create 2 stacked panels. | |
1918 StackedPanelCollection* stack = panel_manager->CreateStack(); | |
1919 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 100, 200, 150); | |
1920 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack); | |
1921 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100); | |
1922 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack); | |
1923 ASSERT_EQ(0, detached_collection->num_panels()); | |
1924 ASSERT_EQ(1, panel_manager->num_stacks()); | |
1925 ASSERT_EQ(2, stack->num_panels()); | |
1926 EXPECT_EQ(stack, panel1->stack()); | |
1927 EXPECT_EQ(stack, panel2->stack()); | |
1928 | |
1929 gfx::Rect panel1_expected_bounds(panel1_initial_bounds); | |
1930 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
1931 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds( | |
1932 panel2_initial_bounds, panel1_expected_bounds); | |
1933 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
1934 | |
1935 // Create 1 detached panel. | |
1936 gfx::Rect panel3_initial_bounds = gfx::Rect(300, 200, 100, 100); | |
1937 Panel* panel3 = CreateDetachedPanel("3", panel3_initial_bounds); | |
1938 ASSERT_EQ(1, detached_collection->num_panels()); | |
1939 gfx::Rect panel3_expected_bounds(panel3_initial_bounds); | |
1940 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
1941 | |
1942 // Drag P1 (together with P2) to stack to the bottom of P3. | |
1943 // Expect that P1 and P2 append to the bottom of P3 and all 3 panels are in | |
1944 // one stack. | |
1945 gfx::Vector2d drag_delta_to_stack = | |
1946 GetDragDeltaToStackToBottom(panel1, panel3); | |
1947 DragPanelByDelta(panel1, drag_delta_to_stack); | |
1948 WaitForBoundsAnimationFinished(panel1); | |
1949 WaitForBoundsAnimationFinished(panel2); | |
1950 ASSERT_EQ(0, detached_collection->num_panels()); | |
1951 ASSERT_EQ(1, panel_manager->num_stacks()); | |
1952 StackedPanelCollection* final_stack = panel_manager->stacks().front(); | |
1953 ASSERT_EQ(3, final_stack->num_panels()); | |
1954 EXPECT_EQ(final_stack, panel1->stack()); | |
1955 EXPECT_EQ(final_stack, panel2->stack()); | |
1956 EXPECT_EQ(final_stack, panel3->stack()); | |
1957 | |
1958 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
1959 panel1_expected_bounds = GetStackedAtBottomPanelBounds( | |
1960 panel1_initial_bounds, panel3_expected_bounds); | |
1961 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
1962 panel2_expected_bounds = GetStackedAtBottomPanelBounds( | |
1963 panel2_initial_bounds, panel1_expected_bounds); | |
1964 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
1965 | |
1966 panel_manager->CloseAll(); | |
1967 } | |
1968 | |
1969 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupStackAndPanelFromTop) { | |
1970 PanelManager* panel_manager = PanelManager::GetInstance(); | |
1971 DetachedPanelCollection* detached_collection = | |
1972 panel_manager->detached_collection(); | |
1973 | |
1974 // Create 2 stacked panels. | |
1975 StackedPanelCollection* stack = panel_manager->CreateStack(); | |
1976 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 100, 200, 150); | |
1977 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack); | |
1978 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100); | |
1979 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack); | |
1980 ASSERT_EQ(0, detached_collection->num_panels()); | |
1981 ASSERT_EQ(1, panel_manager->num_stacks()); | |
1982 ASSERT_EQ(2, stack->num_panels()); | |
1983 EXPECT_EQ(stack, panel1->stack()); | |
1984 EXPECT_EQ(stack, panel2->stack()); | |
1985 | |
1986 gfx::Rect panel1_expected_bounds(panel1_initial_bounds); | |
1987 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
1988 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds( | |
1989 panel2_initial_bounds, panel1_expected_bounds); | |
1990 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
1991 | |
1992 // Create 1 detached panel. | |
1993 gfx::Rect panel3_initial_bounds = gfx::Rect(300, 450, 100, 100); | |
1994 Panel* panel3 = CreateDetachedPanel("3", panel3_initial_bounds); | |
1995 ASSERT_EQ(1, detached_collection->num_panels()); | |
1996 gfx::Rect panel3_expected_bounds(panel3_initial_bounds); | |
1997 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
1998 | |
1999 // Drag P1 (together with P2) to stack to the top of P3. | |
2000 // Expect that P1 and P2 add to the top of P3 and all 3 panels are in | |
2001 // one stack. P1 and P2 should align to top of P3 while P3 should update its | |
2002 // width to be same as the width of P1 and P2. | |
2003 gfx::Vector2d drag_delta_to_stack = GetDragDeltaToStackToTop(panel1, panel3); | |
2004 DragPanelByDelta(panel1, drag_delta_to_stack); | |
2005 WaitForBoundsAnimationFinished(panel3); | |
2006 ASSERT_EQ(0, detached_collection->num_panels()); | |
2007 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2008 StackedPanelCollection* final_stack = panel_manager->stacks().front(); | |
2009 ASSERT_EQ(3, final_stack->num_panels()); | |
2010 EXPECT_EQ(final_stack, panel1->stack()); | |
2011 EXPECT_EQ(final_stack, panel2->stack()); | |
2012 EXPECT_EQ(final_stack, panel3->stack()); | |
2013 | |
2014 panel3_expected_bounds.set_width(panel1_expected_bounds.width()); | |
2015 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
2016 panel2_expected_bounds = GetStackedAtTopPanelBounds( | |
2017 panel2_expected_bounds, panel3_expected_bounds); | |
2018 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2019 panel1_expected_bounds = GetStackedAtTopPanelBounds( | |
2020 panel1_expected_bounds, panel2_expected_bounds); | |
2021 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2022 | |
2023 panel_manager->CloseAll(); | |
2024 } | |
2025 | |
2026 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupStackAndStackFromBottom) { | |
2027 PanelManager* panel_manager = PanelManager::GetInstance(); | |
2028 DetachedPanelCollection* detached_collection = | |
2029 panel_manager->detached_collection(); | |
2030 | |
2031 // Create 2 stacked panels. | |
2032 StackedPanelCollection* stack1 = panel_manager->CreateStack(); | |
2033 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150); | |
2034 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack1); | |
2035 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100); | |
2036 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack1); | |
2037 ASSERT_EQ(0, detached_collection->num_panels()); | |
2038 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2039 ASSERT_EQ(2, stack1->num_panels()); | |
2040 EXPECT_EQ(stack1, panel1->stack()); | |
2041 EXPECT_EQ(stack1, panel2->stack()); | |
2042 | |
2043 gfx::Rect panel1_expected_bounds(panel1_initial_bounds); | |
2044 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2045 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds( | |
2046 panel2_initial_bounds, panel1_expected_bounds); | |
2047 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2048 | |
2049 // Create 2 more stacked panels in another stack. | |
2050 StackedPanelCollection* stack2 = panel_manager->CreateStack(); | |
2051 gfx::Rect panel3_initial_bounds = gfx::Rect(300, 100, 220, 120); | |
2052 Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack2); | |
2053 gfx::Rect panel4_initial_bounds = gfx::Rect(0, 0, 180, 140); | |
2054 Panel* panel4 = CreateStackedPanel("4", panel4_initial_bounds, stack2); | |
2055 ASSERT_EQ(0, detached_collection->num_panels()); | |
2056 ASSERT_EQ(2, panel_manager->num_stacks()); | |
2057 ASSERT_EQ(2, stack2->num_panels()); | |
2058 EXPECT_EQ(stack2, panel3->stack()); | |
2059 EXPECT_EQ(stack2, panel4->stack()); | |
2060 | |
2061 gfx::Rect panel3_expected_bounds(panel3_initial_bounds); | |
2062 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
2063 gfx::Rect panel4_expected_bounds = GetStackedAtBottomPanelBounds( | |
2064 panel4_initial_bounds, panel3_expected_bounds); | |
2065 EXPECT_EQ(panel4_expected_bounds, panel4->GetBounds()); | |
2066 | |
2067 // Drag P3 (together with P4) to stack to the bottom of the stack consisting | |
2068 // P1 and P2. | |
2069 // Expect that P3 and P4 append to the bottom of P2 and all 4 panels are in | |
2070 // one stack. | |
2071 gfx::Vector2d drag_delta_to_stack = | |
2072 GetDragDeltaToStackToBottom(panel3, panel2); | |
2073 DragPanelByDelta(panel3, drag_delta_to_stack); | |
2074 WaitForBoundsAnimationFinished(panel3); | |
2075 WaitForBoundsAnimationFinished(panel4); | |
2076 ASSERT_EQ(0, detached_collection->num_panels()); | |
2077 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2078 StackedPanelCollection* final_stack = panel_manager->stacks().front(); | |
2079 ASSERT_EQ(4, final_stack->num_panels()); | |
2080 EXPECT_EQ(final_stack, panel1->stack()); | |
2081 EXPECT_EQ(final_stack, panel2->stack()); | |
2082 EXPECT_EQ(final_stack, panel3->stack()); | |
2083 EXPECT_EQ(final_stack, panel4->stack()); | |
2084 | |
2085 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2086 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2087 panel3_expected_bounds = GetStackedAtBottomPanelBounds( | |
2088 panel3_initial_bounds, panel2_expected_bounds); | |
2089 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
2090 panel4_expected_bounds = GetStackedAtBottomPanelBounds( | |
2091 panel4_initial_bounds, panel3_expected_bounds); | |
2092 EXPECT_EQ(panel4_expected_bounds, panel4->GetBounds()); | |
2093 | |
2094 panel_manager->CloseAll(); | |
2095 } | |
2096 | |
2097 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupStackAndStackFromTop) { | |
2098 PanelManager* panel_manager = PanelManager::GetInstance(); | |
2099 DetachedPanelCollection* detached_collection = | |
2100 panel_manager->detached_collection(); | |
2101 | |
2102 // Create 2 stacked panels. | |
2103 StackedPanelCollection* stack1 = panel_manager->CreateStack(); | |
2104 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150); | |
2105 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack1); | |
2106 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100); | |
2107 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack1); | |
2108 ASSERT_EQ(0, detached_collection->num_panels()); | |
2109 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2110 ASSERT_EQ(2, stack1->num_panels()); | |
2111 EXPECT_EQ(stack1, panel1->stack()); | |
2112 EXPECT_EQ(stack1, panel2->stack()); | |
2113 | |
2114 gfx::Rect panel1_expected_bounds(panel1_initial_bounds); | |
2115 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2116 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds( | |
2117 panel2_initial_bounds, panel1_expected_bounds); | |
2118 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2119 | |
2120 // Create 2 more stacked panels in another stack. | |
2121 StackedPanelCollection* stack2 = panel_manager->CreateStack(); | |
2122 gfx::Rect panel3_initial_bounds = gfx::Rect(300, 350, 220, 110); | |
2123 Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack2); | |
2124 gfx::Rect panel4_initial_bounds = gfx::Rect(0, 0, 180, 100); | |
2125 Panel* panel4 = CreateStackedPanel("4", panel4_initial_bounds, stack2); | |
2126 ASSERT_EQ(0, detached_collection->num_panels()); | |
2127 ASSERT_EQ(2, panel_manager->num_stacks()); | |
2128 ASSERT_EQ(2, stack2->num_panels()); | |
2129 EXPECT_EQ(stack2, panel3->stack()); | |
2130 EXPECT_EQ(stack2, panel4->stack()); | |
2131 | |
2132 gfx::Rect panel3_expected_bounds(panel3_initial_bounds); | |
2133 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
2134 gfx::Rect panel4_expected_bounds = GetStackedAtBottomPanelBounds( | |
2135 panel4_initial_bounds, panel3_expected_bounds); | |
2136 EXPECT_EQ(panel4_expected_bounds, panel4->GetBounds()); | |
2137 | |
2138 // Drag P1 (together with P2) to stack to the top of the stack consisting | |
2139 // P3 and P4. | |
2140 // Expect that P1 and P2 add to the top of P3 and all 4 panels are in | |
2141 // one stack. P1 and P2 should align to top of P3 while P3 and P4 should | |
2142 // update their width to be same as the width of P1 and P2. | |
2143 gfx::Vector2d drag_delta_to_stack = GetDragDeltaToStackToTop(panel1, panel3); | |
2144 DragPanelByDelta(panel1, drag_delta_to_stack); | |
2145 WaitForBoundsAnimationFinished(panel3); | |
2146 WaitForBoundsAnimationFinished(panel4); | |
2147 ASSERT_EQ(0, detached_collection->num_panels()); | |
2148 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2149 StackedPanelCollection* final_stack = panel_manager->stacks().front(); | |
2150 ASSERT_EQ(4, final_stack->num_panels()); | |
2151 EXPECT_EQ(final_stack, panel1->stack()); | |
2152 EXPECT_EQ(final_stack, panel2->stack()); | |
2153 EXPECT_EQ(final_stack, panel3->stack()); | |
2154 EXPECT_EQ(final_stack, panel4->stack()); | |
2155 | |
2156 panel4_expected_bounds.set_width(panel1_expected_bounds.width()); | |
2157 EXPECT_EQ(panel4_expected_bounds, panel4->GetBounds()); | |
2158 panel3_expected_bounds.set_width(panel1_expected_bounds.width()); | |
2159 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
2160 panel2_expected_bounds = GetStackedAtTopPanelBounds( | |
2161 panel2_expected_bounds, panel3_expected_bounds); | |
2162 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2163 panel1_expected_bounds = GetStackedAtTopPanelBounds( | |
2164 panel1_expected_bounds, panel2_expected_bounds); | |
2165 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2166 | |
2167 panel_manager->CloseAll(); | |
2168 } | |
2169 | |
2170 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, UngroupTwoPanelStack) { | |
2171 PanelManager* panel_manager = PanelManager::GetInstance(); | |
2172 DetachedPanelCollection* detached_collection = | |
2173 panel_manager->detached_collection(); | |
2174 | |
2175 // Create 2 stacked panels. | |
2176 StackedPanelCollection* stack = panel_manager->CreateStack(); | |
2177 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150); | |
2178 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack); | |
2179 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100); | |
2180 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack); | |
2181 ASSERT_EQ(0, detached_collection->num_panels()); | |
2182 ASSERT_EQ(2, stack->num_panels()); | |
2183 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2184 EXPECT_EQ(stack, panel1->stack()); | |
2185 EXPECT_EQ(stack, panel2->stack()); | |
2186 | |
2187 gfx::Rect panel1_expected_bounds(panel1_initial_bounds); | |
2188 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2189 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds( | |
2190 panel2_initial_bounds, panel1_expected_bounds); | |
2191 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2192 gfx::Rect panel2_old_bounds = panel2_expected_bounds; | |
2193 | |
2194 // Press on title-bar. | |
2195 std::unique_ptr<NativePanelTesting> panel2_testing( | |
2196 CreateNativePanelTesting(panel2)); | |
2197 gfx::Point mouse_location(panel2->GetBounds().origin()); | |
2198 gfx::Point original_mouse_location = mouse_location; | |
2199 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
2200 | |
2201 // Drag P2 away from the bottom of P1 to trigger the unstacking. | |
2202 // Expect that P1 and P2 get detached. | |
2203 gfx::Vector2d drag_delta_to_unstack = | |
2204 GetDragDeltaToUnstackFromBottom(panel2, panel1); | |
2205 mouse_location += drag_delta_to_unstack; | |
2206 panel2_testing->DragTitlebar(mouse_location); | |
2207 ASSERT_EQ(2, detached_collection->num_panels()); | |
2208 ASSERT_TRUE(stack->num_panels() == 0); | |
2209 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); | |
2210 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type()); | |
2211 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2212 panel2_expected_bounds.Offset(drag_delta_to_unstack); | |
2213 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2214 | |
2215 // Drag P2 a bit closer to the bottom of P1 to trigger the stacking. | |
2216 // Expect P1 and P2 get stacked together. | |
2217 gfx::Vector2d drag_delta_to_stack = | |
2218 GetDragDeltaToStackToBottom(panel2, panel1); | |
2219 mouse_location += drag_delta_to_stack; | |
2220 panel2_testing->DragTitlebar(mouse_location); | |
2221 ASSERT_EQ(0, detached_collection->num_panels()); | |
2222 // Note that the empty stack might still exist until the drag ends. | |
2223 ASSERT_GE(panel_manager->num_stacks(), 1); | |
2224 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type()); | |
2225 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type()); | |
2226 EXPECT_EQ(panel1->stack(), panel2->stack()); | |
2227 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2228 panel2_expected_bounds = GetStackedAtBottomPanelBounds( | |
2229 panel2_initial_bounds, panel1_expected_bounds); | |
2230 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2231 | |
2232 // Drag P2 away from the bottom of P1 to trigger the unstacking again. | |
2233 // Expect that P1 and P2 get detached. | |
2234 drag_delta_to_unstack = GetDragDeltaToUnstackFromBottom(panel2, panel1); | |
2235 mouse_location += drag_delta_to_unstack; | |
2236 panel2_testing->DragTitlebar(mouse_location); | |
2237 ASSERT_EQ(2, detached_collection->num_panels()); | |
2238 ASSERT_TRUE(stack->num_panels() == 0); | |
2239 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); | |
2240 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type()); | |
2241 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2242 panel2_expected_bounds = panel2_old_bounds; | |
2243 panel2_expected_bounds.Offset(mouse_location - original_mouse_location); | |
2244 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2245 | |
2246 // Finish the drag. | |
2247 // Expect that the P1 and P2 stay detached. | |
2248 panel2_testing->FinishDragTitlebar(); | |
2249 ASSERT_EQ(2, detached_collection->num_panels()); | |
2250 ASSERT_EQ(0, panel_manager->num_stacks()); | |
2251 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); | |
2252 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type()); | |
2253 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2254 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2255 | |
2256 panel_manager->CloseAll(); | |
2257 } | |
2258 | |
2259 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, UngroupAndCancel) { | |
2260 PanelManager* panel_manager = PanelManager::GetInstance(); | |
2261 DetachedPanelCollection* detached_collection = | |
2262 panel_manager->detached_collection(); | |
2263 | |
2264 // Create 2 stacked panels. | |
2265 StackedPanelCollection* stack = panel_manager->CreateStack(); | |
2266 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150); | |
2267 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack); | |
2268 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100); | |
2269 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack); | |
2270 ASSERT_EQ(0, detached_collection->num_panels()); | |
2271 ASSERT_EQ(2, stack->num_panels()); | |
2272 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2273 EXPECT_EQ(stack, panel1->stack()); | |
2274 EXPECT_EQ(stack, panel2->stack()); | |
2275 | |
2276 gfx::Rect panel1_expected_bounds(panel1_initial_bounds); | |
2277 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2278 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds( | |
2279 panel2_initial_bounds, panel1_expected_bounds); | |
2280 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2281 gfx::Rect panel2_old_bounds = panel2->GetBounds(); | |
2282 | |
2283 // Press on title-bar. | |
2284 std::unique_ptr<NativePanelTesting> panel2_testing( | |
2285 CreateNativePanelTesting(panel2)); | |
2286 gfx::Point mouse_location(panel2->GetBounds().origin()); | |
2287 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
2288 | |
2289 // Drag P2 away from the bottom of P1 to trigger the unstacking. | |
2290 // Expect that P1 and P2 get detached. | |
2291 gfx::Vector2d drag_delta_to_unstack = | |
2292 GetDragDeltaToUnstackFromBottom(panel2, panel1); | |
2293 mouse_location += drag_delta_to_unstack; | |
2294 panel2_testing->DragTitlebar(mouse_location); | |
2295 ASSERT_EQ(2, detached_collection->num_panels()); | |
2296 ASSERT_TRUE(stack->num_panels() == 0); | |
2297 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); | |
2298 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type()); | |
2299 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2300 panel2_expected_bounds.Offset(drag_delta_to_unstack); | |
2301 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2302 | |
2303 // Cancel the drag. | |
2304 // Expect that the P1 and P2 put back to the same stack. | |
2305 panel2_testing->CancelDragTitlebar(); | |
2306 WaitForBoundsAnimationFinished(panel2); | |
2307 ASSERT_EQ(0, detached_collection->num_panels()); | |
2308 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2309 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type()); | |
2310 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type()); | |
2311 EXPECT_EQ(stack, panel1->stack()); | |
2312 EXPECT_EQ(stack, panel2->stack()); | |
2313 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2314 EXPECT_EQ(panel2_old_bounds, panel2->GetBounds()); | |
2315 | |
2316 panel_manager->CloseAll(); | |
2317 } | |
2318 | |
2319 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, | |
2320 UngroupBottomPanelInThreePanelStack) { | |
2321 PanelManager* panel_manager = PanelManager::GetInstance(); | |
2322 DetachedPanelCollection* detached_collection = | |
2323 panel_manager->detached_collection(); | |
2324 | |
2325 // Create 3 stacked panels. | |
2326 StackedPanelCollection* stack = panel_manager->CreateStack(); | |
2327 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150); | |
2328 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack); | |
2329 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100); | |
2330 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack); | |
2331 gfx::Rect panel3_initial_bounds = gfx::Rect(0, 0, 120, 120); | |
2332 Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack); | |
2333 ASSERT_EQ(0, detached_collection->num_panels()); | |
2334 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2335 ASSERT_EQ(3, stack->num_panels()); | |
2336 EXPECT_EQ(stack, panel1->stack()); | |
2337 EXPECT_EQ(stack, panel2->stack()); | |
2338 EXPECT_EQ(stack, panel3->stack()); | |
2339 | |
2340 gfx::Rect panel1_expected_bounds(panel1_initial_bounds); | |
2341 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2342 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds( | |
2343 panel2_initial_bounds, panel1_expected_bounds); | |
2344 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2345 gfx::Rect panel3_expected_bounds = GetStackedAtBottomPanelBounds( | |
2346 panel3_initial_bounds, panel2_expected_bounds); | |
2347 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
2348 | |
2349 // Drag P3 away to unstack from P2 and P1. | |
2350 // Expect that P1 and P2 are still in the stack while P3 gets detached. | |
2351 gfx::Vector2d drag_delta_to_unstack = | |
2352 GetDragDeltaToUnstackFromBottom(panel3, panel2); | |
2353 DragPanelByDelta(panel3, drag_delta_to_unstack); | |
2354 ASSERT_EQ(1, detached_collection->num_panels()); | |
2355 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2356 ASSERT_EQ(2, stack->num_panels()); | |
2357 EXPECT_EQ(stack, panel1->stack()); | |
2358 EXPECT_EQ(stack, panel2->stack()); | |
2359 EXPECT_EQ(PanelCollection::DETACHED, panel3->collection()->type()); | |
2360 | |
2361 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2362 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2363 panel3_expected_bounds.Offset(drag_delta_to_unstack); | |
2364 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
2365 | |
2366 panel_manager->CloseAll(); | |
2367 } | |
2368 | |
2369 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, | |
2370 UngroupMiddlePanelInThreePanelStack) { | |
2371 PanelManager* panel_manager = PanelManager::GetInstance(); | |
2372 DetachedPanelCollection* detached_collection = | |
2373 panel_manager->detached_collection(); | |
2374 | |
2375 // Create 3 stacked panels. | |
2376 StackedPanelCollection* stack = panel_manager->CreateStack(); | |
2377 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150); | |
2378 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack); | |
2379 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100); | |
2380 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack); | |
2381 gfx::Rect panel3_initial_bounds = gfx::Rect(0, 0, 120, 120); | |
2382 Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack); | |
2383 ASSERT_EQ(0, detached_collection->num_panels()); | |
2384 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2385 ASSERT_EQ(3, stack->num_panels()); | |
2386 EXPECT_EQ(stack, panel1->stack()); | |
2387 EXPECT_EQ(stack, panel2->stack()); | |
2388 EXPECT_EQ(stack, panel3->stack()); | |
2389 | |
2390 gfx::Rect panel1_expected_bounds(panel1_initial_bounds); | |
2391 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2392 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds( | |
2393 panel2_initial_bounds, panel1_expected_bounds); | |
2394 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2395 gfx::Rect panel3_expected_bounds = GetStackedAtBottomPanelBounds( | |
2396 panel3_initial_bounds, panel2_expected_bounds); | |
2397 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
2398 | |
2399 // Drag P2 (together with P3) away to unstack from P1. | |
2400 // Expect that P2 and P3 are still in a stack while P1 gets detached. | |
2401 gfx::Vector2d drag_delta_to_unstack = | |
2402 GetDragDeltaToUnstackFromBottom(panel2, panel1); | |
2403 DragPanelByDelta(panel2, drag_delta_to_unstack); | |
2404 ASSERT_EQ(1, detached_collection->num_panels()); | |
2405 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2406 StackedPanelCollection* final_stack = panel_manager->stacks().front(); | |
2407 ASSERT_EQ(2, final_stack->num_panels()); | |
2408 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); | |
2409 EXPECT_EQ(final_stack, panel2->stack()); | |
2410 EXPECT_EQ(final_stack, panel3->stack()); | |
2411 | |
2412 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2413 panel2_expected_bounds.Offset(drag_delta_to_unstack); | |
2414 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2415 panel3_expected_bounds.Offset(drag_delta_to_unstack); | |
2416 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
2417 | |
2418 panel_manager->CloseAll(); | |
2419 } | |
2420 | |
2421 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, | |
2422 UngroupThirdPanelInFourPanelStack) { | |
2423 PanelManager* panel_manager = PanelManager::GetInstance(); | |
2424 DetachedPanelCollection* detached_collection = | |
2425 panel_manager->detached_collection(); | |
2426 | |
2427 // Create 4 stacked panels. | |
2428 StackedPanelCollection* stack = panel_manager->CreateStack(); | |
2429 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 120, 200, 100); | |
2430 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack); | |
2431 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100); | |
2432 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack); | |
2433 gfx::Rect panel3_initial_bounds = gfx::Rect(0, 0, 120, 120); | |
2434 Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack); | |
2435 gfx::Rect panel4_initial_bounds = gfx::Rect(0, 0, 120, 110); | |
2436 Panel* panel4 = CreateStackedPanel("4", panel4_initial_bounds, stack); | |
2437 ASSERT_EQ(0, detached_collection->num_panels()); | |
2438 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2439 ASSERT_EQ(4, stack->num_panels()); | |
2440 EXPECT_EQ(stack, panel1->stack()); | |
2441 EXPECT_EQ(stack, panel2->stack()); | |
2442 EXPECT_EQ(stack, panel3->stack()); | |
2443 EXPECT_EQ(stack, panel4->stack()); | |
2444 | |
2445 gfx::Rect panel1_expected_bounds(panel1_initial_bounds); | |
2446 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2447 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds( | |
2448 panel2_initial_bounds, panel1_expected_bounds); | |
2449 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2450 gfx::Rect panel3_expected_bounds = GetStackedAtBottomPanelBounds( | |
2451 panel3_initial_bounds, panel2_expected_bounds); | |
2452 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
2453 gfx::Rect panel4_expected_bounds = GetStackedAtBottomPanelBounds( | |
2454 panel4_initial_bounds, panel3_expected_bounds); | |
2455 EXPECT_EQ(panel4_expected_bounds, panel4->GetBounds()); | |
2456 | |
2457 // Drag P3 (together with P4) away to unstack from P2. | |
2458 // Expect that P1 and P2 are in one stack while P3 and P4 are in different | |
2459 // stack. | |
2460 gfx::Vector2d drag_delta_to_unstack = | |
2461 GetDragDeltaToUnstackFromBottom(panel3, panel2); | |
2462 DragPanelByDelta(panel3, drag_delta_to_unstack); | |
2463 ASSERT_EQ(0, detached_collection->num_panels()); | |
2464 ASSERT_EQ(2, panel_manager->num_stacks()); | |
2465 StackedPanelCollection* final_stack1 = panel_manager->stacks().front(); | |
2466 ASSERT_EQ(2, final_stack1->num_panels()); | |
2467 StackedPanelCollection* final_stack2 = panel_manager->stacks().back(); | |
2468 ASSERT_EQ(2, final_stack2->num_panels()); | |
2469 EXPECT_EQ(panel1->stack(), panel2->stack()); | |
2470 EXPECT_EQ(panel3->stack(), panel4->stack()); | |
2471 | |
2472 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2473 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2474 panel3_expected_bounds.Offset(drag_delta_to_unstack); | |
2475 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
2476 panel4_expected_bounds.Offset(drag_delta_to_unstack); | |
2477 EXPECT_EQ(panel4_expected_bounds, panel4->GetBounds()); | |
2478 | |
2479 panel_manager->CloseAll(); | |
2480 } | |
2481 | |
2482 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, UngroupAndGroup) { | |
2483 PanelManager* panel_manager = PanelManager::GetInstance(); | |
2484 DetachedPanelCollection* detached_collection = | |
2485 panel_manager->detached_collection(); | |
2486 | |
2487 // Create 2 stacked panels. | |
2488 StackedPanelCollection* stack = panel_manager->CreateStack(); | |
2489 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150); | |
2490 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack); | |
2491 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100); | |
2492 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack); | |
2493 ASSERT_EQ(0, detached_collection->num_panels()); | |
2494 ASSERT_EQ(2, stack->num_panels()); | |
2495 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2496 EXPECT_EQ(stack, panel1->stack()); | |
2497 EXPECT_EQ(stack, panel2->stack()); | |
2498 | |
2499 gfx::Rect panel1_expected_bounds(panel1_initial_bounds); | |
2500 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2501 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds( | |
2502 panel2_initial_bounds, panel1_expected_bounds); | |
2503 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2504 | |
2505 // Create 1 detached panel. | |
2506 gfx::Rect panel3_initial_bounds = gfx::Rect(300, 200, 100, 100); | |
2507 Panel* panel3 = CreateDetachedPanel("3", panel3_initial_bounds); | |
2508 ASSERT_EQ(1, detached_collection->num_panels()); | |
2509 gfx::Rect panel3_expected_bounds(panel3_initial_bounds); | |
2510 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
2511 | |
2512 // Drag P2 to the bottom edge of P3 to trigger both unstacking and stacking. | |
2513 // Expect that P3 and P2 are stacked together while P1 gets detached. | |
2514 gfx::Vector2d drag_delta_to_unstack_and_stack = | |
2515 GetDragDeltaToStackToBottom(panel2, panel3); | |
2516 DragPanelByDelta(panel2, drag_delta_to_unstack_and_stack); | |
2517 WaitForBoundsAnimationFinished(panel2); | |
2518 ASSERT_EQ(1, detached_collection->num_panels()); | |
2519 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2520 StackedPanelCollection* final_stack = panel_manager->stacks().front(); | |
2521 ASSERT_EQ(2, final_stack->num_panels()); | |
2522 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); | |
2523 EXPECT_EQ(final_stack, panel2->stack()); | |
2524 EXPECT_EQ(final_stack, panel3->stack()); | |
2525 | |
2526 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2527 panel2_expected_bounds = GetStackedAtBottomPanelBounds( | |
2528 panel2_initial_bounds, panel3_expected_bounds); | |
2529 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2530 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
2531 | |
2532 panel_manager->CloseAll(); | |
2533 } | |
2534 | |
2535 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, UngroupAndAttach) { | |
2536 PanelManager* panel_manager = PanelManager::GetInstance(); | |
2537 DockedPanelCollection* docked_collection = panel_manager->docked_collection(); | |
2538 DetachedPanelCollection* detached_collection = | |
2539 panel_manager->detached_collection(); | |
2540 | |
2541 // Create 2 stacked panels. | |
2542 StackedPanelCollection* stack = panel_manager->CreateStack(); | |
2543 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150); | |
2544 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack); | |
2545 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100); | |
2546 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack); | |
2547 ASSERT_EQ(0, docked_collection->num_panels()); | |
2548 ASSERT_EQ(0, detached_collection->num_panels()); | |
2549 ASSERT_EQ(2, stack->num_panels()); | |
2550 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2551 EXPECT_EQ(stack, panel1->stack()); | |
2552 EXPECT_EQ(stack, panel2->stack()); | |
2553 | |
2554 gfx::Rect panel1_expected_bounds(panel1_initial_bounds); | |
2555 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2556 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds( | |
2557 panel2_initial_bounds, panel1_expected_bounds); | |
2558 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2559 | |
2560 // Drag P2 close to the bottom of the work area to trigger both unstacking and | |
2561 // docking for P2. | |
2562 // Expect that P2 gets docked while P2 gets detached. | |
2563 gfx::Vector2d drag_delta_to_unstack_and_attach = GetDragDeltaToAttach(panel2); | |
2564 DragPanelByDelta(panel2, drag_delta_to_unstack_and_attach); | |
2565 WaitForBoundsAnimationFinished(panel2); | |
2566 ASSERT_EQ(1, docked_collection->num_panels()); | |
2567 ASSERT_EQ(1, detached_collection->num_panels()); | |
2568 ASSERT_EQ(0, panel_manager->num_stacks()); | |
2569 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); | |
2570 EXPECT_EQ(PanelCollection::DOCKED, panel2->collection()->type()); | |
2571 | |
2572 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2573 panel2_expected_bounds.set_x(docked_collection->StartingRightPosition() - | |
2574 panel2_expected_bounds.width()); | |
2575 panel2_expected_bounds.set_y(docked_collection->work_area().bottom() - | |
2576 panel2_expected_bounds.height()); | |
2577 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2578 | |
2579 panel_manager->CloseAll(); | |
2580 } | |
2581 | |
2582 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, SnapPanelToPanelLeft) { | |
2583 PanelManager* panel_manager = PanelManager::GetInstance(); | |
2584 DetachedPanelCollection* detached_collection = | |
2585 panel_manager->detached_collection(); | |
2586 | |
2587 // Create 2 detached panels. | |
2588 gfx::Rect panel1_initial_bounds = gfx::Rect(300, 200, 300, 200); | |
2589 Panel* panel1 = CreateDetachedPanel("1", panel1_initial_bounds); | |
2590 gfx::Rect panel2_initial_bounds = gfx::Rect(100, 100, 100, 250); | |
2591 Panel* panel2 = CreateDetachedPanel("2", panel2_initial_bounds); | |
2592 ASSERT_EQ(2, detached_collection->num_panels()); | |
2593 | |
2594 gfx::Rect panel1_expected_bounds(panel1_initial_bounds); | |
2595 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2596 gfx::Rect panel2_expected_bounds(panel2_initial_bounds); | |
2597 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2598 | |
2599 // Press on title-bar. | |
2600 std::unique_ptr<NativePanelTesting> panel2_testing( | |
2601 CreateNativePanelTesting(panel2)); | |
2602 gfx::Point mouse_location(panel2->GetBounds().origin()); | |
2603 gfx::Point original_mouse_location = mouse_location; | |
2604 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
2605 | |
2606 // Drag P2 close to the left of P1 to trigger the snapping. | |
2607 gfx::Vector2d drag_delta_to_snap = GetDragDeltaToSnapToLeft(panel2, panel1); | |
2608 mouse_location += drag_delta_to_snap; | |
2609 panel2_testing->DragTitlebar(mouse_location); | |
2610 ASSERT_EQ(2, detached_collection->num_panels()); | |
2611 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2612 panel2_expected_bounds.Offset(drag_delta_to_snap); | |
2613 panel2_expected_bounds.set_x( | |
2614 panel1_expected_bounds.x() - panel2_expected_bounds.width()); | |
2615 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2616 | |
2617 // Drag P2 a bit away from the left of P1 to trigger the unsnapping. | |
2618 gfx::Vector2d drag_delta_to_unsnap = GetDragDeltaToUnsnap(panel1); | |
2619 mouse_location += drag_delta_to_unsnap; | |
2620 panel2_testing->DragTitlebar(mouse_location); | |
2621 ASSERT_EQ(2, detached_collection->num_panels()); | |
2622 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2623 panel2_expected_bounds = panel2_initial_bounds; | |
2624 panel2_expected_bounds.Offset(mouse_location - original_mouse_location); | |
2625 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2626 | |
2627 // Drag P2 close to the left of P1 to trigger the snapping again. | |
2628 drag_delta_to_snap = GetDragDeltaToSnapToLeft(panel2, panel1); | |
2629 mouse_location += drag_delta_to_snap; | |
2630 panel2_testing->DragTitlebar(mouse_location); | |
2631 ASSERT_EQ(2, detached_collection->num_panels()); | |
2632 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2633 panel2_expected_bounds.Offset(drag_delta_to_snap); | |
2634 panel2_expected_bounds.set_x( | |
2635 panel1_expected_bounds.x() - panel2_expected_bounds.width()); | |
2636 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2637 | |
2638 // Drag P2 vertically with a little bit of horizontal movement should still | |
2639 // keep the snapping. | |
2640 gfx::Vector2d drag_delta_almost_vertically(2, 20); | |
2641 mouse_location += drag_delta_almost_vertically; | |
2642 panel2_testing->DragTitlebar(mouse_location); | |
2643 ASSERT_EQ(2, detached_collection->num_panels()); | |
2644 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2645 panel2_expected_bounds.set_y( | |
2646 panel2_expected_bounds.y() + drag_delta_almost_vertically.y()); | |
2647 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2648 | |
2649 // Finish the drag. | |
2650 panel2_testing->FinishDragTitlebar(); | |
2651 ASSERT_EQ(2, detached_collection->num_panels()); | |
2652 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2653 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2654 | |
2655 panel_manager->CloseAll(); | |
2656 } | |
2657 | |
2658 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, SnapPanelToPanelRight) { | |
2659 PanelManager* panel_manager = PanelManager::GetInstance(); | |
2660 DetachedPanelCollection* detached_collection = | |
2661 panel_manager->detached_collection(); | |
2662 | |
2663 // Create 2 detached panels. | |
2664 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 200, 100, 200); | |
2665 Panel* panel1 = CreateDetachedPanel("1", panel1_initial_bounds); | |
2666 gfx::Rect panel2_initial_bounds = gfx::Rect(300, 100, 200, 250); | |
2667 Panel* panel2 = CreateDetachedPanel("2", panel2_initial_bounds); | |
2668 ASSERT_EQ(2, detached_collection->num_panels()); | |
2669 | |
2670 gfx::Rect panel1_expected_bounds(panel1_initial_bounds); | |
2671 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2672 gfx::Rect panel2_expected_bounds(panel2_initial_bounds); | |
2673 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2674 | |
2675 // Press on title-bar. | |
2676 std::unique_ptr<NativePanelTesting> panel2_testing( | |
2677 CreateNativePanelTesting(panel2)); | |
2678 gfx::Point mouse_location(panel2->GetBounds().origin()); | |
2679 gfx::Point original_mouse_location = mouse_location; | |
2680 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
2681 | |
2682 // Drag P1 close to the right of P2 to trigger the snapping. | |
2683 gfx::Vector2d drag_delta_to_snap = GetDragDeltaToSnapToRight(panel2, panel1); | |
2684 mouse_location += drag_delta_to_snap; | |
2685 panel2_testing->DragTitlebar(mouse_location); | |
2686 ASSERT_EQ(2, detached_collection->num_panels()); | |
2687 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2688 panel2_expected_bounds.Offset(drag_delta_to_snap); | |
2689 panel2_expected_bounds.set_x(panel1_expected_bounds.right()); | |
2690 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2691 | |
2692 // Drag P2 a bit away from the right of P1 to trigger the unsnapping. | |
2693 gfx::Vector2d drag_delta_to_unsnap = GetDragDeltaToUnsnap(panel1); | |
2694 mouse_location += drag_delta_to_unsnap; | |
2695 panel2_testing->DragTitlebar(mouse_location); | |
2696 ASSERT_EQ(2, detached_collection->num_panels()); | |
2697 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2698 panel2_expected_bounds = panel2_initial_bounds; | |
2699 panel2_expected_bounds.Offset(mouse_location - original_mouse_location); | |
2700 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2701 | |
2702 // Drag P2 close to the right of P1 to trigger the snapping again. | |
2703 drag_delta_to_snap = GetDragDeltaToSnapToRight(panel2, panel1); | |
2704 mouse_location += drag_delta_to_snap; | |
2705 panel2_testing->DragTitlebar(mouse_location); | |
2706 ASSERT_EQ(2, detached_collection->num_panels()); | |
2707 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2708 panel2_expected_bounds.Offset(drag_delta_to_snap); | |
2709 panel2_expected_bounds.set_x(panel1_expected_bounds.right()); | |
2710 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2711 | |
2712 // Drag P2 vertically with a little bit of horizontal movement should still | |
2713 // keep the snapping. | |
2714 gfx::Vector2d drag_delta_almost_vertically(2, -20); | |
2715 mouse_location += drag_delta_almost_vertically; | |
2716 panel2_testing->DragTitlebar(mouse_location); | |
2717 ASSERT_EQ(2, detached_collection->num_panels()); | |
2718 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2719 panel2_expected_bounds.set_y( | |
2720 panel2_expected_bounds.y() + drag_delta_almost_vertically.y()); | |
2721 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2722 | |
2723 // Finish the drag. | |
2724 panel2_testing->FinishDragTitlebar(); | |
2725 ASSERT_EQ(2, detached_collection->num_panels()); | |
2726 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2727 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2728 | |
2729 panel_manager->CloseAll(); | |
2730 } | |
2731 | |
2732 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, SnapAndCancel) { | |
2733 PanelManager* panel_manager = PanelManager::GetInstance(); | |
2734 DetachedPanelCollection* detached_collection = | |
2735 panel_manager->detached_collection(); | |
2736 | |
2737 // Create 2 detached panels. | |
2738 gfx::Rect panel1_initial_bounds = gfx::Rect(300, 200, 300, 200); | |
2739 Panel* panel1 = CreateDetachedPanel("1", panel1_initial_bounds); | |
2740 gfx::Rect panel2_initial_bounds = gfx::Rect(100, 100, 100, 250); | |
2741 Panel* panel2 = CreateDetachedPanel("2", panel2_initial_bounds); | |
2742 ASSERT_EQ(2, detached_collection->num_panels()); | |
2743 | |
2744 gfx::Rect panel1_expected_bounds(panel1_initial_bounds); | |
2745 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2746 gfx::Rect panel2_expected_bounds(panel2_initial_bounds); | |
2747 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2748 | |
2749 // Press on title-bar. | |
2750 std::unique_ptr<NativePanelTesting> panel2_testing( | |
2751 CreateNativePanelTesting(panel2)); | |
2752 gfx::Point mouse_location(panel2->GetBounds().origin()); | |
2753 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
2754 | |
2755 // Drag P2 close to the left of P1 to trigger the snapping. | |
2756 gfx::Vector2d drag_delta_to_snap = GetDragDeltaToSnapToLeft(panel2, panel1); | |
2757 mouse_location += drag_delta_to_snap; | |
2758 panel2_testing->DragTitlebar(mouse_location); | |
2759 ASSERT_EQ(2, detached_collection->num_panels()); | |
2760 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2761 panel2_expected_bounds.Offset(drag_delta_to_snap); | |
2762 panel2_expected_bounds.set_x( | |
2763 panel1_expected_bounds.x() - panel2_expected_bounds.width()); | |
2764 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2765 | |
2766 // Cancel the drag. | |
2767 panel2_testing->CancelDragTitlebar(); | |
2768 ASSERT_EQ(2, detached_collection->num_panels()); | |
2769 EXPECT_EQ(panel1_initial_bounds, panel1->GetBounds()); | |
2770 EXPECT_EQ(panel2_initial_bounds, panel2->GetBounds()); | |
2771 | |
2772 panel_manager->CloseAll(); | |
2773 } | |
2774 | |
2775 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, SnapPanelToStackLeft) { | |
2776 PanelManager* panel_manager = PanelManager::GetInstance(); | |
2777 DetachedPanelCollection* detached_collection = | |
2778 panel_manager->detached_collection(); | |
2779 | |
2780 // Create 2 stacked panels. | |
2781 StackedPanelCollection* stack = panel_manager->CreateStack(); | |
2782 gfx::Rect panel1_initial_bounds = gfx::Rect(300, 100, 200, 150); | |
2783 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack); | |
2784 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100); | |
2785 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack); | |
2786 ASSERT_EQ(0, detached_collection->num_panels()); | |
2787 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2788 ASSERT_EQ(2, stack->num_panels()); | |
2789 EXPECT_EQ(stack, panel1->collection()); | |
2790 EXPECT_EQ(stack, panel2->collection()); | |
2791 | |
2792 gfx::Rect panel1_expected_bounds(panel1_initial_bounds); | |
2793 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2794 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds( | |
2795 panel2_initial_bounds, panel1_expected_bounds); | |
2796 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2797 | |
2798 // Create 1 detached panel. | |
2799 gfx::Rect panel3_initial_bounds = gfx::Rect(100, 200, 100, 100); | |
2800 Panel* panel3 = CreateDetachedPanel("3", panel3_initial_bounds); | |
2801 ASSERT_EQ(1, detached_collection->num_panels()); | |
2802 EXPECT_EQ(PanelCollection::DETACHED, panel3->collection()->type()); | |
2803 gfx::Rect panel3_expected_bounds(panel3_initial_bounds); | |
2804 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
2805 | |
2806 // Drag P3 close to the left of the stack of P1 and P2 to trigger the | |
2807 // snapping. | |
2808 gfx::Vector2d drag_delta_to_snap = GetDragDeltaToSnapToLeft(panel3, panel1); | |
2809 DragPanelByDelta(panel3, drag_delta_to_snap); | |
2810 ASSERT_EQ(1, detached_collection->num_panels()); | |
2811 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2812 ASSERT_EQ(2, stack->num_panels()); | |
2813 EXPECT_EQ(stack, panel1->collection()); | |
2814 EXPECT_EQ(stack, panel2->collection()); | |
2815 EXPECT_EQ(PanelCollection::DETACHED, panel3->collection()->type()); | |
2816 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2817 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2818 panel3_expected_bounds.Offset(drag_delta_to_snap); | |
2819 panel3_expected_bounds.set_x( | |
2820 panel1_expected_bounds.x() - panel3_expected_bounds.width()); | |
2821 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
2822 | |
2823 panel_manager->CloseAll(); | |
2824 } | |
2825 | |
2826 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, SnapPanelToStackRight) { | |
2827 PanelManager* panel_manager = PanelManager::GetInstance(); | |
2828 DetachedPanelCollection* detached_collection = | |
2829 panel_manager->detached_collection(); | |
2830 | |
2831 // Create 2 stacked panels. | |
2832 StackedPanelCollection* stack = panel_manager->CreateStack(); | |
2833 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 100, 200, 150); | |
2834 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack); | |
2835 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100); | |
2836 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack); | |
2837 ASSERT_EQ(0, detached_collection->num_panels()); | |
2838 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2839 ASSERT_EQ(2, stack->num_panels()); | |
2840 EXPECT_EQ(stack, panel1->collection()); | |
2841 EXPECT_EQ(stack, panel2->collection()); | |
2842 | |
2843 gfx::Rect panel1_expected_bounds(panel1_initial_bounds); | |
2844 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2845 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds( | |
2846 panel2_initial_bounds, panel1_expected_bounds); | |
2847 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2848 | |
2849 // Create 1 detached panel. | |
2850 gfx::Rect panel3_initial_bounds = gfx::Rect(300, 200, 100, 100); | |
2851 Panel* panel3 = CreateDetachedPanel("3", panel3_initial_bounds); | |
2852 ASSERT_EQ(1, detached_collection->num_panels()); | |
2853 EXPECT_EQ(PanelCollection::DETACHED, panel3->collection()->type()); | |
2854 gfx::Rect panel3_expected_bounds(panel3_initial_bounds); | |
2855 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
2856 | |
2857 // Drag P3 close to the right of the stack of P1 and P2 to trigger the | |
2858 // snapping. | |
2859 gfx::Vector2d drag_delta_to_snap = GetDragDeltaToSnapToRight(panel3, panel1); | |
2860 DragPanelByDelta(panel3, drag_delta_to_snap); | |
2861 ASSERT_EQ(1, detached_collection->num_panels()); | |
2862 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2863 ASSERT_EQ(2, stack->num_panels()); | |
2864 EXPECT_EQ(stack, panel1->collection()); | |
2865 EXPECT_EQ(stack, panel2->collection()); | |
2866 EXPECT_EQ(PanelCollection::DETACHED, panel3->collection()->type()); | |
2867 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2868 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2869 panel3_expected_bounds.Offset(drag_delta_to_snap); | |
2870 panel3_expected_bounds.set_x(panel1_expected_bounds.right()); | |
2871 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
2872 | |
2873 panel_manager->CloseAll(); | |
2874 } | |
2875 | |
2876 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DetachAndSnap) { | |
2877 PanelManager* panel_manager = PanelManager::GetInstance(); | |
2878 DockedPanelCollection* docked_collection = panel_manager->docked_collection(); | |
2879 DetachedPanelCollection* detached_collection = | |
2880 panel_manager->detached_collection(); | |
2881 | |
2882 // Create 1 detached panel. | |
2883 Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(300, 200, 100, 100)); | |
2884 ASSERT_EQ(0, docked_collection->num_panels()); | |
2885 ASSERT_EQ(1, detached_collection->num_panels()); | |
2886 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); | |
2887 gfx::Rect panel1_bounds = panel1->GetBounds(); | |
2888 | |
2889 // Create 1 docked panel. | |
2890 Panel* panel2 = CreateDockedPanel("2", gfx::Rect(0, 0, 150, 150)); | |
2891 ASSERT_EQ(1, docked_collection->num_panels()); | |
2892 ASSERT_EQ(1, detached_collection->num_panels()); | |
2893 EXPECT_EQ(PanelCollection::DOCKED, panel2->collection()->type()); | |
2894 gfx::Rect panel2_bounds = panel2->GetBounds(); | |
2895 | |
2896 // Drag P2 close to the right of P1 to trigger both detaching and snapping. | |
2897 gfx::Vector2d drag_delta_to_detach_and_snap = | |
2898 GetDragDeltaToSnapToRight(panel2, panel1); | |
2899 DragPanelByDelta(panel2, drag_delta_to_detach_and_snap); | |
2900 ASSERT_EQ(0, docked_collection->num_panels()); | |
2901 ASSERT_EQ(2, detached_collection->num_panels()); | |
2902 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); | |
2903 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type()); | |
2904 EXPECT_EQ(panel1_bounds, panel1->GetBounds()); | |
2905 panel2_bounds.Offset(drag_delta_to_detach_and_snap); | |
2906 panel2_bounds.set_x(panel1_bounds.right()); | |
2907 EXPECT_EQ(panel2_bounds, panel2->GetBounds()); | |
2908 | |
2909 panel_manager->CloseAll(); | |
2910 } | |
2911 | |
2912 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragTopStackedPanel) { | |
2913 PanelManager* panel_manager = PanelManager::GetInstance(); | |
2914 | |
2915 // Create 3 stacked panels. | |
2916 StackedPanelCollection* stack = panel_manager->CreateStack(); | |
2917 gfx::Rect panel1_initial_bounds = gfx::Rect(300, 100, 200, 150); | |
2918 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack); | |
2919 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100); | |
2920 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack); | |
2921 gfx::Rect panel3_initial_bounds = gfx::Rect(0, 0, 150, 200); | |
2922 Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack); | |
2923 ASSERT_EQ(3, stack->num_panels()); | |
2924 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2925 EXPECT_EQ(stack, panel1->collection()); | |
2926 EXPECT_EQ(stack, panel2->collection()); | |
2927 EXPECT_EQ(stack, panel3->collection()); | |
2928 | |
2929 gfx::Rect panel1_expected_bounds(panel1_initial_bounds); | |
2930 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2931 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds( | |
2932 panel2_initial_bounds, panel1_expected_bounds); | |
2933 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2934 gfx::Rect panel3_expected_bounds = GetStackedAtBottomPanelBounds( | |
2935 panel3_initial_bounds, panel2_expected_bounds); | |
2936 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
2937 | |
2938 // Drag the top panel by a delta. | |
2939 // Expect all panels are still in the same stack and they are all moved by the | |
2940 // same delta. | |
2941 gfx::Vector2d drag_delta(-50, -20); | |
2942 DragPanelByDelta(panel1, drag_delta); | |
2943 ASSERT_EQ(3, stack->num_panels()); | |
2944 ASSERT_EQ(1, panel_manager->num_stacks()); | |
2945 EXPECT_EQ(stack, panel1->collection()); | |
2946 EXPECT_EQ(stack, panel2->collection()); | |
2947 EXPECT_EQ(stack, panel3->collection()); | |
2948 | |
2949 panel1_expected_bounds.Offset(drag_delta); | |
2950 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
2951 panel2_expected_bounds.Offset(drag_delta); | |
2952 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
2953 panel3_expected_bounds.Offset(drag_delta); | |
2954 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
2955 | |
2956 panel_manager->CloseAll(); | |
2957 } | |
2958 | |
2959 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, SnapDetachedPanelToScreenEdge) { | |
2960 PanelManager* panel_manager = PanelManager::GetInstance(); | |
2961 int small_distance = | |
2962 PanelDragController::GetSnapPanelToScreenEdgeThresholdForTesting() / 2; | |
2963 | |
2964 // Setup 2 displays with secondary display on the right side of primary | |
2965 // display. | |
2966 gfx::Rect primary_display_area(0, 0, 400, 600); | |
2967 gfx::Rect primary_work_area(0, 0, 400, 560); | |
2968 mock_display_settings_provider()->SetPrimaryDisplay( | |
2969 primary_display_area, primary_work_area); | |
2970 gfx::Rect secondary_display_area(400, 100, 400, 500); | |
2971 gfx::Rect secondary_work_area(400, 140, 400, 460); | |
2972 mock_display_settings_provider()->SetSecondaryDisplay( | |
2973 secondary_display_area, secondary_work_area); | |
2974 | |
2975 // Create one detached panel on the primary display. | |
2976 gfx::Rect initial_bounds = gfx::Rect(100, 100, 200, 150); | |
2977 Panel* panel = CreateDetachedPanel("1", initial_bounds); | |
2978 gfx::Rect expected_bounds(initial_bounds); | |
2979 EXPECT_EQ(expected_bounds, panel->GetBounds()); | |
2980 | |
2981 // Drag the panel close to the right edge of the primary display. | |
2982 // Expect that the panel should snap to the right edge. | |
2983 gfx::Point drag_to_location( | |
2984 primary_work_area.right() - small_distance - panel->GetBounds().width(), | |
2985 panel->GetBounds().y()); | |
2986 DragPanelToMouseLocation(panel, drag_to_location); | |
2987 expected_bounds.set_x(primary_work_area.right() - panel->GetBounds().width()); | |
2988 EXPECT_EQ(expected_bounds, panel->GetBounds()); | |
2989 | |
2990 // Drag the panel close to the top-left corner of the primary display. | |
2991 // Expect that the panel should snap to the top-left corner. | |
2992 drag_to_location = gfx::Point( | |
2993 primary_work_area.x() + small_distance, | |
2994 primary_work_area.y() - small_distance); | |
2995 DragPanelToMouseLocation(panel, drag_to_location); | |
2996 expected_bounds.set_origin(primary_work_area.origin()); | |
2997 EXPECT_EQ(expected_bounds, panel->GetBounds()); | |
2998 | |
2999 // Drag the panel close to the top-right corner of the secondary display. | |
3000 // Expect that the panel should snap to the top-right corner. | |
3001 drag_to_location = gfx::Point( | |
3002 secondary_work_area.right() - small_distance - panel->GetBounds().width(), | |
3003 secondary_work_area.y() + small_distance); | |
3004 DragPanelToMouseLocation(panel, drag_to_location); | |
3005 expected_bounds.set_x( | |
3006 secondary_work_area.right() - panel->GetBounds().width()); | |
3007 expected_bounds.set_y(secondary_work_area.y()); | |
3008 EXPECT_EQ(expected_bounds, panel->GetBounds()); | |
3009 | |
3010 panel_manager->CloseAll(); | |
3011 } | |
3012 | |
3013 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, SnapStackedPanelToScreenEdge) { | |
3014 PanelManager* panel_manager = PanelManager::GetInstance(); | |
3015 int small_distance = | |
3016 PanelDragController::GetSnapPanelToScreenEdgeThresholdForTesting() / 2; | |
3017 | |
3018 // Setup 2 displays with secondary display on the right side of primary | |
3019 // display. | |
3020 gfx::Rect primary_display_area(0, 0, 400, 600); | |
3021 gfx::Rect primary_work_area(0, 0, 400, 560); | |
3022 mock_display_settings_provider()->SetPrimaryDisplay( | |
3023 primary_display_area, primary_work_area); | |
3024 gfx::Rect secondary_display_area(400, 100, 400, 500); | |
3025 gfx::Rect secondary_work_area(400, 140, 400, 460); | |
3026 mock_display_settings_provider()->SetSecondaryDisplay( | |
3027 secondary_display_area, secondary_work_area); | |
3028 | |
3029 // Create 2 stacked panels on the primary display. | |
3030 StackedPanelCollection* stack = panel_manager->CreateStack(); | |
3031 gfx::Rect panel1_initial_bounds = gfx::Rect(300, 100, 200, 150); | |
3032 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack); | |
3033 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100); | |
3034 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack); | |
3035 | |
3036 gfx::Rect panel1_expected_bounds(panel1_initial_bounds); | |
3037 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
3038 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds( | |
3039 panel2_initial_bounds, panel1_expected_bounds); | |
3040 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
3041 | |
3042 // Drag the stack close to the left edge of the primary display. | |
3043 // Expect that the stack should snap to the left edge. | |
3044 gfx::Point drag_to_location( | |
3045 primary_work_area.x() + small_distance, panel1->GetBounds().y()); | |
3046 DragPanelToMouseLocation(panel1, drag_to_location); | |
3047 | |
3048 panel1_expected_bounds.set_x(primary_work_area.x()); | |
3049 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
3050 panel2_expected_bounds.set_x(primary_work_area.x()); | |
3051 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
3052 | |
3053 // Drag the stack close to the bottom-right corner of the primary display. | |
3054 // Expect that the stack should snap to the bottom-right corner. | |
3055 drag_to_location = gfx::Point( | |
3056 primary_work_area.right() + small_distance - panel1->GetBounds().width(), | |
3057 primary_work_area.bottom() - small_distance - | |
3058 panel1->GetBounds().height() - panel2->GetBounds().height()); | |
3059 DragPanelToMouseLocation(panel1, drag_to_location); | |
3060 | |
3061 int expected_x = primary_work_area.right() - panel1->GetBounds().width(); | |
3062 panel1_expected_bounds.set_x(expected_x); | |
3063 panel1_expected_bounds.set_y(primary_work_area.bottom() - | |
3064 panel1->GetBounds().height() - panel2->GetBounds().height()); | |
3065 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
3066 panel2_expected_bounds.set_x(expected_x); | |
3067 panel2_expected_bounds.set_y(primary_work_area.bottom() - | |
3068 panel2->GetBounds().height()); | |
3069 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
3070 | |
3071 // Drag the stack close to the top-left corner of the secondary display. | |
3072 // Expect that the stack should snap to the top-left corner. | |
3073 drag_to_location = gfx::Point( | |
3074 secondary_work_area.x() + small_distance, | |
3075 secondary_work_area.y() + small_distance); | |
3076 DragPanelToMouseLocation(panel1, drag_to_location); | |
3077 | |
3078 expected_x = secondary_work_area.x(); | |
3079 panel1_expected_bounds.set_x(expected_x); | |
3080 panel1_expected_bounds.set_y(secondary_work_area.y()); | |
3081 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
3082 panel2_expected_bounds.set_x(expected_x); | |
3083 panel2_expected_bounds.set_y(panel1_expected_bounds.bottom()); | |
3084 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
3085 | |
3086 panel_manager->CloseAll(); | |
3087 } | |
OLD | NEW |