OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "chrome/browser/ui/panels/base_panel_browser_test.h" | 6 #include "chrome/browser/ui/panels/base_panel_browser_test.h" |
7 #include "chrome/browser/ui/panels/detached_panel_strip.h" | 7 #include "chrome/browser/ui/panels/detached_panel_strip.h" |
8 #include "chrome/browser/ui/panels/docked_panel_strip.h" | 8 #include "chrome/browser/ui/panels/docked_panel_strip.h" |
9 #include "chrome/browser/ui/panels/native_panel.h" | 9 #include "chrome/browser/ui/panels/native_panel.h" |
10 #include "chrome/browser/ui/panels/panel.h" | 10 #include "chrome/browser/ui/panels/panel.h" |
11 #include "chrome/browser/ui/panels/panel_drag_controller.h" | 11 #include "chrome/browser/ui/panels/panel_drag_controller.h" |
12 #include "chrome/browser/ui/panels/panel_manager.h" | 12 #include "chrome/browser/ui/panels/panel_manager.h" |
| 13 #include "chrome/browser/ui/panels/test_panel_mouse_watcher.h" |
13 | 14 |
14 class PanelDragBrowserTest : public BasePanelBrowserTest { | 15 class PanelDragBrowserTest : public BasePanelBrowserTest { |
15 public: | 16 public: |
16 PanelDragBrowserTest() : BasePanelBrowserTest() { | 17 PanelDragBrowserTest() : BasePanelBrowserTest() { |
17 } | 18 } |
18 | 19 |
19 virtual ~PanelDragBrowserTest() { | 20 virtual ~PanelDragBrowserTest() { |
20 } | 21 } |
21 | 22 |
22 virtual void SetUpOnMainThread() OVERRIDE { | 23 virtual void SetUpOnMainThread() OVERRIDE { |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 EXPECT_EQ(mouse_location, panel3->GetBounds().origin()); | 394 EXPECT_EQ(mouse_location, panel3->GetBounds().origin()); |
394 | 395 |
395 panel3_testing->CancelDragTitlebar(); | 396 panel3_testing->CancelDragTitlebar(); |
396 EXPECT_EQ(position2, panel1->GetBounds().origin()); | 397 EXPECT_EQ(position2, panel1->GetBounds().origin()); |
397 EXPECT_EQ(position3, panel2->GetBounds().origin()); | 398 EXPECT_EQ(position3, panel2->GetBounds().origin()); |
398 EXPECT_EQ(position1, panel3->GetBounds().origin()); | 399 EXPECT_EQ(position1, panel3->GetBounds().origin()); |
399 | 400 |
400 PanelManager::GetInstance()->CloseAll(); | 401 PanelManager::GetInstance()->CloseAll(); |
401 } | 402 } |
402 | 403 |
| 404 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragMinimizedPanel) { |
| 405 // We'll simulate mouse movements for test. |
| 406 PanelMouseWatcher* mouse_watcher = new TestPanelMouseWatcher(); |
| 407 PanelManager::GetInstance()->SetMouseWatcherForTesting(mouse_watcher); |
| 408 |
| 409 Panel* panel = CreatePanel("panel1"); |
| 410 scoped_ptr<NativePanelTesting> panel_testing( |
| 411 NativePanelTesting::Create(panel->native_panel())); |
| 412 |
| 413 panel->Minimize(); |
| 414 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); |
| 415 |
| 416 // Hover over minimized panel to bring up titlebar. |
| 417 gfx::Point hover_point(panel->GetBounds().origin()); |
| 418 MoveMouseAndWaitForExpansionStateChange(panel, hover_point); |
| 419 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
| 420 |
| 421 // Verify we can drag a minimized panel. |
| 422 gfx::Rect panel_old_bounds = panel->GetBounds(); |
| 423 gfx::Point mouse_location = panel_old_bounds.origin(); |
| 424 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 425 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 426 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
| 427 |
| 428 mouse_location.Offset(-70, 0); |
| 429 panel_testing->DragTitlebar(mouse_location); |
| 430 gfx::Rect panel_new_bounds = panel_old_bounds; |
| 431 panel_new_bounds.Offset(-70, 0); |
| 432 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 433 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
| 434 |
| 435 // Verify panel returns to fully minimized state after dragging ends once |
| 436 // mouse moves away from panel. |
| 437 panel_testing->FinishDragTitlebar(); |
| 438 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
| 439 |
| 440 MoveMouseAndWaitForExpansionStateChange(panel, mouse_location); |
| 441 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); |
| 442 |
| 443 panel->Close(); |
| 444 } |
| 445 |
| 446 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, |
| 447 DragMinimizedPanelWhileDrawingAttention) { |
| 448 // We'll simulate mouse movements for test. |
| 449 PanelMouseWatcher* mouse_watcher = new TestPanelMouseWatcher(); |
| 450 PanelManager::GetInstance()->SetMouseWatcherForTesting(mouse_watcher); |
| 451 |
| 452 Panel* panel = CreatePanel("panel1"); |
| 453 scoped_ptr<NativePanelTesting> panel_testing( |
| 454 NativePanelTesting::Create(panel->native_panel())); |
| 455 CreatePanel("panel2"); |
| 456 |
| 457 panel->Minimize(); |
| 458 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); |
| 459 |
| 460 panel->FlashFrame(true); |
| 461 EXPECT_TRUE(panel->IsDrawingAttention()); |
| 462 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
| 463 |
| 464 // Drag the panel. Verify panel stays in title-only state after attention is |
| 465 // cleared because it is being dragged. |
| 466 gfx::Rect panel_old_bounds = panel->GetBounds(); |
| 467 gfx::Point mouse_location = panel_old_bounds.origin(); |
| 468 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); |
| 469 EXPECT_EQ(panel_old_bounds, panel->GetBounds()); |
| 470 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
| 471 |
| 472 mouse_location.Offset(-70, 0); |
| 473 panel_testing->DragTitlebar(mouse_location); |
| 474 gfx::Rect panel_new_bounds = panel_old_bounds; |
| 475 panel_new_bounds.Offset(-70, 0); |
| 476 EXPECT_EQ(panel_new_bounds, panel->GetBounds()); |
| 477 |
| 478 panel->FlashFrame(false); |
| 479 EXPECT_FALSE(panel->IsDrawingAttention()); |
| 480 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
| 481 |
| 482 // Verify panel returns to fully minimized state after dragging ends once |
| 483 // mouse moves away from the panel. |
| 484 panel_testing->FinishDragTitlebar(); |
| 485 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
| 486 |
| 487 mouse_location.Offset(0, -50); |
| 488 MoveMouseAndWaitForExpansionStateChange(panel, mouse_location); |
| 489 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); |
| 490 |
| 491 PanelManager::GetInstance()->CloseAll(); |
| 492 } |
| 493 |
403 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, CloseDockedPanelOnDrag) { | 494 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, CloseDockedPanelOnDrag) { |
404 PanelManager* panel_manager = PanelManager::GetInstance(); | 495 PanelManager* panel_manager = PanelManager::GetInstance(); |
405 PanelDragController* drag_controller = panel_manager->drag_controller(); | 496 PanelDragController* drag_controller = panel_manager->drag_controller(); |
406 DockedPanelStrip* docked_strip = panel_manager->docked_strip(); | 497 DockedPanelStrip* docked_strip = panel_manager->docked_strip(); |
407 | 498 |
408 // Create 4 docked panels. | 499 // Create 4 docked panels. |
409 // We have: P4 P3 P2 P1 | 500 // We have: P4 P3 P2 P1 |
410 Panel* panel1 = CreatePanelWithBounds("Panel1", gfx::Rect(0, 0, 100, 100)); | 501 Panel* panel1 = CreatePanelWithBounds("Panel1", gfx::Rect(0, 0, 100, 100)); |
411 Panel* panel2 = CreatePanelWithBounds("Panel2", gfx::Rect(0, 0, 100, 100)); | 502 Panel* panel2 = CreatePanelWithBounds("Panel2", gfx::Rect(0, 0, 100, 100)); |
412 Panel* panel3 = CreatePanelWithBounds("Panel3", gfx::Rect(0, 0, 100, 100)); | 503 Panel* panel3 = CreatePanelWithBounds("Panel3", gfx::Rect(0, 0, 100, 100)); |
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 EXPECT_EQ(PanelStrip::DOCKED, panel1->panel_strip()->type()); | 1306 EXPECT_EQ(PanelStrip::DOCKED, panel1->panel_strip()->type()); |
1216 EXPECT_EQ(PanelStrip::DOCKED, panel2->panel_strip()->type()); | 1307 EXPECT_EQ(PanelStrip::DOCKED, panel2->panel_strip()->type()); |
1217 EXPECT_EQ(PanelStrip::DOCKED, panel3->panel_strip()->type()); | 1308 EXPECT_EQ(PanelStrip::DOCKED, panel3->panel_strip()->type()); |
1218 EXPECT_EQ(PanelStrip::DOCKED, panel4->panel_strip()->type()); | 1309 EXPECT_EQ(PanelStrip::DOCKED, panel4->panel_strip()->type()); |
1219 EXPECT_EQ(PanelStrip::DOCKED, panel5->panel_strip()->type()); | 1310 EXPECT_EQ(PanelStrip::DOCKED, panel5->panel_strip()->type()); |
1220 EXPECT_EQ(PanelStrip::DOCKED, panel6->panel_strip()->type()); | 1311 EXPECT_EQ(PanelStrip::DOCKED, panel6->panel_strip()->type()); |
1221 EXPECT_EQ(PanelStrip::DOCKED, panel7->panel_strip()->type()); | 1312 EXPECT_EQ(PanelStrip::DOCKED, panel7->panel_strip()->type()); |
1222 | 1313 |
1223 panel_manager->CloseAll(); | 1314 panel_manager->CloseAll(); |
1224 } | 1315 } |
OLD | NEW |