chromium/content/browser/private_aggregation/private_aggregation_host_unittest.cc

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/342213636): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif

#include "content/browser/private_aggregation/private_aggregation_host.h"

#include <stddef.h>

#include <limits>
#include <memory>
#include <optional>
#include <string_view>
#include <utility>
#include <vector>

#include "base/check_op.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/metrics/field_trial_params.h"
#include "base/numerics/safe_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/time/clock.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/aggregation_service/aggregation_coordinator_utils.h"
#include "components/aggregation_service/features.h"
#include "content/browser/aggregation_service/aggregatable_report.h"
#include "content/browser/aggregation_service/aggregation_service_features.h"
#include "content/browser/aggregation_service/aggregation_service_test_utils.h"
#include "content/browser/private_aggregation/private_aggregation_budget_key.h"
#include "content/browser/private_aggregation/private_aggregation_budgeter.h"
#include "content/browser/private_aggregation/private_aggregation_features.h"
#include "content/browser/private_aggregation/private_aggregation_test_utils.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_utils.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.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.h"
#include "url/gurl.h"
#include "url/origin.h"

namespace content {

namespace {

BudgetDeniedBehavior;

_;
Invoke;
Property;

auto GenerateAndSaveReportRequest(
    std::optional<AggregatableReportRequest>* out) {}

constexpr std::string_view kPipeResultHistogram =;

constexpr std::string_view kTimeoutResultHistogram =;

constexpr std::string_view kTimeToGenerateReportRequestWithContextIdHistogram =;

constexpr std::string_view kFilteringIdStatusHistogram =;

void ExpectNumberOfContributionMergeKeysHistogram(
    const base::HistogramTester& tester,
    size_t value,
    PrivateAggregationBudgetKey::Api api,
    bool is_reduced_delay) {}

class PrivateAggregationHostTest : public testing::Test {};

TEST_F(PrivateAggregationHostTest,
       ContributeToHistogram_ReportRequestHasCorrectMembers) {}

TEST_F(PrivateAggregationHostTest, ApiDiffers_RequestUpdatesCorrectly) {}

TEST_F(PrivateAggregationHostTest, EnableDebugMode_ReflectedInReport) {}

TEST_F(PrivateAggregationHostTest,
       MultipleReceievers_ContributeToHistogramCallsRoutedCorrectly) {}

TEST_F(PrivateAggregationHostTest, BindUntrustworthyOriginReceiver_Fails) {}

TEST_F(PrivateAggregationHostTest, BindReceiverWithTooLongContextId_Fails) {}

TEST_F(PrivateAggregationHostTest, TimeoutSetWithoutDeterministicReport_Fails) {}

TEST_F(PrivateAggregationHostTest, TimeoutSetWithContextId_Succeeds) {}

TEST_F(PrivateAggregationHostTest,
       TimeoutSetWithNonDefaultFilteringIdMaxBytes_Succeeds) {}

TEST_F(PrivateAggregationHostTest, InvalidRequest_Rejected) {}

constexpr struct {} kMaxNumContributionsTestCases[]{};

TEST_F(PrivateAggregationHostTest,
       TooManyContributionsWithMergingDisabled_Truncated) {}

TEST_F(PrivateAggregationHostTest,
       TooManyContributionsWithMergingEnabled_Truncated) {}

TEST_F(PrivateAggregationHostTest,
       ContributionsMergedIffSameBucketAndFilteringId) {}

TEST_F(PrivateAggregationHostTest, ContributionsNotMergedIfFeatureDisabled) {}

TEST_F(PrivateAggregationHostTest,
       MergeableContributions_NotTruncatedUnnecessarily) {}

TEST_F(PrivateAggregationHostTest,
       ZeroValueContributions_DroppedAndTruncationHistogramNotTriggered) {}

TEST_F(PrivateAggregationHostTest,
       NumberOfContributionMergeKeysHistograms_RecordsCorrectSubMetrics) {}

TEST_F(PrivateAggregationHostTest, PrivateAggregationAllowed_RequestSucceeds) {}

TEST_F(PrivateAggregationHostTest, PrivateAggregationDisallowed_RequestFails) {}

TEST_F(PrivateAggregationHostTest, ContextIdSet_ReflectedInSingleReport) {}

TEST_F(PrivateAggregationHostTest,
       ContextIdSetNoContributions_NullReportSentWithoutDebugModeEnabled) {}

TEST_F(PrivateAggregationHostTest, ContextIdNotSet_NoNullReportSent) {}

TEST_F(PrivateAggregationHostTest, AggregationCoordinatorOrigin) {}

TEST_F(PrivateAggregationHostTest, FilteringIdMaxBytesValidated) {}

TEST_F(PrivateAggregationHostTest, FilteringIdValidatedToFitInMaxBytes) {}

TEST_F(PrivateAggregationHostTest,
       FilteringIdMaxBytesNotValidatedIfFeatureDisabled) {}

TEST_F(PrivateAggregationHostTest,
       FilteringIdNotValidatedToFitInMaxBytesIfFeatureDisabled) {}

TEST_F(PrivateAggregationHostTest,
       DebugModeFeatureParamsAndSettingsCheckAppliedCorrectly) {}

TEST_F(PrivateAggregationHostTest, PipeClosedBeforeShutdown_NoHistogram) {}

TEST_F(PrivateAggregationHostTest, PipeStillOpenAtShutdown_Histogram) {}

TEST_F(PrivateAggregationHostTest, TimeoutBeforeDisconnect) {}

TEST_F(PrivateAggregationHostTest, TimeoutAfterDisconnect) {}

// Test the scenario that the disconnect happens before the timer fires, but we
// find the remaining time is negative. This can happen if enough time passes
// between the disconnect and the point when we compute the remaining time that
// the current time exceeds the original timer deadline. Viewed as a timeline:
//
//        T1                    T2                    T3
//    ----|---------------------|---------------------|--------------->
//    Disconnect           Timer deadline      Compute remaining time
//
TEST_F(PrivateAggregationHostTest,
       TimeoutAfterDisconnectTimeRemainingNegative) {}

TEST_F(PrivateAggregationHostTest, TimeoutBeforeDisconnectForTwoHosts) {}

TEST_F(PrivateAggregationHostTest, TimeoutAfterDisconnectForTwoHosts) {}

TEST_F(PrivateAggregationHostTest, TimeoutCanceledDueToError) {}

TEST_F(PrivateAggregationHostTest,
       TimeoutStillScheduledOnShutdownWithPipeOpen) {}

TEST_F(PrivateAggregationHostTest,
       TimeoutStillScheduledOnShutdownWithPipeOpenForTwoHosts) {}

class PrivateAggregationHostDeveloperModeTest
    : public PrivateAggregationHostTest {};

TEST_F(PrivateAggregationHostDeveloperModeTest,
       ContributeToHistogram_ScheduledReportTimeIsNotDelayed) {}

TEST_F(PrivateAggregationHostDeveloperModeTest,
       TimeoutSet_ScheduledReportTimeIsAtTimeout) {}

}  // namespace

}  // namespace content