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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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
5 #include "base/values.h"
6 #include "chrome/browser/prefs/pref_service.h"
7 #include "chrome/browser/protector/protected_prefs_watcher.h"
8 #include "chrome/browser/protector/protector_service.h"
9 #include "chrome/browser/protector/protector_service_factory.h"
10 #include "chrome/common/pref_names.h"
11 #include "chrome/test/base/testing_profile.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace protector {
15
16 namespace {
17
18 const char kNewHomePage[] = "http://example.com";
19
20 }
21
22 class ProtectedPrefsWatcherTest : public testing::Test {
23 public:
24 virtual void SetUp() OVERRIDE {
25 prefs_watcher_ =
26 ProtectorServiceFactory::GetForProfile(&profile_)->prefs_watcher_.get();
27 prefs_ = profile_.GetPrefs();
28 }
29
30 protected:
31 ProtectedPrefsWatcher* prefs_watcher_;
32 TestingProfile profile_;
33 PrefService* prefs_;
34 };
35
36 TEST_F(ProtectedPrefsWatcherTest, ValidOnCleanProfile) {
37 EXPECT_TRUE(prefs_watcher_->HasBackup());
38 EXPECT_TRUE(prefs_watcher_->IsSignatureValid());
39 }
40
41 TEST_F(ProtectedPrefsWatcherTest, ValidAfterPrefChange) {
42 // Signature is still valid after a protected pref has been changed.
43 base::StringValue new_homepage(kNewHomePage);
44 EXPECT_NE(prefs_->GetString(prefs::kHomePage), kNewHomePage);
45 EXPECT_FALSE(new_homepage.Equals(
46 prefs_watcher_->GetBackupForPref(prefs::kHomePage)));
47
48 profile_.GetPrefs()->SetString(prefs::kHomePage, kNewHomePage);
49
50 EXPECT_TRUE(prefs_watcher_->HasBackup());
51 EXPECT_TRUE(prefs_watcher_->IsSignatureValid());
52 EXPECT_EQ(prefs_->GetString(prefs::kHomePage), kNewHomePage);
53 // Backup is updated accordingly.
54 EXPECT_TRUE(new_homepage.Equals(
55 prefs_watcher_->GetBackupForPref(prefs::kHomePage)));
56 }
57
58 TEST_F(ProtectedPrefsWatcherTest, NoBackupForUnknownPref) {
59 // Returns NULL for prefs that are not protected.
60 EXPECT_FALSE(prefs_watcher_->GetBackupForPref(prefs::kDefaultApps));
61 }
62
63 TEST_F(ProtectedPrefsWatcherTest, InvalidSignature) {
64 // Invalidate backup by changing one of its members directly.
65 prefs_->SetString("backup.homepage", kNewHomePage);
66 EXPECT_TRUE(prefs_watcher_->HasBackup());
67 EXPECT_FALSE(prefs_watcher_->IsSignatureValid());
68 }
69
70 } // namespace protector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698