OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/values.h" | 6 #include "base/values.h" |
7 #include "chrome/browser/extensions/extension_pref_value_map.h" | 7 #include "chrome/browser/extensions/extension_pref_value_map.h" |
8 #include "chrome/browser/extensions/extension_prefs.h" | 8 #include "chrome/browser/extensions/extension_prefs.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 } | 46 } |
47 | 47 |
48 protected: | 48 protected: |
49 ProtectedPrefsWatcher* prefs_watcher_; | 49 ProtectedPrefsWatcher* prefs_watcher_; |
50 TestingProfile profile_; | 50 TestingProfile profile_; |
51 PrefService* prefs_; | 51 PrefService* prefs_; |
52 }; | 52 }; |
53 | 53 |
54 TEST_F(ProtectedPrefsWatcherTest, ValidOnCleanProfile) { | 54 TEST_F(ProtectedPrefsWatcherTest, ValidOnCleanProfile) { |
55 EXPECT_TRUE(HasBackup()); | 55 EXPECT_TRUE(HasBackup()); |
56 EXPECT_TRUE(IsSignatureValid()); | |
57 EXPECT_TRUE(prefs_watcher_->is_backup_valid()); | 56 EXPECT_TRUE(prefs_watcher_->is_backup_valid()); |
58 } | 57 } |
59 | 58 |
60 TEST_F(ProtectedPrefsWatcherTest, ValidAfterPrefChange) { | 59 TEST_F(ProtectedPrefsWatcherTest, ValidAfterPrefChange) { |
61 // Signature is still valid after a protected pref has been changed. | 60 // Signature is still valid after a protected pref has been changed. |
62 base::StringValue new_homepage(kNewHomePage); | 61 base::StringValue new_homepage(kNewHomePage); |
63 EXPECT_NE(prefs_->GetString(prefs::kHomePage), kNewHomePage); | 62 EXPECT_NE(prefs_->GetString(prefs::kHomePage), kNewHomePage); |
64 EXPECT_FALSE(new_homepage.Equals( | 63 EXPECT_FALSE(new_homepage.Equals( |
65 prefs_watcher_->GetBackupForPref(prefs::kHomePage))); | 64 prefs_watcher_->GetBackupForPref(prefs::kHomePage))); |
66 | 65 |
67 prefs_->SetString(prefs::kHomePage, kNewHomePage); | 66 prefs_->SetString(prefs::kHomePage, kNewHomePage); |
68 | 67 |
69 EXPECT_TRUE(HasBackup()); | 68 EXPECT_TRUE(HasBackup()); |
70 EXPECT_TRUE(IsSignatureValid()); | |
71 EXPECT_TRUE(prefs_watcher_->is_backup_valid()); | 69 EXPECT_TRUE(prefs_watcher_->is_backup_valid()); |
72 EXPECT_EQ(prefs_->GetString(prefs::kHomePage), kNewHomePage); | 70 EXPECT_EQ(prefs_->GetString(prefs::kHomePage), kNewHomePage); |
73 // Backup is updated accordingly. | 71 // Backup is updated accordingly. |
74 EXPECT_TRUE(new_homepage.Equals( | 72 EXPECT_TRUE(new_homepage.Equals( |
75 prefs_watcher_->GetBackupForPref(prefs::kHomePage))); | 73 prefs_watcher_->GetBackupForPref(prefs::kHomePage))); |
76 } | 74 } |
77 | 75 |
78 TEST_F(ProtectedPrefsWatcherTest, InvalidSignature) { | 76 TEST_F(ProtectedPrefsWatcherTest, InvalidSignature) { |
79 // Make backup invalid by changing one of its members directly. | 77 // Make backup invalid by changing one of its members directly. |
80 prefs_->SetString("backup.homepage", kNewHomePage); | 78 prefs_->SetString("backup.homepage", kNewHomePage); |
81 RevalidateBackup(); | 79 RevalidateBackup(); |
82 EXPECT_TRUE(HasBackup()); | 80 EXPECT_TRUE(HasBackup()); |
83 EXPECT_FALSE(IsSignatureValid()); | |
84 EXPECT_FALSE(prefs_watcher_->is_backup_valid()); | 81 EXPECT_FALSE(prefs_watcher_->is_backup_valid()); |
85 // No backup values available. | 82 // No backup values available. |
86 EXPECT_FALSE(prefs_watcher_->GetBackupForPref(prefs::kHomePage)); | 83 EXPECT_FALSE(prefs_watcher_->GetBackupForPref(prefs::kHomePage)); |
87 | 84 |
88 // Now change the corresponding protected prefernce: backup should be signed | 85 // Now change the corresponding protected prefernce: backup should be signed |
89 // again but still invalid. | 86 // again but still invalid. |
90 prefs_->SetString(prefs::kHomePage, kNewHomePage); | 87 prefs_->SetString(prefs::kHomePage, kNewHomePage); |
91 EXPECT_TRUE(IsSignatureValid()); | 88 EXPECT_TRUE(IsSignatureValid()); |
92 EXPECT_FALSE(prefs_watcher_->is_backup_valid()); | 89 EXPECT_FALSE(prefs_watcher_->is_backup_valid()); |
93 EXPECT_FALSE(prefs_watcher_->GetBackupForPref(prefs::kHomePage)); | 90 EXPECT_FALSE(prefs_watcher_->GetBackupForPref(prefs::kHomePage)); |
(...skipping 14 matching lines...) Expand all Loading... |
108 new ExtensionPrefs(profile_.GetPrefs(), | 105 new ExtensionPrefs(profile_.GetPrefs(), |
109 extensions_install_dir, | 106 extensions_install_dir, |
110 extension_pref_value_map_.get())); | 107 extension_pref_value_map_.get())); |
111 std::string sample_id = extension_misc::kWebStoreAppId; | 108 std::string sample_id = extension_misc::kWebStoreAppId; |
112 extension_prefs->Init(false); | 109 extension_prefs->Init(false); |
113 // Flip a pref value of an extension (this will actually add it to the list). | 110 // Flip a pref value of an extension (this will actually add it to the list). |
114 extension_prefs->SetAppNotificationDisabled( | 111 extension_prefs->SetAppNotificationDisabled( |
115 sample_id, !extension_prefs->IsAppNotificationDisabled(sample_id)); | 112 sample_id, !extension_prefs->IsAppNotificationDisabled(sample_id)); |
116 | 113 |
117 // Backup is still valid. | 114 // Backup is still valid. |
118 EXPECT_TRUE(IsSignatureValid()); | |
119 EXPECT_TRUE(prefs_watcher_->is_backup_valid()); | 115 EXPECT_TRUE(prefs_watcher_->is_backup_valid()); |
120 | 116 |
121 // Make backup invalid by changing one of its members directly. | 117 // Make signature invalid by changing it directly. |
122 prefs_->SetString("backup.homepage", kNewHomePage); | 118 prefs_->SetString("backup._signature", "INVALID"); |
123 RevalidateBackup(); | |
124 EXPECT_FALSE(IsSignatureValid()); | 119 EXPECT_FALSE(IsSignatureValid()); |
125 | 120 |
126 // Flip another pref value of that extension. | 121 // Flip another pref value of that extension. |
127 extension_prefs->SetIsIncognitoEnabled( | 122 extension_prefs->SetIsIncognitoEnabled( |
128 sample_id, !extension_prefs->IsIncognitoEnabled(sample_id)); | 123 sample_id, !extension_prefs->IsIncognitoEnabled(sample_id)); |
129 | 124 |
130 // No changes to the backup and signature. | 125 // No changes to the backup and signature. |
131 EXPECT_FALSE(IsSignatureValid()); | 126 EXPECT_FALSE(IsSignatureValid()); |
132 | 127 |
133 // Blacklisting the extension does update the backup and signature. | 128 // Blacklisting the extension does update the backup and signature. |
134 std::set<std::string> blacklist; | 129 std::set<std::string> blacklist; |
135 blacklist.insert(sample_id); | 130 blacklist.insert(sample_id); |
136 extension_prefs->UpdateBlacklist(blacklist); | 131 extension_prefs->UpdateBlacklist(blacklist); |
137 | 132 |
138 EXPECT_TRUE(IsSignatureValid()); | 133 EXPECT_TRUE(IsSignatureValid()); |
139 } | 134 } |
140 | 135 |
141 } // namespace protector | 136 } // namespace protector |
OLD | NEW |