5 <body onload=
"tests.next();">
6 <script type=
"text/javascript">
7 const SJS
= "referrer_test_server.sjs?";
8 const BASE_URL
= "https://example.com/tests/dom/workers/test/" + SJS
;
9 const GET_RESULT
= BASE_URL
+ 'ACTION=get-test-results';
10 const RESET_STATE
= BASE_URL
+ 'ACTION=resetState';
12 function ok(val
, message
) {
13 val
= val
? "true" : "false";
14 window
.parent
.postMessage("SimpleTest.ok(" + val
+ ", '" + message
+ "');", "*");
18 window
.parent
.postMessage("SimpleTest.info(" + val
+ ");", "*");
21 function is(a
, b
, message
) {
26 // Let window.onerror have a chance to fire
27 setTimeout(function() {
28 setTimeout(function() {
30 window
.parent
.postMessage("SimpleTest.finish();", "*");
36 'same-origin': { 'Referrer-Policy' : { 'default' : 'full',
38 'origin-when-cross-origin' : 'full',
39 'unsafe-url' : 'full',
40 'same-origin' : 'full',
41 'strict-origin' : 'origin',
42 'strict-origin-when-cross-origin' : 'full',
43 'no-referrer' : 'none',
44 'unsafe-url, no-referrer' : 'none',
45 'invalid' : 'full' }},
47 'cross-origin': { 'Referrer-Policy' : { 'default' : 'origin',
49 'origin-when-cross-origin' : 'origin',
50 'unsafe-url' : 'full',
51 'same-origin' : 'none',
52 'strict-origin' : 'origin',
53 'strict-origin-when-cross-origin' : 'origin',
54 'no-referrer' : 'none',
55 'unsafe-url, no-referrer' : 'none',
56 'invalid' : 'origin' }},
58 // Downgrading in worker is blocked entirely without unblock option
59 // https://bugzilla.mozilla.org/show_bug.cgi?id=1198078#c17
60 // Skip the downgrading test
61 /* 'downgrade': { 'Referrer-Policy' : { 'default' : 'full',
63 'origin-when-cross-origin"' : 'full',
64 'unsafe-url' : 'full',
65 'same-origin' : 'none',
66 'strict-origin' : 'none',
67 'strict-origin-when-cross-origin' : 'none',
68 'no-referrer' : 'full',
69 'unsafe-url, no-referrer' : 'none',
70 'invalid' : 'full' }}, */
75 var advance = function() { tests
.next(); };
78 * helper to perform an XHR
79 * to do checkIndividualResults and resetState
81 function doXHR(aUrl
, onSuccess
, onFail
) {
82 var xhr
= new XMLHttpRequest({mozSystem
: true});
83 xhr
.responseType
= "json";
84 xhr
.onload = function () {
87 xhr
.onerror = function () {
90 xhr
.open('GET', aUrl
, true);
95 function resetState() {
99 ok(false, "error in reset state");
104 function checkIndividualResults(aType
, aPolicy
, aExpected
) {
105 var onload
= xhr
=> {
106 var results
= xhr
.response
;
107 dump(JSON
.stringify(xhr
.response
));
108 // test id equals type + "-" + policy
109 // Ex: same-origin-default
110 var id
= aType
+ "-" + aPolicy
;
111 ok(id
in results
, id
+ " tests have to be performed.");
112 is(results
[id
].policy
, aExpected
, id
+ ' --- ' + results
[id
].policy
+ ' (' + results
[id
].referrer
+ ')');
115 var onerror
= xhr
=> {
116 ok(false, "Can't get results from the counter server.");
119 doXHR(GET_RESULT
, onload
, onerror
);
122 var tests
= (function*() {
124 for (var type
in testCases
) {
125 for (var policy
in testCases
[type
]['Referrer-Policy']) {
127 var searchParams
= new URLSearchParams();
128 searchParams
.append("TYPE", type
);
129 searchParams
.append("ACTION", "test");
130 searchParams
.append("Referrer-Policy", policy
);
131 var worker
= new Worker(BASE_URL
+ searchParams
.toString());
132 worker
.onmessage = function () {
135 yield worker
.postMessage(42);
136 yield checkIndividualResults(type
, policy
, escape(testCases
[type
]['Referrer-Policy'][policy
]));