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 <memory> | 7 #include <memory> |
8 #include <queue> | 8 #include <queue> |
9 #include "platform/scheduler/base/task_queue_impl.h" | 9 #include "platform/scheduler/base/task_queue_impl.h" |
10 #include "platform/scheduler/child/web_task_runner_impl.h" | 10 #include "platform/scheduler/child/web_task_runner_impl.h" |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 | 290 |
291 TEST_F(TimerTest, StartRepeatingTask) { | 291 TEST_F(TimerTest, StartRepeatingTask) { |
292 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 292 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
293 timer.startRepeating(1.0, BLINK_FROM_HERE); | 293 timer.startRepeating(1.0, BLINK_FROM_HERE); |
294 | 294 |
295 double runTime; | 295 double runTime; |
296 EXPECT_TRUE(timeTillNextDelayedTask(&runTime)); | 296 EXPECT_TRUE(timeTillNextDelayedTask(&runTime)); |
297 EXPECT_FLOAT_EQ(1.0, runTime); | 297 EXPECT_FLOAT_EQ(1.0, runTime); |
298 | 298 |
299 runUntilDeadline(m_startTime + 5.5); | 299 runUntilDeadline(m_startTime + 5.5); |
300 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 1.0, m_startTime + 2.0, | 300 EXPECT_THAT( |
301 m_startTime + 3.0, m_startTime + 4.0, | 301 m_runTimes, |
302 m_startTime + 5.0)); | 302 ElementsAre(m_startTime + 1.0, m_startTime + 2.0, m_startTime + 3.0, |
| 303 m_startTime + 4.0, m_startTime + 5.0)); |
303 } | 304 } |
304 | 305 |
305 TEST_F(TimerTest, StartRepeatingTask_ThenCancel) { | 306 TEST_F(TimerTest, StartRepeatingTask_ThenCancel) { |
306 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 307 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
307 timer.startRepeating(1.0, BLINK_FROM_HERE); | 308 timer.startRepeating(1.0, BLINK_FROM_HERE); |
308 | 309 |
309 double runTime; | 310 double runTime; |
310 EXPECT_TRUE(timeTillNextDelayedTask(&runTime)); | 311 EXPECT_TRUE(timeTillNextDelayedTask(&runTime)); |
311 EXPECT_FLOAT_EQ(1.0, runTime); | 312 EXPECT_FLOAT_EQ(1.0, runTime); |
312 | 313 |
(...skipping 13 matching lines...) Expand all Loading... |
326 double runTime; | 327 double runTime; |
327 EXPECT_TRUE(timeTillNextDelayedTask(&runTime)); | 328 EXPECT_TRUE(timeTillNextDelayedTask(&runTime)); |
328 EXPECT_FLOAT_EQ(1.0, runTime); | 329 EXPECT_FLOAT_EQ(1.0, runTime); |
329 | 330 |
330 runUntilDeadline(m_startTime + 2.5); | 331 runUntilDeadline(m_startTime + 2.5); |
331 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 1.0, m_startTime + 2.0)); | 332 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 1.0, m_startTime + 2.0)); |
332 | 333 |
333 timer.startOneShot(0, BLINK_FROM_HERE); | 334 timer.startOneShot(0, BLINK_FROM_HERE); |
334 m_platform->runUntilIdle(); | 335 m_platform->runUntilIdle(); |
335 | 336 |
336 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 1.0, m_startTime + 2.0, | 337 EXPECT_THAT( |
337 m_startTime + 2.5)); | 338 m_runTimes, |
| 339 ElementsAre(m_startTime + 1.0, m_startTime + 2.0, m_startTime + 2.5)); |
338 } | 340 } |
339 | 341 |
340 TEST_F(TimerTest, IsActive_NeverPosted) { | 342 TEST_F(TimerTest, IsActive_NeverPosted) { |
341 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 343 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
342 | 344 |
343 EXPECT_FALSE(timer.isActive()); | 345 EXPECT_FALSE(timer.isActive()); |
344 } | 346 } |
345 | 347 |
346 TEST_F(TimerTest, IsActive_AfterPosting_OneShotZero) { | 348 TEST_F(TimerTest, IsActive_AfterPosting_OneShotZero) { |
347 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 349 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 double startTime = monotonicallyIncreasingTime(); | 684 double startTime = monotonicallyIncreasingTime(); |
683 | 685 |
684 timer.startRepeating(1, BLINK_FROM_HERE); | 686 timer.startRepeating(1, BLINK_FROM_HERE); |
685 | 687 |
686 m_platform->runForPeriodSeconds(2.5); | 688 m_platform->runForPeriodSeconds(2.5); |
687 | 689 |
688 timer.moveToNewTaskRunner(webTaskRunner2); | 690 timer.moveToNewTaskRunner(webTaskRunner2); |
689 | 691 |
690 m_platform->runForPeriodSeconds(2); | 692 m_platform->runForPeriodSeconds(2); |
691 | 693 |
692 EXPECT_THAT(m_runTimes, ElementsAre(startTime + 1.0, startTime + 2.0, | 694 EXPECT_THAT(m_runTimes, |
693 startTime + 3.0, startTime + 4.0)); | 695 ElementsAre(startTime + 1.0, startTime + 2.0, startTime + 3.0, |
| 696 startTime + 4.0)); |
694 | 697 |
695 EXPECT_THAT(runOrder, ElementsAre(webTaskRunner1, webTaskRunner1, | 698 EXPECT_THAT(runOrder, |
696 webTaskRunner2, webTaskRunner2)); | 699 ElementsAre(webTaskRunner1, webTaskRunner1, webTaskRunner2, |
| 700 webTaskRunner2)); |
697 | 701 |
698 EXPECT_TRUE(taskRunner1->IsEmpty()); | 702 EXPECT_TRUE(taskRunner1->IsEmpty()); |
699 EXPECT_FALSE(taskRunner2->IsEmpty()); | 703 EXPECT_FALSE(taskRunner2->IsEmpty()); |
700 } | 704 } |
701 | 705 |
702 // This test checks that when inactive timer is moved to a different task | 706 // This test checks that when inactive timer is moved to a different task |
703 // runner it isn't activated. | 707 // runner it isn't activated. |
704 TEST_F(TimerTest, MoveToNewTaskRunnerWithoutTasks) { | 708 TEST_F(TimerTest, MoveToNewTaskRunnerWithoutTasks) { |
705 scoped_refptr<scheduler::TaskQueue> taskRunner1( | 709 scoped_refptr<scheduler::TaskQueue> taskRunner1( |
706 m_platform->rendererScheduler()->NewTimerTaskRunner( | 710 m_platform->rendererScheduler()->NewTimerTaskRunner( |
(...skipping 10 matching lines...) Expand all Loading... |
717 TimerForTest<TimerTest> timer(webTaskRunner1, this, &TimerTest::countingTask); | 721 TimerForTest<TimerTest> timer(webTaskRunner1, this, &TimerTest::countingTask); |
718 | 722 |
719 m_platform->runUntilIdle(); | 723 m_platform->runUntilIdle(); |
720 EXPECT_TRUE(!m_runTimes.size()); | 724 EXPECT_TRUE(!m_runTimes.size()); |
721 EXPECT_TRUE(taskRunner1->IsEmpty()); | 725 EXPECT_TRUE(taskRunner1->IsEmpty()); |
722 EXPECT_TRUE(taskRunner2->IsEmpty()); | 726 EXPECT_TRUE(taskRunner2->IsEmpty()); |
723 } | 727 } |
724 | 728 |
725 } // namespace | 729 } // namespace |
726 } // namespace blink | 730 } // namespace blink |
OLD | NEW |