| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 | 178 |
| 179 bool hasOneTimerTask() const | 179 bool hasOneTimerTask() const |
| 180 { | 180 { |
| 181 return m_timerTasks.size() == 1; | 181 return m_timerTasks.size() == 1; |
| 182 } | 182 } |
| 183 | 183 |
| 184 double nextTimerTaskDelaySecs() const | 184 double nextTimerTaskDelaySecs() const |
| 185 { | 185 { |
| 186 ASSERT(hasOneTimerTask()); | |
| 187 return m_timerTasks.top().delaySeconds(); | 186 return m_timerTasks.top().delaySeconds(); |
| 188 } | 187 } |
| 189 | 188 |
| 190 void shutdown() override {} | 189 void shutdown() override {} |
| 191 std::unique_ptr<WebViewScheduler> createWebViewScheduler(blink::WebView*) ov
erride { return nullptr; } | 190 std::unique_ptr<WebViewScheduler> createWebViewScheduler(blink::WebView*) ov
erride { return nullptr; } |
| 192 void suspendTimerQueue() override { } | 191 void suspendTimerQueue() override { } |
| 193 void resumeTimerQueue() override { } | 192 void resumeTimerQueue() override { } |
| 194 void addPendingNavigation(WebScheduler::NavigatingFrameType) override { } | 193 void addPendingNavigation(WebScheduler::NavigatingFrameType) override { } |
| 195 void removePendingNavigation(WebScheduler::NavigatingFrameType) override { } | 194 void removePendingNavigation(WebScheduler::NavigatingFrameType) override { } |
| 196 void onNavigationStarted() override { } | 195 void onNavigationStarted() override { } |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 | 474 |
| 476 timer.startOneShot(20, BLINK_FROM_HERE); | 475 timer.startOneShot(20, BLINK_FROM_HERE); |
| 477 | 476 |
| 478 ASSERT(hasOneTimerTask()); | 477 ASSERT(hasOneTimerTask()); |
| 479 EXPECT_FLOAT_EQ(20.0, nextTimerTaskDelaySecs()); | 478 EXPECT_FLOAT_EQ(20.0, nextTimerTaskDelaySecs()); |
| 480 | 479 |
| 481 runUntilIdle(); | 480 runUntilIdle(); |
| 482 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 10.0, m_startTime + 30.0))
; | 481 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 10.0, m_startTime + 30.0))
; |
| 483 } | 482 } |
| 484 | 483 |
| 485 TEST_F(TimerTest, PostingTimerTwiceWithSameRunTimeDoesNothing) | 484 TEST_F(TimerTest, PostingTimerTwiceWithSameRunTimeOnlyExecutesOnce) |
| 486 { | 485 { |
| 487 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 486 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
| 488 timer.startOneShot(10, BLINK_FROM_HERE); | 487 timer.startOneShot(10, BLINK_FROM_HERE); |
| 489 timer.startOneShot(10, BLINK_FROM_HERE); | 488 timer.startOneShot(10, BLINK_FROM_HERE); |
| 490 | 489 |
| 491 ASSERT(hasOneTimerTask()); | |
| 492 EXPECT_FLOAT_EQ(10.0, nextTimerTaskDelaySecs()); | 490 EXPECT_FLOAT_EQ(10.0, nextTimerTaskDelaySecs()); |
| 493 | 491 |
| 494 runUntilIdle(); | 492 runUntilIdle(); |
| 495 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 10.0)); | 493 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 10.0)); |
| 496 } | 494 } |
| 497 | 495 |
| 498 TEST_F(TimerTest, PostingTimerTwiceWithNewerRunTimeCancelsOriginalTask) | 496 TEST_F(TimerTest, PostingTimerTwiceWithNewerRunTimeCancelsOriginalTask) |
| 499 { | 497 { |
| 500 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 498 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
| 501 timer.startOneShot(10, BLINK_FROM_HERE); | 499 timer.startOneShot(10, BLINK_FROM_HERE); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 TimerForTest<TimerTest> timer(this, &TimerTest::countingTask, &taskRunner); | 776 TimerForTest<TimerTest> timer(this, &TimerTest::countingTask, &taskRunner); |
| 779 timer.startOneShot(0, BLINK_FROM_HERE); | 777 timer.startOneShot(0, BLINK_FROM_HERE); |
| 780 | 778 |
| 781 // Make sure the task was posted on taskRunner. | 779 // Make sure the task was posted on taskRunner. |
| 782 EXPECT_FALSE(timerTasks.empty()); | 780 EXPECT_FALSE(timerTasks.empty()); |
| 783 } | 781 } |
| 784 | 782 |
| 785 | 783 |
| 786 } // namespace | 784 } // namespace |
| 787 } // namespace blink | 785 } // namespace blink |
| OLD | NEW |