| Index: cc/scheduler/delay_based_time_source_unittest.cc
|
| diff --git a/cc/scheduler/delay_based_time_source_unittest.cc b/cc/scheduler/delay_based_time_source_unittest.cc
|
| index ac54f57a6344ab89287372c4c1527dfbb4a36f40..b018dc369c67a250d4ddf222d89f16ec132856b0 100644
|
| --- a/cc/scheduler/delay_based_time_source_unittest.cc
|
| +++ b/cc/scheduler/delay_based_time_source_unittest.cc
|
| @@ -305,6 +305,115 @@ TEST(DelayBasedTimeSource, HanldlesSignificantIntervalChangesImmediately) {
|
| EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
|
| }
|
|
|
| +TEST(DelayBasedTimeSource, JitteryRuntimeWithFutureTimebases) {
|
| + scoped_refptr<base::TestSimpleTaskRunner> task_runner =
|
| + new base::TestSimpleTaskRunner;
|
| + FakeTimeSourceClient client;
|
| + scoped_refptr<FakeDelayBasedTimeSource> timer =
|
| + FakeDelayBasedTimeSource::Create(Interval(), task_runner.get());
|
| + timer->SetClient(&client);
|
| + timer->SetActive(true);
|
| +
|
| + // Run the first tick.
|
| + task_runner->RunPendingTasks();
|
| + EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
|
| +
|
| + base::TimeTicks future_timebase = timer->Now() + Interval() * 10;
|
| +
|
| + // 1ms jitter
|
| + base::TimeDelta jitter1 = base::TimeDelta::FromMilliseconds(1);
|
| +
|
| + // Tick with +1ms of jitter
|
| + future_timebase += Interval();
|
| + timer->SetTimebaseAndInterval(future_timebase, Interval());
|
| + timer->SetNow(timer->Now() + Interval() + jitter1);
|
| + task_runner->RunPendingTasks();
|
| + EXPECT_EQ(15, task_runner->NextPendingTaskDelay().InMilliseconds());
|
| +
|
| + // Tick with 0ms of jitter
|
| + future_timebase += Interval();
|
| + timer->SetTimebaseAndInterval(future_timebase, Interval());
|
| + timer->SetNow(timer->Now() + Interval() - jitter1);
|
| + task_runner->RunPendingTasks();
|
| + EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
|
| +
|
| + // Tick with -1ms of jitter
|
| + future_timebase += Interval();
|
| + timer->SetTimebaseAndInterval(future_timebase, Interval());
|
| + timer->SetNow(timer->Now() + Interval() - jitter1);
|
| + task_runner->RunPendingTasks();
|
| + EXPECT_EQ(17, task_runner->NextPendingTaskDelay().InMilliseconds());
|
| +
|
| + // Tick with 0ms of jitter
|
| + future_timebase += Interval();
|
| + timer->SetTimebaseAndInterval(future_timebase, Interval());
|
| + timer->SetNow(timer->Now() + Interval() + jitter1);
|
| + task_runner->RunPendingTasks();
|
| + EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
|
| +
|
| + // 8 ms jitter
|
| + base::TimeDelta jitter8 = base::TimeDelta::FromMilliseconds(8);
|
| +
|
| + // Tick with +8ms of jitter
|
| + future_timebase += Interval();
|
| + timer->SetTimebaseAndInterval(future_timebase, Interval());
|
| + timer->SetNow(timer->Now() + Interval() + jitter8);
|
| + task_runner->RunPendingTasks();
|
| + EXPECT_EQ(8, task_runner->NextPendingTaskDelay().InMilliseconds());
|
| +
|
| + // Tick with 0ms of jitter
|
| + future_timebase += Interval();
|
| + timer->SetTimebaseAndInterval(future_timebase, Interval());
|
| + timer->SetNow(timer->Now() + Interval() - jitter8);
|
| + task_runner->RunPendingTasks();
|
| + EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
|
| +
|
| + // Tick with -8ms of jitter
|
| + future_timebase += Interval();
|
| + timer->SetTimebaseAndInterval(future_timebase, Interval());
|
| + timer->SetNow(timer->Now() + Interval() - jitter8);
|
| + task_runner->RunPendingTasks();
|
| + EXPECT_EQ(24, task_runner->NextPendingTaskDelay().InMilliseconds());
|
| +
|
| + // Tick with 0ms of jitter
|
| + future_timebase += Interval();
|
| + timer->SetTimebaseAndInterval(future_timebase, Interval());
|
| + timer->SetNow(timer->Now() + Interval() + jitter8);
|
| + task_runner->RunPendingTasks();
|
| + EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
|
| +
|
| + // 15 ms jitter
|
| + base::TimeDelta jitter15 = base::TimeDelta::FromMilliseconds(15);
|
| +
|
| + // Tick with +15ms jitter
|
| + future_timebase += Interval();
|
| + timer->SetTimebaseAndInterval(future_timebase, Interval());
|
| + timer->SetNow(timer->Now() + Interval() + jitter15);
|
| + task_runner->RunPendingTasks();
|
| + EXPECT_EQ(1, task_runner->NextPendingTaskDelay().InMilliseconds());
|
| +
|
| + // Tick with 0ms of jitter
|
| + future_timebase += Interval();
|
| + timer->SetTimebaseAndInterval(future_timebase, Interval());
|
| + timer->SetNow(timer->Now() + Interval() - jitter15);
|
| + task_runner->RunPendingTasks();
|
| + EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
|
| +
|
| + // Tick with -15ms of jitter
|
| + future_timebase += Interval();
|
| + timer->SetTimebaseAndInterval(future_timebase, Interval());
|
| + timer->SetNow(timer->Now() + Interval() - jitter15);
|
| + task_runner->RunPendingTasks();
|
| + EXPECT_EQ(31, task_runner->NextPendingTaskDelay().InMilliseconds());
|
| +
|
| + // Tick with 0ms of jitter
|
| + future_timebase += Interval();
|
| + timer->SetTimebaseAndInterval(future_timebase, Interval());
|
| + timer->SetNow(timer->Now() + Interval() + jitter15);
|
| + task_runner->RunPendingTasks();
|
| + EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
|
| +}
|
| +
|
| TEST(DelayBasedTimeSourceTest, AchievesTargetRateWithNoNoise) {
|
| int num_iterations = 10;
|
|
|
|
|