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 "base/message_loop/message_loop.h"
      6 #include "chrome/browser/chrome_notification_types.h"
      7 #include "chrome/browser/ui/panels/base_panel_browser_test.h"
      8 #include "chrome/browser/ui/panels/docked_panel_collection.h"
      9 #include "chrome/browser/ui/panels/panel.h"
     10 #include "chrome/browser/ui/panels/panel_manager.h"
     11 #include "chrome/browser/ui/panels/test_panel_collection_squeeze_observer.h"
     12 #include "content/public/browser/notification_service.h"
     13 #include "content/public/test/test_utils.h"
     14 
     15 class DockedPanelBrowserTest : public BasePanelBrowserTest {
     16  public:
     17   virtual void SetUpOnMainThread() OVERRIDE {
     18     BasePanelBrowserTest::SetUpOnMainThread();
     19 
     20     // All the tests here assume using mocked 800x600 display area for the
     21     // primary monitor. Do the check now.
     22     gfx::Rect primary_display_area = PanelManager::GetInstance()->
     23         display_settings_provider()->GetPrimaryDisplayArea();
     24     DCHECK(primary_display_area.width() == 800);
     25     DCHECK(primary_display_area.height() == 600);
     26   }
     27 };
     28 
     29 // http://crbug.com/143247
     30 #if !defined(OS_WIN)
     31 #define MAYBE_SqueezePanelsInDock DISABLED_SqueezePanelsInDock
     32 #else
     33 #define MAYBE_SqueezePanelsInDock SqueezePanelsInDock
     34 #endif
     35 IN_PROC_BROWSER_TEST_F(DockedPanelBrowserTest, MAYBE_SqueezePanelsInDock) {
     36   PanelManager* panel_manager = PanelManager::GetInstance();
     37   DockedPanelCollection* docked_collection = panel_manager->docked_collection();
     38 
     39   // Create some docked panels.
     40   Panel* panel1 = CreateInactiveDockedPanel("1", gfx::Rect(0, 0, 200, 100));
     41   Panel* panel2 = CreateInactiveDockedPanel("2", gfx::Rect(0, 0, 200, 100));
     42   Panel* panel3 = CreateInactiveDockedPanel("3", gfx::Rect(0, 0, 200, 100));
     43   ASSERT_EQ(3, docked_collection->num_panels());
     44 
     45   // Check that nothing has been squeezed so far.
     46   EXPECT_EQ(panel1->GetBounds().width(), panel1->GetRestoredBounds().width());
     47   EXPECT_EQ(panel2->GetBounds().width(), panel2->GetRestoredBounds().width());
     48   EXPECT_EQ(panel3->GetBounds().width(), panel3->GetRestoredBounds().width());
     49 
     50   // Create more panels so they start getting squeezed.
     51   Panel* panel4 = CreateInactiveDockedPanel("4", gfx::Rect(0, 0, 200, 100));
     52   Panel* panel5 = CreateInactiveDockedPanel("5", gfx::Rect(0, 0, 200, 100));
     53   Panel* panel6 = CreateInactiveDockedPanel("6", gfx::Rect(0, 0, 200, 100));
     54   Panel* panel7 = CreateDockedPanel("7", gfx::Rect(0, 0, 200, 100));
     55 
     56   // Wait for active states to settle.
     57   PanelCollectionSqueezeObserver panel7_settled(docked_collection, panel7);
     58   panel7_settled.Wait();
     59 
     60   // The active panel should be at full width.
     61   EXPECT_EQ(panel7->GetBounds().width(), panel7->GetRestoredBounds().width());
     62   EXPECT_GT(panel7->GetBounds().x(), docked_collection->work_area().x());
     63 
     64   // The rest of them should be at reduced width.
     65   EXPECT_LT(panel1->GetBounds().width(), panel1->GetRestoredBounds().width());
     66   EXPECT_LT(panel2->GetBounds().width(), panel2->GetRestoredBounds().width());
     67   EXPECT_LT(panel3->GetBounds().width(), panel3->GetRestoredBounds().width());
     68   EXPECT_LT(panel4->GetBounds().width(), panel4->GetRestoredBounds().width());
     69   EXPECT_LT(panel5->GetBounds().width(), panel5->GetRestoredBounds().width());
     70   EXPECT_LT(panel6->GetBounds().width(), panel6->GetRestoredBounds().width());
     71 
     72   // Activate a different panel.
     73   ActivatePanel(panel2);
     74   WaitForPanelActiveState(panel2, SHOW_AS_ACTIVE);
     75 
     76   // Wait for active states to settle.
     77   PanelCollectionSqueezeObserver panel2_settled(docked_collection, panel2);
     78   panel2_settled.Wait();
     79 
     80   // The active panel should be at full width.
     81   EXPECT_EQ(panel2->GetBounds().width(), panel2->GetRestoredBounds().width());
     82 
     83   // The rest of them should be at reduced width.
     84   EXPECT_LT(panel1->GetBounds().width(), panel1->GetRestoredBounds().width());
     85   EXPECT_LT(panel3->GetBounds().width(), panel3->GetRestoredBounds().width());
     86   EXPECT_LT(panel4->GetBounds().width(), panel4->GetRestoredBounds().width());
     87   EXPECT_LT(panel5->GetBounds().width(), panel5->GetRestoredBounds().width());
     88   EXPECT_LT(panel6->GetBounds().width(), panel6->GetRestoredBounds().width());
     89   EXPECT_LT(panel7->GetBounds().width(), panel7->GetRestoredBounds().width());
     90 
     91   panel_manager->CloseAll();
     92 }
     93 
     94 IN_PROC_BROWSER_TEST_F(DockedPanelBrowserTest, SqueezeAndThenSomeMore) {
     95   PanelManager* panel_manager = PanelManager::GetInstance();
     96   DockedPanelCollection* docked_collection = panel_manager->docked_collection();
     97 
     98   // Create enough docked panels to get into squeezing.
     99   Panel* panel1 = CreateInactiveDockedPanel("1", gfx::Rect(0, 0, 200, 100));
    100   Panel* panel2 = CreateInactiveDockedPanel("2", gfx::Rect(0, 0, 200, 100));
    101   Panel* panel3 = CreateInactiveDockedPanel("3", gfx::Rect(0, 0, 200, 100));
    102   Panel* panel4 = CreateInactiveDockedPanel("4", gfx::Rect(0, 0, 200, 100));
    103   Panel* panel5 = CreateInactiveDockedPanel("5", gfx::Rect(0, 0, 200, 100));
    104   Panel* panel6 = CreateInactiveDockedPanel("6", gfx::Rect(0, 0, 200, 100));
    105 
    106   // Wait for active states to settle.
    107   PanelCollectionSqueezeObserver panel6_settled(docked_collection, panel6);
    108   panel6_settled.Wait();
    109 
    110   // Record current widths of some panels.
    111   int panel_1_width_less_squeezed = panel1->GetBounds().width();
    112   int panel_2_width_less_squeezed = panel2->GetBounds().width();
    113   int panel_3_width_less_squeezed = panel3->GetBounds().width();
    114   int panel_4_width_less_squeezed = panel4->GetBounds().width();
    115   int panel_5_width_less_squeezed = panel5->GetBounds().width();
    116 
    117   // These widths should be reduced.
    118   EXPECT_LT(panel_1_width_less_squeezed, panel1->GetRestoredBounds().width());
    119   EXPECT_LT(panel_2_width_less_squeezed, panel2->GetRestoredBounds().width());
    120   EXPECT_LT(panel_3_width_less_squeezed, panel3->GetRestoredBounds().width());
    121   EXPECT_LT(panel_4_width_less_squeezed, panel4->GetRestoredBounds().width());
    122   EXPECT_LT(panel_5_width_less_squeezed, panel5->GetRestoredBounds().width());
    123 
    124   Panel* panel7 = CreateDockedPanel("7", gfx::Rect(0, 0, 200, 100));
    125 
    126   // Wait for active states to settle.
    127   PanelCollectionSqueezeObserver panel7_settled(docked_collection, panel7);
    128   panel7_settled.Wait();
    129 
    130   // The active panel should be at full width.
    131   EXPECT_EQ(panel7->GetBounds().width(), panel7->GetRestoredBounds().width());
    132 
    133   // The panels should shrink in width.
    134   EXPECT_LT(panel1->GetBounds().width(), panel_1_width_less_squeezed);
    135   EXPECT_LT(panel2->GetBounds().width(), panel_2_width_less_squeezed);
    136   EXPECT_LT(panel3->GetBounds().width(), panel_3_width_less_squeezed);
    137   EXPECT_LT(panel4->GetBounds().width(), panel_4_width_less_squeezed);
    138   EXPECT_LT(panel5->GetBounds().width(), panel_5_width_less_squeezed);
    139 
    140   panel_manager->CloseAll();
    141 }
    142 
    143 IN_PROC_BROWSER_TEST_F(DockedPanelBrowserTest, MinimizeSqueezedActive) {
    144   PanelManager* panel_manager = PanelManager::GetInstance();
    145   DockedPanelCollection* docked_collection = panel_manager->docked_collection();
    146 
    147   // Create enough docked panels to get into squeezing.
    148   Panel* panel1 = CreateInactiveDockedPanel("1", gfx::Rect(0, 0, 200, 100));
    149   Panel* panel2 = CreateInactiveDockedPanel("2", gfx::Rect(0, 0, 200, 100));
    150   Panel* panel3 = CreateInactiveDockedPanel("3", gfx::Rect(0, 0, 200, 100));
    151   Panel* panel4 = CreateInactiveDockedPanel("4", gfx::Rect(0, 0, 200, 100));
    152   Panel* panel5 = CreateInactiveDockedPanel("5", gfx::Rect(0, 0, 200, 100));
    153   Panel* panel6 = CreateInactiveDockedPanel("6", gfx::Rect(0, 0, 200, 100));
    154   Panel* panel7 = CreateDockedPanel("7", gfx::Rect(0, 0, 200, 100));
    155 
    156   // Wait for active states to settle.
    157   PanelCollectionSqueezeObserver panel7_settled(docked_collection, panel7);
    158   panel7_settled.Wait();
    159 
    160   // The active panel should be at full width.
    161   EXPECT_EQ(panel7->GetBounds().width(), panel7->GetRestoredBounds().width());
    162 
    163   // The rest of them should be at reduced width.
    164   EXPECT_LT(panel1->GetBounds().width(), panel1->GetRestoredBounds().width());
    165   EXPECT_LT(panel2->GetBounds().width(), panel2->GetRestoredBounds().width());
    166   EXPECT_LT(panel3->GetBounds().width(), panel3->GetRestoredBounds().width());
    167   EXPECT_LT(panel4->GetBounds().width(), panel4->GetRestoredBounds().width());
    168   EXPECT_LT(panel5->GetBounds().width(), panel5->GetRestoredBounds().width());
    169   EXPECT_LT(panel6->GetBounds().width(), panel6->GetRestoredBounds().width());
    170 
    171   // Record the width of an inactive panel and minimize it.
    172   int width_of_panel3_squeezed = panel3->GetBounds().width();
    173   panel3->Minimize();
    174 
    175   // Check that this panel is still at the same width.
    176   EXPECT_EQ(width_of_panel3_squeezed, panel3->GetBounds().width());
    177 
    178   // Minimize the active panel. It should become inactive and shrink in width.
    179   content::WindowedNotificationObserver signal(
    180       chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED,
    181       content::NotificationService::AllSources());
    182   panel7->Minimize();
    183 
    184   // Wait for active states to settle.
    185   WaitForPanelActiveState(panel7, SHOW_AS_INACTIVE);
    186 
    187   // Wait for the scheduled layout to run.
    188   signal.Wait();
    189 
    190   // The minimized panel should now be at reduced width.
    191   EXPECT_LT(panel7->GetBounds().width(), panel7->GetRestoredBounds().width());
    192 
    193   panel_manager->CloseAll();
    194 }
    195 
    196 IN_PROC_BROWSER_TEST_F(DockedPanelBrowserTest, CloseSqueezedPanels) {
    197   PanelManager* panel_manager = PanelManager::GetInstance();
    198   DockedPanelCollection* docked_collection = panel_manager->docked_collection();
    199 
    200   // Create enough docked panels to get into squeezing.
    201   Panel* panel1 = CreateInactiveDockedPanel("1", gfx::Rect(0, 0, 200, 100));
    202   Panel* panel2 = CreateInactiveDockedPanel("2", gfx::Rect(0, 0, 200, 100));
    203   Panel* panel3 = CreateInactiveDockedPanel("3", gfx::Rect(0, 0, 200, 100));
    204   Panel* panel4 = CreateInactiveDockedPanel("4", gfx::Rect(0, 0, 200, 100));
    205   Panel* panel5 = CreateInactiveDockedPanel("5", gfx::Rect(0, 0, 200, 100));
    206   Panel* panel6 = CreateInactiveDockedPanel("6", gfx::Rect(0, 0, 200, 100));
    207   Panel* panel7 = CreateDockedPanel("7", gfx::Rect(0, 0, 200, 100));
    208 
    209   // Wait for active states to settle.
    210   PanelCollectionSqueezeObserver panel7_settled(docked_collection, panel7);
    211   panel7_settled.Wait();
    212 
    213   // Record current widths of some panels.
    214   int panel_1_orig_width = panel1->GetBounds().width();
    215   int panel_2_orig_width = panel2->GetBounds().width();
    216   int panel_3_orig_width = panel3->GetBounds().width();
    217   int panel_4_orig_width = panel4->GetBounds().width();
    218   int panel_5_orig_width = panel5->GetBounds().width();
    219   int panel_6_orig_width = panel6->GetBounds().width();
    220   int panel_7_orig_width = panel7->GetBounds().width();
    221 
    222   // The active panel should be at full width.
    223   EXPECT_EQ(panel_7_orig_width, panel7->GetRestoredBounds().width());
    224 
    225   // The rest of them should be at reduced width.
    226   EXPECT_LT(panel_1_orig_width, panel1->GetRestoredBounds().width());
    227   EXPECT_LT(panel_2_orig_width, panel2->GetRestoredBounds().width());
    228   EXPECT_LT(panel_3_orig_width, panel3->GetRestoredBounds().width());
    229   EXPECT_LT(panel_4_orig_width, panel4->GetRestoredBounds().width());
    230   EXPECT_LT(panel_5_orig_width, panel5->GetRestoredBounds().width());
    231   EXPECT_LT(panel_6_orig_width, panel6->GetRestoredBounds().width());
    232 
    233   // Close one panel.
    234   content::WindowedNotificationObserver signal(
    235       chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED,
    236       content::NotificationService::AllSources());
    237   CloseWindowAndWait(panel2);
    238   signal.Wait();
    239 
    240   // The widths of the remaining panels should have increased.
    241   EXPECT_GT(panel1->GetBounds().width(), panel_1_orig_width);
    242   EXPECT_GT(panel3->GetBounds().width(), panel_3_orig_width);
    243   EXPECT_GT(panel4->GetBounds().width(), panel_4_orig_width);
    244   EXPECT_GT(panel5->GetBounds().width(), panel_5_orig_width);
    245   EXPECT_GT(panel6->GetBounds().width(), panel_6_orig_width);
    246 
    247   // The active panel should have stayed at full width.
    248   EXPECT_EQ(panel7->GetBounds().width(), panel_7_orig_width);
    249 
    250   // Close several panels.
    251   CloseWindowAndWait(panel3);
    252   CloseWindowAndWait(panel5);
    253 
    254   // Wait for collection update after last close.
    255   content::WindowedNotificationObserver signal2(
    256       chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED,
    257       content::NotificationService::AllSources());
    258   CloseWindowAndWait(panel7);
    259   signal2.Wait();
    260 
    261   // We should not have squeezing any more; all panels should be at full width.
    262   EXPECT_EQ(panel1->GetBounds().width(), panel1->GetRestoredBounds().width());
    263   EXPECT_EQ(panel4->GetBounds().width(), panel4->GetRestoredBounds().width());
    264   EXPECT_EQ(panel6->GetBounds().width(), panel6->GetRestoredBounds().width());
    265 
    266   panel_manager->CloseAll();
    267 }
    268