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