WebCore:
[WebKit-https.git] / LayoutTests / http / tests / workers / worker-redirect.html
index 86037f2..972744f 100644 (file)
@@ -7,22 +7,67 @@ function log(message)
     document.getElementById("result").innerHTML += message + "<br>";
 }
 
+var testCases = [
+    "testCrossOriginLoad",
+    "testCrossOriginRedirectedLoad",
+];
+var testIndex = 0;
+
+function runNextTest()
+{
+    if (testIndex < testCases.length) {
+        testIndex++;
+        window[testCases[testIndex - 1]]();
+    } else {
+        log("DONE");
+        if (window.layoutTestController)
+            layoutTestController.notifyDone();
+    }
+}
+
+function testCrossOriginLoad()
+{
+    try {
+        var worker = new Worker('http://localhost:8000/workers/resources/worker-redirect-target.js');
+        worker.onerror = function(evt) {
+            log("FAIL: threw error when attempting to cross origin while loading the worker script.");
+            runNextTest();
+        }
+        worker.onmessage = function(evt) {
+            log("FAIL: executed script when redirect cross origin.");
+            runNextTest();
+        }
+    } catch (ex) {
+        log("SUCCESS: threw exception (" + ex + ") when attempting to cross origin while loading the worker script.");
+        runNextTest();
+    }
+}
+
+function testCrossOriginRedirectedLoad()
+{
+    try {
+        var worker = new Worker('/resources/redirect.php?url=http://localhost:8000/workers/resources/worker-redirect-target.js');
+        worker.onerror = function(evt) {
+            log("SUCCESS: threw error when attempting to redirected cross origin while loading the worker script.");
+            runNextTest();
+        }
+        worker.onmessage = function(evt) {
+            log("FAIL: executed script when redirect cross origin.");
+            runNextTest();
+        }
+    } catch (ex) {
+        log("FAIL: unexpected exception " + ex);
+        runNextTest();
+    }
+}
+
 if (window.layoutTestController) {
     layoutTestController.dumpAsText();
     layoutTestController.waitUntilDone();
 }
 
-var worker = new Worker('/resources/redirect.php?url=http://localhost:8000/workers/resources/worker-redirect-target.js');
-worker.onerror = function(evt) {
-    log("SUCCESS: threw error when attempting to redirected cross origin while loading the worker script.");
-    if (window.layoutTestController)
-        layoutTestController.notifyDone();
-}
-worker.onmessage = function(evt) {
-    log("FAIL: executed script when redirect cross origin.");
-    if (window.layoutTestController)
-        layoutTestController.notifyDone();
-}
+runNextTest();
+
 </script>
 </body>
 </html>