Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: third_party/WebKit/Source/platform/TimerTest.cpp

Issue 2020513003: Prevent augmentRepeatInterval from computing a negative delay (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/Timer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 advanceTimeBy(2.0); 692 advanceTimeBy(2.0);
693 timer.augmentRepeatInterval(10); 693 timer.augmentRepeatInterval(10);
694 694
695 EXPECT_FLOAT_EQ(20.0, timer.repeatInterval()); 695 EXPECT_FLOAT_EQ(20.0, timer.repeatInterval());
696 EXPECT_FLOAT_EQ(18.0, timer.nextFireInterval()); 696 EXPECT_FLOAT_EQ(18.0, timer.nextFireInterval());
697 697
698 runUntilIdleOrDeadlinePassed(m_startTime + 50.0); 698 runUntilIdleOrDeadlinePassed(m_startTime + 50.0);
699 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 20.0, m_startTime + 40.0)) ; 699 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 20.0, m_startTime + 40.0)) ;
700 } 700 }
701 701
702 TEST_F(TimerTest, AugmentRepeatInterval_TimerFireDelayed)
703 {
704 Timer<TimerTest> timer(this, &TimerTest::countingTask);
705 timer.startRepeating(10, BLINK_FROM_HERE);
706 EXPECT_FLOAT_EQ(10.0, timer.repeatInterval());
707 EXPECT_FLOAT_EQ(10.0, timer.nextFireInterval());
708
709 advanceTimeBy(123.0); // Make the timer long overdue.
710 timer.augmentRepeatInterval(10);
711
712 EXPECT_FLOAT_EQ(20.0, timer.repeatInterval());
713 // The timer is overdue so it should be scheduled to fire immediatly.
714 EXPECT_FLOAT_EQ(0.0, timer.nextFireInterval());
715 }
716
702 TEST_F(TimerTest, RepeatingTimerDoesNotDrift) 717 TEST_F(TimerTest, RepeatingTimerDoesNotDrift)
703 { 718 {
704 Timer<TimerTest> timer(this, &TimerTest::recordNextFireTimeTask); 719 Timer<TimerTest> timer(this, &TimerTest::recordNextFireTimeTask);
705 timer.startRepeating(2.0, BLINK_FROM_HERE); 720 timer.startRepeating(2.0, BLINK_FROM_HERE);
706 721
707 ASSERT(hasOneTimerTask()); 722 ASSERT(hasOneTimerTask());
708 recordNextFireTimeTask(&timer); // Next scheduled task to run at m_startTime + 2.0 723 recordNextFireTimeTask(&timer); // Next scheduled task to run at m_startTime + 2.0
709 724
710 // Simulate timer firing early. Next scheduled task to run at m_startTime + 4.0 725 // Simulate timer firing early. Next scheduled task to run at m_startTime + 4.0
711 advanceTimeBy(1.9); 726 advanceTimeBy(1.9);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 TimerForTest<TimerTest> timer(this, &TimerTest::countingTask, &taskRunner); 776 TimerForTest<TimerTest> timer(this, &TimerTest::countingTask, &taskRunner);
762 timer.startOneShot(0, BLINK_FROM_HERE); 777 timer.startOneShot(0, BLINK_FROM_HERE);
763 778
764 // Make sure the task was posted on taskRunner. 779 // Make sure the task was posted on taskRunner.
765 EXPECT_FALSE(timerTasks.empty()); 780 EXPECT_FALSE(timerTasks.empty());
766 } 781 }
767 782
768 783
769 } // namespace 784 } // namespace
770 } // namespace blink 785 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/Timer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698