OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/message_loop.h" |
| 6 #include "chrome/browser/ui/panels/base_panel_browser_test.h" |
| 7 #include "chrome/browser/ui/panels/detached_panel_strip.h" |
| 8 #include "chrome/browser/ui/panels/docked_panel_strip.h" |
| 9 #include "chrome/browser/ui/panels/native_panel.h" |
| 10 #include "chrome/browser/ui/panels/panel.h" |
| 11 #include "chrome/browser/ui/panels/panel_drag_controller.h" |
| 12 #include "chrome/browser/ui/panels/panel_manager.h" |
| 13 #include "chrome/browser/ui/panels/test_panel_mouse_watcher.h" |
| 14 |
| 15 class PanelDragBrowserTest : public BasePanelBrowserTest { |
| 16 public: |
| 17 PanelDragBrowserTest() : BasePanelBrowserTest() { |
| 18 } |
| 19 |
| 20 virtual ~PanelDragBrowserTest() { |
| 21 } |
| 22 |
| 23 virtual void SetUpOnMainThread() OVERRIDE { |
| 24 BasePanelBrowserTest::SetUpOnMainThread(); |
| 25 |
| 26 // All the tests here assume using mocked 800x600 screen area for the |
| 27 // primary monitor. Do the check now. |
| 28 gfx::Rect primary_screen_area = PanelManager::GetInstance()-> |
| 29 display_settings_provider()->GetPrimaryScreenArea(); |
| 30 DCHECK(primary_screen_area.width() == 800); |
| 31 DCHECK(primary_screen_area.height() == 600); |
| 32 } |
| 33 |
| 34 // Drag |panel| from its origin by the offset |delta|. |
| 35 void DragPanelByDelta(Panel* panel, const gfx::Point& delta) { |
| 36 scoped_ptr<NativePanelTesting> panel_testing( |
| 37 NativePanelTesting::Create(panel->native_panel())); |
| 38 gfx::Point mouse_location(panel->GetBounds().origin()); |
| 39 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 40 panel_testing->DragTitlebar(mouse_location.Add(delta)); |
| 41 panel_testing->FinishDragTitlebar(); |
| 42 } |
| 43 |
| 44 // Drag |panel| from its origin to |new_mouse_location|. |
| 45 void DragPanelToMouseLocation(Panel* panel, |
| 46 const gfx::Point& new_mouse_location) { |
| 47 scoped_ptr<NativePanelTesting> panel_testing( |
| 48 NativePanelTesting::Create(panel->native_panel())); |
| 49 gfx::Point mouse_location(panel->GetBounds().origin()); |
| 50 panel_testing->PressLeftMouseButtonTitlebar(panel->GetBounds().origin()); |
| 51 panel_testing->DragTitlebar(new_mouse_location); |
| 52 panel_testing->FinishDragTitlebar(); |
| 53 } |
| 54 |
| 55 static gfx::Point GetDragDeltaToRemainDocked() { |
| 56 return gfx::Point( |
| 57 -5, |
| 58 -(PanelDragController::GetDetachDockedPanelThreshold() / 2)); |
| 59 } |
| 60 |
| 61 static gfx::Point GetDragDeltaToDetach() { |
| 62 return gfx::Point( |
| 63 -20, |
| 64 -(PanelDragController::GetDetachDockedPanelThreshold() + 20)); |
| 65 } |
| 66 |
| 67 static gfx::Point GetDragDeltaToRemainDetached(Panel* panel) { |
| 68 int distance = panel->manager()->docked_strip()->display_area().bottom() - |
| 69 panel->GetBounds().bottom(); |
| 70 return gfx::Point( |
| 71 -5, |
| 72 distance - PanelDragController::GetDockDetachedPanelThreshold() * 2); |
| 73 } |
| 74 |
| 75 static gfx::Point GetDragDeltaToAttach(Panel* panel) { |
| 76 int distance = panel->manager()->docked_strip()->display_area().bottom() - |
| 77 panel->GetBounds().bottom(); |
| 78 return gfx::Point( |
| 79 -20, |
| 80 distance - PanelDragController::GetDockDetachedPanelThreshold() / 2); |
| 81 } |
| 82 }; |
| 83 |
| 84 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragOneDockedPanel) { |
| 85 static const int big_delta_x = 70; |
| 86 static const int big_delta_y = 30; // Do not exceed the threshold to detach. |
| 87 |
| 88 Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100)); |
| 89 scoped_ptr<NativePanelTesting> panel_testing( |
| 90 NativePanelTesting::Create(panel->native_panel())); |
| 91 gfx::Rect panel_old_bounds = panel->GetBounds(); |
| 92 |
| 93 // Drag left. |
| 94 gfx::Point mouse_location = panel_old_bounds.origin(); |
| 95 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 96 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 97 |
| 98 mouse_location.Offset(-big_delta_x, 0); |
| 99 panel_testing->DragTitlebar(mouse_location); |
| 100 gfx::Rect panel_new_bounds = panel_old_bounds; |
| 101 panel_new_bounds.Offset(-big_delta_x, 0); |
| 102 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 103 |
| 104 panel_testing->FinishDragTitlebar(); |
| 105 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 106 |
| 107 // Drag left and cancel. |
| 108 mouse_location = panel_old_bounds.origin(); |
| 109 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 110 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 111 |
| 112 mouse_location.Offset(-big_delta_x, 0); |
| 113 panel_testing->DragTitlebar(mouse_location); |
| 114 panel_new_bounds = panel_old_bounds; |
| 115 panel_new_bounds.Offset(-big_delta_x, 0); |
| 116 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 117 |
| 118 panel_testing->CancelDragTitlebar(); |
| 119 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 120 |
| 121 // Drag right. |
| 122 mouse_location = panel_old_bounds.origin(); |
| 123 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 124 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 125 |
| 126 mouse_location.Offset(big_delta_x, 0); |
| 127 panel_testing->DragTitlebar(mouse_location); |
| 128 panel_new_bounds = panel_old_bounds; |
| 129 panel_new_bounds.Offset(big_delta_x, 0); |
| 130 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 131 |
| 132 panel_testing->FinishDragTitlebar(); |
| 133 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 134 |
| 135 // Drag right and up. Expect no vertical movement. |
| 136 mouse_location = panel_old_bounds.origin(); |
| 137 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 138 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 139 |
| 140 mouse_location.Offset(big_delta_x, big_delta_y); |
| 141 panel_testing->DragTitlebar(mouse_location); |
| 142 panel_new_bounds = panel_old_bounds; |
| 143 panel_new_bounds.Offset(big_delta_x, 0); |
| 144 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 145 |
| 146 panel_testing->FinishDragTitlebar(); |
| 147 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 148 |
| 149 // Drag up. Expect no movement on drag. |
| 150 mouse_location = panel_old_bounds.origin(); |
| 151 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 152 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 153 |
| 154 mouse_location.Offset(0, -big_delta_y); |
| 155 panel_testing->DragTitlebar(mouse_location); |
| 156 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 157 |
| 158 panel_testing->FinishDragTitlebar(); |
| 159 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 160 |
| 161 // Drag down. Expect no movement on drag. |
| 162 mouse_location = panel_old_bounds.origin(); |
| 163 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 164 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 165 |
| 166 mouse_location.Offset(0, big_delta_y); |
| 167 panel_testing->DragTitlebar(mouse_location); |
| 168 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 169 |
| 170 panel_testing->FinishDragTitlebar(); |
| 171 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 172 |
| 173 PanelManager::GetInstance()->CloseAll(); |
| 174 } |
| 175 |
| 176 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragTwoDockedPanels) { |
| 177 static const gfx::Point small_delta(10, 0); |
| 178 |
| 179 Panel* panel1 = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100)); |
| 180 Panel* panel2 = CreateDockedPanel("2", gfx::Rect(0, 0, 100, 100)); |
| 181 scoped_ptr<NativePanelTesting> panel1_testing( |
| 182 NativePanelTesting::Create(panel1->native_panel())); |
| 183 scoped_ptr<NativePanelTesting> panel2_testing( |
| 184 NativePanelTesting::Create(panel2->native_panel())); |
| 185 gfx::Point position1 = panel1->GetBounds().origin(); |
| 186 gfx::Point position2 = panel2->GetBounds().origin(); |
| 187 |
| 188 // Drag right panel towards left with small delta. |
| 189 // Expect no shuffle: P1 P2 |
| 190 gfx::Point mouse_location = position1; |
| 191 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 192 EXPECT_EQ(position1, panel1->GetBounds().origin()); |
| 193 EXPECT_EQ(position2, panel2->GetBounds().origin()); |
| 194 |
| 195 mouse_location = mouse_location.Subtract(small_delta); |
| 196 panel1_testing->DragTitlebar(mouse_location); |
| 197 EXPECT_EQ(mouse_location, panel1->GetBounds().origin()); |
| 198 EXPECT_EQ(position2, panel2->GetBounds().origin()); |
| 199 |
| 200 panel1_testing->FinishDragTitlebar(); |
| 201 EXPECT_EQ(position1, panel1->GetBounds().origin()); |
| 202 EXPECT_EQ(position2, panel2->GetBounds().origin()); |
| 203 |
| 204 // Drag right panel towards left with big delta. |
| 205 // Expect shuffle: P2 P1 |
| 206 mouse_location = position1; |
| 207 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 208 EXPECT_EQ(position1, panel1->GetBounds().origin()); |
| 209 EXPECT_EQ(position2, panel2->GetBounds().origin()); |
| 210 |
| 211 mouse_location = position2.Add(gfx::Point(1, 0)); |
| 212 panel1_testing->DragTitlebar(mouse_location); |
| 213 EXPECT_EQ(mouse_location, panel1->GetBounds().origin()); |
| 214 EXPECT_EQ(position1, panel2->GetBounds().origin()); |
| 215 |
| 216 panel1_testing->FinishDragTitlebar(); |
| 217 EXPECT_EQ(position2, panel1->GetBounds().origin()); |
| 218 EXPECT_EQ(position1, panel2->GetBounds().origin()); |
| 219 |
| 220 // Drag left panel towards right with small delta. |
| 221 // Expect no shuffle: P2 P1 |
| 222 mouse_location = position2; |
| 223 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 224 EXPECT_EQ(position2, panel1->GetBounds().origin()); |
| 225 EXPECT_EQ(position1, panel2->GetBounds().origin()); |
| 226 |
| 227 mouse_location = mouse_location.Add(small_delta); |
| 228 panel1_testing->DragTitlebar(mouse_location); |
| 229 EXPECT_EQ(mouse_location, panel1->GetBounds().origin()); |
| 230 EXPECT_EQ(position1, panel2->GetBounds().origin()); |
| 231 |
| 232 panel1_testing->FinishDragTitlebar(); |
| 233 EXPECT_EQ(position2, panel1->GetBounds().origin()); |
| 234 EXPECT_EQ(position1, panel2->GetBounds().origin()); |
| 235 |
| 236 // Drag left panel towards right with big delta. |
| 237 // Expect shuffle: P1 P2 |
| 238 mouse_location = position2; |
| 239 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 240 EXPECT_EQ(position2, panel1->GetBounds().origin()); |
| 241 EXPECT_EQ(position1, panel2->GetBounds().origin()); |
| 242 |
| 243 mouse_location = position1.Add(gfx::Point(1, 0)); |
| 244 panel1_testing->DragTitlebar(mouse_location); |
| 245 EXPECT_EQ(mouse_location, panel1->GetBounds().origin()); |
| 246 EXPECT_EQ(position2, panel2->GetBounds().origin()); |
| 247 |
| 248 panel1_testing->FinishDragTitlebar(); |
| 249 EXPECT_EQ(position1, panel1->GetBounds().origin()); |
| 250 EXPECT_EQ(position2, panel2->GetBounds().origin()); |
| 251 |
| 252 // Drag right panel towards left with big delta and then cancel the drag. |
| 253 // Expect shuffle after drag: P2 P1 |
| 254 // Expect shuffle after cancel: P1 P2 |
| 255 mouse_location = position1; |
| 256 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 257 EXPECT_EQ(position1, panel1->GetBounds().origin()); |
| 258 EXPECT_EQ(position2, panel2->GetBounds().origin()); |
| 259 |
| 260 mouse_location = position2.Add(gfx::Point(1, 0)); |
| 261 panel1_testing->DragTitlebar(mouse_location); |
| 262 EXPECT_EQ(mouse_location, panel1->GetBounds().origin()); |
| 263 EXPECT_EQ(position1, panel2->GetBounds().origin()); |
| 264 |
| 265 panel1_testing->CancelDragTitlebar(); |
| 266 EXPECT_EQ(position1, panel1->GetBounds().origin()); |
| 267 EXPECT_EQ(position2, panel2->GetBounds().origin()); |
| 268 |
| 269 PanelManager::GetInstance()->CloseAll(); |
| 270 } |
| 271 |
| 272 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragThreeDockedPanels) { |
| 273 Panel* panel1 = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100)); |
| 274 Panel* panel2 = CreateDockedPanel("2", gfx::Rect(0, 0, 100, 100)); |
| 275 Panel* panel3 = CreateDockedPanel("3", gfx::Rect(0, 0, 100, 100)); |
| 276 scoped_ptr<NativePanelTesting> panel2_testing( |
| 277 NativePanelTesting::Create(panel2->native_panel())); |
| 278 scoped_ptr<NativePanelTesting> panel3_testing( |
| 279 NativePanelTesting::Create(panel3->native_panel())); |
| 280 gfx::Point position1 = panel1->GetBounds().origin(); |
| 281 gfx::Point position2 = panel2->GetBounds().origin(); |
| 282 gfx::Point position3 = panel3->GetBounds().origin(); |
| 283 |
| 284 // Drag leftmost panel to become the rightmost in 2 drags. Each drag will |
| 285 // shuffle one panel. |
| 286 // Expect shuffle after 1st drag: P1 P3 P2 |
| 287 // Expect shuffle after 2nd drag: P3 P1 P2 |
| 288 gfx::Point mouse_location = position3; |
| 289 panel3_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 290 EXPECT_EQ(position1, panel1->GetBounds().origin()); |
| 291 EXPECT_EQ(position2, panel2->GetBounds().origin()); |
| 292 EXPECT_EQ(position3, panel3->GetBounds().origin()); |
| 293 |
| 294 mouse_location = position2.Add(gfx::Point(1, 0)); |
| 295 panel3_testing->DragTitlebar(mouse_location); |
| 296 EXPECT_EQ(position1, panel1->GetBounds().origin()); |
| 297 EXPECT_EQ(position3, panel2->GetBounds().origin()); |
| 298 EXPECT_EQ(mouse_location, panel3->GetBounds().origin()); |
| 299 |
| 300 mouse_location = position1.Add(gfx::Point(1, 0)); |
| 301 panel3_testing->DragTitlebar(mouse_location); |
| 302 EXPECT_EQ(position2, panel1->GetBounds().origin()); |
| 303 EXPECT_EQ(position3, panel2->GetBounds().origin()); |
| 304 EXPECT_EQ(mouse_location, panel3->GetBounds().origin()); |
| 305 |
| 306 panel3_testing->FinishDragTitlebar(); |
| 307 EXPECT_EQ(position2, panel1->GetBounds().origin()); |
| 308 EXPECT_EQ(position3, panel2->GetBounds().origin()); |
| 309 EXPECT_EQ(position1, panel3->GetBounds().origin()); |
| 310 |
| 311 // Drag rightmost panel to become the leftmost in 2 drags and then cancel the |
| 312 // drag. Each drag will shuffle one panel and the cancellation will restore |
| 313 // all panels. |
| 314 // Expect shuffle after 1st drag: P1 P3 P2 |
| 315 // Expect shuffle after 2nd drag: P1 P2 P3 |
| 316 // Expect shuffle after cancel: P3 P1 P2 |
| 317 mouse_location = position1; |
| 318 panel3_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 319 EXPECT_EQ(position2, panel1->GetBounds().origin()); |
| 320 EXPECT_EQ(position3, panel2->GetBounds().origin()); |
| 321 EXPECT_EQ(position1, panel3->GetBounds().origin()); |
| 322 |
| 323 mouse_location = position2.Add(gfx::Point(1, 0)); |
| 324 panel3_testing->DragTitlebar(mouse_location); |
| 325 EXPECT_EQ(position1, panel1->GetBounds().origin()); |
| 326 EXPECT_EQ(position3, panel2->GetBounds().origin()); |
| 327 EXPECT_EQ(mouse_location, panel3->GetBounds().origin()); |
| 328 |
| 329 mouse_location = position3.Add(gfx::Point(1, 0)); |
| 330 panel3_testing->DragTitlebar(mouse_location); |
| 331 EXPECT_EQ(position1, panel1->GetBounds().origin()); |
| 332 EXPECT_EQ(position2, panel2->GetBounds().origin()); |
| 333 EXPECT_EQ(mouse_location, panel3->GetBounds().origin()); |
| 334 |
| 335 panel3_testing->CancelDragTitlebar(); |
| 336 EXPECT_EQ(position2, panel1->GetBounds().origin()); |
| 337 EXPECT_EQ(position3, panel2->GetBounds().origin()); |
| 338 EXPECT_EQ(position1, panel3->GetBounds().origin()); |
| 339 |
| 340 // Drag leftmost panel to become the rightmost in a single drag. The drag will |
| 341 // shuffle 2 panels at a time. |
| 342 // Expect shuffle: P2 P3 P1 |
| 343 mouse_location = position3; |
| 344 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 345 EXPECT_EQ(position2, panel1->GetBounds().origin()); |
| 346 EXPECT_EQ(position3, panel2->GetBounds().origin()); |
| 347 EXPECT_EQ(position1, panel3->GetBounds().origin()); |
| 348 |
| 349 mouse_location = position1.Add(gfx::Point(1, 0)); |
| 350 panel2_testing->DragTitlebar(mouse_location); |
| 351 EXPECT_EQ(position3, panel1->GetBounds().origin()); |
| 352 EXPECT_EQ(mouse_location, panel2->GetBounds().origin()); |
| 353 EXPECT_EQ(position2, panel3->GetBounds().origin()); |
| 354 |
| 355 panel2_testing->FinishDragTitlebar(); |
| 356 EXPECT_EQ(position3, panel1->GetBounds().origin()); |
| 357 EXPECT_EQ(position1, panel2->GetBounds().origin()); |
| 358 EXPECT_EQ(position2, panel3->GetBounds().origin()); |
| 359 |
| 360 // Drag rightmost panel to become the leftmost in a single drag. The drag will |
| 361 // shuffle 2 panels at a time. |
| 362 // Expect shuffle: P3 P1 P2 |
| 363 mouse_location = position1; |
| 364 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 365 EXPECT_EQ(position3, panel1->GetBounds().origin()); |
| 366 EXPECT_EQ(position1, panel2->GetBounds().origin()); |
| 367 EXPECT_EQ(position2, panel3->GetBounds().origin()); |
| 368 |
| 369 mouse_location = position3.Add(gfx::Point(1, 0)); |
| 370 panel2_testing->DragTitlebar(mouse_location); |
| 371 EXPECT_EQ(position2, panel1->GetBounds().origin()); |
| 372 EXPECT_EQ(mouse_location, panel2->GetBounds().origin()); |
| 373 EXPECT_EQ(position1, panel3->GetBounds().origin()); |
| 374 |
| 375 panel2_testing->FinishDragTitlebar(); |
| 376 EXPECT_EQ(position2, panel1->GetBounds().origin()); |
| 377 EXPECT_EQ(position3, panel2->GetBounds().origin()); |
| 378 EXPECT_EQ(position1, panel3->GetBounds().origin()); |
| 379 |
| 380 // Drag rightmost panel to become the leftmost in a single drag and then |
| 381 // cancel the drag. The drag will shuffle 2 panels and the cancellation will |
| 382 // restore all panels. |
| 383 // Expect shuffle after drag: P1 P2 P3 |
| 384 // Expect shuffle after cancel: P3 P1 P2 |
| 385 mouse_location = position1; |
| 386 panel3_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 387 EXPECT_EQ(position2, panel1->GetBounds().origin()); |
| 388 EXPECT_EQ(position3, panel2->GetBounds().origin()); |
| 389 EXPECT_EQ(position1, panel3->GetBounds().origin()); |
| 390 |
| 391 mouse_location = position3.Add(gfx::Point(1, 0)); |
| 392 panel3_testing->DragTitlebar(mouse_location); |
| 393 EXPECT_EQ(position1, panel1->GetBounds().origin()); |
| 394 EXPECT_EQ(position2, panel2->GetBounds().origin()); |
| 395 EXPECT_EQ(mouse_location, panel3->GetBounds().origin()); |
| 396 |
| 397 panel3_testing->CancelDragTitlebar(); |
| 398 EXPECT_EQ(position2, panel1->GetBounds().origin()); |
| 399 EXPECT_EQ(position3, panel2->GetBounds().origin()); |
| 400 EXPECT_EQ(position1, panel3->GetBounds().origin()); |
| 401 |
| 402 PanelManager::GetInstance()->CloseAll(); |
| 403 } |
| 404 |
| 405 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragMinimizedPanel) { |
| 406 // We'll simulate mouse movements for test. |
| 407 PanelMouseWatcher* mouse_watcher = new TestPanelMouseWatcher(); |
| 408 PanelManager::GetInstance()->SetMouseWatcherForTesting(mouse_watcher); |
| 409 |
| 410 Panel* panel = CreatePanel("panel1"); |
| 411 scoped_ptr<NativePanelTesting> panel_testing( |
| 412 NativePanelTesting::Create(panel->native_panel())); |
| 413 |
| 414 panel->Minimize(); |
| 415 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); |
| 416 |
| 417 // Hover over minimized panel to bring up titlebar. |
| 418 gfx::Point hover_point(panel->GetBounds().origin()); |
| 419 MoveMouseAndWaitForExpansionStateChange(panel, hover_point); |
| 420 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
| 421 |
| 422 // Verify we can drag a minimized panel. |
| 423 gfx::Rect panel_old_bounds = panel->GetBounds(); |
| 424 gfx::Point mouse_location = panel_old_bounds.origin(); |
| 425 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 426 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 427 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
| 428 |
| 429 mouse_location.Offset(-70, 0); |
| 430 panel_testing->DragTitlebar(mouse_location); |
| 431 gfx::Rect panel_new_bounds = panel_old_bounds; |
| 432 panel_new_bounds.Offset(-70, 0); |
| 433 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 434 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
| 435 |
| 436 // Verify panel returns to fully minimized state after dragging ends once |
| 437 // mouse moves away from panel. |
| 438 panel_testing->FinishDragTitlebar(); |
| 439 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
| 440 |
| 441 MoveMouseAndWaitForExpansionStateChange(panel, mouse_location); |
| 442 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); |
| 443 |
| 444 panel->Close(); |
| 445 } |
| 446 |
| 447 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, |
| 448 DragMinimizedPanelWhileDrawingAttention) { |
| 449 // We'll simulate mouse movements for test. |
| 450 PanelMouseWatcher* mouse_watcher = new TestPanelMouseWatcher(); |
| 451 PanelManager::GetInstance()->SetMouseWatcherForTesting(mouse_watcher); |
| 452 |
| 453 Panel* panel = CreatePanel("panel1"); |
| 454 scoped_ptr<NativePanelTesting> panel_testing( |
| 455 NativePanelTesting::Create(panel->native_panel())); |
| 456 CreatePanel("panel2"); |
| 457 |
| 458 panel->Minimize(); |
| 459 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); |
| 460 |
| 461 panel->FlashFrame(true); |
| 462 EXPECT_TRUE(panel->IsDrawingAttention()); |
| 463 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
| 464 |
| 465 // Drag the panel. Verify panel stays in title-only state after attention is |
| 466 // cleared because it is being dragged. |
| 467 gfx::Rect panel_old_bounds = panel->GetBounds(); |
| 468 gfx::Point mouse_location = panel_old_bounds.origin(); |
| 469 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 470 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 471 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
| 472 |
| 473 mouse_location.Offset(-70, 0); |
| 474 panel_testing->DragTitlebar(mouse_location); |
| 475 gfx::Rect panel_new_bounds = panel_old_bounds; |
| 476 panel_new_bounds.Offset(-70, 0); |
| 477 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 478 |
| 479 panel->FlashFrame(false); |
| 480 EXPECT_FALSE(panel->IsDrawingAttention()); |
| 481 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
| 482 |
| 483 // Verify panel returns to fully minimized state after dragging ends once |
| 484 // mouse moves away from the panel. |
| 485 panel_testing->FinishDragTitlebar(); |
| 486 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
| 487 |
| 488 mouse_location.Offset(0, -50); |
| 489 MoveMouseAndWaitForExpansionStateChange(panel, mouse_location); |
| 490 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); |
| 491 |
| 492 PanelManager::GetInstance()->CloseAll(); |
| 493 } |
| 494 |
| 495 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, CloseDockedPanelOnDrag) { |
| 496 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 497 PanelDragController* drag_controller = panel_manager->drag_controller(); |
| 498 DockedPanelStrip* docked_strip = panel_manager->docked_strip(); |
| 499 |
| 500 // Create 4 docked panels. |
| 501 // We have: P4 P3 P2 P1 |
| 502 Panel* panel1 = CreatePanelWithBounds("Panel1", gfx::Rect(0, 0, 100, 100)); |
| 503 Panel* panel2 = CreatePanelWithBounds("Panel2", gfx::Rect(0, 0, 100, 100)); |
| 504 Panel* panel3 = CreatePanelWithBounds("Panel3", gfx::Rect(0, 0, 100, 100)); |
| 505 Panel* panel4 = CreatePanelWithBounds("Panel4", gfx::Rect(0, 0, 100, 100)); |
| 506 ASSERT_EQ(4, docked_strip->num_panels()); |
| 507 |
| 508 scoped_ptr<NativePanelTesting> panel1_testing( |
| 509 NativePanelTesting::Create(panel1->native_panel())); |
| 510 gfx::Point position1 = panel1->GetBounds().origin(); |
| 511 gfx::Point position2 = panel2->GetBounds().origin(); |
| 512 gfx::Point position3 = panel3->GetBounds().origin(); |
| 513 gfx::Point position4 = panel4->GetBounds().origin(); |
| 514 |
| 515 // Test the scenario: drag a panel, close another panel, cancel the drag. |
| 516 { |
| 517 std::vector<Panel*> panels; |
| 518 gfx::Point panel1_new_position = position1; |
| 519 panel1_new_position.Offset(-500, 0); |
| 520 |
| 521 // Start dragging a panel. |
| 522 // We have: P1* P4 P3 P2 |
| 523 gfx::Point mouse_location = panel1->GetBounds().origin(); |
| 524 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 525 mouse_location.Offset(-500, -5); |
| 526 panel1_testing->DragTitlebar(mouse_location); |
| 527 EXPECT_TRUE(drag_controller->IsDragging()); |
| 528 EXPECT_EQ(panel1, drag_controller->dragging_panel()); |
| 529 |
| 530 ASSERT_EQ(4, docked_strip->num_panels()); |
| 531 panels = PanelManager::GetInstance()->panels(); |
| 532 EXPECT_EQ(panel2, panels[0]); |
| 533 EXPECT_EQ(panel3, panels[1]); |
| 534 EXPECT_EQ(panel4, panels[2]); |
| 535 EXPECT_EQ(panel1, panels[3]); |
| 536 EXPECT_EQ(position1, panel2->GetBounds().origin()); |
| 537 EXPECT_EQ(position2, panel3->GetBounds().origin()); |
| 538 EXPECT_EQ(position3, panel4->GetBounds().origin()); |
| 539 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); |
| 540 |
| 541 // Closing another panel while dragging in progress will keep the dragging |
| 542 // panel intact. |
| 543 // We have: P1* P4 P3 |
| 544 CloseWindowAndWait(panel2); |
| 545 EXPECT_TRUE(drag_controller->IsDragging()); |
| 546 EXPECT_EQ(panel1, drag_controller->dragging_panel()); |
| 547 |
| 548 ASSERT_EQ(3, docked_strip->num_panels()); |
| 549 panels = PanelManager::GetInstance()->panels(); |
| 550 EXPECT_EQ(panel3, panels[0]); |
| 551 EXPECT_EQ(panel4, panels[1]); |
| 552 EXPECT_EQ(panel1, panels[2]); |
| 553 EXPECT_EQ(position1, panel3->GetBounds().origin()); |
| 554 EXPECT_EQ(position2, panel4->GetBounds().origin()); |
| 555 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); |
| 556 |
| 557 // Cancel the drag. |
| 558 // We have: P4 P3 P1 |
| 559 panel1_testing->CancelDragTitlebar(); |
| 560 EXPECT_FALSE(drag_controller->IsDragging()); |
| 561 |
| 562 ASSERT_EQ(3, docked_strip->num_panels()); |
| 563 panels = PanelManager::GetInstance()->panels(); |
| 564 EXPECT_EQ(panel1, panels[0]); |
| 565 EXPECT_EQ(panel3, panels[1]); |
| 566 EXPECT_EQ(panel4, panels[2]); |
| 567 EXPECT_EQ(position1, panel1->GetBounds().origin()); |
| 568 EXPECT_EQ(position2, panel3->GetBounds().origin()); |
| 569 EXPECT_EQ(position3, panel4->GetBounds().origin()); |
| 570 } |
| 571 |
| 572 // Test the scenario: drag a panel, close another panel, end the drag. |
| 573 { |
| 574 std::vector<Panel*> panels; |
| 575 gfx::Point panel1_new_position = position1; |
| 576 panel1_new_position.Offset(-500, 0); |
| 577 |
| 578 // Start dragging a panel. |
| 579 // We have: P1* P4 P3 |
| 580 gfx::Point mouse_location = panel1->GetBounds().origin(); |
| 581 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 582 mouse_location.Offset(-500, -5); |
| 583 panel1_testing->DragTitlebar(mouse_location); |
| 584 EXPECT_TRUE(drag_controller->IsDragging()); |
| 585 EXPECT_EQ(panel1, drag_controller->dragging_panel()); |
| 586 |
| 587 ASSERT_EQ(3, docked_strip->num_panels()); |
| 588 panels = PanelManager::GetInstance()->panels(); |
| 589 EXPECT_EQ(panel3, panels[0]); |
| 590 EXPECT_EQ(panel4, panels[1]); |
| 591 EXPECT_EQ(panel1, panels[2]); |
| 592 EXPECT_EQ(position1, panel3->GetBounds().origin()); |
| 593 EXPECT_EQ(position2, panel4->GetBounds().origin()); |
| 594 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); |
| 595 |
| 596 // Closing another panel while dragging in progress will keep the dragging |
| 597 // panel intact. |
| 598 // We have: P1* P4 |
| 599 CloseWindowAndWait(panel3); |
| 600 EXPECT_TRUE(drag_controller->IsDragging()); |
| 601 EXPECT_EQ(panel1, drag_controller->dragging_panel()); |
| 602 |
| 603 ASSERT_EQ(2, docked_strip->num_panels()); |
| 604 panels = PanelManager::GetInstance()->panels(); |
| 605 EXPECT_EQ(panel4, panels[0]); |
| 606 EXPECT_EQ(panel1, panels[1]); |
| 607 EXPECT_EQ(position1, panel4->GetBounds().origin()); |
| 608 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); |
| 609 |
| 610 // Finish the drag. |
| 611 // We have: P1 P4 |
| 612 panel1_testing->FinishDragTitlebar(); |
| 613 EXPECT_FALSE(drag_controller->IsDragging()); |
| 614 |
| 615 ASSERT_EQ(2, docked_strip->num_panels()); |
| 616 panels = PanelManager::GetInstance()->panels(); |
| 617 EXPECT_EQ(panel4, panels[0]); |
| 618 EXPECT_EQ(panel1, panels[1]); |
| 619 EXPECT_EQ(position1, panel4->GetBounds().origin()); |
| 620 EXPECT_EQ(position2, panel1->GetBounds().origin()); |
| 621 } |
| 622 |
| 623 // Test the scenario: drag a panel and close the dragging panel. |
| 624 { |
| 625 std::vector<Panel*> panels; |
| 626 gfx::Point panel1_new_position = position2; |
| 627 panel1_new_position.Offset(-500, 0); |
| 628 |
| 629 // Start dragging a panel again. |
| 630 // We have: P1* P4 |
| 631 gfx::Point mouse_location = panel1->GetBounds().origin(); |
| 632 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 633 mouse_location.Offset(-500, -5); |
| 634 panel1_testing->DragTitlebar(mouse_location); |
| 635 EXPECT_TRUE(drag_controller->IsDragging()); |
| 636 EXPECT_EQ(panel1, drag_controller->dragging_panel()); |
| 637 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); |
| 638 |
| 639 ASSERT_EQ(2, docked_strip->num_panels()); |
| 640 panels = PanelManager::GetInstance()->panels(); |
| 641 EXPECT_EQ(panel4, panels[0]); |
| 642 EXPECT_EQ(panel1, panels[1]); |
| 643 EXPECT_EQ(position1, panel4->GetBounds().origin()); |
| 644 |
| 645 // Closing the dragging panel should end the drag. |
| 646 // We have: P4 |
| 647 CloseWindowAndWait(panel1); |
| 648 EXPECT_FALSE(drag_controller->IsDragging()); |
| 649 |
| 650 ASSERT_EQ(1, docked_strip->num_panels()); |
| 651 panels = PanelManager::GetInstance()->panels(); |
| 652 EXPECT_EQ(panel4, panels[0]); |
| 653 EXPECT_EQ(position1, panel4->GetBounds().origin()); |
| 654 } |
| 655 |
| 656 panel_manager->CloseAll(); |
| 657 } |
| 658 |
| 659 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragOneDetachedPanel) { |
| 660 Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200)); |
| 661 |
| 662 // Test that the detached panel can be dragged almost anywhere except getting |
| 663 // close to the bottom of the docked area to trigger the attach. |
| 664 scoped_ptr<NativePanelTesting> panel_testing( |
| 665 NativePanelTesting::Create(panel->native_panel())); |
| 666 gfx::Point origin = panel->GetBounds().origin(); |
| 667 |
| 668 panel_testing->PressLeftMouseButtonTitlebar(origin); |
| 669 EXPECT_EQ(origin, panel->GetBounds().origin()); |
| 670 |
| 671 origin.Offset(-51, -102); |
| 672 panel_testing->DragTitlebar(origin); |
| 673 EXPECT_EQ(origin, panel->GetBounds().origin()); |
| 674 |
| 675 origin.Offset(37, 45); |
| 676 panel_testing->DragTitlebar(origin); |
| 677 EXPECT_EQ(origin, panel->GetBounds().origin()); |
| 678 |
| 679 panel_testing->FinishDragTitlebar(); |
| 680 EXPECT_EQ(origin, panel->GetBounds().origin()); |
| 681 |
| 682 // Test that cancelling the drag will return the panel the the original |
| 683 // position. |
| 684 gfx::Point original_position = panel->GetBounds().origin(); |
| 685 origin = original_position; |
| 686 |
| 687 panel_testing->PressLeftMouseButtonTitlebar(origin); |
| 688 EXPECT_EQ(origin, panel->GetBounds().origin()); |
| 689 |
| 690 origin.Offset(-51, -102); |
| 691 panel_testing->DragTitlebar(origin); |
| 692 EXPECT_EQ(origin, panel->GetBounds().origin()); |
| 693 |
| 694 origin.Offset(37, 45); |
| 695 panel_testing->DragTitlebar(origin); |
| 696 EXPECT_EQ(origin, panel->GetBounds().origin()); |
| 697 |
| 698 panel_testing->CancelDragTitlebar(); |
| 699 WaitForBoundsAnimationFinished(panel); |
| 700 EXPECT_EQ(original_position, panel->GetBounds().origin()); |
| 701 |
| 702 PanelManager::GetInstance()->CloseAll(); |
| 703 } |
| 704 |
| 705 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, CloseDetachedPanelOnDrag) { |
| 706 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 707 PanelDragController* drag_controller = panel_manager->drag_controller(); |
| 708 DetachedPanelStrip* detached_strip = panel_manager->detached_strip(); |
| 709 |
| 710 // Create 4 detached panels. |
| 711 Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(100, 200, 100, 100)); |
| 712 Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(200, 210, 110, 110)); |
| 713 Panel* panel3 = CreateDetachedPanel("3", gfx::Rect(300, 220, 120, 120)); |
| 714 Panel* panel4 = CreateDetachedPanel("4", gfx::Rect(400, 230, 130, 130)); |
| 715 ASSERT_EQ(4, detached_strip->num_panels()); |
| 716 |
| 717 scoped_ptr<NativePanelTesting> panel1_testing( |
| 718 NativePanelTesting::Create(panel1->native_panel())); |
| 719 gfx::Point panel1_old_position = panel1->GetBounds().origin(); |
| 720 gfx::Point panel2_position = panel2->GetBounds().origin(); |
| 721 gfx::Point panel3_position = panel3->GetBounds().origin(); |
| 722 gfx::Point panel4_position = panel4->GetBounds().origin(); |
| 723 |
| 724 // Test the scenario: drag a panel, close another panel, cancel the drag. |
| 725 { |
| 726 gfx::Point panel1_new_position = panel1_old_position; |
| 727 panel1_new_position.Offset(-51, -102); |
| 728 |
| 729 // Start dragging a panel. |
| 730 panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); |
| 731 panel1_testing->DragTitlebar(panel1_new_position); |
| 732 EXPECT_TRUE(drag_controller->IsDragging()); |
| 733 EXPECT_EQ(panel1, drag_controller->dragging_panel()); |
| 734 |
| 735 ASSERT_EQ(4, detached_strip->num_panels()); |
| 736 EXPECT_TRUE(detached_strip->HasPanel(panel1)); |
| 737 EXPECT_TRUE(detached_strip->HasPanel(panel2)); |
| 738 EXPECT_TRUE(detached_strip->HasPanel(panel3)); |
| 739 EXPECT_TRUE(detached_strip->HasPanel(panel4)); |
| 740 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); |
| 741 EXPECT_EQ(panel2_position, panel2->GetBounds().origin()); |
| 742 EXPECT_EQ(panel3_position, panel3->GetBounds().origin()); |
| 743 EXPECT_EQ(panel4_position, panel4->GetBounds().origin()); |
| 744 |
| 745 // Closing another panel while dragging in progress will keep the dragging |
| 746 // panel intact. |
| 747 CloseWindowAndWait(panel2); |
| 748 EXPECT_TRUE(drag_controller->IsDragging()); |
| 749 EXPECT_EQ(panel1, drag_controller->dragging_panel()); |
| 750 |
| 751 ASSERT_EQ(3, detached_strip->num_panels()); |
| 752 EXPECT_TRUE(detached_strip->HasPanel(panel1)); |
| 753 EXPECT_TRUE(detached_strip->HasPanel(panel3)); |
| 754 EXPECT_TRUE(detached_strip->HasPanel(panel4)); |
| 755 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); |
| 756 EXPECT_EQ(panel3_position, panel3->GetBounds().origin()); |
| 757 EXPECT_EQ(panel4_position, panel4->GetBounds().origin()); |
| 758 |
| 759 // Cancel the drag. |
| 760 panel1_testing->CancelDragTitlebar(); |
| 761 WaitForBoundsAnimationFinished(panel1); |
| 762 EXPECT_FALSE(drag_controller->IsDragging()); |
| 763 |
| 764 ASSERT_EQ(3, detached_strip->num_panels()); |
| 765 EXPECT_TRUE(detached_strip->HasPanel(panel1)); |
| 766 EXPECT_TRUE(detached_strip->HasPanel(panel3)); |
| 767 EXPECT_TRUE(detached_strip->HasPanel(panel4)); |
| 768 EXPECT_EQ(panel1_old_position, panel1->GetBounds().origin()); |
| 769 EXPECT_EQ(panel3_position, panel3->GetBounds().origin()); |
| 770 EXPECT_EQ(panel4_position, panel4->GetBounds().origin()); |
| 771 } |
| 772 |
| 773 // Test the scenario: drag a panel, close another panel, end the drag. |
| 774 { |
| 775 gfx::Point panel1_new_position = panel1_old_position; |
| 776 panel1_new_position.Offset(-51, -102); |
| 777 |
| 778 // Start dragging a panel. |
| 779 panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); |
| 780 panel1_testing->DragTitlebar(panel1_new_position); |
| 781 EXPECT_TRUE(drag_controller->IsDragging()); |
| 782 EXPECT_EQ(panel1, drag_controller->dragging_panel()); |
| 783 |
| 784 ASSERT_EQ(3, detached_strip->num_panels()); |
| 785 EXPECT_TRUE(detached_strip->HasPanel(panel1)); |
| 786 EXPECT_TRUE(detached_strip->HasPanel(panel3)); |
| 787 EXPECT_TRUE(detached_strip->HasPanel(panel4)); |
| 788 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); |
| 789 EXPECT_EQ(panel3_position, panel3->GetBounds().origin()); |
| 790 EXPECT_EQ(panel4_position, panel4->GetBounds().origin()); |
| 791 |
| 792 // Closing another panel while dragging in progress will keep the dragging |
| 793 // panel intact. |
| 794 CloseWindowAndWait(panel3); |
| 795 EXPECT_TRUE(drag_controller->IsDragging()); |
| 796 EXPECT_EQ(panel1, drag_controller->dragging_panel()); |
| 797 |
| 798 ASSERT_EQ(2, detached_strip->num_panels()); |
| 799 EXPECT_TRUE(detached_strip->HasPanel(panel1)); |
| 800 EXPECT_TRUE(detached_strip->HasPanel(panel4)); |
| 801 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); |
| 802 EXPECT_EQ(panel4_position, panel4->GetBounds().origin()); |
| 803 |
| 804 // Finish the drag. |
| 805 panel1_testing->FinishDragTitlebar(); |
| 806 EXPECT_FALSE(drag_controller->IsDragging()); |
| 807 |
| 808 ASSERT_EQ(2, detached_strip->num_panels()); |
| 809 EXPECT_TRUE(detached_strip->HasPanel(panel1)); |
| 810 EXPECT_TRUE(detached_strip->HasPanel(panel4)); |
| 811 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); |
| 812 EXPECT_EQ(panel4_position, panel4->GetBounds().origin()); |
| 813 } |
| 814 |
| 815 // Test the scenario: drag a panel and close the dragging panel. |
| 816 { |
| 817 gfx::Point panel1_new_position = panel1->GetBounds().origin(); |
| 818 panel1_new_position.Offset(-51, -102); |
| 819 |
| 820 // Start dragging a panel again. |
| 821 panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); |
| 822 panel1_testing->DragTitlebar(panel1_new_position); |
| 823 EXPECT_TRUE(drag_controller->IsDragging()); |
| 824 EXPECT_EQ(panel1, drag_controller->dragging_panel()); |
| 825 |
| 826 ASSERT_EQ(2, detached_strip->num_panels()); |
| 827 EXPECT_TRUE(detached_strip->HasPanel(panel1)); |
| 828 EXPECT_TRUE(detached_strip->HasPanel(panel4)); |
| 829 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); |
| 830 EXPECT_EQ(panel4_position, panel4->GetBounds().origin()); |
| 831 |
| 832 // Closing the dragging panel should end the drag. |
| 833 CloseWindowAndWait(panel1); |
| 834 EXPECT_FALSE(drag_controller->IsDragging()); |
| 835 |
| 836 ASSERT_EQ(1, detached_strip->num_panels()); |
| 837 EXPECT_TRUE(detached_strip->HasPanel(panel4)); |
| 838 EXPECT_EQ(panel4_position, panel4->GetBounds().origin()); |
| 839 } |
| 840 |
| 841 panel_manager->CloseAll(); |
| 842 } |
| 843 |
| 844 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, Detach) { |
| 845 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 846 DockedPanelStrip* docked_strip = panel_manager->docked_strip(); |
| 847 DetachedPanelStrip* detached_strip = panel_manager->detached_strip(); |
| 848 |
| 849 // Create one docked panel. |
| 850 Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100)); |
| 851 ASSERT_EQ(1, docked_strip->num_panels()); |
| 852 ASSERT_EQ(0, detached_strip->num_panels()); |
| 853 |
| 854 gfx::Rect panel_old_bounds = panel->GetBounds(); |
| 855 |
| 856 // Press on title-bar. |
| 857 scoped_ptr<NativePanelTesting> panel_testing( |
| 858 NativePanelTesting::Create(panel->native_panel())); |
| 859 gfx::Point mouse_location(panel->GetBounds().origin()); |
| 860 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 861 |
| 862 // Drag up the panel in a small offset that does not trigger the detach. |
| 863 // Expect that the panel is still docked and only x coordinate of its position |
| 864 // is changed. |
| 865 gfx::Point drag_delta_to_remain_docked = GetDragDeltaToRemainDocked(); |
| 866 mouse_location = mouse_location.Add(drag_delta_to_remain_docked); |
| 867 panel_testing->DragTitlebar(mouse_location); |
| 868 ASSERT_EQ(1, docked_strip->num_panels()); |
| 869 ASSERT_EQ(0, detached_strip->num_panels()); |
| 870 EXPECT_EQ(PanelStrip::DOCKED, panel->panel_strip()->type()); |
| 871 gfx::Rect panel_new_bounds = panel_old_bounds; |
| 872 panel_new_bounds.Offset(drag_delta_to_remain_docked.x(), 0); |
| 873 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 874 |
| 875 // Continue dragging up the panel in big offset that triggers the detach. |
| 876 // Expect that the panel is previewed as detached. |
| 877 gfx::Point drag_delta_to_detach = GetDragDeltaToDetach(); |
| 878 mouse_location = mouse_location.Add(drag_delta_to_detach); |
| 879 panel_testing->DragTitlebar(mouse_location); |
| 880 ASSERT_EQ(0, docked_strip->num_panels()); |
| 881 ASSERT_EQ(1, detached_strip->num_panels()); |
| 882 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 883 panel_new_bounds.Offset( |
| 884 drag_delta_to_detach.x(), |
| 885 drag_delta_to_detach.y() + drag_delta_to_remain_docked.y()); |
| 886 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 887 |
| 888 // Finish the drag. |
| 889 // Expect that the panel stays as detached. |
| 890 panel_testing->FinishDragTitlebar(); |
| 891 ASSERT_EQ(0, docked_strip->num_panels()); |
| 892 ASSERT_EQ(1, detached_strip->num_panels()); |
| 893 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 894 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 895 |
| 896 panel_manager->CloseAll(); |
| 897 } |
| 898 |
| 899 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DetachAndCancel) { |
| 900 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 901 DockedPanelStrip* docked_strip = panel_manager->docked_strip(); |
| 902 DetachedPanelStrip* detached_strip = panel_manager->detached_strip(); |
| 903 |
| 904 // Create one docked panel. |
| 905 Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100)); |
| 906 ASSERT_EQ(1, docked_strip->num_panels()); |
| 907 ASSERT_EQ(0, detached_strip->num_panels()); |
| 908 |
| 909 gfx::Rect panel_old_bounds = panel->GetBounds(); |
| 910 |
| 911 // Press on title-bar. |
| 912 scoped_ptr<NativePanelTesting> panel_testing( |
| 913 NativePanelTesting::Create(panel->native_panel())); |
| 914 gfx::Point mouse_location(panel->GetBounds().origin()); |
| 915 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 916 |
| 917 // Drag up the panel in a small offset that does not trigger the detach. |
| 918 // Expect that the panel is still docked and only x coordinate of its position |
| 919 // is changed. |
| 920 gfx::Point drag_delta_to_remain_docked = GetDragDeltaToRemainDocked(); |
| 921 mouse_location = mouse_location.Add(drag_delta_to_remain_docked); |
| 922 panel_testing->DragTitlebar(mouse_location); |
| 923 ASSERT_EQ(1, docked_strip->num_panels()); |
| 924 ASSERT_EQ(0, detached_strip->num_panels()); |
| 925 EXPECT_EQ(PanelStrip::DOCKED, panel->panel_strip()->type()); |
| 926 gfx::Rect panel_new_bounds = panel_old_bounds; |
| 927 panel_new_bounds.Offset(drag_delta_to_remain_docked.x(), 0); |
| 928 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 929 |
| 930 // Continue dragging up the panel in big offset that triggers the detach. |
| 931 // Expect that the panel is previewed as detached. |
| 932 gfx::Point drag_delta_to_detach = GetDragDeltaToDetach(); |
| 933 mouse_location = mouse_location.Add(drag_delta_to_detach); |
| 934 panel_testing->DragTitlebar(mouse_location); |
| 935 ASSERT_EQ(0, docked_strip->num_panels()); |
| 936 ASSERT_EQ(1, detached_strip->num_panels()); |
| 937 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 938 panel_new_bounds.Offset( |
| 939 drag_delta_to_detach.x(), |
| 940 drag_delta_to_detach.y() + drag_delta_to_remain_docked.y()); |
| 941 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 942 |
| 943 // Cancel the drag. |
| 944 // Expect that the panel is back as docked. |
| 945 panel_testing->CancelDragTitlebar(); |
| 946 ASSERT_EQ(1, docked_strip->num_panels()); |
| 947 ASSERT_EQ(0, detached_strip->num_panels()); |
| 948 EXPECT_EQ(PanelStrip::DOCKED, panel->panel_strip()->type()); |
| 949 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 950 |
| 951 panel_manager->CloseAll(); |
| 952 } |
| 953 |
| 954 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, Attach) { |
| 955 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 956 DockedPanelStrip* docked_strip = panel_manager->docked_strip(); |
| 957 DetachedPanelStrip* detached_strip = panel_manager->detached_strip(); |
| 958 |
| 959 // Create one detached panel. |
| 960 Panel* panel = CreateDetachedPanel("1", gfx::Rect(400, 300, 100, 100)); |
| 961 ASSERT_EQ(0, docked_strip->num_panels()); |
| 962 ASSERT_EQ(1, detached_strip->num_panels()); |
| 963 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 964 |
| 965 gfx::Rect panel_old_bounds = panel->GetBounds(); |
| 966 |
| 967 // Press on title-bar. |
| 968 scoped_ptr<NativePanelTesting> panel_testing( |
| 969 NativePanelTesting::Create(panel->native_panel())); |
| 970 gfx::Point mouse_location(panel->GetBounds().origin()); |
| 971 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 972 |
| 973 // Drag down the panel but not close enough to the bottom of work area. |
| 974 // Expect that the panel is still detached. |
| 975 gfx::Point drag_delta_to_remain_detached = |
| 976 GetDragDeltaToRemainDetached(panel); |
| 977 mouse_location = mouse_location.Add(drag_delta_to_remain_detached); |
| 978 panel_testing->DragTitlebar(mouse_location); |
| 979 ASSERT_EQ(0, docked_strip->num_panels()); |
| 980 ASSERT_EQ(1, detached_strip->num_panels()); |
| 981 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 982 gfx::Rect panel_new_bounds = panel_old_bounds; |
| 983 panel_new_bounds.Offset(drag_delta_to_remain_detached); |
| 984 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 985 |
| 986 // Continue dragging down the panel to make it close enough to the bottom of |
| 987 // work area. |
| 988 // Expect that the panel is previewed as docked. |
| 989 gfx::Point drag_delta_to_attach = GetDragDeltaToAttach(panel); |
| 990 mouse_location = mouse_location.Add(drag_delta_to_attach); |
| 991 panel_testing->DragTitlebar(mouse_location); |
| 992 ASSERT_EQ(1, docked_strip->num_panels()); |
| 993 ASSERT_EQ(0, detached_strip->num_panels()); |
| 994 EXPECT_EQ(PanelStrip::DOCKED, panel->panel_strip()->type()); |
| 995 panel_new_bounds.Offset(drag_delta_to_attach); |
| 996 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 997 |
| 998 // Finish the drag. |
| 999 // Expect that the panel stays as docked and moves to the final position. |
| 1000 panel_testing->FinishDragTitlebar(); |
| 1001 ASSERT_EQ(1, docked_strip->num_panels()); |
| 1002 ASSERT_EQ(0, detached_strip->num_panels()); |
| 1003 EXPECT_EQ(PanelStrip::DOCKED, panel->panel_strip()->type()); |
| 1004 panel_new_bounds.set_x( |
| 1005 docked_strip->StartingRightPosition() - panel_new_bounds.width()); |
| 1006 panel_new_bounds.set_y( |
| 1007 docked_strip->display_area().bottom() - panel_new_bounds.height()); |
| 1008 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 1009 |
| 1010 panel_manager->CloseAll(); |
| 1011 } |
| 1012 |
| 1013 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, AttachAndCancel) { |
| 1014 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 1015 DockedPanelStrip* docked_strip = panel_manager->docked_strip(); |
| 1016 DetachedPanelStrip* detached_strip = panel_manager->detached_strip(); |
| 1017 |
| 1018 // Create one detached panel. |
| 1019 Panel* panel = CreateDetachedPanel("1", gfx::Rect(400, 300, 100, 100)); |
| 1020 ASSERT_EQ(0, docked_strip->num_panels()); |
| 1021 ASSERT_EQ(1, detached_strip->num_panels()); |
| 1022 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 1023 |
| 1024 gfx::Rect panel_old_bounds = panel->GetBounds(); |
| 1025 |
| 1026 // Press on title-bar. |
| 1027 scoped_ptr<NativePanelTesting> panel_testing( |
| 1028 NativePanelTesting::Create(panel->native_panel())); |
| 1029 gfx::Point mouse_location(panel->GetBounds().origin()); |
| 1030 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 1031 |
| 1032 // Drag down the panel but not close enough to the bottom of work area. |
| 1033 // Expect that the panel is still detached. |
| 1034 gfx::Point drag_delta_to_remain_detached = |
| 1035 GetDragDeltaToRemainDetached(panel); |
| 1036 mouse_location = mouse_location.Add(drag_delta_to_remain_detached); |
| 1037 panel_testing->DragTitlebar(mouse_location); |
| 1038 ASSERT_EQ(0, docked_strip->num_panels()); |
| 1039 ASSERT_EQ(1, detached_strip->num_panels()); |
| 1040 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 1041 gfx::Rect panel_new_bounds = panel_old_bounds; |
| 1042 panel_new_bounds.Offset(drag_delta_to_remain_detached); |
| 1043 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 1044 |
| 1045 // Continue dragging down the panel to make it close enough to the bottom of |
| 1046 // work area. |
| 1047 // Expect that the panel is previewed as docked. |
| 1048 gfx::Point drag_delta_to_attach = GetDragDeltaToAttach(panel); |
| 1049 mouse_location = mouse_location.Add(drag_delta_to_attach); |
| 1050 panel_testing->DragTitlebar(mouse_location); |
| 1051 ASSERT_EQ(1, docked_strip->num_panels()); |
| 1052 ASSERT_EQ(0, detached_strip->num_panels()); |
| 1053 EXPECT_EQ(PanelStrip::DOCKED, panel->panel_strip()->type()); |
| 1054 panel_new_bounds.Offset(drag_delta_to_attach); |
| 1055 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 1056 |
| 1057 // Cancel the drag. |
| 1058 // Expect that the panel is back as detached. |
| 1059 panel_testing->CancelDragTitlebar(); |
| 1060 ASSERT_EQ(0, docked_strip->num_panels()); |
| 1061 ASSERT_EQ(1, detached_strip->num_panels()); |
| 1062 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 1063 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 1064 |
| 1065 panel_manager->CloseAll(); |
| 1066 } |
| 1067 |
| 1068 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DetachAttachAndCancel) { |
| 1069 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 1070 DockedPanelStrip* docked_strip = panel_manager->docked_strip(); |
| 1071 DetachedPanelStrip* detached_strip = panel_manager->detached_strip(); |
| 1072 |
| 1073 // Create one docked panel. |
| 1074 Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100)); |
| 1075 ASSERT_EQ(1, docked_strip->num_panels()); |
| 1076 ASSERT_EQ(0, detached_strip->num_panels()); |
| 1077 |
| 1078 gfx::Rect panel_old_bounds = panel->GetBounds(); |
| 1079 |
| 1080 // Press on title-bar. |
| 1081 scoped_ptr<NativePanelTesting> panel_testing( |
| 1082 NativePanelTesting::Create(panel->native_panel())); |
| 1083 gfx::Point mouse_location(panel->GetBounds().origin()); |
| 1084 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 1085 |
| 1086 // Drag up the panel to trigger the detach. |
| 1087 // Expect that the panel is previewed as detached. |
| 1088 gfx::Point drag_delta_to_detach = GetDragDeltaToDetach(); |
| 1089 mouse_location = mouse_location.Add(drag_delta_to_detach); |
| 1090 panel_testing->DragTitlebar(mouse_location); |
| 1091 ASSERT_EQ(0, docked_strip->num_panels()); |
| 1092 ASSERT_EQ(1, detached_strip->num_panels()); |
| 1093 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 1094 gfx::Rect panel_new_bounds = panel_old_bounds; |
| 1095 panel_new_bounds.Offset(drag_delta_to_detach); |
| 1096 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 1097 |
| 1098 // Continue dragging down the panel to trigger the re-attach. |
| 1099 gfx::Point drag_delta_to_reattach = GetDragDeltaToAttach(panel); |
| 1100 mouse_location = mouse_location.Add(drag_delta_to_reattach); |
| 1101 panel_testing->DragTitlebar(mouse_location); |
| 1102 ASSERT_EQ(1, docked_strip->num_panels()); |
| 1103 ASSERT_EQ(0, detached_strip->num_panels()); |
| 1104 EXPECT_EQ(PanelStrip::DOCKED, panel->panel_strip()->type()); |
| 1105 panel_new_bounds.Offset(drag_delta_to_reattach); |
| 1106 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 1107 |
| 1108 // Continue dragging up the panel to trigger the detach again. |
| 1109 gfx::Point drag_delta_to_detach_again = GetDragDeltaToDetach(); |
| 1110 mouse_location = mouse_location.Add(drag_delta_to_detach_again); |
| 1111 panel_testing->DragTitlebar(mouse_location); |
| 1112 ASSERT_EQ(0, docked_strip->num_panels()); |
| 1113 ASSERT_EQ(1, detached_strip->num_panels()); |
| 1114 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 1115 panel_new_bounds.Offset(drag_delta_to_detach_again); |
| 1116 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 1117 |
| 1118 // Cancel the drag. |
| 1119 // Expect that the panel stays as docked. |
| 1120 panel_testing->CancelDragTitlebar(); |
| 1121 ASSERT_EQ(1, docked_strip->num_panels()); |
| 1122 ASSERT_EQ(0, detached_strip->num_panels()); |
| 1123 EXPECT_EQ(PanelStrip::DOCKED, panel->panel_strip()->type()); |
| 1124 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 1125 |
| 1126 panel_manager->CloseAll(); |
| 1127 } |
| 1128 |
| 1129 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DetachWithSqueeze) { |
| 1130 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 1131 DockedPanelStrip* docked_strip = panel_manager->docked_strip(); |
| 1132 DetachedPanelStrip* detached_strip = panel_manager->detached_strip(); |
| 1133 |
| 1134 gfx::Point drag_delta_to_detach = GetDragDeltaToDetach(); |
| 1135 |
| 1136 // Create some docked panels. |
| 1137 // docked: P1 P2 P3 P4 P5 |
| 1138 Panel* panel1 = CreateDockedPanel("1", gfx::Rect(0, 0, 200, 100)); |
| 1139 Panel* panel2 = CreateDockedPanel("2", gfx::Rect(0, 0, 200, 100)); |
| 1140 Panel* panel3 = CreateDockedPanel("3", gfx::Rect(0, 0, 200, 100)); |
| 1141 Panel* panel4 = CreateDockedPanel("4", gfx::Rect(0, 0, 200, 100)); |
| 1142 Panel* panel5 = CreateDockedPanel("5", gfx::Rect(0, 0, 200, 100)); |
| 1143 ASSERT_EQ(0, detached_strip->num_panels()); |
| 1144 ASSERT_EQ(5, docked_strip->num_panels()); |
| 1145 |
| 1146 // Drag to detach the middle docked panel. |
| 1147 // Expect to have: |
| 1148 // detached: P2 |
| 1149 // docked: P1 P3 P4 P5 |
| 1150 gfx::Point panel2_docked_position = panel2->GetBounds().origin(); |
| 1151 DragPanelByDelta(panel2, drag_delta_to_detach); |
| 1152 ASSERT_EQ(1, detached_strip->num_panels()); |
| 1153 ASSERT_EQ(4, docked_strip->num_panels()); |
| 1154 EXPECT_EQ(PanelStrip::DOCKED, panel1->panel_strip()->type()); |
| 1155 EXPECT_EQ(PanelStrip::DETACHED, panel2->panel_strip()->type()); |
| 1156 EXPECT_EQ(PanelStrip::DOCKED, panel3->panel_strip()->type()); |
| 1157 EXPECT_EQ(PanelStrip::DOCKED, panel4->panel_strip()->type()); |
| 1158 EXPECT_EQ(PanelStrip::DOCKED, panel5->panel_strip()->type()); |
| 1159 gfx::Point panel2_new_position = |
| 1160 panel2_docked_position.Add(drag_delta_to_detach); |
| 1161 EXPECT_EQ(panel2_new_position, panel2->GetBounds().origin()); |
| 1162 |
| 1163 // Drag to detach the left-most docked panel. |
| 1164 // Expect to have: |
| 1165 // detached: P2 P4 |
| 1166 // docked: P1 P3 P5 |
| 1167 gfx::Point panel4_docked_position = panel4->GetBounds().origin(); |
| 1168 DragPanelByDelta(panel4, drag_delta_to_detach); |
| 1169 ASSERT_EQ(2, detached_strip->num_panels()); |
| 1170 ASSERT_EQ(3, docked_strip->num_panels()); |
| 1171 EXPECT_EQ(PanelStrip::DOCKED, panel1->panel_strip()->type()); |
| 1172 EXPECT_EQ(PanelStrip::DETACHED, panel2->panel_strip()->type()); |
| 1173 EXPECT_EQ(PanelStrip::DOCKED, panel3->panel_strip()->type()); |
| 1174 EXPECT_EQ(PanelStrip::DETACHED, panel4->panel_strip()->type()); |
| 1175 EXPECT_EQ(PanelStrip::DOCKED, panel5->panel_strip()->type()); |
| 1176 EXPECT_EQ(panel2_new_position, panel2->GetBounds().origin()); |
| 1177 gfx::Point panel4_new_position = |
| 1178 panel4_docked_position.Add(drag_delta_to_detach); |
| 1179 EXPECT_EQ(panel4_new_position, panel4->GetBounds().origin()); |
| 1180 |
| 1181 // Drag to detach the right-most docked panel. |
| 1182 // Expect to have: |
| 1183 // detached: P1 P2 P4 |
| 1184 // docked: P3 P5 |
| 1185 gfx::Point docked_position1 = panel1->GetBounds().origin(); |
| 1186 gfx::Point docked_position2 = panel3->GetBounds().origin(); |
| 1187 |
| 1188 DragPanelByDelta(panel1, drag_delta_to_detach); |
| 1189 ASSERT_EQ(3, detached_strip->num_panels()); |
| 1190 ASSERT_EQ(2, docked_strip->num_panels()); |
| 1191 EXPECT_EQ(PanelStrip::DETACHED, panel1->panel_strip()->type()); |
| 1192 EXPECT_EQ(PanelStrip::DETACHED, panel2->panel_strip()->type()); |
| 1193 EXPECT_EQ(PanelStrip::DOCKED, panel3->panel_strip()->type()); |
| 1194 EXPECT_EQ(PanelStrip::DETACHED, panel4->panel_strip()->type()); |
| 1195 EXPECT_EQ(PanelStrip::DOCKED, panel5->panel_strip()->type()); |
| 1196 gfx::Point panel1_new_position = docked_position1.Add(drag_delta_to_detach); |
| 1197 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); |
| 1198 EXPECT_EQ(panel2_new_position, panel2->GetBounds().origin()); |
| 1199 EXPECT_EQ(panel4_new_position, panel4->GetBounds().origin()); |
| 1200 |
| 1201 // No more squeeze, docked panels should stay put. |
| 1202 EXPECT_EQ(docked_position1, panel3->GetBounds().origin()); |
| 1203 EXPECT_EQ(panel1->GetBounds().width(), panel1->GetRestoredBounds().width()); |
| 1204 EXPECT_EQ(docked_position2, panel5->GetBounds().origin()); |
| 1205 EXPECT_EQ(panel2->GetBounds().width(), panel2->GetRestoredBounds().width()); |
| 1206 |
| 1207 panel_manager->CloseAll(); |
| 1208 } |
| 1209 |
| 1210 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, AttachWithSqueeze) { |
| 1211 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 1212 DockedPanelStrip* docked_strip = panel_manager->docked_strip(); |
| 1213 DetachedPanelStrip* detached_strip = panel_manager->detached_strip(); |
| 1214 |
| 1215 // Create some detached, docked panels. |
| 1216 // detached: P1 P2 P3 |
| 1217 // docked: P4 P5 P6 P7 |
| 1218 Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(100, 300, 200, 100)); |
| 1219 Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(200, 300, 200, 100)); |
| 1220 Panel* panel3 = CreateDetachedPanel("3", gfx::Rect(400, 300, 200, 100)); |
| 1221 Panel* panel4 = CreateDockedPanel("4", gfx::Rect(0, 0, 200, 100)); |
| 1222 Panel* panel5 = CreateDockedPanel("5", gfx::Rect(0, 0, 200, 100)); |
| 1223 Panel* panel6 = CreateDockedPanel("6", gfx::Rect(0, 0, 200, 100)); |
| 1224 Panel* panel7 = CreateDockedPanel("7", gfx::Rect(0, 0, 200, 100)); |
| 1225 ASSERT_EQ(3, detached_strip->num_panels()); |
| 1226 ASSERT_EQ(4, docked_strip->num_panels()); |
| 1227 |
| 1228 gfx::Point detached_position1 = panel1->GetBounds().origin(); |
| 1229 gfx::Point detached_position2 = panel2->GetBounds().origin(); |
| 1230 gfx::Point detached_position3 = panel3->GetBounds().origin(); |
| 1231 gfx::Point docked_position4 = panel4->GetBounds().origin(); |
| 1232 gfx::Point docked_position5 = panel5->GetBounds().origin(); |
| 1233 gfx::Point docked_position6 = panel6->GetBounds().origin(); |
| 1234 gfx::Point docked_position7 = panel7->GetBounds().origin(); |
| 1235 |
| 1236 // Drag to attach a detached panel between 2 docked panels. |
| 1237 // Expect to have: |
| 1238 // detached: P1 P2 |
| 1239 // docked: P4 P3 P5 P6 P7 |
| 1240 gfx::Point drag_to_location(panel5->GetBounds().x() + 10, |
| 1241 panel5->GetBounds().y()); |
| 1242 DragPanelToMouseLocation(panel3, drag_to_location); |
| 1243 ASSERT_EQ(2, detached_strip->num_panels()); |
| 1244 ASSERT_EQ(5, docked_strip->num_panels()); |
| 1245 EXPECT_EQ(PanelStrip::DETACHED, panel1->panel_strip()->type()); |
| 1246 EXPECT_EQ(PanelStrip::DETACHED, panel2->panel_strip()->type()); |
| 1247 EXPECT_EQ(PanelStrip::DOCKED, panel3->panel_strip()->type()); |
| 1248 EXPECT_EQ(PanelStrip::DOCKED, panel4->panel_strip()->type()); |
| 1249 EXPECT_EQ(PanelStrip::DOCKED, panel5->panel_strip()->type()); |
| 1250 EXPECT_EQ(PanelStrip::DOCKED, panel6->panel_strip()->type()); |
| 1251 EXPECT_EQ(PanelStrip::DOCKED, panel7->panel_strip()->type()); |
| 1252 EXPECT_EQ(detached_position1, panel1->GetBounds().origin()); |
| 1253 EXPECT_EQ(detached_position2, panel2->GetBounds().origin()); |
| 1254 |
| 1255 // Wait for active states to settle. |
| 1256 MessageLoopForUI::current()->RunAllPending(); |
| 1257 |
| 1258 // Panel positions should have shifted because of the "squeeze" mode. |
| 1259 EXPECT_NE(docked_position4, panel4->GetBounds().origin()); |
| 1260 EXPECT_LT(panel4->GetBounds().width(), panel4->GetRestoredBounds().width()); |
| 1261 EXPECT_NE(docked_position5, panel5->GetBounds().origin()); |
| 1262 EXPECT_LT(panel5->GetBounds().width(), panel5->GetRestoredBounds().width()); |
| 1263 |
| 1264 #if defined(OS_WIN) |
| 1265 // The panel we dragged becomes the active one. |
| 1266 EXPECT_EQ(true, panel3->IsActive()); |
| 1267 EXPECT_EQ(panel3->GetBounds().width(), panel3->GetRestoredBounds().width()); |
| 1268 |
| 1269 EXPECT_NE(docked_position6, panel6->GetBounds().origin()); |
| 1270 #else |
| 1271 // The last panel is active so these positions do not change. |
| 1272 // TODO (ABurago) this is wrong behavior, a panel should activate |
| 1273 // when it is dragged. Change the test when the behavior is fixed. |
| 1274 EXPECT_EQ(true, panel7->IsActive()); |
| 1275 EXPECT_EQ(panel7->GetBounds().width(), panel7->GetRestoredBounds().width()); |
| 1276 |
| 1277 EXPECT_EQ(docked_position6, panel6->GetBounds().origin()); |
| 1278 #endif |
| 1279 EXPECT_EQ(docked_position7, panel7->GetBounds().origin()); |
| 1280 |
| 1281 // Drag to attach a detached panel to most-right. |
| 1282 // Expect to have: |
| 1283 // detached: P1 |
| 1284 // docked: P2 P4 P3 P5 P6 P7 |
| 1285 gfx::Point drag_to_location2(panel4->GetBounds().right() + 10, |
| 1286 panel4->GetBounds().y()); |
| 1287 DragPanelToMouseLocation(panel2, drag_to_location2); |
| 1288 ASSERT_EQ(1, detached_strip->num_panels()); |
| 1289 ASSERT_EQ(6, docked_strip->num_panels()); |
| 1290 EXPECT_EQ(PanelStrip::DETACHED, panel1->panel_strip()->type()); |
| 1291 EXPECT_EQ(PanelStrip::DOCKED, panel2->panel_strip()->type()); |
| 1292 EXPECT_EQ(PanelStrip::DOCKED, panel3->panel_strip()->type()); |
| 1293 EXPECT_EQ(PanelStrip::DOCKED, panel4->panel_strip()->type()); |
| 1294 EXPECT_EQ(PanelStrip::DOCKED, panel5->panel_strip()->type()); |
| 1295 EXPECT_EQ(PanelStrip::DOCKED, panel6->panel_strip()->type()); |
| 1296 EXPECT_EQ(PanelStrip::DOCKED, panel7->panel_strip()->type()); |
| 1297 EXPECT_EQ(detached_position1, panel1->GetBounds().origin()); |
| 1298 |
| 1299 // Drag to attach a detached panel to most-left. |
| 1300 // Expect to have: |
| 1301 // docked: P2 P4 P1 P3 P5 P6 P7 |
| 1302 gfx::Point drag_to_location3(panel3->GetBounds().x() - 10, |
| 1303 panel3->GetBounds().y()); |
| 1304 DragPanelToMouseLocation(panel1, drag_to_location3); |
| 1305 ASSERT_EQ(0, detached_strip->num_panels()); |
| 1306 ASSERT_EQ(7, docked_strip->num_panels()); |
| 1307 EXPECT_EQ(PanelStrip::DOCKED, panel1->panel_strip()->type()); |
| 1308 EXPECT_EQ(PanelStrip::DOCKED, panel2->panel_strip()->type()); |
| 1309 EXPECT_EQ(PanelStrip::DOCKED, panel3->panel_strip()->type()); |
| 1310 EXPECT_EQ(PanelStrip::DOCKED, panel4->panel_strip()->type()); |
| 1311 EXPECT_EQ(PanelStrip::DOCKED, panel5->panel_strip()->type()); |
| 1312 EXPECT_EQ(PanelStrip::DOCKED, panel6->panel_strip()->type()); |
| 1313 EXPECT_EQ(PanelStrip::DOCKED, panel7->panel_strip()->type()); |
| 1314 |
| 1315 panel_manager->CloseAll(); |
| 1316 } |
| 1317 |
| 1318 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragDetachedPanelToTop) { |
| 1319 // Setup the test areas to have top-aligned bar excluded from work area. |
| 1320 const gfx::Rect primary_screen_area(0, 0, 800, 600); |
| 1321 const gfx::Rect work_area(0, 10, 800, 590); |
| 1322 SetTestingAreas(primary_screen_area, work_area); |
| 1323 |
| 1324 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 1325 Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200)); |
| 1326 |
| 1327 // Drag up the panel. Expect that the panel should not go outside the top of |
| 1328 // the work area. |
| 1329 gfx::Point drag_to_location(250, 0); |
| 1330 DragPanelToMouseLocation(panel, drag_to_location); |
| 1331 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 1332 EXPECT_EQ(drag_to_location.x(), panel->GetBounds().origin().x()); |
| 1333 EXPECT_EQ(work_area.y(), panel->GetBounds().origin().y()); |
| 1334 |
| 1335 // Drag down the panel. Expect that the panel can be dragged without |
| 1336 // constraint. |
| 1337 drag_to_location = gfx::Point(280, 150); |
| 1338 DragPanelToMouseLocation(panel, drag_to_location); |
| 1339 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 1340 EXPECT_EQ(drag_to_location, panel->GetBounds().origin()); |
| 1341 |
| 1342 panel_manager->CloseAll(); |
| 1343 } |
OLD | NEW |