Sync web-platform-tests up to revision a5b95cb31914507088a4eda16f7674bbc6f3313f
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / XMLHttpRequest / open-url-redirected-worker-origin.htm
1  <!DOCTYPE html>
2 <html>
3 <head>
4     <meta charset="utf-8" />
5     <title>XMLHttpRequest: redirected worker scripts, origin and referrer</title>
6     <script src="/resources/testharness.js"></script>
7     <script src="/resources/testharnessreport.js"></script>
8 </head>
9 <body>
10     <div id="log"></div>
11     <script type="text/javascript">
12         var test = async_test() // This "test" does not actually do any assertations. It's just there to have multiple, separate, asyncronous sub-tests.
13         var expectations = {
14             'Referer header': 'Referer: '+(location.href.replace(/[^/]*$/, ''))+"resources/workerxhr-origin-referrer.js\n",
15             'Origin header': 'Origin: '+location.protocol+'//'+location.hostname+((location.port === "")?"":":"+location.port)+'\n',
16             'Request URL test' : (location.href.replace(/[^/]*$/, ''))+'resources/requri.py?full'
17         }
18         // now start the worker
19         var finalWorkerURL = "workerxhr-origin-referrer.js";
20         var url = "resources/redirect.py?location=" + encodeURIComponent(finalWorkerURL);
21         var worker = new Worker(url, true)
22         worker.onmessage = function (e) {
23             var subtest = async_test(e.data.test)
24             subtest.step(function(){
25                 var thisExpectation = expectations[e.data.test]
26                 delete expectations[e.data.test]
27                 assert_equals(e.data.result, thisExpectation)
28                 subtest.done()
29             })
30             var allDone = true
31             for(var prop in expectations){
32                   allDone = false
33             }
34             if(allDone){
35                 test.step(function(){
36                     test.done()
37                 })
38             }
39         }
40
41     </script>
42 </body>
43 </html>