chromium/components/domain_reliability/context_unittest.cc

// Copyright 2014 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/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "components/domain_reliability/context.h"

#include <stddef.h>

#include <map>
#include <memory>
#include <string>
#include <string_view>
#include <utility>

#include "base/functional/bind.h"
#include "base/strings/stringprintf.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/values_test_util.h"
#include "base/time/time.h"
#include "components/domain_reliability/beacon.h"
#include "components/domain_reliability/dispatcher.h"
#include "components/domain_reliability/scheduler.h"
#include "components/domain_reliability/test_util.h"
#include "components/domain_reliability/uploader.h"
#include "net/base/net_errors.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace domain_reliability {
namespace {

Value;

BeaconVector;

const char kBeaconOutcomeHistogram[] =;

std::unique_ptr<DomainReliabilityBeacon> MakeCustomizedBeacon(
    MockableTime* time,
    std::string status,
    std::string quic_error,
    bool quic_port_migration_detected) {}

std::unique_ptr<DomainReliabilityBeacon> MakeBeacon(MockableTime* time) {}

std::unique_ptr<DomainReliabilityBeacon> MakeBeaconWithNetworkAnonymizationKey(
    MockableTime* time,
    const std::string& status,
    const net::NetworkAnonymizationKey& network_anonymization_key) {}

// Create a status string from in integer. For eviction tests. Include string
// values before and after the string representation of the integer, to make
// sure only exact matches are found when searching a JSON string.
std::string StatusFromInt(int i) {}

template <typename ValueTypeFindResult,
          typename ValueType,
          ValueTypeFindResult (Value::Dict::*FindValueType)(std::string_view)
              const>
struct HasValue {};

HasValue<std::optional<bool>, bool, &Value::Dict::FindBoolByDottedPath>
    HasBooleanValue;
HasValue<std::optional<double>, double, &Value::Dict::FindDoubleByDottedPath>
    HasDoubleValue;
HasValue<std::optional<int>, int, &Value::Dict::FindIntByDottedPath>
    HasIntegerValue;
HasValue<const std::string*, std::string, &Value::Dict::FindStringByDottedPath>
    HasStringValue;

const Value::Dict* GetEntryFromReport(const Value::Dict& report, size_t index) {}

class DomainReliabilityContextTest : public testing::Test {};

TEST_F(DomainReliabilityContextTest, Create) {}

TEST_F(DomainReliabilityContextTest, QueueBeacon) {}

TEST_F(DomainReliabilityContextTest, MaxNestedBeaconSchedules) {}

TEST_F(DomainReliabilityContextTest, OverlyNestedBeaconDoesNotSchedule) {}

TEST_F(DomainReliabilityContextTest,
    MaxNestedBeaconAfterOverlyNestedBeaconSchedules) {}

TEST_F(DomainReliabilityContextTest, ReportUpload) {}

TEST_F(DomainReliabilityContextTest, ReportUploadFails) {}

// Make sure that requests with only one NetworkAnonymizationKey are uploaded at
// a time, in FIFO order.
TEST_F(DomainReliabilityContextTest, ReportUploadNetworkAnonymizationKey) {}

// Make sure that kMaxUploadDepthToSchedule is respected when requests have
// different NetworkAnonymizationKeys.
TEST_F(DomainReliabilityContextTest, ReportUploadDepthNetworkAnonymizationKey) {}

TEST_F(DomainReliabilityContextTest, UploadForbidden) {}

TEST_F(DomainReliabilityContextTest, NetworkChanged) {}

// Always expecting granular QUIC errors if status is quic.protocol error.
TEST_F(DomainReliabilityContextTest,
       ReportUploadWithQuicProtocolErrorAndQuicError) {}

// If status is not quic.protocol, expect no granular QUIC error to be reported.
TEST_F(DomainReliabilityContextTest,
       ReportUploadWithNonQuicProtocolErrorAndNoQuicError) {}

// Edge cases that a non-QUIC protocol error with granular QUIC error reported,
// probably indicating state machine in http_network_transaction is working
// in a different way.
TEST_F(DomainReliabilityContextTest,
       ReportUploadWithNonQuicProtocolErrorAndQuicError) {}

TEST_F(DomainReliabilityContextTest, ZeroSampleRate) {}

TEST_F(DomainReliabilityContextTest, FractionalSampleRate) {}

TEST_F(DomainReliabilityContextTest, FailureSampleOnly) {}

TEST_F(DomainReliabilityContextTest, SuccessSampleOnly) {}

TEST_F(DomainReliabilityContextTest, SampleAllBeacons) {}

TEST_F(DomainReliabilityContextTest, SampleNoBeacons) {}

TEST_F(DomainReliabilityContextTest, ExpiredBeaconDoesNotUpload) {}

TEST_F(DomainReliabilityContextTest, EvictOldestBeacon) {}

// Test eviction when there's no active upload.
TEST_F(DomainReliabilityContextTest, Eviction) {}

// Test eviction when there's an upload that eventually succeeds.
TEST_F(DomainReliabilityContextTest, EvictionDuringSuccessfulUpload) {}

// Test eviction when there's an upload that eventually fails.
TEST_F(DomainReliabilityContextTest, EvictionDuringUnsuccessfulUpload) {}

// Test eviction of all initially pending reports when there's an upload that
// eventually succeeds.
TEST_F(DomainReliabilityContextTest, EvictAllDuringSuccessfulUpload) {}

// Make sure that evictions account for when there are different
// NetworkAnonymizationKeys in use.
TEST_F(DomainReliabilityContextTest,
       EvictionDuringSuccessfulUploadNetworkAnonymizationKey) {}

// TODO(juliatuttle): Add beacon_unittest.cc to test serialization.

}  // namespace
}  // namespace domain_reliability