diff options
author | ginkage <ginkage@chromium.org> | 2015-04-22 10:54:18 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-22 17:55:14 +0000 |
commit | 3a599661a49fa5ebfe63cb4016bb8efcd2d02712 (patch) | |
tree | e3189872e381c763f90909c4a18c4bc18cebad90 | |
parent | f72001505b06d68f7716b474e35865f33fffd4fe (diff) | |
download | chromium_src-3a599661a49fa5ebfe63cb4016bb8efcd2d02712.zip chromium_src-3a599661a49fa5ebfe63cb4016bb8efcd2d02712.tar.gz chromium_src-3a599661a49fa5ebfe63cb4016bb8efcd2d02712.tar.bz2 |
Get rid of excessive CrosSettings::Get()->Set*() usage, mostly in tests.
The following tests were affected:
unit_tests:
AttestationPolicyObserverTest.*
CryptohomeAuthenticatorTest.*
ExtensionCacheTest.*
EPKPChallengeMachineKeyTest.DevicePolicyDisabled
EPKPChallengeUserKeyTest.DevicePolicyDisabled
HeartbeatSchedulerTest.*
NetworkConfigurationUpdaterTest.*
PlatformVerificationFlowTest.*
StatusUploaderTest.*
ShutdownPolicyHandlerTest.*
UserManagerTest.*
browser_tests:
DeviceStatusCollectorTest.*
KioskAppManagerTest.*
KioskEnterpriseTest.*
KioskTest.*
KioskUpdateTest.*
BUG=433840
Review URL: https://codereview.chromium.org/1019283004
Cr-Commit-Position: refs/heads/master@{#326338}
35 files changed, 573 insertions, 533 deletions
diff --git a/chrome/browser/chromeos/app_mode/kiosk_app_manager.cc b/chrome/browser/chromeos/app_mode/kiosk_app_manager.cc index ab182b5..a37df89 100644 --- a/chrome/browser/chromeos/app_mode/kiosk_app_manager.cc +++ b/chrome/browser/chromeos/app_mode/kiosk_app_manager.cc @@ -23,6 +23,7 @@ #include "chrome/browser/chromeos/app_mode/kiosk_app_external_loader.h" #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" #include "chrome/browser/chromeos/app_mode/kiosk_external_updater.h" +#include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_factory.h" #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" #include "chrome/browser/chromeos/policy/device_local_account.h" @@ -183,20 +184,20 @@ std::string KioskAppManager::GetAutoLaunchApp() const { return auto_launch_app_id_; } -void KioskAppManager::SetAutoLaunchApp(const std::string& app_id) { +void KioskAppManager::SetAutoLaunchApp(const std::string& app_id, + OwnerSettingsServiceChromeOS* service) { SetAutoLoginState(AUTOLOGIN_REQUESTED); // Clean first, so the proper change callbacks are triggered even // if we are only changing AutoLoginState here. if (!auto_launch_app_id_.empty()) { - CrosSettings::Get()->SetString(kAccountsPrefDeviceLocalAccountAutoLoginId, - std::string()); + service->SetString(kAccountsPrefDeviceLocalAccountAutoLoginId, + std::string()); } - CrosSettings::Get()->SetString( + service->SetString( kAccountsPrefDeviceLocalAccountAutoLoginId, app_id.empty() ? std::string() : GenerateKioskAppAccountId(app_id)); - CrosSettings::Get()->SetInteger( - kAccountsPrefDeviceLocalAccountAutoLoginDelay, 0); + service->SetInteger(kAccountsPrefDeviceLocalAccountAutoLoginDelay, 0); } void KioskAppManager::SetAppWasAutoLaunchedWithZeroDelay( @@ -332,7 +333,8 @@ bool KioskAppManager::IsAutoLaunchEnabled() const { return GetAutoLoginState() == AUTOLOGIN_APPROVED; } -void KioskAppManager::AddApp(const std::string& app_id) { +void KioskAppManager::AddApp(const std::string& app_id, + OwnerSettingsServiceChromeOS* service) { std::vector<policy::DeviceLocalAccount> device_local_accounts = policy::GetDeviceLocalAccounts(CrosSettings::Get()); @@ -353,13 +355,14 @@ void KioskAppManager::AddApp(const std::string& app_id) { app_id, std::string())); - policy::SetDeviceLocalAccounts(CrosSettings::Get(), device_local_accounts); + policy::SetDeviceLocalAccounts(service, device_local_accounts); } -void KioskAppManager::RemoveApp(const std::string& app_id) { +void KioskAppManager::RemoveApp(const std::string& app_id, + OwnerSettingsServiceChromeOS* service) { // Resets auto launch app if it is the removed app. if (auto_launch_app_id_ == app_id) - SetAutoLaunchApp(std::string()); + SetAutoLaunchApp(std::string(), service); std::vector<policy::DeviceLocalAccount> device_local_accounts = policy::GetDeviceLocalAccounts(CrosSettings::Get()); @@ -377,7 +380,7 @@ void KioskAppManager::RemoveApp(const std::string& app_id) { } } - policy::SetDeviceLocalAccounts(CrosSettings::Get(), device_local_accounts); + policy::SetDeviceLocalAccounts(service, device_local_accounts); } void KioskAppManager::GetApps(Apps* apps) const { diff --git a/chrome/browser/chromeos/app_mode/kiosk_app_manager.h b/chrome/browser/chromeos/app_mode/kiosk_app_manager.h index aff5898..72d511c 100644 --- a/chrome/browser/chromeos/app_mode/kiosk_app_manager.h +++ b/chrome/browser/chromeos/app_mode/kiosk_app_manager.h @@ -38,6 +38,7 @@ class KioskAppData; class KioskAppExternalLoader; class KioskAppManagerObserver; class KioskExternalUpdater; +class OwnerSettingsServiceChromeOS; // KioskAppManager manages cached app data. class KioskAppManager : public KioskAppDataDelegate, @@ -121,7 +122,8 @@ class KioskAppManager : public KioskAppDataDelegate, std::string GetAutoLaunchApp() const; // Sets |app_id| as the app to auto launch at start up. - void SetAutoLaunchApp(const std::string& app_id); + void SetAutoLaunchApp(const std::string& app_id, + OwnerSettingsServiceChromeOS* service); // Returns true if there is a pending auto-launch request. bool IsAutoLaunchRequested() const; @@ -134,8 +136,9 @@ class KioskAppManager : public KioskAppDataDelegate, // Adds/removes a kiosk app by id. When removed, all locally cached data // will be removed as well. - void AddApp(const std::string& app_id); - void RemoveApp(const std::string& app_id); + void AddApp(const std::string& app_id, OwnerSettingsServiceChromeOS* service); + void RemoveApp(const std::string& app_id, + OwnerSettingsServiceChromeOS* service); // Gets info of all apps that have no meta data load error. void GetApps(Apps* apps) const; diff --git a/chrome/browser/chromeos/app_mode/kiosk_app_manager_browsertest.cc b/chrome/browser/chromeos/app_mode/kiosk_app_manager_browsertest.cc index 48498b6..16f85d0 100644 --- a/chrome/browser/chromeos/app_mode/kiosk_app_manager_browsertest.cc +++ b/chrome/browser/chromeos/app_mode/kiosk_app_manager_browsertest.cc @@ -7,6 +7,7 @@ #include "base/command_line.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" +#include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop.h" #include "base/path_service.h" #include "base/prefs/scoped_user_pref_update.h" @@ -15,9 +16,10 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/chromeos/app_mode/fake_cws.h" #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" +#include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h" #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" #include "chrome/browser/chromeos/policy/device_local_account.h" -#include "chrome/browser/chromeos/settings/cros_settings.h" +#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" #include "chrome/browser/ui/browser.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" @@ -165,7 +167,7 @@ class AppDataLoadWaiter : public KioskAppManagerObserver { class KioskAppManagerTest : public InProcessBrowserTest { public: - KioskAppManagerTest() : fake_cws_(new FakeCWS()) {} + KioskAppManagerTest() : settings_helper_(false), fake_cws_(new FakeCWS()) {} ~KioskAppManagerTest() override {} // InProcessBrowserTest overrides: @@ -195,8 +197,14 @@ class KioskAppManagerTest : public InProcessBrowserTest { // Restart the thread as the sandbox host process has already been spawned. embedded_test_server()->RestartThreadAndListen(); + + settings_helper_.ReplaceProvider(kAccountsPrefDeviceLocalAccounts); + owner_settings_service_ = + settings_helper_.CreateOwnerSettingsService(browser()->profile()); } + void TearDownOnMainThread() override { settings_helper_.RestoreProvider(); } + void SetUpInProcessBrowserTestFixture() override { InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); @@ -270,8 +278,8 @@ class KioskAppManagerTest : public InProcessBrowserTest { kAccountsPrefDeviceLocalAccountsKeyKioskAppId, app_id); device_local_accounts.Append(entry.release()); - CrosSettings::Get()->Set(kAccountsPrefDeviceLocalAccounts, - device_local_accounts); + owner_settings_service_->Set(kAccountsPrefDeviceLocalAccounts, + device_local_accounts); } bool GetCachedCrx(const std::string& app_id, @@ -289,7 +297,7 @@ class KioskAppManagerTest : public InProcessBrowserTest { fake_cws_->SetUpdateCrx(id, crx_file_name, version); AppDataLoadWaiter waiter(manager(), 3); - manager()->AddApp(id); + manager()->AddApp(id, owner_settings_service_.get()); waiter.Wait(); EXPECT_TRUE(waiter.loaded()); @@ -342,6 +350,10 @@ class KioskAppManagerTest : public InProcessBrowserTest { KioskAppManager* manager() const { return KioskAppManager::Get(); } FakeCWS* fake_cws() { return fake_cws_.get(); } + protected: + ScopedCrosSettingsTestHelper settings_helper_; + scoped_ptr<FakeOwnerSettingsService> owner_settings_service_; + private: base::ScopedTempDir temp_dir_; scoped_ptr<FakeCWS> fake_cws_; @@ -353,12 +365,12 @@ IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, Basic) { // Add a couple of apps. Use "fake_app_x" that do not have data on the test // server to avoid pending data loads that could be lingering on tear down and // cause DCHECK failure in utility_process_host_impl.cc. - manager()->AddApp("fake_app_1"); - manager()->AddApp("fake_app_2"); + manager()->AddApp("fake_app_1", owner_settings_service_.get()); + manager()->AddApp("fake_app_2", owner_settings_service_.get()); EXPECT_EQ("fake_app_1,fake_app_2", GetAppIds()); // Set an auto launch app. - manager()->SetAutoLaunchApp("fake_app_1"); + manager()->SetAutoLaunchApp("fake_app_1", owner_settings_service_.get()); EXPECT_EQ("fake_app_1", manager()->GetAutoLaunchApp()); // Make sure that if an app was auto launched with zero delay, it is reflected @@ -372,7 +384,7 @@ IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, Basic) { EXPECT_TRUE(app.was_auto_launched_with_zero_delay); // Clear the auto launch app. - manager()->SetAutoLaunchApp(""); + manager()->SetAutoLaunchApp("", owner_settings_service_.get()); EXPECT_EQ("", manager()->GetAutoLaunchApp()); EXPECT_FALSE(manager()->IsAutoLaunchEnabled()); @@ -382,7 +394,7 @@ IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, Basic) { EXPECT_TRUE(app.was_auto_launched_with_zero_delay); // Set another auto launch app. - manager()->SetAutoLaunchApp("fake_app_2"); + manager()->SetAutoLaunchApp("fake_app_2", owner_settings_service_.get()); EXPECT_EQ("fake_app_2", manager()->GetAutoLaunchApp()); // Check auto launch permissions. @@ -391,24 +403,24 @@ IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, Basic) { EXPECT_TRUE(manager()->IsAutoLaunchEnabled()); // Remove the auto launch app. - manager()->RemoveApp("fake_app_2"); + manager()->RemoveApp("fake_app_2", owner_settings_service_.get()); EXPECT_EQ("fake_app_1", GetAppIds()); EXPECT_EQ("", manager()->GetAutoLaunchApp()); // Add the just removed auto launch app again and it should no longer be // the auto launch app. - manager()->AddApp("fake_app_2"); + manager()->AddApp("fake_app_2", owner_settings_service_.get()); EXPECT_EQ("", manager()->GetAutoLaunchApp()); - manager()->RemoveApp("fake_app_2"); + manager()->RemoveApp("fake_app_2", owner_settings_service_.get()); EXPECT_EQ("fake_app_1", GetAppIds()); // Set a none exist app as auto launch. - manager()->SetAutoLaunchApp("none_exist_app"); + manager()->SetAutoLaunchApp("none_exist_app", owner_settings_service_.get()); EXPECT_EQ("", manager()->GetAutoLaunchApp()); EXPECT_FALSE(manager()->IsAutoLaunchEnabled()); // Add an existing app again. - manager()->AddApp("fake_app_1"); + manager()->AddApp("fake_app_1", owner_settings_service_.get()); EXPECT_EQ("fake_app_1", GetAppIds()); } @@ -473,7 +485,7 @@ IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, UpdateAppDataFromProfile) { IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, BadApp) { AppDataLoadWaiter waiter(manager(), 2); - manager()->AddApp("unknown_app"); + manager()->AddApp("unknown_app", owner_settings_service_.get()); waiter.Wait(); EXPECT_FALSE(waiter.loaded()); EXPECT_EQ("", GetAppIds()); @@ -484,7 +496,7 @@ IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, GoodApp) { // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/detail/app_1 fake_cws()->SetNoUpdate("app_1"); AppDataLoadWaiter waiter(manager(), 2); - manager()->AddApp("app_1"); + manager()->AddApp("app_1", owner_settings_service_.get()); waiter.Wait(); EXPECT_TRUE(waiter.loaded()); @@ -533,7 +545,7 @@ IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, RemoveApp) { EXPECT_EQ("1.0.0", version); // Remove the app now. - manager()->RemoveApp(kTestLocalFsKioskApp); + manager()->RemoveApp(kTestLocalFsKioskApp, owner_settings_service_.get()); content::RunAllBlockingPoolTasksUntilIdle(); manager()->GetApps(&apps); ASSERT_EQ(0u, apps.size()); @@ -615,7 +627,7 @@ IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, UpdateAndRemoveApp) { EXPECT_TRUE(base::PathExists(v2_crx_path)); // Remove the app now. - manager()->RemoveApp(kTestLocalFsKioskApp); + manager()->RemoveApp(kTestLocalFsKioskApp, owner_settings_service_.get()); content::RunAllBlockingPoolTasksUntilIdle(); manager()->GetApps(&apps); ASSERT_EQ(0u, apps.size()); diff --git a/chrome/browser/chromeos/attestation/attestation_policy_observer_unittest.cc b/chrome/browser/chromeos/attestation/attestation_policy_observer_unittest.cc index 61fa81f..ebb0fd0 100644 --- a/chrome/browser/chromeos/attestation/attestation_policy_observer_unittest.cc +++ b/chrome/browser/chromeos/attestation/attestation_policy_observer_unittest.cc @@ -10,9 +10,7 @@ #include "chrome/browser/chromeos/attestation/attestation_key_payload.pb.h" #include "chrome/browser/chromeos/attestation/attestation_policy_observer.h" #include "chrome/browser/chromeos/attestation/fake_certificate.h" -#include "chrome/browser/chromeos/settings/cros_settings.h" -#include "chrome/browser/chromeos/settings/device_settings_service.h" -#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" +#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" #include "chromeos/attestation/mock_attestation_flow.h" #include "chromeos/dbus/mock_cryptohome_client.h" #include "chromeos/settings/cros_settings_names.h" @@ -80,23 +78,11 @@ class AttestationPolicyObserverTest : public ::testing::Test { public: AttestationPolicyObserverTest() : ui_thread_(content::BrowserThread::UI, &message_loop_) { - // Remove the real DeviceSettingsProvider and replace it with a stub. - CrosSettings* cros_settings = CrosSettings::Get(); - device_settings_provider_ = - cros_settings->GetProvider(kDeviceAttestationEnabled); - cros_settings->RemoveSettingsProvider(device_settings_provider_); - cros_settings->AddSettingsProvider(&stub_settings_provider_); - cros_settings->SetBoolean(kDeviceAttestationEnabled, true); + settings_helper_.ReplaceProvider(kDeviceAttestationEnabled); + settings_helper_.SetBoolean(kDeviceAttestationEnabled, true); policy_client_.SetDMToken("fake_dm_token"); } - virtual ~AttestationPolicyObserverTest() { - // Restore the real DeviceSettingsProvider. - CrosSettings* cros_settings = CrosSettings::Get(); - cros_settings->RemoveSettingsProvider(&stub_settings_provider_); - cros_settings->AddSettingsProvider(device_settings_provider_); - } - protected: enum MockOptions { MOCK_KEY_EXISTS = 1, // Configure so a certified key exists. @@ -168,18 +154,14 @@ class AttestationPolicyObserverTest : public ::testing::Test { base::MessageLoopForUI message_loop_; content::TestBrowserThread ui_thread_; - ScopedTestDeviceSettingsService test_device_settings_service_; - ScopedTestCrosSettings test_cros_settings_; - CrosSettingsProvider* device_settings_provider_; - StubCrosSettingsProvider stub_settings_provider_; + ScopedCrosSettingsTestHelper settings_helper_; StrictMock<MockCryptohomeClient> cryptohome_client_; StrictMock<MockAttestationFlow> attestation_flow_; StrictMock<policy::MockCloudPolicyClient> policy_client_; }; TEST_F(AttestationPolicyObserverTest, FeatureDisabled) { - CrosSettings* cros_settings = CrosSettings::Get(); - cros_settings->SetBoolean(kDeviceAttestationEnabled, false); + settings_helper_.SetBoolean(kDeviceAttestationEnabled, false); Run(); } diff --git a/chrome/browser/chromeos/attestation/platform_verification_flow_unittest.cc b/chrome/browser/chromeos/attestation/platform_verification_flow_unittest.cc index a3101e5..5319ddf 100644 --- a/chrome/browser/chromeos/attestation/platform_verification_flow_unittest.cc +++ b/chrome/browser/chromeos/attestation/platform_verification_flow_unittest.cc @@ -11,9 +11,7 @@ #include "chrome/browser/chromeos/attestation/fake_certificate.h" #include "chrome/browser/chromeos/attestation/platform_verification_flow.h" #include "chrome/browser/chromeos/login/users/mock_user_manager.h" -#include "chrome/browser/chromeos/settings/cros_settings.h" -#include "chrome/browser/chromeos/settings/device_settings_service.h" -#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" +#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" #include "chrome/browser/profiles/profile_impl.h" #include "chrome/common/pref_names.h" #include "chromeos/attestation/mock_attestation_flow.h" @@ -153,20 +151,8 @@ class PlatformVerificationFlowTest : public ::testing::Test { callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback, base::Unretained(this)); - // Configure the global cros_settings. - CrosSettings* cros_settings = CrosSettings::Get(); - device_settings_provider_ = - cros_settings->GetProvider(kAttestationForContentProtectionEnabled); - cros_settings->RemoveSettingsProvider(device_settings_provider_); - cros_settings->AddSettingsProvider(&stub_settings_provider_); - cros_settings->SetBoolean(kAttestationForContentProtectionEnabled, true); - } - - void TearDown() { - // Restore the real DeviceSettingsProvider. - CrosSettings* cros_settings = CrosSettings::Get(); - cros_settings->RemoveSettingsProvider(&stub_settings_provider_); - cros_settings->AddSettingsProvider(device_settings_provider_); + settings_helper_.ReplaceProvider(kAttestationForContentProtectionEnabled); + settings_helper_.SetBoolean(kAttestationForContentProtectionEnabled, true); } void ExpectAttestationFlow() { @@ -239,10 +225,7 @@ class PlatformVerificationFlowTest : public ::testing::Test { cryptohome::MockAsyncMethodCaller mock_async_caller_; CustomFakeCryptohomeClient fake_cryptohome_client_; FakeDelegate fake_delegate_; - CrosSettingsProvider* device_settings_provider_; - StubCrosSettingsProvider stub_settings_provider_; - ScopedTestDeviceSettingsService test_device_settings_service_; - ScopedTestCrosSettings test_cros_settings_; + ScopedCrosSettingsTestHelper settings_helper_; scoped_refptr<PlatformVerificationFlow> verifier_; // Controls result of FakeGetCertificate. @@ -279,8 +262,7 @@ TEST_F(PlatformVerificationFlowTest, NotPermittedByUser) { } TEST_F(PlatformVerificationFlowTest, FeatureDisabledByPolicy) { - CrosSettings::Get()->SetBoolean(kAttestationForContentProtectionEnabled, - false); + settings_helper_.SetBoolean(kAttestationForContentProtectionEnabled, false); verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); base::RunLoop().RunUntilIdle(); EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); diff --git a/chrome/browser/chromeos/login/auth/cryptohome_authenticator_unittest.cc b/chrome/browser/chromeos/login/auth/cryptohome_authenticator_unittest.cc index c3dcd6e..2607ace 100644 --- a/chrome/browser/chromeos/login/auth/cryptohome_authenticator_unittest.cc +++ b/chrome/browser/chromeos/login/auth/cryptohome_authenticator_unittest.cc @@ -22,7 +22,7 @@ #include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" -#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" +#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile_manager.h" @@ -434,15 +434,9 @@ TEST_F(CryptohomeAuthenticatorTest, ResolveOwnerNeededFailedMount) { // and succeeded but we are in safe mode and the current user is not owner. state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); SetOwnerState(false, false); - // Remove the real DeviceSettingsProvider and replace it with a stub. - CrosSettingsProvider* device_settings_provider = - CrosSettings::Get()->GetProvider(chromeos::kReportDeviceVersionInfo); - EXPECT_TRUE(device_settings_provider != NULL); - EXPECT_TRUE( - CrosSettings::Get()->RemoveSettingsProvider(device_settings_provider)); - StubCrosSettingsProvider stub_settings_provider; - CrosSettings::Get()->AddSettingsProvider(&stub_settings_provider); - CrosSettings::Get()->SetBoolean(kPolicyMissingMitigationMode, true); + ScopedCrosSettingsTestHelper settings_helper(false); + settings_helper.ReplaceProvider(kPolicyMissingMitigationMode); + settings_helper.SetBoolean(kPolicyMissingMitigationMode, true); // Initialize login state for this test to verify the login state is changed // to SAFE_MODE. @@ -468,9 +462,6 @@ TEST_F(CryptohomeAuthenticatorTest, ResolveOwnerNeededFailedMount) { // Unset global objects used by this test. fake_cryptohome_client_->set_unmount_result(true); LoginState::Shutdown(); - EXPECT_TRUE( - CrosSettings::Get()->RemoveSettingsProvider(&stub_settings_provider)); - CrosSettings::Get()->AddSettingsProvider(device_settings_provider); } // Test the case that login switches to SafeMode and the Owner logs in, which @@ -493,15 +484,9 @@ TEST_F(CryptohomeAuthenticatorTest, ResolveOwnerNeededSuccess) { // and succeeded but we are in safe mode and the current user is not owner. state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); SetOwnerState(false, false); - // Remove the real DeviceSettingsProvider and replace it with a stub. - CrosSettingsProvider* device_settings_provider = - CrosSettings::Get()->GetProvider(chromeos::kReportDeviceVersionInfo); - EXPECT_TRUE(device_settings_provider != NULL); - EXPECT_TRUE( - CrosSettings::Get()->RemoveSettingsProvider(device_settings_provider)); - StubCrosSettingsProvider stub_settings_provider; - CrosSettings::Get()->AddSettingsProvider(&stub_settings_provider); - CrosSettings::Get()->SetBoolean(kPolicyMissingMitigationMode, true); + ScopedCrosSettingsTestHelper settings_helper(false); + settings_helper.ReplaceProvider(kPolicyMissingMitigationMode); + settings_helper.SetBoolean(kPolicyMissingMitigationMode, true); // Initialize login state for this test to verify the login state is changed // to SAFE_MODE. @@ -526,9 +511,6 @@ TEST_F(CryptohomeAuthenticatorTest, ResolveOwnerNeededSuccess) { // Unset global objects used by this test. fake_cryptohome_client_->set_unmount_result(true); LoginState::Shutdown(); - EXPECT_TRUE( - CrosSettings::Get()->RemoveSettingsProvider(&stub_settings_provider)); - CrosSettings::Get()->AddSettingsProvider(device_settings_provider); } TEST_F(CryptohomeAuthenticatorTest, DriveFailedMount) { diff --git a/chrome/browser/chromeos/login/kiosk_browsertest.cc b/chrome/browser/chromeos/login/kiosk_browsertest.cc index b583daf..ad6d36b 100644 --- a/chrome/browser/chromeos/login/kiosk_browsertest.cc +++ b/chrome/browser/chromeos/login/kiosk_browsertest.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <vector> + #include "ash/desktop_background/desktop_background_controller.h" #include "ash/desktop_background/desktop_background_controller_observer.h" #include "ash/shell.h" @@ -14,11 +16,9 @@ #include "base/path_service.h" #include "base/prefs/pref_service.h" #include "base/run_loop.h" -#include "base/single_thread_task_runner.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" #include "base/synchronization/lock.h" -#include "base/thread_task_runner_handle.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chromeos/app_mode/fake_cws.h" #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" @@ -35,13 +35,13 @@ #include "chrome/browser/chromeos/login/users/mock_user_manager.h" #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" #include "chrome/browser/chromeos/login/wizard_controller.h" +#include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h" +#include "chrome/browser/chromeos/policy/device_local_account.h" #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" -#include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" #include "chrome/browser/chromeos/profiles/profile_helper.h" -#include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h" -#include "chrome/browser/chromeos/settings/device_settings_service.h" +#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/profiles/profile_impl.h" #include "chrome/browser/profiles/profile_manager.h" @@ -410,68 +410,6 @@ class AppDataLoadWaiter : public KioskAppManagerObserver { DISALLOW_COPY_AND_ASSIGN(AppDataLoadWaiter); }; -class CrosSettingsPermanentlyUntrustedMaker : - public DeviceSettingsService::Observer { - public: - CrosSettingsPermanentlyUntrustedMaker(); - - // DeviceSettingsService::Observer: - void OwnershipStatusChanged() override; - void DeviceSettingsUpdated() override; - void OnDeviceSettingsServiceShutdown() override; - - private: - bool untrusted_check_running_; - base::RunLoop run_loop_; - - void CheckIfUntrusted(); - - DISALLOW_COPY_AND_ASSIGN(CrosSettingsPermanentlyUntrustedMaker); -}; - -CrosSettingsPermanentlyUntrustedMaker::CrosSettingsPermanentlyUntrustedMaker() - : untrusted_check_running_(false) { - DeviceSettingsService::Get()->AddObserver(this); - - policy::DevicePolicyCrosTestHelper().InstallOwnerKey(); - DeviceSettingsService::Get()->OwnerKeySet(true); - - run_loop_.Run(); -} - -void CrosSettingsPermanentlyUntrustedMaker::OwnershipStatusChanged() { - if (untrusted_check_running_) - return; - - base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, - base::Bind(&CrosSettingsPermanentlyUntrustedMaker::CheckIfUntrusted, - base::Unretained(this))); -} - -void CrosSettingsPermanentlyUntrustedMaker::DeviceSettingsUpdated() { -} - -void CrosSettingsPermanentlyUntrustedMaker::OnDeviceSettingsServiceShutdown() { -} - -void CrosSettingsPermanentlyUntrustedMaker::CheckIfUntrusted() { - untrusted_check_running_ = true; - const CrosSettingsProvider::TrustedStatus trusted_status = - CrosSettings::Get()->PrepareTrustedValues( - base::Bind(&CrosSettingsPermanentlyUntrustedMaker::CheckIfUntrusted, - base::Unretained(this))); - if (trusted_status == CrosSettingsProvider::TEMPORARILY_UNTRUSTED) - return; - untrusted_check_running_ = false; - - if (trusted_status == CrosSettingsProvider::TRUSTED) - return; - - DeviceSettingsService::Get()->RemoveObserver(this); - run_loop_.Quit(); -} - } // namespace // Boolean parameter is used to run this test for webview (true) and for @@ -479,8 +417,10 @@ void CrosSettingsPermanentlyUntrustedMaker::CheckIfUntrusted() { class KioskTest : public OobeBaseTest, public testing::WithParamInterface<bool> { public: - KioskTest() : use_consumer_kiosk_mode_(true), - fake_cws_(new FakeCWS) { + KioskTest() + : settings_helper_(false), + use_consumer_kiosk_mode_(true), + fake_cws_(new FakeCWS) { set_use_webview(GetParam()); set_exit_when_last_browser_closes(false); } @@ -511,9 +451,13 @@ class KioskTest : public OobeBaseTest, // Needed to avoid showing Gaia screen instead of owner signin for // consumer network down test cases. StartupUtils::MarkDeviceRegistered(base::Closure()); + settings_helper_.ReplaceProvider(kAccountsPrefDeviceLocalAccounts); + owner_settings_service_ = settings_helper_.CreateOwnerSettingsService( + ProfileManager::GetPrimaryUserProfile()); } void TearDownOnMainThread() override { + settings_helper_.RestoreProvider(); AppLaunchController::SetNetworkTimeoutCallbackForTesting(NULL); AppLaunchSigninScreen::SetUserManagerForTesting(NULL); @@ -541,8 +485,9 @@ class KioskTest : public OobeBaseTest, SetupTestAppUpdateCheck(); // Remove then add to ensure NOTIFICATION_KIOSK_APPS_LOADED fires. - KioskAppManager::Get()->RemoveApp(test_app_id_); - KioskAppManager::Get()->AddApp(test_app_id_); + KioskAppManager::Get()->RemoveApp(test_app_id_, + owner_settings_service_.get()); + KioskAppManager::Get()->AddApp(test_app_id_, owner_settings_service_.get()); } void FireKioskAppSettingsChanged() { @@ -559,8 +504,9 @@ class KioskTest : public OobeBaseTest, void ReloadAutolaunchKioskApps() { SetupTestAppUpdateCheck(); - KioskAppManager::Get()->AddApp(test_app_id_); - KioskAppManager::Get()->SetAutoLaunchApp(test_app_id_); + KioskAppManager::Get()->AddApp(test_app_id_, owner_settings_service_.get()); + KioskAppManager::Get()->SetAutoLaunchApp(test_app_id_, + owner_settings_service_.get()); } void StartUIForAppLaunch() { @@ -804,6 +750,9 @@ class KioskTest : public OobeBaseTest, use_consumer_kiosk_mode_ = use; } + ScopedCrosSettingsTestHelper settings_helper_; + scoped_ptr<FakeOwnerSettingsService> owner_settings_service_; + private: bool use_consumer_kiosk_mode_; std::string test_app_id_; @@ -994,7 +943,7 @@ IN_PROC_BROWSER_TEST_P(KioskTest, LaunchAppUserCancel) { OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH); splash_waiter.Wait(); - CrosSettings::Get()->SetBoolean( + settings_helper_.SetBoolean( kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled, true); content::WindowedNotificationObserver signal( chrome::NOTIFICATION_APP_TERMINATING, @@ -1218,7 +1167,8 @@ IN_PROC_BROWSER_TEST_P(KioskTest, DoNotLaunchWhenUntrusted) { SimulateNetworkOnline(); // Make cros settings untrusted. - CrosSettingsPermanentlyUntrustedMaker(); + settings_helper_.SetTrustedStatus( + CrosSettingsProvider::PERMANENTLY_UNTRUSTED); // Check that the attempt to start a kiosk app fails with an error. LaunchApp(test_app_id(), false); @@ -1257,7 +1207,8 @@ IN_PROC_BROWSER_TEST_P(KioskTest, NoConsumerAutoLaunchWhenUntrusted) { base::FundamentalValue(true)); // Make cros settings untrusted. - CrosSettingsPermanentlyUntrustedMaker(); + settings_helper_.SetTrustedStatus( + CrosSettingsProvider::PERMANENTLY_UNTRUSTED); // Check that the attempt to auto-launch a kiosk app fails with an error. OobeScreenWaiter(OobeDisplay::SCREEN_ERROR_MESSAGE).Wait(); @@ -1281,7 +1232,8 @@ IN_PROC_BROWSER_TEST_P(KioskTest, NoEnterpriseAutoLaunchWhenUntrusted) { SimulateNetworkOnline(); // Make cros settings untrusted. - CrosSettingsPermanentlyUntrustedMaker(); + settings_helper_.SetTrustedStatus( + CrosSettingsProvider::PERMANENTLY_UNTRUSTED); // Trigger the code that handles auto-launch on enterprise devices. This would // normally be called from ShowLoginWizard(), which runs so early that it is @@ -1313,7 +1265,19 @@ class KioskUpdateTest : public KioskTest { KioskTest::TearDown(); } - void SetUpOnMainThread() override { KioskTest::SetUpOnMainThread(); } + void SetUpOnMainThread() override { + // For update tests, we cache the app in the PRE part, and then we load it + // in the test, so we need to both store the apps list on teardown (so that + // the app manager would accept existing files in its extension cache on the + // next startup) and copy the list to our stub settings provider as well. + settings_helper_.CopyStoredValue(kAccountsPrefDeviceLocalAccounts); + KioskTest::SetUpOnMainThread(); + } + + void TearDownOnMainThread() override { + settings_helper_.StoreCachedDeviceSetting(kAccountsPrefDeviceLocalAccounts); + KioskTest::TearDownOnMainThread(); + } void PreCacheApp(const std::string& app_id, const std::string& version, @@ -1755,8 +1719,9 @@ class KioskEnterpriseTest : public KioskTest { } void SetUpInProcessBrowserTestFixture() override { - device_policy_test_helper_.MarkAsEnterpriseOwned(); - device_policy_test_helper_.InstallOwnerKey(); + policy::DevicePolicyCrosTestHelper::MarkAsEnterpriseOwnedBy( + kTestOwnerEmail); + settings_helper_.SetCurrentUserIsOwner(false); KioskTest::SetUpInProcessBrowserTestFixture(); } @@ -1799,41 +1764,21 @@ class KioskEnterpriseTest : public KioskTest { base::RunLoop().RunUntilIdle(); } - static void StorePolicyCallback(const base::Closure& callback, bool result) { - ASSERT_TRUE(result); - callback.Run(); - } - void ConfigureKioskAppInPolicy(const std::string& account_id, const std::string& app_id, const std::string& update_url) { - em::DeviceLocalAccountsProto* accounts = - device_policy_test_helper_.device_policy()->payload() - .mutable_device_local_accounts(); - em::DeviceLocalAccountInfoProto* account = accounts->add_account(); - account->set_account_id(account_id); - account->set_type( - em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_KIOSK_APP); - account->mutable_kiosk_app()->set_app_id(app_id); - if (!update_url.empty()) - account->mutable_kiosk_app()->set_update_url(update_url); - accounts->set_auto_login_id(account_id); - em::PolicyData& policy_data = - device_policy_test_helper_.device_policy()->policy_data(); - policy_data.set_service_account_identity(kTestEnterpriseServiceAccountId); - device_policy_test_helper_.device_policy()->Build(); - - base::RunLoop run_loop; - DBusThreadManager::Get()->GetSessionManagerClient()->StoreDevicePolicy( - device_policy_test_helper_.device_policy()->GetBlob(), - base::Bind(&KioskEnterpriseTest::StorePolicyCallback, - run_loop.QuitClosure())); - run_loop.Run(); - - DeviceSettingsService::Get()->Load(); - } - - policy::DevicePolicyCrosTestHelper device_policy_test_helper_; + settings_helper_.SetCurrentUserIsOwner(true); + std::vector<policy::DeviceLocalAccount> accounts; + accounts.push_back( + policy::DeviceLocalAccount(policy::DeviceLocalAccount::TYPE_KIOSK_APP, + account_id, app_id, update_url)); + policy::SetDeviceLocalAccounts(owner_settings_service_.get(), accounts); + settings_helper_.SetString(kAccountsPrefDeviceLocalAccountAutoLoginId, + account_id); + settings_helper_.SetString(kServiceAccountIdentity, + kTestEnterpriseServiceAccountId); + settings_helper_.SetCurrentUserIsOwner(false); + } private: DISALLOW_COPY_AND_ASSIGN(KioskEnterpriseTest); diff --git a/chrome/browser/chromeos/login/users/user_manager_unittest.cc b/chrome/browser/chromeos/login/users/user_manager_unittest.cc index 3765efa..b2e6368 100644 --- a/chrome/browser/chromeos/login/users/user_manager_unittest.cc +++ b/chrome/browser/chromeos/login/users/user_manager_unittest.cc @@ -11,14 +11,11 @@ #include "base/memory/scoped_ptr.h" #include "base/prefs/pref_service.h" #include "base/run_loop.h" -#include "base/values.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/chromeos/login/users/chrome_user_manager_impl.h" #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" -#include "chrome/browser/chromeos/settings/cros_settings.h" -#include "chrome/browser/chromeos/settings/device_settings_service.h" -#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" +#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/test/base/scoped_testing_local_state.h" #include "chrome/test/base/testing_browser_process.h" @@ -26,7 +23,6 @@ #include "chromeos/chromeos_switches.h" #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/settings/cros_settings_names.h" -#include "chromeos/settings/cros_settings_provider.h" #include "components/user_manager/user.h" #include "components/user_manager/user_manager.h" #include "content/public/common/content_switches.h" @@ -50,7 +46,6 @@ class UnittestProfileManager : public ::ProfileManagerWithoutInit { } }; - class UserManagerTest : public testing::Test { protected: void SetUp() override { @@ -59,15 +54,7 @@ class UserManagerTest : public testing::Test { command_line.AppendSwitch( chromeos::switches::kIgnoreUserProfileMappingForTests); - cros_settings_ = CrosSettings::Get(); - - // Replace the real DeviceSettingsProvider with a stub. - device_settings_provider_ = - cros_settings_->GetProvider(chromeos::kReportDeviceVersionInfo); - EXPECT_TRUE(device_settings_provider_); - EXPECT_TRUE( - cros_settings_->RemoveSettingsProvider(device_settings_provider_)); - cros_settings_->AddSettingsProvider(&stub_settings_provider_); + settings_helper_.ReplaceProvider(kDeviceOwner); // Populate the stub DeviceSettingsProvider with valid values. SetDeviceSettings(false, "", false); @@ -90,11 +77,6 @@ class UserManagerTest : public testing::Test { // Unregister the in-memory local settings instance. local_state_.reset(); - // Restore the real DeviceSettingsProvider. - EXPECT_TRUE( - cros_settings_->RemoveSettingsProvider(&stub_settings_provider_)); - cros_settings_->AddSettingsProvider(device_settings_provider_); - // Shut down the DeviceSettingsService. DeviceSettingsService::Get()->UnsetSessionManager(); TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); @@ -140,14 +122,11 @@ class UserManagerTest : public testing::Test { void SetDeviceSettings(bool ephemeral_users_enabled, const std::string &owner, bool supervised_users_enabled) { - base::FundamentalValue - ephemeral_users_enabled_value(ephemeral_users_enabled); - stub_settings_provider_.Set(kAccountsPrefEphemeralUsersEnabled, - ephemeral_users_enabled_value); - base::StringValue owner_value(owner); - stub_settings_provider_.Set(kDeviceOwner, owner_value); - stub_settings_provider_.Set(kAccountsPrefSupervisedUsersEnabled, - base::FundamentalValue(supervised_users_enabled)); + settings_helper_.SetBoolean(kAccountsPrefEphemeralUsersEnabled, + ephemeral_users_enabled); + settings_helper_.SetString(kDeviceOwner, owner); + settings_helper_.SetBoolean(kAccountsPrefSupervisedUsersEnabled, + supervised_users_enabled); } void RetrieveTrustedDevicePolicies() { @@ -157,14 +136,9 @@ class UserManagerTest : public testing::Test { protected: content::TestBrowserThreadBundle thread_bundle_; - CrosSettings* cros_settings_; - CrosSettingsProvider* device_settings_provider_; - StubCrosSettingsProvider stub_settings_provider_; + ScopedCrosSettingsTestHelper settings_helper_; scoped_ptr<ScopedTestingLocalState> local_state_; - ScopedTestDeviceSettingsService test_device_settings_service_; - ScopedTestCrosSettings test_cros_settings_; - scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; base::ScopedTempDir temp_dir_; }; diff --git a/chrome/browser/chromeos/ownership/fake_owner_settings_service.cc b/chrome/browser/chromeos/ownership/fake_owner_settings_service.cc index b515447..8042251 100644 --- a/chrome/browser/chromeos/ownership/fake_owner_settings_service.cc +++ b/chrome/browser/chromeos/ownership/fake_owner_settings_service.cc @@ -4,13 +4,27 @@ #include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h" +#include "base/logging.h" +#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" +#include "components/ownership/mock_owner_key_util.h" + namespace chromeos { +FakeOwnerSettingsService::FakeOwnerSettingsService(Profile* profile) + : OwnerSettingsServiceChromeOS(nullptr, + profile, + new ownership::MockOwnerKeyUtil()), + set_management_settings_result_(true), + settings_provider_(nullptr) { +} + FakeOwnerSettingsService::FakeOwnerSettingsService( Profile* profile, - const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util) + const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util, + StubCrosSettingsProvider* provider) : OwnerSettingsServiceChromeOS(nullptr, profile, owner_key_util), - set_management_settings_result_(true) { + set_management_settings_result_(true), + settings_provider_(provider) { } FakeOwnerSettingsService::~FakeOwnerSettingsService() { @@ -23,4 +37,11 @@ void FakeOwnerSettingsService::SetManagementSettings( callback.Run(set_management_settings_result_); } +bool FakeOwnerSettingsService::Set(const std::string& setting, + const base::Value& value) { + CHECK(settings_provider_); + settings_provider_->Set(setting, value); + return true; +} + } // namespace chromeos diff --git a/chrome/browser/chromeos/ownership/fake_owner_settings_service.h b/chrome/browser/chromeos/ownership/fake_owner_settings_service.h index bed4d06..3f785c1 100644 --- a/chrome/browser/chromeos/ownership/fake_owner_settings_service.h +++ b/chrome/browser/chromeos/ownership/fake_owner_settings_service.h @@ -17,11 +17,15 @@ class OwnerKeyUtil; namespace chromeos { +class StubCrosSettingsProvider; + class FakeOwnerSettingsService : public OwnerSettingsServiceChromeOS { public: + explicit FakeOwnerSettingsService(Profile* profile); FakeOwnerSettingsService( Profile* profile, - const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util); + const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util, + StubCrosSettingsProvider* provider); ~FakeOwnerSettingsService() override; void set_set_management_settings_result(bool success) { @@ -36,10 +40,12 @@ class FakeOwnerSettingsService : public OwnerSettingsServiceChromeOS { void SetManagementSettings( const ManagementSettings& settings, const OnManagementSettingsSetCallback& callback) override; + bool Set(const std::string& setting, const base::Value& value) override; private: bool set_management_settings_result_; ManagementSettings last_settings_; + StubCrosSettingsProvider* settings_provider_; DISALLOW_COPY_AND_ASSIGN(FakeOwnerSettingsService); }; diff --git a/chrome/browser/chromeos/ownership/owner_settings_service_chromeos.cc b/chrome/browser/chromeos/ownership/owner_settings_service_chromeos.cc index bac0fba..a96f0aa 100644 --- a/chrome/browser/chromeos/ownership/owner_settings_service_chromeos.cc +++ b/chrome/browser/chromeos/ownership/owner_settings_service_chromeos.cc @@ -174,6 +174,7 @@ bool CheckManagementModeTransition(policy::ManagementMode current_mode, NOTREACHED(); return false; } + } // namespace OwnerSettingsServiceChromeOS::ManagementSettings::ManagementSettings() { diff --git a/chrome/browser/chromeos/policy/consumer_unenrollment_handler_unittest.cc b/chrome/browser/chromeos/policy/consumer_unenrollment_handler_unittest.cc index cacf396..1a9ba8b 100644 --- a/chrome/browser/chromeos/policy/consumer_unenrollment_handler_unittest.cc +++ b/chrome/browser/chromeos/policy/consumer_unenrollment_handler_unittest.cc @@ -59,9 +59,8 @@ class ConsumerUnenrollmentHandlerTest base::ThreadTaskRunnerHandle::Get())); // Set up FakeOwnerSettingsService. - fake_owner_settings_service_.reset( - new chromeos::FakeOwnerSettingsService( - profile_.get(), owner_key_util_)); + fake_owner_settings_service_.reset(new chromeos::FakeOwnerSettingsService( + profile_.get(), owner_key_util_, nullptr)); chromeos::OwnerSettingsServiceChromeOS::ManagementSettings settings; settings.management_mode = policy::MANAGEMENT_MODE_CONSUMER_MANAGED; settings.request_token = "fake_request_token"; diff --git a/chrome/browser/chromeos/policy/device_local_account.cc b/chrome/browser/chromeos/policy/device_local_account.cc index 80b89b2..63c7a14 100644 --- a/chrome/browser/chromeos/policy/device_local_account.cc +++ b/chrome/browser/chromeos/policy/device_local_account.cc @@ -12,6 +12,7 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" #include "base/values.h" +#include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" #include "chrome/browser/chromeos/settings/cros_settings.h" #include "chromeos/login/user_names.h" #include "chromeos/settings/cros_settings_names.h" @@ -91,9 +92,8 @@ bool IsDeviceLocalAccountUser(const std::string& user_id, return true; } -void SetDeviceLocalAccounts( - chromeos::CrosSettings* cros_settings, - const std::vector<DeviceLocalAccount>& accounts) { +void SetDeviceLocalAccounts(chromeos::OwnerSettingsServiceChromeOS* service, + const std::vector<DeviceLocalAccount>& accounts) { base::ListValue list; for (std::vector<DeviceLocalAccount>::const_iterator it = accounts.begin(); it != accounts.end(); ++it) { @@ -117,7 +117,7 @@ void SetDeviceLocalAccounts( list.Append(entry.release()); } - cros_settings->Set(chromeos::kAccountsPrefDeviceLocalAccounts, list); + service->Set(chromeos::kAccountsPrefDeviceLocalAccounts, list); } std::vector<DeviceLocalAccount> GetDeviceLocalAccounts( diff --git a/chrome/browser/chromeos/policy/device_local_account.h b/chrome/browser/chromeos/policy/device_local_account.h index 69a7480..8827119 100644 --- a/chrome/browser/chromeos/policy/device_local_account.h +++ b/chrome/browser/chromeos/policy/device_local_account.h @@ -10,6 +10,7 @@ namespace chromeos { class CrosSettings; +class OwnerSettingsServiceChromeOS; } namespace policy { @@ -64,12 +65,11 @@ std::string GenerateDeviceLocalAccountUserId(const std::string& account_id, bool IsDeviceLocalAccountUser(const std::string& user_id, DeviceLocalAccount::Type* type); -// Stores a list of device-local accounts in |cros_settings|. The accounts are -// stored as a list of dictionaries with each dictionary containing the -// information about one |DeviceLocalAccount|. -void SetDeviceLocalAccounts( - chromeos::CrosSettings* cros_settings, - const std::vector<DeviceLocalAccount>& accounts); +// Stores a list of device-local accounts in |service|. The accounts are stored +// as a list of dictionaries with each dictionary containing the information +// about one |DeviceLocalAccount|. +void SetDeviceLocalAccounts(chromeos::OwnerSettingsServiceChromeOS* service, + const std::vector<DeviceLocalAccount>& accounts); // Retrieves a list of device-local accounts from |cros_settings|. std::vector<DeviceLocalAccount> GetDeviceLocalAccounts( diff --git a/chrome/browser/chromeos/policy/device_policy_cros_browser_test.cc b/chrome/browser/chromeos/policy/device_policy_cros_browser_test.cc index 59e8401..8e78071 100644 --- a/chrome/browser/chromeos/policy/device_policy_cros_browser_test.cc +++ b/chrome/browser/chromeos/policy/device_policy_cros_browser_test.cc @@ -4,7 +4,6 @@ #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" -#include <string> #include <vector> #include "base/files/file_path.h" @@ -31,13 +30,14 @@ DevicePolicyCrosTestHelper::DevicePolicyCrosTestHelper() {} DevicePolicyCrosTestHelper::~DevicePolicyCrosTestHelper() {} -void DevicePolicyCrosTestHelper::MarkAsEnterpriseOwned() { +// static +void DevicePolicyCrosTestHelper::MarkAsEnterpriseOwnedBy( + const std::string& user_name) { OverridePaths(); const std::string install_attrs_blob( EnterpriseInstallAttributes:: - GetEnterpriseOwnedInstallAttributesBlobForTesting( - device_policy_.policy_data().username())); + GetEnterpriseOwnedInstallAttributesBlobForTesting(user_name)); base::FilePath install_attrs_file; ASSERT_TRUE( @@ -48,6 +48,10 @@ void DevicePolicyCrosTestHelper::MarkAsEnterpriseOwned() { install_attrs_blob.size())); } +void DevicePolicyCrosTestHelper::MarkAsEnterpriseOwned() { + MarkAsEnterpriseOwnedBy(device_policy_.policy_data().username()); +} + void DevicePolicyCrosTestHelper::InstallOwnerKey() { OverridePaths(); @@ -63,6 +67,7 @@ void DevicePolicyCrosTestHelper::InstallOwnerKey() { static_cast<int>(owner_key_bits.size())); } +// static void DevicePolicyCrosTestHelper::OverridePaths() { // This is usually done by ChromeBrowserMainChromeOS, but some tests // use the overridden paths before ChromeBrowserMain starts. Make sure that diff --git a/chrome/browser/chromeos/policy/device_policy_cros_browser_test.h b/chrome/browser/chromeos/policy/device_policy_cros_browser_test.h index e6e90a9..ca52897 100644 --- a/chrome/browser/chromeos/policy/device_policy_cros_browser_test.h +++ b/chrome/browser/chromeos/policy/device_policy_cros_browser_test.h @@ -5,6 +5,8 @@ #ifndef CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_POLICY_CROS_BROWSER_TEST_H_ #define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_POLICY_CROS_BROWSER_TEST_H_ +#include <string> + #include "base/basictypes.h" #include "base/compiler_specific.h" #include "chrome/browser/chromeos/policy/device_policy_builder.h" @@ -25,6 +27,7 @@ class DevicePolicyCrosTestHelper { // Marks the device as enterprise-owned. Must be called to make device // policies apply Chrome-wide. If this is not called, device policies will // affect CrosSettings only. + static void MarkAsEnterpriseOwnedBy(const std::string& user_name); void MarkAsEnterpriseOwned(); // Writes the owner key to disk. To be called before installing a policy. @@ -33,7 +36,7 @@ class DevicePolicyCrosTestHelper { DevicePolicyBuilder* device_policy() { return &device_policy_; } private: - void OverridePaths(); + static void OverridePaths(); // Carries Chrome OS device policies for tests. DevicePolicyBuilder device_policy_; diff --git a/chrome/browser/chromeos/policy/device_status_collector_browsertest.cc b/chrome/browser/chromeos/policy/device_status_collector_browsertest.cc index c031b59..dbd79a7 100644 --- a/chrome/browser/chromeos/policy/device_status_collector_browsertest.cc +++ b/chrome/browser/chromeos/policy/device_status_collector_browsertest.cc @@ -18,12 +18,11 @@ #include "base/threading/sequenced_worker_pool.h" #include "chrome/browser/chromeos/login/users/mock_user_manager.h" #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" +#include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h" #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" #include "chrome/browser/chromeos/policy/device_local_account.h" #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h" -#include "chrome/browser/chromeos/settings/cros_settings.h" -#include "chrome/browser/chromeos/settings/device_settings_service.h" -#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" +#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/testing_browser_process.h" #include "chromeos/dbus/cros_disks_client.h" @@ -37,7 +36,6 @@ #include "chromeos/network/network_state.h" #include "chromeos/network/network_state_handler.h" #include "chromeos/settings/cros_settings_names.h" -#include "chromeos/settings/cros_settings_provider.h" #include "chromeos/system/fake_statistics_provider.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/geolocation_provider.h" @@ -230,20 +228,20 @@ namespace policy { class DeviceStatusCollectorTest : public testing::Test { public: DeviceStatusCollectorTest() - : ui_thread_(content::BrowserThread::UI, &message_loop_), - file_thread_(content::BrowserThread::FILE, &message_loop_), - io_thread_(content::BrowserThread::IO, &message_loop_), - install_attributes_("managed.com", - "user@managed.com", - "device_id", - DEVICE_MODE_ENTERPRISE), - user_manager_(new chromeos::MockUserManager()), - user_manager_enabler_(user_manager_), - fake_device_local_account_( - policy::DeviceLocalAccount::TYPE_KIOSK_APP, - kKioskAccountId, - kKioskAppId, - std::string() /* kiosk_app_update_url */) { + : ui_thread_(content::BrowserThread::UI, &message_loop_), + file_thread_(content::BrowserThread::FILE, &message_loop_), + io_thread_(content::BrowserThread::IO, &message_loop_), + install_attributes_("managed.com", + "user@managed.com", + "device_id", + DEVICE_MODE_ENTERPRISE), + settings_helper_(false), + user_manager_(new chromeos::MockUserManager()), + user_manager_enabler_(user_manager_), + fake_device_local_account_(policy::DeviceLocalAccount::TYPE_KIOSK_APP, + kKioskAccountId, + kKioskAppId, + std::string() /* kiosk_app_update_url */) { // Run this test with a well-known timezone so that Time::LocalMidnight() // returns the same values on all machines. scoped_ptr<base::Environment> env(base::Environment::Create()); @@ -274,14 +272,9 @@ class DeviceStatusCollectorTest : public testing::Test { DiskMountManager::InitializeForTesting(mock_disk_mount_manager.release()); TestingDeviceStatusCollector::RegisterPrefs(prefs_.registry()); - // Remove the real DeviceSettingsProvider and replace it with a stub. - cros_settings_ = chromeos::CrosSettings::Get(); - device_settings_provider_ = - cros_settings_->GetProvider(chromeos::kReportDeviceVersionInfo); - EXPECT_TRUE(device_settings_provider_ != NULL); - EXPECT_TRUE( - cros_settings_->RemoveSettingsProvider(device_settings_provider_)); - cros_settings_->AddSettingsProvider(&stub_settings_provider_); + settings_helper_.ReplaceProvider(chromeos::kReportDeviceActivityTimes); + owner_settings_service_ = + settings_helper_.CreateOwnerSettingsService(nullptr); RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo), base::Bind(&GetEmptyCPUStatistics)); @@ -301,18 +294,16 @@ class DeviceStatusCollectorTest : public testing::Test { message_loop_.RunUntilIdle(); storage::ExternalMountPoints::GetSystemInstance()->RevokeAllFileSystems(); DiskMountManager::Shutdown(); - - // Restore the real DeviceSettingsProvider. - EXPECT_TRUE( - cros_settings_->RemoveSettingsProvider(&stub_settings_provider_)); - cros_settings_->AddSettingsProvider(device_settings_provider_); } void SetUp() override { // Disable network interface reporting since it requires additional setup. - cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false); + settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, + false); } + void TearDown() override { settings_helper_.RestoreProvider(); } + void RestartStatusCollector( const policy::DeviceStatusCollector::VolumeInfoFetcher& volume_info, const policy::DeviceStatusCollector::CPUStatisticsFetcher& cpu_stats) { @@ -370,7 +361,7 @@ class DeviceStatusCollectorTest : public testing::Test { void MockRunningKioskApp(const DeviceLocalAccount& account) { std::vector<DeviceLocalAccount> accounts; accounts.push_back(account); - SetDeviceLocalAccounts(cros_settings_, accounts); + SetDeviceLocalAccounts(owner_settings_service_.get(), accounts); user_manager_->CreateKioskAppUser(account.user_id); EXPECT_CALL(*user_manager_, IsLoggedInAsKioskApp()).WillRepeatedly( Return(true)); @@ -396,9 +387,8 @@ class DeviceStatusCollectorTest : public testing::Test { DiskMountManager::MountPointMap mount_point_map_; chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; chromeos::ScopedTestCrosSettings test_cros_settings_; - chromeos::CrosSettings* cros_settings_; - chromeos::CrosSettingsProvider* device_settings_provider_; - chromeos::StubCrosSettingsProvider stub_settings_provider_; + chromeos::ScopedCrosSettingsTestHelper settings_helper_; + scoped_ptr<chromeos::FakeOwnerSettingsService> owner_settings_service_; chromeos::MockUserManager* user_manager_; chromeos::ScopedUserManagerEnabler user_manager_enabler_; em::DeviceStatusReportRequest status_; @@ -412,7 +402,7 @@ TEST_F(DeviceStatusCollectorTest, AllIdle) { ui::IDLE_STATE_IDLE, ui::IDLE_STATE_IDLE }; - cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); + settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); // Test reporting with no data. GetStatus(); @@ -439,7 +429,7 @@ TEST_F(DeviceStatusCollectorTest, AllActive) { ui::IDLE_STATE_ACTIVE, ui::IDLE_STATE_ACTIVE }; - cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); + settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); // Test a single active sample. status_collector_->Simulate(test_states, 1); @@ -466,7 +456,7 @@ TEST_F(DeviceStatusCollectorTest, MixedStates) { ui::IDLE_STATE_IDLE, ui::IDLE_STATE_ACTIVE }; - cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); + settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); status_collector_->Simulate(test_states, sizeof(test_states) / sizeof(ui::IdleState)); GetStatus(); @@ -482,7 +472,7 @@ TEST_F(DeviceStatusCollectorTest, StateKeptInPref) { ui::IDLE_STATE_IDLE, ui::IDLE_STATE_IDLE }; - cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); + settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); status_collector_->Simulate(test_states, sizeof(test_states) / sizeof(ui::IdleState)); @@ -507,7 +497,7 @@ TEST_F(DeviceStatusCollectorTest, Times) { ui::IDLE_STATE_IDLE, ui::IDLE_STATE_IDLE }; - cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); + settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); status_collector_->Simulate(test_states, sizeof(test_states) / sizeof(ui::IdleState)); GetStatus(); @@ -521,7 +511,7 @@ TEST_F(DeviceStatusCollectorTest, MaxStoredPeriods) { }; const int kMaxDays = 10; - cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); + settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); status_collector_->set_max_stored_past_activity_days(kMaxDays - 1); status_collector_->set_max_stored_future_activity_days(1); Time baseline = Time::Now().LocalMidnight(); @@ -576,7 +566,7 @@ TEST_F(DeviceStatusCollectorTest, ActivityTimesEnabledByDefault) { TEST_F(DeviceStatusCollectorTest, ActivityTimesOff) { // Device activity times should not be reported if explicitly disabled. - cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, false); + settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, false); ui::IdleState test_states[] = { ui::IDLE_STATE_ACTIVE, @@ -594,7 +584,7 @@ TEST_F(DeviceStatusCollectorTest, ActivityCrossingMidnight) { ui::IdleState test_states[] = { ui::IDLE_STATE_ACTIVE }; - cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); + settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); // Set the baseline time to 10 seconds after midnight. status_collector_->SetBaselineTime( @@ -626,7 +616,7 @@ TEST_F(DeviceStatusCollectorTest, ActivityTimesKeptUntilSubmittedSuccessfully) { ui::IDLE_STATE_ACTIVE, ui::IDLE_STATE_ACTIVE, }; - cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); + settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); status_collector_->Simulate(test_states, 2); GetStatus(); @@ -654,14 +644,14 @@ TEST_F(DeviceStatusCollectorTest, DevSwitchBootMode) { EXPECT_EQ("Verified", status_.boot_mode()); // Test that boot mode data is not reported if the pref turned off. - cros_settings_->SetBoolean(chromeos::kReportDeviceBootMode, false); + settings_helper_.SetBoolean(chromeos::kReportDeviceBootMode, false); GetStatus(); EXPECT_FALSE(status_.has_boot_mode()); // Turn the pref on, and check that the status is reported iff the // statistics provider returns valid data. - cros_settings_->SetBoolean(chromeos::kReportDeviceBootMode, true); + settings_helper_.SetBoolean(chromeos::kReportDeviceBootMode, true); fake_statistics_provider_.SetMachineStatistic( chromeos::system::kDevSwitchBootKey, "(error)"); @@ -695,13 +685,13 @@ TEST_F(DeviceStatusCollectorTest, VersionInfo) { // When the pref to collect this data is not enabled, expect that none of // the fields are present in the protobuf. - cros_settings_->SetBoolean(chromeos::kReportDeviceVersionInfo, false); + settings_helper_.SetBoolean(chromeos::kReportDeviceVersionInfo, false); GetStatus(); EXPECT_FALSE(status_.has_browser_version()); EXPECT_FALSE(status_.has_os_version()); EXPECT_FALSE(status_.has_firmware_version()); - cros_settings_->SetBoolean(chromeos::kReportDeviceVersionInfo, true); + settings_helper_.SetBoolean(chromeos::kReportDeviceVersionInfo, true); GetStatus(); EXPECT_TRUE(status_.has_browser_version()); EXPECT_TRUE(status_.has_os_version()); @@ -733,7 +723,7 @@ TEST_F(DeviceStatusCollectorTest, Location) { // Check that when device location reporting is enabled and a valid fix is // available, the location is reported and is stored in local state. SetMockPositionToReturnNext(valid_fix); - cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true); + settings_helper_.SetBoolean(chromeos::kReportDeviceLocation, true); EXPECT_FALSE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty()); CheckThatAValidLocationIsReported(); @@ -748,7 +738,7 @@ TEST_F(DeviceStatusCollectorTest, Location) { // Check that after disabling location reporting again, the last known // location has been cleared from local state and is no longer reported. SetMockPositionToReturnNext(valid_fix); - cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, false); + settings_helper_.SetBoolean(chromeos::kReportDeviceLocation, false); // Allow the new pref to propagate to the status collector. message_loop_.RunUntilIdle(); EXPECT_TRUE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty()); @@ -757,7 +747,7 @@ TEST_F(DeviceStatusCollectorTest, Location) { // Check that after enabling location reporting again, an error is reported // if no valid fix is available. SetMockPositionToReturnNext(invalid_fix); - cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true); + settings_helper_.SetBoolean(chromeos::kReportDeviceLocation, true); // Allow the new pref to propagate to the status collector. message_loop_.RunUntilIdle(); CheckThatALocationErrorIsReported(); @@ -777,7 +767,7 @@ TEST_F(DeviceStatusCollectorTest, ReportUsers) { EXPECT_EQ(6, status_.user_size()); // Verify that users are reported after enabling the setting. - cros_settings_->SetBoolean(chromeos::kReportDeviceUsers, true); + settings_helper_.SetBoolean(chromeos::kReportDeviceUsers, true); GetStatus(); EXPECT_EQ(6, status_.user_size()); EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(0).type()); @@ -794,7 +784,7 @@ TEST_F(DeviceStatusCollectorTest, ReportUsers) { EXPECT_EQ("user5@managed.com", status_.user(5).email()); // Verify that users are no longer reported if setting is disabled. - cros_settings_->SetBoolean(chromeos::kReportDeviceUsers, false); + settings_helper_.SetBoolean(chromeos::kReportDeviceUsers, false); GetStatus(); EXPECT_EQ(0, status_.user_size()); } @@ -843,7 +833,7 @@ TEST_F(DeviceStatusCollectorTest, TestVolumeInfo) { } // Now turn off hardware status reporting - should have no data. - cros_settings_->SetBoolean(chromeos::kReportDeviceHardwareStatus, false); + settings_helper_.SetBoolean(chromeos::kReportDeviceHardwareStatus, false); GetStatus(); EXPECT_EQ(0, status_.volume_info_size()); } @@ -903,21 +893,21 @@ TEST_F(DeviceStatusCollectorTest, DISABLED_TestCPUSamples) { EXPECT_EQ(0, utilization); // Turning off hardware reporting should not report CPU utilization. - cros_settings_->SetBoolean(chromeos::kReportDeviceHardwareStatus, false); + settings_helper_.SetBoolean(chromeos::kReportDeviceHardwareStatus, false); GetStatus(); EXPECT_EQ(0, status_.cpu_utilization_pct().size()); } TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfNotKioskMode) { // Should not report session status if we don't have an active kiosk app. - cros_settings_->SetBoolean(chromeos::kReportDeviceSessionStatus, true); + settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, true); em::SessionStatusReportRequest session_status; EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status)); } TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfSessionReportingDisabled) { // Should not report session status if session status reporting is disabled. - cros_settings_->SetBoolean(chromeos::kReportDeviceSessionStatus, false); + settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, false); status_collector_->set_kiosk_account(make_scoped_ptr( new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); // Set up a device-local account for single-app kiosk mode. @@ -928,7 +918,7 @@ TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfSessionReportingDisabled) { } TEST_F(DeviceStatusCollectorTest, ReportSessionStatus) { - cros_settings_->SetBoolean(chromeos::kReportDeviceSessionStatus, true); + settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, true); status_collector_->set_kiosk_account(make_scoped_ptr( new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); @@ -1164,13 +1154,13 @@ TEST_F(DeviceStatusCollectorNetworkInterfacesTest, NetworkInterfaces) { EXPECT_LT(0, status_.network_state_size()); // No interfaces should be reported if the policy is off. - cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false); + settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false); GetStatus(); EXPECT_EQ(0, status_.network_interface_size()); EXPECT_EQ(0, status_.network_state_size()); // Switch the policy on and verify the interface list is present. - cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); + settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); GetStatus(); int count = 0; diff --git a/chrome/browser/chromeos/policy/extension_cache_unittest.cc b/chrome/browser/chromeos/policy/extension_cache_unittest.cc index 0b88894..5191e0c 100644 --- a/chrome/browser/chromeos/policy/extension_cache_unittest.cc +++ b/chrome/browser/chromeos/policy/extension_cache_unittest.cc @@ -10,14 +10,11 @@ #include "base/memory/scoped_ptr.h" #include "base/run_loop.h" #include "base/time/time.h" -#include "chrome/browser/chromeos/settings/cros_settings.h" -#include "chrome/browser/chromeos/settings/device_settings_service.h" -#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" +#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" #include "chrome/browser/extensions/updater/chromeos_extension_cache_delegate.h" #include "chrome/browser/extensions/updater/extension_cache_impl.h" #include "chrome/browser/extensions/updater/local_extension_cache.h" #include "chromeos/settings/cros_settings_names.h" -#include "chromeos/settings/cros_settings_provider.h" #include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" @@ -58,39 +55,14 @@ static base::FilePath CreateExtensionFile(const base::FilePath& dir, } // namespace class ExtensionCacheTest : public testing::Test { - public: - void SetUp() override { - // Swap out the DeviceSettingsProvider with our stub settings provider - // so we can set values for maximum extension cache size. - chromeos::CrosSettings* const cros_settings = chromeos::CrosSettings::Get(); - device_settings_provider_ = - cros_settings->GetProvider(chromeos::kExtensionCacheSize); - EXPECT_TRUE(device_settings_provider_); - EXPECT_TRUE( - cros_settings->RemoveSettingsProvider(device_settings_provider_)); - cros_settings->AddSettingsProvider(&stub_settings_provider_); - } - - void TearDown() override { - // Restore the real DeviceSettingsProvider. - chromeos::CrosSettings* const cros_settings = chromeos::CrosSettings::Get(); - EXPECT_TRUE( - cros_settings->RemoveSettingsProvider(&stub_settings_provider_)); - cros_settings->AddSettingsProvider(device_settings_provider_); - } - - // Helpers used to mock out cros settings. - chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; - chromeos::ScopedTestCrosSettings test_cros_settings_; - chromeos::CrosSettingsProvider* device_settings_provider_ = nullptr; - chromeos::StubCrosSettingsProvider stub_settings_provider_; - + protected: content::TestBrowserThreadBundle thread_bundle_; + chromeos::ScopedCrosSettingsTestHelper settings_helper_; }; TEST_F(ExtensionCacheTest, SizePolicy) { - chromeos::CrosSettings::Get()->SetInteger(chromeos::kExtensionCacheSize, - kMaxCacheSize); + settings_helper_.ReplaceProvider(chromeos::kExtensionCacheSize); + settings_helper_.SetInteger(chromeos::kExtensionCacheSize, kMaxCacheSize); // Create and initialize local cache. const base::Time now = base::Time::Now(); diff --git a/chrome/browser/chromeos/policy/heartbeat_scheduler_unittest.cc b/chrome/browser/chromeos/policy/heartbeat_scheduler_unittest.cc index 7a1a05c..8e5686b 100644 --- a/chrome/browser/chromeos/policy/heartbeat_scheduler_unittest.cc +++ b/chrome/browser/chromeos/policy/heartbeat_scheduler_unittest.cc @@ -6,9 +6,7 @@ #include "base/strings/string_number_conversions.h" #include "base/test/test_simple_task_runner.h" -#include "chrome/browser/chromeos/settings/cros_settings.h" -#include "chrome/browser/chromeos/settings/device_settings_service.h" -#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" +#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" #include "chromeos/settings/cros_settings_names.h" #include "components/gcm_driver/fake_gcm_driver.h" #include "content/public/test/test_utils.h" @@ -63,24 +61,11 @@ class HeartbeatSchedulerTest : public testing::Test { } void SetUp() override { - // Swap out the DeviceSettingsProvider with our stub settings provider - // so we can set values for the heartbeat frequency. - chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get(); - device_settings_provider_ = - cros_settings->GetProvider(chromeos::kReportDeviceVersionInfo); - EXPECT_TRUE(device_settings_provider_); - EXPECT_TRUE( - cros_settings->RemoveSettingsProvider(device_settings_provider_)); - cros_settings->AddSettingsProvider(&stub_settings_provider_); + settings_helper_.ReplaceProvider(chromeos::kHeartbeatEnabled); } void TearDown() override { content::RunAllBlockingPoolTasksUntilIdle(); - // Restore the real DeviceSettingsProvider. - chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get(); - EXPECT_TRUE(cros_settings->RemoveSettingsProvider( - &stub_settings_provider_)); - cros_settings->AddSettingsProvider(device_settings_provider_); } void CheckPendingTaskDelay(base::Time last_heartbeat, @@ -106,14 +91,8 @@ class HeartbeatSchedulerTest : public testing::Test { } base::MessageLoop loop_; - - // Helpers used to mock out cros settings. - chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; - chromeos::ScopedTestCrosSettings test_cros_settings_; - chromeos::CrosSettingsProvider* device_settings_provider_; - chromeos::StubCrosSettingsProvider stub_settings_provider_; - MockGCMDriver gcm_driver_; + chromeos::ScopedCrosSettingsTestHelper settings_helper_; // TaskRunner used to run individual tests. scoped_refptr<base::TestSimpleTaskRunner> task_runner_; @@ -125,16 +104,14 @@ class HeartbeatSchedulerTest : public testing::Test { TEST_F(HeartbeatSchedulerTest, Basic) { // Just makes sure we can spin up and shutdown the scheduler with // heartbeats disabled. - chromeos::CrosSettings::Get()->SetBoolean( - chromeos::kHeartbeatEnabled, false); + settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, false); ASSERT_TRUE(task_runner_->GetPendingTasks().empty()); } TEST_F(HeartbeatSchedulerTest, PermanentlyFailedGCMRegistration) { // If heartbeats are enabled, we should register with GCMDriver. EXPECT_CALL(gcm_driver_, RegisterImpl(kHeartbeatGCMAppID, _)); - chromeos::CrosSettings::Get()->SetBoolean( - chromeos::kHeartbeatEnabled, true); + settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, true); gcm_driver_.CompleteRegistration( kHeartbeatGCMAppID, gcm::GCMClient::GCM_DISABLED); @@ -144,8 +121,7 @@ TEST_F(HeartbeatSchedulerTest, PermanentlyFailedGCMRegistration) { TEST_F(HeartbeatSchedulerTest, TemporarilyFailedGCMRegistration) { EXPECT_CALL(gcm_driver_, RegisterImpl(kHeartbeatGCMAppID, _)); - chromeos::CrosSettings::Get()->SetBoolean( - chromeos::kHeartbeatEnabled, true); + settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, true); gcm_driver_.CompleteRegistration( kHeartbeatGCMAppID, gcm::GCMClient::SERVER_ERROR); testing::Mock::VerifyAndClearExpectations(&gcm_driver_); @@ -165,8 +141,7 @@ TEST_F(HeartbeatSchedulerTest, TemporarilyFailedGCMRegistration) { TEST_F(HeartbeatSchedulerTest, ChangeHeartbeatFrequency) { EXPECT_CALL(gcm_driver_, RegisterImpl(kHeartbeatGCMAppID, _)); - chromeos::CrosSettings::Get()->SetBoolean( - chromeos::kHeartbeatEnabled, true); + settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, true); gcm_driver_.CompleteRegistration( kHeartbeatGCMAppID, gcm::GCMClient::SUCCESS); @@ -176,8 +151,7 @@ TEST_F(HeartbeatSchedulerTest, ChangeHeartbeatFrequency) { testing::Mock::VerifyAndClearExpectations(&gcm_driver_); const int new_delay = 1234*1000; // 1234 seconds. - chromeos::CrosSettings::Get()->SetInteger(chromeos::kHeartbeatFrequency, - new_delay); + settings_helper_.SetInteger(chromeos::kHeartbeatFrequency, new_delay); // Now run pending heartbeat task, should send a heartbeat. gcm::GCMClient::OutgoingMessage message; EXPECT_CALL(gcm_driver_, SendImpl(kHeartbeatGCMAppID, _, _)) @@ -197,8 +171,7 @@ TEST_F(HeartbeatSchedulerTest, ChangeHeartbeatFrequency) { TEST_F(HeartbeatSchedulerTest, DisableHeartbeats) { // Makes sure that we can disable heartbeats on the fly. EXPECT_CALL(gcm_driver_, RegisterImpl(kHeartbeatGCMAppID, _)); - chromeos::CrosSettings::Get()->SetBoolean( - chromeos::kHeartbeatEnabled, true); + settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, true); gcm::GCMClient::OutgoingMessage message; EXPECT_CALL(gcm_driver_, SendImpl(kHeartbeatGCMAppID, _, _)) .WillOnce(SaveArg<2>(&message)); @@ -221,8 +194,7 @@ TEST_F(HeartbeatSchedulerTest, DisableHeartbeats) { testing::Mock::VerifyAndClearExpectations(&gcm_driver_); // Now disable heartbeats. Should get no more heartbeats sent. - chromeos::CrosSettings::Get()->SetBoolean( - chromeos::kHeartbeatEnabled, false); + settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, false); task_runner_->RunPendingTasks(); EXPECT_TRUE(task_runner_->GetPendingTasks().empty()); } @@ -232,8 +204,7 @@ TEST_F(HeartbeatSchedulerTest, CheckMessageContents) { EXPECT_CALL(gcm_driver_, RegisterImpl(kHeartbeatGCMAppID, _)); EXPECT_CALL(gcm_driver_, SendImpl(kHeartbeatGCMAppID, _, _)) .WillOnce(SaveArg<2>(&message)); - chromeos::CrosSettings::Get()->SetBoolean( - chromeos::kHeartbeatEnabled, true); + settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, true); gcm_driver_.CompleteRegistration( kHeartbeatGCMAppID, gcm::GCMClient::SUCCESS); task_runner_->RunPendingTasks(); diff --git a/chrome/browser/chromeos/policy/network_configuration_updater_unittest.cc b/chrome/browser/chromeos/policy/network_configuration_updater_unittest.cc index 1dd6406..da4a95c 100644 --- a/chrome/browser/chromeos/policy/network_configuration_updater_unittest.cc +++ b/chrome/browser/chromeos/policy/network_configuration_updater_unittest.cc @@ -12,8 +12,7 @@ #include "chrome/browser/chromeos/policy/device_network_configuration_updater.h" #include "chrome/browser/chromeos/policy/user_network_configuration_updater.h" #include "chrome/browser/chromeos/settings/cros_settings.h" -#include "chrome/browser/chromeos/settings/device_settings_service.h" -#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" +#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" #include "chrome/test/base/testing_profile.h" #include "chromeos/network/fake_network_device_handler.h" #include "chromeos/network/mock_managed_network_configuration_handler.h" @@ -287,10 +286,7 @@ class NetworkConfigurationUpdaterTest : public testing::Test { StrictMock<chromeos::MockManagedNetworkConfigurationHandler> network_config_handler_; FakeNetworkDeviceHandler network_device_handler_; - - // Not used directly. Required for CrosSettings. - chromeos::ScopedTestDeviceSettingsService scoped_device_settings_service_; - chromeos::ScopedTestCrosSettings scoped_cros_settings_; + chromeos::ScopedCrosSettingsTestHelper settings_helper_; // Ownership of certificate_importer_owned_ is passed to the // NetworkConfigurationUpdater. When that happens, |certificate_importer_| @@ -313,28 +309,16 @@ TEST_F(NetworkConfigurationUpdaterTest, CellularAllowRoaming) { // Ignore network config updates. EXPECT_CALL(network_config_handler_, SetPolicy(_, _, _, _)).Times(AtLeast(1)); - // Setup the DataRoaming device setting. - chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get(); - chromeos::CrosSettingsProvider* device_settings_provider = - cros_settings->GetProvider(chromeos::kSignedDataRoamingEnabled); - cros_settings->RemoveSettingsProvider(device_settings_provider); - delete device_settings_provider; - chromeos::StubCrosSettingsProvider* stub_settings_provider = - new chromeos::StubCrosSettingsProvider; - cros_settings->AddSettingsProvider(stub_settings_provider); - - chromeos::CrosSettings::Get()->Set(chromeos::kSignedDataRoamingEnabled, - base::FundamentalValue(false)); + settings_helper_.ReplaceProvider(chromeos::kSignedDataRoamingEnabled); + settings_helper_.SetBoolean(chromeos::kSignedDataRoamingEnabled, false); EXPECT_FALSE(network_device_handler_.allow_roaming_); CreateNetworkConfigurationUpdaterForDevicePolicy(); MarkPolicyProviderInitialized(); - chromeos::CrosSettings::Get()->Set(chromeos::kSignedDataRoamingEnabled, - base::FundamentalValue(true)); + settings_helper_.SetBoolean(chromeos::kSignedDataRoamingEnabled, true); EXPECT_TRUE(network_device_handler_.allow_roaming_); - chromeos::CrosSettings::Get()->Set(chromeos::kSignedDataRoamingEnabled, - base::FundamentalValue(false)); + settings_helper_.SetBoolean(chromeos::kSignedDataRoamingEnabled, false); EXPECT_FALSE(network_device_handler_.allow_roaming_); } diff --git a/chrome/browser/chromeos/policy/status_uploader_unittest.cc b/chrome/browser/chromeos/policy/status_uploader_unittest.cc index 4ef34eb..13a033c 100644 --- a/chrome/browser/chromeos/policy/status_uploader_unittest.cc +++ b/chrome/browser/chromeos/policy/status_uploader_unittest.cc @@ -7,8 +7,7 @@ #include "base/time/time.h" #include "chrome/browser/chromeos/policy/device_status_collector.h" #include "chrome/browser/chromeos/policy/status_uploader.h" -#include "chrome/browser/chromeos/settings/device_settings_service.h" -#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" +#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" #include "chromeos/settings/cros_settings_names.h" #include "components/policy/core/common/cloud/cloud_policy_client.h" #include "components/policy/core/common/cloud/mock_cloud_policy_client.h" @@ -46,35 +45,18 @@ class MockDeviceStatusCollector : public policy::DeviceStatusCollector { namespace policy { class StatusUploaderTest : public testing::Test { public: - StatusUploaderTest() - : task_runner_(new base::TestSimpleTaskRunner()), - device_settings_provider_(nullptr) { + StatusUploaderTest() : task_runner_(new base::TestSimpleTaskRunner()) { DeviceStatusCollector::RegisterPrefs(prefs_.registry()); } void SetUp() override { client_.SetDMToken("dm_token"); collector_.reset(new MockDeviceStatusCollector(&prefs_)); - - // Swap out the DeviceSettingsProvider with our stub settings provider - // so we can set values for the upload frequency. - chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get(); - device_settings_provider_ = - cros_settings->GetProvider(chromeos::kReportDeviceVersionInfo); - EXPECT_TRUE(device_settings_provider_); - EXPECT_TRUE( - cros_settings->RemoveSettingsProvider(device_settings_provider_)); - cros_settings->AddSettingsProvider(&stub_settings_provider_); - + settings_helper_.ReplaceProvider(chromeos::kReportUploadFrequency); } void TearDown() override { content::RunAllBlockingPoolTasksUntilIdle(); - // Restore the real DeviceSettingsProvider. - chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get(); - EXPECT_TRUE(cros_settings->RemoveSettingsProvider( - &stub_settings_provider_)); - cros_settings->AddSettingsProvider(device_settings_provider_); } // Given a pending task to upload status, mocks out a server response. @@ -114,11 +96,8 @@ class StatusUploaderTest : public testing::Test { base::MessageLoop loop_; scoped_refptr<base::TestSimpleTaskRunner> task_runner_; - chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; - chromeos::ScopedTestCrosSettings test_cros_settings_; + chromeos::ScopedCrosSettingsTestHelper settings_helper_; scoped_ptr<MockDeviceStatusCollector> collector_; - chromeos::CrosSettingsProvider* device_settings_provider_; - chromeos::StubCrosSettingsProvider stub_settings_provider_; MockCloudPolicyClient client_; MockDeviceManagementService device_management_service_; TestingPrefServiceSimple prefs_; @@ -137,8 +116,7 @@ TEST_F(StatusUploaderTest, DifferentFrequencyAtStart) { // when it is passed to the StatusUploader constructor below. MockDeviceStatusCollector* const mock_collector = collector_.get(); const int new_delay = StatusUploader::kDefaultUploadDelayMs * 2; - chromeos::CrosSettings::Get()->SetInteger(chromeos::kReportUploadFrequency, - new_delay); + settings_helper_.SetInteger(chromeos::kReportUploadFrequency, new_delay); const base::TimeDelta expected_delay = base::TimeDelta::FromMilliseconds( new_delay); EXPECT_TRUE(task_runner_->GetPendingTasks().empty()); @@ -202,8 +180,7 @@ TEST_F(StatusUploaderTest, ChangeFrequency) { // Change the frequency. The new frequency should be reflected in the timing // used for the next callback. const int new_delay = StatusUploader::kDefaultUploadDelayMs * 2; - chromeos::CrosSettings::Get()->SetInteger(chromeos::kReportUploadFrequency, - new_delay); + settings_helper_.SetInteger(chromeos::kReportUploadFrequency, new_delay); const base::TimeDelta expected_delay = base::TimeDelta::FromMilliseconds( new_delay); RunPendingUploadTaskAndCheckNext(uploader, expected_delay); diff --git a/chrome/browser/chromeos/settings/device_settings_provider.cc b/chrome/browser/chromeos/settings/device_settings_provider.cc index a33b23f..05fe7685 100644 --- a/chrome/browser/chromeos/settings/device_settings_provider.cc +++ b/chrome/browser/chromeos/settings/device_settings_provider.cc @@ -56,10 +56,14 @@ const char* const kKnownSettings[] = { kAllowedConnectionTypesForUpdate, kAttestationForContentProtectionEnabled, kDeviceAttestationEnabled, + kDeviceDisabled, + kDeviceDisabledMessage, kDeviceOwner, + kExtensionCacheSize, kHeartbeatEnabled, kHeartbeatFrequency, kPolicyMissingMitigationMode, + kRebootOnShutdown, kReleaseChannel, kReleaseChannelDelegated, kReportDeviceActivityTimes, @@ -79,10 +83,6 @@ const char* const kKnownSettings[] = { kSystemUse24HourClock, kUpdateDisabled, kVariationsRestrictParameter, - kDeviceDisabled, - kDeviceDisabledMessage, - kRebootOnShutdown, - kExtensionCacheSize, }; bool HasOldMetricsFile() { diff --git a/chrome/browser/chromeos/settings/device_settings_test_helper.h b/chrome/browser/chromeos/settings/device_settings_test_helper.h index 0e5742e..0736342 100644 --- a/chrome/browser/chromeos/settings/device_settings_test_helper.h +++ b/chrome/browser/chromeos/settings/device_settings_test_helper.h @@ -19,7 +19,6 @@ #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" #include "chrome/browser/chromeos/policy/device_policy_builder.h" #include "chrome/browser/chromeos/settings/device_settings_service.h" -#include "chrome/browser/chromeos/settings/device_settings_test_helper.h" #include "chromeos/dbus/session_manager_client.h" #include "components/ownership/mock_owner_key_util.h" #include "content/public/test/test_browser_thread_bundle.h" diff --git a/chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.cc b/chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.cc new file mode 100644 index 0000000..bcbb947 --- /dev/null +++ b/chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.cc @@ -0,0 +1,132 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" + +#include "base/logging.h" +#include "base/values.h" +#include "chrome/browser/browser_process.h" +#include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h" +#include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" +#include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" +#include "chrome/browser/chromeos/settings/cros_settings.h" +#include "chrome/browser/chromeos/settings/device_settings_cache.h" +#include "chrome/browser/chromeos/settings/device_settings_service.h" +#include "chrome/browser/profiles/profile.h" +#include "components/ownership/mock_owner_key_util.h" +#include "policy/proto/device_management_backend.pb.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace chromeos { + +ScopedCrosSettingsTestHelper::ScopedCrosSettingsTestHelper() { + Initialize(true); +} + +ScopedCrosSettingsTestHelper::ScopedCrosSettingsTestHelper( + bool create_settings_service) { + Initialize(create_settings_service); +} + +ScopedCrosSettingsTestHelper::~ScopedCrosSettingsTestHelper() { + RestoreProvider(); +} + +scoped_ptr<FakeOwnerSettingsService> +ScopedCrosSettingsTestHelper::CreateOwnerSettingsService(Profile* profile) { + return make_scoped_ptr(new FakeOwnerSettingsService( + profile, new ownership::MockOwnerKeyUtil(), &stub_settings_provider_)); +} + +void ScopedCrosSettingsTestHelper::ReplaceProvider(const std::string& path) { + CHECK(!real_settings_provider_); + // Swap out the DeviceSettingsProvider with our settings provider so we can + // set values for the specified path. + CrosSettings* const cros_settings = CrosSettings::Get(); + real_settings_provider_ = cros_settings->GetProvider(path); + EXPECT_TRUE(real_settings_provider_); + EXPECT_TRUE(cros_settings->RemoveSettingsProvider(real_settings_provider_)); + cros_settings->AddSettingsProvider(&stub_settings_provider_); +} + +void ScopedCrosSettingsTestHelper::RestoreProvider() { + if (real_settings_provider_) { + // Restore the real DeviceSettingsProvider. + CrosSettings* const cros_settings = CrosSettings::Get(); + EXPECT_TRUE( + cros_settings->RemoveSettingsProvider(&stub_settings_provider_)); + cros_settings->AddSettingsProvider(real_settings_provider_); + real_settings_provider_ = nullptr; + } +} + +void ScopedCrosSettingsTestHelper::SetTrustedStatus( + CrosSettingsProvider::TrustedStatus status) { + stub_settings_provider_.SetTrustedStatus(status); +} + +void ScopedCrosSettingsTestHelper::SetCurrentUserIsOwner(bool owner) { + stub_settings_provider_.SetCurrentUserIsOwner(owner); +} + +void ScopedCrosSettingsTestHelper::Set(const std::string& path, + const base::Value& in_value) { + stub_settings_provider_.Set(path, in_value); +} + +void ScopedCrosSettingsTestHelper::SetBoolean(const std::string& path, + bool in_value) { + Set(path, base::FundamentalValue(in_value)); +} + +void ScopedCrosSettingsTestHelper::SetInteger(const std::string& path, + int in_value) { + Set(path, base::FundamentalValue(in_value)); +} + +void ScopedCrosSettingsTestHelper::SetDouble(const std::string& path, + double in_value) { + Set(path, base::FundamentalValue(in_value)); +} + +void ScopedCrosSettingsTestHelper::SetString(const std::string& path, + const std::string& in_value) { + Set(path, base::StringValue(in_value)); +} + +void ScopedCrosSettingsTestHelper::StoreCachedDeviceSetting( + const std::string& path) { + const base::Value* const value = stub_settings_provider_.Get(path); + if (value) { + enterprise_management::PolicyData data; + enterprise_management::ChromeDeviceSettingsProto settings; + if (device_settings_cache::Retrieve(&data, + g_browser_process->local_state())) { + CHECK(settings.ParseFromString(data.policy_value())); + } + OwnerSettingsServiceChromeOS::UpdateDeviceSettings(path, *value, settings); + CHECK(settings.SerializeToString(data.mutable_policy_value())); + CHECK(device_settings_cache::Store(data, g_browser_process->local_state())); + } +} + +void ScopedCrosSettingsTestHelper::CopyStoredValue(const std::string& path) { + CrosSettingsProvider* provider = real_settings_provider_ + ? real_settings_provider_ + : CrosSettings::Get()->GetProvider(path); + const base::Value* const value = provider->Get(path); + if (value) { + stub_settings_provider_.Set(path, *value); + } +} + +void ScopedCrosSettingsTestHelper::Initialize(bool create_settings_service) { + if (create_settings_service) { + CHECK(!DeviceSettingsService::IsInitialized()); + test_device_settings_service_.reset(new ScopedTestDeviceSettingsService()); + test_cros_settings_.reset(new ScopedTestCrosSettings()); + } +} + +} // namespace chromeos diff --git a/chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h b/chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h new file mode 100644 index 0000000..86a07bd --- /dev/null +++ b/chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h @@ -0,0 +1,83 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_SCOPED_CROS_SETTINGS_TEST_HELPER_H_ +#define CHROME_BROWSER_CHROMEOS_SETTINGS_SCOPED_CROS_SETTINGS_TEST_HELPER_H_ + +#include <string> + +#include "base/macros.h" +#include "base/memory/scoped_ptr.h" +#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" +#include "chromeos/settings/cros_settings_provider.h" + +class Profile; + +namespace base { +class Value; +} + +namespace chromeos { + +class FakeOwnerSettingsService; +class ScopedTestCrosSettings; +class ScopedTestDeviceSettingsService; + +class ScopedCrosSettingsTestHelper { + public: + ScopedCrosSettingsTestHelper(); + + // In some cases it is required to pass |create_settings_service| as false: + // If the test already has a device settings service and/or CrosSettings set + // up by another (instantiated or base) class, creating another one causes + // crash. + explicit ScopedCrosSettingsTestHelper(bool create_settings_service); + ~ScopedCrosSettingsTestHelper(); + + // Methods to replace and restore CrosSettingsProvider for the specified + // |path|. + void ReplaceProvider(const std::string& path); + void RestoreProvider(); + + // Method to create an owner settings service that uses + // |stub_settings_provider_| as settings write path. + scoped_ptr<FakeOwnerSettingsService> CreateOwnerSettingsService( + Profile* profile); + + // These methods simply call the according |stub_settings_provider_| method. + void SetTrustedStatus(CrosSettingsProvider::TrustedStatus status); + void SetCurrentUserIsOwner(bool owner); + void Set(const std::string& path, const base::Value& in_value); + + // Convenience forms of Set() from CrosSettingsProvider. These methods will + // replace any existing value at that |path|, even if it has a different type. + void SetBoolean(const std::string& path, bool in_value); + void SetInteger(const std::string& path, int in_value); + void SetDouble(const std::string& path, double in_value); + void SetString(const std::string& path, const std::string& in_value); + + // This may be called before |ReplaceProvider| to copy values currently stored + // in the old provider. If the method is called after |ReplaceProvider|, then + // the value is retreived from |real_settings_provider_| for any |path|. + void CopyStoredValue(const std::string& path); + + // Write the setting from |path| to local state so that it can be retreived + // later on browser test startup by the device settings service. + void StoreCachedDeviceSetting(const std::string& path); + + private: + // Helpers used to mock out cros settings. + scoped_ptr<ScopedTestDeviceSettingsService> test_device_settings_service_; + scoped_ptr<ScopedTestCrosSettings> test_cros_settings_; + CrosSettingsProvider* real_settings_provider_ = nullptr; + StubCrosSettingsProvider stub_settings_provider_; + + void Initialize(bool create_settings_service); + + DISALLOW_COPY_AND_ASSIGN(ScopedCrosSettingsTestHelper); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_SETTINGS_SCOPED_CROS_SETTINGS_TEST_HELPER_H_ diff --git a/chrome/browser/chromeos/settings/shutdown_policy_handler_unittest.cc b/chrome/browser/chromeos/settings/shutdown_policy_handler_unittest.cc index eadd410..8b9669f9 100644 --- a/chrome/browser/chromeos/settings/shutdown_policy_handler_unittest.cc +++ b/chrome/browser/chromeos/settings/shutdown_policy_handler_unittest.cc @@ -6,15 +6,10 @@ #include "base/bind.h" #include "base/bind_helpers.h" -#include "base/command_line.h" -#include "base/memory/scoped_ptr.h" #include "base/run_loop.h" -#include "base/values.h" -#include "chrome/browser/chromeos/settings/device_settings_service.h" -#include "chromeos/chromeos_switches.h" +#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/settings/cros_settings_names.h" -#include "chromeos/settings/cros_settings_provider.h" #include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" @@ -30,29 +25,21 @@ class ShutdownPolicyHandlerTest : public testing::Test, protected: ShutdownPolicyHandlerTest() - : cros_settings_(nullptr), - callback_called_(false), + : callback_called_(false), reboot_on_shutdown_(false), - delegate_invocations_count_(0) { - base::CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kStubCrosSettings); - test_cros_settings_.reset(new ScopedTestCrosSettings); -} + delegate_invocations_count_(0) {} // testing::Test: -void SetUp() override { + void SetUp() override { testing::Test::SetUp(); - cros_settings_ = CrosSettings::Get(); DBusThreadManager::Initialize(); + settings_helper_.ReplaceProvider(kRebootOnShutdown); } void TearDown() override { DBusThreadManager::Shutdown(); } void SetRebootOnShutdown(bool reboot_on_shutdown) { - const base::FundamentalValue reboot_on_shutdown_value(reboot_on_shutdown); - CrosSettings::Get() - ->GetProvider(kRebootOnShutdown) - ->Set(kRebootOnShutdown, reboot_on_shutdown_value); + settings_helper_.SetBoolean(kRebootOnShutdown, reboot_on_shutdown); base::RunLoop().RunUntilIdle(); } @@ -64,20 +51,14 @@ void SetUp() override { protected: content::TestBrowserThreadBundle thread_bundle_; - - CrosSettings* cros_settings_; - scoped_ptr<CrosSettingsProvider> device_settings_provider_; - - ScopedTestDeviceSettingsService test_device_settings_service_; - scoped_ptr<ScopedTestCrosSettings> test_cros_settings_; - + ScopedCrosSettingsTestHelper settings_helper_; bool callback_called_; bool reboot_on_shutdown_; int delegate_invocations_count_; }; TEST_F(ShutdownPolicyHandlerTest, RetrieveTrustedDevicePolicies) { - ShutdownPolicyHandler shutdown_policy_observer(cros_settings_, this); + ShutdownPolicyHandler shutdown_policy_observer(CrosSettings::Get(), this); base::RunLoop().RunUntilIdle(); EXPECT_EQ(0, delegate_invocations_count_); @@ -100,7 +81,7 @@ TEST_F(ShutdownPolicyHandlerTest, RetrieveTrustedDevicePolicies) { } TEST_F(ShutdownPolicyHandlerTest, CheckIfRebootOnShutdown) { - ShutdownPolicyHandler shutdown_policy_observer(cros_settings_, this); + ShutdownPolicyHandler shutdown_policy_observer(CrosSettings::Get(), this); base::RunLoop().RunUntilIdle(); // Allow shutdown. diff --git a/chrome/browser/chromeos/settings/stub_cros_settings_provider.cc b/chrome/browser/chromeos/settings/stub_cros_settings_provider.cc index c11e3c3..3b6a89a 100644 --- a/chrome/browser/chromeos/settings/stub_cros_settings_provider.cc +++ b/chrome/browser/chromeos/settings/stub_cros_settings_provider.cc @@ -37,17 +37,27 @@ const base::Value* StubCrosSettingsProvider::Get( CrosSettingsProvider::TrustedStatus StubCrosSettingsProvider::PrepareTrustedValues(const base::Closure& cb) { - // We don't have a trusted store so all values are available immediately. - return TRUSTED; + return trusted_status_; } bool StubCrosSettingsProvider::HandlesSetting(const std::string& path) const { return DeviceSettingsProvider::IsDeviceSetting(path); } +void StubCrosSettingsProvider::SetTrustedStatus(TrustedStatus status) { + trusted_status_ = status; +} + +void StubCrosSettingsProvider::SetCurrentUserIsOwner(bool owner) { + current_user_is_owner_ = owner; +} + void StubCrosSettingsProvider::DoSet(const std::string& path, const base::Value& value) { - values_.SetValue(path, value.DeepCopy()); + if (current_user_is_owner_) + values_.SetValue(path, value.DeepCopy()); + else + LOG(WARNING) << "Changing settings from non-owner, setting=" << path; NotifyObservers(path); } diff --git a/chrome/browser/chromeos/settings/stub_cros_settings_provider.h b/chrome/browser/chromeos/settings/stub_cros_settings_provider.h index 5fcb65c1..4d54a3e 100644 --- a/chrome/browser/chromeos/settings/stub_cros_settings_provider.h +++ b/chrome/browser/chromeos/settings/stub_cros_settings_provider.h @@ -24,6 +24,9 @@ class StubCrosSettingsProvider : public CrosSettingsProvider { TrustedStatus PrepareTrustedValues(const base::Closure& callback) override; bool HandlesSetting(const std::string& path) const override; + void SetTrustedStatus(TrustedStatus status); + void SetCurrentUserIsOwner(bool owner); + private: // CrosSettingsProvider implementation: void DoSet(const std::string& path, const base::Value& value) override; @@ -34,6 +37,14 @@ class StubCrosSettingsProvider : public CrosSettingsProvider { // In-memory settings storage. PrefValueMap values_; + // Some tests imply that calling Set() as non-owner doesn't change the actual + // value but still trigger a notification. For such cases, it is possible to + // emulate this behavior by changing the ownership status to non-owner with + // |SetCurrentUserIsOwner(false)|. + bool current_user_is_owner_ = true; + + TrustedStatus trusted_status_ = CrosSettingsProvider::TRUSTED; + DISALLOW_COPY_AND_ASSIGN(StubCrosSettingsProvider); }; diff --git a/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api_unittest.cc b/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api_unittest.cc index d85b6ad..3f64a3f 100644 --- a/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api_unittest.cc +++ b/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api_unittest.cc @@ -13,9 +13,10 @@ #include "base/strings/stringprintf.h" #include "base/values.h" #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h" -#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" +#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" #include "chrome/browser/extensions/extension_function_test_utils.h" #include "chrome/browser/signin/signin_manager_factory.h" +#include "chrome/browser/ui/browser.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/browser_with_test_window_test.h" #include "chromeos/attestation/attestation_constants.h" @@ -24,7 +25,6 @@ #include "chromeos/cryptohome/mock_async_method_caller.h" #include "chromeos/dbus/dbus_method_call_status.h" #include "chromeos/dbus/mock_cryptohome_client.h" -#include "chromeos/settings/cros_settings_provider.h" #include "components/policy/core/common/cloud/cloud_policy_constants.h" #include "components/signin/core/browser/signin_manager.h" #include "extensions/common/test_util.h" @@ -141,7 +141,8 @@ void GetCertificateCallbackFalse( class EPKPChallengeKeyTestBase : public BrowserWithTestWindowTest { protected: - EPKPChallengeKeyTestBase() : extension_(test_util::CreateEmptyExtension()) { + EPKPChallengeKeyTestBase() + : settings_helper_(false), extension_(test_util::CreateEmptyExtension()) { // Set up the default behavior of mocks. ON_CALL(mock_cryptohome_client_, TpmAttestationDoesKeyExist(_, _, _, _)) .WillByDefault(WithArgs<3>(Invoke(FakeBoolDBusMethod( @@ -163,25 +164,8 @@ class EPKPChallengeKeyTestBase : public BrowserWithTestWindowTest { stub_install_attributes_.SetDeviceId("device_id"); stub_install_attributes_.SetMode(policy::DEVICE_MODE_ENTERPRISE); - // Replace the default device setting provider with the stub. - device_settings_provider_ = chromeos::CrosSettings::Get()->GetProvider( - chromeos::kReportDeviceVersionInfo); - EXPECT_TRUE(device_settings_provider_ != NULL); - EXPECT_TRUE(chromeos::CrosSettings::Get()-> - RemoveSettingsProvider(device_settings_provider_)); - chromeos::CrosSettings::Get()-> - AddSettingsProvider(&stub_settings_provider_); - - // Set the device settings. - stub_settings_provider_.Set(chromeos::kDeviceAttestationEnabled, - base::FundamentalValue(true)); - } - - virtual ~EPKPChallengeKeyTestBase() { - EXPECT_TRUE(chromeos::CrosSettings::Get()-> - RemoveSettingsProvider(&stub_settings_provider_)); - chromeos::CrosSettings::Get()-> - AddSettingsProvider(device_settings_provider_); + settings_helper_.ReplaceProvider(chromeos::kDeviceAttestationEnabled); + settings_helper_.SetBoolean(chromeos::kDeviceAttestationEnabled, true); } virtual void SetUp() override { @@ -206,10 +190,9 @@ class EPKPChallengeKeyTestBase : public BrowserWithTestWindowTest { NiceMock<chromeos::MockCryptohomeClient> mock_cryptohome_client_; NiceMock<cryptohome::MockAsyncMethodCaller> mock_async_method_caller_; NiceMock<chromeos::attestation::MockAttestationFlow> mock_attestation_flow_; + chromeos::ScopedCrosSettingsTestHelper settings_helper_; scoped_refptr<extensions::Extension> extension_; policy::StubEnterpriseInstallAttributes stub_install_attributes_; - chromeos::CrosSettingsProvider* device_settings_provider_; - chromeos::StubCrosSettingsProvider stub_settings_provider_; PrefService* prefs_; }; @@ -260,8 +243,7 @@ TEST_F(EPKPChallengeMachineKeyTest, ExtensionNotWhitelisted) { } TEST_F(EPKPChallengeMachineKeyTest, DevicePolicyDisabled) { - stub_settings_provider_.Set(chromeos::kDeviceAttestationEnabled, - base::FundamentalValue(false)); + settings_helper_.SetBoolean(chromeos::kDeviceAttestationEnabled, false); EXPECT_EQ(EPKPChallengeKeyBase::kDevicePolicyDisabledError, utils::RunFunctionAndReturnError(func_.get(), kArgs, browser())); @@ -397,8 +379,7 @@ TEST_F(EPKPChallengeUserKeyTest, ExtensionNotWhitelisted) { } TEST_F(EPKPChallengeUserKeyTest, DevicePolicyDisabled) { - stub_settings_provider_.Set(chromeos::kDeviceAttestationEnabled, - base::FundamentalValue(false)); + settings_helper_.SetBoolean(chromeos::kDeviceAttestationEnabled, false); EXPECT_EQ(EPKPChallengeKeyBase::kDevicePolicyDisabledError, utils::RunFunctionAndReturnError(func_.get(), kArgs, browser())); diff --git a/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc b/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc index f3ef877..c70275f 100644 --- a/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc +++ b/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc @@ -58,6 +58,8 @@ #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" #include "chrome/browser/chromeos/options/network_config_view.h" +#include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" +#include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_factory.h" #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" #include "chrome/browser/chromeos/profiles/multiprofiles_intro_dialog.h" @@ -1018,8 +1020,17 @@ void SystemTrayDelegateChromeOS::UpdateClockType() { GetSystemTrayNotifier()->NotifyDateFormatChanged(); // This also works for enterprise-managed devices because they never have // local owner. - if (user_manager::UserManager::Get()->IsCurrentUserOwner()) - CrosSettings::Get()->SetBoolean(kSystemUse24HourClock, use_24_hour_clock); + if (user_manager::UserManager::Get()->IsCurrentUserOwner()) { + user_manager::User* const user = + user_manager::UserManager::Get()->GetActiveUser(); + CHECK(user); + Profile* const profile = ProfileHelper::Get()->GetProfileByUser(user); + CHECK(profile); + OwnerSettingsServiceChromeOS* const service = + OwnerSettingsServiceChromeOSFactory::GetForBrowserContext(profile); + CHECK(service); + service->SetBoolean(kSystemUse24HourClock, use_24_hour_clock); + } } void SystemTrayDelegateChromeOS::UpdateShowLogoutButtonInTray() { @@ -1120,8 +1131,15 @@ void SystemTrayDelegateChromeOS::LoggedInStateChanged() { // user's profile has actually been loaded (http://crbug.com/317745). The // system tray's time format is updated at login via SetProfile(). if (user_manager::UserManager::Get()->IsCurrentUserOwner()) { - CrosSettings::Get()->SetBoolean(kSystemUse24HourClock, - ShouldUse24HourClock()); + user_manager::User* const user = + user_manager::UserManager::Get()->GetActiveUser(); + CHECK(user); + Profile* const profile = ProfileHelper::Get()->GetProfileByUser(user); + CHECK(profile); + OwnerSettingsServiceChromeOS* const service = + OwnerSettingsServiceChromeOSFactory::GetForBrowserContext(profile); + CHECK(service); + service->SetBoolean(kSystemUse24HourClock, ShouldUse24HourClock()); } } diff --git a/chrome/browser/ui/webui/extensions/chromeos/kiosk_apps_handler.cc b/chrome/browser/ui/webui/extensions/chromeos/kiosk_apps_handler.cc index d8a0567..b1d3d56 100644 --- a/chrome/browser/ui/webui/extensions/chromeos/kiosk_apps_handler.cc +++ b/chrome/browser/ui/webui/extensions/chromeos/kiosk_apps_handler.cc @@ -15,6 +15,7 @@ #include "base/strings/string_util.h" #include "base/sys_info.h" #include "base/values.h" +#include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" #include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/grit/chromium_strings.h" #include "chrome/grit/generated_resources.h" @@ -94,11 +95,12 @@ bool ExtractsAppIdFromInput(const std::string& input, } // namespace -KioskAppsHandler::KioskAppsHandler() +KioskAppsHandler::KioskAppsHandler(OwnerSettingsServiceChromeOS* service) : kiosk_app_manager_(KioskAppManager::Get()), initialized_(false), is_kiosk_enabled_(false), is_auto_launch_enabled_(false), + owner_settings_service_(service), weak_ptr_factory_(this) { kiosk_app_manager_->AddObserver(this); } @@ -281,7 +283,7 @@ void KioskAppsHandler::HandleAddKioskApp(const base::ListValue* args) { return; } - kiosk_app_manager_->AddApp(app_id); + kiosk_app_manager_->AddApp(app_id, owner_settings_service_); } void KioskAppsHandler::HandleRemoveKioskApp(const base::ListValue* args) { @@ -291,7 +293,7 @@ void KioskAppsHandler::HandleRemoveKioskApp(const base::ListValue* args) { std::string app_id; CHECK(args->GetString(0, &app_id)); - kiosk_app_manager_->RemoveApp(app_id); + kiosk_app_manager_->RemoveApp(app_id, owner_settings_service_); } void KioskAppsHandler::HandleEnableKioskAutoLaunch( @@ -302,7 +304,7 @@ void KioskAppsHandler::HandleEnableKioskAutoLaunch( std::string app_id; CHECK(args->GetString(0, &app_id)); - kiosk_app_manager_->SetAutoLaunchApp(app_id); + kiosk_app_manager_->SetAutoLaunchApp(app_id, owner_settings_service_); } void KioskAppsHandler::HandleDisableKioskAutoLaunch( @@ -317,7 +319,7 @@ void KioskAppsHandler::HandleDisableKioskAutoLaunch( if (startup_app_id != app_id) return; - kiosk_app_manager_->SetAutoLaunchApp(""); + kiosk_app_manager_->SetAutoLaunchApp("", owner_settings_service_); } void KioskAppsHandler::HandleSetDisableBailoutShortcut( @@ -328,7 +330,7 @@ void KioskAppsHandler::HandleSetDisableBailoutShortcut( bool disable_bailout_shortcut; CHECK(args->GetBoolean(0, &disable_bailout_shortcut)); - CrosSettings::Get()->SetBoolean( + owner_settings_service_->SetBoolean( kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled, !disable_bailout_shortcut); } @@ -350,7 +352,7 @@ void KioskAppsHandler::ShowError(const std::string& app_id) { web_ui()->CallJavascriptFunction("extensions.KioskAppsOverlay.showError", app_id_value); - kiosk_app_manager_->RemoveApp(app_id); + kiosk_app_manager_->RemoveApp(app_id, owner_settings_service_); } } // namespace chromeos diff --git a/chrome/browser/ui/webui/extensions/chromeos/kiosk_apps_handler.h b/chrome/browser/ui/webui/extensions/chromeos/kiosk_apps_handler.h index 23df3a1..83fa88e 100644 --- a/chrome/browser/ui/webui/extensions/chromeos/kiosk_apps_handler.h +++ b/chrome/browser/ui/webui/extensions/chromeos/kiosk_apps_handler.h @@ -25,11 +25,12 @@ class WebUIDataSource; namespace chromeos { class KioskAppManager; +class OwnerSettingsServiceChromeOS; class KioskAppsHandler : public content::WebUIMessageHandler, public KioskAppManagerObserver { public: - KioskAppsHandler(); + explicit KioskAppsHandler(OwnerSettingsServiceChromeOS* service); ~KioskAppsHandler() override; void GetLocalizedValues(content::WebUIDataSource* source); @@ -69,6 +70,7 @@ class KioskAppsHandler : public content::WebUIMessageHandler, bool initialized_; bool is_kiosk_enabled_; bool is_auto_launch_enabled_; + OwnerSettingsServiceChromeOS* const owner_settings_service_; // not owned base::WeakPtrFactory<KioskAppsHandler> weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(KioskAppsHandler); diff --git a/chrome/browser/ui/webui/extensions/extensions_ui.cc b/chrome/browser/ui/webui/extensions/extensions_ui.cc index 49d921b..681fd3f 100644 --- a/chrome/browser/ui/webui/extensions/extensions_ui.cc +++ b/chrome/browser/ui/webui/extensions/extensions_ui.cc @@ -18,6 +18,7 @@ #include "ui/base/resource/resource_bundle.h" #if defined(OS_CHROMEOS) +#include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_factory.h" #include "chrome/browser/ui/webui/extensions/chromeos/kiosk_apps_handler.h" #endif @@ -65,7 +66,9 @@ ExtensionsUI::ExtensionsUI(content::WebUI* web_ui) : WebUIController(web_ui) { #if defined(OS_CHROMEOS) chromeos::KioskAppsHandler* kiosk_app_handler = - new chromeos::KioskAppsHandler(); + new chromeos::KioskAppsHandler( + chromeos::OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( + profile)); kiosk_app_handler->GetLocalizedValues(source); web_ui->AddMessageHandler(kiosk_app_handler); #endif diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index aafe8f5..fa9d5fa 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -727,6 +727,8 @@ 'browser/chromeos/login/wizard_controller_browsertest.cc', 'browser/chromeos/memory/oom_priority_manager_browsertest.cc', 'browser/chromeos/net/network_portal_detector_impl_browsertest.cc', + 'browser/chromeos/ownership/fake_owner_settings_service.cc', + 'browser/chromeos/ownership/fake_owner_settings_service.h', 'browser/chromeos/policy/blocking_login_browsertest.cc', 'browser/chromeos/policy/device_cloud_policy_browsertest.cc', 'browser/chromeos/policy/device_local_account_browsertest.cc', @@ -747,6 +749,8 @@ 'browser/chromeos/power/peripheral_battery_observer_browsertest.cc', 'browser/chromeos/preferences_browsertest.cc', 'browser/chromeos/profiles/profile_helper_browsertest.cc', + 'browser/chromeos/settings/scoped_cros_settings_test_helper.cc', + 'browser/chromeos/settings/scoped_cros_settings_test_helper.h', 'browser/chromeos/shutdown_policy_browsertest.cc', 'browser/chromeos/system/device_disabling_browsertest.cc', 'browser/chromeos/system/tray_accessibility_browsertest.cc', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 62572cf..1897576 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -1301,6 +1301,8 @@ 'browser/chromeos/settings/device_oauth2_token_service_unittest.cc', 'browser/chromeos/settings/device_settings_provider_unittest.cc', 'browser/chromeos/settings/device_settings_service_unittest.cc', + 'browser/chromeos/settings/scoped_cros_settings_test_helper.cc', + 'browser/chromeos/settings/scoped_cros_settings_test_helper.h', 'browser/chromeos/settings/session_manager_operation_unittest.cc', 'browser/chromeos/settings/shutdown_policy_handler_unittest.cc', 'browser/chromeos/settings/stub_cros_settings_provider_unittest.cc', |