Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / kiosk_browsertest.cc
blobad6d36b891f91697afc8756db32ce13e96ce4fa3
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 <vector>
7 #include "ash/desktop_background/desktop_background_controller.h"
8 #include "ash/desktop_background/desktop_background_controller_observer.h"
9 #include "ash/shell.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;
81 namespace chromeos {
83 namespace {
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";
151 // Test JS API.
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(
173 bool* out_locked,
174 const base::Closure& runner_quit_task,
175 bool in_locked) {
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) {
188 lock->Acquire();
189 lock->Release();
192 // Helper functions for CanConfigureNetwork mock.
193 class ScopedCanConfigureNetwork {
194 public:
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(
212 NULL);
215 bool CanConfigureNetwork() {
216 return can_configure_;
219 bool NeedsOwnerAuthToConfigureNetwork() {
220 return needs_owner_auth_;
223 private:
224 bool can_configure_;
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 {
233 public:
234 JsConditionWaiter(content::WebContents* web_contents,
235 const std::string& js)
236 : web_contents_(web_contents),
237 js_(js) {
240 void Wait() {
241 if (CheckJs())
242 return;
244 base::RepeatingTimer<JsConditionWaiter> check_timer;
245 check_timer.Start(
246 FROM_HERE,
247 base::TimeDelta::FromMilliseconds(10),
248 this,
249 &JsConditionWaiter::OnTimer);
251 runner_ = new content::MessageLoopRunner;
252 runner_->Run();
255 private:
256 bool CheckJs() {
257 bool result;
258 CHECK(content::ExecuteScriptAndExtractBool(
259 web_contents_,
260 "window.domAutomationController.send(!!(" + js_ + "));",
261 &result));
262 return result;
265 void OnTimer() {
266 DCHECK(runner_.get());
267 if (CheckJs())
268 runner_->Quit();
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 {
279 public:
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());
300 private:
301 std::string usb_mount_path_;
303 DISALLOW_COPY_AND_ASSIGN(KioskFakeDiskMountManager);
306 class AppDataLoadWaiter : public KioskAppManagerObserver {
307 public:
308 AppDataLoadWaiter(KioskAppManager* manager,
309 const std::string& app_id,
310 const std::string& version)
311 : runner_(NULL),
312 manager_(manager),
313 wait_type_(WAIT_FOR_CRX_CACHE),
314 loaded_(false),
315 quit_(false),
316 app_id_(app_id),
317 version_(version) {
318 manager_->AddObserver(this);
321 ~AppDataLoadWaiter() override { manager_->RemoveObserver(this); }
323 void Wait() {
324 wait_type_ = WAIT_FOR_CRX_CACHE;
325 if (quit_)
326 return;
327 runner_ = new content::MessageLoopRunner;
328 runner_->Run();
331 void WaitForAppData() {
332 wait_type_ = WAIT_FOR_APP_DATA;
333 if (quit_ || IsAppDataLoaded())
334 return;
335 runner_ = new content::MessageLoopRunner;
336 runner_->Run();
339 bool loaded() const { return loaded_; }
341 private:
342 enum WaitType {
343 WAIT_FOR_CRX_CACHE,
344 WAIT_FOR_APP_DATA,
347 // KioskAppManagerObserver overrides:
348 void OnKioskAppDataChanged(const std::string& app_id) override {
349 if (wait_type_ != WAIT_FOR_APP_DATA ||
350 app_id != app_id_ ||
351 !IsAppDataLoaded()) {
352 return;
355 loaded_ = true;
356 quit_ = true;
357 if (runner_.get())
358 runner_->Quit();
361 void OnKioskAppDataLoadFailure(const std::string& app_id) override {
362 if (wait_type_ != WAIT_FOR_APP_DATA || app_id != app_id_)
363 return;
365 loaded_ = false;
366 quit_ = true;
367 if (runner_.get())
368 runner_->Quit();
371 void OnKioskExtensionLoadedInCache(const std::string& app_id) override {
372 if (wait_type_ != WAIT_FOR_CRX_CACHE)
373 return;
375 std::string cached_version;
376 base::FilePath file_path;
377 if (!manager_->GetCachedCrx(app_id_, &file_path, &cached_version))
378 return;
379 if (version_ != cached_version)
380 return;
381 loaded_ = true;
382 quit_ = true;
383 if (runner_.get())
384 runner_->Quit();
387 void OnKioskExtensionDownloadFailed(const std::string& app_id) override {
388 if (wait_type_ != WAIT_FOR_CRX_CACHE)
389 return;
391 loaded_ = false;
392 quit_ = true;
393 if (runner_.get())
394 runner_->Quit();
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_;
404 WaitType wait_type_;
405 bool loaded_;
406 bool quit_;
407 std::string app_id_;
408 std::string version_;
410 DISALLOW_COPY_AND_ASSIGN(AppDataLoadWaiter);
413 } // namespace
415 // Boolean parameter is used to run this test for webview (true) and for
416 // iframe (false) GAIA sign in.
417 class KioskTest : public OobeBaseTest,
418 public testing::WithParamInterface<bool> {
419 public:
420 KioskTest()
421 : settings_helper_(false),
422 use_consumer_kiosk_mode_(true),
423 fake_cws_(new FakeCWS) {
424 set_use_webview(GetParam());
425 set_exit_when_last_browser_closes(false);
428 ~KioskTest() override {}
430 protected:
431 void SetUp() override {
432 test_app_id_ = kTestKioskApp;
433 set_test_app_version("1.0.0");
434 set_test_crx_file(test_app_id() + ".crx");
435 needs_background_networking_ = true;
436 mock_user_manager_.reset(new MockUserManager);
437 ProfileHelper::SetAlwaysReturnPrimaryUserForTesting(true);
438 AppLaunchController::SkipSplashWaitForTesting();
439 AppLaunchController::SetNetworkWaitForTesting(kTestNetworkTimeoutSeconds);
441 OobeBaseTest::SetUp();
444 void TearDown() override {
445 ProfileHelper::SetAlwaysReturnPrimaryUserForTesting(false);
446 OobeBaseTest::TearDown();
449 void SetUpOnMainThread() override {
450 OobeBaseTest::SetUpOnMainThread();
451 // Needed to avoid showing Gaia screen instead of owner signin for
452 // consumer network down test cases.
453 StartupUtils::MarkDeviceRegistered(base::Closure());
454 settings_helper_.ReplaceProvider(kAccountsPrefDeviceLocalAccounts);
455 owner_settings_service_ = settings_helper_.CreateOwnerSettingsService(
456 ProfileManager::GetPrimaryUserProfile());
459 void TearDownOnMainThread() override {
460 settings_helper_.RestoreProvider();
461 AppLaunchController::SetNetworkTimeoutCallbackForTesting(NULL);
462 AppLaunchSigninScreen::SetUserManagerForTesting(NULL);
464 OobeBaseTest::TearDownOnMainThread();
466 // Clean up while main thread still runs.
467 // See http://crbug.com/176659.
468 KioskAppManager::Get()->CleanUp();
471 void SetUpCommandLine(base::CommandLine* command_line) override {
472 OobeBaseTest::SetUpCommandLine(command_line);
473 fake_cws_->Init(embedded_test_server());
476 void LaunchApp(const std::string& app_id, bool diagnostic_mode) {
477 bool new_kiosk_ui = KioskAppMenuHandler::EnableNewKioskUI();
478 GetLoginUI()->CallJavascriptFunction(new_kiosk_ui ?
479 kLaunchAppForTestNewAPI : kLaunchAppForTestOldAPI,
480 base::StringValue(app_id),
481 base::FundamentalValue(diagnostic_mode));
484 void ReloadKioskApps() {
485 SetupTestAppUpdateCheck();
487 // Remove then add to ensure NOTIFICATION_KIOSK_APPS_LOADED fires.
488 KioskAppManager::Get()->RemoveApp(test_app_id_,
489 owner_settings_service_.get());
490 KioskAppManager::Get()->AddApp(test_app_id_, owner_settings_service_.get());
493 void FireKioskAppSettingsChanged() {
494 KioskAppManager::Get()->UpdateAppData();
497 void SetupTestAppUpdateCheck() {
498 if (!test_app_version().empty()) {
499 fake_cws_->SetUpdateCrx(
500 test_app_id(), test_crx_file(), test_app_version());
504 void ReloadAutolaunchKioskApps() {
505 SetupTestAppUpdateCheck();
507 KioskAppManager::Get()->AddApp(test_app_id_, owner_settings_service_.get());
508 KioskAppManager::Get()->SetAutoLaunchApp(test_app_id_,
509 owner_settings_service_.get());
512 void StartUIForAppLaunch() {
513 if (use_consumer_kiosk_mode_)
514 EnableConsumerKioskMode();
516 // Start UI
517 chromeos::WizardController::SkipPostLoginScreensForTesting();
518 chromeos::WizardController* wizard_controller =
519 chromeos::WizardController::default_controller();
520 if (wizard_controller) {
521 wizard_controller->SkipToLoginForTesting(LoginScreenContext());
522 OobeScreenWaiter(OobeDisplay::SCREEN_GAIA_SIGNIN).Wait();
523 } else {
524 // No wizard and running with an existing profile and it should land
525 // on account picker when new kiosk UI is enabled. Otherwise, just
526 // wait for the login signal from Gaia.
527 if (KioskAppMenuHandler::EnableNewKioskUI())
528 OobeScreenWaiter(OobeDisplay::SCREEN_ACCOUNT_PICKER).Wait();
529 else
530 OobeScreenWaiter(OobeDisplay::SCREEN_GAIA_SIGNIN).Wait();
534 void PrepareAppLaunch() {
535 // Start UI
536 StartUIForAppLaunch();
538 // Wait for the Kiosk App configuration to reload.
539 content::WindowedNotificationObserver apps_loaded_signal(
540 chrome::NOTIFICATION_KIOSK_APPS_LOADED,
541 content::NotificationService::AllSources());
542 ReloadKioskApps();
543 apps_loaded_signal.Wait();
546 void StartAppLaunchFromLoginScreen(const base::Closure& network_setup_cb) {
547 PrepareAppLaunch();
549 if (!network_setup_cb.is_null())
550 network_setup_cb.Run();
552 LaunchApp(test_app_id(), false);
555 const extensions::Extension* GetInstalledApp() {
556 Profile* app_profile = ProfileManager::GetPrimaryUserProfile();
557 return extensions::ExtensionSystem::Get(app_profile)->
558 extension_service()->GetInstalledExtension(test_app_id_);
561 const Version& GetInstalledAppVersion() {
562 return *GetInstalledApp()->version();
565 void WaitForAppLaunchWithOptions(bool check_launch_data, bool terminate_app) {
566 ExtensionTestMessageListener
567 launch_data_check_listener("launchData.isKioskSession = true", false);
569 // Wait for the Kiosk App to launch.
570 content::WindowedNotificationObserver(
571 chrome::NOTIFICATION_KIOSK_APP_LAUNCHED,
572 content::NotificationService::AllSources()).Wait();
574 // Default profile switches to app profile after app is launched.
575 Profile* app_profile = ProfileManager::GetPrimaryUserProfile();
576 ASSERT_TRUE(app_profile);
578 // Check ChromeOS preference is initialized.
579 EXPECT_TRUE(
580 static_cast<ProfileImpl*>(app_profile)->chromeos_preferences_);
582 // Check installer status.
583 EXPECT_EQ(chromeos::KioskAppLaunchError::NONE,
584 chromeos::KioskAppLaunchError::Get());
586 // Check if the kiosk webapp is really installed for the default profile.
587 const extensions::Extension* app =
588 extensions::ExtensionSystem::Get(app_profile)->
589 extension_service()->GetInstalledExtension(test_app_id_);
590 EXPECT_TRUE(app);
592 // App should appear with its window.
593 extensions::AppWindowRegistry* app_window_registry =
594 extensions::AppWindowRegistry::Get(app_profile);
595 extensions::AppWindow* window =
596 AppWindowWaiter(app_window_registry, test_app_id_).Wait();
597 EXPECT_TRUE(window);
599 // Login screen should be gone or fading out.
600 chromeos::LoginDisplayHost* login_display_host =
601 chromeos::LoginDisplayHostImpl::default_host();
602 EXPECT_TRUE(
603 login_display_host == NULL ||
604 login_display_host->GetNativeWindow()->layer()->GetTargetOpacity() ==
605 0.0f);
607 // Terminate the app.
608 if (terminate_app)
609 window->GetBaseWindow()->Close();
611 // Wait until the app terminates if it is still running.
612 if (!app_window_registry->GetAppWindowsForApp(test_app_id_).empty())
613 content::RunMessageLoop();
615 // Check that the app had been informed that it is running in a kiosk
616 // session.
617 if (check_launch_data)
618 EXPECT_TRUE(launch_data_check_listener.was_satisfied());
621 void WaitForAppLaunchSuccess() {
622 WaitForAppLaunchWithOptions(true /* check_launch_data */,
623 true /* terminate_app */);
626 void WaitForAppLaunchNetworkTimeout() {
627 if (GetAppLaunchController()->network_wait_timedout())
628 return;
630 scoped_refptr<content::MessageLoopRunner> runner =
631 new content::MessageLoopRunner;
633 base::Closure callback = base::Bind(
634 &OnNetworkWaitTimedOut, runner->QuitClosure());
635 AppLaunchController::SetNetworkTimeoutCallbackForTesting(&callback);
637 runner->Run();
639 CHECK(GetAppLaunchController()->network_wait_timedout());
640 AppLaunchController::SetNetworkTimeoutCallbackForTesting(NULL);
643 void EnableConsumerKioskMode() {
644 scoped_ptr<bool> locked(new bool(false));
645 scoped_refptr<content::MessageLoopRunner> runner =
646 new content::MessageLoopRunner;
647 KioskAppManager::Get()->EnableConsumerKioskAutoLaunch(
648 base::Bind(&ConsumerKioskModeAutoStartLockCheck,
649 locked.get(),
650 runner->QuitClosure()));
651 runner->Run();
652 EXPECT_TRUE(*locked.get());
655 KioskAppManager::ConsumerKioskAutoLaunchStatus
656 GetConsumerKioskModeStatus() {
657 KioskAppManager::ConsumerKioskAutoLaunchStatus status =
658 static_cast<KioskAppManager::ConsumerKioskAutoLaunchStatus>(-1);
659 scoped_refptr<content::MessageLoopRunner> runner =
660 new content::MessageLoopRunner;
661 KioskAppManager::Get()->GetConsumerKioskAutoLaunchStatus(
662 base::Bind(&ConsumerKioskAutoLaunchStatusCheck,
663 &status,
664 runner->QuitClosure()));
665 runner->Run();
666 CHECK_NE(status,
667 static_cast<KioskAppManager::ConsumerKioskAutoLaunchStatus>(-1));
668 return status;
671 void RunAppLaunchNetworkDownTest() {
672 mock_user_manager()->SetActiveUser(kTestOwnerEmail);
673 AppLaunchSigninScreen::SetUserManagerForTesting(mock_user_manager());
675 // Mock network could be configured with owner's password.
676 ScopedCanConfigureNetwork can_configure_network(true, true);
678 // Start app launch and wait for network connectivity timeout.
679 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure());
680 OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH);
681 splash_waiter.Wait();
682 WaitForAppLaunchNetworkTimeout();
684 // Configure network link should be visible.
685 JsExpect("$('splash-config-network').hidden == false");
687 // Set up fake user manager with an owner for the test.
688 static_cast<LoginDisplayHostImpl*>(LoginDisplayHostImpl::default_host())
689 ->GetOobeUI()->ShowOobeUI(false);
691 // Configure network should bring up lock screen for owner.
692 OobeScreenWaiter lock_screen_waiter(OobeDisplay::SCREEN_ACCOUNT_PICKER);
693 static_cast<AppLaunchSplashScreenActor::Delegate*>(GetAppLaunchController())
694 ->OnConfigureNetwork();
695 lock_screen_waiter.Wait();
697 // There should be only one owner pod on this screen.
698 JsExpect("$('pod-row').alwaysFocusSinglePod");
700 // A network error screen should be shown after authenticating.
701 OobeScreenWaiter error_screen_waiter(OobeDisplay::SCREEN_ERROR_MESSAGE);
702 static_cast<AppLaunchSigninScreen::Delegate*>(GetAppLaunchController())
703 ->OnOwnerSigninSuccess();
704 error_screen_waiter.Wait();
706 ASSERT_TRUE(GetAppLaunchController()->showing_network_dialog());
708 SimulateNetworkOnline();
709 WaitForAppLaunchSuccess();
712 AppLaunchController* GetAppLaunchController() {
713 return chromeos::LoginDisplayHostImpl::default_host()
714 ->GetAppLaunchController();
717 // Returns a lock that is holding a task on the FILE thread. Any tasks posted
718 // to the FILE thread after this call will be blocked until the returned
719 // lock is released.
720 // This can be used to prevent app installation from completing until some
721 // other conditions are checked and triggered. For example, this can be used
722 // to trigger the network screen during app launch without racing with the
723 // app launching process itself.
724 scoped_ptr<base::AutoLock> LockFileThread() {
725 scoped_ptr<base::Lock> lock(new base::Lock);
726 scoped_ptr<base::AutoLock> auto_lock(new base::AutoLock(*lock));
727 content::BrowserThread::PostTask(
728 content::BrowserThread::FILE, FROM_HERE,
729 base::Bind(&LockAndUnlock, base::Passed(&lock)));
730 return auto_lock.Pass();
733 MockUserManager* mock_user_manager() { return mock_user_manager_.get(); }
735 void set_test_app_id(const std::string& test_app_id) {
736 test_app_id_ = test_app_id;
738 const std::string& test_app_id() const { return test_app_id_; }
739 void set_test_app_version(const std::string& version) {
740 test_app_version_ = version;
742 const std::string& test_app_version() const { return test_app_version_; }
743 void set_test_crx_file(const std::string& filename) {
744 test_crx_file_ = filename;
746 const std::string& test_crx_file() const { return test_crx_file_; }
747 FakeCWS* fake_cws() { return fake_cws_.get(); }
749 void set_use_consumer_kiosk_mode(bool use) {
750 use_consumer_kiosk_mode_ = use;
753 ScopedCrosSettingsTestHelper settings_helper_;
754 scoped_ptr<FakeOwnerSettingsService> owner_settings_service_;
756 private:
757 bool use_consumer_kiosk_mode_;
758 std::string test_app_id_;
759 std::string test_app_version_;
760 std::string test_crx_file_;
761 scoped_ptr<FakeCWS> fake_cws_;
762 scoped_ptr<MockUserManager> mock_user_manager_;
764 DISALLOW_COPY_AND_ASSIGN(KioskTest);
767 IN_PROC_BROWSER_TEST_P(KioskTest, InstallAndLaunchApp) {
768 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
769 WaitForAppLaunchSuccess();
770 KioskAppManager::App app;
771 ASSERT_TRUE(KioskAppManager::Get()->GetApp(test_app_id(), &app));
772 EXPECT_FALSE(app.was_auto_launched_with_zero_delay);
775 IN_PROC_BROWSER_TEST_P(KioskTest, ZoomSupport) {
776 ExtensionTestMessageListener
777 app_window_loaded_listener("appWindowLoaded", false);
778 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
779 app_window_loaded_listener.WaitUntilSatisfied();
781 Profile* app_profile = ProfileManager::GetPrimaryUserProfile();
782 ASSERT_TRUE(app_profile);
784 extensions::AppWindowRegistry* app_window_registry =
785 extensions::AppWindowRegistry::Get(app_profile);
786 extensions::AppWindow* window =
787 AppWindowWaiter(app_window_registry, test_app_id()).Wait();
788 ASSERT_TRUE(window);
790 // Gets the original width of the app window.
791 int original_width;
792 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
793 window->web_contents(),
794 "window.domAutomationController.setAutomationId(0);"
795 "window.domAutomationController.send(window.innerWidth);",
796 &original_width));
798 native_app_window::NativeAppWindowViews* native_app_window_views =
799 static_cast<native_app_window::NativeAppWindowViews*>(
800 window->GetBaseWindow());
801 ui::AcceleratorTarget* accelerator_target =
802 static_cast<ui::AcceleratorTarget*>(native_app_window_views);
804 // Zoom in. Text is bigger and content window width becomes smaller.
805 accelerator_target->AcceleratorPressed(ui::Accelerator(
806 ui::VKEY_ADD, ui::EF_CONTROL_DOWN));
807 int width_zoomed_in;
808 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
809 window->web_contents(),
810 "window.domAutomationController.setAutomationId(0);"
811 "window.domAutomationController.send(window.innerWidth);",
812 &width_zoomed_in));
813 DCHECK_LT(width_zoomed_in, original_width);
815 // Go back to normal. Window width is restored.
816 accelerator_target->AcceleratorPressed(ui::Accelerator(
817 ui::VKEY_0, ui::EF_CONTROL_DOWN));
818 int width_zoom_normal;
819 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
820 window->web_contents(),
821 "window.domAutomationController.setAutomationId(0);"
822 "window.domAutomationController.send(window.innerWidth);",
823 &width_zoom_normal));
824 DCHECK_EQ(width_zoom_normal, original_width);
826 // Zoom out. Text is smaller and content window width becomes larger.
827 accelerator_target->AcceleratorPressed(ui::Accelerator(
828 ui::VKEY_SUBTRACT, ui::EF_CONTROL_DOWN));
829 int width_zoomed_out;
830 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
831 window->web_contents(),
832 "window.domAutomationController.setAutomationId(0);"
833 "window.domAutomationController.send(window.innerWidth);",
834 &width_zoomed_out));
835 DCHECK_GT(width_zoomed_out, original_width);
837 // Terminate the app.
838 window->GetBaseWindow()->Close();
839 content::RunAllPendingInMessageLoop();
842 IN_PROC_BROWSER_TEST_P(KioskTest, NotSignedInWithGAIAAccount) {
843 // Tests that the kiosk session is not considered to be logged in with a GAIA
844 // account.
845 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
846 WaitForAppLaunchSuccess();
848 Profile* app_profile = ProfileManager::GetPrimaryUserProfile();
849 ASSERT_TRUE(app_profile);
850 EXPECT_FALSE(
851 SigninManagerFactory::GetForProfile(app_profile)->IsAuthenticated());
854 IN_PROC_BROWSER_TEST_P(KioskTest, PRE_LaunchAppNetworkDown) {
855 // Tests the network down case for the initial app download and launch.
856 RunAppLaunchNetworkDownTest();
859 IN_PROC_BROWSER_TEST_P(KioskTest, LaunchAppNetworkDown) {
860 // Tests the network down case for launching an existing app that is
861 // installed in PRE_LaunchAppNetworkDown.
862 RunAppLaunchNetworkDownTest();
865 IN_PROC_BROWSER_TEST_P(KioskTest, LaunchAppWithNetworkConfigAccelerator) {
866 ScopedCanConfigureNetwork can_configure_network(true, false);
868 // Block app loading until the network screen is shown.
869 scoped_ptr<base::AutoLock> lock = LockFileThread();
871 // Start app launch and wait for network connectivity timeout.
872 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
873 OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH);
874 splash_waiter.Wait();
876 // A network error screen should be shown after authenticating.
877 OobeScreenWaiter error_screen_waiter(OobeDisplay::SCREEN_ERROR_MESSAGE);
878 // Simulate Ctrl+Alt+N accelerator.
879 GetLoginUI()->CallJavascriptFunction(
880 "cr.ui.Oobe.handleAccelerator",
881 base::StringValue("app_launch_network_config"));
882 error_screen_waiter.Wait();
883 ASSERT_TRUE(GetAppLaunchController()->showing_network_dialog());
885 // Continue button should be visible since we are online.
886 JsExpect("$('continue-network-config-btn').hidden == false");
888 // Click on [Continue] button.
889 ASSERT_TRUE(content::ExecuteScript(
890 GetLoginUI()->GetWebContents(),
891 "(function() {"
892 "var e = new Event('click');"
893 "$('continue-network-config-btn').dispatchEvent(e);"
894 "})();"));
896 // Let app launching resume.
897 lock.reset();
899 WaitForAppLaunchSuccess();
902 IN_PROC_BROWSER_TEST_P(KioskTest, LaunchAppNetworkDownConfigureNotAllowed) {
903 // Mock network could not be configured.
904 ScopedCanConfigureNetwork can_configure_network(false, true);
906 // Start app launch and wait for network connectivity timeout.
907 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure());
908 OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH);
909 splash_waiter.Wait();
910 WaitForAppLaunchNetworkTimeout();
912 // Configure network link should not be visible.
913 JsExpect("$('splash-config-network').hidden == true");
915 // Network becomes online and app launch is resumed.
916 SimulateNetworkOnline();
917 WaitForAppLaunchSuccess();
920 IN_PROC_BROWSER_TEST_P(KioskTest, LaunchAppNetworkPortal) {
921 // Mock network could be configured without the owner password.
922 ScopedCanConfigureNetwork can_configure_network(true, false);
924 // Start app launch with network portal state.
925 StartAppLaunchFromLoginScreen(SimulateNetworkPortalClosure());
926 OobeScreenWaiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH)
927 .WaitNoAssertCurrentScreen();
928 WaitForAppLaunchNetworkTimeout();
930 // Network error should show up automatically since this test does not
931 // require owner auth to configure network.
932 OobeScreenWaiter(OobeDisplay::SCREEN_ERROR_MESSAGE).Wait();
934 ASSERT_TRUE(GetAppLaunchController()->showing_network_dialog());
935 SimulateNetworkOnline();
936 WaitForAppLaunchSuccess();
939 IN_PROC_BROWSER_TEST_P(KioskTest, LaunchAppUserCancel) {
940 // Make fake_cws_ return empty update response.
941 set_test_app_version("");
942 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure());
943 OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH);
944 splash_waiter.Wait();
946 settings_helper_.SetBoolean(
947 kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled, true);
948 content::WindowedNotificationObserver signal(
949 chrome::NOTIFICATION_APP_TERMINATING,
950 content::NotificationService::AllSources());
951 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
952 base::StringValue("app_launch_bailout"));
953 signal.Wait();
954 EXPECT_EQ(chromeos::KioskAppLaunchError::USER_CANCEL,
955 chromeos::KioskAppLaunchError::Get());
958 IN_PROC_BROWSER_TEST_P(KioskTest, LaunchInDiagnosticMode) {
959 PrepareAppLaunch();
960 SimulateNetworkOnline();
962 LaunchApp(kTestKioskApp, true);
964 content::WebContents* login_contents = GetLoginUI()->GetWebContents();
966 bool new_kiosk_ui = KioskAppMenuHandler::EnableNewKioskUI();
967 JsConditionWaiter(login_contents, new_kiosk_ui ?
968 kCheckDiagnosticModeNewAPI : kCheckDiagnosticModeOldAPI).Wait();
970 std::string diagnosticMode(new_kiosk_ui ?
971 kCheckDiagnosticModeNewAPI : kCheckDiagnosticModeOldAPI);
972 ASSERT_TRUE(content::ExecuteScript(
973 login_contents,
974 "(function() {"
975 "var e = new Event('click');" +
976 diagnosticMode + "."
977 "okButton_.dispatchEvent(e);"
978 "})();"));
980 WaitForAppLaunchSuccess();
983 IN_PROC_BROWSER_TEST_P(KioskTest, AutolaunchWarningCancel) {
984 EnableConsumerKioskMode();
986 chromeos::WizardController::SkipPostLoginScreensForTesting();
987 chromeos::WizardController* wizard_controller =
988 chromeos::WizardController::default_controller();
989 CHECK(wizard_controller);
991 // Start login screen after configuring auto launch app since the warning
992 // is triggered when switching to login screen.
993 wizard_controller->AdvanceToScreen(WizardController::kNetworkScreenName);
994 ReloadAutolaunchKioskApps();
995 EXPECT_FALSE(KioskAppManager::Get()->GetAutoLaunchApp().empty());
996 EXPECT_FALSE(KioskAppManager::Get()->IsAutoLaunchEnabled());
997 wizard_controller->SkipToLoginForTesting(LoginScreenContext());
999 // Wait for the auto launch warning come up.
1000 content::WindowedNotificationObserver(
1001 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE,
1002 content::NotificationService::AllSources()).Wait();
1003 GetLoginUI()->CallJavascriptFunction(
1004 "login.AutolaunchScreen.confirmAutoLaunchForTesting",
1005 base::FundamentalValue(false));
1007 // Wait for the auto launch warning to go away.
1008 content::WindowedNotificationObserver(
1009 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_COMPLETED,
1010 content::NotificationService::AllSources()).Wait();
1012 EXPECT_FALSE(KioskAppManager::Get()->IsAutoLaunchEnabled());
1015 IN_PROC_BROWSER_TEST_P(KioskTest, AutolaunchWarningConfirm) {
1016 EnableConsumerKioskMode();
1018 chromeos::WizardController::SkipPostLoginScreensForTesting();
1019 chromeos::WizardController* wizard_controller =
1020 chromeos::WizardController::default_controller();
1021 CHECK(wizard_controller);
1023 // Start login screen after configuring auto launch app since the warning
1024 // is triggered when switching to login screen.
1025 wizard_controller->AdvanceToScreen(WizardController::kNetworkScreenName);
1026 ReloadAutolaunchKioskApps();
1027 EXPECT_FALSE(KioskAppManager::Get()->GetAutoLaunchApp().empty());
1028 EXPECT_FALSE(KioskAppManager::Get()->IsAutoLaunchEnabled());
1029 wizard_controller->SkipToLoginForTesting(LoginScreenContext());
1031 // Wait for the auto launch warning come up.
1032 content::WindowedNotificationObserver(
1033 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE,
1034 content::NotificationService::AllSources()).Wait();
1035 GetLoginUI()->CallJavascriptFunction(
1036 "login.AutolaunchScreen.confirmAutoLaunchForTesting",
1037 base::FundamentalValue(true));
1039 // Wait for the auto launch warning to go away.
1040 content::WindowedNotificationObserver(
1041 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_COMPLETED,
1042 content::NotificationService::AllSources()).Wait();
1044 EXPECT_FALSE(KioskAppManager::Get()->GetAutoLaunchApp().empty());
1045 EXPECT_TRUE(KioskAppManager::Get()->IsAutoLaunchEnabled());
1047 WaitForAppLaunchSuccess();
1049 KioskAppManager::App app;
1050 ASSERT_TRUE(KioskAppManager::Get()->GetApp(test_app_id(), &app));
1051 EXPECT_TRUE(app.was_auto_launched_with_zero_delay);
1054 IN_PROC_BROWSER_TEST_P(KioskTest, KioskEnableCancel) {
1055 chromeos::WizardController::SkipPostLoginScreensForTesting();
1056 chromeos::WizardController* wizard_controller =
1057 chromeos::WizardController::default_controller();
1058 CHECK(wizard_controller);
1060 // Check Kiosk mode status.
1061 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE,
1062 GetConsumerKioskModeStatus());
1064 // Wait for the login UI to come up and switch to the kiosk_enable screen.
1065 wizard_controller->SkipToLoginForTesting(LoginScreenContext());
1066 OobeScreenWaiter(OobeDisplay::SCREEN_GAIA_SIGNIN).Wait();
1067 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
1068 base::StringValue("kiosk_enable"));
1070 // Wait for the kiosk_enable screen to show and cancel the screen.
1071 content::WindowedNotificationObserver(
1072 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE,
1073 content::NotificationService::AllSources()).Wait();
1074 GetLoginUI()->CallJavascriptFunction(
1075 "login.KioskEnableScreen.enableKioskForTesting",
1076 base::FundamentalValue(false));
1078 // Wait for the kiosk_enable screen to disappear.
1079 content::WindowedNotificationObserver(
1080 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_COMPLETED,
1081 content::NotificationService::AllSources()).Wait();
1083 // Check that the status still says configurable.
1084 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE,
1085 GetConsumerKioskModeStatus());
1088 IN_PROC_BROWSER_TEST_P(KioskTest, KioskEnableConfirmed) {
1089 // Start UI, find menu entry for this app and launch it.
1090 chromeos::WizardController::SkipPostLoginScreensForTesting();
1091 chromeos::WizardController* wizard_controller =
1092 chromeos::WizardController::default_controller();
1093 CHECK(wizard_controller);
1095 // Check Kiosk mode status.
1096 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE,
1097 GetConsumerKioskModeStatus());
1099 // Wait for the login UI to come up and switch to the kiosk_enable screen.
1100 wizard_controller->SkipToLoginForTesting(LoginScreenContext());
1101 OobeScreenWaiter(OobeDisplay::SCREEN_GAIA_SIGNIN).Wait();
1102 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
1103 base::StringValue("kiosk_enable"));
1105 // Wait for the kiosk_enable screen to show and cancel the screen.
1106 content::WindowedNotificationObserver(
1107 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE,
1108 content::NotificationService::AllSources()).Wait();
1109 GetLoginUI()->CallJavascriptFunction(
1110 "login.KioskEnableScreen.enableKioskForTesting",
1111 base::FundamentalValue(true));
1113 // Wait for the signal that indicates Kiosk Mode is enabled.
1114 content::WindowedNotificationObserver(
1115 chrome::NOTIFICATION_KIOSK_ENABLED,
1116 content::NotificationService::AllSources()).Wait();
1117 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_ENABLED,
1118 GetConsumerKioskModeStatus());
1121 IN_PROC_BROWSER_TEST_P(KioskTest, KioskEnableAfter2ndSigninScreen) {
1122 chromeos::WizardController::SkipPostLoginScreensForTesting();
1123 chromeos::WizardController* wizard_controller =
1124 chromeos::WizardController::default_controller();
1125 CHECK(wizard_controller);
1127 // Check Kiosk mode status.
1128 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE,
1129 GetConsumerKioskModeStatus());
1131 // Wait for the login UI to come up and switch to the kiosk_enable screen.
1132 wizard_controller->SkipToLoginForTesting(LoginScreenContext());
1133 OobeScreenWaiter(OobeDisplay::SCREEN_GAIA_SIGNIN).Wait();
1134 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
1135 base::StringValue("kiosk_enable"));
1137 // Wait for the kiosk_enable screen to show and cancel the screen.
1138 content::WindowedNotificationObserver(
1139 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE,
1140 content::NotificationService::AllSources()).Wait();
1141 GetLoginUI()->CallJavascriptFunction(
1142 "login.KioskEnableScreen.enableKioskForTesting",
1143 base::FundamentalValue(false));
1145 // Wait for the kiosk_enable screen to disappear.
1146 content::WindowedNotificationObserver(
1147 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_COMPLETED,
1148 content::NotificationService::AllSources()).Wait();
1150 // Show signin screen again.
1151 chromeos::LoginDisplayHostImpl::default_host()->StartSignInScreen(
1152 LoginScreenContext());
1153 OobeScreenWaiter(OobeDisplay::SCREEN_GAIA_SIGNIN).Wait();
1155 // Show kiosk enable screen again.
1156 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
1157 base::StringValue("kiosk_enable"));
1159 // And it should show up.
1160 content::WindowedNotificationObserver(
1161 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE,
1162 content::NotificationService::AllSources()).Wait();
1165 IN_PROC_BROWSER_TEST_P(KioskTest, DoNotLaunchWhenUntrusted) {
1166 PrepareAppLaunch();
1167 SimulateNetworkOnline();
1169 // Make cros settings untrusted.
1170 settings_helper_.SetTrustedStatus(
1171 CrosSettingsProvider::PERMANENTLY_UNTRUSTED);
1173 // Check that the attempt to start a kiosk app fails with an error.
1174 LaunchApp(test_app_id(), false);
1175 bool ignored = false;
1176 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
1177 GetLoginUI()->GetWebContents(),
1178 "if (cr.ui.Oobe.getInstance().errorMessageWasShownForTesting_) {"
1179 " window.domAutomationController.send(true);"
1180 "} else {"
1181 " cr.ui.Oobe.showSignInError = function("
1182 " loginAttempts, message, link, helpId) {"
1183 " window.domAutomationController.send(true);"
1184 " };"
1185 "}",
1186 &ignored));
1189 // Verifies that a consumer device does not auto-launch kiosk mode when cros
1190 // settings are untrusted.
1191 IN_PROC_BROWSER_TEST_P(KioskTest, NoConsumerAutoLaunchWhenUntrusted) {
1192 EnableConsumerKioskMode();
1194 // Wait for and confirm the auto-launch warning.
1195 chromeos::WizardController::SkipPostLoginScreensForTesting();
1196 chromeos::WizardController* wizard_controller =
1197 chromeos::WizardController::default_controller();
1198 ASSERT_TRUE(wizard_controller);
1199 wizard_controller->AdvanceToScreen(WizardController::kNetworkScreenName);
1200 ReloadAutolaunchKioskApps();
1201 wizard_controller->SkipToLoginForTesting(LoginScreenContext());
1202 content::WindowedNotificationObserver(
1203 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE,
1204 content::NotificationService::AllSources()).Wait();
1205 GetLoginUI()->CallJavascriptFunction(
1206 "login.AutolaunchScreen.confirmAutoLaunchForTesting",
1207 base::FundamentalValue(true));
1209 // Make cros settings untrusted.
1210 settings_helper_.SetTrustedStatus(
1211 CrosSettingsProvider::PERMANENTLY_UNTRUSTED);
1213 // Check that the attempt to auto-launch a kiosk app fails with an error.
1214 OobeScreenWaiter(OobeDisplay::SCREEN_ERROR_MESSAGE).Wait();
1217 // Verifies available volumes for kiosk apps in kiosk session.
1218 IN_PROC_BROWSER_TEST_P(KioskTest, GetVolumeList) {
1219 set_test_app_id(kTestGetVolumeListKioskApp);
1220 set_test_app_version("0.1");
1221 set_test_crx_file(test_app_id() + ".crx");
1223 extensions::ResultCatcher catcher;
1224 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
1225 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
1228 // Verifies that an enterprise device does not auto-launch kiosk mode when cros
1229 // settings are untrusted.
1230 IN_PROC_BROWSER_TEST_P(KioskTest, NoEnterpriseAutoLaunchWhenUntrusted) {
1231 PrepareAppLaunch();
1232 SimulateNetworkOnline();
1234 // Make cros settings untrusted.
1235 settings_helper_.SetTrustedStatus(
1236 CrosSettingsProvider::PERMANENTLY_UNTRUSTED);
1238 // Trigger the code that handles auto-launch on enterprise devices. This would
1239 // normally be called from ShowLoginWizard(), which runs so early that it is
1240 // not possible to inject an auto-launch policy before it runs.
1241 LoginDisplayHost* login_display_host = LoginDisplayHostImpl::default_host();
1242 ASSERT_TRUE(login_display_host);
1243 login_display_host->StartAppLaunch(test_app_id(), false, true);
1245 // Check that no launch has started.
1246 EXPECT_FALSE(login_display_host->GetAppLaunchController());
1249 class KioskUpdateTest : public KioskTest {
1250 public:
1251 KioskUpdateTest() {}
1252 ~KioskUpdateTest() override {}
1254 protected:
1255 void SetUp() override {
1256 fake_disk_mount_manager_ = new KioskFakeDiskMountManager();
1257 disks::DiskMountManager::InitializeForTesting(fake_disk_mount_manager_);
1259 KioskTest::SetUp();
1262 void TearDown() override {
1263 disks::DiskMountManager::Shutdown();
1265 KioskTest::TearDown();
1268 void SetUpOnMainThread() override {
1269 // For update tests, we cache the app in the PRE part, and then we load it
1270 // in the test, so we need to both store the apps list on teardown (so that
1271 // the app manager would accept existing files in its extension cache on the
1272 // next startup) and copy the list to our stub settings provider as well.
1273 settings_helper_.CopyStoredValue(kAccountsPrefDeviceLocalAccounts);
1274 KioskTest::SetUpOnMainThread();
1277 void TearDownOnMainThread() override {
1278 settings_helper_.StoreCachedDeviceSetting(kAccountsPrefDeviceLocalAccounts);
1279 KioskTest::TearDownOnMainThread();
1282 void PreCacheApp(const std::string& app_id,
1283 const std::string& version,
1284 const std::string& crx_file) {
1285 set_test_app_id(app_id);
1286 set_test_app_version(version);
1287 set_test_crx_file(crx_file);
1289 KioskAppManager* manager = KioskAppManager::Get();
1290 AppDataLoadWaiter waiter(manager, app_id, version);
1291 ReloadKioskApps();
1292 waiter.Wait();
1293 EXPECT_TRUE(waiter.loaded());
1294 std::string cached_version;
1295 base::FilePath file_path;
1296 EXPECT_TRUE(manager->GetCachedCrx(app_id, &file_path, &cached_version));
1297 EXPECT_EQ(version, cached_version);
1300 void UpdateExternalCache(const std::string& version,
1301 const std::string& crx_file) {
1302 set_test_app_version(version);
1303 set_test_crx_file(crx_file);
1304 SetupTestAppUpdateCheck();
1306 KioskAppManager* manager = KioskAppManager::Get();
1307 AppDataLoadWaiter waiter(manager, test_app_id(), version);
1308 KioskAppManager::Get()->UpdateExternalCache();
1309 waiter.Wait();
1310 EXPECT_TRUE(waiter.loaded());
1311 std::string cached_version;
1312 base::FilePath file_path;
1313 EXPECT_TRUE(
1314 manager->GetCachedCrx(test_app_id(), &file_path, &cached_version));
1315 EXPECT_EQ(version, cached_version);
1318 void SetupFakeDiskMountManagerMountPath(const std::string mount_path) {
1319 base::FilePath test_data_dir;
1320 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
1321 test_data_dir = test_data_dir.AppendASCII(mount_path);
1322 fake_disk_mount_manager_->set_usb_mount_path(test_data_dir.value());
1325 void SimulateUpdateAppFromUsbStick(const std::string& usb_mount_path,
1326 bool* app_update_notified,
1327 bool* update_success) {
1328 SetupFakeDiskMountManagerMountPath(usb_mount_path);
1329 KioskAppExternalUpdateWaiter waiter(KioskAppManager::Get(), test_app_id());
1330 fake_disk_mount_manager_->MountUsbStick();
1331 waiter.Wait();
1332 fake_disk_mount_manager_->UnMountUsbStick();
1333 *update_success = waiter.update_success();
1334 *app_update_notified = waiter.app_update_notified();
1337 void PreCacheAndLaunchApp(const std::string& app_id,
1338 const std::string& version,
1339 const std::string& crx_file) {
1340 set_test_app_id(app_id);
1341 set_test_app_version(version);
1342 set_test_crx_file(crx_file);
1343 PrepareAppLaunch();
1344 SimulateNetworkOnline();
1345 LaunchApp(test_app_id(), false);
1346 WaitForAppLaunchSuccess();
1347 EXPECT_EQ(version, GetInstalledAppVersion().GetString());
1350 private:
1351 class KioskAppExternalUpdateWaiter : public KioskAppManagerObserver {
1352 public:
1353 KioskAppExternalUpdateWaiter(KioskAppManager* manager,
1354 const std::string& app_id)
1355 : runner_(NULL),
1356 manager_(manager),
1357 app_id_(app_id),
1358 quit_(false),
1359 update_success_(false),
1360 app_update_notified_(false) {
1361 manager_->AddObserver(this);
1364 ~KioskAppExternalUpdateWaiter() override { manager_->RemoveObserver(this); }
1366 void Wait() {
1367 if (quit_)
1368 return;
1369 runner_ = new content::MessageLoopRunner;
1370 runner_->Run();
1373 bool update_success() const { return update_success_; }
1375 bool app_update_notified() const { return app_update_notified_; }
1377 private:
1378 // KioskAppManagerObserver overrides:
1379 void OnKioskAppCacheUpdated(const std::string& app_id) override {
1380 if (app_id_ != app_id)
1381 return;
1382 app_update_notified_ = true;
1385 void OnKioskAppExternalUpdateComplete(bool success) override {
1386 quit_ = true;
1387 update_success_ = success;
1388 if (runner_.get())
1389 runner_->Quit();
1392 scoped_refptr<content::MessageLoopRunner> runner_;
1393 KioskAppManager* manager_;
1394 const std::string app_id_;
1395 bool quit_;
1396 bool update_success_;
1397 bool app_update_notified_;
1399 DISALLOW_COPY_AND_ASSIGN(KioskAppExternalUpdateWaiter);
1402 // Owned by DiskMountManager.
1403 KioskFakeDiskMountManager* fake_disk_mount_manager_;
1405 DISALLOW_COPY_AND_ASSIGN(KioskUpdateTest);
1408 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, PRE_LaunchOfflineEnabledAppNoNetwork) {
1409 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp,
1410 "1.0.0",
1411 std::string(kTestOfflineEnabledKioskApp) + "_v1.crx");
1414 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, LaunchOfflineEnabledAppNoNetwork) {
1415 set_test_app_id(kTestOfflineEnabledKioskApp);
1416 StartUIForAppLaunch();
1417 SimulateNetworkOffline();
1418 LaunchApp(test_app_id(), false);
1419 WaitForAppLaunchSuccess();
1421 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString());
1424 IN_PROC_BROWSER_TEST_P(KioskUpdateTest,
1425 PRE_LaunchCachedOfflineEnabledAppNoNetwork) {
1426 PreCacheApp(kTestOfflineEnabledKioskApp,
1427 "1.0.0",
1428 std::string(kTestOfflineEnabledKioskApp) + "_v1.crx");
1431 IN_PROC_BROWSER_TEST_P(KioskUpdateTest,
1432 LaunchCachedOfflineEnabledAppNoNetwork) {
1433 set_test_app_id(kTestOfflineEnabledKioskApp);
1434 EXPECT_TRUE(
1435 KioskAppManager::Get()->HasCachedCrx(kTestOfflineEnabledKioskApp));
1436 StartUIForAppLaunch();
1437 SimulateNetworkOffline();
1438 LaunchApp(test_app_id(), false);
1439 WaitForAppLaunchSuccess();
1441 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString());
1444 // Network offline, app v1.0 has run before, has cached v2.0 crx and v2.0 should
1445 // be installed and launched during next launch.
1446 IN_PROC_BROWSER_TEST_P(KioskUpdateTest,
1447 PRE_LaunchCachedNewVersionOfflineEnabledAppNoNetwork) {
1448 // Install and launch v1 app.
1449 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp,
1450 "1.0.0",
1451 std::string(kTestOfflineEnabledKioskApp) + "_v1.crx");
1452 // Update cache for v2 app.
1453 UpdateExternalCache("2.0.0",
1454 std::string(kTestOfflineEnabledKioskApp) + ".crx");
1455 // The installed app is still in v1.
1456 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString());
1459 IN_PROC_BROWSER_TEST_P(KioskUpdateTest,
1460 LaunchCachedNewVersionOfflineEnabledAppNoNetwork) {
1461 set_test_app_id(kTestOfflineEnabledKioskApp);
1462 EXPECT_TRUE(KioskAppManager::Get()->HasCachedCrx(test_app_id()));
1464 StartUIForAppLaunch();
1465 SimulateNetworkOffline();
1466 LaunchApp(test_app_id(), false);
1467 WaitForAppLaunchSuccess();
1469 // v2 app should have been installed.
1470 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString());
1473 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, PRE_LaunchOfflineEnabledAppNoUpdate) {
1474 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp,
1475 "1.0.0",
1476 std::string(kTestOfflineEnabledKioskApp) + "_v1.crx");
1479 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, LaunchOfflineEnabledAppNoUpdate) {
1480 set_test_app_id(kTestOfflineEnabledKioskApp);
1481 fake_cws()->SetNoUpdate(test_app_id());
1483 StartUIForAppLaunch();
1484 SimulateNetworkOnline();
1485 LaunchApp(test_app_id(), false);
1486 WaitForAppLaunchSuccess();
1488 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString());
1491 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, PRE_LaunchOfflineEnabledAppHasUpdate) {
1492 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp,
1493 "1.0.0",
1494 std::string(kTestOfflineEnabledKioskApp) + "_v1.crx");
1497 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, LaunchOfflineEnabledAppHasUpdate) {
1498 set_test_app_id(kTestOfflineEnabledKioskApp);
1499 fake_cws()->SetUpdateCrx(
1500 test_app_id(), "ajoggoflpgplnnjkjamcmbepjdjdnpdp.crx", "2.0.0");
1502 StartUIForAppLaunch();
1503 SimulateNetworkOnline();
1504 LaunchApp(test_app_id(), false);
1505 WaitForAppLaunchSuccess();
1507 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString());
1510 // Pre-cache v1 kiosk app, then launch the app without network,
1511 // plug in usb stick with a v2 app for offline updating.
1512 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, PRE_UsbStickUpdateAppNoNetwork) {
1513 PreCacheApp(kTestOfflineEnabledKioskApp,
1514 "1.0.0",
1515 std::string(kTestOfflineEnabledKioskApp) + "_v1.crx");
1517 set_test_app_id(kTestOfflineEnabledKioskApp);
1518 StartUIForAppLaunch();
1519 SimulateNetworkOffline();
1520 LaunchApp(test_app_id(), false);
1521 WaitForAppLaunchSuccess();
1522 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString());
1524 // Simulate mounting of usb stick with v2 app on the stick.
1525 bool update_success;
1526 bool app_update_notified;
1527 SimulateUpdateAppFromUsbStick(
1528 kFakeUsbMountPathUpdatePass, &app_update_notified, &update_success);
1529 EXPECT_TRUE(update_success);
1530 EXPECT_TRUE(app_update_notified);
1532 // The v2 kiosk app is loaded into external cache, but won't be installed
1533 // until next time the device is started.
1534 base::FilePath crx_path;
1535 std::string cached_version;
1536 EXPECT_TRUE(KioskAppManager::Get()->GetCachedCrx(
1537 test_app_id(), &crx_path, &cached_version));
1538 EXPECT_EQ("2.0.0", cached_version);
1539 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString());
1542 // Restart the device, verify the app has been updated to v2.
1543 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, UsbStickUpdateAppNoNetwork) {
1544 // Verify the kiosk app has been updated to v2.
1545 set_test_app_id(kTestOfflineEnabledKioskApp);
1546 StartUIForAppLaunch();
1547 SimulateNetworkOffline();
1548 LaunchApp(test_app_id(), false);
1549 WaitForAppLaunchSuccess();
1550 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString());
1553 // Usb stick is plugged in without a manifest file on it.
1554 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, UsbStickUpdateAppNoManifest) {
1555 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp,
1556 "1.0.0",
1557 std::string(kTestOfflineEnabledKioskApp) + "_v1.crx");
1558 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString());
1560 // Simulate mounting of usb stick with v2 app on the stick.
1561 bool update_success;
1562 bool app_update_notified;
1563 SimulateUpdateAppFromUsbStick(
1564 kFakeUsbMountPathNoManifest, &app_update_notified, &update_success);
1565 EXPECT_FALSE(update_success);
1567 // Kiosk app is not updated.
1568 base::FilePath crx_path;
1569 std::string cached_version;
1570 EXPECT_TRUE(KioskAppManager::Get()->GetCachedCrx(
1571 test_app_id(), &crx_path, &cached_version));
1572 EXPECT_EQ("1.0.0", cached_version);
1575 // Usb stick is plugged in with a bad manifest file on it.
1576 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, UsbStickUpdateAppBadManifest) {
1577 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp,
1578 "1.0.0",
1579 std::string(kTestOfflineEnabledKioskApp) + "_v1.crx");
1580 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString());
1582 // Simulate mounting of usb stick with v2 app on the stick.
1583 bool update_success;
1584 bool app_update_notified;
1585 SimulateUpdateAppFromUsbStick(
1586 kFakeUsbMountPathBadManifest, &app_update_notified, &update_success);
1587 EXPECT_FALSE(update_success);
1589 // Kiosk app is not updated.
1590 base::FilePath crx_path;
1591 std::string cached_version;
1592 EXPECT_TRUE(KioskAppManager::Get()->GetCachedCrx(
1593 test_app_id(), &crx_path, &cached_version));
1594 EXPECT_EQ("1.0.0", cached_version);
1597 // Usb stick is plugged in with a lower version of crx file specified in
1598 // manifest.
1599 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, UsbStickUpdateAppLowerAppVersion) {
1600 // Precache v2 version of app.
1601 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp,
1602 "2.0.0",
1603 std::string(kTestOfflineEnabledKioskApp) + ".crx");
1604 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString());
1606 // Simulate mounting of usb stick with v1 app on the stick.
1607 bool update_success;
1608 bool app_update_notified;
1609 SimulateUpdateAppFromUsbStick(
1610 kFakeUsbMountPathLowerAppVersion, &app_update_notified, &update_success);
1611 EXPECT_FALSE(update_success);
1613 // Kiosk app is NOT updated to the lower version.
1614 base::FilePath crx_path;
1615 std::string cached_version;
1616 EXPECT_TRUE(KioskAppManager::Get()->GetCachedCrx(
1617 test_app_id(), &crx_path, &cached_version));
1618 EXPECT_EQ("2.0.0", cached_version);
1621 // Usb stick is plugged in with a v1 crx file, although the manifest says
1622 // this is a v3 version.
1623 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, UsbStickUpdateAppLowerCrxVersion) {
1624 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp,
1625 "2.0.0",
1626 std::string(kTestOfflineEnabledKioskApp) + ".crx");
1627 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString());
1629 // Simulate mounting of usb stick with v1 crx file on the stick, although
1630 // the manifest says it is v3 app.
1631 bool update_success;
1632 bool app_update_notified;
1633 SimulateUpdateAppFromUsbStick(
1634 kFakeUsbMountPathLowerCrxVersion, &app_update_notified, &update_success);
1635 EXPECT_FALSE(update_success);
1637 // Kiosk app is NOT updated to the lower version.
1638 base::FilePath crx_path;
1639 std::string cached_version;
1640 EXPECT_TRUE(KioskAppManager::Get()->GetCachedCrx(
1641 test_app_id(), &crx_path, &cached_version));
1642 EXPECT_EQ("2.0.0", cached_version);
1645 // Usb stick is plugged in with a bad crx file.
1646 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, UsbStickUpdateAppBadCrx) {
1647 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp,
1648 "1.0.0",
1649 std::string(kTestOfflineEnabledKioskApp) + "_v1.crx");
1650 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString());
1652 // Simulate mounting of usb stick with v1 crx file on the stick, although
1653 // the manifest says it is v3 app.
1654 bool update_success;
1655 bool app_update_notified;
1656 SimulateUpdateAppFromUsbStick(
1657 kFakeUsbMountPathBadCrx, &app_update_notified, &update_success);
1658 EXPECT_FALSE(update_success);
1660 // Kiosk app is NOT updated.
1661 base::FilePath crx_path;
1662 std::string cached_version;
1663 EXPECT_TRUE(KioskAppManager::Get()->GetCachedCrx(
1664 test_app_id(), &crx_path, &cached_version));
1665 EXPECT_EQ("1.0.0", cached_version);
1668 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, PRE_PermissionChange) {
1669 PreCacheAndLaunchApp(kTestOfflineEnabledKioskApp,
1670 "2.0.0",
1671 std::string(kTestOfflineEnabledKioskApp) + ".crx");
1674 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, PermissionChange) {
1675 set_test_app_id(kTestOfflineEnabledKioskApp);
1676 set_test_app_version("2.0.0");
1677 set_test_crx_file(test_app_id() + "_v2_permission_change.crx");
1679 StartUIForAppLaunch();
1680 SimulateNetworkOnline();
1681 LaunchApp(test_app_id(), false);
1682 WaitForAppLaunchSuccess();
1684 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString());
1687 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, PRE_PreserveLocalData) {
1688 // Installs v1 app and writes some local data.
1689 set_test_app_id(kTestLocalFsKioskApp);
1690 set_test_app_version("1.0.0");
1691 set_test_crx_file(test_app_id() + ".crx");
1693 extensions::ResultCatcher catcher;
1694 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
1695 WaitForAppLaunchWithOptions(true /* check_launch_data */,
1696 false /* terminate_app */);
1697 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
1700 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, PreserveLocalData) {
1701 // Update existing v1 app installed in PRE_PreserveLocalData to v2
1702 // that reads and verifies the local data.
1703 set_test_app_id(kTestLocalFsKioskApp);
1704 set_test_app_version("2.0.0");
1705 set_test_crx_file(test_app_id() + "_v2_read_and_verify_data.crx");
1706 extensions::ResultCatcher catcher;
1707 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
1708 WaitForAppLaunchWithOptions(true /* check_launch_data */,
1709 false /* terminate_app */);
1711 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString());
1712 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
1715 class KioskEnterpriseTest : public KioskTest {
1716 protected:
1717 KioskEnterpriseTest() {
1718 set_use_consumer_kiosk_mode(false);
1721 void SetUpInProcessBrowserTestFixture() override {
1722 policy::DevicePolicyCrosTestHelper::MarkAsEnterpriseOwnedBy(
1723 kTestOwnerEmail);
1724 settings_helper_.SetCurrentUserIsOwner(false);
1726 KioskTest::SetUpInProcessBrowserTestFixture();
1729 void SetUpOnMainThread() override {
1730 KioskTest::SetUpOnMainThread();
1732 // Configure OAuth authentication.
1733 GaiaUrls* gaia_urls = GaiaUrls::GetInstance();
1735 // This token satisfies the userinfo.email request from
1736 // DeviceOAuth2TokenService used in token validation.
1737 FakeGaia::AccessTokenInfo userinfo_token_info;
1738 userinfo_token_info.token = kTestUserinfoToken;
1739 userinfo_token_info.scopes.insert(
1740 "https://www.googleapis.com/auth/userinfo.email");
1741 userinfo_token_info.audience = gaia_urls->oauth2_chrome_client_id();
1742 userinfo_token_info.email = kTestEnterpriseServiceAccountId;
1743 fake_gaia_->IssueOAuthToken(kTestRefreshToken, userinfo_token_info);
1745 // The any-api access token for accessing the token minting endpoint.
1746 FakeGaia::AccessTokenInfo login_token_info;
1747 login_token_info.token = kTestLoginToken;
1748 login_token_info.scopes.insert(GaiaConstants::kAnyApiOAuth2Scope);
1749 login_token_info.audience = gaia_urls->oauth2_chrome_client_id();
1750 fake_gaia_->IssueOAuthToken(kTestRefreshToken, login_token_info);
1752 // This is the access token requested by the app via the identity API.
1753 FakeGaia::AccessTokenInfo access_token_info;
1754 access_token_info.token = kTestAccessToken;
1755 access_token_info.scopes.insert(kTestAppScope);
1756 access_token_info.audience = kTestClientId;
1757 access_token_info.email = kTestEnterpriseServiceAccountId;
1758 fake_gaia_->IssueOAuthToken(kTestLoginToken, access_token_info);
1760 DeviceOAuth2TokenService* token_service =
1761 DeviceOAuth2TokenServiceFactory::Get();
1762 token_service->SetAndSaveRefreshToken(
1763 kTestRefreshToken, DeviceOAuth2TokenService::StatusCallback());
1764 base::RunLoop().RunUntilIdle();
1767 void ConfigureKioskAppInPolicy(const std::string& account_id,
1768 const std::string& app_id,
1769 const std::string& update_url) {
1770 settings_helper_.SetCurrentUserIsOwner(true);
1771 std::vector<policy::DeviceLocalAccount> accounts;
1772 accounts.push_back(
1773 policy::DeviceLocalAccount(policy::DeviceLocalAccount::TYPE_KIOSK_APP,
1774 account_id, app_id, update_url));
1775 policy::SetDeviceLocalAccounts(owner_settings_service_.get(), accounts);
1776 settings_helper_.SetString(kAccountsPrefDeviceLocalAccountAutoLoginId,
1777 account_id);
1778 settings_helper_.SetString(kServiceAccountIdentity,
1779 kTestEnterpriseServiceAccountId);
1780 settings_helper_.SetCurrentUserIsOwner(false);
1783 private:
1784 DISALLOW_COPY_AND_ASSIGN(KioskEnterpriseTest);
1787 IN_PROC_BROWSER_TEST_P(KioskEnterpriseTest, EnterpriseKioskApp) {
1788 // Prepare Fake CWS to serve app crx.
1789 set_test_app_id(kTestEnterpriseKioskApp);
1790 set_test_app_version("1.0.0");
1791 set_test_crx_file(test_app_id() + ".crx");
1792 SetupTestAppUpdateCheck();
1794 // Configure kTestEnterpriseKioskApp in device policy.
1795 ConfigureKioskAppInPolicy(kTestEnterpriseAccountId,
1796 kTestEnterpriseKioskApp,
1797 "");
1799 PrepareAppLaunch();
1800 LaunchApp(kTestEnterpriseKioskApp, false);
1802 // Wait for the Kiosk App to launch.
1803 content::WindowedNotificationObserver(
1804 chrome::NOTIFICATION_KIOSK_APP_LAUNCHED,
1805 content::NotificationService::AllSources()).Wait();
1807 // Check installer status.
1808 EXPECT_EQ(chromeos::KioskAppLaunchError::NONE,
1809 chromeos::KioskAppLaunchError::Get());
1811 // Wait for the window to appear.
1812 extensions::AppWindow* window =
1813 AppWindowWaiter(
1814 extensions::AppWindowRegistry::Get(
1815 ProfileManager::GetPrimaryUserProfile()),
1816 kTestEnterpriseKioskApp).Wait();
1817 ASSERT_TRUE(window);
1819 // Check whether the app can retrieve an OAuth2 access token.
1820 std::string result;
1821 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
1822 window->web_contents(),
1823 "chrome.identity.getAuthToken({ 'interactive': false }, function(token) {"
1824 " window.domAutomationController.setAutomationId(0);"
1825 " window.domAutomationController.send(token);"
1826 "});",
1827 &result));
1828 EXPECT_EQ(kTestAccessToken, result);
1830 // Verify that the session is not considered to be logged in with a GAIA
1831 // account.
1832 Profile* app_profile = ProfileManager::GetPrimaryUserProfile();
1833 ASSERT_TRUE(app_profile);
1834 EXPECT_FALSE(
1835 SigninManagerFactory::GetForProfile(app_profile)->IsAuthenticated());
1837 // Terminate the app.
1838 window->GetBaseWindow()->Close();
1839 content::RunAllPendingInMessageLoop();
1842 IN_PROC_BROWSER_TEST_P(KioskEnterpriseTest, PrivateStore) {
1843 set_test_app_id(kTestEnterpriseKioskApp);
1845 const char kPrivateStoreUpdate[] = "/private_store_update";
1846 net::test_server::EmbeddedTestServer private_server;
1847 ASSERT_TRUE(private_server.InitializeAndWaitUntilReady());
1849 // |private_server| serves crx from test data dir.
1850 base::FilePath test_data_dir;
1851 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
1852 private_server.ServeFilesFromDirectory(test_data_dir);
1854 FakeCWS private_store;
1855 private_store.InitAsPrivateStore(&private_server, kPrivateStoreUpdate);
1856 private_store.SetUpdateCrx(kTestEnterpriseKioskApp,
1857 std::string(kTestEnterpriseKioskApp) + ".crx",
1858 "1.0.0");
1860 // Configure kTestEnterpriseKioskApp in device policy.
1861 ConfigureKioskAppInPolicy(kTestEnterpriseAccountId,
1862 kTestEnterpriseKioskApp,
1863 private_server.GetURL(kPrivateStoreUpdate).spec());
1865 // Meta should be able to be extracted from crx before launching.
1866 KioskAppManager* manager = KioskAppManager::Get();
1867 AppDataLoadWaiter waiter(manager, kTestEnterpriseKioskApp, std::string());
1868 waiter.WaitForAppData();
1870 PrepareAppLaunch();
1871 LaunchApp(kTestEnterpriseKioskApp, false);
1872 WaitForAppLaunchWithOptions(false /* check_launch_data */,
1873 true /* terminate_app */);
1875 // Private store should serve crx and CWS should not.
1876 DCHECK_GT(private_store.GetUpdateCheckCountAndReset(), 0);
1877 DCHECK_EQ(0, fake_cws()->GetUpdateCheckCountAndReset());
1880 // Specialized test fixture for testing kiosk mode on the
1881 // hidden WebUI initialization flow for slow hardware.
1882 class KioskHiddenWebUITest : public KioskTest,
1883 public ash::DesktopBackgroundControllerObserver {
1884 public:
1885 KioskHiddenWebUITest() : wallpaper_loaded_(false) {}
1887 // KioskTest overrides:
1888 void SetUpCommandLine(base::CommandLine* command_line) override {
1889 KioskTest::SetUpCommandLine(command_line);
1890 command_line->AppendSwitch(switches::kDisableBootAnimation);
1893 void SetUpOnMainThread() override {
1894 KioskTest::SetUpOnMainThread();
1895 ash::Shell::GetInstance()->desktop_background_controller()
1896 ->AddObserver(this);
1899 void TearDownOnMainThread() override {
1900 ash::Shell::GetInstance()->desktop_background_controller()
1901 ->RemoveObserver(this);
1902 KioskTest::TearDownOnMainThread();
1905 void WaitForWallpaper() {
1906 if (!wallpaper_loaded_) {
1907 runner_ = new content::MessageLoopRunner;
1908 runner_->Run();
1912 bool wallpaper_loaded() const { return wallpaper_loaded_; }
1914 // ash::DesktopBackgroundControllerObserver overrides:
1915 void OnWallpaperDataChanged() override {
1916 wallpaper_loaded_ = true;
1917 if (runner_.get())
1918 runner_->Quit();
1921 bool wallpaper_loaded_;
1922 scoped_refptr<content::MessageLoopRunner> runner_;
1924 DISALLOW_COPY_AND_ASSIGN(KioskHiddenWebUITest);
1927 IN_PROC_BROWSER_TEST_P(KioskHiddenWebUITest, AutolaunchWarning) {
1928 // Add a device owner.
1929 FakeChromeUserManager* user_manager = new FakeChromeUserManager();
1930 user_manager->AddUser(kTestOwnerEmail);
1931 ScopedUserManagerEnabler enabler(user_manager);
1933 // Set kiosk app to autolaunch.
1934 EnableConsumerKioskMode();
1935 WizardController::SkipPostLoginScreensForTesting();
1936 WizardController* wizard_controller = WizardController::default_controller();
1937 CHECK(wizard_controller);
1939 // Start login screen after configuring auto launch app since the warning
1940 // is triggered when switching to login screen.
1941 wizard_controller->AdvanceToScreen(WizardController::kNetworkScreenName);
1942 ReloadAutolaunchKioskApps();
1943 wizard_controller->SkipToLoginForTesting(LoginScreenContext());
1945 EXPECT_FALSE(KioskAppManager::Get()->GetAutoLaunchApp().empty());
1946 EXPECT_FALSE(KioskAppManager::Get()->IsAutoLaunchEnabled());
1948 // Wait for the auto launch warning come up.
1949 content::WindowedNotificationObserver(
1950 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE,
1951 content::NotificationService::AllSources()).Wait();
1953 // Wait for the wallpaper to load.
1954 WaitForWallpaper();
1955 EXPECT_TRUE(wallpaper_loaded());
1958 INSTANTIATE_TEST_CASE_P(KioskSuite, KioskTest, testing::Bool());
1959 INSTANTIATE_TEST_CASE_P(KioskUpdateSuite, KioskUpdateTest, testing::Bool());
1960 INSTANTIATE_TEST_CASE_P(KioskEnterpriseSuite,
1961 KioskEnterpriseTest,
1962 testing::Bool());
1963 INSTANTIATE_TEST_CASE_P(KioskHiddenWebUISuite,
1964 KioskHiddenWebUITest,
1965 testing::Bool());
1967 } // namespace chromeos