2 <!-- Any copyright is dedicated to the Public Domain.
3 - http://creativecommons.org/publicdomain/zero/1.0/ -->
6 <title> Bug
446344 - Test Origin Header
</title>
7 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
8 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css">
12 <p><a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=446344">Mozilla Bug
446344</a></p>
16 <script class=
"testbody" type=
"text/javascript">
17 const EMPTY_ORIGIN =
"Origin: ";
21 name:
"sendOriginHeader=0 (never)",
23 [
"network.http.sendOriginHeader",
0],
26 framePost: EMPTY_ORIGIN,
27 framePostXOrigin: EMPTY_ORIGIN,
28 frameGet: EMPTY_ORIGIN,
29 framePostNonSandboxed: EMPTY_ORIGIN,
30 framePostNonSandboxedXOrigin: EMPTY_ORIGIN,
31 framePostSandboxed: EMPTY_ORIGIN,
32 framePostSrcDoc: EMPTY_ORIGIN,
33 framePostSrcDocXOrigin: EMPTY_ORIGIN,
34 framePostDataURI: EMPTY_ORIGIN,
35 framePostSameOriginToXOrigin: EMPTY_ORIGIN,
36 framePostXOriginToSameOrigin: EMPTY_ORIGIN,
37 framePostXOriginToXOrigin: EMPTY_ORIGIN,
41 name:
"sendOriginHeader=1 (same-origin)",
43 [
"network.http.sendOriginHeader",
1],
46 framePost:
"Origin: http://mochi.test:8888",
47 framePostXOrigin:
"Origin: null",
48 frameGet: EMPTY_ORIGIN,
49 framePostNonSandboxed:
"Origin: http://mochi.test:8888",
50 framePostNonSandboxedXOrigin:
"Origin: null",
51 framePostSandboxed:
"Origin: null",
52 framePostSrcDoc:
"Origin: http://mochi.test:8888",
53 framePostSrcDocXOrigin:
"Origin: null",
54 framePostDataURI:
"Origin: null",
55 framePostSameOriginToXOrigin:
"Origin: null",
56 framePostXOriginToSameOrigin:
"Origin: null",
57 framePostXOriginToXOrigin:
"Origin: null",
61 name:
"sendOriginHeader=2 (always)",
63 [
"network.http.sendOriginHeader",
2],
66 framePost:
"Origin: http://mochi.test:8888",
67 framePostXOrigin:
"Origin: http://mochi.test:8888",
68 frameGet: EMPTY_ORIGIN,
69 framePostNonSandboxed:
"Origin: http://mochi.test:8888",
70 framePostNonSandboxedXOrigin:
"Origin: http://mochi.test:8888",
71 framePostSandboxed:
"Origin: null",
72 framePostSrcDoc:
"Origin: http://mochi.test:8888",
73 framePostSrcDocXOrigin:
"Origin: http://mochi.test:8888",
74 framePostDataURI:
"Origin: null",
75 framePostSameOriginToXOrigin:
"Origin: http://mochi.test:8888",
76 framePostXOriginToSameOrigin:
"Origin: null",
77 framePostXOriginToXOrigin:
"Origin: http://mochi.test:8888",
81 name:
"sendRefererHeader=0 (never)",
83 [
"network.http.sendRefererHeader",
0],
86 framePost:
"Origin: http://mochi.test:8888",
87 framePostXOrigin:
"Origin: http://mochi.test:8888",
88 frameGet: EMPTY_ORIGIN,
89 framePostNonSandboxed:
"Origin: http://mochi.test:8888",
90 framePostNonSandboxedXOrigin:
"Origin: http://mochi.test:8888",
91 framePostSandboxed:
"Origin: null",
92 framePostSrcDoc:
"Origin: http://mochi.test:8888",
93 framePostSrcDocXOrigin:
"Origin: http://mochi.test:8888",
94 framePostDataURI:
"Origin: null",
95 framePostSameOriginToXOrigin:
"Origin: http://mochi.test:8888",
96 framePostXOriginToSameOrigin:
"Origin: null",
97 framePostXOriginToXOrigin:
"Origin: http://mochi.test:8888",
101 name:
"userControlPolicy=0 (no-referrer)",
103 [
"network.http.sendRefererHeader",
2],
104 [
"network.http.referer.defaultPolicy",
0],
107 framePost:
"Origin: null",
108 framePostXOrigin:
"Origin: null",
109 frameGet: EMPTY_ORIGIN,
110 framePostNonSandboxed:
"Origin: null",
111 framePostNonSandboxedXOrigin:
"Origin: null",
112 framePostSandboxed:
"Origin: null",
113 framePostSrcDoc:
"Origin: null",
114 framePostSrcDocXOrigin:
"Origin: null",
115 framePostDataURI:
"Origin: null",
116 framePostSameOriginToXOrigin:
"Origin: null",
117 framePostXOriginToSameOrigin:
"Origin: null",
118 framePostXOriginToXOrigin:
"Origin: null",
126 frameID:
"framePost",
130 name:
"cross-origin POST",
131 frameID:
"framePostXOrigin",
132 formID:
"formPostXOrigin",
140 name:
"POST inside iframe",
141 frameID:
"framePostNonSandboxed",
142 frameSrc:
"HTTP://mochi.test:8888/tests/netwerk/test/mochitests/origin_header_form_post.html",
145 name:
"cross-origin POST inside iframe",
146 frameID:
"framePostNonSandboxedXOrigin",
147 frameSrc:
"Http://mochi.test:8888/tests/netwerk/test/mochitests/origin_header_form_post_xorigin.html",
150 name:
"POST inside sandboxed iframe",
151 frameID:
"framePostSandboxed",
152 frameSrc:
"http://mochi.test:8888/tests/netwerk/test/mochitests/origin_header_form_post.html",
155 name:
"POST inside a srcdoc iframe",
156 frameID:
"framePostSrcDoc",
157 srcdoc:
"origin_header_form_post.html",
160 name:
"cross-origin POST inside a srcdoc iframe",
161 frameID:
"framePostSrcDocXOrigin",
162 srcdoc:
"origin_header_form_post_xorigin.html",
165 name:
"POST inside a data: iframe",
166 frameID:
"framePostDataURI",
167 dataURI:
"origin_header_form_post.html",
170 name:
"same-origin POST redirected to cross-origin",
171 frameID:
"framePostSameOriginToXOrigin",
172 formID:
"formPostSameOriginToXOrigin",
175 name:
"cross-origin POST redirected to same-origin",
176 frameID:
"framePostXOriginToSameOrigin",
177 formID:
"formPostXOriginToSameOrigin",
180 name:
"cross-origin POST redirected to cross-origin",
181 frameID:
"framePostXOriginToXOrigin",
182 formID:
"formPostXOriginToXOrigin",
186 function frameLoaded(test, check)
188 let frame = window.document.getElementById(check.frameID);
190 let result = SpecialPowers.wrap(frame).contentDocument.documentElement.textContent;
191 is(result, test.results[check.frameID], check.name +
" with " + test.name);
194 function submitForm(test, check)
196 return new Promise((resolve, reject) =
> {
197 document.getElementById(check.frameID).onload = () =
> {
198 frameLoaded(test, check);
201 document.getElementById(check.formID).submit();
205 function loadIframe(test, check)
207 return new Promise((resolve, reject) =
> {
208 let frame = SpecialPowers.wrap(window.document.getElementById(check.frameID));
209 frame.onload = function () {
210 // Ignore the first load and wait for the submitted form instead.
211 let location = frame.contentWindow.location +
"";
212 if (location.endsWith(
"origin_header.sjs")) {
213 frameLoaded(test, check);
217 frame.src = check.frameSrc;
221 function loadSrcDocFrame(test, check)
223 return new Promise((resolve, reject) =
> {
224 let frame = SpecialPowers.wrap(window.document.getElementById(check.frameID));
225 frame.onload = function () {
226 // Ignore the first load and wait for the submitted form instead.
227 let location = frame.contentWindow.location +
"";
228 if (location.endsWith(
"origin_header.sjs")) {
229 frameLoaded(test, check);
233 fetch(check.srcdoc).then((response) =
> {
234 response.text().then((body) =
> {
241 function loadDataURIFrame(test, check)
243 return new Promise((resolve, reject) =
> {
244 let frame = SpecialPowers.wrap(window.document.getElementById(check.frameID));
245 frame.onload = function () {
246 // Ignore the first load and wait for the submitted form instead.
247 let location = frame.contentWindow.location +
"";
248 if (location.endsWith(
"origin_header.sjs")) {
249 frameLoaded(test, check);
253 fetch(check.dataURI).then((response) =
> {
254 response.text().then((body) =
> {
255 frame.src =
"data:text/html," + encodeURIComponent(body);
261 async function resetFrames()
263 let checkPromises = [];
264 for (let check of checksToRun) {
265 checkPromises.push(new Promise((resolve, reject) =
> {
266 let frame = document.getElementById(check.frameID);
267 frame.onload = () =
> resolve();
271 frame.src =
"about:blank";
275 await Promise.all(checkPromises);
278 async function runTests()
280 for (let test of testsToRun) {
282 await SpecialPowers.pushPrefEnv({
"set": test.prefs});
284 let checkPromises = [];
285 for (let check of checksToRun) {
287 checkPromises.push(submitForm(test, check));
288 } else if (check.frameSrc) {
289 checkPromises.push(loadIframe(test, check));
290 } else if (check.srcdoc) {
291 checkPromises.push(loadSrcDocFrame(test, check));
292 } else if (check.dataURI) {
293 checkPromises.push(loadDataURIFrame(test, check));
295 ok(false,
"Unsupported check");
299 await Promise.all(checkPromises);
304 SimpleTest.waitForExplicitFinish();
305 SimpleTest.requestLongerTimeout(
5); // work around Android timeouts
306 addLoadEvent(runTests);
313 <iframe src=
"about:blank" name=
"framePost" id=
"framePost"></iframe>
314 <form action=
"origin_header.sjs"
318 <input type=
"submit" value=
"Submit POST">
322 <iframe src=
"about:blank" name=
"framePostXOrigin" id=
"framePostXOrigin"></iframe>
323 <form action=
"http://test1.mochi.test:8888/tests/netwerk/test/mochitests/origin_header.sjs"
326 target=
"framePostXOrigin">
327 <input type=
"submit" value=
"Submit XOrigin POST">
331 <iframe src=
"about:blank" name=
"frameGet" id=
"frameGet"></iframe>
332 <form action=
"origin_header.sjs"
336 <input type=
"submit" value=
"Submit GET">
340 <iframe src=
"about:blank" name=
"framePostSameOriginToXOrigin" id=
"framePostSameOriginToXOrigin"></iframe>
341 <form action=
"redirect_to.sjs?http://test1.mochi.test:8888/tests/netwerk/test/mochitests/origin_header.sjs"
343 id=
"formPostSameOriginToXOrigin"
344 target=
"framePostSameOriginToXOrigin">
345 <input type=
"Submit" value=
"Submit SameOrigin POST redirected to XOrigin">
349 <iframe src=
"about:blank" name=
"framePostXOriginToSameOrigin" id=
"framePostXOriginToSameOrigin"></iframe>
350 <form action=
"http://test1.mochi.test:8888/tests/netwerk/test/mochitests/redirect_to.sjs?http://mochi.test:8888/tests/netwerk/test/mochitests/origin_header.sjs"
352 id=
"formPostXOriginToSameOrigin"
353 target=
"framePostXOriginToSameOrigin">
354 <input type=
"Submit" value=
"Submit XOrigin POST redirected to SameOrigin">
358 <iframe src=
"about:blank" name=
"framePostXOriginToXOrigin" id=
"framePostXOriginToXOrigin"></iframe>
359 <form action=
"http://test1.mochi.test:8888/tests/netwerk/test/mochitests/redirect_to.sjs?/tests/netwerk/test/mochitests/origin_header.sjs"
361 id=
"formPostXOriginToXOrigin"
362 target=
"framePostXOriginToXOrigin">
363 <input type=
"Submit" value=
"Submit XOrigin POST redirected to XOrigin">
369 <iframe src=
"about:blank" id=
"framePostNonSandboxed"></iframe>
370 <div>Non-sandboxed iframe
</div>
373 <iframe src=
"about:blank" id=
"framePostNonSandboxedXOrigin"></iframe>
374 <div>Non-sandboxed cross-origin iframe
</div>
377 <iframe src=
"about:blank" id=
"framePostSandboxed" sandbox=
"allow-forms allow-scripts"></iframe>
378 <div>Sandboxed iframe
</div>
383 <iframe id=
"framePostSrcDoc" src=
"about:blank"></iframe>
384 <div>Srcdoc iframe
</div>
387 <iframe id=
"framePostSrcDocXOrigin" src=
"about:blank"></iframe>
388 <div>Srcdoc cross-origin iframe
</div>
391 <iframe id=
"framePostDataURI" src=
"about:blank"></iframe>
392 <div>data: URI iframe
</div>