| Index: third_party/WebKit/Source/platform/TimerTest.cpp
|
| diff --git a/third_party/WebKit/Source/platform/TimerTest.cpp b/third_party/WebKit/Source/platform/TimerTest.cpp
|
| index 57b99b5c3e5888955ffc8ccf57ce1a481118eb56..80b97362fd09242c7a287d88f07fb2103f94e80c 100644
|
| --- a/third_party/WebKit/Source/platform/TimerTest.cpp
|
| +++ b/third_party/WebKit/Source/platform/TimerTest.cpp
|
| @@ -27,11 +27,9 @@ namespace {
|
|
|
| class TimerTest : public testing::Test {
|
| public:
|
| - void initialize(
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>&
|
| - platform) {
|
| + void SetUp() override {
|
| m_runTimes.clear();
|
| - platform->advanceClockSeconds(10.0);
|
| + m_platform->advanceClockSeconds(10.0);
|
| m_startTime = monotonicallyIncreasingTime();
|
| }
|
|
|
| @@ -44,29 +42,24 @@ class TimerTest : public testing::Test {
|
| timer->nextFireInterval());
|
| }
|
|
|
| - void runUntilDeadline(ScopedTestingPlatformSupport<
|
| - TestingPlatformSupportWithMockScheduler>& platform,
|
| - double deadline) {
|
| + void runUntilDeadline(double deadline) {
|
| double period = deadline - monotonicallyIncreasingTime();
|
| EXPECT_GE(period, 0.0);
|
| - platform->runForPeriodSeconds(period);
|
| + m_platform->runForPeriodSeconds(period);
|
| }
|
|
|
| // Returns false if there are no pending delayed tasks, otherwise sets |time|
|
| // to the delay in seconds till the next pending delayed task is scheduled to
|
| // fire.
|
| - bool timeTillNextDelayedTask(
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>&
|
| - platform,
|
| - double* time) const {
|
| + bool timeTillNextDelayedTask(double* time) const {
|
| base::TimeTicks nextRunTime;
|
| - if (!platform->rendererScheduler()
|
| + if (!m_platform->rendererScheduler()
|
| ->TimerTaskRunner()
|
| ->GetTimeDomain()
|
| ->NextScheduledRunTime(&nextRunTime))
|
| return false;
|
| *time = (nextRunTime -
|
| - platform->rendererScheduler()
|
| + m_platform->rendererScheduler()
|
| ->TimerTaskRunner()
|
| ->GetTimeDomain()
|
| ->Now())
|
| @@ -78,6 +71,8 @@ class TimerTest : public testing::Test {
|
| double m_startTime;
|
| WTF::Vector<double> m_runTimes;
|
| WTF::Vector<double> m_nextFireTimes;
|
| + ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| + m_platform;
|
| };
|
|
|
| class OnHeapTimerOwner final
|
| @@ -130,289 +125,225 @@ class GCForbiddenScope final {
|
| };
|
|
|
| TEST_F(TimerTest, StartOneShot_Zero) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startOneShot(0, BLINK_FROM_HERE);
|
|
|
| double runTime;
|
| - EXPECT_FALSE(timeTillNextDelayedTask(platform, &runTime));
|
| + EXPECT_FALSE(timeTillNextDelayedTask(&runTime));
|
|
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
| EXPECT_THAT(m_runTimes, ElementsAre(m_startTime));
|
| }
|
|
|
| TEST_F(TimerTest, StartOneShot_ZeroAndCancel) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startOneShot(0, BLINK_FROM_HERE);
|
|
|
| double runTime;
|
| - EXPECT_FALSE(timeTillNextDelayedTask(platform, &runTime));
|
| + EXPECT_FALSE(timeTillNextDelayedTask(&runTime));
|
|
|
| timer.stop();
|
|
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
| EXPECT_FALSE(m_runTimes.size());
|
| }
|
|
|
| TEST_F(TimerTest, StartOneShot_ZeroAndCancelThenRepost) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startOneShot(0, BLINK_FROM_HERE);
|
|
|
| double runTime;
|
| - EXPECT_FALSE(timeTillNextDelayedTask(platform, &runTime));
|
| + EXPECT_FALSE(timeTillNextDelayedTask(&runTime));
|
|
|
| timer.stop();
|
|
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
| EXPECT_FALSE(m_runTimes.size());
|
|
|
| timer.startOneShot(0, BLINK_FROM_HERE);
|
|
|
| - EXPECT_FALSE(timeTillNextDelayedTask(platform, &runTime));
|
| + EXPECT_FALSE(timeTillNextDelayedTask(&runTime));
|
|
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
| EXPECT_THAT(m_runTimes, ElementsAre(m_startTime));
|
| }
|
|
|
| TEST_F(TimerTest, StartOneShot_Zero_RepostingAfterRunning) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startOneShot(0, BLINK_FROM_HERE);
|
|
|
| double runTime;
|
| - EXPECT_FALSE(timeTillNextDelayedTask(platform, &runTime));
|
| + EXPECT_FALSE(timeTillNextDelayedTask(&runTime));
|
|
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
| EXPECT_THAT(m_runTimes, ElementsAre(m_startTime));
|
|
|
| timer.startOneShot(0, BLINK_FROM_HERE);
|
|
|
| - EXPECT_FALSE(timeTillNextDelayedTask(platform, &runTime));
|
| + EXPECT_FALSE(timeTillNextDelayedTask(&runTime));
|
|
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
| EXPECT_THAT(m_runTimes, ElementsAre(m_startTime, m_startTime));
|
| }
|
|
|
| TEST_F(TimerTest, StartOneShot_NonZero) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startOneShot(10.0, BLINK_FROM_HERE);
|
|
|
| double runTime;
|
| - EXPECT_TRUE(timeTillNextDelayedTask(platform, &runTime));
|
| + EXPECT_TRUE(timeTillNextDelayedTask(&runTime));
|
| EXPECT_FLOAT_EQ(10.0, runTime);
|
|
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
| EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 10.0));
|
| }
|
|
|
| TEST_F(TimerTest, StartOneShot_NonZeroAndCancel) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startOneShot(10, BLINK_FROM_HERE);
|
|
|
| double runTime;
|
| - EXPECT_TRUE(timeTillNextDelayedTask(platform, &runTime));
|
| + EXPECT_TRUE(timeTillNextDelayedTask(&runTime));
|
| EXPECT_FLOAT_EQ(10.0, runTime);
|
|
|
| timer.stop();
|
| - EXPECT_TRUE(timeTillNextDelayedTask(platform, &runTime));
|
| + EXPECT_TRUE(timeTillNextDelayedTask(&runTime));
|
|
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
| EXPECT_FALSE(m_runTimes.size());
|
| }
|
|
|
| TEST_F(TimerTest, StartOneShot_NonZeroAndCancelThenRepost) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startOneShot(10, BLINK_FROM_HERE);
|
|
|
| double runTime;
|
| - EXPECT_TRUE(timeTillNextDelayedTask(platform, &runTime));
|
| + EXPECT_TRUE(timeTillNextDelayedTask(&runTime));
|
| EXPECT_FLOAT_EQ(10.0, runTime);
|
|
|
| timer.stop();
|
| - EXPECT_TRUE(timeTillNextDelayedTask(platform, &runTime));
|
| + EXPECT_TRUE(timeTillNextDelayedTask(&runTime));
|
|
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
| EXPECT_FALSE(m_runTimes.size());
|
|
|
| double secondPostTime = monotonicallyIncreasingTime();
|
| timer.startOneShot(10, BLINK_FROM_HERE);
|
|
|
| - EXPECT_TRUE(timeTillNextDelayedTask(platform, &runTime));
|
| + EXPECT_TRUE(timeTillNextDelayedTask(&runTime));
|
| EXPECT_FLOAT_EQ(10.0, runTime);
|
|
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
| EXPECT_THAT(m_runTimes, ElementsAre(secondPostTime + 10.0));
|
| }
|
|
|
| TEST_F(TimerTest, StartOneShot_NonZero_RepostingAfterRunning) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startOneShot(10, BLINK_FROM_HERE);
|
|
|
| double runTime;
|
| - EXPECT_TRUE(timeTillNextDelayedTask(platform, &runTime));
|
| + EXPECT_TRUE(timeTillNextDelayedTask(&runTime));
|
| EXPECT_FLOAT_EQ(10.0, runTime);
|
|
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
| EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 10.0));
|
|
|
| timer.startOneShot(20, BLINK_FROM_HERE);
|
|
|
| - EXPECT_TRUE(timeTillNextDelayedTask(platform, &runTime));
|
| + EXPECT_TRUE(timeTillNextDelayedTask(&runTime));
|
| EXPECT_FLOAT_EQ(20.0, runTime);
|
|
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
| EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 10.0, m_startTime + 30.0));
|
| }
|
|
|
| TEST_F(TimerTest, PostingTimerTwiceWithSameRunTimeDoesNothing) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startOneShot(10, BLINK_FROM_HERE);
|
| timer.startOneShot(10, BLINK_FROM_HERE);
|
|
|
| double runTime;
|
| - EXPECT_TRUE(timeTillNextDelayedTask(platform, &runTime));
|
| + EXPECT_TRUE(timeTillNextDelayedTask(&runTime));
|
| EXPECT_FLOAT_EQ(10.0, runTime);
|
|
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
| EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 10.0));
|
| }
|
|
|
| TEST_F(TimerTest, PostingTimerTwiceWithNewerRunTimeCancelsOriginalTask) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startOneShot(10, BLINK_FROM_HERE);
|
| timer.startOneShot(0, BLINK_FROM_HERE);
|
|
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
| EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 0.0));
|
| }
|
|
|
| TEST_F(TimerTest, PostingTimerTwiceWithLaterRunTimeCancelsOriginalTask) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startOneShot(0, BLINK_FROM_HERE);
|
| timer.startOneShot(10, BLINK_FROM_HERE);
|
|
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
| EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 10.0));
|
| }
|
|
|
| TEST_F(TimerTest, StartRepeatingTask) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startRepeating(1.0, BLINK_FROM_HERE);
|
|
|
| double runTime;
|
| - EXPECT_TRUE(timeTillNextDelayedTask(platform, &runTime));
|
| + EXPECT_TRUE(timeTillNextDelayedTask(&runTime));
|
| EXPECT_FLOAT_EQ(1.0, runTime);
|
|
|
| - runUntilDeadline(platform, m_startTime + 5.5);
|
| + runUntilDeadline(m_startTime + 5.5);
|
| EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 1.0, m_startTime + 2.0,
|
| m_startTime + 3.0, m_startTime + 4.0,
|
| m_startTime + 5.0));
|
| }
|
|
|
| TEST_F(TimerTest, StartRepeatingTask_ThenCancel) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startRepeating(1.0, BLINK_FROM_HERE);
|
|
|
| double runTime;
|
| - EXPECT_TRUE(timeTillNextDelayedTask(platform, &runTime));
|
| + EXPECT_TRUE(timeTillNextDelayedTask(&runTime));
|
| EXPECT_FLOAT_EQ(1.0, runTime);
|
|
|
| - runUntilDeadline(platform, m_startTime + 2.5);
|
| + runUntilDeadline(m_startTime + 2.5);
|
| EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 1.0, m_startTime + 2.0));
|
|
|
| timer.stop();
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
|
|
| EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 1.0, m_startTime + 2.0));
|
| }
|
|
|
| TEST_F(TimerTest, StartRepeatingTask_ThenPostOneShot) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startRepeating(1.0, BLINK_FROM_HERE);
|
|
|
| double runTime;
|
| - EXPECT_TRUE(timeTillNextDelayedTask(platform, &runTime));
|
| + EXPECT_TRUE(timeTillNextDelayedTask(&runTime));
|
| EXPECT_FLOAT_EQ(1.0, runTime);
|
|
|
| - runUntilDeadline(platform, m_startTime + 2.5);
|
| + runUntilDeadline(m_startTime + 2.5);
|
| EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 1.0, m_startTime + 2.0));
|
|
|
| timer.startOneShot(0, BLINK_FROM_HERE);
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
|
|
| EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 1.0, m_startTime + 2.0,
|
| m_startTime + 2.5));
|
| }
|
|
|
| TEST_F(TimerTest, IsActive_NeverPosted) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
|
|
| EXPECT_FALSE(timer.isActive());
|
| }
|
|
|
| TEST_F(TimerTest, IsActive_AfterPosting_OneShotZero) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startOneShot(0, BLINK_FROM_HERE);
|
|
|
| @@ -420,10 +351,6 @@ TEST_F(TimerTest, IsActive_AfterPosting_OneShotZero) {
|
| }
|
|
|
| TEST_F(TimerTest, IsActive_AfterPosting_OneShotNonZero) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startOneShot(10, BLINK_FROM_HERE);
|
|
|
| @@ -431,10 +358,6 @@ TEST_F(TimerTest, IsActive_AfterPosting_OneShotNonZero) {
|
| }
|
|
|
| TEST_F(TimerTest, IsActive_AfterPosting_Repeating) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startRepeating(1.0, BLINK_FROM_HERE);
|
|
|
| @@ -442,46 +365,30 @@ TEST_F(TimerTest, IsActive_AfterPosting_Repeating) {
|
| }
|
|
|
| TEST_F(TimerTest, IsActive_AfterRunning_OneShotZero) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startOneShot(0, BLINK_FROM_HERE);
|
|
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
| EXPECT_FALSE(timer.isActive());
|
| }
|
|
|
| TEST_F(TimerTest, IsActive_AfterRunning_OneShotNonZero) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startOneShot(10, BLINK_FROM_HERE);
|
|
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
| EXPECT_FALSE(timer.isActive());
|
| }
|
|
|
| TEST_F(TimerTest, IsActive_AfterRunning_Repeating) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startRepeating(1.0, BLINK_FROM_HERE);
|
|
|
| - runUntilDeadline(platform, m_startTime + 10);
|
| + runUntilDeadline(m_startTime + 10);
|
| EXPECT_TRUE(timer.isActive()); // It should run until cancelled.
|
| }
|
|
|
| TEST_F(TimerTest, NextFireInterval_OneShotZero) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startOneShot(0, BLINK_FROM_HERE);
|
|
|
| @@ -489,10 +396,6 @@ TEST_F(TimerTest, NextFireInterval_OneShotZero) {
|
| }
|
|
|
| TEST_F(TimerTest, NextFireInterval_OneShotNonZero) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startOneShot(10, BLINK_FROM_HERE);
|
|
|
| @@ -500,24 +403,16 @@ TEST_F(TimerTest, NextFireInterval_OneShotNonZero) {
|
| }
|
|
|
| TEST_F(TimerTest, NextFireInterval_OneShotNonZero_AfterAFewSeconds) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| - platform->setAutoAdvanceNowToPendingTasks(false);
|
| + m_platform->setAutoAdvanceNowToPendingTasks(false);
|
|
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startOneShot(10, BLINK_FROM_HERE);
|
|
|
| - platform->advanceClockSeconds(2.0);
|
| + m_platform->advanceClockSeconds(2.0);
|
| EXPECT_FLOAT_EQ(8.0, timer.nextFireInterval());
|
| }
|
|
|
| TEST_F(TimerTest, NextFireInterval_Repeating) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startRepeating(20, BLINK_FROM_HERE);
|
|
|
| @@ -525,20 +420,12 @@ TEST_F(TimerTest, NextFireInterval_Repeating) {
|
| }
|
|
|
| TEST_F(TimerTest, RepeatInterval_NeverStarted) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
|
|
| EXPECT_FLOAT_EQ(0.0, timer.repeatInterval());
|
| }
|
|
|
| TEST_F(TimerTest, RepeatInterval_OneShotZero) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startOneShot(0, BLINK_FROM_HERE);
|
|
|
| @@ -546,10 +433,6 @@ TEST_F(TimerTest, RepeatInterval_OneShotZero) {
|
| }
|
|
|
| TEST_F(TimerTest, RepeatInterval_OneShotNonZero) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startOneShot(10, BLINK_FROM_HERE);
|
|
|
| @@ -557,10 +440,6 @@ TEST_F(TimerTest, RepeatInterval_OneShotNonZero) {
|
| }
|
|
|
| TEST_F(TimerTest, RepeatInterval_Repeating) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startRepeating(20, BLINK_FROM_HERE);
|
|
|
| @@ -568,16 +447,12 @@ TEST_F(TimerTest, RepeatInterval_Repeating) {
|
| }
|
|
|
| TEST_F(TimerTest, AugmentRepeatInterval) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startRepeating(10, BLINK_FROM_HERE);
|
| EXPECT_FLOAT_EQ(10.0, timer.repeatInterval());
|
| EXPECT_FLOAT_EQ(10.0, timer.nextFireInterval());
|
|
|
| - platform->advanceClockSeconds(2.0);
|
| + m_platform->advanceClockSeconds(2.0);
|
| timer.augmentRepeatInterval(10);
|
|
|
| EXPECT_FLOAT_EQ(20.0, timer.repeatInterval());
|
| @@ -587,23 +462,19 @@ TEST_F(TimerTest, AugmentRepeatInterval) {
|
| // cc::OrderedSimpleTaskRunner) results in somewhat strange behavior of the
|
| // test clock which breaks this test. Specifically the test clock advancing
|
| // logic ignores newly posted delayed tasks and advances too far.
|
| - runUntilDeadline(platform, m_startTime + 50.0);
|
| + runUntilDeadline(m_startTime + 50.0);
|
| EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 20.0, m_startTime + 40.0));
|
| }
|
|
|
| TEST_F(TimerTest, AugmentRepeatInterval_TimerFireDelayed) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| - platform->setAutoAdvanceNowToPendingTasks(false);
|
| + m_platform->setAutoAdvanceNowToPendingTasks(false);
|
|
|
| Timer<TimerTest> timer(this, &TimerTest::countingTask);
|
| timer.startRepeating(10, BLINK_FROM_HERE);
|
| EXPECT_FLOAT_EQ(10.0, timer.repeatInterval());
|
| EXPECT_FLOAT_EQ(10.0, timer.nextFireInterval());
|
|
|
| - platform->advanceClockSeconds(123.0); // Make the timer long overdue.
|
| + m_platform->advanceClockSeconds(123.0); // Make the timer long overdue.
|
| timer.augmentRepeatInterval(10);
|
|
|
| EXPECT_FLOAT_EQ(20.0, timer.repeatInterval());
|
| @@ -612,11 +483,7 @@ TEST_F(TimerTest, AugmentRepeatInterval_TimerFireDelayed) {
|
| }
|
|
|
| TEST_F(TimerTest, RepeatingTimerDoesNotDrift) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| - platform->setAutoAdvanceNowToPendingTasks(false);
|
| + m_platform->setAutoAdvanceNowToPendingTasks(false);
|
|
|
| Timer<TimerTest> timer(this, &TimerTest::recordNextFireTimeTask);
|
| timer.startRepeating(2.0, BLINK_FROM_HERE);
|
| @@ -626,24 +493,24 @@ TEST_F(TimerTest, RepeatingTimerDoesNotDrift) {
|
|
|
| // Simulate timer firing early. Next scheduled task to run at
|
| // m_startTime + 4.0
|
| - platform->advanceClockSeconds(1.9);
|
| - runUntilDeadline(platform, monotonicallyIncreasingTime() + 0.2);
|
| + m_platform->advanceClockSeconds(1.9);
|
| + runUntilDeadline(monotonicallyIncreasingTime() + 0.2);
|
|
|
| // Next scheduled task to run at m_startTime + 6.0
|
| - platform->runForPeriodSeconds(2.0);
|
| + m_platform->runForPeriodSeconds(2.0);
|
| // Next scheduled task to run at m_startTime + 8.0
|
| - platform->runForPeriodSeconds(2.1);
|
| + m_platform->runForPeriodSeconds(2.1);
|
| // Next scheduled task to run at m_startTime + 10.0
|
| - platform->runForPeriodSeconds(2.9);
|
| + m_platform->runForPeriodSeconds(2.9);
|
| // Next scheduled task to run at m_startTime + 14.0 (skips a beat)
|
| - platform->advanceClockSeconds(3.1);
|
| - platform->runUntilIdle();
|
| + m_platform->advanceClockSeconds(3.1);
|
| + m_platform->runUntilIdle();
|
| // Next scheduled task to run at m_startTime + 18.0 (skips a beat)
|
| - platform->advanceClockSeconds(4.0);
|
| - platform->runUntilIdle();
|
| + m_platform->advanceClockSeconds(4.0);
|
| + m_platform->runUntilIdle();
|
| // Next scheduled task to run at m_startTime + 28.0 (skips 5 beats)
|
| - platform->advanceClockSeconds(10.0);
|
| - platform->runUntilIdle();
|
| + m_platform->advanceClockSeconds(10.0);
|
| + m_platform->runUntilIdle();
|
|
|
| EXPECT_THAT(
|
| m_nextFireTimes,
|
| @@ -669,12 +536,8 @@ class TimerForTest : public TaskRunnerTimer<TimerFiredClass> {
|
| };
|
|
|
| TEST_F(TimerTest, UserSuppliedWebTaskRunner) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| scoped_refptr<scheduler::TaskQueue> taskRunner(
|
| - platform->rendererScheduler()->NewTimerTaskRunner(
|
| + m_platform->rendererScheduler()->NewTimerTaskRunner(
|
| scheduler::TaskQueue::QueueType::TEST));
|
| RefPtr<scheduler::WebTaskRunnerImpl> webTaskRunner =
|
| scheduler::WebTaskRunnerImpl::create(taskRunner);
|
| @@ -686,25 +549,17 @@ TEST_F(TimerTest, UserSuppliedWebTaskRunner) {
|
| }
|
|
|
| TEST_F(TimerTest, RunOnHeapTimer) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| RefPtr<OnHeapTimerOwner::Record> record = OnHeapTimerOwner::Record::create();
|
| Persistent<OnHeapTimerOwner> owner = new OnHeapTimerOwner(record);
|
|
|
| owner->startOneShot(0, BLINK_FROM_HERE);
|
|
|
| EXPECT_FALSE(record->timerHasFired());
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
| EXPECT_TRUE(record->timerHasFired());
|
| }
|
|
|
| TEST_F(TimerTest, DestructOnHeapTimer) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| RefPtr<OnHeapTimerOwner::Record> record = OnHeapTimerOwner::Record::create();
|
| Persistent<OnHeapTimerOwner> owner = new OnHeapTimerOwner(record);
|
|
|
| @@ -717,15 +572,11 @@ TEST_F(TimerTest, DestructOnHeapTimer) {
|
| EXPECT_TRUE(record->ownerIsDestructed());
|
|
|
| EXPECT_FALSE(record->timerHasFired());
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
| EXPECT_FALSE(record->timerHasFired());
|
| }
|
|
|
| TEST_F(TimerTest, MarkOnHeapTimerAsUnreachable) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| RefPtr<OnHeapTimerOwner::Record> record = OnHeapTimerOwner::Record::create();
|
| Persistent<OnHeapTimerOwner> owner = new OnHeapTimerOwner(record);
|
|
|
| @@ -741,7 +592,7 @@ TEST_F(TimerTest, MarkOnHeapTimerAsUnreachable) {
|
| {
|
| GCForbiddenScope scope;
|
| EXPECT_FALSE(record->timerHasFired());
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
| EXPECT_FALSE(record->timerHasFired());
|
| EXPECT_FALSE(record->ownerIsDestructed());
|
| }
|
| @@ -769,14 +620,10 @@ class TaskObserver : public base::MessageLoop::TaskObserver {
|
| } // namespace
|
|
|
| TEST_F(TimerTest, MoveToNewTaskRunnerOneShot) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| std::vector<RefPtr<WebTaskRunner>> runOrder;
|
|
|
| scoped_refptr<scheduler::TaskQueue> taskRunner1(
|
| - platform->rendererScheduler()->NewTimerTaskRunner(
|
| + m_platform->rendererScheduler()->NewTimerTaskRunner(
|
| scheduler::TaskQueue::QueueType::TEST));
|
| RefPtr<scheduler::WebTaskRunnerImpl> webTaskRunner1 =
|
| scheduler::WebTaskRunnerImpl::create(taskRunner1);
|
| @@ -784,7 +631,7 @@ TEST_F(TimerTest, MoveToNewTaskRunnerOneShot) {
|
| taskRunner1->AddTaskObserver(&taskObserver1);
|
|
|
| scoped_refptr<scheduler::TaskQueue> taskRunner2(
|
| - platform->rendererScheduler()->NewTimerTaskRunner(
|
| + m_platform->rendererScheduler()->NewTimerTaskRunner(
|
| scheduler::TaskQueue::QueueType::TEST));
|
| RefPtr<scheduler::WebTaskRunnerImpl> webTaskRunner2 =
|
| scheduler::WebTaskRunnerImpl::create(taskRunner2);
|
| @@ -797,11 +644,11 @@ TEST_F(TimerTest, MoveToNewTaskRunnerOneShot) {
|
|
|
| timer.startOneShot(1, BLINK_FROM_HERE);
|
|
|
| - platform->runForPeriodSeconds(0.5);
|
| + m_platform->runForPeriodSeconds(0.5);
|
|
|
| timer.moveToNewTaskRunner(webTaskRunner2);
|
|
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
|
|
| EXPECT_THAT(m_runTimes, ElementsAre(startTime + 1.0));
|
|
|
| @@ -812,14 +659,10 @@ TEST_F(TimerTest, MoveToNewTaskRunnerOneShot) {
|
| }
|
|
|
| TEST_F(TimerTest, MoveToNewTaskRunnerRepeating) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| std::vector<RefPtr<WebTaskRunner>> runOrder;
|
|
|
| scoped_refptr<scheduler::TaskQueue> taskRunner1(
|
| - platform->rendererScheduler()->NewTimerTaskRunner(
|
| + m_platform->rendererScheduler()->NewTimerTaskRunner(
|
| scheduler::TaskQueue::QueueType::TEST));
|
| RefPtr<scheduler::WebTaskRunnerImpl> webTaskRunner1 =
|
| scheduler::WebTaskRunnerImpl::create(taskRunner1);
|
| @@ -827,7 +670,7 @@ TEST_F(TimerTest, MoveToNewTaskRunnerRepeating) {
|
| taskRunner1->AddTaskObserver(&taskObserver1);
|
|
|
| scoped_refptr<scheduler::TaskQueue> taskRunner2(
|
| - platform->rendererScheduler()->NewTimerTaskRunner(
|
| + m_platform->rendererScheduler()->NewTimerTaskRunner(
|
| scheduler::TaskQueue::QueueType::TEST));
|
| RefPtr<scheduler::WebTaskRunnerImpl> webTaskRunner2 =
|
| scheduler::WebTaskRunnerImpl::create(taskRunner2);
|
| @@ -840,11 +683,11 @@ TEST_F(TimerTest, MoveToNewTaskRunnerRepeating) {
|
|
|
| timer.startRepeating(1, BLINK_FROM_HERE);
|
|
|
| - platform->runForPeriodSeconds(2.5);
|
| + m_platform->runForPeriodSeconds(2.5);
|
|
|
| timer.moveToNewTaskRunner(webTaskRunner2);
|
|
|
| - platform->runForPeriodSeconds(2);
|
| + m_platform->runForPeriodSeconds(2);
|
|
|
| EXPECT_THAT(m_runTimes, ElementsAre(startTime + 1.0, startTime + 2.0,
|
| startTime + 3.0, startTime + 4.0));
|
| @@ -859,25 +702,21 @@ TEST_F(TimerTest, MoveToNewTaskRunnerRepeating) {
|
| // This test checks that when inactive timer is moved to a different task
|
| // runner it isn't activated.
|
| TEST_F(TimerTest, MoveToNewTaskRunnerWithoutTasks) {
|
| - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| - platform;
|
| - initialize(platform);
|
| -
|
| scoped_refptr<scheduler::TaskQueue> taskRunner1(
|
| - platform->rendererScheduler()->NewTimerTaskRunner(
|
| + m_platform->rendererScheduler()->NewTimerTaskRunner(
|
| scheduler::TaskQueue::QueueType::TEST));
|
| RefPtr<scheduler::WebTaskRunnerImpl> webTaskRunner1 =
|
| scheduler::WebTaskRunnerImpl::create(taskRunner1);
|
|
|
| scoped_refptr<scheduler::TaskQueue> taskRunner2(
|
| - platform->rendererScheduler()->NewTimerTaskRunner(
|
| + m_platform->rendererScheduler()->NewTimerTaskRunner(
|
| scheduler::TaskQueue::QueueType::TEST));
|
| RefPtr<scheduler::WebTaskRunnerImpl> webTaskRunner2 =
|
| scheduler::WebTaskRunnerImpl::create(taskRunner2);
|
|
|
| TimerForTest<TimerTest> timer(webTaskRunner1, this, &TimerTest::countingTask);
|
|
|
| - platform->runUntilIdle();
|
| + m_platform->runUntilIdle();
|
| EXPECT_TRUE(!m_runTimes.size());
|
| EXPECT_TRUE(taskRunner1->IsEmpty());
|
| EXPECT_TRUE(taskRunner2->IsEmpty());
|
|
|