chromium/services/network/resource_scheduler/resource_scheduler_unittest.cc

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

#include "services/network/resource_scheduler/resource_scheduler.h"

#include <map>
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>

#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/test/task_environment.h"
#include "base/test/test_mock_time_task_runner.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "net/base/features.h"
#include "net/base/host_port_pair.h"
#include "net/base/isolation_info.h"
#include "net/base/load_timing_info.h"
#include "net/base/request_priority.h"
#include "net/nqe/network_quality_estimator_test_util.h"
#include "net/test/embedded_test_server/embedded_test_server.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 "services/network/public/cpp/features.h"
#include "services/network/public/mojom/network_context.mojom.h"
#include "services/network/resource_scheduler/resource_scheduler_params_manager.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/scheme_host_port.h"

string;

namespace network {

namespace {

class TestRequestFactory;

ClientId;
const ClientId kClientId1 =;
const ClientId kClientId2 =;
const ClientId kTrustedClientId =;
const ClientId kBackgroundClientId =;

const size_t kMaxNumDelayableRequestsPerHostPerClient =;

class TestRequest {};

class CancelingTestRequest : public TestRequest {};

class ResourceSchedulerTest : public testing::Test {};

TEST_F(ResourceSchedulerTest, OneIsolatedLowRequest) {}

TEST_F(ResourceSchedulerTest, OneLowLoadsUntilCriticalComplete) {}

TEST_F(ResourceSchedulerTest, MaxRequestsPerHostForSpdyWhenNotDelayable) {}

TEST_F(ResourceSchedulerTest,
       MaxRequestsPerHostForSpdyWhenNotDelayableWithIsolationInfo) {}

TEST_F(ResourceSchedulerTest, BackgroundRequestStartsImmediately) {}

TEST_F(ResourceSchedulerTest, CancelOtherRequestsWhileResuming) {}

TEST_F(ResourceSchedulerTest, LimitedNumberOfDelayableRequestsInFlight) {}

TEST_F(ResourceSchedulerTest, RaisePriorityAndStart) {}

TEST_F(ResourceSchedulerTest, RaisePriorityInQueue) {}

TEST_F(ResourceSchedulerTest, LowerPriority) {}

// Verify that browser requests are not throttled by the resource scheduler.
TEST_F(ResourceSchedulerTest, LowerPriorityBrowserRequestsNotThrottled) {}

// Verify that browser requests are throttled by the resource scheduler only
// when all the conditions are met.
TEST_F(ResourceSchedulerTest,
       LowerPriorityBrowserRequestsThrottleP2PConnections) {}

// Verify that browser requests that are currently queued are dispatched to the
// network as soon as the active P2P connections count drops to 0.
TEST_F(ResourceSchedulerTest, P2PConnectionWentAway) {}

// Verify that the previously queued browser requests are dispatched to the
// network when the network quality becomes faster.
TEST_F(ResourceSchedulerTest,
       RequestThrottleOnlyOnSlowConnectionsWithP2PRequests) {}

TEST_F(ResourceSchedulerTest, ReprioritizedRequestGoesToBackOfQueue) {}

TEST_F(ResourceSchedulerTest, HigherIntraPriorityGoesToFrontOfQueue) {}

TEST_F(ResourceSchedulerTest, NonHTTPSchedulesImmediately) {}

TEST_F(ResourceSchedulerTest, SpdyProxySchedulesImmediately) {}

TEST_F(ResourceSchedulerTest, NewSpdyHostInDelayableRequests) {}

// Similar to NewSpdyHostInDelayableRequests test above, but tests the behavior
// when |delay_requests_on_multiplexed_connections| is true.
TEST_F(ResourceSchedulerTest,
       NewDelayableSpdyHostInDelayableRequestsSlowConnection) {}

// Async revalidations which are not started when the tab is closed must be
// started at some point, or they will hang around forever and prevent other
// async revalidations to the same URL from being issued.
TEST_F(ResourceSchedulerTest, RequestStartedAfterClientDeleted) {}

// The ResourceScheduler::Client destructor calls
// LoadAnyStartablePendingRequests(), which may start some pending requests.
// This test is to verify that requests will be started at some point
// even if they were not started by the destructor.
TEST_F(ResourceSchedulerTest, RequestStartedAfterClientDeletedManyDelayable) {}

// Tests that the maximum number of delayable requests is overridden when the
// experiment is enabled.
TEST_F(ResourceSchedulerTest, RequestLimitOverrideEnabled) {}

// Tests that the maximum number of delayable requests is not overridden when
// the experiment is disabled.
TEST_F(ResourceSchedulerTest, RequestLimitOverrideDisabled) {}

// Test that the limit is not overridden when the effective connection type is
// not equal to any of the values provided in the experiment configuration.
TEST_F(ResourceSchedulerTest, RequestLimitOverrideOutsideECTRange) {}

// Test that a change in network conditions midway during loading
// changes the behavior of the resource scheduler.
TEST_F(ResourceSchedulerTest, RequestLimitOverrideNotFixedForPageLoad) {}

// Test that when the network quality changes such that the new limit is lower,
// the new delayable requests don't start until the number of requests in
// flight have gone below the new limit.
TEST_F(ResourceSchedulerTest, RequestLimitReducedAcrossPageLoads) {}

TEST_F(ResourceSchedulerTest, ThrottleDelayableDisabled) {}

// Test that the default limit is used for delayable requests when the
// experiment is enabled, but the current effective connection type is higher
// than the maximum effective connection type set in the experiment
// configuration.
TEST_F(ResourceSchedulerTest, NonDelayableThrottlesDelayableOutsideECT) {}

// Test that delayable requests are throttled by the right amount as the number
// of non-delayable requests in-flight change.
TEST_F(ResourceSchedulerTest, NonDelayableThrottlesDelayableVaryNonDelayable) {}

// Test that each non-delayable request in-flight results in the reduction of
// one in the limit of delayable requests in-flight when the non-delayable
// request weight is 1.
TEST_F(ResourceSchedulerTest, NonDelayableThrottlesDelayableWeight1) {}

// Test that each non-delayable request in-flight results in the reduction of
// three in the limit of delayable requests in-flight when the non-delayable
// request weight is 3.
TEST_F(ResourceSchedulerTest, NonDelayableThrottlesDelayableWeight3) {}

TEST_F(ResourceSchedulerTest, Simple) {}

TEST_F(ResourceSchedulerTest, MultipleInstances_1) {}

TEST_F(ResourceSchedulerTest, MultipleInstances_2) {}

// Verify that when |delay_requests_on_multiplexed_connections| is true, spdy
// hosts are not subject to kMaxNumDelayableRequestsPerHostPerClient limit, but
// are still subject to kDefaultMaxNumDelayableRequestsPerClient limit.
TEST_F(ResourceSchedulerTest,
       MaxRequestsPerHostForSpdyWhenDelayableSlowConnections) {}

TEST_F(ResourceSchedulerTest,
       MaxRequestsPerHostForSpdyWhenDelayableSlowConnectionsWithIsolationInfo) {}

// Verify that when |delay_requests_on_multiplexed_connections| is false, spdy
// hosts are not subject to kMaxNumDelayableRequestsPerHostPerClient or
// kDefaultMaxNumDelayableRequestsPerClient limits.
TEST_F(ResourceSchedulerTest,
       MaxRequestsPerHostForSpdyWhenDelayableFastConnections) {}

// Verify that when |delay_requests_on_multiplexed_connections| is true,
// non-spdy hosts are still subject to kMaxNumDelayableRequestsPerHostPerClient
// limit.
TEST_F(ResourceSchedulerTest,
       MaxRequestsPerHostForNonSpdyWhenDelayableSlowConnections) {}

// Verify that when |delay_requests_on_multiplexed_connections| is true,
// non-spdy requests are still subject to
// kDefaultMaxNumDelayableRequestsPerClient limit.
TEST_F(ResourceSchedulerTest,
       DelayableRequestLimitSpdyDelayableSlowConnections) {}

// Verify that when |max_queuing_time| is set, requests queued for too long
// duration are dispatched to the network.
TEST_F(ResourceSchedulerTest, MaxQueuingDelaySet) {}

// Verify that when |max_queuing_time| is not set, requests queued for too long
// duration are not dispatched to the network.
TEST_F(ResourceSchedulerTest, MaxQueuingDelayNotSet) {}

// Verify that when the timer for dispatching long queued requests is fired,
// then the long queued requests are dispatched to the network.
TEST_F(ResourceSchedulerTest, MaxQueuingDelayTimerFires) {}

// Verify that when the timer for dispatching long queued requests is not fired,
// then the long queued requests are not dispatched to the network.
TEST_F(ResourceSchedulerTest, MaxQueuingDelayTimerNotFired) {}

// Verify that the timer to dispatch long queued requests starts only when there
// are requests in-flight.
TEST_F(ResourceSchedulerTest, MaxQueuingDelayTimerRunsOnRequestSchedule) {}

// Starts a delayable request followed by a non-delayable request. The delayable
// request finishes after the start of the non-delayable request.
TEST_F(ResourceSchedulerTest, NonDelayableRequestArrivesAfterDelayableStarts) {}

// Verify that when the proactive throttling is enabled, then delayable
// requests are throttled.
TEST_F(ResourceSchedulerTest, ProactiveThrottlingExperiment) {}

// Verify that when the proactive throttling is enabled, then delayable
// requests are throttled, and the non-delayable requests are not throttled.
TEST_F(ResourceSchedulerTest,
       ProactiveThrottlingDoesNotThrottleHighPriorityRequests) {}

// Verify that when the proactive throttling is enabled, then delayable
// requests are throttled, and the non-delayable requests are not throttled.
TEST_F(ResourceSchedulerTest, ProactiveThrottling_UnthrottledOnTimerFired) {}

class VisibilityAwareResourceSchedulerTest : public ResourceSchedulerTest {};

TEST_F(VisibilityAwareResourceSchedulerTest, DeprioritizeBackgroundRequest) {}

TEST_F(VisibilityAwareResourceSchedulerTest, BackgroundRequestIgnoreLimit) {}

TEST_F(VisibilityAwareResourceSchedulerTest, ChangePriorityBasedOnVisibility) {}

}  // unnamed namespace

}  // namespace network