chromium/chrome/browser/extensions/manifest_v2_experiment_manager_unittest.cc

// Copyright 2024 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/extensions/manifest_v2_experiment_manager.h"

#include "base/memory/raw_ptr.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/extensions/extension_management_internal.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_service_user_test_base.h"
#include "chrome/browser/extensions/mv2_experiment_stage.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/test/base/testing_profile.h"
#include "components/crx_file/id_util.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "extensions/browser/disable_reason.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/pref_names.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/mojom/manifest.mojom.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "components/account_id/account_id.h"
#include "components/user_manager/user.h"
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

namespace extensions {

class ManifestV2ExperimentManagerUnitTestBase
    : public ExtensionServiceUserTestBase {};

ManifestV2ExperimentManagerUnitTestBase::
    ManifestV2ExperimentManagerUnitTestBase(
        const std::vector<base::test::FeatureRef>& enabled_features,
        const std::vector<base::test::FeatureRef>& disabled_features) {}

// Test suite for cases where the user is in the "warning" experiment phase.
class ManifestV2ExperimentManagerWarningUnitTest
    : public ManifestV2ExperimentManagerUnitTestBase {};

// Test suite for cases where the user is not in any experiment phase; i.e., the
// experiment is disabled.
class ManifestV2ExperimentManagerDisabledUnitTest
    : public ManifestV2ExperimentManagerUnitTestBase {};

// Test suite for cases where the user is in the "disable with re-enable"
// experiment phase.
class ManifestV2ExperimentManagerDisableWithReEnableUnitTest
    : public ManifestV2ExperimentManagerUnitTestBase {};

// Test suite for cases where the user is in the "disable with re-enable"
// experiment phase *and* the warning experiment is still active.
class ManifestV2ExperimentManagerDisableWithReEnableAndWarningUnitTest
    : public ManifestV2ExperimentManagerUnitTestBase {};

// Tests that the experiment stage is properly set when the manifest V2
// deprecation warning experiment is enabled.
TEST_F(ManifestV2ExperimentManagerWarningUnitTest,
       ExperimentStageIsSetToWarning) {}

// Sanity check that MV2 extensions are considered affected when the
// experiment is enabled. The "is affected" logic is much more heavily tested
// in mv2_deprecation_impact_checker_unittest.cc.
TEST_F(ManifestV2ExperimentManagerWarningUnitTest, MV2ExtensionsAreAffected) {}

TEST_F(ManifestV2ExperimentManagerWarningUnitTest,
       MarkingNoticeAsAcknowledged) {}

TEST_F(ManifestV2ExperimentManagerWarningUnitTest,
       MarkingGlobalNoticeAsAcknowledged) {}

// Tests that the experiment stage is properly set when the manifest V2
// deprecation warning experiment is disabled.
TEST_F(ManifestV2ExperimentManagerDisabledUnitTest,
       ExperimentStageIsSetToNone) {}

// Sanity check that no extensions are considered affected when the
// experiment is disabled. The "is affected" logic is much more heavily tested
// in mv2_deprecation_impact_checker_unittest.cc.
TEST_F(ManifestV2ExperimentManagerDisabledUnitTest, NoExtensionsAreAffected) {}

// Tests that the experiment phase is properly set for a user in the
// "disable with re-enable" experiment phase.
TEST_F(ManifestV2ExperimentManagerDisableWithReEnableUnitTest,
       ExperimentStageIsSetToDisableWithReEnable) {}

// Tests that the experiment phase is properly set for a user in the
// "disable with re-enable" experiment phase if the "warning" experiment is
// still active. That is, verifies that the "latest" stage takes precedence.
TEST_F(ManifestV2ExperimentManagerDisableWithReEnableAndWarningUnitTest,
       ExperimentStageIsSetToDisableWithReEnable) {}

// Sanity check that MV2 extensions are considered affected when the
// experiment is enabled in the "disable with re-enable" phase. The
// "is affected" logic is much more heavily tested
// in mv2_deprecation_impact_checker_unittest.cc.
TEST_F(ManifestV2ExperimentManagerDisableWithReEnableUnitTest,
       MV2ExtensionsAreAffected) {}

// Tests the manager properly indicates when to block user-installed extensions
// while the "soft disable" experiment stage is active.
TEST_F(ManifestV2ExperimentManagerDisableWithReEnableUnitTest,
       ShouldBlockInstallation_UserInstalledExtensions) {}

// Tests the manager never blocks component extensions from installing.
TEST_F(ManifestV2ExperimentManagerDisableWithReEnableUnitTest,
       ShouldBlockInstallation_ComponentExtensions) {}

TEST_F(ManifestV2ExperimentManagerDisableWithReEnableUnitTest,
       MarkingNoticeAsAcknowledged) {}

// Tests that the proper manifest group is used when emitting metrics for
// disabled extensions.
TEST_F(ManifestV2ExperimentManagerDisableWithReEnableUnitTest,
       ProfileMetrics_ExtensionLocationsAreProperlyGrouped) {}

// Tests that MV3 extensions don't emit any metrics.
TEST_F(ManifestV2ExperimentManagerDisableWithReEnableUnitTest,
       ProfileMetrics_MV3ExtensionsArentIncluded) {}

// Tests that extensions that are re-enabled by the user are properly emitted
// as `kUserReEnabled`.
TEST_F(ManifestV2ExperimentManagerDisableWithReEnableUnitTest,
       ProfileMetrics_UserReEnabledAreProperlyEmitted) {}

// Tests that extensions that are disabled for other reasons (such as by user
// action) emit `kOther` for their state.
TEST_F(ManifestV2ExperimentManagerDisableWithReEnableUnitTest,
       ProfileMetrics_ExtensionsThatAreDisabledForOtherReasonsEmitOther) {}

enum class MV2PolicyLevel {};

// A test suite to allow setting various MV2-related policies.
class ManifestV2ExperimentManagerDisableWithReEnableAndPolicyUnitTest
    : public ManifestV2ExperimentManagerDisableWithReEnableUnitTest {};

// Tests that installation of all extensions is allowed if MV2 is allowed by
// policy.
TEST_F(ManifestV2ExperimentManagerDisableWithReEnableAndPolicyUnitTest,
       ShouldBlockInstallation_DontBlockWhenAllMV2Allowed) {}

// Tests installation of all extensions (other than component extensions) is
// disallowed if disallowed by policy.
TEST_F(ManifestV2ExperimentManagerDisableWithReEnableAndPolicyUnitTest,
       ShouldBlockInstallation_AllAreBlockedWhenMV2Disallowed) {}

// Tests admin-installed extensions may be installed, while others may not be,
// if the MV2 policy is set to admin-installed-only.
TEST_F(
    ManifestV2ExperimentManagerDisableWithReEnableAndPolicyUnitTest,
    ShouldBlockInstallation_UserInstalledAreBlockedWhenForceInstalledAllowed) {}

TEST_F(ManifestV2ExperimentManagerDisableWithReEnableAndPolicyUnitTest,
       ExtensionsAreReEnabledOrDisabledOnPolicyChange) {}

// Tests that MV2 extensions that are allowed by policy emit `kUnaffected` for
// their state.
TEST_F(ManifestV2ExperimentManagerDisableWithReEnableAndPolicyUnitTest,
       ProfileMetrics_ExtensionsAllowedByPolicyEmitUnaffected) {}

}  // namespace extensions