content/media/test/test_load_same_resource.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 <head>
michael@0 4 <title>Test loading of the same resource in multiple elements</title>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 7 <script type="text/javascript" src="manifest.js"></script>
michael@0 8 </head>
michael@0 9 <body>
michael@0 10
michael@0 11 <pre id="test">
michael@0 12 <script class="testbody" type="text/javascript">
michael@0 13
michael@0 14 var manager = new MediaTestManager;
michael@0 15
michael@0 16 function cloneLoaded(event) {
michael@0 17 ok(true, "Clone loaded OK");
michael@0 18 var e = event.target;
michael@0 19
michael@0 20 if (e._expectedDuration) {
michael@0 21 ok(Math.abs(e.duration - e._expectedDuration) < 0.1,
michael@0 22 "Clone " + e.currentSrc + " duration: " + e.duration + " expected: " + e._expectedDuration);
michael@0 23 }
michael@0 24
michael@0 25 e.removeEventListener("loadeddata", cloneLoaded, false);
michael@0 26 removeNodeAndSource(e);
michael@0 27 manager.finished(e.token);
michael@0 28 }
michael@0 29
michael@0 30 function tryClone(event) {
michael@0 31 var e = event.target;
michael@0 32 var clone = e.cloneNode(false);
michael@0 33 clone.token = e.token;
michael@0 34
michael@0 35 if (e._expectedDuration) {
michael@0 36 ok(Math.abs(e.duration - e._expectedDuration) < 0.1,
michael@0 37 e.currentSrc + " duration: " + e.duration + " expected: " + e._expectedDuration);
michael@0 38 clone._expectedDuration = e._expectedDuration;
michael@0 39 }
michael@0 40
michael@0 41 clone.addEventListener("loadeddata", cloneLoaded, false);
michael@0 42 clone.onloadstart = function(evt) {
michael@0 43 info("cloned " + evt.target.token + " start loading.");
michael@0 44 evt.target.onloadstart = null;
michael@0 45 // Since there is only one H264 decoder instance, we have to delete the
michael@0 46 // decoder of the original element for the cloned element to load. However,
michael@0 47 // we can't delete the decoder too early otherwise cloning decoder will
michael@0 48 // fail to kick in. We wait for 'loadstart' event of the cloned element to
michael@0 49 // know when the decoder is already cloned and we can delete the decoder of
michael@0 50 // the original element.
michael@0 51 removeNodeAndSource(e);
michael@0 52 }
michael@0 53
michael@0 54 e.removeEventListener("loadeddata", tryClone, false);
michael@0 55 }
michael@0 56
michael@0 57 // This test checks that loading the same URI twice in different elements at the same time
michael@0 58 // uses the same resource without doing another network fetch. One of the gCloneTests
michael@0 59 // uses dynamic_resource.sjs to return one resource on the first fetch and a different resource
michael@0 60 // on the second fetch. These resources have different lengths, so if the cloned element
michael@0 61 // does a network fetch it will get a resource with the wrong length and we get a test
michael@0 62 // failure.
michael@0 63
michael@0 64 function initTest(test, token) {
michael@0 65 var elemType = /^audio/.test(test.type) ? "audio" : "video";
michael@0 66 var e = document.createElement(elemType);
michael@0 67 e.preload = "auto";
michael@0 68 if (e.canPlayType(test.type)) {
michael@0 69 e.src = test.name;
michael@0 70 if (test.duration) {
michael@0 71 e._expectedDuration = test.duration;
michael@0 72 }
michael@0 73 ok(true, "Trying to load " + test.name);
michael@0 74 e.addEventListener("loadeddata", tryClone, false);
michael@0 75 e.load();
michael@0 76 e.token = token;
michael@0 77 manager.started(token);
michael@0 78 }
michael@0 79 }
michael@0 80
michael@0 81 manager.runTests(gCloneTests, initTest);
michael@0 82
michael@0 83 </script>
michael@0 84 </pre>
michael@0 85 </body>
michael@0 86 </html>

mercurial