| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" | 5 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ptr_util.h" |
| 8 #include "base/values.h" | 9 #include "base/values.h" |
| 9 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h" | 11 #include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h" |
| 11 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" | 12 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
| 12 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 13 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
| 13 #include "chrome/browser/chromeos/settings/cros_settings.h" | 14 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 14 #include "chrome/browser/chromeos/settings/device_settings_cache.h" | 15 #include "chrome/browser/chromeos/settings/device_settings_cache.h" |
| 15 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 16 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #include "components/ownership/mock_owner_key_util.h" | 18 #include "components/ownership/mock_owner_key_util.h" |
| 18 #include "policy/proto/device_management_backend.pb.h" | 19 #include "policy/proto/device_management_backend.pb.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 21 |
| 21 namespace chromeos { | 22 namespace chromeos { |
| 22 | 23 |
| 23 ScopedCrosSettingsTestHelper::ScopedCrosSettingsTestHelper() { | 24 ScopedCrosSettingsTestHelper::ScopedCrosSettingsTestHelper() { |
| 24 Initialize(true); | 25 Initialize(true); |
| 25 } | 26 } |
| 26 | 27 |
| 27 ScopedCrosSettingsTestHelper::ScopedCrosSettingsTestHelper( | 28 ScopedCrosSettingsTestHelper::ScopedCrosSettingsTestHelper( |
| 28 bool create_settings_service) { | 29 bool create_settings_service) { |
| 29 Initialize(create_settings_service); | 30 Initialize(create_settings_service); |
| 30 } | 31 } |
| 31 | 32 |
| 32 ScopedCrosSettingsTestHelper::~ScopedCrosSettingsTestHelper() { | 33 ScopedCrosSettingsTestHelper::~ScopedCrosSettingsTestHelper() { |
| 33 RestoreProvider(); | 34 RestoreProvider(); |
| 34 } | 35 } |
| 35 | 36 |
| 36 scoped_ptr<FakeOwnerSettingsService> | 37 std::unique_ptr<FakeOwnerSettingsService> |
| 37 ScopedCrosSettingsTestHelper::CreateOwnerSettingsService(Profile* profile) { | 38 ScopedCrosSettingsTestHelper::CreateOwnerSettingsService(Profile* profile) { |
| 38 return make_scoped_ptr(new FakeOwnerSettingsService( | 39 return base::WrapUnique(new FakeOwnerSettingsService( |
| 39 profile, new ownership::MockOwnerKeyUtil(), &stub_settings_provider_)); | 40 profile, new ownership::MockOwnerKeyUtil(), &stub_settings_provider_)); |
| 40 } | 41 } |
| 41 | 42 |
| 42 void ScopedCrosSettingsTestHelper::ReplaceProvider(const std::string& path) { | 43 void ScopedCrosSettingsTestHelper::ReplaceProvider(const std::string& path) { |
| 43 CHECK(!real_settings_provider_); | 44 CHECK(!real_settings_provider_); |
| 44 // Swap out the DeviceSettingsProvider with our settings provider so we can | 45 // Swap out the DeviceSettingsProvider with our settings provider so we can |
| 45 // set values for the specified path. | 46 // set values for the specified path. |
| 46 CrosSettings* const cros_settings = CrosSettings::Get(); | 47 CrosSettings* const cros_settings = CrosSettings::Get(); |
| 47 real_settings_provider_ = cros_settings->GetProvider(path); | 48 real_settings_provider_ = cros_settings->GetProvider(path); |
| 48 EXPECT_TRUE(real_settings_provider_); | 49 EXPECT_TRUE(real_settings_provider_); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 124 |
| 124 void ScopedCrosSettingsTestHelper::Initialize(bool create_settings_service) { | 125 void ScopedCrosSettingsTestHelper::Initialize(bool create_settings_service) { |
| 125 if (create_settings_service) { | 126 if (create_settings_service) { |
| 126 CHECK(!DeviceSettingsService::IsInitialized()); | 127 CHECK(!DeviceSettingsService::IsInitialized()); |
| 127 test_device_settings_service_.reset(new ScopedTestDeviceSettingsService()); | 128 test_device_settings_service_.reset(new ScopedTestDeviceSettingsService()); |
| 128 test_cros_settings_.reset(new ScopedTestCrosSettings()); | 129 test_cros_settings_.reset(new ScopedTestCrosSettings()); |
| 129 } | 130 } |
| 130 } | 131 } |
| 131 | 132 |
| 132 } // namespace chromeos | 133 } // namespace chromeos |
| OLD | NEW |