chromium/chrome/browser/web_applications/test/web_app_test_utils.cc

// 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.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "chrome/browser/web_applications/test/web_app_test_utils.h"

#include <stddef.h>

#include <algorithm>
#include <array>
#include <functional>
#include <iterator>
#include <limits>
#include <optional>
#include <ostream>
#include <random>
#include <set>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

#include "base/base64.h"
#include "base/check.h"
#include "base/check_op.h"
#include "base/containers/flat_set.h"
#include "base/containers/flat_tree.h"
#include "base/containers/span.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/location.h"
#include "base/memory/scoped_refptr.h"
#include "base/numerics/clamped_math.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/test/bind.h"
#include "base/test/test_future.h"
#include "base/time/time.h"
#include "base/values.h"
#include "base/version.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/web_applications/web_app_dialogs.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_integrity_block_data.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_storage_location.h"
#include "chrome/browser/web_applications/mojom/user_display_mode.mojom.h"
#include "chrome/browser/web_applications/proto/web_app.pb.h"
#include "chrome/browser/web_applications/proto/web_app_isolation_data.pb.h"
#include "chrome/browser/web_applications/proto/web_app_os_integration_state.pb.h"
#include "chrome/browser/web_applications/proto/web_app_proto_package.pb.h"
#include "chrome/browser/web_applications/scope_extension_info.h"
#include "chrome/browser/web_applications/test/web_app_test_observers.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/browser/web_applications/web_app_chromeos_data.h"
#include "chrome/browser/web_applications/web_app_command_scheduler.h"
#include "chrome/browser/web_applications/web_app_constants.h"
#include "chrome/browser/web_applications/web_app_helpers.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "chrome/browser/web_applications/web_app_install_utils.h"
#include "chrome/browser/web_applications/web_app_proto_utils.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_registry_update.h"
#include "chrome/browser/web_applications/web_app_sync_bridge.h"
#include "chrome/browser/web_applications/web_app_utils.h"
#include "chrome/common/pref_names.h"
#include "components/base32/base32.h"
#include "components/prefs/pref_service.h"
#include "components/services/app_service/public/cpp/file_handler.h"
#include "components/services/app_service/public/cpp/icon_info.h"
#include "components/services/app_service/public/cpp/protocol_handler_info.h"
#include "components/services/app_service/public/cpp/share_target.h"
#include "components/services/app_service/public/cpp/url_handler_info.h"
#include "components/sync/base/time.h"
#include "components/sync/model/string_ordinal.h"
#include "components/sync/protocol/web_app_specifics.pb.h"
#include "components/webapps/browser/installable/installable_metrics.h"
#include "content/public/browser/service_worker_context.h"
#include "content/public/browser/storage_partition.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "third_party/blink/public/common/manifest/manifest.h"
#include "third_party/blink/public/common/permissions_policy/origin_with_possible_wildcards.h"
#include "third_party/blink/public/common/permissions_policy/permissions_policy_declaration.h"
#include "third_party/blink/public/common/permissions_policy/policy_helper_public.h"
#include "third_party/blink/public/common/safe_url_pattern.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/manifest/capture_links.mojom-shared.h"
#include "third_party/blink/public/mojom/manifest/display_mode.mojom-shared.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom-shared.h"
#include "third_party/blink/public/mojom/manifest/manifest_launch_handler.mojom-shared.h"
#include "third_party/liburlpattern/pattern.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/geometry/size.h"
#include "url/gurl.h"
#include "url/origin.h"

namespace {

std::vector<std::string> test_features =;

constexpr std::string_view kEd25519PublicKeyBase64 =;
constexpr std::string_view kEd25519SignatureHex =;

constexpr std::string_view kEcdsaP256PublicKeyBase64 =;
constexpr std::string_view kEcdsaP256SHA256SignatureHex =;

}  // namespace

namespace web_app {
namespace test {

namespace {

class RandomHelper {};

#define NEXT_PROTO_ENUM(random_helper, T, skip_zero)

apps::FileHandlers CreateRandomFileHandlers(uint32_t suffix) {}

apps::ShareTarget CreateRandomShareTarget(uint32_t suffix) {}

blink::ParsedPermissionsPolicy CreateRandomPermissionsPolicy(
    RandomHelper& random) {}

std::vector<apps::ProtocolHandlerInfo> CreateRandomProtocolHandlers(
    uint32_t suffix) {}

std::vector<apps::UrlHandlerInfo> CreateRandomUrlHandlers(uint32_t suffix) {}

ScopeExtensions CreateRandomScopeExtensions(uint32_t suffix,
                                            RandomHelper& random) {}

std::vector<WebAppShortcutsMenuItemInfo> CreateRandomShortcutsMenuItemInfos(
    const GURL& scope,
    int num,
    RandomHelper& random) {}

std::vector<IconSizes> CreateRandomDownloadedShortcutsMenuIconsSizes(
    int num,
    RandomHelper& random) {}

std::vector<blink::Manifest::ImageResource> CreateRandomHomeTabIcons(
    RandomHelper& random) {}

std::vector<blink::SafeUrlPattern> CreateRandomScopePatterns(
    RandomHelper& random) {}

proto::WebAppOsIntegrationState GenerateRandomWebAppOsIntegrationState(
    RandomHelper& random,
    WebApp& app) {}

std::optional<IsolatedWebAppIntegrityBlockData> CreateIntegrityBlockData(
    RandomHelper& random) {}

}  // namespace

std::unique_ptr<WebApp> CreateWebApp(const GURL& start_url,
                                     WebAppManagement::Type source_type) {}

std::unique_ptr<WebApp> CreateRandomWebApp(CreateRandomWebAppParams params) {}

void TestAcceptDialogCallback(
    content::WebContents* initiator_web_contents,
    std::unique_ptr<WebAppInstallInfo> web_app_info,
    WebAppInstallationAcceptanceCallback acceptance_callback) {}

void TestDeclineDialogCallback(
    content::WebContents* initiator_web_contents,
    std::unique_ptr<WebAppInstallInfo> web_app_info,
    WebAppInstallationAcceptanceCallback acceptance_callback) {}

// TODO(b/329703817): Make this smarter by waiting for a specific dialog, and
// then triggering accept on the dialog.
webapps::AppId InstallPwaForCurrentUrl(Browser* browser) {}

void CheckServiceWorkerStatus(const GURL& url,
                              content::StoragePartition* storage_partition,
                              content::ServiceWorkerCapability status) {}

void SetWebAppSettingsListPref(Profile* profile, const std::string_view pref) {}

void AddInstallUrlData(PrefService* pref_service,
                       WebAppSyncBridge* sync_bridge,
                       const webapps::AppId& app_id,
                       const GURL& url,
                       const ExternalInstallSource& source) {}

void AddInstallUrlAndPlaceholderData(PrefService* pref_service,
                                     WebAppSyncBridge* sync_bridge,
                                     const webapps::AppId& app_id,
                                     const GURL& url,
                                     const ExternalInstallSource& source,
                                     bool is_placeholder) {}

void SynchronizeOsIntegration(Profile* profile,
                              const webapps::AppId& app_id,
                              std::optional<SynchronizeOsOptions> options) {}

std::vector<web_package::SignedWebBundleSignatureInfo> CreateSignatures() {}

#if BUILDFLAG(IS_CHROMEOS_LACROS)
ScopedSkipMainProfileCheck::ScopedSkipMainProfileCheck() {
  EXPECT_FALSE(IsMainProfileCheckSkippedForTesting());
  SetSkipMainProfileCheckForTesting(/*skip_check=*/true);
}

ScopedSkipMainProfileCheck::~ScopedSkipMainProfileCheck() {
  SetSkipMainProfileCheckForTesting(/*skip_check=*/false);
}
#endif

}  // namespace test
}  // namespace web_app