This source file includes following definitions.
- SetUpOnMainThread
- DragPanelByDelta
- DragPanelToMouseLocation
- GetStackedAtBottomPanelBounds
- GetStackedAtTopPanelBounds
- GetDragDeltaToRemainDocked
- GetDragDeltaToDetach
- GetDragDeltaToRemainDetached
- GetDragDeltaToAttach
- GetDragDeltaToStackToBottom
- GetDragDeltaToUnstackFromBottom
- GetDragDeltaToStackToTop
- GetDragDeltaToUnstackFromTop
- GetDragDeltaToSnapToLeft
- GetDragDeltaToSnapToRight
- GetDragDeltaToUnsnap
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/message_loop/message_loop.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/ui/panels/base_panel_browser_test.h"
#include "chrome/browser/ui/panels/detached_panel_collection.h"
#include "chrome/browser/ui/panels/docked_panel_collection.h"
#include "chrome/browser/ui/panels/native_panel.h"
#include "chrome/browser/ui/panels/panel.h"
#include "chrome/browser/ui/panels/panel_drag_controller.h"
#include "chrome/browser/ui/panels/panel_manager.h"
#include "chrome/browser/ui/panels/stacked_panel_collection.h"
#include "chrome/browser/ui/panels/test_panel_collection_squeeze_observer.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/test_utils.h"
class PanelDragBrowserTest : public BasePanelBrowserTest {
public:
PanelDragBrowserTest() : BasePanelBrowserTest() {
}
virtual ~PanelDragBrowserTest() {
}
virtual void SetUpOnMainThread() OVERRIDE {
BasePanelBrowserTest::SetUpOnMainThread();
gfx::Rect primary_display_area = PanelManager::GetInstance()->
display_settings_provider()->GetPrimaryDisplayArea();
DCHECK(primary_display_area.width() == 800);
DCHECK(primary_display_area.height() == 600);
}
void DragPanelByDelta(Panel* panel, const gfx::Vector2d& delta) {
scoped_ptr<NativePanelTesting> panel_testing(
CreateNativePanelTesting(panel));
gfx::Point mouse_location(panel->GetBounds().origin());
panel_testing->PressLeftMouseButtonTitlebar(mouse_location);
panel_testing->DragTitlebar(mouse_location + delta);
panel_testing->FinishDragTitlebar();
}
void DragPanelToMouseLocation(Panel* panel,
const gfx::Point& new_mouse_location) {
scoped_ptr<NativePanelTesting> panel_testing(
CreateNativePanelTesting(panel));
gfx::Point mouse_location(panel->GetBounds().origin());
panel_testing->PressLeftMouseButtonTitlebar(panel->GetBounds().origin());
panel_testing->DragTitlebar(new_mouse_location);
panel_testing->FinishDragTitlebar();
}
static gfx::Rect GetStackedAtBottomPanelBounds(
const gfx::Rect& initial_bounds,
const gfx::Rect& above_bounds) {
return gfx::Rect(above_bounds.x(),
above_bounds.bottom(),
above_bounds.width(),
initial_bounds.height());
}
static gfx::Rect GetStackedAtTopPanelBounds(
const gfx::Rect& initial_bounds,
const gfx::Rect& below_bounds) {
return gfx::Rect(below_bounds.x(),
below_bounds.y() - initial_bounds.height(),
initial_bounds.width(),
initial_bounds.height());
}
static gfx::Vector2d GetDragDeltaToRemainDocked() {
return gfx::Vector2d(
-5,
-(PanelDragController::GetDetachDockedPanelThresholdForTesting() / 2));
}
static gfx::Vector2d GetDragDeltaToDetach() {
return gfx::Vector2d(
-20,
-(PanelDragController::GetDetachDockedPanelThresholdForTesting() + 20));
}
static gfx::Vector2d GetDragDeltaToRemainDetached(Panel* panel) {
int distance =
panel->manager()->docked_collection()->work_area().bottom() -
panel->GetBounds().bottom();
return gfx::Vector2d(
-5,
distance -
PanelDragController::GetDockDetachedPanelThresholdForTesting() * 2);
}
static gfx::Vector2d GetDragDeltaToAttach(Panel* panel) {
int distance =
panel->manager()->docked_collection()->work_area().bottom() -
panel->GetBounds().bottom();
return gfx::Vector2d(
-20,
distance -
PanelDragController::GetDockDetachedPanelThresholdForTesting() / 2);
}
static gfx::Vector2d GetDragDeltaToStackToBottom(Panel* panel1,
Panel* panel2) {
gfx::Rect bounds1 = panel1->GetBounds();
gfx::Rect bounds2 = panel2->GetBounds();
return gfx::Vector2d(
bounds2.x() - bounds1.x(),
bounds2.bottom() - bounds1.y() +
PanelDragController::GetGluePanelDistanceThresholdForTesting() / 2);
}
static gfx::Vector2d GetDragDeltaToUnstackFromBottom(Panel* panel1,
Panel* panel2) {
gfx::Rect bounds1 = panel1->GetBounds();
gfx::Rect bounds2 = panel2->GetBounds();
return gfx::Vector2d(
0, PanelDragController::GetGluePanelDistanceThresholdForTesting() * 2);
}
static gfx::Vector2d GetDragDeltaToStackToTop(Panel* panel1, Panel* panel2) {
gfx::Rect bounds1 = panel1->GetBounds();
gfx::Rect bounds2 = panel2->GetBounds();
StackedPanelCollection* stack1 = panel1->stack();
int bottom = stack1 ? stack1->bottom_panel()->GetBounds().bottom()
: bounds1.bottom();
return gfx::Vector2d(
bounds2.x() - bounds1.x(),
bounds2.y() - bottom -
PanelDragController::GetGluePanelDistanceThresholdForTesting() / 2);
}
static gfx::Vector2d GetDragDeltaToUnstackFromTop(Panel* panel1,
Panel* panel2) {
gfx::Rect bounds1 = panel1->GetBounds();
gfx::Rect bounds2 = panel2->GetBounds();
return gfx::Vector2d(
0, -PanelDragController::GetGluePanelDistanceThresholdForTesting() * 2);
}
static gfx::Vector2d GetDragDeltaToSnapToLeft(Panel* panel1,
Panel* panel2) {
gfx::Rect bounds1 = panel1->GetBounds();
gfx::Rect bounds2 = panel2->GetBounds();
return gfx::Vector2d(
bounds2.x() - bounds1.width() - bounds1.x() -
PanelDragController::GetGluePanelDistanceThresholdForTesting() / 2,
bounds2.y() - bounds1.y() +
PanelDragController::GetGluePanelDistanceThresholdForTesting() * 2);
}
static gfx::Vector2d GetDragDeltaToSnapToRight(Panel* panel1,
Panel* panel2) {
gfx::Rect bounds1 = panel1->GetBounds();
gfx::Rect bounds2 = panel2->GetBounds();
return gfx::Vector2d(
bounds2.right() - bounds1.x() +
PanelDragController::GetGluePanelDistanceThresholdForTesting() / 2,
bounds2.y() - bounds1.y() +
PanelDragController::GetGluePanelDistanceThresholdForTesting() * 2);
}
static gfx::Vector2d GetDragDeltaToUnsnap(Panel* panel) {
return gfx::Vector2d(
PanelDragController::GetGluePanelDistanceThresholdForTesting() * 2, 0);
}
};
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragOneDockedPanel) {
static const int big_delta_x = 70;
static const int big_delta_y = 30;
Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100));
scoped_ptr<NativePanelTesting> panel_testing(
CreateNativePanelTesting(panel));
gfx::Rect panel_old_bounds = panel->GetBounds();
gfx::Point mouse_location = panel_old_bounds.origin();
panel_testing->PressLeftMouseButtonTitlebar(mouse_location);
EXPECT_EQ(panel_old_bounds, panel->GetBounds());
mouse_location.Offset(-big_delta_x, 0);
panel_testing->DragTitlebar(mouse_location);
gfx::Rect panel_new_bounds = panel_old_bounds;
panel_new_bounds.Offset(-big_delta_x, 0);
EXPECT_EQ(panel_new_bounds, panel->GetBounds());
panel_testing->FinishDragTitlebar();
EXPECT_EQ(panel_old_bounds, panel->GetBounds());
mouse_location = panel_old_bounds.origin();
panel_testing->PressLeftMouseButtonTitlebar(mouse_location);
EXPECT_EQ(panel_old_bounds, panel->GetBounds());
mouse_location.Offset(-big_delta_x, 0);
panel_testing->DragTitlebar(mouse_location);
panel_new_bounds = panel_old_bounds;
panel_new_bounds.Offset(-big_delta_x, 0);
EXPECT_EQ(panel_new_bounds, panel->GetBounds());
panel_testing->CancelDragTitlebar();
EXPECT_EQ(panel_old_bounds, panel->GetBounds());
mouse_location = panel_old_bounds.origin();
panel_testing->PressLeftMouseButtonTitlebar(mouse_location);
EXPECT_EQ(panel_old_bounds, panel->GetBounds());
mouse_location.Offset(big_delta_x, 0);
panel_testing->DragTitlebar(mouse_location);
panel_new_bounds = panel_old_bounds;
panel_new_bounds.Offset(big_delta_x, 0);
EXPECT_EQ(panel_new_bounds, panel->GetBounds());
panel_testing->FinishDragTitlebar();
EXPECT_EQ(panel_old_bounds, panel->GetBounds());
mouse_location = panel_old_bounds.origin();
panel_testing->PressLeftMouseButtonTitlebar(mouse_location);
EXPECT_EQ(panel_old_bounds, panel->GetBounds());
mouse_location.Offset(big_delta_x, big_delta_y);
panel_testing->DragTitlebar(mouse_location);
panel_new_bounds = panel_old_bounds;
panel_new_bounds.Offset(big_delta_x, 0);
EXPECT_EQ(panel_new_bounds, panel->GetBounds());
panel_testing->FinishDragTitlebar();
EXPECT_EQ(panel_old_bounds, panel->GetBounds());
mouse_location = panel_old_bounds.origin();
panel_testing->PressLeftMouseButtonTitlebar(mouse_location);
EXPECT_EQ(panel_old_bounds, panel->GetBounds());
mouse_location.Offset(0, -big_delta_y);
panel_testing->DragTitlebar(mouse_location);
EXPECT_EQ(panel_old_bounds, panel->GetBounds());
panel_testing->FinishDragTitlebar();
EXPECT_EQ(panel_old_bounds, panel->GetBounds());
mouse_location = panel_old_bounds.origin();
panel_testing->PressLeftMouseButtonTitlebar(mouse_location);
EXPECT_EQ(panel_old_bounds, panel->GetBounds());
mouse_location.Offset(0, big_delta_y);
panel_testing->DragTitlebar(mouse_location);
EXPECT_EQ(panel_old_bounds, panel->GetBounds());
panel_testing->FinishDragTitlebar();
EXPECT_EQ(panel_old_bounds, panel->GetBounds());
PanelManager::GetInstance()->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragTwoDockedPanels) {
static const gfx::Vector2d small_delta(10, 0);
Panel* panel1 = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100));
Panel* panel2 = CreateDockedPanel("2", gfx::Rect(0, 0, 100, 100));
scoped_ptr<NativePanelTesting> panel1_testing(
CreateNativePanelTesting(panel1));
scoped_ptr<NativePanelTesting> panel2_testing(
CreateNativePanelTesting(panel2));
gfx::Point position1 = panel1->GetBounds().origin();
gfx::Point position2 = panel2->GetBounds().origin();
gfx::Point mouse_location = position1;
panel1_testing->PressLeftMouseButtonTitlebar(mouse_location);
EXPECT_EQ(position1, panel1->GetBounds().origin());
EXPECT_EQ(position2, panel2->GetBounds().origin());
mouse_location = mouse_location - small_delta;
panel1_testing->DragTitlebar(mouse_location);
EXPECT_EQ(mouse_location, panel1->GetBounds().origin());
EXPECT_EQ(position2, panel2->GetBounds().origin());
panel1_testing->FinishDragTitlebar();
EXPECT_EQ(position1, panel1->GetBounds().origin());
EXPECT_EQ(position2, panel2->GetBounds().origin());
mouse_location = position1;
panel1_testing->PressLeftMouseButtonTitlebar(mouse_location);
EXPECT_EQ(position1, panel1->GetBounds().origin());
EXPECT_EQ(position2, panel2->GetBounds().origin());
mouse_location = position2 + gfx::Vector2d(1, 0);
panel1_testing->DragTitlebar(mouse_location);
EXPECT_EQ(mouse_location, panel1->GetBounds().origin());
EXPECT_EQ(position1, panel2->GetBounds().origin());
panel1_testing->FinishDragTitlebar();
EXPECT_EQ(position2, panel1->GetBounds().origin());
EXPECT_EQ(position1, panel2->GetBounds().origin());
mouse_location = position2;
panel1_testing->PressLeftMouseButtonTitlebar(mouse_location);
EXPECT_EQ(position2, panel1->GetBounds().origin());
EXPECT_EQ(position1, panel2->GetBounds().origin());
mouse_location = mouse_location + small_delta;
panel1_testing->DragTitlebar(mouse_location);
EXPECT_EQ(mouse_location, panel1->GetBounds().origin());
EXPECT_EQ(position1, panel2->GetBounds().origin());
panel1_testing->FinishDragTitlebar();
EXPECT_EQ(position2, panel1->GetBounds().origin());
EXPECT_EQ(position1, panel2->GetBounds().origin());
mouse_location = position2;
panel1_testing->PressLeftMouseButtonTitlebar(mouse_location);
EXPECT_EQ(position2, panel1->GetBounds().origin());
EXPECT_EQ(position1, panel2->GetBounds().origin());
mouse_location = position1 + gfx::Vector2d(1, 0);
panel1_testing->DragTitlebar(mouse_location);
EXPECT_EQ(mouse_location, panel1->GetBounds().origin());
EXPECT_EQ(position2, panel2->GetBounds().origin());
panel1_testing->FinishDragTitlebar();
EXPECT_EQ(position1, panel1->GetBounds().origin());
EXPECT_EQ(position2, panel2->GetBounds().origin());
mouse_location = position1;
panel1_testing->PressLeftMouseButtonTitlebar(mouse_location);
EXPECT_EQ(position1, panel1->GetBounds().origin());
EXPECT_EQ(position2, panel2->GetBounds().origin());
mouse_location = position2 + gfx::Vector2d(1, 0);
panel1_testing->DragTitlebar(mouse_location);
EXPECT_EQ(mouse_location, panel1->GetBounds().origin());
EXPECT_EQ(position1, panel2->GetBounds().origin());
panel1_testing->CancelDragTitlebar();
EXPECT_EQ(position1, panel1->GetBounds().origin());
EXPECT_EQ(position2, panel2->GetBounds().origin());
PanelManager::GetInstance()->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragThreeDockedPanels) {
Panel* panel1 = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100));
Panel* panel2 = CreateDockedPanel("2", gfx::Rect(0, 0, 100, 100));
Panel* panel3 = CreateDockedPanel("3", gfx::Rect(0, 0, 100, 100));
scoped_ptr<NativePanelTesting> panel2_testing(
CreateNativePanelTesting(panel2));
scoped_ptr<NativePanelTesting> panel3_testing(
CreateNativePanelTesting(panel3));
gfx::Point position1 = panel1->GetBounds().origin();
gfx::Point position2 = panel2->GetBounds().origin();
gfx::Point position3 = panel3->GetBounds().origin();
gfx::Point mouse_location = position3;
panel3_testing->PressLeftMouseButtonTitlebar(mouse_location);
EXPECT_EQ(position1, panel1->GetBounds().origin());
EXPECT_EQ(position2, panel2->GetBounds().origin());
EXPECT_EQ(position3, panel3->GetBounds().origin());
mouse_location = position2 + gfx::Vector2d(1, 0);
panel3_testing->DragTitlebar(mouse_location);
EXPECT_EQ(position1, panel1->GetBounds().origin());
EXPECT_EQ(position3, panel2->GetBounds().origin());
EXPECT_EQ(mouse_location, panel3->GetBounds().origin());
mouse_location = position1 + gfx::Vector2d(1, 0);
panel3_testing->DragTitlebar(mouse_location);
EXPECT_EQ(position2, panel1->GetBounds().origin());
EXPECT_EQ(position3, panel2->GetBounds().origin());
EXPECT_EQ(mouse_location, panel3->GetBounds().origin());
panel3_testing->FinishDragTitlebar();
EXPECT_EQ(position2, panel1->GetBounds().origin());
EXPECT_EQ(position3, panel2->GetBounds().origin());
EXPECT_EQ(position1, panel3->GetBounds().origin());
mouse_location = position1;
panel3_testing->PressLeftMouseButtonTitlebar(mouse_location);
EXPECT_EQ(position2, panel1->GetBounds().origin());
EXPECT_EQ(position3, panel2->GetBounds().origin());
EXPECT_EQ(position1, panel3->GetBounds().origin());
mouse_location = position2 + gfx::Vector2d(1, 0);
panel3_testing->DragTitlebar(mouse_location);
EXPECT_EQ(position1, panel1->GetBounds().origin());
EXPECT_EQ(position3, panel2->GetBounds().origin());
EXPECT_EQ(mouse_location, panel3->GetBounds().origin());
mouse_location = position3 + gfx::Vector2d(1, 0);
panel3_testing->DragTitlebar(mouse_location);
EXPECT_EQ(position1, panel1->GetBounds().origin());
EXPECT_EQ(position2, panel2->GetBounds().origin());
EXPECT_EQ(mouse_location, panel3->GetBounds().origin());
panel3_testing->CancelDragTitlebar();
EXPECT_EQ(position2, panel1->GetBounds().origin());
EXPECT_EQ(position3, panel2->GetBounds().origin());
EXPECT_EQ(position1, panel3->GetBounds().origin());
mouse_location = position3;
panel2_testing->PressLeftMouseButtonTitlebar(mouse_location);
EXPECT_EQ(position2, panel1->GetBounds().origin());
EXPECT_EQ(position3, panel2->GetBounds().origin());
EXPECT_EQ(position1, panel3->GetBounds().origin());
mouse_location = position1 + gfx::Vector2d(1, 0);
panel2_testing->DragTitlebar(mouse_location);
EXPECT_EQ(position3, panel1->GetBounds().origin());
EXPECT_EQ(mouse_location, panel2->GetBounds().origin());
EXPECT_EQ(position2, panel3->GetBounds().origin());
panel2_testing->FinishDragTitlebar();
EXPECT_EQ(position3, panel1->GetBounds().origin());
EXPECT_EQ(position1, panel2->GetBounds().origin());
EXPECT_EQ(position2, panel3->GetBounds().origin());
mouse_location = position1;
panel2_testing->PressLeftMouseButtonTitlebar(mouse_location);
EXPECT_EQ(position3, panel1->GetBounds().origin());
EXPECT_EQ(position1, panel2->GetBounds().origin());
EXPECT_EQ(position2, panel3->GetBounds().origin());
mouse_location = position3 + gfx::Vector2d(1, 0);
panel2_testing->DragTitlebar(mouse_location);
EXPECT_EQ(position2, panel1->GetBounds().origin());
EXPECT_EQ(mouse_location, panel2->GetBounds().origin());
EXPECT_EQ(position1, panel3->GetBounds().origin());
panel2_testing->FinishDragTitlebar();
EXPECT_EQ(position2, panel1->GetBounds().origin());
EXPECT_EQ(position3, panel2->GetBounds().origin());
EXPECT_EQ(position1, panel3->GetBounds().origin());
mouse_location = position1;
panel3_testing->PressLeftMouseButtonTitlebar(mouse_location);
EXPECT_EQ(position2, panel1->GetBounds().origin());
EXPECT_EQ(position3, panel2->GetBounds().origin());
EXPECT_EQ(position1, panel3->GetBounds().origin());
mouse_location = position3 + gfx::Vector2d(1, 0);
panel3_testing->DragTitlebar(mouse_location);
EXPECT_EQ(position1, panel1->GetBounds().origin());
EXPECT_EQ(position2, panel2->GetBounds().origin());
EXPECT_EQ(mouse_location, panel3->GetBounds().origin());
panel3_testing->CancelDragTitlebar();
EXPECT_EQ(position2, panel1->GetBounds().origin());
EXPECT_EQ(position3, panel2->GetBounds().origin());
EXPECT_EQ(position1, panel3->GetBounds().origin());
PanelManager::GetInstance()->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragMinimizedPanel) {
Panel* panel = CreatePanel("panel1");
scoped_ptr<NativePanelTesting> panel_testing(
CreateNativePanelTesting(panel));
panel->Minimize();
EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
gfx::Point hover_point(panel->GetBounds().origin());
MoveMouseAndWaitForExpansionStateChange(panel, hover_point);
EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
gfx::Rect panel_old_bounds = panel->GetBounds();
gfx::Point mouse_location = panel_old_bounds.origin();
panel_testing->PressLeftMouseButtonTitlebar(mouse_location);
EXPECT_EQ(panel_old_bounds, panel->GetBounds());
EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
mouse_location.Offset(-70, 0);
panel_testing->DragTitlebar(mouse_location);
gfx::Rect panel_new_bounds = panel_old_bounds;
panel_new_bounds.Offset(-70, 0);
EXPECT_EQ(panel_new_bounds, panel->GetBounds());
EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
panel_testing->FinishDragTitlebar();
EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
MoveMouseAndWaitForExpansionStateChange(panel, mouse_location);
EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest,
DragMinimizedPanelWhileDrawingAttention) {
Panel* panel = CreatePanel("panel1");
scoped_ptr<NativePanelTesting> panel_testing(
CreateNativePanelTesting(panel));
CreatePanel("panel2");
panel->Minimize();
EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
panel->FlashFrame(true);
EXPECT_TRUE(panel->IsDrawingAttention());
EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
gfx::Rect panel_old_bounds = panel->GetBounds();
gfx::Point mouse_location = panel_old_bounds.origin();
panel_testing->PressLeftMouseButtonTitlebar(mouse_location);
EXPECT_EQ(panel_old_bounds, panel->GetBounds());
EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
mouse_location.Offset(-70, 0);
panel_testing->DragTitlebar(mouse_location);
gfx::Rect panel_new_bounds = panel_old_bounds;
panel_new_bounds.Offset(-70, 0);
EXPECT_EQ(panel_new_bounds, panel->GetBounds());
panel->FlashFrame(false);
EXPECT_FALSE(panel->IsDrawingAttention());
EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
MoveMouse(mouse_location);
panel_testing->FinishDragTitlebar();
EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
mouse_location.Offset(0, -50);
MoveMouseAndWaitForExpansionStateChange(panel, mouse_location);
EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
PanelManager::GetInstance()->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, CloseDockedPanelOnDrag) {
PanelManager* panel_manager = PanelManager::GetInstance();
PanelDragController* drag_controller = panel_manager->drag_controller();
DockedPanelCollection* docked_collection = panel_manager->docked_collection();
Panel* panel1 = CreatePanelWithBounds("Panel1", gfx::Rect(0, 0, 100, 100));
Panel* panel2 = CreatePanelWithBounds("Panel2", gfx::Rect(0, 0, 100, 100));
Panel* panel3 = CreatePanelWithBounds("Panel3", gfx::Rect(0, 0, 100, 100));
Panel* panel4 = CreatePanelWithBounds("Panel4", gfx::Rect(0, 0, 100, 100));
ASSERT_EQ(4, docked_collection->num_panels());
scoped_ptr<NativePanelTesting> panel1_testing(
CreateNativePanelTesting(panel1));
gfx::Point position1 = panel1->GetBounds().origin();
gfx::Point position2 = panel2->GetBounds().origin();
gfx::Point position3 = panel3->GetBounds().origin();
gfx::Point position4 = panel4->GetBounds().origin();
{
std::vector<Panel*> panels;
gfx::Point panel1_new_position = position1;
panel1_new_position.Offset(-500, 0);
gfx::Point mouse_location = panel1->GetBounds().origin();
panel1_testing->PressLeftMouseButtonTitlebar(mouse_location);
mouse_location.Offset(-500, -5);
panel1_testing->DragTitlebar(mouse_location);
EXPECT_TRUE(drag_controller->is_dragging());
EXPECT_EQ(panel1, drag_controller->dragging_panel());
ASSERT_EQ(4, docked_collection->num_panels());
panels = PanelManager::GetInstance()->panels();
EXPECT_EQ(panel2, panels[0]);
EXPECT_EQ(panel3, panels[1]);
EXPECT_EQ(panel4, panels[2]);
EXPECT_EQ(panel1, panels[3]);
EXPECT_EQ(position1, panel2->GetBounds().origin());
EXPECT_EQ(position2, panel3->GetBounds().origin());
EXPECT_EQ(position3, panel4->GetBounds().origin());
EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin());
CloseWindowAndWait(panel2);
EXPECT_TRUE(drag_controller->is_dragging());
EXPECT_EQ(panel1, drag_controller->dragging_panel());
ASSERT_EQ(3, docked_collection->num_panels());
panels = PanelManager::GetInstance()->panels();
EXPECT_EQ(panel3, panels[0]);
EXPECT_EQ(panel4, panels[1]);
EXPECT_EQ(panel1, panels[2]);
EXPECT_EQ(position1, panel3->GetBounds().origin());
EXPECT_EQ(position2, panel4->GetBounds().origin());
EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin());
panel1_testing->CancelDragTitlebar();
EXPECT_FALSE(drag_controller->is_dragging());
ASSERT_EQ(3, docked_collection->num_panels());
panels = PanelManager::GetInstance()->panels();
EXPECT_EQ(panel1, panels[0]);
EXPECT_EQ(panel3, panels[1]);
EXPECT_EQ(panel4, panels[2]);
EXPECT_EQ(position1, panel1->GetBounds().origin());
EXPECT_EQ(position2, panel3->GetBounds().origin());
EXPECT_EQ(position3, panel4->GetBounds().origin());
}
{
std::vector<Panel*> panels;
gfx::Point panel1_new_position = position1;
panel1_new_position.Offset(-500, 0);
gfx::Point mouse_location = panel1->GetBounds().origin();
panel1_testing->PressLeftMouseButtonTitlebar(mouse_location);
mouse_location.Offset(-500, -5);
panel1_testing->DragTitlebar(mouse_location);
EXPECT_TRUE(drag_controller->is_dragging());
EXPECT_EQ(panel1, drag_controller->dragging_panel());
ASSERT_EQ(3, docked_collection->num_panels());
panels = PanelManager::GetInstance()->panels();
EXPECT_EQ(panel3, panels[0]);
EXPECT_EQ(panel4, panels[1]);
EXPECT_EQ(panel1, panels[2]);
EXPECT_EQ(position1, panel3->GetBounds().origin());
EXPECT_EQ(position2, panel4->GetBounds().origin());
EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin());
CloseWindowAndWait(panel3);
EXPECT_TRUE(drag_controller->is_dragging());
EXPECT_EQ(panel1, drag_controller->dragging_panel());
ASSERT_EQ(2, docked_collection->num_panels());
panels = PanelManager::GetInstance()->panels();
EXPECT_EQ(panel4, panels[0]);
EXPECT_EQ(panel1, panels[1]);
EXPECT_EQ(position1, panel4->GetBounds().origin());
EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin());
panel1_testing->FinishDragTitlebar();
EXPECT_FALSE(drag_controller->is_dragging());
ASSERT_EQ(2, docked_collection->num_panels());
panels = PanelManager::GetInstance()->panels();
EXPECT_EQ(panel4, panels[0]);
EXPECT_EQ(panel1, panels[1]);
EXPECT_EQ(position1, panel4->GetBounds().origin());
EXPECT_EQ(position2, panel1->GetBounds().origin());
}
{
std::vector<Panel*> panels;
gfx::Point panel1_new_position = position2;
panel1_new_position.Offset(-500, 0);
gfx::Point mouse_location = panel1->GetBounds().origin();
panel1_testing->PressLeftMouseButtonTitlebar(mouse_location);
mouse_location.Offset(-500, -5);
panel1_testing->DragTitlebar(mouse_location);
EXPECT_TRUE(drag_controller->is_dragging());
EXPECT_EQ(panel1, drag_controller->dragging_panel());
EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin());
ASSERT_EQ(2, docked_collection->num_panels());
panels = PanelManager::GetInstance()->panels();
EXPECT_EQ(panel4, panels[0]);
EXPECT_EQ(panel1, panels[1]);
EXPECT_EQ(position1, panel4->GetBounds().origin());
content::WindowedNotificationObserver signal(
chrome::NOTIFICATION_PANEL_CLOSED, content::Source<Panel>(panel1));
panel1->Close();
EXPECT_FALSE(drag_controller->is_dragging());
panel1_new_position.Offset(20, 30);
panel1_testing->DragTitlebar(panel1_new_position);
panel1_testing->FinishDragTitlebar();
signal.Wait();
ASSERT_EQ(1, docked_collection->num_panels());
panels = PanelManager::GetInstance()->panels();
EXPECT_EQ(panel4, panels[0]);
EXPECT_EQ(position1, panel4->GetBounds().origin());
}
panel_manager->CloseAll();
}
#if defined(OS_MACOSX)
#define MAYBE_DragOneDetachedPanel DISABLED_DragOneDetachedPanel
#else
#define MAYBE_DragOneDetachedPanel DragOneDetachedPanel
#endif
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, MAYBE_DragOneDetachedPanel) {
Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
scoped_ptr<NativePanelTesting> panel_testing(
CreateNativePanelTesting(panel));
gfx::Point origin = panel->GetBounds().origin();
panel_testing->PressLeftMouseButtonTitlebar(origin);
EXPECT_EQ(origin, panel->GetBounds().origin());
origin.Offset(-51, -102);
panel_testing->DragTitlebar(origin);
EXPECT_EQ(origin, panel->GetBounds().origin());
origin.Offset(37, 45);
panel_testing->DragTitlebar(origin);
EXPECT_EQ(origin, panel->GetBounds().origin());
panel_testing->FinishDragTitlebar();
EXPECT_EQ(origin, panel->GetBounds().origin());
gfx::Point original_position = panel->GetBounds().origin();
origin = original_position;
panel_testing->PressLeftMouseButtonTitlebar(origin);
EXPECT_EQ(origin, panel->GetBounds().origin());
origin.Offset(-51, -102);
panel_testing->DragTitlebar(origin);
EXPECT_EQ(origin, panel->GetBounds().origin());
origin.Offset(37, 45);
panel_testing->DragTitlebar(origin);
EXPECT_EQ(origin, panel->GetBounds().origin());
panel_testing->CancelDragTitlebar();
WaitForBoundsAnimationFinished(panel);
EXPECT_EQ(original_position, panel->GetBounds().origin());
PanelManager::GetInstance()->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, CloseDetachedPanelOnDrag) {
PanelManager* panel_manager = PanelManager::GetInstance();
PanelDragController* drag_controller = panel_manager->drag_controller();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(100, 200, 100, 100));
ASSERT_EQ(1, detached_collection->num_panels());
scoped_ptr<NativePanelTesting> panel1_testing(
CreateNativePanelTesting(panel1));
gfx::Point panel1_old_position = panel1->GetBounds().origin();
{
Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(300, 210, 110, 110));
panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin());
gfx::Point panel1_new_position = panel1_old_position;
panel1_new_position.Offset(-51, -102);
panel1_testing->DragTitlebar(panel1_new_position);
EXPECT_TRUE(drag_controller->is_dragging());
EXPECT_EQ(panel1, drag_controller->dragging_panel());
ASSERT_EQ(2, detached_collection->num_panels());
EXPECT_TRUE(detached_collection->HasPanel(panel1));
EXPECT_TRUE(detached_collection->HasPanel(panel2));
EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin());
CloseWindowAndWait(panel2);
EXPECT_TRUE(drag_controller->is_dragging());
EXPECT_EQ(panel1, drag_controller->dragging_panel());
ASSERT_EQ(1, detached_collection->num_panels());
EXPECT_TRUE(detached_collection->HasPanel(panel1));
EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin());
panel1_testing->CancelDragTitlebar();
WaitForBoundsAnimationFinished(panel1);
EXPECT_FALSE(drag_controller->is_dragging());
EXPECT_EQ(panel1_old_position, panel1->GetBounds().origin());
}
{
Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(300, 210, 110, 110));
panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin());
gfx::Point panel1_new_position = panel1_old_position;
panel1_new_position.Offset(-51, -102);
panel1_testing->DragTitlebar(panel1_new_position);
EXPECT_TRUE(drag_controller->is_dragging());
EXPECT_EQ(panel1, drag_controller->dragging_panel());
ASSERT_EQ(2, detached_collection->num_panels());
EXPECT_TRUE(detached_collection->HasPanel(panel1));
EXPECT_TRUE(detached_collection->HasPanel(panel2));
EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin());
CloseWindowAndWait(panel2);
EXPECT_TRUE(drag_controller->is_dragging());
EXPECT_EQ(panel1, drag_controller->dragging_panel());
ASSERT_EQ(1, detached_collection->num_panels());
EXPECT_TRUE(detached_collection->HasPanel(panel1));
EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin());
panel1_testing->FinishDragTitlebar();
EXPECT_FALSE(drag_controller->is_dragging());
EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin());
}
{
panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin());
gfx::Point panel1_new_position = panel1->GetBounds().origin();
panel1_new_position.Offset(45, 67);
panel1_testing->DragTitlebar(panel1_new_position);
EXPECT_TRUE(drag_controller->is_dragging());
EXPECT_EQ(panel1, drag_controller->dragging_panel());
ASSERT_EQ(1, detached_collection->num_panels());
EXPECT_TRUE(detached_collection->HasPanel(panel1));
EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin());
content::WindowedNotificationObserver signal(
chrome::NOTIFICATION_PANEL_CLOSED, content::Source<Panel>(panel1));
panel1->Close();
EXPECT_FALSE(drag_controller->is_dragging());
panel1_new_position.Offset(20, 30);
panel1_testing->DragTitlebar(panel1_new_position);
panel1_testing->FinishDragTitlebar();
signal.Wait();
ASSERT_EQ(0, detached_collection->num_panels());
}
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, Detach) {
PanelManager* panel_manager = PanelManager::GetInstance();
DockedPanelCollection* docked_collection = panel_manager->docked_collection();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100));
ASSERT_EQ(1, docked_collection->num_panels());
ASSERT_EQ(0, detached_collection->num_panels());
gfx::Rect panel_old_bounds = panel->GetBounds();
scoped_ptr<NativePanelTesting> panel_testing(
CreateNativePanelTesting(panel));
gfx::Point mouse_location(panel->GetBounds().origin());
panel_testing->PressLeftMouseButtonTitlebar(mouse_location);
gfx::Vector2d drag_delta_to_remain_docked = GetDragDeltaToRemainDocked();
mouse_location = mouse_location + drag_delta_to_remain_docked;
panel_testing->DragTitlebar(mouse_location);
ASSERT_EQ(1, docked_collection->num_panels());
ASSERT_EQ(0, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DOCKED, panel->collection()->type());
gfx::Rect panel_new_bounds = panel_old_bounds;
panel_new_bounds.Offset(drag_delta_to_remain_docked.x(), 0);
EXPECT_EQ(panel_new_bounds, panel->GetBounds());
gfx::Vector2d drag_delta_to_detach = GetDragDeltaToDetach();
mouse_location = mouse_location + drag_delta_to_detach;
panel_testing->DragTitlebar(mouse_location);
ASSERT_EQ(0, docked_collection->num_panels());
ASSERT_EQ(1, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type());
panel_new_bounds.Offset(
drag_delta_to_detach.x(),
drag_delta_to_detach.y() + drag_delta_to_remain_docked.y());
EXPECT_EQ(panel_new_bounds, panel->GetBounds());
panel_testing->FinishDragTitlebar();
ASSERT_EQ(0, docked_collection->num_panels());
ASSERT_EQ(1, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type());
EXPECT_EQ(panel_new_bounds, panel->GetBounds());
panel_manager->CloseAll();
}
#if defined(OS_MACOSX)
#define MAYBE_DetachAndCancel DISABLED_DetachAndCancel
#else
#define MAYBE_DetachAndCancel DetachAndCancel
#endif
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, MAYBE_DetachAndCancel) {
PanelManager* panel_manager = PanelManager::GetInstance();
DockedPanelCollection* docked_collection = panel_manager->docked_collection();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100));
ASSERT_EQ(1, docked_collection->num_panels());
ASSERT_EQ(0, detached_collection->num_panels());
gfx::Rect panel_old_bounds = panel->GetBounds();
scoped_ptr<NativePanelTesting> panel_testing(
CreateNativePanelTesting(panel));
gfx::Point mouse_location(panel->GetBounds().origin());
panel_testing->PressLeftMouseButtonTitlebar(mouse_location);
gfx::Vector2d drag_delta_to_remain_docked = GetDragDeltaToRemainDocked();
mouse_location = mouse_location + drag_delta_to_remain_docked;
panel_testing->DragTitlebar(mouse_location);
ASSERT_EQ(1, docked_collection->num_panels());
ASSERT_EQ(0, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DOCKED, panel->collection()->type());
gfx::Rect panel_new_bounds = panel_old_bounds;
panel_new_bounds.Offset(drag_delta_to_remain_docked.x(), 0);
EXPECT_EQ(panel_new_bounds, panel->GetBounds());
gfx::Vector2d drag_delta_to_detach = GetDragDeltaToDetach();
mouse_location = mouse_location + drag_delta_to_detach;
panel_testing->DragTitlebar(mouse_location);
ASSERT_EQ(0, docked_collection->num_panels());
ASSERT_EQ(1, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type());
panel_new_bounds.Offset(
drag_delta_to_detach.x(),
drag_delta_to_detach.y() + drag_delta_to_remain_docked.y());
EXPECT_EQ(panel_new_bounds, panel->GetBounds());
panel_testing->CancelDragTitlebar();
ASSERT_EQ(1, docked_collection->num_panels());
ASSERT_EQ(0, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DOCKED, panel->collection()->type());
EXPECT_EQ(panel_old_bounds, panel->GetBounds());
panel_manager->CloseAll();
}
#if defined(OS_MACOSX)
#define MAYBE_Attach DISABLED_Attach
#else
#define MAYBE_Attach Attach
#endif
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, MAYBE_Attach) {
PanelManager* panel_manager = PanelManager::GetInstance();
DockedPanelCollection* docked_collection = panel_manager->docked_collection();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
Panel* panel = CreateDetachedPanel("1", gfx::Rect(400, 300, 100, 100));
ASSERT_EQ(0, docked_collection->num_panels());
ASSERT_EQ(1, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type());
gfx::Rect panel_old_bounds = panel->GetBounds();
scoped_ptr<NativePanelTesting> panel_testing(
CreateNativePanelTesting(panel));
gfx::Point mouse_location(panel->GetBounds().origin());
panel_testing->PressLeftMouseButtonTitlebar(mouse_location);
gfx::Vector2d drag_delta_to_remain_detached =
GetDragDeltaToRemainDetached(panel);
mouse_location = mouse_location + drag_delta_to_remain_detached;
panel_testing->DragTitlebar(mouse_location);
ASSERT_EQ(0, docked_collection->num_panels());
ASSERT_EQ(1, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type());
gfx::Rect panel_new_bounds = panel_old_bounds;
panel_new_bounds.Offset(drag_delta_to_remain_detached);
EXPECT_EQ(panel_new_bounds, panel->GetBounds());
gfx::Vector2d drag_delta_to_attach = GetDragDeltaToAttach(panel);
mouse_location = mouse_location + drag_delta_to_attach;
panel_testing->DragTitlebar(mouse_location);
ASSERT_EQ(1, docked_collection->num_panels());
ASSERT_EQ(0, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DOCKED, panel->collection()->type());
panel_new_bounds.Offset(drag_delta_to_attach);
EXPECT_EQ(panel_new_bounds, panel->GetBounds());
panel_testing->FinishDragTitlebar();
ASSERT_EQ(1, docked_collection->num_panels());
ASSERT_EQ(0, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DOCKED, panel->collection()->type());
panel_new_bounds.set_x(
docked_collection->StartingRightPosition() - panel_new_bounds.width());
panel_new_bounds.set_y(
docked_collection->work_area().bottom() - panel_new_bounds.height());
EXPECT_EQ(panel_new_bounds, panel->GetBounds());
panel_manager->CloseAll();
}
#if defined(OS_MACOSX)
#define MAYBE_AttachAndCancel DISABLED_AttachAndCancel
#else
#define MAYBE_AttachAndCancel AttachAndCancel
#endif
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, MAYBE_AttachAndCancel) {
PanelManager* panel_manager = PanelManager::GetInstance();
DockedPanelCollection* docked_collection = panel_manager->docked_collection();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
Panel* panel = CreateDetachedPanel("1", gfx::Rect(400, 300, 100, 100));
ASSERT_EQ(0, docked_collection->num_panels());
ASSERT_EQ(1, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type());
gfx::Rect panel_old_bounds = panel->GetBounds();
scoped_ptr<NativePanelTesting> panel_testing(
CreateNativePanelTesting(panel));
gfx::Point mouse_location(panel->GetBounds().origin());
panel_testing->PressLeftMouseButtonTitlebar(mouse_location);
gfx::Vector2d drag_delta_to_remain_detached =
GetDragDeltaToRemainDetached(panel);
mouse_location = mouse_location + drag_delta_to_remain_detached;
panel_testing->DragTitlebar(mouse_location);
ASSERT_EQ(0, docked_collection->num_panels());
ASSERT_EQ(1, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type());
gfx::Rect panel_new_bounds = panel_old_bounds;
panel_new_bounds.Offset(drag_delta_to_remain_detached);
EXPECT_EQ(panel_new_bounds, panel->GetBounds());
gfx::Vector2d drag_delta_to_attach = GetDragDeltaToAttach(panel);
mouse_location = mouse_location + drag_delta_to_attach;
panel_testing->DragTitlebar(mouse_location);
ASSERT_EQ(1, docked_collection->num_panels());
ASSERT_EQ(0, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DOCKED, panel->collection()->type());
panel_new_bounds.Offset(drag_delta_to_attach);
EXPECT_EQ(panel_new_bounds, panel->GetBounds());
panel_testing->CancelDragTitlebar();
ASSERT_EQ(0, docked_collection->num_panels());
ASSERT_EQ(1, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type());
EXPECT_EQ(panel_old_bounds, panel->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DetachAttachAndCancel) {
PanelManager* panel_manager = PanelManager::GetInstance();
DockedPanelCollection* docked_collection = panel_manager->docked_collection();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100));
ASSERT_EQ(1, docked_collection->num_panels());
ASSERT_EQ(0, detached_collection->num_panels());
gfx::Rect panel_old_bounds = panel->GetBounds();
scoped_ptr<NativePanelTesting> panel_testing(
CreateNativePanelTesting(panel));
gfx::Point mouse_location(panel->GetBounds().origin());
panel_testing->PressLeftMouseButtonTitlebar(mouse_location);
gfx::Vector2d drag_delta_to_detach = GetDragDeltaToDetach();
mouse_location = mouse_location + drag_delta_to_detach;
panel_testing->DragTitlebar(mouse_location);
ASSERT_EQ(0, docked_collection->num_panels());
ASSERT_EQ(1, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type());
gfx::Rect panel_new_bounds = panel_old_bounds;
panel_new_bounds.Offset(drag_delta_to_detach);
EXPECT_EQ(panel_new_bounds, panel->GetBounds());
gfx::Vector2d drag_delta_to_reattach = GetDragDeltaToAttach(panel);
mouse_location = mouse_location + drag_delta_to_reattach;
panel_testing->DragTitlebar(mouse_location);
ASSERT_EQ(1, docked_collection->num_panels());
ASSERT_EQ(0, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DOCKED, panel->collection()->type());
panel_new_bounds.Offset(drag_delta_to_reattach);
EXPECT_EQ(panel_new_bounds, panel->GetBounds());
gfx::Vector2d drag_delta_to_detach_again = GetDragDeltaToDetach();
mouse_location = mouse_location + drag_delta_to_detach_again;
panel_testing->DragTitlebar(mouse_location);
ASSERT_EQ(0, docked_collection->num_panels());
ASSERT_EQ(1, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type());
panel_new_bounds.Offset(drag_delta_to_detach_again);
EXPECT_EQ(panel_new_bounds, panel->GetBounds());
panel_testing->CancelDragTitlebar();
ASSERT_EQ(1, docked_collection->num_panels());
ASSERT_EQ(0, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DOCKED, panel->collection()->type());
EXPECT_EQ(panel_old_bounds, panel->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DetachWithSqueeze) {
PanelManager* panel_manager = PanelManager::GetInstance();
DockedPanelCollection* docked_collection = panel_manager->docked_collection();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
Panel* panel1 = CreateDockedPanel("1", gfx::Rect(0, 0, 200, 100));
Panel* panel2 = CreateDockedPanel("2", gfx::Rect(0, 0, 200, 100));
Panel* panel3 = CreateDockedPanel("3", gfx::Rect(0, 0, 200, 100));
Panel* panel4 = CreateDockedPanel("4", gfx::Rect(0, 0, 200, 100));
Panel* panel5 = CreateDockedPanel("5", gfx::Rect(0, 0, 200, 100));
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(5, docked_collection->num_panels());
gfx::Point panel2_docked_position = panel2->GetBounds().origin();
gfx::Vector2d drag_delta_to_detach_panel2(-20, -100);
DragPanelByDelta(panel2, drag_delta_to_detach_panel2);
ASSERT_EQ(1, detached_collection->num_panels());
ASSERT_EQ(4, docked_collection->num_panels());
EXPECT_EQ(PanelCollection::DOCKED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel3->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel4->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel5->collection()->type());
gfx::Point panel2_new_position =
panel2_docked_position + drag_delta_to_detach_panel2;
EXPECT_EQ(panel2_new_position, panel2->GetBounds().origin());
gfx::Point panel4_docked_position = panel4->GetBounds().origin();
gfx::Vector2d drag_delta_to_detach_panel4(-40, -250);
DragPanelByDelta(panel4, drag_delta_to_detach_panel4);
ASSERT_EQ(2, detached_collection->num_panels());
ASSERT_EQ(3, docked_collection->num_panels());
EXPECT_EQ(PanelCollection::DOCKED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel3->collection()->type());
EXPECT_EQ(PanelCollection::DETACHED, panel4->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel5->collection()->type());
EXPECT_EQ(panel2_new_position, panel2->GetBounds().origin());
gfx::Point panel4_new_position =
panel4_docked_position + drag_delta_to_detach_panel4;
EXPECT_EQ(panel4_new_position, panel4->GetBounds().origin());
gfx::Point docked_position1 = panel1->GetBounds().origin();
gfx::Point docked_position2 = panel3->GetBounds().origin();
gfx::Vector2d drag_delta_to_detach_panel1(-60, -400);
DragPanelByDelta(panel1, drag_delta_to_detach_panel1);
ASSERT_EQ(3, detached_collection->num_panels());
ASSERT_EQ(2, docked_collection->num_panels());
EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel3->collection()->type());
EXPECT_EQ(PanelCollection::DETACHED, panel4->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel5->collection()->type());
gfx::Point panel1_new_position =
docked_position1 + drag_delta_to_detach_panel1;
EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin());
EXPECT_EQ(panel2_new_position, panel2->GetBounds().origin());
EXPECT_EQ(panel4_new_position, panel4->GetBounds().origin());
EXPECT_EQ(docked_position1, panel3->GetBounds().origin());
EXPECT_EQ(panel1->GetBounds().width(), panel1->GetRestoredBounds().width());
EXPECT_EQ(docked_position2, panel5->GetBounds().origin());
EXPECT_EQ(panel2->GetBounds().width(), panel2->GetRestoredBounds().width());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, AttachWithSqueeze) {
PanelManager* panel_manager = PanelManager::GetInstance();
DockedPanelCollection* docked_collection = panel_manager->docked_collection();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
Panel* panel1 = CreateInactiveDetachedPanel(
"1", gfx::Rect(100, 300, 200, 100));
Panel* panel2 = CreateInactiveDetachedPanel(
"2", gfx::Rect(200, 300, 200, 100));
Panel* panel3 = CreateInactiveDetachedPanel(
"3", gfx::Rect(400, 300, 200, 100));
Panel* panel4 = CreateInactiveDockedPanel("4", gfx::Rect(0, 0, 200, 100));
Panel* panel5 = CreateInactiveDockedPanel("5", gfx::Rect(0, 0, 200, 100));
Panel* panel6 = CreateInactiveDockedPanel("6", gfx::Rect(0, 0, 200, 100));
Panel* panel7 = CreateDockedPanel("7", gfx::Rect(0, 0, 200, 100));
ASSERT_EQ(3, detached_collection->num_panels());
ASSERT_EQ(4, docked_collection->num_panels());
PanelCollectionSqueezeObserver panel7_settled(docked_collection, panel7);
panel7_settled.Wait();
gfx::Point detached_position1 = panel1->GetBounds().origin();
gfx::Point detached_position2 = panel2->GetBounds().origin();
gfx::Point detached_position3 = panel3->GetBounds().origin();
gfx::Point docked_position4 = panel4->GetBounds().origin();
gfx::Point docked_position5 = panel5->GetBounds().origin();
gfx::Point docked_position6 = panel6->GetBounds().origin();
gfx::Point docked_position7 = panel7->GetBounds().origin();
gfx::Point drag_to_location(panel5->GetBounds().x() + 10,
panel5->GetBounds().y());
DragPanelToMouseLocation(panel3, drag_to_location);
ASSERT_EQ(2, detached_collection->num_panels());
ASSERT_EQ(5, docked_collection->num_panels());
EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel3->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel4->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel5->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel6->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel7->collection()->type());
EXPECT_EQ(detached_position1, panel1->GetBounds().origin());
EXPECT_EQ(detached_position2, panel2->GetBounds().origin());
base::MessageLoopForUI::current()->RunUntilIdle();
EXPECT_NE(docked_position4, panel4->GetBounds().origin());
EXPECT_LT(panel4->GetBounds().width(), panel4->GetRestoredBounds().width());
EXPECT_NE(docked_position5, panel5->GetBounds().origin());
EXPECT_LT(panel5->GetBounds().width(), panel5->GetRestoredBounds().width());
#if defined(OS_WIN)
EXPECT_EQ(true, panel3->IsActive());
EXPECT_EQ(panel3->GetBounds().width(), panel3->GetRestoredBounds().width());
EXPECT_NE(docked_position6, panel6->GetBounds().origin());
#else
EXPECT_EQ(true, panel7->IsActive());
EXPECT_EQ(panel7->GetBounds().width(), panel7->GetRestoredBounds().width());
EXPECT_EQ(docked_position6, panel6->GetBounds().origin());
#endif
EXPECT_EQ(docked_position7, panel7->GetBounds().origin());
gfx::Point drag_to_location2(panel4->GetBounds().right() + 10,
panel4->GetBounds().y());
DragPanelToMouseLocation(panel2, drag_to_location2);
ASSERT_EQ(1, detached_collection->num_panels());
ASSERT_EQ(6, docked_collection->num_panels());
EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel2->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel3->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel4->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel5->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel6->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel7->collection()->type());
EXPECT_EQ(detached_position1, panel1->GetBounds().origin());
gfx::Point drag_to_location3(panel3->GetBounds().x() - 10,
panel3->GetBounds().y());
DragPanelToMouseLocation(panel1, drag_to_location3);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(7, docked_collection->num_panels());
EXPECT_EQ(PanelCollection::DOCKED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel2->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel3->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel4->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel5->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel6->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel7->collection()->type());
panel_manager->CloseAll();
}
#if defined(OS_MACOSX)
#define MAYBE_DragDetachedPanelToTop DISABLED_DragDetachedPanelToTop
#else
#define MAYBE_DragDetachedPanelToTop DragDetachedPanelToTop
#endif
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, MAYBE_DragDetachedPanelToTop) {
const gfx::Rect primary_display_area(0, 0, 800, 600);
const gfx::Rect primary_work_area(0, 10, 800, 590);
mock_display_settings_provider()->SetPrimaryDisplay(
primary_display_area, primary_work_area);
PanelManager* panel_manager = PanelManager::GetInstance();
Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
gfx::Point drag_to_location(250, 0);
DragPanelToMouseLocation(panel, drag_to_location);
EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type());
EXPECT_EQ(drag_to_location.x(), panel->GetBounds().origin().x());
EXPECT_EQ(primary_work_area.y(), panel->GetBounds().origin().y());
drag_to_location = gfx::Point(280, 150);
DragPanelToMouseLocation(panel, drag_to_location);
EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type());
EXPECT_EQ(drag_to_location, panel->GetBounds().origin());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest,
DragDockedPanelToSecondaryDisplay) {
mock_display_settings_provider()->SetPrimaryDisplay(
gfx::Rect(0, 0, 400, 600), gfx::Rect(0, 0, 400, 560));
gfx::Rect secondary_display_area(400, 100, 400, 500);
mock_display_settings_provider()->SetSecondaryDisplay(
secondary_display_area, secondary_display_area);
gfx::Size panel_size(100, 100);
Panel* panel = CreateDockedPanel("1", gfx::Rect(gfx::Point(), panel_size));
EXPECT_EQ(PanelCollection::DOCKED, panel->collection()->type());
gfx::Point drag_to_location(secondary_display_area.x() + 100,
panel->GetBounds().y());
DragPanelToMouseLocation(panel, drag_to_location);
EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type());
gfx::Rect expected_bounds(drag_to_location, panel_size);
EXPECT_EQ(expected_bounds, panel->GetBounds());
PanelManager::GetInstance()->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest,
DragDetachedPanelToSecondaryDisplay) {
mock_display_settings_provider()->SetPrimaryDisplay(
gfx::Rect(0, 0, 800, 300), gfx::Rect(0, 0, 800, 260));
gfx::Rect secondary_display_area(100, 300, 700, 250);
mock_display_settings_provider()->SetSecondaryDisplay(
secondary_display_area, secondary_display_area);
gfx::Rect initial_panel_bounds(300, 50, 100, 100);
Panel* panel = CreateDetachedPanel("1", initial_panel_bounds);
EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type());
EXPECT_EQ(initial_panel_bounds, panel->GetBounds());
gfx::Point drag_to_location(initial_panel_bounds.x(),
secondary_display_area.y() + 100);
DragPanelToMouseLocation(panel, drag_to_location);
EXPECT_EQ(PanelCollection::DETACHED, panel->collection()->type());
gfx::Rect expected_bounds(drag_to_location, initial_panel_bounds.size());
EXPECT_EQ(expected_bounds, panel->GetBounds());
PanelManager::GetInstance()->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupPanelAndPanelFromBottom) {
PanelManager* panel_manager = PanelManager::GetInstance();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(300, 200, 200, 100));
Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(100, 100, 150, 150));
ASSERT_EQ(2, detached_collection->num_panels());
ASSERT_EQ(0, panel_manager->num_stacks());
EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
gfx::Rect panel1_old_bounds = panel1->GetBounds();
gfx::Rect panel2_old_bounds = panel2->GetBounds();
scoped_ptr<NativePanelTesting> panel2_testing(
CreateNativePanelTesting(panel2));
gfx::Point mouse_location(panel2->GetBounds().origin());
gfx::Point original_mouse_location = mouse_location;
panel2_testing->PressLeftMouseButtonTitlebar(mouse_location);
gfx::Vector2d drag_delta_to_stack =
GetDragDeltaToStackToBottom(panel2, panel1);
mouse_location = mouse_location + drag_delta_to_stack;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
gfx::Rect panel2_new_bounds(panel2_old_bounds.x() + drag_delta_to_stack.x(),
panel1_old_bounds.bottom(),
panel2_old_bounds.width(),
panel2_old_bounds.height());
EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
gfx::Vector2d drag_delta_to_unstack =
GetDragDeltaToUnstackFromBottom(panel2, panel1);
mouse_location = mouse_location + drag_delta_to_unstack;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(2, detached_collection->num_panels());
ASSERT_EQ(0, panel_manager->num_stacks());
EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
panel2_new_bounds.set_origin(panel2_old_bounds.origin());
panel2_new_bounds.Offset(mouse_location - original_mouse_location);
EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
drag_delta_to_stack = GetDragDeltaToStackToBottom(panel2, panel1);
mouse_location = mouse_location + drag_delta_to_stack;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
panel2_new_bounds.set_x(panel2_new_bounds.x() + drag_delta_to_stack.x());
panel2_new_bounds.set_y(panel1_old_bounds.bottom());
EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
gfx::Vector2d small_delta(1, -1);
mouse_location = mouse_location + small_delta;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
panel2_new_bounds.set_x(panel2_new_bounds.x() + small_delta.x());
EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
panel2_testing->FinishDragTitlebar();
WaitForBoundsAnimationFinished(panel2);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
panel2_new_bounds.set_x(panel1_old_bounds.x());
panel2_new_bounds.set_width(panel1_old_bounds.width());
EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupPanelAndPanelFromTop) {
PanelManager* panel_manager = PanelManager::GetInstance();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(300, 300, 200, 100));
Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(100, 200, 150, 150));
ASSERT_EQ(2, detached_collection->num_panels());
ASSERT_EQ(0, panel_manager->num_stacks());
EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
gfx::Rect panel1_old_bounds = panel1->GetBounds();
gfx::Rect panel2_old_bounds = panel2->GetBounds();
scoped_ptr<NativePanelTesting> panel2_testing(
CreateNativePanelTesting(panel2));
gfx::Point mouse_location(panel2->GetBounds().origin());
gfx::Point original_mouse_location = mouse_location;
panel2_testing->PressLeftMouseButtonTitlebar(mouse_location);
gfx::Vector2d drag_delta_to_stack = GetDragDeltaToStackToTop(panel2, panel1);
mouse_location = mouse_location + drag_delta_to_stack;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
gfx::Rect panel2_new_bounds(
panel2_old_bounds.x() + drag_delta_to_stack.x(),
panel1_old_bounds.y() - panel2_old_bounds.height(),
panel2_old_bounds.width(),
panel2_old_bounds.height());
EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
gfx::Vector2d drag_delta_to_unstack =
GetDragDeltaToUnstackFromTop(panel2, panel1);
mouse_location = mouse_location + drag_delta_to_unstack;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(2, detached_collection->num_panels());
ASSERT_EQ(0, panel_manager->num_stacks());
EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
panel2_new_bounds.set_origin(panel2_old_bounds.origin());
panel2_new_bounds.Offset(mouse_location - original_mouse_location);
EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
drag_delta_to_stack = GetDragDeltaToStackToTop(panel2, panel1);
mouse_location = mouse_location + drag_delta_to_stack;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
panel2_new_bounds.set_x(panel2_new_bounds.x() + drag_delta_to_stack.x());
panel2_new_bounds.set_y(panel1_old_bounds.y() - panel2_old_bounds.height());
EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
gfx::Vector2d small_delta(1, -1);
mouse_location = mouse_location + small_delta;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
panel2_new_bounds.set_x(panel2_new_bounds.x() + small_delta.x());
EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
panel2_testing->FinishDragTitlebar();
WaitForBoundsAnimationFinished(panel1);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
gfx::Rect panel1_new_bounds = panel1_old_bounds;
panel1_new_bounds.set_width(panel2_new_bounds.width());
EXPECT_EQ(panel1_new_bounds, panel1->GetBounds());
panel2_new_bounds.set_x(panel1_new_bounds.x());
EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupAndCancel) {
PanelManager* panel_manager = PanelManager::GetInstance();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(300, 200, 200, 100));
Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(100, 100, 150, 150));
ASSERT_EQ(2, detached_collection->num_panels());
ASSERT_EQ(0, panel_manager->num_stacks());
EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
gfx::Rect panel1_old_bounds = panel1->GetBounds();
gfx::Rect panel2_old_bounds = panel2->GetBounds();
scoped_ptr<NativePanelTesting> panel2_testing(
CreateNativePanelTesting(panel2));
gfx::Point mouse_location(panel2->GetBounds().origin());
gfx::Point original_mouse_location = mouse_location;
panel2_testing->PressLeftMouseButtonTitlebar(mouse_location);
gfx::Vector2d drag_delta_to_stack =
GetDragDeltaToStackToBottom(panel2, panel1);
mouse_location = mouse_location + drag_delta_to_stack;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
gfx::Rect panel2_new_bounds(panel1_old_bounds.x(),
panel1_old_bounds.bottom(),
panel2_old_bounds.width(),
panel2_old_bounds.height());
EXPECT_EQ(panel2_new_bounds, panel2->GetBounds());
panel2_testing->CancelDragTitlebar();
ASSERT_EQ(2, detached_collection->num_panels());
ASSERT_EQ(0, panel_manager->num_stacks());
EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
EXPECT_EQ(panel1_old_bounds, panel1->GetBounds());
EXPECT_EQ(panel2_old_bounds, panel2->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupPanelAndStackFromBottom) {
PanelManager* panel_manager = PanelManager::GetInstance();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
StackedPanelCollection* stack = panel_manager->CreateStack();
gfx::Rect panel1_initial_bounds = gfx::Rect(100, 100, 200, 150);
Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
ASSERT_EQ(2, stack->num_panels());
EXPECT_EQ(stack, panel1->collection());
EXPECT_EQ(stack, panel2->collection());
gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
panel2_initial_bounds, panel1_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
gfx::Rect panel3_initial_bounds = gfx::Rect(300, 200, 100, 100);
Panel* panel3 = CreateDetachedPanel("3", panel3_initial_bounds);
ASSERT_EQ(1, detached_collection->num_panels());
gfx::Rect panel3_expected_bounds(panel3_initial_bounds);
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
gfx::Vector2d drag_delta_to_stack =
GetDragDeltaToStackToBottom(panel3, panel1);
DragPanelByDelta(panel3, drag_delta_to_stack);
ASSERT_EQ(1, detached_collection->num_panels());
ASSERT_EQ(2, stack->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
drag_delta_to_stack = GetDragDeltaToStackToBottom(panel3, panel2);
DragPanelByDelta(panel3, drag_delta_to_stack);
WaitForBoundsAnimationFinished(panel3);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(3, stack->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
EXPECT_EQ(stack, panel1->collection());
EXPECT_EQ(stack, panel2->collection());
EXPECT_EQ(stack, panel3->collection());
EXPECT_EQ(panel3, stack->bottom_panel());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel3_expected_bounds = GetStackedAtBottomPanelBounds(
panel3_initial_bounds, panel2_expected_bounds);
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupPanelAndStackFromTop) {
PanelManager* panel_manager = PanelManager::GetInstance();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
StackedPanelCollection* stack = panel_manager->CreateStack();
gfx::Rect panel1_initial_bounds = gfx::Rect(100, 300, 200, 150);
Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
ASSERT_EQ(2, stack->num_panels());
EXPECT_EQ(stack, panel1->collection());
EXPECT_EQ(stack, panel2->collection());
gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
panel2_initial_bounds, panel1_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
gfx::Rect panel3_initial_bounds = gfx::Rect(300, 200, 100, 100);
Panel* panel3 = CreateDetachedPanel("3", panel3_initial_bounds);
ASSERT_EQ(1, detached_collection->num_panels());
gfx::Rect panel3_expected_bounds(panel3_initial_bounds);
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
gfx::Vector2d drag_delta_to_stack = GetDragDeltaToStackToTop(panel3, panel2);
DragPanelByDelta(panel3, drag_delta_to_stack);
ASSERT_EQ(1, detached_collection->num_panels());
ASSERT_EQ(2, stack->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
drag_delta_to_stack = GetDragDeltaToStackToTop(panel3, panel1);
DragPanelByDelta(panel3, drag_delta_to_stack);
WaitForBoundsAnimationFinished(panel1);
WaitForBoundsAnimationFinished(panel2);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(3, stack->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
EXPECT_EQ(stack, panel1->collection());
EXPECT_EQ(stack, panel2->collection());
EXPECT_EQ(stack, panel3->collection());
EXPECT_EQ(panel3, stack->top_panel());
panel3_expected_bounds = GetStackedAtTopPanelBounds(
panel3_initial_bounds, panel1_expected_bounds);
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
panel1_expected_bounds.set_width(panel3_expected_bounds.width());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds.set_width(panel3_expected_bounds.width());
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupStackAndPanelFromBottom) {
PanelManager* panel_manager = PanelManager::GetInstance();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
StackedPanelCollection* stack = panel_manager->CreateStack();
gfx::Rect panel1_initial_bounds = gfx::Rect(100, 100, 200, 150);
Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
ASSERT_EQ(2, stack->num_panels());
EXPECT_EQ(stack, panel1->stack());
EXPECT_EQ(stack, panel2->stack());
gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
panel2_initial_bounds, panel1_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
gfx::Rect panel3_initial_bounds = gfx::Rect(300, 200, 100, 100);
Panel* panel3 = CreateDetachedPanel("3", panel3_initial_bounds);
ASSERT_EQ(1, detached_collection->num_panels());
gfx::Rect panel3_expected_bounds(panel3_initial_bounds);
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
gfx::Vector2d drag_delta_to_stack =
GetDragDeltaToStackToBottom(panel1, panel3);
DragPanelByDelta(panel1, drag_delta_to_stack);
WaitForBoundsAnimationFinished(panel1);
WaitForBoundsAnimationFinished(panel2);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
StackedPanelCollection* final_stack = panel_manager->stacks().front();
ASSERT_EQ(3, final_stack->num_panels());
EXPECT_EQ(final_stack, panel1->stack());
EXPECT_EQ(final_stack, panel2->stack());
EXPECT_EQ(final_stack, panel3->stack());
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
panel1_expected_bounds = GetStackedAtBottomPanelBounds(
panel1_initial_bounds, panel3_expected_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds = GetStackedAtBottomPanelBounds(
panel2_initial_bounds, panel1_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupStackAndPanelFromTop) {
PanelManager* panel_manager = PanelManager::GetInstance();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
StackedPanelCollection* stack = panel_manager->CreateStack();
gfx::Rect panel1_initial_bounds = gfx::Rect(100, 100, 200, 150);
Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
ASSERT_EQ(2, stack->num_panels());
EXPECT_EQ(stack, panel1->stack());
EXPECT_EQ(stack, panel2->stack());
gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
panel2_initial_bounds, panel1_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
gfx::Rect panel3_initial_bounds = gfx::Rect(300, 450, 100, 100);
Panel* panel3 = CreateDetachedPanel("3", panel3_initial_bounds);
ASSERT_EQ(1, detached_collection->num_panels());
gfx::Rect panel3_expected_bounds(panel3_initial_bounds);
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
gfx::Vector2d drag_delta_to_stack = GetDragDeltaToStackToTop(panel1, panel3);
DragPanelByDelta(panel1, drag_delta_to_stack);
WaitForBoundsAnimationFinished(panel3);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
StackedPanelCollection* final_stack = panel_manager->stacks().front();
ASSERT_EQ(3, final_stack->num_panels());
EXPECT_EQ(final_stack, panel1->stack());
EXPECT_EQ(final_stack, panel2->stack());
EXPECT_EQ(final_stack, panel3->stack());
panel3_expected_bounds.set_width(panel1_expected_bounds.width());
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
panel2_expected_bounds = GetStackedAtTopPanelBounds(
panel2_expected_bounds, panel3_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel1_expected_bounds = GetStackedAtTopPanelBounds(
panel1_expected_bounds, panel2_expected_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupStackAndStackFromBottom) {
PanelManager* panel_manager = PanelManager::GetInstance();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
StackedPanelCollection* stack1 = panel_manager->CreateStack();
gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack1);
gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack1);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
ASSERT_EQ(2, stack1->num_panels());
EXPECT_EQ(stack1, panel1->stack());
EXPECT_EQ(stack1, panel2->stack());
gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
panel2_initial_bounds, panel1_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
StackedPanelCollection* stack2 = panel_manager->CreateStack();
gfx::Rect panel3_initial_bounds = gfx::Rect(300, 100, 220, 120);
Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack2);
gfx::Rect panel4_initial_bounds = gfx::Rect(0, 0, 180, 140);
Panel* panel4 = CreateStackedPanel("4", panel4_initial_bounds, stack2);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(2, panel_manager->num_stacks());
ASSERT_EQ(2, stack2->num_panels());
EXPECT_EQ(stack2, panel3->stack());
EXPECT_EQ(stack2, panel4->stack());
gfx::Rect panel3_expected_bounds(panel3_initial_bounds);
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
gfx::Rect panel4_expected_bounds = GetStackedAtBottomPanelBounds(
panel4_initial_bounds, panel3_expected_bounds);
EXPECT_EQ(panel4_expected_bounds, panel4->GetBounds());
gfx::Vector2d drag_delta_to_stack =
GetDragDeltaToStackToBottom(panel3, panel2);
DragPanelByDelta(panel3, drag_delta_to_stack);
WaitForBoundsAnimationFinished(panel3);
WaitForBoundsAnimationFinished(panel4);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
StackedPanelCollection* final_stack = panel_manager->stacks().front();
ASSERT_EQ(4, final_stack->num_panels());
EXPECT_EQ(final_stack, panel1->stack());
EXPECT_EQ(final_stack, panel2->stack());
EXPECT_EQ(final_stack, panel3->stack());
EXPECT_EQ(final_stack, panel4->stack());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel3_expected_bounds = GetStackedAtBottomPanelBounds(
panel3_initial_bounds, panel2_expected_bounds);
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
panel4_expected_bounds = GetStackedAtBottomPanelBounds(
panel4_initial_bounds, panel3_expected_bounds);
EXPECT_EQ(panel4_expected_bounds, panel4->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, GroupStackAndStackFromTop) {
PanelManager* panel_manager = PanelManager::GetInstance();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
StackedPanelCollection* stack1 = panel_manager->CreateStack();
gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack1);
gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack1);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
ASSERT_EQ(2, stack1->num_panels());
EXPECT_EQ(stack1, panel1->stack());
EXPECT_EQ(stack1, panel2->stack());
gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
panel2_initial_bounds, panel1_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
StackedPanelCollection* stack2 = panel_manager->CreateStack();
gfx::Rect panel3_initial_bounds = gfx::Rect(300, 350, 220, 110);
Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack2);
gfx::Rect panel4_initial_bounds = gfx::Rect(0, 0, 180, 100);
Panel* panel4 = CreateStackedPanel("4", panel4_initial_bounds, stack2);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(2, panel_manager->num_stacks());
ASSERT_EQ(2, stack2->num_panels());
EXPECT_EQ(stack2, panel3->stack());
EXPECT_EQ(stack2, panel4->stack());
gfx::Rect panel3_expected_bounds(panel3_initial_bounds);
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
gfx::Rect panel4_expected_bounds = GetStackedAtBottomPanelBounds(
panel4_initial_bounds, panel3_expected_bounds);
EXPECT_EQ(panel4_expected_bounds, panel4->GetBounds());
gfx::Vector2d drag_delta_to_stack = GetDragDeltaToStackToTop(panel1, panel3);
DragPanelByDelta(panel1, drag_delta_to_stack);
WaitForBoundsAnimationFinished(panel3);
WaitForBoundsAnimationFinished(panel4);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
StackedPanelCollection* final_stack = panel_manager->stacks().front();
ASSERT_EQ(4, final_stack->num_panels());
EXPECT_EQ(final_stack, panel1->stack());
EXPECT_EQ(final_stack, panel2->stack());
EXPECT_EQ(final_stack, panel3->stack());
EXPECT_EQ(final_stack, panel4->stack());
panel4_expected_bounds.set_width(panel1_expected_bounds.width());
EXPECT_EQ(panel4_expected_bounds, panel4->GetBounds());
panel3_expected_bounds.set_width(panel1_expected_bounds.width());
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
panel2_expected_bounds = GetStackedAtTopPanelBounds(
panel2_expected_bounds, panel3_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel1_expected_bounds = GetStackedAtTopPanelBounds(
panel1_expected_bounds, panel2_expected_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, UngroupTwoPanelStack) {
PanelManager* panel_manager = PanelManager::GetInstance();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
StackedPanelCollection* stack = panel_manager->CreateStack();
gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(2, stack->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
EXPECT_EQ(stack, panel1->stack());
EXPECT_EQ(stack, panel2->stack());
gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
panel2_initial_bounds, panel1_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
gfx::Rect panel2_old_bounds = panel2_expected_bounds;
scoped_ptr<NativePanelTesting> panel2_testing(
CreateNativePanelTesting(panel2));
gfx::Point mouse_location(panel2->GetBounds().origin());
gfx::Point original_mouse_location = mouse_location;
panel2_testing->PressLeftMouseButtonTitlebar(mouse_location);
gfx::Vector2d drag_delta_to_unstack =
GetDragDeltaToUnstackFromBottom(panel2, panel1);
mouse_location = mouse_location + drag_delta_to_unstack;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(2, detached_collection->num_panels());
ASSERT_TRUE(stack->num_panels() == 0);
EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds.Offset(drag_delta_to_unstack);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
gfx::Vector2d drag_delta_to_stack =
GetDragDeltaToStackToBottom(panel2, panel1);
mouse_location = mouse_location + drag_delta_to_stack;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_GE(panel_manager->num_stacks(), 1);
EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
EXPECT_EQ(panel1->stack(), panel2->stack());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds = GetStackedAtBottomPanelBounds(
panel2_initial_bounds, panel1_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
drag_delta_to_unstack = GetDragDeltaToUnstackFromBottom(panel2, panel1);
mouse_location = mouse_location + drag_delta_to_unstack;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(2, detached_collection->num_panels());
ASSERT_TRUE(stack->num_panels() == 0);
EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds = panel2_old_bounds;
panel2_expected_bounds.Offset(mouse_location - original_mouse_location);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel2_testing->FinishDragTitlebar();
ASSERT_EQ(2, detached_collection->num_panels());
ASSERT_EQ(0, panel_manager->num_stacks());
EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, UngroupAndCancel) {
PanelManager* panel_manager = PanelManager::GetInstance();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
StackedPanelCollection* stack = panel_manager->CreateStack();
gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(2, stack->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
EXPECT_EQ(stack, panel1->stack());
EXPECT_EQ(stack, panel2->stack());
gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
panel2_initial_bounds, panel1_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
gfx::Rect panel2_old_bounds = panel2->GetBounds();
scoped_ptr<NativePanelTesting> panel2_testing(
CreateNativePanelTesting(panel2));
gfx::Point mouse_location(panel2->GetBounds().origin());
gfx::Point original_mouse_location = mouse_location;
panel2_testing->PressLeftMouseButtonTitlebar(mouse_location);
gfx::Vector2d drag_delta_to_unstack =
GetDragDeltaToUnstackFromBottom(panel2, panel1);
mouse_location = mouse_location + drag_delta_to_unstack;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(2, detached_collection->num_panels());
ASSERT_TRUE(stack->num_panels() == 0);
EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds.Offset(drag_delta_to_unstack);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel2_testing->CancelDragTitlebar();
WaitForBoundsAnimationFinished(panel2);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
EXPECT_EQ(stack, panel1->stack());
EXPECT_EQ(stack, panel2->stack());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
EXPECT_EQ(panel2_old_bounds, panel2->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest,
UngroupBottomPanelInThreePanelStack) {
PanelManager* panel_manager = PanelManager::GetInstance();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
StackedPanelCollection* stack = panel_manager->CreateStack();
gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
gfx::Rect panel3_initial_bounds = gfx::Rect(0, 0, 120, 120);
Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
ASSERT_EQ(3, stack->num_panels());
EXPECT_EQ(stack, panel1->stack());
EXPECT_EQ(stack, panel2->stack());
EXPECT_EQ(stack, panel3->stack());
gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
panel2_initial_bounds, panel1_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
gfx::Rect panel3_expected_bounds = GetStackedAtBottomPanelBounds(
panel3_initial_bounds, panel2_expected_bounds);
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
gfx::Vector2d drag_delta_to_unstack =
GetDragDeltaToUnstackFromBottom(panel3, panel2);
DragPanelByDelta(panel3, drag_delta_to_unstack);
ASSERT_EQ(1, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
ASSERT_EQ(2, stack->num_panels());
EXPECT_EQ(stack, panel1->stack());
EXPECT_EQ(stack, panel2->stack());
EXPECT_EQ(PanelCollection::DETACHED, panel3->collection()->type());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel3_expected_bounds.Offset(drag_delta_to_unstack);
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest,
UngroupMiddlePanelInThreePanelStack) {
PanelManager* panel_manager = PanelManager::GetInstance();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
StackedPanelCollection* stack = panel_manager->CreateStack();
gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
gfx::Rect panel3_initial_bounds = gfx::Rect(0, 0, 120, 120);
Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
ASSERT_EQ(3, stack->num_panels());
EXPECT_EQ(stack, panel1->stack());
EXPECT_EQ(stack, panel2->stack());
EXPECT_EQ(stack, panel3->stack());
gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
panel2_initial_bounds, panel1_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
gfx::Rect panel3_expected_bounds = GetStackedAtBottomPanelBounds(
panel3_initial_bounds, panel2_expected_bounds);
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
gfx::Vector2d drag_delta_to_unstack =
GetDragDeltaToUnstackFromBottom(panel2, panel1);
DragPanelByDelta(panel2, drag_delta_to_unstack);
ASSERT_EQ(1, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
StackedPanelCollection* final_stack = panel_manager->stacks().front();
ASSERT_EQ(2, final_stack->num_panels());
EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
EXPECT_EQ(final_stack, panel2->stack());
EXPECT_EQ(final_stack, panel3->stack());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds.Offset(drag_delta_to_unstack);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel3_expected_bounds.Offset(drag_delta_to_unstack);
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest,
UngroupThirdPanelInFourPanelStack) {
PanelManager* panel_manager = PanelManager::GetInstance();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
StackedPanelCollection* stack = panel_manager->CreateStack();
gfx::Rect panel1_initial_bounds = gfx::Rect(100, 120, 200, 100);
Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
gfx::Rect panel3_initial_bounds = gfx::Rect(0, 0, 120, 120);
Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack);
gfx::Rect panel4_initial_bounds = gfx::Rect(0, 0, 120, 110);
Panel* panel4 = CreateStackedPanel("4", panel4_initial_bounds, stack);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
ASSERT_EQ(4, stack->num_panels());
EXPECT_EQ(stack, panel1->stack());
EXPECT_EQ(stack, panel2->stack());
EXPECT_EQ(stack, panel3->stack());
EXPECT_EQ(stack, panel4->stack());
gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
panel2_initial_bounds, panel1_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
gfx::Rect panel3_expected_bounds = GetStackedAtBottomPanelBounds(
panel3_initial_bounds, panel2_expected_bounds);
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
gfx::Rect panel4_expected_bounds = GetStackedAtBottomPanelBounds(
panel4_initial_bounds, panel3_expected_bounds);
EXPECT_EQ(panel4_expected_bounds, panel4->GetBounds());
gfx::Vector2d drag_delta_to_unstack =
GetDragDeltaToUnstackFromBottom(panel3, panel2);
DragPanelByDelta(panel3, drag_delta_to_unstack);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(2, panel_manager->num_stacks());
StackedPanelCollection* final_stack1 = panel_manager->stacks().front();
ASSERT_EQ(2, final_stack1->num_panels());
StackedPanelCollection* final_stack2 = panel_manager->stacks().back();
ASSERT_EQ(2, final_stack2->num_panels());
EXPECT_EQ(panel1->stack(), panel2->stack());
EXPECT_EQ(panel3->stack(), panel4->stack());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel3_expected_bounds.Offset(drag_delta_to_unstack);
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
panel4_expected_bounds.Offset(drag_delta_to_unstack);
EXPECT_EQ(panel4_expected_bounds, panel4->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, UngroupAndGroup) {
PanelManager* panel_manager = PanelManager::GetInstance();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
StackedPanelCollection* stack = panel_manager->CreateStack();
gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(2, stack->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
EXPECT_EQ(stack, panel1->stack());
EXPECT_EQ(stack, panel2->stack());
gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
panel2_initial_bounds, panel1_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
gfx::Rect panel3_initial_bounds = gfx::Rect(300, 200, 100, 100);
Panel* panel3 = CreateDetachedPanel("3", panel3_initial_bounds);
ASSERT_EQ(1, detached_collection->num_panels());
gfx::Rect panel3_expected_bounds(panel3_initial_bounds);
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
gfx::Vector2d drag_delta_to_unstack_and_stack =
GetDragDeltaToStackToBottom(panel2, panel3);
DragPanelByDelta(panel2, drag_delta_to_unstack_and_stack);
WaitForBoundsAnimationFinished(panel2);
ASSERT_EQ(1, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
StackedPanelCollection* final_stack = panel_manager->stacks().front();
ASSERT_EQ(2, final_stack->num_panels());
EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
EXPECT_EQ(final_stack, panel2->stack());
EXPECT_EQ(final_stack, panel3->stack());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds = GetStackedAtBottomPanelBounds(
panel2_initial_bounds, panel3_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, UngroupAndAttach) {
PanelManager* panel_manager = PanelManager::GetInstance();
DockedPanelCollection* docked_collection = panel_manager->docked_collection();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
StackedPanelCollection* stack = panel_manager->CreateStack();
gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
ASSERT_EQ(0, docked_collection->num_panels());
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(2, stack->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
EXPECT_EQ(stack, panel1->stack());
EXPECT_EQ(stack, panel2->stack());
gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
panel2_initial_bounds, panel1_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
gfx::Vector2d drag_delta_to_unstack_and_attach = GetDragDeltaToAttach(panel2);
DragPanelByDelta(panel2, drag_delta_to_unstack_and_attach);
WaitForBoundsAnimationFinished(panel2);
ASSERT_EQ(1, docked_collection->num_panels());
ASSERT_EQ(1, detached_collection->num_panels());
ASSERT_EQ(0, panel_manager->num_stacks());
EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::DOCKED, panel2->collection()->type());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds.set_x(docked_collection->StartingRightPosition() -
panel2_expected_bounds.width());
panel2_expected_bounds.set_y(docked_collection->work_area().bottom() -
panel2_expected_bounds.height());
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, SnapPanelToPanelLeft) {
PanelManager* panel_manager = PanelManager::GetInstance();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
gfx::Rect panel1_initial_bounds = gfx::Rect(300, 200, 300, 200);
Panel* panel1 = CreateDetachedPanel("1", panel1_initial_bounds);
gfx::Rect panel2_initial_bounds = gfx::Rect(100, 100, 100, 250);
Panel* panel2 = CreateDetachedPanel("2", panel2_initial_bounds);
ASSERT_EQ(2, detached_collection->num_panels());
gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
gfx::Rect panel2_expected_bounds(panel2_initial_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
scoped_ptr<NativePanelTesting> panel2_testing(
CreateNativePanelTesting(panel2));
gfx::Point mouse_location(panel2->GetBounds().origin());
gfx::Point original_mouse_location = mouse_location;
panel2_testing->PressLeftMouseButtonTitlebar(mouse_location);
gfx::Vector2d drag_delta_to_snap = GetDragDeltaToSnapToLeft(panel2, panel1);
mouse_location = mouse_location + drag_delta_to_snap;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(2, detached_collection->num_panels());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds.Offset(drag_delta_to_snap);
panel2_expected_bounds.set_x(
panel1_expected_bounds.x() - panel2_expected_bounds.width());
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
gfx::Vector2d drag_delta_to_unsnap = GetDragDeltaToUnsnap(panel1);
mouse_location = mouse_location + drag_delta_to_unsnap;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(2, detached_collection->num_panels());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds = panel2_initial_bounds;
panel2_expected_bounds.Offset(mouse_location - original_mouse_location);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
drag_delta_to_snap = GetDragDeltaToSnapToLeft(panel2, panel1);
mouse_location = mouse_location + drag_delta_to_snap;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(2, detached_collection->num_panels());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds.Offset(drag_delta_to_snap);
panel2_expected_bounds.set_x(
panel1_expected_bounds.x() - panel2_expected_bounds.width());
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
gfx::Vector2d drag_delta_almost_vertically(2, 20);
mouse_location = mouse_location + drag_delta_almost_vertically;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(2, detached_collection->num_panels());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds.set_y(
panel2_expected_bounds.y() + drag_delta_almost_vertically.y());
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel2_testing->FinishDragTitlebar();
ASSERT_EQ(2, detached_collection->num_panels());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, SnapPanelToPanelRight) {
PanelManager* panel_manager = PanelManager::GetInstance();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
gfx::Rect panel1_initial_bounds = gfx::Rect(100, 200, 100, 200);
Panel* panel1 = CreateDetachedPanel("1", panel1_initial_bounds);
gfx::Rect panel2_initial_bounds = gfx::Rect(300, 100, 200, 250);
Panel* panel2 = CreateDetachedPanel("2", panel2_initial_bounds);
ASSERT_EQ(2, detached_collection->num_panels());
gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
gfx::Rect panel2_expected_bounds(panel2_initial_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
scoped_ptr<NativePanelTesting> panel2_testing(
CreateNativePanelTesting(panel2));
gfx::Point mouse_location(panel2->GetBounds().origin());
gfx::Point original_mouse_location = mouse_location;
panel2_testing->PressLeftMouseButtonTitlebar(mouse_location);
gfx::Vector2d drag_delta_to_snap = GetDragDeltaToSnapToRight(panel2, panel1);
mouse_location = mouse_location + drag_delta_to_snap;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(2, detached_collection->num_panels());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds.Offset(drag_delta_to_snap);
panel2_expected_bounds.set_x(panel1_expected_bounds.right());
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
gfx::Vector2d drag_delta_to_unsnap = GetDragDeltaToUnsnap(panel1);
mouse_location = mouse_location + drag_delta_to_unsnap;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(2, detached_collection->num_panels());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds = panel2_initial_bounds;
panel2_expected_bounds.Offset(mouse_location - original_mouse_location);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
drag_delta_to_snap = GetDragDeltaToSnapToRight(panel2, panel1);
mouse_location = mouse_location + drag_delta_to_snap;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(2, detached_collection->num_panels());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds.Offset(drag_delta_to_snap);
panel2_expected_bounds.set_x(panel1_expected_bounds.right());
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
gfx::Vector2d drag_delta_almost_vertically(2, -20);
mouse_location = mouse_location + drag_delta_almost_vertically;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(2, detached_collection->num_panels());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds.set_y(
panel2_expected_bounds.y() + drag_delta_almost_vertically.y());
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel2_testing->FinishDragTitlebar();
ASSERT_EQ(2, detached_collection->num_panels());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, SnapAndCancel) {
PanelManager* panel_manager = PanelManager::GetInstance();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
gfx::Rect panel1_initial_bounds = gfx::Rect(300, 200, 300, 200);
Panel* panel1 = CreateDetachedPanel("1", panel1_initial_bounds);
gfx::Rect panel2_initial_bounds = gfx::Rect(100, 100, 100, 250);
Panel* panel2 = CreateDetachedPanel("2", panel2_initial_bounds);
ASSERT_EQ(2, detached_collection->num_panels());
gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
gfx::Rect panel2_expected_bounds(panel2_initial_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
scoped_ptr<NativePanelTesting> panel2_testing(
CreateNativePanelTesting(panel2));
gfx::Point mouse_location(panel2->GetBounds().origin());
gfx::Point original_mouse_location = mouse_location;
panel2_testing->PressLeftMouseButtonTitlebar(mouse_location);
gfx::Vector2d drag_delta_to_snap = GetDragDeltaToSnapToLeft(panel2, panel1);
mouse_location = mouse_location + drag_delta_to_snap;
panel2_testing->DragTitlebar(mouse_location);
ASSERT_EQ(2, detached_collection->num_panels());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds.Offset(drag_delta_to_snap);
panel2_expected_bounds.set_x(
panel1_expected_bounds.x() - panel2_expected_bounds.width());
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel2_testing->CancelDragTitlebar();
ASSERT_EQ(2, detached_collection->num_panels());
EXPECT_EQ(panel1_initial_bounds, panel1->GetBounds());
EXPECT_EQ(panel2_initial_bounds, panel2->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, SnapPanelToStackLeft) {
PanelManager* panel_manager = PanelManager::GetInstance();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
StackedPanelCollection* stack = panel_manager->CreateStack();
gfx::Rect panel1_initial_bounds = gfx::Rect(300, 100, 200, 150);
Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
ASSERT_EQ(2, stack->num_panels());
EXPECT_EQ(stack, panel1->collection());
EXPECT_EQ(stack, panel2->collection());
gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
panel2_initial_bounds, panel1_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
gfx::Rect panel3_initial_bounds = gfx::Rect(100, 200, 100, 100);
Panel* panel3 = CreateDetachedPanel("3", panel3_initial_bounds);
ASSERT_EQ(1, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DETACHED, panel3->collection()->type());
gfx::Rect panel3_expected_bounds(panel3_initial_bounds);
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
gfx::Vector2d drag_delta_to_snap = GetDragDeltaToSnapToLeft(panel3, panel1);
DragPanelByDelta(panel3, drag_delta_to_snap);
ASSERT_EQ(1, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
ASSERT_EQ(2, stack->num_panels());
EXPECT_EQ(stack, panel1->collection());
EXPECT_EQ(stack, panel2->collection());
EXPECT_EQ(PanelCollection::DETACHED, panel3->collection()->type());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel3_expected_bounds.Offset(drag_delta_to_snap);
panel3_expected_bounds.set_x(
panel1_expected_bounds.x() - panel3_expected_bounds.width());
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, SnapPanelToStackRight) {
PanelManager* panel_manager = PanelManager::GetInstance();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
StackedPanelCollection* stack = panel_manager->CreateStack();
gfx::Rect panel1_initial_bounds = gfx::Rect(100, 100, 200, 150);
Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
ASSERT_EQ(0, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
ASSERT_EQ(2, stack->num_panels());
EXPECT_EQ(stack, panel1->collection());
EXPECT_EQ(stack, panel2->collection());
gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
panel2_initial_bounds, panel1_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
gfx::Rect panel3_initial_bounds = gfx::Rect(300, 200, 100, 100);
Panel* panel3 = CreateDetachedPanel("3", panel3_initial_bounds);
ASSERT_EQ(1, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DETACHED, panel3->collection()->type());
gfx::Rect panel3_expected_bounds(panel3_initial_bounds);
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
gfx::Vector2d drag_delta_to_snap = GetDragDeltaToSnapToRight(panel3, panel1);
DragPanelByDelta(panel3, drag_delta_to_snap);
ASSERT_EQ(1, detached_collection->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
ASSERT_EQ(2, stack->num_panels());
EXPECT_EQ(stack, panel1->collection());
EXPECT_EQ(stack, panel2->collection());
EXPECT_EQ(PanelCollection::DETACHED, panel3->collection()->type());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel3_expected_bounds.Offset(drag_delta_to_snap);
panel3_expected_bounds.set_x(panel1_expected_bounds.right());
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DetachAndSnap) {
PanelManager* panel_manager = PanelManager::GetInstance();
DockedPanelCollection* docked_collection = panel_manager->docked_collection();
DetachedPanelCollection* detached_collection =
panel_manager->detached_collection();
Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(300, 200, 100, 100));
ASSERT_EQ(0, docked_collection->num_panels());
ASSERT_EQ(1, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
gfx::Rect panel1_bounds = panel1->GetBounds();
Panel* panel2 = CreateDockedPanel("2", gfx::Rect(0, 0, 150, 150));
ASSERT_EQ(1, docked_collection->num_panels());
ASSERT_EQ(1, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DOCKED, panel2->collection()->type());
gfx::Rect panel2_bounds = panel2->GetBounds();
gfx::Vector2d drag_delta_to_detach_and_snap =
GetDragDeltaToSnapToRight(panel2, panel1);
DragPanelByDelta(panel2, drag_delta_to_detach_and_snap);
ASSERT_EQ(0, docked_collection->num_panels());
ASSERT_EQ(2, detached_collection->num_panels());
EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
EXPECT_EQ(panel1_bounds, panel1->GetBounds());
panel2_bounds.Offset(drag_delta_to_detach_and_snap);
panel2_bounds.set_x(panel1_bounds.right());
EXPECT_EQ(panel2_bounds, panel2->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragTopStackedPanel) {
PanelManager* panel_manager = PanelManager::GetInstance();
StackedPanelCollection* stack = panel_manager->CreateStack();
gfx::Rect panel1_initial_bounds = gfx::Rect(300, 100, 200, 150);
Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
gfx::Rect panel3_initial_bounds = gfx::Rect(0, 0, 150, 200);
Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack);
ASSERT_EQ(3, stack->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
EXPECT_EQ(stack, panel1->collection());
EXPECT_EQ(stack, panel2->collection());
EXPECT_EQ(stack, panel3->collection());
gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
panel2_initial_bounds, panel1_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
gfx::Rect panel3_expected_bounds = GetStackedAtBottomPanelBounds(
panel3_initial_bounds, panel2_expected_bounds);
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
gfx::Vector2d drag_delta(-50, -20);
DragPanelByDelta(panel1, drag_delta);
ASSERT_EQ(3, stack->num_panels());
ASSERT_EQ(1, panel_manager->num_stacks());
EXPECT_EQ(stack, panel1->collection());
EXPECT_EQ(stack, panel2->collection());
EXPECT_EQ(stack, panel3->collection());
panel1_expected_bounds.Offset(drag_delta);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds.Offset(drag_delta);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel3_expected_bounds.Offset(drag_delta);
EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, SnapDetachedPanelToScreenEdge) {
PanelManager* panel_manager = PanelManager::GetInstance();
int small_distance =
PanelDragController::GetSnapPanelToScreenEdgeThresholdForTesting() / 2;
gfx::Rect primary_display_area(0, 0, 400, 600);
gfx::Rect primary_work_area(0, 0, 400, 560);
mock_display_settings_provider()->SetPrimaryDisplay(
primary_display_area, primary_work_area);
gfx::Rect secondary_display_area(400, 100, 400, 500);
gfx::Rect secondary_work_area(400, 140, 400, 460);
mock_display_settings_provider()->SetSecondaryDisplay(
secondary_display_area, secondary_work_area);
gfx::Rect initial_bounds = gfx::Rect(100, 100, 200, 150);
Panel* panel = CreateDetachedPanel("1", initial_bounds);
gfx::Rect expected_bounds(initial_bounds);
EXPECT_EQ(expected_bounds, panel->GetBounds());
gfx::Point drag_to_location(
primary_work_area.right() - small_distance - panel->GetBounds().width(),
panel->GetBounds().y());
DragPanelToMouseLocation(panel, drag_to_location);
expected_bounds.set_x(primary_work_area.right() - panel->GetBounds().width());
EXPECT_EQ(expected_bounds, panel->GetBounds());
drag_to_location = gfx::Point(
primary_work_area.x() + small_distance,
primary_work_area.y() - small_distance);
DragPanelToMouseLocation(panel, drag_to_location);
expected_bounds.set_origin(primary_work_area.origin());
EXPECT_EQ(expected_bounds, panel->GetBounds());
drag_to_location = gfx::Point(
secondary_work_area.right() - small_distance - panel->GetBounds().width(),
secondary_work_area.y() + small_distance);
DragPanelToMouseLocation(panel, drag_to_location);
expected_bounds.set_x(
secondary_work_area.right() - panel->GetBounds().width());
expected_bounds.set_y(secondary_work_area.y());
EXPECT_EQ(expected_bounds, panel->GetBounds());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, SnapStackedPanelToScreenEdge) {
PanelManager* panel_manager = PanelManager::GetInstance();
int small_distance =
PanelDragController::GetSnapPanelToScreenEdgeThresholdForTesting() / 2;
gfx::Rect primary_display_area(0, 0, 400, 600);
gfx::Rect primary_work_area(0, 0, 400, 560);
mock_display_settings_provider()->SetPrimaryDisplay(
primary_display_area, primary_work_area);
gfx::Rect secondary_display_area(400, 100, 400, 500);
gfx::Rect secondary_work_area(400, 140, 400, 460);
mock_display_settings_provider()->SetSecondaryDisplay(
secondary_display_area, secondary_work_area);
StackedPanelCollection* stack = panel_manager->CreateStack();
gfx::Rect panel1_initial_bounds = gfx::Rect(300, 100, 200, 150);
Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
gfx::Rect panel2_expected_bounds = GetStackedAtBottomPanelBounds(
panel2_initial_bounds, panel1_expected_bounds);
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
gfx::Point drag_to_location(
primary_work_area.x() + small_distance, panel1->GetBounds().y());
DragPanelToMouseLocation(panel1, drag_to_location);
panel1_expected_bounds.set_x(primary_work_area.x());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds.set_x(primary_work_area.x());
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
drag_to_location = gfx::Point(
primary_work_area.right() + small_distance - panel1->GetBounds().width(),
primary_work_area.bottom() - small_distance -
panel1->GetBounds().height() - panel2->GetBounds().height());
DragPanelToMouseLocation(panel1, drag_to_location);
int expected_x = primary_work_area.right() - panel1->GetBounds().width();
panel1_expected_bounds.set_x(expected_x);
panel1_expected_bounds.set_y(primary_work_area.bottom() -
panel1->GetBounds().height() - panel2->GetBounds().height());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds.set_x(expected_x);
panel2_expected_bounds.set_y(primary_work_area.bottom() -
panel2->GetBounds().height());
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
drag_to_location = gfx::Point(
secondary_work_area.x() + small_distance,
secondary_work_area.y() + small_distance);
DragPanelToMouseLocation(panel1, drag_to_location);
expected_x = secondary_work_area.x();
panel1_expected_bounds.set_x(expected_x);
panel1_expected_bounds.set_y(secondary_work_area.y());
EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
panel2_expected_bounds.set_x(expected_x);
panel2_expected_bounds.set_y(panel1_expected_bounds.bottom());
EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
panel_manager->CloseAll();
}