chromium/services/network/shared_storage/shared_storage_test_utils.h

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

#ifndef SERVICES_NETWORK_SHARED_STORAGE_SHARED_STORAGE_TEST_UTILS_H_
#define SERVICES_NETWORK_SHARED_STORAGE_SHARED_STORAGE_TEST_UTILS_H_

#include <optional>
#include <string>
#include <utility>
#include <vector>

#include "net/test/embedded_test_server/embedded_test_server.h"

namespace network {

static constexpr char kSharedStoragePathPrefix[] =;
static constexpr char kSharedStorageWritePathSuffix[] =;
static constexpr char kSharedStorageTestPath[] =;
static constexpr char kSharedStorageBypassPath[] =;
static constexpr char kSharedStorageRedirectPath[] =;
static constexpr char kSharedStorageResponseData[] =;

std::string MakeSharedStorageTestPath();
std::string MakeSharedStorageBypassPath();
std::string MakeSharedStorageRedirectPrefix();

class SharedStorageRequestCount {};

class SharedStorageResponse : public net::test_server::BasicHttpResponse {};

// Sends a response with the "Shared-Storage-Write" header, with value
// `shared_storage_write`, to any request whose path starts with the
// `kSharedStoragePathPrefix` prefix and which has the
// "Sec-Shared-Storage-Writable: ?1" request header or whose full path is
// `MakeSharedStorageBypassPath()`.
std::unique_ptr<net::test_server::HttpResponse>
HandleSharedStorageRequestSimple(std::string shared_storage_write,
                                 const net::test_server::HttpRequest& request);

// Sends a response with the "Shared-Storage-Write" header, with the next
// available value in `shared_storage_write_headers` as tracked by
// `SharedStorageRequestCount`, to any request whose path starts with the
// `kSharedStoragePathPrefix` prefix and ends with the
// `kSharedStorageWritePathSuffix` and which has the
// "Sec-Shared-Storage-Writable: ?1" request header, as long as
// `shared_storage_write_headers` has not yet been fully iterated through..
std::unique_ptr<net::test_server::HttpResponse>
HandleSharedStorageRequestMultiple(
    std::vector<std::string> shared_storage_write_headers,
    const net::test_server::HttpRequest& request);

}  // namespace network

#endif  // SERVICES_NETWORK_SHARED_STORAGE_SHARED_STORAGE_TEST_UTILS_H_