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 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 | 564 |
565 ExtensionServiceInitParams params; | 565 ExtensionServiceInitParams params; |
566 params.profile_path = path; | 566 params.profile_path = path; |
567 params.pref_file = prefs_filename; | 567 params.pref_file = prefs_filename; |
568 params.extensions_install_dir = extensions_install_dir_; | 568 params.extensions_install_dir = extensions_install_dir_; |
569 params.autoupdate_enabled = autoupdate_enabled; | 569 params.autoupdate_enabled = autoupdate_enabled; |
570 params.is_first_run = is_first_run; | 570 params.is_first_run = is_first_run; |
571 InitializeExtensionService(params); | 571 InitializeExtensionService(params); |
572 } | 572 } |
573 | 573 |
574 void ExtensionServiceTestBase::InitializeRequestContext() { | |
575 ASSERT_TRUE(profile_.get()); | |
576 TestingProfile* profile = | |
577 static_cast<TestingProfile*>(profile_.get()); | |
578 profile->CreateRequestContext(); | |
579 } | |
580 | |
581 // static | 574 // static |
582 void ExtensionServiceTestBase::SetUpTestCase() { | 575 void ExtensionServiceTestBase::SetUpTestCase() { |
583 ExtensionErrorReporter::Init(false); // no noisy errors | 576 ExtensionErrorReporter::Init(false); // no noisy errors |
584 } | 577 } |
585 | 578 |
586 void ExtensionServiceTestBase::SetUp() { | 579 void ExtensionServiceTestBase::SetUp() { |
587 ExtensionErrorReporter::GetInstance()->ClearErrors(); | 580 ExtensionErrorReporter::GetInstance()->ClearErrors(); |
588 content::RenderProcessHost::SetRunRendererInProcess(true); | 581 content::RenderProcessHost::SetRunRendererInProcess(true); |
589 } | 582 } |
590 | 583 |
(...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1886 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); | 1879 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); |
1887 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); | 1880 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); |
1888 } | 1881 } |
1889 | 1882 |
1890 | 1883 |
1891 #if !defined(OS_CHROMEOS) | 1884 #if !defined(OS_CHROMEOS) |
1892 // This tests that the granted permissions preferences are correctly set for | 1885 // This tests that the granted permissions preferences are correctly set for |
1893 // default apps. | 1886 // default apps. |
1894 TEST_F(ExtensionServiceTest, DefaultAppsGrantedPermissions) { | 1887 TEST_F(ExtensionServiceTest, DefaultAppsGrantedPermissions) { |
1895 InitializeEmptyExtensionService(); | 1888 InitializeEmptyExtensionService(); |
1896 InitializeRequestContext(); | |
1897 base::FilePath path = data_dir_ | 1889 base::FilePath path = data_dir_ |
1898 .AppendASCII("permissions"); | 1890 .AppendASCII("permissions"); |
1899 | 1891 |
1900 base::FilePath pem_path = path.AppendASCII("unknown.pem"); | 1892 base::FilePath pem_path = path.AppendASCII("unknown.pem"); |
1901 path = path.AppendASCII("unknown"); | 1893 path = path.AppendASCII("unknown"); |
1902 | 1894 |
1903 ASSERT_TRUE(base::PathExists(pem_path)); | 1895 ASSERT_TRUE(base::PathExists(pem_path)); |
1904 ASSERT_TRUE(base::PathExists(path)); | 1896 ASSERT_TRUE(base::PathExists(path)); |
1905 | 1897 |
1906 ExtensionPrefs* prefs = service_->extension_prefs(); | 1898 ExtensionPrefs* prefs = service_->extension_prefs(); |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2519 | 2511 |
2520 ExtensionSorting* sorting = service_->extension_prefs()->extension_sorting(); | 2512 ExtensionSorting* sorting = service_->extension_prefs()->extension_sorting(); |
2521 EXPECT_TRUE( | 2513 EXPECT_TRUE( |
2522 sorting->GetPageOrdinal(extension_misc::kWebStoreAppId).IsValid()); | 2514 sorting->GetPageOrdinal(extension_misc::kWebStoreAppId).IsValid()); |
2523 EXPECT_TRUE( | 2515 EXPECT_TRUE( |
2524 sorting->GetAppLaunchOrdinal(extension_misc::kWebStoreAppId).IsValid()); | 2516 sorting->GetAppLaunchOrdinal(extension_misc::kWebStoreAppId).IsValid()); |
2525 } | 2517 } |
2526 | 2518 |
2527 TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) { | 2519 TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) { |
2528 InitializeEmptyExtensionService(); | 2520 InitializeEmptyExtensionService(); |
2529 InitializeRequestContext(); | |
2530 EXPECT_TRUE(service_->extensions()->is_empty()); | 2521 EXPECT_TRUE(service_->extensions()->is_empty()); |
2531 | 2522 |
2532 int pref_count = 0; | 2523 int pref_count = 0; |
2533 | 2524 |
2534 // Install app1 with unlimited storage. | 2525 // Install app1 with unlimited storage. |
2535 const Extension* extension = | 2526 const Extension* extension = |
2536 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); | 2527 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); |
2537 ValidatePrefKeyCount(++pref_count); | 2528 ValidatePrefKeyCount(++pref_count); |
2538 ASSERT_EQ(1u, service_->extensions()->size()); | 2529 ASSERT_EQ(1u, service_->extensions()->size()); |
2539 const std::string id1 = extension->id(); | 2530 const std::string id1 = extension->id(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2571 | 2562 |
2572 // Uninstall the other, unlimited storage should be revoked. | 2563 // Uninstall the other, unlimited storage should be revoked. |
2573 UninstallExtension(id2, false); | 2564 UninstallExtension(id2, false); |
2574 EXPECT_EQ(0u, service_->extensions()->size()); | 2565 EXPECT_EQ(0u, service_->extensions()->size()); |
2575 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> | 2566 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> |
2576 IsStorageUnlimited(origin2)); | 2567 IsStorageUnlimited(origin2)); |
2577 } | 2568 } |
2578 | 2569 |
2579 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { | 2570 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { |
2580 InitializeEmptyExtensionService(); | 2571 InitializeEmptyExtensionService(); |
2581 InitializeRequestContext(); | |
2582 EXPECT_TRUE(service_->extensions()->is_empty()); | 2572 EXPECT_TRUE(service_->extensions()->is_empty()); |
2583 | 2573 |
2584 int pref_count = 0; | 2574 int pref_count = 0; |
2585 | 2575 |
2586 const Extension* extension = | 2576 const Extension* extension = |
2587 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); | 2577 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); |
2588 ValidatePrefKeyCount(++pref_count); | 2578 ValidatePrefKeyCount(++pref_count); |
2589 ASSERT_EQ(1u, service_->extensions()->size()); | 2579 ASSERT_EQ(1u, service_->extensions()->size()); |
2590 EXPECT_TRUE(extension->is_app()); | 2580 EXPECT_TRUE(extension->is_app()); |
2591 const std::string id1 = extension->id(); | 2581 const std::string id1 = extension->id(); |
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3654 EXPECT_TRUE(service_->GetExtensionById(page_action, false)); | 3644 EXPECT_TRUE(service_->GetExtensionById(page_action, false)); |
3655 ExtensionPrefs* prefs = service_->extension_prefs(); | 3645 ExtensionPrefs* prefs = service_->extension_prefs(); |
3656 ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx)); | 3646 ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx)); |
3657 ASSERT_TRUE(prefs->IsExternalExtensionAcknowledged(page_action)); | 3647 ASSERT_TRUE(prefs->IsExternalExtensionAcknowledged(page_action)); |
3658 } | 3648 } |
3659 | 3649 |
3660 #if !defined(OS_CHROMEOS) | 3650 #if !defined(OS_CHROMEOS) |
3661 // This tests if default apps are installed correctly. | 3651 // This tests if default apps are installed correctly. |
3662 TEST_F(ExtensionServiceTest, DefaultAppsInstall) { | 3652 TEST_F(ExtensionServiceTest, DefaultAppsInstall) { |
3663 InitializeEmptyExtensionService(); | 3653 InitializeEmptyExtensionService(); |
3664 InitializeRequestContext(); | |
3665 set_extensions_enabled(true); | 3654 set_extensions_enabled(true); |
3666 | 3655 |
3667 { | 3656 { |
3668 std::string json_data = | 3657 std::string json_data = |
3669 "{" | 3658 "{" |
3670 " \"ldnnhddmnhbkjipkidpdiheffobcpfmf\" : {" | 3659 " \"ldnnhddmnhbkjipkidpdiheffobcpfmf\" : {" |
3671 " \"external_crx\": \"good.crx\"," | 3660 " \"external_crx\": \"good.crx\"," |
3672 " \"external_version\": \"1.0.0.0\"," | 3661 " \"external_version\": \"1.0.0.0\"," |
3673 " \"is_bookmark_app\": false" | 3662 " \"is_bookmark_app\": false" |
3674 " }" | 3663 " }" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3763 service_->set_extensions_enabled(true); | 3752 service_->set_extensions_enabled(true); |
3764 service_->ReloadExtensions(); | 3753 service_->ReloadExtensions(); |
3765 | 3754 |
3766 EXPECT_EQ(1u, service_->extensions()->size()); | 3755 EXPECT_EQ(1u, service_->extensions()->size()); |
3767 EXPECT_EQ(0u, service_->disabled_extensions()->size()); | 3756 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
3768 } | 3757 } |
3769 | 3758 |
3770 // Tests reloading extensions. | 3759 // Tests reloading extensions. |
3771 TEST_F(ExtensionServiceTest, ReloadExtensions) { | 3760 TEST_F(ExtensionServiceTest, ReloadExtensions) { |
3772 InitializeEmptyExtensionService(); | 3761 InitializeEmptyExtensionService(); |
3773 InitializeRequestContext(); | |
3774 | 3762 |
3775 // Simple extension that should install without error. | 3763 // Simple extension that should install without error. |
3776 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 3764 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
3777 InstallCRX(path, INSTALL_NEW, | 3765 InstallCRX(path, INSTALL_NEW, |
3778 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); | 3766 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); |
3779 const char* extension_id = good_crx; | 3767 const char* extension_id = good_crx; |
3780 service_->DisableExtension(extension_id, Extension::DISABLE_USER_ACTION); | 3768 service_->DisableExtension(extension_id, Extension::DISABLE_USER_ACTION); |
3781 | 3769 |
3782 EXPECT_EQ(0u, service_->extensions()->size()); | 3770 EXPECT_EQ(0u, service_->extensions()->size()); |
3783 EXPECT_EQ(1u, service_->disabled_extensions()->size()); | 3771 EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4094 // Check that the LSO file has been removed. | 4082 // Check that the LSO file has been removed. |
4095 EXPECT_FALSE(base::PathExists(lso_file_path)); | 4083 EXPECT_FALSE(base::PathExists(lso_file_path)); |
4096 | 4084 |
4097 // Check if the indexed db has disappeared too. | 4085 // Check if the indexed db has disappeared too. |
4098 EXPECT_FALSE(file_util::DirectoryExists(idb_path)); | 4086 EXPECT_FALSE(file_util::DirectoryExists(idb_path)); |
4099 } | 4087 } |
4100 | 4088 |
4101 // Verifies app state is removed upon uninstall. | 4089 // Verifies app state is removed upon uninstall. |
4102 TEST_F(ExtensionServiceTest, ClearAppData) { | 4090 TEST_F(ExtensionServiceTest, ClearAppData) { |
4103 InitializeEmptyExtensionService(); | 4091 InitializeEmptyExtensionService(); |
4104 InitializeRequestContext(); | |
4105 ExtensionCookieCallback callback; | 4092 ExtensionCookieCallback callback; |
4106 | 4093 |
4107 int pref_count = 0; | 4094 int pref_count = 0; |
4108 | 4095 |
4109 // Install app1 with unlimited storage. | 4096 // Install app1 with unlimited storage. |
4110 const Extension* extension = | 4097 const Extension* extension = |
4111 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); | 4098 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); |
4112 ValidatePrefKeyCount(++pref_count); | 4099 ValidatePrefKeyCount(++pref_count); |
4113 ASSERT_EQ(1u, service_->extensions()->size()); | 4100 ASSERT_EQ(1u, service_->extensions()->size()); |
4114 const std::string id1 = extension->id(); | 4101 const std::string id1 = extension->id(); |
(...skipping 1444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5559 | 5546 |
5560 service_->ProcessSyncChanges(FROM_HERE, list); | 5547 service_->ProcessSyncChanges(FROM_HERE, list); |
5561 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); | 5548 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
5562 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); | 5549 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); |
5563 | 5550 |
5564 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); | 5551 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); |
5565 } | 5552 } |
5566 | 5553 |
5567 TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) { | 5554 TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) { |
5568 InitializeExtensionServiceWithUpdater(); | 5555 InitializeExtensionServiceWithUpdater(); |
5569 InitializeRequestContext(); | |
5570 TestSyncProcessorStub processor; | 5556 TestSyncProcessorStub processor; |
5571 service_->MergeDataAndStartSyncing( | 5557 service_->MergeDataAndStartSyncing( |
5572 syncer::EXTENSIONS, syncer::SyncDataList(), | 5558 syncer::EXTENSIONS, syncer::SyncDataList(), |
5573 scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), | 5559 scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
5574 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 5560 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
5575 | 5561 |
5576 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); | 5562 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
5577 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); | 5563 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
5578 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); | 5564 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); |
5579 | 5565 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5627 | 5613 |
5628 service_->ProcessSyncChanges(FROM_HERE, list); | 5614 service_->ProcessSyncChanges(FROM_HERE, list); |
5629 EXPECT_TRUE(service_->updater()->WillCheckSoon()); | 5615 EXPECT_TRUE(service_->updater()->WillCheckSoon()); |
5630 } | 5616 } |
5631 | 5617 |
5632 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); | 5618 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); |
5633 } | 5619 } |
5634 | 5620 |
5635 TEST_F(ExtensionServiceTest, ProcessSyncDataNotInstalled) { | 5621 TEST_F(ExtensionServiceTest, ProcessSyncDataNotInstalled) { |
5636 InitializeExtensionServiceWithUpdater(); | 5622 InitializeExtensionServiceWithUpdater(); |
5637 InitializeRequestContext(); | |
5638 TestSyncProcessorStub processor; | 5623 TestSyncProcessorStub processor; |
5639 service_->MergeDataAndStartSyncing( | 5624 service_->MergeDataAndStartSyncing( |
5640 syncer::EXTENSIONS, syncer::SyncDataList(), | 5625 syncer::EXTENSIONS, syncer::SyncDataList(), |
5641 scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), | 5626 scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
5642 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 5627 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
5643 | 5628 |
5644 sync_pb::EntitySpecifics specifics; | 5629 sync_pb::EntitySpecifics specifics; |
5645 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); | 5630 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
5646 ext_specifics->set_id(good_crx); | 5631 ext_specifics->set_id(good_crx); |
5647 ext_specifics->set_enabled(false); | 5632 ext_specifics->set_enabled(false); |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6272 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); | 6257 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
6273 | 6258 |
6274 service_->CheckForExternalUpdates(); | 6259 service_->CheckForExternalUpdates(); |
6275 content::WindowedNotificationObserver( | 6260 content::WindowedNotificationObserver( |
6276 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 6261 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
6277 content::NotificationService::AllSources()).Wait(); | 6262 content::NotificationService::AllSources()).Wait(); |
6278 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); | 6263 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
6279 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); | 6264 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); |
6280 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); | 6265 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); |
6281 } | 6266 } |
OLD | NEW |