Home | History | Annotate | Download | only in panels
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/ui/panels/base_panel_browser_test.h"
      6 #include "chrome/browser/ui/panels/detached_panel_collection.h"
      7 #include "chrome/browser/ui/panels/panel.h"
      8 #include "chrome/browser/ui/panels/panel_manager.h"
      9 #include "chrome/browser/ui/panels/panel_resize_controller.h"
     10 #include "chrome/browser/ui/panels/stacked_panel_collection.h"
     11 
     12 class PanelResizeBrowserTest : public BasePanelBrowserTest {
     13  public:
     14   PanelResizeBrowserTest() : BasePanelBrowserTest() {
     15   }
     16 
     17   virtual ~PanelResizeBrowserTest() {
     18   }
     19 
     20   virtual void SetUpOnMainThread() OVERRIDE {
     21     BasePanelBrowserTest::SetUpOnMainThread();
     22 
     23     // All the tests here assume using mocked 800x600 display area for the
     24     // primary monitor. Do the check now.
     25     gfx::Rect primary_display_area = PanelManager::GetInstance()->
     26         display_settings_provider()->GetPrimaryDisplayArea();
     27     DCHECK(primary_display_area.width() == 800);
     28     DCHECK(primary_display_area.height() == 600);
     29   }
     30 
     31   void ResizePanel(Panel* panel,
     32                    panel::ResizingSides sides,
     33                    const gfx::Vector2d& delta) {
     34     PanelManager* panel_manager = PanelManager::GetInstance();
     35     gfx::Rect bounds = panel->GetBounds();
     36     gfx::Point mouse_location;
     37     switch (sides) {
     38       case panel::RESIZE_TOP_LEFT:
     39         mouse_location = bounds.origin();
     40         break;
     41       case panel::RESIZE_TOP:
     42         mouse_location.SetPoint(bounds.x() + bounds.width() / 2, bounds.y());
     43         break;
     44       case panel::RESIZE_TOP_RIGHT:
     45         mouse_location.SetPoint(bounds.right(), bounds.y());
     46         break;
     47       case panel::RESIZE_LEFT:
     48         mouse_location.SetPoint(bounds.x(), bounds.y() + bounds.height() / 2);
     49         break;
     50       case panel::RESIZE_RIGHT:
     51         mouse_location.SetPoint(bounds.right(),
     52                                 bounds.y() + bounds.height() / 2);
     53         break;
     54       case panel::RESIZE_BOTTOM_LEFT:
     55         mouse_location.SetPoint(bounds.x(), bounds.bottom());
     56         break;
     57       case panel::RESIZE_BOTTOM:
     58         mouse_location.SetPoint(bounds.x() + bounds.width() / 2,
     59                                 bounds.bottom());
     60         break;
     61       case panel::RESIZE_BOTTOM_RIGHT:
     62         mouse_location.SetPoint(bounds.right(), bounds.bottom());
     63         break;
     64       default:
     65         NOTREACHED();
     66         break;
     67     }
     68     panel_manager->StartResizingByMouse(panel, mouse_location, sides);
     69     mouse_location += delta;
     70     panel_manager->ResizeByMouse(mouse_location);
     71     panel_manager->EndResizingByMouse(false);
     72   }
     73 };
     74 
     75 // http://crbug.com/175760; several panel tests failing regularly on mac.
     76 #if defined(OS_MACOSX)
     77 #define MAYBE_DockedPanelResizability DISABLED_DockedPanelResizability
     78 #else
     79 #define MAYBE_DockedPanelResizability DockedPanelResizability
     80 #endif
     81 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, MAYBE_DockedPanelResizability) {
     82   PanelManager* panel_manager = PanelManager::GetInstance();
     83   Panel* panel = CreatePanel("Panel");
     84 
     85   EXPECT_EQ(panel::RESIZABLE_EXCEPT_BOTTOM, panel->CanResizeByMouse());
     86 
     87   gfx::Rect bounds = panel->GetBounds();
     88 
     89   // Try resizing by the top left corner.
     90   gfx::Point mouse_location = bounds.origin();
     91   panel_manager->StartResizingByMouse(panel, mouse_location,
     92                                       panel::RESIZE_TOP_LEFT);
     93   mouse_location.Offset(-20, -10);
     94   panel_manager->ResizeByMouse(mouse_location);
     95 
     96   bounds.set_size(gfx::Size(bounds.width() + 20, bounds.height() + 10));
     97   bounds.Offset(-20, -10);
     98   EXPECT_EQ(bounds, panel->GetBounds());
     99 
    100   panel_manager->EndResizingByMouse(false);
    101   EXPECT_EQ(bounds, panel->GetBounds());
    102 
    103   // Try resizing by the top.
    104   mouse_location = bounds.origin() + gfx::Vector2d(10, 1);
    105   panel_manager->StartResizingByMouse(panel, mouse_location,
    106                                       panel::RESIZE_TOP);
    107   mouse_location.Offset(5, -10);
    108   panel_manager->ResizeByMouse(mouse_location);
    109 
    110   bounds.set_height(bounds.height() + 10);
    111   bounds.Offset(0, -10);
    112   EXPECT_EQ(bounds, panel->GetBounds());
    113 
    114   panel_manager->EndResizingByMouse(false);
    115   EXPECT_EQ(bounds, panel->GetBounds());
    116 
    117   // Try resizing by the left side.
    118   mouse_location = bounds.origin() + gfx::Vector2d(1, 30);
    119   panel_manager->StartResizingByMouse(panel, mouse_location,
    120                                       panel::RESIZE_LEFT);
    121   mouse_location.Offset(-5, 25);
    122   panel_manager->ResizeByMouse(mouse_location);
    123 
    124   bounds.set_width(bounds.width() + 5);
    125   bounds.Offset(-5, 0);
    126   EXPECT_EQ(bounds, panel->GetBounds());
    127 
    128   panel_manager->EndResizingByMouse(false);
    129   EXPECT_EQ(bounds, panel->GetBounds());
    130 
    131   // Try resizing by the top right side.
    132   mouse_location = bounds.origin() + gfx::Vector2d(bounds.width() - 1, 2);
    133   panel_manager->StartResizingByMouse(panel, mouse_location,
    134                                       panel::RESIZE_TOP_RIGHT);
    135   mouse_location.Offset(30, 20);
    136   panel_manager->ResizeByMouse(mouse_location);
    137 
    138   bounds.set_size(gfx::Size(bounds.width() + 30, bounds.height() - 20));
    139   bounds.Offset(0, 20);
    140   EXPECT_EQ(bounds, panel->GetBounds());
    141 
    142   panel_manager->EndResizingByMouse(false);
    143   WaitForBoundsAnimationFinished(panel);
    144   bounds.Offset(-30, 0);  // Layout of panel adjusted in docked collection.
    145   EXPECT_EQ(bounds, panel->GetBounds());
    146 
    147   // Try resizing by the right side.
    148   mouse_location = bounds.origin() + gfx::Vector2d(bounds.width() - 1, 30);
    149   panel_manager->StartResizingByMouse(panel, mouse_location,
    150                                       panel::RESIZE_RIGHT);
    151   mouse_location.Offset(5, 25);
    152   panel_manager->ResizeByMouse(mouse_location);
    153 
    154   bounds.set_width(bounds.width() + 5);
    155   EXPECT_EQ(bounds, panel->GetBounds());
    156 
    157   panel_manager->EndResizingByMouse(false);
    158   WaitForBoundsAnimationFinished(panel);
    159   bounds.Offset(-5, 0);  // Layout of panel adjusted in docked collection.
    160   EXPECT_EQ(bounds, panel->GetBounds());
    161 
    162   // Try resizing by the bottom side; verify resize won't work.
    163   mouse_location = bounds.origin() + gfx::Vector2d(10, bounds.height() - 1);
    164   panel_manager->StartResizingByMouse(panel, mouse_location,
    165                                       panel::RESIZE_BOTTOM);
    166   mouse_location.Offset(30, -10);
    167   panel_manager->ResizeByMouse(mouse_location);
    168   EXPECT_EQ(bounds, panel->GetBounds());
    169 
    170   panel_manager->EndResizingByMouse(false);
    171   EXPECT_EQ(bounds, panel->GetBounds());
    172 
    173   // Try resizing by the bottom left corner; verify resize won't work.
    174   mouse_location = bounds.origin() + gfx::Vector2d(1, bounds.height() - 1);
    175   panel_manager->StartResizingByMouse(panel, mouse_location,
    176                                       panel::RESIZE_BOTTOM_LEFT);
    177   mouse_location.Offset(-10, 15);
    178   panel_manager->ResizeByMouse(mouse_location);
    179   EXPECT_EQ(bounds, panel->GetBounds());
    180 
    181   panel_manager->EndResizingByMouse(false);
    182   EXPECT_EQ(bounds, panel->GetBounds());
    183 
    184   // Try resizing by the bottom right corner; verify resize won't work.
    185   mouse_location = bounds.origin() +
    186       gfx::Vector2d(bounds.width() - 2, bounds.height());
    187   panel_manager->StartResizingByMouse(panel, mouse_location,
    188                                       panel::RESIZE_BOTTOM_RIGHT);
    189   mouse_location.Offset(20, 10);
    190   panel_manager->ResizeByMouse(mouse_location);
    191   EXPECT_EQ(bounds, panel->GetBounds());
    192 
    193   panel_manager->EndResizingByMouse(false);
    194   EXPECT_EQ(bounds, panel->GetBounds());
    195 
    196   panel->Close();
    197 }
    198 
    199 // http://crbug.com/175760; several panel tests failing regularly on mac.
    200 #if defined(OS_MACOSX)
    201 #define MAYBE_ResizeDetachedPanel DISABLED_ResizeDetachedPanel
    202 #else
    203 #define MAYBE_ResizeDetachedPanel ResizeDetachedPanel
    204 #endif
    205 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, MAYBE_ResizeDetachedPanel) {
    206   PanelManager* panel_manager = PanelManager::GetInstance();
    207   Panel* panel = CreateDetachedPanel("Panel", gfx::Rect(300, 200, 150, 100));
    208 
    209   EXPECT_EQ(panel::RESIZABLE_ALL, panel->CanResizeByMouse());
    210 
    211   gfx::Rect bounds = panel->GetBounds();
    212 
    213   // Try resizing by the right side; verify resize will change width only.
    214   gfx::Point mouse_location = bounds.origin() +
    215       gfx::Vector2d(bounds.width() - 1, 30);
    216   panel_manager->StartResizingByMouse(panel, mouse_location,
    217                                       panel::RESIZE_RIGHT);
    218   mouse_location.Offset(5, 25);
    219   panel_manager->ResizeByMouse(mouse_location);
    220 
    221   bounds.set_width(bounds.width() + 5);
    222   EXPECT_EQ(bounds, panel->GetBounds());
    223 
    224   panel_manager->EndResizingByMouse(false);
    225   EXPECT_EQ(bounds, panel->GetBounds());
    226 
    227   // Try resizing by the bottom left side.
    228   mouse_location = bounds.origin() + gfx::Vector2d(1, bounds.height() - 1);
    229   panel_manager->StartResizingByMouse(panel, mouse_location,
    230                                       panel::RESIZE_BOTTOM_LEFT);
    231   mouse_location.Offset(-10, 15);
    232   panel_manager->ResizeByMouse(mouse_location);
    233 
    234   bounds.set_size(gfx::Size(bounds.width() + 10, bounds.height() + 15));
    235   bounds.Offset(-10, 0);
    236   EXPECT_EQ(bounds, panel->GetBounds());
    237 
    238   panel_manager->EndResizingByMouse(false);
    239   EXPECT_EQ(bounds, panel->GetBounds());
    240 
    241   // Try resizing by the top right side.
    242   mouse_location = bounds.origin() + gfx::Vector2d(bounds.width() - 1, 2);
    243   panel_manager->StartResizingByMouse(panel, mouse_location,
    244                                       panel::RESIZE_TOP_RIGHT);
    245   mouse_location.Offset(30, 20);
    246   panel_manager->ResizeByMouse(mouse_location);
    247 
    248   bounds.set_size(gfx::Size(bounds.width() + 30, bounds.height() - 20));
    249   bounds.Offset(0, 20);
    250   EXPECT_EQ(bounds, panel->GetBounds());
    251 
    252   panel_manager->EndResizingByMouse(false);
    253   EXPECT_EQ(bounds, panel->GetBounds());
    254 
    255   // Try resizing by the top left side.
    256   mouse_location = bounds.origin() + gfx::Vector2d(1, 0);
    257   panel_manager->StartResizingByMouse(panel, mouse_location,
    258                                       panel::RESIZE_TOP_LEFT);
    259   mouse_location.Offset(-20, -10);
    260   panel_manager->ResizeByMouse(mouse_location);
    261 
    262   bounds.set_size(gfx::Size(bounds.width() + 20, bounds.height() + 10));
    263   bounds.Offset(-20, -10);
    264   EXPECT_EQ(bounds, panel->GetBounds());
    265 
    266   panel_manager->EndResizingByMouse(false);
    267   EXPECT_EQ(bounds, panel->GetBounds());
    268 
    269   PanelManager::GetInstance()->CloseAll();
    270 }
    271 
    272 // http://crbug.com/175760; several panel tests failing regularly on mac.
    273 #if defined(OS_MACOSX)
    274 #define MAYBE_TryResizePanelBelowMinimizeSize \
    275   DISABLED_TryResizePanelBelowMinimizeSize
    276 #else
    277 #define MAYBE_TryResizePanelBelowMinimizeSize TryResizePanelBelowMinimizeSize
    278 #endif
    279 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest,
    280                        MAYBE_TryResizePanelBelowMinimizeSize) {
    281   int initial_width = 150;
    282   int initial_height = 100;
    283   Panel* panel = CreateDetachedPanel("1",
    284       gfx::Rect(300, 200, initial_width, initial_height));
    285 
    286   // Try to resize the panel below the minimum size. Expect that the panel
    287   // shrinks to the minimum size.
    288   int resize_width = panel::kPanelMinWidth / 2 - initial_width;
    289   int resize_height = panel::kPanelMinHeight / 2 - initial_height;
    290   ResizePanel(panel,
    291               panel::RESIZE_BOTTOM_RIGHT,
    292               gfx::Vector2d(resize_width, resize_height));
    293 
    294   EXPECT_EQ(panel::kPanelMinWidth, panel->GetBounds().width());
    295   EXPECT_EQ(panel::kPanelMinHeight, panel->GetBounds().height());
    296 
    297   PanelManager::GetInstance()->CloseAll();
    298 }
    299 
    300 // http://crbug.com/175760; several panel tests failing regularly on mac.
    301 #if defined(OS_MACOSX)
    302 #define MAYBE_ResizeDetachedPanelToClampSize \
    303   DISABLED_ResizeDetachedPanelToClampSize
    304 #else
    305 #define MAYBE_ResizeDetachedPanelToClampSize ResizeDetachedPanelToClampSize
    306 #endif
    307 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest,
    308                        MAYBE_ResizeDetachedPanelToClampSize) {
    309   PanelManager* panel_manager = PanelManager::GetInstance();
    310   Panel* panel = CreateDetachedPanel("Panel", gfx::Rect(300, 200, 150, 100));
    311 
    312   EXPECT_EQ(panel::RESIZABLE_ALL, panel->CanResizeByMouse());
    313 
    314   gfx::Rect bounds = panel->GetBounds();
    315 
    316   // Make sure the panel does not resize smaller than its min size.
    317   gfx::Point mouse_location = bounds.origin() +
    318       gfx::Vector2d(30, bounds.height() - 2);
    319   panel_manager->StartResizingByMouse(panel, mouse_location,
    320                                       panel::RESIZE_BOTTOM);
    321   mouse_location.Offset(-20, -500);
    322   panel_manager->ResizeByMouse(mouse_location);
    323 
    324   bounds.set_height(panel->min_size().height());
    325   EXPECT_EQ(bounds, panel->GetBounds());
    326 
    327   panel_manager->EndResizingByMouse(false);
    328   EXPECT_EQ(bounds, panel->GetBounds());
    329 
    330   // Make sure the panel can resize larger than its size. User is in control.
    331   mouse_location = bounds.origin() +
    332       gfx::Vector2d(bounds.width(), bounds.height() - 2);
    333   panel_manager->StartResizingByMouse(panel, mouse_location,
    334                                       panel::RESIZE_BOTTOM_RIGHT);
    335 
    336   // This drag would take us beyond max size.
    337   int delta_x = panel->max_size().width() + 10 - panel->GetBounds().width();
    338   int delta_y = panel->max_size().height() + 10 - panel->GetBounds().height();
    339   mouse_location.Offset(delta_x, delta_y);
    340   panel_manager->ResizeByMouse(mouse_location);
    341 
    342   // The bounds if the max_size does not limit the resize.
    343   bounds.set_size(gfx::Size(bounds.width() + delta_x,
    344                             bounds.height() + delta_y));
    345   EXPECT_EQ(bounds, panel->GetBounds());
    346 
    347   panel_manager->EndResizingByMouse(false);
    348   EXPECT_EQ(bounds, panel->GetBounds());
    349 
    350   PanelManager::GetInstance()->CloseAll();
    351 }
    352 
    353 // http://crbug.com/175760; several panel tests failing regularly on mac.
    354 #if defined(OS_MACOSX)
    355 #define MAYBE_CloseDetachedPanelOnResize DISABLED_CloseDetachedPanelOnResize
    356 #else
    357 #define MAYBE_CloseDetachedPanelOnResize CloseDetachedPanelOnResize
    358 #endif
    359 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest,
    360                        MAYBE_CloseDetachedPanelOnResize) {
    361   PanelManager* panel_manager = PanelManager::GetInstance();
    362   PanelResizeController* resize_controller = panel_manager->resize_controller();
    363   DetachedPanelCollection* detached_collection =
    364       panel_manager->detached_collection();
    365 
    366   // Create 3 detached panels.
    367   Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(100, 200, 100, 100));
    368   Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(200, 210, 110, 110));
    369   Panel* panel3 = CreateDetachedPanel("3", gfx::Rect(300, 220, 120, 120));
    370   ASSERT_EQ(3, detached_collection->num_panels());
    371 
    372   gfx::Rect panel1_bounds = panel1->GetBounds();
    373   gfx::Rect panel2_bounds = panel2->GetBounds();
    374   gfx::Rect panel3_bounds = panel3->GetBounds();
    375 
    376   // Start resizing panel1, and close panel2 in the process.
    377   // Panel1 is not affected.
    378   gfx::Point mouse_location = panel1_bounds.origin() +
    379       gfx::Vector2d(1, panel1_bounds.height() - 1);
    380   panel_manager->StartResizingByMouse(panel1, mouse_location,
    381                                       panel::RESIZE_BOTTOM_LEFT);
    382   mouse_location.Offset(-10, 15);
    383   panel_manager->ResizeByMouse(mouse_location);
    384 
    385   panel1_bounds.set_size(gfx::Size(panel1_bounds.width() + 10,
    386                                    panel1_bounds.height() + 15));
    387   panel1_bounds.Offset(-10, 0);
    388   EXPECT_EQ(panel1_bounds, panel1->GetBounds());
    389 
    390   CloseWindowAndWait(panel2);
    391   EXPECT_TRUE(resize_controller->IsResizing());
    392   EXPECT_EQ(2, detached_collection->num_panels());
    393 
    394   panel_manager->EndResizingByMouse(false);
    395   EXPECT_EQ(panel1_bounds, panel1->GetBounds());
    396 
    397   // Start resizing panel3, and close it in the process.
    398   // Resize should abort, panel1 will not be affected.
    399   mouse_location = panel3_bounds.origin() +
    400       gfx::Vector2d(panel3_bounds.width() - 1, panel3_bounds.height() - 2);
    401   panel_manager->StartResizingByMouse(panel3, mouse_location,
    402                                       panel::RESIZE_BOTTOM_RIGHT);
    403   mouse_location.Offset(7, -12);
    404   panel_manager->ResizeByMouse(mouse_location);
    405 
    406   panel3_bounds.set_size(gfx::Size(panel3_bounds.width() + 7,
    407                                    panel3_bounds.height() - 12));
    408   EXPECT_EQ(panel3_bounds, panel3->GetBounds());
    409 
    410   CloseWindowAndWait(panel3);
    411   EXPECT_EQ(1, detached_collection->num_panels());
    412   // Since we closed the panel we were resizing, we should be out of the
    413   // resizing mode by now.
    414   EXPECT_FALSE(resize_controller->IsResizing());
    415 
    416   panel_manager->EndResizingByMouse(false);
    417   EXPECT_FALSE(resize_controller->IsResizing());
    418   EXPECT_EQ(panel1_bounds, panel1->GetBounds());
    419 
    420   panel_manager->CloseAll();
    421 }
    422 
    423 // http://crbug.com/175760; several panel tests failing regularly on mac.
    424 #if defined(OS_MACOSX)
    425 #define MAYBE_ResizeAndCancel DISABLED_ResizeAndCancel
    426 #else
    427 #define MAYBE_ResizeAndCancel ResizeAndCancel
    428 #endif
    429 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, MAYBE_ResizeAndCancel) {
    430   PanelManager* panel_manager = PanelManager::GetInstance();
    431   Panel* panel = CreateDetachedPanel("Panel", gfx::Rect(300, 200, 150, 100));
    432   PanelResizeController* resize_controller = panel_manager->resize_controller();
    433 
    434   EXPECT_EQ(panel::RESIZABLE_ALL, panel->CanResizeByMouse());
    435 
    436   gfx::Rect original_bounds = panel->GetBounds();
    437 
    438   // Resizing the panel, then cancelling should return it to the original state.
    439   // Try resizing by the top right side.
    440   gfx::Rect bounds = panel->GetBounds();
    441   gfx::Point mouse_location = bounds.origin() +
    442       gfx::Vector2d(bounds.width() - 1, 1);
    443   panel_manager->StartResizingByMouse(panel, mouse_location,
    444                                       panel::RESIZE_TOP_RIGHT);
    445   mouse_location.Offset(5, 25);
    446   panel_manager->ResizeByMouse(mouse_location);
    447 
    448   bounds.set_size(gfx::Size(bounds.width() + 5, bounds.height() - 25));
    449   bounds.Offset(0, 25);
    450   EXPECT_EQ(bounds, panel->GetBounds());
    451 
    452   panel_manager->EndResizingByMouse(true);
    453   EXPECT_EQ(original_bounds, panel->GetBounds());
    454 
    455   // Try resizing by the bottom left side.
    456   bounds = panel->GetBounds();
    457   mouse_location = bounds.origin() + gfx::Vector2d(1, bounds.height() - 1);
    458   panel_manager->StartResizingByMouse(panel, mouse_location,
    459                                       panel::RESIZE_BOTTOM_LEFT);
    460   mouse_location.Offset(-10, 15);
    461   panel_manager->ResizeByMouse(mouse_location);
    462 
    463   bounds.set_size(gfx::Size(bounds.width() + 10, bounds.height() + 15));
    464   bounds.Offset(-10, 0);
    465   EXPECT_EQ(bounds, panel->GetBounds());
    466 
    467   panel_manager->EndResizingByMouse(true);
    468   EXPECT_EQ(original_bounds, panel->GetBounds());
    469   EXPECT_FALSE(resize_controller->IsResizing());
    470 
    471   panel_manager->CloseAll();
    472 }
    473 
    474 // http://crbug.com/175760; several panel tests failing regularly on mac.
    475 #if defined(OS_MACOSX)
    476 #define MAYBE_ResizeDetachedPanelToTop DISABLED_ResizeDetachedPanelToTop
    477 #else
    478 #define MAYBE_ResizeDetachedPanelToTop ResizeDetachedPanelToTop
    479 #endif
    480 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, MAYBE_ResizeDetachedPanelToTop) {
    481   // Setup the test areas to have top-aligned bar excluded from work area.
    482   const gfx::Rect primary_display_area(0, 0, 800, 600);
    483   const gfx::Rect primary_work_area(0, 10, 800, 590);
    484   mock_display_settings_provider()->SetPrimaryDisplay(
    485       primary_display_area, primary_work_area);
    486 
    487   PanelManager* panel_manager = PanelManager::GetInstance();
    488   Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
    489   gfx::Rect bounds = panel->GetBounds();
    490 
    491   // Try resizing by the top left corner.
    492   gfx::Point mouse_location = bounds.origin();
    493   panel_manager->StartResizingByMouse(panel,
    494                                       mouse_location,
    495                                       panel::RESIZE_TOP_LEFT);
    496 
    497   // Try moving the mouse outside the top of the work area. Expect that panel's
    498   // top position will not exceed the top of the work area.
    499   mouse_location = gfx::Point(250, 2);
    500   panel_manager->ResizeByMouse(mouse_location);
    501 
    502   bounds.set_width(bounds.width() + bounds.x() - mouse_location.x());
    503   bounds.set_height(bounds.height() + bounds.y() - primary_work_area.y());
    504   bounds.set_x(mouse_location.x());
    505   bounds.set_y(primary_work_area.y());
    506   EXPECT_EQ(bounds, panel->GetBounds());
    507 
    508   // Try moving the mouse inside the work area. Expect that the panel can be
    509   // resized without constraint.
    510   mouse_location = gfx::Point(280, 50);
    511   panel_manager->ResizeByMouse(mouse_location);
    512 
    513   bounds.set_width(bounds.width() + bounds.x() - mouse_location.x());
    514   bounds.set_height(bounds.height() + bounds.y() - mouse_location.y());
    515   bounds.set_x(mouse_location.x());
    516   bounds.set_y(mouse_location.y());
    517   EXPECT_EQ(bounds, panel->GetBounds());
    518 
    519   panel_manager->EndResizingByMouse(false);
    520   EXPECT_EQ(bounds, panel->GetBounds());
    521 
    522   panel_manager->CloseAll();
    523 }
    524 
    525 // TODO(jianli): to be enabled for other platforms when stacked panels are
    526 // supported.
    527 #if defined(OS_WIN)
    528 
    529 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeStackedPanels) {
    530   PanelManager* panel_manager = PanelManager::GetInstance();
    531 
    532   // Create 3 stacked panels.
    533   StackedPanelCollection* stack = panel_manager->CreateStack();
    534   gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
    535   Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
    536   gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
    537   Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
    538   gfx::Rect panel3_initial_bounds = gfx::Rect(0, 0, 120, 110);
    539   Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack);
    540   ASSERT_EQ(3, panel_manager->num_panels());
    541   ASSERT_EQ(1, panel_manager->num_stacks());
    542   ASSERT_EQ(3, stack->num_panels());
    543 
    544   gfx::Size panel1_expected_full_size = panel1_initial_bounds.size();
    545   EXPECT_EQ(panel1_expected_full_size, panel1->full_size());
    546   gfx::Size panel2_expected_full_size(panel1_initial_bounds.width(),
    547                                       panel2_initial_bounds.height());
    548   EXPECT_EQ(panel2_expected_full_size, panel2->full_size());
    549   gfx::Size panel3_expected_full_size(panel1_initial_bounds.width(),
    550                                       panel3_initial_bounds.height());
    551   EXPECT_EQ(panel3_expected_full_size, panel3->full_size());
    552 
    553   gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
    554   EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
    555   gfx::Rect panel2_expected_bounds(panel1_expected_bounds.x(),
    556                                    panel1_expected_bounds.bottom(),
    557                                    panel1_expected_bounds.width(),
    558                                    panel2_initial_bounds.height());
    559   EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
    560   gfx::Rect panel3_expected_bounds(panel2_expected_bounds.x(),
    561                                    panel2_expected_bounds.bottom(),
    562                                    panel2_expected_bounds.width(),
    563                                    panel3_initial_bounds.height());
    564   EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
    565 
    566   // Resize by the top-left corner of the top panel.
    567   // Expect that the width of all stacked panels get increased by the same
    568   // amount and the top panel also expands in height.
    569   int top_resize_width = 15;
    570   int top_resize_height = 10;
    571   ResizePanel(panel1,
    572               panel::RESIZE_TOP_LEFT,
    573               gfx::Vector2d(-top_resize_width, -top_resize_height));
    574 
    575   panel1_expected_full_size.Enlarge(top_resize_width, top_resize_height);
    576   EXPECT_EQ(panel1_expected_full_size, panel1->full_size());
    577   panel2_expected_full_size.Enlarge(top_resize_width, 0);
    578   EXPECT_EQ(panel2_expected_full_size, panel2->full_size());
    579   panel3_expected_full_size.Enlarge(top_resize_width, 0);
    580   EXPECT_EQ(panel3_expected_full_size, panel3->full_size());
    581 
    582   panel1_expected_bounds.SetRect(
    583       panel1_expected_bounds.x() - top_resize_width,
    584       panel1_expected_bounds.y() - top_resize_height,
    585       panel1_expected_bounds.width() + top_resize_width,
    586       panel1_expected_bounds.height() + top_resize_height);
    587   EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
    588   panel2_expected_bounds.set_x(panel2_expected_bounds.x() - top_resize_width);
    589   panel2_expected_bounds.set_width(
    590       panel2_expected_bounds.width() + top_resize_width);
    591   EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
    592   panel3_expected_bounds.set_x(panel3_expected_bounds.x() - top_resize_width);
    593   panel3_expected_bounds.set_width(
    594       panel3_expected_bounds.width() + top_resize_width);
    595   EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
    596 
    597   // Resize by the bottom-right corner of the bottom panel.
    598   // Expect that the width of all stacked panels get increased by the same
    599   // amount and the bottom panel also shrinks in height.
    600   int bottom_resize_width = 12;
    601   int bottom_resize_height = 8;
    602   ResizePanel(panel3,
    603               panel::RESIZE_BOTTOM_RIGHT,
    604               gfx::Vector2d(-bottom_resize_width, -bottom_resize_height));
    605 
    606   panel1_expected_full_size.Enlarge(-bottom_resize_width, 0);
    607   EXPECT_EQ(panel1_expected_full_size, panel1->full_size());
    608   panel2_expected_full_size.Enlarge(-bottom_resize_width, 0);
    609   EXPECT_EQ(panel2_expected_full_size, panel2->full_size());
    610   panel3_expected_full_size.Enlarge(-bottom_resize_width,
    611                                     -bottom_resize_height);
    612   EXPECT_EQ(panel3_expected_full_size, panel3->full_size());
    613 
    614   panel1_expected_bounds.set_width(
    615       panel1_expected_bounds.width() - bottom_resize_width);
    616   EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
    617   panel2_expected_bounds.set_width(
    618       panel2_expected_bounds.width() - bottom_resize_width);
    619   EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
    620   panel3_expected_bounds.set_width(
    621       panel3_expected_bounds.width() - bottom_resize_width);
    622   panel3_expected_bounds.set_height(
    623       panel3_expected_bounds.height() - bottom_resize_height);
    624   EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
    625 
    626   // Resize by the bottom edge of the middle panel.
    627   // Expect that the height of the middle panel increases and the height of
    628   // the bottom panel decreases by the same amount.
    629   int middle_resize_height = 5;
    630   ResizePanel(panel2,
    631               panel::RESIZE_BOTTOM,
    632               gfx::Vector2d(0, middle_resize_height));
    633 
    634   EXPECT_EQ(panel1_expected_full_size, panel1->full_size());
    635   panel2_expected_full_size.Enlarge(0, middle_resize_height);
    636   EXPECT_EQ(panel2_expected_full_size, panel2->full_size());
    637   panel3_expected_full_size.Enlarge(0, -middle_resize_height);
    638   EXPECT_EQ(panel3_expected_full_size, panel3->full_size());
    639 
    640   EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
    641   panel2_expected_bounds.set_height(
    642       panel2_expected_bounds.height() + middle_resize_height);
    643   EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
    644   panel3_expected_bounds.set_y(
    645       panel3_expected_bounds.y() + middle_resize_height);
    646   panel3_expected_bounds.set_height(
    647       panel3_expected_bounds.height() - middle_resize_height);
    648   EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
    649 
    650   // Collapse the middle panel.
    651   panel2->Minimize();
    652   WaitForBoundsAnimationFinished(panel2);
    653   EXPECT_TRUE(panel2->IsMinimized());
    654 
    655   EXPECT_EQ(panel1_expected_full_size, panel1->full_size());
    656   EXPECT_EQ(panel2_expected_full_size, panel2->full_size());
    657   EXPECT_EQ(panel3_expected_full_size, panel3->full_size());
    658 
    659   EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
    660   panel2_expected_bounds.set_height(panel2->TitleOnlyHeight());
    661   EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
    662   panel3_expected_bounds.set_y(panel2_expected_bounds.bottom());
    663   EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
    664 
    665   // Resize by the bottom edge of the top panel.
    666   // Expect that the height of the top panel increases and the height of
    667   // the middle panel is not affected because it is collapsed.
    668   top_resize_height = 18;
    669   ResizePanel(panel1,
    670               panel::RESIZE_BOTTOM,
    671               gfx::Vector2d(0, top_resize_height));
    672 
    673   panel1_expected_full_size.Enlarge(0, top_resize_height);
    674   EXPECT_EQ(panel1_expected_full_size, panel1->full_size());
    675   EXPECT_EQ(panel2_expected_full_size, panel2->full_size());
    676   EXPECT_EQ(panel3_expected_full_size, panel3->full_size());
    677 
    678   panel1_expected_bounds.set_height(
    679       panel1_expected_bounds.height() + top_resize_height);
    680   EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
    681   panel2_expected_bounds.set_y(
    682       panel2_expected_bounds.y() + top_resize_height);
    683   EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
    684   panel3_expected_bounds.set_y(
    685       panel3_expected_bounds.y() + top_resize_height);
    686   EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
    687 
    688   panel_manager->CloseAll();
    689 }
    690 
    691 #endif
    692