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