content/media/test/test_source.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>Media test: append source child</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 <video id="v1"></video>
michael@0 11 <audio id="a1"></audio>
michael@0 12 <pre id="test">
michael@0 13 <script class="testbody" type="text/javascript">
michael@0 14 var v1 = document.getElementById("v1");
michael@0 15 var a1 = document.getElementById("a1");
michael@0 16 v1.preload = "auto";
michael@0 17 a1.preload = "auto";
michael@0 18
michael@0 19 is(v1.src, "", "src should be null");
michael@0 20 is(a1.src, "", "src should be null");
michael@0 21 is(v1.currentSrc, "", "currentSrc should be null");
michael@0 22 is(a1.currentSrc, "", "currentSrc should be null");
michael@0 23 is(v1.childNodes.length, 0, "should have no children");
michael@0 24 is(a1.childNodes.length, 0, "should have no children");
michael@0 25
michael@0 26 function newSource(filter) {
michael@0 27 var test = null;
michael@0 28 var candidates = gSmallTests.filter(function(x){return filter.test(x.type);});
michael@0 29 if (candidates.length > 0) {
michael@0 30 var e = document.createElement("source");
michael@0 31 e.type = candidates[0].type;
michael@0 32 e.src = candidates[0].name;
michael@0 33 return e;
michael@0 34 } else {
michael@0 35 return null
michael@0 36 }
michael@0 37 }
michael@0 38
michael@0 39 var audioLoaded = false;
michael@0 40 var videoLoaded = false;
michael@0 41
michael@0 42 function loaded(e) {
michael@0 43 var media = e.target;
michael@0 44 ok(media.networkState > 0, "networkState should be > 0");
michael@0 45 is(media.childNodes.length, 1, "should have 1 child");
michael@0 46 var sourceFile = media.currentSrc.substring(media.currentSrc.lastIndexOf('/')+1);
michael@0 47 var resource = media.firstChild.src.substring(media.firstChild.src.lastIndexOf('/')+1);
michael@0 48 is(sourceFile, resource, "loaded wrong resource!");
michael@0 49 if (media == a1)
michael@0 50 audioLoaded = true;
michael@0 51 else if (media == v1)
michael@0 52 videoLoaded = true;
michael@0 53 if (audioLoaded && videoLoaded) {
michael@0 54 SimpleTest.finish();
michael@0 55 }
michael@0 56 }
michael@0 57
michael@0 58 v1.addEventListener('loadeddata', loaded, false);
michael@0 59 a1.addEventListener('loadeddata', loaded, false);
michael@0 60
michael@0 61 var videoSource = newSource(/^video/);
michael@0 62 if (videoSource) {
michael@0 63 v1.appendChild(videoSource);
michael@0 64 v1.load();
michael@0 65 } else {
michael@0 66 // No video backends? Don't test anything.
michael@0 67 videoLoaded = true;
michael@0 68 }
michael@0 69
michael@0 70 var audioSource = newSource(/^audio/);
michael@0 71 if (audioSource) {
michael@0 72 a1.appendChild(audioSource);
michael@0 73 a1.load();
michael@0 74 } else {
michael@0 75 audioLoaded = true;
michael@0 76 }
michael@0 77
michael@0 78 if (!audioLoaded && !videoLoaded) {
michael@0 79 SimpleTest.waitForExplicitFinish();
michael@0 80 } else {
michael@0 81 if (audioLoaded) {
michael@0 82 todo(false, "No audio types supported");
michael@0 83 }
michael@0 84 if (videoLoaded) {
michael@0 85 todo(false, "No video types supported");
michael@0 86 }
michael@0 87 }
michael@0 88
michael@0 89 </script>
michael@0 90 </pre>
michael@0 91 </body>
michael@0 92 </html>

mercurial