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 "ash/test/test_shell_delegate.h" 6 7 #include <limits> 8 9 #include "ash/default_accessibility_delegate.h" 10 #include "ash/gpu_support_stub.h" 11 #include "ash/media_delegate.h" 12 #include "ash/new_window_delegate.h" 13 #include "ash/session/session_state_delegate.h" 14 #include "ash/shell.h" 15 #include "ash/shell/keyboard_controller_proxy_stub.h" 16 #include "ash/shell_window_ids.h" 17 #include "ash/test/test_session_state_delegate.h" 18 #include "ash/test/test_shelf_delegate.h" 19 #include "ash/test/test_system_tray_delegate.h" 20 #include "ash/test/test_user_wallpaper_delegate.h" 21 #include "ash/wm/window_state.h" 22 #include "ash/wm/window_util.h" 23 #include "base/logging.h" 24 #include "content/public/test/test_browser_context.h" 25 #include "ui/app_list/app_list_model.h" 26 #include "ui/app_list/app_list_view_delegate.h" 27 #include "ui/app_list/test/app_list_test_view_delegate.h" 28 #include "ui/aura/window.h" 29 30 #if defined(OS_CHROMEOS) 31 #include "ash/system/tray/system_tray_notifier.h" 32 #endif 33 34 namespace ash { 35 namespace test { 36 namespace { 37 38 class NewWindowDelegateImpl : public NewWindowDelegate { 39 public: NewWindowDelegateImpl()40 NewWindowDelegateImpl() {} ~NewWindowDelegateImpl()41 virtual ~NewWindowDelegateImpl() {} 42 43 private: 44 // NewWindowDelegate: NewTab()45 virtual void NewTab() OVERRIDE {} NewWindow(bool incognito)46 virtual void NewWindow(bool incognito) OVERRIDE {} OpenFileManager()47 virtual void OpenFileManager() OVERRIDE {} OpenCrosh()48 virtual void OpenCrosh() OVERRIDE {} RestoreTab()49 virtual void RestoreTab() OVERRIDE {} ShowKeyboardOverlay()50 virtual void ShowKeyboardOverlay() OVERRIDE {} ShowTaskManager()51 virtual void ShowTaskManager() OVERRIDE {} OpenFeedbackPage()52 virtual void OpenFeedbackPage() OVERRIDE {} 53 54 DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl); 55 }; 56 57 class MediaDelegateImpl : public MediaDelegate { 58 public: MediaDelegateImpl()59 MediaDelegateImpl() : state_(MEDIA_CAPTURE_NONE) {} ~MediaDelegateImpl()60 virtual ~MediaDelegateImpl() {} 61 set_media_capture_state(MediaCaptureState state)62 void set_media_capture_state(MediaCaptureState state) { state_ = state; } 63 64 private: 65 // MediaDelegate: HandleMediaNextTrack()66 virtual void HandleMediaNextTrack() OVERRIDE {} HandleMediaPlayPause()67 virtual void HandleMediaPlayPause() OVERRIDE {} HandleMediaPrevTrack()68 virtual void HandleMediaPrevTrack() OVERRIDE {} GetMediaCaptureState(content::BrowserContext * context)69 virtual MediaCaptureState GetMediaCaptureState( 70 content::BrowserContext* context) OVERRIDE { 71 return state_; 72 } 73 74 MediaCaptureState state_; 75 76 DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl); 77 }; 78 79 } // namespace 80 TestShellDelegate()81TestShellDelegate::TestShellDelegate() 82 : num_exit_requests_(0), 83 multi_profiles_enabled_(false), 84 test_session_state_delegate_(NULL) { 85 } 86 ~TestShellDelegate()87TestShellDelegate::~TestShellDelegate() { 88 } 89 IsFirstRunAfterBoot() const90bool TestShellDelegate::IsFirstRunAfterBoot() const { 91 return false; 92 } 93 IsIncognitoAllowed() const94bool TestShellDelegate::IsIncognitoAllowed() const { 95 return true; 96 } 97 IsMultiProfilesEnabled() const98bool TestShellDelegate::IsMultiProfilesEnabled() const { 99 return multi_profiles_enabled_; 100 } 101 IsRunningInForcedAppMode() const102bool TestShellDelegate::IsRunningInForcedAppMode() const { 103 return false; 104 } 105 IsMultiAccountEnabled() const106bool TestShellDelegate::IsMultiAccountEnabled() const { 107 return false; 108 } 109 PreInit()110void TestShellDelegate::PreInit() { 111 } 112 PreShutdown()113void TestShellDelegate::PreShutdown() { 114 } 115 Exit()116void TestShellDelegate::Exit() { 117 num_exit_requests_++; 118 } 119 120 keyboard::KeyboardControllerProxy* CreateKeyboardControllerProxy()121 TestShellDelegate::CreateKeyboardControllerProxy() { 122 return new KeyboardControllerProxyStub(); 123 } 124 VirtualKeyboardActivated(bool activated)125void TestShellDelegate::VirtualKeyboardActivated(bool activated) { 126 FOR_EACH_OBSERVER(ash::VirtualKeyboardStateObserver, 127 keyboard_state_observer_list_, 128 OnVirtualKeyboardStateChanged(activated)); 129 } 130 AddVirtualKeyboardStateObserver(VirtualKeyboardStateObserver * observer)131void TestShellDelegate::AddVirtualKeyboardStateObserver( 132 VirtualKeyboardStateObserver* observer) { 133 keyboard_state_observer_list_.AddObserver(observer); 134 } 135 RemoveVirtualKeyboardStateObserver(VirtualKeyboardStateObserver * observer)136void TestShellDelegate::RemoveVirtualKeyboardStateObserver( 137 VirtualKeyboardStateObserver* observer) { 138 keyboard_state_observer_list_.RemoveObserver(observer); 139 } 140 GetActiveBrowserContext()141content::BrowserContext* TestShellDelegate::GetActiveBrowserContext() { 142 active_browser_context_.reset(new content::TestBrowserContext()); 143 return active_browser_context_.get(); 144 } 145 GetAppListViewDelegate()146app_list::AppListViewDelegate* TestShellDelegate::GetAppListViewDelegate() { 147 if (!app_list_view_delegate_) 148 app_list_view_delegate_.reset(new app_list::test::AppListTestViewDelegate); 149 return app_list_view_delegate_.get(); 150 } 151 CreateShelfDelegate(ShelfModel * model)152ShelfDelegate* TestShellDelegate::CreateShelfDelegate(ShelfModel* model) { 153 return new TestShelfDelegate(model); 154 } 155 CreateSystemTrayDelegate()156SystemTrayDelegate* TestShellDelegate::CreateSystemTrayDelegate() { 157 return new TestSystemTrayDelegate; 158 } 159 CreateUserWallpaperDelegate()160UserWallpaperDelegate* TestShellDelegate::CreateUserWallpaperDelegate() { 161 return new TestUserWallpaperDelegate(); 162 } 163 CreateSessionStateDelegate()164SessionStateDelegate* TestShellDelegate::CreateSessionStateDelegate() { 165 DCHECK(!test_session_state_delegate_); 166 test_session_state_delegate_ = new TestSessionStateDelegate(); 167 return test_session_state_delegate_; 168 } 169 CreateAccessibilityDelegate()170AccessibilityDelegate* TestShellDelegate::CreateAccessibilityDelegate() { 171 return new DefaultAccessibilityDelegate(); 172 } 173 CreateNewWindowDelegate()174NewWindowDelegate* TestShellDelegate::CreateNewWindowDelegate() { 175 return new NewWindowDelegateImpl; 176 } 177 CreateMediaDelegate()178MediaDelegate* TestShellDelegate::CreateMediaDelegate() { 179 return new MediaDelegateImpl; 180 } 181 CreateContextMenu(aura::Window * root,ash::ShelfItemDelegate * item_delegate,ash::ShelfItem * item)182ui::MenuModel* TestShellDelegate::CreateContextMenu( 183 aura::Window* root, 184 ash::ShelfItemDelegate* item_delegate, 185 ash::ShelfItem* item) { 186 return NULL; 187 } 188 CreateGPUSupport()189GPUSupport* TestShellDelegate::CreateGPUSupport() { 190 // Real GPU support depends on src/content, so just use a stub. 191 return new GPUSupportStub; 192 } 193 GetProductName() const194base::string16 TestShellDelegate::GetProductName() const { 195 return base::string16(); 196 } 197 SetMediaCaptureState(MediaCaptureState state)198void TestShellDelegate::SetMediaCaptureState(MediaCaptureState state) { 199 #if defined(OS_CHROMEOS) 200 Shell* shell = Shell::GetInstance(); 201 static_cast<MediaDelegateImpl*>(shell->media_delegate()) 202 ->set_media_capture_state(state); 203 shell->system_tray_notifier()->NotifyMediaCaptureChanged(); 204 #endif 205 } 206 207 } // namespace test 208 } // namespace ash 209