chromium/chrome/browser/supervised_user/supervised_user_extensions_manager_unittest.cc

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

#include "chrome/browser/supervised_user/supervised_user_extensions_manager.h"

#include <string>
#include <vector>

#include "base/test/gtest_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/values.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_service_test_base.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/supervised_user/supervised_user_extensions_metrics_recorder.h"
#include "chrome/browser/supervised_user/supervised_user_test_util.h"
#include "chrome/test/base/testing_profile.h"
#include "components/prefs/pref_service.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/version_info/version_info.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/features/feature_channel.h"
#include "extensions/common/manifest_constants.h"
#include "testing/gtest/include/gtest/gtest.h"

enum class ExtensionsManagingToggle : int {};

Extension;

class SupervisedUserExtensionsManagerTestBase
    : public extensions::ExtensionServiceTestBase {};

class SupervisedUserExtensionsManagerTest
    : public SupervisedUserExtensionsManagerTestBase,
      public ::testing::WithParamInterface<ExtensionsManagingToggle> {};

TEST_P(SupervisedUserExtensionsManagerTest,
       ExtensionManagementPolicyProviderWithoutSUInitiatedInstalls) {}

TEST_P(SupervisedUserExtensionsManagerTest,
       ExtensionManagementPolicyProviderWithSUInitiatedInstalls) {}

// Tests that on Desktop (Win/Linux/Mac) platforms, when the feature
// `kEnableSupervisedUserSkipParentApprovalToInstallExtensions` is first
// enabled, present extensions will be marked as locally parent-approved
// when the SupervisedUserExtensionsManager is created for a supervised user.
TEST_P(SupervisedUserExtensionsManagerTest,
       MigrateExtensionsToLocallyApproved) {}

// Tests that extensions missing parent approval are granted parent approval
// on their installation, when the extensions are managed by the Extensions
// toggle and the toggle is ON. If extensions are managed by the Permissions
// toggle, the extensions remain disabled and pending approval.
TEST_P(SupervisedUserExtensionsManagerTest,
       GrantParentApprovalOnInstallationWhenExtensionsToggleOn) {}

// Tests that extensions missing parent approval are granted parent approval
// when the extensions are managed by the Extensions toggle and the toggle is
// flipped to ON.
// If extensions are managed by the Permissions toggle, the extensions remain
// disabled and pending approval.
TEST_P(SupervisedUserExtensionsManagerTest,
       GrantParentApprovalOnExtensionsWhenExtensionsToggleSetToOn) {}

// Tests the local approval is revoked on uninstalling the extension or
// when the extension gains normal parental approval.
TEST_P(SupervisedUserExtensionsManagerTest, RevokeLocalApproval) {}

INSTANTIATE_TEST_SUITE_P();

// Whether the local approval extension migration for
// Win/Mac/Linux platforms has already run at the beginning of
// each test case.
enum class LocalApprovalMigrationForDesktopState : int {};

// Tests the managed extensions' state when an existing profile becomes
// supervised.
class AddingSupervisionTest
    : public SupervisedUserExtensionsManagerTestBase,
      public ::testing::WithParamInterface<
          std::tuple<ExtensionsManagingToggle,
                     LocalApprovalMigrationForDesktopState>> {};

// Tests that on Desktop (Win/Linux/Mac) platforms, when:
// 1) the feature `kEnableSupervisedUserSkipParentApprovalToInstallExtensions`
// is first enabled and
// 2) a supervised user sings-in on an existing unsupervised profile or
//    the existing profile becomes supervised (Gellerized) then
// the existing extensions remain disabled and pending approval.
// The states of the present extensions should not be impacted by the local
// extension approval migration that is executed on feature release for Desktop
// platforms.
TEST_P(AddingSupervisionTest,
       DisableExistingExtensionsOnProfileBecomingSupervised) {}

INSTANTIATE_TEST_SUITE_P();