Fire suspend event whenever network state is set to NETWORK_IDLE.
authorscherkus@chromium.org <scherkus@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Aug 2012 18:18:09 +0000 (18:18 +0000)
committerscherkus@chromium.org <scherkus@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Aug 2012 18:18:09 +0000 (18:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=93052

Reviewed by Eric Carlson.

There was a regression in the Chromium port (http://crbug.com/139511) that revealed we didn't
have a layout test for suspend events. Upon further investigation it appeared we also had a bug
where we didn't fire the suspend event when a media engine reported they had completely loaded
the media.

Covered by new test http/tests/media/video-load-suspend.html.

Source/WebCore:

* html/HTMLMediaElement.cpp: Move firing of suspend event to changeNetworkStateFromLoadingToIdle
(WebCore::HTMLMediaElement::setNetworkState):
(WebCore::HTMLMediaElement::changeNetworkStateFromLoadingToIdle):

LayoutTests:

* http/tests/media/video-load-suspend-expected.txt: Added.
* http/tests/media/video-load-suspend.html: Added.
* media/event-attributes-expected.txt: Updated to include suspend event.

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

LayoutTests/ChangeLog
LayoutTests/http/tests/media/video-load-suspend-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/media/video-load-suspend.html [new file with mode: 0644]
LayoutTests/media/event-attributes-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp

index 2949672..c693c64 100644 (file)
@@ -1,3 +1,21 @@
+2012-08-08  Andrew Scherkus  <scherkus@chromium.org>
+
+        Fire suspend event whenever network state is set to NETWORK_IDLE.
+        https://bugs.webkit.org/show_bug.cgi?id=93052
+
+        Reviewed by Eric Carlson.
+
+        There was a regression in the Chromium port (http://crbug.com/139511) that revealed we didn't
+        have a layout test for suspend events. Upon further investigation it appeared we also had a bug
+        where we didn't fire the suspend event when a media engine reported they had completely loaded
+        the media.
+
+        Covered by new test http/tests/media/video-load-suspend.html.
+
+        * http/tests/media/video-load-suspend-expected.txt: Added.
+        * http/tests/media/video-load-suspend.html: Added.
+        * media/event-attributes-expected.txt: Updated to include suspend event.
+
 2012-08-08  Tom Sepez  <tsepez@chromium.org>
 
         Video element image loader must persist after element detach.  
diff --git a/LayoutTests/http/tests/media/video-load-suspend-expected.txt b/LayoutTests/http/tests/media/video-load-suspend-expected.txt
new file mode 100644 (file)
index 0000000..92697a2
--- /dev/null
@@ -0,0 +1,8 @@
+Test that the load eventually suspends and returns to NETWORK_IDLE.
+
+RUN(video.src = file)
+EVENT(loadstart)
+EVENT(suspend)
+EXPECTED (video.networkState == '1') OK
+END OF TEST
+
diff --git a/LayoutTests/http/tests/media/video-load-suspend.html b/LayoutTests/http/tests/media/video-load-suspend.html
new file mode 100644 (file)
index 0000000..4970f72
--- /dev/null
@@ -0,0 +1,31 @@
+<html>
+<head>
+<script src=../../media-resources/media-file.js></script>
+<script src=../../media-resources/video-test.js></script>
+<script>
+    var file = findMediaFile("video", "http://127.0.0.1:8000/resources/test");
+
+    function init()
+    {
+        findMediaElement();
+        run("video.src = file");
+        waitForEvent('loadstart', onLoadStart);
+    }
+
+    function onLoadStart()
+    {
+        waitForEvent('suspend', onSuspend);
+    }
+
+    function onSuspend()
+    {
+        testExpected("video.networkState", HTMLMediaElement.NETWORK_IDLE, "==");
+        endTest();
+    }
+</script>
+</head>
+<body onload="init()">
+    <p>Test that the load eventually suspends and returns to NETWORK_IDLE.</p>
+    <video></video>
+</body>
+</html>
index 788637e..b9ff139 100644 (file)
@@ -1,4 +1,5 @@
 EVENT(loadstart)
+EVENT(suspend)
 EVENT(durationchange)
 EVENT(loadedmetadata)
 EVENT(loadeddata)
index cd0cb11..b724932 100644 (file)
@@ -1,3 +1,21 @@
+2012-08-08  Andrew Scherkus  <scherkus@chromium.org>
+
+        Fire suspend event whenever network state is set to NETWORK_IDLE.
+        https://bugs.webkit.org/show_bug.cgi?id=93052
+
+        Reviewed by Eric Carlson.
+
+        There was a regression in the Chromium port (http://crbug.com/139511) that revealed we didn't
+        have a layout test for suspend events. Upon further investigation it appeared we also had a bug
+        where we didn't fire the suspend event when a media engine reported they had completely loaded
+        the media.
+
+        Covered by new test http/tests/media/video-load-suspend.html.
+
+        * html/HTMLMediaElement.cpp: Move firing of suspend event to changeNetworkStateFromLoadingToIdle
+        (WebCore::HTMLMediaElement::setNetworkState):
+        (WebCore::HTMLMediaElement::changeNetworkStateFromLoadingToIdle):
+
 2012-08-08  Tom Sepez  <tsepez@chromium.org>
 
         Video element image loader must persist after element detach.  
index a648e69..fecdf8c 100644 (file)
@@ -1581,7 +1581,6 @@ void HTMLMediaElement::setNetworkState(MediaPlayer::NetworkState state)
     if (state == MediaPlayer::Idle) {
         if (m_networkState > NETWORK_IDLE) {
             changeNetworkStateFromLoadingToIdle();
-            scheduleEvent(eventNames().suspendEvent);
             setShouldDelayLoadEvent(false);
         } else {
             m_networkState = NETWORK_IDLE;
@@ -1613,6 +1612,7 @@ void HTMLMediaElement::changeNetworkStateFromLoadingToIdle()
     // Schedule one last progress event so we guarantee that at least one is fired
     // for files that load very quickly.
     scheduleEvent(eventNames().progressEvent);
+    scheduleEvent(eventNames().suspendEvent);
     m_networkState = NETWORK_IDLE;
 }