OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/extensions/extensions_service_unittest.h" | 5 #include "chrome/browser/extensions/extensions_service_unittest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
28 #include "chrome/browser/extensions/extension_creator.h" | 28 #include "chrome/browser/extensions/extension_creator.h" |
29 #include "chrome/browser/extensions/extension_error_reporter.h" | 29 #include "chrome/browser/extensions/extension_error_reporter.h" |
30 #include "chrome/browser/extensions/extensions_service.h" | 30 #include "chrome/browser/extensions/extensions_service.h" |
31 #include "chrome/browser/extensions/external_extension_provider.h" | 31 #include "chrome/browser/extensions/external_extension_provider.h" |
32 #include "chrome/browser/extensions/external_pref_extension_provider.h" | 32 #include "chrome/browser/extensions/external_pref_extension_provider.h" |
33 #include "chrome/browser/extensions/pack_extension_job.cc" | 33 #include "chrome/browser/extensions/pack_extension_job.cc" |
34 #include "chrome/browser/in_process_webkit/dom_storage_context.h" | 34 #include "chrome/browser/in_process_webkit/dom_storage_context.h" |
35 #include "chrome/browser/in_process_webkit/webkit_context.h" | 35 #include "chrome/browser/in_process_webkit/webkit_context.h" |
36 #include "chrome/browser/prefs/browser_prefs.h" | 36 #include "chrome/browser/prefs/browser_prefs.h" |
37 #include "chrome/browser/prefs/pref_value_store.h" | 37 #include "chrome/browser/prefs/pref_value_store.h" |
38 #include "chrome/browser/prefs/scoped_pref_update.h" | |
38 #include "chrome/common/chrome_paths.h" | 39 #include "chrome/common/chrome_paths.h" |
39 #include "chrome/common/chrome_switches.h" | 40 #include "chrome/common/chrome_switches.h" |
40 #include "chrome/common/extensions/extension.h" | 41 #include "chrome/common/extensions/extension.h" |
41 #include "chrome/common/extensions/extension_constants.h" | 42 #include "chrome/common/extensions/extension_constants.h" |
42 #include "chrome/common/extensions/extension_resource.h" | 43 #include "chrome/common/extensions/extension_resource.h" |
43 #include "chrome/common/extensions/url_pattern.h" | 44 #include "chrome/common/extensions/url_pattern.h" |
44 #include "chrome/common/json_value_serializer.h" | 45 #include "chrome/common/json_value_serializer.h" |
45 #include "chrome/common/net/url_request_context_getter.h" | 46 #include "chrome/common/net/url_request_context_getter.h" |
46 #include "chrome/common/notification_registrar.h" | 47 #include "chrome/common/notification_registrar.h" |
47 #include "chrome/common/notification_service.h" | 48 #include "chrome/common/notification_service.h" |
(...skipping 2232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2280 EXPECT_NE(std::string(good1), loaded_[0]->id()); | 2281 EXPECT_NE(std::string(good1), loaded_[0]->id()); |
2281 EXPECT_NE(std::string(good1), loaded_[1]->id()); | 2282 EXPECT_NE(std::string(good1), loaded_[1]->id()); |
2282 } | 2283 } |
2283 #endif | 2284 #endif |
2284 | 2285 |
2285 // Will not install extension blacklisted by policy. | 2286 // Will not install extension blacklisted by policy. |
2286 TEST_F(ExtensionsServiceTest, BlacklistedByPolicyWillNotInstall) { | 2287 TEST_F(ExtensionsServiceTest, BlacklistedByPolicyWillNotInstall) { |
2287 InitializeEmptyExtensionsService(); | 2288 InitializeEmptyExtensionsService(); |
2288 | 2289 |
2289 ListValue* whitelist = | 2290 ListValue* whitelist = |
2290 profile_->GetPrefs()->GetMutableList("extensions.install.allowlist"); | 2291 profile_->GetPrefs()->GetMutableList(prefs::kExtensionInstallAllowList); |
2291 ListValue* blacklist = | 2292 ListValue* blacklist = |
2292 profile_->GetPrefs()->GetMutableList("extensions.install.denylist"); | 2293 profile_->GetPrefs()->GetMutableList(prefs::kExtensionInstallDenyList); |
2293 ASSERT_TRUE(whitelist != NULL && blacklist != NULL); | 2294 ASSERT_TRUE(whitelist != NULL && blacklist != NULL); |
2294 | 2295 |
2295 // Blacklist everything. | 2296 // Blacklist everything. |
2296 blacklist->Append(Value::CreateStringValue("*")); | 2297 blacklist->Append(Value::CreateStringValue("*")); |
2297 | 2298 |
2298 // Blacklist prevents us from installing good_crx. | 2299 // Blacklist prevents us from installing good_crx. |
2299 FilePath extensions_path; | 2300 FilePath extensions_path; |
2300 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 2301 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
2301 extensions_path = extensions_path.AppendASCII("extensions"); | 2302 extensions_path = extensions_path.AppendASCII("extensions"); |
2302 FilePath path = extensions_path.AppendASCII("good.crx"); | 2303 FilePath path = extensions_path.AppendASCII("good.crx"); |
(...skipping 16 matching lines...) Expand all Loading... | |
2319 | 2320 |
2320 // Install good_crx. | 2321 // Install good_crx. |
2321 FilePath extensions_path; | 2322 FilePath extensions_path; |
2322 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 2323 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
2323 extensions_path = extensions_path.AppendASCII("extensions"); | 2324 extensions_path = extensions_path.AppendASCII("extensions"); |
2324 FilePath path = extensions_path.AppendASCII("good.crx"); | 2325 FilePath path = extensions_path.AppendASCII("good.crx"); |
2325 service_->InstallExtension(path); | 2326 service_->InstallExtension(path); |
2326 loop_.RunAllPending(); | 2327 loop_.RunAllPending(); |
2327 EXPECT_EQ(1u, service_->extensions()->size()); | 2328 EXPECT_EQ(1u, service_->extensions()->size()); |
2328 | 2329 |
2329 PrefService* prefs = profile_->GetPrefs(); | 2330 { |
battre (please use the other)
2010/12/02 10:41:19
add "// Scope for update notification"?
Mattias Nissler (ping if slow)
2010/12/02 16:38:24
Done.
| |
2330 ListValue* blacklist = | 2331 PrefService* prefs = profile_->GetPrefs(); |
2331 prefs->GetMutableList("extensions.install.denylist"); | 2332 ScopedPrefUpdate pref_update(prefs, prefs::kExtensionInstallDenyList); |
2332 ASSERT_TRUE(blacklist != NULL); | 2333 ListValue* blacklist = |
2334 prefs->GetMutableList(prefs::kExtensionInstallDenyList); | |
2335 ASSERT_TRUE(blacklist != NULL); | |
2333 | 2336 |
2334 // Blacklist this extension. | 2337 // Blacklist this extension. |
2335 blacklist->Append(Value::CreateStringValue(good_crx)); | 2338 blacklist->Append(Value::CreateStringValue(good_crx)); |
2336 prefs->ScheduleSavePersistentPrefs(); | 2339 prefs->ScheduleSavePersistentPrefs(); |
2337 | 2340 } |
2338 // Programmatically appending to the prefs doesn't seem to notify the | |
2339 // observers... :/ | |
2340 prefs->pref_notifier()->FireObservers("extensions.install.denylist"); | |
2341 | 2341 |
2342 // Extension should not be running now. | 2342 // Extension should not be running now. |
2343 loop_.RunAllPending(); | 2343 loop_.RunAllPending(); |
2344 EXPECT_EQ(0u, service_->extensions()->size()); | 2344 EXPECT_EQ(0u, service_->extensions()->size()); |
2345 } | 2345 } |
2346 | 2346 |
2347 // Tests disabling extensions | 2347 // Tests disabling extensions |
2348 TEST_F(ExtensionsServiceTest, DisableExtension) { | 2348 TEST_F(ExtensionsServiceTest, DisableExtension) { |
2349 InitializeEmptyExtensionsService(); | 2349 InitializeEmptyExtensionsService(); |
2350 FilePath extensions_path; | 2350 FilePath extensions_path; |
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3097 // Component extensions shouldn't get recourded in the prefs. | 3097 // Component extensions shouldn't get recourded in the prefs. |
3098 ValidatePrefKeyCount(0); | 3098 ValidatePrefKeyCount(0); |
3099 | 3099 |
3100 // Reload all extensions, and make sure it comes back. | 3100 // Reload all extensions, and make sure it comes back. |
3101 std::string extension_id = service_->extensions()->at(0)->id(); | 3101 std::string extension_id = service_->extensions()->at(0)->id(); |
3102 loaded_.clear(); | 3102 loaded_.clear(); |
3103 service_->ReloadExtensions(); | 3103 service_->ReloadExtensions(); |
3104 ASSERT_EQ(1u, service_->extensions()->size()); | 3104 ASSERT_EQ(1u, service_->extensions()->size()); |
3105 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); | 3105 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); |
3106 } | 3106 } |
OLD | NEW |