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 "chrome/browser/ui/panels/base_panel_browser_test.h" | 5 #include "chrome/browser/ui/panels/base_panel_browser_test.h" |
6 #include "chrome/browser/ui/panels/detached_panel_strip.h" | 6 #include "chrome/browser/ui/panels/detached_panel_strip.h" |
7 #include "chrome/browser/ui/panels/native_panel.h" | 7 #include "chrome/browser/ui/panels/native_panel.h" |
8 #include "chrome/browser/ui/panels/panel.h" | 8 #include "chrome/browser/ui/panels/panel.h" |
9 #include "chrome/browser/ui/panels/panel_drag_controller.h" | 9 #include "chrome/browser/ui/panels/panel_drag_controller.h" |
10 #include "chrome/browser/ui/panels/panel_manager.h" | 10 #include "chrome/browser/ui/panels/panel_manager.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, DragDetachedPanel) { | 45 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, DragDetachedPanel) { |
46 PanelManager* panel_manager = PanelManager::GetInstance(); | 46 PanelManager* panel_manager = PanelManager::GetInstance(); |
47 DetachedPanelStrip* detached_strip = panel_manager->detached_strip(); | 47 DetachedPanelStrip* detached_strip = panel_manager->detached_strip(); |
48 | 48 |
49 // Create one detached panel. | 49 // Create one detached panel. |
50 Panel* panel = CreatePanelWithBounds("Panel1", gfx::Rect(0, 0, 250, 200)); | 50 Panel* panel = CreatePanelWithBounds("Panel1", gfx::Rect(0, 0, 250, 200)); |
51 panel->MoveToStrip(detached_strip); | 51 panel->MoveToStrip(detached_strip); |
52 | 52 |
53 // Test that the detached panel can be dragged anywhere. | 53 // Test that the detached panel can be dragged anywhere. |
| 54 // Note that we should not drag the panel close to the bottom area to trigger |
| 55 // the attach. |
54 scoped_ptr<NativePanelTesting> panel_testing( | 56 scoped_ptr<NativePanelTesting> panel_testing( |
55 NativePanelTesting::Create(panel->native_panel())); | 57 NativePanelTesting::Create(panel->native_panel())); |
56 gfx::Point origin = panel->GetBounds().origin(); | 58 gfx::Point origin = panel->GetBounds().origin(); |
57 | 59 |
58 panel_testing->PressLeftMouseButtonTitlebar(origin); | 60 panel_testing->PressLeftMouseButtonTitlebar(origin); |
59 EXPECT_EQ(origin, panel->GetBounds().origin()); | 61 EXPECT_EQ(origin, panel->GetBounds().origin()); |
60 | 62 |
61 panel_testing->DragTitlebar(-51, 102); | 63 origin.Offset(-51, -102); |
62 origin.Offset(-51, 102); | 64 panel_testing->DragTitlebar(origin); |
63 EXPECT_EQ(origin, panel->GetBounds().origin()); | 65 EXPECT_EQ(origin, panel->GetBounds().origin()); |
64 | 66 |
65 panel_testing->DragTitlebar(37, -42); | 67 origin.Offset(37, 45); |
66 origin.Offset(37, -42); | 68 panel_testing->DragTitlebar(origin); |
67 EXPECT_EQ(origin, panel->GetBounds().origin()); | 69 EXPECT_EQ(origin, panel->GetBounds().origin()); |
68 | 70 |
69 panel_testing->FinishDragTitlebar(); | 71 panel_testing->FinishDragTitlebar(); |
70 EXPECT_EQ(origin, panel->GetBounds().origin()); | 72 EXPECT_EQ(origin, panel->GetBounds().origin()); |
71 | 73 |
72 // Test that cancelling the drag will return the panel the the original | 74 // Test that cancelling the drag will return the panel the the original |
73 // position. | 75 // position. |
74 gfx::Point original_position = panel->GetBounds().origin(); | 76 gfx::Point original_position = panel->GetBounds().origin(); |
75 origin = original_position; | 77 origin = original_position; |
76 | 78 |
77 panel_testing->PressLeftMouseButtonTitlebar(origin); | 79 panel_testing->PressLeftMouseButtonTitlebar(origin); |
78 EXPECT_EQ(origin, panel->GetBounds().origin()); | 80 EXPECT_EQ(origin, panel->GetBounds().origin()); |
79 | 81 |
80 panel_testing->DragTitlebar(-51, 102); | 82 origin.Offset(-51, -102); |
81 origin.Offset(-51, 102); | 83 panel_testing->DragTitlebar(origin); |
82 EXPECT_EQ(origin, panel->GetBounds().origin()); | 84 EXPECT_EQ(origin, panel->GetBounds().origin()); |
83 | 85 |
84 panel_testing->DragTitlebar(37, -42); | 86 origin.Offset(37, 45); |
85 origin.Offset(37, -42); | 87 panel_testing->DragTitlebar(origin); |
86 EXPECT_EQ(origin, panel->GetBounds().origin()); | 88 EXPECT_EQ(origin, panel->GetBounds().origin()); |
87 | 89 |
88 panel_testing->CancelDragTitlebar(); | 90 panel_testing->CancelDragTitlebar(); |
89 EXPECT_EQ(original_position, panel->GetBounds().origin()); | 91 EXPECT_EQ(original_position, panel->GetBounds().origin()); |
90 | 92 |
91 panel_manager->CloseAll(); | 93 panel_manager->CloseAll(); |
92 } | 94 } |
93 | 95 |
94 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, CloseDetachedPanelOnDrag) { | 96 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, CloseDetachedPanelOnDrag) { |
95 PanelManager* panel_manager = PanelManager::GetInstance(); | 97 PanelManager* panel_manager = PanelManager::GetInstance(); |
(...skipping 18 matching lines...) Expand all Loading... |
114 gfx::Point panel3_position = panel3->GetBounds().origin(); | 116 gfx::Point panel3_position = panel3->GetBounds().origin(); |
115 gfx::Point panel4_position = panel4->GetBounds().origin(); | 117 gfx::Point panel4_position = panel4->GetBounds().origin(); |
116 | 118 |
117 // Test the scenario: drag a panel, close another panel, cancel the drag. | 119 // Test the scenario: drag a panel, close another panel, cancel the drag. |
118 { | 120 { |
119 gfx::Point panel1_new_position = panel1_old_position; | 121 gfx::Point panel1_new_position = panel1_old_position; |
120 panel1_new_position.Offset(-51, -102); | 122 panel1_new_position.Offset(-51, -102); |
121 | 123 |
122 // Start dragging a panel. | 124 // Start dragging a panel. |
123 panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); | 125 panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); |
124 panel1_testing->DragTitlebar(-51, -102); | 126 panel1_testing->DragTitlebar(panel1_new_position); |
125 EXPECT_TRUE(drag_controller->IsDragging()); | 127 EXPECT_TRUE(drag_controller->IsDragging()); |
126 EXPECT_EQ(panel1, drag_controller->dragging_panel()); | 128 EXPECT_EQ(panel1, drag_controller->dragging_panel()); |
127 | 129 |
128 ASSERT_EQ(4, detached_strip->num_panels()); | 130 ASSERT_EQ(4, detached_strip->num_panels()); |
129 EXPECT_TRUE(detached_strip->HasPanel(panel1)); | 131 EXPECT_TRUE(detached_strip->HasPanel(panel1)); |
130 EXPECT_TRUE(detached_strip->HasPanel(panel2)); | 132 EXPECT_TRUE(detached_strip->HasPanel(panel2)); |
131 EXPECT_TRUE(detached_strip->HasPanel(panel3)); | 133 EXPECT_TRUE(detached_strip->HasPanel(panel3)); |
132 EXPECT_TRUE(detached_strip->HasPanel(panel4)); | 134 EXPECT_TRUE(detached_strip->HasPanel(panel4)); |
133 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); | 135 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); |
134 EXPECT_EQ(panel2_position, panel2->GetBounds().origin()); | 136 EXPECT_EQ(panel2_position, panel2->GetBounds().origin()); |
(...skipping 27 matching lines...) Expand all Loading... |
162 EXPECT_EQ(panel4_position, panel4->GetBounds().origin()); | 164 EXPECT_EQ(panel4_position, panel4->GetBounds().origin()); |
163 } | 165 } |
164 | 166 |
165 // Test the scenario: drag a panel, close another panel, end the drag. | 167 // Test the scenario: drag a panel, close another panel, end the drag. |
166 { | 168 { |
167 gfx::Point panel1_new_position = panel1_old_position; | 169 gfx::Point panel1_new_position = panel1_old_position; |
168 panel1_new_position.Offset(-51, -102); | 170 panel1_new_position.Offset(-51, -102); |
169 | 171 |
170 // Start dragging a panel. | 172 // Start dragging a panel. |
171 panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); | 173 panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); |
172 panel1_testing->DragTitlebar(-51, -102); | 174 panel1_testing->DragTitlebar(panel1_new_position); |
173 EXPECT_TRUE(drag_controller->IsDragging()); | 175 EXPECT_TRUE(drag_controller->IsDragging()); |
174 EXPECT_EQ(panel1, drag_controller->dragging_panel()); | 176 EXPECT_EQ(panel1, drag_controller->dragging_panel()); |
175 | 177 |
176 ASSERT_EQ(3, detached_strip->num_panels()); | 178 ASSERT_EQ(3, detached_strip->num_panels()); |
177 EXPECT_TRUE(detached_strip->HasPanel(panel1)); | 179 EXPECT_TRUE(detached_strip->HasPanel(panel1)); |
178 EXPECT_TRUE(detached_strip->HasPanel(panel3)); | 180 EXPECT_TRUE(detached_strip->HasPanel(panel3)); |
179 EXPECT_TRUE(detached_strip->HasPanel(panel4)); | 181 EXPECT_TRUE(detached_strip->HasPanel(panel4)); |
180 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); | 182 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); |
181 EXPECT_EQ(panel3_position, panel3->GetBounds().origin()); | 183 EXPECT_EQ(panel3_position, panel3->GetBounds().origin()); |
182 EXPECT_EQ(panel4_position, panel4->GetBounds().origin()); | 184 EXPECT_EQ(panel4_position, panel4->GetBounds().origin()); |
(...skipping 21 matching lines...) Expand all Loading... |
204 EXPECT_EQ(panel4_position, panel4->GetBounds().origin()); | 206 EXPECT_EQ(panel4_position, panel4->GetBounds().origin()); |
205 } | 207 } |
206 | 208 |
207 // Test the scenario: drag a panel and close the dragging panel. | 209 // Test the scenario: drag a panel and close the dragging panel. |
208 { | 210 { |
209 gfx::Point panel1_new_position = panel1->GetBounds().origin(); | 211 gfx::Point panel1_new_position = panel1->GetBounds().origin(); |
210 panel1_new_position.Offset(-51, -102); | 212 panel1_new_position.Offset(-51, -102); |
211 | 213 |
212 // Start dragging a panel again. | 214 // Start dragging a panel again. |
213 panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); | 215 panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); |
214 panel1_testing->DragTitlebar(-51, -102); | 216 panel1_testing->DragTitlebar(panel1_new_position); |
215 EXPECT_TRUE(drag_controller->IsDragging()); | 217 EXPECT_TRUE(drag_controller->IsDragging()); |
216 EXPECT_EQ(panel1, drag_controller->dragging_panel()); | 218 EXPECT_EQ(panel1, drag_controller->dragging_panel()); |
217 | 219 |
218 ASSERT_EQ(2, detached_strip->num_panels()); | 220 ASSERT_EQ(2, detached_strip->num_panels()); |
219 EXPECT_TRUE(detached_strip->HasPanel(panel1)); | 221 EXPECT_TRUE(detached_strip->HasPanel(panel1)); |
220 EXPECT_TRUE(detached_strip->HasPanel(panel4)); | 222 EXPECT_TRUE(detached_strip->HasPanel(panel4)); |
221 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); | 223 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); |
222 EXPECT_EQ(panel4_position, panel4->GetBounds().origin()); | 224 EXPECT_EQ(panel4_position, panel4->GetBounds().origin()); |
223 | 225 |
224 // Closing the dragging panel should end the drag. | 226 // Closing the dragging panel should end the drag. |
225 CloseWindowAndWait(panel1->browser()); | 227 CloseWindowAndWait(panel1->browser()); |
226 EXPECT_FALSE(drag_controller->IsDragging()); | 228 EXPECT_FALSE(drag_controller->IsDragging()); |
227 | 229 |
228 ASSERT_EQ(1, detached_strip->num_panels()); | 230 ASSERT_EQ(1, detached_strip->num_panels()); |
229 EXPECT_TRUE(detached_strip->HasPanel(panel4)); | 231 EXPECT_TRUE(detached_strip->HasPanel(panel4)); |
230 EXPECT_EQ(panel4_position, panel4->GetBounds().origin()); | 232 EXPECT_EQ(panel4_position, panel4->GetBounds().origin()); |
231 } | 233 } |
232 | 234 |
233 panel_manager->CloseAll(); | 235 panel_manager->CloseAll(); |
234 } | 236 } |
OLD | NEW |