1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "apps/app_window.h"
6 #include "apps/app_window_registry.h"
7 #include "apps/ui/native_app_window.h"
8 #include "ash/desktop_background/desktop_background_controller.h"
9 #include "ash/desktop_background/desktop_background_controller_observer.h"
10 #include "ash/shell.h"
11 #include "base/file_util.h"
12 #include "base/path_service.h"
13 #include "base/prefs/pref_service.h"
14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_util.h"
16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h"
19 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
20 #include "chrome/browser/chromeos/login/app_launch_controller.h"
21 #include "chrome/browser/chromeos/login/fake_user_manager.h"
22 #include "chrome/browser/chromeos/login/mock_user_manager.h"
23 #include "chrome/browser/chromeos/login/oobe_base_test.h"
24 #include "chrome/browser/chromeos/login/startup_utils.h"
25 #include "chrome/browser/chromeos/login/test/app_window_waiter.h"
26 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
27 #include "chrome/browser/chromeos/login/wizard_controller.h"
28 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
29 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
30 #include "chrome/browser/chromeos/profiles/profile_helper.h"
31 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
32 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h"
33 #include "chrome/browser/extensions/extension_service.h"
34 #include "chrome/browser/extensions/extension_test_message_listener.h"
35 #include "chrome/browser/ui/webui/chromeos/login/kiosk_app_menu_handler.h"
36 #include "chrome/common/chrome_constants.h"
37 #include "chrome/common/chrome_paths.h"
38 #include "chrome/common/chrome_switches.h"
39 #include "chrome/common/pref_names.h"
40 #include "chromeos/chromeos_switches.h"
41 #include "chromeos/dbus/cryptohome_client.h"
42 #include "components/signin/core/common/signin_pref_names.h"
43 #include "content/public/browser/notification_observer.h"
44 #include "content/public/browser/notification_registrar.h"
45 #include "content/public/browser/notification_service.h"
46 #include "content/public/test/browser_test_utils.h"
47 #include "crypto/sha2.h"
48 #include "extensions/browser/extension_system.h"
49 #include "google_apis/gaia/gaia_constants.h"
50 #include "google_apis/gaia/gaia_switches.h"
51 #include "google_apis/gaia/gaia_urls.h"
52 #include "net/test/embedded_test_server/embedded_test_server.h"
53 #include "net/test/embedded_test_server/http_request.h"
54 #include "net/test/embedded_test_server/http_response.h"
56 using net::test_server::BasicHttpResponse
;
57 using net::test_server::HttpRequest
;
58 using net::test_server::HttpResponse
;
60 namespace em
= enterprise_management
;
66 // This is a simple test app that creates an app window and immediately closes
67 // it again. Webstore data json is in
68 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/
69 // detail/ggbflgnkafappblpkiflbgpmkfdpnhhe
70 const char kTestKioskApp
[] = "ggbflgnkafappblpkiflbgpmkfdpnhhe";
72 // This app creates a window and declares usage of the identity API in its
73 // manifest, so we can test device robot token minting via the identity API.
74 // Webstore data json is in
75 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/
76 // detail/ibjkkfdnfcaoapcpheeijckmpcfkifob
77 const char kTestEnterpriseKioskApp
[] = "ibjkkfdnfcaoapcpheeijckmpcfkifob";
79 // An offline enable test app. Webstore data json is in
80 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/
81 // detail/ajoggoflpgplnnjkjamcmbepjdjdnpdp
82 // An app profile with version 1.0.0 installed is in
83 // chrome/test/data/chromeos/app_mode/offline_enabled_app_profile
84 // The version 2.0.0 crx is in
85 // chrome/test/data/chromeos/app_mode/webstore/downloads/
86 const char kTestOfflineEnabledKioskApp
[] = "ajoggoflpgplnnjkjamcmbepjdjdnpdp";
88 // An app to test local fs data persistence across app update. V1 app writes
89 // data into local fs. V2 app reads and verifies the data.
90 // Webstore data json is in
91 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/
92 // detail/bmbpicmpniaclbbpdkfglgipkkebnbjf
93 const char kTestLocalFsKioskApp
[] = "bmbpicmpniaclbbpdkfglgipkkebnbjf";
95 // Timeout while waiting for network connectivity during tests.
96 const int kTestNetworkTimeoutSeconds
= 1;
98 // Email of owner account for test.
99 const char kTestOwnerEmail
[] = "owner@example.com";
101 const char kTestEnterpriseAccountId
[] = "enterprise-kiosk-app@localhost";
102 const char kTestEnterpriseServiceAccountId
[] = "service_account@example.com";
103 const char kTestRefreshToken
[] = "fake-refresh-token";
104 const char kTestUserinfoToken
[] = "fake-userinfo-token";
105 const char kTestLoginToken
[] = "fake-login-token";
106 const char kTestAccessToken
[] = "fake-access-token";
107 const char kTestClientId
[] = "fake-client-id";
108 const char kTestAppScope
[] =
109 "https://www.googleapis.com/auth/userinfo.profile";
112 const char kLaunchAppForTestNewAPI
[] =
113 "login.AccountPickerScreen.runAppForTesting";
114 const char kLaunchAppForTestOldAPI
[] =
115 "login.AppsMenuButton.runAppForTesting";
116 const char kCheckDiagnosticModeNewAPI
[] =
117 "$('oobe').confirmDiagnosticMode_";
118 const char kCheckDiagnosticModeOldAPI
[] =
119 "$('show-apps-button').confirmDiagnosticMode_";
121 // Helper function for GetConsumerKioskAutoLaunchStatusCallback.
122 void ConsumerKioskAutoLaunchStatusCheck(
123 KioskAppManager::ConsumerKioskAutoLaunchStatus
* out_status
,
124 const base::Closure
& runner_quit_task
,
125 KioskAppManager::ConsumerKioskAutoLaunchStatus in_status
) {
126 LOG(INFO
) << "KioskAppManager::ConsumerKioskModeStatus = " << in_status
;
127 *out_status
= in_status
;
128 runner_quit_task
.Run();
131 // Helper KioskAppManager::EnableKioskModeCallback implementation.
132 void ConsumerKioskModeAutoStartLockCheck(
134 const base::Closure
& runner_quit_task
,
136 LOG(INFO
) << "kiosk locked = " << in_locked
;
137 *out_locked
= in_locked
;
138 runner_quit_task
.Run();
141 // Helper function for WaitForNetworkTimeOut.
142 void OnNetworkWaitTimedOut(const base::Closure
& runner_quit_task
) {
143 runner_quit_task
.Run();
146 // Helper functions for CanConfigureNetwork mock.
147 class ScopedCanConfigureNetwork
{
149 ScopedCanConfigureNetwork(bool can_configure
, bool needs_owner_auth
)
150 : can_configure_(can_configure
),
151 needs_owner_auth_(needs_owner_auth
),
152 can_configure_network_callback_(
153 base::Bind(&ScopedCanConfigureNetwork::CanConfigureNetwork
,
154 base::Unretained(this))),
155 needs_owner_auth_callback_(base::Bind(
156 &ScopedCanConfigureNetwork::NeedsOwnerAuthToConfigureNetwork
,
157 base::Unretained(this))) {
158 AppLaunchController::SetCanConfigureNetworkCallbackForTesting(
159 &can_configure_network_callback_
);
160 AppLaunchController::SetNeedOwnerAuthToConfigureNetworkCallbackForTesting(
161 &needs_owner_auth_callback_
);
163 ~ScopedCanConfigureNetwork() {
164 AppLaunchController::SetCanConfigureNetworkCallbackForTesting(NULL
);
165 AppLaunchController::SetNeedOwnerAuthToConfigureNetworkCallbackForTesting(
169 bool CanConfigureNetwork() {
170 return can_configure_
;
173 bool NeedsOwnerAuthToConfigureNetwork() {
174 return needs_owner_auth_
;
179 bool needs_owner_auth_
;
180 AppLaunchController::ReturnBoolCallback can_configure_network_callback_
;
181 AppLaunchController::ReturnBoolCallback needs_owner_auth_callback_
;
182 DISALLOW_COPY_AND_ASSIGN(ScopedCanConfigureNetwork
);
185 // Helper class to wait until a js condition becomes true.
186 class JsConditionWaiter
{
188 JsConditionWaiter(content::WebContents
* web_contents
,
189 const std::string
& js
)
190 : web_contents_(web_contents
),
198 base::RepeatingTimer
<JsConditionWaiter
> check_timer
;
201 base::TimeDelta::FromMilliseconds(10),
203 &JsConditionWaiter::OnTimer
);
205 runner_
= new content::MessageLoopRunner
;
212 CHECK(content::ExecuteScriptAndExtractBool(
214 "window.domAutomationController.send(!!(" + js_
+ "));",
225 content::WebContents
* web_contents_
;
226 const std::string js_
;
227 scoped_refptr
<content::MessageLoopRunner
> runner_
;
229 DISALLOW_COPY_AND_ASSIGN(JsConditionWaiter
);
234 class KioskTest
: public OobeBaseTest
{
237 set_exit_when_last_browser_closes(false);
240 virtual ~KioskTest() {}
243 virtual void SetUp() OVERRIDE
{
244 test_app_id_
= kTestKioskApp
;
245 mock_user_manager_
.reset(new MockUserManager
);
246 AppLaunchController::SkipSplashWaitForTesting();
247 AppLaunchController::SetNetworkWaitForTesting(kTestNetworkTimeoutSeconds
);
249 OobeBaseTest::SetUp();
252 virtual void CleanUpOnMainThread() OVERRIDE
{
253 AppLaunchController::SetNetworkTimeoutCallbackForTesting(NULL
);
254 AppLaunchSigninScreen::SetUserManagerForTesting(NULL
);
256 OobeBaseTest::CleanUpOnMainThread();
258 // Clean up while main thread still runs.
259 // See http://crbug.com/176659.
260 KioskAppManager::Get()->CleanUp();
263 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
264 OobeBaseTest::SetUpCommandLine(command_line
);
266 // Create gaia and webstore URL from test server url but using different
267 // host names. This is to avoid gaia response being tagged as from
268 // webstore in chrome_resource_dispatcher_host_delegate.cc.
269 GURL webstore_url
= GetTestWebstoreUrl();
270 command_line
->AppendSwitchASCII(
271 ::switches::kAppsGalleryURL
,
272 webstore_url
.Resolve("/chromeos/app_mode/webstore").spec());
273 command_line
->AppendSwitchASCII(
274 ::switches::kAppsGalleryDownloadURL
,
275 webstore_url
.Resolve(
276 "/chromeos/app_mode/webstore/downloads/%s.crx").spec());
279 GURL
GetTestWebstoreUrl() {
280 const GURL
& server_url
= embedded_test_server()->base_url();
281 std::string
webstore_host("webstore");
282 GURL::Replacements replace_webstore_host
;
283 replace_webstore_host
.SetHostStr(webstore_host
);
284 return server_url
.ReplaceComponents(replace_webstore_host
);
287 void LaunchApp(const std::string
& app_id
, bool diagnostic_mode
) {
288 bool new_kiosk_ui
= KioskAppMenuHandler::EnableNewKioskUI();
289 GetLoginUI()->CallJavascriptFunction(new_kiosk_ui
?
290 kLaunchAppForTestNewAPI
: kLaunchAppForTestOldAPI
,
291 base::StringValue(app_id
),
292 base::FundamentalValue(diagnostic_mode
));
295 void ReloadKioskApps() {
296 // Remove then add to ensure NOTIFICATION_KIOSK_APPS_LOADED fires.
297 KioskAppManager::Get()->RemoveApp(test_app_id_
);
298 KioskAppManager::Get()->AddApp(test_app_id_
);
301 void ReloadAutolaunchKioskApps() {
302 KioskAppManager::Get()->AddApp(test_app_id_
);
303 KioskAppManager::Get()->SetAutoLaunchApp(test_app_id_
);
306 void PrepareAppLaunch() {
307 EnableConsumerKioskMode();
310 content::WindowedNotificationObserver
login_signal(
311 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE
,
312 content::NotificationService::AllSources());
313 chromeos::WizardController::SkipPostLoginScreensForTesting();
314 chromeos::WizardController
* wizard_controller
=
315 chromeos::WizardController::default_controller();
316 if (wizard_controller
) {
317 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
320 // No wizard and running with an existing profile and it should land
321 // on account picker when new kiosk UI is enabled. Otherwise, just
322 // wait for the login signal from Gaia.
323 if (KioskAppMenuHandler::EnableNewKioskUI())
324 OobeScreenWaiter(OobeDisplay::SCREEN_ACCOUNT_PICKER
).Wait();
329 // Wait for the Kiosk App configuration to reload.
330 content::WindowedNotificationObserver
apps_loaded_signal(
331 chrome::NOTIFICATION_KIOSK_APPS_LOADED
,
332 content::NotificationService::AllSources());
334 apps_loaded_signal
.Wait();
337 void StartAppLaunchFromLoginScreen(const base::Closure
& network_setup_cb
) {
340 if (!network_setup_cb
.is_null())
341 network_setup_cb
.Run();
343 LaunchApp(test_app_id(), false);
346 const extensions::Extension
* GetInstalledApp() {
347 Profile
* app_profile
= ProfileManager::GetPrimaryUserProfile();
348 return extensions::ExtensionSystem::Get(app_profile
)->
349 extension_service()->GetInstalledExtension(test_app_id_
);
352 const Version
& GetInstalledAppVersion() {
353 return *GetInstalledApp()->version();
356 void WaitForAppLaunchSuccess() {
357 ExtensionTestMessageListener
358 launch_data_check_listener("launchData.isKioskSession = true", false);
360 // Wait for the Kiosk App to launch.
361 content::WindowedNotificationObserver(
362 chrome::NOTIFICATION_KIOSK_APP_LAUNCHED
,
363 content::NotificationService::AllSources()).Wait();
365 // Default profile switches to app profile after app is launched.
366 Profile
* app_profile
= ProfileManager::GetPrimaryUserProfile();
367 ASSERT_TRUE(app_profile
);
369 // Check installer status.
370 EXPECT_EQ(chromeos::KioskAppLaunchError::NONE
,
371 chromeos::KioskAppLaunchError::Get());
373 // Check if the kiosk webapp is really installed for the default profile.
374 const extensions::Extension
* app
=
375 extensions::ExtensionSystem::Get(app_profile
)->
376 extension_service()->GetInstalledExtension(test_app_id_
);
379 // App should appear with its window.
380 apps::AppWindowRegistry
* app_window_registry
=
381 apps::AppWindowRegistry::Get(app_profile
);
382 apps::AppWindow
* window
=
383 AppWindowWaiter(app_window_registry
, test_app_id_
).Wait();
386 // Login screen should be gone or fading out.
387 chromeos::LoginDisplayHost
* login_display_host
=
388 chromeos::LoginDisplayHostImpl::default_host();
390 login_display_host
== NULL
||
391 login_display_host
->GetNativeWindow()->layer()->GetTargetOpacity() ==
394 // Wait until the app terminates if it is still running.
395 if (!app_window_registry
->GetAppWindowsForApp(test_app_id_
).empty())
396 content::RunMessageLoop();
398 // Check that the app had been informed that it is running in a kiosk
400 EXPECT_TRUE(launch_data_check_listener
.was_satisfied());
403 void WaitForAppLaunchNetworkTimeout() {
404 if (GetAppLaunchController()->network_wait_timedout())
407 scoped_refptr
<content::MessageLoopRunner
> runner
=
408 new content::MessageLoopRunner
;
410 base::Closure callback
= base::Bind(
411 &OnNetworkWaitTimedOut
, runner
->QuitClosure());
412 AppLaunchController::SetNetworkTimeoutCallbackForTesting(&callback
);
416 CHECK(GetAppLaunchController()->network_wait_timedout());
417 AppLaunchController::SetNetworkTimeoutCallbackForTesting(NULL
);
420 void EnableConsumerKioskMode() {
421 scoped_ptr
<bool> locked(new bool(false));
422 scoped_refptr
<content::MessageLoopRunner
> runner
=
423 new content::MessageLoopRunner
;
424 KioskAppManager::Get()->EnableConsumerKioskAutoLaunch(
425 base::Bind(&ConsumerKioskModeAutoStartLockCheck
,
427 runner
->QuitClosure()));
429 EXPECT_TRUE(*locked
.get());
432 KioskAppManager::ConsumerKioskAutoLaunchStatus
433 GetConsumerKioskModeStatus() {
434 KioskAppManager::ConsumerKioskAutoLaunchStatus status
=
435 static_cast<KioskAppManager::ConsumerKioskAutoLaunchStatus
>(-1);
436 scoped_refptr
<content::MessageLoopRunner
> runner
=
437 new content::MessageLoopRunner
;
438 KioskAppManager::Get()->GetConsumerKioskAutoLaunchStatus(
439 base::Bind(&ConsumerKioskAutoLaunchStatusCheck
,
441 runner
->QuitClosure()));
444 static_cast<KioskAppManager::ConsumerKioskAutoLaunchStatus
>(-1));
448 // Copies the app profile from |relative_app_profile_dir| from test directory
449 // to the app profile directory (assuming "user") under testing profile. This
450 // is for that needs to have a kiosk app already installed from a previous
451 // run. Note this must be called before app profile is loaded.
452 void SetupAppProfile(const std::string
& relative_app_profile_dir
) {
453 base::FilePath app_profile_dir
;
454 if (CommandLine::ForCurrentProcess()->HasSwitch(
455 ::switches::kMultiProfiles
)) {
456 KioskAppManager::App app_data
;
457 CHECK(KioskAppManager::Get()->GetApp(test_app_id(), &app_data
));
458 std::string app_user_id_hash
=
459 CryptohomeClient::GetStubSanitizedUsername(app_data
.user_id
);
461 ProfileHelper::GetProfilePathByUserIdHash(app_user_id_hash
);
463 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA
, &app_profile_dir
));
464 app_profile_dir
= app_profile_dir
.Append(
465 ProfileHelper::GetProfileDirByLegacyLoginProfileSwitch());
467 ASSERT_TRUE(base::CreateDirectory(app_profile_dir
));
469 base::FilePath test_data_dir
;
470 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA
, &test_data_dir
));
471 test_data_dir
= test_data_dir
.AppendASCII(relative_app_profile_dir
);
473 base::CopyFile(test_data_dir
.Append(chrome::kPreferencesFilename
),
474 app_profile_dir
.Append(chrome::kPreferencesFilename
)));
476 base::CopyDirectory(test_data_dir
.AppendASCII("Extensions"),
481 void RunAppLaunchNetworkDownTest() {
482 // Mock network could be configured with owner's password.
483 ScopedCanConfigureNetwork
can_configure_network(true, true);
485 // Start app launch and wait for network connectivity timeout.
486 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure());
487 OobeScreenWaiter
splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH
);
488 splash_waiter
.Wait();
489 WaitForAppLaunchNetworkTimeout();
491 // Configure network link should be visible.
492 JsExpect("$('splash-config-network').hidden == false");
494 // Set up fake user manager with an owner for the test.
495 mock_user_manager()->SetActiveUser(kTestOwnerEmail
);
496 AppLaunchSigninScreen::SetUserManagerForTesting(mock_user_manager());
497 static_cast<LoginDisplayHostImpl
*>(LoginDisplayHostImpl::default_host())
498 ->GetOobeUI()->ShowOobeUI(false);
500 // Configure network should bring up lock screen for owner.
501 OobeScreenWaiter
lock_screen_waiter(OobeDisplay::SCREEN_ACCOUNT_PICKER
);
502 static_cast<AppLaunchSplashScreenActor::Delegate
*>(GetAppLaunchController())
503 ->OnConfigureNetwork();
504 lock_screen_waiter
.Wait();
506 // There should be only one owner pod on this screen.
507 JsExpect("$('pod-row').isSinglePod");
509 // A network error screen should be shown after authenticating.
510 OobeScreenWaiter
error_screen_waiter(OobeDisplay::SCREEN_ERROR_MESSAGE
);
511 static_cast<AppLaunchSigninScreen::Delegate
*>(GetAppLaunchController())
512 ->OnOwnerSigninSuccess();
513 error_screen_waiter
.Wait();
515 ASSERT_TRUE(GetAppLaunchController()->showing_network_dialog());
517 SimulateNetworkOnline();
518 WaitForAppLaunchSuccess();
521 AppLaunchController
* GetAppLaunchController() {
522 return chromeos::LoginDisplayHostImpl::default_host()
523 ->GetAppLaunchController();
526 MockUserManager
* mock_user_manager() { return mock_user_manager_
.get(); }
528 void set_test_app_id(const std::string
& test_app_id
) {
529 test_app_id_
= test_app_id
;
531 const std::string
& test_app_id() const { return test_app_id_
; }
534 std::string test_app_id_
;
535 scoped_ptr
<MockUserManager
> mock_user_manager_
;
537 DISALLOW_COPY_AND_ASSIGN(KioskTest
);
540 IN_PROC_BROWSER_TEST_F(KioskTest
, InstallAndLaunchApp
) {
541 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
542 WaitForAppLaunchSuccess();
545 IN_PROC_BROWSER_TEST_F(KioskTest
, NotSignedInWithGAIAAccount
) {
546 // Tests that the kiosk session is not considered to be logged in with a GAIA
548 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
549 WaitForAppLaunchSuccess();
551 Profile
* app_profile
= ProfileManager::GetPrimaryUserProfile();
552 ASSERT_TRUE(app_profile
);
553 EXPECT_FALSE(app_profile
->GetPrefs()->HasPrefPath(
554 prefs::kGoogleServicesUsername
));
557 IN_PROC_BROWSER_TEST_F(KioskTest
, PRE_LaunchAppNetworkDown
) {
558 // Tests the network down case for the initial app download and launch.
559 RunAppLaunchNetworkDownTest();
562 IN_PROC_BROWSER_TEST_F(KioskTest
, LaunchAppNetworkDown
) {
563 // Tests the network down case for launching an existing app that is
564 // installed in PRE_LaunchAppNetworkDown.
565 RunAppLaunchNetworkDownTest();
568 // TODO(zelidrag): Figure out why this test is flaky on bbots.
569 IN_PROC_BROWSER_TEST_F(KioskTest
,
570 DISABLED_LaunchAppWithNetworkConfigAccelerator
) {
571 ScopedCanConfigureNetwork
can_configure_network(true, false);
573 // Start app launch and wait for network connectivity timeout.
574 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
575 OobeScreenWaiter
splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH
);
576 splash_waiter
.Wait();
578 // A network error screen should be shown after authenticating.
579 OobeScreenWaiter
error_screen_waiter(OobeDisplay::SCREEN_ERROR_MESSAGE
);
580 // Simulate Ctrl+Alt+N accelerator.
581 GetLoginUI()->CallJavascriptFunction(
582 "cr.ui.Oobe.handleAccelerator",
583 base::StringValue("app_launch_network_config"));
584 error_screen_waiter
.Wait();
585 ASSERT_TRUE(GetAppLaunchController()->showing_network_dialog());
587 // Continue button should be visible since we are online.
588 JsExpect("$('continue-network-config-btn').hidden == false");
590 // Click on [Continue] button.
591 ASSERT_TRUE(content::ExecuteScript(
592 GetLoginUI()->GetWebContents(),
594 "var e = new Event('click');"
595 "$('continue-network-config-btn').dispatchEvent(e);"
598 WaitForAppLaunchSuccess();
601 IN_PROC_BROWSER_TEST_F(KioskTest
, LaunchAppNetworkDownConfigureNotAllowed
) {
602 // Mock network could not be configured.
603 ScopedCanConfigureNetwork
can_configure_network(false, true);
605 // Start app launch and wait for network connectivity timeout.
606 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure());
607 OobeScreenWaiter
splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH
);
608 splash_waiter
.Wait();
609 WaitForAppLaunchNetworkTimeout();
611 // Configure network link should not be visible.
612 JsExpect("$('splash-config-network').hidden == true");
614 // Network becomes online and app launch is resumed.
615 SimulateNetworkOnline();
616 WaitForAppLaunchSuccess();
619 // Flaky on bots. http://crbug.com/365507
620 IN_PROC_BROWSER_TEST_F(KioskTest
, DISABLED_LaunchAppNetworkPortal
) {
621 // Mock network could be configured without the owner password.
622 ScopedCanConfigureNetwork
can_configure_network(true, false);
624 // Start app launch with network portal state.
625 StartAppLaunchFromLoginScreen(SimulateNetworkPortalClosure());
626 OobeScreenWaiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH
)
627 .WaitNoAssertCurrentScreen();
628 WaitForAppLaunchNetworkTimeout();
630 // Network error should show up automatically since this test does not
631 // require owner auth to configure network.
632 OobeScreenWaiter(OobeDisplay::SCREEN_ERROR_MESSAGE
).Wait();
634 ASSERT_TRUE(GetAppLaunchController()->showing_network_dialog());
635 SimulateNetworkOnline();
636 WaitForAppLaunchSuccess();
639 IN_PROC_BROWSER_TEST_F(KioskTest
, LaunchAppUserCancel
) {
640 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure());
641 OobeScreenWaiter
splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH
);
642 splash_waiter
.Wait();
644 CrosSettings::Get()->SetBoolean(
645 kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled
, true);
646 content::WindowedNotificationObserver
signal(
647 chrome::NOTIFICATION_APP_TERMINATING
,
648 content::NotificationService::AllSources());
649 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
650 base::StringValue("app_launch_bailout"));
652 EXPECT_EQ(chromeos::KioskAppLaunchError::USER_CANCEL
,
653 chromeos::KioskAppLaunchError::Get());
656 IN_PROC_BROWSER_TEST_F(KioskTest
, LaunchInDiagnosticMode
) {
658 SimulateNetworkOnline();
660 LaunchApp(kTestKioskApp
, true);
662 content::WebContents
* login_contents
= GetLoginUI()->GetWebContents();
664 bool new_kiosk_ui
= KioskAppMenuHandler::EnableNewKioskUI();
665 JsConditionWaiter(login_contents
, new_kiosk_ui
?
666 kCheckDiagnosticModeNewAPI
: kCheckDiagnosticModeOldAPI
).Wait();
668 std::string
diagnosticMode(new_kiosk_ui
?
669 kCheckDiagnosticModeNewAPI
: kCheckDiagnosticModeOldAPI
);
670 ASSERT_TRUE(content::ExecuteScript(
673 "var e = new Event('click');" +
675 "okButton_.dispatchEvent(e);"
678 WaitForAppLaunchSuccess();
681 IN_PROC_BROWSER_TEST_F(KioskTest
, AutolaunchWarningCancel
) {
682 EnableConsumerKioskMode();
683 // Start UI, find menu entry for this app and launch it.
684 chromeos::WizardController::SkipPostLoginScreensForTesting();
685 chromeos::WizardController
* wizard_controller
=
686 chromeos::WizardController::default_controller();
687 CHECK(wizard_controller
);
688 ReloadAutolaunchKioskApps();
689 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
691 EXPECT_FALSE(KioskAppManager::Get()->GetAutoLaunchApp().empty());
692 EXPECT_FALSE(KioskAppManager::Get()->IsAutoLaunchEnabled());
694 // Wait for the auto launch warning come up.
695 content::WindowedNotificationObserver(
696 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE
,
697 content::NotificationService::AllSources()).Wait();
698 GetLoginUI()->CallJavascriptFunction(
699 "login.AutolaunchScreen.confirmAutoLaunchForTesting",
700 base::FundamentalValue(false));
702 // Wait for the auto launch warning to go away.
703 content::WindowedNotificationObserver(
704 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_COMPLETED
,
705 content::NotificationService::AllSources()).Wait();
707 EXPECT_FALSE(KioskAppManager::Get()->IsAutoLaunchEnabled());
710 IN_PROC_BROWSER_TEST_F(KioskTest
, AutolaunchWarningConfirm
) {
711 EnableConsumerKioskMode();
712 // Start UI, find menu entry for this app and launch it.
713 chromeos::WizardController::SkipPostLoginScreensForTesting();
714 chromeos::WizardController
* wizard_controller
=
715 chromeos::WizardController::default_controller();
716 CHECK(wizard_controller
);
717 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
719 ReloadAutolaunchKioskApps();
720 EXPECT_FALSE(KioskAppManager::Get()->GetAutoLaunchApp().empty());
721 EXPECT_FALSE(KioskAppManager::Get()->IsAutoLaunchEnabled());
723 // Wait for the auto launch warning come up.
724 content::WindowedNotificationObserver(
725 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE
,
726 content::NotificationService::AllSources()).Wait();
727 GetLoginUI()->CallJavascriptFunction(
728 "login.AutolaunchScreen.confirmAutoLaunchForTesting",
729 base::FundamentalValue(true));
731 // Wait for the auto launch warning to go away.
732 content::WindowedNotificationObserver(
733 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_COMPLETED
,
734 content::NotificationService::AllSources()).Wait();
736 EXPECT_FALSE(KioskAppManager::Get()->GetAutoLaunchApp().empty());
737 EXPECT_TRUE(KioskAppManager::Get()->IsAutoLaunchEnabled());
739 WaitForAppLaunchSuccess();
742 IN_PROC_BROWSER_TEST_F(KioskTest
, KioskEnableCancel
) {
743 chromeos::WizardController::SkipPostLoginScreensForTesting();
744 chromeos::WizardController
* wizard_controller
=
745 chromeos::WizardController::default_controller();
746 CHECK(wizard_controller
);
748 // Check Kiosk mode status.
749 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE
,
750 GetConsumerKioskModeStatus());
752 // Wait for the login UI to come up and switch to the kiosk_enable screen.
753 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
754 content::WindowedNotificationObserver(
755 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE
,
756 content::NotificationService::AllSources()).Wait();
757 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
758 base::StringValue("kiosk_enable"));
760 // Wait for the kiosk_enable screen to show and cancel the screen.
761 content::WindowedNotificationObserver(
762 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE
,
763 content::NotificationService::AllSources()).Wait();
764 GetLoginUI()->CallJavascriptFunction(
765 "login.KioskEnableScreen.enableKioskForTesting",
766 base::FundamentalValue(false));
768 // Wait for the kiosk_enable screen to disappear.
769 content::WindowedNotificationObserver(
770 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_COMPLETED
,
771 content::NotificationService::AllSources()).Wait();
773 // Check that the status still says configurable.
774 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE
,
775 GetConsumerKioskModeStatus());
778 IN_PROC_BROWSER_TEST_F(KioskTest
, KioskEnableConfirmed
) {
779 // Start UI, find menu entry for this app and launch it.
780 chromeos::WizardController::SkipPostLoginScreensForTesting();
781 chromeos::WizardController
* wizard_controller
=
782 chromeos::WizardController::default_controller();
783 CHECK(wizard_controller
);
785 // Check Kiosk mode status.
786 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE
,
787 GetConsumerKioskModeStatus());
788 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
790 // Wait for the login UI to come up and switch to the kiosk_enable screen.
791 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
792 content::WindowedNotificationObserver(
793 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE
,
794 content::NotificationService::AllSources()).Wait();
795 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
796 base::StringValue("kiosk_enable"));
798 // Wait for the kiosk_enable screen to show and cancel the screen.
799 content::WindowedNotificationObserver(
800 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE
,
801 content::NotificationService::AllSources()).Wait();
802 GetLoginUI()->CallJavascriptFunction(
803 "login.KioskEnableScreen.enableKioskForTesting",
804 base::FundamentalValue(true));
806 // Wait for the signal that indicates Kiosk Mode is enabled.
807 content::WindowedNotificationObserver(
808 chrome::NOTIFICATION_KIOSK_ENABLED
,
809 content::NotificationService::AllSources()).Wait();
810 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_ENABLED
,
811 GetConsumerKioskModeStatus());
814 IN_PROC_BROWSER_TEST_F(KioskTest
, KioskEnableAbortedWithAutoEnrollment
) {
815 // Fake an auto enrollment is going to be enforced.
816 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
817 switches::kEnterpriseEnrollmentInitialModulus
, "1");
818 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
819 switches::kEnterpriseEnrollmentModulusLimit
, "2");
820 g_browser_process
->local_state()->SetBoolean(prefs::kShouldAutoEnroll
, true);
821 g_browser_process
->local_state()->SetInteger(
822 prefs::kAutoEnrollmentPowerLimit
, 3);
824 // Start UI, find menu entry for this app and launch it.
825 chromeos::WizardController::SkipPostLoginScreensForTesting();
826 chromeos::WizardController
* wizard_controller
=
827 chromeos::WizardController::default_controller();
828 CHECK(wizard_controller
);
830 // Check Kiosk mode status.
831 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE
,
832 GetConsumerKioskModeStatus());
833 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
835 // Wait for the login UI to come up and switch to the kiosk_enable screen.
836 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
837 content::WindowedNotificationObserver(
838 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE
,
839 content::NotificationService::AllSources()).Wait();
840 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
841 base::StringValue("kiosk_enable"));
843 // The flow should be aborted due to auto enrollment enforcement.
844 scoped_refptr
<content::MessageLoopRunner
> runner
=
845 new content::MessageLoopRunner
;
846 GetSigninScreenHandler()->set_kiosk_enable_flow_aborted_callback_for_test(
847 runner
->QuitClosure());
851 IN_PROC_BROWSER_TEST_F(KioskTest
, KioskEnableAfter2ndSigninScreen
) {
852 chromeos::WizardController::SkipPostLoginScreensForTesting();
853 chromeos::WizardController
* wizard_controller
=
854 chromeos::WizardController::default_controller();
855 CHECK(wizard_controller
);
857 // Check Kiosk mode status.
858 EXPECT_EQ(KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE
,
859 GetConsumerKioskModeStatus());
861 // Wait for the login UI to come up and switch to the kiosk_enable screen.
862 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
863 content::WindowedNotificationObserver(
864 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE
,
865 content::NotificationService::AllSources()).Wait();
866 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
867 base::StringValue("kiosk_enable"));
869 // Wait for the kiosk_enable screen to show and cancel the screen.
870 content::WindowedNotificationObserver(
871 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE
,
872 content::NotificationService::AllSources()).Wait();
873 GetLoginUI()->CallJavascriptFunction(
874 "login.KioskEnableScreen.enableKioskForTesting",
875 base::FundamentalValue(false));
877 // Wait for the kiosk_enable screen to disappear.
878 content::WindowedNotificationObserver(
879 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_COMPLETED
,
880 content::NotificationService::AllSources()).Wait();
882 // Show signin screen again.
883 chromeos::LoginDisplayHostImpl::default_host()->StartSignInScreen(
884 LoginScreenContext());
885 OobeScreenWaiter(OobeDisplay::SCREEN_GAIA_SIGNIN
).Wait();
887 // Show kiosk enable screen again.
888 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
889 base::StringValue("kiosk_enable"));
891 // And it should show up.
892 content::WindowedNotificationObserver(
893 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE
,
894 content::NotificationService::AllSources()).Wait();
897 class KioskUpdateTest
: public KioskTest
,
898 public testing::WithParamInterface
<bool> {
901 virtual ~KioskUpdateTest() {}
904 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
905 // Needs background networking so that ExtensionDownloader works.
906 needs_background_networking_
= true;
908 KioskTest::SetUpCommandLine(command_line
);
910 command_line
->AppendSwitch(::switches::kMultiProfiles
);
913 virtual void SetUpOnMainThread() OVERRIDE
{
914 KioskTest::SetUpOnMainThread();
916 GURL webstore_url
= GetTestWebstoreUrl();
917 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
918 ::switches::kAppsGalleryUpdateURL
,
919 webstore_url
.Resolve("/update_check.xml").spec());
921 embedded_test_server()->RegisterRequestHandler(
922 base::Bind(&KioskUpdateTest::HandleRequest
,
923 base::Unretained(this)));
927 SetUpdateCheckContent(
928 "chromeos/app_mode/webstore/update_check/no_update.xml",
935 void SetUpdateCrx(const std::string
& crx_file
, const std::string
& version
) {
936 GURL webstore_url
= GetTestWebstoreUrl();
937 GURL crx_download_url
= webstore_url
.Resolve(
938 "/chromeos/app_mode/webstore/downloads/" + crx_file
);
939 base::FilePath test_data_dir
;
940 PathService::Get(chrome::DIR_TEST_DATA
, &test_data_dir
);
941 base::FilePath crx_file_path
=
942 test_data_dir
.AppendASCII("chromeos/app_mode/webstore/downloads")
943 .AppendASCII(crx_file
);
945 std::string crx_content
;
946 ASSERT_TRUE(base::ReadFileToString(crx_file_path
, &crx_content
));
948 const std::string sha256
= crypto::SHA256HashString(crx_content
);
949 const std::string sha256_hex
=
950 base::HexEncode(sha256
.c_str(), sha256
.size());
952 SetUpdateCheckContent(
953 "chromeos/app_mode/webstore/update_check/has_update.xml",
956 base::UintToString(crx_content
.size()),
961 void SetUpdateCheckContent(const std::string
& update_check_file
,
962 const GURL
& crx_download_url
,
963 const std::string
& crx_fp
,
964 const std::string
& crx_size
,
965 const std::string
& version
) {
966 base::FilePath test_data_dir
;
967 PathService::Get(chrome::DIR_TEST_DATA
, &test_data_dir
);
968 base::FilePath update_file
=
969 test_data_dir
.AppendASCII(update_check_file
.c_str());
970 ASSERT_TRUE(base::ReadFileToString(update_file
, &update_check_content_
));
972 ReplaceSubstringsAfterOffset(
973 &update_check_content_
, 0, "$AppId", test_app_id());
974 ReplaceSubstringsAfterOffset(
975 &update_check_content_
, 0, "$CrxDownloadUrl", crx_download_url
.spec());
976 ReplaceSubstringsAfterOffset(&update_check_content_
, 0, "$FP", crx_fp
);
977 ReplaceSubstringsAfterOffset(&update_check_content_
, 0, "$Size", crx_size
);
978 ReplaceSubstringsAfterOffset(
979 &update_check_content_
, 0, "$Version", version
);
982 scoped_ptr
<HttpResponse
> HandleRequest(const HttpRequest
& request
) {
983 GURL request_url
= GURL("http://localhost").Resolve(request
.relative_url
);
984 std::string request_path
= request_url
.path();
985 if (!update_check_content_
.empty() &&
986 request_path
== "/update_check.xml") {
987 scoped_ptr
<BasicHttpResponse
> http_response(new BasicHttpResponse());
988 http_response
->set_code(net::HTTP_OK
);
989 http_response
->set_content_type("text/xml");
990 http_response
->set_content(update_check_content_
);
991 return http_response
.PassAs
<HttpResponse
>();
994 return scoped_ptr
<HttpResponse
>();
997 std::string update_check_content_
;
999 DISALLOW_COPY_AND_ASSIGN(KioskUpdateTest
);
1002 IN_PROC_BROWSER_TEST_P(KioskUpdateTest
, LaunchOfflineEnabledAppNoNetwork
) {
1003 set_test_app_id(kTestOfflineEnabledKioskApp
);
1006 SimulateNetworkOffline();
1007 SetupAppProfile("chromeos/app_mode/offline_enabled_app_profile");
1009 LaunchApp(test_app_id(), false);
1010 WaitForAppLaunchSuccess();
1013 IN_PROC_BROWSER_TEST_P(KioskUpdateTest
, LaunchOfflineEnabledAppNoUpdate
) {
1014 set_test_app_id(kTestOfflineEnabledKioskApp
);
1019 SimulateNetworkOnline();
1020 SetupAppProfile("chromeos/app_mode/offline_enabled_app_profile");
1022 LaunchApp(test_app_id(), false);
1023 WaitForAppLaunchSuccess();
1025 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString());
1028 IN_PROC_BROWSER_TEST_P(KioskUpdateTest
, LaunchOfflineEnabledAppHasUpdate
) {
1029 set_test_app_id(kTestOfflineEnabledKioskApp
);
1031 SetUpdateCrx("ajoggoflpgplnnjkjamcmbepjdjdnpdp.crx", "2.0.0");
1034 SimulateNetworkOnline();
1035 SetupAppProfile("chromeos/app_mode/offline_enabled_app_profile");
1037 LaunchApp(test_app_id(), false);
1038 WaitForAppLaunchSuccess();
1040 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString());
1043 IN_PROC_BROWSER_TEST_P(KioskUpdateTest
, PermissionChange
) {
1044 set_test_app_id(kTestOfflineEnabledKioskApp
);
1046 SetUpdateCrx("ajoggoflpgplnnjkjamcmbepjdjdnpdp_v2_permission_change.crx",
1050 SimulateNetworkOnline();
1051 SetupAppProfile("chromeos/app_mode/offline_enabled_app_profile");
1053 LaunchApp(test_app_id(), false);
1054 WaitForAppLaunchSuccess();
1056 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString());
1059 IN_PROC_BROWSER_TEST_P(KioskUpdateTest
, PRE_PreserveLocalData
) {
1060 // Installs v1 app and writes some local data.
1061 set_test_app_id(kTestLocalFsKioskApp
);
1063 ResultCatcher catcher
;
1064 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
1065 WaitForAppLaunchSuccess();
1066 ASSERT_TRUE(catcher
.GetNextResult()) << catcher
.message();
1069 IN_PROC_BROWSER_TEST_P(KioskUpdateTest
, PreserveLocalData
) {
1070 // Update existing v1 app installed in PRE_PreserveLocalData to v2
1071 // that reads and verifies the local data.
1072 set_test_app_id(kTestLocalFsKioskApp
);
1074 SetUpdateCrx("bmbpicmpniaclbbpdkfglgipkkebnbjf_v2_read_and_verify_data.crx",
1077 ResultCatcher catcher
;
1078 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
1079 WaitForAppLaunchSuccess();
1081 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString());
1082 ASSERT_TRUE(catcher
.GetNextResult()) << catcher
.message();
1085 // TODO(xiyuan): Remove this after multi profile is turned on by default.
1086 INSTANTIATE_TEST_CASE_P(KioskUpdateTestInstantiation
,
1090 class KioskEnterpriseTest
: public KioskTest
{
1092 KioskEnterpriseTest() {}
1094 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE
{
1095 device_policy_test_helper_
.MarkAsEnterpriseOwned();
1096 device_policy_test_helper_
.InstallOwnerKey();
1098 KioskTest::SetUpInProcessBrowserTestFixture();
1101 virtual void SetUpOnMainThread() OVERRIDE
{
1102 KioskTest::SetUpOnMainThread();
1103 // Configure kTestEnterpriseKioskApp in device policy.
1104 em::DeviceLocalAccountsProto
* accounts
=
1105 device_policy_test_helper_
.device_policy()->payload()
1106 .mutable_device_local_accounts();
1107 em::DeviceLocalAccountInfoProto
* account
= accounts
->add_account();
1108 account
->set_account_id(kTestEnterpriseAccountId
);
1110 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_KIOSK_APP
);
1111 account
->mutable_kiosk_app()->set_app_id(kTestEnterpriseKioskApp
);
1112 accounts
->set_auto_login_id(kTestEnterpriseAccountId
);
1113 em::PolicyData
& policy_data
=
1114 device_policy_test_helper_
.device_policy()->policy_data();
1115 policy_data
.set_service_account_identity(kTestEnterpriseServiceAccountId
);
1116 device_policy_test_helper_
.device_policy()->Build();
1118 base::RunLoop run_loop
;
1119 DBusThreadManager::Get()->GetSessionManagerClient()->StoreDevicePolicy(
1120 device_policy_test_helper_
.device_policy()->GetBlob(),
1121 base::Bind(&KioskEnterpriseTest::StorePolicyCallback
,
1122 run_loop
.QuitClosure()));
1125 DeviceSettingsService::Get()->Load();
1127 // Configure OAuth authentication.
1128 GaiaUrls
* gaia_urls
= GaiaUrls::GetInstance();
1130 // This token satisfies the userinfo.email request from
1131 // DeviceOAuth2TokenService used in token validation.
1132 FakeGaia::AccessTokenInfo userinfo_token_info
;
1133 userinfo_token_info
.token
= kTestUserinfoToken
;
1134 userinfo_token_info
.scopes
.insert(
1135 "https://www.googleapis.com/auth/userinfo.email");
1136 userinfo_token_info
.audience
= gaia_urls
->oauth2_chrome_client_id();
1137 userinfo_token_info
.email
= kTestEnterpriseServiceAccountId
;
1138 fake_gaia_
->IssueOAuthToken(kTestRefreshToken
, userinfo_token_info
);
1140 // The any-api access token for accessing the token minting endpoint.
1141 FakeGaia::AccessTokenInfo login_token_info
;
1142 login_token_info
.token
= kTestLoginToken
;
1143 login_token_info
.scopes
.insert(GaiaConstants::kAnyApiOAuth2Scope
);
1144 login_token_info
.audience
= gaia_urls
->oauth2_chrome_client_id();
1145 fake_gaia_
->IssueOAuthToken(kTestRefreshToken
, login_token_info
);
1147 // This is the access token requested by the app via the identity API.
1148 FakeGaia::AccessTokenInfo access_token_info
;
1149 access_token_info
.token
= kTestAccessToken
;
1150 access_token_info
.scopes
.insert(kTestAppScope
);
1151 access_token_info
.audience
= kTestClientId
;
1152 access_token_info
.email
= kTestEnterpriseServiceAccountId
;
1153 fake_gaia_
->IssueOAuthToken(kTestLoginToken
, access_token_info
);
1155 DeviceOAuth2TokenService
* token_service
=
1156 DeviceOAuth2TokenServiceFactory::Get();
1157 token_service
->SetAndSaveRefreshToken(
1158 kTestRefreshToken
, DeviceOAuth2TokenService::StatusCallback());
1159 base::RunLoop().RunUntilIdle();
1162 static void StorePolicyCallback(const base::Closure
& callback
, bool result
) {
1163 ASSERT_TRUE(result
);
1167 policy::DevicePolicyCrosTestHelper device_policy_test_helper_
;
1170 DISALLOW_COPY_AND_ASSIGN(KioskEnterpriseTest
);
1173 IN_PROC_BROWSER_TEST_F(KioskEnterpriseTest
, EnterpriseKioskApp
) {
1174 chromeos::WizardController::SkipPostLoginScreensForTesting();
1175 chromeos::WizardController
* wizard_controller
=
1176 chromeos::WizardController::default_controller();
1177 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
1179 // Wait for the Kiosk App configuration to reload, then launch the app.
1180 KioskAppManager::App app
;
1181 content::WindowedNotificationObserver(
1182 chrome::NOTIFICATION_KIOSK_APPS_LOADED
,
1183 base::Bind(&KioskAppManager::GetApp
,
1184 base::Unretained(KioskAppManager::Get()),
1185 kTestEnterpriseKioskApp
, &app
)).Wait();
1187 LaunchApp(kTestEnterpriseKioskApp
, false);
1189 // Wait for the Kiosk App to launch.
1190 content::WindowedNotificationObserver(
1191 chrome::NOTIFICATION_KIOSK_APP_LAUNCHED
,
1192 content::NotificationService::AllSources()).Wait();
1194 // Check installer status.
1195 EXPECT_EQ(chromeos::KioskAppLaunchError::NONE
,
1196 chromeos::KioskAppLaunchError::Get());
1198 // Wait for the window to appear.
1199 apps::AppWindow
* window
=
1201 apps::AppWindowRegistry::Get(ProfileManager::GetPrimaryUserProfile()),
1202 kTestEnterpriseKioskApp
).Wait();
1203 ASSERT_TRUE(window
);
1205 // Check whether the app can retrieve an OAuth2 access token.
1207 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
1208 window
->web_contents(),
1209 "chrome.identity.getAuthToken({ 'interactive': false }, function(token) {"
1210 " window.domAutomationController.setAutomationId(0);"
1211 " window.domAutomationController.send(token);"
1214 EXPECT_EQ(kTestAccessToken
, result
);
1216 // Verify that the session is not considered to be logged in with a GAIA
1218 Profile
* app_profile
= ProfileManager::GetPrimaryUserProfile();
1219 ASSERT_TRUE(app_profile
);
1220 EXPECT_FALSE(app_profile
->GetPrefs()->HasPrefPath(
1221 prefs::kGoogleServicesUsername
));
1223 // Terminate the app.
1224 window
->GetBaseWindow()->Close();
1225 content::RunAllPendingInMessageLoop();
1228 // Specialized test fixture for testing kiosk mode on the
1229 // hidden WebUI initialization flow for slow hardware.
1230 class KioskHiddenWebUITest
: public KioskTest
,
1231 public ash::DesktopBackgroundControllerObserver
{
1233 KioskHiddenWebUITest() : wallpaper_loaded_(false) {}
1235 // KioskTest overrides:
1236 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
1237 KioskTest::SetUpCommandLine(command_line
);
1238 command_line
->AppendSwitch(switches::kDisableBootAnimation
);
1241 virtual void SetUpOnMainThread() OVERRIDE
{
1242 KioskTest::SetUpOnMainThread();
1243 ash::Shell::GetInstance()->desktop_background_controller()
1244 ->AddObserver(this);
1245 StartupUtils::MarkDeviceRegistered();
1248 virtual void TearDownOnMainThread() OVERRIDE
{
1249 ash::Shell::GetInstance()->desktop_background_controller()
1250 ->RemoveObserver(this);
1251 KioskTest::TearDownOnMainThread();
1254 void WaitForWallpaper() {
1255 if (!wallpaper_loaded_
) {
1256 runner_
= new content::MessageLoopRunner
;
1261 bool wallpaper_loaded() const { return wallpaper_loaded_
; }
1263 // ash::DesktopBackgroundControllerObserver overrides:
1264 virtual void OnWallpaperDataChanged() OVERRIDE
{
1265 wallpaper_loaded_
= true;
1270 bool wallpaper_loaded_
;
1271 scoped_refptr
<content::MessageLoopRunner
> runner_
;
1273 DISALLOW_COPY_AND_ASSIGN(KioskHiddenWebUITest
);
1276 IN_PROC_BROWSER_TEST_F(KioskHiddenWebUITest
, AutolaunchWarning
) {
1277 // Add a device owner.
1278 FakeUserManager
* user_manager
= new FakeUserManager();
1279 user_manager
->AddUser(kTestOwnerEmail
);
1280 ScopedUserManagerEnabler
enabler(user_manager
);
1282 // Set kiosk app to autolaunch.
1283 EnableConsumerKioskMode();
1284 chromeos::WizardController::SkipPostLoginScreensForTesting();
1285 chromeos::WizardController
* wizard_controller
=
1286 chromeos::WizardController::default_controller();
1287 CHECK(wizard_controller
);
1288 ReloadAutolaunchKioskApps();
1289 wizard_controller
->SkipToLoginForTesting(LoginScreenContext());
1291 EXPECT_FALSE(KioskAppManager::Get()->GetAutoLaunchApp().empty());
1292 EXPECT_FALSE(KioskAppManager::Get()->IsAutoLaunchEnabled());
1294 // Wait for the auto launch warning come up.
1295 content::WindowedNotificationObserver(
1296 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE
,
1297 content::NotificationService::AllSources()).Wait();
1299 // Wait for the wallpaper to load.
1301 EXPECT_TRUE(wallpaper_loaded());
1304 } // namespace chromeos