content/media/test/file_access_controls.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 <html>
michael@0 2 <head>
michael@0 3 <script type="text/javascript" src="manifest.js"></script>
michael@0 4 </head>
michael@0 5 <body onload="setTimeout(load, 0);" onunload="done()">
michael@0 6 <script>
michael@0 7
michael@0 8 // Page URL: http://example.org/tests/content/media/test/file_access_controls.html
michael@0 9
michael@0 10 var gResource = getPlayableVideo(gSmallTests).name;
michael@0 11
michael@0 12 var gTests = [
michael@0 13 {
michael@0 14 // Test 0
michael@0 15 url: "redirect.sjs?domain=example.com&file="+ gResource,
michael@0 16 result: "error",
michael@0 17 description: "Won't load when redirected to different domain",
michael@0 18 },{
michael@0 19 // Test 1
michael@0 20 url: "redirect.sjs?domain=example.com&allowed&file=" + gResource,
michael@0 21 result: "loadeddata",
michael@0 22 description: "Can load when redirected to different domain with allow-origin",
michael@0 23 },{
michael@0 24 // Test 2
michael@0 25 url: "redirect.sjs?domain=test1.example.org&file=" + gResource,
michael@0 26 result: "error",
michael@0 27 description: "Won't load when redirected to subdomain",
michael@0 28 },{
michael@0 29 // Test 3
michael@0 30 url: "redirect.sjs?domain=test1.example.org&allowed&file=" + gResource,
michael@0 31 result: "loadeddata",
michael@0 32 description: "Can load when redirected to subdomain with allow-origin",
michael@0 33 },{
michael@0 34 // Test 4
michael@0 35 url: "redirect.sjs?domain=example.org&file=" + gResource,
michael@0 36 result: "loadeddata",
michael@0 37 description: "Can load when redirected to same domain",
michael@0 38 },{
michael@0 39 // Test 5
michael@0 40 url: "http://example.org/tests/content/media/test/" + gResource,
michael@0 41 result: "loadeddata",
michael@0 42 description: "Can load from same domain"
michael@0 43 },{
michael@0 44 // Test 6
michael@0 45 url: "http://example.org:8000/tests/content/media/test/" + gResource,
michael@0 46 result: "error",
michael@0 47 description: "Won't load from different port on same domain"
michael@0 48 },{
michael@0 49 // Test 7
michael@0 50 url: "http://example.org:8000/tests/content/media/test/allowed.sjs?" + gResource,
michael@0 51 result: "loadeddata",
michael@0 52 description: "Can load from different port on same domain with allow-origin",
michael@0 53 },{
michael@0 54 // Test 8
michael@0 55 url: "http://example.com/tests/content/media/test/" + gResource,
michael@0 56 result: "error",
michael@0 57 description: "Won't load cross domain",
michael@0 58 },{
michael@0 59 // Test 9
michael@0 60 url: "http://example.com/tests/content/media/test/allowed.sjs?" + gResource,
michael@0 61 result: "loadeddata",
michael@0 62 description: "Can load cross domain with allow-origin",
michael@0 63 },{
michael@0 64 // Test 10
michael@0 65 url: "http://test1.example.org/tests/content/media/test/allowed.sjs?" + gResource,
michael@0 66 result: "loadeddata",
michael@0 67 description: "Can load from subdomain with allow-origin",
michael@0 68 },{
michael@0 69 // Test 11
michael@0 70 url: "http://test1.example.org/tests/content/media/test/" + gResource,
michael@0 71 result: "error",
michael@0 72 description: "Won't load from subdomain",
michael@0 73 }
michael@0 74 ];
michael@0 75
michael@0 76 var gTestNum = 0;
michael@0 77 var gVideo = null;
michael@0 78 var gTestedRemoved = false;
michael@0 79
michael@0 80 function eventHandler(event) {
michael@0 81 //dump((gTestNum - 1) + ": " + event.type + "\n");
michael@0 82 var video = event.target;
michael@0 83 opener.postMessage({"result": (event.type == video.expectedResult),
michael@0 84 "message": video.testDescription + (gTestedRemoved ? " (element not in document)" : " (element in document)")},
michael@0 85 "http://mochi.test:8888");
michael@0 86 // Make sure any extra events cause an error
michael@0 87 video.expectedResult = "<none>";
michael@0 88 nextTest();
michael@0 89 }
michael@0 90
michael@0 91 function createVideo() {
michael@0 92 var v = document.createElement('video');
michael@0 93 v.addEventListener('loadeddata', eventHandler, false);
michael@0 94 v.addEventListener('error', eventHandler, false);
michael@0 95 v.crossOrigin = 'anonymous';
michael@0 96 return v;
michael@0 97 }
michael@0 98
michael@0 99 function load() {
michael@0 100 opener.postMessage({"result": (window.location.href == "http://example.org/tests/content/media/test/file_access_controls.html"),
michael@0 101 "message": "We must be on a example.org:80"},
michael@0 102 "http://mochi.test:8888");
michael@0 103
michael@0 104 nextTest();
michael@0 105 }
michael@0 106
michael@0 107 function nextTest() {
michael@0 108 //dump("nextTest() called, gTestNum="+gTestNum+" gTestedRemoved="+gTestedRemoved+"\n");
michael@0 109 if (gTestNum == gTests.length) {
michael@0 110 //dump("gTestNum == gTests.length\n");
michael@0 111 if (!gTestedRemoved) {
michael@0 112 // Repeat all tests with element removed from doc, should get same result.
michael@0 113 gTestedRemoved = true;
michael@0 114 gTestNum = 0;
michael@0 115 } else {
michael@0 116 //dump("Exiting...\n");
michael@0 117 // We're done, exit the test.
michael@0 118 window.close();
michael@0 119 return;
michael@0 120 }
michael@0 121 }
michael@0 122
michael@0 123 if (gVideo && gVideo.parentNode)
michael@0 124 gVideo.parentNode.removeChild(gVideo);
michael@0 125
michael@0 126 gVideo = null;
michael@0 127 SpecialPowers.forceGC();
michael@0 128
michael@0 129 gVideo = createVideo();
michael@0 130 gVideo.expectedResult = gTests[gTestNum].result;
michael@0 131 gVideo.testDescription = gTests[gTestNum].description;
michael@0 132 // Uniquify the resource URL to ensure that the resources loaded by earlier or subsequent tests
michael@0 133 // don't overlap with the resources we load here, which are loaded with non-default preferences set.
michael@0 134 // We also want to make sure that an HTTP fetch actually happens for each testcase.
michael@0 135 var url = gTests[gTestNum].url;
michael@0 136 var random = Math.floor(Math.random()*1000000000);
michael@0 137 url += (url.search(/\?/) < 0 ? "?" : "&") + "rand=" + random;
michael@0 138 gVideo.src = url;
michael@0 139 //dump("Starting test " + gTestNum + " at " + gVideo.src + " expecting:" + gVideo.expectedResult + "\n");
michael@0 140 if (!gTestedRemoved) {
michael@0 141 document.body.appendChild(gVideo);
michael@0 142 // Will cause load() to be invoked.
michael@0 143 } else {
michael@0 144 gVideo.load();
michael@0 145 }
michael@0 146 gTestNum++;
michael@0 147 }
michael@0 148
michael@0 149 function done() {
michael@0 150 opener.postMessage({"done": "true"}, "http://mochi.test:8888");
michael@0 151 }
michael@0 152
michael@0 153 </script>
michael@0 154 </body>
michael@0 155 </html>
michael@0 156

mercurial