content/media/test/file_access_controls.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/test/file_access_controls.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,156 @@
     1.4 +<html>
     1.5 +<head>
     1.6 +  <script type="text/javascript" src="manifest.js"></script>
     1.7 +</head>
     1.8 +<body onload="setTimeout(load, 0);" onunload="done()">
     1.9 +<script>
    1.10 +
    1.11 +// Page URL: http://example.org/tests/content/media/test/file_access_controls.html
    1.12 +
    1.13 +var gResource = getPlayableVideo(gSmallTests).name;
    1.14 +
    1.15 +var gTests = [
    1.16 +  {
    1.17 +    // Test 0
    1.18 +    url: "redirect.sjs?domain=example.com&file="+ gResource,
    1.19 +    result: "error",
    1.20 +    description: "Won't load when redirected to different domain",
    1.21 +  },{
    1.22 +    // Test 1
    1.23 +    url: "redirect.sjs?domain=example.com&allowed&file=" + gResource,
    1.24 +    result: "loadeddata",
    1.25 +    description: "Can load when redirected to different domain with allow-origin",
    1.26 +  },{
    1.27 +    // Test 2
    1.28 +    url: "redirect.sjs?domain=test1.example.org&file=" + gResource,
    1.29 +    result: "error",
    1.30 +    description: "Won't load when redirected to subdomain",
    1.31 +  },{
    1.32 +    // Test 3
    1.33 +    url: "redirect.sjs?domain=test1.example.org&allowed&file=" + gResource,
    1.34 +    result: "loadeddata",
    1.35 +    description: "Can load when redirected to subdomain with allow-origin",
    1.36 +  },{
    1.37 +    // Test 4
    1.38 +    url: "redirect.sjs?domain=example.org&file=" + gResource,
    1.39 +    result: "loadeddata",
    1.40 +    description: "Can load when redirected to same domain",
    1.41 +  },{
    1.42 +    // Test 5
    1.43 +    url: "http://example.org/tests/content/media/test/" + gResource,
    1.44 +    result: "loadeddata",
    1.45 +    description: "Can load from same domain"
    1.46 +  },{
    1.47 +    // Test 6
    1.48 +    url: "http://example.org:8000/tests/content/media/test/" + gResource,
    1.49 +    result: "error",
    1.50 +    description: "Won't load from different port on same domain"
    1.51 +  },{
    1.52 +    // Test 7
    1.53 +    url: "http://example.org:8000/tests/content/media/test/allowed.sjs?" + gResource,
    1.54 +    result: "loadeddata",
    1.55 +    description: "Can load from different port on same domain with allow-origin",
    1.56 +  },{
    1.57 +    // Test 8
    1.58 +    url: "http://example.com/tests/content/media/test/" + gResource,
    1.59 +    result: "error",
    1.60 +    description: "Won't load cross domain",
    1.61 +  },{
    1.62 +    // Test 9
    1.63 +    url: "http://example.com/tests/content/media/test/allowed.sjs?" + gResource,
    1.64 +    result: "loadeddata",
    1.65 +    description: "Can load cross domain with allow-origin",
    1.66 +  },{
    1.67 +    // Test 10
    1.68 +    url: "http://test1.example.org/tests/content/media/test/allowed.sjs?" + gResource,
    1.69 +    result: "loadeddata",
    1.70 +    description: "Can load from subdomain with allow-origin",
    1.71 +  },{
    1.72 +    // Test 11
    1.73 +    url: "http://test1.example.org/tests/content/media/test/" + gResource,
    1.74 +    result: "error",
    1.75 +    description: "Won't load from subdomain",
    1.76 +  }
    1.77 +];
    1.78 +
    1.79 +var gTestNum = 0;
    1.80 +var gVideo = null;
    1.81 +var gTestedRemoved = false;
    1.82 +
    1.83 +function eventHandler(event) {
    1.84 +  //dump((gTestNum - 1) + ": " + event.type + "\n");
    1.85 +  var video = event.target;
    1.86 +  opener.postMessage({"result": (event.type == video.expectedResult),
    1.87 +                      "message":  video.testDescription + (gTestedRemoved ? " (element not in document)" : " (element in document)")},
    1.88 +                     "http://mochi.test:8888");
    1.89 +  // Make sure any extra events cause an error
    1.90 +  video.expectedResult = "<none>";
    1.91 +  nextTest();
    1.92 +}
    1.93 +
    1.94 +function createVideo() {
    1.95 +  var v = document.createElement('video');
    1.96 +  v.addEventListener('loadeddata', eventHandler, false);
    1.97 +  v.addEventListener('error', eventHandler, false);
    1.98 +  v.crossOrigin = 'anonymous';
    1.99 +  return v;
   1.100 +}
   1.101 +
   1.102 +function load() {
   1.103 +  opener.postMessage({"result": (window.location.href == "http://example.org/tests/content/media/test/file_access_controls.html"),
   1.104 +                      "message":  "We must be on a example.org:80"},
   1.105 +                     "http://mochi.test:8888");
   1.106 +
   1.107 +  nextTest();
   1.108 +}
   1.109 +
   1.110 +function nextTest() {
   1.111 +  //dump("nextTest() called, gTestNum="+gTestNum+" gTestedRemoved="+gTestedRemoved+"\n");
   1.112 +  if (gTestNum == gTests.length) {
   1.113 +    //dump("gTestNum == gTests.length\n");
   1.114 +    if (!gTestedRemoved) {
   1.115 +      // Repeat all tests with element removed from doc, should get same result.
   1.116 +      gTestedRemoved = true;
   1.117 +      gTestNum = 0;
   1.118 +    } else {
   1.119 +      //dump("Exiting...\n");
   1.120 +      // We're done, exit the test.
   1.121 +      window.close();
   1.122 +      return;
   1.123 +    }
   1.124 +  }
   1.125 +
   1.126 +  if (gVideo && gVideo.parentNode)
   1.127 +    gVideo.parentNode.removeChild(gVideo);
   1.128 +
   1.129 +  gVideo = null;
   1.130 +  SpecialPowers.forceGC();  
   1.131 +  
   1.132 +  gVideo = createVideo();
   1.133 +  gVideo.expectedResult = gTests[gTestNum].result;
   1.134 +  gVideo.testDescription = gTests[gTestNum].description;
   1.135 +  // Uniquify the resource URL to ensure that the resources loaded by earlier or subsequent tests
   1.136 +  // don't overlap with the resources we load here, which are loaded with non-default preferences set.
   1.137 +  // We also want to make sure that an HTTP fetch actually happens for each testcase.
   1.138 +  var url = gTests[gTestNum].url;
   1.139 +  var random = Math.floor(Math.random()*1000000000);
   1.140 +  url += (url.search(/\?/) < 0 ? "?" : "&") + "rand=" + random;
   1.141 +  gVideo.src = url;
   1.142 +  //dump("Starting test " + gTestNum + " at " + gVideo.src + " expecting:" + gVideo.expectedResult + "\n");
   1.143 +  if (!gTestedRemoved) {
   1.144 +    document.body.appendChild(gVideo); 
   1.145 +    // Will cause load() to be invoked.
   1.146 +  } else {
   1.147 +    gVideo.load();
   1.148 +  }
   1.149 +  gTestNum++;
   1.150 +}
   1.151 +
   1.152 +function done() {
   1.153 +  opener.postMessage({"done": "true"}, "http://mochi.test:8888");
   1.154 +}
   1.155 +
   1.156 +</script>
   1.157 +</body>
   1.158 +</html>
   1.159 +

mercurial