| Index: content/renderer/scheduler/resource_dispatch_throttler_unittest.cc
|
| diff --git a/content/renderer/scheduler/resource_dispatch_throttler_unittest.cc b/content/renderer/scheduler/resource_dispatch_throttler_unittest.cc
|
| index a1dbcac7076b45fde695105bc068a5bb6f60c0ad..15a233430c4138611b216ea9c48d16566d3a1361 100644
|
| --- a/content/renderer/scheduler/resource_dispatch_throttler_unittest.cc
|
| +++ b/content/renderer/scheduler/resource_dispatch_throttler_unittest.cc
|
| @@ -75,6 +75,7 @@ class ResourceDispatchThrottlerForTest : public ResourceDispatchThrottler {
|
| scheduler,
|
| base::TimeDelta::FromSecondsD(kFlushPeriodSeconds),
|
| kRequestsPerFlush),
|
| + now_(base::TimeTicks() + base::TimeDelta::FromDays(1)),
|
| flush_scheduled_(false) {}
|
| ~ResourceDispatchThrottlerForTest() override {}
|
|
|
| @@ -252,6 +253,45 @@ TEST_F(ResourceDispatchThrottlerTest, NotThrottledIfSufficientTimePassed) {
|
| }
|
| }
|
|
|
| +TEST_F(ResourceDispatchThrottlerTest, NotThrottledIfSendRateSufficientlyLow) {
|
| + SetHighPriorityWorkAnticipated(true);
|
| +
|
| + // Continuous dispatch of resource requests below the allowed send rate
|
| + // should never throttled.
|
| + const base::TimeDelta kAllowedContinuousSendInterval =
|
| + base::TimeDelta::FromSecondsD((kFlushPeriodSeconds / kRequestsPerFlush) +
|
| + .00001);
|
| + for (size_t i = 0; i < kRequestsPerFlush * 10; ++i) {
|
| + Advance(kAllowedContinuousSendInterval);
|
| + RequestResource();
|
| + EXPECT_EQ(1U, GetAndResetSentMessageCount());
|
| + EXPECT_FALSE(FlushScheduled());
|
| + }
|
| +}
|
| +
|
| +TEST_F(ResourceDispatchThrottlerTest, ThrottledIfSendRateSufficientlyHigh) {
|
| + SetHighPriorityWorkAnticipated(true);
|
| +
|
| + // Continuous dispatch of resource requests above the allowed send rate
|
| + // should be throttled.
|
| + const base::TimeDelta kThrottledContinuousSendInterval =
|
| + base::TimeDelta::FromSecondsD((kFlushPeriodSeconds / kRequestsPerFlush) -
|
| + .00001);
|
| +
|
| + for (size_t i = 0; i < kRequestsPerFlush * 10; ++i) {
|
| + Advance(kThrottledContinuousSendInterval);
|
| + RequestResource();
|
| + // Only the first batch of requests under the limit should be unthrottled.
|
| + if (i < kRequestsPerFlush) {
|
| + EXPECT_EQ(1U, GetAndResetSentMessageCount());
|
| + EXPECT_FALSE(FlushScheduled());
|
| + } else {
|
| + EXPECT_EQ(0U, GetAndResetSentMessageCount());
|
| + EXPECT_TRUE(FlushScheduled());
|
| + }
|
| + }
|
| +}
|
| +
|
| TEST_F(ResourceDispatchThrottlerTest, NotThrottledIfSyncMessage) {
|
| SetHighPriorityWorkAnticipated(true);
|
|
|
|
|