| 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/testing/TestingPlatformSupport.h" | 7 #include "platform/testing/TestingPlatformSupport.h" |
| 8 #include "public/platform/Platform.h" | 8 #include "public/platform/Platform.h" |
| 9 #include "public/platform/WebScheduler.h" | 9 #include "public/platform/WebScheduler.h" |
| 10 #include "public/platform/WebThread.h" | 10 #include "public/platform/WebThread.h" |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 | 295 |
| 296 class TimerTest : public testing::Test { | 296 class TimerTest : public testing::Test { |
| 297 public: | 297 public: |
| 298 void SetUp() override | 298 void SetUp() override |
| 299 { | 299 { |
| 300 m_runTimes.clear(); | 300 m_runTimes.clear(); |
| 301 gCurrentTimeSecs = 10.0; | 301 gCurrentTimeSecs = 10.0; |
| 302 m_startTime = gCurrentTimeSecs; | 302 m_startTime = gCurrentTimeSecs; |
| 303 } | 303 } |
| 304 | 304 |
| 305 void countingTask(Timer<TimerTest>*) | 305 void countingTask(TimerBase*) |
| 306 { | 306 { |
| 307 m_runTimes.append(gCurrentTimeSecs); | 307 m_runTimes.append(gCurrentTimeSecs); |
| 308 } | 308 } |
| 309 | 309 |
| 310 void recordNextFireTimeTask(Timer<TimerTest>* timer) | 310 void recordNextFireTimeTask(TimerBase* timer) |
| 311 { | 311 { |
| 312 m_nextFireTimes.append(gCurrentTimeSecs + timer->nextFireInterval()); | 312 m_nextFireTimes.append(gCurrentTimeSecs + timer->nextFireInterval()); |
| 313 } | 313 } |
| 314 | 314 |
| 315 void advanceTimeBy(double timeSecs) | 315 void advanceTimeBy(double timeSecs) |
| 316 { | 316 { |
| 317 gCurrentTimeSecs += timeSecs; | 317 gCurrentTimeSecs += timeSecs; |
| 318 } | 318 } |
| 319 | 319 |
| 320 void runUntilIdle() | 320 void runUntilIdle() |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 m_startTime + 4.0, | 758 m_startTime + 4.0, |
| 759 m_startTime + 6.0, | 759 m_startTime + 6.0, |
| 760 m_startTime + 8.0, | 760 m_startTime + 8.0, |
| 761 m_startTime + 10.0, | 761 m_startTime + 10.0, |
| 762 m_startTime + 14.0, | 762 m_startTime + 14.0, |
| 763 m_startTime + 18.0, | 763 m_startTime + 18.0, |
| 764 m_startTime + 28.0)); | 764 m_startTime + 28.0)); |
| 765 } | 765 } |
| 766 | 766 |
| 767 template <typename TimerFiredClass> | 767 template <typename TimerFiredClass> |
| 768 class TimerForTest : public Timer<TimerFiredClass> { | 768 class TimerForTest : public TaskRunnerTimer<TimerFiredClass> { |
| 769 public: | 769 public: |
| 770 using TimerFiredFunction = void (TimerFiredClass::*)(Timer<TimerFiredClass>*
); | 770 using TimerFiredFunction = typename TaskRunnerTimer<TimerFiredClass>::TimerF
iredFunction; |
| 771 | 771 |
| 772 ~TimerForTest() override { } | 772 ~TimerForTest() override { } |
| 773 | 773 |
| 774 TimerForTest(TimerFiredClass* timerFiredClass, TimerFiredFunction timerFired
Function, WebTaskRunner* webTaskRunner) | 774 TimerForTest(WebTaskRunner* webTaskRunner, TimerFiredClass* timerFiredClass,
TimerFiredFunction timerFiredFunction) |
| 775 : Timer<TimerFiredClass>(timerFiredClass, timerFiredFunction, webTaskRun
ner) | 775 : TaskRunnerTimer<TimerFiredClass>(webTaskRunner, timerFiredClass, timer
FiredFunction) |
| 776 { | 776 { |
| 777 } | 777 } |
| 778 }; | 778 }; |
| 779 | 779 |
| 780 TEST_F(TimerTest, UserSuppliedWebTaskRunner) | 780 TEST_F(TimerTest, UserSuppliedWebTaskRunner) |
| 781 { | 781 { |
| 782 std::priority_queue<DelayedTask> timerTasks; | 782 std::priority_queue<DelayedTask> timerTasks; |
| 783 MockWebTaskRunner taskRunner(&timerTasks); | 783 MockWebTaskRunner taskRunner(&timerTasks); |
| 784 TimerForTest<TimerTest> timer(this, &TimerTest::countingTask, &taskRunner); | 784 TimerForTest<TimerTest> timer(&taskRunner, this, &TimerTest::countingTask); |
| 785 timer.startOneShot(0, BLINK_FROM_HERE); | 785 timer.startOneShot(0, BLINK_FROM_HERE); |
| 786 | 786 |
| 787 // Make sure the task was posted on taskRunner. | 787 // Make sure the task was posted on taskRunner. |
| 788 EXPECT_FALSE(timerTasks.empty()); | 788 EXPECT_FALSE(timerTasks.empty()); |
| 789 } | 789 } |
| 790 | 790 |
| 791 | 791 |
| 792 } // namespace | 792 } // namespace |
| 793 } // namespace blink | 793 } // namespace blink |
| OLD | NEW |