MediaController.currentTime should be kept stable during script execution.
https://bugs.webkit.org/show_bug.cgi?id=88555

Reviewed by Eric Carlson.

Source/WebCore:

Test: media/media-controller-time-constant.html

To keep MediaController.currentTime stable, add a new m_position variable and
a new m_clearPositionTimer timer.  Both must be mutable variables as they will
be updated from within const functions.  Calls to currentTime() will result in
stable values until the next runloop iteration.

* html/MediaController.cpp:
(MediaController::MediaController):
(MediaController::currentTime):
(MediaController::setCurrentTime):
(MediaController::clearPositionTimerFired):
* html/MediaController.h:

LayoutTests:

* media/media-controller-time-constant-expected.txt: Added.
* media/media-controller-time-constant.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@123386 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/html/MediaController.cpp b/Source/WebCore/html/MediaController.cpp
index bba6f03..39fd09d 100644
--- a/Source/WebCore/html/MediaController.cpp
+++ b/Source/WebCore/html/MediaController.cpp
@@ -47,10 +47,12 @@
     : m_paused(false)
     , m_defaultPlaybackRate(1)
     , m_volume(1)
+    , m_position(MediaPlayer::invalidTime())
     , m_muted(false)
     , m_readyState(HAVE_NOTHING)
     , m_playbackState(WAITING)
     , m_asyncEventTimer(this, &MediaController::asyncEventTimerFired)
+    , m_clearPositionTimer(this, &MediaController::clearPositionTimerFired)
     , m_closedCaptionsVisible(false)
     , m_clock(Clock::create())
     , m_scriptExecutionContext(context)
@@ -143,8 +145,13 @@
     if (m_mediaElements.isEmpty())
         return 0;
 
-    // Some clocks may return times outside the range of [0..duration].
-    return max(0.0f, min(duration(), m_clock->currentTime()));
+    if (m_position == MediaPlayer::invalidTime()) {
+        // Some clocks may return times outside the range of [0..duration].
+        m_position = max(0.0f, min(duration(), m_clock->currentTime()));
+        m_clearPositionTimer.startOneShot(0);
+    }
+
+    return m_position;
 }
 
 void MediaController::setCurrentTime(float time, ExceptionCode& code)
@@ -493,6 +500,11 @@
         dispatchEvent(pendingEvents[index].release(), ec);
 }
 
+void MediaController::clearPositionTimerFired(Timer<MediaController>*)
+{
+    m_position = MediaPlayer::invalidTime();
+}
+
 bool MediaController::hasAudio() const
 {
     for (size_t index = 0; index < m_mediaElements.size(); ++index) {