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

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

Issue 2204943002: Integrate registry_hash_store_contents with the rest of tracked prefs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Apply comments from patch set 27 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
« no previous file with comments | « chrome/browser/prefs/profile_pref_store_manager.cc ('k') | components/prefs/json_pref_store.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
41 namespace { 45 namespace {
42 46
43 // Extension ID of chrome/test/data/extensions/good.crx 47 // Extension ID of chrome/test/data/extensions/good.crx
44 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; 48 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
45 49
46 // Explicit expectations from the caller of GetTrackedPrefHistogramCount(). This 50 // Explicit expectations from the caller of GetTrackedPrefHistogramCount(). This
47 // enables detailed reporting of the culprit on failure. 51 // enables detailed reporting of the culprit on failure.
48 enum AllowedBuckets { 52 enum AllowedBuckets {
49 // Allow no samples in any buckets. 53 // Allow no samples in any buckets.
50 ALLOW_NONE = -1, 54 ALLOW_NONE = -1,
51 // Any integer between BEGIN_ALLOW_SINGLE_BUCKET and END_ALLOW_SINGLE_BUCKET 55 // Any integer between BEGIN_ALLOW_SINGLE_BUCKET and END_ALLOW_SINGLE_BUCKET
52 // indicates that only this specific bucket is allowed to have a sample. 56 // indicates that only this specific bucket is allowed to have a sample.
53 BEGIN_ALLOW_SINGLE_BUCKET = 0, 57 BEGIN_ALLOW_SINGLE_BUCKET = 0,
54 END_ALLOW_SINGLE_BUCKET = 100, 58 END_ALLOW_SINGLE_BUCKET = 100,
55 // Allow any buckets (no extra verifications performed). 59 // Allow any buckets (no extra verifications performed).
56 ALLOW_ANY 60 ALLOW_ANY
57 }; 61 };
58 62
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
59 // Returns the number of times |histogram_name| was reported so far; adding the 72 // Returns the number of times |histogram_name| was reported so far; adding the
60 // results of the first 100 buckets (there are only ~19 reporting IDs as of this 73 // results of the first 100 buckets (there are only ~19 reporting IDs as of this
61 // writing; varies depending on the platform). |allowed_buckets| hints at extra 74 // writing; varies depending on the platform). |allowed_buckets| hints at extra
62 // requirements verified in this method (see AllowedBuckets for details). 75 // requirements verified in this method (see AllowedBuckets for details).
63 int GetTrackedPrefHistogramCount(const char* histogram_name, 76 int GetTrackedPrefHistogramCount(const char* histogram_name,
77 const char* histogram_suffix,
64 int allowed_buckets) { 78 int allowed_buckets) {
79 std::string full_histogram_name(histogram_name);
80 if (*histogram_suffix)
81 full_histogram_name.append(".").append(histogram_suffix);
65 const base::HistogramBase* histogram = 82 const base::HistogramBase* histogram =
66 base::StatisticsRecorder::FindHistogram(histogram_name); 83 base::StatisticsRecorder::FindHistogram(full_histogram_name);
67 if (!histogram) 84 if (!histogram)
68 return 0; 85 return 0;
69 86
70 std::unique_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); 87 std::unique_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples());
71 int sum = 0; 88 int sum = 0;
72 for (int i = 0; i < 100; ++i) { 89 for (int i = 0; i < 100; ++i) {
73 int count_for_id = samples->GetCount(i); 90 int count_for_id = samples->GetCount(i);
74 EXPECT_GE(count_for_id, 0); 91 EXPECT_GE(count_for_id, 0);
75 sum += count_for_id; 92 sum += count_for_id;
76 93
77 if (allowed_buckets == ALLOW_NONE || 94 if (allowed_buckets == ALLOW_NONE ||
78 (allowed_buckets != ALLOW_ANY && i != allowed_buckets)) { 95 (allowed_buckets != ALLOW_ANY && i != allowed_buckets)) {
79 EXPECT_EQ(0, count_for_id) << "Unexpected reporting_id: " << i; 96 EXPECT_EQ(0, count_for_id) << "Unexpected reporting_id: " << i;
80 } 97 }
81 } 98 }
82 return sum; 99 return sum;
83 } 100 }
84 101
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
85 std::unique_ptr<base::DictionaryValue> ReadPrefsDictionary( 109 std::unique_ptr<base::DictionaryValue> ReadPrefsDictionary(
86 const base::FilePath& pref_file) { 110 const base::FilePath& pref_file) {
87 JSONFileValueDeserializer deserializer(pref_file); 111 JSONFileValueDeserializer deserializer(pref_file);
88 int error_code = JSONFileValueDeserializer::JSON_NO_ERROR; 112 int error_code = JSONFileValueDeserializer::JSON_NO_ERROR;
89 std::string error_str; 113 std::string error_str;
90 std::unique_ptr<base::Value> prefs = 114 std::unique_ptr<base::Value> prefs =
91 deserializer.Deserialize(&error_code, &error_str); 115 deserializer.Deserialize(&error_code, &error_str);
92 if (!prefs || error_code != JSONFileValueDeserializer::JSON_NO_ERROR) { 116 if (!prefs || error_code != JSONFileValueDeserializer::JSON_NO_ERROR) {
93 ADD_FAILURE() << "Error #" << error_code << ": " << error_str; 117 ADD_FAILURE() << "Error #" << error_code << ": " << error_str;
94 return std::unique_ptr<base::DictionaryValue>(); 118 return std::unique_ptr<base::DictionaryValue>();
95 } 119 }
96 if (!prefs->IsType(base::Value::TYPE_DICTIONARY)) { 120 if (!prefs->IsType(base::Value::TYPE_DICTIONARY)) {
97 ADD_FAILURE(); 121 ADD_FAILURE();
98 return std::unique_ptr<base::DictionaryValue>(); 122 return std::unique_ptr<base::DictionaryValue>();
99 } 123 }
100 return std::unique_ptr<base::DictionaryValue>( 124 return std::unique_ptr<base::DictionaryValue>(
101 static_cast<base::DictionaryValue*>(prefs.release())); 125 static_cast<base::DictionaryValue*>(prefs.release()));
102 } 126 }
103 127
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
104 #define PREF_HASH_BROWSER_TEST(fixture, test_name) \ 138 #define PREF_HASH_BROWSER_TEST(fixture, test_name) \
105 IN_PROC_BROWSER_TEST_P(fixture, PRE_##test_name) { \ 139 IN_PROC_BROWSER_TEST_P(fixture, PRE_##test_name) { \
106 SetupPreferences(); \ 140 SetupPreferences(); \
107 } \ 141 } \
108 IN_PROC_BROWSER_TEST_P(fixture, test_name) { \ 142 IN_PROC_BROWSER_TEST_P(fixture, test_name) { \
109 VerifyReactionToPrefAttack(); \ 143 VerifyReactionToPrefAttack(); \
110 } \ 144 } \
111 INSTANTIATE_TEST_CASE_P( \ 145 INSTANTIATE_TEST_CASE_P( \
112 fixture##Instance, \ 146 fixture##Instance, \
113 fixture, \ 147 fixture, \
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 260
227 return true; 261 return true;
228 } 262 }
229 263
230 void SetUpInProcessBrowserTestFixture() override { 264 void SetUpInProcessBrowserTestFixture() override {
231 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture(); 265 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture();
232 266
233 // Bots are on a domain, turn off the domain check for settings hardening in 267 // Bots are on a domain, turn off the domain check for settings hardening in
234 // order to be able to test all SettingsEnforcement groups. 268 // order to be able to test all SettingsEnforcement groups.
235 chrome_prefs::DisableDomainCheckForTesting(); 269 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();
236 } 308 }
237 309
238 // In the PRE_ test, find the number of tracked preferences that were 310 // In the PRE_ test, find the number of tracked preferences that were
239 // initialized and save it to a file to be read back in the main test and used 311 // initialized and save it to a file to be read back in the main test and used
240 // as the total number of tracked preferences. 312 // as the total number of tracked preferences.
241 void SetUpOnMainThread() override { 313 void SetUpOnMainThread() override {
242 ExtensionBrowserTest::SetUpOnMainThread(); 314 ExtensionBrowserTest::SetUpOnMainThread();
243 315
244 // File in which the PRE_ test will save the number of tracked preferences 316 // File in which the PRE_ test will save the number of tracked preferences
245 // on this platform. 317 // on this platform.
(...skipping 13 matching lines...) Expand all
259 331
260 // Split tracked prefs are reported as Unchanged not as NullInitialized 332 // Split tracked prefs are reported as Unchanged not as NullInitialized
261 // when an empty dictionary is encountered on first run (this should only 333 // when an empty dictionary is encountered on first run (this should only
262 // hit for pref #5 in the current design). 334 // hit for pref #5 in the current design).
263 int num_split_tracked_prefs = GetTrackedPrefHistogramCount( 335 int num_split_tracked_prefs = GetTrackedPrefHistogramCount(
264 user_prefs::tracked::kTrackedPrefHistogramUnchanged, 336 user_prefs::tracked::kTrackedPrefHistogramUnchanged,
265 BEGIN_ALLOW_SINGLE_BUCKET + 5); 337 BEGIN_ALLOW_SINGLE_BUCKET + 5);
266 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, 338 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0,
267 num_split_tracked_prefs); 339 num_split_tracked_prefs);
268 340
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
269 num_tracked_prefs_ += num_split_tracked_prefs; 358 num_tracked_prefs_ += num_split_tracked_prefs;
270 359
271 std::string num_tracked_prefs_str = base::IntToString(num_tracked_prefs_); 360 std::string num_tracked_prefs_str = base::IntToString(num_tracked_prefs_);
272 EXPECT_EQ(static_cast<int>(num_tracked_prefs_str.size()), 361 EXPECT_EQ(static_cast<int>(num_tracked_prefs_str.size()),
273 base::WriteFile(num_tracked_prefs_file, 362 base::WriteFile(num_tracked_prefs_file,
274 num_tracked_prefs_str.c_str(), 363 num_tracked_prefs_str.c_str(),
275 num_tracked_prefs_str.size())); 364 num_tracked_prefs_str.size()));
276 } else { 365 } else {
277 std::string num_tracked_prefs_str; 366 std::string num_tracked_prefs_str;
278 EXPECT_TRUE(base::ReadFileToString(num_tracked_prefs_file, 367 EXPECT_TRUE(base::ReadFileToString(num_tracked_prefs_file,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 } else { 435 } else {
347 ADD_FAILURE(); 436 ADD_FAILURE();
348 return static_cast<SettingsProtectionLevel>(-1); 437 return static_cast<SettingsProtectionLevel>(-1);
349 } 438 }
350 439
351 #endif // defined(OFFICIAL_BUILD) 440 #endif // defined(OFFICIAL_BUILD)
352 441
353 } 442 }
354 443
355 int num_tracked_prefs_; 444 int num_tracked_prefs_;
445
446 #if defined(OS_WIN)
447 base::string16 registry_key_for_external_validation_;
448 #endif
356 }; 449 };
357 450
358 } // namespace 451 } // namespace
359 452
360 // Verifies that nothing is reset when nothing is tampered with. 453 // Verifies that nothing is reset when nothing is tampered with.
361 // Also sanity checks that the expected preferences files are in place. 454 // Also sanity checks that the expected preferences files are in place.
362 class PrefHashBrowserTestUnchangedDefault : public PrefHashBrowserTestBase { 455 class PrefHashBrowserTestUnchangedDefault : public PrefHashBrowserTestBase {
363 public: 456 public:
364 void SetupPreferences() override { 457 void SetupPreferences() override {
365 // Default Chrome setup. 458 // Default Chrome setup.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 GetTrackedPrefHistogramCount( 493 GetTrackedPrefHistogramCount(
401 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, 494 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized,
402 ALLOW_NONE)); 495 ALLOW_NONE));
403 EXPECT_EQ(0, GetTrackedPrefHistogramCount( 496 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
404 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, 497 user_prefs::tracked::kTrackedPrefHistogramNullInitialized,
405 ALLOW_NONE)); 498 ALLOW_NONE));
406 EXPECT_EQ( 499 EXPECT_EQ(
407 0, GetTrackedPrefHistogramCount( 500 0, GetTrackedPrefHistogramCount(
408 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, 501 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
409 ALLOW_NONE)); 502 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 }
410 } 514 }
411 }; 515 };
412 516
413 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUnchangedDefault, UnchangedDefault); 517 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUnchangedDefault, UnchangedDefault);
414 518
415 // Augments PrefHashBrowserTestUnchangedDefault to confirm that nothing is reset 519 // Augments PrefHashBrowserTestUnchangedDefault to confirm that nothing is reset
416 // when nothing is tampered with, even if Chrome itself wrote custom prefs in 520 // when nothing is tampered with, even if Chrome itself wrote custom prefs in
417 // its last run. 521 // its last run.
418 class PrefHashBrowserTestUnchangedCustom 522 class PrefHashBrowserTestUnchangedCustom
419 : public PrefHashBrowserTestUnchangedDefault { 523 : public PrefHashBrowserTestUnchangedDefault {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 GetTrackedPrefHistogramCount( 594 GetTrackedPrefHistogramCount(
491 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, 595 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized,
492 ALLOW_NONE)); 596 ALLOW_NONE));
493 EXPECT_EQ(0, GetTrackedPrefHistogramCount( 597 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
494 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, 598 user_prefs::tracked::kTrackedPrefHistogramNullInitialized,
495 ALLOW_NONE)); 599 ALLOW_NONE));
496 EXPECT_EQ( 600 EXPECT_EQ(
497 0, GetTrackedPrefHistogramCount( 601 0, GetTrackedPrefHistogramCount(
498 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, 602 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
499 ALLOW_NONE)); 603 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 }
500 } 613 }
501 }; 614 };
502 615
503 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestClearedAtomic, ClearedAtomic); 616 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestClearedAtomic, ClearedAtomic);
504 617
505 // Verifies that clearing the MACs results in untrusted Initialized pings for 618 // Verifies that clearing the MACs results in untrusted Initialized pings for
506 // non-null protected prefs. 619 // non-null protected prefs.
507 class PrefHashBrowserTestUntrustedInitialized : public PrefHashBrowserTestBase { 620 class PrefHashBrowserTestUntrustedInitialized : public PrefHashBrowserTestBase {
508 public: 621 public:
509 void SetupPreferences() override { 622 void SetupPreferences() override {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 EXPECT_EQ( 725 EXPECT_EQ(
613 0, GetTrackedPrefHistogramCount( 726 0, GetTrackedPrefHistogramCount(
614 user_prefs::tracked::kTrackedPrefHistogramChanged, ALLOW_NONE)); 727 user_prefs::tracked::kTrackedPrefHistogramChanged, ALLOW_NONE));
615 EXPECT_EQ( 728 EXPECT_EQ(
616 0, GetTrackedPrefHistogramCount( 729 0, GetTrackedPrefHistogramCount(
617 user_prefs::tracked::kTrackedPrefHistogramCleared, ALLOW_NONE)); 730 user_prefs::tracked::kTrackedPrefHistogramCleared, ALLOW_NONE));
618 EXPECT_EQ( 731 EXPECT_EQ(
619 0, GetTrackedPrefHistogramCount( 732 0, GetTrackedPrefHistogramCount(
620 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, 733 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
621 ALLOW_NONE)); 734 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 }
622 } 747 }
623 }; 748 };
624 749
625 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedInitialized, 750 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedInitialized,
626 UntrustedInitialized); 751 UntrustedInitialized);
627 752
628 // Verifies that changing an atomic pref results in it being reported (and reset 753 // Verifies that changing an atomic pref results in it being reported (and reset
629 // if the protection level allows it). 754 // if the protection level allows it).
630 class PrefHashBrowserTestChangedAtomic : public PrefHashBrowserTestBase { 755 class PrefHashBrowserTestChangedAtomic : public PrefHashBrowserTestBase {
631 public: 756 public:
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 GetTrackedPrefHistogramCount( 827 GetTrackedPrefHistogramCount(
703 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, 828 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized,
704 ALLOW_NONE)); 829 ALLOW_NONE));
705 EXPECT_EQ(0, GetTrackedPrefHistogramCount( 830 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
706 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, 831 user_prefs::tracked::kTrackedPrefHistogramNullInitialized,
707 ALLOW_NONE)); 832 ALLOW_NONE));
708 EXPECT_EQ( 833 EXPECT_EQ(
709 0, GetTrackedPrefHistogramCount( 834 0, GetTrackedPrefHistogramCount(
710 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, 835 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
711 ALLOW_NONE)); 836 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 }
712 } 846 }
713 }; 847 };
714 848
715 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedAtomic, ChangedAtomic); 849 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedAtomic, ChangedAtomic);
716 850
717 // Verifies that changing or adding an entry in a split pref results in both 851 // Verifies that changing or adding an entry in a split pref results in both
718 // items being reported (and remove if the protection level allows it). 852 // items being reported (and remove if the protection level allows it).
719 class PrefHashBrowserTestChangedSplitPref : public PrefHashBrowserTestBase { 853 class PrefHashBrowserTestChangedSplitPref : public PrefHashBrowserTestBase {
720 public: 854 public:
721 void SetupPreferences() override { 855 void SetupPreferences() override {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 GetTrackedPrefHistogramCount( 933 GetTrackedPrefHistogramCount(
800 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, 934 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized,
801 ALLOW_NONE)); 935 ALLOW_NONE));
802 EXPECT_EQ(0, GetTrackedPrefHistogramCount( 936 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
803 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, 937 user_prefs::tracked::kTrackedPrefHistogramNullInitialized,
804 ALLOW_NONE)); 938 ALLOW_NONE));
805 EXPECT_EQ( 939 EXPECT_EQ(
806 0, GetTrackedPrefHistogramCount( 940 0, GetTrackedPrefHistogramCount(
807 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, 941 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
808 ALLOW_NONE)); 942 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 }
809 } 953 }
810 }; 954 };
811 955
812 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedSplitPref, ChangedSplitPref); 956 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedSplitPref, ChangedSplitPref);
813 957
814 // Verifies that adding a value to unprotected preferences for a key which is 958 // Verifies that adding a value to unprotected preferences for a key which is
815 // still using the default (i.e. has no value stored in protected preferences) 959 // still using the default (i.e. has no value stored in protected preferences)
816 // doesn't allow that value to slip in with no valid MAC (regression test for 960 // doesn't allow that value to slip in with no valid MAC (regression test for
817 // http://crbug.com/414554) 961 // http://crbug.com/414554)
818 class PrefHashBrowserTestUntrustedAdditionToPrefs 962 class PrefHashBrowserTestUntrustedAdditionToPrefs
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 GetTrackedPrefHistogramCount( 1016 GetTrackedPrefHistogramCount(
873 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, 1017 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized,
874 ALLOW_NONE)); 1018 ALLOW_NONE));
875 EXPECT_EQ(0, GetTrackedPrefHistogramCount( 1019 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
876 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, 1020 user_prefs::tracked::kTrackedPrefHistogramNullInitialized,
877 ALLOW_NONE)); 1021 ALLOW_NONE));
878 EXPECT_EQ( 1022 EXPECT_EQ(
879 0, GetTrackedPrefHistogramCount( 1023 0, GetTrackedPrefHistogramCount(
880 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, 1024 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
881 ALLOW_NONE)); 1025 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 }
882 } 1037 }
883 }; 1038 };
884 1039
885 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefs, 1040 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefs,
886 UntrustedAdditionToPrefs); 1041 UntrustedAdditionToPrefs);
887 1042
888 // Verifies that adding a value to unprotected preferences while wiping a 1043 // Verifies that adding a value to unprotected preferences while wiping a
889 // user-selected value from protected preferences doesn't allow that value to 1044 // user-selected value from protected preferences doesn't allow that value to
890 // slip in with no valid MAC (regression test for http://crbug.com/414554). 1045 // slip in with no valid MAC (regression test for http://crbug.com/414554).
891 class PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe 1046 class PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 GetTrackedPrefHistogramCount( 1101 GetTrackedPrefHistogramCount(
947 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, 1102 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized,
948 ALLOW_NONE)); 1103 ALLOW_NONE));
949 EXPECT_EQ(0, GetTrackedPrefHistogramCount( 1104 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
950 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, 1105 user_prefs::tracked::kTrackedPrefHistogramNullInitialized,
951 ALLOW_NONE)); 1106 ALLOW_NONE));
952 EXPECT_EQ( 1107 EXPECT_EQ(
953 0, GetTrackedPrefHistogramCount( 1108 0, GetTrackedPrefHistogramCount(
954 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, 1109 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
955 ALLOW_NONE)); 1110 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 }
956 } 1124 }
957 }; 1125 };
958 1126
959 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe, 1127 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe,
960 UntrustedAdditionToPrefsAfterWipe); 1128 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/prefs/json_pref_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698