Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
1 <html>
2 <head>
3 <script type="text/javascript" src="manifest.js"></script>
4 </head>
5 <body onload="setTimeout(load, 0);" onunload="done()">
6 <script>
8 // Page URL: http://example.org/tests/content/media/test/file_access_controls.html
10 var gResource = getPlayableVideo(gSmallTests).name;
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/content/media/test/" + gResource,
41 result: "loadeddata",
42 description: "Can load from same domain"
43 },{
44 // Test 6
45 url: "http://example.org:8000/tests/content/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/content/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/content/media/test/" + gResource,
56 result: "error",
57 description: "Won't load cross domain",
58 },{
59 // Test 9
60 url: "http://example.com/tests/content/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/content/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/content/media/test/" + gResource,
71 result: "error",
72 description: "Won't load from subdomain",
73 }
74 ];
76 var gTestNum = 0;
77 var gVideo = null;
78 var gTestedRemoved = false;
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 }
91 function createVideo() {
92 var v = document.createElement('video');
93 v.addEventListener('loadeddata', eventHandler, false);
94 v.addEventListener('error', eventHandler, false);
95 v.crossOrigin = 'anonymous';
96 return v;
97 }
99 function load() {
100 opener.postMessage({"result": (window.location.href == "http://example.org/tests/content/media/test/file_access_controls.html"),
101 "message": "We must be on a example.org:80"},
102 "http://mochi.test:8888");
104 nextTest();
105 }
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 window.close();
119 return;
120 }
121 }
123 if (gVideo && gVideo.parentNode)
124 gVideo.parentNode.removeChild(gVideo);
126 gVideo = null;
127 SpecialPowers.forceGC();
129 gVideo = createVideo();
130 gVideo.expectedResult = gTests[gTestNum].result;
131 gVideo.testDescription = gTests[gTestNum].description;
132 // Uniquify the resource URL to ensure that the resources loaded by earlier or subsequent tests
133 // don't overlap with the resources we load here, which are loaded with non-default preferences set.
134 // We also want to make sure that an HTTP fetch actually happens for each testcase.
135 var url = gTests[gTestNum].url;
136 var random = Math.floor(Math.random()*1000000000);
137 url += (url.search(/\?/) < 0 ? "?" : "&") + "rand=" + random;
138 gVideo.src = url;
139 //dump("Starting test " + gTestNum + " at " + gVideo.src + " expecting:" + gVideo.expectedResult + "\n");
140 if (!gTestedRemoved) {
141 document.body.appendChild(gVideo);
142 // Will cause load() to be invoked.
143 } else {
144 gVideo.load();
145 }
146 gTestNum++;
147 }
149 function done() {
150 opener.postMessage({"done": "true"}, "http://mochi.test:8888");
151 }
153 </script>
154 </body>
155 </html>