OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/prefs/profile_pref_store_manager.h" | 5 #include "chrome/browser/prefs/profile_pref_store_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "base/values.h" | 26 #include "base/values.h" |
27 #include "chrome/common/chrome_features.h" | 27 #include "chrome/common/chrome_features.h" |
28 #include "components/pref_registry/pref_registry_syncable.h" | 28 #include "components/pref_registry/pref_registry_syncable.h" |
29 #include "components/prefs/json_pref_store.h" | 29 #include "components/prefs/json_pref_store.h" |
30 #include "components/prefs/persistent_pref_store.h" | 30 #include "components/prefs/persistent_pref_store.h" |
31 #include "components/prefs/pref_service.h" | 31 #include "components/prefs/pref_service.h" |
32 #include "components/prefs/pref_service_factory.h" | 32 #include "components/prefs/pref_service_factory.h" |
33 #include "components/prefs/pref_store.h" | 33 #include "components/prefs/pref_store.h" |
34 #include "components/prefs/testing_pref_service.h" | 34 #include "components/prefs/testing_pref_service.h" |
35 #include "content/public/common/service_names.mojom.h" | 35 #include "content/public/common/service_names.mojom.h" |
36 #include "mojo/public/cpp/bindings/binding_set.h" | |
37 #include "services/preferences/public/cpp/pref_service_main.h" | 36 #include "services/preferences/public/cpp/pref_service_main.h" |
38 #include "services/preferences/public/cpp/tracked/configuration.h" | 37 #include "services/preferences/public/cpp/tracked/configuration.h" |
39 #include "services/preferences/public/cpp/tracked/mock_validation_delegate.h" | 38 #include "services/preferences/public/cpp/tracked/mock_validation_delegate.h" |
40 #include "services/preferences/public/cpp/tracked/pref_names.h" | 39 #include "services/preferences/public/cpp/tracked/pref_names.h" |
41 #include "services/preferences/public/interfaces/preferences.mojom.h" | 40 #include "services/preferences/public/interfaces/preferences.mojom.h" |
42 #include "services/service_manager/public/cpp/connector.h" | 41 #include "services/service_manager/public/cpp/connector.h" |
43 #include "services/service_manager/public/cpp/service_context.h" | 42 #include "services/service_manager/public/cpp/service_context.h" |
44 #include "testing/gtest/include/gtest/gtest.h" | 43 #include "testing/gtest/include/gtest/gtest.h" |
45 | 44 |
46 namespace { | 45 namespace { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 {0u, kTrackedAtomic, EnforcementLevel::NO_ENFORCEMENT, | 130 {0u, kTrackedAtomic, EnforcementLevel::NO_ENFORCEMENT, |
132 PrefTrackingStrategy::ATOMIC}, | 131 PrefTrackingStrategy::ATOMIC}, |
133 {1u, kProtectedAtomic, EnforcementLevel::ENFORCE_ON_LOAD, | 132 {1u, kProtectedAtomic, EnforcementLevel::ENFORCE_ON_LOAD, |
134 PrefTrackingStrategy::ATOMIC}}; | 133 PrefTrackingStrategy::ATOMIC}}; |
135 | 134 |
136 const size_t kExtraReportingId = 2u; | 135 const size_t kExtraReportingId = 2u; |
137 const size_t kReportingIdCount = 3u; | 136 const size_t kReportingIdCount = 3u; |
138 | 137 |
139 } // namespace | 138 } // namespace |
140 | 139 |
141 class ProfilePrefStoreManagerTest : public testing::TestWithParam<bool>, | 140 class ProfilePrefStoreManagerTest : public testing::TestWithParam<bool> { |
142 public prefs::mojom::ResetOnLoadObserver { | |
143 public: | 141 public: |
144 ProfilePrefStoreManagerTest() | 142 ProfilePrefStoreManagerTest() |
145 : configuration_(prefs::ConstructTrackedConfiguration(kConfiguration)), | 143 : configuration_(prefs::ConstructTrackedConfiguration(kConfiguration)), |
146 profile_pref_registry_(new user_prefs::PrefRegistrySyncable), | 144 profile_pref_registry_(new user_prefs::PrefRegistrySyncable), |
147 registry_verifier_(profile_pref_registry_.get()), | 145 registry_verifier_(profile_pref_registry_.get()), |
148 seed_("seed"), | 146 seed_("seed"), |
149 reset_recorded_(false) {} | 147 reset_recorded_(false) {} |
150 | 148 |
151 void SetUp() override { | 149 void SetUp() override { |
152 worker_pool_ = base::MakeUnique<base::SequencedWorkerPoolOwner>( | 150 worker_pool_ = base::MakeUnique<base::SequencedWorkerPoolOwner>( |
(...skipping 14 matching lines...) Expand all Loading... |
167 prefs::mojom::PrefStoreConnector::Name_)); | 165 prefs::mojom::PrefStoreConnector::Name_)); |
168 test_api.OverrideBinderForTesting( | 166 test_api.OverrideBinderForTesting( |
169 prefs::mojom::kServiceName, prefs::mojom::PrefServiceControl::Name_, | 167 prefs::mojom::kServiceName, prefs::mojom::PrefServiceControl::Name_, |
170 base::Bind(&ProfilePrefStoreManagerTest::BindInterface, | 168 base::Bind(&ProfilePrefStoreManagerTest::BindInterface, |
171 base::Unretained(this), | 169 base::Unretained(this), |
172 prefs::mojom::PrefServiceControl::Name_)); | 170 prefs::mojom::PrefServiceControl::Name_)); |
173 } else { | 171 } else { |
174 feature_list_.InitAndDisableFeature(features::kPrefService); | 172 feature_list_.InitAndDisableFeature(features::kPrefService); |
175 } | 173 } |
176 mock_validation_delegate_record_ = new MockValidationDelegateRecord; | 174 mock_validation_delegate_record_ = new MockValidationDelegateRecord; |
177 mock_validation_delegate_ = base::MakeUnique<MockValidationDelegate>( | |
178 mock_validation_delegate_record_); | |
179 | |
180 ProfilePrefStoreManager::RegisterProfilePrefs(profile_pref_registry_.get()); | 175 ProfilePrefStoreManager::RegisterProfilePrefs(profile_pref_registry_.get()); |
181 for (const prefs::TrackedPreferenceMetadata* it = kConfiguration; | 176 for (const prefs::TrackedPreferenceMetadata* it = kConfiguration; |
182 it != kConfiguration + arraysize(kConfiguration); ++it) { | 177 it != kConfiguration + arraysize(kConfiguration); ++it) { |
183 if (it->strategy == PrefTrackingStrategy::ATOMIC) { | 178 if (it->strategy == PrefTrackingStrategy::ATOMIC) { |
184 profile_pref_registry_->RegisterStringPref(it->name, std::string()); | 179 profile_pref_registry_->RegisterStringPref(it->name, std::string()); |
185 } else { | 180 } else { |
186 profile_pref_registry_->RegisterDictionaryPref(it->name); | 181 profile_pref_registry_->RegisterDictionaryPref(it->name); |
187 } | 182 } |
188 } | 183 } |
189 profile_pref_registry_->RegisterStringPref(kUnprotectedPref, std::string()); | 184 profile_pref_registry_->RegisterStringPref(kUnprotectedPref, std::string()); |
190 | 185 |
191 // As in chrome_pref_service_factory.cc, kPreferencesResetTime needs to be | 186 // As in chrome_pref_service_factory.cc, kPreferencesResetTime needs to be |
192 // declared as protected in order to be read from the proper store by the | 187 // declared as protected in order to be read from the proper store by the |
193 // SegregatedPrefStore. Only declare it after configured prefs have been | 188 // SegregatedPrefStore. Only declare it after configured prefs have been |
194 // registered above for this test as kPreferenceResetTime is already | 189 // registered above for this test as kPreferenceResetTime is already |
195 // registered in ProfilePrefStoreManager::RegisterProfilePrefs. | 190 // registered in ProfilePrefStoreManager::RegisterProfilePrefs. |
196 prefs::TrackedPreferenceMetadata pref_reset_time_config = { | 191 prefs::TrackedPreferenceMetadata pref_reset_time_config = { |
197 (*configuration_.rbegin())->reporting_id + 1, | 192 (*configuration_.rbegin())->reporting_id + 1, |
198 user_prefs::kPreferenceResetTime, EnforcementLevel::ENFORCE_ON_LOAD, | 193 user_prefs::kPreferenceResetTime, EnforcementLevel::ENFORCE_ON_LOAD, |
199 PrefTrackingStrategy::ATOMIC}; | 194 PrefTrackingStrategy::ATOMIC}; |
200 configuration_.push_back( | 195 configuration_.push_back( |
201 prefs::ConstructTrackedMetadata(pref_reset_time_config)); | 196 prefs::ConstructTrackedMetadata(pref_reset_time_config)); |
202 | 197 |
203 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); | 198 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); |
204 ReloadConfiguration(); | 199 ReloadConfiguration(); |
205 } | 200 } |
206 | 201 |
207 void ReloadConfiguration() { | 202 void ReloadConfiguration() { |
208 RelaunchPrefService(); | 203 RelaunchPrefService(); |
209 manager_.reset(new ProfilePrefStoreManager(profile_dir_.GetPath(), seed_, | 204 manager_.reset(new ProfilePrefStoreManager( |
210 "device_id")); | 205 profile_dir_.GetPath(), |
| 206 prefs::CloneTrackedConfiguration(configuration_), kReportingIdCount, |
| 207 seed_, "device_id", &local_state_)); |
211 } | 208 } |
212 | 209 |
213 void TearDown() override { | 210 void TearDown() override { |
214 DestroyPrefStore(); | 211 DestroyPrefStore(); |
215 if (GetParam()) { | 212 if (GetParam()) { |
216 connector_.reset(); | 213 connector_.reset(); |
217 pref_service_context_.reset(); | 214 pref_service_context_.reset(); |
218 } | 215 } |
219 worker_pool_.reset(); | 216 worker_pool_.reset(); |
220 } | 217 } |
221 | 218 |
222 protected: | 219 protected: |
| 220 bool SupportsPreferenceTracking() { |
| 221 return ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking && |
| 222 !GetParam(); |
| 223 } |
| 224 |
223 void RelaunchPrefService() { | 225 void RelaunchPrefService() { |
224 if (!GetParam()) | 226 if (!GetParam()) |
225 return; | 227 return; |
226 | 228 |
227 service_manager::mojom::ServicePtr service_ptr; | 229 service_manager::mojom::ServicePtr service_ptr; |
228 pref_service_context_ = base::MakeUnique<service_manager::ServiceContext>( | 230 pref_service_context_ = base::MakeUnique<service_manager::ServiceContext>( |
229 prefs::CreatePrefService(std::set<PrefValueStore::PrefStoreType>(), | 231 prefs::CreatePrefService(std::set<PrefValueStore::PrefStoreType>(), |
230 worker_pool_->pool()), | 232 worker_pool_->pool()), |
231 mojo::MakeRequest(&service_ptr)); | 233 mojo::MakeRequest(&service_ptr)); |
232 } | 234 } |
233 | 235 |
234 // Verifies whether a reset was reported via the OnResetOnLoad() hook. Also | 236 // Verifies whether a reset was reported via the RecordReset() hook. Also |
235 // verifies that GetResetTime() was set (or not) accordingly. | 237 // verifies that GetResetTime() was set (or not) accordingly. |
236 void VerifyResetRecorded(bool reset_expected) { | 238 void VerifyResetRecorded(bool reset_expected) { |
237 base::RunLoop().RunUntilIdle(); | |
238 EXPECT_EQ(reset_expected, reset_recorded_); | 239 EXPECT_EQ(reset_expected, reset_recorded_); |
239 | 240 |
240 PrefServiceFactory pref_service_factory; | 241 PrefServiceFactory pref_service_factory; |
241 pref_service_factory.set_user_prefs(pref_store_); | 242 pref_service_factory.set_user_prefs(pref_store_); |
242 | 243 |
243 std::unique_ptr<PrefService> pref_service( | 244 std::unique_ptr<PrefService> pref_service( |
244 pref_service_factory.Create(profile_pref_registry_.get())); | 245 pref_service_factory.Create(profile_pref_registry_.get())); |
245 | 246 |
246 EXPECT_EQ( | 247 EXPECT_EQ( |
247 reset_expected, | 248 reset_expected, |
248 !ProfilePrefStoreManager::GetResetTime(pref_service.get()).is_null()); | 249 !ProfilePrefStoreManager::GetResetTime(pref_service.get()).is_null()); |
249 } | 250 } |
250 | 251 |
251 void ClearResetRecorded() { | 252 void ClearResetRecorded() { |
252 reset_recorded_ = false; | 253 reset_recorded_ = false; |
253 | 254 |
254 PrefServiceFactory pref_service_factory; | 255 PrefServiceFactory pref_service_factory; |
255 pref_service_factory.set_user_prefs(pref_store_); | 256 pref_service_factory.set_user_prefs(pref_store_); |
256 | 257 |
257 std::unique_ptr<PrefService> pref_service( | 258 std::unique_ptr<PrefService> pref_service( |
258 pref_service_factory.Create(profile_pref_registry_.get())); | 259 pref_service_factory.Create(profile_pref_registry_.get())); |
259 | 260 |
260 ProfilePrefStoreManager::ClearResetTime(pref_service.get()); | 261 ProfilePrefStoreManager::ClearResetTime(pref_service.get()); |
261 } | 262 } |
262 | 263 |
263 void InitializePrefs() { | 264 void InitializePrefs() { |
264 // According to the implementation of ProfilePrefStoreManager, this is | 265 // According to the implementation of ProfilePrefStoreManager, this is |
265 // actually a SegregatedPrefStore backed by two underlying pref stores. | 266 // actually a SegregatedPrefStore backed by two underlying pref stores. |
| 267 mock_validation_delegate_ = base::MakeUnique<MockValidationDelegate>( |
| 268 mock_validation_delegate_record_); |
266 scoped_refptr<PersistentPrefStore> pref_store = | 269 scoped_refptr<PersistentPrefStore> pref_store = |
267 manager_->CreateProfilePrefStore( | 270 manager_->CreateProfilePrefStore( |
268 prefs::CloneTrackedConfiguration(configuration_), kReportingIdCount, | 271 main_message_loop_.task_runner(), |
269 worker_pool_->pool().get(), | 272 base::Bind(&ProfilePrefStoreManagerTest::RecordReset, |
270 reset_on_load_observer_bindings_.CreateInterfacePtrAndBind(this), | 273 base::Unretained(this)), |
271 mock_validation_delegate_bindings_.CreateInterfacePtrAndBind( | 274 mock_validation_delegate_.get(), connector_.get(), |
272 mock_validation_delegate_.get()), | 275 profile_pref_registry_); |
273 connector_.get(), profile_pref_registry_); | |
274 InitializePrefStore(pref_store.get()); | 276 InitializePrefStore(pref_store.get()); |
275 pref_store = NULL; | 277 pref_store = NULL; |
276 base::RunLoop().RunUntilIdle(); | 278 base::RunLoop().RunUntilIdle(); |
277 } | 279 } |
278 | 280 |
279 void DestroyPrefStore() { | 281 void DestroyPrefStore() { |
280 if (pref_store_.get()) { | 282 if (pref_store_.get()) { |
281 ClearResetRecorded(); | 283 ClearResetRecorded(); |
282 // Force everything to be written to disk, triggering the PrefHashFilter | 284 // Force everything to be written to disk, triggering the PrefHashFilter |
283 // while our RegistryVerifier is watching. | 285 // while our RegistryVerifier is watching. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 base::RunLoop run_loop; | 320 base::RunLoop run_loop; |
319 JsonPrefStore::GetTaskRunnerForFile(profile_dir_.GetPath(), | 321 JsonPrefStore::GetTaskRunnerForFile(profile_dir_.GetPath(), |
320 worker_pool_->pool().get()) | 322 worker_pool_->pool().get()) |
321 ->PostTaskAndReply(FROM_HERE, base::Bind(&base::DoNothing), | 323 ->PostTaskAndReply(FROM_HERE, base::Bind(&base::DoNothing), |
322 run_loop.QuitClosure()); | 324 run_loop.QuitClosure()); |
323 run_loop.Run(); | 325 run_loop.Run(); |
324 } | 326 } |
325 | 327 |
326 void LoadExistingPrefs() { | 328 void LoadExistingPrefs() { |
327 DestroyPrefStore(); | 329 DestroyPrefStore(); |
| 330 // Constructing the PrefStore consumes the tracking configuration in |
| 331 // |manager_|, so recreate it before constructing another PrefStore. |
| 332 ReloadConfiguration(); |
| 333 mock_validation_delegate_ = base::MakeUnique<MockValidationDelegate>( |
| 334 mock_validation_delegate_record_); |
328 pref_store_ = manager_->CreateProfilePrefStore( | 335 pref_store_ = manager_->CreateProfilePrefStore( |
329 prefs::CloneTrackedConfiguration(configuration_), kReportingIdCount, | 336 JsonPrefStore::GetTaskRunnerForFile(profile_dir_.GetPath(), |
330 worker_pool_->pool().get(), | 337 worker_pool_->pool().get()), |
331 reset_on_load_observer_bindings_.CreateInterfacePtrAndBind(this), | 338 base::Bind(&ProfilePrefStoreManagerTest::RecordReset, |
332 mock_validation_delegate_bindings_.CreateInterfacePtrAndBind( | 339 base::Unretained(this)), |
333 mock_validation_delegate_.get()), | 340 mock_validation_delegate_.get(), connector_.get(), |
334 connector_.get(), profile_pref_registry_); | 341 profile_pref_registry_); |
335 pref_store_->AddObserver(®istry_verifier_); | 342 pref_store_->AddObserver(®istry_verifier_); |
336 PrefStoreReadObserver read_observer(pref_store_); | 343 PrefStoreReadObserver read_observer(pref_store_); |
337 read_observer.Read(); | 344 read_observer.Read(); |
338 } | 345 } |
339 | 346 |
340 void ReplaceStringInPrefs(const std::string& find, | 347 void ReplaceStringInPrefs(const std::string& find, |
341 const std::string& replace) { | 348 const std::string& replace) { |
342 base::FileEnumerator file_enum(profile_dir_.GetPath(), true, | 349 base::FileEnumerator file_enum(profile_dir_.GetPath(), true, |
343 base::FileEnumerator::FILES); | 350 base::FileEnumerator::FILES); |
344 | 351 |
(...skipping 16 matching lines...) Expand all Loading... |
361 ADD_FAILURE() << name << " is not a defined value."; | 368 ADD_FAILURE() << name << " is not a defined value."; |
362 } else if (!value->GetAsString(&as_string)) { | 369 } else if (!value->GetAsString(&as_string)) { |
363 ADD_FAILURE() << name << " could not be coerced to a string."; | 370 ADD_FAILURE() << name << " could not be coerced to a string."; |
364 } else { | 371 } else { |
365 EXPECT_EQ(expected, as_string); | 372 EXPECT_EQ(expected, as_string); |
366 } | 373 } |
367 } | 374 } |
368 | 375 |
369 void ExpectValidationObserved(const std::string& pref_path) { | 376 void ExpectValidationObserved(const std::string& pref_path) { |
370 // No validations are expected for platforms that do not support tracking. | 377 // No validations are expected for platforms that do not support tracking. |
371 if (!ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking) | 378 if (!SupportsPreferenceTracking()) |
372 return; | 379 return; |
373 if (!mock_validation_delegate_record_->GetEventForPath(pref_path)) | 380 if (!mock_validation_delegate_record_->GetEventForPath(pref_path)) |
374 ADD_FAILURE() << "No validation observed for preference: " << pref_path; | 381 ADD_FAILURE() << "No validation observed for preference: " << pref_path; |
375 } | 382 } |
376 | 383 |
377 base::MessageLoop main_message_loop_; | 384 base::MessageLoop main_message_loop_; |
378 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> configuration_; | 385 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> configuration_; |
379 base::ScopedTempDir profile_dir_; | 386 base::ScopedTempDir profile_dir_; |
| 387 TestingPrefServiceSimple local_state_; |
380 scoped_refptr<user_prefs::PrefRegistrySyncable> profile_pref_registry_; | 388 scoped_refptr<user_prefs::PrefRegistrySyncable> profile_pref_registry_; |
381 RegistryVerifier registry_verifier_; | 389 RegistryVerifier registry_verifier_; |
382 scoped_refptr<MockValidationDelegateRecord> mock_validation_delegate_record_; | 390 scoped_refptr<MockValidationDelegateRecord> mock_validation_delegate_record_; |
383 std::unique_ptr<MockValidationDelegate> mock_validation_delegate_; | 391 std::unique_ptr<prefs::mojom::TrackedPreferenceValidationDelegate> |
384 mojo::BindingSet<prefs::mojom::TrackedPreferenceValidationDelegate> | 392 mock_validation_delegate_; |
385 mock_validation_delegate_bindings_; | |
386 std::unique_ptr<ProfilePrefStoreManager> manager_; | 393 std::unique_ptr<ProfilePrefStoreManager> manager_; |
387 scoped_refptr<PersistentPrefStore> pref_store_; | 394 scoped_refptr<PersistentPrefStore> pref_store_; |
388 | 395 |
389 std::string seed_; | 396 std::string seed_; |
390 | 397 |
391 private: | 398 private: |
392 void OnResetOnLoad() override { | 399 void RecordReset() { |
393 // As-is |reset_recorded_| is only designed to remember a single reset, make | 400 // As-is |reset_recorded_| is only designed to remember a single reset, make |
394 // sure none was previously recorded (or that ClearResetRecorded() was | 401 // sure none was previously recorded (or that ClearResetRecorded() was |
395 // called). | 402 // called). |
396 EXPECT_FALSE(reset_recorded_); | 403 EXPECT_FALSE(reset_recorded_); |
397 reset_recorded_ = true; | 404 reset_recorded_ = true; |
398 } | 405 } |
399 | 406 |
400 void BindInterface(const std::string& interface_name, | 407 void BindInterface(const std::string& interface_name, |
401 mojo::ScopedMessagePipeHandle handle) { | 408 mojo::ScopedMessagePipeHandle handle) { |
402 service_manager::ServiceInfo source( | 409 service_manager::ServiceInfo source( |
403 service_manager::Identity(content::mojom::kBrowserServiceName, | 410 service_manager::Identity(content::mojom::kBrowserServiceName, |
404 service_manager::mojom::kRootUserID), | 411 service_manager::mojom::kRootUserID), |
405 service_manager::InterfaceProviderSpecMap()); | 412 service_manager::InterfaceProviderSpecMap()); |
406 static_cast<service_manager::mojom::Service*>(pref_service_context_.get()) | 413 static_cast<service_manager::mojom::Service*>(pref_service_context_.get()) |
407 ->OnBindInterface(source, interface_name, std::move(handle), | 414 ->OnBindInterface(source, interface_name, std::move(handle), |
408 base::Bind(&base::DoNothing)); | 415 base::Bind(&base::DoNothing)); |
409 } | 416 } |
410 | 417 |
411 base::test::ScopedFeatureList feature_list_; | 418 base::test::ScopedFeatureList feature_list_; |
412 bool reset_recorded_; | 419 bool reset_recorded_; |
413 std::unique_ptr<base::SequencedWorkerPoolOwner> worker_pool_; | 420 std::unique_ptr<base::SequencedWorkerPoolOwner> worker_pool_; |
414 std::unique_ptr<service_manager::ServiceContext> pref_service_context_; | 421 std::unique_ptr<service_manager::ServiceContext> pref_service_context_; |
415 std::unique_ptr<service_manager::Connector> connector_; | 422 std::unique_ptr<service_manager::Connector> connector_; |
416 service_manager::mojom::ConnectorRequest connector_request_; | 423 service_manager::mojom::ConnectorRequest connector_request_; |
417 mojo::BindingSet<prefs::mojom::ResetOnLoadObserver> | |
418 reset_on_load_observer_bindings_; | |
419 }; | 424 }; |
420 | 425 |
421 TEST_P(ProfilePrefStoreManagerTest, StoreValues) { | 426 TEST_P(ProfilePrefStoreManagerTest, StoreValues) { |
422 InitializePrefs(); | 427 InitializePrefs(); |
423 | 428 |
424 LoadExistingPrefs(); | 429 LoadExistingPrefs(); |
425 | 430 |
426 ExpectStringValueEquals(kTrackedAtomic, kFoobar); | 431 ExpectStringValueEquals(kTrackedAtomic, kFoobar); |
427 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); | 432 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); |
428 VerifyResetRecorded(false); | 433 VerifyResetRecorded(false); |
429 ExpectValidationObserved(kTrackedAtomic); | 434 ExpectValidationObserved(kTrackedAtomic); |
430 ExpectValidationObserved(kProtectedAtomic); | 435 ExpectValidationObserved(kProtectedAtomic); |
431 } | 436 } |
432 | 437 |
433 TEST_P(ProfilePrefStoreManagerTest, ProtectValues) { | 438 TEST_P(ProfilePrefStoreManagerTest, ProtectValues) { |
434 InitializePrefs(); | 439 InitializePrefs(); |
435 | 440 |
436 ReplaceStringInPrefs(kFoobar, kBarfoo); | 441 ReplaceStringInPrefs(kFoobar, kBarfoo); |
437 ReplaceStringInPrefs(kHelloWorld, kGoodbyeWorld); | 442 ReplaceStringInPrefs(kHelloWorld, kGoodbyeWorld); |
438 | 443 |
439 LoadExistingPrefs(); | 444 LoadExistingPrefs(); |
440 | 445 |
441 // kTrackedAtomic is unprotected and thus will be loaded as it appears on | 446 // kTrackedAtomic is unprotected and thus will be loaded as it appears on |
442 // disk. | 447 // disk. |
443 ExpectStringValueEquals(kTrackedAtomic, kBarfoo); | 448 ExpectStringValueEquals(kTrackedAtomic, kBarfoo); |
444 | 449 |
445 // If preference tracking is supported, the tampered value of kProtectedAtomic | 450 // If preference tracking is supported, the tampered value of kProtectedAtomic |
446 // will be discarded at load time, leaving this preference undefined. | 451 // will be discarded at load time, leaving this preference undefined. |
447 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 452 EXPECT_NE(SupportsPreferenceTracking(), |
448 pref_store_->GetValue(kProtectedAtomic, NULL)); | 453 pref_store_->GetValue(kProtectedAtomic, NULL)); |
449 VerifyResetRecorded( | 454 VerifyResetRecorded(SupportsPreferenceTracking()); |
450 ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking); | |
451 | 455 |
452 ExpectValidationObserved(kTrackedAtomic); | 456 ExpectValidationObserved(kTrackedAtomic); |
453 ExpectValidationObserved(kProtectedAtomic); | 457 ExpectValidationObserved(kProtectedAtomic); |
454 } | 458 } |
455 | 459 |
456 TEST_P(ProfilePrefStoreManagerTest, InitializePrefsFromMasterPrefs) { | 460 TEST_P(ProfilePrefStoreManagerTest, InitializePrefsFromMasterPrefs) { |
457 auto master_prefs = base::MakeUnique<base::DictionaryValue>(); | 461 auto master_prefs = base::MakeUnique<base::DictionaryValue>(); |
458 master_prefs->Set(kTrackedAtomic, new base::Value(kFoobar)); | 462 master_prefs->Set(kTrackedAtomic, new base::Value(kFoobar)); |
459 master_prefs->Set(kProtectedAtomic, new base::Value(kHelloWorld)); | 463 master_prefs->Set(kProtectedAtomic, new base::Value(kHelloWorld)); |
460 EXPECT_TRUE(manager_->InitializePrefsFromMasterPrefs( | 464 EXPECT_TRUE( |
461 prefs::CloneTrackedConfiguration(configuration_), kReportingIdCount, | 465 manager_->InitializePrefsFromMasterPrefs(std::move(master_prefs))); |
462 std::move(master_prefs))); | |
463 | 466 |
464 LoadExistingPrefs(); | 467 LoadExistingPrefs(); |
465 | 468 |
466 // Verify that InitializePrefsFromMasterPrefs correctly applied the MACs | 469 // Verify that InitializePrefsFromMasterPrefs correctly applied the MACs |
467 // necessary to authenticate these values. | 470 // necessary to authenticate these values. |
468 ExpectStringValueEquals(kTrackedAtomic, kFoobar); | 471 ExpectStringValueEquals(kTrackedAtomic, kFoobar); |
469 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); | 472 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); |
470 VerifyResetRecorded(false); | 473 VerifyResetRecorded(false); |
471 } | 474 } |
472 | 475 |
(...skipping 30 matching lines...) Expand all Loading... |
503 ExpectStringValueEquals(kUnprotectedPref, kBarfoo); | 506 ExpectStringValueEquals(kUnprotectedPref, kBarfoo); |
504 VerifyResetRecorded(false); | 507 VerifyResetRecorded(false); |
505 | 508 |
506 // Ensure everything is written out to disk. | 509 // Ensure everything is written out to disk. |
507 DestroyPrefStore(); | 510 DestroyPrefStore(); |
508 | 511 |
509 // It's protected now, so (if the platform supports it) any tampering should | 512 // It's protected now, so (if the platform supports it) any tampering should |
510 // lead to a reset. | 513 // lead to a reset. |
511 ReplaceStringInPrefs(kBarfoo, kFoobar); | 514 ReplaceStringInPrefs(kBarfoo, kFoobar); |
512 LoadExistingPrefs(); | 515 LoadExistingPrefs(); |
513 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 516 EXPECT_NE(SupportsPreferenceTracking(), |
514 pref_store_->GetValue(kUnprotectedPref, NULL)); | 517 pref_store_->GetValue(kUnprotectedPref, NULL)); |
515 VerifyResetRecorded( | 518 VerifyResetRecorded(SupportsPreferenceTracking()); |
516 ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking); | |
517 } | 519 } |
518 | 520 |
519 TEST_P(ProfilePrefStoreManagerTest, NewPrefWhenFirstProtecting) { | 521 TEST_P(ProfilePrefStoreManagerTest, NewPrefWhenFirstProtecting) { |
520 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> | 522 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> |
521 original_configuration = prefs::CloneTrackedConfiguration(configuration_); | 523 original_configuration = prefs::CloneTrackedConfiguration(configuration_); |
522 for (const auto& metadata : configuration_) { | 524 for (const auto& metadata : configuration_) { |
523 metadata->enforcement_level = EnforcementLevel::NO_ENFORCEMENT; | 525 metadata->enforcement_level = EnforcementLevel::NO_ENFORCEMENT; |
524 } | 526 } |
525 ReloadConfiguration(); | 527 ReloadConfiguration(); |
526 | 528 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 PrefTrackingStrategy::ATOMIC}; | 566 PrefTrackingStrategy::ATOMIC}; |
565 configuration_.push_back(prefs::ConstructTrackedMetadata(new_protected)); | 567 configuration_.push_back(prefs::ConstructTrackedMetadata(new_protected)); |
566 seed_ = "new-seed-to-break-trust"; | 568 seed_ = "new-seed-to-break-trust"; |
567 ReloadConfiguration(); | 569 ReloadConfiguration(); |
568 | 570 |
569 // And try loading with the new configuration. | 571 // And try loading with the new configuration. |
570 LoadExistingPrefs(); | 572 LoadExistingPrefs(); |
571 | 573 |
572 // If preference tracking is supported, kUnprotectedPref will have been | 574 // If preference tracking is supported, kUnprotectedPref will have been |
573 // discarded because new values are not accepted without a valid super MAC. | 575 // discarded because new values are not accepted without a valid super MAC. |
574 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 576 EXPECT_NE(SupportsPreferenceTracking(), |
575 pref_store_->GetValue(kUnprotectedPref, NULL)); | 577 pref_store_->GetValue(kUnprotectedPref, NULL)); |
576 VerifyResetRecorded( | 578 VerifyResetRecorded(SupportsPreferenceTracking()); |
577 ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking); | |
578 } | 579 } |
579 | 580 |
580 // This test verifies that preference values are correctly maintained when a | 581 // This test verifies that preference values are correctly maintained when a |
581 // preference's protection state changes from protected to unprotected. | 582 // preference's protection state changes from protected to unprotected. |
582 TEST_P(ProfilePrefStoreManagerTest, ProtectedToUnprotected) { | 583 TEST_P(ProfilePrefStoreManagerTest, ProtectedToUnprotected) { |
583 InitializePrefs(); | 584 InitializePrefs(); |
584 | 585 |
585 ExpectValidationObserved(kTrackedAtomic); | 586 ExpectValidationObserved(kTrackedAtomic); |
586 ExpectValidationObserved(kProtectedAtomic); | 587 ExpectValidationObserved(kProtectedAtomic); |
587 | 588 |
(...skipping 24 matching lines...) Expand all Loading... |
612 // Trigger the logic that migrates it back to the unprotected preferences | 613 // Trigger the logic that migrates it back to the unprotected preferences |
613 // file. | 614 // file. |
614 pref_store_->SetValue(kProtectedAtomic, | 615 pref_store_->SetValue(kProtectedAtomic, |
615 base::WrapUnique(new base::Value(kGoodbyeWorld)), | 616 base::WrapUnique(new base::Value(kGoodbyeWorld)), |
616 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 617 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
617 LoadExistingPrefs(); | 618 LoadExistingPrefs(); |
618 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); | 619 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); |
619 VerifyResetRecorded(false); | 620 VerifyResetRecorded(false); |
620 } | 621 } |
621 | 622 |
622 // The parameter controls whether the user pref store is created within a | |
623 // service. | |
624 INSTANTIATE_TEST_CASE_P(ProfilePrefStoreManagerTest, | 623 INSTANTIATE_TEST_CASE_P(ProfilePrefStoreManagerTest, |
625 ProfilePrefStoreManagerTest, | 624 ProfilePrefStoreManagerTest, |
626 testing::Bool()); | 625 testing::Bool()); |
OLD | NEW |