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 var testCases = [
11     "testCrossOriginLoad",
12     "testCrossOriginRedirectedLoad",
13 ];
14 var testIndex = 0;
15
16 function runNextTest()
17 {
18     if (testIndex < testCases.length) {
19         testIndex++;
20         window[testCases[testIndex - 1]]();
21     } else {
22         log("DONE");
23         if (window.layoutTestController)
24             layoutTestController.notifyDone();
25     }
26 }
27
28 function testCrossOriginLoad()
29 {
30     try {
31         var worker = new Worker('http://localhost:8000/workers/resources/worker-redirect-target.js');
32         worker.onerror = function(evt) {
33             log("FAIL: threw error when attempting to cross origin while loading the worker script.");
34             runNextTest();
35         }
36         worker.onmessage = function(evt) {
37             log("FAIL: executed script when redirect cross origin.");
38             runNextTest();
39         }
40     } catch (ex) {
41         log("SUCCESS: threw exception (" + ex + ") when attempting to cross origin while loading the worker script.");
42         runNextTest();
43     }
44 }
45
46 function testCrossOriginRedirectedLoad()
47 {
48     try {
49         var worker = new Worker('/resources/redirect.php?url=http://localhost:8000/workers/resources/worker-redirect-target.js');
50         worker.onerror = function(evt) {
51             log("SUCCESS: threw error when attempting to redirected cross origin while loading the worker script.");
52             runNextTest();
53         }
54         worker.onmessage = function(evt) {
55             log("FAIL: executed script when redirect cross origin.");
56             runNextTest();
57         }
58     } catch (ex) {
59         log("FAIL: unexpected exception " + ex);
60         runNextTest();
61     }
62 }
63
64 if (window.layoutTestController) {
65     layoutTestController.dumpAsText();
66     layoutTestController.waitUntilDone();
67 }
68
69 runNextTest();
70
71 </script>
72 </body>
73 </html>