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