Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: chrome/browser/prefs/tracked/pref_hash_browsertest.cc

Issue 2396443002: Revert of Integrate registry_hash_store_contents with the rest of tracked prefs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/base_switches.h" 8 #include "base/base_switches.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 20 matching lines...) Expand all
31 #include "chrome/test/base/testing_profile.h" 31 #include "chrome/test/base/testing_profile.h"
32 #include "components/search_engines/default_search_manager.h" 32 #include "components/search_engines/default_search_manager.h"
33 #include "components/user_prefs/tracked/tracked_preference_histogram_names.h" 33 #include "components/user_prefs/tracked/tracked_preference_histogram_names.h"
34 #include "extensions/browser/pref_names.h" 34 #include "extensions/browser/pref_names.h"
35 #include "extensions/common/extension.h" 35 #include "extensions/common/extension.h"
36 36
37 #if defined(OS_CHROMEOS) 37 #if defined(OS_CHROMEOS)
38 #include "chromeos/chromeos_switches.h" 38 #include "chromeos/chromeos_switches.h"
39 #endif 39 #endif
40 40
41 #if defined(OS_WIN)
42 #include "base/test/test_reg_util_win.h"
43 #endif
44
45 namespace { 41 namespace {
46 42
47 // Extension ID of chrome/test/data/extensions/good.crx 43 // Extension ID of chrome/test/data/extensions/good.crx
48 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; 44 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
49 45
50 // Explicit expectations from the caller of GetTrackedPrefHistogramCount(). This 46 // Explicit expectations from the caller of GetTrackedPrefHistogramCount(). This
51 // enables detailed reporting of the culprit on failure. 47 // enables detailed reporting of the culprit on failure.
52 enum AllowedBuckets { 48 enum AllowedBuckets {
53 // Allow no samples in any buckets. 49 // Allow no samples in any buckets.
54 ALLOW_NONE = -1, 50 ALLOW_NONE = -1,
55 // Any integer between BEGIN_ALLOW_SINGLE_BUCKET and END_ALLOW_SINGLE_BUCKET 51 // Any integer between BEGIN_ALLOW_SINGLE_BUCKET and END_ALLOW_SINGLE_BUCKET
56 // indicates that only this specific bucket is allowed to have a sample. 52 // indicates that only this specific bucket is allowed to have a sample.
57 BEGIN_ALLOW_SINGLE_BUCKET = 0, 53 BEGIN_ALLOW_SINGLE_BUCKET = 0,
58 END_ALLOW_SINGLE_BUCKET = 100, 54 END_ALLOW_SINGLE_BUCKET = 100,
59 // Allow any buckets (no extra verifications performed). 55 // Allow any buckets (no extra verifications performed).
60 ALLOW_ANY 56 ALLOW_ANY
61 }; 57 };
62 58
63 #if defined(OS_WIN)
64 base::string16 GetRegistryPathForTestProfile() {
65 base::FilePath profile_dir;
66 EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &profile_dir));
67 return L"SOFTWARE\\Chromium\\PrefHashBrowserTest\\" +
68 profile_dir.BaseName().value();
69 }
70 #endif
71
72 // Returns the number of times |histogram_name| was reported so far; adding the 59 // Returns the number of times |histogram_name| was reported so far; adding the
73 // results of the first 100 buckets (there are only ~19 reporting IDs as of this 60 // results of the first 100 buckets (there are only ~19 reporting IDs as of this
74 // writing; varies depending on the platform). |allowed_buckets| hints at extra 61 // writing; varies depending on the platform). |allowed_buckets| hints at extra
75 // requirements verified in this method (see AllowedBuckets for details). 62 // requirements verified in this method (see AllowedBuckets for details).
76 int GetTrackedPrefHistogramCount(const char* histogram_name, 63 int GetTrackedPrefHistogramCount(const char* histogram_name,
77 const char* histogram_suffix,
78 int allowed_buckets) { 64 int allowed_buckets) {
79 std::string full_histogram_name(histogram_name);
80 if (*histogram_suffix)
81 full_histogram_name.append(".").append(histogram_suffix);
82 const base::HistogramBase* histogram = 65 const base::HistogramBase* histogram =
83 base::StatisticsRecorder::FindHistogram(full_histogram_name); 66 base::StatisticsRecorder::FindHistogram(histogram_name);
84 if (!histogram) 67 if (!histogram)
85 return 0; 68 return 0;
86 69
87 std::unique_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); 70 std::unique_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples());
88 int sum = 0; 71 int sum = 0;
89 for (int i = 0; i < 100; ++i) { 72 for (int i = 0; i < 100; ++i) {
90 int count_for_id = samples->GetCount(i); 73 int count_for_id = samples->GetCount(i);
91 EXPECT_GE(count_for_id, 0); 74 EXPECT_GE(count_for_id, 0);
92 sum += count_for_id; 75 sum += count_for_id;
93 76
94 if (allowed_buckets == ALLOW_NONE || 77 if (allowed_buckets == ALLOW_NONE ||
95 (allowed_buckets != ALLOW_ANY && i != allowed_buckets)) { 78 (allowed_buckets != ALLOW_ANY && i != allowed_buckets)) {
96 EXPECT_EQ(0, count_for_id) << "Unexpected reporting_id: " << i; 79 EXPECT_EQ(0, count_for_id) << "Unexpected reporting_id: " << i;
97 } 80 }
98 } 81 }
99 return sum; 82 return sum;
100 } 83 }
101 84
102 // Helper function to call GetTrackedPrefHistogramCount with no external
103 // validation suffix.
104 int GetTrackedPrefHistogramCount(const char* histogram_name,
105 int allowed_buckets) {
106 return GetTrackedPrefHistogramCount(histogram_name, "", allowed_buckets);
107 }
108
109 std::unique_ptr<base::DictionaryValue> ReadPrefsDictionary( 85 std::unique_ptr<base::DictionaryValue> ReadPrefsDictionary(
110 const base::FilePath& pref_file) { 86 const base::FilePath& pref_file) {
111 JSONFileValueDeserializer deserializer(pref_file); 87 JSONFileValueDeserializer deserializer(pref_file);
112 int error_code = JSONFileValueDeserializer::JSON_NO_ERROR; 88 int error_code = JSONFileValueDeserializer::JSON_NO_ERROR;
113 std::string error_str; 89 std::string error_str;
114 std::unique_ptr<base::Value> prefs = 90 std::unique_ptr<base::Value> prefs =
115 deserializer.Deserialize(&error_code, &error_str); 91 deserializer.Deserialize(&error_code, &error_str);
116 if (!prefs || error_code != JSONFileValueDeserializer::JSON_NO_ERROR) { 92 if (!prefs || error_code != JSONFileValueDeserializer::JSON_NO_ERROR) {
117 ADD_FAILURE() << "Error #" << error_code << ": " << error_str; 93 ADD_FAILURE() << "Error #" << error_code << ": " << error_str;
118 return std::unique_ptr<base::DictionaryValue>(); 94 return std::unique_ptr<base::DictionaryValue>();
119 } 95 }
120 if (!prefs->IsType(base::Value::TYPE_DICTIONARY)) { 96 if (!prefs->IsType(base::Value::TYPE_DICTIONARY)) {
121 ADD_FAILURE(); 97 ADD_FAILURE();
122 return std::unique_ptr<base::DictionaryValue>(); 98 return std::unique_ptr<base::DictionaryValue>();
123 } 99 }
124 return std::unique_ptr<base::DictionaryValue>( 100 return std::unique_ptr<base::DictionaryValue>(
125 static_cast<base::DictionaryValue*>(prefs.release())); 101 static_cast<base::DictionaryValue*>(prefs.release()));
126 } 102 }
127 103
128 // Returns whether external validation is supported on the platform through
129 // storing MACs in the registry.
130 bool SupportsRegistryValidation() {
131 #if defined(OS_WIN)
132 return true;
133 #else
134 return false;
135 #endif
136 }
137
138 #define PREF_HASH_BROWSER_TEST(fixture, test_name) \ 104 #define PREF_HASH_BROWSER_TEST(fixture, test_name) \
139 IN_PROC_BROWSER_TEST_P(fixture, PRE_##test_name) { \ 105 IN_PROC_BROWSER_TEST_P(fixture, PRE_##test_name) { \
140 SetupPreferences(); \ 106 SetupPreferences(); \
141 } \ 107 } \
142 IN_PROC_BROWSER_TEST_P(fixture, test_name) { \ 108 IN_PROC_BROWSER_TEST_P(fixture, test_name) { \
143 VerifyReactionToPrefAttack(); \ 109 VerifyReactionToPrefAttack(); \
144 } \ 110 } \
145 INSTANTIATE_TEST_CASE_P( \ 111 INSTANTIATE_TEST_CASE_P( \
146 fixture##Instance, \ 112 fixture##Instance, \
147 fixture, \ 113 fixture, \
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 226
261 return true; 227 return true;
262 } 228 }
263 229
264 void SetUpInProcessBrowserTestFixture() override { 230 void SetUpInProcessBrowserTestFixture() override {
265 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture(); 231 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture();
266 232
267 // Bots are on a domain, turn off the domain check for settings hardening in 233 // Bots are on a domain, turn off the domain check for settings hardening in
268 // order to be able to test all SettingsEnforcement groups. 234 // order to be able to test all SettingsEnforcement groups.
269 chrome_prefs::DisableDomainCheckForTesting(); 235 chrome_prefs::DisableDomainCheckForTesting();
270
271 #if defined(OS_WIN)
272 // Avoid polluting prefs for the user and the bots by writing to a specific
273 // testing registry path.
274 registry_key_for_external_validation_ = GetRegistryPathForTestProfile();
275 ProfilePrefStoreManager::SetPreferenceValidationRegistryPathForTesting(
276 &registry_key_for_external_validation_);
277
278 // Keys should be unique, but to avoid flakes in the long run make sure an
279 // identical test key wasn't left behind by a previous test.
280 if (IsPRETest()) {
281 base::win::RegKey key;
282 if (key.Open(HKEY_CURRENT_USER,
283 registry_key_for_external_validation_.c_str(),
284 KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) {
285 LONG result = key.DeleteKey(L"");
286 ASSERT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
287 }
288 }
289 #endif
290 }
291
292 void TearDown() override {
293 #if defined(OS_WIN)
294 // When done, delete the Registry key to avoid polluting the registry.
295 // TODO(proberge): it would be nice to delete keys from interrupted tests
296 // as well.
297 if (!IsPRETest()) {
298 base::string16 registry_key = GetRegistryPathForTestProfile();
299 base::win::RegKey key;
300 if (key.Open(HKEY_CURRENT_USER, registry_key.c_str(),
301 KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) {
302 LONG result = key.DeleteKey(L"");
303 ASSERT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
304 }
305 }
306 #endif
307 ExtensionBrowserTest::TearDown();
308 } 236 }
309 237
310 // In the PRE_ test, find the number of tracked preferences that were 238 // In the PRE_ test, find the number of tracked preferences that were
311 // initialized and save it to a file to be read back in the main test and used 239 // initialized and save it to a file to be read back in the main test and used
312 // as the total number of tracked preferences. 240 // as the total number of tracked preferences.
313 void SetUpOnMainThread() override { 241 void SetUpOnMainThread() override {
314 ExtensionBrowserTest::SetUpOnMainThread(); 242 ExtensionBrowserTest::SetUpOnMainThread();
315 243
316 // File in which the PRE_ test will save the number of tracked preferences 244 // File in which the PRE_ test will save the number of tracked preferences
317 // on this platform. 245 // on this platform.
(...skipping 13 matching lines...) Expand all
331 259
332 // Split tracked prefs are reported as Unchanged not as NullInitialized 260 // Split tracked prefs are reported as Unchanged not as NullInitialized
333 // when an empty dictionary is encountered on first run (this should only 261 // when an empty dictionary is encountered on first run (this should only
334 // hit for pref #5 in the current design). 262 // hit for pref #5 in the current design).
335 int num_split_tracked_prefs = GetTrackedPrefHistogramCount( 263 int num_split_tracked_prefs = GetTrackedPrefHistogramCount(
336 user_prefs::tracked::kTrackedPrefHistogramUnchanged, 264 user_prefs::tracked::kTrackedPrefHistogramUnchanged,
337 BEGIN_ALLOW_SINGLE_BUCKET + 5); 265 BEGIN_ALLOW_SINGLE_BUCKET + 5);
338 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, 266 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0,
339 num_split_tracked_prefs); 267 num_split_tracked_prefs);
340 268
341 if (SupportsRegistryValidation()) {
342 // Same checks as above, but for the registry.
343 num_tracked_prefs_ = GetTrackedPrefHistogramCount(
344 user_prefs::tracked::kTrackedPrefHistogramNullInitialized,
345 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
346 ALLOW_ANY);
347 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM,
348 num_tracked_prefs_ > 0);
349
350 int num_split_tracked_prefs = GetTrackedPrefHistogramCount(
351 user_prefs::tracked::kTrackedPrefHistogramUnchanged,
352 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
353 BEGIN_ALLOW_SINGLE_BUCKET + 5);
354 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0,
355 num_split_tracked_prefs);
356 }
357
358 num_tracked_prefs_ += num_split_tracked_prefs; 269 num_tracked_prefs_ += num_split_tracked_prefs;
359 270
360 std::string num_tracked_prefs_str = base::IntToString(num_tracked_prefs_); 271 std::string num_tracked_prefs_str = base::IntToString(num_tracked_prefs_);
361 EXPECT_EQ(static_cast<int>(num_tracked_prefs_str.size()), 272 EXPECT_EQ(static_cast<int>(num_tracked_prefs_str.size()),
362 base::WriteFile(num_tracked_prefs_file, 273 base::WriteFile(num_tracked_prefs_file,
363 num_tracked_prefs_str.c_str(), 274 num_tracked_prefs_str.c_str(),
364 num_tracked_prefs_str.size())); 275 num_tracked_prefs_str.size()));
365 } else { 276 } else {
366 std::string num_tracked_prefs_str; 277 std::string num_tracked_prefs_str;
367 EXPECT_TRUE(base::ReadFileToString(num_tracked_prefs_file, 278 EXPECT_TRUE(base::ReadFileToString(num_tracked_prefs_file,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 } else { 346 } else {
436 ADD_FAILURE(); 347 ADD_FAILURE();
437 return static_cast<SettingsProtectionLevel>(-1); 348 return static_cast<SettingsProtectionLevel>(-1);
438 } 349 }
439 350
440 #endif // defined(OFFICIAL_BUILD) 351 #endif // defined(OFFICIAL_BUILD)
441 352
442 } 353 }
443 354
444 int num_tracked_prefs_; 355 int num_tracked_prefs_;
445
446 #if defined(OS_WIN)
447 base::string16 registry_key_for_external_validation_;
448 #endif
449 }; 356 };
450 357
451 } // namespace 358 } // namespace
452 359
453 // Verifies that nothing is reset when nothing is tampered with. 360 // Verifies that nothing is reset when nothing is tampered with.
454 // Also sanity checks that the expected preferences files are in place. 361 // Also sanity checks that the expected preferences files are in place.
455 class PrefHashBrowserTestUnchangedDefault : public PrefHashBrowserTestBase { 362 class PrefHashBrowserTestUnchangedDefault : public PrefHashBrowserTestBase {
456 public: 363 public:
457 void SetupPreferences() override { 364 void SetupPreferences() override {
458 // Default Chrome setup. 365 // Default Chrome setup.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 GetTrackedPrefHistogramCount( 400 GetTrackedPrefHistogramCount(
494 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, 401 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized,
495 ALLOW_NONE)); 402 ALLOW_NONE));
496 EXPECT_EQ(0, GetTrackedPrefHistogramCount( 403 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
497 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, 404 user_prefs::tracked::kTrackedPrefHistogramNullInitialized,
498 ALLOW_NONE)); 405 ALLOW_NONE));
499 EXPECT_EQ( 406 EXPECT_EQ(
500 0, GetTrackedPrefHistogramCount( 407 0, GetTrackedPrefHistogramCount(
501 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, 408 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
502 ALLOW_NONE)); 409 ALLOW_NONE));
503
504 if (SupportsRegistryValidation()) {
505 // Expect all prefs to be reported as Unchanged.
506 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM
507 ? num_tracked_prefs()
508 : 0,
509 GetTrackedPrefHistogramCount(
510 user_prefs::tracked::kTrackedPrefHistogramUnchanged,
511 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
512 ALLOW_ANY));
513 }
514 } 410 }
515 }; 411 };
516 412
517 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUnchangedDefault, UnchangedDefault); 413 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUnchangedDefault, UnchangedDefault);
518 414
519 // Augments PrefHashBrowserTestUnchangedDefault to confirm that nothing is reset 415 // Augments PrefHashBrowserTestUnchangedDefault to confirm that nothing is reset
520 // when nothing is tampered with, even if Chrome itself wrote custom prefs in 416 // when nothing is tampered with, even if Chrome itself wrote custom prefs in
521 // its last run. 417 // its last run.
522 class PrefHashBrowserTestUnchangedCustom 418 class PrefHashBrowserTestUnchangedCustom
523 : public PrefHashBrowserTestUnchangedDefault { 419 : public PrefHashBrowserTestUnchangedDefault {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 GetTrackedPrefHistogramCount( 490 GetTrackedPrefHistogramCount(
595 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, 491 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized,
596 ALLOW_NONE)); 492 ALLOW_NONE));
597 EXPECT_EQ(0, GetTrackedPrefHistogramCount( 493 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
598 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, 494 user_prefs::tracked::kTrackedPrefHistogramNullInitialized,
599 ALLOW_NONE)); 495 ALLOW_NONE));
600 EXPECT_EQ( 496 EXPECT_EQ(
601 0, GetTrackedPrefHistogramCount( 497 0, GetTrackedPrefHistogramCount(
602 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, 498 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
603 ALLOW_NONE)); 499 ALLOW_NONE));
604
605 if (SupportsRegistryValidation()) {
606 // Expect homepage clearance to have been noticed by registry validation.
607 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0,
608 GetTrackedPrefHistogramCount(
609 user_prefs::tracked::kTrackedPrefHistogramCleared,
610 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
611 BEGIN_ALLOW_SINGLE_BUCKET + 2));
612 }
613 } 500 }
614 }; 501 };
615 502
616 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestClearedAtomic, ClearedAtomic); 503 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestClearedAtomic, ClearedAtomic);
617 504
618 // Verifies that clearing the MACs results in untrusted Initialized pings for 505 // Verifies that clearing the MACs results in untrusted Initialized pings for
619 // non-null protected prefs. 506 // non-null protected prefs.
620 class PrefHashBrowserTestUntrustedInitialized : public PrefHashBrowserTestBase { 507 class PrefHashBrowserTestUntrustedInitialized : public PrefHashBrowserTestBase {
621 public: 508 public:
622 void SetupPreferences() override { 509 void SetupPreferences() override {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 EXPECT_EQ( 612 EXPECT_EQ(
726 0, GetTrackedPrefHistogramCount( 613 0, GetTrackedPrefHistogramCount(
727 user_prefs::tracked::kTrackedPrefHistogramChanged, ALLOW_NONE)); 614 user_prefs::tracked::kTrackedPrefHistogramChanged, ALLOW_NONE));
728 EXPECT_EQ( 615 EXPECT_EQ(
729 0, GetTrackedPrefHistogramCount( 616 0, GetTrackedPrefHistogramCount(
730 user_prefs::tracked::kTrackedPrefHistogramCleared, ALLOW_NONE)); 617 user_prefs::tracked::kTrackedPrefHistogramCleared, ALLOW_NONE));
731 EXPECT_EQ( 618 EXPECT_EQ(
732 0, GetTrackedPrefHistogramCount( 619 0, GetTrackedPrefHistogramCount(
733 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, 620 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
734 ALLOW_NONE)); 621 ALLOW_NONE));
735
736 if (SupportsRegistryValidation()) {
737 // The MACs have been cleared but the preferences have not been tampered.
738 // The registry should report all prefs as unchanged.
739 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM
740 ? num_tracked_prefs()
741 : 0,
742 GetTrackedPrefHistogramCount(
743 user_prefs::tracked::kTrackedPrefHistogramUnchanged,
744 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
745 ALLOW_ANY));
746 }
747 } 622 }
748 }; 623 };
749 624
750 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedInitialized, 625 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedInitialized,
751 UntrustedInitialized); 626 UntrustedInitialized);
752 627
753 // Verifies that changing an atomic pref results in it being reported (and reset 628 // Verifies that changing an atomic pref results in it being reported (and reset
754 // if the protection level allows it). 629 // if the protection level allows it).
755 class PrefHashBrowserTestChangedAtomic : public PrefHashBrowserTestBase { 630 class PrefHashBrowserTestChangedAtomic : public PrefHashBrowserTestBase {
756 public: 631 public:
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 GetTrackedPrefHistogramCount( 702 GetTrackedPrefHistogramCount(
828 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, 703 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized,
829 ALLOW_NONE)); 704 ALLOW_NONE));
830 EXPECT_EQ(0, GetTrackedPrefHistogramCount( 705 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
831 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, 706 user_prefs::tracked::kTrackedPrefHistogramNullInitialized,
832 ALLOW_NONE)); 707 ALLOW_NONE));
833 EXPECT_EQ( 708 EXPECT_EQ(
834 0, GetTrackedPrefHistogramCount( 709 0, GetTrackedPrefHistogramCount(
835 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, 710 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
836 ALLOW_NONE)); 711 ALLOW_NONE));
837
838 if (SupportsRegistryValidation()) {
839 // Expect a single Changed event for tracked pref #4 (startup URLs).
840 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0,
841 GetTrackedPrefHistogramCount(
842 user_prefs::tracked::kTrackedPrefHistogramChanged,
843 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
844 BEGIN_ALLOW_SINGLE_BUCKET + 4));
845 }
846 } 712 }
847 }; 713 };
848 714
849 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedAtomic, ChangedAtomic); 715 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedAtomic, ChangedAtomic);
850 716
851 // Verifies that changing or adding an entry in a split pref results in both 717 // Verifies that changing or adding an entry in a split pref results in both
852 // items being reported (and remove if the protection level allows it). 718 // items being reported (and remove if the protection level allows it).
853 class PrefHashBrowserTestChangedSplitPref : public PrefHashBrowserTestBase { 719 class PrefHashBrowserTestChangedSplitPref : public PrefHashBrowserTestBase {
854 public: 720 public:
855 void SetupPreferences() override { 721 void SetupPreferences() override {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 GetTrackedPrefHistogramCount( 799 GetTrackedPrefHistogramCount(
934 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, 800 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized,
935 ALLOW_NONE)); 801 ALLOW_NONE));
936 EXPECT_EQ(0, GetTrackedPrefHistogramCount( 802 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
937 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, 803 user_prefs::tracked::kTrackedPrefHistogramNullInitialized,
938 ALLOW_NONE)); 804 ALLOW_NONE));
939 EXPECT_EQ( 805 EXPECT_EQ(
940 0, GetTrackedPrefHistogramCount( 806 0, GetTrackedPrefHistogramCount(
941 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, 807 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
942 ALLOW_NONE)); 808 ALLOW_NONE));
943
944 if (SupportsRegistryValidation()) {
945 // Expect that the registry validation caught the invalid MAC in split
946 // pref #5 (extensions).
947 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0,
948 GetTrackedPrefHistogramCount(
949 user_prefs::tracked::kTrackedPrefHistogramChanged,
950 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
951 BEGIN_ALLOW_SINGLE_BUCKET + 5));
952 }
953 } 809 }
954 }; 810 };
955 811
956 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedSplitPref, ChangedSplitPref); 812 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedSplitPref, ChangedSplitPref);
957 813
958 // Verifies that adding a value to unprotected preferences for a key which is 814 // Verifies that adding a value to unprotected preferences for a key which is
959 // still using the default (i.e. has no value stored in protected preferences) 815 // still using the default (i.e. has no value stored in protected preferences)
960 // doesn't allow that value to slip in with no valid MAC (regression test for 816 // doesn't allow that value to slip in with no valid MAC (regression test for
961 // http://crbug.com/414554) 817 // http://crbug.com/414554)
962 class PrefHashBrowserTestUntrustedAdditionToPrefs 818 class PrefHashBrowserTestUntrustedAdditionToPrefs
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 GetTrackedPrefHistogramCount( 872 GetTrackedPrefHistogramCount(
1017 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, 873 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized,
1018 ALLOW_NONE)); 874 ALLOW_NONE));
1019 EXPECT_EQ(0, GetTrackedPrefHistogramCount( 875 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
1020 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, 876 user_prefs::tracked::kTrackedPrefHistogramNullInitialized,
1021 ALLOW_NONE)); 877 ALLOW_NONE));
1022 EXPECT_EQ( 878 EXPECT_EQ(
1023 0, GetTrackedPrefHistogramCount( 879 0, GetTrackedPrefHistogramCount(
1024 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, 880 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
1025 ALLOW_NONE)); 881 ALLOW_NONE));
1026
1027 if (SupportsRegistryValidation()) {
1028 EXPECT_EQ((protection_level_ > PROTECTION_DISABLED_ON_PLATFORM &&
1029 protection_level_ < PROTECTION_ENABLED_BASIC)
1030 ? changed_expected
1031 : 0,
1032 GetTrackedPrefHistogramCount(
1033 user_prefs::tracked::kTrackedPrefHistogramChanged,
1034 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
1035 BEGIN_ALLOW_SINGLE_BUCKET + 3));
1036 }
1037 } 882 }
1038 }; 883 };
1039 884
1040 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefs, 885 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefs,
1041 UntrustedAdditionToPrefs); 886 UntrustedAdditionToPrefs);
1042 887
1043 // Verifies that adding a value to unprotected preferences while wiping a 888 // Verifies that adding a value to unprotected preferences while wiping a
1044 // user-selected value from protected preferences doesn't allow that value to 889 // user-selected value from protected preferences doesn't allow that value to
1045 // slip in with no valid MAC (regression test for http://crbug.com/414554). 890 // slip in with no valid MAC (regression test for http://crbug.com/414554).
1046 class PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe 891 class PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 GetTrackedPrefHistogramCount( 946 GetTrackedPrefHistogramCount(
1102 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, 947 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized,
1103 ALLOW_NONE)); 948 ALLOW_NONE));
1104 EXPECT_EQ(0, GetTrackedPrefHistogramCount( 949 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
1105 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, 950 user_prefs::tracked::kTrackedPrefHistogramNullInitialized,
1106 ALLOW_NONE)); 951 ALLOW_NONE));
1107 EXPECT_EQ( 952 EXPECT_EQ(
1108 0, GetTrackedPrefHistogramCount( 953 0, GetTrackedPrefHistogramCount(
1109 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, 954 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
1110 ALLOW_NONE)); 955 ALLOW_NONE));
1111
1112 if (SupportsRegistryValidation()) {
1113 EXPECT_EQ(changed_expected,
1114 GetTrackedPrefHistogramCount(
1115 user_prefs::tracked::kTrackedPrefHistogramChanged,
1116 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
1117 BEGIN_ALLOW_SINGLE_BUCKET + 2));
1118 EXPECT_EQ(cleared_expected,
1119 GetTrackedPrefHistogramCount(
1120 user_prefs::tracked::kTrackedPrefHistogramCleared,
1121 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
1122 BEGIN_ALLOW_SINGLE_BUCKET + 2));
1123 }
1124 } 956 }
1125 }; 957 };
1126 958
1127 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe, 959 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe,
1128 UntrustedAdditionToPrefsAfterWipe); 960 UntrustedAdditionToPrefsAfterWipe);
1129
1130 #if defined(OS_WIN)
1131 class PrefHashBrowserTestRegistryValidationFailure
1132 : public PrefHashBrowserTestBase {
1133 public:
1134 void SetupPreferences() override {
1135 profile()->GetPrefs()->SetString(prefs::kHomePage, "http://example.com");
1136 }
1137
1138 void AttackPreferencesOnDisk(
1139 base::DictionaryValue* unprotected_preferences,
1140 base::DictionaryValue* protected_preferences) override {
1141 base::string16 registry_key =
1142 GetRegistryPathForTestProfile() + L"\\PreferenceMACs\\Default";
1143 base::win::RegKey key;
1144 ASSERT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, registry_key.c_str(),
1145 KEY_SET_VALUE | KEY_WOW64_32KEY));
1146 // An incorrect hash should still have the correct size.
1147 ASSERT_EQ(ERROR_SUCCESS,
1148 key.WriteValue(L"homepage", base::string16(64, 'A').c_str()));
1149 }
1150
1151 void VerifyReactionToPrefAttack() override {
1152 EXPECT_EQ(
1153 protection_level_ > PROTECTION_DISABLED_ON_PLATFORM
1154 ? num_tracked_prefs()
1155 : 0,
1156 GetTrackedPrefHistogramCount(
1157 user_prefs::tracked::kTrackedPrefHistogramUnchanged, ALLOW_ANY));
1158
1159 if (SupportsRegistryValidation()) {
1160 // Expect that the registry validation caught the invalid MAC for pref #2
1161 // (homepage).
1162 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0,
1163 GetTrackedPrefHistogramCount(
1164 user_prefs::tracked::kTrackedPrefHistogramChanged,
1165 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
1166 BEGIN_ALLOW_SINGLE_BUCKET + 2));
1167 }
1168 }
1169 };
1170
1171 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestRegistryValidationFailure,
1172 RegistryValidationFailure);
1173 #endif
OLDNEW
« no previous file with comments | « chrome/browser/prefs/profile_pref_store_manager.cc ('k') | components/user_prefs/tracked/dictionary_hash_store_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698