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/ui/panels/base_panel_browser_test.h"
      7 #include "chrome/browser/ui/panels/detached_panel_collection.h"
      8 #include "chrome/browser/ui/panels/native_panel.h"
      9 #include "chrome/browser/ui/panels/panel.h"
     10 #include "chrome/browser/ui/panels/panel_manager.h"
     11 
     12 class DetachedPanelBrowserTest : public BasePanelBrowserTest {
     13 };
     14 
     15 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, CheckDetachedPanelProperties) {
     16   PanelManager* panel_manager = PanelManager::GetInstance();
     17   DetachedPanelCollection* detached_collection =
     18       panel_manager->detached_collection();
     19 
     20   // Create an initially detached panel (as opposed to other tests which create
     21   // a docked panel, then detaches it).
     22   gfx::Rect bounds(300, 200, 250, 200);
     23   CreatePanelParams params("1", bounds, SHOW_AS_ACTIVE);
     24   params.create_mode = PanelManager::CREATE_AS_DETACHED;
     25   Panel* panel = CreatePanelWithParams(params);
     26   scoped_ptr<NativePanelTesting> panel_testing(
     27       CreateNativePanelTesting(panel));
     28 
     29   EXPECT_EQ(1, panel_manager->num_panels());
     30   EXPECT_TRUE(detached_collection->HasPanel(panel));
     31 
     32   EXPECT_EQ(bounds.x(), panel->GetBounds().x());
     33   // Ignore checking y position since the detached panel will be placed near
     34   // the top if the stacking mode is enabled.
     35   if (!PanelManager::IsPanelStackingEnabled())
     36     EXPECT_EQ(bounds.y(), panel->GetBounds().y());
     37   EXPECT_EQ(bounds.width(), panel->GetBounds().width());
     38   EXPECT_EQ(bounds.height(), panel->GetBounds().height());
     39   EXPECT_FALSE(panel->IsAlwaysOnTop());
     40 
     41   EXPECT_TRUE(panel_testing->IsButtonVisible(panel::CLOSE_BUTTON));
     42   // The minimize button will not be shown on some Linux desktop environment
     43   // that does not support system minimize.
     44   if (PanelManager::CanUseSystemMinimize())
     45     EXPECT_TRUE(panel_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
     46   else
     47     EXPECT_FALSE(panel_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
     48   EXPECT_FALSE(panel_testing->IsButtonVisible(panel::RESTORE_BUTTON));
     49 
     50   EXPECT_EQ(panel::RESIZABLE_ALL, panel->CanResizeByMouse());
     51 
     52   EXPECT_EQ(panel::ALL_ROUNDED, panel_testing->GetWindowCornerStyle());
     53 
     54   Panel::AttentionMode expected_attention_mode =
     55       static_cast<Panel::AttentionMode>(Panel::USE_PANEL_ATTENTION |
     56                                          Panel::USE_SYSTEM_ATTENTION);
     57   EXPECT_EQ(expected_attention_mode, panel->attention_mode());
     58 
     59   panel_manager->CloseAll();
     60 }
     61 
     62 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, DrawAttentionOnActive) {
     63   // Create a detached panel that is initially active.
     64   Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
     65   scoped_ptr<NativePanelTesting> native_panel_testing(
     66       CreateNativePanelTesting(panel));
     67 
     68   // Test that the attention should not be drawn if the detached panel is in
     69   // focus.
     70   EXPECT_FALSE(panel->IsDrawingAttention());
     71   panel->FlashFrame(true);
     72   EXPECT_FALSE(panel->IsDrawingAttention());
     73   EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
     74 
     75   panel->Close();
     76 }
     77 
     78 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, DrawAttentionOnInactive) {
     79   // Create an inactive detached panel.
     80   Panel* panel =
     81       CreateInactiveDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
     82   scoped_ptr<NativePanelTesting> native_panel_testing(
     83       CreateNativePanelTesting(panel));
     84 
     85   // Test that the attention is drawn when the detached panel is not in focus.
     86   EXPECT_FALSE(panel->IsActive());
     87   EXPECT_FALSE(panel->IsDrawingAttention());
     88   panel->FlashFrame(true);
     89   EXPECT_TRUE(panel->IsDrawingAttention());
     90   EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
     91 
     92   // Stop drawing attention.
     93   panel->FlashFrame(false);
     94   EXPECT_FALSE(panel->IsDrawingAttention());
     95   EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
     96 
     97   PanelManager::GetInstance()->CloseAll();
     98 }
     99 
    100 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, DrawAttentionResetOnActivate) {
    101   // Create an inactive detached panel.
    102   Panel* panel =
    103       CreateInactiveDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
    104   scoped_ptr<NativePanelTesting> native_panel_testing(
    105       CreateNativePanelTesting(panel));
    106 
    107   // Test that the attention is drawn when the detached panel is not in focus.
    108   panel->FlashFrame(true);
    109   EXPECT_TRUE(panel->IsDrawingAttention());
    110   EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
    111 
    112   // Test that the attention is cleared when panel gets focus.
    113   panel->Activate();
    114   WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
    115   EXPECT_FALSE(panel->IsDrawingAttention());
    116   EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
    117 
    118   PanelManager::GetInstance()->CloseAll();
    119 }
    120 
    121 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, ClickTitlebar) {
    122   Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
    123   EXPECT_FALSE(panel->IsMinimized());
    124 
    125   // Clicking on an active detached panel's titlebar has no effect, regardless
    126   // of modifier.
    127   scoped_ptr<NativePanelTesting> test_panel(
    128       CreateNativePanelTesting(panel));
    129   test_panel->PressLeftMouseButtonTitlebar(panel->GetBounds().origin());
    130   test_panel->ReleaseMouseButtonTitlebar();
    131   EXPECT_TRUE(panel->IsActive());
    132   EXPECT_FALSE(panel->IsMinimized());
    133 
    134   test_panel->PressLeftMouseButtonTitlebar(panel->GetBounds().origin(),
    135                                            panel::APPLY_TO_ALL);
    136   test_panel->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
    137   EXPECT_TRUE(panel->IsActive());
    138   EXPECT_FALSE(panel->IsMinimized());
    139 
    140   // Clicking on an inactive detached panel's titlebar activates it.
    141   DeactivatePanel(panel);
    142   test_panel->PressLeftMouseButtonTitlebar(panel->GetBounds().origin());
    143   test_panel->ReleaseMouseButtonTitlebar();
    144   WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
    145   EXPECT_FALSE(panel->IsMinimized());
    146 
    147   PanelManager::GetInstance()->CloseAll();
    148 }
    149 
    150 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest,
    151                        UpdateDetachedPanelOnPrimaryDisplayChange) {
    152   PanelManager* panel_manager = PanelManager::GetInstance();
    153 
    154   // Create a big detached panel on the primary display.
    155   gfx::Rect initial_bounds(50, 50, 700, 500);
    156   Panel* panel = CreateDetachedPanel("1", initial_bounds);
    157   EXPECT_EQ(initial_bounds, panel->GetBounds());
    158 
    159   // Make the primary display smaller.
    160   // Expect that the panel should be resized to fit within the display.
    161   gfx::Rect primary_display_area(0, 0, 500, 300);
    162   gfx::Rect primary_work_area(0, 0, 500, 280);
    163   mock_display_settings_provider()->SetPrimaryDisplay(
    164       primary_display_area, primary_work_area);
    165 
    166   gfx::Rect bounds = panel->GetBounds();
    167   EXPECT_LE(primary_work_area.x(), bounds.x());
    168   EXPECT_LE(bounds.x(), primary_work_area.right());
    169   EXPECT_LE(primary_work_area.y(), bounds.y());
    170   EXPECT_LE(bounds.y(), primary_work_area.bottom());
    171 
    172   panel_manager->CloseAll();
    173 }
    174 
    175 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest,
    176                        UpdateDetachedPanelOnSecondaryDisplayChange) {
    177   PanelManager* panel_manager = PanelManager::GetInstance();
    178 
    179   // Setup 2 displays with secondary display on the right side of primary
    180   // display.
    181   gfx::Rect primary_display_area(0, 0, 400, 600);
    182   gfx::Rect primary_work_area(0, 0, 400, 560);
    183   mock_display_settings_provider()->SetPrimaryDisplay(
    184       primary_display_area, primary_work_area);
    185   gfx::Rect secondary_display_area(400, 0, 400, 500);
    186   gfx::Rect secondary_work_area(400, 0, 400, 460);
    187   mock_display_settings_provider()->SetSecondaryDisplay(
    188       secondary_display_area, secondary_work_area);
    189 
    190   // Create a big detached panel on the seconday display.
    191   gfx::Rect initial_bounds(450, 50, 350, 400);
    192   Panel* panel = CreateDetachedPanel("1", initial_bounds);
    193   EXPECT_EQ(initial_bounds, panel->GetBounds());
    194 
    195   // Move down the secondary display and make it smaller.
    196   // Expect that the panel should be resized to fit within the display.
    197   secondary_display_area.SetRect(400, 100, 300, 400);
    198   secondary_work_area.SetRect(400, 100, 300, 360);
    199   mock_display_settings_provider()->SetSecondaryDisplay(
    200       secondary_display_area, secondary_work_area);
    201 
    202   gfx::Rect bounds = panel->GetBounds();
    203   EXPECT_LE(secondary_work_area.x(), bounds.x());
    204   EXPECT_LE(bounds.x(), secondary_work_area.right());
    205   EXPECT_LE(secondary_work_area.y(), bounds.y());
    206   EXPECT_LE(bounds.y(), secondary_work_area.bottom());
    207 
    208   panel_manager->CloseAll();
    209 }
    210