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 #ifndef CHROME_BROWSER_UI_PANELS_BASE_PANEL_BROWSER_TEST_H_
      6 #define CHROME_BROWSER_UI_PANELS_BASE_PANEL_BROWSER_TEST_H_
      7 
      8 #include "base/memory/ref_counted.h"
      9 #include "base/values.h"
     10 #include "chrome/browser/ui/panels/display_settings_provider.h"
     11 #include "chrome/browser/ui/panels/panel.h"
     12 #include "chrome/browser/ui/panels/panel_manager.h"
     13 #include "chrome/test/base/in_process_browser_test.h"
     14 #include "extensions/common/extension.h"
     15 #include "extensions/common/manifest.h"
     16 #include "ui/gfx/rect.h"
     17 
     18 class NativePanelTesting;
     19 class StackedPanelCollection;
     20 
     21 class BasePanelBrowserTest : public InProcessBrowserTest {
     22  public:
     23   class MockDisplaySettingsProvider : public DisplaySettingsProvider {
     24    public:
     25     MockDisplaySettingsProvider() { }
     26     virtual ~MockDisplaySettingsProvider() { }
     27 
     28     virtual void SetPrimaryDisplay(
     29         const gfx::Rect& display_area, const gfx::Rect& work_area) = 0;
     30     virtual void SetSecondaryDisplay(
     31         const gfx::Rect& display_area, const gfx::Rect& work_area) = 0;
     32     virtual void EnableAutoHidingDesktopBar(DesktopBarAlignment alignment,
     33                                             bool enabled,
     34                                             int thickness) = 0;
     35     virtual void SetDesktopBarVisibility(DesktopBarAlignment alignment,
     36                                          DesktopBarVisibility visibility) = 0;
     37     virtual void SetDesktopBarThickness(DesktopBarAlignment alignment,
     38                                         int thickness) = 0;
     39     virtual void EnableFullScreenMode(bool enabled) = 0;
     40   };
     41 
     42   BasePanelBrowserTest();
     43   virtual ~BasePanelBrowserTest();
     44 
     45   // Linux bots use icewm which activate windows in ways that break
     46   // certain panel tests. Skip those tests when running on the bots.
     47   // We do not disable the tests to make it easy for developers to run
     48   // them locally. [Icewm always activates a window when shown.]
     49   bool SkipTestIfIceWM();
     50 
     51   // Gnome running compiz refuses to activate a window that was initially
     52   // created as inactive, causing certain panel tests to fail. These tests
     53   // pass fine on the bots, but fail for developers as Gnome running compiz
     54   // is the typical linux dev machine configuration. We do not disable the
     55   // tests to ensure we still have coverage on the bots.
     56   bool SkipTestIfCompizWM();
     57 
     58   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
     59   virtual void SetUpOnMainThread() OVERRIDE;
     60 
     61  protected:
     62   enum ActiveState { SHOW_AS_ACTIVE, SHOW_AS_INACTIVE };
     63 
     64   struct CreatePanelParams {
     65     std::string name;
     66     gfx::Rect bounds;
     67     ActiveState show_flag;
     68     GURL url;
     69     bool wait_for_fully_created;
     70     ActiveState expected_active_state;
     71     PanelManager::CreateMode create_mode;
     72     Profile* profile;
     73 
     74     CreatePanelParams(const std::string& name,
     75                       const gfx::Rect& bounds,
     76                       ActiveState show_flag);
     77   };
     78 
     79   Panel* CreatePanelWithParams(const CreatePanelParams& params);
     80   Panel* CreatePanelWithBounds(const std::string& panel_name,
     81                                const gfx::Rect& bounds);
     82   Panel* CreatePanel(const std::string& panel_name);
     83 
     84   Panel* CreateDockedPanel(const std::string& name, const gfx::Rect& bounds);
     85   Panel* CreateDetachedPanel(const std::string& name, const gfx::Rect& bounds);
     86   Panel* CreateStackedPanel(const std::string& name,
     87                             const gfx::Rect& bounds,
     88                             StackedPanelCollection* stack);
     89 
     90   Panel* CreateInactivePanel(const std::string& name);
     91   Panel* CreateInactiveDockedPanel(const std::string& name,
     92                                    const gfx::Rect& bounds);
     93   Panel* CreateInactiveDetachedPanel(const std::string& name,
     94                                      const gfx::Rect& bounds);
     95 
     96   void ActivatePanel(Panel* panel);
     97   void DeactivatePanel(Panel* panel);
     98 
     99   static NativePanelTesting* CreateNativePanelTesting(Panel* panel);
    100 
    101   void WaitForPanelActiveState(Panel* panel, ActiveState state);
    102   void WaitForWindowSizeAvailable(Panel* panel);
    103   void WaitForBoundsAnimationFinished(Panel* panel);
    104 
    105   scoped_refptr<extensions::Extension> CreateExtension(
    106       const base::FilePath::StringType& path,
    107       extensions::Manifest::Location location,
    108       const DictionaryValue& extra_value);
    109 
    110   void MoveMouseAndWaitForExpansionStateChange(Panel* panel,
    111                                                const gfx::Point& position);
    112   static void MoveMouse(const gfx::Point& position);
    113   void CloseWindowAndWait(Panel* panel);
    114   static std::string MakePanelName(int index);
    115 
    116   // Checks if the WM supports activation. This may not be true sometimes on
    117   // buildbots for example when the wm has crashed.
    118   static bool WmSupportWindowActivation();
    119 
    120   MockDisplaySettingsProvider* mock_display_settings_provider() const {
    121     return mock_display_settings_provider_;
    122   }
    123 
    124   // Some tests might not want to use the mock version.
    125   void disable_display_settings_mock() {
    126     mock_display_settings_enabled_ = false;
    127   }
    128 
    129   static const base::FilePath::CharType* kTestDir;
    130 
    131  private:
    132   // Passed to and owned by PanelManager.
    133   MockDisplaySettingsProvider* mock_display_settings_provider_;
    134 
    135   bool mock_display_settings_enabled_;
    136 };
    137 
    138 #endif  // CHROME_BROWSER_UI_PANELS_BASE_PANEL_BROWSER_TEST_H_
    139