chromium/content/browser/interest_group/auction_process_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/browser/interest_group/auction_process_manager.h"

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

#include "base/check.h"
#include "base/functional/callback.h"
#include "base/notreached.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/test/bind.h"
#include "base/test/scoped_command_line.h"
#include "base/test/scoped_feature_list.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/common/features.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/site_isolation_mode.h"
#include "content/public/browser/site_isolation_policy.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_browser_context.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-forward.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 "content/test/test_content_browser_client.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#include "url/origin.h"

namespace content {
namespace {

// Alias constants to improve readability.
const size_t kMaxSellerProcesses =;
const size_t kMaxBidderProcesses =;

class TestAuctionProcessManager
    : public AuctionProcessManager,
      public auction_worklet::mojom::AuctionWorkletService {};

class AuctionProcessManagerTest
    : public testing::TestWithParam<AuctionProcessManager::WorkletType> {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(AuctionProcessManagerTest, Basic) {}

// Make sure requests for different origins don't share processes, nor do
// sellers and bidders.
//
// This test doesn't use the parameterization, but using TEST_F() for a single
// test would require another test fixture, and so would add more complexity
// than it's worth, for only a single unit test.
TEST_P(AuctionProcessManagerTest, MultipleRequestsForDifferentProcesses) {}

TEST_P(AuctionProcessManagerTest, MultipleRequestsForSameProcess) {}

// Test requesting and releasing worklet processes, exceeding the limit. This
// test does not cover the case of multiple requests sharing the same process,
// which is covered by the next test.
TEST_P(AuctionProcessManagerTest, LimitExceeded) {}

// Check the process sharing logic - specifically, that requests share processes
// when origins match, and that handles that share a process only count once
// towrads the process limit the process limit.
TEST_P(AuctionProcessManagerTest, ProcessSharing) {}

TEST_P(AuctionProcessManagerTest, DestroyHandlesWithPendingRequests) {}

// Check that process crash is handled properly, by creating a new process.
TEST_P(AuctionProcessManagerTest, ProcessCrash) {}

TEST_P(AuctionProcessManagerTest, DisconnectBeforeDelete) {}

TEST_P(AuctionProcessManagerTest, ProcessDeleteBeforeHandle) {}

TEST_F(AuctionProcessManagerTest, PidLookup) {}

TEST_F(AuctionProcessManagerTest, PidLookupAlreadyRunning) {}

class PartialSiteIsolationContentBrowserClient
    : public TestContentBrowserClient {};

// A base class for AuctionProcessManager tests that sets up the basic test
// environment. Since this class creates SiteInstances and (implicitly)
// BrowsingInstances, it's important that it knows whether to use
// kOriginKeyedProcessesByDefault at the time it's constructed.
class InRendererAuctionProcessManagerTestBase : public ::testing::Test {};

// A test class for AuctionProcessManager tests that require desktop-like
// behavior, i.e. site-per-process is enabled, and
// kOriginKeyedProcessesByDefault and process sharing for non-default
// SiteInstances is allowed.
class InRendererAuctionProcessManagerTest
    : public InRendererAuctionProcessManagerTestBase {};

// A test class for AuctionProcessManager tests that require Android-like
// behavior, i.e. site-per-process is disabled, kOriginKeyedProcessesByDefault
// is disabled, and process sharing is set for default SiteInstances only.
class InRendererAuctionProcessManagerTest_NoOriginKeyedProcessesByDefault
    : public InRendererAuctionProcessManagerTestBase {};

TEST_F(InRendererAuctionProcessManagerTest_NoOriginKeyedProcessesByDefault,
       AndroidLike) {}

TEST_F(InRendererAuctionProcessManagerTest, DesktopLike) {}

TEST_F(InRendererAuctionProcessManagerTest_NoOriginKeyedProcessesByDefault,
       PolicyChange) {}

}  // namespace
}  // namespace content