Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: chrome/browser/chromeos/login/kiosk_browsertest.cc

Issue 1019283004: Switch to direct use of OwnerSettingsServiceChromeOS::Set() in tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replace checks with DCHECKs. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <vector>
6
5 #include "ash/desktop_background/desktop_background_controller.h" 7 #include "ash/desktop_background/desktop_background_controller.h"
6 #include "ash/desktop_background/desktop_background_controller_observer.h" 8 #include "ash/desktop_background/desktop_background_controller_observer.h"
7 #include "ash/shell.h" 9 #include "ash/shell.h"
8 #include "base/bind.h" 10 #include "base/bind.h"
9 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
10 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
11 #include "base/location.h" 13 #include "base/location.h"
12 #include "base/macros.h" 14 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
14 #include "base/path_service.h" 16 #include "base/path_service.h"
15 #include "base/prefs/pref_service.h" 17 #include "base/prefs/pref_service.h"
16 #include "base/run_loop.h" 18 #include "base/run_loop.h"
17 #include "base/single_thread_task_runner.h"
18 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
20 #include "base/synchronization/lock.h" 21 #include "base/synchronization/lock.h"
21 #include "base/thread_task_runner_handle.h"
22 #include "chrome/browser/chrome_notification_types.h" 22 #include "chrome/browser/chrome_notification_types.h"
23 #include "chrome/browser/chromeos/app_mode/fake_cws.h" 23 #include "chrome/browser/chromeos/app_mode/fake_cws.h"
24 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" 24 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h"
25 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" 25 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
26 #include "chrome/browser/chromeos/file_manager/fake_disk_mount_manager.h" 26 #include "chrome/browser/chromeos/file_manager/fake_disk_mount_manager.h"
27 #include "chrome/browser/chromeos/login/app_launch_controller.h" 27 #include "chrome/browser/chromeos/login/app_launch_controller.h"
28 #include "chrome/browser/chromeos/login/startup_utils.h" 28 #include "chrome/browser/chromeos/login/startup_utils.h"
29 #include "chrome/browser/chromeos/login/test/app_window_waiter.h" 29 #include "chrome/browser/chromeos/login/test/app_window_waiter.h"
30 #include "chrome/browser/chromeos/login/test/oobe_base_test.h" 30 #include "chrome/browser/chromeos/login/test/oobe_base_test.h"
31 #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" 32 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
33 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.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" 34 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
35 #include "chrome/browser/chromeos/login/users/mock_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" 36 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
37 #include "chrome/browser/chromeos/login/wizard_controller.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"
38 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" 40 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
39 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
40 #include "chrome/browser/chromeos/profiles/profile_helper.h" 41 #include "chrome/browser/chromeos/profiles/profile_helper.h"
41 #include "chrome/browser/chromeos/settings/cros_settings.h"
42 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" 42 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
43 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " 43 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h "
44 #include "chrome/browser/chromeos/settings/device_settings_service.h" 44 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h"
45 #include "chrome/browser/extensions/extension_service.h" 45 #include "chrome/browser/extensions/extension_service.h"
46 #include "chrome/browser/profiles/profile_impl.h" 46 #include "chrome/browser/profiles/profile_impl.h"
47 #include "chrome/browser/profiles/profile_manager.h" 47 #include "chrome/browser/profiles/profile_manager.h"
48 #include "chrome/browser/profiles/profiles_state.h" 48 #include "chrome/browser/profiles/profiles_state.h"
49 #include "chrome/browser/signin/signin_manager_factory.h" 49 #include "chrome/browser/signin/signin_manager_factory.h"
50 #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"
51 #include "chrome/common/chrome_constants.h" 51 #include "chrome/common/chrome_constants.h"
52 #include "chrome/common/chrome_paths.h" 52 #include "chrome/common/chrome_paths.h"
53 #include "chrome/common/pref_names.h" 53 #include "chrome/common/pref_names.h"
54 #include "chromeos/chromeos_switches.h" 54 #include "chromeos/chromeos_switches.h"
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 KioskAppManager* manager_; 396 KioskAppManager* manager_;
397 WaitType wait_type_; 397 WaitType wait_type_;
398 bool loaded_; 398 bool loaded_;
399 bool quit_; 399 bool quit_;
400 std::string app_id_; 400 std::string app_id_;
401 std::string version_; 401 std::string version_;
402 402
403 DISALLOW_COPY_AND_ASSIGN(AppDataLoadWaiter); 403 DISALLOW_COPY_AND_ASSIGN(AppDataLoadWaiter);
404 }; 404 };
405 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
468 } // namespace 406 } // namespace
469 407
470 class KioskTest : public OobeBaseTest { 408 class KioskTest : public OobeBaseTest {
471 public: 409 public:
472 KioskTest() : use_consumer_kiosk_mode_(true), 410 KioskTest()
473 fake_cws_(new FakeCWS) { 411 : settings_helper_(false),
412 use_consumer_kiosk_mode_(true),
413 fake_cws_(new FakeCWS) {
474 set_exit_when_last_browser_closes(false); 414 set_exit_when_last_browser_closes(false);
475 } 415 }
476 416
477 ~KioskTest() override {} 417 ~KioskTest() override {}
478 418
479 protected: 419 protected:
480 void SetUp() override { 420 void SetUp() override {
481 test_app_id_ = kTestKioskApp; 421 test_app_id_ = kTestKioskApp;
482 set_test_app_version("1.0.0"); 422 set_test_app_version("1.0.0");
483 set_test_crx_file(test_app_id() + ".crx"); 423 set_test_crx_file(test_app_id() + ".crx");
484 needs_background_networking_ = true; 424 needs_background_networking_ = true;
485 mock_user_manager_.reset(new MockUserManager); 425 mock_user_manager_.reset(new MockUserManager);
486 ProfileHelper::SetAlwaysReturnPrimaryUserForTesting(true); 426 ProfileHelper::SetAlwaysReturnPrimaryUserForTesting(true);
487 AppLaunchController::SkipSplashWaitForTesting(); 427 AppLaunchController::SkipSplashWaitForTesting();
488 AppLaunchController::SetNetworkWaitForTesting(kTestNetworkTimeoutSeconds); 428 AppLaunchController::SetNetworkWaitForTesting(kTestNetworkTimeoutSeconds);
489 429
490 OobeBaseTest::SetUp(); 430 OobeBaseTest::SetUp();
491 } 431 }
492 432
493 void TearDown() override { 433 void TearDown() override {
494 ProfileHelper::SetAlwaysReturnPrimaryUserForTesting(false); 434 ProfileHelper::SetAlwaysReturnPrimaryUserForTesting(false);
495 OobeBaseTest::TearDown(); 435 OobeBaseTest::TearDown();
496 } 436 }
497 437
498 void SetUpOnMainThread() override { 438 void SetUpOnMainThread() override {
499 OobeBaseTest::SetUpOnMainThread(); 439 OobeBaseTest::SetUpOnMainThread();
500 // Needed to avoid showing Gaia screen instead of owner signin for 440 // Needed to avoid showing Gaia screen instead of owner signin for
501 // consumer network down test cases. 441 // consumer network down test cases.
502 StartupUtils::MarkDeviceRegistered(base::Closure()); 442 StartupUtils::MarkDeviceRegistered(base::Closure());
443 settings_helper_.ReplaceProvider(kAccountsPrefDeviceLocalAccounts);
444 owner_settings_service_ = settings_helper_.CreateOwnerSettingsService(
445 ProfileManager::GetPrimaryUserProfile());
503 } 446 }
504 447
505 void TearDownOnMainThread() override { 448 void TearDownOnMainThread() override {
449 settings_helper_.RestoreProvider();
506 AppLaunchController::SetNetworkTimeoutCallbackForTesting(NULL); 450 AppLaunchController::SetNetworkTimeoutCallbackForTesting(NULL);
507 AppLaunchSigninScreen::SetUserManagerForTesting(NULL); 451 AppLaunchSigninScreen::SetUserManagerForTesting(NULL);
508 452
509 OobeBaseTest::TearDownOnMainThread(); 453 OobeBaseTest::TearDownOnMainThread();
510 454
511 // Clean up while main thread still runs. 455 // Clean up while main thread still runs.
512 // See http://crbug.com/176659. 456 // See http://crbug.com/176659.
513 KioskAppManager::Get()->CleanUp(); 457 KioskAppManager::Get()->CleanUp();
514 } 458 }
515 459
516 void SetUpCommandLine(base::CommandLine* command_line) override { 460 void SetUpCommandLine(base::CommandLine* command_line) override {
517 OobeBaseTest::SetUpCommandLine(command_line); 461 OobeBaseTest::SetUpCommandLine(command_line);
518 fake_cws_->Init(embedded_test_server()); 462 fake_cws_->Init(embedded_test_server());
519 } 463 }
520 464
521 void LaunchApp(const std::string& app_id, bool diagnostic_mode) { 465 void LaunchApp(const std::string& app_id, bool diagnostic_mode) {
522 bool new_kiosk_ui = KioskAppMenuHandler::EnableNewKioskUI(); 466 bool new_kiosk_ui = KioskAppMenuHandler::EnableNewKioskUI();
523 GetLoginUI()->CallJavascriptFunction(new_kiosk_ui ? 467 GetLoginUI()->CallJavascriptFunction(new_kiosk_ui ?
524 kLaunchAppForTestNewAPI : kLaunchAppForTestOldAPI, 468 kLaunchAppForTestNewAPI : kLaunchAppForTestOldAPI,
525 base::StringValue(app_id), 469 base::StringValue(app_id),
526 base::FundamentalValue(diagnostic_mode)); 470 base::FundamentalValue(diagnostic_mode));
527 } 471 }
528 472
529 void ReloadKioskApps() { 473 void ReloadKioskApps() {
530 SetupTestAppUpdateCheck(); 474 SetupTestAppUpdateCheck();
531 475
532 // Remove then add to ensure NOTIFICATION_KIOSK_APPS_LOADED fires. 476 // Remove then add to ensure NOTIFICATION_KIOSK_APPS_LOADED fires.
533 KioskAppManager::Get()->RemoveApp(test_app_id_); 477 KioskAppManager::Get()->RemoveApp(test_app_id_,
534 KioskAppManager::Get()->AddApp(test_app_id_); 478 owner_settings_service_.get());
479 KioskAppManager::Get()->AddApp(test_app_id_, owner_settings_service_.get());
535 } 480 }
536 481
537 void FireKioskAppSettingsChanged() { 482 void FireKioskAppSettingsChanged() {
538 KioskAppManager::Get()->UpdateAppData(); 483 KioskAppManager::Get()->UpdateAppData();
539 } 484 }
540 485
541 void SetupTestAppUpdateCheck() { 486 void SetupTestAppUpdateCheck() {
542 if (!test_app_version().empty()) { 487 if (!test_app_version().empty()) {
543 fake_cws_->SetUpdateCrx( 488 fake_cws_->SetUpdateCrx(
544 test_app_id(), test_crx_file(), test_app_version()); 489 test_app_id(), test_crx_file(), test_app_version());
545 } 490 }
546 } 491 }
547 492
548 void ReloadAutolaunchKioskApps() { 493 void ReloadAutolaunchKioskApps() {
549 SetupTestAppUpdateCheck(); 494 SetupTestAppUpdateCheck();
550 495
551 KioskAppManager::Get()->AddApp(test_app_id_); 496 KioskAppManager::Get()->AddApp(test_app_id_, owner_settings_service_.get());
552 KioskAppManager::Get()->SetAutoLaunchApp(test_app_id_); 497 KioskAppManager::Get()->SetAutoLaunchApp(test_app_id_,
498 owner_settings_service_.get());
553 } 499 }
554 500
555 void StartUIForAppLaunch() { 501 void StartUIForAppLaunch() {
556 if (use_consumer_kiosk_mode_) 502 if (use_consumer_kiosk_mode_)
557 EnableConsumerKioskMode(); 503 EnableConsumerKioskMode();
558 504
559 // Start UI 505 // Start UI
560 chromeos::WizardController::SkipPostLoginScreensForTesting(); 506 chromeos::WizardController::SkipPostLoginScreensForTesting();
561 chromeos::WizardController* wizard_controller = 507 chromeos::WizardController* wizard_controller =
562 chromeos::WizardController::default_controller(); 508 chromeos::WizardController::default_controller();
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 void set_test_crx_file(const std::string& filename) { 732 void set_test_crx_file(const std::string& filename) {
787 test_crx_file_ = filename; 733 test_crx_file_ = filename;
788 } 734 }
789 const std::string& test_crx_file() const { return test_crx_file_; } 735 const std::string& test_crx_file() const { return test_crx_file_; }
790 FakeCWS* fake_cws() { return fake_cws_.get(); } 736 FakeCWS* fake_cws() { return fake_cws_.get(); }
791 737
792 void set_use_consumer_kiosk_mode(bool use) { 738 void set_use_consumer_kiosk_mode(bool use) {
793 use_consumer_kiosk_mode_ = use; 739 use_consumer_kiosk_mode_ = use;
794 } 740 }
795 741
742 ScopedCrosSettingsTestHelper settings_helper_;
743 scoped_ptr<FakeOwnerSettingsService> owner_settings_service_;
744
796 private: 745 private:
797 bool use_consumer_kiosk_mode_; 746 bool use_consumer_kiosk_mode_;
798 std::string test_app_id_; 747 std::string test_app_id_;
799 std::string test_app_version_; 748 std::string test_app_version_;
800 std::string test_crx_file_; 749 std::string test_crx_file_;
801 scoped_ptr<FakeCWS> fake_cws_; 750 scoped_ptr<FakeCWS> fake_cws_;
802 scoped_ptr<MockUserManager> mock_user_manager_; 751 scoped_ptr<MockUserManager> mock_user_manager_;
803 752
804 DISALLOW_COPY_AND_ASSIGN(KioskTest); 753 DISALLOW_COPY_AND_ASSIGN(KioskTest);
805 }; 754 };
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 WaitForAppLaunchSuccess(); 925 WaitForAppLaunchSuccess();
977 } 926 }
978 927
979 IN_PROC_BROWSER_TEST_F(KioskTest, LaunchAppUserCancel) { 928 IN_PROC_BROWSER_TEST_F(KioskTest, LaunchAppUserCancel) {
980 // Make fake_cws_ return empty update response. 929 // Make fake_cws_ return empty update response.
981 set_test_app_version(""); 930 set_test_app_version("");
982 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure()); 931 StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure());
983 OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH); 932 OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH);
984 splash_waiter.Wait(); 933 splash_waiter.Wait();
985 934
986 CrosSettings::Get()->SetBoolean( 935 settings_helper_.SetBoolean(
987 kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled, true); 936 kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled, true);
988 content::WindowedNotificationObserver signal( 937 content::WindowedNotificationObserver signal(
989 chrome::NOTIFICATION_APP_TERMINATING, 938 chrome::NOTIFICATION_APP_TERMINATING,
990 content::NotificationService::AllSources()); 939 content::NotificationService::AllSources());
991 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator", 940 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
992 base::StringValue("app_launch_bailout")); 941 base::StringValue("app_launch_bailout"));
993 signal.Wait(); 942 signal.Wait();
994 EXPECT_EQ(chromeos::KioskAppLaunchError::USER_CANCEL, 943 EXPECT_EQ(chromeos::KioskAppLaunchError::USER_CANCEL,
995 chromeos::KioskAppLaunchError::Get()); 944 chromeos::KioskAppLaunchError::Get());
996 } 945 }
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 content::WindowedNotificationObserver( 1149 content::WindowedNotificationObserver(
1201 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE, 1150 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE,
1202 content::NotificationService::AllSources()).Wait(); 1151 content::NotificationService::AllSources()).Wait();
1203 } 1152 }
1204 1153
1205 IN_PROC_BROWSER_TEST_F(KioskTest, DoNotLaunchWhenUntrusted) { 1154 IN_PROC_BROWSER_TEST_F(KioskTest, DoNotLaunchWhenUntrusted) {
1206 PrepareAppLaunch(); 1155 PrepareAppLaunch();
1207 SimulateNetworkOnline(); 1156 SimulateNetworkOnline();
1208 1157
1209 // Make cros settings untrusted. 1158 // Make cros settings untrusted.
1210 CrosSettingsPermanentlyUntrustedMaker(); 1159 settings_helper_.SetTrustedStatus(
1160 CrosSettingsProvider::PERMANENTLY_UNTRUSTED);
1211 1161
1212 // Check that the attempt to start a kiosk app fails with an error. 1162 // Check that the attempt to start a kiosk app fails with an error.
1213 LaunchApp(test_app_id(), false); 1163 LaunchApp(test_app_id(), false);
1214 bool ignored = false; 1164 bool ignored = false;
1215 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 1165 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
1216 GetLoginUI()->GetWebContents(), 1166 GetLoginUI()->GetWebContents(),
1217 "if (cr.ui.Oobe.getInstance().errorMessageWasShownForTesting_) {" 1167 "if (cr.ui.Oobe.getInstance().errorMessageWasShownForTesting_) {"
1218 " window.domAutomationController.send(true);" 1168 " window.domAutomationController.send(true);"
1219 "} else {" 1169 "} else {"
1220 " cr.ui.Oobe.showSignInError = function(" 1170 " cr.ui.Oobe.showSignInError = function("
(...skipping 18 matching lines...) Expand all
1239 ReloadAutolaunchKioskApps(); 1189 ReloadAutolaunchKioskApps();
1240 wizard_controller->SkipToLoginForTesting(LoginScreenContext()); 1190 wizard_controller->SkipToLoginForTesting(LoginScreenContext());
1241 content::WindowedNotificationObserver( 1191 content::WindowedNotificationObserver(
1242 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE, 1192 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE,
1243 content::NotificationService::AllSources()).Wait(); 1193 content::NotificationService::AllSources()).Wait();
1244 GetLoginUI()->CallJavascriptFunction( 1194 GetLoginUI()->CallJavascriptFunction(
1245 "login.AutolaunchScreen.confirmAutoLaunchForTesting", 1195 "login.AutolaunchScreen.confirmAutoLaunchForTesting",
1246 base::FundamentalValue(true)); 1196 base::FundamentalValue(true));
1247 1197
1248 // Make cros settings untrusted. 1198 // Make cros settings untrusted.
1249 CrosSettingsPermanentlyUntrustedMaker(); 1199 settings_helper_.SetTrustedStatus(
1200 CrosSettingsProvider::PERMANENTLY_UNTRUSTED);
1250 1201
1251 // Check that the attempt to auto-launch a kiosk app fails with an error. 1202 // Check that the attempt to auto-launch a kiosk app fails with an error.
1252 OobeScreenWaiter(OobeDisplay::SCREEN_ERROR_MESSAGE).Wait(); 1203 OobeScreenWaiter(OobeDisplay::SCREEN_ERROR_MESSAGE).Wait();
1253 } 1204 }
1254 1205
1255 // Verifies that an enterprise device does not auto-launch kiosk mode when cros 1206 // Verifies that an enterprise device does not auto-launch kiosk mode when cros
1256 // settings are untrusted. 1207 // settings are untrusted.
1257 IN_PROC_BROWSER_TEST_F(KioskTest, NoEnterpriseAutoLaunchWhenUntrusted) { 1208 IN_PROC_BROWSER_TEST_F(KioskTest, NoEnterpriseAutoLaunchWhenUntrusted) {
1258 PrepareAppLaunch(); 1209 PrepareAppLaunch();
1259 SimulateNetworkOnline(); 1210 SimulateNetworkOnline();
1260 1211
1261 // Make cros settings untrusted. 1212 // Make cros settings untrusted.
1262 CrosSettingsPermanentlyUntrustedMaker(); 1213 settings_helper_.SetTrustedStatus(
1214 CrosSettingsProvider::PERMANENTLY_UNTRUSTED);
1263 1215
1264 // Trigger the code that handles auto-launch on enterprise devices. This would 1216 // Trigger the code that handles auto-launch on enterprise devices. This would
1265 // normally be called from ShowLoginWizard(), which runs so early that it is 1217 // normally be called from ShowLoginWizard(), which runs so early that it is
1266 // not possible to inject an auto-launch policy before it runs. 1218 // not possible to inject an auto-launch policy before it runs.
1267 LoginDisplayHost* login_display_host = LoginDisplayHostImpl::default_host(); 1219 LoginDisplayHost* login_display_host = LoginDisplayHostImpl::default_host();
1268 ASSERT_TRUE(login_display_host); 1220 ASSERT_TRUE(login_display_host);
1269 login_display_host->StartAppLaunch(test_app_id(), false, true); 1221 login_display_host->StartAppLaunch(test_app_id(), false, true);
1270 1222
1271 // Check that no launch has started. 1223 // Check that no launch has started.
1272 EXPECT_FALSE(login_display_host->GetAppLaunchController()); 1224 EXPECT_FALSE(login_display_host->GetAppLaunchController());
(...skipping 11 matching lines...) Expand all
1284 1236
1285 KioskTest::SetUp(); 1237 KioskTest::SetUp();
1286 } 1238 }
1287 1239
1288 void TearDown() override { 1240 void TearDown() override {
1289 disks::DiskMountManager::Shutdown(); 1241 disks::DiskMountManager::Shutdown();
1290 1242
1291 KioskTest::TearDown(); 1243 KioskTest::TearDown();
1292 } 1244 }
1293 1245
1294 void SetUpOnMainThread() override { KioskTest::SetUpOnMainThread(); } 1246 void SetUpOnMainThread() override {
1247 // For update tests, we cache the app in the PRE part, and then we load it
1248 // in the test, so we need to both store the apps list on teardown (so that
1249 // the app manager would accept existing files in its extension cache on the
1250 // next startup) and copy the list to our stub settings provider as well.
1251 settings_helper_.CopyStoredValue(kAccountsPrefDeviceLocalAccounts);
1252 KioskTest::SetUpOnMainThread();
1253 }
1254
1255 void TearDownOnMainThread() override {
1256 settings_helper_.StoreCachedDeviceSetting(kAccountsPrefDeviceLocalAccounts);
1257 KioskTest::TearDownOnMainThread();
1258 }
1295 1259
1296 void PreCacheApp(const std::string& app_id, 1260 void PreCacheApp(const std::string& app_id,
1297 const std::string& version, 1261 const std::string& version,
1298 const std::string& crx_file) { 1262 const std::string& crx_file) {
1299 set_test_app_id(app_id); 1263 set_test_app_id(app_id);
1300 set_test_app_version(version); 1264 set_test_app_version(version);
1301 set_test_crx_file(crx_file); 1265 set_test_crx_file(crx_file);
1302 1266
1303 KioskAppManager* manager = KioskAppManager::Get(); 1267 KioskAppManager* manager = KioskAppManager::Get();
1304 AppDataLoadWaiter waiter(manager, app_id, version); 1268 AppDataLoadWaiter waiter(manager, app_id, version);
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 1690 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
1727 } 1691 }
1728 1692
1729 class KioskEnterpriseTest : public KioskTest { 1693 class KioskEnterpriseTest : public KioskTest {
1730 protected: 1694 protected:
1731 KioskEnterpriseTest() { 1695 KioskEnterpriseTest() {
1732 set_use_consumer_kiosk_mode(false); 1696 set_use_consumer_kiosk_mode(false);
1733 } 1697 }
1734 1698
1735 void SetUpInProcessBrowserTestFixture() override { 1699 void SetUpInProcessBrowserTestFixture() override {
1736 device_policy_test_helper_.MarkAsEnterpriseOwned(); 1700 policy::DevicePolicyCrosTestHelper::MarkAsEnterpriseOwnedBy(
1737 device_policy_test_helper_.InstallOwnerKey(); 1701 kTestOwnerEmail);
1702 settings_helper_.SetCurrentUserIsOwner(false);
1738 1703
1739 KioskTest::SetUpInProcessBrowserTestFixture(); 1704 KioskTest::SetUpInProcessBrowserTestFixture();
1740 } 1705 }
1741 1706
1742 void SetUpOnMainThread() override { 1707 void SetUpOnMainThread() override {
1743 KioskTest::SetUpOnMainThread(); 1708 KioskTest::SetUpOnMainThread();
1744 1709
1745 // Configure OAuth authentication. 1710 // Configure OAuth authentication.
1746 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); 1711 GaiaUrls* gaia_urls = GaiaUrls::GetInstance();
1747 1712
(...skipping 22 matching lines...) Expand all
1770 access_token_info.email = kTestEnterpriseServiceAccountId; 1735 access_token_info.email = kTestEnterpriseServiceAccountId;
1771 fake_gaia_->IssueOAuthToken(kTestLoginToken, access_token_info); 1736 fake_gaia_->IssueOAuthToken(kTestLoginToken, access_token_info);
1772 1737
1773 DeviceOAuth2TokenService* token_service = 1738 DeviceOAuth2TokenService* token_service =
1774 DeviceOAuth2TokenServiceFactory::Get(); 1739 DeviceOAuth2TokenServiceFactory::Get();
1775 token_service->SetAndSaveRefreshToken( 1740 token_service->SetAndSaveRefreshToken(
1776 kTestRefreshToken, DeviceOAuth2TokenService::StatusCallback()); 1741 kTestRefreshToken, DeviceOAuth2TokenService::StatusCallback());
1777 base::RunLoop().RunUntilIdle(); 1742 base::RunLoop().RunUntilIdle();
1778 } 1743 }
1779 1744
1780 static void StorePolicyCallback(const base::Closure& callback, bool result) {
1781 ASSERT_TRUE(result);
1782 callback.Run();
1783 }
1784
1785 void ConfigureKioskAppInPolicy(const std::string& account_id, 1745 void ConfigureKioskAppInPolicy(const std::string& account_id,
1786 const std::string& app_id, 1746 const std::string& app_id,
1787 const std::string& update_url) { 1747 const std::string& update_url) {
1788 em::DeviceLocalAccountsProto* accounts = 1748 settings_helper_.SetCurrentUserIsOwner(true);
1789 device_policy_test_helper_.device_policy()->payload() 1749 std::vector<policy::DeviceLocalAccount> accounts;
1790 .mutable_device_local_accounts(); 1750 accounts.push_back(
1791 em::DeviceLocalAccountInfoProto* account = accounts->add_account(); 1751 policy::DeviceLocalAccount(policy::DeviceLocalAccount::TYPE_KIOSK_APP,
1792 account->set_account_id(account_id); 1752 account_id, app_id, update_url));
1793 account->set_type( 1753 policy::SetDeviceLocalAccounts(owner_settings_service_.get(), accounts);
1794 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_KIOSK_APP); 1754 settings_helper_.SetString(kAccountsPrefDeviceLocalAccountAutoLoginId,
1795 account->mutable_kiosk_app()->set_app_id(app_id); 1755 account_id);
1796 if (!update_url.empty()) 1756 settings_helper_.SetString(kServiceAccountIdentity,
1797 account->mutable_kiosk_app()->set_update_url(update_url); 1757 kTestEnterpriseServiceAccountId);
1798 accounts->set_auto_login_id(account_id); 1758 settings_helper_.SetCurrentUserIsOwner(false);
1799 em::PolicyData& policy_data =
1800 device_policy_test_helper_.device_policy()->policy_data();
1801 policy_data.set_service_account_identity(kTestEnterpriseServiceAccountId);
1802 device_policy_test_helper_.device_policy()->Build();
1803
1804 base::RunLoop run_loop;
1805 DBusThreadManager::Get()->GetSessionManagerClient()->StoreDevicePolicy(
1806 device_policy_test_helper_.device_policy()->GetBlob(),
1807 base::Bind(&KioskEnterpriseTest::StorePolicyCallback,
1808 run_loop.QuitClosure()));
1809 run_loop.Run();
1810
1811 DeviceSettingsService::Get()->Load();
1812 } 1759 }
1813 1760
1814 policy::DevicePolicyCrosTestHelper device_policy_test_helper_;
1815
1816 private: 1761 private:
1817 DISALLOW_COPY_AND_ASSIGN(KioskEnterpriseTest); 1762 DISALLOW_COPY_AND_ASSIGN(KioskEnterpriseTest);
1818 }; 1763 };
1819 1764
1820 IN_PROC_BROWSER_TEST_F(KioskEnterpriseTest, EnterpriseKioskApp) { 1765 IN_PROC_BROWSER_TEST_F(KioskEnterpriseTest, EnterpriseKioskApp) {
1821 // Prepare Fake CWS to serve app crx. 1766 // Prepare Fake CWS to serve app crx.
1822 set_test_app_id(kTestEnterpriseKioskApp); 1767 set_test_app_id(kTestEnterpriseKioskApp);
1823 set_test_app_version("1.0.0"); 1768 set_test_app_version("1.0.0");
1824 set_test_crx_file(test_app_id() + ".crx"); 1769 set_test_crx_file(test_app_id() + ".crx");
1825 SetupTestAppUpdateCheck(); 1770 SetupTestAppUpdateCheck();
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1982 content::WindowedNotificationObserver( 1927 content::WindowedNotificationObserver(
1983 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE, 1928 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE,
1984 content::NotificationService::AllSources()).Wait(); 1929 content::NotificationService::AllSources()).Wait();
1985 1930
1986 // Wait for the wallpaper to load. 1931 // Wait for the wallpaper to load.
1987 WaitForWallpaper(); 1932 WaitForWallpaper();
1988 EXPECT_TRUE(wallpaper_loaded()); 1933 EXPECT_TRUE(wallpaper_loaded());
1989 } 1934 }
1990 1935
1991 } // namespace chromeos 1936 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698