#include "extensions/browser/api/management/management_api.h"
#include <memory>
#include <optional>
#include <utility>
#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/strings/stringprintf.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/metrics/user_action_tester.h"
#include "base/types/optional_ref.h"
#include "base/values.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/background/background_contents.h"
#include "chrome/browser/extensions/extension_install_prompt_show_params.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_service_test_base.h"
#include "chrome/browser/extensions/extension_service_test_with_install.h"
#include "chrome/browser/extensions/extension_uninstall_dialog.h"
#include "chrome/browser/extensions/test_extension_system.h"
#include "chrome/browser/supervised_user/supervised_user_extensions_delegate_impl.h"
#include "chrome/browser/supervised_user/supervised_user_extensions_metrics_recorder.h"
#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
#include "chrome/browser/supervised_user/supervised_user_test_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/extensions/extensions_dialogs.h"
#include "chrome/test/base/test_browser_window.h"
#include "components/supervised_user/core/browser/supervised_user_service.h"
#include "components/supervised_user/core/common/features.h"
#include "components/supervised_user/core/common/pref_names.h"
#include "components/supervised_user/core/common/supervised_user_constants.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/gpu_data_manager.h"
#include "content/public/test/web_contents_tester.h"
#include "extensions/browser/api/management/management_api_constants.h"
#include "extensions/browser/api_test_utils.h"
#include "extensions/browser/disable_reason.h"
#include "extensions/browser/event_router_factory.h"
#include "extensions/browser/extension_dialog_auto_confirm.h"
#include "extensions/browser/extension_function_dispatcher.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/management_policy.h"
#include "extensions/browser/supervised_user_extensions_delegate.h"
#include "extensions/browser/test_management_policy.h"
#include "extensions/browser/uninstall_reason.h"
#include "extensions/common/api/management.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/mojom/context_type.mojom.h"
#include "extensions/common/permissions/permission_set.h"
ManifestLocation;
namespace extensions {
namespace {
std::unique_ptr<KeyedService> BuildManagementApi(
content::BrowserContext* context) { … }
std::unique_ptr<KeyedService> BuildEventRouter(
content::BrowserContext* profile) { … }
constants;
class ManagementApiUnitTest : public ExtensionServiceTestWithInstall { … };
bool ManagementApiUnitTest::RunFunction(
const scoped_refptr<ExtensionFunction>& function,
const base::Value::List& args) { … }
bool ManagementApiUnitTest::RunSetEnabledFunction(
content::WebContents* web_contents,
const ExtensionId& extension_id,
bool use_user_gesture,
bool accept_dialog,
std::string* error,
bool enabled) { … }
void ManagementApiUnitTest::SetUp() { … }
void ManagementApiUnitTest::TearDown() { … }
TEST_F(ManagementApiUnitTest, ManagementSetEnabled) { … }
TEST_F(ManagementApiUnitTest, ComponentPolicyDisabling) { … }
TEST_F(ManagementApiUnitTest, ComponentPolicyEnabling) { … }
TEST_F(ManagementApiUnitTest, ManagementUninstall) { … }
TEST_F(ManagementApiUnitTest, ManagementUninstallWebstoreHostedApp) { … }
TEST_F(ManagementApiUnitTest, ManagementUninstallNewWebstore) { … }
TEST_F(ManagementApiUnitTest, ManagementUninstallProgramatic) { … }
TEST_F(ManagementApiUnitTest, ManagementUninstallBlocklisted) { … }
TEST_F(ManagementApiUnitTest, ManagementEnableOrDisableBlocklisted) { … }
TEST_F(ManagementApiUnitTest, ExtensionInfo_MayEnable) { … }
TEST_F(ManagementApiUnitTest, ExtensionInfo_MayDisable) { … }
TEST_F(ManagementApiUnitTest, SetEnabled_UnsupportedRequirements) { … }
TEST_F(ManagementApiUnitTest, SetEnabled_IncreasedPermissions) { … }
TEST_F(ManagementApiUnitTest,
SetEnabled_UnsupportedRequirementsAndPermissionsIncrease) { … }
class ManagementApiUnitTestMV2DisableWithReEnableUnitTest
: public ManagementApiUnitTest { … };
TEST_F(ManagementApiUnitTestMV2DisableWithReEnableUnitTest,
SetEnabled_MV2Deprecation) { … }
TEST_F(ManagementApiUnitTestMV2DisableWithReEnableUnitTest,
SetEnabled_PermissionsIncreaseAndMV2Deprecation) { … }
class TestManagementAPIDelegate : public ManagementAPIDelegate { … };
class TestSupervisedUserExtensionsDelegate
: public SupervisedUserExtensionsDelegateImpl { … };
enum class ExtensionManagementSwitch : int { … };
class ManagementApiSupervisedUserTest
: public ManagementApiUnitTest,
public ::testing::WithParamInterface<ExtensionManagementSwitch> { … };
TEST_P(ManagementApiSupervisedUserTest,
SetEnabled_SetEnabledForLocallyApprovedExtension) { … }
TEST_P(ManagementApiSupervisedUserTest, SetEnabled_BlockedByParent) { … }
TEST_P(ManagementApiSupervisedUserTest, SetEnabled_AfterIncreasedPermissions) { … }
TEST_P(ManagementApiSupervisedUserTest,
SetEnabled_CantApprovePermissionUpdatesToggleOff) { … }
TEST_P(ManagementApiSupervisedUserTest,
SetEnabled_CustodianApprovalRequiredAndPermissionsIncrease) { … }
TEST_P(ManagementApiSupervisedUserTest, SetEnabled_UnsupportedRequirement) { … }
TEST_P(ManagementApiSupervisedUserTest, SetEnabledDisabled_UmaMetrics) { … }
INSTANTIATE_TEST_SUITE_P(…);
class ManagementApiSupervisedUserTestWithSetup
: public ManagementApiSupervisedUserTest { … };
TEST_P(ManagementApiSupervisedUserTestWithSetup, SetEnabled_ParentApproves) { … }
TEST_P(ManagementApiSupervisedUserTestWithSetup, SetEnabled_ParentDenies) { … }
TEST_P(ManagementApiSupervisedUserTestWithSetup, SetEnabled_DialogFails) { … }
TEST_P(ManagementApiSupervisedUserTestWithSetup, SetEnabled_PreviouslyAllowed) { … }
TEST_P(ManagementApiSupervisedUserTestWithSetup,
SetEnabled_ParentPermissionApprovedFromBackgroundPage) { … }
TEST_P(ManagementApiSupervisedUserTestWithSetup,
SetEnabled_ParentPermissionCanceledFromBackgroundPage) { … }
TEST_P(ManagementApiSupervisedUserTestWithSetup,
SetEnabled_ParentPermissionFailedFromBackgroundPage) { … }
TEST_P(ManagementApiSupervisedUserTestWithSetup,
SetEnabled_ExtensionInstallBlockedByParentFromBackgroundPage) { … }
INSTANTIATE_TEST_SUITE_P(…);
}
}