Commit 4188b394 authored by Oleg Davydov's avatar Oleg Davydov Committed by Commit Bot

Move extensions-related stuff from PolicyTest

Methods and initializations which make sense only for extensions tests
moved from generic PolicyTest (int policy_test_util.h) to special
ExtensionPolicyTest in extension_policy_browsertest.cc.

Note that some tests in policy_browsertest.cc use extensions but don't
test extension-related policies, so PolicyTest::LoadUpackedExtension
remained in PolicyTest.

Bug: 1002483
Change-Id: Ia5a0114bb1c2b8b1240cf41ad8e2c977418efe8e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1807219
Commit-Queue: Oleg Davydov <burunduk@chromium.org>
Reviewed-by: default avatarPavol Marko <pmarko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697224}
parent 6d308af2
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "chrome/browser/extensions/chrome_test_extension_loader.h" #include "chrome/browser/extensions/chrome_test_extension_loader.h"
#include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ash/chrome_screenshot_grabber.h" #include "chrome/browser/ui/ash/chrome_screenshot_grabber.h"
#include "chrome/browser/ui/ash/chrome_screenshot_grabber_test_observer.h" #include "chrome/browser/ui/ash/chrome_screenshot_grabber_test_observer.h"
...@@ -19,7 +17,6 @@ ...@@ -19,7 +17,6 @@
#include "chrome/browser/ui/location_bar/location_bar.h" #include "chrome/browser/ui/location_bar/location_bar.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chrome/common/net/safe_search_util.h" #include "chrome/common/net/safe_search_util.h"
#include "chrome/common/web_application_info.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "components/omnibox/browser/omnibox_edit_model.h" #include "components/omnibox/browser/omnibox_edit_model.h"
#include "components/policy/core/browser/browser_policy_connector.h" #include "components/policy/core/browser/browser_policy_connector.h"
...@@ -37,10 +34,6 @@ ...@@ -37,10 +34,6 @@
#include "content/public/common/service_names.mojom.h" #include "content/public/common/service_names.mojom.h"
#include "content/public/test/test_navigation_observer.h" #include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/notification_types.h"
#include "extensions/browser/test_extension_registry_observer.h"
#include "net/dns/mock_host_resolver.h" #include "net/dns/mock_host_resolver.h"
#include "net/http/transport_security_state.h" #include "net/http/transport_security_state.h"
#include "services/network/public/mojom/network_service_test.mojom.h" #include "services/network/public/mojom/network_service_test.mojom.h"
...@@ -68,7 +61,6 @@ PolicyTest::PolicyTest() = default; ...@@ -68,7 +61,6 @@ PolicyTest::PolicyTest() = default;
PolicyTest::~PolicyTest() = default; PolicyTest::~PolicyTest() = default;
void PolicyTest::SetUp() { void PolicyTest::SetUp() {
test_extension_cache_.reset(new extensions::ExtensionCacheFake());
InProcessBrowserTest::SetUp(); InProcessBrowserTest::SetUp();
} }
...@@ -81,10 +73,6 @@ void PolicyTest::SetUpInProcessBrowserTestFixture() { ...@@ -81,10 +73,6 @@ void PolicyTest::SetUpInProcessBrowserTestFixture() {
void PolicyTest::SetUpOnMainThread() { void PolicyTest::SetUpOnMainThread() {
host_resolver()->AddRule("*", "127.0.0.1"); host_resolver()->AddRule("*", "127.0.0.1");
if (extension_service()->updater()) {
extension_service()->updater()->SetExtensionCacheForTesting(
test_extension_cache_.get());
}
} }
void PolicyTest::SetUpCommandLine(base::CommandLine* command_line) { void PolicyTest::SetUpCommandLine(base::CommandLine* command_line) {
...@@ -160,55 +148,6 @@ void PolicyTest::TestScreenshotFile(bool enabled) { ...@@ -160,55 +148,6 @@ void PolicyTest::TestScreenshotFile(bool enabled) {
} }
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
extensions::ExtensionService* PolicyTest::extension_service() {
extensions::ExtensionSystem* system =
extensions::ExtensionSystem::Get(browser()->profile());
return system->extension_service();
}
extensions::ExtensionRegistry* PolicyTest::extension_registry() {
return extensions::ExtensionRegistry::Get(browser()->profile());
}
const extensions::Extension* PolicyTest::InstallExtension(
const base::FilePath::StringType& name) {
base::FilePath extension_path(ui_test_utils::GetTestFilePath(
base::FilePath(kTestExtensionsDir), base::FilePath(name)));
scoped_refptr<extensions::CrxInstaller> installer =
extensions::CrxInstaller::CreateSilent(extension_service());
installer->set_allow_silent_install(true);
installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
installer->set_creation_flags(extensions::Extension::FROM_WEBSTORE);
installer->set_off_store_install_allow_reason(
extensions::CrxInstaller::OffStoreInstallAllowReason::
OffStoreInstallAllowedInTest);
content::WindowedNotificationObserver observer(
extensions::NOTIFICATION_CRX_INSTALLER_DONE,
content::NotificationService::AllSources());
installer->InstallCrx(extension_path);
observer.Wait();
content::Details<const extensions::Extension> details = observer.details();
return details.ptr();
}
const extensions::Extension* PolicyTest::InstallBookmarkApp() {
WebApplicationInfo web_app;
web_app.title = base::ASCIIToUTF16("Bookmark App");
web_app.app_url = GURL("http://www.google.com");
scoped_refptr<extensions::CrxInstaller> installer =
extensions::CrxInstaller::CreateSilent(extension_service());
content::WindowedNotificationObserver observer(
extensions::NOTIFICATION_CRX_INSTALLER_DONE,
content::NotificationService::AllSources());
installer->InstallWebApp(web_app);
observer.Wait();
content::Details<const extensions::Extension> details = observer.details();
return details.ptr();
}
scoped_refptr<const extensions::Extension> PolicyTest::LoadUnpackedExtension( scoped_refptr<const extensions::Extension> PolicyTest::LoadUnpackedExtension(
const base::FilePath::StringType& name) { const base::FilePath::StringType& name) {
base::FilePath extension_path(ui_test_utils::GetTestFilePath( base::FilePath extension_path(ui_test_utils::GetTestFilePath(
...@@ -217,30 +156,6 @@ scoped_refptr<const extensions::Extension> PolicyTest::LoadUnpackedExtension( ...@@ -217,30 +156,6 @@ scoped_refptr<const extensions::Extension> PolicyTest::LoadUnpackedExtension(
return loader.LoadExtension(extension_path); return loader.LoadExtension(extension_path);
} }
void PolicyTest::UninstallExtension(const std::string& id,
bool expect_success) {
if (expect_success) {
extensions::TestExtensionRegistryObserver observer(extension_registry());
extension_service()->UninstallExtension(
id, extensions::UNINSTALL_REASON_FOR_TESTING, nullptr);
observer.WaitForExtensionUninstalled();
} else {
content::WindowedNotificationObserver observer(
extensions::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
content::NotificationService::AllSources());
extension_service()->UninstallExtension(
id, extensions::UNINSTALL_REASON_FOR_TESTING, nullptr);
observer.Wait();
}
}
void PolicyTest::DisableExtension(const std::string& id) {
extensions::TestExtensionRegistryObserver observer(extension_registry());
extension_service()->DisableExtension(
id, extensions::disable_reason::DISABLE_USER_ACTION);
observer.WaitForExtensionUnloaded();
}
void PolicyTest::UpdateProviderPolicy(const PolicyMap& policy) { void PolicyTest::UpdateProviderPolicy(const PolicyMap& policy) {
PolicyMap policy_with_defaults; PolicyMap policy_with_defaults;
policy_with_defaults.CopyFrom(policy); policy_with_defaults.CopyFrom(policy);
......
...@@ -7,17 +7,12 @@ ...@@ -7,17 +7,12 @@
#include "ash/public/cpp/keyboard/keyboard_types.h" #include "ash/public/cpp/keyboard/keyboard_types.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "chrome/browser/extensions/updater/extension_cache_fake.h"
#include "chrome/browser/extensions/updater/extension_updater.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "components/policy/core/common/mock_configuration_policy_provider.h" #include "components/policy/core/common/mock_configuration_policy_provider.h"
#include "components/security_interstitials/core/controller_client.h" #include "components/security_interstitials/core/controller_client.h"
#include "extensions/browser/scoped_ignore_content_verifier_for_test.h"
namespace extensions { namespace extensions {
class Extension; class Extension;
class ExtensionRegistry;
class ExtensionService;
} // namespace extensions } // namespace extensions
namespace policy { namespace policy {
...@@ -45,22 +40,9 @@ class PolicyTest : public InProcessBrowserTest { ...@@ -45,22 +40,9 @@ class PolicyTest : public InProcessBrowserTest {
void SetShouldRequireCTForTesting(bool* required); void SetShouldRequireCTForTesting(bool* required);
extensions::ExtensionService* extension_service();
extensions::ExtensionRegistry* extension_registry();
const extensions::Extension* InstallExtension(
const base::FilePath::StringType& name);
const extensions::Extension* InstallBookmarkApp();
scoped_refptr<const extensions::Extension> LoadUnpackedExtension( scoped_refptr<const extensions::Extension> LoadUnpackedExtension(
const base::FilePath::StringType& name); const base::FilePath::StringType& name);
void UninstallExtension(const std::string& id, bool expect_success);
void DisableExtension(const std::string& id);
void UpdateProviderPolicy(const PolicyMap& policy); void UpdateProviderPolicy(const PolicyMap& policy);
// Sends a mouse click at the given coordinates to the current renderer. // Sends a mouse click at the given coordinates to the current renderer.
...@@ -113,10 +95,6 @@ class PolicyTest : public InProcessBrowserTest { ...@@ -113,10 +95,6 @@ class PolicyTest : public InProcessBrowserTest {
security_interstitials::SecurityInterstitialCommand command); security_interstitials::SecurityInterstitialCommand command);
MockConfigurationPolicyProvider provider_; MockConfigurationPolicyProvider provider_;
std::unique_ptr<extensions::ExtensionCacheFake> test_extension_cache_;
extensions::ScopedIgnoreContentVerifierForTest ignore_content_verifier_;
extensions::ExtensionUpdater::ScopedSkipScheduledCheckForTest
skip_scheduled_extension_checks_;
}; };
} // namespace policy } // namespace policy
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment