Commit 2e25dae5 authored by antti's avatar antti

WebCore:

        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: http://svn.webkit.org/repository/webkit/trunk@27696 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent dc7c497d
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.
......
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
......@@ -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")
......
Test that pause() from EMPTY network state triggers load()
TEST(video.networkState == HTMLMediaElement.EMPTY) OK
RUN(video.pause())
EVENT(begin)
END OF TEST
<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>
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
<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>
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
<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>
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
<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>
......@@ -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)
......
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.
......
......@@ -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
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment