summaryrefslogtreecommitdiff
path: root/chromium/cc/scheduler/delay_based_time_source_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/cc/scheduler/delay_based_time_source_unittest.cc')
-rw-r--r--chromium/cc/scheduler/delay_based_time_source_unittest.cc133
1 files changed, 12 insertions, 121 deletions
diff --git a/chromium/cc/scheduler/delay_based_time_source_unittest.cc b/chromium/cc/scheduler/delay_based_time_source_unittest.cc
index 77d570f1d92..df84c978e57 100644
--- a/chromium/cc/scheduler/delay_based_time_source_unittest.cc
+++ b/chromium/cc/scheduler/delay_based_time_source_unittest.cc
@@ -88,7 +88,7 @@ TEST(DelayBasedTimeSource, NextDelaySaneWhenExactlyOnRequestedTime) {
FakeDelayBasedTimeSource::Create(Interval(), task_runner.get());
timer->SetClient(&client);
timer->SetActive(true);
- // Run the first tick.
+ // Run the first task, as that activates the timer and picks up a timebase.
task_runner->RunPendingTasks();
EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
@@ -109,7 +109,7 @@ TEST(DelayBasedTimeSource, NextDelaySaneWhenSlightlyAfterRequestedTime) {
FakeDelayBasedTimeSource::Create(Interval(), task_runner.get());
timer->SetClient(&client);
timer->SetActive(true);
- // Run the first tick.
+ // Run the first task, as that activates the timer and picks up a timebase.
task_runner->RunPendingTasks();
EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
@@ -122,7 +122,7 @@ TEST(DelayBasedTimeSource, NextDelaySaneWhenSlightlyAfterRequestedTime) {
}
// At 60Hz, when the tick returns at exactly 2*interval after the requested next
-// time, make sure a 0ms next delay is posted.
+// time, make sure a 16ms next delay is posted.
TEST(DelayBasedTimeSource, NextDelaySaneWhenExactlyTwiceAfterRequestedTime) {
scoped_refptr<base::TestSimpleTaskRunner> task_runner =
new base::TestSimpleTaskRunner;
@@ -131,7 +131,7 @@ TEST(DelayBasedTimeSource, NextDelaySaneWhenExactlyTwiceAfterRequestedTime) {
FakeDelayBasedTimeSource::Create(Interval(), task_runner.get());
timer->SetClient(&client);
timer->SetActive(true);
- // Run the first tick.
+ // Run the first task, as that activates the timer and picks up a timebase.
task_runner->RunPendingTasks();
EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
@@ -139,7 +139,7 @@ TEST(DelayBasedTimeSource, NextDelaySaneWhenExactlyTwiceAfterRequestedTime) {
timer->SetNow(timer->Now() + 2 * Interval());
task_runner->RunPendingTasks();
- EXPECT_EQ(0, task_runner->NextPendingTaskDelay().InMilliseconds());
+ EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
}
// At 60Hz, when the tick returns at 2*interval and a bit after the requested
@@ -152,7 +152,7 @@ TEST(DelayBasedTimeSource, NextDelaySaneWhenSlightlyAfterTwiceRequestedTime) {
FakeDelayBasedTimeSource::Create(Interval(), task_runner.get());
timer->SetClient(&client);
timer->SetActive(true);
- // Run the first tick.
+ // Run the first task, as that activates the timer and picks up a timebase.
task_runner->RunPendingTasks();
EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
@@ -174,7 +174,7 @@ TEST(DelayBasedTimeSource, NextDelaySaneWhenHalfAfterRequestedTime) {
FakeDelayBasedTimeSource::Create(Interval(), task_runner.get());
timer->SetClient(&client);
timer->SetActive(true);
- // Run the first tick.
+ // Run the first task, as that activates the timer and picks up a timebase.
task_runner->RunPendingTasks();
EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
@@ -196,7 +196,7 @@ TEST(DelayBasedTimeSource, SaneHandlingOfJitteryTimebase) {
FakeDelayBasedTimeSource::Create(Interval(), task_runner.get());
timer->SetClient(&client);
timer->SetActive(true);
- // Run the first tick.
+ // Run the first task, as that activates the timer and picks up a timebase.
task_runner->RunPendingTasks();
EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
@@ -227,7 +227,7 @@ TEST(DelayBasedTimeSource, HandlesSignificantTimebaseChangesImmediately) {
FakeDelayBasedTimeSource::Create(Interval(), task_runner.get());
timer->SetClient(&client);
timer->SetActive(true);
- // Run the first tick.
+ // Run the first task, as that activates the timer and picks up a timebase.
task_runner->RunPendingTasks();
EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
@@ -246,10 +246,10 @@ TEST(DelayBasedTimeSource, HandlesSignificantTimebaseChangesImmediately) {
timer->SetTimebaseAndInterval(timer->Now() + jitter, Interval());
EXPECT_FALSE(client.TickCalled()); // Make sure pending tasks were canceled.
- EXPECT_EQ(16 + 7, task_runner->NextPendingTaskDelay().InMilliseconds());
+ EXPECT_EQ(7, task_runner->NextPendingTaskDelay().InMilliseconds());
// Tick, then shift timebase by -7ms.
- timer->SetNow(timer->Now() + Interval() + jitter);
+ timer->SetNow(timer->Now() + jitter);
task_runner->RunPendingTasks();
EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
@@ -271,7 +271,7 @@ TEST(DelayBasedTimeSource, HanldlesSignificantIntervalChangesImmediately) {
FakeDelayBasedTimeSource::Create(Interval(), task_runner.get());
timer->SetClient(&client);
timer->SetActive(true);
- // Run the first tick.
+ // Run the first task, as that activates the timer and picks up a timebase.
task_runner->RunPendingTasks();
EXPECT_EQ(16, task_runner->NextPendingTaskDelay().InMilliseconds());
@@ -305,115 +305,6 @@ 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;