Consolidate SameProcessAuctionProcessManager classes into a single class
Three different test fixtures have a class named "SameProcessAuctionProcessManager" that all largely do the same thing. This CL consolodites them into a single "TestSameProcessAuctionProcessManager" class. Also delete all ProcessHandleTestPeer classes. There were two of them, neither with static scope, which is dangerous. Made ProcessHandle::OnBaseProcessLaunchedForTesting() method public to do that, but that should be fine. Bug: None Change-Id: I5bbfa11748d78ace9588903bbdffa3ea95e6fe12 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5953912 Reviewed-by: Maks Orlovich <morlovich@chromium.org> Reviewed-by: Paul Semel <paulsemel@chromium.org> Commit-Queue: mmenke <mmenke@chromium.org> Cr-Commit-Position: refs/heads/main@{#1373304}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
77c27ef2c5
commit
b7f7f93244
content
browser
interest_group
services
auction_worklet
test
@ -6,8 +6,7 @@ include_rules = [
|
||||
]
|
||||
|
||||
specific_include_rules = {
|
||||
# Some unit tests directly instantiate an in-process auction_worklet service.
|
||||
".*_unittest\.cc": [
|
||||
"(.*_unittest\.cc|test_same_process_auction_process_manager.cc)": [
|
||||
"+content/services/auction_worklet",
|
||||
],
|
||||
".*_fuzzer.cc": [
|
||||
|
@ -55,6 +55,7 @@
|
||||
#include "content/browser/interest_group/interest_group_manager_impl.h"
|
||||
#include "content/browser/interest_group/interest_group_storage.h"
|
||||
#include "content/browser/interest_group/storage_interest_group.h"
|
||||
#include "content/browser/interest_group/test_same_process_auction_process_manager.h"
|
||||
#include "content/browser/private_aggregation/private_aggregation_budgeter.h"
|
||||
#include "content/browser/private_aggregation/private_aggregation_caller_api.h"
|
||||
#include "content/browser/private_aggregation/private_aggregation_manager_impl.h"
|
||||
@ -72,10 +73,6 @@
|
||||
#include "content/public/test/test_renderer_host.h"
|
||||
#include "content/public/test/test_utils.h"
|
||||
#include "content/public/test/url_loader_interceptor.h"
|
||||
#include "content/services/auction_worklet/auction_v8_helper.h"
|
||||
#include "content/services/auction_worklet/auction_worklet_service_impl.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/test/fenced_frame_test_utils.h"
|
||||
#include "content/test/test_content_browser_client.h"
|
||||
#include "crypto/sha2.h"
|
||||
@ -738,33 +735,6 @@ class NetworkResponder {
|
||||
base::OnceClosure quit_report_wait_loop_callback_ GUARDED_BY(lock_);
|
||||
};
|
||||
|
||||
// AuctionProcessManager that allows running auctions in-proc.
|
||||
class SameProcessAuctionProcessManager : public DedicatedAuctionProcessManager {
|
||||
public:
|
||||
SameProcessAuctionProcessManager() = default;
|
||||
SameProcessAuctionProcessManager(const SameProcessAuctionProcessManager&) =
|
||||
delete;
|
||||
SameProcessAuctionProcessManager& operator=(
|
||||
const SameProcessAuctionProcessManager&) = delete;
|
||||
~SameProcessAuctionProcessManager() override = default;
|
||||
|
||||
private:
|
||||
WorkletProcess::ProcessContext CreateProcessInternal(
|
||||
WorkletProcess& worklet_process) override {
|
||||
// Create one AuctionWorkletServiceImpl per Mojo pipe, just like in
|
||||
// production code. Don't bother to delete the service on pipe close,
|
||||
// though; just keep it in a vector instead.
|
||||
mojo::PendingRemote<auction_worklet::mojom::AuctionWorkletService> service;
|
||||
auction_worklet_services_.push_back(
|
||||
auction_worklet::AuctionWorkletServiceImpl::CreateForService(
|
||||
service.InitWithNewPipeAndPassReceiver()));
|
||||
return WorkletProcess::ProcessContext(std::move(service));
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<auction_worklet::AuctionWorkletServiceImpl>>
|
||||
auction_worklet_services_;
|
||||
};
|
||||
|
||||
class TestKAnonymityServiceDelegate : public KAnonymityServiceDelegate {
|
||||
public:
|
||||
TestKAnonymityServiceDelegate() = default;
|
||||
@ -900,7 +870,7 @@ class AdAuctionServiceImplTest : public RenderViewHostTestHarness {
|
||||
// Process creation crashes in the Chrome zygote init in unit tests, so run
|
||||
// the auction "processes" in-process instead.
|
||||
manager_->set_auction_process_manager_for_testing(
|
||||
std::make_unique<SameProcessAuctionProcessManager>());
|
||||
std::make_unique<TestSameProcessAuctionProcessManager>());
|
||||
manager_->set_k_anonymity_manager_for_testing(
|
||||
std::make_unique<InterestGroupKAnonymityManager>(
|
||||
manager_.get(),
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "content/browser/interest_group/auction_process_manager.h"
|
||||
#include "content/browser/interest_group/interest_group_features.h"
|
||||
#include "content/browser/interest_group/interest_group_manager_impl.h"
|
||||
#include "content/browser/interest_group/test_same_process_auction_process_manager.h"
|
||||
#include "content/browser/renderer_host/render_frame_host_impl.h"
|
||||
#include "content/common/features.h"
|
||||
#include "content/public/browser/browser_context.h"
|
||||
@ -42,7 +43,6 @@
|
||||
#include "content/public/browser/site_instance.h"
|
||||
#include "content/public/test/test_renderer_host.h"
|
||||
#include "content/public/test/url_loader_interceptor.h"
|
||||
#include "content/services/auction_worklet/auction_worklet_service_impl.h"
|
||||
#include "content/test/fuzzer/mojolpm_fuzzer_support.h"
|
||||
#include "content/test/test_content_browser_client.h"
|
||||
#include "content/test/test_render_frame_host.h"
|
||||
@ -164,34 +164,6 @@ class NetworkResponder {
|
||||
std::optional<std::string> script_ GUARDED_BY(lock_);
|
||||
};
|
||||
|
||||
// AuctionProcessManager that allows running auctions in-proc.
|
||||
class SameProcessAuctionProcessManager
|
||||
: public content::DedicatedAuctionProcessManager {
|
||||
public:
|
||||
SameProcessAuctionProcessManager() = default;
|
||||
SameProcessAuctionProcessManager(const SameProcessAuctionProcessManager&) =
|
||||
delete;
|
||||
SameProcessAuctionProcessManager& operator=(
|
||||
const SameProcessAuctionProcessManager&) = delete;
|
||||
~SameProcessAuctionProcessManager() override = default;
|
||||
|
||||
private:
|
||||
WorkletProcess::ProcessContext CreateProcessInternal(
|
||||
WorkletProcess& worklet_process) override {
|
||||
// Create one AuctionWorkletServiceImpl per Mojo pipe, just like in
|
||||
// production code. Don't bother to delete the service on pipe close,
|
||||
// though; just keep it in a vector instead.
|
||||
mojo::PendingRemote<auction_worklet::mojom::AuctionWorkletService> service;
|
||||
auction_worklet_services_.push_back(
|
||||
auction_worklet::AuctionWorkletServiceImpl::CreateForService(
|
||||
service.InitWithNewPipeAndPassReceiver()));
|
||||
return WorkletProcess::ProcessContext(std::move(service));
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<auction_worklet::AuctionWorkletServiceImpl>>
|
||||
auction_worklet_services_;
|
||||
};
|
||||
|
||||
const char* const kCmdline[] = {"ad_auction_service_mojolpm_fuzzer", nullptr};
|
||||
|
||||
content::mojolpm::FuzzerEnvironment& GetEnvironment() {
|
||||
@ -376,7 +348,7 @@ void AdAuctionServiceTestcase::SetUpOnUIThread() {
|
||||
// Process creation crashes in the Chrome zygote init in unit tests, so run
|
||||
// the auction "processes" in-process instead.
|
||||
manager_->set_auction_process_manager_for_testing(
|
||||
std::make_unique<SameProcessAuctionProcessManager>());
|
||||
std::make_unique<TestSameProcessAuctionProcessManager>());
|
||||
}
|
||||
|
||||
void AdAuctionServiceTestcase::TearDown(base::OnceClosure done_closure) {
|
||||
|
@ -280,16 +280,15 @@ class CONTENT_EXPORT AuctionProcessManager {
|
||||
std::optional<base::ProcessId> GetPid(
|
||||
base::OnceCallback<void(base::ProcessId)> callback);
|
||||
|
||||
private:
|
||||
friend class ProcessHandleTestPeer;
|
||||
friend class AuctionProcessManager;
|
||||
friend class InRendererAuctionProcessManager;
|
||||
friend class DedicatedAuctionProcessManager;
|
||||
|
||||
// Tests can call this function to configure this ProcessHandle's worklet
|
||||
// process's PID to this process.
|
||||
void OnBaseProcessLaunchedForTesting(const base::Process& process) const;
|
||||
|
||||
private:
|
||||
friend class AuctionProcessManager;
|
||||
friend class InRendererAuctionProcessManager;
|
||||
friend class DedicatedAuctionProcessManager;
|
||||
|
||||
// Assigns `worklet_process` to `this`. If `callback_` is non-null, queues a
|
||||
// task to invoke it asynchronously, and GetService() will return nullptr
|
||||
// until its invoked, so the consumer sees a consistent picture of the
|
||||
|
@ -59,6 +59,7 @@
|
||||
#include "content/browser/interest_group/mock_auction_process_manager.h"
|
||||
#include "content/browser/interest_group/test_interest_group_manager_impl.h"
|
||||
#include "content/browser/interest_group/test_interest_group_private_aggregation_manager.h"
|
||||
#include "content/browser/interest_group/test_same_process_auction_process_manager.h"
|
||||
#include "content/browser/renderer_host/render_frame_host_impl.h"
|
||||
#include "content/public/browser/auction_result.h"
|
||||
#include "content/public/browser/page.h"
|
||||
@ -109,19 +110,6 @@ using auction_worklet::TestDevToolsAgentClient;
|
||||
using testing::HasSubstr;
|
||||
|
||||
namespace content {
|
||||
class ProcessHandleTestPeer {
|
||||
public:
|
||||
explicit ProcessHandleTestPeer(
|
||||
const AuctionProcessManager::ProcessHandle* handle)
|
||||
: handle_(handle) {}
|
||||
|
||||
void CallOnLaunchedWithPidForCurrentProcess() {
|
||||
handle_->OnBaseProcessLaunchedForTesting(base::Process::Current());
|
||||
}
|
||||
|
||||
private:
|
||||
raw_ptr<const AuctionProcessManager::ProcessHandle> handle_;
|
||||
};
|
||||
|
||||
namespace {
|
||||
|
||||
@ -1442,64 +1430,6 @@ CreateBiddingAndAuctionEncryptionContext() {
|
||||
return std::move(request).ReleaseContext();
|
||||
}
|
||||
|
||||
class SameProcessAuctionProcessManager : public DedicatedAuctionProcessManager {
|
||||
public:
|
||||
SameProcessAuctionProcessManager() = default;
|
||||
SameProcessAuctionProcessManager(const SameProcessAuctionProcessManager&) =
|
||||
delete;
|
||||
SameProcessAuctionProcessManager& operator=(
|
||||
const SameProcessAuctionProcessManager&) = delete;
|
||||
~SameProcessAuctionProcessManager() override = default;
|
||||
|
||||
// Resume all worklets paused waiting for debugger on startup.
|
||||
void ResumeAllPaused() {
|
||||
for (const auto& svc : auction_worklet_services_) {
|
||||
for (const auto& v8_helper : svc->AuctionV8HelpersForTesting()) {
|
||||
v8_helper->v8_runner()->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(
|
||||
[](scoped_refptr<auction_worklet::AuctionV8Helper> v8_helper) {
|
||||
v8_helper->ResumeAllForTesting();
|
||||
},
|
||||
v8_helper));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int NumBidderWorklets() const {
|
||||
int total = 0;
|
||||
for (const auto& svc : auction_worklet_services_) {
|
||||
total += svc->NumBidderWorkletsForTesting();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
int NumSellerWorklets() const {
|
||||
int total = 0;
|
||||
for (const auto& svc : auction_worklet_services_) {
|
||||
total += svc->NumSellerWorkletsForTesting();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
private:
|
||||
WorkletProcess::ProcessContext CreateProcessInternal(
|
||||
WorkletProcess& worklet_process) override {
|
||||
mojo::PendingRemote<auction_worklet::mojom::AuctionWorkletService> service;
|
||||
auction_worklet_services_.push_back(
|
||||
auction_worklet::AuctionWorkletServiceImpl::CreateForService(
|
||||
service.InitWithNewPipeAndPassReceiver()));
|
||||
return WorkletProcess::ProcessContext(std::move(service));
|
||||
}
|
||||
|
||||
void OnNewProcessAssigned(const ProcessHandle* handle) override {
|
||||
ProcessHandleTestPeer(handle).CallOnLaunchedWithPidForCurrentProcess();
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<auction_worklet::AuctionWorkletServiceImpl>>
|
||||
auction_worklet_services_;
|
||||
};
|
||||
|
||||
MATCHER_P2(HasMetricWithValue, key, matcher, "") {
|
||||
if (!arg.contains(key)) {
|
||||
*result_listener << "which does not contain " << key;
|
||||
@ -1956,7 +1886,7 @@ class AuctionRunnerTest : public RenderViewHostTestHarness,
|
||||
|
||||
if (!auction_process_manager_) {
|
||||
auto same_process_auction_process_manager =
|
||||
std::make_unique<SameProcessAuctionProcessManager>();
|
||||
std::make_unique<TestSameProcessAuctionProcessManager>();
|
||||
same_process_auction_process_manager_ =
|
||||
same_process_auction_process_manager.get();
|
||||
auction_process_manager_ =
|
||||
@ -3423,9 +3353,9 @@ class AuctionRunnerTest : public RenderViewHostTestHarness,
|
||||
|
||||
// This is used (and consumed) when starting an auction, if non-null. Allows
|
||||
// either using a MockAuctionProcessManager instead of a
|
||||
// SameProcessAuctionProcessManager, or using a
|
||||
// SameProcessAuctionProcessManager that has already vended processes. If
|
||||
// nullptr, a new SameProcessAuctionProcessManager() is created when an
|
||||
// TestSameProcessAuctionProcessManager, or using a
|
||||
// TestSameProcessAuctionProcessManager that has already vended processes. If
|
||||
// nullptr, a new TestSameProcessAuctionProcessManager() is created when an
|
||||
// auction is started.
|
||||
std::unique_ptr<AuctionProcessManager> auction_process_manager_;
|
||||
|
||||
@ -3434,10 +3364,10 @@ class AuctionRunnerTest : public RenderViewHostTestHarness,
|
||||
// InterestGroupManager.
|
||||
raw_ptr<MockAuctionProcessManager> mock_auction_process_manager_ = nullptr;
|
||||
|
||||
// If StartAuction() created a SameProcessAuctionProcessManager for
|
||||
// If StartAuction() created a TestSameProcessAuctionProcessManager for
|
||||
// `auction_process_manager_`, this alises it.
|
||||
// Reset by other things that set `auction_process_manager_`.
|
||||
raw_ptr<SameProcessAuctionProcessManager>
|
||||
raw_ptr<TestSameProcessAuctionProcessManager>
|
||||
same_process_auction_process_manager_ = nullptr;
|
||||
|
||||
// The TestInterestGroupManager is recreated and repopulated for each auction.
|
||||
@ -7593,7 +7523,7 @@ TEST_F(AuctionRunnerTest, PromiseAuctionSignalsDeliveredBeforeWorklet) {
|
||||
// Create AuctionProcessManager in advance of starting the auction so can
|
||||
// create worklets before the auction starts.
|
||||
auction_process_manager_ =
|
||||
std::make_unique<SameProcessAuctionProcessManager>();
|
||||
std::make_unique<TestSameProcessAuctionProcessManager>();
|
||||
|
||||
std::vector<std::unique_ptr<AuctionProcessManager::ProcessHandle>>
|
||||
busy_processes;
|
||||
@ -10196,7 +10126,7 @@ TEST_F(AuctionRunnerTest, ProcessManagerBlocksWorkletCreation) {
|
||||
// Create AuctionProcessManager in advance of starting the auction so can
|
||||
// create worklets before the auction starts.
|
||||
auction_process_manager_ =
|
||||
std::make_unique<SameProcessAuctionProcessManager>();
|
||||
std::make_unique<TestSameProcessAuctionProcessManager>();
|
||||
|
||||
AuctionProcessManager* auction_process_manager =
|
||||
auction_process_manager_.get();
|
||||
@ -10388,7 +10318,7 @@ TEST_F(AuctionRunnerTest, ComponentAuctionProcessManagerBlocksWorkletCreation) {
|
||||
// Create AuctionProcessManager in advance of starting the auction so can
|
||||
// create worklets before the auction starts.
|
||||
auction_process_manager_ =
|
||||
std::make_unique<SameProcessAuctionProcessManager>();
|
||||
std::make_unique<TestSameProcessAuctionProcessManager>();
|
||||
|
||||
AuctionProcessManager* auction_process_manager =
|
||||
auction_process_manager_.get();
|
||||
@ -10599,7 +10529,7 @@ TEST_F(AuctionRunnerTest, SellerLoadErrorWhileWaitingForBidders) {
|
||||
// Create AuctionProcessManager in advance of starting the auction so can
|
||||
// create worklets before the auction starts.
|
||||
auction_process_manager_ =
|
||||
std::make_unique<SameProcessAuctionProcessManager>();
|
||||
std::make_unique<TestSameProcessAuctionProcessManager>();
|
||||
|
||||
// Make kMaxBidderProcesses bidder worklet requests for different origins.
|
||||
std::list<std::unique_ptr<AuctionProcessManager::ProcessHandle>>
|
||||
@ -10683,7 +10613,7 @@ TEST_F(AuctionRunnerTest,
|
||||
/*bid_from_component_auction_wins=*/true));
|
||||
|
||||
auction_process_manager_ =
|
||||
std::make_unique<SameProcessAuctionProcessManager>();
|
||||
std::make_unique<TestSameProcessAuctionProcessManager>();
|
||||
|
||||
// Take up all but 1 of the seller worklet process slots.
|
||||
std::list<std::unique_ptr<AuctionProcessManager::ProcessHandle>> sellers;
|
||||
@ -15135,7 +15065,7 @@ TEST_F(AuctionRunnerTest,
|
||||
// Test the phase metrics for the WorkletCreation phase.
|
||||
TEST_F(AuctionRunnerTest, VerifyWorkletCreationPhaseMetrics) {
|
||||
auto same_process_auction_process_manager =
|
||||
std::make_unique<SameProcessAuctionProcessManager>();
|
||||
std::make_unique<TestSameProcessAuctionProcessManager>();
|
||||
same_process_auction_process_manager_ =
|
||||
same_process_auction_process_manager.get();
|
||||
auction_process_manager_ = std::move(same_process_auction_process_manager);
|
||||
|
@ -60,32 +60,6 @@
|
||||
using testing::UnorderedElementsAre;
|
||||
|
||||
namespace content {
|
||||
class ProcessHandleTestPeer {
|
||||
public:
|
||||
explicit ProcessHandleTestPeer(
|
||||
const AuctionProcessManager::ProcessHandle* handle)
|
||||
: handle_(handle) {}
|
||||
|
||||
void CallOnLaunchedWithPid() {
|
||||
handle_->OnBaseProcessLaunchedForTesting(base::Process::Current());
|
||||
}
|
||||
|
||||
std::unique_ptr<AuctionProcessManager::ProcessHandle> CloneHandle(
|
||||
AuctionProcessManager& auction_process_manager) {
|
||||
auto new_handle = std::make_unique<AuctionProcessManager::ProcessHandle>();
|
||||
base::test::TestFuture<void> process_available;
|
||||
if (!auction_process_manager.RequestWorkletService(
|
||||
handle_->worklet_type_, handle_->origin_,
|
||||
/*frame_site_instance=*/nullptr, new_handle.get(),
|
||||
process_available.GetCallback())) {
|
||||
CHECK(process_available.Wait());
|
||||
}
|
||||
return new_handle;
|
||||
}
|
||||
|
||||
private:
|
||||
raw_ptr<const AuctionProcessManager::ProcessHandle> handle_;
|
||||
};
|
||||
|
||||
namespace {
|
||||
|
||||
@ -582,10 +556,18 @@ class MockAuctionProcessManager
|
||||
|
||||
void OnNewProcessAssigned(const ProcessHandle* handle) override {
|
||||
if (defer_on_launched_for_handles_) {
|
||||
deferred_on_launch_call_handles_.push_back(
|
||||
ProcessHandleTestPeer(handle).CloneHandle(*this));
|
||||
auto new_handle =
|
||||
std::make_unique<AuctionProcessManager::ProcessHandle>();
|
||||
base::test::TestFuture<void> process_available;
|
||||
if (!RequestWorkletService(handle->worklet_type(), handle->origin(),
|
||||
/*frame_site_instance=*/nullptr,
|
||||
new_handle.get(),
|
||||
process_available.GetCallback())) {
|
||||
CHECK(process_available.Wait());
|
||||
}
|
||||
deferred_on_launch_call_handles_.push_back(std::move(new_handle));
|
||||
} else {
|
||||
ProcessHandleTestPeer(handle).CallOnLaunchedWithPid();
|
||||
handle->OnBaseProcessLaunchedForTesting(base::Process::Current());
|
||||
}
|
||||
}
|
||||
|
||||
@ -593,7 +575,7 @@ class MockAuctionProcessManager
|
||||
|
||||
void CallOnLaunchedWithPidForAllHandles() {
|
||||
for (auto& handle : deferred_on_launch_call_handles_) {
|
||||
ProcessHandleTestPeer(handle.get()).CallOnLaunchedWithPid();
|
||||
handle->OnBaseProcessLaunchedForTesting(base::Process::Current());
|
||||
}
|
||||
deferred_on_launch_call_handles_.clear();
|
||||
}
|
||||
|
@ -0,0 +1,71 @@
|
||||
// Copyright 2024 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/test_same_process_auction_process_manager.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "base/process/process.h"
|
||||
#include "content/browser/interest_group/auction_process_manager.h"
|
||||
#include "content/services/auction_worklet/auction_worklet_service_impl.h"
|
||||
#include "mojo/public/cpp/bindings/pending_receiver.h"
|
||||
#include "mojo/public/cpp/bindings/pending_remote.h"
|
||||
|
||||
namespace content {
|
||||
|
||||
TestSameProcessAuctionProcessManager::TestSameProcessAuctionProcessManager() =
|
||||
default;
|
||||
TestSameProcessAuctionProcessManager::~TestSameProcessAuctionProcessManager() =
|
||||
default;
|
||||
|
||||
void TestSameProcessAuctionProcessManager::ResumeAllPaused() {
|
||||
for (const auto& svc : auction_worklet_services_) {
|
||||
for (const auto& v8_helper : svc->AuctionV8HelpersForTesting()) {
|
||||
v8_helper->v8_runner()->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(
|
||||
[](scoped_refptr<auction_worklet::AuctionV8Helper> v8_helper) {
|
||||
v8_helper->ResumeAllForTesting();
|
||||
},
|
||||
v8_helper));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int TestSameProcessAuctionProcessManager::NumBidderWorklets() const {
|
||||
int total = 0;
|
||||
for (const auto& svc : auction_worklet_services_) {
|
||||
total += svc->NumBidderWorkletsForTesting();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
int TestSameProcessAuctionProcessManager::NumSellerWorklets() const {
|
||||
int total = 0;
|
||||
for (const auto& svc : auction_worklet_services_) {
|
||||
total += svc->NumSellerWorkletsForTesting();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
AuctionProcessManager::WorkletProcess::ProcessContext
|
||||
TestSameProcessAuctionProcessManager::CreateProcessInternal(
|
||||
WorkletProcess& worklet_process) {
|
||||
// Create one AuctionWorkletServiceImpl per Mojo pipe, just like in
|
||||
// production code. Don't bother to delete the service on pipe close,
|
||||
// though; just keep it in a vector instead.
|
||||
mojo::PendingRemote<auction_worklet::mojom::AuctionWorkletService> service;
|
||||
auction_worklet_services_.push_back(
|
||||
auction_worklet::AuctionWorkletServiceImpl::CreateForService(
|
||||
service.InitWithNewPipeAndPassReceiver()));
|
||||
return WorkletProcess::ProcessContext(std::move(service));
|
||||
}
|
||||
|
||||
void TestSameProcessAuctionProcessManager::OnNewProcessAssigned(
|
||||
const ProcessHandle* handle) {
|
||||
handle->OnBaseProcessLaunchedForTesting(base::Process::Current());
|
||||
}
|
||||
|
||||
} // namespace content
|
@ -0,0 +1,49 @@
|
||||
// Copyright 2024 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_BROWSER_INTEREST_GROUP_TEST_SAME_PROCESS_AUCTION_PROCESS_MANAGER_H_
|
||||
#define CONTENT_BROWSER_INTEREST_GROUP_TEST_SAME_PROCESS_AUCTION_PROCESS_MANAGER_H_
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "content/browser/interest_group/auction_process_manager.h"
|
||||
|
||||
namespace auction_worklet {
|
||||
class AuctionWorkletServiceImpl;
|
||||
}
|
||||
|
||||
namespace content {
|
||||
|
||||
// AuctionProcessManager that allows running auctions in-process, using real
|
||||
// worklets.
|
||||
class TestSameProcessAuctionProcessManager
|
||||
: public DedicatedAuctionProcessManager {
|
||||
public:
|
||||
TestSameProcessAuctionProcessManager();
|
||||
TestSameProcessAuctionProcessManager(
|
||||
const TestSameProcessAuctionProcessManager&) = delete;
|
||||
TestSameProcessAuctionProcessManager& operator=(
|
||||
const TestSameProcessAuctionProcessManager&) = delete;
|
||||
~TestSameProcessAuctionProcessManager() override;
|
||||
|
||||
// Resume all worklets paused waiting for debugger on startup.
|
||||
void ResumeAllPaused();
|
||||
|
||||
// Number of live bidder/seller worklets across all created services.
|
||||
int NumBidderWorklets() const;
|
||||
int NumSellerWorklets() const;
|
||||
|
||||
private:
|
||||
WorkletProcess::ProcessContext CreateProcessInternal(
|
||||
WorkletProcess& worklet_process) override;
|
||||
void OnNewProcessAssigned(const ProcessHandle* handle) override;
|
||||
|
||||
std::vector<std::unique_ptr<auction_worklet::AuctionWorkletServiceImpl>>
|
||||
auction_worklet_services_;
|
||||
};
|
||||
|
||||
} // namespace content
|
||||
|
||||
#endif // CONTENT_BROWSER_INTEREST_GROUP_TEST_SAME_PROCESS_AUCTION_PROCESS_MANAGER_H_
|
@ -136,7 +136,10 @@ source_set("auction_worklet") {
|
||||
|
||||
# See comment at the top of //content/BUILD.gn for how this works.
|
||||
group("for_content_tests") {
|
||||
visibility = [ ":tests" ]
|
||||
visibility = [
|
||||
":tests",
|
||||
"//content/test:test_support",
|
||||
]
|
||||
if (!is_component_build) {
|
||||
public_deps = [ ":auction_worklet" ]
|
||||
} else {
|
||||
|
@ -106,6 +106,8 @@ static_library("test_support") {
|
||||
"../browser/interest_group/additional_bids_test_util.h",
|
||||
"../browser/interest_group/test_interest_group_observer.cc",
|
||||
"../browser/interest_group/test_interest_group_observer.h",
|
||||
"../browser/interest_group/test_same_process_auction_process_manager.cc",
|
||||
"../browser/interest_group/test_same_process_auction_process_manager.h",
|
||||
"../browser/media/session/mock_media_session_player_observer.cc",
|
||||
"../browser/media/session/mock_media_session_player_observer.h",
|
||||
"../browser/media/session/mock_media_session_service_impl.cc",
|
||||
@ -571,6 +573,7 @@ static_library("test_support") {
|
||||
"//content/public/renderer",
|
||||
"//content/public/utility",
|
||||
"//content/renderer:for_content_tests",
|
||||
"//content/services/auction_worklet:for_content_tests",
|
||||
"//content/shell:pak",
|
||||
"//content/utility:for_content_tests",
|
||||
"//device/base/synchronization",
|
||||
|
@ -447,7 +447,7 @@ mojolpm_fuzzer_test("ad_auction_service_mojolpm_fuzzer") {
|
||||
"//content/browser:browser",
|
||||
"//content/browser:for_content_tests",
|
||||
"//content/public/browser:browser_sources",
|
||||
"//content/services/auction_worklet:auction_worklet",
|
||||
"//content/test:test_support",
|
||||
"//services/data_decoder/public/cpp:test_support",
|
||||
]
|
||||
|
||||
|
Reference in New Issue
Block a user