Opera CORS-tests: Do some small cleanup
authorOdin Hørthe Omdal <odinho@opera.com>
Mon, 05 Mar 2012 10:49:47 +0100
changeset 22 1e1ca166961c
parent 21 bace715cb5a3
child 23 07b3b3269e24
child 33 ff9b01d942e1
Opera CORS-tests: Do some small cleanup
tests/cors/submitted/opera/js/basic.htm
tests/cors/submitted/opera/js/credentials-flag.htm
tests/cors/submitted/opera/js/errors-async.htm
tests/cors/submitted/opera/js/errors-sync.htm
tests/cors/submitted/opera/js/https.htm
tests/cors/submitted/opera/js/origin.htm
tests/cors/submitted/opera/js/preflight-cache.htm
tests/cors/submitted/opera/js/redirect-preflight.htm
tests/cors/submitted/opera/js/redirect.htm
tests/cors/submitted/opera/js/request.htm
tests/cors/submitted/opera/js/response.htm
tests/cors/submitted/opera/js/simple-requests.htm
tests/cors/submitted/opera/js/status-async.htm
tests/cors/submitted/opera/js/status-errors.htm
tests/cors/submitted/opera/js/status-preflight.htm
tests/cors/submitted/opera/js/status.htm
tests/cors/submitted/opera/js/support.js
--- a/tests/cors/submitted/opera/js/basic.htm	Thu Feb 02 16:31:22 2012 -0800
+++ b/tests/cors/submitted/opera/js/basic.htm	Mon Mar 05 10:49:47 2012 +0100
@@ -4,19 +4,14 @@
     <title>XMLHttpRequest: Basic CORS</title>
     <script src="/resources/testharness.js"></script>
     <script src="/resources/testharnessreport.js"></script>
+    <script src="support.js"></script>
   </head>
   <body>
     <p>This shouldn't be tested inside a tunnel.</p>
     <div id="log"></div>
     <script>
 
-    function dirname(path) {
-        return path.replace(/\/[^\/]*$/, '/')
-    }
-
-    var crossdomain = "http://crosssite." + location.hostname
-    var port = "8081" // Extra port for http
-    var folder = dirname(location.pathname)
+    var crossdomain = "http://" + SUBDOMAIN + "." + location.hostname
 
 
     /*
@@ -25,7 +20,7 @@
 
     test(function() {
         var client = new XMLHttpRequest()
-        client.open('GET', dirname(location.href) + 'resources/cors-headers.php', false)
+        client.open('GET', 'resources/cors-headers.php', false)
         client.send(null)
 
         assert_equals(client.response, 'TEST')
@@ -33,7 +28,7 @@
 
     test(function() {
         var client = new XMLHttpRequest()
-        client.open('GET', crossdomain + folder + 'resources/cors-headers.php', false)
+        client.open('GET', CROSSDOMAIN + 'resources/cors-headers.php', false)
         client.send(null)
 
         assert_equals(client.response, 'TEST')
@@ -41,7 +36,7 @@
 
     test(function() {
         var client = new XMLHttpRequest()
-        client.open('GET', 'http://' + location.hostname + ":" + port + dirname(location.pathname) + 'resources/cors-headers.php', false)
+        client.open('GET', 'http://' + location.hostname + ":" + PORT + dirname(location.pathname) + 'resources/cors-headers.php', false)
         client.send(null)
 
         assert_equals(client.response, 'TEST')
@@ -49,7 +44,7 @@
 
     test(function() {
         var client = new XMLHttpRequest()
-        client.open('GET', crossdomain + ":" + port + dirname(location.pathname) + 'resources/cors-headers.php', false)
+        client.open('GET', 'http://' + SUBDOMAIN + '.' + location.hostname + ':' + PORT + dirname(location.pathname) + 'resources/cors-headers.php', false)
         client.send(null)
 
         assert_equals(client.response, 'TEST')
--- a/tests/cors/submitted/opera/js/credentials-flag.htm	Thu Feb 02 16:31:22 2012 -0800
+++ b/tests/cors/submitted/opera/js/credentials-flag.htm	Mon Mar 05 10:49:47 2012 +0100
@@ -4,14 +4,14 @@
     <title>XMLHttpRequest: CORS - withCredentials</title>
     <script src="/resources/testharness.js"></script>
     <script src="/resources/testharnessreport.js"></script>
+    <script src="support.js"></script>
   </head>
   <body>
     <p>This shouldn't be tested inside a tunnel.</p>
     <div id="log"></div>
     <script>
 
-    var crossdomain = "http://crosssite." + location.host + location.pathname.replace(/\/[^\/]*$/, '/')
-    var url = crossdomain + 'resources/cors-cookie.php?ident='
+    var url = CROSSDOMAIN + 'resources/cors-cookie.php?ident='
 
 
     /*
@@ -79,7 +79,7 @@
         test(function () {
             var client = new XMLHttpRequest()
             client.open('GET',
-                crossdomain + 'resources/cors-makeheader.php?credentials=' + allow,
+                CROSSDOMAIN + 'resources/cors-makeheader.php?credentials=' + allow,
                 false)
             client.withCredentials = true;
             assert_throws('NETWORK_ERR', function() { client.send() }, 'send')
@@ -89,7 +89,7 @@
         resp_test.step(function() {
             var client = new XMLHttpRequest()
             client.open('GET',
-                crossdomain + 'resources/cors-makeheader.php?credentials=' + allow,
+                CROSSDOMAIN + 'resources/cors-makeheader.php?credentials=' + allow,
                 true)
             client.withCredentials = true;
             client.onload = resp_test.step_func(function() {
--- a/tests/cors/submitted/opera/js/errors-async.htm	Thu Feb 02 16:31:22 2012 -0800
+++ b/tests/cors/submitted/opera/js/errors-async.htm	Mon Mar 05 10:49:47 2012 +0100
@@ -4,18 +4,13 @@
     <title>XMLHttpRequest: CORS - errors (async)</title>
     <script src="/resources/testharness.js"></script>
     <script src="/resources/testharnessreport.js"></script>
+    <script src="support.js"></script>
   </head>
   <body>
     <p>This shouldn't be tested inside a tunnel.</p>
     <div id="log"></div>
     <script>
 
-    function dirname(path) {
-        return path.replace(/\/[^\/]*$/, '/')
-    }
-
-    var crossdomain = "http://crosssite." + location.hostname + dirname(location.pathname)
-
     /*
      * Error checking
      */
@@ -24,7 +19,7 @@
         var test = async_test('CORS fail async, getting onerror')
         test.step(function() {
             var xhr = new XMLHttpRequest()
-            xhr.open('GET', crossdomain + 'resources/cors-makeheader.php?origin=none', true)
+            xhr.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin=none', true)
             xhr.onerror = test.step_func(function(e) {
                 assert_equals(xhr.readyState, xhr.DONE, "readyState")
                 assert_equals(xhr.status, 0, "status")
@@ -42,7 +37,7 @@
         test.step(function() {
             var xhr = new XMLHttpRequest(),
                 passed = false
-            xhr.open('GET', crossdomain + 'resources/cors-makeheader.php?origin=none', true)
+            xhr.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin=none', true)
             xhr.onreadystatechange = test.step_func(function(e) {
                 if (xhr.readyState > xhr.OPENED)
                     assert_equals(xhr.status, 0, "status")
--- a/tests/cors/submitted/opera/js/errors-sync.htm	Thu Feb 02 16:31:22 2012 -0800
+++ b/tests/cors/submitted/opera/js/errors-sync.htm	Mon Mar 05 10:49:47 2012 +0100
@@ -4,25 +4,20 @@
     <title>XMLHttpRequest: CORS - errors (sync)</title>
     <script src="/resources/testharness.js"></script>
     <script src="/resources/testharnessreport.js"></script>
+    <script src="support.js"></script>
   </head>
   <body>
     <p>This shouldn't be tested inside a tunnel.</p>
     <div id="log"></div>
     <script>
 
-    function dirname(path) {
-        return path.replace(/\/[^\/]*$/, '/')
-    }
-
-    var crossdomain = "http://crosssite." + location.hostname + dirname(location.pathname)
-
     /*
      * Error checking
      */
 
     test(function() {
         var client = new XMLHttpRequest()
-        client.open('GET', crossdomain + 'resources/cors-makeheader.php?origin=none', false)
+        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin=none', false)
         assert_throws('NETWORK_ERR', function() { client.send() }, 'send');
         assert_equals(client.status, 0, "status")
         assert_equals(client.readyState, client.DONE, "readyState")
@@ -31,7 +26,7 @@
     var t = async_test('Failed sync cross origin request: onreadystatechange')
     t.step(function() {
         var client = new XMLHttpRequest()
-        client.open('GET', crossdomain + 'resources/cors-makeheader.php?origin=none', false)
+        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin=none', false)
         client.onreadystatechange = t.step_func(function() {
             assert_equals(client.status, 0, "status")
             if (client.readyState == client.DONE)
--- a/tests/cors/submitted/opera/js/https.htm	Thu Feb 02 16:31:22 2012 -0800
+++ b/tests/cors/submitted/opera/js/https.htm	Mon Mar 05 10:49:47 2012 +0100
@@ -4,16 +4,13 @@
     <title>XMLHttpRequest: CORS - https</title>
     <script src="/resources/testharness.js"></script>
     <script src="/resources/testharnessreport.js"></script>
+    <script src="support.js"></script>
   </head>
   <body>
     <p>This shouldn't be tested inside a tunnel.</p>
     <div id="log"></div>
     <script>
 
-    function dirname(path) {
-        return path.replace(/\/[^\/]*$/, '/')
-    }
-
     var crossdomain = "crosssite." + location.hostname
     var url = "https://" + crossdomain + dirname(location.pathname)
     var ports = "8443"
--- a/tests/cors/submitted/opera/js/origin.htm	Thu Feb 02 16:31:22 2012 -0800
+++ b/tests/cors/submitted/opera/js/origin.htm	Mon Mar 05 10:49:47 2012 +0100
@@ -4,26 +4,20 @@
     <title>XMLHttpRequest: CORS - Access-Control-Allow-Origin, various</title>
     <script src="/resources/testharness.js"></script>
     <script src="/resources/testharnessreport.js"></script>
+    <script src="support.js"></script>
   </head>
   <body>
     <p>This shouldn't be tested inside a tunnel.</p>
     <div id="log"></div>
     <script>
 
-    function dirname(path) {
-        return path.replace(/\/[^\/]*$/, '/')
-    }
-
-    var crossdomain = "http://crosssite." + location.host + dirname(location.pathname)
-
-
     /*
      * Origin header
      */
     function shouldPass(origin) {
         test(function () {
             var client = new XMLHttpRequest()
-            client.open('GET', crossdomain
+            client.open('GET', CROSSDOMAIN
                                 + '/resources/cors-makeheader.php?origin='
                                 + encodeURIComponent(origin),
                         false)
@@ -46,7 +40,7 @@
     function shouldFail(origin) {
         test(function () {
             var client = new XMLHttpRequest()
-            client.open('GET', crossdomain
+            client.open('GET', CROSSDOMAIN
                                 + '/resources/cors-makeheader.php?origin='
                                 + encodeURIComponent(origin),
                         false)
@@ -54,7 +48,7 @@
         }, 'Allow origin: ' + origin + ' should throw NETWORK_ERR');
     }
 
-    shouldFail(location.protocol + "//crosssite." + location.host)
+    shouldFail(location.protocol + "//" + SUBDOMAIN + "." + location.host)
     shouldFail("//" + location.host)
     shouldFail("://" + location.host)
     shouldFail("ftp://" + location.host)
@@ -84,7 +78,7 @@
     shouldFail('')
     shouldFail(location.href)
     shouldFail(dirname(location.href))
-    shouldFail(crossdomain)
+    shouldFail(CROSSDOMAIN)
 
     </script>
  </body>
--- a/tests/cors/submitted/opera/js/preflight-cache.htm	Thu Feb 02 16:31:22 2012 -0800
+++ b/tests/cors/submitted/opera/js/preflight-cache.htm	Mon Mar 05 10:49:47 2012 +0100
@@ -4,18 +4,13 @@
     <title>XMLHttpRequest: CORS - preflight cache</title>
     <script src="/resources/testharness.js"></script>
     <script src="/resources/testharnessreport.js"></script>
+    <script src="support.js"></script>
   </head>
   <body>
     <p>This shouldn't be tested inside a tunnel.</p>
     <div id="log"></div>
     <script>
 
-    function dirname(path) {
-        return path.replace(/\/[^\/]*$/, '/')
-    }
-
-    var crossdomain = "http://crosssite." + location.host + dirname(location.pathname)
-
     /*
      * Cache
      */
@@ -30,7 +25,7 @@
         }
 
         client.open(set.method,
-                crossdomain + 'resources/preflight.php?ident=' + ident + set.extra,
+                CROSSDOMAIN + 'resources/preflight.php?ident=' + ident + set.extra,
                 false)
         client.setRequestHeader('x-print', ident)
         client.send()
@@ -85,7 +80,7 @@
 
     ;(function() {
         test_c++;
-        var test = async_test("preflight first request, second from cache, wait, third should preflight again", { timeout: 4000 }),
+        var test = async_test("preflight first request, second from cache, wait, third should preflight again", { timeout: 6000 }),
             time = new Date().getTime(),
             dothing = function (url, msg, setrequest, func) {
                 client = new XMLHttpRequest(),
@@ -99,13 +94,16 @@
                             test.step(func)
                     }
                 })
+                client.onerror = test.step_func(function(e) {
+                    assert_unreached("Got unexpected error event on the XHR object")
+                })
                 client.send()
                 console.log(client)
             }
 
         test.step(function() {
             /* First cycle, gets x-print into the cache, with timeout 1 */
-            dothing(crossdomain + 'resources/preflight.php?max_age=1&ident=',
+            dothing(CROSSDOMAIN + 'resources/preflight.php?max_age=1&ident=',
             'first', true, function(){
                 test = test;
 
@@ -113,7 +111,7 @@
                 dothing('resources/checkandremovefromlog.php?ident=',
                 '1', false, function(){
                     test = test;
-                    dothing(crossdomain + 'resources/preflight.php?max_age=1&ident=',
+                    dothing(CROSSDOMAIN + 'resources/preflight.php?max_age=1&ident=',
                     'second', true, function() {
                         test = test;
 
@@ -124,7 +122,7 @@
 
                             /* Wait until the preflight cache age is old (and thus cleared) */
                             setTimeout(test.step_func(function(){
-                                dothing(crossdomain + 'resources/preflight.php?max_age=1&ident=',
+                                dothing(CROSSDOMAIN + 'resources/preflight.php?max_age=1&ident=',
                                 'third', true, function(){
                                     test = test;
 
--- a/tests/cors/submitted/opera/js/redirect-preflight.htm	Thu Feb 02 16:31:22 2012 -0800
+++ b/tests/cors/submitted/opera/js/redirect-preflight.htm	Mon Mar 05 10:49:47 2012 +0100
@@ -4,17 +4,13 @@
     <title>XMLHttpRequest: CORS - redirect with preflight</title>
     <script src="/resources/testharness.js"></script>
     <script src="/resources/testharnessreport.js"></script>
+    <script src="support.js"></script>
   </head>
   <body>
     <p>This shouldn't be tested inside a tunnel.</p>
     <div id="log"></div>
     <script>
 
-    function dirname(path) {
-        return path.replace(/\/[^\/]*$/, '/')
-    }
-
-    var crossdomain = "http://crosssite." + location.hostname + dirname(location.pathname)
     var req_c = 0 // Request count for cache busting and easy identifying of request in traffic analyzer
 
     /*
@@ -24,9 +20,9 @@
     function redir_preflight(code) {
         test(function() {
             var client = new XMLHttpRequest(),
-                redirect = crossdomain + 'resources/cors-makeheader.php?headers=x-test&' + req_c++
+                redirect = CROSSDOMAIN + 'resources/cors-makeheader.php?headers=x-test&' + req_c++
 
-            client.open('GET', crossdomain + 'resources/cors-makeheader.php?'
+            client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?'
                                + 'headers=x-test&location=' + encodeURIComponent(redirect)
                                + '&code=' + code + '&preflight=' + code + '&' + req_c++,
                         false)
@@ -46,9 +42,9 @@
     function redir_after_preflight(code) {
         test(function() {
             var client = new XMLHttpRequest(),
-                redirect = crossdomain + 'resources/cors-makeheader.php?headers=x-test&' + req_c++
+                redirect = CROSSDOMAIN + 'resources/cors-makeheader.php?headers=x-test&' + req_c++
 
-            client.open('GET', crossdomain + 'resources/cors-makeheader.php?'
+            client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?'
                                + 'preflight=200&headers=x-test&location='
                                + encodeURIComponent(redirect) + '&code=' + code + '&' + req_c++,
                         false)
@@ -56,7 +52,7 @@
             assert_throws('NETWORK_ERR', function() { client.send(null) });
 
         },
-        'Redirect ' + code + ' after succesful preflight')
+        'Redirect ' + code + ' after succesful (200) preflight')
     }
     redir_after_preflight(301)
     redir_after_preflight(302)
--- a/tests/cors/submitted/opera/js/redirect.htm	Thu Feb 02 16:31:22 2012 -0800
+++ b/tests/cors/submitted/opera/js/redirect.htm	Mon Mar 05 10:49:47 2012 +0100
@@ -4,17 +4,13 @@
     <title>XMLHttpRequest: CORS - redirect</title>
     <script src="/resources/testharness.js"></script>
     <script src="/resources/testharnessreport.js"></script>
+    <script src="support.js"></script>
   </head>
   <body>
     <p>This shouldn't be tested inside a tunnel.</p>
     <div id="log"></div>
     <script>
 
-    function dirname(path) {
-        return path.replace(/\/[^\/]*$/, '/')
-    }
-
-    var crossdomain = "http://crosssite." + location.hostname + dirname(location.pathname)
     var req_c = 0 // Request count for cache busting and easy identifying of request in traffic analyzer
 
     /*
@@ -24,7 +20,7 @@
     test(function() {
         var client = new XMLHttpRequest()
         client.open('GET', 'resources/cors-makeheader.php?origin=none&location='
-                            + crossdomain + 'resources/cors-headers.php&' + req_c++,
+                            + CROSSDOMAIN + 'resources/cors-headers.php&' + req_c++,
                     false)
         client.send(null)
 
@@ -34,7 +30,7 @@
 
     test(function() {
         var client = new XMLHttpRequest()
-        client.open('GET', crossdomain + 'resources/cors-makeheader.php?origin=none&location='
+        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin=none&location='
                            + dirname(location.href) + 'resources/cors-headers.php&' + req_c++,
                     false)
         assert_throws('NETWORK_ERR', function () { client.send(null) } )
@@ -43,7 +39,7 @@
 
     test(function() {
         var client = new XMLHttpRequest()
-        client.open('GET', crossdomain + 'resources/cors-makeheader.php?origin=*&location='
+        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin=*&location='
                            + dirname(location.href) + 'resources/cors-headers.php&' + req_c++,
                     false)
         client.send(null)
@@ -54,7 +50,7 @@
 
     test(function() {
         var client = new XMLHttpRequest()
-        client.open('GET', crossdomain + 'resources/cors-makeheader.php?origin=&location='
+        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin=&location='
                            + dirname(location.href) + 'resources/cors-headers.php&' + req_c++,
                     false)
         assert_throws('NETWORK_ERR', function () { client.send(null) } )
@@ -63,7 +59,7 @@
 
     test(function() {
         var client = new XMLHttpRequest()
-        client.open('GET', crossdomain + 'resources/cors-makeheader.php?origin='
+        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin='
                            + location.protocol + "//" + location.host+'&location='
                            + dirname(location.href) + 'resources/cors-headers.php&' + req_c++,
                     false)
@@ -75,9 +71,9 @@
 
     test(function() {
         var client = new XMLHttpRequest()
-        client.open('GET', crossdomain + 'resources/cors-makeheader.php?origin='
+        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin='
                            + location.protocol + "//" + location.host + '&location='
-                           + crossdomain + 'resources/cors-headers.php&' + req_c++,
+                           + CROSSDOMAIN + 'resources/cors-headers.php&' + req_c++,
                     false)
         client.send(null)
 
@@ -90,9 +86,9 @@
         var client = new XMLHttpRequest(),
             redir3 = dirname(location.href)
                     + "resources/cors-makeheader.php?origin=none&get_value=NyanNyan&" + req_c++,
-            redir2 = crossdomain + 'resources/cors-makeheader.php?origin=*&location='
+            redir2 = CROSSDOMAIN + 'resources/cors-makeheader.php?origin=*&location='
                      + encodeURIComponent(redir3) + "&" + req_c++
-        client.open('GET', crossdomain + 'resources/cors-makeheader.php?origin='
+        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin='
                            + location.protocol + "//" + location.host + '&location='
                            + encodeURIComponent(redir2) + '&' + req_c++,
                     false)
@@ -107,9 +103,9 @@
         var client = new XMLHttpRequest(),
             redir3 = dirname(location.href)
                     + "resources/cors-makeheader.php?origin=http://example.net&get_value=Cool&" + req_c++,
-            redir2 = crossdomain + 'resources/cors-makeheader.php?location='
+            redir2 = CROSSDOMAIN + 'resources/cors-makeheader.php?location='
                      + encodeURIComponent(redir3) + '&' + req_c++
-        client.open('GET', crossdomain + 'resources/cors-makeheader.php?origin=*'
+        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin=*'
                            + '&location=' + encodeURIComponent(redir2) + '&' + req_c++,
                     false)
         client.send(null)
@@ -122,8 +118,8 @@
     test(function() {
         var client = new XMLHttpRequest(),
             redir2 = dirname(location.href) + 'resources/cors-makeheader.php?origin=none&location='
-                     + crossdomain + 'resources/cors-makeheader.php&' + req_c++
-        client.open('GET', crossdomain + 'resources/cors-makeheader.php?location='
+                     + CROSSDOMAIN + 'resources/cors-makeheader.php&' + req_c++
+        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?location='
                            + encodeURIComponent(redir2) + '&' + req_c++,
                     false)
         client.send(null)
@@ -135,9 +131,9 @@
 
     test(function() {
         var client = new XMLHttpRequest(),
-            redir2 = crossdomain + 'resources/cors-makeheader.php?origin=none&' + req_c++
+            redir2 = CROSSDOMAIN + 'resources/cors-makeheader.php?origin=none&' + req_c++
 
-        client.open('GET', crossdomain + 'resources/cors-makeheader.php?origin='
+        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin='
                            + location.protocol + "//" + location.host + '&location='
                            + encodeURIComponent(redir2) + '&' + req_c++,
                     false)
@@ -147,9 +143,9 @@
 
     test(function() {
         var client = new XMLHttpRequest(),
-            redir2 = crossdomain + 'resources/cors-makeheader.php?origin=null&' + req_c++
+            redir2 = CROSSDOMAIN + 'resources/cors-makeheader.php?origin=null&' + req_c++
 
-        client.open('GET', crossdomain + 'resources/cors-makeheader.php?origin='
+        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin='
                            + location.protocol + "//" + location.host + '&location='
                            + encodeURIComponent(redir2) + '&' + req_c++,
                     false)
@@ -161,11 +157,11 @@
     function redir(code) {
         test(function() {
             var client = new XMLHttpRequest(),
-                redir3 = crossdomain + 'resources/cors-makeheader.php?get_value=last&' + req_c++,
-                redir2 = crossdomain + 'resources/cors-makeheader.php?code=' + code
+                redir3 = CROSSDOMAIN + 'resources/cors-makeheader.php?get_value=last&' + req_c++,
+                redir2 = CROSSDOMAIN + 'resources/cors-makeheader.php?code=' + code
                          + '&location=' + encodeURIComponent(redir3) + '&' + req_c++
 
-            client.open('GET', crossdomain + 'resources/cors-makeheader.php?location='
+            client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?location='
                                + encodeURIComponent(redir2) + '&' + req_c++,
                         false)
             client.send(null)
--- a/tests/cors/submitted/opera/js/request.htm	Thu Feb 02 16:31:22 2012 -0800
+++ b/tests/cors/submitted/opera/js/request.htm	Mon Mar 05 10:49:47 2012 +0100
@@ -4,22 +4,20 @@
     <title>XMLHttpRequest: CORS - request</title>
     <script src="/resources/testharness.js"></script>
     <script src="/resources/testharnessreport.js"></script>
+    <script src="support.js"></script>
   </head>
   <body>
     <p>This shouldn't be tested inside a tunnel.</p>
     <div id="log"></div>
     <script>
 
-    var crossdomain = "http://crosssite." + location.host + location.pathname.replace(/\/[^\/]*$/, '/')
-
-
     /*
      * Request Headers
      */
 
     test(function() {
         var client = new XMLHttpRequest()
-        client.open('GET', crossdomain + 'resources/cors-makeheader.php?headers=x-print', false)
+        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?headers=x-print', false)
         client.setRequestHeader('x-print', 'unicorn')
         client.send(null)
 
@@ -29,7 +27,7 @@
 
     test(function() {
         var client = new XMLHttpRequest()
-        client.open('GET', crossdomain + 'resources/cors-makeheader.php?headers=x-print,', false)
+        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?headers=x-print,', false)
         client.setRequestHeader('x-print', 'unicorn')
         client.setRequestHeader('content-type', 'text/plain')
         client.setRequestHeader('accept', 'test')
@@ -47,7 +45,7 @@
 
     test(function() {
         var client = new XMLHttpRequest()
-        client.open('GET', crossdomain + 'resources/cors-makeheader.php?headers=x-print', false)
+        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?headers=x-print', false)
         client.setRequestHeader('x-print', 'unicorn')
         client.setRequestHeader('y-print', 'unicorn')
         assert_throws('NETWORK_ERR', function() { client.send(null) })
@@ -55,7 +53,7 @@
 
     test(function() {
         var client = new XMLHttpRequest()
-        client.open('GET', crossdomain + 'resources/cors-makeheader.php?headers=,y-lol,x-PriNT,%20,,,Y-PRINT', false)
+        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?headers=,y-lol,x-PriNT,%20,,,Y-PRINT', false)
         client.setRequestHeader('x-print', 'unicorn')
         client.setRequestHeader('y-print', 'narwhal')
         client.send(null)
@@ -73,7 +71,7 @@
 
     test(function() {
         var client = new XMLHttpRequest()
-        client.open('GET', crossdomain + 'resources/cors-makeheader.php?headers=,y-lol,x-PriNT,%20,,,Y-PRINT', false)
+        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?headers=,y-lol,x-PriNT,%20,,,Y-PRINT', false)
         client.send()
         assert_throws('INVALID_STATE_ERR', function() { client.setRequestHeader('x-print', 'unicorn') })
     },
--- a/tests/cors/submitted/opera/js/response.htm	Thu Feb 02 16:31:22 2012 -0800
+++ b/tests/cors/submitted/opera/js/response.htm	Mon Mar 05 10:49:47 2012 +0100
@@ -4,14 +4,13 @@
     <title>XMLHttpRequest: CORS - Response headers</title>
     <script src="/resources/testharness.js"></script>
     <script src="/resources/testharnessreport.js"></script>
+    <script src="support.js"></script>
   </head>
   <body>
     <p>This shouldn't be tested inside a tunnel.</p>
     <div id="log"></div>
     <script>
 
-    var crossdomain = "http://crosssite." + location.host + location.pathname.replace(/\/[^\/]*$/, '/')
-
     /*
      * Response Headers
      */
@@ -19,7 +18,7 @@
     function check_response_header(head, value, desc) {
         test(function() {
             var client = new XMLHttpRequest()
-            client.open('GET', crossdomain + 'resources/cors-headers.php', false)
+            client.open('GET', CROSSDOMAIN + 'resources/cors-headers.php', false)
             client.send(null)
 
             if (typeof value === 'function')
@@ -60,7 +59,7 @@
         test.step(function()
         {
             var client = new XMLHttpRequest();
-            client.open("GET", crossdomain + 'resources/cors-headers.php')
+            client.open("GET", CROSSDOMAIN + 'resources/cors-headers.php')
             window.c=client;
             client.onreadystatechange = function()
             {
@@ -91,7 +90,7 @@
 
     test(function() {
         var client = new XMLHttpRequest()
-        client.open('GET', crossdomain + 'resources/cors-headers.php', false)
+        client.open('GET', CROSSDOMAIN + 'resources/cors-headers.php', false)
         client.send(null)
         assert_equals(client.getResponseHeader("x-custom-header"), "test", 'x-custom-header')
         assert_equals(client.getResponseHeader("x-nonexposed"), null, 'x-nonexposed')
@@ -99,7 +98,7 @@
 
     test(function() {
         var client = new XMLHttpRequest()
-        client.open('GET', crossdomain + 'resources/cors-headers.php', false)
+        client.open('GET', CROSSDOMAIN + 'resources/cors-headers.php', false)
         client.send(null)
 
         h = client.getAllResponseHeaders().toLowerCase()
--- a/tests/cors/submitted/opera/js/simple-requests.htm	Thu Feb 02 16:31:22 2012 -0800
+++ b/tests/cors/submitted/opera/js/simple-requests.htm	Mon Mar 05 10:49:47 2012 +0100
@@ -4,14 +4,13 @@
     <title>XMLHttpRequest: CORS - simple requests</title>
     <script src="/resources/testharness.js"></script>
     <script src="/resources/testharnessreport.js"></script>
+    <script src="support.js"></script>
   </head>
   <body>
     <p>This shouldn't be tested inside a tunnel.</p>
     <div id="log"></div>
     <script>
 
-    var crossdomain = "http://crosssite." + location.host + location.pathname.replace(/\/[^\/]*$/, '/')
-
     /*
      * Simple requests that shouldn't trigger preflight
      */
@@ -24,7 +23,7 @@
             var time = new Date().getTime(),
                 client = new XMLHttpRequest()
             test_c++
-            client.open(method, crossdomain + 'resources/preflight.php?ident='
+            client.open(method, CROSSDOMAIN + 'resources/preflight.php?ident='
                                 + test_c + time, false)
             for (head in headers)
                 client.setRequestHeader(head, headers[head])
@@ -74,7 +73,7 @@
     simple_async.step(function (){
         var time = new Date().getTime(),
             client = new XMLHttpRequest()
-        client.open('POST', crossdomain + 'resources/preflight.php?ident='
+        client.open('POST', CROSSDOMAIN + 'resources/preflight.php?ident='
                             + time, true)
 
         client.setRequestHeader('Accept', 'jewelry')
--- a/tests/cors/submitted/opera/js/status-async.htm	Thu Feb 02 16:31:22 2012 -0800
+++ b/tests/cors/submitted/opera/js/status-async.htm	Mon Mar 05 10:49:47 2012 +0100
@@ -4,18 +4,18 @@
     <title>XMLHttpRequest: CORS - status (async)</title>
     <script src="/resources/testharness.js"></script>
     <script src="/resources/testharnessreport.js"></script>
+    <script src="support.js"></script>
   </head>
   <body>
     <p>This shouldn't be tested inside a tunnel.</p>
     <div id="log"></div>
     <script>
-      var crossdomain = "http://crosssite." + location.hostname + location.pathname.replace(/\/[^\/]*$/, '/')
 
       function statusRequest(method, code, text, content, type) {
         var test = async_test("Status on " + method + " " + code)
         test.step(function() {
           var client = new XMLHttpRequest()
-          client.open(method, crossdomain + "resources/status.php?code="
+          client.open(method, CROSSDOMAIN + "resources/status.php?code="
             + code + "&text=" + text + "&content=" + content + "&type=" + type, true)
           client.onreadystatechange = test.step_func(function() {
             if (client.readyState != client.DONE)
@@ -51,7 +51,7 @@
         test.step(function() {
           var client = new XMLHttpRequest()
 
-          client.open(method, crossdomain + "resources/status.php?code="
+          client.open(method, CROSSDOMAIN + "resources/status.php?code="
             + code + '&headers=x-nonsimple&text=OHAI', true)
 
           if (nonsimple === true)
--- a/tests/cors/submitted/opera/js/status-errors.htm	Thu Feb 02 16:31:22 2012 -0800
+++ b/tests/cors/submitted/opera/js/status-errors.htm	Mon Mar 05 10:49:47 2012 +0100
@@ -3,6 +3,7 @@
 <title>CORS error events</title>
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
+<script src="support.js"></script>
 
 <pre>
    allowed  preflight  response  | status |
@@ -18,10 +19,7 @@
 
 <script>
 
-    var counter = 0,
-        crossdomain = location.href
-            .replace('://', '://crosssite.')
-            .replace(/\/[^\/]*$/, '/')
+    var counter = 0
 
     function testit(allow, preflight, response, status) {
         var test = async_test(
@@ -34,7 +32,7 @@
 
         test.step(function() {
             var client = new XMLHttpRequest()
-            client.open('GET', crossdomain + 'resources/cors-makeheader.php?' + counter +
+            client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?' + counter +
                 (allow ? '&headers=x-custom': '&origin=none') +
                 (response ? '&code='+response : '') +
                 (preflight ? '&preflight='+preflight : '')
--- a/tests/cors/submitted/opera/js/status-preflight.htm	Thu Feb 02 16:31:22 2012 -0800
+++ b/tests/cors/submitted/opera/js/status-preflight.htm	Mon Mar 05 10:49:47 2012 +0100
@@ -4,14 +4,13 @@
     <title>CORS - status after preflight</title>
     <script src="/resources/testharness.js"></script>
     <script src="/resources/testharnessreport.js"></script>
+    <script src="support.js"></script>
   </head>
   <body>
     <p>This shouldn't be tested inside a tunnel.</p>
     <div id="log"></div>
     <script>
-      var crossdomain = "http://crosssite." + location.hostname + location.pathname.replace(/\/[^\/]*$/, '/'),
-          counter = 0
-
+      var counter = 0
 
       function statusAfterPreflight(method, code) {
         counter++
@@ -20,7 +19,7 @@
 
         test.step(function() {
           var client = new XMLHttpRequest()
-          client.open(method, crossdomain + "resources/status.php?" + counter
+          client.open(method, CROSSDOMAIN + "resources/status.php?" + counter
             +"&code=" + code + '&headers=x-nonsimple&preflight=200', true)
 
           client.setRequestHeader('x-nonsimple', true)
--- a/tests/cors/submitted/opera/js/status.htm	Thu Feb 02 16:31:22 2012 -0800
+++ b/tests/cors/submitted/opera/js/status.htm	Mon Mar 05 10:49:47 2012 +0100
@@ -3,6 +3,7 @@
 <title>CORS status</title>
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
+<script src="support.js"></script>
 
 <pre>
    allowed  preflight  response  | status |
@@ -18,10 +19,7 @@
 
 <script>
 
-    var counter = 0,
-        crossdomain = location.href
-            .replace('://', '://crosssite.')
-            .replace(/\/[^\/]*$/, '/')
+    var counter = 0
 
     function testit(allow, preflight, response, status) {
         var test = async_test(
@@ -34,7 +32,7 @@
 
         test.step(function() {
             var client = new XMLHttpRequest()
-            client.open('GET', crossdomain + 'resources/cors-makeheader.php?' + counter +
+            client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?' + counter +
                 (allow ? '&headers=x-custom': '&origin=none') +
                 (response ? '&code='+response : '') +
                 (preflight ? '&preflight='+preflight : '')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/cors/submitted/opera/js/support.js	Mon Mar 05 10:49:47 2012 +0100
@@ -0,0 +1,24 @@
+// For ignoring exception names (just for testing)
+/*
+_real_assert_throws = assert_throws;
+function assert_throws(d, func, desc) {
+    try {
+        func();
+    } catch(e) {
+        return true;
+    }
+    assert_unreached("Didn't throw!");
+}
+*/
+
+function dirname(path) {
+    return path.replace(/\/[^\/]*$/, '/')
+}
+
+/* This subdomain should point to this same location */
+var SUBDOMAIN = 'www1'
+var PORT = "8081"
+
+/* Changes http://example.com/abc/def/cool.htm to http://www1.example.com/abc/def/ */
+var CROSSDOMAIN = dirname(location.href)
+    .replace('://', '://' + SUBDOMAIN + '.')