| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" | 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 |
| 9 #include <memory> |
| 8 #include <utility> | 10 #include <utility> |
| 9 | 11 |
| 10 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 11 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/macros.h" | 15 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 17 #include "base/values.h" | 18 #include "base/values.h" |
| 18 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/chromeos/app_mode/fake_cws.h" | 20 #include "chrome/browser/chromeos/app_mode/fake_cws.h" |
| 20 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" | 21 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" |
| 21 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" | 22 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" |
| 22 #include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h" | 23 #include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h" |
| 23 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 24 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 24 #include "chrome/browser/chromeos/policy/device_local_account.h" | 25 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 } | 88 } |
| 88 | 89 |
| 89 scoped_refptr<extensions::Extension> MakeKioskApp( | 90 scoped_refptr<extensions::Extension> MakeKioskApp( |
| 90 const std::string& name, | 91 const std::string& name, |
| 91 const std::string& version, | 92 const std::string& version, |
| 92 const std::string& id, | 93 const std::string& id, |
| 93 const std::string& required_platform_version) { | 94 const std::string& required_platform_version) { |
| 94 base::DictionaryValue value; | 95 base::DictionaryValue value; |
| 95 value.SetString("name", name); | 96 value.SetString("name", name); |
| 96 value.SetString("version", version); | 97 value.SetString("version", version); |
| 97 scoped_ptr<base::ListValue> scripts(new base::ListValue); | 98 std::unique_ptr<base::ListValue> scripts(new base::ListValue); |
| 98 scripts->AppendString("main.js"); | 99 scripts->AppendString("main.js"); |
| 99 value.Set("app.background.scripts", std::move(scripts)); | 100 value.Set("app.background.scripts", std::move(scripts)); |
| 100 value.SetBoolean("kiosk_enabled", true); | 101 value.SetBoolean("kiosk_enabled", true); |
| 101 value.SetString("kiosk.required_platform_version", required_platform_version); | 102 value.SetString("kiosk.required_platform_version", required_platform_version); |
| 102 | 103 |
| 103 std::string err; | 104 std::string err; |
| 104 scoped_refptr<extensions::Extension> app = | 105 scoped_refptr<extensions::Extension> app = |
| 105 extensions::Extension::Create( | 106 extensions::Extension::Create( |
| 106 base::FilePath(), | 107 base::FilePath(), |
| 107 extensions::Manifest::INTERNAL, | 108 extensions::Manifest::INTERNAL, |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 if (i > 0) | 266 if (i > 0) |
| 266 str += ','; | 267 str += ','; |
| 267 str += apps[i].app_id; | 268 str += apps[i].app_id; |
| 268 } | 269 } |
| 269 | 270 |
| 270 return str; | 271 return str; |
| 271 } | 272 } |
| 272 | 273 |
| 273 // Locks device for enterprise. | 274 // Locks device for enterprise. |
| 274 policy::EnterpriseInstallAttributes::LockResult LockDeviceForEnterprise() { | 275 policy::EnterpriseInstallAttributes::LockResult LockDeviceForEnterprise() { |
| 275 scoped_ptr<policy::EnterpriseInstallAttributes::LockResult> lock_result( | 276 std::unique_ptr<policy::EnterpriseInstallAttributes::LockResult> |
| 276 new policy::EnterpriseInstallAttributes::LockResult( | 277 lock_result(new policy::EnterpriseInstallAttributes::LockResult( |
| 277 policy::EnterpriseInstallAttributes::LOCK_NOT_READY)); | 278 policy::EnterpriseInstallAttributes::LOCK_NOT_READY)); |
| 278 scoped_refptr<content::MessageLoopRunner> runner = | 279 scoped_refptr<content::MessageLoopRunner> runner = |
| 279 new content::MessageLoopRunner; | 280 new content::MessageLoopRunner; |
| 280 policy::BrowserPolicyConnectorChromeOS* connector = | 281 policy::BrowserPolicyConnectorChromeOS* connector = |
| 281 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 282 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 282 connector->GetInstallAttributes()->LockDevice( | 283 connector->GetInstallAttributes()->LockDevice( |
| 283 "user@domain.com", | 284 "user@domain.com", |
| 284 policy::DEVICE_MODE_ENTERPRISE, | 285 policy::DEVICE_MODE_ENTERPRISE, |
| 285 "device-id", | 286 "device-id", |
| 286 base::Bind( | 287 base::Bind( |
| 287 &OnEnterpriseDeviceLock, lock_result.get(), runner->QuitClosure())); | 288 &OnEnterpriseDeviceLock, lock_result.get(), runner->QuitClosure())); |
| 288 runner->Run(); | 289 runner->Run(); |
| 289 return *lock_result.get(); | 290 return *lock_result.get(); |
| 290 } | 291 } |
| 291 | 292 |
| 292 void SetExistingApp(const std::string& app_id, | 293 void SetExistingApp(const std::string& app_id, |
| 293 const std::string& app_name, | 294 const std::string& app_name, |
| 294 const std::string& icon_file_name, | 295 const std::string& icon_file_name, |
| 295 const std::string& required_platform_version) { | 296 const std::string& required_platform_version) { |
| 296 base::FilePath test_dir; | 297 base::FilePath test_dir; |
| 297 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); | 298 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); |
| 298 base::FilePath data_dir = test_dir.AppendASCII("chromeos/app_mode/"); | 299 base::FilePath data_dir = test_dir.AppendASCII("chromeos/app_mode/"); |
| 299 | 300 |
| 300 // Copy the icon file to temp dir for using because ClearAppData test | 301 // Copy the icon file to temp dir for using because ClearAppData test |
| 301 // deletes it. | 302 // deletes it. |
| 302 base::FilePath icon_path = | 303 base::FilePath icon_path = |
| 303 CopyFileToTempDir(data_dir.AppendASCII(icon_file_name)); | 304 CopyFileToTempDir(data_dir.AppendASCII(icon_file_name)); |
| 304 | 305 |
| 305 scoped_ptr<base::DictionaryValue> apps_dict(new base::DictionaryValue); | 306 std::unique_ptr<base::DictionaryValue> apps_dict(new base::DictionaryValue); |
| 306 apps_dict->SetString(app_id + ".name", app_name); | 307 apps_dict->SetString(app_id + ".name", app_name); |
| 307 apps_dict->SetString(app_id + ".icon", icon_path.MaybeAsASCII()); | 308 apps_dict->SetString(app_id + ".icon", icon_path.MaybeAsASCII()); |
| 308 apps_dict->SetString(app_id + ".required_platform_version", | 309 apps_dict->SetString(app_id + ".required_platform_version", |
| 309 required_platform_version); | 310 required_platform_version); |
| 310 | 311 |
| 311 PrefService* local_state = g_browser_process->local_state(); | 312 PrefService* local_state = g_browser_process->local_state(); |
| 312 DictionaryPrefUpdate dict_update(local_state, | 313 DictionaryPrefUpdate dict_update(local_state, |
| 313 KioskAppManager::kKioskDictionaryName); | 314 KioskAppManager::kKioskDictionaryName); |
| 314 dict_update->Set(KioskAppManager::kKeyApps, apps_dict.release()); | 315 dict_update->Set(KioskAppManager::kKeyApps, apps_dict.release()); |
| 315 | 316 |
| 316 // Make the app appear in device settings. | 317 // Make the app appear in device settings. |
| 317 base::ListValue device_local_accounts; | 318 base::ListValue device_local_accounts; |
| 318 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); | 319 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue); |
| 319 // Fake an account id. Note this needs to match GenerateKioskAppAccountId | 320 // Fake an account id. Note this needs to match GenerateKioskAppAccountId |
| 320 // in kiosk_app_manager.cc to make SetAutoLaunchApp work with the | 321 // in kiosk_app_manager.cc to make SetAutoLaunchApp work with the |
| 321 // existing app entry created here. | 322 // existing app entry created here. |
| 322 entry->SetStringWithoutPathExpansion(kAccountsPrefDeviceLocalAccountsKeyId, | 323 entry->SetStringWithoutPathExpansion(kAccountsPrefDeviceLocalAccountsKeyId, |
| 323 app_id + "@kiosk-apps"); | 324 app_id + "@kiosk-apps"); |
| 324 entry->SetIntegerWithoutPathExpansion( | 325 entry->SetIntegerWithoutPathExpansion( |
| 325 kAccountsPrefDeviceLocalAccountsKeyType, | 326 kAccountsPrefDeviceLocalAccountsKeyType, |
| 326 policy::DeviceLocalAccount::TYPE_KIOSK_APP); | 327 policy::DeviceLocalAccount::TYPE_KIOSK_APP); |
| 327 entry->SetStringWithoutPathExpansion( | 328 entry->SetStringWithoutPathExpansion( |
| 328 kAccountsPrefDeviceLocalAccountsKeyKioskAppId, | 329 kAccountsPrefDeviceLocalAccountsKeyKioskAppId, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 | 432 |
| 432 KioskAppData* GetAppDataMutable(const std::string& app_id) { | 433 KioskAppData* GetAppDataMutable(const std::string& app_id) { |
| 433 return manager()->GetAppDataMutable(app_id); | 434 return manager()->GetAppDataMutable(app_id); |
| 434 } | 435 } |
| 435 | 436 |
| 436 KioskAppManager* manager() const { return KioskAppManager::Get(); } | 437 KioskAppManager* manager() const { return KioskAppManager::Get(); } |
| 437 FakeCWS* fake_cws() { return fake_cws_.get(); } | 438 FakeCWS* fake_cws() { return fake_cws_.get(); } |
| 438 | 439 |
| 439 protected: | 440 protected: |
| 440 ScopedCrosSettingsTestHelper settings_helper_; | 441 ScopedCrosSettingsTestHelper settings_helper_; |
| 441 scoped_ptr<FakeOwnerSettingsService> owner_settings_service_; | 442 std::unique_ptr<FakeOwnerSettingsService> owner_settings_service_; |
| 442 | 443 |
| 443 private: | 444 private: |
| 444 base::ScopedTempDir temp_dir_; | 445 base::ScopedTempDir temp_dir_; |
| 445 scoped_ptr<FakeCWS> fake_cws_; | 446 std::unique_ptr<FakeCWS> fake_cws_; |
| 446 | 447 |
| 447 DISALLOW_COPY_AND_ASSIGN(KioskAppManagerTest); | 448 DISALLOW_COPY_AND_ASSIGN(KioskAppManagerTest); |
| 448 }; | 449 }; |
| 449 | 450 |
| 450 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, Basic) { | 451 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, Basic) { |
| 451 // Add a couple of apps. Use "fake_app_x" that do not have data on the test | 452 // Add a couple of apps. Use "fake_app_x" that do not have data on the test |
| 452 // server to avoid pending data loads that could be lingering on tear down and | 453 // server to avoid pending data loads that could be lingering on tear down and |
| 453 // cause DCHECK failure in utility_process_host_impl.cc. | 454 // cause DCHECK failure in utility_process_host_impl.cc. |
| 454 manager()->AddApp("fake_app_1", owner_settings_service_.get()); | 455 manager()->AddApp("fake_app_1", owner_settings_service_.get()); |
| 455 manager()->AddApp("fake_app_2", owner_settings_service_.get()); | 456 manager()->AddApp("fake_app_2", owner_settings_service_.get()); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 content::RunAllBlockingPoolTasksUntilIdle(); | 760 content::RunAllBlockingPoolTasksUntilIdle(); |
| 760 manager()->GetApps(&apps); | 761 manager()->GetApps(&apps); |
| 761 ASSERT_EQ(0u, apps.size()); | 762 ASSERT_EQ(0u, apps.size()); |
| 762 // Verify both v1 and v2 crx files are removed. | 763 // Verify both v1 and v2 crx files are removed. |
| 763 EXPECT_FALSE(base::PathExists(v1_crx_path)); | 764 EXPECT_FALSE(base::PathExists(v1_crx_path)); |
| 764 EXPECT_FALSE(base::PathExists(v2_crx_path)); | 765 EXPECT_FALSE(base::PathExists(v2_crx_path)); |
| 765 EXPECT_FALSE(GetCachedCrx(kTestLocalFsKioskApp, &v2_crx_path, &version)); | 766 EXPECT_FALSE(GetCachedCrx(kTestLocalFsKioskApp, &v2_crx_path, &version)); |
| 766 } | 767 } |
| 767 | 768 |
| 768 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, EnableConsumerKiosk) { | 769 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, EnableConsumerKiosk) { |
| 769 scoped_ptr<KioskAppManager::ConsumerKioskAutoLaunchStatus> status( | 770 std::unique_ptr<KioskAppManager::ConsumerKioskAutoLaunchStatus> status( |
| 770 new KioskAppManager::ConsumerKioskAutoLaunchStatus( | 771 new KioskAppManager::ConsumerKioskAutoLaunchStatus( |
| 771 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED)); | 772 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED)); |
| 772 scoped_ptr<bool> locked(new bool(false)); | 773 std::unique_ptr<bool> locked(new bool(false)); |
| 773 | 774 |
| 774 scoped_refptr<content::MessageLoopRunner> runner = | 775 scoped_refptr<content::MessageLoopRunner> runner = |
| 775 new content::MessageLoopRunner; | 776 new content::MessageLoopRunner; |
| 776 manager()->GetConsumerKioskAutoLaunchStatus( | 777 manager()->GetConsumerKioskAutoLaunchStatus( |
| 777 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, | 778 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, |
| 778 status.get(), | 779 status.get(), |
| 779 runner->QuitClosure())); | 780 runner->QuitClosure())); |
| 780 runner->Run(); | 781 runner->Run(); |
| 781 EXPECT_EQ(*status.get(), | 782 EXPECT_EQ(*status.get(), |
| 782 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE); | 783 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 800 EXPECT_EQ(*status.get(), | 801 EXPECT_EQ(*status.get(), |
| 801 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_ENABLED); | 802 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_ENABLED); |
| 802 } | 803 } |
| 803 | 804 |
| 804 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, | 805 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, |
| 805 PreventEnableConsumerKioskForEnterprise) { | 806 PreventEnableConsumerKioskForEnterprise) { |
| 806 // First, lock the device as enterprise. | 807 // First, lock the device as enterprise. |
| 807 EXPECT_EQ(LockDeviceForEnterprise(), | 808 EXPECT_EQ(LockDeviceForEnterprise(), |
| 808 policy::EnterpriseInstallAttributes::LOCK_SUCCESS); | 809 policy::EnterpriseInstallAttributes::LOCK_SUCCESS); |
| 809 | 810 |
| 810 scoped_ptr<KioskAppManager::ConsumerKioskAutoLaunchStatus> status( | 811 std::unique_ptr<KioskAppManager::ConsumerKioskAutoLaunchStatus> status( |
| 811 new KioskAppManager::ConsumerKioskAutoLaunchStatus( | 812 new KioskAppManager::ConsumerKioskAutoLaunchStatus( |
| 812 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED)); | 813 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED)); |
| 813 scoped_ptr<bool> locked(new bool(true)); | 814 std::unique_ptr<bool> locked(new bool(true)); |
| 814 | 815 |
| 815 scoped_refptr<content::MessageLoopRunner> runner = | 816 scoped_refptr<content::MessageLoopRunner> runner = |
| 816 new content::MessageLoopRunner; | 817 new content::MessageLoopRunner; |
| 817 manager()->GetConsumerKioskAutoLaunchStatus( | 818 manager()->GetConsumerKioskAutoLaunchStatus( |
| 818 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, | 819 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, |
| 819 status.get(), | 820 status.get(), |
| 820 runner->QuitClosure())); | 821 runner->QuitClosure())); |
| 821 runner->Run(); | 822 runner->Run(); |
| 822 EXPECT_EQ(*status.get(), | 823 EXPECT_EQ(*status.get(), |
| 823 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED); | 824 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 // No require platform version if auto launched app has a non-zero delay set. | 868 // No require platform version if auto launched app has a non-zero delay set. |
| 868 settings_helper_.SetInteger(kAccountsPrefDeviceLocalAccountAutoLoginDelay, 1); | 869 settings_helper_.SetInteger(kAccountsPrefDeviceLocalAccountAutoLoginDelay, 1); |
| 869 EXPECT_EQ("", manager()->GetAutoLaunchAppRequiredPlatformVersion()); | 870 EXPECT_EQ("", manager()->GetAutoLaunchAppRequiredPlatformVersion()); |
| 870 | 871 |
| 871 settings_helper_.SetInteger(kAccountsPrefDeviceLocalAccountAutoLoginDelay, 0); | 872 settings_helper_.SetInteger(kAccountsPrefDeviceLocalAccountAutoLoginDelay, 0); |
| 872 EXPECT_EQ(kRequiredPlatformVersion, | 873 EXPECT_EQ(kRequiredPlatformVersion, |
| 873 manager()->GetAutoLaunchAppRequiredPlatformVersion()); | 874 manager()->GetAutoLaunchAppRequiredPlatformVersion()); |
| 874 } | 875 } |
| 875 | 876 |
| 876 } // namespace chromeos | 877 } // namespace chromeos |
| OLD | NEW |