| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/browser/prefs/chrome_pref_service_factory.h" | 25 #include "chrome/browser/prefs/chrome_pref_service_factory.h" |
| 26 #include "chrome/browser/prefs/profile_pref_store_manager.h" | 26 #include "chrome/browser/prefs/profile_pref_store_manager.h" |
| 27 #include "chrome/browser/prefs/session_startup_pref.h" | 27 #include "chrome/browser/prefs/session_startup_pref.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
| 30 #include "chrome/common/chrome_constants.h" | 30 #include "chrome/common/chrome_constants.h" |
| 31 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
| 32 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 33 #include "chrome/test/base/testing_profile.h" | 33 #include "chrome/test/base/testing_profile.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 "extensions/browser/pref_names.h" | 36 #include "extensions/browser/pref_names.h" |
| 36 #include "extensions/common/extension.h" | 37 #include "extensions/common/extension.h" |
| 37 | 38 |
| 38 #if defined(OS_CHROMEOS) | 39 #if defined(OS_CHROMEOS) |
| 39 #include "chromeos/chromeos_switches.h" | 40 #include "chromeos/chromeos_switches.h" |
| 40 #endif | 41 #endif |
| 41 | 42 |
| 42 namespace { | 43 namespace { |
| 43 | 44 |
| 44 // Extension ID of chrome/test/data/extensions/good.crx | 45 // Extension ID of chrome/test/data/extensions/good.crx |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 const char kNumTrackedPrefFilename[] = "NumTrackedPrefs"; | 248 const char kNumTrackedPrefFilename[] = "NumTrackedPrefs"; |
| 248 | 249 |
| 249 base::FilePath num_tracked_prefs_file; | 250 base::FilePath num_tracked_prefs_file; |
| 250 ASSERT_TRUE( | 251 ASSERT_TRUE( |
| 251 PathService::Get(chrome::DIR_USER_DATA, &num_tracked_prefs_file)); | 252 PathService::Get(chrome::DIR_USER_DATA, &num_tracked_prefs_file)); |
| 252 num_tracked_prefs_file = | 253 num_tracked_prefs_file = |
| 253 num_tracked_prefs_file.AppendASCII(kNumTrackedPrefFilename); | 254 num_tracked_prefs_file.AppendASCII(kNumTrackedPrefFilename); |
| 254 | 255 |
| 255 if (IsPRETest()) { | 256 if (IsPRETest()) { |
| 256 num_tracked_prefs_ = GetTrackedPrefHistogramCount( | 257 num_tracked_prefs_ = GetTrackedPrefHistogramCount( |
| 257 "Settings.TrackedPreferenceNullInitialized", ALLOW_ANY); | 258 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, ALLOW_ANY); |
| 258 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM, | 259 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM, |
| 259 num_tracked_prefs_ > 0); | 260 num_tracked_prefs_ > 0); |
| 260 | 261 |
| 261 // Split tracked prefs are reported as Unchanged not as NullInitialized | 262 // Split tracked prefs are reported as Unchanged not as NullInitialized |
| 262 // when an empty dictionary is encountered on first run (this should only | 263 // when an empty dictionary is encountered on first run (this should only |
| 263 // hit for pref #5 in the current design). | 264 // hit for pref #5 in the current design). |
| 264 int num_split_tracked_prefs = GetTrackedPrefHistogramCount( | 265 int num_split_tracked_prefs = GetTrackedPrefHistogramCount( |
| 265 "Settings.TrackedPreferenceUnchanged", BEGIN_ALLOW_SINGLE_BUCKET + 5); | 266 user_prefs::tracked::kTrackedPrefHistogramUnchanged, |
| 267 BEGIN_ALLOW_SINGLE_BUCKET + 5); |
| 266 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, | 268 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, |
| 267 num_split_tracked_prefs); | 269 num_split_tracked_prefs); |
| 268 | 270 |
| 269 num_tracked_prefs_ += num_split_tracked_prefs; | 271 num_tracked_prefs_ += num_split_tracked_prefs; |
| 270 | 272 |
| 271 std::string num_tracked_prefs_str = base::IntToString(num_tracked_prefs_); | 273 std::string num_tracked_prefs_str = base::IntToString(num_tracked_prefs_); |
| 272 EXPECT_EQ(static_cast<int>(num_tracked_prefs_str.size()), | 274 EXPECT_EQ(static_cast<int>(num_tracked_prefs_str.size()), |
| 273 base::WriteFile(num_tracked_prefs_file, | 275 base::WriteFile(num_tracked_prefs_file, |
| 274 num_tracked_prefs_str.c_str(), | 276 num_tracked_prefs_str.c_str(), |
| 275 num_tracked_prefs_str.size())); | 277 num_tracked_prefs_str.size())); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 } | 368 } |
| 367 | 369 |
| 368 void AttackPreferencesOnDisk( | 370 void AttackPreferencesOnDisk( |
| 369 base::DictionaryValue* unprotected_preferences, | 371 base::DictionaryValue* unprotected_preferences, |
| 370 base::DictionaryValue* protected_preferences) override { | 372 base::DictionaryValue* protected_preferences) override { |
| 371 // No attack. | 373 // No attack. |
| 372 } | 374 } |
| 373 | 375 |
| 374 void VerifyReactionToPrefAttack() override { | 376 void VerifyReactionToPrefAttack() override { |
| 375 // Expect all prefs to be reported as Unchanged with no resets. | 377 // Expect all prefs to be reported as Unchanged with no resets. |
| 376 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM | 378 EXPECT_EQ( |
| 377 ? num_tracked_prefs() : 0, | 379 protection_level_ > PROTECTION_DISABLED_ON_PLATFORM |
| 378 GetTrackedPrefHistogramCount( | 380 ? num_tracked_prefs() |
| 379 "Settings.TrackedPreferenceUnchanged", ALLOW_ANY)); | 381 : 0, |
| 382 GetTrackedPrefHistogramCount( |
| 383 user_prefs::tracked::kTrackedPrefHistogramUnchanged, ALLOW_ANY)); |
| 384 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 385 user_prefs::tracked::kTrackedPrefHistogramWantedReset, |
| 386 ALLOW_NONE)); |
| 380 EXPECT_EQ(0, | 387 EXPECT_EQ(0, |
| 381 GetTrackedPrefHistogramCount( | 388 GetTrackedPrefHistogramCount( |
| 382 "Settings.TrackedPreferenceWantedReset", ALLOW_NONE)); | 389 user_prefs::tracked::kTrackedPrefHistogramReset, ALLOW_NONE)); |
| 383 EXPECT_EQ(0, | |
| 384 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceReset", | |
| 385 ALLOW_NONE)); | |
| 386 | 390 |
| 387 // Nothing else should have triggered. | 391 // Nothing else should have triggered. |
| 388 EXPECT_EQ(0, | 392 EXPECT_EQ( |
| 389 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceChanged", | 393 0, GetTrackedPrefHistogramCount( |
| 390 ALLOW_NONE)); | 394 user_prefs::tracked::kTrackedPrefHistogramChanged, ALLOW_NONE)); |
| 391 EXPECT_EQ(0, | 395 EXPECT_EQ( |
| 392 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceCleared", | 396 0, GetTrackedPrefHistogramCount( |
| 393 ALLOW_NONE)); | 397 user_prefs::tracked::kTrackedPrefHistogramCleared, ALLOW_NONE)); |
| 398 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 399 user_prefs::tracked::kTrackedPrefHistogramInitialized, |
| 400 ALLOW_NONE)); |
| 394 EXPECT_EQ(0, | 401 EXPECT_EQ(0, |
| 395 GetTrackedPrefHistogramCount( | 402 GetTrackedPrefHistogramCount( |
| 396 "Settings.TrackedPreferenceInitialized", ALLOW_NONE)); | 403 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, |
| 397 EXPECT_EQ(0, | 404 ALLOW_NONE)); |
| 398 GetTrackedPrefHistogramCount( | 405 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 399 "Settings.TrackedPreferenceTrustedInitialized", ALLOW_NONE)); | 406 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, |
| 400 EXPECT_EQ(0, | 407 ALLOW_NONE)); |
| 401 GetTrackedPrefHistogramCount( | |
| 402 "Settings.TrackedPreferenceNullInitialized", ALLOW_NONE)); | |
| 403 EXPECT_EQ( | 408 EXPECT_EQ( |
| 404 0, | 409 0, GetTrackedPrefHistogramCount( |
| 405 GetTrackedPrefHistogramCount( | 410 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, |
| 406 "Settings.TrackedPreferenceMigratedLegacyDeviceId", ALLOW_NONE)); | 411 ALLOW_NONE)); |
| 407 } | 412 } |
| 408 }; | 413 }; |
| 409 | 414 |
| 410 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUnchangedDefault, UnchangedDefault); | 415 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUnchangedDefault, UnchangedDefault); |
| 411 | 416 |
| 412 // Augments PrefHashBrowserTestUnchangedDefault to confirm that nothing is reset | 417 // Augments PrefHashBrowserTestUnchangedDefault to confirm that nothing is reset |
| 413 // when nothing is tampered with, even if Chrome itself wrote custom prefs in | 418 // when nothing is tampered with, even if Chrome itself wrote custom prefs in |
| 414 // its last run. | 419 // its last run. |
| 415 class PrefHashBrowserTestUnchangedCustom | 420 class PrefHashBrowserTestUnchangedCustom |
| 416 : public PrefHashBrowserTestUnchangedDefault { | 421 : public PrefHashBrowserTestUnchangedDefault { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 // it. | 458 // it. |
| 454 EXPECT_TRUE(selected_prefs); | 459 EXPECT_TRUE(selected_prefs); |
| 455 EXPECT_TRUE(selected_prefs->Remove(prefs::kHomePage, NULL)); | 460 EXPECT_TRUE(selected_prefs->Remove(prefs::kHomePage, NULL)); |
| 456 } | 461 } |
| 457 | 462 |
| 458 void VerifyReactionToPrefAttack() override { | 463 void VerifyReactionToPrefAttack() override { |
| 459 // The clearance of homepage should have been noticed (as pref #2 being | 464 // The clearance of homepage should have been noticed (as pref #2 being |
| 460 // cleared), but shouldn't have triggered a reset (as there is nothing we | 465 // cleared), but shouldn't have triggered a reset (as there is nothing we |
| 461 // can do when the pref is already gone). | 466 // can do when the pref is already gone). |
| 462 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, | 467 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, |
| 463 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceCleared", | |
| 464 BEGIN_ALLOW_SINGLE_BUCKET + 2)); | |
| 465 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM | |
| 466 ? num_tracked_prefs() - 1 : 0, | |
| 467 GetTrackedPrefHistogramCount( | 468 GetTrackedPrefHistogramCount( |
| 468 "Settings.TrackedPreferenceUnchanged", ALLOW_ANY)); | 469 user_prefs::tracked::kTrackedPrefHistogramCleared, |
| 470 BEGIN_ALLOW_SINGLE_BUCKET + 2)); |
| 471 EXPECT_EQ( |
| 472 protection_level_ > PROTECTION_DISABLED_ON_PLATFORM |
| 473 ? num_tracked_prefs() - 1 |
| 474 : 0, |
| 475 GetTrackedPrefHistogramCount( |
| 476 user_prefs::tracked::kTrackedPrefHistogramUnchanged, ALLOW_ANY)); |
| 477 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 478 user_prefs::tracked::kTrackedPrefHistogramWantedReset, |
| 479 ALLOW_NONE)); |
| 469 EXPECT_EQ(0, | 480 EXPECT_EQ(0, |
| 470 GetTrackedPrefHistogramCount( | 481 GetTrackedPrefHistogramCount( |
| 471 "Settings.TrackedPreferenceWantedReset", ALLOW_NONE)); | 482 user_prefs::tracked::kTrackedPrefHistogramReset, ALLOW_NONE)); |
| 472 EXPECT_EQ(0, | |
| 473 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceReset", | |
| 474 ALLOW_NONE)); | |
| 475 | 483 |
| 476 // Nothing else should have triggered. | 484 // Nothing else should have triggered. |
| 477 EXPECT_EQ(0, | 485 EXPECT_EQ( |
| 478 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceChanged", | 486 0, GetTrackedPrefHistogramCount( |
| 479 ALLOW_NONE)); | 487 user_prefs::tracked::kTrackedPrefHistogramChanged, ALLOW_NONE)); |
| 488 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 489 user_prefs::tracked::kTrackedPrefHistogramInitialized, |
| 490 ALLOW_NONE)); |
| 480 EXPECT_EQ(0, | 491 EXPECT_EQ(0, |
| 481 GetTrackedPrefHistogramCount( | 492 GetTrackedPrefHistogramCount( |
| 482 "Settings.TrackedPreferenceInitialized", ALLOW_NONE)); | 493 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, |
| 483 EXPECT_EQ(0, | 494 ALLOW_NONE)); |
| 484 GetTrackedPrefHistogramCount( | 495 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 485 "Settings.TrackedPreferenceTrustedInitialized", ALLOW_NONE)); | 496 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, |
| 486 EXPECT_EQ(0, | 497 ALLOW_NONE)); |
| 487 GetTrackedPrefHistogramCount( | |
| 488 "Settings.TrackedPreferenceNullInitialized", ALLOW_NONE)); | |
| 489 EXPECT_EQ( | 498 EXPECT_EQ( |
| 490 0, | 499 0, GetTrackedPrefHistogramCount( |
| 491 GetTrackedPrefHistogramCount( | 500 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, |
| 492 "Settings.TrackedPreferenceMigratedLegacyDeviceId", ALLOW_NONE)); | 501 ALLOW_NONE)); |
| 493 } | 502 } |
| 494 }; | 503 }; |
| 495 | 504 |
| 496 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestClearedAtomic, ClearedAtomic); | 505 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestClearedAtomic, ClearedAtomic); |
| 497 | 506 |
| 498 // Verifies that clearing the MACs results in untrusted Initialized pings for | 507 // Verifies that clearing the MACs results in untrusted Initialized pings for |
| 499 // non-null protected prefs. | 508 // non-null protected prefs. |
| 500 class PrefHashBrowserTestUntrustedInitialized : public PrefHashBrowserTestBase { | 509 class PrefHashBrowserTestUntrustedInitialized : public PrefHashBrowserTestBase { |
| 501 public: | 510 public: |
| 502 void SetupPreferences() override { | 511 void SetupPreferences() override { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 527 base::DictionaryValue* unprotected_preferences, | 536 base::DictionaryValue* unprotected_preferences, |
| 528 base::DictionaryValue* protected_preferences) override { | 537 base::DictionaryValue* protected_preferences) override { |
| 529 EXPECT_TRUE(unprotected_preferences->Remove("protection.macs", NULL)); | 538 EXPECT_TRUE(unprotected_preferences->Remove("protection.macs", NULL)); |
| 530 if (protected_preferences) | 539 if (protected_preferences) |
| 531 EXPECT_TRUE(protected_preferences->Remove("protection.macs", NULL)); | 540 EXPECT_TRUE(protected_preferences->Remove("protection.macs", NULL)); |
| 532 } | 541 } |
| 533 | 542 |
| 534 void VerifyReactionToPrefAttack() override { | 543 void VerifyReactionToPrefAttack() override { |
| 535 // Preferences that are NULL by default will be NullInitialized. | 544 // Preferences that are NULL by default will be NullInitialized. |
| 536 int num_null_values = GetTrackedPrefHistogramCount( | 545 int num_null_values = GetTrackedPrefHistogramCount( |
| 537 "Settings.TrackedPreferenceNullInitialized", ALLOW_ANY); | 546 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, ALLOW_ANY); |
| 538 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM, | 547 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM, |
| 539 num_null_values > 0); | 548 num_null_values > 0); |
| 540 if (num_null_values > 0) { | 549 if (num_null_values > 0) { |
| 541 // This test requires that at least 3 prefs be non-null (extensions, DSE, | 550 // This test requires that at least 3 prefs be non-null (extensions, DSE, |
| 542 // and 1 atomic pref explictly set for this test above). | 551 // and 1 atomic pref explictly set for this test above). |
| 543 EXPECT_GE(num_tracked_prefs() - num_null_values, 3); | 552 EXPECT_GE(num_tracked_prefs() - num_null_values, 3); |
| 544 } | 553 } |
| 545 | 554 |
| 546 // Expect all non-null prefs to be reported as Initialized (with | 555 // Expect all non-null prefs to be reported as Initialized (with |
| 547 // accompanying resets or wanted resets based on the current protection | 556 // accompanying resets or wanted resets based on the current protection |
| 548 // level). | 557 // level). |
| 549 EXPECT_EQ(num_tracked_prefs() - num_null_values, | 558 EXPECT_EQ( |
| 550 GetTrackedPrefHistogramCount( | 559 num_tracked_prefs() - num_null_values, |
| 551 "Settings.TrackedPreferenceInitialized", ALLOW_ANY)); | 560 GetTrackedPrefHistogramCount( |
| 561 user_prefs::tracked::kTrackedPrefHistogramInitialized, ALLOW_ANY)); |
| 552 | 562 |
| 553 int num_protected_prefs = 0; | 563 int num_protected_prefs = 0; |
| 554 // A switch statement falling through each protection level in decreasing | 564 // A switch statement falling through each protection level in decreasing |
| 555 // levels of protection to add expectations for each level which augments | 565 // levels of protection to add expectations for each level which augments |
| 556 // the previous one. | 566 // the previous one. |
| 557 switch (protection_level_) { | 567 switch (protection_level_) { |
| 558 case PROTECTION_ENABLED_ALL: | 568 case PROTECTION_ENABLED_ALL: |
| 559 // Falls through. | 569 // Falls through. |
| 560 case PROTECTION_ENABLED_EXTENSIONS: | 570 case PROTECTION_ENABLED_EXTENSIONS: |
| 561 ++num_protected_prefs; | 571 ++num_protected_prefs; |
| 562 // Falls through. | 572 // Falls through. |
| 563 case PROTECTION_ENABLED_DSE: | 573 case PROTECTION_ENABLED_DSE: |
| 564 ++num_protected_prefs; | 574 ++num_protected_prefs; |
| 565 // Falls through. | 575 // Falls through. |
| 566 case PROTECTION_ENABLED_BASIC: | 576 case PROTECTION_ENABLED_BASIC: |
| 567 num_protected_prefs += num_tracked_prefs() - num_null_values - 2; | 577 num_protected_prefs += num_tracked_prefs() - num_null_values - 2; |
| 568 // Falls through. | 578 // Falls through. |
| 569 case PROTECTION_DISABLED_FOR_GROUP: | 579 case PROTECTION_DISABLED_FOR_GROUP: |
| 570 // No protection. Falls through. | 580 // No protection. Falls through. |
| 571 case PROTECTION_DISABLED_ON_PLATFORM: | 581 case PROTECTION_DISABLED_ON_PLATFORM: |
| 572 // No protection. | 582 // No protection. |
| 573 break; | 583 break; |
| 574 } | 584 } |
| 575 | 585 |
| 576 EXPECT_EQ(num_tracked_prefs() - num_null_values - num_protected_prefs, | 586 EXPECT_EQ( |
| 587 num_tracked_prefs() - num_null_values - num_protected_prefs, |
| 588 GetTrackedPrefHistogramCount( |
| 589 user_prefs::tracked::kTrackedPrefHistogramWantedReset, ALLOW_ANY)); |
| 590 EXPECT_EQ(num_protected_prefs, |
| 577 GetTrackedPrefHistogramCount( | 591 GetTrackedPrefHistogramCount( |
| 578 "Settings.TrackedPreferenceWantedReset", ALLOW_ANY)); | 592 user_prefs::tracked::kTrackedPrefHistogramReset, ALLOW_ANY)); |
| 579 EXPECT_EQ(num_protected_prefs, | |
| 580 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceReset", | |
| 581 ALLOW_ANY)); | |
| 582 | 593 |
| 583 // Explicitly verify the result of reported resets. | 594 // Explicitly verify the result of reported resets. |
| 584 | 595 |
| 585 DefaultSearchManager default_search_manager( | 596 DefaultSearchManager default_search_manager( |
| 586 profile()->GetPrefs(), DefaultSearchManager::ObserverCallback()); | 597 profile()->GetPrefs(), DefaultSearchManager::ObserverCallback()); |
| 587 DefaultSearchManager::Source dse_source = | 598 DefaultSearchManager::Source dse_source = |
| 588 static_cast<DefaultSearchManager::Source>(-1); | 599 static_cast<DefaultSearchManager::Source>(-1); |
| 589 default_search_manager.GetDefaultSearchEngine(&dse_source); | 600 default_search_manager.GetDefaultSearchEngine(&dse_source); |
| 590 EXPECT_EQ(protection_level_ < PROTECTION_ENABLED_DSE | 601 EXPECT_EQ(protection_level_ < PROTECTION_ENABLED_DSE |
| 591 ? DefaultSearchManager::FROM_USER | 602 ? DefaultSearchManager::FROM_USER |
| 592 : DefaultSearchManager::FROM_FALLBACK, | 603 : DefaultSearchManager::FROM_FALLBACK, |
| 593 dse_source); | 604 dse_source); |
| 594 | 605 |
| 595 EXPECT_EQ(protection_level_ < PROTECTION_ENABLED_BASIC, | 606 EXPECT_EQ(protection_level_ < PROTECTION_ENABLED_BASIC, |
| 596 profile()->GetPrefs()->GetInteger(prefs::kRestoreOnStartup) == | 607 profile()->GetPrefs()->GetInteger(prefs::kRestoreOnStartup) == |
| 597 SessionStartupPref::URLS); | 608 SessionStartupPref::URLS); |
| 598 | 609 |
| 599 // Nothing else should have triggered. | 610 // Nothing else should have triggered. |
| 600 EXPECT_EQ(0, | 611 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 601 GetTrackedPrefHistogramCount( | 612 user_prefs::tracked::kTrackedPrefHistogramUnchanged, |
| 602 "Settings.TrackedPreferenceUnchanged", ALLOW_NONE)); | 613 ALLOW_NONE)); |
| 603 EXPECT_EQ(0, | |
| 604 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceChanged", | |
| 605 ALLOW_NONE)); | |
| 606 EXPECT_EQ(0, | |
| 607 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceCleared", | |
| 608 ALLOW_NONE)); | |
| 609 EXPECT_EQ( | 614 EXPECT_EQ( |
| 610 0, | 615 0, GetTrackedPrefHistogramCount( |
| 611 GetTrackedPrefHistogramCount( | 616 user_prefs::tracked::kTrackedPrefHistogramChanged, ALLOW_NONE)); |
| 612 "Settings.TrackedPreferenceMigratedLegacyDeviceId", ALLOW_NONE)); | 617 EXPECT_EQ( |
| 618 0, GetTrackedPrefHistogramCount( |
| 619 user_prefs::tracked::kTrackedPrefHistogramCleared, ALLOW_NONE)); |
| 620 EXPECT_EQ( |
| 621 0, GetTrackedPrefHistogramCount( |
| 622 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, |
| 623 ALLOW_NONE)); |
| 613 } | 624 } |
| 614 }; | 625 }; |
| 615 | 626 |
| 616 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedInitialized, | 627 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedInitialized, |
| 617 UntrustedInitialized); | 628 UntrustedInitialized); |
| 618 | 629 |
| 619 // Verifies that changing an atomic pref results in it being reported (and reset | 630 // Verifies that changing an atomic pref results in it being reported (and reset |
| 620 // if the protection level allows it). | 631 // if the protection level allows it). |
| 621 class PrefHashBrowserTestChangedAtomic : public PrefHashBrowserTestBase { | 632 class PrefHashBrowserTestChangedAtomic : public PrefHashBrowserTestBase { |
| 622 public: | 633 public: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 642 EXPECT_TRUE( | 653 EXPECT_TRUE( |
| 643 selected_prefs->GetList(prefs::kURLsToRestoreOnStartup, &startup_urls)); | 654 selected_prefs->GetList(prefs::kURLsToRestoreOnStartup, &startup_urls)); |
| 644 EXPECT_TRUE(startup_urls); | 655 EXPECT_TRUE(startup_urls); |
| 645 EXPECT_EQ(1U, startup_urls->GetSize()); | 656 EXPECT_EQ(1U, startup_urls->GetSize()); |
| 646 startup_urls->AppendString("http://example.org"); | 657 startup_urls->AppendString("http://example.org"); |
| 647 } | 658 } |
| 648 | 659 |
| 649 void VerifyReactionToPrefAttack() override { | 660 void VerifyReactionToPrefAttack() override { |
| 650 // Expect a single Changed event for tracked pref #4 (startup URLs). | 661 // Expect a single Changed event for tracked pref #4 (startup URLs). |
| 651 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, | 662 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, |
| 652 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceChanged", | |
| 653 BEGIN_ALLOW_SINGLE_BUCKET + 4)); | |
| 654 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM | |
| 655 ? num_tracked_prefs() - 1 : 0, | |
| 656 GetTrackedPrefHistogramCount( | 663 GetTrackedPrefHistogramCount( |
| 657 "Settings.TrackedPreferenceUnchanged", ALLOW_ANY)); | 664 user_prefs::tracked::kTrackedPrefHistogramChanged, |
| 665 BEGIN_ALLOW_SINGLE_BUCKET + 4)); |
| 666 EXPECT_EQ( |
| 667 protection_level_ > PROTECTION_DISABLED_ON_PLATFORM |
| 668 ? num_tracked_prefs() - 1 |
| 669 : 0, |
| 670 GetTrackedPrefHistogramCount( |
| 671 user_prefs::tracked::kTrackedPrefHistogramUnchanged, ALLOW_ANY)); |
| 658 | 672 |
| 659 EXPECT_EQ( | 673 EXPECT_EQ((protection_level_ > PROTECTION_DISABLED_ON_PLATFORM && |
| 660 (protection_level_ > PROTECTION_DISABLED_ON_PLATFORM && | 674 protection_level_ < PROTECTION_ENABLED_BASIC) |
| 661 protection_level_ < PROTECTION_ENABLED_BASIC) ? 1 : 0, | 675 ? 1 |
| 662 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceWantedReset", | 676 : 0, |
| 663 BEGIN_ALLOW_SINGLE_BUCKET + 4)); | 677 GetTrackedPrefHistogramCount( |
| 678 user_prefs::tracked::kTrackedPrefHistogramWantedReset, |
| 679 BEGIN_ALLOW_SINGLE_BUCKET + 4)); |
| 664 EXPECT_EQ(protection_level_ >= PROTECTION_ENABLED_BASIC ? 1 : 0, | 680 EXPECT_EQ(protection_level_ >= PROTECTION_ENABLED_BASIC ? 1 : 0, |
| 665 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceReset", | 681 GetTrackedPrefHistogramCount( |
| 666 BEGIN_ALLOW_SINGLE_BUCKET + 4)); | 682 user_prefs::tracked::kTrackedPrefHistogramReset, |
| 683 BEGIN_ALLOW_SINGLE_BUCKET + 4)); |
| 667 | 684 |
| 668 // TODO(gab): This doesn't work on OS_CHROMEOS because we fail to attack | 685 // TODO(gab): This doesn't work on OS_CHROMEOS because we fail to attack |
| 669 // Preferences. | 686 // Preferences. |
| 670 #if !defined(OS_CHROMEOS) | 687 #if !defined(OS_CHROMEOS) |
| 671 // Explicitly verify the result of reported resets. | 688 // Explicitly verify the result of reported resets. |
| 672 EXPECT_EQ(protection_level_ >= PROTECTION_ENABLED_BASIC ? 0U : 2U, | 689 EXPECT_EQ(protection_level_ >= PROTECTION_ENABLED_BASIC ? 0U : 2U, |
| 673 profile() | 690 profile() |
| 674 ->GetPrefs() | 691 ->GetPrefs() |
| 675 ->GetList(prefs::kURLsToRestoreOnStartup) | 692 ->GetList(prefs::kURLsToRestoreOnStartup) |
| 676 ->GetSize()); | 693 ->GetSize()); |
| 677 #endif | 694 #endif |
| 678 | 695 |
| 679 // Nothing else should have triggered. | 696 // Nothing else should have triggered. |
| 680 EXPECT_EQ(0, | 697 EXPECT_EQ( |
| 681 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceCleared", | 698 0, GetTrackedPrefHistogramCount( |
| 682 ALLOW_NONE)); | 699 user_prefs::tracked::kTrackedPrefHistogramCleared, ALLOW_NONE)); |
| 700 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 701 user_prefs::tracked::kTrackedPrefHistogramInitialized, |
| 702 ALLOW_NONE)); |
| 683 EXPECT_EQ(0, | 703 EXPECT_EQ(0, |
| 684 GetTrackedPrefHistogramCount( | 704 GetTrackedPrefHistogramCount( |
| 685 "Settings.TrackedPreferenceInitialized", ALLOW_NONE)); | 705 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, |
| 686 EXPECT_EQ(0, | 706 ALLOW_NONE)); |
| 687 GetTrackedPrefHistogramCount( | 707 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 688 "Settings.TrackedPreferenceTrustedInitialized", ALLOW_NONE)); | 708 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, |
| 689 EXPECT_EQ(0, | 709 ALLOW_NONE)); |
| 690 GetTrackedPrefHistogramCount( | |
| 691 "Settings.TrackedPreferenceNullInitialized", ALLOW_NONE)); | |
| 692 EXPECT_EQ( | 710 EXPECT_EQ( |
| 693 0, | 711 0, GetTrackedPrefHistogramCount( |
| 694 GetTrackedPrefHistogramCount( | 712 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, |
| 695 "Settings.TrackedPreferenceMigratedLegacyDeviceId", ALLOW_NONE)); | 713 ALLOW_NONE)); |
| 696 } | 714 } |
| 697 }; | 715 }; |
| 698 | 716 |
| 699 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedAtomic, ChangedAtomic); | 717 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedAtomic, ChangedAtomic); |
| 700 | 718 |
| 701 // Verifies that changing or adding an entry in a split pref results in both | 719 // Verifies that changing or adding an entry in a split pref results in both |
| 702 // items being reported (and remove if the protection level allows it). | 720 // items being reported (and remove if the protection level allows it). |
| 703 class PrefHashBrowserTestChangedSplitPref : public PrefHashBrowserTestBase { | 721 class PrefHashBrowserTestChangedSplitPref : public PrefHashBrowserTestBase { |
| 704 public: | 722 public: |
| 705 void SetupPreferences() override { | 723 void SetupPreferences() override { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 734 // don't need to be valid extension settings). | 752 // don't need to be valid extension settings). |
| 735 base::DictionaryValue* fake_extension = new base::DictionaryValue; | 753 base::DictionaryValue* fake_extension = new base::DictionaryValue; |
| 736 fake_extension->SetString("name", "foo"); | 754 fake_extension->SetString("name", "foo"); |
| 737 extensions_dict->Set(std::string(32, 'a'), fake_extension); | 755 extensions_dict->Set(std::string(32, 'a'), fake_extension); |
| 738 } | 756 } |
| 739 | 757 |
| 740 void VerifyReactionToPrefAttack() override { | 758 void VerifyReactionToPrefAttack() override { |
| 741 // Expect a single split pref changed report with a count of 2 for tracked | 759 // Expect a single split pref changed report with a count of 2 for tracked |
| 742 // pref #5 (extensions). | 760 // pref #5 (extensions). |
| 743 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, | 761 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, |
| 744 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceChanged", | 762 GetTrackedPrefHistogramCount( |
| 745 BEGIN_ALLOW_SINGLE_BUCKET + 5)); | 763 user_prefs::tracked::kTrackedPrefHistogramChanged, |
| 764 BEGIN_ALLOW_SINGLE_BUCKET + 5)); |
| 746 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, | 765 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, |
| 747 GetTrackedPrefHistogramCount( | 766 GetTrackedPrefHistogramCount( |
| 748 "Settings.TrackedSplitPreferenceChanged.extensions.settings", | 767 "Settings.TrackedSplitPreferenceChanged.extensions.settings", |
| 749 BEGIN_ALLOW_SINGLE_BUCKET + 2)); | 768 BEGIN_ALLOW_SINGLE_BUCKET + 2)); |
| 750 | 769 |
| 751 // Everything else should have remained unchanged. | 770 // Everything else should have remained unchanged. |
| 752 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM | 771 EXPECT_EQ( |
| 753 ? num_tracked_prefs() - 1 : 0, | 772 protection_level_ > PROTECTION_DISABLED_ON_PLATFORM |
| 773 ? num_tracked_prefs() - 1 |
| 774 : 0, |
| 775 GetTrackedPrefHistogramCount( |
| 776 user_prefs::tracked::kTrackedPrefHistogramUnchanged, ALLOW_ANY)); |
| 777 |
| 778 EXPECT_EQ((protection_level_ > PROTECTION_DISABLED_ON_PLATFORM && |
| 779 protection_level_ < PROTECTION_ENABLED_EXTENSIONS) |
| 780 ? 1 |
| 781 : 0, |
| 754 GetTrackedPrefHistogramCount( | 782 GetTrackedPrefHistogramCount( |
| 755 "Settings.TrackedPreferenceUnchanged", ALLOW_ANY)); | 783 user_prefs::tracked::kTrackedPrefHistogramWantedReset, |
| 756 | 784 BEGIN_ALLOW_SINGLE_BUCKET + 5)); |
| 757 EXPECT_EQ( | |
| 758 (protection_level_ > PROTECTION_DISABLED_ON_PLATFORM && | |
| 759 protection_level_ < PROTECTION_ENABLED_EXTENSIONS) ? 1 : 0, | |
| 760 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceWantedReset", | |
| 761 BEGIN_ALLOW_SINGLE_BUCKET + 5)); | |
| 762 EXPECT_EQ(protection_level_ >= PROTECTION_ENABLED_EXTENSIONS ? 1 : 0, | 785 EXPECT_EQ(protection_level_ >= PROTECTION_ENABLED_EXTENSIONS ? 1 : 0, |
| 763 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceReset", | 786 GetTrackedPrefHistogramCount( |
| 764 BEGIN_ALLOW_SINGLE_BUCKET + 5)); | 787 user_prefs::tracked::kTrackedPrefHistogramReset, |
| 788 BEGIN_ALLOW_SINGLE_BUCKET + 5)); |
| 765 | 789 |
| 766 EXPECT_EQ(protection_level_ < PROTECTION_ENABLED_EXTENSIONS, | 790 EXPECT_EQ(protection_level_ < PROTECTION_ENABLED_EXTENSIONS, |
| 767 extension_service()->GetExtensionById(kGoodCrxId, true) != NULL); | 791 extension_service()->GetExtensionById(kGoodCrxId, true) != NULL); |
| 768 | 792 |
| 769 // Nothing else should have triggered. | 793 // Nothing else should have triggered. |
| 770 EXPECT_EQ(0, | 794 EXPECT_EQ( |
| 771 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceCleared", | 795 0, GetTrackedPrefHistogramCount( |
| 772 ALLOW_NONE)); | 796 user_prefs::tracked::kTrackedPrefHistogramCleared, ALLOW_NONE)); |
| 797 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 798 user_prefs::tracked::kTrackedPrefHistogramInitialized, |
| 799 ALLOW_NONE)); |
| 773 EXPECT_EQ(0, | 800 EXPECT_EQ(0, |
| 774 GetTrackedPrefHistogramCount( | 801 GetTrackedPrefHistogramCount( |
| 775 "Settings.TrackedPreferenceInitialized", ALLOW_NONE)); | 802 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, |
| 776 EXPECT_EQ(0, | 803 ALLOW_NONE)); |
| 777 GetTrackedPrefHistogramCount( | 804 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 778 "Settings.TrackedPreferenceTrustedInitialized", ALLOW_NONE)); | 805 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, |
| 779 EXPECT_EQ(0, | 806 ALLOW_NONE)); |
| 780 GetTrackedPrefHistogramCount( | |
| 781 "Settings.TrackedPreferenceNullInitialized", ALLOW_NONE)); | |
| 782 EXPECT_EQ( | 807 EXPECT_EQ( |
| 783 0, | 808 0, GetTrackedPrefHistogramCount( |
| 784 GetTrackedPrefHistogramCount( | 809 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, |
| 785 "Settings.TrackedPreferenceMigratedLegacyDeviceId", ALLOW_NONE)); | 810 ALLOW_NONE)); |
| 786 } | 811 } |
| 787 }; | 812 }; |
| 788 | 813 |
| 789 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedSplitPref, ChangedSplitPref); | 814 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedSplitPref, ChangedSplitPref); |
| 790 | 815 |
| 791 // Verifies that adding a value to unprotected preferences for a key which is | 816 // Verifies that adding a value to unprotected preferences for a key which is |
| 792 // still using the default (i.e. has no value stored in protected preferences) | 817 // still using the default (i.e. has no value stored in protected preferences) |
| 793 // doesn't allow that value to slip in with no valid MAC (regression test for | 818 // doesn't allow that value to slip in with no valid MAC (regression test for |
| 794 // http://crbug.com/414554) | 819 // http://crbug.com/414554) |
| 795 class PrefHashBrowserTestUntrustedAdditionToPrefs | 820 class PrefHashBrowserTestUntrustedAdditionToPrefs |
| (...skipping 10 matching lines...) Expand all Loading... |
| 806 base::DictionaryValue* protected_preferences) override { | 831 base::DictionaryValue* protected_preferences) override { |
| 807 unprotected_preferences->SetInteger(prefs::kRestoreOnStartup, | 832 unprotected_preferences->SetInteger(prefs::kRestoreOnStartup, |
| 808 SessionStartupPref::LAST); | 833 SessionStartupPref::LAST); |
| 809 } | 834 } |
| 810 | 835 |
| 811 void VerifyReactionToPrefAttack() override { | 836 void VerifyReactionToPrefAttack() override { |
| 812 // Expect a single Changed event for tracked pref #3 (kRestoreOnStartup) if | 837 // Expect a single Changed event for tracked pref #3 (kRestoreOnStartup) if |
| 813 // not protecting; if protection is enabled the change should be a no-op. | 838 // not protecting; if protection is enabled the change should be a no-op. |
| 814 int changed_expected = | 839 int changed_expected = |
| 815 protection_level_ == PROTECTION_DISABLED_FOR_GROUP ? 1 : 0; | 840 protection_level_ == PROTECTION_DISABLED_FOR_GROUP ? 1 : 0; |
| 841 EXPECT_EQ((protection_level_ > PROTECTION_DISABLED_ON_PLATFORM && |
| 842 protection_level_ < PROTECTION_ENABLED_BASIC) |
| 843 ? changed_expected |
| 844 : 0, |
| 845 GetTrackedPrefHistogramCount( |
| 846 user_prefs::tracked::kTrackedPrefHistogramChanged, |
| 847 BEGIN_ALLOW_SINGLE_BUCKET + 3)); |
| 816 EXPECT_EQ( | 848 EXPECT_EQ( |
| 817 (protection_level_ > PROTECTION_DISABLED_ON_PLATFORM && | 849 protection_level_ > PROTECTION_DISABLED_ON_PLATFORM |
| 818 protection_level_ < PROTECTION_ENABLED_BASIC) ? changed_expected : 0, | 850 ? num_tracked_prefs() - changed_expected |
| 819 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceChanged", | 851 : 0, |
| 820 BEGIN_ALLOW_SINGLE_BUCKET + 3)); | 852 GetTrackedPrefHistogramCount( |
| 821 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM | 853 user_prefs::tracked::kTrackedPrefHistogramUnchanged, ALLOW_ANY)); |
| 822 ? num_tracked_prefs() - changed_expected : 0, | 854 |
| 855 EXPECT_EQ((protection_level_ > PROTECTION_DISABLED_ON_PLATFORM && |
| 856 protection_level_ < PROTECTION_ENABLED_BASIC) |
| 857 ? 1 |
| 858 : 0, |
| 823 GetTrackedPrefHistogramCount( | 859 GetTrackedPrefHistogramCount( |
| 824 "Settings.TrackedPreferenceUnchanged", ALLOW_ANY)); | 860 user_prefs::tracked::kTrackedPrefHistogramWantedReset, |
| 825 | 861 BEGIN_ALLOW_SINGLE_BUCKET + 3)); |
| 826 EXPECT_EQ( | |
| 827 (protection_level_ > PROTECTION_DISABLED_ON_PLATFORM && | |
| 828 protection_level_ < PROTECTION_ENABLED_BASIC) ? 1 : 0, | |
| 829 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceWantedReset", | |
| 830 BEGIN_ALLOW_SINGLE_BUCKET + 3)); | |
| 831 EXPECT_EQ(0, | 862 EXPECT_EQ(0, |
| 832 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceReset", | 863 GetTrackedPrefHistogramCount( |
| 833 ALLOW_NONE)); | 864 user_prefs::tracked::kTrackedPrefHistogramReset, ALLOW_NONE)); |
| 834 | 865 |
| 835 // Nothing else should have triggered. | 866 // Nothing else should have triggered. |
| 836 EXPECT_EQ(0, | 867 EXPECT_EQ( |
| 837 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceCleared", | 868 0, GetTrackedPrefHistogramCount( |
| 838 ALLOW_NONE)); | 869 user_prefs::tracked::kTrackedPrefHistogramCleared, ALLOW_NONE)); |
| 870 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 871 user_prefs::tracked::kTrackedPrefHistogramInitialized, |
| 872 ALLOW_NONE)); |
| 839 EXPECT_EQ(0, | 873 EXPECT_EQ(0, |
| 840 GetTrackedPrefHistogramCount( | 874 GetTrackedPrefHistogramCount( |
| 841 "Settings.TrackedPreferenceInitialized", ALLOW_NONE)); | 875 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, |
| 842 EXPECT_EQ(0, | 876 ALLOW_NONE)); |
| 843 GetTrackedPrefHistogramCount( | 877 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 844 "Settings.TrackedPreferenceTrustedInitialized", ALLOW_NONE)); | 878 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, |
| 845 EXPECT_EQ(0, | 879 ALLOW_NONE)); |
| 846 GetTrackedPrefHistogramCount( | |
| 847 "Settings.TrackedPreferenceNullInitialized", ALLOW_NONE)); | |
| 848 EXPECT_EQ( | 880 EXPECT_EQ( |
| 849 0, | 881 0, GetTrackedPrefHistogramCount( |
| 850 GetTrackedPrefHistogramCount( | 882 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, |
| 851 "Settings.TrackedPreferenceMigratedLegacyDeviceId", ALLOW_NONE)); | 883 ALLOW_NONE)); |
| 852 } | 884 } |
| 853 }; | 885 }; |
| 854 | 886 |
| 855 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefs, | 887 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefs, |
| 856 UntrustedAdditionToPrefs); | 888 UntrustedAdditionToPrefs); |
| 857 | 889 |
| 858 // Verifies that adding a value to unprotected preferences while wiping a | 890 // Verifies that adding a value to unprotected preferences while wiping a |
| 859 // user-selected value from protected preferences doesn't allow that value to | 891 // user-selected value from protected preferences doesn't allow that value to |
| 860 // slip in with no valid MAC (regression test for http://crbug.com/414554). | 892 // slip in with no valid MAC (regression test for http://crbug.com/414554). |
| 861 class PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe | 893 class PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe |
| (...skipping 17 matching lines...) Expand all Loading... |
| 879 // Expect a single Changed event for tracked pref #2 (kHomePage) if | 911 // Expect a single Changed event for tracked pref #2 (kHomePage) if |
| 880 // not protecting; if protection is enabled the change should be a Cleared. | 912 // not protecting; if protection is enabled the change should be a Cleared. |
| 881 int changed_expected = | 913 int changed_expected = |
| 882 protection_level_ > PROTECTION_DISABLED_ON_PLATFORM && | 914 protection_level_ > PROTECTION_DISABLED_ON_PLATFORM && |
| 883 protection_level_ < PROTECTION_ENABLED_BASIC | 915 protection_level_ < PROTECTION_ENABLED_BASIC |
| 884 ? 1 : 0; | 916 ? 1 : 0; |
| 885 int cleared_expected = | 917 int cleared_expected = |
| 886 protection_level_ >= PROTECTION_ENABLED_BASIC | 918 protection_level_ >= PROTECTION_ENABLED_BASIC |
| 887 ? 1 : 0; | 919 ? 1 : 0; |
| 888 EXPECT_EQ(changed_expected, | 920 EXPECT_EQ(changed_expected, |
| 889 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceChanged", | 921 GetTrackedPrefHistogramCount( |
| 890 BEGIN_ALLOW_SINGLE_BUCKET + 2)); | 922 user_prefs::tracked::kTrackedPrefHistogramChanged, |
| 923 BEGIN_ALLOW_SINGLE_BUCKET + 2)); |
| 891 EXPECT_EQ(cleared_expected, | 924 EXPECT_EQ(cleared_expected, |
| 892 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceCleared", | |
| 893 BEGIN_ALLOW_SINGLE_BUCKET + 2)); | |
| 894 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM | |
| 895 ? num_tracked_prefs() - changed_expected - cleared_expected | |
| 896 : 0, | |
| 897 GetTrackedPrefHistogramCount( | 925 GetTrackedPrefHistogramCount( |
| 898 "Settings.TrackedPreferenceUnchanged", ALLOW_ANY)); | 926 user_prefs::tracked::kTrackedPrefHistogramCleared, |
| 927 BEGIN_ALLOW_SINGLE_BUCKET + 2)); |
| 928 EXPECT_EQ( |
| 929 protection_level_ > PROTECTION_DISABLED_ON_PLATFORM |
| 930 ? num_tracked_prefs() - changed_expected - cleared_expected |
| 931 : 0, |
| 932 GetTrackedPrefHistogramCount( |
| 933 user_prefs::tracked::kTrackedPrefHistogramUnchanged, ALLOW_ANY)); |
| 899 | 934 |
| 900 EXPECT_EQ( | 935 EXPECT_EQ(changed_expected, |
| 901 changed_expected, | 936 GetTrackedPrefHistogramCount( |
| 902 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceWantedReset", | 937 user_prefs::tracked::kTrackedPrefHistogramWantedReset, |
| 903 BEGIN_ALLOW_SINGLE_BUCKET + 2)); | 938 BEGIN_ALLOW_SINGLE_BUCKET + 2)); |
| 904 EXPECT_EQ(0, | 939 EXPECT_EQ(0, |
| 905 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceReset", | 940 GetTrackedPrefHistogramCount( |
| 906 ALLOW_NONE)); | 941 user_prefs::tracked::kTrackedPrefHistogramReset, ALLOW_NONE)); |
| 907 | 942 |
| 908 // Nothing else should have triggered. | 943 // Nothing else should have triggered. |
| 944 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 945 user_prefs::tracked::kTrackedPrefHistogramInitialized, |
| 946 ALLOW_NONE)); |
| 909 EXPECT_EQ(0, | 947 EXPECT_EQ(0, |
| 910 GetTrackedPrefHistogramCount( | 948 GetTrackedPrefHistogramCount( |
| 911 "Settings.TrackedPreferenceInitialized", ALLOW_NONE)); | 949 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, |
| 912 EXPECT_EQ(0, | 950 ALLOW_NONE)); |
| 913 GetTrackedPrefHistogramCount( | 951 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 914 "Settings.TrackedPreferenceTrustedInitialized", ALLOW_NONE)); | 952 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, |
| 915 EXPECT_EQ(0, | 953 ALLOW_NONE)); |
| 916 GetTrackedPrefHistogramCount( | |
| 917 "Settings.TrackedPreferenceNullInitialized", ALLOW_NONE)); | |
| 918 EXPECT_EQ( | 954 EXPECT_EQ( |
| 919 0, | 955 0, GetTrackedPrefHistogramCount( |
| 920 GetTrackedPrefHistogramCount( | 956 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, |
| 921 "Settings.TrackedPreferenceMigratedLegacyDeviceId", ALLOW_NONE)); | 957 ALLOW_NONE)); |
| 922 } | 958 } |
| 923 }; | 959 }; |
| 924 | 960 |
| 925 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe, | 961 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe, |
| 926 UntrustedAdditionToPrefsAfterWipe); | 962 UntrustedAdditionToPrefsAfterWipe); |
| OLD | NEW |