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

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

Issue 11669018: Support dragging panels to stack and snap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix CrOS build for relanding Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "chrome/browser/ui/panels/base_panel_browser_test.h" 6 #include "chrome/browser/ui/panels/base_panel_browser_test.h"
7 #include "chrome/browser/ui/panels/detached_panel_collection.h" 7 #include "chrome/browser/ui/panels/detached_panel_collection.h"
8 #include "chrome/browser/ui/panels/docked_panel_collection.h" 8 #include "chrome/browser/ui/panels/docked_panel_collection.h"
9 #include "chrome/browser/ui/panels/native_panel.h" 9 #include "chrome/browser/ui/panels/native_panel.h"
10 #include "chrome/browser/ui/panels/panel.h" 10 #include "chrome/browser/ui/panels/panel.h"
11 #include "chrome/browser/ui/panels/panel_drag_controller.h" 11 #include "chrome/browser/ui/panels/panel_drag_controller.h"
12 #include "chrome/browser/ui/panels/panel_manager.h" 12 #include "chrome/browser/ui/panels/panel_manager.h"
13 #include "chrome/browser/ui/panels/stacked_panel_collection.h"
13 #include "chrome/browser/ui/panels/test_panel_collection_squeeze_observer.h" 14 #include "chrome/browser/ui/panels/test_panel_collection_squeeze_observer.h"
14 #include "chrome/common/chrome_notification_types.h" 15 #include "chrome/common/chrome_notification_types.h"
15 #include "content/public/browser/notification_service.h" 16 #include "content/public/browser/notification_service.h"
16 #include "content/public/test/test_utils.h" 17 #include "content/public/test/test_utils.h"
17 18
18 class PanelDragBrowserTest : public BasePanelBrowserTest { 19 class PanelDragBrowserTest : public BasePanelBrowserTest {
19 public: 20 public:
20 PanelDragBrowserTest() : BasePanelBrowserTest() { 21 PanelDragBrowserTest() : BasePanelBrowserTest() {
21 } 22 }
22 23
(...skipping 25 matching lines...) Expand all
48 void DragPanelToMouseLocation(Panel* panel, 49 void DragPanelToMouseLocation(Panel* panel,
49 const gfx::Point& new_mouse_location) { 50 const gfx::Point& new_mouse_location) {
50 scoped_ptr<NativePanelTesting> panel_testing( 51 scoped_ptr<NativePanelTesting> panel_testing(
51 CreateNativePanelTesting(panel)); 52 CreateNativePanelTesting(panel));
52 gfx::Point mouse_location(panel->GetBounds().origin()); 53 gfx::Point mouse_location(panel->GetBounds().origin());
53 panel_testing->PressLeftMouseButtonTitlebar(panel->GetBounds().origin()); 54 panel_testing->PressLeftMouseButtonTitlebar(panel->GetBounds().origin());
54 panel_testing->DragTitlebar(new_mouse_location); 55 panel_testing->DragTitlebar(new_mouse_location);
55 panel_testing->FinishDragTitlebar(); 56 panel_testing->FinishDragTitlebar();
56 } 57 }
57 58
59 // Return the bounds of a panel given its initial bounds and the bounds of the
60 // panel above it.
61 static gfx::Rect GetStackedAtBottomPanelBounds(
62 const gfx::Rect& initial_bounds,
63 const gfx::Rect& above_bounds) {
64 return gfx::Rect(above_bounds.x(),
65 above_bounds.bottom(),
66 above_bounds.width(),
67 initial_bounds.height());
68 }
69
70 // Return the bounds of a panel given its initial bounds and the bounds of the
71 // panel below it.
72 static gfx::Rect GetStackedAtTopPanelBounds(
73 const gfx::Rect& initial_bounds,
74 const gfx::Rect& below_bounds) {
75 return gfx::Rect(below_bounds.x(),
76 below_bounds.y() - initial_bounds.height(),
77 initial_bounds.width(),
78 initial_bounds.height());
79 }
80
58 static gfx::Vector2d GetDragDeltaToRemainDocked() { 81 static gfx::Vector2d GetDragDeltaToRemainDocked() {
59 return gfx::Vector2d( 82 return gfx::Vector2d(
60 -5, 83 -5,
61 -(PanelDragController::GetDetachDockedPanelThresholdForTesting() / 2)); 84 -(PanelDragController::GetDetachDockedPanelThresholdForTesting() / 2));
62 } 85 }
63 86
64 static gfx::Vector2d GetDragDeltaToDetach() { 87 static gfx::Vector2d GetDragDeltaToDetach() {
65 return gfx::Vector2d( 88 return gfx::Vector2d(
66 -20, 89 -20,
67 -(PanelDragController::GetDetachDockedPanelThresholdForTesting() + 20)); 90 -(PanelDragController::GetDetachDockedPanelThresholdForTesting() + 20));
(...skipping 11 matching lines...) Expand all
79 102
80 static gfx::Vector2d GetDragDeltaToAttach(Panel* panel) { 103 static gfx::Vector2d GetDragDeltaToAttach(Panel* panel) {
81 int distance = 104 int distance =
82 panel->manager()->docked_collection()->display_area().bottom() - 105 panel->manager()->docked_collection()->display_area().bottom() -
83 panel->GetBounds().bottom(); 106 panel->GetBounds().bottom();
84 return gfx::Vector2d( 107 return gfx::Vector2d(
85 -20, 108 -20,
86 distance - 109 distance -
87 PanelDragController::GetDockDetachedPanelThresholdForTesting() / 2); 110 PanelDragController::GetDockDetachedPanelThresholdForTesting() / 2);
88 } 111 }
112
113 // Return the delta needed to drag |panel1| to stack to the bottom of
114 // |panel2|.
115 static gfx::Vector2d GetDragDeltaToStackToBottom(Panel* panel1,
116 Panel* panel2) {
117 gfx::Rect bounds1 = panel1->GetBounds();
118 gfx::Rect bounds2 = panel2->GetBounds();
119 return gfx::Vector2d(
120 bounds2.x() - bounds1.x(),
121 bounds2.bottom() - bounds1.y() +
122 PanelDragController::GetGluePanelDistanceThresholdForTesting() / 2);
123 }
124
125 // Return the delta needed to drag |panel1| to unstack from the bottom of
126 // |panel2|.
127 static gfx::Vector2d GetDragDeltaToUnstackFromBottom(Panel* panel1,
128 Panel* panel2) {
129 gfx::Rect bounds1 = panel1->GetBounds();
130 gfx::Rect bounds2 = panel2->GetBounds();
131 return gfx::Vector2d(
132 0, PanelDragController::GetGluePanelDistanceThresholdForTesting() * 2);
133 }
134
135 // Return the delta needed to drag |panel1| to stack to the top of |panel2|.
136 static gfx::Vector2d GetDragDeltaToStackToTop(Panel* panel1, Panel* panel2) {
137 gfx::Rect bounds1 = panel1->GetBounds();
138 gfx::Rect bounds2 = panel2->GetBounds();
139 StackedPanelCollection* stack1 = panel1->stack();
140 int bottom = stack1 ? stack1->bottom_panel()->GetBounds().bottom()
141 : bounds1.bottom();
142 return gfx::Vector2d(
143 bounds2.x() - bounds1.x(),
144 bounds2.y() - bottom -
145 PanelDragController::GetGluePanelDistanceThresholdForTesting() / 2);
146 }
147
148 // Return the delta needed to drag |panel1| to unstack from the top of
149 // |panel2|.
150 static gfx::Vector2d GetDragDeltaToUnstackFromTop(Panel* panel1,
151 Panel* panel2) {
152 gfx::Rect bounds1 = panel1->GetBounds();
153 gfx::Rect bounds2 = panel2->GetBounds();
154 return gfx::Vector2d(
155 0, -PanelDragController::GetGluePanelDistanceThresholdForTesting() * 2);
156 }
157
158 // Return the delta needed to drag |panel1| to snap to the left of |panel2|.
159 static gfx::Vector2d GetDragDeltaToSnapToLeft(Panel* panel1,
160 Panel* panel2) {
161 gfx::Rect bounds1 = panel1->GetBounds();
162 gfx::Rect bounds2 = panel2->GetBounds();
163 return gfx::Vector2d(
164 bounds2.x() - bounds1.width() - bounds1.x() -
165 PanelDragController::GetGluePanelDistanceThresholdForTesting() / 2,
166 bounds2.y() - bounds1.y() +
167 PanelDragController::GetGluePanelDistanceThresholdForTesting() * 2);
168 }
169
170 // Return the delta needed to drag |panel1| to snap to the right of |panel2|.
171 static gfx::Vector2d GetDragDeltaToSnapToRight(Panel* panel1,
172 Panel* panel2) {
173 gfx::Rect bounds1 = panel1->GetBounds();
174 gfx::Rect bounds2 = panel2->GetBounds();
175 return gfx::Vector2d(
176 bounds2.right() - bounds1.x() +
177 PanelDragController::GetGluePanelDistanceThresholdForTesting() / 2,
178 bounds2.y() - bounds1.y() +
179 PanelDragController::GetGluePanelDistanceThresholdForTesting() * 2);
180 }
181
182 // Return the delta needed to drag |panel| to unsnap from its current
183 // position.
184 static gfx::Vector2d GetDragDeltaToUnsnap(Panel* panel) {
185 return gfx::Vector2d(
186 PanelDragController::GetGluePanelDistanceThresholdForTesting() * 2, 0);
187 }
89 }; 188 };
90 189
91 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragOneDockedPanel) { 190 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragOneDockedPanel) {
92 static const int big_delta_x = 70; 191 static const int big_delta_x = 70;
93 static const int big_delta_y = 30; // Do not exceed the threshold to detach. 192 static const int big_delta_y = 30; // Do not exceed the threshold to detach.
94 193
95 Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100)); 194 Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100));
96 scoped_ptr<NativePanelTesting> panel_testing( 195 scoped_ptr<NativePanelTesting> panel_testing(
97 CreateNativePanelTesting(panel)); 196 CreateNativePanelTesting(panel));
98 gfx::Rect panel_old_bounds = panel->GetBounds(); 197 gfx::Rect panel_old_bounds = panel->GetBounds();
(...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after
1375 1474
1376 // Drag down the panel. Expect that the panel can be dragged without 1475 // Drag down the panel. Expect that the panel can be dragged without
1377 // constraint. 1476 // constraint.
1378 drag_to_location = gfx::Point(280, 150); 1477 drag_to_location = gfx::Point(280, 150);
1379 DragPanelToMouseLocation(panel, drag_to_location); 1478 DragPanelToMouseLocation(panel, drag_to_location);
1380 EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type()); 1479 EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type());
1381 EXPECT_EQ(drag_to_location, panel->GetBounds().origin()); 1480 EXPECT_EQ(drag_to_location, panel->GetBounds().origin());
1382 1481
1383 panel_manager->CloseAll(); 1482 panel_manager->CloseAll();
1384 } 1483 }
1484
1485 // TODO(jianli): to be enabled for other platforms when grouping and snapping
1486 // are supported.
1487 #if defined(OS_WIN)
1488 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupPanelAndPanelFromBottom) {
1489 PanelManager* panel_manager = PanelManager::GetInstance();
1490 DetachedPanelCollection* detached_collection =
1491 panel_manager->detached_collection();
1492
1493 // Create two detached panels.
1494 Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(300, 200, 200, 100));
1495 Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(100, 100, 150, 150));
1496 ASSERT_EQ(2, detached_collection->num_panels());
1497 ASSERT_EQ(0, panel_manager->num_stacks());
1498 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
1499 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
1500
1501 gfx::Rect panel1_old_bounds = panel1->GetBounds();
1502 gfx::Rect panel2_old_bounds = panel2->GetBounds();
1503
1504 // Press on title-bar of P2.
1505 scoped_ptr<NativePanelTesting> panel2_testing(
1506 CreateNativePanelTesting(panel2));
1507 gfx::Point mouse_location(panel2->GetBounds().origin());
1508 gfx::Point original_mouse_location = mouse_location;
1509 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location);
1510
1511 // Drag P2 close to the bottom of P1 to trigger the stacking. Expect:
1512 // 1) P1 and P2 form a stack.
1513 // 2) P2 jumps vertcially to align to the bottom edge of P1.
1514 // 3) P2 moves horizontally by the dragging delta.
1515 // 4) The width of P2 remains unchanged.
1516 gfx::Vector2d drag_delta_to_stack =
1517 GetDragDeltaToStackToBottom(panel2, panel1);
1518 mouse_location = mouse_location + drag_delta_to_stack;
1519 panel2_testing->DragTitlebar(mouse_location);
1520 ASSERT_EQ(0, detached_collection->num_panels());
1521 ASSERT_EQ(1, panel_manager->num_stacks());
1522 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
1523 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
1524 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
1525 gfx::Rect panel2_new_bounds(panel2_old_bounds.x() + drag_delta_to_stack.x(),
1526 panel1_old_bounds.bottom(),
1527 panel2_old_bounds.width(),
1528 panel2_old_bounds.height());
1529 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
1530
1531 // Drag P2 somewhat away from the bottom of P1 to trigger the unstacking.
1532 // Expect P1 and P2 become detached.
1533 gfx::Vector2d drag_delta_to_unstack =
1534 GetDragDeltaToUnstackFromBottom(panel2, panel1);
1535 mouse_location = mouse_location + drag_delta_to_unstack;
1536 panel2_testing->DragTitlebar(mouse_location);
1537 ASSERT_EQ(2, detached_collection->num_panels());
1538 ASSERT_EQ(0, panel_manager->num_stacks());
1539 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
1540 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
1541 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
1542 panel2_new_bounds.set_origin(panel2_old_bounds.origin());
1543 panel2_new_bounds.Offset(mouse_location - original_mouse_location);
1544 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
1545
1546 // Drag P2 close to the bottom of P1 to trigger the stacking again. Expect:
1547 // 1) P1 and P2 form a stack.
1548 // 2) P2 jumps vertcially to align to the bottom edge of P1.
1549 // 3) P2 moves horizontally by the dragging delta.
1550 // 4) The width of P2 remains unchanged.
1551 drag_delta_to_stack = GetDragDeltaToStackToBottom(panel2, panel1);
1552 mouse_location = mouse_location + drag_delta_to_stack;
1553 panel2_testing->DragTitlebar(mouse_location);
1554 ASSERT_EQ(0, detached_collection->num_panels());
1555 ASSERT_EQ(1, panel_manager->num_stacks());
1556 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
1557 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
1558 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
1559 panel2_new_bounds.set_x(panel2_new_bounds.x() + drag_delta_to_stack.x());
1560 panel2_new_bounds.set_y(panel1_old_bounds.bottom());
1561 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
1562
1563 // Move the mouse a little bit. Expect P2 only moves horizontally. P2 should
1564 // not move vertically since its top edge already glues to the bottom edge
1565 // of P1.
1566 gfx::Vector2d small_delta(1, -1);
1567 mouse_location = mouse_location + small_delta;
1568 panel2_testing->DragTitlebar(mouse_location);
1569 ASSERT_EQ(0, detached_collection->num_panels());
1570 ASSERT_EQ(1, panel_manager->num_stacks());
1571 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
1572 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
1573 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
1574 panel2_new_bounds.set_x(panel2_new_bounds.x() + small_delta.x());
1575 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
1576
1577 // Finish the drag. Expect:
1578 // 1) P1 and P2 remain stacked.
1579 // 2) P2 moves horizontally to align with P1.
1580 // 3) The width of P2 is adjusted to be same as the one of P1.
1581 panel2_testing->FinishDragTitlebar();
1582 ASSERT_EQ(0, detached_collection->num_panels());
1583 ASSERT_EQ(1, panel_manager->num_stacks());
1584 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
1585 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
1586 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
1587 panel2_new_bounds.set_x(panel1_old_bounds.x());
1588 panel2_new_bounds.set_width(panel1_old_bounds.width());
1589 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
1590
1591 panel_manager->CloseAll();
1592 }
1593
1594 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupPanelAndPanelFromTop) {
1595 PanelManager* panel_manager = PanelManager::GetInstance();
1596 DetachedPanelCollection* detached_collection =
1597 panel_manager->detached_collection();
1598
1599 // Create two detached panels.
1600 Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(300, 200, 200, 100));
1601 Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(100, 100, 150, 150));
1602 ASSERT_EQ(2, detached_collection->num_panels());
1603 ASSERT_EQ(0, panel_manager->num_stacks());
1604 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
1605 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
1606
1607 gfx::Rect panel1_old_bounds = panel1->GetBounds();
1608 gfx::Rect panel2_old_bounds = panel2->GetBounds();
1609
1610 // Press on title-bar of P2.
1611 scoped_ptr<NativePanelTesting> panel2_testing(
1612 CreateNativePanelTesting(panel2));
1613 gfx::Point mouse_location(panel2->GetBounds().origin());
1614 gfx::Point original_mouse_location = mouse_location;
1615 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location);
1616
1617 // Drag P2 close to the top of P1 to trigger the stacking. Expect:
1618 // 1) P2 and P1 form a stack.
1619 // 2) P2 jumps vertcially to align to the top edge of P1.
1620 // 3) P2 moves horizontally by the dragging delta.
1621 // 4) The width of both P1 and P2 remains unchanged.
1622 gfx::Vector2d drag_delta_to_stack = GetDragDeltaToStackToTop(panel2, panel1);
1623 mouse_location = mouse_location + drag_delta_to_stack;
1624 panel2_testing->DragTitlebar(mouse_location);
1625 ASSERT_EQ(0, detached_collection->num_panels());
1626 ASSERT_EQ(1, panel_manager->num_stacks());
1627 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
1628 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
1629 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
1630 gfx::Rect panel2_new_bounds(
1631 panel2_old_bounds.x() + drag_delta_to_stack.x(),
1632 panel1_old_bounds.y() - panel2_old_bounds.height(),
1633 panel2_old_bounds.width(),
1634 panel2_old_bounds.height());
1635 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
1636
1637 // Drag P2 somewhat away from the top of P1 to trigger the unstacking.
1638 // Expect P1 and P2 become detached.
1639 gfx::Vector2d drag_delta_to_unstack =
1640 GetDragDeltaToUnstackFromTop(panel2, panel1);
1641 mouse_location = mouse_location + drag_delta_to_unstack;
1642 panel2_testing->DragTitlebar(mouse_location);
1643 ASSERT_EQ(2, detached_collection->num_panels());
1644 ASSERT_EQ(0, panel_manager->num_stacks());
1645 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
1646 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
1647 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
1648 panel2_new_bounds.set_origin(panel2_old_bounds.origin());
1649 panel2_new_bounds.Offset(mouse_location - original_mouse_location);
1650 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
1651
1652 // Drag P2 close to the top of P1 to trigger the stacking again. Expect:
1653 // 1) P2 and P1 form a stack.
1654 // 2) P2 jumps vertcially to align to the top edge of P1.
1655 // 3) P2 moves horizontally by the dragging delta.
1656 // 4) The width of both P1 and P2 remains unchanged.
1657 drag_delta_to_stack = GetDragDeltaToStackToTop(panel2, panel1);
1658 mouse_location = mouse_location + drag_delta_to_stack;
1659 panel2_testing->DragTitlebar(mouse_location);
1660 ASSERT_EQ(0, detached_collection->num_panels());
1661 ASSERT_EQ(1, panel_manager->num_stacks());
1662 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
1663 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
1664 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
1665 panel2_new_bounds.set_x(panel2_new_bounds.x() + drag_delta_to_stack.x());
1666 panel2_new_bounds.set_y(panel1_old_bounds.y() - panel2_old_bounds.height());
1667 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
1668
1669 // Move the mouse a little bit. Expect only P2 moves horizontally. P2 should
1670 // not move vertically because its bottom edge already glues to the top edge
1671 // of P1.
1672 gfx::Vector2d small_delta(1, -1);
1673 mouse_location = mouse_location + small_delta;
1674 panel2_testing->DragTitlebar(mouse_location);
1675 ASSERT_EQ(0, detached_collection->num_panels());
1676 ASSERT_EQ(1, panel_manager->num_stacks());
1677 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
1678 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
1679 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
1680 panel2_new_bounds.set_x(panel2_new_bounds.x() + small_delta.x());
1681 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
1682
1683 // Finish the drag. Expect:
1684 // 1) P2 and P1 remain stacked.
1685 // 2) P2 moves horizontally to align with P1.
1686 // 3) The width of P1 is adjusted to be same as the one of P2.
1687 panel2_testing->FinishDragTitlebar();
1688 ASSERT_EQ(0, detached_collection->num_panels());
1689 ASSERT_EQ(1, panel_manager->num_stacks());
1690 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
1691 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
1692 gfx::Rect panel1_new_bounds = panel1_old_bounds;
1693 panel1_new_bounds.set_width(panel2_new_bounds.width());
1694 EXPECT_EQ(panel1_new_bounds, panel1->GetBounds());
1695 panel2_new_bounds.set_x(panel1_new_bounds.x());
1696 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
1697
1698 panel_manager->CloseAll();
1699 }
1700
1701 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupAndCancel) {
1702 PanelManager* panel_manager = PanelManager::GetInstance();
1703 DetachedPanelCollection* detached_collection =
1704 panel_manager->detached_collection();
1705
1706 // Create two detached panels.
1707 Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(300, 200, 200, 100));
1708 Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(100, 100, 150, 150));
1709 ASSERT_EQ(2, detached_collection->num_panels());
1710 ASSERT_EQ(0, panel_manager->num_stacks());
1711 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
1712 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
1713
1714 gfx::Rect panel1_old_bounds = panel1->GetBounds();
1715 gfx::Rect panel2_old_bounds = panel2->GetBounds();
1716
1717 // Press on title-bar.
1718 scoped_ptr<NativePanelTesting> panel2_testing(
1719 CreateNativePanelTesting(panel2));
1720 gfx::Point mouse_location(panel2->GetBounds().origin());
1721 gfx::Point original_mouse_location = mouse_location;
1722 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location);
1723
1724 // Drag P2 close to the bottom of P1 to trigger the stacking.
1725 // Expect that P2 stacks to P1 and P2's width remains unchanged.
1726 gfx::Vector2d drag_delta_to_stack =
1727 GetDragDeltaToStackToBottom(panel2, panel1);
1728 mouse_location = mouse_location + drag_delta_to_stack;
1729 panel2_testing->DragTitlebar(mouse_location);
1730 ASSERT_EQ(0, detached_collection->num_panels());
1731 ASSERT_EQ(1, panel_manager->num_stacks());
1732 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
1733 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
1734 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
1735 gfx::Rect panel2_new_bounds(panel1_old_bounds.x(),
1736 panel1_old_bounds.bottom(),
1737 panel2_old_bounds.width(),
1738 panel2_old_bounds.height());
1739 EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
1740
1741 // Cancel the drag.
1742 // Expect that the P1 and P2 become detached.
1743 panel2_testing->CancelDragTitlebar();
1744 ASSERT_EQ(2, detached_collection->num_panels());
1745 ASSERT_EQ(0, panel_manager->num_stacks());
1746 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
1747 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
1748 EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
1749 EXPECT_EQ(panel2_old_bounds, panel2->GetBounds());
1750
1751 panel_manager->CloseAll();
1752 }
1753
1754 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupPanelAndStackFromBottom) {
1755 PanelManager* panel_manager = PanelManager::GetInstance();
1756 DetachedPanelCollection* detached_collection =
1757 panel_manager->detached_collection();
1758
1759 // Create 2 stacked panels.
1760 StackedPanelCollection* stack = panel_manager->CreateStack();
1761 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 100, 200, 150);
1762 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
1763 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
1764 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
1765 ASSERT_EQ(0, detached_collection->num_panels());
1766 ASSERT_EQ(1, panel_manager->num_stacks());
1767 ASSERT_EQ(2, stack->num_panels());
1768 EXPECT_EQ(stack, panel1->collection());
1769 EXPECT_EQ(stack, panel2->collection());
1770
1771 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
1772 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
1773 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
1774 panel2_initial_bounds, panel1_expected_bounds);
1775 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
1776
1777 // Create 1 detached panel.
1778 gfx::Rect panel3_initial_bounds = gfx::Rect(300, 200, 100, 100);
1779 Panel* panel3 = CreateDetachedPanel("3", panel3_initial_bounds);
1780 ASSERT_EQ(1, detached_collection->num_panels());
1781 gfx::Rect panel3_expected_bounds(panel3_initial_bounds);
1782 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
1783
1784 // Drag P3 to stack to the bottom of the stack consisting P1 and P2.
1785 // Expect that P3 becomes the bottom panel of the stack.
1786 gfx::Vector2d drag_delta_to_stack =
1787 GetDragDeltaToStackToBottom(panel3, panel2);
1788 DragPanelByDelta(panel3, drag_delta_to_stack);
1789 ASSERT_EQ(0, detached_collection->num_panels());
1790 ASSERT_EQ(3, stack->num_panels());
1791 ASSERT_EQ(1, panel_manager->num_stacks());
1792 EXPECT_EQ(stack, panel1->collection());
1793 EXPECT_EQ(stack, panel2->collection());
1794 EXPECT_EQ(stack, panel3->collection());
1795
1796 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
1797 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
1798 panel3_expected_bounds = GetStackedAtBottomPanelBounds(
1799 panel3_initial_bounds, panel2_expected_bounds);
1800 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
1801
1802 panel_manager->CloseAll();
1803 }
1804
1805 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupStackAndPanelFromBottom) {
1806 PanelManager* panel_manager = PanelManager::GetInstance();
1807 DetachedPanelCollection* detached_collection =
1808 panel_manager->detached_collection();
1809
1810 // Create 2 stacked panels.
1811 StackedPanelCollection* stack = panel_manager->CreateStack();
1812 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 100, 200, 150);
1813 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
1814 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
1815 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
1816 ASSERT_EQ(0, detached_collection->num_panels());
1817 ASSERT_EQ(1, panel_manager->num_stacks());
1818 ASSERT_EQ(2, stack->num_panels());
1819 EXPECT_EQ(stack, panel1->stack());
1820 EXPECT_EQ(stack, panel2->stack());
1821
1822 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
1823 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
1824 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
1825 panel2_initial_bounds, panel1_expected_bounds);
1826 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
1827
1828 // Create 1 detached panel.
1829 gfx::Rect panel3_initial_bounds = gfx::Rect(300, 200, 100, 100);
1830 Panel* panel3 = CreateDetachedPanel("3", panel3_initial_bounds);
1831 ASSERT_EQ(1, detached_collection->num_panels());
1832 gfx::Rect panel3_expected_bounds(panel3_initial_bounds);
1833 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
1834
1835 // Drag P1 (together with P2) to stack to the bottom of P3.
1836 // Expect that P1 and P2 append to the bottom of P3 and all 3 panels are in
1837 // one stack.
1838 gfx::Vector2d drag_delta_to_stack =
1839 GetDragDeltaToStackToBottom(panel1, panel3);
1840 DragPanelByDelta(panel1, drag_delta_to_stack);
1841 ASSERT_EQ(0, detached_collection->num_panels());
1842 ASSERT_EQ(1, panel_manager->num_stacks());
1843 StackedPanelCollection* final_stack = panel_manager->stacks().front();
1844 ASSERT_EQ(3, final_stack->num_panels());
1845 EXPECT_EQ(final_stack, panel1->stack());
1846 EXPECT_EQ(final_stack, panel2->stack());
1847 EXPECT_EQ(final_stack, panel3->stack());
1848
1849 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
1850 panel1_expected_bounds = GetStackedAtBottomPanelBounds(
1851 panel1_initial_bounds, panel3_expected_bounds);
1852 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
1853 panel2_expected_bounds = GetStackedAtBottomPanelBounds(
1854 panel2_initial_bounds, panel1_expected_bounds);
1855 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
1856
1857 panel_manager->CloseAll();
1858 }
1859
1860 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupStackAndPanelFromTop) {
1861 PanelManager* panel_manager = PanelManager::GetInstance();
1862 DetachedPanelCollection* detached_collection =
1863 panel_manager->detached_collection();
1864
1865 // Create 2 stacked panels.
1866 StackedPanelCollection* stack = panel_manager->CreateStack();
1867 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 100, 200, 150);
1868 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
1869 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
1870 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
1871 ASSERT_EQ(0, detached_collection->num_panels());
1872 ASSERT_EQ(1, panel_manager->num_stacks());
1873 ASSERT_EQ(2, stack->num_panels());
1874 EXPECT_EQ(stack, panel1->stack());
1875 EXPECT_EQ(stack, panel2->stack());
1876
1877 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
1878 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
1879 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
1880 panel2_initial_bounds, panel1_expected_bounds);
1881 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
1882
1883 // Create 1 detached panel.
1884 gfx::Rect panel3_initial_bounds = gfx::Rect(300, 450, 100, 100);
1885 Panel* panel3 = CreateDetachedPanel("3", panel3_initial_bounds);
1886 ASSERT_EQ(1, detached_collection->num_panels());
1887 gfx::Rect panel3_expected_bounds(panel3_initial_bounds);
1888 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
1889
1890 // Drag P1 (together with P2) to stack to the top of P3.
1891 // Expect that P1 and P2 add to the top of P3 and all 3 panels are in
1892 // one stack. P1 and P2 should align to top of P3 while P3 should update its
1893 // width to be same as the width of P1 and P2.
1894 gfx::Vector2d drag_delta_to_stack = GetDragDeltaToStackToTop(panel1, panel3);
1895 DragPanelByDelta(panel1, drag_delta_to_stack);
1896 ASSERT_EQ(0, detached_collection->num_panels());
1897 ASSERT_EQ(1, panel_manager->num_stacks());
1898 StackedPanelCollection* final_stack = panel_manager->stacks().front();
1899 ASSERT_EQ(3, final_stack->num_panels());
1900 EXPECT_EQ(final_stack, panel1->stack());
1901 EXPECT_EQ(final_stack, panel2->stack());
1902 EXPECT_EQ(final_stack, panel3->stack());
1903
1904 panel3_expected_bounds.set_width(panel1_expected_bounds.width());
1905 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
1906 panel2_expected_bounds = GetStackedAtTopPanelBounds(
1907 panel2_expected_bounds, panel3_expected_bounds);
1908 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
1909 panel1_expected_bounds = GetStackedAtTopPanelBounds(
1910 panel1_expected_bounds, panel2_expected_bounds);
1911 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
1912
1913 panel_manager->CloseAll();
1914 }
1915
1916 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupStackAndStackFromBottom) {
1917 PanelManager* panel_manager = PanelManager::GetInstance();
1918 DetachedPanelCollection* detached_collection =
1919 panel_manager->detached_collection();
1920
1921 // Create 2 stacked panels.
1922 StackedPanelCollection* stack1 = panel_manager->CreateStack();
1923 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
1924 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack1);
1925 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
1926 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack1);
1927 ASSERT_EQ(0, detached_collection->num_panels());
1928 ASSERT_EQ(1, panel_manager->num_stacks());
1929 ASSERT_EQ(2, stack1->num_panels());
1930 EXPECT_EQ(stack1, panel1->stack());
1931 EXPECT_EQ(stack1, panel2->stack());
1932
1933 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
1934 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
1935 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
1936 panel2_initial_bounds, panel1_expected_bounds);
1937 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
1938
1939 // Create 2 more stacked panels in another stack.
1940 StackedPanelCollection* stack2 = panel_manager->CreateStack();
1941 gfx::Rect panel3_initial_bounds = gfx::Rect(300, 100, 220, 120);
1942 Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack2);
1943 gfx::Rect panel4_initial_bounds = gfx::Rect(0, 0, 180, 140);
1944 Panel* panel4 = CreateStackedPanel("4", panel4_initial_bounds, stack2);
1945 ASSERT_EQ(0, detached_collection->num_panels());
1946 ASSERT_EQ(2, panel_manager->num_stacks());
1947 ASSERT_EQ(2, stack2->num_panels());
1948 EXPECT_EQ(stack2, panel3->stack());
1949 EXPECT_EQ(stack2, panel4->stack());
1950
1951 gfx::Rect panel3_expected_bounds(panel3_initial_bounds);
1952 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
1953 gfx::Rect panel4_expected_bounds = GetStackedAtBottomPanelBounds(
1954 panel4_initial_bounds, panel3_expected_bounds);
1955 EXPECT_EQ(panel4_expected_bounds, panel4->GetBounds());
1956
1957 // Drag P3 (together with P4) to stack to the bottom of the stack consisting
1958 // P1 and P2.
1959 // Expect that P3 and P4 append to the bottom of P2 and all 4 panels are in
1960 // one stack.
1961 gfx::Vector2d drag_delta_to_stack =
1962 GetDragDeltaToStackToBottom(panel3, panel2);
1963 DragPanelByDelta(panel3, drag_delta_to_stack);
1964 ASSERT_EQ(0, detached_collection->num_panels());
1965 ASSERT_EQ(1, panel_manager->num_stacks());
1966 StackedPanelCollection* final_stack = panel_manager->stacks().front();
1967 ASSERT_EQ(4, final_stack->num_panels());
1968 EXPECT_EQ(final_stack, panel1->stack());
1969 EXPECT_EQ(final_stack, panel2->stack());
1970 EXPECT_EQ(final_stack, panel3->stack());
1971 EXPECT_EQ(final_stack, panel4->stack());
1972
1973 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
1974 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
1975 panel3_expected_bounds = GetStackedAtBottomPanelBounds(
1976 panel3_initial_bounds, panel2_expected_bounds);
1977 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
1978 panel4_expected_bounds = GetStackedAtBottomPanelBounds(
1979 panel4_initial_bounds, panel3_expected_bounds);
1980 EXPECT_EQ(panel4_expected_bounds, panel4->GetBounds());
1981
1982 panel_manager->CloseAll();
1983 }
1984
1985 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupStackAndStackFromTop) {
1986 PanelManager* panel_manager = PanelManager::GetInstance();
1987 DetachedPanelCollection* detached_collection =
1988 panel_manager->detached_collection();
1989
1990 // Create 2 stacked panels.
1991 StackedPanelCollection* stack1 = panel_manager->CreateStack();
1992 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
1993 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack1);
1994 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
1995 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack1);
1996 ASSERT_EQ(0, detached_collection->num_panels());
1997 ASSERT_EQ(1, panel_manager->num_stacks());
1998 ASSERT_EQ(2, stack1->num_panels());
1999 EXPECT_EQ(stack1, panel1->stack());
2000 EXPECT_EQ(stack1, panel2->stack());
2001
2002 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
2003 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2004 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
2005 panel2_initial_bounds, panel1_expected_bounds);
2006 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2007
2008 // Create 2 more stacked panels in another stack.
2009 StackedPanelCollection* stack2 = panel_manager->CreateStack();
2010 gfx::Rect panel3_initial_bounds = gfx::Rect(300, 350, 220, 110);
2011 Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack2);
2012 gfx::Rect panel4_initial_bounds = gfx::Rect(0, 0, 180, 100);
2013 Panel* panel4 = CreateStackedPanel("4", panel4_initial_bounds, stack2);
2014 ASSERT_EQ(0, detached_collection->num_panels());
2015 ASSERT_EQ(2, panel_manager->num_stacks());
2016 ASSERT_EQ(2, stack2->num_panels());
2017 EXPECT_EQ(stack2, panel3->stack());
2018 EXPECT_EQ(stack2, panel4->stack());
2019
2020 gfx::Rect panel3_expected_bounds(panel3_initial_bounds);
2021 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
2022 gfx::Rect panel4_expected_bounds = GetStackedAtBottomPanelBounds(
2023 panel4_initial_bounds, panel3_expected_bounds);
2024 EXPECT_EQ(panel4_expected_bounds, panel4->GetBounds());
2025
2026 // Drag P1 (together with P2) to stack to the top of the stack consisting
2027 // P3 and P4.
2028 // Expect that P1 and P2 add to the top of P3 and all 4 panels are in
2029 // one stack. P1 and P2 should align to top of P3 while P3 and P4 should
2030 // update their width to be same as the width of P1 and P2.
2031 gfx::Vector2d drag_delta_to_stack = GetDragDeltaToStackToTop(panel1, panel3);
2032 DragPanelByDelta(panel1, drag_delta_to_stack);
2033 ASSERT_EQ(0, detached_collection->num_panels());
2034 ASSERT_EQ(1, panel_manager->num_stacks());
2035 StackedPanelCollection* final_stack = panel_manager->stacks().front();
2036 ASSERT_EQ(4, final_stack->num_panels());
2037 EXPECT_EQ(final_stack, panel1->stack());
2038 EXPECT_EQ(final_stack, panel2->stack());
2039 EXPECT_EQ(final_stack, panel3->stack());
2040 EXPECT_EQ(final_stack, panel4->stack());
2041
2042 panel4_expected_bounds.set_width(panel1_expected_bounds.width());
2043 EXPECT_EQ(panel4_expected_bounds, panel4->GetBounds());
2044 panel3_expected_bounds.set_width(panel1_expected_bounds.width());
2045 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
2046 panel2_expected_bounds = GetStackedAtTopPanelBounds(
2047 panel2_expected_bounds, panel3_expected_bounds);
2048 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2049 panel1_expected_bounds = GetStackedAtTopPanelBounds(
2050 panel1_expected_bounds, panel2_expected_bounds);
2051 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2052
2053 panel_manager->CloseAll();
2054 }
2055
2056 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, UngroupTwoPanelStack) {
2057 PanelManager* panel_manager = PanelManager::GetInstance();
2058 DetachedPanelCollection* detached_collection =
2059 panel_manager->detached_collection();
2060
2061 // Create 2 stacked panels.
2062 StackedPanelCollection* stack = panel_manager->CreateStack();
2063 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
2064 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
2065 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
2066 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
2067 ASSERT_EQ(0, detached_collection->num_panels());
2068 ASSERT_EQ(2, stack->num_panels());
2069 ASSERT_EQ(1, panel_manager->num_stacks());
2070 EXPECT_EQ(stack, panel1->stack());
2071 EXPECT_EQ(stack, panel2->stack());
2072
2073 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
2074 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2075 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
2076 panel2_initial_bounds, panel1_expected_bounds);
2077 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2078 gfx::Rect panel2_old_bounds = panel2_expected_bounds;
2079
2080 // Press on title-bar.
2081 scoped_ptr<NativePanelTesting> panel2_testing(
2082 CreateNativePanelTesting(panel2));
2083 gfx::Point mouse_location(panel2->GetBounds().origin());
2084 gfx::Point original_mouse_location = mouse_location;
2085 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location);
2086
2087 // Drag P2 away from the bottom of P1 to trigger the unstacking.
2088 // Expect that P1 and P2 get detached.
2089 gfx::Vector2d drag_delta_to_unstack =
2090 GetDragDeltaToUnstackFromBottom(panel2, panel1);
2091 mouse_location = mouse_location + drag_delta_to_unstack;
2092 panel2_testing->DragTitlebar(mouse_location);
2093 ASSERT_EQ(2, detached_collection->num_panels());
2094 ASSERT_TRUE(stack->num_panels() == 0);
2095 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
2096 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
2097 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2098 panel2_expected_bounds.Offset(drag_delta_to_unstack);
2099 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2100
2101 // Drag P2 a bit closer to the bottom of P1 to trigger the stacking.
2102 // Expect P1 and P2 get stacked together.
2103 gfx::Vector2d drag_delta_to_stack =
2104 GetDragDeltaToStackToBottom(panel2, panel1);
2105 mouse_location = mouse_location + drag_delta_to_stack;
2106 panel2_testing->DragTitlebar(mouse_location);
2107 ASSERT_EQ(0, detached_collection->num_panels());
2108 // Note that the empty stack might still exist until the drag ends.
2109 ASSERT_GE(panel_manager->num_stacks(), 1);
2110 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
2111 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
2112 EXPECT_EQ(panel1->stack(), panel2->stack());
2113 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2114 panel2_expected_bounds = GetStackedAtBottomPanelBounds(
2115 panel2_initial_bounds, panel1_expected_bounds);
2116 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2117
2118 // Drag P2 away from the bottom of P1 to trigger the unstacking again.
2119 // Expect that P1 and P2 get detached.
2120 drag_delta_to_unstack = GetDragDeltaToUnstackFromBottom(panel2, panel1);
2121 mouse_location = mouse_location + drag_delta_to_unstack;
2122 panel2_testing->DragTitlebar(mouse_location);
2123 ASSERT_EQ(2, detached_collection->num_panels());
2124 ASSERT_TRUE(stack->num_panels() == 0);
2125 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
2126 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
2127 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2128 panel2_expected_bounds = panel2_old_bounds;
2129 panel2_expected_bounds.Offset(mouse_location - original_mouse_location);
2130 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2131
2132 // Finish the drag.
2133 // Expect that the P1 and P2 stay detached.
2134 panel2_testing->FinishDragTitlebar();
2135 ASSERT_EQ(2, detached_collection->num_panels());
2136 ASSERT_EQ(0, panel_manager->num_stacks());
2137 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
2138 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
2139 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2140 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2141
2142 panel_manager->CloseAll();
2143 }
2144
2145 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, UngroupAndCancel) {
2146 PanelManager* panel_manager = PanelManager::GetInstance();
2147 DetachedPanelCollection* detached_collection =
2148 panel_manager->detached_collection();
2149
2150 // Create 2 stacked panels.
2151 StackedPanelCollection* stack = panel_manager->CreateStack();
2152 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
2153 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
2154 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
2155 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
2156 ASSERT_EQ(0, detached_collection->num_panels());
2157 ASSERT_EQ(2, stack->num_panels());
2158 ASSERT_EQ(1, panel_manager->num_stacks());
2159 EXPECT_EQ(stack, panel1->stack());
2160 EXPECT_EQ(stack, panel2->stack());
2161
2162 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
2163 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2164 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
2165 panel2_initial_bounds, panel1_expected_bounds);
2166 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2167 gfx::Rect panel2_old_bounds = panel2->GetBounds();
2168
2169 // Press on title-bar.
2170 scoped_ptr<NativePanelTesting> panel2_testing(
2171 CreateNativePanelTesting(panel2));
2172 gfx::Point mouse_location(panel2->GetBounds().origin());
2173 gfx::Point original_mouse_location = mouse_location;
2174 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location);
2175
2176 // Drag P2 away from the bottom of P1 to trigger the unstacking.
2177 // Expect that P1 and P2 get detached.
2178 gfx::Vector2d drag_delta_to_unstack =
2179 GetDragDeltaToUnstackFromBottom(panel2, panel1);
2180 mouse_location = mouse_location + drag_delta_to_unstack;
2181 panel2_testing->DragTitlebar(mouse_location);
2182 ASSERT_EQ(2, detached_collection->num_panels());
2183 ASSERT_TRUE(stack->num_panels() == 0);
2184 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
2185 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
2186 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2187 panel2_expected_bounds.Offset(drag_delta_to_unstack);
2188 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2189
2190 // Cancel the drag.
2191 // Expect that the P1 and P2 put back to the same stack.
2192 panel2_testing->CancelDragTitlebar();
2193 ASSERT_EQ(0, detached_collection->num_panels());
2194 ASSERT_EQ(1, panel_manager->num_stacks());
2195 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
2196 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
2197 EXPECT_EQ(stack, panel1->stack());
2198 EXPECT_EQ(stack, panel2->stack());
2199 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2200 EXPECT_EQ(panel2_old_bounds, panel2->GetBounds());
2201
2202 panel_manager->CloseAll();
2203 }
2204
2205 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest,
2206 UngroupBottomPanelInThreePanelStack) {
2207 PanelManager* panel_manager = PanelManager::GetInstance();
2208 DetachedPanelCollection* detached_collection =
2209 panel_manager->detached_collection();
2210
2211 // Create 3 stacked panels.
2212 StackedPanelCollection* stack = panel_manager->CreateStack();
2213 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
2214 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
2215 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
2216 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
2217 gfx::Rect panel3_initial_bounds = gfx::Rect(0, 0, 120, 120);
2218 Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack);
2219 ASSERT_EQ(0, detached_collection->num_panels());
2220 ASSERT_EQ(1, panel_manager->num_stacks());
2221 ASSERT_EQ(3, stack->num_panels());
2222 EXPECT_EQ(stack, panel1->stack());
2223 EXPECT_EQ(stack, panel2->stack());
2224 EXPECT_EQ(stack, panel3->stack());
2225
2226 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
2227 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2228 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
2229 panel2_initial_bounds, panel1_expected_bounds);
2230 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2231 gfx::Rect panel3_expected_bounds = GetStackedAtBottomPanelBounds(
2232 panel3_initial_bounds, panel2_expected_bounds);
2233 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
2234
2235 // Drag P3 away to unstack from P2 and P1.
2236 // Expect that P1 and P2 are still in the stack while P3 gets detached.
2237 gfx::Vector2d drag_delta_to_unstack =
2238 GetDragDeltaToUnstackFromBottom(panel3, panel2);
2239 DragPanelByDelta(panel3, drag_delta_to_unstack);
2240 ASSERT_EQ(1, detached_collection->num_panels());
2241 ASSERT_EQ(1, panel_manager->num_stacks());
2242 ASSERT_EQ(2, stack->num_panels());
2243 EXPECT_EQ(stack, panel1->stack());
2244 EXPECT_EQ(stack, panel2->stack());
2245 EXPECT_EQ(PanelCollection::DETACHED, panel3->collection()->type());
2246
2247 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2248 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2249 panel3_expected_bounds.Offset(drag_delta_to_unstack);
2250 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
2251
2252 panel_manager->CloseAll();
2253 }
2254
2255 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest,
2256 UngroupMiddlePanelInThreePanelStack) {
2257 PanelManager* panel_manager = PanelManager::GetInstance();
2258 DetachedPanelCollection* detached_collection =
2259 panel_manager->detached_collection();
2260
2261 // Create 3 stacked panels.
2262 StackedPanelCollection* stack = panel_manager->CreateStack();
2263 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
2264 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
2265 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
2266 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
2267 gfx::Rect panel3_initial_bounds = gfx::Rect(0, 0, 120, 120);
2268 Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack);
2269 ASSERT_EQ(0, detached_collection->num_panels());
2270 ASSERT_EQ(1, panel_manager->num_stacks());
2271 ASSERT_EQ(3, stack->num_panels());
2272 EXPECT_EQ(stack, panel1->stack());
2273 EXPECT_EQ(stack, panel2->stack());
2274 EXPECT_EQ(stack, panel3->stack());
2275
2276 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
2277 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2278 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
2279 panel2_initial_bounds, panel1_expected_bounds);
2280 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2281 gfx::Rect panel3_expected_bounds = GetStackedAtBottomPanelBounds(
2282 panel3_initial_bounds, panel2_expected_bounds);
2283 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
2284
2285 // Drag P2 (together with P3) away to unstack from P1.
2286 // Expect that P2 and P3 are still in a stack while P1 gets detached.
2287 gfx::Vector2d drag_delta_to_unstack =
2288 GetDragDeltaToUnstackFromBottom(panel2, panel1);
2289 DragPanelByDelta(panel2, drag_delta_to_unstack);
2290 ASSERT_EQ(1, detached_collection->num_panels());
2291 ASSERT_EQ(1, panel_manager->num_stacks());
2292 StackedPanelCollection* final_stack = panel_manager->stacks().front();
2293 ASSERT_EQ(2, final_stack->num_panels());
2294 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
2295 EXPECT_EQ(final_stack, panel2->stack());
2296 EXPECT_EQ(final_stack, panel3->stack());
2297
2298 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2299 panel2_expected_bounds.Offset(drag_delta_to_unstack);
2300 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2301 panel3_expected_bounds.Offset(drag_delta_to_unstack);
2302 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
2303
2304 panel_manager->CloseAll();
2305 }
2306
2307 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest,
2308 UngroupThirdPanelInFourPanelStack) {
2309 PanelManager* panel_manager = PanelManager::GetInstance();
2310 DetachedPanelCollection* detached_collection =
2311 panel_manager->detached_collection();
2312
2313 // Create 4 stacked panels.
2314 StackedPanelCollection* stack = panel_manager->CreateStack();
2315 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
2316 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
2317 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
2318 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
2319 gfx::Rect panel3_initial_bounds = gfx::Rect(0, 0, 120, 120);
2320 Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack);
2321 gfx::Rect panel4_initial_bounds = gfx::Rect(0, 0, 120, 110);
2322 Panel* panel4 = CreateStackedPanel("4", panel4_initial_bounds, stack);
2323 ASSERT_EQ(0, detached_collection->num_panels());
2324 ASSERT_EQ(1, panel_manager->num_stacks());
2325 ASSERT_EQ(4, stack->num_panels());
2326 EXPECT_EQ(stack, panel1->stack());
2327 EXPECT_EQ(stack, panel2->stack());
2328 EXPECT_EQ(stack, panel3->stack());
2329 EXPECT_EQ(stack, panel4->stack());
2330
2331 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
2332 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2333 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
2334 panel2_initial_bounds, panel1_expected_bounds);
2335 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2336 gfx::Rect panel3_expected_bounds = GetStackedAtBottomPanelBounds(
2337 panel3_initial_bounds, panel2_expected_bounds);
2338 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
2339 gfx::Rect panel4_expected_bounds = GetStackedAtBottomPanelBounds(
2340 panel4_initial_bounds, panel3_expected_bounds);
2341 EXPECT_EQ(panel4_expected_bounds, panel4->GetBounds());
2342
2343 // Drag P3 (together with P4) away to unstack from P2.
2344 // Expect that P1 and P2 are in one stack while P3 and P4 are in different
2345 // stack.
2346 gfx::Vector2d drag_delta_to_unstack =
2347 GetDragDeltaToUnstackFromBottom(panel3, panel2);
2348 DragPanelByDelta(panel3, drag_delta_to_unstack);
2349 ASSERT_EQ(0, detached_collection->num_panels());
2350 ASSERT_EQ(2, panel_manager->num_stacks());
2351 StackedPanelCollection* final_stack1 = panel_manager->stacks().front();
2352 ASSERT_EQ(2, final_stack1->num_panels());
2353 StackedPanelCollection* final_stack2 = panel_manager->stacks().back();
2354 ASSERT_EQ(2, final_stack2->num_panels());
2355 EXPECT_EQ(panel1->stack(), panel2->stack());
2356 EXPECT_EQ(panel3->stack(), panel4->stack());
2357
2358 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2359 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2360 panel3_expected_bounds.Offset(drag_delta_to_unstack);
2361 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
2362 panel4_expected_bounds.Offset(drag_delta_to_unstack);
2363 EXPECT_EQ(panel4_expected_bounds, panel4->GetBounds());
2364
2365 panel_manager->CloseAll();
2366 }
2367
2368 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, UngroupAndGroup) {
2369 PanelManager* panel_manager = PanelManager::GetInstance();
2370 DetachedPanelCollection* detached_collection =
2371 panel_manager->detached_collection();
2372
2373 // Create 2 stacked panels.
2374 StackedPanelCollection* stack = panel_manager->CreateStack();
2375 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
2376 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
2377 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
2378 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
2379 ASSERT_EQ(0, detached_collection->num_panels());
2380 ASSERT_EQ(2, stack->num_panels());
2381 ASSERT_EQ(1, panel_manager->num_stacks());
2382 EXPECT_EQ(stack, panel1->stack());
2383 EXPECT_EQ(stack, panel2->stack());
2384
2385 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
2386 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2387 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
2388 panel2_initial_bounds, panel1_expected_bounds);
2389 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2390
2391 // Create 1 detached panel.
2392 gfx::Rect panel3_initial_bounds = gfx::Rect(300, 200, 100, 100);
2393 Panel* panel3 = CreateDetachedPanel("3", panel3_initial_bounds);
2394 ASSERT_EQ(1, detached_collection->num_panels());
2395 gfx::Rect panel3_expected_bounds(panel3_initial_bounds);
2396 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
2397
2398 // Drag P2 to the bottom edge of P3 to trigger both unstacking and stacking.
2399 // Expect that P3 and P2 are stacked together while P1 gets detached.
2400 gfx::Vector2d drag_delta_to_unstack_and_stack =
2401 GetDragDeltaToStackToBottom(panel2, panel3);
2402 DragPanelByDelta(panel2, drag_delta_to_unstack_and_stack);
2403 ASSERT_EQ(1, detached_collection->num_panels());
2404 ASSERT_EQ(1, panel_manager->num_stacks());
2405 StackedPanelCollection* final_stack = panel_manager->stacks().front();
2406 ASSERT_EQ(2, final_stack->num_panels());
2407 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
2408 EXPECT_EQ(final_stack, panel2->stack());
2409 EXPECT_EQ(final_stack, panel3->stack());
2410
2411 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2412 panel2_expected_bounds = GetStackedAtBottomPanelBounds(
2413 panel2_initial_bounds, panel3_expected_bounds);
2414 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2415 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
2416
2417 panel_manager->CloseAll();
2418 }
2419
2420 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, UngroupAndAttach) {
2421 PanelManager* panel_manager = PanelManager::GetInstance();
2422 DockedPanelCollection* docked_collection = panel_manager->docked_collection();
2423 DetachedPanelCollection* detached_collection =
2424 panel_manager->detached_collection();
2425
2426 // Create 2 stacked panels.
2427 StackedPanelCollection* stack = panel_manager->CreateStack();
2428 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
2429 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
2430 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
2431 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
2432 ASSERT_EQ(0, docked_collection->num_panels());
2433 ASSERT_EQ(0, detached_collection->num_panels());
2434 ASSERT_EQ(2, stack->num_panels());
2435 ASSERT_EQ(1, panel_manager->num_stacks());
2436 EXPECT_EQ(stack, panel1->stack());
2437 EXPECT_EQ(stack, panel2->stack());
2438
2439 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
2440 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2441 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
2442 panel2_initial_bounds, panel1_expected_bounds);
2443 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2444
2445 // Drag P2 close to the bottom of the work area to trigger both unstacking and
2446 // docking for P2.
2447 // Expect that P2 gets docked while P2 gets detached.
2448 gfx::Vector2d drag_delta_to_unstack_and_attach = GetDragDeltaToAttach(panel2);
2449 DragPanelByDelta(panel2, drag_delta_to_unstack_and_attach);
2450 WaitForBoundsAnimationFinished(panel2);
2451 ASSERT_EQ(1, docked_collection->num_panels());
2452 ASSERT_EQ(1, detached_collection->num_panels());
2453 ASSERT_EQ(0, panel_manager->num_stacks());
2454 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
2455 EXPECT_EQ(PanelCollection::DOCKED, panel2->collection()->type());
2456
2457 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2458 panel2_expected_bounds.set_x(docked_collection->StartingRightPosition() -
2459 panel2_expected_bounds.width());
2460 panel2_expected_bounds.set_y(docked_collection->display_area().bottom() -
2461 panel2_expected_bounds.height());
2462 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2463
2464 panel_manager->CloseAll();
2465 }
2466
2467 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, SnapPanelToPanelLeft) {
2468 PanelManager* panel_manager = PanelManager::GetInstance();
2469 DetachedPanelCollection* detached_collection =
2470 panel_manager->detached_collection();
2471
2472 // Create 2 detached panels.
2473 gfx::Rect panel1_initial_bounds = gfx::Rect(300, 200, 300, 200);
2474 Panel* panel1 = CreateDetachedPanel("1", panel1_initial_bounds);
2475 gfx::Rect panel2_initial_bounds = gfx::Rect(100, 100, 100, 250);
2476 Panel* panel2 = CreateDetachedPanel("2", panel2_initial_bounds);
2477 ASSERT_EQ(2, detached_collection->num_panels());
2478
2479 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
2480 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2481 gfx::Rect panel2_expected_bounds(panel2_initial_bounds);
2482 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2483
2484 // Press on title-bar.
2485 scoped_ptr<NativePanelTesting> panel2_testing(
2486 CreateNativePanelTesting(panel2));
2487 gfx::Point mouse_location(panel2->GetBounds().origin());
2488 gfx::Point original_mouse_location = mouse_location;
2489 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location);
2490
2491 // Drag P2 close to the left of P1 to trigger the snapping.
2492 gfx::Vector2d drag_delta_to_snap = GetDragDeltaToSnapToLeft(panel2, panel1);
2493 mouse_location = mouse_location + drag_delta_to_snap;
2494 panel2_testing->DragTitlebar(mouse_location);
2495 ASSERT_EQ(2, detached_collection->num_panels());
2496 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2497 panel2_expected_bounds.Offset(drag_delta_to_snap);
2498 panel2_expected_bounds.set_x(
2499 panel1_expected_bounds.x() - panel2_expected_bounds.width());
2500 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2501
2502 // Drag P2 a bit away from the left of P1 to trigger the unsnapping.
2503 gfx::Vector2d drag_delta_to_unsnap = GetDragDeltaToUnsnap(panel1);
2504 mouse_location = mouse_location + drag_delta_to_unsnap;
2505 panel2_testing->DragTitlebar(mouse_location);
2506 ASSERT_EQ(2, detached_collection->num_panels());
2507 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2508 panel2_expected_bounds = panel2_initial_bounds;
2509 panel2_expected_bounds.Offset(mouse_location - original_mouse_location);
2510 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2511
2512 // Drag P2 close to the left of P1 to trigger the snapping again.
2513 drag_delta_to_snap = GetDragDeltaToSnapToLeft(panel2, panel1);
2514 mouse_location = mouse_location + drag_delta_to_snap;
2515 panel2_testing->DragTitlebar(mouse_location);
2516 ASSERT_EQ(2, detached_collection->num_panels());
2517 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2518 panel2_expected_bounds.Offset(drag_delta_to_snap);
2519 panel2_expected_bounds.set_x(
2520 panel1_expected_bounds.x() - panel2_expected_bounds.width());
2521 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2522
2523 // Drag P2 vertically with a little bit of horizontal movement should still
2524 // keep the snapping.
2525 gfx::Vector2d drag_delta_almost_vertically(2, 20);
2526 mouse_location = mouse_location + drag_delta_almost_vertically;
2527 panel2_testing->DragTitlebar(mouse_location);
2528 ASSERT_EQ(2, detached_collection->num_panels());
2529 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2530 panel2_expected_bounds.set_y(
2531 panel2_expected_bounds.y() + drag_delta_almost_vertically.y());
2532 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2533
2534 // Finish the drag.
2535 panel2_testing->FinishDragTitlebar();
2536 ASSERT_EQ(2, detached_collection->num_panels());
2537 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2538 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2539
2540 panel_manager->CloseAll();
2541 }
2542
2543 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, SnapPanelToPanelRight) {
2544 PanelManager* panel_manager = PanelManager::GetInstance();
2545 DetachedPanelCollection* detached_collection =
2546 panel_manager->detached_collection();
2547
2548 // Create 2 detached panels.
2549 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 200, 100, 200);
2550 Panel* panel1 = CreateDetachedPanel("1", panel1_initial_bounds);
2551 gfx::Rect panel2_initial_bounds = gfx::Rect(300, 100, 200, 250);
2552 Panel* panel2 = CreateDetachedPanel("2", panel2_initial_bounds);
2553 ASSERT_EQ(2, detached_collection->num_panels());
2554
2555 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
2556 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2557 gfx::Rect panel2_expected_bounds(panel2_initial_bounds);
2558 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2559
2560 // Press on title-bar.
2561 scoped_ptr<NativePanelTesting> panel2_testing(
2562 CreateNativePanelTesting(panel2));
2563 gfx::Point mouse_location(panel2->GetBounds().origin());
2564 gfx::Point original_mouse_location = mouse_location;
2565 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location);
2566
2567 // Drag P1 close to the right of P2 to trigger the snapping.
2568 gfx::Vector2d drag_delta_to_snap = GetDragDeltaToSnapToRight(panel2, panel1);
2569 mouse_location = mouse_location + drag_delta_to_snap;
2570 panel2_testing->DragTitlebar(mouse_location);
2571 ASSERT_EQ(2, detached_collection->num_panels());
2572 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2573 panel2_expected_bounds.Offset(drag_delta_to_snap);
2574 panel2_expected_bounds.set_x(panel1_expected_bounds.right());
2575 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2576
2577 // Drag P2 a bit away from the right of P1 to trigger the unsnapping.
2578 gfx::Vector2d drag_delta_to_unsnap = GetDragDeltaToUnsnap(panel1);
2579 mouse_location = mouse_location + drag_delta_to_unsnap;
2580 panel2_testing->DragTitlebar(mouse_location);
2581 ASSERT_EQ(2, detached_collection->num_panels());
2582 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2583 panel2_expected_bounds = panel2_initial_bounds;
2584 panel2_expected_bounds.Offset(mouse_location - original_mouse_location);
2585 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2586
2587 // Drag P2 close to the right of P1 to trigger the snapping again.
2588 drag_delta_to_snap = GetDragDeltaToSnapToRight(panel2, panel1);
2589 mouse_location = mouse_location + drag_delta_to_snap;
2590 panel2_testing->DragTitlebar(mouse_location);
2591 ASSERT_EQ(2, detached_collection->num_panels());
2592 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2593 panel2_expected_bounds.Offset(drag_delta_to_snap);
2594 panel2_expected_bounds.set_x(panel1_expected_bounds.right());
2595 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2596
2597 // Drag P2 vertically with a little bit of horizontal movement should still
2598 // keep the snapping.
2599 gfx::Vector2d drag_delta_almost_vertically(2, -20);
2600 mouse_location = mouse_location + drag_delta_almost_vertically;
2601 panel2_testing->DragTitlebar(mouse_location);
2602 ASSERT_EQ(2, detached_collection->num_panels());
2603 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2604 panel2_expected_bounds.set_y(
2605 panel2_expected_bounds.y() + drag_delta_almost_vertically.y());
2606 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2607
2608 // Finish the drag.
2609 panel2_testing->FinishDragTitlebar();
2610 ASSERT_EQ(2, detached_collection->num_panels());
2611 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2612 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2613
2614 panel_manager->CloseAll();
2615 }
2616
2617 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, SnapAndCancel) {
2618 PanelManager* panel_manager = PanelManager::GetInstance();
2619 DetachedPanelCollection* detached_collection =
2620 panel_manager->detached_collection();
2621
2622 // Create 2 detached panels.
2623 gfx::Rect panel1_initial_bounds = gfx::Rect(300, 200, 300, 200);
2624 Panel* panel1 = CreateDetachedPanel("1", panel1_initial_bounds);
2625 gfx::Rect panel2_initial_bounds = gfx::Rect(100, 100, 100, 250);
2626 Panel* panel2 = CreateDetachedPanel("2", panel2_initial_bounds);
2627 ASSERT_EQ(2, detached_collection->num_panels());
2628
2629 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
2630 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2631 gfx::Rect panel2_expected_bounds(panel2_initial_bounds);
2632 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2633
2634 // Press on title-bar.
2635 scoped_ptr<NativePanelTesting> panel2_testing(
2636 CreateNativePanelTesting(panel2));
2637 gfx::Point mouse_location(panel2->GetBounds().origin());
2638 gfx::Point original_mouse_location = mouse_location;
2639 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location);
2640
2641 // Drag P2 close to the left of P1 to trigger the snapping.
2642 gfx::Vector2d drag_delta_to_snap = GetDragDeltaToSnapToLeft(panel2, panel1);
2643 mouse_location = mouse_location + drag_delta_to_snap;
2644 panel2_testing->DragTitlebar(mouse_location);
2645 ASSERT_EQ(2, detached_collection->num_panels());
2646 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2647 panel2_expected_bounds.Offset(drag_delta_to_snap);
2648 panel2_expected_bounds.set_x(
2649 panel1_expected_bounds.x() - panel2_expected_bounds.width());
2650 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2651
2652 // Cancel the drag.
2653 panel2_testing->CancelDragTitlebar();
2654 ASSERT_EQ(2, detached_collection->num_panels());
2655 EXPECT_EQ(panel1_initial_bounds, panel1->GetBounds());
2656 EXPECT_EQ(panel2_initial_bounds, panel2->GetBounds());
2657
2658 panel_manager->CloseAll();
2659 }
2660
2661 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, SnapPanelToStackLeft) {
2662 PanelManager* panel_manager = PanelManager::GetInstance();
2663 DetachedPanelCollection* detached_collection =
2664 panel_manager->detached_collection();
2665
2666 // Create 2 stacked panels.
2667 StackedPanelCollection* stack = panel_manager->CreateStack();
2668 gfx::Rect panel1_initial_bounds = gfx::Rect(300, 100, 200, 150);
2669 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
2670 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
2671 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
2672 ASSERT_EQ(0, detached_collection->num_panels());
2673 ASSERT_EQ(1, panel_manager->num_stacks());
2674 ASSERT_EQ(2, stack->num_panels());
2675 EXPECT_EQ(stack, panel1->collection());
2676 EXPECT_EQ(stack, panel2->collection());
2677
2678 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
2679 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2680 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
2681 panel2_initial_bounds, panel1_expected_bounds);
2682 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2683
2684 // Create 1 detached panel.
2685 gfx::Rect panel3_initial_bounds = gfx::Rect(100, 200, 100, 100);
2686 Panel* panel3 = CreateDetachedPanel("3", panel3_initial_bounds);
2687 ASSERT_EQ(1, detached_collection->num_panels());
2688 EXPECT_EQ(PanelCollection::DETACHED, panel3->collection()->type());
2689 gfx::Rect panel3_expected_bounds(panel3_initial_bounds);
2690 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
2691
2692 // Drag P3 close to the left of the stack of P1 and P2 to trigger the
2693 // snapping.
2694 gfx::Vector2d drag_delta_to_snap = GetDragDeltaToSnapToLeft(panel3, panel1);
2695 DragPanelByDelta(panel3, drag_delta_to_snap);
2696 ASSERT_EQ(1, detached_collection->num_panels());
2697 ASSERT_EQ(1, panel_manager->num_stacks());
2698 ASSERT_EQ(2, stack->num_panels());
2699 EXPECT_EQ(stack, panel1->collection());
2700 EXPECT_EQ(stack, panel2->collection());
2701 EXPECT_EQ(PanelCollection::DETACHED, panel3->collection()->type());
2702 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2703 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2704 panel3_expected_bounds.Offset(drag_delta_to_snap);
2705 panel3_expected_bounds.set_x(
2706 panel1_expected_bounds.x() - panel3_expected_bounds.width());
2707 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
2708
2709 panel_manager->CloseAll();
2710 }
2711
2712 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, SnapPanelToStackRight) {
2713 PanelManager* panel_manager = PanelManager::GetInstance();
2714 DetachedPanelCollection* detached_collection =
2715 panel_manager->detached_collection();
2716
2717 // Create 2 stacked panels.
2718 StackedPanelCollection* stack = panel_manager->CreateStack();
2719 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 100, 200, 150);
2720 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
2721 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
2722 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
2723 ASSERT_EQ(0, detached_collection->num_panels());
2724 ASSERT_EQ(1, panel_manager->num_stacks());
2725 ASSERT_EQ(2, stack->num_panels());
2726 EXPECT_EQ(stack, panel1->collection());
2727 EXPECT_EQ(stack, panel2->collection());
2728
2729 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
2730 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2731 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
2732 panel2_initial_bounds, panel1_expected_bounds);
2733 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2734
2735 // Create 1 detached panel.
2736 gfx::Rect panel3_initial_bounds = gfx::Rect(300, 200, 100, 100);
2737 Panel* panel3 = CreateDetachedPanel("3", panel3_initial_bounds);
2738 ASSERT_EQ(1, detached_collection->num_panels());
2739 EXPECT_EQ(PanelCollection::DETACHED, panel3->collection()->type());
2740 gfx::Rect panel3_expected_bounds(panel3_initial_bounds);
2741 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
2742
2743 // Drag P3 close to the right of the stack of P1 and P2 to trigger the
2744 // snapping.
2745 gfx::Vector2d drag_delta_to_snap = GetDragDeltaToSnapToRight(panel3, panel1);
2746 DragPanelByDelta(panel3, drag_delta_to_snap);
2747 ASSERT_EQ(1, detached_collection->num_panels());
2748 ASSERT_EQ(1, panel_manager->num_stacks());
2749 ASSERT_EQ(2, stack->num_panels());
2750 EXPECT_EQ(stack, panel1->collection());
2751 EXPECT_EQ(stack, panel2->collection());
2752 EXPECT_EQ(PanelCollection::DETACHED, panel3->collection()->type());
2753 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2754 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2755 panel3_expected_bounds.Offset(drag_delta_to_snap);
2756 panel3_expected_bounds.set_x(panel1_expected_bounds.right());
2757 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
2758
2759 panel_manager->CloseAll();
2760 }
2761
2762 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DetachAndSnap) {
2763 PanelManager* panel_manager = PanelManager::GetInstance();
2764 DockedPanelCollection* docked_collection = panel_manager->docked_collection();
2765 DetachedPanelCollection* detached_collection =
2766 panel_manager->detached_collection();
2767
2768 // Create 1 detached panel.
2769 Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(300, 200, 100, 100));
2770 ASSERT_EQ(0, docked_collection->num_panels());
2771 ASSERT_EQ(1, detached_collection->num_panels());
2772 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
2773 gfx::Rect panel1_bounds = panel1->GetBounds();
2774
2775 // Create 1 docked panel.
2776 Panel* panel2 = CreateDockedPanel("2", gfx::Rect(0, 0, 150, 150));
2777 ASSERT_EQ(1, docked_collection->num_panels());
2778 ASSERT_EQ(1, detached_collection->num_panels());
2779 EXPECT_EQ(PanelCollection::DOCKED, panel2->collection()->type());
2780 gfx::Rect panel2_bounds = panel2->GetBounds();
2781
2782 // Drag P2 close to the right of P1 to trigger both detaching and snapping.
2783 gfx::Vector2d drag_delta_to_detach_and_snap =
2784 GetDragDeltaToSnapToRight(panel2, panel1);
2785 DragPanelByDelta(panel2, drag_delta_to_detach_and_snap);
2786 ASSERT_EQ(0, docked_collection->num_panels());
2787 ASSERT_EQ(2, detached_collection->num_panels());
2788 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
2789 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
2790 EXPECT_EQ(panel1_bounds, panel1->GetBounds());
2791 panel2_bounds.Offset(drag_delta_to_detach_and_snap);
2792 panel2_bounds.set_x(panel1_bounds.right());
2793 EXPECT_EQ(panel2_bounds, panel2->GetBounds());
2794
2795 panel_manager->CloseAll();
2796 }
2797
2798 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragTopStackedPanel) {
2799 PanelManager* panel_manager = PanelManager::GetInstance();
2800
2801 // Create 3 stacked panels.
2802 StackedPanelCollection* stack = panel_manager->CreateStack();
2803 gfx::Rect panel1_initial_bounds = gfx::Rect(300, 100, 200, 150);
2804 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
2805 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
2806 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
2807 gfx::Rect panel3_initial_bounds = gfx::Rect(0, 0, 150, 200);
2808 Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack);
2809 ASSERT_EQ(3, stack->num_panels());
2810 ASSERT_EQ(1, panel_manager->num_stacks());
2811 EXPECT_EQ(stack, panel1->collection());
2812 EXPECT_EQ(stack, panel2->collection());
2813 EXPECT_EQ(stack, panel3->collection());
2814
2815 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
2816 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2817 gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
2818 panel2_initial_bounds, panel1_expected_bounds);
2819 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2820 gfx::Rect panel3_expected_bounds = GetStackedAtBottomPanelBounds(
2821 panel3_initial_bounds, panel2_expected_bounds);
2822 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
2823
2824 // Drag the top panel by a delta.
2825 // Expect all panels are still in the same stack and they are all moved by the
2826 // same delta.
2827 gfx::Vector2d drag_delta(-50, -20);
2828 DragPanelByDelta(panel1, drag_delta);
2829 ASSERT_EQ(3, stack->num_panels());
2830 ASSERT_EQ(1, panel_manager->num_stacks());
2831 EXPECT_EQ(stack, panel1->collection());
2832 EXPECT_EQ(stack, panel2->collection());
2833 EXPECT_EQ(stack, panel3->collection());
2834
2835 panel1_expected_bounds.Offset(drag_delta);
2836 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
2837 panel2_expected_bounds.Offset(drag_delta);
2838 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
2839 panel3_expected_bounds.Offset(drag_delta);
2840 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
2841
2842 panel_manager->CloseAll();
2843 }
2844 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/panel_collection.h ('k') | chrome/browser/ui/panels/panel_drag_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698