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

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

Powered by Google App Engine
This is Rietveld 408576698