Bug 1280692: Update sendBeacon redirect test. r=sicking
authorChristoph Kerschbaumer <ckerschb@christophkerschbaumer.com>
Tue, 26 Jul 2016 13:46:17 +0200
changeset 346744 52730f426ea0e0c13f0a6ab681e3311f7bb05435
parent 346743 a477bb461f3c77ef4ee090cbf1701b5e7434e1c4
child 346745 670d4c99c1c7310525a5820e3dfd65569b063e7d
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs1280692
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1280692: Update sendBeacon redirect test. r=sicking
dom/tests/mochitest/beacon/beacon-cors-redirect-handler.sjs
dom/tests/mochitest/beacon/beacon-redirect-handler.sjs
dom/tests/mochitest/beacon/mochitest.ini
dom/tests/mochitest/beacon/test_beaconCORSRedirect.html
dom/tests/mochitest/beacon/test_beaconRedirect.html
rename from dom/tests/mochitest/beacon/beacon-cors-redirect-handler.sjs
rename to dom/tests/mochitest/beacon/beacon-redirect-handler.sjs
--- a/dom/tests/mochitest/beacon/beacon-cors-redirect-handler.sjs
+++ b/dom/tests/mochitest/beacon/beacon-redirect-handler.sjs
@@ -1,52 +1,47 @@
 /*
  * TestSever customized specifically for the needs of:
- * Bug 1111834 - sendBeacon() should not follow 30x redirect after preflight
+ * Bug 1280692 - sendBeacon() should follow 30x redirect
  *
  * Here is a sequence of the test:
- * [1] preflight channel (identified by the queryString 'beacon' and method 'OPTIONS')
- * [2] actual channel (identified by the queryString 'beacon') which gets redirected
- * [3] should never happen (the actual redirected request)
- * [4] xhr request (identified by the queryString 'verifyRedirectDidNotSucceed')
- *     which checks if the state was not changed from 'green' to 'red'. If the channel
+ * [1] sendBeacon (identified by the queryString 'beacon') which gets redirected
+ * [2] redirected sendBeacon (identified by the queryString 'redirected') which
+ *     updates the state idniciating that redirected sendBeacon succeeds.
+ * [3] xhr request (identified by the queryString 'verifyRedirectDidSucceed')
+ *     which checks if the state was not changed from 'reset' to 'gree'. If the channel
  *     woulnd't be blocked correctly the redirected channel would set the state to 'red'.
  *
  */
 
 function handleRequest(request, response)
 {
   response.setHeader("Cache-Control", "no-cache, must-revalidate", false);
 
-  // [Sequence 4]
-  if (request.queryString === "verifyRedirectDidNotSucceed") {
+  // [Sequence 3]
+  if (request.queryString === "verifyRedirectDidSucceed") {
     var redirectState = getState("redirectState");
     response.write(redirectState);
     return;
   }
 
-  var originHeader = request.getHeader("origin");
-  response.setHeader("Cache-Control", "no-cache, must-revalidate", false);
-  response.setHeader("Access-Control-Allow-Headers", "content-type", false);
-  response.setHeader("Access-Control-Allow-Methods", "POST, GET", false);
-  response.setHeader("Access-Control-Allow-Origin", originHeader, false);
-  response.setHeader("Access-Control-Allow-Credentials", "true", false);
-
-  // [Sequence 1,2]
+  // [Sequence 1]
   if (request.queryString === "beacon") {
-    setState("redirectState", "green");
-    // [1]
-    if (request.method == "OPTIONS") {
-      response.setStatusLine(null, 200, "OK");
-      return;
-    }
-    // [Sequence 2]
+    setState("redirectState", "reset");
     var newLocation =
-      "http://mochi.test:8888/tests/dom/tests/mochitest/beacon/beacon-cors-redirect-handler.sjs?redirected";
+      "http://mochi.test:8888/tests/dom/tests/mochitest/beacon/beacon-redirect-handler.sjs?redirected";
     response.setStatusLine("1.1", 302, "Found");
     response.setHeader("Location", newLocation, false);
     return;
   }
 
-  // [Sequence 3]
+  // [Sequence 2]
+  if (request.queryString === "redirected") {
+    setState("redirectState", "green");
+    response.setStatusLine(null, 200, "OK");
+    return;
+  }
+
+  // we should never get here, but just in case let's
+  // set the state to something unexpected
   setState("redirectState", "red");
   response.setStatusLine(null, 200, "OK");
 }
--- a/dom/tests/mochitest/beacon/mochitest.ini
+++ b/dom/tests/mochitest/beacon/mochitest.ini
@@ -1,16 +1,16 @@
 [DEFAULT]
 skip-if = buildapp == 'b2g'
 support-files = beacon-frame.html
                 beacon-handler.sjs
                 beacon-preflight-handler.sjs
                 beacon-originheader-handler.sjs
-                beacon-cors-redirect-handler.sjs
+                beacon-redirect-handler.sjs
 
 [test_beacon.html]
 [test_beaconFrame.html]
 [test_beaconPreflight.html]
 [test_beaconPreflightFailure.html]
 [test_beaconPreflightWithCustomContentType.html]
 [test_beaconContentPolicy.html]
 [test_beaconOriginHeader.html]
-[test_beaconCORSRedirect.html]
+[test_beaconRedirect.html]
rename from dom/tests/mochitest/beacon/test_beaconCORSRedirect.html
rename to dom/tests/mochitest/beacon/test_beaconRedirect.html
--- a/dom/tests/mochitest/beacon/test_beaconCORSRedirect.html
+++ b/dom/tests/mochitest/beacon/test_beaconRedirect.html
@@ -1,57 +1,57 @@
 <!DOCTYPE HTML>
 <html>
 <head>
-  <title>Bug 1111834 - sendBeacon() should not follow 30x redirect after preflight</title>
+  <title>Bug 1280692 - sendBeacon() should follow 30x redirect</title>
   <!-- Including SimpleTest.js so we can use waitForExplicitFinish !-->
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
   <p id="display"></p>
   <div id="content" style="visibility: hidden">
     <iframe style="width:100%;" id="testframe"></iframe>
   </div>
 
 <script class="testbody" type="text/javascript">
 
 /* Description of the test:
- *   We do perform a non simple sendBeacon request. After the preflight channel returns correctly
- *   the actual channel is about to follow a 30x cross origin redirect, which is forbidden by the spec.
+ *   We do perform a non simple sendBeacon request which should not use CORS and should follow
+ *   a 30x cross origin redirect, which is allowed by the spec.
  */
 
 SimpleTest.waitForExplicitFinish();
 
-const BEACON_URL = "http://example.com/tests/dom/tests/mochitest/beacon/beacon-cors-redirect-handler.sjs?beacon";
+const BEACON_URL = "http://example.com/tests/dom/tests/mochitest/beacon/beacon-redirect-handler.sjs?beacon";
 
 SpecialPowers.pushPrefEnv({'set': [["beacon.enabled", true]]}, runTest);
 
 var intervalID = null;
 
 function queryIfRedirectSucceeded() {
   clearInterval(intervalID);
   var xhr = new XMLHttpRequest();
-  xhr.open("GET", "beacon-cors-redirect-handler.sjs?verifyRedirectDidNotSucceed", true);
+  xhr.open("GET", "beacon-redirect-handler.sjs?verifyRedirectDidSucceed", true);
   xhr.onload = function() {
-    is(xhr.responseText, "green", "SendBeacon does not follow cross origin redirects after preflight!");
+    is(xhr.responseText, "green", "SendBeacon should follow cross origin redirects!");
     SimpleTest.finish();
   };
   xhr.onerror = function() {
     ok(false, "xhr request returned error");
     SimpleTest.finish();
   };
   xhr.send();
 }
 
 function runTest() {
   var data = new Uint8Array([0,1,2,3]);
   navigator.sendBeacon(BEACON_URL, data);
 
-  // we have to make sure the channel did not follow the redirect hence
+  // we have to make sure the channel did follow the redirect hence
   // we have to wait for 2 seconds before we can query the result.
   intervalID = setInterval(queryIfRedirectSucceeded, 2000);
 }
 
 </script>
 </pre>
 </body>
 </html>