WebCore:
[WebKit-https.git] / LayoutTests / http / tests / workers / worker-redirect.html
1 <body>
2 <p>Test that loading the worker's script does not allow a cross origin redirect (<a href="https://bugs.webkit.org/show_bug.cgi?id=26146">bug 26146</a>)</p>
3 <div id=result></div>
4 <script>
5 function log(message)
6 {
7     document.getElementById("result").innerHTML += message + "<br>";
8 }
9
10 function runNextTest()
11 {
12     testIndex++;
13     if (testIndex > totalTests) {
14         log("DONE");
15         if (window.layoutTestController)
16             layoutTestController.notifyDone();
17     } else {
18         eval("test" + testIndex + "();");
19     }
20 }
21
22 function test1()
23 {
24     var worker = new Worker('http://localhost:8000/workers/resources/worker-redirect-target.js');
25     worker.onerror = function(evt) {
26         log("SUCCESS: threw error when attempting to cross origin while loading the worker script.");
27         runNextTest();
28     }
29     worker.onmessage = function(evt) {
30         log("FAIL: executed script when redirect cross origin.");
31         runNextTest();
32     }
33 }
34
35 function test2()
36 {
37     var worker = new Worker('/resources/redirect.php?url=http://localhost:8000/workers/resources/worker-redirect-target.js');
38     worker.onerror = function(evt) {
39         log("SUCCESS: threw error when attempting to redirected cross origin while loading the worker script.");
40         runNextTest();
41     }
42     worker.onmessage = function(evt) {
43         log("FAIL: executed script when redirect cross origin.");
44         runNextTest();
45     }
46 }
47
48 if (window.layoutTestController) {
49     layoutTestController.dumpAsText();
50     layoutTestController.waitUntilDone();
51 }
52
53 var totalTests = 2;
54 var testIndex = 0;
55 runNextTest();
56
57 </script>
58 </body>
59 </html>