chromium/chrome/browser/supervised_user/desktop/supervised_user_extension_browsertest.cc

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/files/file_path.h"
#include "base/functional/callback_forward.h"
#include "base/test/gtest_util.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/supervised_user/supervised_user_extensions_delegate_impl.h"
#include "chrome/browser/supervised_user/supervised_user_test_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/views/supervised_user/parent_permission_dialog_view.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/mixin_based_in_process_browser_test.h"
#include "chrome/test/supervised_user/supervision_mixin.h"
#include "components/supervised_user/core/browser/supervised_user_preferences.h"
#include "components/supervised_user/core/browser/supervised_user_utils.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/web_contents.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_launcher.h"
#include "content/public/test/web_contents_tester.h"
#include "extensions/browser/disable_reason.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/supervised_user_extensions_delegate.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"

#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/supervised_user/chromeos/parent_access_extension_approvals_manager.h"
#include "chromeos/crosapi/mojom/parent_access.mojom.h"
#endif  // BUILDFLAG(IS_CHROMEOS)

namespace {
constexpr char kGoodCrxId[] =;

#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
constexpr char kSimpleWithIconCrxId[] =;
#endif  // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
}  // namespace

namespace extensions {

enum class ExtensionsParentalControlState : int {};

enum class ExtensionManagementSwitch : int {};

std::string CreateTestSuffixFromParam(const auto& info) {
  return std::string(std::get<0>(info.param) ==
                             ExtensionsParentalControlState::kEnabled
                         ? "WithParentalControlsOnExtensions"
                         : "WithoutParentalControlsOnExtensions") +
         std::string(std::get<1>(info.param) ==
                             ExtensionManagementSwitch::kManagedByExtensions
                         ? "ManagedByExtensions"
                         : "ManagedByPermissions");
}

SupervisionMixinSigninModeCallback;

// Tests interaction between supervised users and extensions.
class SupervisionExtensionTestBase
    : public ExtensionBrowserTest,
      public ::testing::WithParamInterface<
          std::tuple<ExtensionsParentalControlState,
                     ExtensionManagementSwitch,
                     SupervisionMixinSigninModeCallback>> {};

// Tests interaction between supervised users and extensions after the optional
// supervision is removed from the account.
class SupervisionRemovalExtensionTest : public SupervisionExtensionTestBase {};

// If extension restrictions apply to supervised users, removing supervision
// should also remove associated disable reasons, such as
// DISABLE_CUSTODIAN_APPROVAL_REQUIRED. Extensions should become enabled again
// after removing supervision. Prevents a regression to crbug/1045625.
// If extension restrictions are disabled, removing supervision leaves the
// extension unchanged and enabled.
IN_PROC_BROWSER_TEST_P(SupervisionRemovalExtensionTest,
                       PRE_RemoveCustodianApprovalRequirement) {}

IN_PROC_BROWSER_TEST_P(SupervisionRemovalExtensionTest,
                       RemoveCustodianApprovalRequirement) {}

INSTANTIATE_TEST_SUITE_P();

// Tests interaction between supervised users and extensions after the optional
// supervision is added to an the account.
class UserGellerizationExtensionTest : public SupervisionExtensionTestBase {};

IN_PROC_BROWSER_TEST_P(UserGellerizationExtensionTest,
                       PRE_UserGellerizationDisablesExistingExtensions) {}

IN_PROC_BROWSER_TEST_P(UserGellerizationExtensionTest,
                       UserGellerizationDisablesExistingExtensions) {}

INSTANTIATE_TEST_SUITE_P();

// Tests the parental controls applied on extensions for supervised users
// under different values of the Family Link Extensions Switch
// ("Allow to add extensions without asking for permission").
class ParentApprovalHandlingByExtensionSwitchTest
    : public SupervisionExtensionTestBase {};

IN_PROC_BROWSER_TEST_P(
    ParentApprovalHandlingByExtensionSwitchTest,
    PRE_GrantParentApprovalWhenExtensionSwitchBecomesEnabled) {}

IN_PROC_BROWSER_TEST_P(ParentApprovalHandlingByExtensionSwitchTest,
                       GrantParentApprovalWhenExtensionSwitchBecomesEnabled) {}

IN_PROC_BROWSER_TEST_P(
    ParentApprovalHandlingByExtensionSwitchTest,
    GrantParentParentApprovalOnInstallationIfExtensionSwitchEnabled) {}

// TODO(b/321240025): Add test case on permission increase.
// TODO(b/321240025): Add test case on an extension trying to change settings of
// a website.

INSTANTIATE_TEST_SUITE_P();

class ParentApprovalRequestTest
    : public SupervisionExtensionTestBase,
#if BUILDFLAG(IS_CHROMEOS)
      public TestExtensionApprovalsManagerObserver,
#endif
      public TestParentPermissionDialogViewObserver {};

// Tests that the method to request extension approval can be triggered
// without errors for new (uninstalled) extensions that already have been
// granted parent approval.
// Prevents regressions to b/321016032.
IN_PROC_BROWSER_TEST_P(ParentApprovalRequestTest,
                       RequestToInstallApprovedExtension) {}

INSTANTIATE_TEST_SUITE_P();

#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
// Tests the behavior of existing and new extensions for a supervised user
// on the release of the `SkipParentalApproval` feature.
class SupervisedUserSkipParentalApprovalModeReleaseTest
    : public SupervisionExtensionTestBase {};

IN_PROC_BROWSER_TEST_P(SupervisedUserSkipParentalApprovalModeReleaseTest,
                       PRE_OnFeatureReleaseForSupervisedUserWithExtensions) {}

IN_PROC_BROWSER_TEST_P(SupervisedUserSkipParentalApprovalModeReleaseTest,
                       OnFeatureReleaseForSupervisedUserWithExtensions) {}

INSTANTIATE_TEST_SUITE_P();

#endif  // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)

}  // namespace extensions