summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_arraybuffer.html
blob: 9ef84c53dc909240d6fad263d2d1fcfebbb478a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1462967
-->
<head>
  <title>Test for Bug 1457661</title>
  <script 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>