blob: 202c30a8c9df327bd2e5ca6a7faa8af561a114e8 [file] [log] [blame]
[email protected]ae7bf342014-08-06 18:03:471// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
dcheng4af48582016-04-19 00:29:355#include <memory>
[email protected]ae7bf342014-08-06 18:03:476#include <string>
vabr9984ea62017-04-10 11:33:497#include <utility>
[email protected]ae7bf342014-08-06 18:03:478
blundell6e85b7c2015-09-29 12:33:359#include "base/base_switches.h"
[email protected]ae7bf342014-08-06 18:03:4710#include "base/command_line.h"
[email protected]ae7bf342014-08-06 18:03:4711#include "base/files/file_path.h"
thestig18dfb7a52014-08-26 10:44:0412#include "base/files/file_util.h"
[email protected]ae7bf342014-08-06 18:03:4713#include "base/json/json_file_value_serializer.h"
a-v-y38416862016-12-08 08:40:1314#include "base/json/json_reader.h"
vabr9984ea62017-04-10 11:33:4915#include "base/memory/ptr_util.h"
[email protected]ae7bf342014-08-06 18:03:4716#include "base/metrics/histogram_base.h"
17#include "base/metrics/histogram_samples.h"
18#include "base/metrics/statistics_recorder.h"
19#include "base/path_service.h"
[email protected]ae7bf342014-08-06 18:03:4720#include "base/strings/string_number_conversions.h"
21#include "base/strings/string_util.h"
a-v-y38416862016-12-08 08:40:1322#include "base/strings/utf_string_conversions.h"
[email protected]ae7bf342014-08-06 18:03:4723#include "base/values.h"
24#include "build/build_config.h"
25#include "chrome/browser/extensions/extension_browsertest.h"
26#include "chrome/browser/extensions/extension_service.h"
27#include "chrome/browser/prefs/chrome_pref_service_factory.h"
28#include "chrome/browser/prefs/profile_pref_store_manager.h"
29#include "chrome/browser/prefs/session_startup_pref.h"
30#include "chrome/browser/profiles/profile.h"
31#include "chrome/browser/ui/browser.h"
32#include "chrome/common/chrome_constants.h"
33#include "chrome/common/chrome_paths.h"
34#include "chrome/common/pref_names.h"
35#include "chrome/test/base/testing_profile.h"
36#include "components/search_engines/default_search_manager.h"
a-v-y38416862016-12-08 08:40:1337#include "components/search_engines/template_url_data.h"
[email protected]ae7bf342014-08-06 18:03:4738#include "extensions/browser/pref_names.h"
39#include "extensions/common/extension.h"
sammcfb473a872017-04-03 01:56:5940#include "services/preferences/public/cpp/tracked/tracked_preference_histogram_names.h"
[email protected]ae7bf342014-08-06 18:03:4741
42#if defined(OS_CHROMEOS)
43#include "chromeos/chromeos_switches.h"
44#endif
45
proberge269fd092016-10-04 22:13:4146#if defined(OS_WIN)
gab36b85522017-05-24 19:30:4547#include "base/win/registry.h"
48#include "chrome/install_static/install_util.h"
proberge269fd092016-10-04 22:13:4149#endif
50
[email protected]ae7bf342014-08-06 18:03:4751namespace {
52
53// Extension ID of chrome/test/data/extensions/good.crx
54const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
55
56// Explicit expectations from the caller of GetTrackedPrefHistogramCount(). This
57// enables detailed reporting of the culprit on failure.
58enum AllowedBuckets {
59 // Allow no samples in any buckets.
60 ALLOW_NONE = -1,
61 // Any integer between BEGIN_ALLOW_SINGLE_BUCKET and END_ALLOW_SINGLE_BUCKET
62 // indicates that only this specific bucket is allowed to have a sample.
63 BEGIN_ALLOW_SINGLE_BUCKET = 0,
64 END_ALLOW_SINGLE_BUCKET = 100,
65 // Allow any buckets (no extra verifications performed).
66 ALLOW_ANY
67};
68
proberge269fd092016-10-04 22:13:4169#if defined(OS_WIN)
70base::string16 GetRegistryPathForTestProfile() {
gab36b85522017-05-24 19:30:4571 // Cleanup follow-up to http://crbug.com/721245 for the previous location of
72 // this test key which had similar problems (to a lesser extent). It's
73 // redundant but harmless to have multiple callers hit this on the same
74 // machine. TODO(gab): remove this mid-june 2017.
75 base::win::RegKey key;
76 if (key.Open(HKEY_CURRENT_USER, L"SOFTWARE\\Chromium\\PrefHashBrowserTest",
77 KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) {
78 LONG result = key.DeleteKey(L"");
79 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
80 }
81
proberge269fd092016-10-04 22:13:4182 base::FilePath profile_dir;
83 EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &profile_dir));
gab36b85522017-05-24 19:30:4584
85 // Use a location under the real PreferenceMACs path so that the backup
86 // cleanup logic in ChromeTestLauncherDelegate::PreSharding() for interrupted
87 // tests covers this test key as well.
88 return install_static::GetRegistryPath() +
89 L"\\PreferenceMACs\\PrefHashBrowserTest\\" +
proberge269fd092016-10-04 22:13:4190 profile_dir.BaseName().value();
91}
92#endif
93
[email protected]ae7bf342014-08-06 18:03:4794// Returns the number of times |histogram_name| was reported so far; adding the
95// results of the first 100 buckets (there are only ~19 reporting IDs as of this
96// writing; varies depending on the platform). |allowed_buckets| hints at extra
97// requirements verified in this method (see AllowedBuckets for details).
98int GetTrackedPrefHistogramCount(const char* histogram_name,
proberge269fd092016-10-04 22:13:4199 const char* histogram_suffix,
[email protected]ae7bf342014-08-06 18:03:47100 int allowed_buckets) {
proberge269fd092016-10-04 22:13:41101 std::string full_histogram_name(histogram_name);
102 if (*histogram_suffix)
103 full_histogram_name.append(".").append(histogram_suffix);
[email protected]ae7bf342014-08-06 18:03:47104 const base::HistogramBase* histogram =
proberge269fd092016-10-04 22:13:41105 base::StatisticsRecorder::FindHistogram(full_histogram_name);
[email protected]ae7bf342014-08-06 18:03:47106 if (!histogram)
107 return 0;
108
dcheng4af48582016-04-19 00:29:35109 std::unique_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples());
[email protected]ae7bf342014-08-06 18:03:47110 int sum = 0;
111 for (int i = 0; i < 100; ++i) {
112 int count_for_id = samples->GetCount(i);
113 EXPECT_GE(count_for_id, 0);
114 sum += count_for_id;
115
116 if (allowed_buckets == ALLOW_NONE ||
117 (allowed_buckets != ALLOW_ANY && i != allowed_buckets)) {
118 EXPECT_EQ(0, count_for_id) << "Unexpected reporting_id: " << i;
119 }
120 }
121 return sum;
122}
123
proberge269fd092016-10-04 22:13:41124// Helper function to call GetTrackedPrefHistogramCount with no external
125// validation suffix.
126int GetTrackedPrefHistogramCount(const char* histogram_name,
127 int allowed_buckets) {
128 return GetTrackedPrefHistogramCount(histogram_name, "", allowed_buckets);
129}
130
dcheng4af48582016-04-19 00:29:35131std::unique_ptr<base::DictionaryValue> ReadPrefsDictionary(
[email protected]ae7bf342014-08-06 18:03:47132 const base::FilePath& pref_file) {
prashhir54a994502015-03-05 09:30:57133 JSONFileValueDeserializer deserializer(pref_file);
134 int error_code = JSONFileValueDeserializer::JSON_NO_ERROR;
[email protected]ae7bf342014-08-06 18:03:47135 std::string error_str;
dcheng4af48582016-04-19 00:29:35136 std::unique_ptr<base::Value> prefs =
olli.raulaba045252015-10-16 06:16:40137 deserializer.Deserialize(&error_code, &error_str);
prashhir54a994502015-03-05 09:30:57138 if (!prefs || error_code != JSONFileValueDeserializer::JSON_NO_ERROR) {
[email protected]ae7bf342014-08-06 18:03:47139 ADD_FAILURE() << "Error #" << error_code << ": " << error_str;
dcheng4af48582016-04-19 00:29:35140 return std::unique_ptr<base::DictionaryValue>();
[email protected]ae7bf342014-08-06 18:03:47141 }
jdoerriedc72ee942016-12-07 15:43:28142 if (!prefs->IsType(base::Value::Type::DICTIONARY)) {
[email protected]ae7bf342014-08-06 18:03:47143 ADD_FAILURE();
dcheng4af48582016-04-19 00:29:35144 return std::unique_ptr<base::DictionaryValue>();
[email protected]ae7bf342014-08-06 18:03:47145 }
dcheng4af48582016-04-19 00:29:35146 return std::unique_ptr<base::DictionaryValue>(
[email protected]ae7bf342014-08-06 18:03:47147 static_cast<base::DictionaryValue*>(prefs.release()));
148}
149
proberge269fd092016-10-04 22:13:41150// Returns whether external validation is supported on the platform through
151// storing MACs in the registry.
152bool SupportsRegistryValidation() {
153#if defined(OS_WIN)
154 return true;
155#else
156 return false;
157#endif
158}
159
[email protected]ae7bf342014-08-06 18:03:47160#define PREF_HASH_BROWSER_TEST(fixture, test_name) \
161 IN_PROC_BROWSER_TEST_P(fixture, PRE_##test_name) { \
162 SetupPreferences(); \
163 } \
164 IN_PROC_BROWSER_TEST_P(fixture, test_name) { \
165 VerifyReactionToPrefAttack(); \
166 } \
167 INSTANTIATE_TEST_CASE_P( \
168 fixture##Instance, \
169 fixture, \
170 testing::Values( \
171 chrome_prefs::internals::kSettingsEnforcementGroupNoEnforcement, \
172 chrome_prefs::internals::kSettingsEnforcementGroupEnforceAlways, \
173 chrome_prefs::internals:: \
174 kSettingsEnforcementGroupEnforceAlwaysWithDSE, \
175 chrome_prefs::internals:: \
176 kSettingsEnforcementGroupEnforceAlwaysWithExtensionsAndDSE));
177
178// A base fixture designed such that implementations do two things:
179// 1) Override all three pure-virtual methods below to setup, attack, and
180// verify preferenes throughout the tests provided by this fixture.
181// 2) Instantiate their test via the PREF_HASH_BROWSER_TEST macro above.
182// Based on top of ExtensionBrowserTest to allow easy interaction with the
183// ExtensionService.
184class PrefHashBrowserTestBase
185 : public ExtensionBrowserTest,
186 public testing::WithParamInterface<std::string> {
187 public:
188 // List of potential protection levels for this test in strict increasing
189 // order of protection levels.
190 enum SettingsProtectionLevel {
191 PROTECTION_DISABLED_ON_PLATFORM,
192 PROTECTION_DISABLED_FOR_GROUP,
193 PROTECTION_ENABLED_BASIC,
194 PROTECTION_ENABLED_DSE,
195 PROTECTION_ENABLED_EXTENSIONS,
196 // Represents the strongest level (i.e. always equivalent to the last one in
197 // terms of protection), leave this one last when adding new levels.
198 PROTECTION_ENABLED_ALL
199 };
200
201 PrefHashBrowserTestBase()
202 : protection_level_(GetProtectionLevelFromTrialGroup(GetParam())) {
203 }
204
avi556c05022014-12-22 23:31:43205 void SetUpCommandLine(base::CommandLine* command_line) override {
[email protected]ae7bf342014-08-06 18:03:47206 ExtensionBrowserTest::SetUpCommandLine(command_line);
207 EXPECT_FALSE(command_line->HasSwitch(switches::kForceFieldTrials));
208 command_line->AppendSwitchASCII(
209 switches::kForceFieldTrials,
210 std::string(chrome_prefs::internals::kSettingsEnforcementTrialName) +
211 "/" + GetParam() + "/");
212#if defined(OS_CHROMEOS)
213 command_line->AppendSwitch(
214 chromeos::switches::kIgnoreUserProfileMappingForTests);
215#endif
216 }
217
dcheng8f4b8622014-10-23 16:37:48218 bool SetUpUserDataDirectory() override {
[email protected]ae7bf342014-08-06 18:03:47219 // Do the normal setup in the PRE test and attack preferences in the main
220 // test.
221 if (IsPRETest())
222 return ExtensionBrowserTest::SetUpUserDataDirectory();
223
224#if defined(OS_CHROMEOS)
225 // For some reason, the Preferences file does not exist in the location
226 // below on Chrome OS. Since protection is disabled on Chrome OS, it's okay
227 // to simply not attack preferences at all (and still assert that no
228 // hardening related histogram kicked in in VerifyReactionToPrefAttack()).
229 // TODO(gab): Figure out why there is no Preferences file in this location
230 // on Chrome OS (and re-enable the section disabled for OS_CHROMEOS further
231 // below).
232 EXPECT_EQ(PROTECTION_DISABLED_ON_PLATFORM, protection_level_);
233 return true;
234#endif
235
236 base::FilePath profile_dir;
237 EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &profile_dir));
238 profile_dir = profile_dir.AppendASCII(TestingProfile::kTestUserProfileDir);
239
240 // Sanity check that old protected pref file is never present in modern
241 // Chromes.
242 EXPECT_FALSE(base::PathExists(
sammcf420c16e2017-03-16 02:11:13243 profile_dir.Append(FILE_PATH_LITERAL("Protected Preferences"))));
[email protected]ae7bf342014-08-06 18:03:47244
245 // Read the preferences from disk.
246
247 const base::FilePath unprotected_pref_file =
248 profile_dir.Append(chrome::kPreferencesFilename);
249 EXPECT_TRUE(base::PathExists(unprotected_pref_file));
250
251 const base::FilePath protected_pref_file =
252 profile_dir.Append(chrome::kSecurePreferencesFilename);
253 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM,
254 base::PathExists(protected_pref_file));
255
dcheng4af48582016-04-19 00:29:35256 std::unique_ptr<base::DictionaryValue> unprotected_preferences(
[email protected]ae7bf342014-08-06 18:03:47257 ReadPrefsDictionary(unprotected_pref_file));
258 if (!unprotected_preferences)
259 return false;
260
dcheng4af48582016-04-19 00:29:35261 std::unique_ptr<base::DictionaryValue> protected_preferences;
[email protected]ae7bf342014-08-06 18:03:47262 if (protection_level_ > PROTECTION_DISABLED_ON_PLATFORM) {
263 protected_preferences = ReadPrefsDictionary(protected_pref_file);
264 if (!protected_preferences)
265 return false;
266 }
267
268 // Let the underlying test modify the preferences.
269 AttackPreferencesOnDisk(unprotected_preferences.get(),
270 protected_preferences.get());
271
272 // Write the modified preferences back to disk.
273
274 JSONFileValueSerializer unprotected_prefs_serializer(unprotected_pref_file);
275 EXPECT_TRUE(
276 unprotected_prefs_serializer.Serialize(*unprotected_preferences));
277
278 if (protected_preferences) {
279 JSONFileValueSerializer protected_prefs_serializer(protected_pref_file);
280 EXPECT_TRUE(protected_prefs_serializer.Serialize(*protected_preferences));
281 }
282
283 return true;
284 }
285
gabbcdefd0cc2015-02-17 18:12:40286 void SetUpInProcessBrowserTestFixture() override {
287 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture();
288
289 // Bots are on a domain, turn off the domain check for settings hardening in
290 // order to be able to test all SettingsEnforcement groups.
291 chrome_prefs::DisableDomainCheckForTesting();
proberge269fd092016-10-04 22:13:41292
293#if defined(OS_WIN)
294 // Avoid polluting prefs for the user and the bots by writing to a specific
295 // testing registry path.
296 registry_key_for_external_validation_ = GetRegistryPathForTestProfile();
297 ProfilePrefStoreManager::SetPreferenceValidationRegistryPathForTesting(
298 &registry_key_for_external_validation_);
299
300 // Keys should be unique, but to avoid flakes in the long run make sure an
301 // identical test key wasn't left behind by a previous test.
302 if (IsPRETest()) {
303 base::win::RegKey key;
304 if (key.Open(HKEY_CURRENT_USER,
305 registry_key_for_external_validation_.c_str(),
306 KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) {
307 LONG result = key.DeleteKey(L"");
308 ASSERT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
309 }
310 }
311#endif
312 }
313
314 void TearDown() override {
315#if defined(OS_WIN)
316 // When done, delete the Registry key to avoid polluting the registry.
proberge269fd092016-10-04 22:13:41317 if (!IsPRETest()) {
318 base::string16 registry_key = GetRegistryPathForTestProfile();
319 base::win::RegKey key;
320 if (key.Open(HKEY_CURRENT_USER, registry_key.c_str(),
321 KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) {
322 LONG result = key.DeleteKey(L"");
323 ASSERT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND);
324 }
325 }
326#endif
327 ExtensionBrowserTest::TearDown();
gabbcdefd0cc2015-02-17 18:12:40328 }
329
[email protected]ae7bf342014-08-06 18:03:47330 // In the PRE_ test, find the number of tracked preferences that were
331 // initialized and save it to a file to be read back in the main test and used
332 // as the total number of tracked preferences.
dcheng8f4b8622014-10-23 16:37:48333 void SetUpOnMainThread() override {
[email protected]ae7bf342014-08-06 18:03:47334 ExtensionBrowserTest::SetUpOnMainThread();
335
336 // File in which the PRE_ test will save the number of tracked preferences
337 // on this platform.
338 const char kNumTrackedPrefFilename[] = "NumTrackedPrefs";
339
340 base::FilePath num_tracked_prefs_file;
341 ASSERT_TRUE(
342 PathService::Get(chrome::DIR_USER_DATA, &num_tracked_prefs_file));
343 num_tracked_prefs_file =
344 num_tracked_prefs_file.AppendASCII(kNumTrackedPrefFilename);
345
346 if (IsPRETest()) {
347 num_tracked_prefs_ = GetTrackedPrefHistogramCount(
deepak.m113481c82015-12-16 05:21:43348 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, ALLOW_ANY);
[email protected]ae7bf342014-08-06 18:03:47349 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM,
350 num_tracked_prefs_ > 0);
351
gab342aa6182014-10-02 21:59:00352 // Split tracked prefs are reported as Unchanged not as NullInitialized
[email protected]ae7bf342014-08-06 18:03:47353 // when an empty dictionary is encountered on first run (this should only
354 // hit for pref #5 in the current design).
355 int num_split_tracked_prefs = GetTrackedPrefHistogramCount(
deepak.m113481c82015-12-16 05:21:43356 user_prefs::tracked::kTrackedPrefHistogramUnchanged,
357 BEGIN_ALLOW_SINGLE_BUCKET + 5);
[email protected]ae7bf342014-08-06 18:03:47358 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0,
359 num_split_tracked_prefs);
360
proberge269fd092016-10-04 22:13:41361 if (SupportsRegistryValidation()) {
362 // Same checks as above, but for the registry.
363 num_tracked_prefs_ = GetTrackedPrefHistogramCount(
364 user_prefs::tracked::kTrackedPrefHistogramNullInitialized,
365 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
366 ALLOW_ANY);
367 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM,
368 num_tracked_prefs_ > 0);
369
370 int num_split_tracked_prefs = GetTrackedPrefHistogramCount(
371 user_prefs::tracked::kTrackedPrefHistogramUnchanged,
372 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
373 BEGIN_ALLOW_SINGLE_BUCKET + 5);
374 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0,
375 num_split_tracked_prefs);
376 }
377
[email protected]ae7bf342014-08-06 18:03:47378 num_tracked_prefs_ += num_split_tracked_prefs;
379
380 std::string num_tracked_prefs_str = base::IntToString(num_tracked_prefs_);
381 EXPECT_EQ(static_cast<int>(num_tracked_prefs_str.size()),
382 base::WriteFile(num_tracked_prefs_file,
383 num_tracked_prefs_str.c_str(),
384 num_tracked_prefs_str.size()));
385 } else {
386 std::string num_tracked_prefs_str;
387 EXPECT_TRUE(base::ReadFileToString(num_tracked_prefs_file,
388 &num_tracked_prefs_str));
389 EXPECT_TRUE(
390 base::StringToInt(num_tracked_prefs_str, &num_tracked_prefs_));
391 }
392 }
393
394 protected:
395 // Called from the PRE_ test's body. Overrides should use it to setup
396 // preferences through Chrome.
397 virtual void SetupPreferences() = 0;
398
399 // Called prior to the main test launching its browser. Overrides should use
400 // it to attack preferences. |(un)protected_preferences| represent the state
401 // on disk prior to launching the main test, they can be modified by this
402 // method and modifications will be flushed back to disk before launching the
403 // main test. |unprotected_preferences| is never NULL, |protected_preferences|
404 // may be NULL if in PROTECTION_DISABLED_ON_PLATFORM mode.
405 virtual void AttackPreferencesOnDisk(
406 base::DictionaryValue* unprotected_preferences,
407 base::DictionaryValue* protected_preferences) = 0;
408
409 // Called from the body of the main test. Overrides should use it to verify
410 // that the browser had the desired reaction when faced when the attack
411 // orchestrated in AttackPreferencesOnDisk().
412 virtual void VerifyReactionToPrefAttack() = 0;
413
414 int num_tracked_prefs() const { return num_tracked_prefs_; }
415
416 const SettingsProtectionLevel protection_level_;
417
418 private:
419 // Returns true if this is the PRE_ phase of the test.
420 bool IsPRETest() {
brettw66d1b81b2015-07-06 19:29:40421 return base::StartsWith(
brettw44ce0ec52015-06-12 01:57:57422 testing::UnitTest::GetInstance()->current_test_info()->name(), "PRE_",
brettw66d1b81b2015-07-06 19:29:40423 base::CompareCase::SENSITIVE);
[email protected]ae7bf342014-08-06 18:03:47424 }
425
426 SettingsProtectionLevel GetProtectionLevelFromTrialGroup(
427 const std::string& trial_group) {
428 if (!ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking)
429 return PROTECTION_DISABLED_ON_PLATFORM;
430
431// Protection levels can't be adjusted via --force-fieldtrials in official
432// builds.
433#if defined(OFFICIAL_BUILD)
434
proberge2562e6f2017-04-10 17:46:57435#if defined(OS_WIN) || defined(OS_MACOSX)
436 // The strongest mode is enforced on Windows and MacOS in the absence of a
437 // field trial.
[email protected]ae7bf342014-08-06 18:03:47438 return PROTECTION_ENABLED_ALL;
439#else
440 return PROTECTION_DISABLED_FOR_GROUP;
441#endif
442
443#else // defined(OFFICIAL_BUILD)
444
445 using namespace chrome_prefs::internals;
446 if (trial_group == kSettingsEnforcementGroupNoEnforcement) {
447 return PROTECTION_DISABLED_FOR_GROUP;
448 } else if (trial_group == kSettingsEnforcementGroupEnforceAlways) {
449 return PROTECTION_ENABLED_BASIC;
450 } else if (trial_group == kSettingsEnforcementGroupEnforceAlwaysWithDSE) {
451 return PROTECTION_ENABLED_DSE;
452 } else if (trial_group ==
453 kSettingsEnforcementGroupEnforceAlwaysWithExtensionsAndDSE) {
454 return PROTECTION_ENABLED_EXTENSIONS;
455 } else {
456 ADD_FAILURE();
457 return static_cast<SettingsProtectionLevel>(-1);
458 }
459
460#endif // defined(OFFICIAL_BUILD)
461
462 }
463
464 int num_tracked_prefs_;
proberge269fd092016-10-04 22:13:41465
466#if defined(OS_WIN)
467 base::string16 registry_key_for_external_validation_;
468#endif
[email protected]ae7bf342014-08-06 18:03:47469};
470
471} // namespace
472
473// Verifies that nothing is reset when nothing is tampered with.
474// Also sanity checks that the expected preferences files are in place.
475class PrefHashBrowserTestUnchangedDefault : public PrefHashBrowserTestBase {
476 public:
dcheng8f4b8622014-10-23 16:37:48477 void SetupPreferences() override {
[email protected]ae7bf342014-08-06 18:03:47478 // Default Chrome setup.
479 }
480
dcheng8f4b8622014-10-23 16:37:48481 void AttackPreferencesOnDisk(
[email protected]ae7bf342014-08-06 18:03:47482 base::DictionaryValue* unprotected_preferences,
mostynb2b52d1db2014-10-07 02:47:17483 base::DictionaryValue* protected_preferences) override {
[email protected]ae7bf342014-08-06 18:03:47484 // No attack.
485 }
486
dcheng8f4b8622014-10-23 16:37:48487 void VerifyReactionToPrefAttack() override {
[email protected]ae7bf342014-08-06 18:03:47488 // Expect all prefs to be reported as Unchanged with no resets.
deepak.m113481c82015-12-16 05:21:43489 EXPECT_EQ(
490 protection_level_ > PROTECTION_DISABLED_ON_PLATFORM
491 ? num_tracked_prefs()
492 : 0,
493 GetTrackedPrefHistogramCount(
494 user_prefs::tracked::kTrackedPrefHistogramUnchanged, ALLOW_ANY));
495 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
496 user_prefs::tracked::kTrackedPrefHistogramWantedReset,
497 ALLOW_NONE));
[email protected]ae7bf342014-08-06 18:03:47498 EXPECT_EQ(0,
499 GetTrackedPrefHistogramCount(
deepak.m113481c82015-12-16 05:21:43500 user_prefs::tracked::kTrackedPrefHistogramReset, ALLOW_NONE));
[email protected]ae7bf342014-08-06 18:03:47501
502 // Nothing else should have triggered.
[email protected]ae7bf342014-08-06 18:03:47503 EXPECT_EQ(
deepak.m113481c82015-12-16 05:21:43504 0, GetTrackedPrefHistogramCount(
505 user_prefs::tracked::kTrackedPrefHistogramChanged, ALLOW_NONE));
506 EXPECT_EQ(
507 0, GetTrackedPrefHistogramCount(
508 user_prefs::tracked::kTrackedPrefHistogramCleared, ALLOW_NONE));
509 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
510 user_prefs::tracked::kTrackedPrefHistogramInitialized,
511 ALLOW_NONE));
512 EXPECT_EQ(0,
513 GetTrackedPrefHistogramCount(
514 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized,
515 ALLOW_NONE));
516 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
517 user_prefs::tracked::kTrackedPrefHistogramNullInitialized,
518 ALLOW_NONE));
519 EXPECT_EQ(
520 0, GetTrackedPrefHistogramCount(
521 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
522 ALLOW_NONE));
proberge269fd092016-10-04 22:13:41523
524 if (SupportsRegistryValidation()) {
525 // Expect all prefs to be reported as Unchanged.
526 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM
527 ? num_tracked_prefs()
528 : 0,
529 GetTrackedPrefHistogramCount(
530 user_prefs::tracked::kTrackedPrefHistogramUnchanged,
531 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
532 ALLOW_ANY));
533 }
[email protected]ae7bf342014-08-06 18:03:47534 }
535};
536
gab36b85522017-05-24 19:30:45537PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUnchangedDefault, UnchangedDefault);
[email protected]ae7bf342014-08-06 18:03:47538
539// Augments PrefHashBrowserTestUnchangedDefault to confirm that nothing is reset
540// when nothing is tampered with, even if Chrome itself wrote custom prefs in
541// its last run.
542class PrefHashBrowserTestUnchangedCustom
543 : public PrefHashBrowserTestUnchangedDefault {
544 public:
dcheng8f4b8622014-10-23 16:37:48545 void SetupPreferences() override {
[email protected]ae7bf342014-08-06 18:03:47546 profile()->GetPrefs()->SetString(prefs::kHomePage, "http://example.com");
547
548 InstallExtensionWithUIAutoConfirm(
549 test_data_dir_.AppendASCII("good.crx"), 1, browser());
550 }
551
dcheng8f4b8622014-10-23 16:37:48552 void VerifyReactionToPrefAttack() override {
[email protected]ae7bf342014-08-06 18:03:47553 // Make sure the settings written in the last run stuck.
554 EXPECT_EQ("http://example.com",
555 profile()->GetPrefs()->GetString(prefs::kHomePage));
556
557 EXPECT_TRUE(extension_service()->GetExtensionById(kGoodCrxId, false));
558
559 // Reaction should be identical to unattacked default prefs.
560 PrefHashBrowserTestUnchangedDefault::VerifyReactionToPrefAttack();
561 }
562};
563
gab36b85522017-05-24 19:30:45564PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUnchangedCustom, UnchangedCustom);
[email protected]ae7bf342014-08-06 18:03:47565
566// Verifies that cleared prefs are reported.
567class PrefHashBrowserTestClearedAtomic : public PrefHashBrowserTestBase {
568 public:
dcheng8f4b8622014-10-23 16:37:48569 void SetupPreferences() override {
[email protected]ae7bf342014-08-06 18:03:47570 profile()->GetPrefs()->SetString(prefs::kHomePage, "http://example.com");
571 }
572
dcheng8f4b8622014-10-23 16:37:48573 void AttackPreferencesOnDisk(
[email protected]ae7bf342014-08-06 18:03:47574 base::DictionaryValue* unprotected_preferences,
mostynb2b52d1db2014-10-07 02:47:17575 base::DictionaryValue* protected_preferences) override {
[email protected]ae7bf342014-08-06 18:03:47576 base::DictionaryValue* selected_prefs =
577 protection_level_ >= PROTECTION_ENABLED_BASIC ? protected_preferences
578 : unprotected_preferences;
579 // |selected_prefs| should never be NULL under the protection level picking
580 // it.
581 EXPECT_TRUE(selected_prefs);
582 EXPECT_TRUE(selected_prefs->Remove(prefs::kHomePage, NULL));
583 }
584
dcheng8f4b8622014-10-23 16:37:48585 void VerifyReactionToPrefAttack() override {
[email protected]ae7bf342014-08-06 18:03:47586 // The clearance of homepage should have been noticed (as pref #2 being
587 // cleared), but shouldn't have triggered a reset (as there is nothing we
588 // can do when the pref is already gone).
589 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0,
[email protected]ae7bf342014-08-06 18:03:47590 GetTrackedPrefHistogramCount(
deepak.m113481c82015-12-16 05:21:43591 user_prefs::tracked::kTrackedPrefHistogramCleared,
592 BEGIN_ALLOW_SINGLE_BUCKET + 2));
593 EXPECT_EQ(
594 protection_level_ > PROTECTION_DISABLED_ON_PLATFORM
595 ? num_tracked_prefs() - 1
596 : 0,
597 GetTrackedPrefHistogramCount(
598 user_prefs::tracked::kTrackedPrefHistogramUnchanged, ALLOW_ANY));
599 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
600 user_prefs::tracked::kTrackedPrefHistogramWantedReset,
601 ALLOW_NONE));
[email protected]ae7bf342014-08-06 18:03:47602 EXPECT_EQ(0,
603 GetTrackedPrefHistogramCount(
deepak.m113481c82015-12-16 05:21:43604 user_prefs::tracked::kTrackedPrefHistogramReset, ALLOW_NONE));
[email protected]ae7bf342014-08-06 18:03:47605
606 // Nothing else should have triggered.
[email protected]ae7bf342014-08-06 18:03:47607 EXPECT_EQ(
deepak.m113481c82015-12-16 05:21:43608 0, GetTrackedPrefHistogramCount(
609 user_prefs::tracked::kTrackedPrefHistogramChanged, ALLOW_NONE));
610 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
611 user_prefs::tracked::kTrackedPrefHistogramInitialized,
612 ALLOW_NONE));
613 EXPECT_EQ(0,
614 GetTrackedPrefHistogramCount(
615 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized,
616 ALLOW_NONE));
617 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
618 user_prefs::tracked::kTrackedPrefHistogramNullInitialized,
619 ALLOW_NONE));
620 EXPECT_EQ(
621 0, GetTrackedPrefHistogramCount(
622 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
623 ALLOW_NONE));
proberge269fd092016-10-04 22:13:41624
625 if (SupportsRegistryValidation()) {
626 // Expect homepage clearance to have been noticed by registry validation.
627 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0,
628 GetTrackedPrefHistogramCount(
629 user_prefs::tracked::kTrackedPrefHistogramCleared,
630 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
631 BEGIN_ALLOW_SINGLE_BUCKET + 2));
632 }
[email protected]ae7bf342014-08-06 18:03:47633 }
634};
635
gab36b85522017-05-24 19:30:45636PREF_HASH_BROWSER_TEST(PrefHashBrowserTestClearedAtomic, ClearedAtomic);
[email protected]ae7bf342014-08-06 18:03:47637
638// Verifies that clearing the MACs results in untrusted Initialized pings for
639// non-null protected prefs.
640class PrefHashBrowserTestUntrustedInitialized : public PrefHashBrowserTestBase {
641 public:
dcheng8f4b8622014-10-23 16:37:48642 void SetupPreferences() override {
[email protected]ae7bf342014-08-06 18:03:47643 // Explicitly set the DSE (it's otherwise NULL by default, preventing
644 // thorough testing of the PROTECTION_ENABLED_DSE level).
645 DefaultSearchManager default_search_manager(
646 profile()->GetPrefs(), DefaultSearchManager::ObserverCallback());
647 DefaultSearchManager::Source dse_source =
648 static_cast<DefaultSearchManager::Source>(-1);
649
650 const TemplateURLData* default_template_url_data =
651 default_search_manager.GetDefaultSearchEngine(&dse_source);
652 EXPECT_EQ(DefaultSearchManager::FROM_FALLBACK, dse_source);
653
654 default_search_manager.SetUserSelectedDefaultSearchEngine(
655 *default_template_url_data);
656
657 default_search_manager.GetDefaultSearchEngine(&dse_source);
658 EXPECT_EQ(DefaultSearchManager::FROM_USER, dse_source);
659
660 // Also explicitly set an atomic pref that falls under
661 // PROTECTION_ENABLED_BASIC.
662 profile()->GetPrefs()->SetInteger(prefs::kRestoreOnStartup,
663 SessionStartupPref::URLS);
664 }
665
dcheng8f4b8622014-10-23 16:37:48666 void AttackPreferencesOnDisk(
[email protected]ae7bf342014-08-06 18:03:47667 base::DictionaryValue* unprotected_preferences,
mostynb2b52d1db2014-10-07 02:47:17668 base::DictionaryValue* protected_preferences) override {
proberge574d7d92016-08-01 20:14:11669 unprotected_preferences->Remove("protection.macs", NULL);
[email protected]ae7bf342014-08-06 18:03:47670 if (protected_preferences)
proberge574d7d92016-08-01 20:14:11671 protected_preferences->Remove("protection.macs", NULL);
[email protected]ae7bf342014-08-06 18:03:47672 }
673
dcheng8f4b8622014-10-23 16:37:48674 void VerifyReactionToPrefAttack() override {
gab342aa6182014-10-02 21:59:00675 // Preferences that are NULL by default will be NullInitialized.
[email protected]ae7bf342014-08-06 18:03:47676 int num_null_values = GetTrackedPrefHistogramCount(
deepak.m113481c82015-12-16 05:21:43677 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, ALLOW_ANY);
[email protected]ae7bf342014-08-06 18:03:47678 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM,
679 num_null_values > 0);
680 if (num_null_values > 0) {
681 // This test requires that at least 3 prefs be non-null (extensions, DSE,
682 // and 1 atomic pref explictly set for this test above).
gab342aa6182014-10-02 21:59:00683 EXPECT_GE(num_tracked_prefs() - num_null_values, 3);
[email protected]ae7bf342014-08-06 18:03:47684 }
685
686 // Expect all non-null prefs to be reported as Initialized (with
687 // accompanying resets or wanted resets based on the current protection
688 // level).
deepak.m113481c82015-12-16 05:21:43689 EXPECT_EQ(
690 num_tracked_prefs() - num_null_values,
691 GetTrackedPrefHistogramCount(
692 user_prefs::tracked::kTrackedPrefHistogramInitialized, ALLOW_ANY));
[email protected]ae7bf342014-08-06 18:03:47693
694 int num_protected_prefs = 0;
695 // A switch statement falling through each protection level in decreasing
696 // levels of protection to add expectations for each level which augments
697 // the previous one.
698 switch (protection_level_) {
699 case PROTECTION_ENABLED_ALL:
700 // Falls through.
701 case PROTECTION_ENABLED_EXTENSIONS:
702 ++num_protected_prefs;
703 // Falls through.
704 case PROTECTION_ENABLED_DSE:
705 ++num_protected_prefs;
706 // Falls through.
707 case PROTECTION_ENABLED_BASIC:
708 num_protected_prefs += num_tracked_prefs() - num_null_values - 2;
709 // Falls through.
710 case PROTECTION_DISABLED_FOR_GROUP:
711 // No protection. Falls through.
712 case PROTECTION_DISABLED_ON_PLATFORM:
713 // No protection.
714 break;
715 }
716
deepak.m113481c82015-12-16 05:21:43717 EXPECT_EQ(
718 num_tracked_prefs() - num_null_values - num_protected_prefs,
719 GetTrackedPrefHistogramCount(
720 user_prefs::tracked::kTrackedPrefHistogramWantedReset, ALLOW_ANY));
[email protected]ae7bf342014-08-06 18:03:47721 EXPECT_EQ(num_protected_prefs,
deepak.m113481c82015-12-16 05:21:43722 GetTrackedPrefHistogramCount(
723 user_prefs::tracked::kTrackedPrefHistogramReset, ALLOW_ANY));
[email protected]ae7bf342014-08-06 18:03:47724
725 // Explicitly verify the result of reported resets.
726
727 DefaultSearchManager default_search_manager(
728 profile()->GetPrefs(), DefaultSearchManager::ObserverCallback());
729 DefaultSearchManager::Source dse_source =
730 static_cast<DefaultSearchManager::Source>(-1);
731 default_search_manager.GetDefaultSearchEngine(&dse_source);
732 EXPECT_EQ(protection_level_ < PROTECTION_ENABLED_DSE
733 ? DefaultSearchManager::FROM_USER
734 : DefaultSearchManager::FROM_FALLBACK,
735 dse_source);
736
737 EXPECT_EQ(protection_level_ < PROTECTION_ENABLED_BASIC,
738 profile()->GetPrefs()->GetInteger(prefs::kRestoreOnStartup) ==
739 SessionStartupPref::URLS);
740
741 // Nothing else should have triggered.
deepak.m113481c82015-12-16 05:21:43742 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
743 user_prefs::tracked::kTrackedPrefHistogramUnchanged,
744 ALLOW_NONE));
[email protected]ae7bf342014-08-06 18:03:47745 EXPECT_EQ(
deepak.m113481c82015-12-16 05:21:43746 0, GetTrackedPrefHistogramCount(
747 user_prefs::tracked::kTrackedPrefHistogramChanged, ALLOW_NONE));
748 EXPECT_EQ(
749 0, GetTrackedPrefHistogramCount(
750 user_prefs::tracked::kTrackedPrefHistogramCleared, ALLOW_NONE));
751 EXPECT_EQ(
752 0, GetTrackedPrefHistogramCount(
753 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
754 ALLOW_NONE));
proberge269fd092016-10-04 22:13:41755
756 if (SupportsRegistryValidation()) {
757 // The MACs have been cleared but the preferences have not been tampered.
758 // The registry should report all prefs as unchanged.
759 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM
760 ? num_tracked_prefs()
761 : 0,
762 GetTrackedPrefHistogramCount(
763 user_prefs::tracked::kTrackedPrefHistogramUnchanged,
764 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
765 ALLOW_ANY));
766 }
[email protected]ae7bf342014-08-06 18:03:47767 }
768};
769
770PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedInitialized,
gab36b85522017-05-24 19:30:45771 UntrustedInitialized);
[email protected]ae7bf342014-08-06 18:03:47772
773// Verifies that changing an atomic pref results in it being reported (and reset
774// if the protection level allows it).
775class PrefHashBrowserTestChangedAtomic : public PrefHashBrowserTestBase {
776 public:
dcheng8f4b8622014-10-23 16:37:48777 void SetupPreferences() override {
[email protected]ae7bf342014-08-06 18:03:47778 profile()->GetPrefs()->SetInteger(prefs::kRestoreOnStartup,
779 SessionStartupPref::URLS);
780
781 ListPrefUpdate update(profile()->GetPrefs(),
782 prefs::kURLsToRestoreOnStartup);
783 update->AppendString("http://example.com");
784 }
785
dcheng8f4b8622014-10-23 16:37:48786 void AttackPreferencesOnDisk(
[email protected]ae7bf342014-08-06 18:03:47787 base::DictionaryValue* unprotected_preferences,
mostynb2b52d1db2014-10-07 02:47:17788 base::DictionaryValue* protected_preferences) override {
[email protected]ae7bf342014-08-06 18:03:47789 base::DictionaryValue* selected_prefs =
790 protection_level_ >= PROTECTION_ENABLED_BASIC ? protected_preferences
791 : unprotected_preferences;
792 // |selected_prefs| should never be NULL under the protection level picking
793 // it.
794 EXPECT_TRUE(selected_prefs);
795 base::ListValue* startup_urls;
796 EXPECT_TRUE(
797 selected_prefs->GetList(prefs::kURLsToRestoreOnStartup, &startup_urls));
798 EXPECT_TRUE(startup_urls);
799 EXPECT_EQ(1U, startup_urls->GetSize());
800 startup_urls->AppendString("http://example.org");
801 }
802
dcheng8f4b8622014-10-23 16:37:48803 void VerifyReactionToPrefAttack() override {
[email protected]ae7bf342014-08-06 18:03:47804 // Expect a single Changed event for tracked pref #4 (startup URLs).
805 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0,
[email protected]ae7bf342014-08-06 18:03:47806 GetTrackedPrefHistogramCount(
deepak.m113481c82015-12-16 05:21:43807 user_prefs::tracked::kTrackedPrefHistogramChanged,
808 BEGIN_ALLOW_SINGLE_BUCKET + 4));
[email protected]ae7bf342014-08-06 18:03:47809 EXPECT_EQ(
deepak.m113481c82015-12-16 05:21:43810 protection_level_ > PROTECTION_DISABLED_ON_PLATFORM
811 ? num_tracked_prefs() - 1
812 : 0,
813 GetTrackedPrefHistogramCount(
814 user_prefs::tracked::kTrackedPrefHistogramUnchanged, ALLOW_ANY));
815
816 EXPECT_EQ((protection_level_ > PROTECTION_DISABLED_ON_PLATFORM &&
817 protection_level_ < PROTECTION_ENABLED_BASIC)
818 ? 1
819 : 0,
820 GetTrackedPrefHistogramCount(
821 user_prefs::tracked::kTrackedPrefHistogramWantedReset,
822 BEGIN_ALLOW_SINGLE_BUCKET + 4));
[email protected]ae7bf342014-08-06 18:03:47823 EXPECT_EQ(protection_level_ >= PROTECTION_ENABLED_BASIC ? 1 : 0,
deepak.m113481c82015-12-16 05:21:43824 GetTrackedPrefHistogramCount(
825 user_prefs::tracked::kTrackedPrefHistogramReset,
826 BEGIN_ALLOW_SINGLE_BUCKET + 4));
[email protected]ae7bf342014-08-06 18:03:47827
828// TODO(gab): This doesn't work on OS_CHROMEOS because we fail to attack
829// Preferences.
830#if !defined(OS_CHROMEOS)
831 // Explicitly verify the result of reported resets.
832 EXPECT_EQ(protection_level_ >= PROTECTION_ENABLED_BASIC ? 0U : 2U,
833 profile()
834 ->GetPrefs()
835 ->GetList(prefs::kURLsToRestoreOnStartup)
836 ->GetSize());
837#endif
838
839 // Nothing else should have triggered.
[email protected]ae7bf342014-08-06 18:03:47840 EXPECT_EQ(
deepak.m113481c82015-12-16 05:21:43841 0, GetTrackedPrefHistogramCount(
842 user_prefs::tracked::kTrackedPrefHistogramCleared, ALLOW_NONE));
843 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
844 user_prefs::tracked::kTrackedPrefHistogramInitialized,
845 ALLOW_NONE));
846 EXPECT_EQ(0,
847 GetTrackedPrefHistogramCount(
848 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized,
849 ALLOW_NONE));
850 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
851 user_prefs::tracked::kTrackedPrefHistogramNullInitialized,
852 ALLOW_NONE));
853 EXPECT_EQ(
854 0, GetTrackedPrefHistogramCount(
855 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
856 ALLOW_NONE));
proberge269fd092016-10-04 22:13:41857
858 if (SupportsRegistryValidation()) {
859 // Expect a single Changed event for tracked pref #4 (startup URLs).
860 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0,
861 GetTrackedPrefHistogramCount(
862 user_prefs::tracked::kTrackedPrefHistogramChanged,
863 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
864 BEGIN_ALLOW_SINGLE_BUCKET + 4));
865 }
[email protected]ae7bf342014-08-06 18:03:47866 }
867};
868
gab36b85522017-05-24 19:30:45869PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedAtomic, ChangedAtomic);
[email protected]ae7bf342014-08-06 18:03:47870
871// Verifies that changing or adding an entry in a split pref results in both
872// items being reported (and remove if the protection level allows it).
873class PrefHashBrowserTestChangedSplitPref : public PrefHashBrowserTestBase {
874 public:
dcheng8f4b8622014-10-23 16:37:48875 void SetupPreferences() override {
[email protected]ae7bf342014-08-06 18:03:47876 InstallExtensionWithUIAutoConfirm(
877 test_data_dir_.AppendASCII("good.crx"), 1, browser());
878 }
879
dcheng8f4b8622014-10-23 16:37:48880 void AttackPreferencesOnDisk(
[email protected]ae7bf342014-08-06 18:03:47881 base::DictionaryValue* unprotected_preferences,
mostynb2b52d1db2014-10-07 02:47:17882 base::DictionaryValue* protected_preferences) override {
[email protected]ae7bf342014-08-06 18:03:47883 base::DictionaryValue* selected_prefs =
884 protection_level_ >= PROTECTION_ENABLED_EXTENSIONS
885 ? protected_preferences
886 : unprotected_preferences;
887 // |selected_prefs| should never be NULL under the protection level picking
888 // it.
889 EXPECT_TRUE(selected_prefs);
890 base::DictionaryValue* extensions_dict;
891 EXPECT_TRUE(selected_prefs->GetDictionary(
892 extensions::pref_names::kExtensions, &extensions_dict));
893 EXPECT_TRUE(extensions_dict);
894
895 // Tamper with any installed setting for good.crx
896 base::DictionaryValue* good_crx_dict;
897 EXPECT_TRUE(extensions_dict->GetDictionary(kGoodCrxId, &good_crx_dict));
898 int good_crx_state;
899 EXPECT_TRUE(good_crx_dict->GetInteger("state", &good_crx_state));
900 EXPECT_EQ(extensions::Extension::ENABLED, good_crx_state);
901 good_crx_dict->SetInteger("state", extensions::Extension::DISABLED);
902
903 // Drop a fake extension (for the purpose of this test, dropped settings
904 // don't need to be valid extension settings).
vabr9984ea62017-04-10 11:33:49905 auto fake_extension = base::MakeUnique<base::DictionaryValue>();
[email protected]ae7bf342014-08-06 18:03:47906 fake_extension->SetString("name", "foo");
vabr9984ea62017-04-10 11:33:49907 extensions_dict->Set(std::string(32, 'a'), std::move(fake_extension));
[email protected]ae7bf342014-08-06 18:03:47908 }
909
dcheng8f4b8622014-10-23 16:37:48910 void VerifyReactionToPrefAttack() override {
[email protected]ae7bf342014-08-06 18:03:47911 // Expect a single split pref changed report with a count of 2 for tracked
912 // pref #5 (extensions).
913 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0,
deepak.m113481c82015-12-16 05:21:43914 GetTrackedPrefHistogramCount(
915 user_prefs::tracked::kTrackedPrefHistogramChanged,
916 BEGIN_ALLOW_SINGLE_BUCKET + 5));
[email protected]ae7bf342014-08-06 18:03:47917 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0,
918 GetTrackedPrefHistogramCount(
919 "Settings.TrackedSplitPreferenceChanged.extensions.settings",
920 BEGIN_ALLOW_SINGLE_BUCKET + 2));
921
922 // Everything else should have remained unchanged.
[email protected]ae7bf342014-08-06 18:03:47923 EXPECT_EQ(
deepak.m113481c82015-12-16 05:21:43924 protection_level_ > PROTECTION_DISABLED_ON_PLATFORM
925 ? num_tracked_prefs() - 1
926 : 0,
927 GetTrackedPrefHistogramCount(
928 user_prefs::tracked::kTrackedPrefHistogramUnchanged, ALLOW_ANY));
929
930 EXPECT_EQ((protection_level_ > PROTECTION_DISABLED_ON_PLATFORM &&
931 protection_level_ < PROTECTION_ENABLED_EXTENSIONS)
932 ? 1
933 : 0,
934 GetTrackedPrefHistogramCount(
935 user_prefs::tracked::kTrackedPrefHistogramWantedReset,
936 BEGIN_ALLOW_SINGLE_BUCKET + 5));
[email protected]ae7bf342014-08-06 18:03:47937 EXPECT_EQ(protection_level_ >= PROTECTION_ENABLED_EXTENSIONS ? 1 : 0,
deepak.m113481c82015-12-16 05:21:43938 GetTrackedPrefHistogramCount(
939 user_prefs::tracked::kTrackedPrefHistogramReset,
940 BEGIN_ALLOW_SINGLE_BUCKET + 5));
[email protected]ae7bf342014-08-06 18:03:47941
942 EXPECT_EQ(protection_level_ < PROTECTION_ENABLED_EXTENSIONS,
943 extension_service()->GetExtensionById(kGoodCrxId, true) != NULL);
944
945 // Nothing else should have triggered.
[email protected]ae7bf342014-08-06 18:03:47946 EXPECT_EQ(
deepak.m113481c82015-12-16 05:21:43947 0, GetTrackedPrefHistogramCount(
948 user_prefs::tracked::kTrackedPrefHistogramCleared, ALLOW_NONE));
949 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
950 user_prefs::tracked::kTrackedPrefHistogramInitialized,
951 ALLOW_NONE));
952 EXPECT_EQ(0,
953 GetTrackedPrefHistogramCount(
954 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized,
955 ALLOW_NONE));
956 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
957 user_prefs::tracked::kTrackedPrefHistogramNullInitialized,
958 ALLOW_NONE));
959 EXPECT_EQ(
960 0, GetTrackedPrefHistogramCount(
961 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
962 ALLOW_NONE));
proberge269fd092016-10-04 22:13:41963
964 if (SupportsRegistryValidation()) {
965 // Expect that the registry validation caught the invalid MAC in split
966 // pref #5 (extensions).
967 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0,
968 GetTrackedPrefHistogramCount(
969 user_prefs::tracked::kTrackedPrefHistogramChanged,
970 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
971 BEGIN_ALLOW_SINGLE_BUCKET + 5));
972 }
[email protected]ae7bf342014-08-06 18:03:47973 }
974};
975
gab36b85522017-05-24 19:30:45976PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedSplitPref, ChangedSplitPref);
gabb004a562014-09-16 12:45:22977
978// Verifies that adding a value to unprotected preferences for a key which is
979// still using the default (i.e. has no value stored in protected preferences)
980// doesn't allow that value to slip in with no valid MAC (regression test for
981// http://crbug.com/414554)
982class PrefHashBrowserTestUntrustedAdditionToPrefs
983 : public PrefHashBrowserTestBase {
984 public:
dcheng8f4b8622014-10-23 16:37:48985 void SetupPreferences() override {
gabb004a562014-09-16 12:45:22986 // Ensure there is no user-selected value for kRestoreOnStartup.
987 EXPECT_FALSE(
988 profile()->GetPrefs()->GetUserPrefValue(prefs::kRestoreOnStartup));
989 }
990
dcheng8f4b8622014-10-23 16:37:48991 void AttackPreferencesOnDisk(
gabb004a562014-09-16 12:45:22992 base::DictionaryValue* unprotected_preferences,
mostynb2b52d1db2014-10-07 02:47:17993 base::DictionaryValue* protected_preferences) override {
gabb004a562014-09-16 12:45:22994 unprotected_preferences->SetInteger(prefs::kRestoreOnStartup,
995 SessionStartupPref::LAST);
996 }
997
dcheng8f4b8622014-10-23 16:37:48998 void VerifyReactionToPrefAttack() override {
gabb004a562014-09-16 12:45:22999 // Expect a single Changed event for tracked pref #3 (kRestoreOnStartup) if
1000 // not protecting; if protection is enabled the change should be a no-op.
1001 int changed_expected =
1002 protection_level_ == PROTECTION_DISABLED_FOR_GROUP ? 1 : 0;
deepak.m113481c82015-12-16 05:21:431003 EXPECT_EQ((protection_level_ > PROTECTION_DISABLED_ON_PLATFORM &&
1004 protection_level_ < PROTECTION_ENABLED_BASIC)
1005 ? changed_expected
1006 : 0,
gabb004a562014-09-16 12:45:221007 GetTrackedPrefHistogramCount(
deepak.m113481c82015-12-16 05:21:431008 user_prefs::tracked::kTrackedPrefHistogramChanged,
1009 BEGIN_ALLOW_SINGLE_BUCKET + 3));
gabb004a562014-09-16 12:45:221010 EXPECT_EQ(
deepak.m113481c82015-12-16 05:21:431011 protection_level_ > PROTECTION_DISABLED_ON_PLATFORM
1012 ? num_tracked_prefs() - changed_expected
1013 : 0,
1014 GetTrackedPrefHistogramCount(
1015 user_prefs::tracked::kTrackedPrefHistogramUnchanged, ALLOW_ANY));
1016
1017 EXPECT_EQ((protection_level_ > PROTECTION_DISABLED_ON_PLATFORM &&
1018 protection_level_ < PROTECTION_ENABLED_BASIC)
1019 ? 1
1020 : 0,
1021 GetTrackedPrefHistogramCount(
1022 user_prefs::tracked::kTrackedPrefHistogramWantedReset,
1023 BEGIN_ALLOW_SINGLE_BUCKET + 3));
gabb004a562014-09-16 12:45:221024 EXPECT_EQ(0,
deepak.m113481c82015-12-16 05:21:431025 GetTrackedPrefHistogramCount(
1026 user_prefs::tracked::kTrackedPrefHistogramReset, ALLOW_NONE));
gabb004a562014-09-16 12:45:221027
1028 // Nothing else should have triggered.
gabb004a562014-09-16 12:45:221029 EXPECT_EQ(
deepak.m113481c82015-12-16 05:21:431030 0, GetTrackedPrefHistogramCount(
1031 user_prefs::tracked::kTrackedPrefHistogramCleared, ALLOW_NONE));
1032 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
1033 user_prefs::tracked::kTrackedPrefHistogramInitialized,
1034 ALLOW_NONE));
1035 EXPECT_EQ(0,
1036 GetTrackedPrefHistogramCount(
1037 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized,
1038 ALLOW_NONE));
1039 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
1040 user_prefs::tracked::kTrackedPrefHistogramNullInitialized,
1041 ALLOW_NONE));
1042 EXPECT_EQ(
1043 0, GetTrackedPrefHistogramCount(
1044 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
1045 ALLOW_NONE));
proberge269fd092016-10-04 22:13:411046
1047 if (SupportsRegistryValidation()) {
1048 EXPECT_EQ((protection_level_ > PROTECTION_DISABLED_ON_PLATFORM &&
1049 protection_level_ < PROTECTION_ENABLED_BASIC)
1050 ? changed_expected
1051 : 0,
1052 GetTrackedPrefHistogramCount(
1053 user_prefs::tracked::kTrackedPrefHistogramChanged,
1054 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
1055 BEGIN_ALLOW_SINGLE_BUCKET + 3));
1056 }
gabb004a562014-09-16 12:45:221057 }
1058};
1059
1060PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefs,
gab36b85522017-05-24 19:30:451061 UntrustedAdditionToPrefs);
erikwrightf4e02b72014-09-17 20:25:451062
1063// Verifies that adding a value to unprotected preferences while wiping a
1064// user-selected value from protected preferences doesn't allow that value to
1065// slip in with no valid MAC (regression test for http://crbug.com/414554).
1066class PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe
1067 : public PrefHashBrowserTestBase {
1068 public:
dcheng8f4b8622014-10-23 16:37:481069 void SetupPreferences() override {
erikwrightf4e02b72014-09-17 20:25:451070 profile()->GetPrefs()->SetString(prefs::kHomePage, "http://example.com");
1071 }
1072
dcheng8f4b8622014-10-23 16:37:481073 void AttackPreferencesOnDisk(
erikwrightf4e02b72014-09-17 20:25:451074 base::DictionaryValue* unprotected_preferences,
mostynb2b52d1db2014-10-07 02:47:171075 base::DictionaryValue* protected_preferences) override {
erikwrightf4e02b72014-09-17 20:25:451076 // Set or change the value in Preferences to the attacker's choice.
1077 unprotected_preferences->SetString(prefs::kHomePage, "http://example.net");
1078 // Clear the value in Secure Preferences, if any.
1079 if (protected_preferences)
1080 protected_preferences->Remove(prefs::kHomePage, NULL);
1081 }
1082
dcheng8f4b8622014-10-23 16:37:481083 void VerifyReactionToPrefAttack() override {
erikwrightf4e02b72014-09-17 20:25:451084 // Expect a single Changed event for tracked pref #2 (kHomePage) if
1085 // not protecting; if protection is enabled the change should be a Cleared.
1086 int changed_expected =
1087 protection_level_ > PROTECTION_DISABLED_ON_PLATFORM &&
1088 protection_level_ < PROTECTION_ENABLED_BASIC
1089 ? 1 : 0;
1090 int cleared_expected =
1091 protection_level_ >= PROTECTION_ENABLED_BASIC
1092 ? 1 : 0;
1093 EXPECT_EQ(changed_expected,
erikwrightf4e02b72014-09-17 20:25:451094 GetTrackedPrefHistogramCount(
deepak.m113481c82015-12-16 05:21:431095 user_prefs::tracked::kTrackedPrefHistogramChanged,
1096 BEGIN_ALLOW_SINGLE_BUCKET + 2));
1097 EXPECT_EQ(cleared_expected,
1098 GetTrackedPrefHistogramCount(
1099 user_prefs::tracked::kTrackedPrefHistogramCleared,
1100 BEGIN_ALLOW_SINGLE_BUCKET + 2));
erikwrightf4e02b72014-09-17 20:25:451101 EXPECT_EQ(
deepak.m113481c82015-12-16 05:21:431102 protection_level_ > PROTECTION_DISABLED_ON_PLATFORM
1103 ? num_tracked_prefs() - changed_expected - cleared_expected
1104 : 0,
1105 GetTrackedPrefHistogramCount(
1106 user_prefs::tracked::kTrackedPrefHistogramUnchanged, ALLOW_ANY));
1107
1108 EXPECT_EQ(changed_expected,
1109 GetTrackedPrefHistogramCount(
1110 user_prefs::tracked::kTrackedPrefHistogramWantedReset,
1111 BEGIN_ALLOW_SINGLE_BUCKET + 2));
erikwrightf4e02b72014-09-17 20:25:451112 EXPECT_EQ(0,
deepak.m113481c82015-12-16 05:21:431113 GetTrackedPrefHistogramCount(
1114 user_prefs::tracked::kTrackedPrefHistogramReset, ALLOW_NONE));
erikwrightf4e02b72014-09-17 20:25:451115
1116 // Nothing else should have triggered.
deepak.m113481c82015-12-16 05:21:431117 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
1118 user_prefs::tracked::kTrackedPrefHistogramInitialized,
1119 ALLOW_NONE));
erikwrightf4e02b72014-09-17 20:25:451120 EXPECT_EQ(0,
1121 GetTrackedPrefHistogramCount(
deepak.m113481c82015-12-16 05:21:431122 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized,
1123 ALLOW_NONE));
1124 EXPECT_EQ(0, GetTrackedPrefHistogramCount(
1125 user_prefs::tracked::kTrackedPrefHistogramNullInitialized,
1126 ALLOW_NONE));
erikwrightf4e02b72014-09-17 20:25:451127 EXPECT_EQ(
deepak.m113481c82015-12-16 05:21:431128 0, GetTrackedPrefHistogramCount(
1129 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
1130 ALLOW_NONE));
proberge269fd092016-10-04 22:13:411131
1132 if (SupportsRegistryValidation()) {
1133 EXPECT_EQ(changed_expected,
1134 GetTrackedPrefHistogramCount(
1135 user_prefs::tracked::kTrackedPrefHistogramChanged,
1136 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
1137 BEGIN_ALLOW_SINGLE_BUCKET + 2));
1138 EXPECT_EQ(cleared_expected,
1139 GetTrackedPrefHistogramCount(
1140 user_prefs::tracked::kTrackedPrefHistogramCleared,
1141 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
1142 BEGIN_ALLOW_SINGLE_BUCKET + 2));
1143 }
erikwrightf4e02b72014-09-17 20:25:451144 }
1145};
1146
1147PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe,
gab36b85522017-05-24 19:30:451148 UntrustedAdditionToPrefsAfterWipe);
proberge269fd092016-10-04 22:13:411149
1150#if defined(OS_WIN)
1151class PrefHashBrowserTestRegistryValidationFailure
1152 : public PrefHashBrowserTestBase {
1153 public:
1154 void SetupPreferences() override {
1155 profile()->GetPrefs()->SetString(prefs::kHomePage, "http://example.com");
1156 }
1157
1158 void AttackPreferencesOnDisk(
1159 base::DictionaryValue* unprotected_preferences,
1160 base::DictionaryValue* protected_preferences) override {
1161 base::string16 registry_key =
1162 GetRegistryPathForTestProfile() + L"\\PreferenceMACs\\Default";
1163 base::win::RegKey key;
1164 ASSERT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, registry_key.c_str(),
1165 KEY_SET_VALUE | KEY_WOW64_32KEY));
1166 // An incorrect hash should still have the correct size.
1167 ASSERT_EQ(ERROR_SUCCESS,
1168 key.WriteValue(L"homepage", base::string16(64, 'A').c_str()));
1169 }
1170
1171 void VerifyReactionToPrefAttack() override {
1172 EXPECT_EQ(
1173 protection_level_ > PROTECTION_DISABLED_ON_PLATFORM
1174 ? num_tracked_prefs()
1175 : 0,
1176 GetTrackedPrefHistogramCount(
1177 user_prefs::tracked::kTrackedPrefHistogramUnchanged, ALLOW_ANY));
1178
1179 if (SupportsRegistryValidation()) {
1180 // Expect that the registry validation caught the invalid MAC for pref #2
1181 // (homepage).
1182 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0,
1183 GetTrackedPrefHistogramCount(
1184 user_prefs::tracked::kTrackedPrefHistogramChanged,
1185 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix,
1186 BEGIN_ALLOW_SINGLE_BUCKET + 2));
1187 }
1188 }
1189};
1190
1191PREF_HASH_BROWSER_TEST(PrefHashBrowserTestRegistryValidationFailure,
gab36b85522017-05-24 19:30:451192 RegistryValidationFailure);
proberge269fd092016-10-04 22:13:411193#endif
a-v-y38416862016-12-08 08:40:131194
1195// Verifies that all preferences related to choice of default search engine are
1196// protected.
1197class PrefHashBrowserTestDefaultSearch : public PrefHashBrowserTestBase {
1198 public:
1199 void SetupPreferences() override {
1200 // Set user selected default search engine.
1201 DefaultSearchManager default_search_manager(
1202 profile()->GetPrefs(), DefaultSearchManager::ObserverCallback());
1203 DefaultSearchManager::Source dse_source =
1204 static_cast<DefaultSearchManager::Source>(-1);
1205
1206 TemplateURLData user_dse;
1207 user_dse.SetKeyword(base::UTF8ToUTF16("userkeyword"));
1208 user_dse.SetShortName(base::UTF8ToUTF16("username"));
1209 user_dse.SetURL("http://user_default_engine/search?q=good_user_query");
1210 default_search_manager.SetUserSelectedDefaultSearchEngine(user_dse);
1211
1212 const TemplateURLData* current_dse =
1213 default_search_manager.GetDefaultSearchEngine(&dse_source);
1214 EXPECT_EQ(DefaultSearchManager::FROM_USER, dse_source);
1215 EXPECT_EQ(current_dse->keyword(), base::UTF8ToUTF16("userkeyword"));
1216 EXPECT_EQ(current_dse->short_name(), base::UTF8ToUTF16("username"));
1217 EXPECT_EQ(current_dse->url(),
1218 "http://user_default_engine/search?q=good_user_query");
1219 }
1220
1221 void AttackPreferencesOnDisk(
1222 base::DictionaryValue* unprotected_preferences,
1223 base::DictionaryValue* protected_preferences) override {
1224 static constexpr char default_search_provider_data[] = R"(
1225 {
1226 "default_search_provider_data" : {
1227 "template_url_data" : {
1228 "keyword" : "badkeyword",
1229 "short_name" : "badname",
1230 "url" : "http://bad_default_engine/search?q=dirty_user_query"
1231 }
1232 }
1233 })";
1234 static constexpr char search_provider_overrides[] = R"(
1235 {
1236 "search_provider_overrides" : [
1237 {
1238 "keyword" : "badkeyword",
1239 "name" : "badname",
1240 "search_url" : "http://bad_default_engine/search?q=dirty_user_query",
1241 "encoding" : "utf-8",
1242 "id" : 1
1243 }, {
1244 "keyword" : "badkeyword2",
1245 "name" : "badname2",
1246 "search_url" : "http://bad_default_engine2/search?q=dirty_user_query",
1247 "encoding" : "utf-8",
1248 "id" : 2
1249 }
1250 ]
1251 })";
a-v-y38416862016-12-08 08:40:131252
1253 // Try to override default search in all three of available preferences.
1254 auto attack1 = base::DictionaryValue::From(
1255 base::JSONReader::Read(default_search_provider_data));
1256 auto attack2 = base::DictionaryValue::From(
1257 base::JSONReader::Read(search_provider_overrides));
a-v-y38416862016-12-08 08:40:131258 unprotected_preferences->MergeDictionary(attack1.get());
1259 unprotected_preferences->MergeDictionary(attack2.get());
a-v-y38416862016-12-08 08:40:131260 if (protected_preferences) {
1261 // Override here, too.
1262 protected_preferences->MergeDictionary(attack1.get());
1263 protected_preferences->MergeDictionary(attack2.get());
a-v-y38416862016-12-08 08:40:131264 }
1265 }
1266
1267 void VerifyReactionToPrefAttack() override {
1268 DefaultSearchManager default_search_manager(
1269 profile()->GetPrefs(), DefaultSearchManager::ObserverCallback());
1270 DefaultSearchManager::Source dse_source =
1271 static_cast<DefaultSearchManager::Source>(-1);
1272
1273 const TemplateURLData* current_dse =
1274 default_search_manager.GetDefaultSearchEngine(&dse_source);
1275
1276 if (protection_level_ < PROTECTION_ENABLED_DSE) {
1277// This doesn't work on OS_CHROMEOS because we fail to attack Preferences.
1278#if !defined(OS_CHROMEOS)
1279 // Attack is successful.
1280 EXPECT_EQ(DefaultSearchManager::FROM_USER, dse_source);
1281 EXPECT_EQ(current_dse->keyword(), base::UTF8ToUTF16("badkeyword"));
1282 EXPECT_EQ(current_dse->short_name(), base::UTF8ToUTF16("badname"));
1283 EXPECT_EQ(current_dse->url(),
1284 "http://bad_default_engine/search?q=dirty_user_query");
1285#endif
1286 } else {
1287 // Attack fails.
1288 EXPECT_EQ(DefaultSearchManager::FROM_FALLBACK, dse_source);
1289 EXPECT_NE(current_dse->keyword(), base::UTF8ToUTF16("badkeyword"));
1290 EXPECT_NE(current_dse->short_name(), base::UTF8ToUTF16("badname"));
1291 EXPECT_NE(current_dse->url(),
1292 "http://bad_default_engine/search?q=dirty_user_query");
1293 }
1294 }
1295};
1296
gab36b85522017-05-24 19:30:451297PREF_HASH_BROWSER_TEST(PrefHashBrowserTestDefaultSearch, SearchProtected);