#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "content/services/auction_worklet/seller_worklet.h"
#include <algorithm>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/containers/flat_map.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/synchronization/waitable_event.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/test/values_test_util.h"
#include "base/test/with_feature_override.h"
#include "base/time/time.h"
#include "content/services/auction_worklet/auction_v8_helper.h"
#include "content/services/auction_worklet/public/cpp/real_time_reporting.h"
#include "content/services/auction_worklet/public/mojom/auction_network_events_handler.mojom.h"
#include "content/services/auction_worklet/public/mojom/auction_worklet_service.mojom.h"
#include "content/services/auction_worklet/public/mojom/private_aggregation_request.mojom.h"
#include "content/services/auction_worklet/public/mojom/real_time_reporting.mojom.h"
#include "content/services/auction_worklet/public/mojom/seller_worklet.mojom.h"
#include "content/services/auction_worklet/worklet_devtools_debug_test_util.h"
#include "content/services/auction_worklet/worklet_test_util.h"
#include "content/services/auction_worklet/worklet_v8_debug_test_util.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "mojo/public/cpp/bindings/unique_receiver_set.h"
#include "net/http/http_status_code.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/interest_group/ad_auction_currencies.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 "third_party/blink/public/mojom/interest_group/interest_group_types.mojom.h"
#include "url/gurl.h"
HasSubstr;
StartsWith;
namespace auction_worklet {
namespace {
PrivateAggregationRequests;
RealTimeReportingContributions;
constexpr base::TimeDelta kTinyTime = …;
const char kTrustedScoringSignalsResponse[] = …;
std::string CreateScoreAdScript(const std::string& raw_return_value,
const std::string& extra_code = std::string()) { … }
std::string CreateBasicSellAdScript() { … }
std::string CreateReportToScript(
const std::string& raw_return_value,
const std::string& extra_code = std::string()) { … }
class TestScoreAdClient : public mojom::ScoreAdClient { … };
class SellerWorkletTest : public testing::Test { … };
class SellerWorkletTwoThreadsTest : public SellerWorkletTest { … };
class SellerWorkletMultiThreadingTest
: public SellerWorkletTest,
public testing::WithParamInterface<size_t> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_F(SellerWorkletTest, PipeClosed) { … }
TEST_F(SellerWorkletTest, NetworkError) { … }
TEST_F(SellerWorkletTest, CompileError) { … }
TEST_F(SellerWorkletTest, ScoreAd) { … }
TEST_F(SellerWorkletTest, ScoreAdAllowComponentAuction) { … }
TEST_F(SellerWorkletTest, ScoreAdAd) { … }
TEST_F(SellerWorkletTest, ScoreAdRejectReason) { … }
TEST_F(SellerWorkletTest, ScoreAdInvalidRejectReason) { … }
TEST_F(SellerWorkletTest, ScoreAdModifiesBid) { … }
TEST_F(SellerWorkletTest, ScoreAdDoesNotModifyBidCurrency) { … }
TEST_F(SellerWorkletTest, ScoreAdIncomingBidInSellerCurrency) { … }
TEST_F(SellerWorkletTest, ScoreAdDateNotAvailable) { … }
TEST_F(SellerWorkletTest, ScoreAdMedata) { … }
TEST_F(SellerWorkletTest, ScoreAdSelectedBuyerAndSellerReportingId) { … }
TEST_F(SellerWorkletTest, ScoreAdBuyerAndSellerReportingIdPresentWithSelected) { … }
TEST_F(SellerWorkletTest, ScoreAdTopWindowOrigin) { … }
TEST_F(SellerWorkletTest, ScoreAdTopLevelSeller) { … }
TEST_F(SellerWorkletTest, ScoreAdComponentSeller) { … }
TEST_F(SellerWorkletTest, ScoreAdInterestGroupOwner) { … }
TEST_F(SellerWorkletTest, ScoreAdRenderUrl) { … }
TEST_F(SellerWorkletTest, ScoreAdRenderUrlDeprecationWarning) { … }
TEST_F(SellerWorkletTest, ScoreAdRenderUrlNoDeprecationWarning) { … }
TEST_F(SellerWorkletTest, ScoreAdAdComponents) { … }
TEST_F(SellerWorkletTest, ScoreAdBid) { … }
TEST_F(SellerWorkletTest, ScoreAdBidCurrency) { … }
TEST_F(SellerWorkletTest, ScoreAdBiddingDuration) { … }
TEST_F(SellerWorkletTest, ScoreAdAuctionConfigParam) { … }
TEST_F(SellerWorkletTest, ScoreAdAuctionConfigUrlDeprecationWarning) { … }
TEST_F(SellerWorkletTest, ScoreAdAuctionConfigUrlNoDeprecationWarning) { … }
TEST_F(SellerWorkletTest, ScoreAdExperimentGroupIdParam) { … }
TEST_P(SellerWorkletMultiThreadingTest, ScoreAdTrustedScoringSignals) { … }
TEST_F(SellerWorkletTest, CrossOriginTrustedSignalsDisabled) { … }
TEST_F(SellerWorkletTest, ScoreAdTrustedScoringSignalsLatency) { … }
TEST_F(SellerWorkletTest, ScoreAdCodeReadyLatency) { … }
TEST_F(SellerWorkletTest, ScoreAdDataVersion) { … }
TEST_F(SellerWorkletTest, ScoreAdExperimentGroupId) { … }
TEST_P(SellerWorkletMultiThreadingTest, ScoreAdParallelBeforeLoadComplete) { … }
TEST_P(SellerWorkletMultiThreadingTest, ScoreAdParallelAfterLoadComplete) { … }
TEST_P(SellerWorkletMultiThreadingTest, ScoreAdParallelLoadFails) { … }
TEST_P(SellerWorkletMultiThreadingTest,
ScoreAdParallelTrustedScoringSignalsNotBatched) { … }
TEST_P(SellerWorkletMultiThreadingTest,
ScoreAdParallelTrustedScoringSignalsBatched1) { … }
TEST_P(SellerWorkletMultiThreadingTest,
ScoreAdParallelTrustedScoringSignalsBatched2) { … }
TEST_P(SellerWorkletMultiThreadingTest,
ScoreAdParallelTrustedScoringSignalsBatched3) { … }
TEST_F(SellerWorkletTest, ScoreAdLoadCompletionOrder) { … }
TEST_F(SellerWorkletTest, ScoreAdDirectFromSellerSignalsMultipleWorklets) { … }
TEST_F(SellerWorkletTest, ReportResultParallel) { … }
TEST_F(SellerWorkletTest, ReportResultParallelLoadFails) { … }
TEST_F(SellerWorkletTest, ReportResult) { … }
TEST_F(SellerWorkletTest, ReportResultSendReportTo) { … }
TEST_F(SellerWorkletTest, ReportResultDateNotAvailable) { … }
TEST_F(SellerWorkletTest, ReportResultTopWindowOrigin) { … }
TEST_F(SellerWorkletTest, ReportResultTopLevelSeller) { … }
TEST_F(SellerWorkletTest, ReportResultComponentSeller) { … }
TEST_F(SellerWorkletTest, ReportResultTopLevelSellerSignals) { … }
TEST_F(SellerWorkletTest, ReportResultModifiedBid) { … }
TEST_F(SellerWorkletTest, ReportResultInterestGroupOwner) { … }
TEST_F(SellerWorkletTest, ReportResultBuyerAndSellerReportingId) { … }
TEST_F(SellerWorkletTest, ReportResultSelectedBuyerAndSellerReportingId) { … }
TEST_F(SellerWorkletTest, ReportResultRenderUrl) { … }
TEST_F(SellerWorkletTest, ReportResultRenderUrlDeprecationWarning) { … }
TEST_F(SellerWorkletTest, ReportResultRenderUrlNoDeprecationWarning) { … }
TEST_F(SellerWorkletTest, ReportResultRegisterAdBeacon) { … }
TEST_F(SellerWorkletTest, ReportResultBid) { … }
TEST_F(SellerWorkletTest, ReportResultBidCurrency) { … }
TEST_F(SellerWorkletTest, ReportResultDesireability) { … }
TEST_F(SellerWorkletTest, ReportResultHighestScoringOtherBid) { … }
TEST_F(SellerWorkletTest, ReportResultHighestScoringOtherBidCurrency) { … }
TEST_F(SellerWorkletTest, ReportResultAuctionConfigParam) { … }
TEST_F(SellerWorkletTest, ReportResultAuctionConfigUrlDeprecationWarning) { … }
TEST_F(SellerWorkletTest, ReportResultAuctionConfigUrlNoDeprecationWarning) { … }
TEST_F(SellerWorkletTest,
ReportResultDirectFromSellerSignalsHeaderAdSlotParam) { … }
TEST_F(SellerWorkletTest, ReportResultAuctionConfigParamPerBuyerTimeouts) { … }
TEST_F(SellerWorkletTest, ReportResultExperimentGroupIdParam) { … }
TEST_F(SellerWorkletTest, ReportResultDataVersion) { … }
TEST_F(SellerWorkletTest, ReportResultLoadCompletionOrder) { … }
TEST_P(SellerWorkletMultiThreadingTest, ScriptIsolation) { … }
TEST_F(SellerWorkletTest,
ContextIsReusedIfFledgeAlwaysReuseSellerContextEnabled) { … }
TEST_F(
SellerWorkletTwoThreadsTest,
OneWorklet_ContextIsReusedInSameThreadIfFledgeAlwaysReuseSellerContextEnabled) { … }
TEST_F(
SellerWorkletTwoThreadsTest,
TwoWorklets_ContextIsReusedInSameThreadIfFledgeAlwaysReuseSellerContextEnabled) { … }
TEST_F(SellerWorkletTwoThreadsTest,
TrustedScoringSignalsTaskTriggersNextThreadIndexCallback) { … }
TEST_F(SellerWorkletTest, ContextReuseDoesNotCrashLazyFiller) { … }
TEST_F(SellerWorkletTest, DeleteBeforeScoreAdCallback) { … }
TEST_F(SellerWorkletTest, DeleteBeforeReportResultCallback) { … }
TEST_F(SellerWorkletTest, PauseOnStart) { … }
TEST_P(SellerWorkletMultiThreadingTest, PauseOnStartDelete) { … }
TEST_F(SellerWorkletTest, BasicV8Debug) { … }
TEST_F(SellerWorkletTwoThreadsTest, BasicV8Debug) { … }
TEST_F(SellerWorkletTest, ParseErrorV8Debug) { … }
TEST_F(SellerWorkletTwoThreadsTest, ParseErrorV8Debug) { … }
TEST_F(SellerWorkletTest, BasicDevToolsDebug) { … }
TEST_F(SellerWorkletTwoThreadsTest, BasicDevToolsDebug) { … }
TEST_F(SellerWorkletTest, InstrumentationBreakpoints) { … }
TEST_F(SellerWorkletTest, UnloadWhilePaused) { … }
TEST_F(SellerWorkletTest, Cancelation) { … }
TEST_F(SellerWorkletTest, CancelationDtor) { … }
TEST_F(SellerWorkletTest, CancelBeforeFetch) { … }
TEST_F(SellerWorkletTest, ForDebuggingOnlyReportsWithDebugFeatureDisabled) { … }
TEST_F(SellerWorkletTest, AuctionRequestedSizeIsPresentInScoreAdJavascript) { … }
TEST_F(SellerWorkletTest,
AuctionRequestedSizeIsMissingFromScoreAdJavascriptWhenNotProvided) { … }
TEST_F(SellerWorkletTest, AuctionRequestedSizeIsPresentReportResultJavascript) { … }
TEST_F(SellerWorkletTest,
AuctionRequestedSizeIsMissingFromReportResultJavascriptWhenNotProvided) { … }
TEST_F(SellerWorkletTest,
ScoreAdBrowserSignalForDebuggingOnlyInCooldownOrLockout) { … }
class ScoreAdBrowserSignalRenderSizeTest
: public base::test::WithFeatureOverride,
public SellerWorkletTest { … };
TEST_P(ScoreAdBrowserSignalRenderSizeTest, ScoreAdBrowserSignalRenderSize) { … }
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE(…);
class SellerWorkletSharedStorageAPIDisabledTest : public SellerWorkletTest { … };
TEST_F(SellerWorkletSharedStorageAPIDisabledTest, SharedStorageNotExposed) { … }
class SellerWorkletSharedStorageAPIEnabledTest : public SellerWorkletTest { … };
TEST_F(SellerWorkletSharedStorageAPIEnabledTest, SharedStorageWriteInScoreAd) { … }
TEST_F(SellerWorkletSharedStorageAPIEnabledTest,
SharedStorageWriteInReportResult) { … }
class SellerWorkletTwoThreadsSharedStorageAPIEnabledTest
: public SellerWorkletSharedStorageAPIEnabledTest { … };
TEST_F(SellerWorkletTwoThreadsSharedStorageAPIEnabledTest,
SharedStorageWriteInScoreAd) { … }
class SellerWorkletRealTimeTest : public SellerWorkletTest { … };
TEST_F(SellerWorkletRealTimeTest, ScoreAdDefaultTimeout) { … }
TEST_F(SellerWorkletRealTimeTest, ScoreAdZeroTimeout) { … }
TEST_F(SellerWorkletRealTimeTest, ScoreAdSellerTimeoutFromAuctionConfig) { … }
TEST_F(SellerWorkletRealTimeTest, ScoreAdJsonTimeout) { … }
TEST_F(SellerWorkletRealTimeTest, ReportResultLatency) { … }
TEST_F(SellerWorkletRealTimeTest, ReportResultZeroTimeout) { … }
TEST_F(SellerWorkletRealTimeTest, ReportResultTimeoutFromAuctionConfig) { … }
TEST_F(SellerWorkletRealTimeTest, ReportResultJsonTimeout) { … }
class SellerWorkletBiddingAndScoringDebugReportingAPIEnabledTest
: public SellerWorkletRealTimeTest { … };
TEST_F(SellerWorkletBiddingAndScoringDebugReportingAPIEnabledTest,
ForDebuggingOnlyReports) { … }
TEST_F(SellerWorkletBiddingAndScoringDebugReportingAPIEnabledTest,
ForDebuggingOnlyReportsInvalidScoreAdParameter) { … }
TEST_F(SellerWorkletBiddingAndScoringDebugReportingAPIEnabledTest,
ScoreAdHasError) { … }
TEST_F(SellerWorkletBiddingAndScoringDebugReportingAPIEnabledTest,
ScoreAdTimedOut) { … }
TEST_F(SellerWorkletBiddingAndScoringDebugReportingAPIEnabledTest,
ForDebuggingOnlyReportsScriptIsolation) { … }
class SellerWorkletSampleDebugReportsDisabledTest : public SellerWorkletTest { … };
TEST_F(SellerWorkletSampleDebugReportsDisabledTest,
ScoreAdBrowserSignalForDebuggingOnlyInCooldownOrLockout) { … }
class SellerWorkletPrivateAggregationEnabledTest : public SellerWorkletTest { … };
TEST_F(SellerWorkletPrivateAggregationEnabledTest, ScoreAd) { … }
TEST_F(SellerWorkletPrivateAggregationEnabledTest, ReportResult) { … }
class SellerWorkletPrivateAggregationDisabledTest : public SellerWorkletTest { … };
TEST_F(SellerWorkletPrivateAggregationDisabledTest, ScoreAd) { … }
TEST_F(SellerWorkletPrivateAggregationDisabledTest, ReportResult) { … }
class SellerWorkletDeprecatedRenderURLReplacementsEnabledTest
: public SellerWorkletTest { … };
TEST_F(SellerWorkletDeprecatedRenderURLReplacementsEnabledTest,
DeprecatedRenderURLReplacementsArePresentInScoreAdJavascript) { … }
class SellerWorkletCrossOriginTrustedSignalsTest : public SellerWorkletTest { … };
TEST_F(SellerWorkletCrossOriginTrustedSignalsTest, SameOrigin) { … }
TEST_F(SellerWorkletCrossOriginTrustedSignalsTest, ForbiddenCrossOrigin) { … }
TEST_F(SellerWorkletCrossOriginTrustedSignalsTest,
ForbiddenCrossOriginNoFetch) { … }
TEST_F(SellerWorkletCrossOriginTrustedSignalsTest, AllowedCrossOrigin) { … }
TEST_F(SellerWorkletCrossOriginTrustedSignalsTest, AllowedCrossOriginTiming) { … }
TEST_F(SellerWorkletCrossOriginTrustedSignalsTest, ErrorCrossOrigin) { … }
class SellerWorkletRealTimeReportingEnabledTest : public SellerWorkletTest { … };
TEST_F(SellerWorkletRealTimeReportingEnabledTest, RealTimeReporting) { … }
TEST_F(SellerWorkletRealTimeReportingEnabledTest, InvalidScore) { … }
TEST_F(SellerWorkletRealTimeReportingEnabledTest, ScriptTimeout) { … }
TEST_F(SellerWorkletRealTimeReportingEnabledTest,
NotExceedingLatencyThreshold) { … }
TEST_F(SellerWorkletRealTimeReportingEnabledTest,
TrustedScoringSignalNetworkError) { … }
TEST_F(SellerWorkletRealTimeReportingEnabledTest,
TrustedScoringSignalNetworkErrorScoreAdFailed) { … }
}
}