| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/extension_service_unittest.h" | 5 #include "chrome/browser/extensions/extension_service_unittest.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 #include "content/public/browser/plugin_service.h" | 86 #include "content/public/browser/plugin_service.h" |
| 87 #include "content/public/browser/render_process_host.h" | 87 #include "content/public/browser/render_process_host.h" |
| 88 #include "content/public/browser/storage_partition.h" | 88 #include "content/public/browser/storage_partition.h" |
| 89 #include "content/public/common/content_constants.h" | 89 #include "content/public/common/content_constants.h" |
| 90 #include "content/public/test/test_utils.h" | 90 #include "content/public/test/test_utils.h" |
| 91 #include "extensions/browser/extension_registry.h" | 91 #include "extensions/browser/extension_registry.h" |
| 92 #include "extensions/browser/external_provider_interface.h" | 92 #include "extensions/browser/external_provider_interface.h" |
| 93 #include "extensions/browser/management_policy.h" | 93 #include "extensions/browser/management_policy.h" |
| 94 #include "extensions/browser/pending_extension_info.h" | 94 #include "extensions/browser/pending_extension_info.h" |
| 95 #include "extensions/browser/pending_extension_manager.h" | 95 #include "extensions/browser/pending_extension_manager.h" |
| 96 #include "extensions/browser/pref_names.h" |
| 96 #include "extensions/browser/test_management_policy.h" | 97 #include "extensions/browser/test_management_policy.h" |
| 97 #include "extensions/common/constants.h" | 98 #include "extensions/common/constants.h" |
| 98 #include "extensions/common/extension.h" | 99 #include "extensions/common/extension.h" |
| 99 #include "extensions/common/extension_builder.h" | 100 #include "extensions/common/extension_builder.h" |
| 100 #include "extensions/common/extension_resource.h" | 101 #include "extensions/common/extension_resource.h" |
| 101 #include "extensions/common/manifest_constants.h" | 102 #include "extensions/common/manifest_constants.h" |
| 102 #include "extensions/common/manifest_handlers/background_info.h" | 103 #include "extensions/common/manifest_handlers/background_info.h" |
| 103 #include "extensions/common/permissions/permission_set.h" | 104 #include "extensions/common/permissions/permission_set.h" |
| 104 #include "extensions/common/url_pattern.h" | 105 #include "extensions/common/url_pattern.h" |
| 105 #include "extensions/common/value_builder.h" | 106 #include "extensions/common/value_builder.h" |
| (...skipping 3360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3466 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 3467 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
| 3467 | 3468 |
| 3468 const Extension* good = InstallCRX(path, INSTALL_NEW); | 3469 const Extension* good = InstallCRX(path, INSTALL_NEW); |
| 3469 EXPECT_EQ(good_crx, good->id()); | 3470 EXPECT_EQ(good_crx, good->id()); |
| 3470 UpdateExtension(good_crx, path, FAILED_SILENTLY); | 3471 UpdateExtension(good_crx, path, FAILED_SILENTLY); |
| 3471 EXPECT_EQ(1u, service_->extensions()->size()); | 3472 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3472 | 3473 |
| 3473 base::ListValue whitelist; | 3474 base::ListValue whitelist; |
| 3474 PrefService* prefs = service_->extension_prefs()->pref_service(); | 3475 PrefService* prefs = service_->extension_prefs()->pref_service(); |
| 3475 whitelist.Append(new base::StringValue(good_crx)); | 3476 whitelist.Append(new base::StringValue(good_crx)); |
| 3476 prefs->Set(prefs::kExtensionInstallAllowList, whitelist); | 3477 prefs->Set(extensions::pref_names::kInstallAllowList, whitelist); |
| 3477 | 3478 |
| 3478 test_blacklist.SetBlacklistState( | 3479 test_blacklist.SetBlacklistState( |
| 3479 good_crx, extensions::BLACKLISTED_MALWARE, true); | 3480 good_crx, extensions::BLACKLISTED_MALWARE, true); |
| 3480 base::RunLoop().RunUntilIdle(); | 3481 base::RunLoop().RunUntilIdle(); |
| 3481 | 3482 |
| 3482 // The good_crx is blacklisted and the whitelist doesn't negate it. | 3483 // The good_crx is blacklisted and the whitelist doesn't negate it. |
| 3483 ASSERT_TRUE(ValidateBooleanPref(good_crx, "blacklist", true)); | 3484 ASSERT_TRUE(ValidateBooleanPref(good_crx, "blacklist", true)); |
| 3484 EXPECT_EQ(0u, service_->extensions()->size()); | 3485 EXPECT_EQ(0u, service_->extensions()->size()); |
| 3485 } | 3486 } |
| 3486 #endif // defined(ENABLE_BLACKLIST_TESTS) | 3487 #endif // defined(ENABLE_BLACKLIST_TESTS) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3551 } | 3552 } |
| 3552 #endif // defined(ENABLE_BLACKLIST_TESTS) | 3553 #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 3553 | 3554 |
| 3554 // Will not install extension blacklisted by policy. | 3555 // Will not install extension blacklisted by policy. |
| 3555 TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { | 3556 TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { |
| 3556 InitializeEmptyExtensionService(); | 3557 InitializeEmptyExtensionService(); |
| 3557 | 3558 |
| 3558 // Blacklist everything. | 3559 // Blacklist everything. |
| 3559 { | 3560 { |
| 3560 ListPrefUpdate update(profile_->GetPrefs(), | 3561 ListPrefUpdate update(profile_->GetPrefs(), |
| 3561 prefs::kExtensionInstallDenyList); | 3562 extensions::pref_names::kInstallDenyList); |
| 3562 base::ListValue* blacklist = update.Get(); | 3563 base::ListValue* blacklist = update.Get(); |
| 3563 blacklist->Append(new base::StringValue("*")); | 3564 blacklist->Append(new base::StringValue("*")); |
| 3564 } | 3565 } |
| 3565 | 3566 |
| 3566 // Blacklist prevents us from installing good_crx. | 3567 // Blacklist prevents us from installing good_crx. |
| 3567 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 3568 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
| 3568 InstallCRX(path, INSTALL_FAILED); | 3569 InstallCRX(path, INSTALL_FAILED); |
| 3569 EXPECT_EQ(0u, service_->extensions()->size()); | 3570 EXPECT_EQ(0u, service_->extensions()->size()); |
| 3570 | 3571 |
| 3571 // Now whitelist this particular extension. | 3572 // Now whitelist this particular extension. |
| 3572 { | 3573 { |
| 3573 ListPrefUpdate update(profile_->GetPrefs(), | 3574 ListPrefUpdate update(profile_->GetPrefs(), |
| 3574 prefs::kExtensionInstallAllowList); | 3575 extensions::pref_names::kInstallAllowList); |
| 3575 base::ListValue* whitelist = update.Get(); | 3576 base::ListValue* whitelist = update.Get(); |
| 3576 whitelist->Append(new base::StringValue(good_crx)); | 3577 whitelist->Append(new base::StringValue(good_crx)); |
| 3577 } | 3578 } |
| 3578 | 3579 |
| 3579 // Ensure we can now install good_crx. | 3580 // Ensure we can now install good_crx. |
| 3580 InstallCRX(path, INSTALL_NEW); | 3581 InstallCRX(path, INSTALL_NEW); |
| 3581 EXPECT_EQ(1u, service_->extensions()->size()); | 3582 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3582 } | 3583 } |
| 3583 | 3584 |
| 3584 // Extension blacklisted by policy get unloaded after installing. | 3585 // Extension blacklisted by policy get unloaded after installing. |
| 3585 TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) { | 3586 TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) { |
| 3586 InitializeEmptyExtensionService(); | 3587 InitializeEmptyExtensionService(); |
| 3587 | 3588 |
| 3588 // Install good_crx. | 3589 // Install good_crx. |
| 3589 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 3590 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
| 3590 InstallCRX(path, INSTALL_NEW); | 3591 InstallCRX(path, INSTALL_NEW); |
| 3591 EXPECT_EQ(1u, service_->extensions()->size()); | 3592 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3592 | 3593 |
| 3593 { // Scope for pref update notification. | 3594 { // Scope for pref update notification. |
| 3594 PrefService* prefs = profile_->GetPrefs(); | 3595 PrefService* prefs = profile_->GetPrefs(); |
| 3595 ListPrefUpdate update(prefs, prefs::kExtensionInstallDenyList); | 3596 ListPrefUpdate update(prefs, extensions::pref_names::kInstallDenyList); |
| 3596 base::ListValue* blacklist = update.Get(); | 3597 base::ListValue* blacklist = update.Get(); |
| 3597 ASSERT_TRUE(blacklist != NULL); | 3598 ASSERT_TRUE(blacklist != NULL); |
| 3598 | 3599 |
| 3599 // Blacklist this extension. | 3600 // Blacklist this extension. |
| 3600 blacklist->Append(new base::StringValue(good_crx)); | 3601 blacklist->Append(new base::StringValue(good_crx)); |
| 3601 } | 3602 } |
| 3602 | 3603 |
| 3603 // Extension should not be running now. | 3604 // Extension should not be running now. |
| 3604 base::RunLoop().RunUntilIdle(); | 3605 base::RunLoop().RunUntilIdle(); |
| 3605 EXPECT_EQ(0u, service_->extensions()->size()); | 3606 EXPECT_EQ(0u, service_->extensions()->size()); |
| 3606 } | 3607 } |
| 3607 | 3608 |
| 3608 // Tests that component extensions are not blacklisted by policy. | 3609 // Tests that component extensions are not blacklisted by policy. |
| 3609 TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) { | 3610 TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) { |
| 3610 InitializeEmptyExtensionService(); | 3611 InitializeEmptyExtensionService(); |
| 3611 | 3612 |
| 3612 // Blacklist everything. | 3613 // Blacklist everything. |
| 3613 { | 3614 { |
| 3614 ListPrefUpdate update(profile_->GetPrefs(), | 3615 ListPrefUpdate update(profile_->GetPrefs(), |
| 3615 prefs::kExtensionInstallDenyList); | 3616 extensions::pref_names::kInstallDenyList); |
| 3616 base::ListValue* blacklist = update.Get(); | 3617 base::ListValue* blacklist = update.Get(); |
| 3617 blacklist->Append(new base::StringValue("*")); | 3618 blacklist->Append(new base::StringValue("*")); |
| 3618 } | 3619 } |
| 3619 | 3620 |
| 3620 // Install a component extension. | 3621 // Install a component extension. |
| 3621 base::FilePath path = data_dir_ | 3622 base::FilePath path = data_dir_ |
| 3622 .AppendASCII("good") | 3623 .AppendASCII("good") |
| 3623 .AppendASCII("Extensions") | 3624 .AppendASCII("Extensions") |
| 3624 .AppendASCII(good0) | 3625 .AppendASCII(good0) |
| 3625 .AppendASCII("1.0.0.0"); | 3626 .AppendASCII("1.0.0.0"); |
| 3626 std::string manifest; | 3627 std::string manifest; |
| 3627 ASSERT_TRUE(base::ReadFileToString( | 3628 ASSERT_TRUE(base::ReadFileToString( |
| 3628 path.Append(extensions::kManifestFilename), &manifest)); | 3629 path.Append(extensions::kManifestFilename), &manifest)); |
| 3629 service_->component_loader()->Add(manifest, path); | 3630 service_->component_loader()->Add(manifest, path); |
| 3630 service_->Init(); | 3631 service_->Init(); |
| 3631 | 3632 |
| 3632 // Extension should be installed despite blacklist. | 3633 // Extension should be installed despite blacklist. |
| 3633 ASSERT_EQ(1u, service_->extensions()->size()); | 3634 ASSERT_EQ(1u, service_->extensions()->size()); |
| 3634 EXPECT_TRUE(service_->GetExtensionById(good0, false)); | 3635 EXPECT_TRUE(service_->GetExtensionById(good0, false)); |
| 3635 | 3636 |
| 3636 // Poke external providers and make sure the extension is still present. | 3637 // Poke external providers and make sure the extension is still present. |
| 3637 service_->CheckForExternalUpdates(); | 3638 service_->CheckForExternalUpdates(); |
| 3638 ASSERT_EQ(1u, service_->extensions()->size()); | 3639 ASSERT_EQ(1u, service_->extensions()->size()); |
| 3639 EXPECT_TRUE(service_->GetExtensionById(good0, false)); | 3640 EXPECT_TRUE(service_->GetExtensionById(good0, false)); |
| 3640 | 3641 |
| 3641 // Extension should not be uninstalled on blacklist changes. | 3642 // Extension should not be uninstalled on blacklist changes. |
| 3642 { | 3643 { |
| 3643 ListPrefUpdate update(profile_->GetPrefs(), | 3644 ListPrefUpdate update(profile_->GetPrefs(), |
| 3644 prefs::kExtensionInstallDenyList); | 3645 extensions::pref_names::kInstallDenyList); |
| 3645 base::ListValue* blacklist = update.Get(); | 3646 base::ListValue* blacklist = update.Get(); |
| 3646 blacklist->Append(new base::StringValue(good0)); | 3647 blacklist->Append(new base::StringValue(good0)); |
| 3647 } | 3648 } |
| 3648 base::RunLoop().RunUntilIdle(); | 3649 base::RunLoop().RunUntilIdle(); |
| 3649 ASSERT_EQ(1u, service_->extensions()->size()); | 3650 ASSERT_EQ(1u, service_->extensions()->size()); |
| 3650 EXPECT_TRUE(service_->GetExtensionById(good0, false)); | 3651 EXPECT_TRUE(service_->GetExtensionById(good0, false)); |
| 3651 } | 3652 } |
| 3652 | 3653 |
| 3653 // Tests that policy-installed extensions are not blacklisted by policy. | 3654 // Tests that policy-installed extensions are not blacklisted by policy. |
| 3654 TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) { | 3655 TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) { |
| 3655 InitializeEmptyExtensionService(); | 3656 InitializeEmptyExtensionService(); |
| 3656 | 3657 |
| 3657 { | 3658 { |
| 3658 // Blacklist everything. | 3659 // Blacklist everything. |
| 3659 ListPrefUpdate blacklist_update(profile_->GetPrefs(), | 3660 ListPrefUpdate blacklist_update( |
| 3660 prefs::kExtensionInstallDenyList); | 3661 profile_->GetPrefs(), extensions::pref_names::kInstallDenyList); |
| 3661 base::ListValue* blacklist = blacklist_update.Get(); | 3662 base::ListValue* blacklist = blacklist_update.Get(); |
| 3662 blacklist->AppendString("*"); | 3663 blacklist->AppendString("*"); |
| 3663 | 3664 |
| 3664 // Mark good.crx for force-installation. | 3665 // Mark good.crx for force-installation. |
| 3665 DictionaryPrefUpdate forcelist_update(profile_->GetPrefs(), | 3666 DictionaryPrefUpdate forcelist_update( |
| 3666 prefs::kExtensionInstallForceList); | 3667 profile_->GetPrefs(), |
| 3668 extensions::pref_names::kInstallForceList); |
| 3667 extensions::ExternalPolicyLoader::AddExtension( | 3669 extensions::ExternalPolicyLoader::AddExtension( |
| 3668 forcelist_update.Get(), good_crx, "http://example.com/update_url"); | 3670 forcelist_update.Get(), good_crx, "http://example.com/update_url"); |
| 3669 } | 3671 } |
| 3670 | 3672 |
| 3671 // Have policy force-install an extension. | 3673 // Have policy force-install an extension. |
| 3672 MockExtensionProvider* provider = | 3674 MockExtensionProvider* provider = |
| 3673 new MockExtensionProvider(service_, | 3675 new MockExtensionProvider(service_, |
| 3674 Manifest::EXTERNAL_POLICY_DOWNLOAD); | 3676 Manifest::EXTERNAL_POLICY_DOWNLOAD); |
| 3675 AddMockExternalProvider(provider); | 3677 AddMockExternalProvider(provider); |
| 3676 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", | 3678 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| 3677 data_dir_.AppendASCII("good.crx")); | 3679 data_dir_.AppendASCII("good.crx")); |
| 3678 | 3680 |
| 3679 // Reloading extensions should find our externally registered extension | 3681 // Reloading extensions should find our externally registered extension |
| 3680 // and install it. | 3682 // and install it. |
| 3681 content::WindowedNotificationObserver observer( | 3683 content::WindowedNotificationObserver observer( |
| 3682 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 3684 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 3683 content::NotificationService::AllSources()); | 3685 content::NotificationService::AllSources()); |
| 3684 service_->CheckForExternalUpdates(); | 3686 service_->CheckForExternalUpdates(); |
| 3685 observer.Wait(); | 3687 observer.Wait(); |
| 3686 | 3688 |
| 3687 // Extension should be installed despite blacklist. | 3689 // Extension should be installed despite blacklist. |
| 3688 ASSERT_EQ(1u, service_->extensions()->size()); | 3690 ASSERT_EQ(1u, service_->extensions()->size()); |
| 3689 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); | 3691 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 3690 | 3692 |
| 3691 // Blacklist update should not uninstall the extension. | 3693 // Blacklist update should not uninstall the extension. |
| 3692 { | 3694 { |
| 3693 ListPrefUpdate update(profile_->GetPrefs(), | 3695 ListPrefUpdate update(profile_->GetPrefs(), |
| 3694 prefs::kExtensionInstallDenyList); | 3696 extensions::pref_names::kInstallDenyList); |
| 3695 base::ListValue* blacklist = update.Get(); | 3697 base::ListValue* blacklist = update.Get(); |
| 3696 blacklist->Append(new base::StringValue(good0)); | 3698 blacklist->Append(new base::StringValue(good0)); |
| 3697 } | 3699 } |
| 3698 base::RunLoop().RunUntilIdle(); | 3700 base::RunLoop().RunUntilIdle(); |
| 3699 ASSERT_EQ(1u, service_->extensions()->size()); | 3701 ASSERT_EQ(1u, service_->extensions()->size()); |
| 3700 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); | 3702 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 3701 } | 3703 } |
| 3702 | 3704 |
| 3703 // Tests that extensions cannot be installed if the policy provider prohibits | 3705 // Tests that extensions cannot be installed if the policy provider prohibits |
| 3704 // it. This functionality is implemented in CrxInstaller::ConfirmInstall(). | 3706 // it. This functionality is implemented in CrxInstaller::ConfirmInstall(). |
| (...skipping 3083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6788 // ReconcileKnownDisabled(). | 6790 // ReconcileKnownDisabled(). |
| 6789 service_->EnableExtension(good2); | 6791 service_->EnableExtension(good2); |
| 6790 service_->ReconcileKnownDisabled(); | 6792 service_->ReconcileKnownDisabled(); |
| 6791 expected_extensions.insert(good2); | 6793 expected_extensions.insert(good2); |
| 6792 expected_disabled_extensions.erase(good2); | 6794 expected_disabled_extensions.erase(good2); |
| 6793 | 6795 |
| 6794 EXPECT_EQ(expected_extensions, service_->extensions()->GetIDs()); | 6796 EXPECT_EQ(expected_extensions, service_->extensions()->GetIDs()); |
| 6795 EXPECT_EQ(expected_disabled_extensions, | 6797 EXPECT_EQ(expected_disabled_extensions, |
| 6796 service_->disabled_extensions()->GetIDs()); | 6798 service_->disabled_extensions()->GetIDs()); |
| 6797 } | 6799 } |
| OLD | NEW |