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.
5 #include "ash/test/test_shell_delegate.h"
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"
30 #if defined(OS_CHROMEOS)
31 #include "ash/system/tray/system_tray_notifier.h"
38 class NewWindowDelegateImpl
: public NewWindowDelegate
{
40 NewWindowDelegateImpl() {}
41 ~NewWindowDelegateImpl() override
{}
45 void NewTab() override
{}
46 void NewWindow(bool incognito
) override
{}
47 void OpenFileManager() override
{}
48 void OpenCrosh() override
{}
49 void RestoreTab() override
{}
50 void ShowKeyboardOverlay() override
{}
51 void ShowTaskManager() override
{}
52 void OpenFeedbackPage() override
{}
54 DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl
);
57 class MediaDelegateImpl
: public MediaDelegate
{
59 MediaDelegateImpl() : state_(MEDIA_CAPTURE_NONE
) {}
60 ~MediaDelegateImpl() override
{}
62 void set_media_capture_state(MediaCaptureState state
) { state_
= state
; }
66 void HandleMediaNextTrack() override
{}
67 void HandleMediaPlayPause() override
{}
68 void HandleMediaPrevTrack() override
{}
69 MediaCaptureState
GetMediaCaptureState(
70 content::BrowserContext
* context
) override
{
74 MediaCaptureState state_
;
76 DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl
);
81 TestShellDelegate::TestShellDelegate()
82 : num_exit_requests_(0),
83 multi_profiles_enabled_(false),
84 test_session_state_delegate_(NULL
) {
87 TestShellDelegate::~TestShellDelegate() {
90 bool TestShellDelegate::IsFirstRunAfterBoot() const {
94 bool TestShellDelegate::IsIncognitoAllowed() const {
98 bool TestShellDelegate::IsMultiProfilesEnabled() const {
99 return multi_profiles_enabled_
;
102 bool TestShellDelegate::IsRunningInForcedAppMode() const {
106 bool TestShellDelegate::IsMultiAccountEnabled() const {
110 void TestShellDelegate::PreInit() {
113 void TestShellDelegate::PreShutdown() {
116 void TestShellDelegate::Exit() {
117 num_exit_requests_
++;
120 keyboard::KeyboardControllerProxy
*
121 TestShellDelegate::CreateKeyboardControllerProxy() {
122 return new KeyboardControllerProxyStub();
125 void TestShellDelegate::VirtualKeyboardActivated(bool activated
) {
126 FOR_EACH_OBSERVER(ash::VirtualKeyboardStateObserver
,
127 keyboard_state_observer_list_
,
128 OnVirtualKeyboardStateChanged(activated
));
131 void TestShellDelegate::AddVirtualKeyboardStateObserver(
132 VirtualKeyboardStateObserver
* observer
) {
133 keyboard_state_observer_list_
.AddObserver(observer
);
136 void TestShellDelegate::RemoveVirtualKeyboardStateObserver(
137 VirtualKeyboardStateObserver
* observer
) {
138 keyboard_state_observer_list_
.RemoveObserver(observer
);
141 content::BrowserContext
* TestShellDelegate::GetActiveBrowserContext() {
142 active_browser_context_
.reset(new content::TestBrowserContext());
143 return active_browser_context_
.get();
146 app_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();
152 ShelfDelegate
* TestShellDelegate::CreateShelfDelegate(ShelfModel
* model
) {
153 return new TestShelfDelegate(model
);
156 SystemTrayDelegate
* TestShellDelegate::CreateSystemTrayDelegate() {
157 return new TestSystemTrayDelegate
;
160 UserWallpaperDelegate
* TestShellDelegate::CreateUserWallpaperDelegate() {
161 return new TestUserWallpaperDelegate();
164 SessionStateDelegate
* TestShellDelegate::CreateSessionStateDelegate() {
165 DCHECK(!test_session_state_delegate_
);
166 test_session_state_delegate_
= new TestSessionStateDelegate();
167 return test_session_state_delegate_
;
170 AccessibilityDelegate
* TestShellDelegate::CreateAccessibilityDelegate() {
171 return new DefaultAccessibilityDelegate();
174 NewWindowDelegate
* TestShellDelegate::CreateNewWindowDelegate() {
175 return new NewWindowDelegateImpl
;
178 MediaDelegate
* TestShellDelegate::CreateMediaDelegate() {
179 return new MediaDelegateImpl
;
182 ui::MenuModel
* TestShellDelegate::CreateContextMenu(
184 ash::ShelfItemDelegate
* item_delegate
,
185 ash::ShelfItem
* item
) {
189 GPUSupport
* TestShellDelegate::CreateGPUSupport() {
190 // Real GPU support depends on src/content, so just use a stub.
191 return new GPUSupportStub
;
194 base::string16
TestShellDelegate::GetProductName() const {
195 return base::string16();
198 void 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();