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