chromium/content/browser/interest_group/auction_worklet_manager_unittest.cc

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

#include "content/services/auction_worklet/public/mojom/auction_worklet_service.mojom-forward.h"
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/342213636): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif

#include <stdint.h>

#include <list>
#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "base/check.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/test/test_future.h"
#include "base/time/time.h"
#include "content/browser/interest_group/auction_metrics_recorder.h"
#include "content/browser/interest_group/auction_process_manager.h"
#include "content/browser/interest_group/auction_worklet_manager.h"
#include "content/browser/interest_group/subresource_url_authorizations.h"
#include "content/browser/interest_group/subresource_url_builder.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/test_renderer_host.h"
#include "content/services/auction_worklet/public/mojom/auction_network_events_handler.mojom.h"
#include "content/services/auction_worklet/public/mojom/auction_shared_storage_host.mojom.h"
#include "content/services/auction_worklet/public/mojom/auction_worklet_service.mojom.h"
#include "content/services/auction_worklet/public/mojom/bidder_worklet.mojom.h"
#include "content/services/auction_worklet/public/mojom/seller_worklet.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/functions.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "services/network/public/mojom/client_security_state.mojom.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/interest_group/ad_display_size.h"
#include "third_party/blink/public/common/interest_group/auction_config.h"
#include "url/gurl.h"
#include "url/origin.h"

UnorderedElementsAre;

namespace content {
class ProcessHandleTestPeer {};

namespace {

const char kAuction1[] =;
const char kAuction2[] =;
const char kAuction3[] =;
const char kAuction4[] =;
const char kAuction5[] =;

BundleSubresourceInfo;

constexpr char kBuyer1OriginStr[] =;
constexpr char kBuyer2OriginStr[] =;

AuctionWorkletManager::FatalErrorCallback NeverInvokedFatalErrorCallback() {}

blink::DirectFromSellerSignalsSubresource CreateSubresource(
    const GURL& bundle_url) {}

blink::DirectFromSellerSignals PopulateSubresources() {}

// Single-use helper for waiting for a load error and inspecting its data.
class FatalLoadErrorHelper {};

// BidderWorklet that holds onto passed in callbacks, to let the test fixture
// invoke them.
class MockBidderWorklet : public auction_worklet::mojom::BidderWorklet {};

// SellerWorklet that holds onto passed in callbacks, to let the test fixture
// invoke them.
class MockSellerWorklet : public auction_worklet::mojom::SellerWorklet {};

// AuctionProcessManager and AuctionWorkletService - combining the two with a
// mojo::ReceiverSet makes it easier to track which call came over which
// receiver than using separate classes.
class MockAuctionProcessManager
    : public AuctionProcessManager,
      public auction_worklet::mojom::AuctionWorkletService {};

class AuctionWorkletManagerTest : public RenderViewHostTestHarness,
                                  public AuctionWorkletManager::Delegate {};

TEST_F(AuctionWorkletManagerTest, SingleBidderWorklet) {}

TEST_F(AuctionWorkletManagerTest, SingleSellerWorklet) {}

TEST_F(AuctionWorkletManagerTest,
       SingleBidderWorkletEmptyDirectFromSellerSignals) {}

TEST_F(AuctionWorkletManagerTest,
       SingleSellerWorkletEmptyDirectFromSellerSignals) {}

// Test the case where a process assignment completes asynchronously. This
// only happens when the BidderWorklet process limit has been reached. This test
// also serves to make sure that different bidder origins result in different
// processes.
TEST_F(AuctionWorkletManagerTest, BidderWorkletAsync) {}

// Test the case where  a process assignment completes asynchronously. This
// only happens when the SellerWorklet process limit has been reached. This test
// also serves to make sure that different seller origins result in different
// processes.
TEST_F(AuctionWorkletManagerTest, SellerWorkletAsync) {}

// Test that requests with the same parameters reuse bidder worklets.
TEST_F(AuctionWorkletManagerTest, ReuseBidderWorklet) {}

// Test that requests with the same parameters reuse seller worklets.
TEST_F(AuctionWorkletManagerTest, ReuseSellerWorklet) {}

// Make sure that worklets are not reused when parameters don't match.
TEST_F(AuctionWorkletManagerTest, DifferentBidderWorklets) {}

// Test bidder worklet matching with different experiment IDs.
TEST_F(AuctionWorkletManagerTest, BidderWorkletExperimentIDs) {}

// Test bidder worklet matching with different CORS mode.
TEST_F(AuctionWorkletManagerTest, BidderWorkletCORSForAdditionalBid) {}

// Make sure that worklets are not reused when parameters don't match.
TEST_F(AuctionWorkletManagerTest, DifferentSellerWorklets) {}

// Test seller worklet matching with different experiment IDs.
TEST_F(AuctionWorkletManagerTest, SellerWorkletExperimentIDs) {}

TEST_F(AuctionWorkletManagerTest, BidderWorkletLoadError) {}

// Make sure that errors that occur when some worklets haven't gotten
// their success callbacks yet work right.
TEST_F(AuctionWorkletManagerTest, LoadErrorWithoutProcessAssigned) {}

// Make sure that success callbacks are ordered properly.
TEST_F(AuctionWorkletManagerTest, LoadSuccessOrder) {}

TEST_F(AuctionWorkletManagerTest, SellerWorkletLoadError) {}

TEST_F(AuctionWorkletManagerTest, BidderWorkletCrash) {}

TEST_F(AuctionWorkletManagerTest, SellerWorkletCrash) {}

// Test reentrant deletion of a WorkletHandle on error.
TEST_F(AuctionWorkletManagerTest, BidderWorkletDeleteOnError) {}

// Test re-entrant deletion of a WorkletHandle on success, and following
// failure on the same worklet.
TEST_F(AuctionWorkletManagerTest, BidderWorkletDeleteOnSuccess) {}

// Test reentrant deletion of a WorkletHandle on error.
TEST_F(AuctionWorkletManagerTest, SellerWorkletDeleteOnError) {}

// Minimal test that bidder worklets' AuctionURLLoaderFactoryProxies are
// correctly configured.
TEST_F(AuctionWorkletManagerTest, BidderWorkletUrlRequestProtection) {}

// Minimal test that seller worklets' AuctionURLLoaderFactoryProxies are
// correctly configured.
TEST_F(AuctionWorkletManagerTest, SellerWorkletUrlRequestProtection) {}

TEST(WorkletKeyTest, HashConsistentForEqualKeys) {}

TEST(WorkletKeyTest, HashIsDifferentForKeysWithDifferentType) {}

TEST(WorkletKeyTest, HashIsDifferentForKeysWithDifferentScriptUrl) {}

TEST(WorkletKeyTest, HashIsDifferentForKeysWithDifferentWasmUrl) {}

TEST(WorkletKeyTest, HashIsDifferentWhenGivenNullOptWasmUrl) {}

TEST(WorkletKeyTest, HashIsDifferentForKeysWithDifferentSignalsUrl) {}

TEST(WorkletKeyTest, HashIsDifferentWhenGivenNullOptSignalsUrl) {}

TEST(WorkletKeyTest, HashIsDifferentForKeysWithDifferentExperiment) {}

TEST(WorkletKeyTest, HashIsDifferentWhenGivenNullOptExperiment) {}

TEST(WorkletKeyTest, HashIsDifferentForKeysWithDifferentCORSForAdditionalBid) {}

TEST(WorkletKeyTest, HashIsSameForDifferentSlotSizeParamWhenNoSignalsUrl) {}

TEST(WorkletKeyTest, HashIsDifferentForDifferentSlotSizeParamWithSignalsUrl) {}

TEST(WorkletKeyTest, HashIsDifferentForKeysWithDifferentCoordinator) {}

TEST(WorkletKeyTest, HashIsDifferentWhenGivenNullOptCoordinator) {}

TEST_F(AuctionWorkletManagerTest,
       DoesNotCrashWhenProcessReadyAfterWorkletDestroyed) {}

}  // namespace
}  // namespace content