chromium/content/services/auction_worklet/context_recycler_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/context_recycler.h"

#include <stdint.h>

#include <limits>
#include <optional>
#include <string>
#include <vector>

#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "content/public/common/content_features.h"
#include "content/services/auction_worklet/auction_v8_helper.h"
#include "content/services/auction_worklet/bidder_lazy_filler.h"
#include "content/services/auction_worklet/for_debugging_only_bindings.h"
#include "content/services/auction_worklet/private_aggregation_bindings.h"
#include "content/services/auction_worklet/public/mojom/bidder_worklet.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/real_time_reporting_bindings.h"
#include "content/services/auction_worklet/register_ad_beacon_bindings.h"
#include "content/services/auction_worklet/register_ad_macro_bindings.h"
#include "content/services/auction_worklet/report_bindings.h"
#include "content/services/auction_worklet/seller_lazy_filler.h"
#include "content/services/auction_worklet/set_bid_bindings.h"
#include "content/services/auction_worklet/set_priority_bindings.h"
#include "content/services/auction_worklet/worklet_test_util.h"
#include "gin/converter.h"
#include "gin/dictionary.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/numeric/int128.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/interest_group.h"
#include "third_party/blink/public/mojom/aggregation_service/aggregatable_report.mojom.h"
#include "third_party/blink/public/mojom/private_aggregation/private_aggregation_host.mojom-forward.h"
#include "v8/include/v8-context.h"
#include "v8/include/v8-primitive.h"

ElementsAre;
Pair;

namespace auction_worklet {

// Helper to avoid excess boilerplate.
template <typename... Ts>
auto ElementsAreRequests(Ts&... requests) {}

class ContextRecyclerTest : public testing::Test {};

// Test with no binding objects, just context creation.
TEST_F(ContextRecyclerTest, Basic) {}

// Exercise ForDebuggingOnlyBindings, and make sure they reset properly.
TEST_F(ContextRecyclerTest, ForDebuggingOnlyBindings) {}

// Exercise ForDebuggingOnlyBindings, and test invalid arguments.
TEST_F(ContextRecyclerTest, ForDebuggingOnlyBindingsInvalidArguments) {}

// Exercise RegisterAdBeaconBindings, and make sure they reset properly.
TEST_F(ContextRecyclerTest, RegisterAdBeaconBindings) {}

// Exercise ReportBindings, and make sure they reset properly.
TEST_F(ContextRecyclerTest, ReportBindings) {}

// Exercise SetBidBindings, and make sure they reset properly.
TEST_F(ContextRecyclerTest, SetBidBindings) {}

// Exercise SetPriorityBindings, and make sure they reset properly.
TEST_F(ContextRecyclerTest, SetPriorityBindings) {}

// Test to make sure lifetime managing/avoiding UaF is done right.
// Actual argument passing is covered thoroughly in bidder worklet unit tests.
//
// This test covers the case that an object with fully populated bidder lazy
// fillers (InterestGroupLazyFiller, BiddingBrowserSignalsLazyFiller) that are
// never invoked is accessed when a context is reused, with fully populated
// bidder lazy fillers with different values.
TEST_F(ContextRecyclerTest, BidderLazyFiller) {}

// Test to make sure lifetime managing/avoiding UaF is done right.
// Actual argument passing is covered thoroughly in bidder worklet unit tests.
//
// This test covers the case that an object with fully populated bidder lazy
// fillers (InterestGroupLazyFiller, BiddingBrowserSignalsLazyFiller) that are
// never invoked is accessed when a context is reused, with minimally populated
// bidder lazy fillers.
TEST_F(ContextRecyclerTest, BidderLazyFiller2) {}

// Test to make sure lifetime managing/avoiding UaF is done right.
// Actual argument passing is covered thoroughly in bidder worklet unit tests.
//
// This test covers the case that an object with fully populated bidder lazy
// fillers (InterestGroupLazyFiller, BiddingBrowserSignalsLazyFiller) that are
// never invoked is accessed when a context is reused, without populating bidder
// lazy fillers.
TEST_F(ContextRecyclerTest, BidderLazyFiller3) {}

TEST_F(ContextRecyclerTest, InterestGroupLazyFillerUsesReportingIdSetFilter) {}

TEST_F(ContextRecyclerTest,
       InterestGroupLazyFillerDoesNotSetReportingIdsWithoutSelected) {}

TEST_F(ContextRecyclerTest, SharedStorageMethods) {}

TEST_F(ContextRecyclerTest, SharedStorageMethodsPermissionsPolicyDisabled) {}

TEST_F(ContextRecyclerTest, SellerBrowserSignalsLazyFiller) {}

TEST_F(ContextRecyclerTest, AuctionConfigLazyFiller) {}

// Test for error-handling when lazy-filling various field in AuctionConfig
// (except interestGroupBuyers, which is covered by the above test).
// An initial value is also serialized to make sure we're not always just
// accessing a typo.
TEST_F(ContextRecyclerTest, AuctionConfigLazyFillerErrorHandling) {}

class ContextRecyclerPrivateAggregationEnabledTest
    : public ContextRecyclerTest {};

// Exercise `contributeToHistogram()` of PrivateAggregationBindings, and make
// sure they reset properly.
TEST_F(ContextRecyclerPrivateAggregationEnabledTest,
       PrivateAggregationBindingsContributeToHistogram) {}

// Exercise `enableDebugMode()` of PrivateAggregationBindings, and make sure
// they reset properly.
TEST_F(ContextRecyclerPrivateAggregationEnabledTest,
       PrivateAggregationBindingsEnableDebugMode) {}

class ContextRecyclerPrivateAggregationExtensionsEnabledTest
    : public ContextRecyclerTest {};

// Exercise `reportContributionsForEvent()` of PrivateAggregationBindings, and
// make sure they reset properly.
TEST_F(ContextRecyclerPrivateAggregationExtensionsEnabledTest,
       PrivateAggregationForEventBindings) {}

class ContextRecyclerPrivateAggregationDisabledTest
    : public ContextRecyclerTest {};

// Exercise PrivateAggregationBindings, and make sure they reset properly.
TEST_F(ContextRecyclerPrivateAggregationDisabledTest,
       PrivateAggregationBindings) {}

class ContextRecyclerPrivateAggregationDisabledForFledgeOnlyTest
    : public ContextRecyclerTest {};

// Exercise PrivateAggregationBindings, and make sure they reset properly.
TEST_F(ContextRecyclerPrivateAggregationDisabledForFledgeOnlyTest,
       PrivateAggregationBindings) {}

class ContextRecyclerPrivateAggregationOnlyFledgeExtensionsDisabledTest
    : public ContextRecyclerTest {};

// Make sure that `contributeToHistogramOnEvent()` isn't available, but the
// other `privateAggregation` functions are.
TEST_F(ContextRecyclerPrivateAggregationOnlyFledgeExtensionsDisabledTest,
       PrivateAggregationForEventBindings) {}

class ContextRecyclerPrivateAggregationOnlyFilteringIdsDisabledTest
    : public ContextRecyclerTest {};

TEST_F(ContextRecyclerPrivateAggregationOnlyFilteringIdsDisabledTest,
       PrivateAggregationForEventBindings) {}

class ContextRecyclerAdMacroReportingEnabledTest : public ContextRecyclerTest {};

// Exercise RegisterAdMacroBindings, and make sure they reset properly.
TEST_F(ContextRecyclerAdMacroReportingEnabledTest, RegisterAdMacroBindings) {}

class ContextRecyclerRealTimeReportingEnabledTest : public ContextRecyclerTest {};

// Exercise RealTimeReportingBindings, and make sure they are not available when
// kCookieDeprecationFacilitatedTesting is enabled.
TEST_F(ContextRecyclerRealTimeReportingEnabledTest, RealTimeReportingBindings) {}

class ContextRecyclerRealTimeReportingDisabledTest
    : public ContextRecyclerTest {};

// Exercise RealTimeReportingBindings, and make sure they reset properly.
TEST_F(ContextRecyclerRealTimeReportingDisabledTest,
       RealTimeReportingBindings) {}

class ContextRecyclerRealTimeReportingAndCookieDeprecationEnabledTest
    : public ContextRecyclerTest {};

// Exercise RealTimeReportingBindings, and make sure they reset properly.
TEST_F(ContextRecyclerRealTimeReportingAndCookieDeprecationEnabledTest,
       RealTimeReportingBindings) {}

}  // namespace auction_worklet