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 "chrome/browser/ui/panels/base_panel_browser_test.h" |
| 6 #include "chrome/browser/ui/panels/detached_panel_strip.h" |
| 7 #include "chrome/browser/ui/panels/docked_panel_strip.h" |
| 8 #include "chrome/browser/ui/panels/overflow_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 |
| 14 class PanelDragBrowserTest : public BasePanelBrowserTest { |
| 15 public: |
| 16 PanelDragBrowserTest() : BasePanelBrowserTest() { |
| 17 } |
| 18 |
| 19 virtual ~PanelDragBrowserTest() { |
| 20 } |
| 21 |
| 22 virtual void SetUpOnMainThread() OVERRIDE { |
| 23 BasePanelBrowserTest::SetUpOnMainThread(); |
| 24 |
| 25 // All the tests here assume 800x600 work area. Do the check now. |
| 26 DCHECK(PanelManager::GetInstance()->work_area().width() == 800); |
| 27 DCHECK(PanelManager::GetInstance()->work_area().height() == 600); |
| 28 } |
| 29 |
| 30 Panel* CreateDockedPanel(const std::string& name, const gfx::Rect& bounds) { |
| 31 Panel* panel = CreatePanelWithBounds(name, bounds); |
| 32 EXPECT_EQ(PanelStrip::DOCKED, panel->panel_strip()->type()); |
| 33 return panel; |
| 34 } |
| 35 |
| 36 Panel* CreateDetachedPanel(const std::string& name, const gfx::Rect& bounds) { |
| 37 Panel* panel = CreatePanelWithBounds(name, bounds); |
| 38 panel->manager()->MovePanelToStrip(panel, PanelStrip::DETACHED); |
| 39 panel->SetPanelBounds(bounds); |
| 40 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 41 return panel; |
| 42 } |
| 43 |
| 44 Panel* CreateOverflowPanel(const std::string& name, const gfx::Rect& bounds) { |
| 45 CreatePanelParams params(name, bounds, SHOW_AS_INACTIVE); |
| 46 Panel* panel = CreatePanelWithParams(params); |
| 47 WaitForLayoutModeChanged(panel, PanelStrip::IN_OVERFLOW); |
| 48 return panel; |
| 49 } |
| 50 |
| 51 void DragPanelAndFinish(Panel* panel, const gfx::Point& delta) { |
| 52 scoped_ptr<NativePanelTesting> panel_testing( |
| 53 NativePanelTesting::Create(panel->native_panel())); |
| 54 gfx::Point mouse_location(panel->GetBounds().origin()); |
| 55 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 56 panel_testing->DragTitlebar(mouse_location.Add(delta)); |
| 57 panel_testing->FinishDragTitlebar(); |
| 58 } |
| 59 |
| 60 void DragPanelAndCancel(Panel* panel, const gfx::Point& delta) { |
| 61 scoped_ptr<NativePanelTesting> panel_testing( |
| 62 NativePanelTesting::Create(panel->native_panel())); |
| 63 gfx::Point mouse_location(panel->GetBounds().origin()); |
| 64 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 65 panel_testing->DragTitlebar(mouse_location.Add(delta)); |
| 66 panel_testing->CancelDragTitlebar(); |
| 67 } |
| 68 |
| 69 static gfx::Point GetDragDeltaToRemainDocked() { |
| 70 return gfx::Point( |
| 71 -5, |
| 72 -(PanelDragController::GetDetachDockedPanelThreshold() / 2)); |
| 73 } |
| 74 |
| 75 static gfx::Point GetDragDeltaToDetach() { |
| 76 return gfx::Point( |
| 77 -20, |
| 78 -(PanelDragController::GetDetachDockedPanelThreshold() + 20)); |
| 79 } |
| 80 |
| 81 static gfx::Point GetDragDeltaToRemainDetached(Panel* panel) { |
| 82 int distance = panel->manager()->docked_strip()->display_area().bottom() - |
| 83 panel->GetBounds().bottom(); |
| 84 return gfx::Point( |
| 85 -5, |
| 86 distance - PanelDragController::GetDockDetachedPanelThreshold() * 2); |
| 87 } |
| 88 |
| 89 static gfx::Point GetDragDeltaToAttach(Panel* panel) { |
| 90 int distance = panel->manager()->docked_strip()->display_area().bottom() - |
| 91 panel->GetBounds().bottom(); |
| 92 return gfx::Point( |
| 93 -20, |
| 94 distance - PanelDragController::GetDockDetachedPanelThreshold() / 2); |
| 95 } |
| 96 }; |
| 97 |
| 98 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, Detach) { |
| 99 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 100 DockedPanelStrip* docked_strip = panel_manager->docked_strip(); |
| 101 DetachedPanelStrip* detached_strip = panel_manager->detached_strip(); |
| 102 |
| 103 // Create one docked panel. |
| 104 Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100)); |
| 105 ASSERT_EQ(1, docked_strip->num_panels()); |
| 106 ASSERT_EQ(0, detached_strip->num_panels()); |
| 107 |
| 108 gfx::Rect panel_old_bounds = panel->GetBounds(); |
| 109 |
| 110 // Press on title-bar. |
| 111 scoped_ptr<NativePanelTesting> panel_testing( |
| 112 NativePanelTesting::Create(panel->native_panel())); |
| 113 gfx::Point mouse_location(panel->GetBounds().origin()); |
| 114 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 115 |
| 116 // Drag up the panel in a small offset that does not trigger the detach. |
| 117 // Expect that the panel is still docked and only x coordinate of its position |
| 118 // is changed. |
| 119 gfx::Point drag_delta_to_remain_docked = GetDragDeltaToRemainDocked(); |
| 120 mouse_location = mouse_location.Add(drag_delta_to_remain_docked); |
| 121 panel_testing->DragTitlebar(mouse_location); |
| 122 ASSERT_EQ(1, docked_strip->num_panels()); |
| 123 ASSERT_EQ(0, detached_strip->num_panels()); |
| 124 EXPECT_EQ(PanelStrip::DOCKED, panel->panel_strip()->type()); |
| 125 gfx::Rect panel_new_bounds = panel_old_bounds; |
| 126 panel_new_bounds.Offset(drag_delta_to_remain_docked.x(), 0); |
| 127 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 128 |
| 129 // Continue dragging up the panel in big offset that triggers the detach. |
| 130 // Expect that the panel is previewed as detached. |
| 131 gfx::Point drag_delta_to_detach = GetDragDeltaToDetach(); |
| 132 mouse_location = mouse_location.Add(drag_delta_to_detach); |
| 133 panel_testing->DragTitlebar(mouse_location); |
| 134 ASSERT_EQ(0, docked_strip->num_panels()); |
| 135 ASSERT_EQ(1, detached_strip->num_panels()); |
| 136 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 137 panel_new_bounds.Offset( |
| 138 drag_delta_to_detach.x(), |
| 139 drag_delta_to_detach.y() + drag_delta_to_remain_docked.y()); |
| 140 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 141 |
| 142 // Finish the drag. |
| 143 // Expect that the panel stays as detached. |
| 144 panel_testing->FinishDragTitlebar(); |
| 145 ASSERT_EQ(0, docked_strip->num_panels()); |
| 146 ASSERT_EQ(1, detached_strip->num_panels()); |
| 147 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 148 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 149 |
| 150 panel_manager->CloseAll(); |
| 151 } |
| 152 |
| 153 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DetachAndCancel) { |
| 154 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 155 DockedPanelStrip* docked_strip = panel_manager->docked_strip(); |
| 156 DetachedPanelStrip* detached_strip = panel_manager->detached_strip(); |
| 157 |
| 158 // Create one docked panel. |
| 159 Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100)); |
| 160 ASSERT_EQ(1, docked_strip->num_panels()); |
| 161 ASSERT_EQ(0, detached_strip->num_panels()); |
| 162 |
| 163 gfx::Rect panel_old_bounds = panel->GetBounds(); |
| 164 |
| 165 // Press on title-bar. |
| 166 scoped_ptr<NativePanelTesting> panel_testing( |
| 167 NativePanelTesting::Create(panel->native_panel())); |
| 168 gfx::Point mouse_location(panel->GetBounds().origin()); |
| 169 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 170 |
| 171 // Drag up the panel in a small offset that does not trigger the detach. |
| 172 // Expect that the panel is still docked and only x coordinate of its position |
| 173 // is changed. |
| 174 gfx::Point drag_delta_to_remain_docked = GetDragDeltaToRemainDocked(); |
| 175 mouse_location = mouse_location.Add(drag_delta_to_remain_docked); |
| 176 panel_testing->DragTitlebar(mouse_location); |
| 177 ASSERT_EQ(1, docked_strip->num_panels()); |
| 178 ASSERT_EQ(0, detached_strip->num_panels()); |
| 179 EXPECT_EQ(PanelStrip::DOCKED, panel->panel_strip()->type()); |
| 180 gfx::Rect panel_new_bounds = panel_old_bounds; |
| 181 panel_new_bounds.Offset(drag_delta_to_remain_docked.x(), 0); |
| 182 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 183 |
| 184 // Continue dragging up the panel in big offset that triggers the detach. |
| 185 // Expect that the panel is previewed as detached. |
| 186 gfx::Point drag_delta_to_detach = GetDragDeltaToDetach(); |
| 187 mouse_location = mouse_location.Add(drag_delta_to_detach); |
| 188 panel_testing->DragTitlebar(mouse_location); |
| 189 ASSERT_EQ(0, docked_strip->num_panels()); |
| 190 ASSERT_EQ(1, detached_strip->num_panels()); |
| 191 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 192 panel_new_bounds.Offset( |
| 193 drag_delta_to_detach.x(), |
| 194 drag_delta_to_detach.y() + drag_delta_to_remain_docked.y()); |
| 195 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 196 |
| 197 // Cancel the drag. |
| 198 // Expect that the panel is back as docked. |
| 199 panel_testing->CancelDragTitlebar(); |
| 200 ASSERT_EQ(1, docked_strip->num_panels()); |
| 201 ASSERT_EQ(0, detached_strip->num_panels()); |
| 202 EXPECT_EQ(PanelStrip::DOCKED, panel->panel_strip()->type()); |
| 203 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 204 |
| 205 panel_manager->CloseAll(); |
| 206 } |
| 207 |
| 208 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, Attach) { |
| 209 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 210 DockedPanelStrip* docked_strip = panel_manager->docked_strip(); |
| 211 DetachedPanelStrip* detached_strip = panel_manager->detached_strip(); |
| 212 |
| 213 // Create one detached panel. |
| 214 Panel* panel = CreateDetachedPanel("1", gfx::Rect(400, 300, 100, 100)); |
| 215 ASSERT_EQ(0, docked_strip->num_panels()); |
| 216 ASSERT_EQ(1, detached_strip->num_panels()); |
| 217 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 218 |
| 219 gfx::Rect panel_old_bounds = panel->GetBounds(); |
| 220 |
| 221 // Press on title-bar. |
| 222 scoped_ptr<NativePanelTesting> panel_testing( |
| 223 NativePanelTesting::Create(panel->native_panel())); |
| 224 gfx::Point mouse_location(panel->GetBounds().origin()); |
| 225 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 226 |
| 227 // Drag down the panel but not close enough to the bottom of work area. |
| 228 // Expect that the panel is still detached. |
| 229 gfx::Point drag_delta_to_remain_detached = |
| 230 GetDragDeltaToRemainDetached(panel); |
| 231 mouse_location = mouse_location.Add(drag_delta_to_remain_detached); |
| 232 panel_testing->DragTitlebar(mouse_location); |
| 233 ASSERT_EQ(0, docked_strip->num_panels()); |
| 234 ASSERT_EQ(1, detached_strip->num_panels()); |
| 235 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 236 gfx::Rect panel_new_bounds = panel_old_bounds; |
| 237 panel_new_bounds.Offset(drag_delta_to_remain_detached); |
| 238 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 239 |
| 240 // Continue dragging down the panel to make it close enough to the bottom of |
| 241 // work area. |
| 242 // Expect that the panel is previewed as docked. |
| 243 gfx::Point drag_delta_to_attach = GetDragDeltaToAttach(panel); |
| 244 mouse_location = mouse_location.Add(drag_delta_to_attach); |
| 245 panel_testing->DragTitlebar(mouse_location); |
| 246 ASSERT_EQ(1, docked_strip->num_panels()); |
| 247 ASSERT_EQ(0, detached_strip->num_panels()); |
| 248 EXPECT_EQ(PanelStrip::DOCKED, panel->panel_strip()->type()); |
| 249 panel_new_bounds.Offset(drag_delta_to_attach); |
| 250 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 251 |
| 252 // Finish the drag. |
| 253 // Expect that the panel stays as docked and moves to the final position. |
| 254 panel_testing->FinishDragTitlebar(); |
| 255 ASSERT_EQ(1, docked_strip->num_panels()); |
| 256 ASSERT_EQ(0, detached_strip->num_panels()); |
| 257 EXPECT_EQ(PanelStrip::DOCKED, panel->panel_strip()->type()); |
| 258 panel_new_bounds.set_x( |
| 259 docked_strip->StartingRightPosition() - panel_new_bounds.width()); |
| 260 panel_new_bounds.set_y( |
| 261 docked_strip->display_area().bottom() - panel_new_bounds.height()); |
| 262 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 263 |
| 264 panel_manager->CloseAll(); |
| 265 } |
| 266 |
| 267 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, AttachAndCancel) { |
| 268 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 269 DockedPanelStrip* docked_strip = panel_manager->docked_strip(); |
| 270 DetachedPanelStrip* detached_strip = panel_manager->detached_strip(); |
| 271 |
| 272 // Create one detached panel. |
| 273 Panel* panel = CreateDetachedPanel("1", gfx::Rect(400, 300, 100, 100)); |
| 274 ASSERT_EQ(0, docked_strip->num_panels()); |
| 275 ASSERT_EQ(1, detached_strip->num_panels()); |
| 276 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 277 |
| 278 gfx::Rect panel_old_bounds = panel->GetBounds(); |
| 279 |
| 280 // Press on title-bar. |
| 281 scoped_ptr<NativePanelTesting> panel_testing( |
| 282 NativePanelTesting::Create(panel->native_panel())); |
| 283 gfx::Point mouse_location(panel->GetBounds().origin()); |
| 284 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 285 |
| 286 // Drag down the panel but not close enough to the bottom of work area. |
| 287 // Expect that the panel is still detached. |
| 288 gfx::Point drag_delta_to_remain_detached = |
| 289 GetDragDeltaToRemainDetached(panel); |
| 290 mouse_location = mouse_location.Add(drag_delta_to_remain_detached); |
| 291 panel_testing->DragTitlebar(mouse_location); |
| 292 ASSERT_EQ(0, docked_strip->num_panels()); |
| 293 ASSERT_EQ(1, detached_strip->num_panels()); |
| 294 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 295 gfx::Rect panel_new_bounds = panel_old_bounds; |
| 296 panel_new_bounds.Offset(drag_delta_to_remain_detached); |
| 297 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 298 |
| 299 // Continue dragging down the panel to make it close enough to the bottom of |
| 300 // work area. |
| 301 // Expect that the panel is previewed as docked. |
| 302 gfx::Point drag_delta_to_attach = GetDragDeltaToAttach(panel); |
| 303 mouse_location = mouse_location.Add(drag_delta_to_attach); |
| 304 panel_testing->DragTitlebar(mouse_location); |
| 305 ASSERT_EQ(1, docked_strip->num_panels()); |
| 306 ASSERT_EQ(0, detached_strip->num_panels()); |
| 307 EXPECT_EQ(PanelStrip::DOCKED, panel->panel_strip()->type()); |
| 308 panel_new_bounds.Offset(drag_delta_to_attach); |
| 309 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 310 |
| 311 // Cancel the drag. |
| 312 // Expect that the panel is back as detached. |
| 313 panel_testing->CancelDragTitlebar(); |
| 314 ASSERT_EQ(0, docked_strip->num_panels()); |
| 315 ASSERT_EQ(1, detached_strip->num_panels()); |
| 316 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 317 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 318 |
| 319 panel_manager->CloseAll(); |
| 320 } |
| 321 |
| 322 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DetachAttachAndCancel) { |
| 323 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 324 DockedPanelStrip* docked_strip = panel_manager->docked_strip(); |
| 325 DetachedPanelStrip* detached_strip = panel_manager->detached_strip(); |
| 326 |
| 327 // Create one docked panel. |
| 328 Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100)); |
| 329 ASSERT_EQ(1, docked_strip->num_panels()); |
| 330 ASSERT_EQ(0, detached_strip->num_panels()); |
| 331 |
| 332 gfx::Rect panel_old_bounds = panel->GetBounds(); |
| 333 |
| 334 // Press on title-bar. |
| 335 scoped_ptr<NativePanelTesting> panel_testing( |
| 336 NativePanelTesting::Create(panel->native_panel())); |
| 337 gfx::Point mouse_location(panel->GetBounds().origin()); |
| 338 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 339 |
| 340 // Drag up the panel to trigger the detach. |
| 341 // Expect that the panel is previewed as detached. |
| 342 gfx::Point drag_delta_to_detach = GetDragDeltaToDetach(); |
| 343 mouse_location = mouse_location.Add(drag_delta_to_detach); |
| 344 panel_testing->DragTitlebar(mouse_location); |
| 345 ASSERT_EQ(0, docked_strip->num_panels()); |
| 346 ASSERT_EQ(1, detached_strip->num_panels()); |
| 347 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 348 gfx::Rect panel_new_bounds = panel_old_bounds; |
| 349 panel_new_bounds.Offset(drag_delta_to_detach); |
| 350 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 351 |
| 352 // Continue dragging down the panel to trigger the re-attach. |
| 353 gfx::Point drag_delta_to_reattach = GetDragDeltaToAttach(panel); |
| 354 mouse_location = mouse_location.Add(drag_delta_to_reattach); |
| 355 panel_testing->DragTitlebar(mouse_location); |
| 356 ASSERT_EQ(1, docked_strip->num_panels()); |
| 357 ASSERT_EQ(0, detached_strip->num_panels()); |
| 358 EXPECT_EQ(PanelStrip::DOCKED, panel->panel_strip()->type()); |
| 359 panel_new_bounds.Offset(drag_delta_to_reattach); |
| 360 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 361 |
| 362 // Continue dragging up the panel to trigger the detach again. |
| 363 gfx::Point drag_delta_to_detach_again = GetDragDeltaToDetach(); |
| 364 mouse_location = mouse_location.Add(drag_delta_to_detach_again); |
| 365 panel_testing->DragTitlebar(mouse_location); |
| 366 ASSERT_EQ(0, docked_strip->num_panels()); |
| 367 ASSERT_EQ(1, detached_strip->num_panels()); |
| 368 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); |
| 369 panel_new_bounds.Offset(drag_delta_to_detach_again); |
| 370 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 371 |
| 372 // Cancel the drag. |
| 373 // Expect that the panel stays as docked. |
| 374 panel_testing->CancelDragTitlebar(); |
| 375 ASSERT_EQ(1, docked_strip->num_panels()); |
| 376 ASSERT_EQ(0, detached_strip->num_panels()); |
| 377 EXPECT_EQ(PanelStrip::DOCKED, panel->panel_strip()->type()); |
| 378 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 379 |
| 380 panel_manager->CloseAll(); |
| 381 } |
| 382 |
| 383 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DetachWithOverflow) { |
| 384 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 385 DockedPanelStrip* docked_strip = panel_manager->docked_strip(); |
| 386 DetachedPanelStrip* detached_strip = panel_manager->detached_strip(); |
| 387 OverflowPanelStrip* overflow_strip = panel_manager->overflow_strip(); |
| 388 |
| 389 gfx::Point drag_delta_to_detach = GetDragDeltaToDetach(); |
| 390 |
| 391 // Create some docked and overflow panels. |
| 392 // docked: P3 P2 P1 |
| 393 // overflow: P5 P4 |
| 394 Panel* panel1 = CreateDockedPanel("1", gfx::Rect(0, 0, 200, 100)); |
| 395 Panel* panel2 = CreateDockedPanel("2", gfx::Rect(0, 0, 200, 100)); |
| 396 Panel* panel3 = CreateDockedPanel("3", gfx::Rect(0, 0, 200, 100)); |
| 397 Panel* panel4 = CreateOverflowPanel("4", gfx::Rect(0, 0, 200, 100)); |
| 398 Panel* panel5 = CreateOverflowPanel("5", gfx::Rect(0, 0, 200, 100)); |
| 399 ASSERT_EQ(0, detached_strip->num_panels()); |
| 400 ASSERT_EQ(3, docked_strip->num_panels()); |
| 401 ASSERT_EQ(2, overflow_strip->num_panels()); |
| 402 |
| 403 gfx::Point docked_position1 = panel1->GetBounds().origin(); |
| 404 gfx::Point docked_position2 = panel2->GetBounds().origin(); |
| 405 gfx::Point docked_position3 = panel3->GetBounds().origin(); |
| 406 |
| 407 // Drag to detach the middle docked panel. |
| 408 // Expect to have: |
| 409 // detached: P2 |
| 410 // docked: P4 P3 P1 |
| 411 // overflow: P5 |
| 412 DragPanelAndFinish(panel2, drag_delta_to_detach); |
| 413 ASSERT_EQ(1, detached_strip->num_panels()); |
| 414 ASSERT_EQ(3, docked_strip->num_panels()); |
| 415 ASSERT_EQ(1, overflow_strip->num_panels()); |
| 416 EXPECT_EQ(PanelStrip::DOCKED, panel1->panel_strip()->type()); |
| 417 EXPECT_EQ(PanelStrip::DETACHED, panel2->panel_strip()->type()); |
| 418 EXPECT_EQ(PanelStrip::DOCKED, panel3->panel_strip()->type()); |
| 419 EXPECT_EQ(PanelStrip::DOCKED, panel4->panel_strip()->type()); |
| 420 EXPECT_EQ(PanelStrip::IN_OVERFLOW, panel5->panel_strip()->type()); |
| 421 EXPECT_EQ(docked_position1, panel1->GetBounds().origin()); |
| 422 gfx::Point panel2_new_position = docked_position2.Add(drag_delta_to_detach); |
| 423 EXPECT_EQ(panel2_new_position, panel2->GetBounds().origin()); |
| 424 EXPECT_EQ(docked_position2, panel3->GetBounds().origin()); |
| 425 EXPECT_EQ(docked_position3, panel4->GetBounds().origin()); |
| 426 |
| 427 // Drag to detach the left-most docked panel. |
| 428 // Expect to have: |
| 429 // detached: P2 P4 |
| 430 // docked: P5 P3 P1 |
| 431 DragPanelAndFinish(panel4, drag_delta_to_detach); |
| 432 ASSERT_EQ(2, detached_strip->num_panels()); |
| 433 ASSERT_EQ(3, docked_strip->num_panels()); |
| 434 ASSERT_EQ(0, overflow_strip->num_panels()); |
| 435 EXPECT_EQ(PanelStrip::DOCKED, panel1->panel_strip()->type()); |
| 436 EXPECT_EQ(PanelStrip::DETACHED, panel2->panel_strip()->type()); |
| 437 EXPECT_EQ(PanelStrip::DOCKED, panel3->panel_strip()->type()); |
| 438 EXPECT_EQ(PanelStrip::DETACHED, panel4->panel_strip()->type()); |
| 439 EXPECT_EQ(PanelStrip::DOCKED, panel5->panel_strip()->type()); |
| 440 EXPECT_EQ(docked_position1, panel1->GetBounds().origin()); |
| 441 EXPECT_EQ(panel2_new_position, panel2->GetBounds().origin()); |
| 442 EXPECT_EQ(docked_position2, panel3->GetBounds().origin()); |
| 443 gfx::Point panel4_new_position = docked_position3.Add(drag_delta_to_detach); |
| 444 EXPECT_EQ(panel4_new_position, panel4->GetBounds().origin()); |
| 445 EXPECT_EQ(docked_position3, panel5->GetBounds().origin()); |
| 446 |
| 447 // Drag to detach the right-most docked panel. |
| 448 // Expect to have: |
| 449 // detached: P1 P2 P4 |
| 450 // docked: P5 P3 |
| 451 DragPanelAndFinish(panel1, drag_delta_to_detach); |
| 452 ASSERT_EQ(3, detached_strip->num_panels()); |
| 453 ASSERT_EQ(2, docked_strip->num_panels()); |
| 454 ASSERT_EQ(0, overflow_strip->num_panels()); |
| 455 EXPECT_EQ(PanelStrip::DETACHED, panel1->panel_strip()->type()); |
| 456 EXPECT_EQ(PanelStrip::DETACHED, panel2->panel_strip()->type()); |
| 457 EXPECT_EQ(PanelStrip::DOCKED, panel3->panel_strip()->type()); |
| 458 EXPECT_EQ(PanelStrip::DETACHED, panel4->panel_strip()->type()); |
| 459 EXPECT_EQ(PanelStrip::DOCKED, panel5->panel_strip()->type()); |
| 460 gfx::Point panel1_new_position = docked_position1.Add(drag_delta_to_detach); |
| 461 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); |
| 462 EXPECT_EQ(panel2_new_position, panel2->GetBounds().origin()); |
| 463 EXPECT_EQ(docked_position1, panel3->GetBounds().origin()); |
| 464 EXPECT_EQ(panel4_new_position, panel4->GetBounds().origin()); |
| 465 EXPECT_EQ(docked_position2, panel5->GetBounds().origin()); |
| 466 |
| 467 panel_manager->CloseAll(); |
| 468 } |
| 469 |
| 470 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, AttachWithOverflow) { |
| 471 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 472 DockedPanelStrip* docked_strip = panel_manager->docked_strip(); |
| 473 DetachedPanelStrip* detached_strip = panel_manager->detached_strip(); |
| 474 OverflowPanelStrip* overflow_strip = panel_manager->overflow_strip(); |
| 475 |
| 476 gfx::Point drag_delta_to_detach = GetDragDeltaToDetach(); |
| 477 |
| 478 // Create some detached, docked and overflow panels. |
| 479 // detached: P1 P2 P3 |
| 480 // docked: P6 P5 P4 |
| 481 // overflow: P7 |
| 482 Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(100, 300, 200, 100)); |
| 483 Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(200, 300, 200, 100)); |
| 484 Panel* panel3 = CreateDetachedPanel("3", gfx::Rect(400, 300, 200, 100)); |
| 485 Panel* panel4 = CreateDockedPanel("4", gfx::Rect(0, 0, 200, 100)); |
| 486 Panel* panel5 = CreateDockedPanel("5", gfx::Rect(0, 0, 200, 100)); |
| 487 Panel* panel6 = CreateDockedPanel("6", gfx::Rect(0, 0, 200, 100)); |
| 488 Panel* panel7 = CreateOverflowPanel("7", gfx::Rect(0, 0, 200, 100)); |
| 489 ASSERT_EQ(3, detached_strip->num_panels()); |
| 490 ASSERT_EQ(3, docked_strip->num_panels()); |
| 491 ASSERT_EQ(1, overflow_strip->num_panels()); |
| 492 |
| 493 gfx::Point detached_position1 = panel1->GetBounds().origin(); |
| 494 gfx::Point detached_position2 = panel2->GetBounds().origin(); |
| 495 gfx::Point detached_position3 = panel3->GetBounds().origin(); |
| 496 gfx::Point docked_position1 = panel4->GetBounds().origin(); |
| 497 gfx::Point docked_position2 = panel5->GetBounds().origin(); |
| 498 gfx::Point docked_position3 = panel6->GetBounds().origin(); |
| 499 |
| 500 // Drag to attach a detached panel between 2 docked panels. |
| 501 // Expect to have: |
| 502 // detached: P1 P2 |
| 503 // docked: P5 P3 P4 |
| 504 // overflow: P7 P6 |
| 505 gfx::Point drag_delta_to_attach( |
| 506 docked_position2.x() - detached_position3.x() + 10, 210); |
| 507 DragPanelAndFinish(panel3, drag_delta_to_attach); |
| 508 ASSERT_EQ(2, detached_strip->num_panels()); |
| 509 ASSERT_EQ(3, docked_strip->num_panels()); |
| 510 ASSERT_EQ(2, overflow_strip->num_panels()); |
| 511 EXPECT_EQ(PanelStrip::DETACHED, panel1->panel_strip()->type()); |
| 512 EXPECT_EQ(PanelStrip::DETACHED, panel2->panel_strip()->type()); |
| 513 EXPECT_EQ(PanelStrip::DOCKED, panel3->panel_strip()->type()); |
| 514 EXPECT_EQ(PanelStrip::DOCKED, panel4->panel_strip()->type()); |
| 515 EXPECT_EQ(PanelStrip::DOCKED, panel5->panel_strip()->type()); |
| 516 EXPECT_EQ(PanelStrip::IN_OVERFLOW, panel6->panel_strip()->type()); |
| 517 EXPECT_EQ(PanelStrip::IN_OVERFLOW, panel7->panel_strip()->type()); |
| 518 EXPECT_EQ(detached_position1, panel1->GetBounds().origin()); |
| 519 EXPECT_EQ(detached_position2, panel2->GetBounds().origin()); |
| 520 EXPECT_EQ(docked_position2, panel3->GetBounds().origin()); |
| 521 EXPECT_EQ(docked_position1, panel4->GetBounds().origin()); |
| 522 EXPECT_EQ(docked_position3, panel5->GetBounds().origin()); |
| 523 |
| 524 // Drag to attach a detached panel to most-right. |
| 525 // Expect to have: |
| 526 // detached: P1 |
| 527 // docked: P3 P4 P2 |
| 528 // overflow: P7 P6 P5 |
| 529 gfx::Point drag_delta_to_attach2( |
| 530 docked_position1.x() - detached_position2.x() + 10, 210); |
| 531 DragPanelAndFinish(panel2, drag_delta_to_attach2); |
| 532 ASSERT_EQ(1, detached_strip->num_panels()); |
| 533 ASSERT_EQ(3, docked_strip->num_panels()); |
| 534 ASSERT_EQ(3, overflow_strip->num_panels()); |
| 535 EXPECT_EQ(PanelStrip::DETACHED, panel1->panel_strip()->type()); |
| 536 EXPECT_EQ(PanelStrip::DOCKED, panel2->panel_strip()->type()); |
| 537 EXPECT_EQ(PanelStrip::DOCKED, panel3->panel_strip()->type()); |
| 538 EXPECT_EQ(PanelStrip::DOCKED, panel4->panel_strip()->type()); |
| 539 EXPECT_EQ(PanelStrip::IN_OVERFLOW, panel5->panel_strip()->type()); |
| 540 EXPECT_EQ(PanelStrip::IN_OVERFLOW, panel6->panel_strip()->type()); |
| 541 EXPECT_EQ(PanelStrip::IN_OVERFLOW, panel7->panel_strip()->type()); |
| 542 EXPECT_EQ(detached_position1, panel1->GetBounds().origin()); |
| 543 EXPECT_EQ(docked_position1, panel2->GetBounds().origin()); |
| 544 EXPECT_EQ(docked_position3, panel3->GetBounds().origin()); |
| 545 EXPECT_EQ(docked_position2, panel4->GetBounds().origin()); |
| 546 |
| 547 // Drag to attach a detached panel to most-left. |
| 548 // Expect to have: |
| 549 // docked: P1 P4 P2 |
| 550 // overflow: P7 P6 P5 P3 |
| 551 gfx::Point drag_delta_to_attach3( |
| 552 docked_position3.x() - detached_position1.x() - 50, 210); |
| 553 DragPanelAndFinish(panel1, drag_delta_to_attach3); |
| 554 ASSERT_EQ(0, detached_strip->num_panels()); |
| 555 ASSERT_EQ(3, docked_strip->num_panels()); |
| 556 ASSERT_EQ(4, overflow_strip->num_panels()); |
| 557 EXPECT_EQ(PanelStrip::DOCKED, panel1->panel_strip()->type()); |
| 558 EXPECT_EQ(PanelStrip::DOCKED, panel2->panel_strip()->type()); |
| 559 EXPECT_EQ(PanelStrip::IN_OVERFLOW, panel3->panel_strip()->type()); |
| 560 EXPECT_EQ(PanelStrip::DOCKED, panel4->panel_strip()->type()); |
| 561 EXPECT_EQ(PanelStrip::IN_OVERFLOW, panel5->panel_strip()->type()); |
| 562 EXPECT_EQ(PanelStrip::IN_OVERFLOW, panel6->panel_strip()->type()); |
| 563 EXPECT_EQ(PanelStrip::IN_OVERFLOW, panel7->panel_strip()->type()); |
| 564 EXPECT_EQ(docked_position3, panel1->GetBounds().origin()); |
| 565 EXPECT_EQ(docked_position1, panel2->GetBounds().origin()); |
| 566 EXPECT_EQ(docked_position2, panel4->GetBounds().origin()); |
| 567 |
| 568 panel_manager->CloseAll(); |
| 569 } |
OLD | NEW |