#include "chrome/browser/extensions/api/developer_private/developer_private_api.h"
#include <memory>
#include <string_view>
#include <utility>
#include "base/base_paths.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/json/json_writer.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/path_service.h"
#include "base/scoped_observation.h"
#include "base/stl_util.h"
#include "base/strings/strcat.h"
#include "base/strings/stringprintf.h"
#include "base/test/bind.h"
#include "base/test/gtest_util.h"
#include "base/test/values_test_util.h"
#include "base/values.h"
#include "chrome/browser/extensions/api/developer_private/extension_info_generator.h"
#include "chrome/browser/extensions/chrome_test_extension_loader.h"
#include "chrome/browser/extensions/error_console/error_console.h"
#include "chrome/browser/extensions/extension_action_test_util.h"
#include "chrome/browser/extensions/extension_install_prompt_show_params.h"
#include "chrome/browser/extensions/extension_management.h"
#include "chrome/browser/extensions/extension_management_test_util.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_service_test_with_install.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/manifest_v2_experiment_manager.h"
#include "chrome/browser/extensions/permissions/permissions_test_util.h"
#include "chrome/browser/extensions/permissions/permissions_updater.h"
#include "chrome/browser/extensions/permissions/scripting_permissions_modifier.h"
#include "chrome/browser/extensions/permissions/site_permissions_helper.h"
#include "chrome/browser/supervised_user/supervised_user_browser_utils.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/extensions/extension_install_ui.h"
#include "chrome/browser/ui/toolbar/toolbar_actions_model.h"
#include "chrome/common/extensions/api/developer_private.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/test_browser_window.h"
#include "chrome/test/base/testing_profile.h"
#include "components/crx_file/id_util.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/supervised_user/core/common/features.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/web_contents_tester.h"
#include "extensions/browser/api_test_utils.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/event_router_factory.h"
#include "extensions/browser/extension_dialog_auto_confirm.h"
#include "extensions/browser/extension_error_test_util.h"
#include "extensions/browser/extension_function_dispatcher.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/mock_external_provider.h"
#include "extensions/browser/permissions_manager.h"
#include "extensions/browser/test_event_router_observer.h"
#include "extensions/browser/test_extension_registry_observer.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/manifest_constants.h"
#include "extensions/common/mojom/context_type.mojom.h"
#include "extensions/common/permissions/permission_set.h"
#include "extensions/common/permissions/permissions_data.h"
#include "extensions/test/test_extension_dir.h"
#include "services/data_decoder/data_decoder_service.h"
#include "services/service_manager/public/cpp/test/test_connector_factory.h"
#include "ui/shell_dialogs/selected_file_info.h"
namespace extensions {
namespace {
const char kGoodCrx[] = …;
const char kGoogleOnlyCrx[] = …;
constexpr char kInvalidHost[] = …;
constexpr char kInvalidHostError[] = …;
std::unique_ptr<KeyedService> BuildAPI(content::BrowserContext* context) { … }
std::unique_ptr<KeyedService> BuildEventRouter(
content::BrowserContext* profile) { … }
bool HasPrefsPermission(bool (*has_pref)(const ExtensionId&,
content::BrowserContext*),
content::BrowserContext* context,
const ExtensionId& id) { … }
bool WasItemChangedEventDispatched(
const TestEventRouterObserver& observer,
const ExtensionId& extension_id,
const api::developer_private::EventType event_type) { … }
bool WasUserSiteSettingsChangedEventDispatched(
const TestEventRouterObserver& observer,
api::developer_private::UserSiteSettings* settings) { … }
void AddUserSpecifiedSites(Profile* profile,
const std::string& hosts,
bool restricted) { … }
void RemoveUserSpecifiedSites(Profile* profile,
const std::string& hosts,
bool restricted) { … }
void AddExtensionAndGrantPermissions(Profile* profile,
ExtensionService* service,
const Extension& extension) { … }
void RunAddHostPermission(Profile* profile,
const Extension& extension,
std::string_view host,
bool should_succeed,
const char* expected_error) { … }
void GetMatchingExtensionsForSite(
Profile* profile,
const std::string& site,
std::vector<api::developer_private::MatchingExtensionInfo>* infos) { … }
auto MatchMatchingExtensionInfo(
const ExtensionId& extension_id,
const api::developer_private::HostAccess& host_access,
bool can_request_all_sites) { … }
api::developer_private::ExtensionSiteAccessUpdate CreateSiteAccessUpdate(
const ExtensionId& id,
api::developer_private::HostAccess access) { … }
void UpdateSiteAccess(
Profile* profile,
const std::string& site,
const std::vector<api::developer_private::ExtensionSiteAccessUpdate>&
updates) { … }
}
class DeveloperPrivateApiUnitTest : public ExtensionServiceTestWithInstall { … };
bool DeveloperPrivateApiUnitTest::RunFunction(
const scoped_refptr<ExtensionFunction>& function,
const base::Value::List& args) { … }
const Extension* DeveloperPrivateApiUnitTest::LoadUnpackedExtension() { … }
const Extension* DeveloperPrivateApiUnitTest::LoadSimpleExtension() { … }
void DeveloperPrivateApiUnitTest::TestExtensionPrefSetting(
const base::RepeatingCallback<bool()>& has_pref,
const std::string& key,
const ExtensionId& extension_id,
bool expected_default_value) { … }
testing::AssertionResult DeveloperPrivateApiUnitTest::TestPackExtensionFunction(
const base::Value::List& args,
api::developer_private::PackStatus expected_status,
int expected_flags) { … }
void DeveloperPrivateApiUnitTest::UpdateProfileConfigurationDevMode(
bool dev_mode) { … }
void DeveloperPrivateApiUnitTest::GetProfileConfiguration(
std::optional<api::developer_private::ProfileInfo>* profile_info) { … }
void DeveloperPrivateApiUnitTest::RunUpdateHostAccess(
const Extension& extension,
std::string_view new_access) { … }
void DeveloperPrivateApiUnitTest::SetUp() { … }
void DeveloperPrivateApiUnitTest::TearDown() { … }
TEST_F(DeveloperPrivateApiUnitTest,
DeveloperPrivateUpdateExtensionConfiguration) { … }
TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateReload) { … }
TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivatePackFunction) { … }
TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateChoosePath) { … }
TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateLoadUnpacked) { … }
TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateLoadUnpackedLoadError) { … }
TEST_F(DeveloperPrivateApiUnitTest, LoadUnpackedRetryId) { … }
TEST_F(DeveloperPrivateApiUnitTest, ReloadBadExtensionToLoadUnpackedRetry) { … }
TEST_F(DeveloperPrivateApiUnitTest,
DeveloperPrivateNotifyDragInstallInProgress) { … }
TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateRequestFileSource) { … }
TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateGetExtensionsInfo) { … }
TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateDeleteExtensionErrors) { … }
TEST_F(DeveloperPrivateApiUnitTest, RepairNotBrokenExtension) { … }
TEST_F(DeveloperPrivateApiUnitTest, RepairPolicyExtension) { … }
TEST_F(DeveloperPrivateApiUnitTest, RepairNonCWSExtension) { … }
TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateDevModeDisabledPolicy) { … }
TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateDevMode) { … }
TEST_F(DeveloperPrivateApiUnitTest, LoadUnpackedFailsWithoutDevMode) { … }
TEST_F(DeveloperPrivateApiUnitTest, LoadUnpackedFailsWithBlocklistingPolicy) { … }
TEST_F(DeveloperPrivateApiUnitTest,
LoadUnpackedWorksWithBlocklistingPolicyAlongAllowlistingPolicy) { … }
TEST_F(DeveloperPrivateApiUnitTest, InstallDroppedFileNoDraggedPath) { … }
TEST_F(DeveloperPrivateApiUnitTest, InstallDroppedFileCrx) { … }
TEST_F(DeveloperPrivateApiUnitTest, InstallDroppedFileUserScript) { … }
TEST_F(DeveloperPrivateApiUnitTest, GrantHostPermission) { … }
TEST_F(DeveloperPrivateApiUnitTest, RemoveHostPermission) { … }
TEST_F(DeveloperPrivateApiUnitTest, UpdateHostAccess) { … }
TEST_F(DeveloperPrivateApiUnitTest,
UpdateHostAccess_SpecificSitesRemovedOnTransitionToOnClick) { … }
TEST_F(DeveloperPrivateApiUnitTest,
UpdateHostAccess_SpecificSitesRemovedOnTransitionToAllSites) { … }
TEST_F(DeveloperPrivateApiUnitTest,
UpdateHostAccess_BroadPermissionsRemovedOnTransitionToSpecificSites) { … }
TEST_F(DeveloperPrivateApiUnitTest,
UpdateHostAccess_GrantScopeGreaterThanRequestedScope) { … }
TEST_F(DeveloperPrivateApiUnitTest,
UpdateHostAccess_UnrequestedHostsDispatchUpdateEvents) { … }
TEST_F(DeveloperPrivateApiUnitTest, ExtensionUpdatedEventOnPermissionsChange) { … }
class DeveloperPrivateApiZipFileUnitTest
: public DeveloperPrivateApiUnitTest,
public testing::WithParamInterface<bool> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(DeveloperPrivateApiZipFileUnitTest, InstallDroppedFileZip) { … }
TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateGetUserSiteSettings) { … }
TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateModifyUserSiteSettings) { … }
TEST_F(DeveloperPrivateApiUnitTest, OnUserSiteSettingsChanged) { … }
class DeveloperPrivateApiWithPermittedSitesUnitTest
: public DeveloperPrivateApiUnitTest { … };
DeveloperPrivateApiWithPermittedSitesUnitTest::
DeveloperPrivateApiWithPermittedSitesUnitTest() { … }
TEST_F(DeveloperPrivateApiWithPermittedSitesUnitTest,
DeveloperPrivateGetUserSiteSettings) { … }
TEST_F(DeveloperPrivateApiWithPermittedSitesUnitTest,
DeveloperPrivateModifyUserSiteSettings) { … }
TEST_F(DeveloperPrivateApiWithPermittedSitesUnitTest,
DeveloperPrivateGetUserAndExtensionSitesByEtld_UserSites) { … }
TEST_F(DeveloperPrivateApiWithPermittedSitesUnitTest,
DeveloperPrivateGetUserAndExtensionSitesByEtld_UserAndExtensionSites) { … }
TEST_F(DeveloperPrivateApiWithPermittedSitesUnitTest,
DeveloperPrivateGetUserAndExtensionSitesByEtld_EffectiveAllHosts) { … }
TEST_F(DeveloperPrivateApiUnitTest,
DeveloperPrivateGetUserAndExtensionSitesByEtld_RuntimeGrantedHosts) { … }
TEST_F(
DeveloperPrivateApiUnitTest,
DeveloperPrivateGetUserAndExtensionSitesByEtld_PolicyControlledExtensions) { … }
TEST_F(DeveloperPrivateApiUnitTest,
DeveloperPrivateGetMatchingExtensionsForSite) { … }
TEST_F(DeveloperPrivateApiUnitTest,
DeveloperPrivateGetMatchingExtensionsForSite_RuntimeGrantedHostAccess) { … }
TEST_F(DeveloperPrivateApiUnitTest,
DeveloperPrivateUpdateSiteAccess_NoWithheldHostPermissions) { … }
TEST_F(DeveloperPrivateApiUnitTest,
DeveloperPrivateUpdateSiteAccess_WitheldHostPermissions) { … }
TEST_F(DeveloperPrivateApiUnitTest,
DeveloperPrivateUpdateSiteAccess_MultipleExtensions) { … }
TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateRemoveMultipleExtensions) { … }
TEST_F(DeveloperPrivateApiUnitTest,
DeveloperPrivateCancelRemoveMultipleExtensions) { … }
TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateRemoveComponentExtensions) { … }
TEST_F(DeveloperPrivateApiUnitTest,
DeveloperPrivateRemoveEnterpriseExtensions) { … }
TEST_F(DeveloperPrivateApiUnitTest,
ExtensionUpdatedEventOnPinnedActionsChange) { … }
class DeveloperPrivateApiAllowlistUnitTest
: public DeveloperPrivateApiUnitTest { … };
TEST_F(DeveloperPrivateApiAllowlistUnitTest,
ExtensionUpdatedEventOnAllowlistWarningChange) { … }
class DeveloperPrivateApiSupervisedUserUnitTest
: public DeveloperPrivateApiUnitTest,
public testing::WithParamInterface<bool> { … };
TEST_P(DeveloperPrivateApiSupervisedUserUnitTest,
LoadUnpackedFailsForSupervisedUsers) { … }
INSTANTIATE_TEST_SUITE_P(…);
class DeveloperPrivateApiWithMV2DeprecationWarningUnitTest
: public DeveloperPrivateApiUnitTest { … };
class DeveloperPrivateApiWithMV2DeprecationDisabledUnitTest
: public DeveloperPrivateApiUnitTest { … };
TEST_F(DeveloperPrivateApiWithMV2DeprecationWarningUnitTest,
TestAcknowledgingAnExtension) { … }
TEST_F(DeveloperPrivateApiWithMV2DeprecationWarningUnitTest,
TestAcknowledgingANonAffectedExtension) { … }
TEST_F(DeveloperPrivateApiWithMV2DeprecationWarningUnitTest,
TestAcknowledgingNoticeGlobally) { … }
TEST_F(DeveloperPrivateApiWithMV2DeprecationDisabledUnitTest,
TestAcknowledgingAnExtension) { … }
}