tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

file_access_controls.html (5029B)


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