WebCore:
authorantti <antti@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Nov 2007 01:54:55 +0000 (01:54 +0000)
committerantti <antti@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Nov 2007 01:54:55 +0000 (01:54 +0000)
        Reviewed by Darin.

        - Update play() and pause() to match current HTML5 draft
            - send events asynchronously
            - add timeupdate event to pause
            - rethrow load() exception, not others
        - Use list for async events to get ordering right

        Tests: media/video-pause-empty-events.html
               media/video-play-empty-events.html
               media/video-play-pause-events.html
               media/video-play-pause-exception.html

        * html/HTMLMediaElement.cpp:
        (WebCore::HTMLMediaElement::dispatchEventAsync):
        (WebCore::HTMLMediaElement::asyncEventTimerFired):
        (WebCore::HTMLMediaElement::play):
        (WebCore::HTMLMediaElement::pause):
        * html/HTMLMediaElement.h:

LayoutTests:

        Reviewed by Darin.

        Add tests for play() and pause() events.
        Update one test to match new behavior.

        * media/video-currentTime-expected.txt:
        * media/video-currentTime.html:
        * media/video-pause-empty-events-expected.txt: Added.
        * media/video-pause-empty-events.html: Added.
        * media/video-play-empty-events-expected.txt: Added.
        * media/video-play-empty-events.html: Added.
        * media/video-play-pause-events-expected.txt: Added.
        * media/video-play-pause-events.html: Added.
        * media/video-play-pause-exception-expected.txt: Added
        * media/video-play-pause-exception.html: Added
        * media/video-test.js:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@27696 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
LayoutTests/ChangeLog
LayoutTests/media/video-currentTime-expected.txt
LayoutTests/media/video-currentTime.html
LayoutTests/media/video-pause-empty-events-expected.txt [new file with mode: 0644]
LayoutTests/media/video-pause-empty-events.html [new file with mode: 0644]
LayoutTests/media/video-play-empty-events-expected.txt [new file with mode: 0644]
LayoutTests/media/video-play-empty-events.html [new file with mode: 0644]
LayoutTests/media/video-play-pause-events-expected.txt [new file with mode: 0644]
LayoutTests/media/video-play-pause-events.html [new file with mode: 0644]
LayoutTests/media/video-play-pause-exception-expected.txt [new file with mode: 0644]
LayoutTests/media/video-play-pause-exception.html [new file with mode: 0644]
LayoutTests/media/video-test.js
WebCore/ChangeLog
WebCore/html/HTMLMediaElement.cpp
WebCore/html/HTMLMediaElement.h

index 12902a7ab323754d095462b66936e292067361e8..30538327612dcc0e3b0921023dee51ced754be98 100644 (file)
@@ -1,3 +1,22 @@
+2007-11-11  Antti Koivisto  <antti@apple.com>
+
+        Reviewed by Darin.
+        
+        Add tests for play() and pause() events. 
+        Update one test to match new behavior.
+
+        * media/video-currentTime-expected.txt:
+        * media/video-currentTime.html:
+        * media/video-pause-empty-events-expected.txt: Added.
+        * media/video-pause-empty-events.html: Added.
+        * media/video-play-empty-events-expected.txt: Added.
+        * media/video-play-empty-events.html: Added.
+        * media/video-play-pause-events-expected.txt: Added.
+        * media/video-play-pause-events.html: Added.
+        * media/video-play-pause-exception-expected.txt: Added
+        * media/video-play-pause-exception.html: Added
+        * media/video-test.js:
+
 2007-11-11  Nikolas Zimmermann  <zimmermann@kde.org>
 
         Reviewed by Eric.
index 76ef9d63686fe560153528c6b934d81e9d8eb651..91ceef6247dc6e62228facdbe2763fee390535eb 100644 (file)
@@ -1,6 +1,6 @@
 TEST(video.currentTime == 0) OK
 EVENT(load) TEST(video.currentTime == 0) OK
-EVENT(play) TEST(video.currentTime == 0) OK
+EVENT(play)
 TEST(video.currentTime > 0) OK
 END OF TEST
 
index 7f562b1c5e9ae69ffef81101c04da057b4509cfe..159ecab4cab709693c14d2a7a9096c8af0119b5a 100644 (file)
@@ -4,7 +4,7 @@
 test("video.currentTime == 0")
 waitForEventAndTest('load', "video.currentTime == 0");
 video.addEventListener('load', function() { video.play(); setTimeout(testCurrentTime, 500) });
-waitForEventAndTest('play', "video.currentTime == 0");
+waitForEvent('play');
 function testCurrentTime()
 {
     test("video.currentTime > 0")
diff --git a/LayoutTests/media/video-pause-empty-events-expected.txt b/LayoutTests/media/video-pause-empty-events-expected.txt
new file mode 100644 (file)
index 0000000..1fc58bd
--- /dev/null
@@ -0,0 +1,7 @@
+Test that pause() from EMPTY network state triggers load()
+
+TEST(video.networkState == HTMLMediaElement.EMPTY) OK
+RUN(video.pause())
+EVENT(begin)
+END OF TEST
+
diff --git a/LayoutTests/media/video-pause-empty-events.html b/LayoutTests/media/video-pause-empty-events.html
new file mode 100644 (file)
index 0000000..da76c6e
--- /dev/null
@@ -0,0 +1,10 @@
+<video></video>
+<p>Test that pause() from EMPTY network state triggers load()</p>
+<script src=video-test.js></script>
+<script>
+video.src = "content/test.mp4";
+test("video.networkState == HTMLMediaElement.EMPTY");
+waitForEventAndEnd('begin');
+run("video.pause()");
+consoleWrite("SCRIPT DONE");
+</script>
diff --git a/LayoutTests/media/video-play-empty-events-expected.txt b/LayoutTests/media/video-play-empty-events-expected.txt
new file mode 100644 (file)
index 0000000..b2d9c8e
--- /dev/null
@@ -0,0 +1,9 @@
+Test that play() from EMPTY network state triggers load() and async play event.
+
+TEST(video.networkState == HTMLMediaElement.EMPTY) OK
+RUN(video.play())
+EVENT(begin) TEST(video.paused) OK
+SCRIPT DONE
+EVENT(play) TEST(!video.paused) OK
+END OF TEST
+
diff --git a/LayoutTests/media/video-play-empty-events.html b/LayoutTests/media/video-play-empty-events.html
new file mode 100644 (file)
index 0000000..e1905ad
--- /dev/null
@@ -0,0 +1,11 @@
+<video></video>
+<p>Test that play() from EMPTY network state triggers load() and async play event.</p>
+<script src=video-test.js></script>
+<script>
+video.src = "content/test.mp4";
+test("video.networkState == HTMLMediaElement.EMPTY");
+waitForEventAndTest('begin', "video.paused");
+waitForEventTestAndEnd('play', "!video.paused");
+run("video.play()");
+consoleWrite("SCRIPT DONE");
+</script>
diff --git a/LayoutTests/media/video-play-pause-events-expected.txt b/LayoutTests/media/video-play-pause-events-expected.txt
new file mode 100644 (file)
index 0000000..8712aea
--- /dev/null
@@ -0,0 +1,10 @@
+Test that calling play() and pause() triggers async play, timeupdate and pause events.
+
+RUN(video.play())
+RUN(video.pause())
+SCRIPT DONE
+EVENT(play) TEST(video.paused) OK
+EVENT(timeupdate) TEST(video.paused) OK
+EVENT(pause) TEST(video.paused) OK
+END OF TEST
+
diff --git a/LayoutTests/media/video-play-pause-events.html b/LayoutTests/media/video-play-pause-events.html
new file mode 100644 (file)
index 0000000..7525552
--- /dev/null
@@ -0,0 +1,12 @@
+<video></video>
+<p>Test that calling play() and pause() triggers async play, timeupdate and pause events.</p>
+<script src=video-test.js></script>
+<script>
+video.src = "content/test.mp4";
+waitForEventAndTest('play', "video.paused");
+waitForEventAndTest('timeupdate', "video.paused");
+waitForEventTestAndEnd('pause', "video.paused");
+run("video.play()");
+run("video.pause()");
+consoleWrite("SCRIPT DONE");
+</script>
diff --git a/LayoutTests/media/video-play-pause-exception-expected.txt b/LayoutTests/media/video-play-pause-exception-expected.txt
new file mode 100644 (file)
index 0000000..aa09c76
--- /dev/null
@@ -0,0 +1,6 @@
+Video has no src. Test that play() and pause() rethrow the exception from load(). Test that the play and pause events are not dispatched.
+
+TEST(video.play()) THROWS(DOMException.INVALID_STATE_ERR) OK
+TEST(video.pause()) THROWS(DOMException.INVALID_STATE_ERR) OK
+END OF TEST
+
diff --git a/LayoutTests/media/video-play-pause-exception.html b/LayoutTests/media/video-play-pause-exception.html
new file mode 100644 (file)
index 0000000..c83a5fc
--- /dev/null
@@ -0,0 +1,10 @@
+<video></video>
+<p>Video has no src. Test that play() and pause() rethrow the exception from load(). Test that the play and pause events are not dispatched.</p>
+<script src=video-test.js></script>
+<script>
+waitForEventAndFail('play');
+waitForEventAndFail('pause');
+testException("video.play()", "DOMException.INVALID_STATE_ERR");
+testException("video.pause()", "DOMException.INVALID_STATE_ERR");
+endTestLater();
+</script>
index 247bafbed97576c14b3f1d0450bed37715d5c3c1..e6b0560984aaa773fe3dd806f23a77c1f3f1f7be 100644 (file)
@@ -34,6 +34,16 @@ function test(testFuncString, endit)
         endTest();  
 }
 
+function run(testFuncString)
+{
+    consoleWrite("RUN(" + testFuncString + ")");
+    try {
+        eval(testFuncString);
+    } catch (ex) {
+        consoleWrite(ex);
+    }
+}
+
 function waitForEventAndEnd(eventName, funcString)
 {
     waitForEvent(eventName, funcString, true)
@@ -103,6 +113,11 @@ function endTest()
         layoutTestController.notifyDone();     
 }
 
+function endTestLater()
+{
+    setTimeout(endTest, 250);
+}
+
 function consoleWrite(text)
 {
     if (testEnded)
index 743a3b18953ea5bf426b64b6e91bab997ac81e08..dcc1437c082d25ff628f3625f985b91f91320beb 100644 (file)
@@ -1,3 +1,25 @@
+2007-11-11  Antti Koivisto  <antti@apple.com>
+
+        Reviewed by Darin.
+        
+        - Update play() and pause() to match current HTML5 draft
+            - send events asynchronously
+            - add timeupdate event to pause
+            - rethrow load() exception, not others
+        - Use list for async events to get ordering right
+
+        Tests: media/video-pause-empty-events.html
+               media/video-play-empty-events.html
+               media/video-play-pause-events.html
+               media/video-play-pause-exception.html
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::dispatchEventAsync): 
+        (WebCore::HTMLMediaElement::asyncEventTimerFired):
+        (WebCore::HTMLMediaElement::play):
+        (WebCore::HTMLMediaElement::pause):
+        * html/HTMLMediaElement.h:
+
 2007-11-11  Nikolas Zimmermann  <zimmermann@kde.org>
 
         Reviewed by Eric.
index ff9f5c51150d3381858e2ebdef6ffa90cf6e6243..20df38f3787ff1ab904b364b880a42ba6621c2b9 100644 (file)
@@ -137,7 +137,7 @@ void HTMLMediaElement::initAndDispatchProgressEvent(const AtomicString& eventNam
 
 void HTMLMediaElement::dispatchEventAsync(const AtomicString& eventName)
 {
-    m_asyncEventsToDispatch.add(eventName);
+    m_asyncEventsToDispatch.append(eventName);
     if (!m_asyncEventTimer.isActive())                            
         m_asyncEventTimer.startOneShot(0);
 }
@@ -150,10 +150,11 @@ void HTMLMediaElement::loadTimerFired(Timer<HTMLMediaElement>*)
 
 void HTMLMediaElement::asyncEventTimerFired(Timer<HTMLMediaElement>*)
 {
-    HashSet<String>::const_iterator end = m_asyncEventsToDispatch.end();
-    for (HashSet<String>::const_iterator it = m_asyncEventsToDispatch.begin(); it != end; ++it)
-        dispatchHTMLEvent(*it, false, true);
-    m_asyncEventsToDispatch.clear();
+    Vector<AtomicString> asyncEventsToDispatch;
+    m_asyncEventsToDispatch.swap(asyncEventsToDispatch);
+    unsigned count = asyncEventsToDispatch.size();
+    for (unsigned n = 0; n < count; ++n)
+        dispatchHTMLEvent(asyncEventsToDispatch[n], false, true);
 }
 
 String serializeTimeOffset(float time)
@@ -604,22 +605,20 @@ void HTMLMediaElement::play(ExceptionCode& ec)
         if (ec)
             return;
     }
+    ExceptionCode unused;
     if (endedPlayback()) {
         m_currentLoop = 0;
-        seek(effectiveStart(), ec);
-        if (ec)
-            return;
+        seek(effectiveStart(), unused);
+        unused = 0;
     }
-    setPlaybackRate(defaultPlaybackRate(), ec);
-    if (ec)
-        return;
-    
-    m_autoplaying = false;
+    setPlaybackRate(defaultPlaybackRate(), unused);
     
     if (m_movie->paused()) {
-        dispatchHTMLEvent(playEvent, false, true);
         m_movie->play();
+        dispatchEventAsync(playEvent);
     }
+
+    m_autoplaying = false;
 }
 
 void HTMLMediaElement::pause(ExceptionCode& ec)
@@ -627,14 +626,17 @@ void HTMLMediaElement::pause(ExceptionCode& ec)
     // 3.14.9.7. Playing the media resource
     if (!m_movie || networkState() == EMPTY) {
         load(ec);
+        if (ec)
+            return;
     }
 
-    m_autoplaying = false;
-
     if (!m_movie->paused()) {
-        dispatchHTMLEvent(pauseEvent, false, true);
         m_movie->pause();
+        dispatchEventAsync(timeupdateEvent);
+        dispatchEventAsync(pauseEvent);
     }
+
+    m_autoplaying = false;
 }
 
 unsigned HTMLMediaElement::loopCount() const
index bac4c9f995a939afaf9fe73ba2baea5f2dea3eca..d7bec748f3a54d4838a51b54575054ffb8a7079b 100644 (file)
@@ -163,7 +163,7 @@ protected:
     Timer<HTMLMediaElement> m_loadTimer;
     Timer<HTMLMediaElement> m_asyncEventTimer;
     Timer<HTMLMediaElement> m_progressEventTimer;
-    HashSet<String> m_asyncEventsToDispatch;
+    Vector<AtomicString> m_asyncEventsToDispatch;
     
     float m_defaultPlaybackRate;
     NetworkState m_networkState;