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