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 "extension_prefs_unittest.h" | 5 #include "extension_prefs_unittest.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/prefs/public/pref_change_registrar.h" | 10 #include "base/prefs/public/pref_change_registrar.h" |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 239 |
240 virtual void Verify() { | 240 virtual void Verify() { |
241 EXPECT_TRUE(prefs()->IsExtensionDisabled(extension->id())); | 241 EXPECT_TRUE(prefs()->IsExtensionDisabled(extension->id())); |
242 } | 242 } |
243 | 243 |
244 private: | 244 private: |
245 scoped_refptr<Extension> extension; | 245 scoped_refptr<Extension> extension; |
246 }; | 246 }; |
247 TEST_F(ExtensionPrefsExtensionState, ExtensionState) {} | 247 TEST_F(ExtensionPrefsExtensionState, ExtensionState) {} |
248 | 248 |
249 | |
250 class ExtensionPrefsEscalatePermissions : public ExtensionPrefsTest { | 249 class ExtensionPrefsEscalatePermissions : public ExtensionPrefsTest { |
251 public: | 250 public: |
252 virtual void Initialize() { | 251 virtual void Initialize() { |
253 extension = prefs_.AddExtension("test"); | 252 extension = prefs_.AddExtension("test"); |
254 prefs()->SetDidExtensionEscalatePermissions(extension.get(), true); | 253 prefs()->SetDidExtensionEscalatePermissions(extension.get(), true); |
255 } | 254 } |
256 | 255 |
257 virtual void Verify() { | 256 virtual void Verify() { |
258 EXPECT_TRUE(prefs()->DidExtensionEscalatePermissions(extension->id())); | 257 EXPECT_TRUE(prefs()->DidExtensionEscalatePermissions(extension->id())); |
259 } | 258 } |
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 } else { | 1181 } else { |
1183 EXPECT_EQ(kDefaultPref1, actual); | 1182 EXPECT_EQ(kDefaultPref1, actual); |
1184 } | 1183 } |
1185 } | 1184 } |
1186 | 1185 |
1187 private: | 1186 private: |
1188 int iteration_; | 1187 int iteration_; |
1189 }; | 1188 }; |
1190 TEST_F(ExtensionPrefsDisableExtensions, ExtensionPrefsDisableExtensions) {} | 1189 TEST_F(ExtensionPrefsDisableExtensions, ExtensionPrefsDisableExtensions) {} |
1191 | 1190 |
| 1191 // Tests that blacklist state can be queried. |
| 1192 class ExtensionPrefsBlacklistedExtensions : public ExtensionPrefsTest { |
| 1193 public: |
| 1194 virtual ~ExtensionPrefsBlacklistedExtensions() {} |
| 1195 |
| 1196 virtual void Initialize() OVERRIDE { |
| 1197 extension_a_ = prefs_.AddExtension("a"); |
| 1198 extension_b_ = prefs_.AddExtension("b"); |
| 1199 extension_c_ = prefs_.AddExtension("c"); |
| 1200 } |
| 1201 |
| 1202 virtual void Verify() OVERRIDE { |
| 1203 { |
| 1204 std::set<std::string> ids; |
| 1205 EXPECT_EQ(ids, prefs()->GetBlacklistedExtensions()); |
| 1206 } |
| 1207 prefs()->SetExtensionBlacklisted(extension_a_->id(), true); |
| 1208 { |
| 1209 std::set<std::string> ids; |
| 1210 ids.insert(extension_a_->id()); |
| 1211 EXPECT_EQ(ids, prefs()->GetBlacklistedExtensions()); |
| 1212 } |
| 1213 prefs()->SetExtensionBlacklisted(extension_b_->id(), true); |
| 1214 prefs()->SetExtensionBlacklisted(extension_c_->id(), true); |
| 1215 { |
| 1216 std::set<std::string> ids; |
| 1217 ids.insert(extension_a_->id()); |
| 1218 ids.insert(extension_b_->id()); |
| 1219 ids.insert(extension_c_->id()); |
| 1220 EXPECT_EQ(ids, prefs()->GetBlacklistedExtensions()); |
| 1221 } |
| 1222 prefs()->SetExtensionBlacklisted(extension_a_->id(), false); |
| 1223 { |
| 1224 std::set<std::string> ids; |
| 1225 ids.insert(extension_b_->id()); |
| 1226 ids.insert(extension_c_->id()); |
| 1227 EXPECT_EQ(ids, prefs()->GetBlacklistedExtensions()); |
| 1228 } |
| 1229 prefs()->SetExtensionBlacklisted(extension_b_->id(), false); |
| 1230 prefs()->SetExtensionBlacklisted(extension_c_->id(), false); |
| 1231 { |
| 1232 std::set<std::string> ids; |
| 1233 EXPECT_EQ(ids, prefs()->GetBlacklistedExtensions()); |
| 1234 } |
| 1235 |
| 1236 // The interesting part: make sure that we're cleaning up after ourselves |
| 1237 // when we're storing *just* the fact that the extension is blacklisted. |
| 1238 std::string arbitrary_id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 1239 |
| 1240 prefs()->SetExtensionBlacklisted(arbitrary_id, true); |
| 1241 prefs()->SetExtensionBlacklisted(extension_a_->id(), true); |
| 1242 |
| 1243 // (And make sure that the acknowledged bit is also cleared). |
| 1244 prefs()->AcknowledgeBlacklistedExtension(arbitrary_id); |
| 1245 |
| 1246 EXPECT_TRUE(prefs()->GetExtensionPref(arbitrary_id)); |
| 1247 { |
| 1248 std::set<std::string> ids; |
| 1249 ids.insert(arbitrary_id); |
| 1250 ids.insert(extension_a_->id()); |
| 1251 EXPECT_EQ(ids, prefs()->GetBlacklistedExtensions()); |
| 1252 } |
| 1253 prefs()->SetExtensionBlacklisted(arbitrary_id, false); |
| 1254 prefs()->SetExtensionBlacklisted(extension_a_->id(), false); |
| 1255 EXPECT_FALSE(prefs()->GetExtensionPref(arbitrary_id)); |
| 1256 { |
| 1257 std::set<std::string> ids; |
| 1258 EXPECT_EQ(ids, prefs()->GetBlacklistedExtensions()); |
| 1259 } |
| 1260 } |
| 1261 |
| 1262 private: |
| 1263 scoped_refptr<const Extension> extension_a_; |
| 1264 scoped_refptr<const Extension> extension_b_; |
| 1265 scoped_refptr<const Extension> extension_c_; |
| 1266 }; |
| 1267 TEST_F(ExtensionPrefsBlacklistedExtensions, |
| 1268 ExtensionPrefsBlacklistedExtensions) {} |
| 1269 |
1192 } // namespace extensions | 1270 } // namespace extensions |
OLD | NEW |