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