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

Unified Diff: chrome/browser/protector/protected_prefs_watcher_unittest.cc

Issue 9620010: Added Protector backup for Preferences. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments, removed blacklist from extension ID list, added unittest. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/protector/protected_prefs_watcher_unittest.cc
diff --git a/chrome/browser/protector/protected_prefs_watcher_unittest.cc b/chrome/browser/protector/protected_prefs_watcher_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..da36f81dd116a87722b05a2bf9a9046fbd1ea104
--- /dev/null
+++ b/chrome/browser/protector/protected_prefs_watcher_unittest.cc
@@ -0,0 +1,70 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/values.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/protector/protected_prefs_watcher.h"
+#include "chrome/browser/protector/protector_service.h"
+#include "chrome/browser/protector/protector_service_factory.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/test/base/testing_profile.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace protector {
+
+namespace {
+
+const char kNewHomePage[] = "http://example.com";
+
+}
+
+class ProtectedPrefsWatcherTest : public testing::Test {
+ public:
+ virtual void SetUp() OVERRIDE {
+ prefs_watcher_ =
+ ProtectorServiceFactory::GetForProfile(&profile_)->prefs_watcher_.get();
+ prefs_ = profile_.GetPrefs();
+ }
+
+ protected:
+ ProtectedPrefsWatcher* prefs_watcher_;
+ TestingProfile profile_;
+ PrefService* prefs_;
+};
+
+TEST_F(ProtectedPrefsWatcherTest, ValidOnCleanProfile) {
+ EXPECT_TRUE(prefs_watcher_->HasBackup());
+ EXPECT_TRUE(prefs_watcher_->IsSignatureValid());
+}
+
+TEST_F(ProtectedPrefsWatcherTest, ValidAfterPrefChange) {
+ // Signature is still valid after a protected pref has been changed.
+ base::StringValue new_homepage(kNewHomePage);
+ EXPECT_NE(prefs_->GetString(prefs::kHomePage), kNewHomePage);
+ EXPECT_FALSE(new_homepage.Equals(
+ prefs_watcher_->GetBackupForPref(prefs::kHomePage)));
+
+ profile_.GetPrefs()->SetString(prefs::kHomePage, kNewHomePage);
+
+ EXPECT_TRUE(prefs_watcher_->HasBackup());
+ EXPECT_TRUE(prefs_watcher_->IsSignatureValid());
+ EXPECT_EQ(prefs_->GetString(prefs::kHomePage), kNewHomePage);
+ // Backup is updated accordingly.
+ EXPECT_TRUE(new_homepage.Equals(
+ prefs_watcher_->GetBackupForPref(prefs::kHomePage)));
+}
+
+TEST_F(ProtectedPrefsWatcherTest, NoBackupForUnknownPref) {
+ // Returns NULL for prefs that are not protected.
+ EXPECT_FALSE(prefs_watcher_->GetBackupForPref(prefs::kDefaultApps));
+}
+
+TEST_F(ProtectedPrefsWatcherTest, InvalidSignature) {
+ // Invalidate backup by changing one of its members directly.
+ prefs_->SetString("backup.homepage", kNewHomePage);
+ EXPECT_TRUE(prefs_watcher_->HasBackup());
+ EXPECT_FALSE(prefs_watcher_->IsSignatureValid());
+}
+
+} // namespace protector

Powered by Google App Engine
This is Rietveld 408576698