Bug 1457661 - P1. Add mochitest. r?bryce draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 28 May 2018 22:39:10 +0200
changeset 800936 6dbd813ec3887a93e0030bffc118e3ece9f4a31f
parent 800652 4a88bf0bcf58c0c247ec37c5c72e62187e94f603
child 800937 e077dcd603f069204889342d3a9dc84ffeaa1805
push id111523
push userbmo:jyavenard@mozilla.com
push dateTue, 29 May 2018 14:28:02 +0000
reviewersbryce
bugs1457661
milestone62.0a1
Bug 1457661 - P1. Add mochitest. r?bryce MozReview-Commit-ID: 9YC8MaXRF42
dom/media/test/mochitest.ini
dom/media/test/test_arraybuffer.html
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -679,16 +679,18 @@ support-files =
   hls/416x243_seg0_5s.ts
   hls/640x480_seg0.ts
   hls/640x480_seg1.ts
   hls/960x720_seg0.ts
   hls/960x720_seg1.ts
 
 [test_access_control.html]
 skip-if = android_version == '15' || android_version == '17' # bug 1292836, android(bug 1232305)
+[test_arraybuffer.html]
+skip-if = android_version == '15' || android_version == '22' # bug 1308388, android(bug 1232305)
 [test_aspectratio_mp4.html]
 skip-if = android_version == '15' # android(bug 1232305)
 [test_audio1.html]
 [test_audio2.html]
 [test_audioDocumentTitle.html]
 skip-if = true # bug 475110 - disabled since we don't play Wave files standalone
 [test_autoplay.html]
 [test_autoplay_contentEditable.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/test/test_arraybuffer.html
@@ -0,0 +1,83 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1462967
+-->
+<head>
+  <title>Test for Bug 1457661</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="text/javascript" src="manifest.js"></script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1457661">Mozilla Bug 1457661</a>
+
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+// Test for Bug 1457661; Ensure that readyState properly move to 4 when using arrayBuffer obtained from XMLHttpRequest
+
+var manager = new MediaTestManager;
+
+function getBlob(url, callback) {
+  const req = new XMLHttpRequest();
+  req.addEventListener("load", function() {
+    callback(req.response);
+  });
+  req.open("GET", url, true);
+  req.responseType = "arraybuffer";
+  req.send();
+}
+
+function startTest(test, token) {
+  manager.started(token);
+  // Fetch the media resource using XHR so we can be sure the entire
+  // resource is loaded before we test buffered ranges. This ensures
+  // we have deterministic behaviour.
+  getBlob(test.name, function(arr) {
+    const v = document.createElement("video");
+    const events = [ "suspend", "play", "canplay", "canplaythrough", "loadstart", "loadedmetadata",
+                     "loadeddata", "playing", "ended", "error", "stalled", "emptied", "abort",
+                     "waiting", "pause", "durationchange", "seeking", "seeked" ];
+    function logEvent(e) {
+      info(test.name + ": got " + e.type + " event");
+    }
+    events.forEach(function(e) {
+      v.addEventListener(e, logEvent);
+    });
+    once(v, "stalled", function(e) {
+      // Resource fetch algorithm in local mode should never fire stalled event.
+      // https://html.spec.whatwg.org/multipage/media.html#concept-media-load-resource
+      ok(false, test.name + ": got stalled");
+      removeNodeAndSource(v);
+      manager.finished(token);
+    });
+    once(v, "canplaythrough", function(e) {
+      ok(true, test.name + ": got canplaythrough");
+      is(v.readyState, v.HAVE_ENOUGH_DATA, test.name + ": readyState is HAVE_ENOUGH_DATA");
+      removeNodeAndSource(v);
+      manager.finished(token);
+    });
+    const blob = new Blob([arr], {type:test.type});
+    const blobUrl = URL.createObjectURL(blob);
+
+    document.body.appendChild(v);
+    v.preload = "auto";
+    v.src = blobUrl;
+    v.load();
+  });
+}
+
+SimpleTest.waitForExplicitFinish();
+// Note: No need to set media test prefs, since we're using XHR to fetch
+// media data.
+manager.runTests(gSmallTests, startTest);
+
+</script>
+</pre>
+</body>
+</html>