1 // Copyright (c) 2013 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 "apps/shell_window.h"
6 #include "apps/shell_window_registry.h"
7 #include "apps/ui/native_app_window.h"
8 #include "ash/desktop_background/desktop_background_controller.h"
9 #include "ash/desktop_background/desktop_background_controller_observer.h"
10 #include "ash/shell.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h"
14 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
15 #include "chrome/browser/chromeos/login/app_launch_controller.h"
16 #include "chrome/browser/chromeos/login/fake_user_manager.h"
17 #include "chrome/browser/chromeos/login/mock_user_manager.h"
18 #include "chrome/browser/chromeos/login/oobe_base_test.h"
19 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
20 #include "chrome/browser/chromeos/login/wizard_controller.h"
21 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
22 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
23 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
24 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h"
25 #include "chrome/browser/extensions/extension_service.h"
26 #include "chrome/browser/extensions/extension_system.h"
27 #include "chrome/browser/extensions/extension_test_message_listener.h"
28 #include "chrome/common/chrome_switches.h"
29 #include "chrome/common/pref_names.h"
30 #include "chromeos/chromeos_switches.h"
31 #include "content/public/browser/notification_observer.h"
32 #include "content/public/browser/notification_registrar.h"
33 #include "content/public/browser/notification_service.h"
34 #include "content/public/test/browser_test_utils.h"
35 #include "google_apis/gaia/gaia_constants.h"
36 #include "google_apis/gaia/gaia_switches.h"
37 #include "google_apis/gaia/gaia_urls.h"
39 namespace em
= enterprise_management
;
45 // This is a simple test app that creates an app window and immediately closes
46 // it again. Webstore data json is in
47 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/
48 // detail/ggbflgnkafappblpkiflbgpmkfdpnhhe
49 const char kTestKioskApp
[] = "ggbflgnkafappblpkiflbgpmkfdpnhhe";
51 // This app creates a window and declares usage of the identity API in its
52 // manifest, so we can test device robot token minting via the identity API.
53 // Webstore data json is in
54 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/
55 // detail/ibjkkfdnfcaoapcpheeijckmpcfkifob
56 const char kTestEnterpriseKioskApp
[] = "ibjkkfdnfcaoapcpheeijckmpcfkifob";
58 // Timeout while waiting for network connectivity during tests.
59 const int kTestNetworkTimeoutSeconds
= 1;
61 // Email of owner account for test.
62 const char kTestOwnerEmail
[] = "owner@example.com";
64 const char kTestEnterpriseAccountId
[] = "enterprise-kiosk-app@localhost";
65 const char kTestEnterpriseServiceAccountId
[] = "service_account@example.com";
66 const char kTestRefreshToken
[] = "fake-refresh-token";
67 const char kTestUserinfoToken
[] = "fake-userinfo-token";
68 const char kTestLoginToken
[] = "fake-login-token";
69 const char kTestAccessToken
[] = "fake-access-token";
70 const char kTestClientId
[] = "fake-client-id";
71 const char kTestAppScope
[] =
72 "https://www.googleapis.com/auth/userinfo.profile";
74 // Helper function for GetConsumerKioskModeStatusCallback.
75 void ConsumerKioskModeStatusCheck(
76 KioskAppManager::ConsumerKioskModeStatus
* out_status
,
77 const base::Closure
& runner_quit_task
,
78 KioskAppManager::ConsumerKioskModeStatus in_status
) {
79 LOG(INFO
) << "KioskAppManager::ConsumerKioskModeStatus = " << in_status
;
80 *out_status
= in_status
;
81 runner_quit_task
.Run();
84 // Helper KioskAppManager::EnableKioskModeCallback implementation.
85 void ConsumerKioskModeLockCheck(
87 const base::Closure
& runner_quit_task
,
89 LOG(INFO
) << "kiosk locked = " << in_locked
;
90 *out_locked
= in_locked
;
91 runner_quit_task
.Run();
94 // Helper function for WaitForNetworkTimeOut.
95 void OnNetworkWaitTimedOut(const base::Closure
& runner_quit_task
) {
96 runner_quit_task
.Run();
99 // Helper function for DeviceOAuth2TokenServiceFactory::Get().
100 void CopyTokenService(DeviceOAuth2TokenService
** out_token_service
,
101 DeviceOAuth2TokenService
* in_token_service
) {
102 *out_token_service
= in_token_service
;
105 // Helper functions for CanConfigureNetwork mock.
106 class ScopedCanConfigureNetwork
{
108 ScopedCanConfigureNetwork(bool can_configure
, bool needs_owner_auth
)
109 : can_configure_(can_configure
),
110 needs_owner_auth_(needs_owner_auth
),
111 can_configure_network_callback_(
112 base::Bind(&ScopedCanConfigureNetwork::CanConfigureNetwork
,
113 base::Unretained(this))),
114 needs_owner_auth_callback_(base::Bind(
115 &ScopedCanConfigureNetwork::NeedsOwnerAuthToConfigureNetwork
,
116 base::Unretained(this))) {
117 AppLaunchController::SetCanConfigureNetworkCallbackForTesting(
118 &can_configure_network_callback_
);
119 AppLaunchController::SetNeedOwnerAuthToConfigureNetworkCallbackForTesting(
120 &needs_owner_auth_callback_
);
122 ~ScopedCanConfigureNetwork() {
123 AppLaunchController::SetCanConfigureNetworkCallbackForTesting(NULL
);
124 AppLaunchController::SetNeedOwnerAuthToConfigureNetworkCallbackForTesting(
128 bool CanConfigureNetwork() {
129 return can_configure_
;
132 bool NeedsOwnerAuthToConfigureNetwork() {
133 return needs_owner_auth_
;
138 bool needs_owner_auth_
;
139 AppLaunchController::ReturnBoolCallback can_configure_network_callback_
;
140 AppLaunchController::ReturnBoolCallback needs_owner_auth_callback_
;
141 DISALLOW_COPY_AND_ASSIGN(ScopedCanConfigureNetwork
);
146 // Helper class that monitors app windows to wait for a window to appear.
147 class ShellWindowObserver
: public apps::ShellWindowRegistry::Observer
{
149 ShellWindowObserver(apps::ShellWindowRegistry
* registry
,
150 const std::string
& app_id
)
151 : registry_(registry
), app_id_(app_id
), window_(NULL
), running_(false) {
152 registry_
->AddObserver(this);
154 virtual ~ShellWindowObserver() {
155 registry_
->RemoveObserver(this);
158 apps::ShellWindow
* Wait() {
160 message_loop_runner_
= new content::MessageLoopRunner
;
161 message_loop_runner_
->Run();
162 EXPECT_TRUE(window_
);
166 // ShellWindowRegistry::Observer
167 virtual void OnShellWindowAdded(apps::ShellWindow
* shell_window
) OVERRIDE
{
171 if (shell_window
->extension_id() == app_id_
) {
172 window_
= shell_window
;
173 message_loop_runner_
->Quit();
177 virtual void OnShellWindowIconChanged(
178 apps::ShellWindow
* shell_window
) OVERRIDE
{}
179 virtual void OnShellWindowRemoved(apps::ShellWindow
* shell_window
) OVERRIDE
{}
182 apps::ShellWindowRegistry
* registry_
;
184 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner_
;
185 apps::ShellWindow
* window_
;
188 DISALLOW_COPY_AND_ASSIGN(ShellWindowObserver
);
191 class KioskTest
: public OobeBaseTest
{
194 set_exit_when_last_browser_closes(false);
197 virtual ~KioskTest() {}
201 virtual void SetUp() OVERRIDE
{
202 mock_user_manager_
.reset(new MockUserManager
);
203 AppLaunchController::SkipSplashWaitForTesting();
204 AppLaunchController::SetNetworkWaitForTesting(kTestNetworkTimeoutSeconds
);
206 OobeBaseTest::SetUp();
209 virtual void CleanUpOnMainThread() OVERRIDE
{
210 AppLaunchController::SetNetworkTimeoutCallbackForTesting(NULL
);
211 AppLaunchSigninScreen::SetUserManagerForTesting(NULL
);
213 OobeBaseTest::CleanUpOnMainThread();
215 // Clean up while main thread still runs.
216 // See http://crbug.com/176659.
217 KioskAppManager::Get()->CleanUp();
220 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
221 OobeBaseTest::SetUpCommandLine(command_line
);
223 // Create gaia and webstore URL from test server url but using different
224 // host names. This is to avoid gaia response being tagged as from
225 // webstore in chrome_resource_dispatcher_host_delegate.cc.
226 const GURL
& server_url
= embedded_test_server()->base_url();
227 std::string
webstore_host("webstore");
228 GURL::Replacements replace_webstore_host
;
229 replace_webstore_host
.SetHostStr(webstore_host
);
230 GURL webstore_url
= server_url
.ReplaceComponents(replace_webstore_host
);
231 command_line
->AppendSwitchASCII(
232 ::switches::kAppsGalleryURL
,
233 webstore_url
.Resolve("/chromeos/app_mode/webstore").spec());
234 command_line
->AppendSwitchASCII(
235 ::switches::kAppsGalleryDownloadURL
,
236 webstore_url
.Resolve(
237 "/chromeos/app_mode/webstore/downloads/%s.crx").spec());
240 void ReloadKioskApps() {
241 KioskAppManager::Get()->AddApp(kTestKioskApp
);
244 void ReloadAutolaunchKioskApps() {
245 KioskAppManager::Get()->AddApp(kTestKioskApp
);
246 KioskAppManager::Get()->SetAutoLaunchApp(kTestKioskApp
);
249 void StartAppLaunchFromLoginScreen(const base::Closure
& network_setup_cb
) {
250 EnableConsumerKioskMode();
252 // Start UI, find menu entry for this app and launch it.
253 content::WindowedNotificationObserver
login_signal(
254 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE
,
255 content::NotificationService::AllSources());
256 chromeos::WizardController::SkipPostLoginScreensForTesting();
257 chromeos::WizardController
* wizard_controller
=
258 chromeos::WizardController::default_controller();
259 CHECK(wizard_controller
);
260 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
263 // Wait for the Kiosk App configuration to reload, then launch the app.
264 content::WindowedNotificationObserver
apps_loaded_signal(
265 chrome::NOTIFICATION_KIOSK_APPS_LOADED
,
266 content::NotificationService::AllSources());
268 apps_loaded_signal
.Wait();
270 if (!network_setup_cb
.is_null())
271 network_setup_cb
.Run();
273 GetLoginUI()->CallJavascriptFunction(
274 "login.AppsMenuButton.runAppForTesting",
275 base::StringValue(kTestKioskApp
));
278 void WaitForAppLaunchSuccess() {
279 SimulateNetworkOnline();
281 ExtensionTestMessageListener
282 launch_data_check_listener("launchData.isKioskSession = true", false);
284 // Wait for the Kiosk App to launch.
285 content::WindowedNotificationObserver(
286 chrome::NOTIFICATION_KIOSK_APP_LAUNCHED
,
287 content::NotificationService::AllSources()).Wait();
289 // Default profile switches to app profile after app is launched.
290 Profile
* app_profile
= ProfileManager::GetPrimaryUserProfile();
291 ASSERT_TRUE(app_profile
);
293 // Check installer status.
294 EXPECT_EQ(chromeos::KioskAppLaunchError::NONE
,
295 chromeos::KioskAppLaunchError::Get());
297 // Check if the kiosk webapp is really installed for the default profile.
298 const extensions::Extension
* app
=
299 extensions::ExtensionSystem::Get(app_profile
)->
300 extension_service()->GetInstalledExtension(kTestKioskApp
);
303 // App should appear with its window.
304 apps::ShellWindowRegistry
* shell_window_registry
=
305 apps::ShellWindowRegistry::Get(app_profile
);
306 apps::ShellWindow
* window
=
307 ShellWindowObserver(shell_window_registry
, kTestKioskApp
).Wait();
310 // Login screen should be gone or fading out.
311 chromeos::LoginDisplayHost
* login_display_host
=
312 chromeos::LoginDisplayHostImpl::default_host();
314 login_display_host
== NULL
||
315 login_display_host
->GetNativeWindow()->layer()->GetTargetOpacity() ==
318 // Wait until the app terminates if it is still running.
319 if (!shell_window_registry
->GetShellWindowsForApp(kTestKioskApp
).empty())
320 content::RunMessageLoop();
322 // Check that the app had been informed that it is running in a kiosk
324 EXPECT_TRUE(launch_data_check_listener
.was_satisfied());
327 void WaitForAppLaunchNetworkTimeout() {
328 if (GetAppLaunchController()->network_wait_timedout())
331 scoped_refptr
<content::MessageLoopRunner
> runner
=
332 new content::MessageLoopRunner
;
334 base::Closure callback
= base::Bind(
335 &OnNetworkWaitTimedOut
, runner
->QuitClosure());
336 AppLaunchController::SetNetworkTimeoutCallbackForTesting(&callback
);
340 CHECK(GetAppLaunchController()->network_wait_timedout());
341 AppLaunchController::SetNetworkTimeoutCallbackForTesting(NULL
);
344 void EnableConsumerKioskMode() {
345 scoped_ptr
<bool> locked(new bool(false));
346 scoped_refptr
<content::MessageLoopRunner
> runner
=
347 new content::MessageLoopRunner
;
348 KioskAppManager::Get()->EnableConsumerModeKiosk(
349 base::Bind(&ConsumerKioskModeLockCheck
,
351 runner
->QuitClosure()));
353 EXPECT_TRUE(*locked
.get());
356 KioskAppManager::ConsumerKioskModeStatus
GetConsumerKioskModeStatus() {
357 KioskAppManager::ConsumerKioskModeStatus status
=
358 static_cast<KioskAppManager::ConsumerKioskModeStatus
>(-1);
359 scoped_refptr
<content::MessageLoopRunner
> runner
=
360 new content::MessageLoopRunner
;
361 KioskAppManager::Get()->GetConsumerKioskModeStatus(
362 base::Bind(&ConsumerKioskModeStatusCheck
,
364 runner
->QuitClosure()));
366 CHECK_NE(status
, static_cast<KioskAppManager::ConsumerKioskModeStatus
>(-1));
370 AppLaunchController
* GetAppLaunchController() {
371 return chromeos::LoginDisplayHostImpl::default_host()
372 ->GetAppLaunchController();
375 scoped_ptr
<MockUserManager
> mock_user_manager_
;
378 IN_PROC_BROWSER_TEST_F(KioskTest
, InstallAndLaunchApp
) {
379 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
380 WaitForAppLaunchSuccess();
383 IN_PROC_BROWSER_TEST_F(KioskTest
, LaunchAppNetworkDown
) {
384 // Mock network could be configured with owner's password.
385 ScopedCanConfigureNetwork
can_configure_network(true, true);
387 // Start app launch and wait for network connectivity timeout.
388 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure());
389 OobeScreenWaiter
splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH
);
390 splash_waiter
.Wait();
391 WaitForAppLaunchNetworkTimeout();
393 // Configure network link should be visible.
394 JsExpect("$('splash-config-network').hidden == false");
396 // Set up fake user manager with an owner for the test.
397 mock_user_manager_
->SetActiveUser(kTestOwnerEmail
);
398 AppLaunchSigninScreen::SetUserManagerForTesting(mock_user_manager_
.get());
399 static_cast<LoginDisplayHostImpl
*>(LoginDisplayHostImpl::default_host())
400 ->GetOobeUI()->ShowOobeUI(false);
402 // Configure network should bring up lock screen for owner.
403 OobeScreenWaiter
lock_screen_waiter(OobeDisplay::SCREEN_ACCOUNT_PICKER
);
404 static_cast<AppLaunchSplashScreenActor::Delegate
*>(GetAppLaunchController())
405 ->OnConfigureNetwork();
406 lock_screen_waiter
.Wait();
408 // A network error screen should be shown after authenticating.
409 OobeScreenWaiter
error_screen_waiter(OobeDisplay::SCREEN_ERROR_MESSAGE
);
410 static_cast<AppLaunchSigninScreen::Delegate
*>(GetAppLaunchController())
411 ->OnOwnerSigninSuccess();
412 error_screen_waiter
.Wait();
414 ASSERT_TRUE(GetAppLaunchController()->showing_network_dialog());
416 WaitForAppLaunchSuccess();
419 IN_PROC_BROWSER_TEST_F(KioskTest
, LaunchAppNetworkDownConfigureNotAllowed
) {
420 // Mock network could not be configured.
421 ScopedCanConfigureNetwork
can_configure_network(false, true);
423 // Start app launch and wait for network connectivity timeout.
424 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure());
425 OobeScreenWaiter
splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH
);
426 splash_waiter
.Wait();
427 WaitForAppLaunchNetworkTimeout();
429 // Configure network link should not be visible.
430 JsExpect("$('splash-config-network').hidden == true");
432 // Network becomes online and app launch is resumed.
433 WaitForAppLaunchSuccess();
436 IN_PROC_BROWSER_TEST_F(KioskTest
, LaunchAppNetworkPortal
) {
437 // Mock network could be configured without the owner password.
438 ScopedCanConfigureNetwork
can_configure_network(true, false);
440 // Start app launch with network portal state.
441 StartAppLaunchFromLoginScreen(SimulateNetworkPortalClosure());
442 OobeScreenWaiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH
)
443 .WaitNoAssertCurrentScreen();
444 WaitForAppLaunchNetworkTimeout();
446 // Network error should show up automatically since this test does not
447 // require owner auth to configure network.
448 OobeScreenWaiter(OobeDisplay::SCREEN_ERROR_MESSAGE
).Wait();
450 ASSERT_TRUE(GetAppLaunchController()->showing_network_dialog());
451 WaitForAppLaunchSuccess();
454 IN_PROC_BROWSER_TEST_F(KioskTest
, LaunchAppUserCancel
) {
455 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure());
456 OobeScreenWaiter
splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH
);
457 splash_waiter
.Wait();
459 CrosSettings::Get()->SetBoolean(
460 kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled
, true);
461 content::WindowedNotificationObserver
signal(
462 chrome::NOTIFICATION_APP_TERMINATING
,
463 content::NotificationService::AllSources());
464 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
465 base::StringValue("app_launch_bailout"));
467 EXPECT_EQ(chromeos::KioskAppLaunchError::USER_CANCEL
,
468 chromeos::KioskAppLaunchError::Get());
471 IN_PROC_BROWSER_TEST_F(KioskTest
, AutolaunchWarningCancel
) {
472 EnableConsumerKioskMode();
473 // Start UI, find menu entry for this app and launch it.
474 chromeos::WizardController::SkipPostLoginScreensForTesting();
475 chromeos::WizardController
* wizard_controller
=
476 chromeos::WizardController::default_controller();
477 CHECK(wizard_controller
);
478 ReloadAutolaunchKioskApps();
479 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
481 EXPECT_FALSE(KioskAppManager::Get()->GetAutoLaunchApp().empty());
482 EXPECT_FALSE(KioskAppManager::Get()->IsAutoLaunchEnabled());
484 // Wait for the auto launch warning come up.
485 content::WindowedNotificationObserver(
486 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE
,
487 content::NotificationService::AllSources()).Wait();
488 GetLoginUI()->CallJavascriptFunction(
489 "login.AutolaunchScreen.confirmAutoLaunchForTesting",
490 base::FundamentalValue(false));
492 // Wait for the auto launch warning to go away.
493 content::WindowedNotificationObserver(
494 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_COMPLETED
,
495 content::NotificationService::AllSources()).Wait();
497 EXPECT_FALSE(KioskAppManager::Get()->IsAutoLaunchEnabled());
500 IN_PROC_BROWSER_TEST_F(KioskTest
, AutolaunchWarningConfirm
) {
501 EnableConsumerKioskMode();
502 // Start UI, find menu entry for this app and launch it.
503 chromeos::WizardController::SkipPostLoginScreensForTesting();
504 chromeos::WizardController
* wizard_controller
=
505 chromeos::WizardController::default_controller();
506 CHECK(wizard_controller
);
507 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
509 ReloadAutolaunchKioskApps();
510 EXPECT_FALSE(KioskAppManager::Get()->GetAutoLaunchApp().empty());
511 EXPECT_FALSE(KioskAppManager::Get()->IsAutoLaunchEnabled());
513 // Wait for the auto launch warning come up.
514 content::WindowedNotificationObserver(
515 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE
,
516 content::NotificationService::AllSources()).Wait();
517 GetLoginUI()->CallJavascriptFunction(
518 "login.AutolaunchScreen.confirmAutoLaunchForTesting",
519 base::FundamentalValue(true));
521 // Wait for the auto launch warning to go away.
522 content::WindowedNotificationObserver(
523 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_COMPLETED
,
524 content::NotificationService::AllSources()).Wait();
526 EXPECT_FALSE(KioskAppManager::Get()->GetAutoLaunchApp().empty());
527 EXPECT_TRUE(KioskAppManager::Get()->IsAutoLaunchEnabled());
529 WaitForAppLaunchSuccess();
532 IN_PROC_BROWSER_TEST_F(KioskTest
, KioskEnableCancel
) {
533 chromeos::WizardController::SkipPostLoginScreensForTesting();
534 chromeos::WizardController
* wizard_controller
=
535 chromeos::WizardController::default_controller();
536 CHECK(wizard_controller
);
538 // Check Kiosk mode status.
539 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_MODE_CONFIGURABLE
,
540 GetConsumerKioskModeStatus());
542 // Wait for the login UI to come up and switch to the kiosk_enable screen.
543 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
544 content::WindowedNotificationObserver(
545 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE
,
546 content::NotificationService::AllSources()).Wait();
547 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
548 base::StringValue("kiosk_enable"));
550 // Wait for the kiosk_enable screen to show and cancel the screen.
551 content::WindowedNotificationObserver(
552 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE
,
553 content::NotificationService::AllSources()).Wait();
554 GetLoginUI()->CallJavascriptFunction(
555 "login.KioskEnableScreen.enableKioskForTesting",
556 base::FundamentalValue(false));
558 // Wait for the kiosk_enable screen to disappear.
559 content::WindowedNotificationObserver(
560 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_COMPLETED
,
561 content::NotificationService::AllSources()).Wait();
563 // Check that the status still says configurable.
564 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_MODE_CONFIGURABLE
,
565 GetConsumerKioskModeStatus());
568 IN_PROC_BROWSER_TEST_F(KioskTest
, KioskEnableConfirmed
) {
569 // Start UI, find menu entry for this app and launch it.
570 chromeos::WizardController::SkipPostLoginScreensForTesting();
571 chromeos::WizardController
* wizard_controller
=
572 chromeos::WizardController::default_controller();
573 CHECK(wizard_controller
);
575 // Check Kiosk mode status.
576 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_MODE_CONFIGURABLE
,
577 GetConsumerKioskModeStatus());
578 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
580 // Wait for the login UI to come up and switch to the kiosk_enable screen.
581 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
582 content::WindowedNotificationObserver(
583 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE
,
584 content::NotificationService::AllSources()).Wait();
585 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
586 base::StringValue("kiosk_enable"));
588 // Wait for the kiosk_enable screen to show and cancel the screen.
589 content::WindowedNotificationObserver(
590 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE
,
591 content::NotificationService::AllSources()).Wait();
592 GetLoginUI()->CallJavascriptFunction(
593 "login.KioskEnableScreen.enableKioskForTesting",
594 base::FundamentalValue(true));
596 // Wait for the signal that indicates Kiosk Mode is enabled.
597 content::WindowedNotificationObserver(
598 chrome::NOTIFICATION_KIOSK_ENABLED
,
599 content::NotificationService::AllSources()).Wait();
600 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_MODE_ENABLED
,
601 GetConsumerKioskModeStatus());
604 IN_PROC_BROWSER_TEST_F(KioskTest
, KioskEnableAbortedWithAutoEnrollment
) {
605 // Fake an auto enrollment is going to be enforced.
606 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
607 switches::kEnterpriseEnrollmentInitialModulus
, "1");
608 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
609 switches::kEnterpriseEnrollmentModulusLimit
, "2");
610 g_browser_process
->local_state()->SetBoolean(prefs::kShouldAutoEnroll
, true);
611 g_browser_process
->local_state()->SetInteger(
612 prefs::kAutoEnrollmentPowerLimit
, 3);
614 // Start UI, find menu entry for this app and launch it.
615 chromeos::WizardController::SkipPostLoginScreensForTesting();
616 chromeos::WizardController
* wizard_controller
=
617 chromeos::WizardController::default_controller();
618 CHECK(wizard_controller
);
620 // Check Kiosk mode status.
621 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_MODE_CONFIGURABLE
,
622 GetConsumerKioskModeStatus());
623 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
625 // Wait for the login UI to come up and switch to the kiosk_enable screen.
626 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
627 content::WindowedNotificationObserver(
628 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE
,
629 content::NotificationService::AllSources()).Wait();
630 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
631 base::StringValue("kiosk_enable"));
633 // The flow should be aborted due to auto enrollment enforcement.
634 scoped_refptr
<content::MessageLoopRunner
> runner
=
635 new content::MessageLoopRunner
;
636 GetSigninScreenHandler()->set_kiosk_enable_flow_aborted_callback_for_test(
637 runner
->QuitClosure());
641 IN_PROC_BROWSER_TEST_F(KioskTest
, KioskEnableAfter2ndSigninScreen
) {
642 // Fake an auto enrollment is not going to be enforced.
643 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
644 switches::kEnterpriseEnrollmentInitialModulus
, "1");
645 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
646 switches::kEnterpriseEnrollmentModulusLimit
, "2");
647 g_browser_process
->local_state()->SetBoolean(prefs::kShouldAutoEnroll
, false);
648 g_browser_process
->local_state()->SetInteger(
649 prefs::kAutoEnrollmentPowerLimit
, -1);
651 chromeos::WizardController::SkipPostLoginScreensForTesting();
652 chromeos::WizardController
* wizard_controller
=
653 chromeos::WizardController::default_controller();
654 CHECK(wizard_controller
);
656 // Check Kiosk mode status.
657 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_MODE_CONFIGURABLE
,
658 GetConsumerKioskModeStatus());
660 // Wait for the login UI to come up and switch to the kiosk_enable screen.
661 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
662 content::WindowedNotificationObserver(
663 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE
,
664 content::NotificationService::AllSources()).Wait();
665 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
666 base::StringValue("kiosk_enable"));
668 // Wait for the kiosk_enable screen to show and cancel the screen.
669 content::WindowedNotificationObserver(
670 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE
,
671 content::NotificationService::AllSources()).Wait();
672 GetLoginUI()->CallJavascriptFunction(
673 "login.KioskEnableScreen.enableKioskForTesting",
674 base::FundamentalValue(false));
676 // Wait for the kiosk_enable screen to disappear.
677 content::WindowedNotificationObserver(
678 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_COMPLETED
,
679 content::NotificationService::AllSources()).Wait();
681 // Show signin screen again.
682 chromeos::LoginDisplayHostImpl::default_host()->StartSignInScreen(
683 LoginScreenContext());
684 OobeScreenWaiter(OobeDisplay::SCREEN_GAIA_SIGNIN
).Wait();
686 // Show kiosk enable screen again.
687 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
688 base::StringValue("kiosk_enable"));
690 // And it should show up.
691 content::WindowedNotificationObserver(
692 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE
,
693 content::NotificationService::AllSources()).Wait();
696 class KioskEnterpriseTest
: public KioskTest
{
698 KioskEnterpriseTest() {}
700 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE
{
701 device_policy_test_helper_
.MarkAsEnterpriseOwned();
702 device_policy_test_helper_
.InstallOwnerKey();
704 KioskTest::SetUpInProcessBrowserTestFixture();
707 virtual void SetUpOnMainThread() OVERRIDE
{
708 KioskTest::SetUpOnMainThread();
709 // Configure kTestEnterpriseKioskApp in device policy.
710 em::DeviceLocalAccountsProto
* accounts
=
711 device_policy_test_helper_
.device_policy()->payload()
712 .mutable_device_local_accounts();
713 em::DeviceLocalAccountInfoProto
* account
= accounts
->add_account();
714 account
->set_account_id(kTestEnterpriseAccountId
);
716 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_KIOSK_APP
);
717 account
->mutable_kiosk_app()->set_app_id(kTestEnterpriseKioskApp
);
718 accounts
->set_auto_login_id(kTestEnterpriseAccountId
);
719 em::PolicyData
& policy_data
=
720 device_policy_test_helper_
.device_policy()->policy_data();
721 policy_data
.set_service_account_identity(kTestEnterpriseServiceAccountId
);
722 device_policy_test_helper_
.device_policy()->Build();
723 DBusThreadManager::Get()->GetSessionManagerClient()->StoreDevicePolicy(
724 device_policy_test_helper_
.device_policy()->GetBlob(),
725 base::Bind(&KioskEnterpriseTest::StorePolicyCallback
));
727 DeviceSettingsService::Get()->Load();
729 // Configure OAuth authentication.
730 GaiaUrls
* gaia_urls
= GaiaUrls::GetInstance();
732 // This token satisfies the userinfo.email request from
733 // DeviceOAuth2TokenService used in token validation.
734 FakeGaia::AccessTokenInfo userinfo_token_info
;
735 userinfo_token_info
.token
= kTestUserinfoToken
;
736 userinfo_token_info
.scopes
.insert(
737 "https://www.googleapis.com/auth/userinfo.email");
738 userinfo_token_info
.audience
= gaia_urls
->oauth2_chrome_client_id();
739 userinfo_token_info
.email
= kTestEnterpriseServiceAccountId
;
740 fake_gaia_
->IssueOAuthToken(kTestRefreshToken
, userinfo_token_info
);
742 // The any-api access token for accessing the token minting endpoint.
743 FakeGaia::AccessTokenInfo login_token_info
;
744 login_token_info
.token
= kTestLoginToken
;
745 login_token_info
.scopes
.insert(GaiaConstants::kAnyApiOAuth2Scope
);
746 login_token_info
.audience
= gaia_urls
->oauth2_chrome_client_id();
747 fake_gaia_
->IssueOAuthToken(kTestRefreshToken
, login_token_info
);
749 // This is the access token requested by the app via the identity API.
750 FakeGaia::AccessTokenInfo access_token_info
;
751 access_token_info
.token
= kTestAccessToken
;
752 access_token_info
.scopes
.insert(kTestAppScope
);
753 access_token_info
.audience
= kTestClientId
;
754 access_token_info
.email
= kTestEnterpriseServiceAccountId
;
755 fake_gaia_
->IssueOAuthToken(kTestLoginToken
, access_token_info
);
757 DeviceOAuth2TokenService
* token_service
= NULL
;
758 DeviceOAuth2TokenServiceFactory::Get(
759 base::Bind(&CopyTokenService
, &token_service
));
760 base::RunLoop().RunUntilIdle();
761 ASSERT_TRUE(token_service
);
762 token_service
->SetAndSaveRefreshToken(kTestRefreshToken
);
765 static void StorePolicyCallback(bool result
) {
769 policy::DevicePolicyCrosTestHelper device_policy_test_helper_
;
772 DISALLOW_COPY_AND_ASSIGN(KioskEnterpriseTest
);
775 IN_PROC_BROWSER_TEST_F(KioskEnterpriseTest
, EnterpriseKioskApp
) {
776 chromeos::WizardController::SkipPostLoginScreensForTesting();
777 chromeos::WizardController
* wizard_controller
=
778 chromeos::WizardController::default_controller();
779 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
781 // Wait for the Kiosk App configuration to reload, then launch the app.
782 KioskAppManager::App app
;
783 content::WindowedNotificationObserver(
784 chrome::NOTIFICATION_KIOSK_APPS_LOADED
,
785 base::Bind(&KioskAppManager::GetApp
,
786 base::Unretained(KioskAppManager::Get()),
787 kTestEnterpriseKioskApp
, &app
)).Wait();
789 GetLoginUI()->CallJavascriptFunction(
790 "login.AppsMenuButton.runAppForTesting",
791 base::StringValue(kTestEnterpriseKioskApp
));
793 // Wait for the Kiosk App to launch.
794 content::WindowedNotificationObserver(
795 chrome::NOTIFICATION_KIOSK_APP_LAUNCHED
,
796 content::NotificationService::AllSources()).Wait();
798 // Check installer status.
799 EXPECT_EQ(chromeos::KioskAppLaunchError::NONE
,
800 chromeos::KioskAppLaunchError::Get());
802 // Wait for the window to appear.
803 apps::ShellWindow
* window
= ShellWindowObserver(
804 apps::ShellWindowRegistry::Get(ProfileManager::GetPrimaryUserProfile()),
805 kTestEnterpriseKioskApp
).Wait();
808 // Check whether the app can retrieve an OAuth2 access token.
810 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
811 window
->web_contents(),
812 "chrome.identity.getAuthToken({ 'interactive': false }, function(token) {"
813 " window.domAutomationController.setAutomationId(0);"
814 " window.domAutomationController.send(token);"
817 EXPECT_EQ(kTestAccessToken
, result
);
819 // Terminate the app.
820 window
->GetBaseWindow()->Close();
821 content::RunAllPendingInMessageLoop();
824 // Specialized test fixture for testing kiosk mode on the
825 // hidden WebUI initialization flow for slow hardware.
826 class KioskHiddenWebUITest
: public KioskTest
,
827 public ash::DesktopBackgroundControllerObserver
{
829 KioskHiddenWebUITest() : wallpaper_loaded_(false) {}
831 // KioskTest overrides:
832 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
833 KioskTest::SetUpCommandLine(command_line
);
834 command_line
->AppendSwitchASCII(switches::kDeviceRegistered
, "1");
835 command_line
->AppendSwitch(switches::kDisableBootAnimation
);
836 command_line
->AppendSwitch(switches::kDisableOobeAnimation
);
839 virtual void SetUpOnMainThread() OVERRIDE
{
840 KioskTest::SetUpOnMainThread();
841 ash::Shell::GetInstance()->desktop_background_controller()
845 virtual void TearDownOnMainThread() OVERRIDE
{
846 ash::Shell::GetInstance()->desktop_background_controller()
847 ->RemoveObserver(this);
848 KioskTest::TearDownOnMainThread();
851 void WaitForWallpaper() {
852 if (!wallpaper_loaded_
) {
853 runner_
= new content::MessageLoopRunner
;
858 bool wallpaper_loaded() const { return wallpaper_loaded_
; }
860 // ash::DesktopBackgroundControllerObserver overrides:
861 virtual void OnWallpaperDataChanged() OVERRIDE
{
862 wallpaper_loaded_
= true;
867 bool wallpaper_loaded_
;
868 scoped_refptr
<content::MessageLoopRunner
> runner_
;
870 DISALLOW_COPY_AND_ASSIGN(KioskHiddenWebUITest
);
873 IN_PROC_BROWSER_TEST_F(KioskHiddenWebUITest
, AutolaunchWarning
) {
874 // Add a device owner.
875 FakeUserManager
* user_manager
= new FakeUserManager();
876 user_manager
->AddUser(kTestOwnerEmail
);
877 ScopedUserManagerEnabler
enabler(user_manager
);
879 // Set kiosk app to autolaunch.
880 EnableConsumerKioskMode();
881 chromeos::WizardController::SkipPostLoginScreensForTesting();
882 chromeos::WizardController
* wizard_controller
=
883 chromeos::WizardController::default_controller();
884 CHECK(wizard_controller
);
885 ReloadAutolaunchKioskApps();
886 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
888 EXPECT_FALSE(KioskAppManager::Get()->GetAutoLaunchApp().empty());
889 EXPECT_FALSE(KioskAppManager::Get()->IsAutoLaunchEnabled());
891 // Wait for the auto launch warning come up.
892 content::WindowedNotificationObserver(
893 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE
,
894 content::NotificationService::AllSources()).Wait();
896 // Wait for the wallpaper to load.
898 EXPECT_TRUE(wallpaper_loaded());
901 } // namespace chromeos