#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "net/nqe/network_quality_estimator.h"
#include <stddef.h>
#include <stdint.h>
#include <cmath>
#include <limits>
#include <map>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/check_op.h"
#include "base/containers/adapters.h"
#include "base/metrics/histogram_samples.h"
#include "base/numerics/safe_conversions.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "net/base/load_flags.h"
#include "net/base/network_change_notifier.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_response_info.h"
#include "net/http/http_status_code.h"
#include "net/log/test_net_log.h"
#include "net/nqe/effective_connection_type.h"
#include "net/nqe/effective_connection_type_observer.h"
#include "net/nqe/network_quality_estimator_test_util.h"
#include "net/nqe/network_quality_observation.h"
#include "net/nqe/network_quality_observation_source.h"
#include "net/nqe/observation_buffer.h"
#include "net/nqe/rtt_throughput_estimates_observer.h"
#include "net/socket/socket_performance_watcher.h"
#include "net/socket/socket_performance_watcher_factory.h"
#include "net/test/test_with_task_environment.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_builder.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
namespace {
void ExpectBucketCountAtLeast(base::HistogramTester* histogram_tester,
const std::string& histogram,
int32_t bucket_min,
int32_t expected_min_count_samples) { … }
}
namespace net {
namespace {
class TestEffectiveConnectionTypeObserver
: public EffectiveConnectionTypeObserver { … };
class TestPeerToPeerConnectionsCountObserver
: public PeerToPeerConnectionsCountObserver { … };
class TestRTTAndThroughputEstimatesObserver
: public RTTAndThroughputEstimatesObserver { … };
class TestRTTObserver : public NetworkQualityEstimator::RTTObserver { … };
class TestThroughputObserver
: public NetworkQualityEstimator::ThroughputObserver { … };
}
NetworkQualityEstimatorTest;
TEST_F(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) { … }
TEST_F(NetworkQualityEstimatorTest, Caching) { … }
TEST_F(NetworkQualityEstimatorTest, CachingDisabled) { … }
TEST_F(NetworkQualityEstimatorTest, QuicObservations) { … }
TEST_F(NetworkQualityEstimatorTest,
QuicObservationsUsedForTransportRTTComputation) { … }
TEST_F(NetworkQualityEstimatorTest,
H2ObservationsUsedForTransportRTTComputation) { … }
TEST_F(NetworkQualityEstimatorTest, StoreObservations) { … }
TEST_F(NetworkQualityEstimatorTest, ComputedPercentiles) { … }
TEST_F(NetworkQualityEstimatorTest, DefaultObservations) { … }
TEST_F(NetworkQualityEstimatorTest, DefaultObservationsOverridden) { … }
TEST_F(NetworkQualityEstimatorTest, Offline) { … }
TEST_F(NetworkQualityEstimatorTest, ObtainThresholdsOnlyRTT) { … }
TEST_F(NetworkQualityEstimatorTest, ClampKbpsBasedOnEct) { … }
TEST_F(NetworkQualityEstimatorTest, DefaultHttpRTTBasedThresholds) { … }
TEST_F(NetworkQualityEstimatorTest, ObtainThresholdsHttpRTTandThroughput) { … }
TEST_F(NetworkQualityEstimatorTest, TestGetMetricsSince) { … }
#if BUILDFLAG(IS_IOS)
#define MAYBE_TestThroughputNoRequestOverlap …
#else
#define MAYBE_TestThroughputNoRequestOverlap …
#endif
TEST_F(NetworkQualityEstimatorTest, MAYBE_TestThroughputNoRequestOverlap) { … }
#if BUILDFLAG(IS_IOS)
#define MAYBE_TestEffectiveConnectionTypeObserver …
#else
#define MAYBE_TestEffectiveConnectionTypeObserver …
#endif
TEST_F(NetworkQualityEstimatorTest, MAYBE_TestEffectiveConnectionTypeObserver) { … }
TEST_F(NetworkQualityEstimatorTest, TestTransportRttUsedForHttpRttComputation) { … }
TEST_F(NetworkQualityEstimatorTest, TestEndToEndRttUsedForHttpRttComputation) { … }
TEST_F(NetworkQualityEstimatorTest, TestRTTAndThroughputEstimatesObserver) { … }
TEST_F(NetworkQualityEstimatorTest, UnknownEffectiveConnectionType) { … }
TEST_F(NetworkQualityEstimatorTest,
AdaptiveRecomputationEffectiveConnectionType) { … }
TEST_F(NetworkQualityEstimatorTest, TestRttThroughputObservers) { … }
TEST_F(NetworkQualityEstimatorTest, TestGlobalSocketWatcherThrottle) { … }
#if (defined(TCP_INFO) || \
(BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)) || \
BUILDFLAG(IS_ANDROID)) && \
!BUILDFLAG(IS_CHROMEOS)
#define MAYBE_TestTCPSocketRTT …
#else
#define MAYBE_TestTCPSocketRTT …
#endif
TEST_F(NetworkQualityEstimatorTest, MAYBE_TestTCPSocketRTT) { … }
class TestNetworkQualitiesCacheObserver
: public nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver { … };
TEST_F(NetworkQualityEstimatorTest, CacheObserver) { … }
TEST_F(NetworkQualityEstimatorTest,
ForceEffectiveConnectionTypeThroughFieldTrial) { … }
TEST_F(NetworkQualityEstimatorTest, SimulateNetworkQualityChangeForTesting) { … }
TEST_F(NetworkQualityEstimatorTest, TypicalNetworkQualities) { … }
TEST_F(NetworkQualityEstimatorTest, OnPrefsRead) { … }
TEST_F(NetworkQualityEstimatorTest, OnPrefsReadWithReadingDisabled) { … }
TEST_F(NetworkQualityEstimatorTest,
ObservationDiscardedIfCachedEstimateAvailable) { … }
TEST_F(NetworkQualityEstimatorTest, MaybeComputeECTAfterNSamples) { … }
TEST_F(NetworkQualityEstimatorTest, HangingRequestUsingHttpOnly) { … }
TEST_F(NetworkQualityEstimatorTest, HangingRequestEndToEndUsingHttpOnly) { … }
TEST_F(NetworkQualityEstimatorTest, HangingRequestUsingTransportAndHttpOnly) { … }
TEST_F(NetworkQualityEstimatorTest, TestPeerToPeerConnectionsCountObserver) { … }
TEST_F(NetworkQualityEstimatorTest, AdjustHttpRttBasedOnRttCounts) { … }
}