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 OpenGetHelp() override
{}
50 void RestoreTab() override
{}
51 void ShowKeyboardOverlay() override
{}
52 void ShowTaskManager() override
{}
53 void OpenFeedbackPage() override
{}
55 DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl
);
58 class MediaDelegateImpl
: public MediaDelegate
{
60 MediaDelegateImpl() : state_(MEDIA_CAPTURE_NONE
) {}
61 ~MediaDelegateImpl() override
{}
63 void set_media_capture_state(MediaCaptureState state
) { state_
= state
; }
67 void HandleMediaNextTrack() override
{}
68 void HandleMediaPlayPause() override
{}
69 void HandleMediaPrevTrack() override
{}
70 MediaCaptureState
GetMediaCaptureState(
71 content::BrowserContext
* context
) override
{
75 MediaCaptureState state_
;
77 DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl
);
82 TestShellDelegate::TestShellDelegate()
83 : num_exit_requests_(0),
84 multi_profiles_enabled_(false),
85 test_session_state_delegate_(NULL
) {
88 TestShellDelegate::~TestShellDelegate() {
91 bool TestShellDelegate::IsFirstRunAfterBoot() const {
95 bool TestShellDelegate::IsIncognitoAllowed() const {
99 bool TestShellDelegate::IsMultiProfilesEnabled() const {
100 return multi_profiles_enabled_
;
103 bool TestShellDelegate::IsRunningInForcedAppMode() const {
107 bool TestShellDelegate::IsMultiAccountEnabled() const {
111 void TestShellDelegate::PreInit() {
114 void TestShellDelegate::PreShutdown() {
117 void TestShellDelegate::Exit() {
118 num_exit_requests_
++;
121 keyboard::KeyboardControllerProxy
*
122 TestShellDelegate::CreateKeyboardControllerProxy() {
123 return new KeyboardControllerProxyStub();
126 void TestShellDelegate::VirtualKeyboardActivated(bool activated
) {
127 FOR_EACH_OBSERVER(ash::VirtualKeyboardStateObserver
,
128 keyboard_state_observer_list_
,
129 OnVirtualKeyboardStateChanged(activated
));
132 void TestShellDelegate::AddVirtualKeyboardStateObserver(
133 VirtualKeyboardStateObserver
* observer
) {
134 keyboard_state_observer_list_
.AddObserver(observer
);
137 void TestShellDelegate::RemoveVirtualKeyboardStateObserver(
138 VirtualKeyboardStateObserver
* observer
) {
139 keyboard_state_observer_list_
.RemoveObserver(observer
);
142 content::BrowserContext
* TestShellDelegate::GetActiveBrowserContext() {
143 active_browser_context_
.reset(new content::TestBrowserContext());
144 return active_browser_context_
.get();
147 app_list::AppListViewDelegate
* TestShellDelegate::GetAppListViewDelegate() {
148 if (!app_list_view_delegate_
)
149 app_list_view_delegate_
.reset(new app_list::test::AppListTestViewDelegate
);
150 return app_list_view_delegate_
.get();
153 ShelfDelegate
* TestShellDelegate::CreateShelfDelegate(ShelfModel
* model
) {
154 return new TestShelfDelegate(model
);
157 SystemTrayDelegate
* TestShellDelegate::CreateSystemTrayDelegate() {
158 return new TestSystemTrayDelegate
;
161 UserWallpaperDelegate
* TestShellDelegate::CreateUserWallpaperDelegate() {
162 return new TestUserWallpaperDelegate();
165 TestSessionStateDelegate
* TestShellDelegate::CreateSessionStateDelegate() {
166 return new TestSessionStateDelegate();
169 AccessibilityDelegate
* TestShellDelegate::CreateAccessibilityDelegate() {
170 return new DefaultAccessibilityDelegate();
173 NewWindowDelegate
* TestShellDelegate::CreateNewWindowDelegate() {
174 return new NewWindowDelegateImpl
;
177 MediaDelegate
* TestShellDelegate::CreateMediaDelegate() {
178 return new MediaDelegateImpl
;
181 ui::MenuModel
* TestShellDelegate::CreateContextMenu(
183 ash::ShelfItemDelegate
* item_delegate
,
184 ash::ShelfItem
* item
) {
188 GPUSupport
* TestShellDelegate::CreateGPUSupport() {
189 // Real GPU support depends on src/content, so just use a stub.
190 return new GPUSupportStub
;
193 base::string16
TestShellDelegate::GetProductName() const {
194 return base::string16();
197 void TestShellDelegate::SetMediaCaptureState(MediaCaptureState state
) {
198 #if defined(OS_CHROMEOS)
199 Shell
* shell
= Shell::GetInstance();
200 static_cast<MediaDelegateImpl
*>(shell
->media_delegate())
201 ->set_media_capture_state(state
);
202 shell
->system_tray_notifier()->NotifyMediaCaptureChanged();