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 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 | 571 |
572 ExtensionServiceInitParams params; | 572 ExtensionServiceInitParams params; |
573 params.profile_path = path; | 573 params.profile_path = path; |
574 params.pref_file = prefs_filename; | 574 params.pref_file = prefs_filename; |
575 params.extensions_install_dir = extensions_install_dir_; | 575 params.extensions_install_dir = extensions_install_dir_; |
576 params.autoupdate_enabled = autoupdate_enabled; | 576 params.autoupdate_enabled = autoupdate_enabled; |
577 params.is_first_run = is_first_run; | 577 params.is_first_run = is_first_run; |
578 InitializeExtensionService(params); | 578 InitializeExtensionService(params); |
579 } | 579 } |
580 | 580 |
581 void ExtensionServiceTestBase::InitializeRequestContext() { | |
582 ASSERT_TRUE(profile_.get()); | |
583 TestingProfile* profile = | |
584 static_cast<TestingProfile*>(profile_.get()); | |
585 profile->CreateRequestContext(); | |
586 } | |
587 | |
588 // static | 581 // static |
589 void ExtensionServiceTestBase::SetUpTestCase() { | 582 void ExtensionServiceTestBase::SetUpTestCase() { |
590 ExtensionErrorReporter::Init(false); // no noisy errors | 583 ExtensionErrorReporter::Init(false); // no noisy errors |
591 } | 584 } |
592 | 585 |
593 void ExtensionServiceTestBase::SetUp() { | 586 void ExtensionServiceTestBase::SetUp() { |
594 ExtensionErrorReporter::GetInstance()->ClearErrors(); | 587 ExtensionErrorReporter::GetInstance()->ClearErrors(); |
595 content::RenderProcessHost::SetRunRendererInProcess(true); | 588 content::RenderProcessHost::SetRunRendererInProcess(true); |
596 } | 589 } |
597 | 590 |
(...skipping 1369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1967 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); | 1960 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); |
1968 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); | 1961 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); |
1969 } | 1962 } |
1970 | 1963 |
1971 | 1964 |
1972 #if !defined(OS_CHROMEOS) | 1965 #if !defined(OS_CHROMEOS) |
1973 // This tests that the granted permissions preferences are correctly set for | 1966 // This tests that the granted permissions preferences are correctly set for |
1974 // default apps. | 1967 // default apps. |
1975 TEST_F(ExtensionServiceTest, DefaultAppsGrantedPermissions) { | 1968 TEST_F(ExtensionServiceTest, DefaultAppsGrantedPermissions) { |
1976 InitializeEmptyExtensionService(); | 1969 InitializeEmptyExtensionService(); |
1977 InitializeRequestContext(); | |
1978 base::FilePath path = data_dir_ | 1970 base::FilePath path = data_dir_ |
1979 .AppendASCII("permissions"); | 1971 .AppendASCII("permissions"); |
1980 | 1972 |
1981 base::FilePath pem_path = path.AppendASCII("unknown.pem"); | 1973 base::FilePath pem_path = path.AppendASCII("unknown.pem"); |
1982 path = path.AppendASCII("unknown"); | 1974 path = path.AppendASCII("unknown"); |
1983 | 1975 |
1984 ASSERT_TRUE(base::PathExists(pem_path)); | 1976 ASSERT_TRUE(base::PathExists(pem_path)); |
1985 ASSERT_TRUE(base::PathExists(path)); | 1977 ASSERT_TRUE(base::PathExists(path)); |
1986 | 1978 |
1987 ExtensionPrefs* prefs = service_->extension_prefs(); | 1979 ExtensionPrefs* prefs = service_->extension_prefs(); |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2600 | 2592 |
2601 ExtensionSorting* sorting = service_->extension_prefs()->extension_sorting(); | 2593 ExtensionSorting* sorting = service_->extension_prefs()->extension_sorting(); |
2602 EXPECT_TRUE( | 2594 EXPECT_TRUE( |
2603 sorting->GetPageOrdinal(extension_misc::kWebStoreAppId).IsValid()); | 2595 sorting->GetPageOrdinal(extension_misc::kWebStoreAppId).IsValid()); |
2604 EXPECT_TRUE( | 2596 EXPECT_TRUE( |
2605 sorting->GetAppLaunchOrdinal(extension_misc::kWebStoreAppId).IsValid()); | 2597 sorting->GetAppLaunchOrdinal(extension_misc::kWebStoreAppId).IsValid()); |
2606 } | 2598 } |
2607 | 2599 |
2608 TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) { | 2600 TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) { |
2609 InitializeEmptyExtensionService(); | 2601 InitializeEmptyExtensionService(); |
2610 InitializeRequestContext(); | |
2611 EXPECT_TRUE(service_->extensions()->is_empty()); | 2602 EXPECT_TRUE(service_->extensions()->is_empty()); |
2612 | 2603 |
2613 int pref_count = 0; | 2604 int pref_count = 0; |
2614 | 2605 |
2615 // Install app1 with unlimited storage. | 2606 // Install app1 with unlimited storage. |
2616 const Extension* extension = | 2607 const Extension* extension = |
2617 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); | 2608 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); |
2618 ValidatePrefKeyCount(++pref_count); | 2609 ValidatePrefKeyCount(++pref_count); |
2619 ASSERT_EQ(1u, service_->extensions()->size()); | 2610 ASSERT_EQ(1u, service_->extensions()->size()); |
2620 const std::string id1 = extension->id(); | 2611 const std::string id1 = extension->id(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2652 | 2643 |
2653 // Uninstall the other, unlimited storage should be revoked. | 2644 // Uninstall the other, unlimited storage should be revoked. |
2654 UninstallExtension(id2, false); | 2645 UninstallExtension(id2, false); |
2655 EXPECT_EQ(0u, service_->extensions()->size()); | 2646 EXPECT_EQ(0u, service_->extensions()->size()); |
2656 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> | 2647 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> |
2657 IsStorageUnlimited(origin2)); | 2648 IsStorageUnlimited(origin2)); |
2658 } | 2649 } |
2659 | 2650 |
2660 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { | 2651 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { |
2661 InitializeEmptyExtensionService(); | 2652 InitializeEmptyExtensionService(); |
2662 InitializeRequestContext(); | |
2663 EXPECT_TRUE(service_->extensions()->is_empty()); | 2653 EXPECT_TRUE(service_->extensions()->is_empty()); |
2664 | 2654 |
2665 int pref_count = 0; | 2655 int pref_count = 0; |
2666 | 2656 |
2667 const Extension* extension = | 2657 const Extension* extension = |
2668 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); | 2658 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); |
2669 ValidatePrefKeyCount(++pref_count); | 2659 ValidatePrefKeyCount(++pref_count); |
2670 ASSERT_EQ(1u, service_->extensions()->size()); | 2660 ASSERT_EQ(1u, service_->extensions()->size()); |
2671 EXPECT_TRUE(extension->is_app()); | 2661 EXPECT_TRUE(extension->is_app()); |
2672 const std::string id1 = extension->id(); | 2662 const std::string id1 = extension->id(); |
(...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3737 EXPECT_TRUE(service_->GetExtensionById(page_action, false)); | 3727 EXPECT_TRUE(service_->GetExtensionById(page_action, false)); |
3738 ExtensionPrefs* prefs = service_->extension_prefs(); | 3728 ExtensionPrefs* prefs = service_->extension_prefs(); |
3739 ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx)); | 3729 ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx)); |
3740 ASSERT_TRUE(prefs->IsExternalExtensionAcknowledged(page_action)); | 3730 ASSERT_TRUE(prefs->IsExternalExtensionAcknowledged(page_action)); |
3741 } | 3731 } |
3742 | 3732 |
3743 #if !defined(OS_CHROMEOS) | 3733 #if !defined(OS_CHROMEOS) |
3744 // This tests if default apps are installed correctly. | 3734 // This tests if default apps are installed correctly. |
3745 TEST_F(ExtensionServiceTest, DefaultAppsInstall) { | 3735 TEST_F(ExtensionServiceTest, DefaultAppsInstall) { |
3746 InitializeEmptyExtensionService(); | 3736 InitializeEmptyExtensionService(); |
3747 InitializeRequestContext(); | |
3748 set_extensions_enabled(true); | 3737 set_extensions_enabled(true); |
3749 | 3738 |
3750 { | 3739 { |
3751 std::string json_data = | 3740 std::string json_data = |
3752 "{" | 3741 "{" |
3753 " \"ldnnhddmnhbkjipkidpdiheffobcpfmf\" : {" | 3742 " \"ldnnhddmnhbkjipkidpdiheffobcpfmf\" : {" |
3754 " \"external_crx\": \"good.crx\"," | 3743 " \"external_crx\": \"good.crx\"," |
3755 " \"external_version\": \"1.0.0.0\"," | 3744 " \"external_version\": \"1.0.0.0\"," |
3756 " \"is_bookmark_app\": false" | 3745 " \"is_bookmark_app\": false" |
3757 " }" | 3746 " }" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3846 service_->set_extensions_enabled(true); | 3835 service_->set_extensions_enabled(true); |
3847 service_->ReloadExtensions(); | 3836 service_->ReloadExtensions(); |
3848 | 3837 |
3849 EXPECT_EQ(1u, service_->extensions()->size()); | 3838 EXPECT_EQ(1u, service_->extensions()->size()); |
3850 EXPECT_EQ(0u, service_->disabled_extensions()->size()); | 3839 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
3851 } | 3840 } |
3852 | 3841 |
3853 // Tests reloading extensions. | 3842 // Tests reloading extensions. |
3854 TEST_F(ExtensionServiceTest, ReloadExtensions) { | 3843 TEST_F(ExtensionServiceTest, ReloadExtensions) { |
3855 InitializeEmptyExtensionService(); | 3844 InitializeEmptyExtensionService(); |
3856 InitializeRequestContext(); | |
3857 | 3845 |
3858 // Simple extension that should install without error. | 3846 // Simple extension that should install without error. |
3859 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 3847 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
3860 InstallCRX(path, INSTALL_NEW, | 3848 InstallCRX(path, INSTALL_NEW, |
3861 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); | 3849 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); |
3862 const char* extension_id = good_crx; | 3850 const char* extension_id = good_crx; |
3863 service_->DisableExtension(extension_id, Extension::DISABLE_USER_ACTION); | 3851 service_->DisableExtension(extension_id, Extension::DISABLE_USER_ACTION); |
3864 | 3852 |
3865 EXPECT_EQ(0u, service_->extensions()->size()); | 3853 EXPECT_EQ(0u, service_->extensions()->size()); |
3866 EXPECT_EQ(1u, service_->disabled_extensions()->size()); | 3854 EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4177 // Check that the LSO file has been removed. | 4165 // Check that the LSO file has been removed. |
4178 EXPECT_FALSE(base::PathExists(lso_file_path)); | 4166 EXPECT_FALSE(base::PathExists(lso_file_path)); |
4179 | 4167 |
4180 // Check if the indexed db has disappeared too. | 4168 // Check if the indexed db has disappeared too. |
4181 EXPECT_FALSE(base::DirectoryExists(idb_path)); | 4169 EXPECT_FALSE(base::DirectoryExists(idb_path)); |
4182 } | 4170 } |
4183 | 4171 |
4184 // Verifies app state is removed upon uninstall. | 4172 // Verifies app state is removed upon uninstall. |
4185 TEST_F(ExtensionServiceTest, ClearAppData) { | 4173 TEST_F(ExtensionServiceTest, ClearAppData) { |
4186 InitializeEmptyExtensionService(); | 4174 InitializeEmptyExtensionService(); |
4187 InitializeRequestContext(); | |
4188 ExtensionCookieCallback callback; | 4175 ExtensionCookieCallback callback; |
4189 | 4176 |
4190 int pref_count = 0; | 4177 int pref_count = 0; |
4191 | 4178 |
4192 // Install app1 with unlimited storage. | 4179 // Install app1 with unlimited storage. |
4193 const Extension* extension = | 4180 const Extension* extension = |
4194 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); | 4181 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); |
4195 ValidatePrefKeyCount(++pref_count); | 4182 ValidatePrefKeyCount(++pref_count); |
4196 ASSERT_EQ(1u, service_->extensions()->size()); | 4183 ASSERT_EQ(1u, service_->extensions()->size()); |
4197 const std::string id1 = extension->id(); | 4184 const std::string id1 = extension->id(); |
(...skipping 1436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5634 | 5621 |
5635 service_->ProcessSyncChanges(FROM_HERE, list); | 5622 service_->ProcessSyncChanges(FROM_HERE, list); |
5636 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); | 5623 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
5637 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); | 5624 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); |
5638 | 5625 |
5639 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); | 5626 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); |
5640 } | 5627 } |
5641 | 5628 |
5642 TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) { | 5629 TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) { |
5643 InitializeExtensionServiceWithUpdater(); | 5630 InitializeExtensionServiceWithUpdater(); |
5644 InitializeRequestContext(); | |
5645 TestSyncProcessorStub processor; | 5631 TestSyncProcessorStub processor; |
5646 service_->MergeDataAndStartSyncing( | 5632 service_->MergeDataAndStartSyncing( |
5647 syncer::EXTENSIONS, syncer::SyncDataList(), | 5633 syncer::EXTENSIONS, syncer::SyncDataList(), |
5648 scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), | 5634 scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
5649 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 5635 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
5650 | 5636 |
5651 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); | 5637 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
5652 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); | 5638 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
5653 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); | 5639 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); |
5654 | 5640 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5702 | 5688 |
5703 service_->ProcessSyncChanges(FROM_HERE, list); | 5689 service_->ProcessSyncChanges(FROM_HERE, list); |
5704 EXPECT_TRUE(service_->updater()->WillCheckSoon()); | 5690 EXPECT_TRUE(service_->updater()->WillCheckSoon()); |
5705 } | 5691 } |
5706 | 5692 |
5707 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); | 5693 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); |
5708 } | 5694 } |
5709 | 5695 |
5710 TEST_F(ExtensionServiceTest, ProcessSyncDataNotInstalled) { | 5696 TEST_F(ExtensionServiceTest, ProcessSyncDataNotInstalled) { |
5711 InitializeExtensionServiceWithUpdater(); | 5697 InitializeExtensionServiceWithUpdater(); |
5712 InitializeRequestContext(); | |
5713 TestSyncProcessorStub processor; | 5698 TestSyncProcessorStub processor; |
5714 service_->MergeDataAndStartSyncing( | 5699 service_->MergeDataAndStartSyncing( |
5715 syncer::EXTENSIONS, syncer::SyncDataList(), | 5700 syncer::EXTENSIONS, syncer::SyncDataList(), |
5716 scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), | 5701 scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
5717 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 5702 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
5718 | 5703 |
5719 sync_pb::EntitySpecifics specifics; | 5704 sync_pb::EntitySpecifics specifics; |
5720 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); | 5705 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
5721 ext_specifics->set_id(good_crx); | 5706 ext_specifics->set_id(good_crx); |
5722 ext_specifics->set_enabled(false); | 5707 ext_specifics->set_enabled(false); |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6347 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); | 6332 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
6348 | 6333 |
6349 service_->CheckForExternalUpdates(); | 6334 service_->CheckForExternalUpdates(); |
6350 content::WindowedNotificationObserver( | 6335 content::WindowedNotificationObserver( |
6351 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 6336 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
6352 content::NotificationService::AllSources()).Wait(); | 6337 content::NotificationService::AllSources()).Wait(); |
6353 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); | 6338 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
6354 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); | 6339 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); |
6355 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); | 6340 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); |
6356 } | 6341 } |
OLD | NEW |