content/media/test/test_buffered.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=462957
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 462957</title>
michael@0 8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 10 <script type="text/javascript" src="manifest.js"></script>
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=462957">Mozilla Bug 462957</a>
michael@0 14
michael@0 15 <p id="display"></p>
michael@0 16 <div id="content" style="display: none">
michael@0 17
michael@0 18 </div>
michael@0 19 <pre id="test">
michael@0 20 <script type="application/javascript">
michael@0 21
michael@0 22 // Test for Bug 462957; HTMLMediaElement.buffered.
michael@0 23
michael@0 24 var manager = new MediaTestManager;
michael@0 25
michael@0 26 function testBuffered(e) {
michael@0 27 var v = e.target;
michael@0 28
michael@0 29 // The whole media should be buffered...
michael@0 30 var b = v.buffered;
michael@0 31 is(b.length, 1, v._name + ": Should be buffered in one range");
michael@0 32 is(b.start(0), 0, v._name + ": First range start should be media start");
michael@0 33 is(b.end(0), v.duration, v._name + ": First range end should be media end");
michael@0 34
michael@0 35 // Ensure INDEX_SIZE_ERR is thrown when we access outside the range
michael@0 36 var caught = false;
michael@0 37 try {
michael@0 38 b.start(-1);
michael@0 39 } catch (e) {
michael@0 40 caught = e.name == "IndexSizeError" && e.code == DOMException.INDEX_SIZE_ERR;
michael@0 41 }
michael@0 42 is(caught, true, v._name + ": Should throw INDEX_SIZE_ERR on under start bounds range");
michael@0 43
michael@0 44 caught = false;
michael@0 45 try {
michael@0 46 b.end(-1);
michael@0 47 } catch (e) {
michael@0 48 caught = e.name == "IndexSizeError" && e.code == DOMException.INDEX_SIZE_ERR;
michael@0 49 }
michael@0 50 is(caught, true, v._name + ": Should throw INDEX_SIZE_ERR on under end bounds range");
michael@0 51
michael@0 52 caught = false;
michael@0 53 try {
michael@0 54 b.start(b.length);
michael@0 55 } catch (e) {
michael@0 56 caught = e.name == "IndexSizeError" && e.code == DOMException.INDEX_SIZE_ERR;
michael@0 57 }
michael@0 58 is(caught, true, v._name + ": Should throw INDEX_SIZE_ERR on over start bounds range");
michael@0 59
michael@0 60 caught = false;
michael@0 61 try {
michael@0 62 b.end(b.length);
michael@0 63 } catch (e) {
michael@0 64 caught = e.name == "IndexSizeError" && e.code == DOMException.INDEX_SIZE_ERR;
michael@0 65 }
michael@0 66 is(caught, true, v._name + ": Should throw INDEX_SIZE_ERR on over end bounds range");
michael@0 67
michael@0 68 manager.finished(v._token);
michael@0 69 v.src = "";
michael@0 70 v.parentNode.removeChild(v);
michael@0 71 }
michael@0 72
michael@0 73 function fetch(url, fetched_callback) {
michael@0 74 var xhr = new XMLHttpRequest();
michael@0 75 xhr.open("GET", url, true);
michael@0 76 xhr.responseType = "blob";
michael@0 77
michael@0 78 var loaded = function (event) {
michael@0 79 if (xhr.status == 200 || xhr.status == 206) {
michael@0 80 // Request fulfilled. Note sometimes we get 206... Presumably because either
michael@0 81 // httpd.js or Necko cached the result.
michael@0 82 fetched_callback(window.URL.createObjectURL(xhr.response));
michael@0 83 } else {
michael@0 84 ok(false, "Fetch failed headers=" + xhr.getAllResponseHeaders());
michael@0 85 }
michael@0 86 };
michael@0 87
michael@0 88 xhr.addEventListener("load", loaded, false);
michael@0 89 xhr.send();
michael@0 90 }
michael@0 91
michael@0 92 function startTest(test, token) {
michael@0 93 // Fetch the media resource using XHR so we can be sure the entire
michael@0 94 // resource is loaded before we test buffered ranges. This ensures
michael@0 95 // we have deterministic behaviour.
michael@0 96 var onfetched = function(uri) {
michael@0 97 var v = document.createElement('video');
michael@0 98 v.preload = "metadata";
michael@0 99 v._token = token;
michael@0 100 v.src = uri;
michael@0 101 v._name = test.name;
michael@0 102 v._test = test;
michael@0 103 v.addEventListener("loadedmetadata", testBuffered, false);
michael@0 104 document.body.appendChild(v);
michael@0 105 };
michael@0 106
michael@0 107 manager.started(token);
michael@0 108 fetch(test.name, onfetched);
michael@0 109 }
michael@0 110
michael@0 111 // Note: No need to set media test prefs, since we're using XHR to fetch
michael@0 112 // media data.
michael@0 113 SimpleTest.waitForExplicitFinish();
michael@0 114 manager.runTests(gSeekTests, startTest);
michael@0 115
michael@0 116 </script>
michael@0 117 </pre>
michael@0 118 </body>
michael@0 119 </html>

mercurial