#ifdef UNSAFE_BUFFERS_BUILD
#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) { … }
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) { … }
TEST_F(DomainReliabilityContextTest, ReportUploadNetworkAnonymizationKey) { … }
TEST_F(DomainReliabilityContextTest, ReportUploadDepthNetworkAnonymizationKey) { … }
TEST_F(DomainReliabilityContextTest, UploadForbidden) { … }
TEST_F(DomainReliabilityContextTest, NetworkChanged) { … }
TEST_F(DomainReliabilityContextTest,
ReportUploadWithQuicProtocolErrorAndQuicError) { … }
TEST_F(DomainReliabilityContextTest,
ReportUploadWithNonQuicProtocolErrorAndNoQuicError) { … }
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_F(DomainReliabilityContextTest, Eviction) { … }
TEST_F(DomainReliabilityContextTest, EvictionDuringSuccessfulUpload) { … }
TEST_F(DomainReliabilityContextTest, EvictionDuringUnsuccessfulUpload) { … }
TEST_F(DomainReliabilityContextTest, EvictAllDuringSuccessfulUpload) { … }
TEST_F(DomainReliabilityContextTest,
EvictionDuringSuccessfulUploadNetworkAnonymizationKey) { … }
}
}