chromium/content/browser/interest_group/auction_metrics_recorder_unittest.cc

// Copyright 2023 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_metrics_recorder.h"

#include <stdint.h>

#include <optional>

#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/gtest_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/browser/interest_group/additional_bid_result.h"
#include "content/browser/interest_group/auction_worklet_manager.h"
#include "content/public/browser/auction_result.h"
#include "content/services/auction_worklet/public/mojom/bidder_worklet.mojom-shared.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

namespace content {
namespace {

UkmEntry;

class AuctionMetricsRecorderTest : public testing::Test {};

TEST_F(AuctionMetricsRecorderTest, ResultAndEndToEndLatencyInMillis) {}

TEST_F(AuctionMetricsRecorderTest, CrashOnRepeatedOnAuctionEnd) {}

TEST_F(AuctionMetricsRecorderTest, MostMethodsCrashAfterOnAuctionEnd) {}

TEST_F(AuctionMetricsRecorderTest, NoLoadInterestGroupPhaseLatencyAndEndTime) {}

TEST_F(AuctionMetricsRecorderTest, LoadInterestGroupPhaseLatencyAndEndTime) {}

TEST_F(AuctionMetricsRecorderTest,
       WorkletCreationPhaseMetricsHaveNoValuesForNoWorkletsCreated) {}

TEST_F(AuctionMetricsRecorderTest, WorkletCreationPhaseMetricsWithOneRecord) {}

TEST_F(AuctionMetricsRecorderTest, WorkletCreationPhaseMetricsWithTwoRecords) {}

TEST_F(AuctionMetricsRecorderTest, NumInterestGroups) {}

TEST_F(AuctionMetricsRecorderTest, NumOwnersWithInterestGroups) {}

TEST_F(AuctionMetricsRecorderTest, NumOwnersWithoutInterestGroups) {}

TEST_F(AuctionMetricsRecorderTest, NumSellersWithBidders) {}

// TODO rest of the histograms, mock AuctionMetricsRecorder,
// use that in auction_runner_unittest.cc.

TEST_F(AuctionMetricsRecorderTest,
       NumNegativeInterestGroupsHasNoValueIfNeverRecorded) {}

TEST_F(AuctionMetricsRecorderTest, NumNegativeInterestGroups) {}

TEST_F(AuctionMetricsRecorderTest, NumDistinctOwnersWithInterestGroupsName) {}

TEST_F(AuctionMetricsRecorderTest, NumBidderWorklets) {}

TEST_F(AuctionMetricsRecorderTest, NumBidsAbortedByBuyerCumulativeTimeout) {}

TEST_F(AuctionMetricsRecorderTest, NumBidsAbortedByBidderWorkletFatalError) {}

TEST_F(AuctionMetricsRecorderTest, NumBidsFilteredDuringInterestGroupLoad) {}

TEST_F(AuctionMetricsRecorderTest, NumBidsFilteredDuringReprioritization) {}

TEST_F(AuctionMetricsRecorderTest, NumBidsFilteredByPerBuyerLimits) {}

TEST_F(AuctionMetricsRecorderTest, NumAdditionalBidsSentForScoring) {}

TEST_F(AuctionMetricsRecorderTest, NumAdditionalBidsNegativeTargeted) {}

TEST_F(AuctionMetricsRecorderTest,
       SetNumAdditionalBidsRejectedDueToInvalidBase64) {}

TEST_F(AuctionMetricsRecorderTest,
       NumAdditionalBidsRejectedDueToSignedBidJsonParseError) {}

TEST_F(AuctionMetricsRecorderTest,
       NumAdditionalBidsRejectedDueToSignedBidDecodeError) {}

TEST_F(AuctionMetricsRecorderTest,
       NumAdditionalBidsRejectedDueToJsonParseError) {}

TEST_F(AuctionMetricsRecorderTest, NumAdditionalBidsRejectedDueToDecodeError) {}

TEST_F(AuctionMetricsRecorderTest,
       NumAdditionalBidsRejectedDueToBuyerNotAllowed) {}

TEST_F(AuctionMetricsRecorderTest,
       NumAdditionalBidsRejectedDueToCurrencyMismatch) {}

TEST_F(AuctionMetricsRecorderTest, AdditionalBidsDecodeLatency) {}

TEST_F(AuctionMetricsRecorderTest,
       RecordNegativeInterestGroupIgnoredDueToInvalidSignature) {}

TEST_F(AuctionMetricsRecorderTest,
       RecordNegativeInterestGroupIgnoredDueToJoiningOriginMismatch) {}

TEST_F(AuctionMetricsRecorderTest, KAnonymityBidMode) {}

TEST_F(AuctionMetricsRecorderTest, NumConfigPromises) {}

TEST_F(AuctionMetricsRecorderTest, OnConfigPromisesResolvedNeverCalled) {}

TEST_F(AuctionMetricsRecorderTest, OnConfigPromisesResolvedCalledOnce) {}

TEST_F(AuctionMetricsRecorderTest, OnConfigPromisesResolvedCalledTwice) {}

TEST_F(AuctionMetricsRecorderTest, NumInterestGroupsWithNoBids) {}

TEST_F(AuctionMetricsRecorderTest, NumInterestGroupsWithOnlyNonKAnonBid) {}

TEST_F(AuctionMetricsRecorderTest,
       NumInterestGroupsWithSameBidForKAnonAndNonKAnon) {}

TEST_F(AuctionMetricsRecorderTest,
       NumInterestGroupsWithSeparateBidsForKAnonAndNonKAnon) {}

TEST_F(AuctionMetricsRecorderTest, NumInterestGroupsWithOtherMultiBid) {}

TEST_F(AuctionMetricsRecorderTest,
       ComponentAuctionLatencyMetricsHaveNoValuesForSingleSellerAuctions) {}

TEST_F(AuctionMetricsRecorderTest, ComponentAuctionLatencyWithOneRecord) {}

TEST_F(AuctionMetricsRecorderTest, ComponentAuctionLatencyWithTwoRecords) {}

TEST_F(AuctionMetricsRecorderTest,
       ComponentAuctionLatencyIgnoresNegativeValues) {}

TEST_F(AuctionMetricsRecorderTest,
       BidForOneInterestGroupLatencyMetricsHaveNoValuesForNoGenerateBids) {}

TEST_F(AuctionMetricsRecorderTest, BidForOneInterestGroupLatencyWithOneRecord) {}

TEST_F(AuctionMetricsRecorderTest,
       BidForOneInterestGroupLatencyWithTwoRecords) {}

TEST_F(AuctionMetricsRecorderTest,
       BidForOneInterestGroupLatencyIgnoresNegativeValues) {}

TEST_F(AuctionMetricsRecorderTest,
       GenerateSingleBidLatencyMetricsHaveNoValuesForNoGenerateBids) {}

TEST_F(AuctionMetricsRecorderTest, GenerateSingleBidLatencyWithOneRecord) {}

TEST_F(AuctionMetricsRecorderTest, GenerateSingleBidLatencyWithTwoRecords) {}

TEST_F(AuctionMetricsRecorderTest,
       GenerateSingleBidLatencyIgnoresNegativeValues) {}

TEST_F(AuctionMetricsRecorderTest,
       GenerateBidDependencyLatencyMetricsHaveNoValuesForNoGenerateBids) {}

TEST_F(AuctionMetricsRecorderTest,
       GenerateBidDependencyLatencyMetricsHaveNoValuesForNullOptLatencies) {}

TEST_F(AuctionMetricsRecorderTest,
       GenerateBidDependencyLatencyMetricsWithOneRecord) {}

TEST_F(AuctionMetricsRecorderTest,
       GenerateBidDependencyLatencyMetricsWithTwoRecords) {}

TEST_F(AuctionMetricsRecorderTest,
       GenerateBidDependencyLatencyMetricsIgnoresNegativeValues) {}

TEST_F(AuctionMetricsRecorderTest,
       GenerateBidCriticalPathMetricsHasNoValuesWhenNoneAreRecorded) {}

TEST_F(AuctionMetricsRecorderTest,
       GenerateBidCriticalPathMetricsRecordedManyTimes) {}

TEST_F(AuctionMetricsRecorderTest, GenerateBidCriticalPathMetricsComputeMean) {}

TEST_F(AuctionMetricsRecorderTest,
       GenerateBidCriticalPathMetricsIgnoreNegativeValues) {}

TEST_F(AuctionMetricsRecorderTest,
       GenerateBidPhaseMetricsHaveNoValuesForNoGenerateBids) {}

// Times for this test:
// - GenerateBid called at 205
// - Signals fetched by (205 + 410) = 615
// - GenerateBid complete by (615 + 190) = 805
TEST_F(AuctionMetricsRecorderTest, GenerateBidPhaseMetricsWithOneRecord) {}

// Times for this test:
// - GenerateBid[bid2] called at 115
// - GenerateBid[bid1] called at (115 + 105) = 220
// - Signals fetched[bid1] by (220 + 415) = 635
// - GenerateBid complete[bid1] by (635 + 250) = 885
// - Signals fetched[bid2] by (885 + 610) = 1495
// - GenerateBid complete[bid2] by (1495 + 100) = 1595
//
// Phases:
// - BidSignalsFetch start: min(115, 220) = 115
// - BidSignalsFetch end: max(635, 1495) = 1495
// - BidGeneration start: min(635, 1495) = 635
// - BidGeneration end: max(885, 1595) = 1595
TEST_F(AuctionMetricsRecorderTest, GenerateBidPhaseMetricsWithTwoRecords) {}

TEST_F(AuctionMetricsRecorderTest,
       TopLevelBidsQueuedWaitingForConfigPromisesMetricsWhenNeverRecorded) {}

TEST_F(AuctionMetricsRecorderTest,
       TopLevelBidsQueuedWaitingForConfigPromisesMetricWhenRecordedManyTimes) {}

TEST_F(AuctionMetricsRecorderTest,
       TopLevelBidsQueuedWaitingForConfigPromisesMetricIgnoresNegativeValues) {}

TEST_F(AuctionMetricsRecorderTest,
       TopLevelBidsQueuedWaitingForSellerWorkletMetricsWhenNeverRecorded) {}

TEST_F(AuctionMetricsRecorderTest,
       TopLevelBidsQueuedWaitingForSellerWorkletMetricWhenRecordedManyTimes) {}

TEST_F(AuctionMetricsRecorderTest,
       TopLevelBidsQueuedWaitingForSellerWorkletMetricIgnoresNegativeValues) {}

TEST_F(AuctionMetricsRecorderTest,
       BidsQueuedWaitingForConfigPromisesMetricsWhenNeverRecorded) {}

TEST_F(AuctionMetricsRecorderTest,
       BidsQueuedWaitingForConfigPromisesMetricWhenRecordedManyTimes) {}

TEST_F(AuctionMetricsRecorderTest,
       BidsQueuedWaitingForConfigPromisesMetricIgnoresNegativeValues) {}

TEST_F(AuctionMetricsRecorderTest,
       BidsQueuedWaitingForSellerWorkletMetricsWhenNeverRecorded) {}

TEST_F(AuctionMetricsRecorderTest,
       BidsQueuedWaitingForSellerWorkletMetricWhenRecordedManyTimes) {}

TEST_F(AuctionMetricsRecorderTest,
       BidsQueuedWaitingForSellerWorkletMetricIgnoresNegativeValues) {}

TEST_F(AuctionMetricsRecorderTest,
       ScoreAdLatencyMetricsHaveNoValuesForNoGenerateBids) {}

TEST_F(AuctionMetricsRecorderTest, ScoreAdLatencyWithOneRecord) {}

TEST_F(AuctionMetricsRecorderTest, ScoreAdLatencyWithTwoRecords) {}

TEST_F(AuctionMetricsRecorderTest, ScoreAdLatencyIgnoresNegativeValues) {}

TEST_F(AuctionMetricsRecorderTest,
       ScoreAdFlowLatencyMetricsHaveNoValuesForNoGenerateBids) {}

TEST_F(AuctionMetricsRecorderTest, ScoreAdFlowLatencyWithOneRecord) {}

TEST_F(AuctionMetricsRecorderTest, ScoreAdFlowLatencyWithTwoRecords) {}

TEST_F(AuctionMetricsRecorderTest, ScoreAdFlowLatencyIgnoresNegativeValues) {}

TEST_F(AuctionMetricsRecorderTest,
       ScoreAdDependencyLatencyMetricsHaveNoValuesForNoScoreAds) {}

TEST_F(AuctionMetricsRecorderTest,
       ScoreAdDependencyLatencyMetricsHaveNoValuesForNullOptLatencies) {}

TEST_F(AuctionMetricsRecorderTest,
       ScoreAdDependencyLatencyMetricsWithOneRecord) {}

TEST_F(AuctionMetricsRecorderTest,
       ScoreAdDependencyLatencyMetricsWithTwoRecords) {}

TEST_F(AuctionMetricsRecorderTest,
       ScoreAdDependencyLatencyMetricsIgnoresNegativeValues) {}

TEST_F(AuctionMetricsRecorderTest,
       ScoreAdCriticalPathMetricsHasNoValuesWhenNoneAreRecorded) {}

TEST_F(AuctionMetricsRecorderTest,
       ScoreAdCriticalPathMetricsRecordedManyTimes) {}

TEST_F(AuctionMetricsRecorderTest, ScoreAdCriticalPathMetricsComputeMean) {}

TEST_F(AuctionMetricsRecorderTest,
       ScoreAdCriticalPathMetricsIgnoreNegativeValues) {}

TEST_F(AuctionMetricsRecorderTest,
       ScoreAdPhaseMetricsHaveNoValuesForNoScoreAds) {}

// Times for this test:
// - ScoreAd called at 205
// - Signals fetched by (205 + 410) = 615
// - ScoreAd complete by (615 + 190) = 805
TEST_F(AuctionMetricsRecorderTest, ScoreAdPhaseMetricsWithOneRecord) {}

// Times for this test:
// - ScoreAd[bid2] called at 115
// - ScoreAd[bid1] called at (115 + 105) = 220
// - Signals fetched[bid1] by (220 + 415) = 635
// - ScoreAd complete[bid1] by (635 + 250) = 885
// - Signals fetched[bid2] by (885 + 610) = 1495
// - ScoreAd complete[bid2] by (1495 + 100) = 1595
//
// Phases:
// - ScoreSignalsFetch start: min(115, 220) = 115
// - ScoreSignalsFetch end: max(635, 1495) = 1495
// - Scoring start: min(635, 1495) = 635
// - Scoring end: max(885, 1595) = 1595
TEST_F(AuctionMetricsRecorderTest, ScoreAdPhaseMetricsWithTwoRecords) {}

TEST_F(AuctionMetricsRecorderTest, MultiBidCount) {}

}  // namespace
}  // namespace content