// 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 <string> #include <tuple> #include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/user_action_tester.h" #include "base/test/scoped_feature_list.h" #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service_test_with_install.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_extensions_metrics_recorder.h" #include "chrome/browser/supervised_user/supervised_user_test_util.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/testing_profile.h" #include "components/supervised_user/core/common/features.h" #include "components/supervised_user/core/common/pref_names.h" #include "extensions/browser/api_test_utils.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_builder.h" #include "testing/gtest/include/gtest/gtest.h" RunFunctionAndReturnSingleResult; namespace { const char good_crx[] = …; const char autoupdate[] = …; const char permissions_increase[] = …; } // namespace namespace extensions { // Base class for the extension parental controls tests for supervised users. class SupervisedUserExtensionTestBase : public ExtensionServiceTestWithInstall { … }; enum class ExtensionsParentalControlState : int { … }; enum class ExtensionManagementSwitch : int { … }; class SupervisedUserExtensionTest : public SupervisedUserExtensionTestBase, public ::testing::WithParamInterface< std::tuple<ExtensionsParentalControlState, ExtensionManagementSwitch>> { … }; // Tests that regular users are not affecting supervised user UMA metrics. TEST_P(SupervisedUserExtensionTest, RegularUsersNotAffectingSupervisedUserMetrics) { … } // Tests that simulating custodian approval for regular users doesn't cause any // unexpected behavior. TEST_P(SupervisedUserExtensionTest, CustodianApprovalDoesNotAffectRegularUsers) { … } // Tests that if the extension parental controls are enabled, adding supervision // to a regular account (Gellerization) disables previously installed // extensions. Otherwise the extension remains enabled. TEST_P(SupervisedUserExtensionTest, ExtensionsStateAfterGellerization) { … } // Tests that extensions that are disabled pending parent approval // for supervised users, become re-enabled if the user becomes unsupervised. TEST_P(SupervisedUserExtensionTest, ExtensionsStateAfterGraduation) { … } // Tests that a child user is allowed to install extensions under the default // values of the Family Link "Permissions" and "Extensions" toggles. // If the extension parental controls apply the newly-installed extensions // are disabled until approved by the parent. // Otherwise the newly-installed extensions are enabled. TEST_P(SupervisedUserExtensionTest, InstallAllowedForSupervisedUser) { … } // Tests that supervised users may approve permission updates without parent // approval under the default values of the Family Link "Permissions" and // "Extensions" toggles, when parental controls apply to extensions. // If parental controls do not apply, the child can approve permission // updates by default. TEST_P(SupervisedUserExtensionTest, UpdateWithPermissionsIncrease) { … } // Tests that when extensions are managed by the "Permissions" Family Link // switch, if the toggle is disabled, then: // If the extension parental controls are enabled, child users cannot approve // permission updates, otherwise they can approve permission updates. // When extensions are managed by the "Extensions" Family Link switch, // toggling the "Permissions" switch has no effect. TEST_P(SupervisedUserExtensionTest, ChildUserCannotApproveAdditionalPermissions) { … } // Tests that if an approved extension is updated to a newer version that // doesn't require additional permissions, it is still enabled. TEST_P(SupervisedUserExtensionTest, UpdateWithoutPermissionIncrease) { … } // Tests that when extensions are managed by the "Permissions" Family Link // toggle, if the "Permissions" toggle is disabled, then: // - If extension parental controls are enabled child users cannot install new // extensions. // - If extension parental controls are disabled child users can install new // extensions. // When extensions are managed by the "Extensions" Family Link toggle, // toggling the "Permissions" switch has no effect to the installation. TEST_P(SupervisedUserExtensionTest, SupervisedUserCannotInstallExtensionUnderPermissionsToggle) { … } // Tests that disabling the "Permissions" Family Link toggle, // has no effect on regular users. TEST_P(SupervisedUserExtensionTest, RegularUserCanInstallExtension) { … } // Tests that if the "Permissions" Family Link toggle becomes disabled, // previously approved extensions are still enabled. TEST_P(SupervisedUserExtensionTest, PermissionsToggleOffDoesNotAffectAlreadyEnabled) { … } // Tests that extensions installed when the "Extensions" Family Link toggle // applies and is enabled, are installed enabled and have been granted parent // approval. TEST_P(SupervisedUserExtensionTest, ExtensionsToggleOnGrantsParentApprovalOnInstallation) { … } // Tests that for extensions installed under the enabled "Extensions" Family // Link toggle the approval remains on installed extensions if the switch is // toggled to false. TEST_P(SupervisedUserExtensionTest, ExtensionsToggleOffDoesNotAffectAlreadyEnabled) { … } // Tests that for extensions installed under the enabled "Extensions" Family // Link, toggling the switch from false to true grants parental approval. TEST_P(SupervisedUserExtensionTest, ExtensionsToggleOnGrantsMissingParentalApproval) { … } // Tests the case when the extension approval arrives through sync before the // extension itself is installed. TEST_P(SupervisedUserExtensionTest, ExtensionApprovalBeforeInstallation) { … } // Tests that when the `SkipParentApprovalToInstallExtensions` feature is first // released (so Extensions are managed by Family Link "Extensions" toggle), // existing extensions remain enabled on Desktop. On ChromeOS they are disabled. TEST_P(SupervisedUserExtensionTest, ExtensionsOnDesktopRemainEnabledOnSkipParentApprovalRelease) { … } // Tests when the `SkipParentApprovalToInstallExtensions` feature is firstly // released (so Extensions are managed by Family Link "Extensions" toggle) // existing extensions that have been marked parent-approved on Desktop by // default can be upgraded without further parental approval. TEST_P(SupervisedUserExtensionTest, ExtensionsEnabledOnSkipParentApprovalReleaseCanBeUpgraded) { … } // Tests that uninstalling a parent-approved extension removes the parental // approval. TEST_P(SupervisedUserExtensionTest, UnistallingRevokesParentApproval) { … } INSTANTIATE_TEST_SUITE_P(…); // Test class for cases that apply only when extension parental controls are // enabled. class SupervisedUserWithEnabledExtensionParentalControlsTest : public SupervisedUserExtensionTestBase, public ::testing::WithParamInterface<ExtensionManagementSwitch> { … }; // Tests that the kApprovalGranted UMA metric only increments once without // duplication for the same extension id. TEST_P(SupervisedUserWithEnabledExtensionParentalControlsTest, DontTriggerMetricsIfAlreadyApproved) { … } // Tests that parent approval is necessary but not sufficient to enable // extensions when both disable reasons custodian_approval_required and // permissions_increase are present. TEST_P(SupervisedUserWithEnabledExtensionParentalControlsTest, ParentApprovalNecessaryButNotSufficient) { … } INSTANTIATE_TEST_SUITE_P(…); } // namespace extensions