| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 const base::FilePath::StringType& name) { | 665 const base::FilePath::StringType& name) { |
| 666 base::FilePath extension_path(ui_test_utils::GetTestFilePath( | 666 base::FilePath extension_path(ui_test_utils::GetTestFilePath( |
| 667 base::FilePath(kTestExtensionsDir), base::FilePath(name))); | 667 base::FilePath(kTestExtensionsDir), base::FilePath(name))); |
| 668 scoped_refptr<extensions::CrxInstaller> installer = | 668 scoped_refptr<extensions::CrxInstaller> installer = |
| 669 extensions::CrxInstaller::CreateSilent(extension_service()); | 669 extensions::CrxInstaller::CreateSilent(extension_service()); |
| 670 installer->set_allow_silent_install(true); | 670 installer->set_allow_silent_install(true); |
| 671 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); | 671 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); |
| 672 installer->set_creation_flags(extensions::Extension::FROM_WEBSTORE); | 672 installer->set_creation_flags(extensions::Extension::FROM_WEBSTORE); |
| 673 | 673 |
| 674 content::WindowedNotificationObserver observer( | 674 content::WindowedNotificationObserver observer( |
| 675 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 675 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
| 676 content::NotificationService::AllSources()); | 676 content::NotificationService::AllSources()); |
| 677 installer->InstallCrx(extension_path); | 677 installer->InstallCrx(extension_path); |
| 678 observer.Wait(); | 678 observer.Wait(); |
| 679 content::Details<const extensions::Extension> details = observer.details(); | 679 content::Details<const extensions::Extension> details = observer.details(); |
| 680 return details.ptr(); | 680 return details.ptr(); |
| 681 } | 681 } |
| 682 | 682 |
| 683 const extensions::Extension* LoadUnpackedExtension( | 683 const extensions::Extension* LoadUnpackedExtension( |
| 684 const base::FilePath::StringType& name, bool expect_success) { | 684 const base::FilePath::StringType& name, bool expect_success) { |
| 685 base::FilePath extension_path(ui_test_utils::GetTestFilePath( | 685 base::FilePath extension_path(ui_test_utils::GetTestFilePath( |
| 686 base::FilePath(kTestExtensionsDir), base::FilePath(name))); | 686 base::FilePath(kTestExtensionsDir), base::FilePath(name))); |
| 687 scoped_refptr<extensions::UnpackedInstaller> installer = | 687 scoped_refptr<extensions::UnpackedInstaller> installer = |
| 688 extensions::UnpackedInstaller::Create(extension_service()); | 688 extensions::UnpackedInstaller::Create(extension_service()); |
| 689 content::WindowedNotificationObserver observer( | 689 content::WindowedNotificationObserver observer( |
| 690 expect_success ? chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED | 690 expect_success ? extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED |
| 691 : chrome::NOTIFICATION_EXTENSION_LOAD_ERROR, | 691 : extensions::NOTIFICATION_EXTENSION_LOAD_ERROR, |
| 692 content::NotificationService::AllSources()); | 692 content::NotificationService::AllSources()); |
| 693 installer->Load(extension_path); | 693 installer->Load(extension_path); |
| 694 observer.Wait(); | 694 observer.Wait(); |
| 695 | 695 |
| 696 const extensions::ExtensionSet* extensions = | 696 const extensions::ExtensionSet* extensions = |
| 697 extension_service()->extensions(); | 697 extension_service()->extensions(); |
| 698 for (extensions::ExtensionSet::const_iterator it = extensions->begin(); | 698 for (extensions::ExtensionSet::const_iterator it = extensions->begin(); |
| 699 it != extensions->end(); ++it) { | 699 it != extensions->end(); ++it) { |
| 700 if ((*it)->path() == extension_path) | 700 if ((*it)->path() == extension_path) |
| 701 return it->get(); | 701 return it->get(); |
| 702 } | 702 } |
| 703 return NULL; | 703 return NULL; |
| 704 } | 704 } |
| 705 | 705 |
| 706 void UninstallExtension(const std::string& id, bool expect_success) { | 706 void UninstallExtension(const std::string& id, bool expect_success) { |
| 707 content::WindowedNotificationObserver observer( | 707 content::WindowedNotificationObserver observer( |
| 708 expect_success ? chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED | 708 expect_success |
| 709 : chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, | 709 ? extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED |
| 710 : extensions::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, |
| 710 content::NotificationService::AllSources()); | 711 content::NotificationService::AllSources()); |
| 711 extension_service()->UninstallExtension( | 712 extension_service()->UninstallExtension( |
| 712 id, | 713 id, |
| 713 extensions::UNINSTALL_REASON_FOR_TESTING, | 714 extensions::UNINSTALL_REASON_FOR_TESTING, |
| 714 base::Bind(&base::DoNothing), | 715 base::Bind(&base::DoNothing), |
| 715 NULL); | 716 NULL); |
| 716 observer.Wait(); | 717 observer.Wait(); |
| 717 } | 718 } |
| 718 | 719 |
| 719 void UpdateProviderPolicy(const PolicyMap& policy) { | 720 void UpdateProviderPolicy(const PolicyMap& policy) { |
| (...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1614 GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); | 1615 GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); |
| 1615 | 1616 |
| 1616 // Setting the forcelist extension should install "good_v1.crx". | 1617 // Setting the forcelist extension should install "good_v1.crx". |
| 1617 base::ListValue forcelist; | 1618 base::ListValue forcelist; |
| 1618 forcelist.Append(new base::StringValue( | 1619 forcelist.Append(new base::StringValue( |
| 1619 base::StringPrintf("%s;%s", kGoodCrxId, url.spec().c_str()))); | 1620 base::StringPrintf("%s;%s", kGoodCrxId, url.spec().c_str()))); |
| 1620 PolicyMap policies; | 1621 PolicyMap policies; |
| 1621 policies.Set(key::kExtensionInstallForcelist, POLICY_LEVEL_MANDATORY, | 1622 policies.Set(key::kExtensionInstallForcelist, POLICY_LEVEL_MANDATORY, |
| 1622 POLICY_SCOPE_USER, forcelist.DeepCopy(), NULL); | 1623 POLICY_SCOPE_USER, forcelist.DeepCopy(), NULL); |
| 1623 content::WindowedNotificationObserver observer( | 1624 content::WindowedNotificationObserver observer( |
| 1624 chrome::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, | 1625 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, |
| 1625 content::NotificationService::AllSources()); | 1626 content::NotificationService::AllSources()); |
| 1626 UpdateProviderPolicy(policies); | 1627 UpdateProviderPolicy(policies); |
| 1627 observer.Wait(); | 1628 observer.Wait(); |
| 1628 // Note: Cannot check that the notification details match the expected | 1629 // Note: Cannot check that the notification details match the expected |
| 1629 // exception, since the details object has already been freed prior to | 1630 // exception, since the details object has already been freed prior to |
| 1630 // the completion of observer.Wait(). | 1631 // the completion of observer.Wait(). |
| 1631 | 1632 |
| 1632 EXPECT_TRUE(service->GetExtensionById(kGoodCrxId, true)); | 1633 EXPECT_TRUE(service->GetExtensionById(kGoodCrxId, true)); |
| 1633 | 1634 |
| 1634 // The user is not allowed to uninstall force-installed extensions. | 1635 // The user is not allowed to uninstall force-installed extensions. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1652 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | 1653 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| 1653 interceptor.PushJobCallback( | 1654 interceptor.PushJobCallback( |
| 1654 TestRequestInterceptor::FileJob( | 1655 TestRequestInterceptor::FileJob( |
| 1655 test_path.Append(kTestExtensionsDir).Append(kGood2CrxManifestName))); | 1656 test_path.Append(kTestExtensionsDir).Append(kGood2CrxManifestName))); |
| 1656 | 1657 |
| 1657 // Updating the force-installed extension. | 1658 // Updating the force-installed extension. |
| 1658 extensions::ExtensionUpdater* updater = service->updater(); | 1659 extensions::ExtensionUpdater* updater = service->updater(); |
| 1659 extensions::ExtensionUpdater::CheckParams params; | 1660 extensions::ExtensionUpdater::CheckParams params; |
| 1660 params.install_immediately = true; | 1661 params.install_immediately = true; |
| 1661 content::WindowedNotificationObserver update_observer( | 1662 content::WindowedNotificationObserver update_observer( |
| 1662 chrome::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, | 1663 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, |
| 1663 content::NotificationService::AllSources()); | 1664 content::NotificationService::AllSources()); |
| 1664 updater->CheckNow(params); | 1665 updater->CheckNow(params); |
| 1665 update_observer.Wait(); | 1666 update_observer.Wait(); |
| 1666 | 1667 |
| 1667 const base::Version* new_version = | 1668 const base::Version* new_version = |
| 1668 service->GetExtensionById(kGoodCrxId, true)->version(); | 1669 service->GetExtensionById(kGoodCrxId, true)->version(); |
| 1669 ASSERT_TRUE(new_version->IsValid()); | 1670 ASSERT_TRUE(new_version->IsValid()); |
| 1670 base::Version old_version(old_version_number); | 1671 base::Version old_version(old_version_number); |
| 1671 ASSERT_TRUE(old_version.IsValid()); | 1672 ASSERT_TRUE(old_version.IsValid()); |
| 1672 | 1673 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1695 // processes. | 1696 // processes. |
| 1696 all_views = manager->GetAllViews(); | 1697 all_views = manager->GetAllViews(); |
| 1697 iter = all_views.begin(); | 1698 iter = all_views.begin(); |
| 1698 } | 1699 } |
| 1699 } | 1700 } |
| 1700 | 1701 |
| 1701 // Test policy-installed extensions are reloaded when killed. | 1702 // Test policy-installed extensions are reloaded when killed. |
| 1702 BackgroundContentsService:: | 1703 BackgroundContentsService:: |
| 1703 SetRestartDelayForForceInstalledAppsAndExtensionsForTesting(0); | 1704 SetRestartDelayForForceInstalledAppsAndExtensionsForTesting(0); |
| 1704 content::WindowedNotificationObserver extension_crashed_observer( | 1705 content::WindowedNotificationObserver extension_crashed_observer( |
| 1705 chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, | 1706 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
| 1706 content::NotificationService::AllSources()); | 1707 content::NotificationService::AllSources()); |
| 1707 content::WindowedNotificationObserver extension_loaded_observer( | 1708 content::WindowedNotificationObserver extension_loaded_observer( |
| 1708 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 1709 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 1709 content::NotificationService::AllSources()); | 1710 content::NotificationService::AllSources()); |
| 1710 extensions::ExtensionHost* extension_host = | 1711 extensions::ExtensionHost* extension_host = |
| 1711 extensions::ExtensionSystem::Get(browser()->profile())-> | 1712 extensions::ExtensionSystem::Get(browser()->profile())-> |
| 1712 process_manager()->GetBackgroundHostForExtension(kGoodCrxId); | 1713 process_manager()->GetBackgroundHostForExtension(kGoodCrxId); |
| 1713 base::KillProcess(extension_host->render_process_host()->GetHandle(), | 1714 base::KillProcess(extension_host->render_process_host()->GetHandle(), |
| 1714 content::RESULT_CODE_KILLED, false); | 1715 content::RESULT_CODE_KILLED, false); |
| 1715 extension_crashed_observer.Wait(); | 1716 extension_crashed_observer.Wait(); |
| 1716 extension_loaded_observer.Wait(); | 1717 extension_loaded_observer.Wait(); |
| 1717 } | 1718 } |
| 1718 | 1719 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1782 // Install the policy and trigger another download. | 1783 // Install the policy and trigger another download. |
| 1783 base::ListValue install_sources; | 1784 base::ListValue install_sources; |
| 1784 install_sources.AppendString(install_source_url.spec()); | 1785 install_sources.AppendString(install_source_url.spec()); |
| 1785 install_sources.AppendString(referrer_url.spec()); | 1786 install_sources.AppendString(referrer_url.spec()); |
| 1786 PolicyMap policies; | 1787 PolicyMap policies; |
| 1787 policies.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY, | 1788 policies.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY, |
| 1788 POLICY_SCOPE_USER, install_sources.DeepCopy(), NULL); | 1789 POLICY_SCOPE_USER, install_sources.DeepCopy(), NULL); |
| 1789 UpdateProviderPolicy(policies); | 1790 UpdateProviderPolicy(policies); |
| 1790 | 1791 |
| 1791 content::WindowedNotificationObserver observer( | 1792 content::WindowedNotificationObserver observer( |
| 1792 chrome::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, | 1793 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, |
| 1793 content::NotificationService::AllSources()); | 1794 content::NotificationService::AllSources()); |
| 1794 PerformClick(1, 0); | 1795 PerformClick(1, 0); |
| 1795 observer.Wait(); | 1796 observer.Wait(); |
| 1796 // Note: Cannot check that the notification details match the expected | 1797 // Note: Cannot check that the notification details match the expected |
| 1797 // exception, since the details object has already been freed prior to | 1798 // exception, since the details object has already been freed prior to |
| 1798 // the completion of observer.Wait(). | 1799 // the completion of observer.Wait(). |
| 1799 | 1800 |
| 1800 // The first extension shouldn't be present, the second should be there. | 1801 // The first extension shouldn't be present, the second should be there. |
| 1801 EXPECT_FALSE(extension_service()->GetExtensionById(kGoodCrxId, true)); | 1802 EXPECT_FALSE(extension_service()->GetExtensionById(kGoodCrxId, true)); |
| 1802 EXPECT_TRUE(extension_service()->GetExtensionById(kAdBlockCrxId, false)); | 1803 EXPECT_TRUE(extension_service()->GetExtensionById(kAdBlockCrxId, false)); |
| (...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3178 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 3179 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 3179 browser2->tab_strip_model()->GetActiveWebContents(), | 3180 browser2->tab_strip_model()->GetActiveWebContents(), |
| 3180 "domAutomationController.send(window.showModalDialog !== undefined);", | 3181 "domAutomationController.send(window.showModalDialog !== undefined);", |
| 3181 &result)); | 3182 &result)); |
| 3182 EXPECT_TRUE(result); | 3183 EXPECT_TRUE(result); |
| 3183 } | 3184 } |
| 3184 | 3185 |
| 3185 #endif // !defined(CHROME_OS) | 3186 #endif // !defined(CHROME_OS) |
| 3186 | 3187 |
| 3187 } // namespace policy | 3188 } // namespace policy |
| OLD | NEW |