chromium/chrome/browser/extensions/extension_browsertest.cc

// Copyright 2012 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/extension_browsertest.h"

#include <stddef.h>

#include <memory>
#include <optional>
#include <utility>
#include <vector>

#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/json/json_file_value_serializer.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/test_future.h"
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/apps/app_service/app_launch_params.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/apps/app_service/browser_app_launcher.h"
#include "chrome/browser/extensions/browsertest_util.h"
#include "chrome/browser/extensions/chrome_extension_test_notification_observer.h"
#include "chrome/browser/extensions/chrome_test_extension_loader.h"
#include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/extension_install_prompt.h"
#include "chrome/browser/extensions/extension_install_prompt_show_params.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/load_error_reporter.h"
#include "chrome/browser/extensions/unpacked_installer.h"
#include "chrome/browser/extensions/updater/extension_updater.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/webui/theme_source.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "components/crx_file/crx_verifier.h"
#include "components/services/app_service/public/cpp/app_launch_util.h"
#include "components/sync/model/string_ordinal.h"
#include "components/version_info/version_info.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/url_data_source.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/browsertest_util.h"
#include "extensions/browser/disable_reason.h"
#include "extensions/browser/extension_dialog_auto_confirm.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/service_worker/service_worker_test_utils.h"
#include "extensions/browser/test_extension_registry_observer.h"
#include "extensions/browser/uninstall_reason.h"
#include "extensions/browser/updater/extension_cache_fake.h"
#include "extensions/common/api/web_accessible_resources.h"
#include "extensions/common/api/web_accessible_resources_mv2.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/file_util.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/manifest_handlers/background_info.h"
#include "extensions/common/switches.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/constants/ash_switches.h"
#endif

ManifestLocation;

namespace extensions {

TestServiceWorkerContextObserver;

namespace {

// Maps all chrome-extension://<id>/_test_resources/foo requests to
// <test_dir_root>/foo or <test_dir_gen_root>/foo, where |test_dir_gen_root| is
// inferred from <test_dir_root>. The latter is triggered only if the first path
// does not correspond to an existing file. This is what allows us to share code
// between tests without needing to duplicate files in each extension.
// Example invocation #1, where the requested file exists in |test_dir_root|
//   Input:
//     test_dir_root: /abs/path/src/chrome/test/data
//     directory_path: /abs/path/src/out/<out_dir>/resources/pdf
//     relative_path: _test_resources/webui/test_browser_proxy.js
//   Output:
//     directory_path: /abs/path/src/chrome/test/data
//     relative_path: webui/test_browser_proxy.js
//
// Example invocation #2, where the requested file exists in |test_dir_gen_root|
//   Input:
//     test_dir_root: /abs/path/src/chrome/test/data
//     directory_path: /abs/path/src/out/<out_dir>/resources/pdf
//     relative_path: _test_resources/webui/test_browser_proxy.js
//   Output:
//     directory_path: /abs/path/src/out/<out_dir>/gen/chrome/test/data
//     relative_path: webui/test_browser_proxy.js
void ExtensionProtocolTestResourcesHandler(const base::FilePath& test_dir_root,
                                           base::FilePath* directory_path,
                                           base::FilePath* relative_path) {}

// Creates a copy of `source` within `temp_dir` and populates `out` with the
// destination path. Returns true on success.
bool CreateTempDirectoryCopy(const base::FilePath& temp_dir,
                             const base::FilePath& source,
                             base::FilePath* out) {}

// Moves match patterns from the `permissions_key` list to the
// `host_permissions_key` list.
void DoMoveHostPermissions(base::Value::Dict& manifest_dict,
                           const char* permissions_key,
                           const char* host_permissions_key) {}

// Moves match patterns from permissions/optional_permissions to the
// host_permissions/optional_host_permissions.
void MoveHostPermissions(base::Value::Dict& manifest_dict) {}

web_accessible_resource;

// Upgrades MV2 format to MV3 format.
void UpgradeWebAccessibleResources(base::Value::Dict& manifest_dict) {}

// Modifies `manifest_dict` changing its manifest version to 3.
bool ModifyManifestForManifestVersion3(base::Value::Dict& manifest_dict) {}

// Modifies extension at `extension_root` and its `manifest_dict` converting it
// to a service worker based extension.
// NOTE: The conversion works only for extensions with background.scripts and
// requires the background.persistent key. The background.page key is not
// supported.
bool ModifyExtensionForServiceWorker(const base::FilePath& extension_root,
                                     base::Value::Dict& manifest_dict) {}

}  // namespace

ExtensionBrowserTest::ExtensionBrowserTest(ContextType context_type)
    :{}

ExtensionBrowserTest::~ExtensionBrowserTest() {}

ExtensionService* ExtensionBrowserTest::extension_service() {}

ExtensionRegistry* ExtensionBrowserTest::extension_registry() {}

void ExtensionBrowserTest::OnExtensionLoaded(
    content::BrowserContext* browser_context,
    const Extension* extension) {}

void ExtensionBrowserTest::OnShutdown(ExtensionRegistry* registry) {}

Profile* ExtensionBrowserTest::profile() {}

bool ExtensionBrowserTest::ShouldEnableContentVerification() {}

bool ExtensionBrowserTest::ShouldEnableInstallVerification() {}

bool ExtensionBrowserTest::ShouldAllowMV2Extensions() {}

base::FilePath ExtensionBrowserTest::GetTestResourcesParentDir() {}

// static
const Extension* ExtensionBrowserTest::GetExtensionByPath(
    const ExtensionSet& extensions,
    const base::FilePath& path) {}

void ExtensionBrowserTest::SetUp() {}

void ExtensionBrowserTest::SetUpCommandLine(base::CommandLine* command_line) {}

void ExtensionBrowserTest::SetUpOnMainThread() {}

void ExtensionBrowserTest::TearDownOnMainThread() {}

const Extension* ExtensionBrowserTest::LoadExtension(
    const base::FilePath& path) {}

const Extension* ExtensionBrowserTest::LoadExtension(
    const base::FilePath& path,
    const LoadOptions& options) {}

const Extension* ExtensionBrowserTest::LoadExtensionAsComponentWithManifest(
    const base::FilePath& path,
    const base::FilePath::CharType* manifest_relative_path) {}

const Extension* ExtensionBrowserTest::LoadExtensionAsComponent(
    const base::FilePath& path) {}

const Extension* ExtensionBrowserTest::LoadAndLaunchApp(
    const base::FilePath& path,
    bool uses_guest_view) {}

Browser* ExtensionBrowserTest::LaunchAppBrowser(const Extension* extension) {}

base::FilePath ExtensionBrowserTest::PackExtension(
    const base::FilePath& dir_path,
    int extra_run_flags) {}

base::FilePath ExtensionBrowserTest::PackExtensionWithOptions(
    const base::FilePath& dir_path,
    const base::FilePath& crx_path,
    const base::FilePath& pem_path,
    const base::FilePath& pem_out_path,
    int extra_run_flags) {}

const Extension* ExtensionBrowserTest::UpdateExtensionWaitForIdle(
    const extensions::ExtensionId& id,
    const base::FilePath& path,
    std::optional<int> expected_change) {}

const Extension* ExtensionBrowserTest::InstallExtensionFromWebstore(
    const base::FilePath& path,
    std::optional<int> expected_change) {}

const Extension* ExtensionBrowserTest::InstallOrUpdateExtension(
    const extensions::ExtensionId& id,
    const base::FilePath& path,
    InstallUIType ui_type,
    std::optional<int> expected_change) {}

const Extension* ExtensionBrowserTest::InstallOrUpdateExtension(
    const extensions::ExtensionId& id,
    const base::FilePath& path,
    InstallUIType ui_type,
    std::optional<int> expected_change,
    Browser* browser,
    Extension::InitFromValueFlags creation_flags) {}

const Extension* ExtensionBrowserTest::InstallOrUpdateExtension(
    const extensions::ExtensionId& id,
    const base::FilePath& path,
    InstallUIType ui_type,
    std::optional<int> expected_change,
    ManifestLocation install_source) {}

const Extension* ExtensionBrowserTest::InstallOrUpdateExtension(
    const extensions::ExtensionId& id,
    const base::FilePath& path,
    InstallUIType ui_type,
    std::optional<int> expected_change,
    ManifestLocation install_source,
    Browser* browser,
    Extension::InitFromValueFlags creation_flags,
    bool install_immediately,
    bool grant_permissions) {}

void ExtensionBrowserTest::ReloadExtension(
    const extensions::ExtensionId& extension_id) {}

void ExtensionBrowserTest::UnloadExtension(
    const extensions::ExtensionId& extension_id) {}

void ExtensionBrowserTest::UninstallExtension(
    const extensions::ExtensionId& extension_id) {}

void ExtensionBrowserTest::DisableExtension(
    const extensions::ExtensionId& extension_id) {}

void ExtensionBrowserTest::EnableExtension(
    const extensions::ExtensionId& extension_id) {}

bool ExtensionBrowserTest::WaitForPageActionVisibilityChangeTo(int count) {}

bool ExtensionBrowserTest::WaitForExtensionViewsToLoad() {}

bool ExtensionBrowserTest::WaitForExtensionIdle(
    const extensions::ExtensionId& extension_id) {}

bool ExtensionBrowserTest::WaitForExtensionNotIdle(
    const extensions::ExtensionId& extension_id) {}

void ExtensionBrowserTest::OpenWindow(content::WebContents* contents,
                                      const GURL& url,
                                      bool newtab_process_should_equal_opener,
                                      bool should_succeed,
                                      content::WebContents** newtab_result) {}

bool ExtensionBrowserTest::NavigateInRenderer(content::WebContents* contents,
                                              const GURL& url) {}

ExtensionHost* ExtensionBrowserTest::FindHostWithPath(ProcessManager* manager,
                                                      const std::string& path,
                                                      int expected_hosts) {}

base::Value ExtensionBrowserTest::ExecuteScriptInBackgroundPage(
    const extensions::ExtensionId& extension_id,
    const std::string& script,
    browsertest_util::ScriptUserActivation script_user_activation) {}

std::string ExtensionBrowserTest::ExecuteScriptInBackgroundPageDeprecated(
    const extensions::ExtensionId& extension_id,
    const std::string& script,
    browsertest_util::ScriptUserActivation script_user_activation) {}

bool ExtensionBrowserTest::ExecuteScriptInBackgroundPageNoWait(
    const extensions::ExtensionId& extension_id,
    const std::string& script,
    browsertest_util::ScriptUserActivation script_user_activation) {}

content::ServiceWorkerContext* ExtensionBrowserTest::GetServiceWorkerContext() {}

// static
content::ServiceWorkerContext* ExtensionBrowserTest::GetServiceWorkerContext(
    content::BrowserContext* browser_context) {}

bool ExtensionBrowserTest::ModifyExtensionIfNeeded(
    const LoadOptions& options,
    const base::FilePath& input_path,
    base::FilePath* out_path) {}

}  // namespace extensions