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.
7 #include "ash/desktop_background/desktop_background_controller.h"
8 #include "ash/desktop_background/desktop_background_controller_observer.h"
10 #include "base/bind.h"
11 #include "base/bind_helpers.h"
12 #include "base/files/file_util.h"
13 #include "base/location.h"
14 #include "base/macros.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/path_service.h"
17 #include "base/prefs/pref_service.h"
18 #include "base/run_loop.h"
19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_util.h"
21 #include "base/synchronization/lock.h"
22 #include "chrome/browser/chrome_notification_types.h"
23 #include "chrome/browser/chromeos/app_mode/fake_cws.h"
24 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h"
25 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
26 #include "chrome/browser/chromeos/file_manager/fake_disk_mount_manager.h"
27 #include "chrome/browser/chromeos/login/app_launch_controller.h"
28 #include "chrome/browser/chromeos/login/startup_utils.h"
29 #include "chrome/browser/chromeos/login/test/app_window_waiter.h"
30 #include "chrome/browser/chromeos/login/test/oobe_base_test.h"
31 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
32 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
33 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
34 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
35 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
36 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
37 #include "chrome/browser/chromeos/login/wizard_controller.h"
38 #include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h"
39 #include "chrome/browser/chromeos/policy/device_local_account.h"
40 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
41 #include "chrome/browser/chromeos/profiles/profile_helper.h"
42 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
43 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h"
44 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h"
45 #include "chrome/browser/extensions/extension_service.h"
46 #include "chrome/browser/profiles/profile_impl.h"
47 #include "chrome/browser/profiles/profile_manager.h"
48 #include "chrome/browser/profiles/profiles_state.h"
49 #include "chrome/browser/signin/signin_manager_factory.h"
50 #include "chrome/browser/ui/webui/chromeos/login/kiosk_app_menu_handler.h"
51 #include "chrome/common/chrome_constants.h"
52 #include "chrome/common/chrome_paths.h"
53 #include "chrome/common/pref_names.h"
54 #include "chromeos/chromeos_switches.h"
55 #include "chromeos/dbus/cryptohome_client.h"
56 #include "chromeos/disks/disk_mount_manager.h"
57 #include "chromeos/settings/cros_settings_provider.h"
58 #include "components/signin/core/browser/signin_manager.h"
59 #include "components/signin/core/common/signin_pref_names.h"
60 #include "content/public/browser/browser_thread.h"
61 #include "content/public/browser/notification_observer.h"
62 #include "content/public/browser/notification_registrar.h"
63 #include "content/public/browser/notification_service.h"
64 #include "content/public/browser/web_ui.h"
65 #include "content/public/test/browser_test_utils.h"
66 #include "extensions/browser/app_window/app_window.h"
67 #include "extensions/browser/app_window/app_window_registry.h"
68 #include "extensions/browser/app_window/native_app_window.h"
69 #include "extensions/browser/extension_system.h"
70 #include "extensions/components/native_app_window/native_app_window_views.h"
71 #include "extensions/test/extension_test_message_listener.h"
72 #include "extensions/test/result_catcher.h"
73 #include "google_apis/gaia/gaia_constants.h"
74 #include "google_apis/gaia/gaia_switches.h"
75 #include "google_apis/gaia/gaia_urls.h"
76 #include "net/test/embedded_test_server/embedded_test_server.h"
77 #include "ui/base/accelerators/accelerator.h"
79 namespace em
= enterprise_management
;
85 // This is a simple test app that creates an app window and immediately closes
86 // it again. Webstore data json is in
87 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/
88 // detail/ggbflgnkafappblpkiflbgpmkfdpnhhe
89 const char kTestKioskApp
[] = "ggbflgnkafappblpkiflbgpmkfdpnhhe";
91 // This app creates a window and declares usage of the identity API in its
92 // manifest, so we can test device robot token minting via the identity API.
93 // Webstore data json is in
94 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/
95 // detail/ibjkkfdnfcaoapcpheeijckmpcfkifob
96 const char kTestEnterpriseKioskApp
[] = "ibjkkfdnfcaoapcpheeijckmpcfkifob";
98 // An offline enable test app. Webstore data json is in
99 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/
100 // detail/ajoggoflpgplnnjkjamcmbepjdjdnpdp
101 // An app profile with version 1.0.0 installed is in
102 // chrome/test/data/chromeos/app_mode/offline_enabled_app_profile
103 // The version 2.0.0 crx is in
104 // chrome/test/data/chromeos/app_mode/webstore/downloads/
105 const char kTestOfflineEnabledKioskApp
[] = "ajoggoflpgplnnjkjamcmbepjdjdnpdp";
107 // An app to test local fs data persistence across app update. V1 app writes
108 // data into local fs. V2 app reads and verifies the data.
109 // Webstore data json is in
110 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/
111 // detail/bmbpicmpniaclbbpdkfglgipkkebnbjf
112 const char kTestLocalFsKioskApp
[] = "bmbpicmpniaclbbpdkfglgipkkebnbjf";
114 // An app to test local access to file systems via the
115 // chrome.fileSystem.requestFileSystem API.
116 // Webstore data json is in
117 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/
118 // detail/aaedpojejpghjkedenggihopfhfijcko
119 const char kTestGetVolumeListKioskApp
[] = "aaedpojejpghjkedenggihopfhfijcko";
121 // Fake usb stick mount path.
122 const char kFakeUsbMountPathUpdatePass
[] =
123 "chromeos/app_mode/external_update/update_pass";
124 const char kFakeUsbMountPathNoManifest
[] =
125 "chromeos/app_mode/external_update/no_manifest";
126 const char kFakeUsbMountPathBadManifest
[] =
127 "chromeos/app_mode/external_update/bad_manifest";
128 const char kFakeUsbMountPathLowerAppVersion
[] =
129 "chromeos/app_mode/external_update/lower_app_version";
130 const char kFakeUsbMountPathLowerCrxVersion
[] =
131 "chromeos/app_mode/external_update/lower_crx_version";
132 const char kFakeUsbMountPathBadCrx
[] =
133 "chromeos/app_mode/external_update/bad_crx";
135 // Timeout while waiting for network connectivity during tests.
136 const int kTestNetworkTimeoutSeconds
= 1;
138 // Email of owner account for test.
139 const char kTestOwnerEmail
[] = "owner@example.com";
141 const char kTestEnterpriseAccountId
[] = "enterprise-kiosk-app@localhost";
142 const char kTestEnterpriseServiceAccountId
[] = "service_account@example.com";
143 const char kTestRefreshToken
[] = "fake-refresh-token";
144 const char kTestUserinfoToken
[] = "fake-userinfo-token";
145 const char kTestLoginToken
[] = "fake-login-token";
146 const char kTestAccessToken
[] = "fake-access-token";
147 const char kTestClientId
[] = "fake-client-id";
148 const char kTestAppScope
[] =
149 "https://www.googleapis.com/auth/userinfo.profile";
152 const char kLaunchAppForTestNewAPI
[] =
153 "login.AccountPickerScreen.runAppForTesting";
154 const char kLaunchAppForTestOldAPI
[] =
155 "login.AppsMenuButton.runAppForTesting";
156 const char kCheckDiagnosticModeNewAPI
[] =
157 "$('oobe').confirmDiagnosticMode_";
158 const char kCheckDiagnosticModeOldAPI
[] =
159 "$('show-apps-button').confirmDiagnosticMode_";
161 // Helper function for GetConsumerKioskAutoLaunchStatusCallback.
162 void ConsumerKioskAutoLaunchStatusCheck(
163 KioskAppManager::ConsumerKioskAutoLaunchStatus
* out_status
,
164 const base::Closure
& runner_quit_task
,
165 KioskAppManager::ConsumerKioskAutoLaunchStatus in_status
) {
166 LOG(INFO
) << "KioskAppManager::ConsumerKioskModeStatus = " << in_status
;
167 *out_status
= in_status
;
168 runner_quit_task
.Run();
171 // Helper KioskAppManager::EnableKioskModeCallback implementation.
172 void ConsumerKioskModeAutoStartLockCheck(
174 const base::Closure
& runner_quit_task
,
176 LOG(INFO
) << "kiosk locked = " << in_locked
;
177 *out_locked
= in_locked
;
178 runner_quit_task
.Run();
181 // Helper function for WaitForNetworkTimeOut.
182 void OnNetworkWaitTimedOut(const base::Closure
& runner_quit_task
) {
183 runner_quit_task
.Run();
186 // Helper function for LockFileThread.
187 void LockAndUnlock(scoped_ptr
<base::Lock
> lock
) {
192 // Helper functions for CanConfigureNetwork mock.
193 class ScopedCanConfigureNetwork
{
195 ScopedCanConfigureNetwork(bool can_configure
, bool needs_owner_auth
)
196 : can_configure_(can_configure
),
197 needs_owner_auth_(needs_owner_auth
),
198 can_configure_network_callback_(
199 base::Bind(&ScopedCanConfigureNetwork::CanConfigureNetwork
,
200 base::Unretained(this))),
201 needs_owner_auth_callback_(base::Bind(
202 &ScopedCanConfigureNetwork::NeedsOwnerAuthToConfigureNetwork
,
203 base::Unretained(this))) {
204 AppLaunchController::SetCanConfigureNetworkCallbackForTesting(
205 &can_configure_network_callback_
);
206 AppLaunchController::SetNeedOwnerAuthToConfigureNetworkCallbackForTesting(
207 &needs_owner_auth_callback_
);
209 ~ScopedCanConfigureNetwork() {
210 AppLaunchController::SetCanConfigureNetworkCallbackForTesting(NULL
);
211 AppLaunchController::SetNeedOwnerAuthToConfigureNetworkCallbackForTesting(
215 bool CanConfigureNetwork() {
216 return can_configure_
;
219 bool NeedsOwnerAuthToConfigureNetwork() {
220 return needs_owner_auth_
;
225 bool needs_owner_auth_
;
226 AppLaunchController::ReturnBoolCallback can_configure_network_callback_
;
227 AppLaunchController::ReturnBoolCallback needs_owner_auth_callback_
;
228 DISALLOW_COPY_AND_ASSIGN(ScopedCanConfigureNetwork
);
231 // Helper class to wait until a js condition becomes true.
232 class JsConditionWaiter
{
234 JsConditionWaiter(content::WebContents
* web_contents
,
235 const std::string
& js
)
236 : web_contents_(web_contents
),
244 base::RepeatingTimer
<JsConditionWaiter
> check_timer
;
247 base::TimeDelta::FromMilliseconds(10),
249 &JsConditionWaiter::OnTimer
);
251 runner_
= new content::MessageLoopRunner
;
258 CHECK(content::ExecuteScriptAndExtractBool(
260 "window.domAutomationController.send(!!(" + js_
+ "));",
266 DCHECK(runner_
.get());
271 content::WebContents
* web_contents_
;
272 const std::string js_
;
273 scoped_refptr
<content::MessageLoopRunner
> runner_
;
275 DISALLOW_COPY_AND_ASSIGN(JsConditionWaiter
);
278 class KioskFakeDiskMountManager
: public file_manager::FakeDiskMountManager
{
280 KioskFakeDiskMountManager() {}
282 ~KioskFakeDiskMountManager() override
{}
284 void set_usb_mount_path(const std::string
& usb_mount_path
) {
285 usb_mount_path_
= usb_mount_path
;
288 void MountUsbStick() {
289 DCHECK(!usb_mount_path_
.empty());
290 MountPath(usb_mount_path_
, "", "", chromeos::MOUNT_TYPE_DEVICE
);
293 void UnMountUsbStick() {
294 DCHECK(!usb_mount_path_
.empty());
295 UnmountPath(usb_mount_path_
,
296 UNMOUNT_OPTIONS_NONE
,
297 disks::DiskMountManager::UnmountPathCallback());
301 std::string usb_mount_path_
;
303 DISALLOW_COPY_AND_ASSIGN(KioskFakeDiskMountManager
);
306 class AppDataLoadWaiter
: public KioskAppManagerObserver
{
308 AppDataLoadWaiter(KioskAppManager
* manager
,
309 const std::string
& app_id
,
310 const std::string
& version
)
313 wait_type_(WAIT_FOR_CRX_CACHE
),
318 manager_
->AddObserver(this);
321 ~AppDataLoadWaiter() override
{ manager_
->RemoveObserver(this); }
324 wait_type_
= WAIT_FOR_CRX_CACHE
;
327 runner_
= new content::MessageLoopRunner
;
331 void WaitForAppData() {
332 wait_type_
= WAIT_FOR_APP_DATA
;
333 if (quit_
|| IsAppDataLoaded())
335 runner_
= new content::MessageLoopRunner
;
339 bool loaded() const { return loaded_
; }
347 // KioskAppManagerObserver overrides:
348 void OnKioskAppDataChanged(const std::string
& app_id
) override
{
349 if (wait_type_
!= WAIT_FOR_APP_DATA
||
351 !IsAppDataLoaded()) {
361 void OnKioskAppDataLoadFailure(const std::string
& app_id
) override
{
362 if (wait_type_
!= WAIT_FOR_APP_DATA
|| app_id
!= app_id_
)
371 void OnKioskExtensionLoadedInCache(const std::string
& app_id
) override
{
372 if (wait_type_
!= WAIT_FOR_CRX_CACHE
)
375 std::string cached_version
;
376 base::FilePath file_path
;
377 if (!manager_
->GetCachedCrx(app_id_
, &file_path
, &cached_version
))
379 if (version_
!= cached_version
)
387 void OnKioskExtensionDownloadFailed(const std::string
& app_id
) override
{
388 if (wait_type_
!= WAIT_FOR_CRX_CACHE
)
397 bool IsAppDataLoaded() {
398 KioskAppManager::App app
;
399 return manager_
->GetApp(app_id_
, &app
) && !app
.is_loading
;
402 scoped_refptr
<content::MessageLoopRunner
> runner_
;
403 KioskAppManager
* manager_
;
408 std::string version_
;
410 DISALLOW_COPY_AND_ASSIGN(AppDataLoadWaiter
);
415 class KioskTest
: public OobeBaseTest
{
418 : settings_helper_(false),
419 use_consumer_kiosk_mode_(true),
420 fake_cws_(new FakeCWS
) {
421 set_exit_when_last_browser_closes(false);
424 ~KioskTest() override
{}
427 void SetUp() override
{
428 test_app_id_
= kTestKioskApp
;
429 set_test_app_version("1.0.0");
430 set_test_crx_file(test_app_id() + ".crx");
431 needs_background_networking_
= true;
432 mock_user_manager_
.reset(new MockUserManager
);
433 ProfileHelper::SetAlwaysReturnPrimaryUserForTesting(true);
434 AppLaunchController::SkipSplashWaitForTesting();
435 AppLaunchController::SetNetworkWaitForTesting(kTestNetworkTimeoutSeconds
);
437 OobeBaseTest::SetUp();
440 void TearDown() override
{
441 ProfileHelper::SetAlwaysReturnPrimaryUserForTesting(false);
442 OobeBaseTest::TearDown();
445 void SetUpOnMainThread() override
{
446 OobeBaseTest::SetUpOnMainThread();
447 // Needed to avoid showing Gaia screen instead of owner signin for
448 // consumer network down test cases.
449 StartupUtils::MarkDeviceRegistered(base::Closure());
450 settings_helper_
.ReplaceProvider(kAccountsPrefDeviceLocalAccounts
);
451 owner_settings_service_
= settings_helper_
.CreateOwnerSettingsService(
452 ProfileManager::GetPrimaryUserProfile());
455 void TearDownOnMainThread() override
{
456 settings_helper_
.RestoreProvider();
457 AppLaunchController::SetNetworkTimeoutCallbackForTesting(NULL
);
458 AppLaunchSigninScreen::SetUserManagerForTesting(NULL
);
460 OobeBaseTest::TearDownOnMainThread();
462 // Clean up while main thread still runs.
463 // See http://crbug.com/176659.
464 KioskAppManager::Get()->CleanUp();
467 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
468 OobeBaseTest::SetUpCommandLine(command_line
);
469 fake_cws_
->Init(embedded_test_server());
472 void LaunchApp(const std::string
& app_id
, bool diagnostic_mode
) {
473 bool new_kiosk_ui
= KioskAppMenuHandler::EnableNewKioskUI();
474 GetLoginUI()->CallJavascriptFunction(new_kiosk_ui
?
475 kLaunchAppForTestNewAPI
: kLaunchAppForTestOldAPI
,
476 base::StringValue(app_id
),
477 base::FundamentalValue(diagnostic_mode
));
480 void ReloadKioskApps() {
481 SetupTestAppUpdateCheck();
483 // Remove then add to ensure NOTIFICATION_KIOSK_APPS_LOADED fires.
484 KioskAppManager::Get()->RemoveApp(test_app_id_
,
485 owner_settings_service_
.get());
486 KioskAppManager::Get()->AddApp(test_app_id_
, owner_settings_service_
.get());
489 void FireKioskAppSettingsChanged() {
490 KioskAppManager::Get()->UpdateAppData();
493 void SetupTestAppUpdateCheck() {
494 if (!test_app_version().empty()) {
495 fake_cws_
->SetUpdateCrx(
496 test_app_id(), test_crx_file(), test_app_version());
500 void ReloadAutolaunchKioskApps() {
501 SetupTestAppUpdateCheck();
503 KioskAppManager::Get()->AddApp(test_app_id_
, owner_settings_service_
.get());
504 KioskAppManager::Get()->SetAutoLaunchApp(test_app_id_
,
505 owner_settings_service_
.get());
508 void StartUIForAppLaunch() {
509 if (use_consumer_kiosk_mode_
)
510 EnableConsumerKioskMode();
513 chromeos::WizardController::SkipPostLoginScreensForTesting();
514 chromeos::WizardController
* wizard_controller
=
515 chromeos::WizardController::default_controller();
516 if (wizard_controller
) {
517 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
518 OobeScreenWaiter(OobeDisplay::SCREEN_GAIA_SIGNIN
).Wait();
520 // No wizard and running with an existing profile and it should land
521 // on account picker when new kiosk UI is enabled. Otherwise, just
522 // wait for the login signal from Gaia.
523 if (KioskAppMenuHandler::EnableNewKioskUI())
524 OobeScreenWaiter(OobeDisplay::SCREEN_ACCOUNT_PICKER
).Wait();
526 OobeScreenWaiter(OobeDisplay::SCREEN_GAIA_SIGNIN
).Wait();
530 void PrepareAppLaunch() {
532 StartUIForAppLaunch();
534 // Wait for the Kiosk App configuration to reload.
535 content::WindowedNotificationObserver
apps_loaded_signal(
536 chrome::NOTIFICATION_KIOSK_APPS_LOADED
,
537 content::NotificationService::AllSources());
539 apps_loaded_signal
.Wait();
542 void StartAppLaunchFromLoginScreen(const base::Closure
& network_setup_cb
) {
545 if (!network_setup_cb
.is_null())
546 network_setup_cb
.Run();
548 LaunchApp(test_app_id(), false);
551 const extensions::Extension
* GetInstalledApp() {
552 Profile
* app_profile
= ProfileManager::GetPrimaryUserProfile();
553 return extensions::ExtensionSystem::Get(app_profile
)->
554 extension_service()->GetInstalledExtension(test_app_id_
);
557 const Version
& GetInstalledAppVersion() {
558 return *GetInstalledApp()->version();
561 void WaitForAppLaunchWithOptions(bool check_launch_data
, bool terminate_app
) {
562 ExtensionTestMessageListener
563 launch_data_check_listener("launchData.isKioskSession = true", false);
565 // Wait for the Kiosk App to launch.
566 content::WindowedNotificationObserver(
567 chrome::NOTIFICATION_KIOSK_APP_LAUNCHED
,
568 content::NotificationService::AllSources()).Wait();
570 // Default profile switches to app profile after app is launched.
571 Profile
* app_profile
= ProfileManager::GetPrimaryUserProfile();
572 ASSERT_TRUE(app_profile
);
574 // Check ChromeOS preference is initialized.
576 static_cast<ProfileImpl
*>(app_profile
)->chromeos_preferences_
);
578 // Check installer status.
579 EXPECT_EQ(chromeos::KioskAppLaunchError::NONE
,
580 chromeos::KioskAppLaunchError::Get());
582 // Check if the kiosk webapp is really installed for the default profile.
583 const extensions::Extension
* app
=
584 extensions::ExtensionSystem::Get(app_profile
)->
585 extension_service()->GetInstalledExtension(test_app_id_
);
588 // App should appear with its window.
589 extensions::AppWindowRegistry
* app_window_registry
=
590 extensions::AppWindowRegistry::Get(app_profile
);
591 extensions::AppWindow
* window
=
592 AppWindowWaiter(app_window_registry
, test_app_id_
).Wait();
595 // Login screen should be gone or fading out.
596 chromeos::LoginDisplayHost
* login_display_host
=
597 chromeos::LoginDisplayHostImpl::default_host();
599 login_display_host
== NULL
||
600 login_display_host
->GetNativeWindow()->layer()->GetTargetOpacity() ==
603 // Terminate the app.
605 window
->GetBaseWindow()->Close();
607 // Wait until the app terminates if it is still running.
608 if (!app_window_registry
->GetAppWindowsForApp(test_app_id_
).empty())
609 content::RunMessageLoop();
611 // Check that the app had been informed that it is running in a kiosk
613 if (check_launch_data
)
614 EXPECT_TRUE(launch_data_check_listener
.was_satisfied());
617 void WaitForAppLaunchSuccess() {
618 WaitForAppLaunchWithOptions(true /* check_launch_data */,
619 true /* terminate_app */);
622 void WaitForAppLaunchNetworkTimeout() {
623 if (GetAppLaunchController()->network_wait_timedout())
626 scoped_refptr
<content::MessageLoopRunner
> runner
=
627 new content::MessageLoopRunner
;
629 base::Closure callback
= base::Bind(
630 &OnNetworkWaitTimedOut
, runner
->QuitClosure());
631 AppLaunchController::SetNetworkTimeoutCallbackForTesting(&callback
);
635 CHECK(GetAppLaunchController()->network_wait_timedout());
636 AppLaunchController::SetNetworkTimeoutCallbackForTesting(NULL
);
639 void EnableConsumerKioskMode() {
640 scoped_ptr
<bool> locked(new bool(false));
641 scoped_refptr
<content::MessageLoopRunner
> runner
=
642 new content::MessageLoopRunner
;
643 KioskAppManager::Get()->EnableConsumerKioskAutoLaunch(
644 base::Bind(&ConsumerKioskModeAutoStartLockCheck
,
646 runner
->QuitClosure()));
648 EXPECT_TRUE(*locked
.get());
651 KioskAppManager::ConsumerKioskAutoLaunchStatus
652 GetConsumerKioskModeStatus() {
653 KioskAppManager::ConsumerKioskAutoLaunchStatus status
=
654 static_cast<KioskAppManager::ConsumerKioskAutoLaunchStatus
>(-1);
655 scoped_refptr
<content::MessageLoopRunner
> runner
=
656 new content::MessageLoopRunner
;
657 KioskAppManager::Get()->GetConsumerKioskAutoLaunchStatus(
658 base::Bind(&ConsumerKioskAutoLaunchStatusCheck
,
660 runner
->QuitClosure()));
663 static_cast<KioskAppManager::ConsumerKioskAutoLaunchStatus
>(-1));
667 void RunAppLaunchNetworkDownTest() {
668 mock_user_manager()->SetActiveUser(kTestOwnerEmail
);
669 AppLaunchSigninScreen::SetUserManagerForTesting(mock_user_manager());
671 // Mock network could be configured with owner's password.
672 ScopedCanConfigureNetwork
can_configure_network(true, true);
674 // Start app launch and wait for network connectivity timeout.
675 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure());
676 OobeScreenWaiter
splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH
);
677 splash_waiter
.Wait();
678 WaitForAppLaunchNetworkTimeout();
680 // Configure network link should be visible.
681 JsExpect("$('splash-config-network').hidden == false");
683 // Set up fake user manager with an owner for the test.
684 static_cast<LoginDisplayHostImpl
*>(LoginDisplayHostImpl::default_host())
685 ->GetOobeUI()->ShowOobeUI(false);
687 // Configure network should bring up lock screen for owner.
688 OobeScreenWaiter
lock_screen_waiter(OobeDisplay::SCREEN_ACCOUNT_PICKER
);
689 static_cast<AppLaunchSplashScreenActor::Delegate
*>(GetAppLaunchController())
690 ->OnConfigureNetwork();
691 lock_screen_waiter
.Wait();
693 // There should be only one owner pod on this screen.
694 JsExpect("$('pod-row').alwaysFocusSinglePod");
696 // A network error screen should be shown after authenticating.
697 OobeScreenWaiter
error_screen_waiter(OobeDisplay::SCREEN_ERROR_MESSAGE
);
698 static_cast<AppLaunchSigninScreen::Delegate
*>(GetAppLaunchController())
699 ->OnOwnerSigninSuccess();
700 error_screen_waiter
.Wait();
702 ASSERT_TRUE(GetAppLaunchController()->showing_network_dialog());
704 SimulateNetworkOnline();
705 WaitForAppLaunchSuccess();
708 AppLaunchController
* GetAppLaunchController() {
709 return chromeos::LoginDisplayHostImpl::default_host()
710 ->GetAppLaunchController();
713 // Returns a lock that is holding a task on the FILE thread. Any tasks posted
714 // to the FILE thread after this call will be blocked until the returned
716 // This can be used to prevent app installation from completing until some
717 // other conditions are checked and triggered. For example, this can be used
718 // to trigger the network screen during app launch without racing with the
719 // app launching process itself.
720 scoped_ptr
<base::AutoLock
> LockFileThread() {
721 scoped_ptr
<base::Lock
> lock(new base::Lock
);
722 scoped_ptr
<base::AutoLock
> auto_lock(new base::AutoLock(*lock
));
723 content::BrowserThread::PostTask(
724 content::BrowserThread::FILE, FROM_HERE
,
725 base::Bind(&LockAndUnlock
, base::Passed(&lock
)));
726 return auto_lock
.Pass();
729 MockUserManager
* mock_user_manager() { return mock_user_manager_
.get(); }
731 void set_test_app_id(const std::string
& test_app_id
) {
732 test_app_id_
= test_app_id
;
734 const std::string
& test_app_id() const { return test_app_id_
; }
735 void set_test_app_version(const std::string
& version
) {
736 test_app_version_
= version
;
738 const std::string
& test_app_version() const { return test_app_version_
; }
739 void set_test_crx_file(const std::string
& filename
) {
740 test_crx_file_
= filename
;
742 const std::string
& test_crx_file() const { return test_crx_file_
; }
743 FakeCWS
* fake_cws() { return fake_cws_
.get(); }
745 void set_use_consumer_kiosk_mode(bool use
) {
746 use_consumer_kiosk_mode_
= use
;
749 ScopedCrosSettingsTestHelper settings_helper_
;
750 scoped_ptr
<FakeOwnerSettingsService
> owner_settings_service_
;
753 bool use_consumer_kiosk_mode_
;
754 std::string test_app_id_
;
755 std::string test_app_version_
;
756 std::string test_crx_file_
;
757 scoped_ptr
<FakeCWS
> fake_cws_
;
758 scoped_ptr
<MockUserManager
> mock_user_manager_
;
760 DISALLOW_COPY_AND_ASSIGN(KioskTest
);
763 IN_PROC_BROWSER_TEST_F(KioskTest
, InstallAndLaunchApp
) {
764 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
765 WaitForAppLaunchSuccess();
766 KioskAppManager::App app
;
767 ASSERT_TRUE(KioskAppManager::Get()->GetApp(test_app_id(), &app
));
768 EXPECT_FALSE(app
.was_auto_launched_with_zero_delay
);
771 IN_PROC_BROWSER_TEST_F(KioskTest
, ZoomSupport
) {
772 ExtensionTestMessageListener
773 app_window_loaded_listener("appWindowLoaded", false);
774 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
775 app_window_loaded_listener
.WaitUntilSatisfied();
777 Profile
* app_profile
= ProfileManager::GetPrimaryUserProfile();
778 ASSERT_TRUE(app_profile
);
780 extensions::AppWindowRegistry
* app_window_registry
=
781 extensions::AppWindowRegistry::Get(app_profile
);
782 extensions::AppWindow
* window
=
783 AppWindowWaiter(app_window_registry
, test_app_id()).Wait();
786 // Gets the original width of the app window.
788 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
789 window
->web_contents(),
790 "window.domAutomationController.setAutomationId(0);"
791 "window.domAutomationController.send(window.innerWidth);",
794 native_app_window::NativeAppWindowViews
* native_app_window_views
=
795 static_cast<native_app_window::NativeAppWindowViews
*>(
796 window
->GetBaseWindow());
797 ui::AcceleratorTarget
* accelerator_target
=
798 static_cast<ui::AcceleratorTarget
*>(native_app_window_views
);
800 // Zoom in. Text is bigger and content window width becomes smaller.
801 accelerator_target
->AcceleratorPressed(ui::Accelerator(
802 ui::VKEY_ADD
, ui::EF_CONTROL_DOWN
));
804 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
805 window
->web_contents(),
806 "window.domAutomationController.setAutomationId(0);"
807 "window.domAutomationController.send(window.innerWidth);",
809 DCHECK_LT(width_zoomed_in
, original_width
);
811 // Go back to normal. Window width is restored.
812 accelerator_target
->AcceleratorPressed(ui::Accelerator(
813 ui::VKEY_0
, ui::EF_CONTROL_DOWN
));
814 int width_zoom_normal
;
815 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
816 window
->web_contents(),
817 "window.domAutomationController.setAutomationId(0);"
818 "window.domAutomationController.send(window.innerWidth);",
819 &width_zoom_normal
));
820 DCHECK_EQ(width_zoom_normal
, original_width
);
822 // Zoom out. Text is smaller and content window width becomes larger.
823 accelerator_target
->AcceleratorPressed(ui::Accelerator(
824 ui::VKEY_SUBTRACT
, ui::EF_CONTROL_DOWN
));
825 int width_zoomed_out
;
826 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
827 window
->web_contents(),
828 "window.domAutomationController.setAutomationId(0);"
829 "window.domAutomationController.send(window.innerWidth);",
831 DCHECK_GT(width_zoomed_out
, original_width
);
833 // Terminate the app.
834 window
->GetBaseWindow()->Close();
835 content::RunAllPendingInMessageLoop();
838 IN_PROC_BROWSER_TEST_F(KioskTest
, NotSignedInWithGAIAAccount
) {
839 // Tests that the kiosk session is not considered to be logged in with a GAIA
841 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
842 WaitForAppLaunchSuccess();
844 Profile
* app_profile
= ProfileManager::GetPrimaryUserProfile();
845 ASSERT_TRUE(app_profile
);
847 SigninManagerFactory::GetForProfile(app_profile
)->IsAuthenticated());
850 IN_PROC_BROWSER_TEST_F(KioskTest
, PRE_LaunchAppNetworkDown
) {
851 // Tests the network down case for the initial app download and launch.
852 RunAppLaunchNetworkDownTest();
855 IN_PROC_BROWSER_TEST_F(KioskTest
, LaunchAppNetworkDown
) {
856 // Tests the network down case for launching an existing app that is
857 // installed in PRE_LaunchAppNetworkDown.
858 RunAppLaunchNetworkDownTest();
861 IN_PROC_BROWSER_TEST_F(KioskTest
, LaunchAppWithNetworkConfigAccelerator
) {
862 ScopedCanConfigureNetwork
can_configure_network(true, false);
864 // Block app loading until the network screen is shown.
865 scoped_ptr
<base::AutoLock
> lock
= LockFileThread();
867 // Start app launch and wait for network connectivity timeout.
868 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
869 OobeScreenWaiter
splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH
);
870 splash_waiter
.Wait();
872 // A network error screen should be shown after authenticating.
873 OobeScreenWaiter
error_screen_waiter(OobeDisplay::SCREEN_ERROR_MESSAGE
);
874 // Simulate Ctrl+Alt+N accelerator.
875 GetLoginUI()->CallJavascriptFunction(
876 "cr.ui.Oobe.handleAccelerator",
877 base::StringValue("app_launch_network_config"));
878 error_screen_waiter
.Wait();
879 ASSERT_TRUE(GetAppLaunchController()->showing_network_dialog());
881 // Continue button should be visible since we are online.
882 JsExpect("$('continue-network-config-btn').hidden == false");
884 // Click on [Continue] button.
885 ASSERT_TRUE(content::ExecuteScript(
886 GetLoginUI()->GetWebContents(),
888 "var e = new Event('click');"
889 "$('continue-network-config-btn').dispatchEvent(e);"
892 // Let app launching resume.
895 WaitForAppLaunchSuccess();
898 IN_PROC_BROWSER_TEST_F(KioskTest
, LaunchAppNetworkDownConfigureNotAllowed
) {
899 // Mock network could not be configured.
900 ScopedCanConfigureNetwork
can_configure_network(false, true);
902 // Start app launch and wait for network connectivity timeout.
903 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure());
904 OobeScreenWaiter
splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH
);
905 splash_waiter
.Wait();
906 WaitForAppLaunchNetworkTimeout();
908 // Configure network link should not be visible.
909 JsExpect("$('splash-config-network').hidden == true");
911 // Network becomes online and app launch is resumed.
912 SimulateNetworkOnline();
913 WaitForAppLaunchSuccess();
916 IN_PROC_BROWSER_TEST_F(KioskTest
, LaunchAppNetworkPortal
) {
917 // Mock network could be configured without the owner password.
918 ScopedCanConfigureNetwork
can_configure_network(true, false);
920 // Start app launch with network portal state.
921 StartAppLaunchFromLoginScreen(SimulateNetworkPortalClosure());
922 OobeScreenWaiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH
)
923 .WaitNoAssertCurrentScreen();
924 WaitForAppLaunchNetworkTimeout();
926 // Network error should show up automatically since this test does not
927 // require owner auth to configure network.
928 OobeScreenWaiter(OobeDisplay::SCREEN_ERROR_MESSAGE
).Wait();
930 ASSERT_TRUE(GetAppLaunchController()->showing_network_dialog());
931 SimulateNetworkOnline();
932 WaitForAppLaunchSuccess();
935 IN_PROC_BROWSER_TEST_F(KioskTest
, LaunchAppUserCancel
) {
936 // Make fake_cws_ return empty update response.
937 set_test_app_version("");
938 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure());
939 OobeScreenWaiter
splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH
);
940 splash_waiter
.Wait();
942 settings_helper_
.SetBoolean(
943 kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled
, true);
944 content::WindowedNotificationObserver
signal(
945 chrome::NOTIFICATION_APP_TERMINATING
,
946 content::NotificationService::AllSources());
947 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
948 base::StringValue("app_launch_bailout"));
950 EXPECT_EQ(chromeos::KioskAppLaunchError::USER_CANCEL
,
951 chromeos::KioskAppLaunchError::Get());
954 IN_PROC_BROWSER_TEST_F(KioskTest
, LaunchInDiagnosticMode
) {
956 SimulateNetworkOnline();
958 LaunchApp(kTestKioskApp
, true);
960 content::WebContents
* login_contents
= GetLoginUI()->GetWebContents();
962 bool new_kiosk_ui
= KioskAppMenuHandler::EnableNewKioskUI();
963 JsConditionWaiter(login_contents
, new_kiosk_ui
?
964 kCheckDiagnosticModeNewAPI
: kCheckDiagnosticModeOldAPI
).Wait();
966 std::string
diagnosticMode(new_kiosk_ui
?
967 kCheckDiagnosticModeNewAPI
: kCheckDiagnosticModeOldAPI
);
968 ASSERT_TRUE(content::ExecuteScript(
971 "var e = new Event('click');" +
973 "okButton_.dispatchEvent(e);"
976 WaitForAppLaunchSuccess();
979 IN_PROC_BROWSER_TEST_F(KioskTest
, AutolaunchWarningCancel
) {
980 EnableConsumerKioskMode();
982 chromeos::WizardController::SkipPostLoginScreensForTesting();
983 chromeos::WizardController
* wizard_controller
=
984 chromeos::WizardController::default_controller();
985 CHECK(wizard_controller
);
987 // Start login screen after configuring auto launch app since the warning
988 // is triggered when switching to login screen.
989 wizard_controller
->AdvanceToScreen(WizardController::kNetworkScreenName
);
990 ReloadAutolaunchKioskApps();
991 EXPECT_FALSE(KioskAppManager::Get()->GetAutoLaunchApp().empty());
992 EXPECT_FALSE(KioskAppManager::Get()->IsAutoLaunchEnabled());
993 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
995 // Wait for the auto launch warning come up.
996 content::WindowedNotificationObserver(
997 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE
,
998 content::NotificationService::AllSources()).Wait();
999 GetLoginUI()->CallJavascriptFunction(
1000 "login.AutolaunchScreen.confirmAutoLaunchForTesting",
1001 base::FundamentalValue(false));
1003 // Wait for the auto launch warning to go away.
1004 content::WindowedNotificationObserver(
1005 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_COMPLETED
,
1006 content::NotificationService::AllSources()).Wait();
1008 EXPECT_FALSE(KioskAppManager::Get()->IsAutoLaunchEnabled());
1011 IN_PROC_BROWSER_TEST_F(KioskTest
, AutolaunchWarningConfirm
) {
1012 EnableConsumerKioskMode();
1014 chromeos::WizardController::SkipPostLoginScreensForTesting();
1015 chromeos::WizardController
* wizard_controller
=
1016 chromeos::WizardController::default_controller();
1017 CHECK(wizard_controller
);
1019 // Start login screen after configuring auto launch app since the warning
1020 // is triggered when switching to login screen.
1021 wizard_controller
->AdvanceToScreen(WizardController::kNetworkScreenName
);
1022 ReloadAutolaunchKioskApps();
1023 EXPECT_FALSE(KioskAppManager::Get()->GetAutoLaunchApp().empty());
1024 EXPECT_FALSE(KioskAppManager::Get()->IsAutoLaunchEnabled());
1025 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
1027 // Wait for the auto launch warning come up.
1028 content::WindowedNotificationObserver(
1029 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE
,
1030 content::NotificationService::AllSources()).Wait();
1031 GetLoginUI()->CallJavascriptFunction(
1032 "login.AutolaunchScreen.confirmAutoLaunchForTesting",
1033 base::FundamentalValue(true));
1035 // Wait for the auto launch warning to go away.
1036 content::WindowedNotificationObserver(
1037 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_COMPLETED
,
1038 content::NotificationService::AllSources()).Wait();
1040 EXPECT_FALSE(KioskAppManager::Get()->GetAutoLaunchApp().empty());
1041 EXPECT_TRUE(KioskAppManager::Get()->IsAutoLaunchEnabled());
1043 WaitForAppLaunchSuccess();
1045 KioskAppManager::App app
;
1046 ASSERT_TRUE(KioskAppManager::Get()->GetApp(test_app_id(), &app
));
1047 EXPECT_TRUE(app
.was_auto_launched_with_zero_delay
);
1050 IN_PROC_BROWSER_TEST_F(KioskTest
, KioskEnableCancel
) {
1051 chromeos::WizardController::SkipPostLoginScreensForTesting();
1052 chromeos::WizardController
* wizard_controller
=
1053 chromeos::WizardController::default_controller();
1054 CHECK(wizard_controller
);
1056 // Check Kiosk mode status.
1057 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE
,
1058 GetConsumerKioskModeStatus());
1060 // Wait for the login UI to come up and switch to the kiosk_enable screen.
1061 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
1062 OobeScreenWaiter(OobeDisplay::SCREEN_GAIA_SIGNIN
).Wait();
1063 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
1064 base::StringValue("kiosk_enable"));
1066 // Wait for the kiosk_enable screen to show and cancel the screen.
1067 content::WindowedNotificationObserver(
1068 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE
,
1069 content::NotificationService::AllSources()).Wait();
1070 GetLoginUI()->CallJavascriptFunction(
1071 "login.KioskEnableScreen.enableKioskForTesting",
1072 base::FundamentalValue(false));
1074 // Wait for the kiosk_enable screen to disappear.
1075 content::WindowedNotificationObserver(
1076 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_COMPLETED
,
1077 content::NotificationService::AllSources()).Wait();
1079 // Check that the status still says configurable.
1080 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE
,
1081 GetConsumerKioskModeStatus());
1084 IN_PROC_BROWSER_TEST_F(KioskTest
, KioskEnableConfirmed
) {
1085 // Start UI, find menu entry for this app and launch it.
1086 chromeos::WizardController::SkipPostLoginScreensForTesting();
1087 chromeos::WizardController
* wizard_controller
=
1088 chromeos::WizardController::default_controller();
1089 CHECK(wizard_controller
);
1091 // Check Kiosk mode status.
1092 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE
,
1093 GetConsumerKioskModeStatus());
1095 // Wait for the login UI to come up and switch to the kiosk_enable screen.
1096 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
1097 OobeScreenWaiter(OobeDisplay::SCREEN_GAIA_SIGNIN
).Wait();
1098 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
1099 base::StringValue("kiosk_enable"));
1101 // Wait for the kiosk_enable screen to show and cancel the screen.
1102 content::WindowedNotificationObserver(
1103 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE
,
1104 content::NotificationService::AllSources()).Wait();
1105 GetLoginUI()->CallJavascriptFunction(
1106 "login.KioskEnableScreen.enableKioskForTesting",
1107 base::FundamentalValue(true));
1109 // Wait for the signal that indicates Kiosk Mode is enabled.
1110 content::WindowedNotificationObserver(
1111 chrome::NOTIFICATION_KIOSK_ENABLED
,
1112 content::NotificationService::AllSources()).Wait();
1113 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_ENABLED
,
1114 GetConsumerKioskModeStatus());
1117 IN_PROC_BROWSER_TEST_F(KioskTest
, KioskEnableAfter2ndSigninScreen
) {
1118 chromeos::WizardController::SkipPostLoginScreensForTesting();
1119 chromeos::WizardController
* wizard_controller
=
1120 chromeos::WizardController::default_controller();
1121 CHECK(wizard_controller
);
1123 // Check Kiosk mode status.
1124 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE
,
1125 GetConsumerKioskModeStatus());
1127 // Wait for the login UI to come up and switch to the kiosk_enable screen.
1128 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
1129 OobeScreenWaiter(OobeDisplay::SCREEN_GAIA_SIGNIN
).Wait();
1130 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
1131 base::StringValue("kiosk_enable"));
1133 // Wait for the kiosk_enable screen to show and cancel the screen.
1134 content::WindowedNotificationObserver(
1135 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE
,
1136 content::NotificationService::AllSources()).Wait();
1137 GetLoginUI()->CallJavascriptFunction(
1138 "login.KioskEnableScreen.enableKioskForTesting",
1139 base::FundamentalValue(false));
1141 // Wait for the kiosk_enable screen to disappear.
1142 content::WindowedNotificationObserver(
1143 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_COMPLETED
,
1144 content::NotificationService::AllSources()).Wait();
1146 // Show signin screen again.
1147 chromeos::LoginDisplayHostImpl::default_host()->StartSignInScreen(
1148 LoginScreenContext());
1149 OobeScreenWaiter(OobeDisplay::SCREEN_GAIA_SIGNIN
).Wait();
1151 // Show kiosk enable screen again.
1152 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
1153 base::StringValue("kiosk_enable"));
1155 // And it should show up.
1156 content::WindowedNotificationObserver(
1157 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE
,
1158 content::NotificationService::AllSources()).Wait();
1161 IN_PROC_BROWSER_TEST_F(KioskTest
, DoNotLaunchWhenUntrusted
) {
1163 SimulateNetworkOnline();
1165 // Make cros settings untrusted.
1166 settings_helper_
.SetTrustedStatus(
1167 CrosSettingsProvider::PERMANENTLY_UNTRUSTED
);
1169 // Check that the attempt to start a kiosk app fails with an error.
1170 LaunchApp(test_app_id(), false);
1171 bool ignored
= false;
1172 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
1173 GetLoginUI()->GetWebContents(),
1174 "if (cr.ui.Oobe.getInstance().errorMessageWasShownForTesting_) {"
1175 " window.domAutomationController.send(true);"
1177 " cr.ui.Oobe.showSignInError = function("
1178 " loginAttempts, message, link, helpId) {"
1179 " window.domAutomationController.send(true);"
1185 // Verifies that a consumer device does not auto-launch kiosk mode when cros
1186 // settings are untrusted.
1187 IN_PROC_BROWSER_TEST_F(KioskTest
, NoConsumerAutoLaunchWhenUntrusted
) {
1188 EnableConsumerKioskMode();
1190 // Wait for and confirm the auto-launch warning.
1191 chromeos::WizardController::SkipPostLoginScreensForTesting();
1192 chromeos::WizardController
* wizard_controller
=
1193 chromeos::WizardController::default_controller();
1194 ASSERT_TRUE(wizard_controller
);
1195 wizard_controller
->AdvanceToScreen(WizardController::kNetworkScreenName
);
1196 ReloadAutolaunchKioskApps();
1197 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
1198 content::WindowedNotificationObserver(
1199 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE
,
1200 content::NotificationService::AllSources()).Wait();
1201 GetLoginUI()->CallJavascriptFunction(
1202 "login.AutolaunchScreen.confirmAutoLaunchForTesting",
1203 base::FundamentalValue(true));
1205 // Make cros settings untrusted.
1206 settings_helper_
.SetTrustedStatus(
1207 CrosSettingsProvider::PERMANENTLY_UNTRUSTED
);
1209 // Check that the attempt to auto-launch a kiosk app fails with an error.
1210 OobeScreenWaiter(OobeDisplay::SCREEN_ERROR_MESSAGE
).Wait();
1213 // Verifies available volumes for kiosk apps in kiosk session.
1214 IN_PROC_BROWSER_TEST_F(KioskTest
, GetVolumeList
) {
1215 set_test_app_id(kTestGetVolumeListKioskApp
);
1216 set_test_app_version("0.1");
1217 set_test_crx_file(test_app_id() + ".crx");
1219 extensions::ResultCatcher catcher
;
1220 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
1221 ASSERT_TRUE(catcher
.GetNextResult()) << catcher
.message();
1224 // Verifies that an enterprise device does not auto-launch kiosk mode when cros
1225 // settings are untrusted.
1226 IN_PROC_BROWSER_TEST_F(KioskTest
, NoEnterpriseAutoLaunchWhenUntrusted
) {
1228 SimulateNetworkOnline();
1230 // Make cros settings untrusted.
1231 settings_helper_
.SetTrustedStatus(
1232 CrosSettingsProvider::PERMANENTLY_UNTRUSTED
);
1234 // Trigger the code that handles auto-launch on enterprise devices. This would
1235 // normally be called from ShowLoginWizard(), which runs so early that it is
1236 // not possible to inject an auto-launch policy before it runs.
1237 LoginDisplayHost
* login_display_host
= LoginDisplayHostImpl::default_host();
1238 ASSERT_TRUE(login_display_host
);
1239 login_display_host
->StartAppLaunch(test_app_id(), false, true);
1241 // Check that no launch has started.
1242 EXPECT_FALSE(login_display_host
->GetAppLaunchController());
1245 class KioskUpdateTest
: public KioskTest
{
1247 KioskUpdateTest() {}
1248 ~KioskUpdateTest() override
{}
1251 void SetUp() override
{
1252 fake_disk_mount_manager_
= new KioskFakeDiskMountManager();
1253 disks::DiskMountManager::InitializeForTesting(fake_disk_mount_manager_
);
1258 void TearDown() override
{
1259 disks::DiskMountManager::Shutdown();
1261 KioskTest::TearDown();
1264 void SetUpOnMainThread() override
{
1265 // For update tests, we cache the app in the PRE part, and then we load it
1266 // in the test, so we need to both store the apps list on teardown (so that
1267 // the app manager would accept existing files in its extension cache on the
1268 // next startup) and copy the list to our stub settings provider as well.
1269 settings_helper_
.CopyStoredValue(kAccountsPrefDeviceLocalAccounts
);
1270 KioskTest::SetUpOnMainThread();
1273 void TearDownOnMainThread() override
{
1274 settings_helper_
.StoreCachedDeviceSetting(kAccountsPrefDeviceLocalAccounts
);
1275 KioskTest::TearDownOnMainThread();
1278 void PreCacheApp(const std::string
& app_id
,
1279 const std::string
& version
,
1280 const std::string
& crx_file
) {
1281 set_test_app_id(app_id
);
1282 set_test_app_version(version
);
1283 set_test_crx_file(crx_file
);
1285 KioskAppManager
* manager
= KioskAppManager::Get();
1286 AppDataLoadWaiter
waiter(manager
, app_id
, version
);
1289 EXPECT_TRUE(waiter
.loaded());
1290 std::string cached_version
;
1291 base::FilePath file_path
;
1292 EXPECT_TRUE(manager
->GetCachedCrx(app_id
, &file_path
, &cached_version
));
1293 EXPECT_EQ(version
, cached_version
);
1296 void UpdateExternalCache(const std::string
& version
,
1297 const std::string
& crx_file
) {
1298 set_test_app_version(version
);
1299 set_test_crx_file(crx_file
);
1300 SetupTestAppUpdateCheck();
1302 KioskAppManager
* manager
= KioskAppManager::Get();
1303 AppDataLoadWaiter
waiter(manager
, test_app_id(), version
);
1304 KioskAppManager::Get()->UpdateExternalCache();
1306 EXPECT_TRUE(waiter
.loaded());
1307 std::string cached_version
;
1308 base::FilePath file_path
;
1310 manager
->GetCachedCrx(test_app_id(), &file_path
, &cached_version
));
1311 EXPECT_EQ(version
, cached_version
);
1314 void SetupFakeDiskMountManagerMountPath(const std::string mount_path
) {
1315 base::FilePath test_data_dir
;
1316 PathService::Get(chrome::DIR_TEST_DATA
, &test_data_dir
);
1317 test_data_dir
= test_data_dir
.AppendASCII(mount_path
);
1318 fake_disk_mount_manager_
->set_usb_mount_path(test_data_dir
.value());
1321 void SimulateUpdateAppFromUsbStick(const std::string
& usb_mount_path
,
1322 bool* app_update_notified
,
1323 bool* update_success
) {
1324 SetupFakeDiskMountManagerMountPath(usb_mount_path
);
1325 KioskAppExternalUpdateWaiter
waiter(KioskAppManager::Get(), test_app_id());
1326 fake_disk_mount_manager_
->MountUsbStick();
1328 fake_disk_mount_manager_
->UnMountUsbStick();
1329 *update_success
= waiter
.update_success();
1330 *app_update_notified
= waiter
.app_update_notified();
1333 void PreCacheAndLaunchApp(const std::string
& app_id
,
1334 const std::string
& version
,
1335 const std::string
& crx_file
) {
1336 set_test_app_id(app_id
);
1337 set_test_app_version(version
);
1338 set_test_crx_file(crx_file
);
1340 SimulateNetworkOnline();
1341 LaunchApp(test_app_id(), false);
1342 WaitForAppLaunchSuccess();
1343 EXPECT_EQ(version
, GetInstalledAppVersion().GetString());
1347 class KioskAppExternalUpdateWaiter
: public KioskAppManagerObserver
{
1349 KioskAppExternalUpdateWaiter(KioskAppManager
* manager
,
1350 const std::string
& app_id
)
1355 update_success_(false),
1356 app_update_notified_(false) {
1357 manager_
->AddObserver(this);
1360 ~KioskAppExternalUpdateWaiter() override
{ manager_
->RemoveObserver(this); }
1365 runner_
= new content::MessageLoopRunner
;
1369 bool update_success() const { return update_success_
; }
1371 bool app_update_notified() const { return app_update_notified_
; }
1374 // KioskAppManagerObserver overrides:
1375 void OnKioskAppCacheUpdated(const std::string
& app_id
) override
{
1376 if (app_id_
!= app_id
)
1378 app_update_notified_
= true;
1381 void OnKioskAppExternalUpdateComplete(bool success
) override
{
1383 update_success_
= success
;
1388 scoped_refptr
<content::MessageLoopRunner
> runner_
;
1389 KioskAppManager
* manager_
;
1390 const std::string app_id_
;
1392 bool update_success_
;
1393 bool app_update_notified_
;
1395 DISALLOW_COPY_AND_ASSIGN(KioskAppExternalUpdateWaiter
);
1398 // Owned by DiskMountManager.
1399 KioskFakeDiskMountManager
* fake_disk_mount_manager_
;
1401 DISALLOW_COPY_AND_ASSIGN(KioskUpdateTest
);
1404 IN_PROC_BROWSER_TEST_F(KioskUpdateTest
, PRE_LaunchOfflineEnabledAppNoNetwork
) {
1405 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp
,
1407 std::string(kTestOfflineEnabledKioskApp
) + "_v1.crx");
1410 IN_PROC_BROWSER_TEST_F(KioskUpdateTest
, LaunchOfflineEnabledAppNoNetwork
) {
1411 set_test_app_id(kTestOfflineEnabledKioskApp
);
1412 StartUIForAppLaunch();
1413 SimulateNetworkOffline();
1414 LaunchApp(test_app_id(), false);
1415 WaitForAppLaunchSuccess();
1417 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString());
1420 IN_PROC_BROWSER_TEST_F(KioskUpdateTest
,
1421 PRE_LaunchCachedOfflineEnabledAppNoNetwork
) {
1422 PreCacheApp(kTestOfflineEnabledKioskApp
,
1424 std::string(kTestOfflineEnabledKioskApp
) + "_v1.crx");
1427 IN_PROC_BROWSER_TEST_F(KioskUpdateTest
,
1428 LaunchCachedOfflineEnabledAppNoNetwork
) {
1429 set_test_app_id(kTestOfflineEnabledKioskApp
);
1431 KioskAppManager::Get()->HasCachedCrx(kTestOfflineEnabledKioskApp
));
1432 StartUIForAppLaunch();
1433 SimulateNetworkOffline();
1434 LaunchApp(test_app_id(), false);
1435 WaitForAppLaunchSuccess();
1437 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString());
1440 // Network offline, app v1.0 has run before, has cached v2.0 crx and v2.0 should
1441 // be installed and launched during next launch.
1442 IN_PROC_BROWSER_TEST_F(KioskUpdateTest
,
1443 PRE_LaunchCachedNewVersionOfflineEnabledAppNoNetwork
) {
1444 // Install and launch v1 app.
1445 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp
,
1447 std::string(kTestOfflineEnabledKioskApp
) + "_v1.crx");
1448 // Update cache for v2 app.
1449 UpdateExternalCache("2.0.0",
1450 std::string(kTestOfflineEnabledKioskApp
) + ".crx");
1451 // The installed app is still in v1.
1452 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString());
1455 IN_PROC_BROWSER_TEST_F(KioskUpdateTest
,
1456 LaunchCachedNewVersionOfflineEnabledAppNoNetwork
) {
1457 set_test_app_id(kTestOfflineEnabledKioskApp
);
1458 EXPECT_TRUE(KioskAppManager::Get()->HasCachedCrx(test_app_id()));
1460 StartUIForAppLaunch();
1461 SimulateNetworkOffline();
1462 LaunchApp(test_app_id(), false);
1463 WaitForAppLaunchSuccess();
1465 // v2 app should have been installed.
1466 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString());
1469 IN_PROC_BROWSER_TEST_F(KioskUpdateTest
, PRE_LaunchOfflineEnabledAppNoUpdate
) {
1470 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp
,
1472 std::string(kTestOfflineEnabledKioskApp
) + "_v1.crx");
1475 IN_PROC_BROWSER_TEST_F(KioskUpdateTest
, LaunchOfflineEnabledAppNoUpdate
) {
1476 set_test_app_id(kTestOfflineEnabledKioskApp
);
1477 fake_cws()->SetNoUpdate(test_app_id());
1479 StartUIForAppLaunch();
1480 SimulateNetworkOnline();
1481 LaunchApp(test_app_id(), false);
1482 WaitForAppLaunchSuccess();
1484 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString());
1487 IN_PROC_BROWSER_TEST_F(KioskUpdateTest
, PRE_LaunchOfflineEnabledAppHasUpdate
) {
1488 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp
,
1490 std::string(kTestOfflineEnabledKioskApp
) + "_v1.crx");
1493 IN_PROC_BROWSER_TEST_F(KioskUpdateTest
, LaunchOfflineEnabledAppHasUpdate
) {
1494 set_test_app_id(kTestOfflineEnabledKioskApp
);
1495 fake_cws()->SetUpdateCrx(
1496 test_app_id(), "ajoggoflpgplnnjkjamcmbepjdjdnpdp.crx", "2.0.0");
1498 StartUIForAppLaunch();
1499 SimulateNetworkOnline();
1500 LaunchApp(test_app_id(), false);
1501 WaitForAppLaunchSuccess();
1503 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString());
1506 // Pre-cache v1 kiosk app, then launch the app without network,
1507 // plug in usb stick with a v2 app for offline updating.
1508 IN_PROC_BROWSER_TEST_F(KioskUpdateTest
, PRE_UsbStickUpdateAppNoNetwork
) {
1509 PreCacheApp(kTestOfflineEnabledKioskApp
,
1511 std::string(kTestOfflineEnabledKioskApp
) + "_v1.crx");
1513 set_test_app_id(kTestOfflineEnabledKioskApp
);
1514 StartUIForAppLaunch();
1515 SimulateNetworkOffline();
1516 LaunchApp(test_app_id(), false);
1517 WaitForAppLaunchSuccess();
1518 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString());
1520 // Simulate mounting of usb stick with v2 app on the stick.
1521 bool update_success
;
1522 bool app_update_notified
;
1523 SimulateUpdateAppFromUsbStick(
1524 kFakeUsbMountPathUpdatePass
, &app_update_notified
, &update_success
);
1525 EXPECT_TRUE(update_success
);
1526 EXPECT_TRUE(app_update_notified
);
1528 // The v2 kiosk app is loaded into external cache, but won't be installed
1529 // until next time the device is started.
1530 base::FilePath crx_path
;
1531 std::string cached_version
;
1532 EXPECT_TRUE(KioskAppManager::Get()->GetCachedCrx(
1533 test_app_id(), &crx_path
, &cached_version
));
1534 EXPECT_EQ("2.0.0", cached_version
);
1535 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString());
1538 // Restart the device, verify the app has been updated to v2.
1539 IN_PROC_BROWSER_TEST_F(KioskUpdateTest
, UsbStickUpdateAppNoNetwork
) {
1540 // Verify the kiosk app has been updated to v2.
1541 set_test_app_id(kTestOfflineEnabledKioskApp
);
1542 StartUIForAppLaunch();
1543 SimulateNetworkOffline();
1544 LaunchApp(test_app_id(), false);
1545 WaitForAppLaunchSuccess();
1546 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString());
1549 // Usb stick is plugged in without a manifest file on it.
1550 IN_PROC_BROWSER_TEST_F(KioskUpdateTest
, UsbStickUpdateAppNoManifest
) {
1551 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp
,
1553 std::string(kTestOfflineEnabledKioskApp
) + "_v1.crx");
1554 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString());
1556 // Simulate mounting of usb stick with v2 app on the stick.
1557 bool update_success
;
1558 bool app_update_notified
;
1559 SimulateUpdateAppFromUsbStick(
1560 kFakeUsbMountPathNoManifest
, &app_update_notified
, &update_success
);
1561 EXPECT_FALSE(update_success
);
1563 // Kiosk app is not updated.
1564 base::FilePath crx_path
;
1565 std::string cached_version
;
1566 EXPECT_TRUE(KioskAppManager::Get()->GetCachedCrx(
1567 test_app_id(), &crx_path
, &cached_version
));
1568 EXPECT_EQ("1.0.0", cached_version
);
1571 // Usb stick is plugged in with a bad manifest file on it.
1572 IN_PROC_BROWSER_TEST_F(KioskUpdateTest
, UsbStickUpdateAppBadManifest
) {
1573 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp
,
1575 std::string(kTestOfflineEnabledKioskApp
) + "_v1.crx");
1576 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString());
1578 // Simulate mounting of usb stick with v2 app on the stick.
1579 bool update_success
;
1580 bool app_update_notified
;
1581 SimulateUpdateAppFromUsbStick(
1582 kFakeUsbMountPathBadManifest
, &app_update_notified
, &update_success
);
1583 EXPECT_FALSE(update_success
);
1585 // Kiosk app is not updated.
1586 base::FilePath crx_path
;
1587 std::string cached_version
;
1588 EXPECT_TRUE(KioskAppManager::Get()->GetCachedCrx(
1589 test_app_id(), &crx_path
, &cached_version
));
1590 EXPECT_EQ("1.0.0", cached_version
);
1593 // Usb stick is plugged in with a lower version of crx file specified in
1595 IN_PROC_BROWSER_TEST_F(KioskUpdateTest
, UsbStickUpdateAppLowerAppVersion
) {
1596 // Precache v2 version of app.
1597 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp
,
1599 std::string(kTestOfflineEnabledKioskApp
) + ".crx");
1600 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString());
1602 // Simulate mounting of usb stick with v1 app on the stick.
1603 bool update_success
;
1604 bool app_update_notified
;
1605 SimulateUpdateAppFromUsbStick(
1606 kFakeUsbMountPathLowerAppVersion
, &app_update_notified
, &update_success
);
1607 EXPECT_FALSE(update_success
);
1609 // Kiosk app is NOT updated to the lower version.
1610 base::FilePath crx_path
;
1611 std::string cached_version
;
1612 EXPECT_TRUE(KioskAppManager::Get()->GetCachedCrx(
1613 test_app_id(), &crx_path
, &cached_version
));
1614 EXPECT_EQ("2.0.0", cached_version
);
1617 // Usb stick is plugged in with a v1 crx file, although the manifest says
1618 // this is a v3 version.
1619 IN_PROC_BROWSER_TEST_F(KioskUpdateTest
, UsbStickUpdateAppLowerCrxVersion
) {
1620 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp
,
1622 std::string(kTestOfflineEnabledKioskApp
) + ".crx");
1623 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString());
1625 // Simulate mounting of usb stick with v1 crx file on the stick, although
1626 // the manifest says it is v3 app.
1627 bool update_success
;
1628 bool app_update_notified
;
1629 SimulateUpdateAppFromUsbStick(
1630 kFakeUsbMountPathLowerCrxVersion
, &app_update_notified
, &update_success
);
1631 EXPECT_FALSE(update_success
);
1633 // Kiosk app is NOT updated to the lower version.
1634 base::FilePath crx_path
;
1635 std::string cached_version
;
1636 EXPECT_TRUE(KioskAppManager::Get()->GetCachedCrx(
1637 test_app_id(), &crx_path
, &cached_version
));
1638 EXPECT_EQ("2.0.0", cached_version
);
1641 // Usb stick is plugged in with a bad crx file.
1642 IN_PROC_BROWSER_TEST_F(KioskUpdateTest
, UsbStickUpdateAppBadCrx
) {
1643 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp
,
1645 std::string(kTestOfflineEnabledKioskApp
) + "_v1.crx");
1646 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString());
1648 // Simulate mounting of usb stick with v1 crx file on the stick, although
1649 // the manifest says it is v3 app.
1650 bool update_success
;
1651 bool app_update_notified
;
1652 SimulateUpdateAppFromUsbStick(
1653 kFakeUsbMountPathBadCrx
, &app_update_notified
, &update_success
);
1654 EXPECT_FALSE(update_success
);
1656 // Kiosk app is NOT updated.
1657 base::FilePath crx_path
;
1658 std::string cached_version
;
1659 EXPECT_TRUE(KioskAppManager::Get()->GetCachedCrx(
1660 test_app_id(), &crx_path
, &cached_version
));
1661 EXPECT_EQ("1.0.0", cached_version
);
1664 IN_PROC_BROWSER_TEST_F(KioskUpdateTest
, PRE_PermissionChange
) {
1665 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp
,
1667 std::string(kTestOfflineEnabledKioskApp
) + ".crx");
1670 IN_PROC_BROWSER_TEST_F(KioskUpdateTest
, PermissionChange
) {
1671 set_test_app_id(kTestOfflineEnabledKioskApp
);
1672 set_test_app_version("2.0.0");
1673 set_test_crx_file(test_app_id() + "_v2_permission_change.crx");
1675 StartUIForAppLaunch();
1676 SimulateNetworkOnline();
1677 LaunchApp(test_app_id(), false);
1678 WaitForAppLaunchSuccess();
1680 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString());
1683 IN_PROC_BROWSER_TEST_F(KioskUpdateTest
, PRE_PreserveLocalData
) {
1684 // Installs v1 app and writes some local data.
1685 set_test_app_id(kTestLocalFsKioskApp
);
1686 set_test_app_version("1.0.0");
1687 set_test_crx_file(test_app_id() + ".crx");
1689 extensions::ResultCatcher catcher
;
1690 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
1691 WaitForAppLaunchWithOptions(true /* check_launch_data */,
1692 false /* terminate_app */);
1693 ASSERT_TRUE(catcher
.GetNextResult()) << catcher
.message();
1696 IN_PROC_BROWSER_TEST_F(KioskUpdateTest
, PreserveLocalData
) {
1697 // Update existing v1 app installed in PRE_PreserveLocalData to v2
1698 // that reads and verifies the local data.
1699 set_test_app_id(kTestLocalFsKioskApp
);
1700 set_test_app_version("2.0.0");
1701 set_test_crx_file(test_app_id() + "_v2_read_and_verify_data.crx");
1702 extensions::ResultCatcher catcher
;
1703 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
1704 WaitForAppLaunchWithOptions(true /* check_launch_data */,
1705 false /* terminate_app */);
1707 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString());
1708 ASSERT_TRUE(catcher
.GetNextResult()) << catcher
.message();
1711 class KioskEnterpriseTest
: public KioskTest
{
1713 KioskEnterpriseTest() {
1714 set_use_consumer_kiosk_mode(false);
1717 void SetUpInProcessBrowserTestFixture() override
{
1718 policy::DevicePolicyCrosTestHelper::MarkAsEnterpriseOwnedBy(
1720 settings_helper_
.SetCurrentUserIsOwner(false);
1722 KioskTest::SetUpInProcessBrowserTestFixture();
1725 void SetUpOnMainThread() override
{
1726 KioskTest::SetUpOnMainThread();
1728 // Configure OAuth authentication.
1729 GaiaUrls
* gaia_urls
= GaiaUrls::GetInstance();
1731 // This token satisfies the userinfo.email request from
1732 // DeviceOAuth2TokenService used in token validation.
1733 FakeGaia::AccessTokenInfo userinfo_token_info
;
1734 userinfo_token_info
.token
= kTestUserinfoToken
;
1735 userinfo_token_info
.scopes
.insert(
1736 "https://www.googleapis.com/auth/userinfo.email");
1737 userinfo_token_info
.audience
= gaia_urls
->oauth2_chrome_client_id();
1738 userinfo_token_info
.email
= kTestEnterpriseServiceAccountId
;
1739 fake_gaia_
->IssueOAuthToken(kTestRefreshToken
, userinfo_token_info
);
1741 // The any-api access token for accessing the token minting endpoint.
1742 FakeGaia::AccessTokenInfo login_token_info
;
1743 login_token_info
.token
= kTestLoginToken
;
1744 login_token_info
.scopes
.insert(GaiaConstants::kAnyApiOAuth2Scope
);
1745 login_token_info
.audience
= gaia_urls
->oauth2_chrome_client_id();
1746 fake_gaia_
->IssueOAuthToken(kTestRefreshToken
, login_token_info
);
1748 // This is the access token requested by the app via the identity API.
1749 FakeGaia::AccessTokenInfo access_token_info
;
1750 access_token_info
.token
= kTestAccessToken
;
1751 access_token_info
.scopes
.insert(kTestAppScope
);
1752 access_token_info
.audience
= kTestClientId
;
1753 access_token_info
.email
= kTestEnterpriseServiceAccountId
;
1754 fake_gaia_
->IssueOAuthToken(kTestLoginToken
, access_token_info
);
1756 DeviceOAuth2TokenService
* token_service
=
1757 DeviceOAuth2TokenServiceFactory::Get();
1758 token_service
->SetAndSaveRefreshToken(
1759 kTestRefreshToken
, DeviceOAuth2TokenService::StatusCallback());
1760 base::RunLoop().RunUntilIdle();
1763 void ConfigureKioskAppInPolicy(const std::string
& account_id
,
1764 const std::string
& app_id
,
1765 const std::string
& update_url
) {
1766 settings_helper_
.SetCurrentUserIsOwner(true);
1767 std::vector
<policy::DeviceLocalAccount
> accounts
;
1769 policy::DeviceLocalAccount(policy::DeviceLocalAccount::TYPE_KIOSK_APP
,
1770 account_id
, app_id
, update_url
));
1771 policy::SetDeviceLocalAccounts(owner_settings_service_
.get(), accounts
);
1772 settings_helper_
.SetString(kAccountsPrefDeviceLocalAccountAutoLoginId
,
1774 settings_helper_
.SetString(kServiceAccountIdentity
,
1775 kTestEnterpriseServiceAccountId
);
1776 settings_helper_
.SetCurrentUserIsOwner(false);
1780 DISALLOW_COPY_AND_ASSIGN(KioskEnterpriseTest
);
1783 IN_PROC_BROWSER_TEST_F(KioskEnterpriseTest
, EnterpriseKioskApp
) {
1784 // Prepare Fake CWS to serve app crx.
1785 set_test_app_id(kTestEnterpriseKioskApp
);
1786 set_test_app_version("1.0.0");
1787 set_test_crx_file(test_app_id() + ".crx");
1788 SetupTestAppUpdateCheck();
1790 // Configure kTestEnterpriseKioskApp in device policy.
1791 ConfigureKioskAppInPolicy(kTestEnterpriseAccountId
,
1792 kTestEnterpriseKioskApp
,
1796 LaunchApp(kTestEnterpriseKioskApp
, false);
1798 // Wait for the Kiosk App to launch.
1799 content::WindowedNotificationObserver(
1800 chrome::NOTIFICATION_KIOSK_APP_LAUNCHED
,
1801 content::NotificationService::AllSources()).Wait();
1803 // Check installer status.
1804 EXPECT_EQ(chromeos::KioskAppLaunchError::NONE
,
1805 chromeos::KioskAppLaunchError::Get());
1807 // Wait for the window to appear.
1808 extensions::AppWindow
* window
=
1810 extensions::AppWindowRegistry::Get(
1811 ProfileManager::GetPrimaryUserProfile()),
1812 kTestEnterpriseKioskApp
).Wait();
1813 ASSERT_TRUE(window
);
1815 // Check whether the app can retrieve an OAuth2 access token.
1817 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
1818 window
->web_contents(),
1819 "chrome.identity.getAuthToken({ 'interactive': false }, function(token) {"
1820 " window.domAutomationController.setAutomationId(0);"
1821 " window.domAutomationController.send(token);"
1824 EXPECT_EQ(kTestAccessToken
, result
);
1826 // Verify that the session is not considered to be logged in with a GAIA
1828 Profile
* app_profile
= ProfileManager::GetPrimaryUserProfile();
1829 ASSERT_TRUE(app_profile
);
1831 SigninManagerFactory::GetForProfile(app_profile
)->IsAuthenticated());
1833 // Terminate the app.
1834 window
->GetBaseWindow()->Close();
1835 content::RunAllPendingInMessageLoop();
1838 IN_PROC_BROWSER_TEST_F(KioskEnterpriseTest
, PrivateStore
) {
1839 set_test_app_id(kTestEnterpriseKioskApp
);
1841 const char kPrivateStoreUpdate
[] = "/private_store_update";
1842 net::test_server::EmbeddedTestServer private_server
;
1843 ASSERT_TRUE(private_server
.InitializeAndWaitUntilReady());
1845 // |private_server| serves crx from test data dir.
1846 base::FilePath test_data_dir
;
1847 PathService::Get(chrome::DIR_TEST_DATA
, &test_data_dir
);
1848 private_server
.ServeFilesFromDirectory(test_data_dir
);
1850 FakeCWS private_store
;
1851 private_store
.InitAsPrivateStore(&private_server
, kPrivateStoreUpdate
);
1852 private_store
.SetUpdateCrx(kTestEnterpriseKioskApp
,
1853 std::string(kTestEnterpriseKioskApp
) + ".crx",
1856 // Configure kTestEnterpriseKioskApp in device policy.
1857 ConfigureKioskAppInPolicy(kTestEnterpriseAccountId
,
1858 kTestEnterpriseKioskApp
,
1859 private_server
.GetURL(kPrivateStoreUpdate
).spec());
1861 // Meta should be able to be extracted from crx before launching.
1862 KioskAppManager
* manager
= KioskAppManager::Get();
1863 AppDataLoadWaiter
waiter(manager
, kTestEnterpriseKioskApp
, std::string());
1864 waiter
.WaitForAppData();
1867 LaunchApp(kTestEnterpriseKioskApp
, false);
1868 WaitForAppLaunchWithOptions(false /* check_launch_data */,
1869 true /* terminate_app */);
1871 // Private store should serve crx and CWS should not.
1872 DCHECK_GT(private_store
.GetUpdateCheckCountAndReset(), 0);
1873 DCHECK_EQ(0, fake_cws()->GetUpdateCheckCountAndReset());
1876 // Specialized test fixture for testing kiosk mode on the
1877 // hidden WebUI initialization flow for slow hardware.
1878 class KioskHiddenWebUITest
: public KioskTest
,
1879 public ash::DesktopBackgroundControllerObserver
{
1881 KioskHiddenWebUITest() : wallpaper_loaded_(false) {}
1883 // KioskTest overrides:
1884 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
1885 KioskTest::SetUpCommandLine(command_line
);
1886 command_line
->AppendSwitch(switches::kDisableBootAnimation
);
1889 void SetUpOnMainThread() override
{
1890 KioskTest::SetUpOnMainThread();
1891 ash::Shell::GetInstance()->desktop_background_controller()
1892 ->AddObserver(this);
1895 void TearDownOnMainThread() override
{
1896 ash::Shell::GetInstance()->desktop_background_controller()
1897 ->RemoveObserver(this);
1898 KioskTest::TearDownOnMainThread();
1901 void WaitForWallpaper() {
1902 if (!wallpaper_loaded_
) {
1903 runner_
= new content::MessageLoopRunner
;
1908 bool wallpaper_loaded() const { return wallpaper_loaded_
; }
1910 // ash::DesktopBackgroundControllerObserver overrides:
1911 void OnWallpaperDataChanged() override
{
1912 wallpaper_loaded_
= true;
1917 bool wallpaper_loaded_
;
1918 scoped_refptr
<content::MessageLoopRunner
> runner_
;
1920 DISALLOW_COPY_AND_ASSIGN(KioskHiddenWebUITest
);
1923 IN_PROC_BROWSER_TEST_F(KioskHiddenWebUITest
, AutolaunchWarning
) {
1924 // Add a device owner.
1925 FakeChromeUserManager
* user_manager
= new FakeChromeUserManager();
1926 user_manager
->AddUser(kTestOwnerEmail
);
1927 ScopedUserManagerEnabler
enabler(user_manager
);
1929 // Set kiosk app to autolaunch.
1930 EnableConsumerKioskMode();
1931 WizardController::SkipPostLoginScreensForTesting();
1932 WizardController
* wizard_controller
= WizardController::default_controller();
1933 CHECK(wizard_controller
);
1935 // Start login screen after configuring auto launch app since the warning
1936 // is triggered when switching to login screen.
1937 wizard_controller
->AdvanceToScreen(WizardController::kNetworkScreenName
);
1938 ReloadAutolaunchKioskApps();
1939 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
1941 EXPECT_FALSE(KioskAppManager::Get()->GetAutoLaunchApp().empty());
1942 EXPECT_FALSE(KioskAppManager::Get()->IsAutoLaunchEnabled());
1944 // Wait for the auto launch warning come up.
1945 content::WindowedNotificationObserver(
1946 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE
,
1947 content::NotificationService::AllSources()).Wait();
1949 // Wait for the wallpaper to load.
1951 EXPECT_TRUE(wallpaper_loaded());
1954 } // namespace chromeos