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 2321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2369 EXPECT_NE(std::string(good1), loaded_[0]->id()); | 2370 EXPECT_NE(std::string(good1), loaded_[0]->id()); |
2370 EXPECT_NE(std::string(good1), loaded_[1]->id()); | 2371 EXPECT_NE(std::string(good1), loaded_[1]->id()); |
2371 } | 2372 } |
2372 #endif | 2373 #endif |
2373 | 2374 |
2374 // Will not install extension blacklisted by policy. | 2375 // Will not install extension blacklisted by policy. |
2375 TEST_F(ExtensionsServiceTest, BlacklistedByPolicyWillNotInstall) { | 2376 TEST_F(ExtensionsServiceTest, BlacklistedByPolicyWillNotInstall) { |
2376 InitializeEmptyExtensionsService(); | 2377 InitializeEmptyExtensionsService(); |
2377 | 2378 |
2378 ListValue* whitelist = | 2379 ListValue* whitelist = |
2379 profile_->GetPrefs()->GetMutableList("extensions.install.allowlist"); | 2380 profile_->GetPrefs()->GetMutableList(prefs::kExtensionInstallAllowList); |
2380 ListValue* blacklist = | 2381 ListValue* blacklist = |
2381 profile_->GetPrefs()->GetMutableList("extensions.install.denylist"); | 2382 profile_->GetPrefs()->GetMutableList(prefs::kExtensionInstallDenyList); |
2382 ASSERT_TRUE(whitelist != NULL && blacklist != NULL); | 2383 ASSERT_TRUE(whitelist != NULL && blacklist != NULL); |
2383 | 2384 |
2384 // Blacklist everything. | 2385 // Blacklist everything. |
2385 blacklist->Append(Value::CreateStringValue("*")); | 2386 blacklist->Append(Value::CreateStringValue("*")); |
2386 | 2387 |
2387 // Blacklist prevents us from installing good_crx. | 2388 // Blacklist prevents us from installing good_crx. |
2388 FilePath extensions_path; | 2389 FilePath extensions_path; |
2389 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 2390 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
2390 extensions_path = extensions_path.AppendASCII("extensions"); | 2391 extensions_path = extensions_path.AppendASCII("extensions"); |
2391 FilePath path = extensions_path.AppendASCII("good.crx"); | 2392 FilePath path = extensions_path.AppendASCII("good.crx"); |
(...skipping 16 matching lines...) Expand all Loading... |
2408 | 2409 |
2409 // Install good_crx. | 2410 // Install good_crx. |
2410 FilePath extensions_path; | 2411 FilePath extensions_path; |
2411 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 2412 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
2412 extensions_path = extensions_path.AppendASCII("extensions"); | 2413 extensions_path = extensions_path.AppendASCII("extensions"); |
2413 FilePath path = extensions_path.AppendASCII("good.crx"); | 2414 FilePath path = extensions_path.AppendASCII("good.crx"); |
2414 service_->InstallExtension(path); | 2415 service_->InstallExtension(path); |
2415 loop_.RunAllPending(); | 2416 loop_.RunAllPending(); |
2416 EXPECT_EQ(1u, service_->extensions()->size()); | 2417 EXPECT_EQ(1u, service_->extensions()->size()); |
2417 | 2418 |
2418 PrefService* prefs = profile_->GetPrefs(); | 2419 { // Scope for pref update notification. |
2419 ListValue* blacklist = | 2420 PrefService* prefs = profile_->GetPrefs(); |
2420 prefs->GetMutableList("extensions.install.denylist"); | 2421 ScopedPrefUpdate pref_update(prefs, prefs::kExtensionInstallDenyList); |
2421 ASSERT_TRUE(blacklist != NULL); | 2422 ListValue* blacklist = |
| 2423 prefs->GetMutableList(prefs::kExtensionInstallDenyList); |
| 2424 ASSERT_TRUE(blacklist != NULL); |
2422 | 2425 |
2423 // Blacklist this extension. | 2426 // Blacklist this extension. |
2424 blacklist->Append(Value::CreateStringValue(good_crx)); | 2427 blacklist->Append(Value::CreateStringValue(good_crx)); |
2425 prefs->ScheduleSavePersistentPrefs(); | 2428 prefs->ScheduleSavePersistentPrefs(); |
2426 | 2429 } |
2427 // Programmatically appending to the prefs doesn't seem to notify the | |
2428 // observers... :/ | |
2429 prefs->pref_notifier()->FireObservers("extensions.install.denylist"); | |
2430 | 2430 |
2431 // Extension should not be running now. | 2431 // Extension should not be running now. |
2432 loop_.RunAllPending(); | 2432 loop_.RunAllPending(); |
2433 EXPECT_EQ(0u, service_->extensions()->size()); | 2433 EXPECT_EQ(0u, service_->extensions()->size()); |
2434 } | 2434 } |
2435 | 2435 |
2436 // Tests disabling extensions | 2436 // Tests disabling extensions |
2437 TEST_F(ExtensionsServiceTest, DisableExtension) { | 2437 TEST_F(ExtensionsServiceTest, DisableExtension) { |
2438 InitializeEmptyExtensionsService(); | 2438 InitializeEmptyExtensionsService(); |
2439 FilePath extensions_path; | 2439 FilePath extensions_path; |
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3176 // Component extensions shouldn't get recourded in the prefs. | 3176 // Component extensions shouldn't get recourded in the prefs. |
3177 ValidatePrefKeyCount(0); | 3177 ValidatePrefKeyCount(0); |
3178 | 3178 |
3179 // Reload all extensions, and make sure it comes back. | 3179 // Reload all extensions, and make sure it comes back. |
3180 std::string extension_id = service_->extensions()->at(0)->id(); | 3180 std::string extension_id = service_->extensions()->at(0)->id(); |
3181 loaded_.clear(); | 3181 loaded_.clear(); |
3182 service_->ReloadExtensions(); | 3182 service_->ReloadExtensions(); |
3183 ASSERT_EQ(1u, service_->extensions()->size()); | 3183 ASSERT_EQ(1u, service_->extensions()->size()); |
3184 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); | 3184 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); |
3185 } | 3185 } |
OLD | NEW |