#include <stddef.h>
#include "base/containers/contains.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/ref_counted.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/test/bind.h"
#include "build/build_config.h"
#include "chrome/browser/enterprise/browser_management/management_service_factory.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_management.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/install_verifier.h"
#include "chrome/browser/extensions/updater/extension_updater.h"
#include "chrome/browser/policy/policy_test_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/url_constants.h"
#include "components/policy/core/browser/browser_policy_connector.h"
#include "components/policy/core/common/mock_configuration_policy_provider.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/core/common/policy_types.h"
#include "components/policy/policy_constants.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "content/public/test/url_loader_interceptor.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_host_test_helper.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/test_extension_registry_observer.h"
#include "extensions/browser/updater/extension_downloader.h"
#include "extensions/common/mojom/view_type.mojom.h"
#include "extensions/test/extension_test_message_listener.h"
#include "testing/gmock/include/gmock/gmock.h"
BrowserThread;
Extension;
ExtensionRegistry;
ExtensionService;
Manifest;
ManifestLocation;
PolicyMap;
_;
Return;
namespace {
std::string BuildForceInstallPolicyValue(const char* extension_id,
const char* update_url) { … }
}
class ExtensionManagementTest : public extensions::ExtensionBrowserTest { … };
IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, InstallSameVersion) { … }
IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, InstallOlderVersion) { … }
IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, InstallThenCancel) { … }
IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, InstallRequiresConfirm) { … }
IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, DisableEnable) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_AutoUpdate …
#else
#if defined(ADDRESS_SANITIZER)
#define MAYBE_AutoUpdate …
#else
#define MAYBE_AutoUpdate …
#endif
#endif
IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, MAYBE_AutoUpdate) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_AutoUpdateDisabledExtensions …
#else
#if defined(ADDRESS_SANITIZER)
#define MAYBE_AutoUpdateDisabledExtensions …
#else
#define MAYBE_AutoUpdateDisabledExtensions …
#endif
#endif
IN_PROC_BROWSER_TEST_F(ExtensionManagementTest,
MAYBE_AutoUpdateDisabledExtensions) { … }
IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalUrlUpdate) { … }
namespace {
const char kForceInstallNotEmptyHelp[] = …;
}
IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalPolicyRefresh) { … }
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(ExtensionManagementTest,
NonCWSForceInstalledDisabledInLowTrustEnvironment) {
policy::ScopedManagementServiceOverrideForTesting platform_management(
policy::ManagementServiceFactory::GetForPlatform(),
policy::EnterpriseManagementAuthority::COMPUTER_LOCAL);
policy::ScopedManagementServiceOverrideForTesting browser_management(
policy::ManagementServiceFactory::GetForProfile(profile()),
policy::EnterpriseManagementAuthority::NONE);
static constexpr char kExtensionId[] = "ogjcoiohnmldgjemafoockdghcjciccf";
base::ScopedAllowBlockingForTesting allow_blocking;
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
embedded_test_server()->ServeFilesFromDirectory(temp_dir.GetPath());
ASSERT_TRUE(embedded_test_server()->Start());
base::FilePath crx_path;
ASSERT_NO_FATAL_FAILURE(SetUpExtensionUpdatePackage(temp_dir.GetPath(), "v2",
"v2.crx", &crx_path));
ASSERT_NO_FATAL_FAILURE(SetUpExtensionUpdateResponse(
temp_dir.GetPath(), "v2.crx", "manifest_v2.xml.template"));
ExtensionRegistry* registry = extension_registry();
base::Value::List forcelist;
forcelist.Append(BuildForceInstallPolicyValue(kExtensionId,
GetUpdateUrl().spec().c_str()));
PolicyMap policies;
policies.Set(policy::key::kExtensionInstallForcelist,
policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
policy::POLICY_SOURCE_CLOUD, base::Value(std::move(forcelist)),
nullptr);
extensions::TestExtensionRegistryObserver install_observer(registry);
UpdateProviderPolicy(policies);
install_observer.WaitForExtensionWillBeInstalled();
EXPECT_EQ(1u, registry->disabled_extensions().size());
EXPECT_TRUE(registry->disabled_extensions().GetByID(kExtensionId));
}
IN_PROC_BROWSER_TEST_F(ExtensionManagementTest,
NonCWSForceInstalledEnabledOnManagedPlatform) {
policy::ScopedManagementServiceOverrideForTesting platform_management(
policy::ManagementServiceFactory::GetForPlatform(),
policy::EnterpriseManagementAuthority::CLOUD);
policy::ScopedManagementServiceOverrideForTesting browser_management(
policy::ManagementServiceFactory::GetForProfile(profile()),
policy::EnterpriseManagementAuthority::NONE);
static constexpr char kExtensionId[] = "ogjcoiohnmldgjemafoockdghcjciccf";
base::ScopedAllowBlockingForTesting allow_blocking;
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
embedded_test_server()->ServeFilesFromDirectory(temp_dir.GetPath());
ASSERT_TRUE(embedded_test_server()->Start());
base::FilePath crx_path;
ASSERT_NO_FATAL_FAILURE(SetUpExtensionUpdatePackage(temp_dir.GetPath(), "v2",
"v2.crx", &crx_path));
ASSERT_NO_FATAL_FAILURE(SetUpExtensionUpdateResponse(
temp_dir.GetPath(), "v2.crx", "manifest_v2.xml.template"));
base::Value::List forcelist;
forcelist.Append(BuildForceInstallPolicyValue(kExtensionId,
GetUpdateUrl().spec().c_str()));
PolicyMap policies;
policies.Set(policy::key::kExtensionInstallForcelist,
policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
policy::POLICY_SOURCE_CLOUD, base::Value(std::move(forcelist)),
nullptr);
ExtensionRegistry* registry = extension_registry();
const size_t size_before = registry->enabled_extensions().size();
extensions::TestExtensionRegistryObserver install_observer(registry);
UpdateProviderPolicy(policies);
install_observer.WaitForExtensionWillBeInstalled();
EXPECT_EQ(size_before + 1, registry->enabled_extensions().size());
EXPECT_TRUE(registry->enabled_extensions().GetByID(kExtensionId));
}
IN_PROC_BROWSER_TEST_F(ExtensionManagementTest,
NonCWSForceInstalledEnabledOnManagedProfile) {
policy::ScopedManagementServiceOverrideForTesting platform_management(
policy::ManagementServiceFactory::GetForPlatform(),
policy::EnterpriseManagementAuthority::NONE);
policy::ScopedManagementServiceOverrideForTesting browser_management(
policy::ManagementServiceFactory::GetForProfile(profile()),
policy::EnterpriseManagementAuthority::CLOUD);
static constexpr char kExtensionId[] = "ogjcoiohnmldgjemafoockdghcjciccf";
base::ScopedAllowBlockingForTesting allow_blocking;
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
embedded_test_server()->ServeFilesFromDirectory(temp_dir.GetPath());
ASSERT_TRUE(embedded_test_server()->Start());
base::FilePath crx_path;
ASSERT_NO_FATAL_FAILURE(SetUpExtensionUpdatePackage(temp_dir.GetPath(), "v2",
"v2.crx", &crx_path));
ASSERT_NO_FATAL_FAILURE(SetUpExtensionUpdateResponse(
temp_dir.GetPath(), "v2.crx", "manifest_v2.xml.template"));
base::Value::List forcelist;
forcelist.Append(BuildForceInstallPolicyValue(kExtensionId,
GetUpdateUrl().spec().c_str()));
PolicyMap policies;
policies.Set(policy::key::kExtensionInstallForcelist,
policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
policy::POLICY_SOURCE_CLOUD, base::Value(std::move(forcelist)),
nullptr);
ExtensionRegistry* registry = extension_registry();
const size_t size_before = registry->enabled_extensions().size();
extensions::TestExtensionRegistryObserver install_observer(registry);
UpdateProviderPolicy(policies);
install_observer.WaitForExtensionWillBeInstalled();
EXPECT_EQ(size_before + 1, registry->enabled_extensions().size());
EXPECT_TRUE(registry->enabled_extensions().GetByID(kExtensionId));
}
#endif
#if defined(ADDRESS_SANITIZER) || BUILDFLAG(IS_WIN)
#define MAYBE_PolicyOverridesUserInstall …
#else
#define MAYBE_PolicyOverridesUserInstall …
#endif
IN_PROC_BROWSER_TEST_F(ExtensionManagementTest,
MAYBE_PolicyOverridesUserInstall) { … }