Index: third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler_unittest.cc |
diff --git a/third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler_unittest.cc b/third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler_unittest.cc |
index 66eec630903f7bfa9480d857b43d5ea9cf8384a0..d4aa08f9d5e8697ead6b6dd14050bb9768685ec8 100644 |
--- a/third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler_unittest.cc |
+++ b/third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler_unittest.cc |
@@ -61,7 +61,29 @@ bool IsQueueBlocked(TaskQueue* task_queue) { |
static_cast<internal::EnqueueOrder>( |
internal::EnqueueOrderValues::BLOCKING_FENCE); |
} |
-} |
+ |
+// Test clock which simulates passage of time by automatically |
+// advancing time with each call to Now(). |
+class AutoAdvancingTestClock : public base::SimpleTestTickClock { |
+ public: |
+ AutoAdvancingTestClock(base::TimeDelta interval) |
+ : advancing_interval_(interval) {} |
+ ~AutoAdvancingTestClock() override {} |
+ |
+ base::TimeTicks NowTicks() override { |
+ Advance(advancing_interval_); |
+ return SimpleTestTickClock::NowTicks(); |
+ } |
+ |
+ base::TimeTicks GetNowTicksWithoutAdvancing() { |
+ return SimpleTestTickClock::NowTicks(); |
+ } |
+ |
+ private: |
+ base::TimeDelta advancing_interval_; |
+}; |
+ |
+} // namespace |
class TaskQueueThrottlerTest : public testing::Test { |
public: |
@@ -69,7 +91,7 @@ class TaskQueueThrottlerTest : public testing::Test { |
~TaskQueueThrottlerTest() override {} |
void SetUp() override { |
- clock_.reset(new base::SimpleTestTickClock()); |
+ clock_ = CreateClock(); |
clock_->Advance(base::TimeDelta::FromMicroseconds(5000)); |
mock_task_runner_ = |
make_scoped_refptr(new cc::OrderedSimpleTaskRunner(clock_.get(), true)); |
@@ -109,7 +131,11 @@ class TaskQueueThrottlerTest : public testing::Test { |
} |
protected: |
- std::unique_ptr<base::SimpleTestTickClock> clock_; |
+ virtual std::unique_ptr<AutoAdvancingTestClock> CreateClock() { |
+ return base::MakeUnique<AutoAdvancingTestClock>(base::TimeDelta()); |
+ } |
+ |
+ std::unique_ptr<AutoAdvancingTestClock> clock_; |
scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; |
scoped_refptr<SchedulerTqmDelegate> delegate_; |
std::unique_ptr<RendererSchedulerImpl> scheduler_; |
@@ -119,6 +145,46 @@ class TaskQueueThrottlerTest : public testing::Test { |
DISALLOW_COPY_AND_ASSIGN(TaskQueueThrottlerTest); |
}; |
+class TaskQueueThrottlerWithAutoAdvancingTimeTest |
+ : public TaskQueueThrottlerTest, |
+ public ::testing::WithParamInterface<bool> { |
+ public: |
+ TaskQueueThrottlerWithAutoAdvancingTimeTest() |
+ : auto_advance_time_interval_(GetParam() |
+ ? base::TimeDelta::FromMicroseconds(1) |
+ : base::TimeDelta()) {} |
+ ~TaskQueueThrottlerWithAutoAdvancingTimeTest() override {} |
+ |
+ protected: |
+ std::unique_ptr<AutoAdvancingTestClock> CreateClock() override { |
+ return base::MakeUnique<AutoAdvancingTestClock>( |
+ auto_advance_time_interval_); |
+ } |
+ |
+ base::TimeDelta auto_advance_time_interval_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TaskQueueThrottlerWithAutoAdvancingTimeTest); |
+}; |
+ |
+INSTANTIATE_TEST_CASE_P(All, |
+ TaskQueueThrottlerWithAutoAdvancingTimeTest, |
+ ::testing::Bool()); |
+ |
+TEST_F(TaskQueueThrottlerTest, ThrottledTasksReportRealTime) { |
+ EXPECT_EQ(timer_queue_->GetTimeDomain()->Now(), |
+ clock_->GetNowTicksWithoutAdvancing()); |
+ |
+ task_queue_throttler_->IncreaseThrottleRefCount(timer_queue_.get()); |
+ EXPECT_EQ(timer_queue_->GetTimeDomain()->Now(), |
+ clock_->GetNowTicksWithoutAdvancing()); |
+ |
+ clock_->Advance(base::TimeDelta::FromMilliseconds(250)); |
+ // Make sure the throttled time domain's Now() reports the same as the |
+ // underlying clock. |
+ EXPECT_EQ(timer_queue_->GetTimeDomain()->Now(), |
+ clock_->GetNowTicksWithoutAdvancing()); |
+} |
+ |
TEST_F(TaskQueueThrottlerTest, AlignedThrottledRunTime) { |
EXPECT_EQ(base::TimeTicks() + base::TimeDelta::FromSecondsD(1.0), |
TaskQueueThrottler::AlignedThrottledRunTime( |
@@ -162,24 +228,38 @@ TEST_F(TaskQueueThrottlerTest, AlignedThrottledRunTime) { |
} |
namespace { |
+ |
+// Round up time to milliseconds to deal with autoadvancing time. |
+// TODO(altimin): round time only when autoadvancing time is enabled. |
+base::TimeDelta RoundTimeToMilliseconds(base::TimeDelta time) { |
+ return time - time % base::TimeDelta::FromMilliseconds(1); |
+} |
+ |
+base::TimeTicks RoundTimeToMilliseconds(base::TimeTicks time) { |
+ return base::TimeTicks() + RoundTimeToMilliseconds(time - base::TimeTicks()); |
+} |
+ |
void TestTask(std::vector<base::TimeTicks>* run_times, |
- base::SimpleTestTickClock* clock) { |
- run_times->push_back(clock->NowTicks()); |
+ AutoAdvancingTestClock* clock) { |
+ run_times->push_back( |
+ RoundTimeToMilliseconds(clock->GetNowTicksWithoutAdvancing())); |
} |
void ExpensiveTestTask(std::vector<base::TimeTicks>* run_times, |
- base::SimpleTestTickClock* clock) { |
- run_times->push_back(clock->NowTicks()); |
+ AutoAdvancingTestClock* clock) { |
+ run_times->push_back( |
+ RoundTimeToMilliseconds(clock->GetNowTicksWithoutAdvancing())); |
clock->Advance(base::TimeDelta::FromMilliseconds(250)); |
} |
void RecordThrottling(std::vector<base::TimeDelta>* reported_throttling_times, |
base::TimeDelta throttling_duration) { |
- reported_throttling_times->push_back(throttling_duration); |
+ reported_throttling_times->push_back( |
+ RoundTimeToMilliseconds(throttling_duration)); |
} |
} // namespace |
-TEST_F(TaskQueueThrottlerTest, TimerAlignment) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, TimerAlignment) { |
std::vector<base::TimeTicks> run_times; |
timer_queue_->PostDelayedTask(FROM_HERE, |
base::Bind(&TestTask, &run_times, clock_.get()), |
@@ -211,9 +291,10 @@ TEST_F(TaskQueueThrottlerTest, TimerAlignment) { |
base::TimeTicks() + base::TimeDelta::FromMilliseconds(9000.0))); |
} |
-TEST_F(TaskQueueThrottlerTest, TimerAlignment_Unthrottled) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
+ TimerAlignment_Unthrottled) { |
std::vector<base::TimeTicks> run_times; |
- base::TimeTicks start_time = clock_->NowTicks(); |
+ base::TimeTicks start_time = clock_->GetNowTicksWithoutAdvancing(); |
timer_queue_->PostDelayedTask(FROM_HERE, |
base::Bind(&TestTask, &run_times, clock_.get()), |
base::TimeDelta::FromMilliseconds(200.0)); |
@@ -238,13 +319,17 @@ TEST_F(TaskQueueThrottlerTest, TimerAlignment_Unthrottled) { |
// Times are not aligned. |
EXPECT_THAT( |
run_times, |
- ElementsAre(start_time + base::TimeDelta::FromMilliseconds(200.0), |
- start_time + base::TimeDelta::FromMilliseconds(800.0), |
- start_time + base::TimeDelta::FromMilliseconds(1200.0), |
- start_time + base::TimeDelta::FromMilliseconds(8300.0))); |
+ ElementsAre(RoundTimeToMilliseconds( |
+ start_time + base::TimeDelta::FromMilliseconds(200.0)), |
+ RoundTimeToMilliseconds( |
+ start_time + base::TimeDelta::FromMilliseconds(800.0)), |
+ RoundTimeToMilliseconds( |
+ start_time + base::TimeDelta::FromMilliseconds(1200.0)), |
+ RoundTimeToMilliseconds( |
+ start_time + base::TimeDelta::FromMilliseconds(8300.0)))); |
} |
-TEST_F(TaskQueueThrottlerTest, Refcount) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, Refcount) { |
ExpectUnthrottled(timer_queue_.get()); |
task_queue_throttler_->IncreaseThrottleRefCount(timer_queue_.get()); |
@@ -267,21 +352,23 @@ TEST_F(TaskQueueThrottlerTest, Refcount) { |
ExpectThrottled(timer_queue_); |
} |
-TEST_F(TaskQueueThrottlerTest, |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
ThrotlingAnEmptyQueueDoesNotPostPumpThrottledTasksLocked) { |
task_queue_throttler_->IncreaseThrottleRefCount(timer_queue_.get()); |
EXPECT_TRUE(task_queue_throttler_->task_queue()->IsEmpty()); |
} |
-TEST_F(TaskQueueThrottlerTest, OnTimeDomainHasImmediateWork_EnabledQueue) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
+ OnTimeDomainHasImmediateWork_EnabledQueue) { |
task_queue_throttler_->OnQueueNextWakeUpChanged(timer_queue_.get(), |
base::TimeTicks()); |
// Check PostPumpThrottledTasksLocked was called. |
EXPECT_FALSE(task_queue_throttler_->task_queue()->IsEmpty()); |
} |
-TEST_F(TaskQueueThrottlerTest, OnTimeDomainHasImmediateWork_DisabledQueue) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
+ OnTimeDomainHasImmediateWork_DisabledQueue) { |
std::unique_ptr<TaskQueue::QueueEnabledVoter> voter = |
timer_queue_->CreateQueueEnabledVoter(); |
voter->SetQueueEnabled(false); |
@@ -292,7 +379,7 @@ TEST_F(TaskQueueThrottlerTest, OnTimeDomainHasImmediateWork_DisabledQueue) { |
EXPECT_TRUE(task_queue_throttler_->task_queue()->IsEmpty()); |
} |
-TEST_F(TaskQueueThrottlerTest, |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
ThrottlingADisabledQueueDoesNotPostPumpThrottledTasks) { |
timer_queue_->PostTask(FROM_HERE, base::Bind(&NopTask)); |
@@ -308,7 +395,7 @@ TEST_F(TaskQueueThrottlerTest, |
EXPECT_FALSE(task_queue_throttler_->task_queue()->IsEmpty()); |
} |
-TEST_F(TaskQueueThrottlerTest, |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
ThrottlingADisabledQueueDoesNotPostPumpThrottledTasks_DelayedTask) { |
timer_queue_->PostDelayedTask(FROM_HERE, base::Bind(&NopTask), |
base::TimeDelta::FromMilliseconds(1)); |
@@ -325,7 +412,7 @@ TEST_F(TaskQueueThrottlerTest, |
EXPECT_FALSE(task_queue_throttler_->task_queue()->IsEmpty()); |
} |
-TEST_F(TaskQueueThrottlerTest, WakeUpForNonDelayedTask) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, WakeUpForNonDelayedTask) { |
std::vector<base::TimeTicks> run_times; |
// Nothing is posted on timer_queue_ so PumpThrottledTasks will not tick. |
@@ -341,7 +428,7 @@ TEST_F(TaskQueueThrottlerTest, WakeUpForNonDelayedTask) { |
base::TimeDelta::FromMilliseconds(1000.0))); |
} |
-TEST_F(TaskQueueThrottlerTest, WakeUpForDelayedTask) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, WakeUpForDelayedTask) { |
std::vector<base::TimeTicks> run_times; |
// Nothing is posted on timer_queue_ so PumpThrottledTasks will not tick. |
@@ -358,7 +445,7 @@ TEST_F(TaskQueueThrottlerTest, WakeUpForDelayedTask) { |
base::TimeDelta::FromMilliseconds(2000.0))); |
} |
-TEST_F(TaskQueueThrottlerTest, |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
SingleThrottledTaskPumpedAndRunWithNoExtraneousMessageLoopTasks) { |
task_queue_throttler_->IncreaseThrottleRefCount(timer_queue_.get()); |
@@ -373,7 +460,7 @@ TEST_F(TaskQueueThrottlerTest, |
EXPECT_EQ(1u, task_count); |
} |
-TEST_F(TaskQueueThrottlerTest, |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
SingleFutureThrottledTaskPumpedAndRunWithNoExtraneousMessageLoopTasks) { |
task_queue_throttler_->IncreaseThrottleRefCount(timer_queue_.get()); |
@@ -388,7 +475,7 @@ TEST_F(TaskQueueThrottlerTest, |
EXPECT_EQ(1u, task_count); |
} |
-TEST_F(TaskQueueThrottlerTest, |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
TwoFutureThrottledTaskPumpedAndRunWithNoExtraneousMessageLoopTasks) { |
task_queue_throttler_->IncreaseThrottleRefCount(timer_queue_.get()); |
std::vector<base::TimeTicks> run_times; |
@@ -414,7 +501,8 @@ TEST_F(TaskQueueThrottlerTest, |
base::TimeTicks() + base::TimeDelta::FromSeconds(16))); |
} |
-TEST_F(TaskQueueThrottlerTest, TaskDelayIsBasedOnRealTime) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
+ TaskDelayIsBasedOnRealTime) { |
std::vector<base::TimeTicks> run_times; |
task_queue_throttler_->IncreaseThrottleRefCount(timer_queue_.get()); |
@@ -444,19 +532,7 @@ TEST_F(TaskQueueThrottlerTest, TaskDelayIsBasedOnRealTime) { |
base::TimeTicks() + base::TimeDelta::FromMilliseconds(3000.0))); |
} |
-TEST_F(TaskQueueThrottlerTest, ThrottledTasksReportRealTime) { |
- EXPECT_EQ(timer_queue_->GetTimeDomain()->Now(), clock_->NowTicks()); |
- |
- task_queue_throttler_->IncreaseThrottleRefCount(timer_queue_.get()); |
- EXPECT_EQ(timer_queue_->GetTimeDomain()->Now(), clock_->NowTicks()); |
- |
- clock_->Advance(base::TimeDelta::FromMilliseconds(250)); |
- // Make sure the throttled time domain's Now() reports the same as the |
- // underlying clock. |
- EXPECT_EQ(timer_queue_->GetTimeDomain()->Now(), clock_->NowTicks()); |
-} |
- |
-TEST_F(TaskQueueThrottlerTest, TaskQueueDisabledTillPump) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, TaskQueueDisabledTillPump) { |
size_t count = 0; |
timer_queue_->PostTask(FROM_HERE, base::Bind(&AddOneTask, &count)); |
@@ -469,7 +545,8 @@ TEST_F(TaskQueueThrottlerTest, TaskQueueDisabledTillPump) { |
EXPECT_FALSE(IsQueueBlocked(timer_queue_.get())); |
} |
-TEST_F(TaskQueueThrottlerTest, DoubleIncrementDoubleDecrement) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
+ DoubleIncrementDoubleDecrement) { |
timer_queue_->PostTask(FROM_HERE, base::Bind(&NopTask)); |
EXPECT_FALSE(IsQueueBlocked(timer_queue_.get())); |
@@ -481,7 +558,8 @@ TEST_F(TaskQueueThrottlerTest, DoubleIncrementDoubleDecrement) { |
EXPECT_FALSE(IsQueueBlocked(timer_queue_.get())); |
} |
-TEST_F(TaskQueueThrottlerTest, EnableVirtualTimeThenIncrement) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
+ EnableVirtualTimeThenIncrement) { |
timer_queue_->PostTask(FROM_HERE, base::Bind(&NopTask)); |
scheduler_->EnableVirtualTime(); |
@@ -493,7 +571,8 @@ TEST_F(TaskQueueThrottlerTest, EnableVirtualTimeThenIncrement) { |
EXPECT_EQ(timer_queue_->GetTimeDomain(), scheduler_->GetVirtualTimeDomain()); |
} |
-TEST_F(TaskQueueThrottlerTest, IncrementThenEnableVirtualTime) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
+ IncrementThenEnableVirtualTime) { |
timer_queue_->PostTask(FROM_HERE, base::Bind(&NopTask)); |
EXPECT_FALSE(IsQueueBlocked(timer_queue_.get())); |
@@ -505,7 +584,7 @@ TEST_F(TaskQueueThrottlerTest, IncrementThenEnableVirtualTime) { |
EXPECT_EQ(timer_queue_->GetTimeDomain(), scheduler_->GetVirtualTimeDomain()); |
} |
-TEST_F(TaskQueueThrottlerTest, TimeBasedThrottling) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, TimeBasedThrottling) { |
std::vector<base::TimeTicks> run_times; |
CPUTimeBudgetPool* pool = |
@@ -531,7 +610,7 @@ TEST_F(TaskQueueThrottlerTest, TimeBasedThrottling) { |
ElementsAre(base::TimeTicks() + base::TimeDelta::FromSeconds(1), |
base::TimeTicks() + base::TimeDelta::FromSeconds(3))); |
- pool->RemoveQueue(clock_->NowTicks(), timer_queue_.get()); |
+ pool->RemoveQueue(clock_->GetNowTicksWithoutAdvancing(), timer_queue_.get()); |
run_times.clear(); |
// Queue was removed from CPUTimeBudgetPool, only timer alignment should be |
@@ -554,7 +633,8 @@ TEST_F(TaskQueueThrottlerTest, TimeBasedThrottling) { |
pool->Close(); |
} |
-TEST_F(TaskQueueThrottlerTest, EnableAndDisableCPUTimeBudgetPool) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
+ EnableAndDisableCPUTimeBudgetPool) { |
std::vector<base::TimeTicks> run_times; |
CPUTimeBudgetPool* pool = |
@@ -610,11 +690,12 @@ TEST_F(TaskQueueThrottlerTest, EnableAndDisableCPUTimeBudgetPool) { |
task_queue_throttler_->DecreaseThrottleRefCount(timer_queue_.get()); |
- pool->RemoveQueue(clock_->NowTicks(), timer_queue_.get()); |
+ pool->RemoveQueue(clock_->GetNowTicksWithoutAdvancing(), timer_queue_.get()); |
pool->Close(); |
} |
-TEST_F(TaskQueueThrottlerTest, ImmediateTasksTimeBudgetThrottling) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
+ ImmediateTasksTimeBudgetThrottling) { |
std::vector<base::TimeTicks> run_times; |
CPUTimeBudgetPool* pool = |
@@ -638,7 +719,7 @@ TEST_F(TaskQueueThrottlerTest, ImmediateTasksTimeBudgetThrottling) { |
ElementsAre(base::TimeTicks() + base::TimeDelta::FromSeconds(1), |
base::TimeTicks() + base::TimeDelta::FromSeconds(3))); |
- pool->RemoveQueue(clock_->NowTicks(), timer_queue_.get()); |
+ pool->RemoveQueue(clock_->GetNowTicksWithoutAdvancing(), timer_queue_.get()); |
run_times.clear(); |
// Queue was removed from CPUTimeBudgetPool, only timer alignment should be |
@@ -659,7 +740,8 @@ TEST_F(TaskQueueThrottlerTest, ImmediateTasksTimeBudgetThrottling) { |
pool->Close(); |
} |
-TEST_F(TaskQueueThrottlerTest, TwoQueuesTimeBudgetThrottling) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
+ TwoQueuesTimeBudgetThrottling) { |
std::vector<base::TimeTicks> run_times; |
scoped_refptr<TaskQueue> second_queue = |
@@ -689,13 +771,14 @@ TEST_F(TaskQueueThrottlerTest, TwoQueuesTimeBudgetThrottling) { |
task_queue_throttler_->DecreaseThrottleRefCount(timer_queue_.get()); |
task_queue_throttler_->DecreaseThrottleRefCount(second_queue.get()); |
- pool->RemoveQueue(clock_->NowTicks(), timer_queue_.get()); |
- pool->RemoveQueue(clock_->NowTicks(), second_queue.get()); |
+ pool->RemoveQueue(clock_->GetNowTicksWithoutAdvancing(), timer_queue_.get()); |
+ pool->RemoveQueue(clock_->GetNowTicksWithoutAdvancing(), second_queue.get()); |
pool->Close(); |
} |
-TEST_F(TaskQueueThrottlerTest, DisabledTimeBudgetDoesNotAffectThrottledQueues) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
+ DisabledTimeBudgetDoesNotAffectThrottledQueues) { |
std::vector<base::TimeTicks> run_times; |
LazyNow lazy_now(clock_.get()); |
@@ -723,7 +806,7 @@ TEST_F(TaskQueueThrottlerTest, DisabledTimeBudgetDoesNotAffectThrottledQueues) { |
base::TimeTicks() + base::TimeDelta::FromMilliseconds(1250))); |
} |
-TEST_F(TaskQueueThrottlerTest, |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
TimeBudgetThrottlingDoesNotAffectUnthrottledQueues) { |
std::vector<base::TimeTicks> run_times; |
@@ -734,7 +817,7 @@ TEST_F(TaskQueueThrottlerTest, |
LazyNow lazy_now(clock_.get()); |
pool->DisableThrottling(&lazy_now); |
- pool->AddQueue(clock_->NowTicks(), timer_queue_.get()); |
+ pool->AddQueue(clock_->GetNowTicksWithoutAdvancing(), timer_queue_.get()); |
timer_queue_->PostDelayedTask( |
FROM_HERE, base::Bind(&ExpensiveTestTask, &run_times, clock_.get()), |
@@ -751,7 +834,7 @@ TEST_F(TaskQueueThrottlerTest, |
base::TimeTicks() + base::TimeDelta::FromMilliseconds(355))); |
} |
-TEST_F(TaskQueueThrottlerTest, MaxThrottlingDelay) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, MaxThrottlingDelay) { |
std::vector<base::TimeTicks> run_times; |
CPUTimeBudgetPool* pool = |
@@ -782,7 +865,8 @@ TEST_F(TaskQueueThrottlerTest, MaxThrottlingDelay) { |
base::TimeTicks() + base::TimeDelta::FromSeconds(245))); |
} |
-TEST_F(TaskQueueThrottlerTest, EnableAndDisableThrottling) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
+ EnableAndDisableThrottling) { |
std::vector<base::TimeTicks> run_times; |
task_queue_throttler_->IncreaseThrottleRefCount(timer_queue_.get()); |
@@ -844,7 +928,7 @@ TEST_F(TaskQueueThrottlerTest, EnableAndDisableThrottling) { |
base::TimeDelta::FromMilliseconds(2000))); |
} |
-TEST_F(TaskQueueThrottlerTest, ReportThrottling) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, ReportThrottling) { |
std::vector<base::TimeTicks> run_times; |
std::vector<base::TimeDelta> reported_throttling_times; |
@@ -880,12 +964,12 @@ TEST_F(TaskQueueThrottlerTest, ReportThrottling) { |
ElementsAre(base::TimeDelta::FromMilliseconds(1255), |
base::TimeDelta::FromMilliseconds(1755))); |
- pool->RemoveQueue(clock_->NowTicks(), timer_queue_.get()); |
+ pool->RemoveQueue(clock_->GetNowTicksWithoutAdvancing(), timer_queue_.get()); |
task_queue_throttler_->DecreaseThrottleRefCount(timer_queue_.get()); |
pool->Close(); |
} |
-TEST_F(TaskQueueThrottlerTest, GrantAdditionalBudget) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, GrantAdditionalBudget) { |
std::vector<base::TimeTicks> run_times; |
CPUTimeBudgetPool* pool = |
@@ -916,12 +1000,13 @@ TEST_F(TaskQueueThrottlerTest, GrantAdditionalBudget) { |
base::TimeTicks() + base::TimeDelta::FromSeconds(3), |
base::TimeTicks() + base::TimeDelta::FromSeconds(6))); |
- pool->RemoveQueue(clock_->NowTicks(), timer_queue_.get()); |
+ pool->RemoveQueue(clock_->GetNowTicksWithoutAdvancing(), timer_queue_.get()); |
task_queue_throttler_->DecreaseThrottleRefCount(timer_queue_.get()); |
pool->Close(); |
} |
-TEST_F(TaskQueueThrottlerTest, EnableAndDisableThrottlingAndTimeBudgets) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
+ EnableAndDisableThrottlingAndTimeBudgets) { |
// This test checks that if time budget pool is enabled when throttling |
// is disabled, it does not throttle the queue. |
std::vector<base::TimeTicks> run_times; |
@@ -953,7 +1038,8 @@ TEST_F(TaskQueueThrottlerTest, EnableAndDisableThrottlingAndTimeBudgets) { |
base::TimeDelta::FromMilliseconds(300))); |
} |
-TEST_F(TaskQueueThrottlerTest, AddQueueToBudgetPoolWhenThrottlingDisabled) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
+ AddQueueToBudgetPoolWhenThrottlingDisabled) { |
// This test checks that a task queue is added to time budget pool |
// when throttling is disabled, is does not throttle queue. |
std::vector<base::TimeTicks> run_times; |
@@ -979,7 +1065,8 @@ TEST_F(TaskQueueThrottlerTest, AddQueueToBudgetPoolWhenThrottlingDisabled) { |
base::TimeDelta::FromMilliseconds(300))); |
} |
-TEST_F(TaskQueueThrottlerTest, DisabledQueueThenEnabledQueue) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
+ DisabledQueueThenEnabledQueue) { |
std::vector<base::TimeTicks> run_times; |
scoped_refptr<TaskQueue> second_queue = |
@@ -1015,7 +1102,7 @@ TEST_F(TaskQueueThrottlerTest, DisabledQueueThenEnabledQueue) { |
base::TimeTicks() + base::TimeDelta::FromMilliseconds(2000))); |
} |
-TEST_F(TaskQueueThrottlerTest, TwoBudgetPools) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, TwoBudgetPools) { |
std::vector<base::TimeTicks> run_times; |
scoped_refptr<TaskQueue> second_queue = |
@@ -1058,10 +1145,11 @@ TEST_F(TaskQueueThrottlerTest, TwoBudgetPools) { |
namespace { |
void RunChainedTask(size_t run_times_count, |
scoped_refptr<TaskQueue> queue, |
- base::SimpleTestTickClock* clock, |
+ AutoAdvancingTestClock* clock, |
base::TimeDelta task_duration, |
std::vector<base::TimeTicks>* run_times) { |
- run_times->push_back(clock->NowTicks()); |
+ run_times->push_back( |
+ RoundTimeToMilliseconds(clock->GetNowTicksWithoutAdvancing())); |
clock->Advance(task_duration); |
if (run_times_count <= 1) |
@@ -1074,11 +1162,12 @@ void RunChainedTask(size_t run_times_count, |
void RunChainedDelayedTask(size_t run_times_count, |
scoped_refptr<TaskQueue> queue, |
- base::SimpleTestTickClock* clock, |
+ AutoAdvancingTestClock* clock, |
base::TimeDelta task_duration, |
std::vector<base::TimeTicks>* run_times, |
base::TimeDelta delay) { |
- run_times->push_back(clock->NowTicks()); |
+ run_times->push_back( |
+ RoundTimeToMilliseconds(clock->GetNowTicksWithoutAdvancing())); |
clock->Advance(task_duration); |
if (run_times_count <= 1) |
@@ -1092,7 +1181,7 @@ void RunChainedDelayedTask(size_t run_times_count, |
} |
} // namespace |
-TEST_F(TaskQueueThrottlerTest, |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
WakeUpBasedThrottling_ChainedTasks_Instantaneous) { |
scheduler_->GetWakeUpBudgetPoolForTesting()->SetWakeUpDuration( |
base::TimeDelta::FromMilliseconds(10)); |
@@ -1121,7 +1210,8 @@ TEST_F(TaskQueueThrottlerTest, |
base::TimeTicks() + base::TimeDelta::FromSeconds(1))); |
} |
-TEST_F(TaskQueueThrottlerTest, WakeUpBasedThrottling_ImmediateTasks_Fast) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
+ WakeUpBasedThrottling_ImmediateTasks_Fast) { |
scheduler_->GetWakeUpBudgetPoolForTesting()->SetWakeUpDuration( |
base::TimeDelta::FromMilliseconds(10)); |
std::vector<base::TimeTicks> run_times; |
@@ -1151,7 +1241,8 @@ TEST_F(TaskQueueThrottlerTest, WakeUpBasedThrottling_ImmediateTasks_Fast) { |
base::TimeTicks() + base::TimeDelta::FromMilliseconds(2012))); |
} |
-TEST_F(TaskQueueThrottlerTest, WakeUpBasedThrottling_DelayedTasks) { |
+TEST_P(TaskQueueThrottlerWithAutoAdvancingTimeTest, |
+ WakeUpBasedThrottling_DelayedTasks) { |
scheduler_->GetWakeUpBudgetPoolForTesting()->SetWakeUpDuration( |
base::TimeDelta::FromMilliseconds(10)); |
std::vector<base::TimeTicks> run_times; |