chromium/content/public/test/shared_storage_test_utils.h

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_PUBLIC_TEST_SHARED_STORAGE_TEST_UTILS_H_
#define CONTENT_PUBLIC_TEST_SHARED_STORAGE_TEST_UTILS_H_

#include <stddef.h>

#include <string>

#include "base/memory/weak_ptr.h"
#include "base/strings/string_split.h"
#include "components/services/storage/shared_storage/shared_storage_manager.h"
#include "content/browser/private_aggregation/private_aggregation_host.h"
#include "services/network/public/mojom/optional_bool.mojom.h"
#include "services/network/public/mojom/url_loader_network_service_observer.mojom.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "url/origin.h"

class GURL;

namespace content {

class RenderFrameHost;
class SharedStorageWorkletHostManager;
class StoragePartition;
class TestSharedStorageHeaderObserver;

FencedFrameNavigationTarget;
OperationResult;
OperationType;
OperationPtr;

SharedStorageWorkletHostManager*
GetSharedStorageWorkletHostManagerForStoragePartition(
    StoragePartition* storage_partition);

std::string GetSharedStorageDisabledMessage();

std::string GetSharedStorageSelectURLDisabledMessage();

std::string GetSharedStorageAddModuleDisabledMessage();

size_t GetAttachedSharedStorageWorkletHostsCount(
    StoragePartition* storage_partition);

size_t GetKeepAliveSharedStorageWorkletHostsCount(
    StoragePartition* storage_partition);

// TODO(crbug.com/40256120): This function should be removed. Use
// `CreateFencedFrame` in fenced_frame_test_util.h instead.
RenderFrameHost* CreateFencedFrame(RenderFrameHost* root,
                                   const FencedFrameNavigationTarget& target);

[[nodiscard]] network::mojom::OptionalBool AbslToMojomOptionalBool(
    std::optional<bool> opt_bool);

// In order to use gmock matchers, it's necessary to copy the members of
// `OperationPtr` into a copyable struct or tuple. We also bundle them with the
// `request_origin` and `result`.
struct SharedStorageWriteOperationAndResult {};

bool operator==(const SharedStorageWriteOperationAndResult& a,
                const SharedStorageWriteOperationAndResult& b);

PrivateAggregationHost::PipeResult
GetPrivateAggregationHostPipeReportSuccessValue();

PrivateAggregationHost::PipeResult
GetPrivateAggregationHostPipeApiDisabledValue();

base::WeakPtr<TestSharedStorageHeaderObserver>
CreateAndOverrideSharedStorageHeaderObserver(StoragePartition* partition);

base::StringPairs SharedStorageCrossOriginWorkletResponseHeaderReplacement(
    const std::string& access_control_allow_origin_replacement,
    const std::string& shared_storage_cross_origin_allowed_replacement);

}  // namespace content

#endif  // CONTENT_PUBLIC_TEST_SHARED_STORAGE_TEST_UTILS_H_