OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/desktop_background/desktop_background_controller.h" | 5 #include "ash/desktop_background/desktop_background_controller.h" |
6 #include "ash/desktop_background/desktop_background_controller_observer.h" | 6 #include "ash/desktop_background/desktop_background_controller_observer.h" |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
14 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 16 #include "base/run_loop.h" |
| 17 #include "base/single_thread_task_runner.h" |
15 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
17 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
| 21 #include "base/thread_task_runner_handle.h" |
18 #include "chrome/browser/chrome_notification_types.h" | 22 #include "chrome/browser/chrome_notification_types.h" |
19 #include "chrome/browser/chromeos/app_mode/fake_cws.h" | 23 #include "chrome/browser/chromeos/app_mode/fake_cws.h" |
20 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" | 24 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" |
21 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" | 25 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
22 #include "chrome/browser/chromeos/file_manager/fake_disk_mount_manager.h" | 26 #include "chrome/browser/chromeos/file_manager/fake_disk_mount_manager.h" |
23 #include "chrome/browser/chromeos/login/app_launch_controller.h" | 27 #include "chrome/browser/chromeos/login/app_launch_controller.h" |
24 #include "chrome/browser/chromeos/login/startup_utils.h" | 28 #include "chrome/browser/chromeos/login/startup_utils.h" |
25 #include "chrome/browser/chromeos/login/test/app_window_waiter.h" | 29 #include "chrome/browser/chromeos/login/test/app_window_waiter.h" |
26 #include "chrome/browser/chromeos/login/test/oobe_base_test.h" | 30 #include "chrome/browser/chromeos/login/test/oobe_base_test.h" |
27 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.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" |
28 #include "chrome/browser/chromeos/login/users/fake_user_manager.h" | 34 #include "chrome/browser/chromeos/login/users/fake_user_manager.h" |
29 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | 35 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
30 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 36 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
31 #include "chrome/browser/chromeos/login/wizard_controller.h" | 37 #include "chrome/browser/chromeos/login/wizard_controller.h" |
32 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" | 38 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" |
33 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 39 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
34 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 40 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 41 #include "chrome/browser/chromeos/settings/cros_settings.h" |
35 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" | 42 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" |
36 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h
" | 43 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h
" |
37 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 44 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
38 #include "chrome/browser/extensions/extension_service.h" | 45 #include "chrome/browser/extensions/extension_service.h" |
39 #include "chrome/browser/profiles/profile_impl.h" | 46 #include "chrome/browser/profiles/profile_impl.h" |
40 #include "chrome/browser/profiles/profile_manager.h" | 47 #include "chrome/browser/profiles/profile_manager.h" |
41 #include "chrome/browser/profiles/profiles_state.h" | 48 #include "chrome/browser/profiles/profiles_state.h" |
42 #include "chrome/browser/signin/signin_manager_factory.h" | 49 #include "chrome/browser/signin/signin_manager_factory.h" |
43 #include "chrome/browser/ui/webui/chromeos/login/kiosk_app_menu_handler.h" | 50 #include "chrome/browser/ui/webui/chromeos/login/kiosk_app_menu_handler.h" |
44 #include "chrome/common/chrome_constants.h" | 51 #include "chrome/common/chrome_constants.h" |
45 #include "chrome/common/chrome_paths.h" | 52 #include "chrome/common/chrome_paths.h" |
46 #include "chrome/common/pref_names.h" | 53 #include "chrome/common/pref_names.h" |
47 #include "chromeos/chromeos_switches.h" | 54 #include "chromeos/chromeos_switches.h" |
48 #include "chromeos/dbus/cryptohome_client.h" | 55 #include "chromeos/dbus/cryptohome_client.h" |
49 #include "chromeos/disks/disk_mount_manager.h" | 56 #include "chromeos/disks/disk_mount_manager.h" |
| 57 #include "chromeos/settings/cros_settings_provider.h" |
50 #include "components/signin/core/browser/signin_manager.h" | 58 #include "components/signin/core/browser/signin_manager.h" |
51 #include "components/signin/core/common/signin_pref_names.h" | 59 #include "components/signin/core/common/signin_pref_names.h" |
52 #include "content/public/browser/browser_thread.h" | 60 #include "content/public/browser/browser_thread.h" |
53 #include "content/public/browser/notification_observer.h" | 61 #include "content/public/browser/notification_observer.h" |
54 #include "content/public/browser/notification_registrar.h" | 62 #include "content/public/browser/notification_registrar.h" |
55 #include "content/public/browser/notification_service.h" | 63 #include "content/public/browser/notification_service.h" |
56 #include "content/public/browser/web_ui.h" | 64 #include "content/public/browser/web_ui.h" |
57 #include "content/public/test/browser_test_utils.h" | 65 #include "content/public/test/browser_test_utils.h" |
58 #include "extensions/browser/app_window/app_window.h" | 66 #include "extensions/browser/app_window/app_window.h" |
59 #include "extensions/browser/app_window/app_window_registry.h" | 67 #include "extensions/browser/app_window/app_window_registry.h" |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 KioskAppManager* manager_; | 396 KioskAppManager* manager_; |
389 WaitType wait_type_; | 397 WaitType wait_type_; |
390 bool loaded_; | 398 bool loaded_; |
391 bool quit_; | 399 bool quit_; |
392 std::string app_id_; | 400 std::string app_id_; |
393 std::string version_; | 401 std::string version_; |
394 | 402 |
395 DISALLOW_COPY_AND_ASSIGN(AppDataLoadWaiter); | 403 DISALLOW_COPY_AND_ASSIGN(AppDataLoadWaiter); |
396 }; | 404 }; |
397 | 405 |
| 406 class CrosSettingsPermanentlyUntrustedMaker : |
| 407 public DeviceSettingsService::Observer { |
| 408 public: |
| 409 CrosSettingsPermanentlyUntrustedMaker(); |
| 410 |
| 411 // DeviceSettingsService::Observer: |
| 412 void OwnershipStatusChanged() override; |
| 413 void DeviceSettingsUpdated() override; |
| 414 void OnDeviceSettingsServiceShutdown() override; |
| 415 |
| 416 private: |
| 417 bool untrusted_check_running_; |
| 418 base::RunLoop run_loop_; |
| 419 |
| 420 void CheckIfUntrusted(); |
| 421 |
| 422 DISALLOW_COPY_AND_ASSIGN(CrosSettingsPermanentlyUntrustedMaker); |
| 423 }; |
| 424 |
| 425 CrosSettingsPermanentlyUntrustedMaker::CrosSettingsPermanentlyUntrustedMaker() |
| 426 : untrusted_check_running_(false) { |
| 427 DeviceSettingsService::Get()->AddObserver(this); |
| 428 |
| 429 policy::DevicePolicyCrosTestHelper().InstallOwnerKey(); |
| 430 DeviceSettingsService::Get()->OwnerKeySet(true); |
| 431 |
| 432 run_loop_.Run(); |
| 433 } |
| 434 |
| 435 void CrosSettingsPermanentlyUntrustedMaker::OwnershipStatusChanged() { |
| 436 if (untrusted_check_running_) |
| 437 return; |
| 438 |
| 439 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 440 FROM_HERE, |
| 441 base::Bind(&CrosSettingsPermanentlyUntrustedMaker::CheckIfUntrusted, |
| 442 base::Unretained(this))); |
| 443 } |
| 444 |
| 445 void CrosSettingsPermanentlyUntrustedMaker::DeviceSettingsUpdated() { |
| 446 } |
| 447 |
| 448 void CrosSettingsPermanentlyUntrustedMaker::OnDeviceSettingsServiceShutdown() { |
| 449 } |
| 450 |
| 451 void CrosSettingsPermanentlyUntrustedMaker::CheckIfUntrusted() { |
| 452 untrusted_check_running_ = true; |
| 453 const CrosSettingsProvider::TrustedStatus trusted_status = |
| 454 CrosSettings::Get()->PrepareTrustedValues( |
| 455 base::Bind(&CrosSettingsPermanentlyUntrustedMaker::CheckIfUntrusted, |
| 456 base::Unretained(this))); |
| 457 if (trusted_status == CrosSettingsProvider::TEMPORARILY_UNTRUSTED) |
| 458 return; |
| 459 untrusted_check_running_ = false; |
| 460 |
| 461 if (trusted_status == CrosSettingsProvider::TRUSTED) |
| 462 return; |
| 463 |
| 464 DeviceSettingsService::Get()->RemoveObserver(this); |
| 465 run_loop_.Quit(); |
| 466 } |
| 467 |
398 } // namespace | 468 } // namespace |
399 | 469 |
400 class KioskTest : public OobeBaseTest { | 470 class KioskTest : public OobeBaseTest { |
401 public: | 471 public: |
402 KioskTest() : use_consumer_kiosk_mode_(true), | 472 KioskTest() : use_consumer_kiosk_mode_(true), |
403 fake_cws_(new FakeCWS) { | 473 fake_cws_(new FakeCWS) { |
404 set_exit_when_last_browser_closes(false); | 474 set_exit_when_last_browser_closes(false); |
405 } | 475 } |
406 | 476 |
407 ~KioskTest() override {} | 477 ~KioskTest() override {} |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 // app launching process itself. | 766 // app launching process itself. |
697 scoped_ptr<base::AutoLock> LockFileThread() { | 767 scoped_ptr<base::AutoLock> LockFileThread() { |
698 scoped_ptr<base::Lock> lock(new base::Lock); | 768 scoped_ptr<base::Lock> lock(new base::Lock); |
699 scoped_ptr<base::AutoLock> auto_lock(new base::AutoLock(*lock)); | 769 scoped_ptr<base::AutoLock> auto_lock(new base::AutoLock(*lock)); |
700 content::BrowserThread::PostTask( | 770 content::BrowserThread::PostTask( |
701 content::BrowserThread::FILE, FROM_HERE, | 771 content::BrowserThread::FILE, FROM_HERE, |
702 base::Bind(&LockAndUnlock, base::Passed(&lock))); | 772 base::Bind(&LockAndUnlock, base::Passed(&lock))); |
703 return auto_lock.Pass(); | 773 return auto_lock.Pass(); |
704 } | 774 } |
705 | 775 |
706 void MakeCrosSettingsPermanentlyUntrusted() { | |
707 policy::DevicePolicyCrosTestHelper().InstallOwnerKey(); | |
708 DeviceSettingsService::Get()->OwnerKeySet(true); | |
709 } | |
710 | |
711 MockUserManager* mock_user_manager() { return mock_user_manager_.get(); } | 776 MockUserManager* mock_user_manager() { return mock_user_manager_.get(); } |
712 | 777 |
713 void set_test_app_id(const std::string& test_app_id) { | 778 void set_test_app_id(const std::string& test_app_id) { |
714 test_app_id_ = test_app_id; | 779 test_app_id_ = test_app_id; |
715 } | 780 } |
716 const std::string& test_app_id() const { return test_app_id_; } | 781 const std::string& test_app_id() const { return test_app_id_; } |
717 void set_test_app_version(const std::string& version) { | 782 void set_test_app_version(const std::string& version) { |
718 test_app_version_ = version; | 783 test_app_version_ = version; |
719 } | 784 } |
720 const std::string& test_app_version() const { return test_app_version_; } | 785 const std::string& test_app_version() const { return test_app_version_; } |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 content::WindowedNotificationObserver( | 1193 content::WindowedNotificationObserver( |
1129 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE, | 1194 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE, |
1130 content::NotificationService::AllSources()).Wait(); | 1195 content::NotificationService::AllSources()).Wait(); |
1131 } | 1196 } |
1132 | 1197 |
1133 IN_PROC_BROWSER_TEST_F(KioskTest, DoNotLaunchWhenUntrusted) { | 1198 IN_PROC_BROWSER_TEST_F(KioskTest, DoNotLaunchWhenUntrusted) { |
1134 PrepareAppLaunch(); | 1199 PrepareAppLaunch(); |
1135 SimulateNetworkOnline(); | 1200 SimulateNetworkOnline(); |
1136 | 1201 |
1137 // Make cros settings untrusted. | 1202 // Make cros settings untrusted. |
1138 MakeCrosSettingsPermanentlyUntrusted(); | 1203 CrosSettingsPermanentlyUntrustedMaker(); |
1139 | 1204 |
1140 // Check that the attempt to start a kiosk app fails with an error. | 1205 // Check that the attempt to start a kiosk app fails with an error. |
1141 LaunchApp(test_app_id(), false); | 1206 LaunchApp(test_app_id(), false); |
1142 bool ignored = false; | 1207 bool ignored = false; |
1143 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 1208 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
1144 GetLoginUI()->GetWebContents(), | 1209 GetLoginUI()->GetWebContents(), |
1145 "if (cr.ui.Oobe.getInstance().errorMessageWasShownForTesting_) {" | 1210 "if (cr.ui.Oobe.getInstance().errorMessageWasShownForTesting_) {" |
1146 " window.domAutomationController.send(true);" | 1211 " window.domAutomationController.send(true);" |
1147 "} else {" | 1212 "} else {" |
1148 " cr.ui.Oobe.showSignInError = function(" | 1213 " cr.ui.Oobe.showSignInError = function(" |
1149 " loginAttempts, message, link, helpId) {" | 1214 " loginAttempts, message, link, helpId) {" |
1150 " window.domAutomationController.send(true);" | 1215 " window.domAutomationController.send(true);" |
1151 " };" | 1216 " };" |
1152 "}", | 1217 "}", |
1153 &ignored)); | 1218 &ignored)); |
1154 } | 1219 } |
1155 | 1220 |
1156 IN_PROC_BROWSER_TEST_F(KioskTest, NoAutoLaunchWhenUntrusted) { | 1221 // Verifies that a consumer device does not auto-launch kiosk mode when cros |
| 1222 // settings are untrusted. |
| 1223 IN_PROC_BROWSER_TEST_F(KioskTest, NoConsumerAutoLaunchWhenUntrusted) { |
1157 EnableConsumerKioskMode(); | 1224 EnableConsumerKioskMode(); |
1158 | 1225 |
1159 // Wait for and confirm the auto-launch warning. | 1226 // Wait for and confirm the auto-launch warning. |
1160 chromeos::WizardController::SkipPostLoginScreensForTesting(); | 1227 chromeos::WizardController::SkipPostLoginScreensForTesting(); |
1161 chromeos::WizardController* wizard_controller = | 1228 chromeos::WizardController* wizard_controller = |
1162 chromeos::WizardController::default_controller(); | 1229 chromeos::WizardController::default_controller(); |
1163 ASSERT_TRUE(wizard_controller); | 1230 ASSERT_TRUE(wizard_controller); |
1164 wizard_controller->AdvanceToScreen(WizardController::kNetworkScreenName); | 1231 wizard_controller->AdvanceToScreen(WizardController::kNetworkScreenName); |
1165 ReloadAutolaunchKioskApps(); | 1232 ReloadAutolaunchKioskApps(); |
1166 wizard_controller->SkipToLoginForTesting(LoginScreenContext()); | 1233 wizard_controller->SkipToLoginForTesting(LoginScreenContext()); |
1167 content::WindowedNotificationObserver( | 1234 content::WindowedNotificationObserver( |
1168 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE, | 1235 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE, |
1169 content::NotificationService::AllSources()).Wait(); | 1236 content::NotificationService::AllSources()).Wait(); |
1170 GetLoginUI()->CallJavascriptFunction( | 1237 GetLoginUI()->CallJavascriptFunction( |
1171 "login.AutolaunchScreen.confirmAutoLaunchForTesting", | 1238 "login.AutolaunchScreen.confirmAutoLaunchForTesting", |
1172 base::FundamentalValue(true)); | 1239 base::FundamentalValue(true)); |
1173 | 1240 |
1174 // Make cros settings untrusted. | 1241 // Make cros settings untrusted. |
1175 MakeCrosSettingsPermanentlyUntrusted(); | 1242 CrosSettingsPermanentlyUntrustedMaker(); |
1176 | 1243 |
1177 // Check that the attempt to auto-launch a kiosk app fails with an error. | 1244 // Check that the attempt to auto-launch a kiosk app fails with an error. |
1178 OobeScreenWaiter(OobeDisplay::SCREEN_ERROR_MESSAGE).Wait(); | 1245 OobeScreenWaiter(OobeDisplay::SCREEN_ERROR_MESSAGE).Wait(); |
1179 } | 1246 } |
1180 | 1247 |
| 1248 // Verifies that an enterprise device does not auto-launch kiosk mode when cros |
| 1249 // settings are untrusted. |
| 1250 IN_PROC_BROWSER_TEST_F(KioskTest, NoEnterpriseAutoLaunchWhenUntrusted) { |
| 1251 PrepareAppLaunch(); |
| 1252 SimulateNetworkOnline(); |
| 1253 |
| 1254 // Make cros settings untrusted. |
| 1255 CrosSettingsPermanentlyUntrustedMaker(); |
| 1256 |
| 1257 // Trigger the code that handles auto-launch on enterprise devices. This would |
| 1258 // normally be called from ShowLoginWizard(), which runs so early that it is |
| 1259 // not to inject an auto-launch policy before it runs. |
| 1260 LoginDisplayHost* login_display_host = LoginDisplayHostImpl::default_host(); |
| 1261 ASSERT_TRUE(login_display_host); |
| 1262 login_display_host->StartAppLaunch(test_app_id(), false); |
| 1263 |
| 1264 // Check that no launch has started. |
| 1265 EXPECT_FALSE(login_display_host->GetAppLaunchController()); |
| 1266 } |
| 1267 |
1181 class KioskUpdateTest : public KioskTest { | 1268 class KioskUpdateTest : public KioskTest { |
1182 public: | 1269 public: |
1183 KioskUpdateTest() {} | 1270 KioskUpdateTest() {} |
1184 ~KioskUpdateTest() override {} | 1271 ~KioskUpdateTest() override {} |
1185 | 1272 |
1186 protected: | 1273 protected: |
1187 void SetUp() override { | 1274 void SetUp() override { |
1188 fake_disk_mount_manager_ = new KioskFakeDiskMountManager(); | 1275 fake_disk_mount_manager_ = new KioskFakeDiskMountManager(); |
1189 disks::DiskMountManager::InitializeForTesting(fake_disk_mount_manager_); | 1276 disks::DiskMountManager::InitializeForTesting(fake_disk_mount_manager_); |
1190 | 1277 |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1889 content::WindowedNotificationObserver( | 1976 content::WindowedNotificationObserver( |
1890 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE, | 1977 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE, |
1891 content::NotificationService::AllSources()).Wait(); | 1978 content::NotificationService::AllSources()).Wait(); |
1892 | 1979 |
1893 // Wait for the wallpaper to load. | 1980 // Wait for the wallpaper to load. |
1894 WaitForWallpaper(); | 1981 WaitForWallpaper(); |
1895 EXPECT_TRUE(wallpaper_loaded()); | 1982 EXPECT_TRUE(wallpaper_loaded()); |
1896 } | 1983 } |
1897 | 1984 |
1898 } // namespace chromeos | 1985 } // namespace chromeos |
OLD | NEW |