OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "platform/Timer.h" | 5 #include "platform/Timer.h" |
6 | 6 |
7 #include "platform/scheduler/base/task_queue_impl.h" | 7 #include "platform/scheduler/base/task_queue_impl.h" |
8 #include "platform/scheduler/child/web_task_runner_impl.h" | 8 #include "platform/scheduler/child/web_task_runner_impl.h" |
9 #include "platform/scheduler/renderer/renderer_scheduler_impl.h" | 9 #include "platform/scheduler/renderer/renderer_scheduler_impl.h" |
10 #include "platform/testing/TestingPlatformSupport.h" | 10 #include "platform/testing/TestingPlatformSupport.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 void recordNextFireTimeTask(TimerBase* timer) { | 40 void recordNextFireTimeTask(TimerBase* timer) { |
41 m_nextFireTimes.append(monotonicallyIncreasingTime() + | 41 m_nextFireTimes.append(monotonicallyIncreasingTime() + |
42 timer->nextFireInterval()); | 42 timer->nextFireInterval()); |
43 } | 43 } |
44 | 44 |
45 void runUntilDeadline(double deadline) { | 45 void runUntilDeadline(double deadline) { |
46 double period = deadline - monotonicallyIncreasingTime(); | 46 double period = deadline - monotonicallyIncreasingTime(); |
47 EXPECT_GE(period, 0.0); | 47 EXPECT_GE(period, 0.0); |
48 m_platform.runForPeriodSeconds(period); | 48 m_platform.runForPeriodSeconds(period); |
49 | |
50 // We may have stopped before the clock advanced to |deadline|. | |
51 double timeToAdvance = deadline - monotonicallyIncreasingTime(); | |
52 m_platform.advanceClockSeconds(timeToAdvance); | |
53 } | 49 } |
54 | 50 |
55 // Returns false if there are no pending delayed tasks, otherwise sets |time| | 51 // Returns false if there are no pending delayed tasks, otherwise sets |time| |
56 // to the delay in seconds till the next pending delayed task is scheduled to | 52 // to the delay in seconds till the next pending delayed task is scheduled to |
57 // fire. | 53 // fire. |
58 bool timeTillNextDelayedTask(double* time) const { | 54 bool timeTillNextDelayedTask(double* time) const { |
59 base::TimeTicks nextRunTime; | 55 base::TimeTicks nextRunTime; |
60 if (!m_platform.rendererScheduler() | 56 if (!m_platform.rendererScheduler() |
61 ->TimerTaskRunner() | 57 ->TimerTaskRunner() |
62 ->GetTimeDomain() | 58 ->GetTimeDomain() |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 m_platform.advanceClockSeconds(1.9); | 446 m_platform.advanceClockSeconds(1.9); |
451 runUntilDeadline(monotonicallyIncreasingTime() + 0.2); | 447 runUntilDeadline(monotonicallyIncreasingTime() + 0.2); |
452 | 448 |
453 // Next scheduled task to run at m_startTime + 6.0 | 449 // Next scheduled task to run at m_startTime + 6.0 |
454 m_platform.runForPeriodSeconds(2.0); | 450 m_platform.runForPeriodSeconds(2.0); |
455 // Next scheduled task to run at m_startTime + 8.0 | 451 // Next scheduled task to run at m_startTime + 8.0 |
456 m_platform.runForPeriodSeconds(2.1); | 452 m_platform.runForPeriodSeconds(2.1); |
457 // Next scheduled task to run at m_startTime + 10.0 | 453 // Next scheduled task to run at m_startTime + 10.0 |
458 m_platform.runForPeriodSeconds(2.9); | 454 m_platform.runForPeriodSeconds(2.9); |
459 // Next scheduled task to run at m_startTime + 14.0 (skips a beat) | 455 // Next scheduled task to run at m_startTime + 14.0 (skips a beat) |
460 m_platform.runForPeriodSeconds(3.1); | 456 m_platform.advanceClockSeconds(3.1); |
| 457 m_platform.runUntilIdle(); |
461 // Next scheduled task to run at m_startTime + 18.0 (skips a beat) | 458 // Next scheduled task to run at m_startTime + 18.0 (skips a beat) |
462 m_platform.runForPeriodSeconds(4.0); | 459 m_platform.advanceClockSeconds(4.0); |
| 460 m_platform.runUntilIdle(); |
463 // Next scheduled task to run at m_startTime + 28.0 (skips 5 beats) | 461 // Next scheduled task to run at m_startTime + 28.0 (skips 5 beats) |
464 m_platform.runForPeriodSeconds(10.0); | 462 m_platform.advanceClockSeconds(10.0); |
| 463 m_platform.runUntilIdle(); |
465 | 464 |
466 EXPECT_THAT( | 465 EXPECT_THAT( |
467 m_nextFireTimes, | 466 m_nextFireTimes, |
468 ElementsAre(m_startTime + 2.0, m_startTime + 4.0, m_startTime + 6.0, | 467 ElementsAre(m_startTime + 2.0, m_startTime + 4.0, m_startTime + 6.0, |
469 m_startTime + 8.0, m_startTime + 10.0, m_startTime + 14.0, | 468 m_startTime + 8.0, m_startTime + 10.0, m_startTime + 14.0, |
470 m_startTime + 18.0, m_startTime + 28.0)); | 469 m_startTime + 18.0, m_startTime + 28.0)); |
471 } | 470 } |
472 | 471 |
473 template <typename TimerFiredClass> | 472 template <typename TimerFiredClass> |
474 class TimerForTest : public TaskRunnerTimer<TimerFiredClass> { | 473 class TimerForTest : public TaskRunnerTimer<TimerFiredClass> { |
(...skipping 17 matching lines...) Expand all Loading... |
492 scheduler::WebTaskRunnerImpl webTaskRunner(taskRunner); | 491 scheduler::WebTaskRunnerImpl webTaskRunner(taskRunner); |
493 TimerForTest<TimerTest> timer(&webTaskRunner, this, &TimerTest::countingTask); | 492 TimerForTest<TimerTest> timer(&webTaskRunner, this, &TimerTest::countingTask); |
494 timer.startOneShot(0, BLINK_FROM_HERE); | 493 timer.startOneShot(0, BLINK_FROM_HERE); |
495 | 494 |
496 // Make sure the task was posted on taskRunner. | 495 // Make sure the task was posted on taskRunner. |
497 EXPECT_FALSE(taskRunner->IsEmpty()); | 496 EXPECT_FALSE(taskRunner->IsEmpty()); |
498 } | 497 } |
499 | 498 |
500 } // namespace | 499 } // namespace |
501 } // namespace blink | 500 } // namespace blink |
OLD | NEW |