diff options
author | ivankr@chromium.org <ivankr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-28 18:08:08 +0000 |
---|---|---|
committer | ivankr@chromium.org <ivankr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-28 18:08:08 +0000 |
commit | 35a6fd1817d0c50fa40545c45711623627133954 (patch) | |
tree | 4f93dab72015393442f24035ef49eab522feee43 /chrome/browser/protector/protected_prefs_watcher_unittest.cc | |
parent | b07ad6c679a2a9adee38fa6225ac33f94a1c266b (diff) | |
download | chromium_src-35a6fd1817d0c50fa40545c45711623627133954.zip chromium_src-35a6fd1817d0c50fa40545c45711623627133954.tar.gz chromium_src-35a6fd1817d0c50fa40545c45711623627133954.tar.bz2 |
[protector] Specific handling of default values of protected prefs.
BUG=124194
TEST=ProtectedPrefsWatcherTest.*
Review URL: https://chromiumcodereview.appspot.com/10399125
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139252 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/protector/protected_prefs_watcher_unittest.cc')
-rw-r--r-- | chrome/browser/protector/protected_prefs_watcher_unittest.cc | 81 |
1 files changed, 76 insertions, 5 deletions
diff --git a/chrome/browser/protector/protected_prefs_watcher_unittest.cc b/chrome/browser/protector/protected_prefs_watcher_unittest.cc index bf7f1fa..7ce50a0 100644 --- a/chrome/browser/protector/protected_prefs_watcher_unittest.cc +++ b/chrome/browser/protector/protected_prefs_watcher_unittest.cc @@ -48,8 +48,8 @@ class ProtectedPrefsWatcherTest : public testing::Test { prefs_watcher_->ValidateBackup(); } - void ForceUpdateSignature() { - prefs_watcher_->UpdateBackupSignature(); + void ForceUpdateSignature(ProtectedPrefsWatcher* prefs_watcher) { + prefs_watcher->UpdateBackupSignature(); } protected: @@ -174,7 +174,7 @@ TEST_F(ProtectedPrefsWatcherTest, MigrationToVersion2) { // Store the old signature (without "pinned_tabs"). prefs_->ClearPref("backup._version"); prefs_->ClearPref("backup.pinned_tabs"); - ForceUpdateSignature(); + ForceUpdateSignature(prefs_watcher_); EXPECT_TRUE(IsSignatureValid()); // This will migrate backup to the latest version. @@ -196,12 +196,12 @@ TEST_F(ProtectedPrefsWatcherTest, MigrationToVersion3) { // Bring startup prefs to an old (pre-migration) version. prefs_->SetBoolean(prefs::kHomePageIsNewTabPage, false); - prefs_->SetString(prefs::kHomePage, "http://example.com/"); + prefs_->SetString(prefs::kHomePage, kNewHomePage); prefs_->ClearPref(prefs::kRestoreOnStartupMigrated); // Reset version to 2 and overwrite the signature. prefs_->SetInteger("backup._version", 2); - ForceUpdateSignature(); + ForceUpdateSignature(prefs_watcher_); EXPECT_TRUE(IsSignatureValid()); // Take down the old instance and create a new ProtectedPrefsWatcher from @@ -219,4 +219,75 @@ TEST_F(ProtectedPrefsWatcherTest, MigrationToVersion3) { prefs_->GetInteger("backup._version")); } +// Verify that migration to version 4 removes backups with default values. +TEST_F(ProtectedPrefsWatcherTest, MigrationToVersion4) { + EXPECT_TRUE(prefs_watcher_->is_backup_valid()); + + prefs_->SetString(prefs::kHomePage, kNewHomePage); + EXPECT_TRUE(prefs_->HasPrefPath("backup.homepage")); + + // Reset version to 3 and overwrite the signature. + prefs_->SetInteger("backup._version", 3); + ForceUpdateSignature(prefs_watcher_); + EXPECT_TRUE(IsSignatureValid()); + + ProtectorServiceFactory::GetForProfile(&profile_)-> + StopWatchingPrefsForTesting(); + + // Restore |kHomePage| to default value. + prefs_->ClearPref(prefs::kHomePage); + + scoped_ptr<ProtectedPrefsWatcher> prefs_watcher2( + new ProtectedPrefsWatcher(&profile_)); + EXPECT_TRUE(prefs_watcher2->is_backup_valid()); + + // Backup for |kHomePage| should now be restored to the default value, too. + EXPECT_FALSE(prefs_->HasPrefPath("backup.homepage")); + EXPECT_FALSE(prefs_watcher2->DidPrefChange(prefs::kHomePage)); + EXPECT_EQ(ProtectedPrefsWatcher::kCurrentVersionNumber, + prefs_->GetInteger("backup._version")); +} + +// Verify handling of default values of protected prefs. +TEST_F(ProtectedPrefsWatcherTest, DefaultValues) { + EXPECT_TRUE(prefs_watcher_->is_backup_valid()); + + EXPECT_FALSE(prefs_->HasPrefPath(prefs::kHomePage)); + EXPECT_FALSE(prefs_watcher_->DidPrefChange(prefs::kHomePage)); + prefs_->SetString(prefs::kHomePage, kNewHomePage); + EXPECT_FALSE(prefs_watcher_->DidPrefChange(prefs::kHomePage)); + + ProtectorServiceFactory::GetForProfile(&profile_)-> + StopWatchingPrefsForTesting(); + + // Restore |kHomePage| to default value. + prefs_->ClearPref(prefs::kHomePage); + + scoped_ptr<ProtectedPrefsWatcher> prefs_watcher2( + new ProtectedPrefsWatcher(&profile_)); + EXPECT_TRUE(prefs_watcher2->is_backup_valid()); + EXPECT_TRUE(prefs_watcher2->DidPrefChange(prefs::kHomePage)); + + prefs_->ClearPref("backup.homepage"); + ForceUpdateSignature(prefs_watcher2.get()); + + EXPECT_TRUE(prefs_watcher2->is_backup_valid()); + EXPECT_FALSE(prefs_watcher2->DidPrefChange(prefs::kHomePage)); +} + +TEST_F(ProtectedPrefsWatcherTest, CheckPrefNames) { + // If any of these preference names change, add corresponding migration code + // to ProtectedPrefsWatcher. + // DO NOT simply fix these literals! + EXPECT_EQ("homepage", std::string(prefs::kHomePage)); + EXPECT_EQ("homepage_is_newtabpage", + std::string(prefs::kHomePageIsNewTabPage)); + EXPECT_EQ("browser.show_home_button", std::string(prefs::kShowHomeButton)); + EXPECT_EQ("session.restore_on_startup", + std::string(prefs::kRestoreOnStartup)); + EXPECT_EQ("session.urls_to_restore_on_startup", + std::string(prefs::kURLsToRestoreOnStartup)); + EXPECT_EQ("pinned_tabs", std::string(prefs::kPinnedTabs)); +} + } // namespace protector |