Bug 975270 - Fire 'emptied' and 'abort' asynchronously in media load algorithm, as per spec. r=roc
☠☠ backed out by 255f08ae80d0 ☠ ☠
authorChris Pearce <cpearce@mozilla.com>
Fri, 28 Feb 2014 15:01:47 +1300
changeset 171748 0ca230c9d79a529d359bb86726b9a7e8db754892
parent 171747 382a65f86218ed95ea46f4150de51fd4a732adec
child 171749 c1eafeaad41658f590cd8243fae6ecab68e8f5a6
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersroc
bugs975270
milestone30.0a1
Bug 975270 - Fire 'emptied' and 'abort' asynchronously in media load algorithm, as per spec. r=roc
content/html/content/src/HTMLMediaElement.cpp
content/media/test/mochitest.ini
content/media/test/test_reset_events_async.html
--- a/content/html/content/src/HTMLMediaElement.cpp
+++ b/content/html/content/src/HTMLMediaElement.cpp
@@ -612,17 +612,17 @@ void HTMLMediaElement::AbortExistingLoad
     mAudioStream = nullptr;
   }
 
   mLoadingSrc = nullptr;
 
   if (mNetworkState == nsIDOMHTMLMediaElement::NETWORK_LOADING ||
       mNetworkState == nsIDOMHTMLMediaElement::NETWORK_IDLE)
   {
-    DispatchEvent(NS_LITERAL_STRING("abort"));
+    DispatchAsyncEvent(NS_LITERAL_STRING("abort"));
   }
 
   mError = nullptr;
   mLoadedFirstFrame = false;
   mAutoplaying = true;
   mIsLoadingFromSourceChildren = false;
   mSuspendedAfterFirstFrame = false;
   mAllowSuspendAfterFirstFrame = true;
@@ -643,17 +643,17 @@ void HTMLMediaElement::AbortExistingLoad
 
     if (fireTimeUpdate) {
       // Since we destroyed the decoder above, the current playback position
       // will now be reported as 0. The playback position was non-zero when
       // we destroyed the decoder, so fire a timeupdate event so that the
       // change will be reflected in the controls.
       FireTimeUpdate(false);
     }
-    DispatchEvent(NS_LITERAL_STRING("emptied"));
+    DispatchAsyncEvent(NS_LITERAL_STRING("emptied"));
   }
 
   // We may have changed mPaused, mAutoplaying, mNetworkState and other
   // things which can affect AddRemoveSelfReference
   AddRemoveSelfReference();
 
   mIsRunningSelectResource = false;
 }
--- a/content/media/test/mochitest.ini
+++ b/content/media/test/mochitest.ini
@@ -351,16 +351,17 @@ support-files =
 [test_playback_errors.html]
 [test_seekable1.html]
 [test_preload_actions.html]
 [test_preload_attribute.html]
 [test_progress.html]
 [test_reactivate.html]
 [test_readyState.html]
 [test_referer.html]
+[test_reset_events_async.html]
 [test_replay_metadata.html]
 [test_seek2.html]
 [test_seek_out_of_range.html]
 [test_seekable2.html]
 [test_seekable3.html]
 [test_source.html]
 [test_source_write.html]
 [test_source_null.html]
new file mode 100644
--- /dev/null
+++ b/content/media/test/test_reset_events_async.html
@@ -0,0 +1,57 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=975270
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug </title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript" src="manifest.js"></script>
+  <script type="application/javascript">
+
+  /** Test for Bug 975270 **/
+  // Test that 'emptied' and 'abort' events are fired asynchronously when re-starting
+  // media load.
+  SimpleTest.waitForExplicitFinish();
+
+  var a = document.createElement("audio");
+  a._abort = 0;
+  a._emptied = 0;
+  
+  is(a.networkState, HTMLMediaElement.NETWORK_EMPTY, "Shouldn't be loading");
+  
+  a.addEventListener("abort", function(e) { a._abort++; });
+  a.addEventListener("emptied", function(e) { a._emptied++; });
+  a.addEventListener("loadedmetadata",
+    function(e) {
+      is(a._abort, 0, "Should not have received 'abort' before 'loadedmetadata");
+      is(a._emptied, 0, "Should not have received 'emptied' before 'loadedmetadata");
+
+      a.addEventListener("loadstart",
+        function(e) {
+          is(a._abort, 1, "Should have received 'abort' before 'loadstart");
+          is(a._emptied, 1, "Should  have received 'emptied' before 'loadstart");
+          SimpleTest.finish();
+        });
+
+      a.src = "";
+      is(a._abort, 0, "Should not have received 'abort' during setting a.src=''");
+      is(a._emptied, 0, "Should not have received 'emptied' during setting a.src=''");
+    });
+  
+  a.src = getPlayableAudio(gSmallTests).name;
+    
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>