From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- dom/tests/mochitest/beacon/beacon-frame.html | 24 ++++ dom/tests/mochitest/beacon/beacon-handler.sjs | 127 +++++++++++++++++++++ .../beacon/beacon-originheader-handler.sjs | 48 ++++++++ .../mochitest/beacon/beacon-preflight-handler.sjs | 39 +++++++ .../mochitest/beacon/beacon-redirect-handler.sjs | 47 ++++++++ dom/tests/mochitest/beacon/beacon-set-cookie.sjs | 8 ++ dom/tests/mochitest/beacon/chrome.ini | 6 + dom/tests/mochitest/beacon/file_beaconCookies.html | 8 ++ dom/tests/mochitest/beacon/mochitest.ini | 13 +++ dom/tests/mochitest/beacon/test_beacon.html | 60 ++++++++++ .../mochitest/beacon/test_beaconContentPolicy.html | 102 +++++++++++++++++ dom/tests/mochitest/beacon/test_beaconCookies.html | 89 +++++++++++++++ dom/tests/mochitest/beacon/test_beaconFrame.html | 118 +++++++++++++++++++ .../mochitest/beacon/test_beaconOriginHeader.html | 67 +++++++++++ .../test_beaconPreflightWithCustomContentType.html | 57 +++++++++ .../mochitest/beacon/test_beaconRedirect.html | 62 ++++++++++ 16 files changed, 875 insertions(+) create mode 100644 dom/tests/mochitest/beacon/beacon-frame.html create mode 100644 dom/tests/mochitest/beacon/beacon-handler.sjs create mode 100644 dom/tests/mochitest/beacon/beacon-originheader-handler.sjs create mode 100644 dom/tests/mochitest/beacon/beacon-preflight-handler.sjs create mode 100644 dom/tests/mochitest/beacon/beacon-redirect-handler.sjs create mode 100644 dom/tests/mochitest/beacon/beacon-set-cookie.sjs create mode 100644 dom/tests/mochitest/beacon/chrome.ini create mode 100644 dom/tests/mochitest/beacon/file_beaconCookies.html create mode 100644 dom/tests/mochitest/beacon/mochitest.ini create mode 100644 dom/tests/mochitest/beacon/test_beacon.html create mode 100644 dom/tests/mochitest/beacon/test_beaconContentPolicy.html create mode 100644 dom/tests/mochitest/beacon/test_beaconCookies.html create mode 100644 dom/tests/mochitest/beacon/test_beaconFrame.html create mode 100644 dom/tests/mochitest/beacon/test_beaconOriginHeader.html create mode 100644 dom/tests/mochitest/beacon/test_beaconPreflightWithCustomContentType.html create mode 100644 dom/tests/mochitest/beacon/test_beaconRedirect.html (limited to 'dom/tests/mochitest/beacon') diff --git a/dom/tests/mochitest/beacon/beacon-frame.html b/dom/tests/mochitest/beacon/beacon-frame.html new file mode 100644 index 000000000..9dc4e4aab --- /dev/null +++ b/dom/tests/mochitest/beacon/beacon-frame.html @@ -0,0 +1,24 @@ + + + + Inner frame performing a basic sendBeacon from within an iframe + + + + + + + diff --git a/dom/tests/mochitest/beacon/beacon-handler.sjs b/dom/tests/mochitest/beacon/beacon-handler.sjs new file mode 100644 index 000000000..a3b6f2593 --- /dev/null +++ b/dom/tests/mochitest/beacon/beacon-handler.sjs @@ -0,0 +1,127 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +const CC = Components.Constructor; +const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1", + "nsIBinaryInputStream", + "setInputStream"); + +function DEBUG(str) +{ + // dump("********** " + str + "\n"); +} + +function setOurState(data) { + x = { data: data, QueryInterface: function(iid) { return this } }; + x.wrappedJSObject = x; + setObjectState("beacon-handler", x); + DEBUG("our state is " + data); +} + +function getOurState() { + var data; + getObjectState("beacon-handler", function(x) { + // x can be null if no one has set any state yet + if (x) { + data = x.wrappedJSObject.data; + } + }); + return data; +} + +function handleRequest(request, response) { + DEBUG("Entered request handler"); + response.setHeader("Cache-Control", "no-cache", false); + + function finishControlResponse(response) { + DEBUG("********* sending out the control GET response"); + var data = getState("beaconData"); + var mimetype = getState("beaconMimetype"); + DEBUG("GET was sending : " + data + "\n"); + DEBUG("GET was sending : " + mimetype + "\n"); + var result = { + "data": data, + "mimetype": mimetype, + }; + response.write(JSON.stringify(result)); + setOurState(null); + } + + if (request.method == "GET") { + DEBUG(" ------------ GET --------------- "); + response.setHeader("Content-Type", "application/json", false); + switch (request.queryString) { + case "getLastBeacon": + var state = getOurState(); + if (state === "unblocked") { + finishControlResponse(response); + } else { + DEBUG("GET has arrived, but POST has not, blocking response!"); + setOurState(response); + response.processAsync(); + } + break; + default: + response.setStatusLine(request.httpVersion, 400, "Bad Request"); + break; + } + return; + } + + if (request.method == "POST") { + DEBUG(" ------------ POST --------------- "); + var body = new BinaryInputStream(request.bodyInputStream); + var avail; + var bytes = []; + + while ((avail = body.available()) > 0) { + Array.prototype.push.apply(bytes, body.readByteArray(avail)); + } + + var data = ""; + for (var i=0; i < bytes.length; i++) { + // We are only passing strings at this point. + if (bytes[i] < 32) continue; + var charcode = String.fromCharCode(bytes[i]); + data += charcode; + } + + var mimetype = request.getHeader("Content-Type"); + + // check to see if this is form data. + if (mimetype.indexOf("multipart/form-data") != -1) { + + // trim the mime type to make testing easier. + mimetype = "multipart/form-data"; + // Extract only the form-data name. + + var pattern = /; name=\"(.+)\";/; + data = data.split(pattern)[1]; + } + + DEBUG("********** POST was sending : " + data + "\n"); + DEBUG("********** POST was sending : " + mimetype + "\n"); + setState("beaconData", data); + setState("beaconMimetype", mimetype); + + response.setHeader("Content-Type", "text/plain", false); + response.write('ok'); + + var blockedResponse = getOurState(); + if (typeof(blockedResponse) == "object" && blockedResponse) { + DEBUG("GET is already pending, finishing!"); + finishControlResponse(blockedResponse); + blockedResponse.finish(); + } else { + DEBUG("GET has not arrived, marking it as unblocked"); + setOurState("unblocked"); + } + + return; + } + + response.setStatusLine(request.httpVersion, 402, "Bad Request"); +} diff --git a/dom/tests/mochitest/beacon/beacon-originheader-handler.sjs b/dom/tests/mochitest/beacon/beacon-originheader-handler.sjs new file mode 100644 index 000000000..f6d70fa8a --- /dev/null +++ b/dom/tests/mochitest/beacon/beacon-originheader-handler.sjs @@ -0,0 +1,48 @@ +/* + * TestSever customized specifically for the needs of: + * Bug 1280692 - navigator.sendBeacon() should not send origin header + */ + +function handleRequest(request, response) +{ + response.setHeader("Cache-Control", "no-cache", false); + response.setHeader("Content-Type", "text/plain", false); + + // case XHR-REQUEST: the xhr-request tries to query the + // stored header from the beacon request. + if (request.queryString == "queryheader") { + var header = getState("originHeader"); + // if the beacon already stored the header - return. + if (header) { + response.write(header); + setState("originHeader", ""); + return; + } + // otherwise wait for the beacon request + response.processAsync(); + setObjectState("xhr-response", response); + return; + } + + // case BEACON-REQUEST: get the beacon header and + // store the header on the server. + var header = "reset"; + try { + header = request.getHeader("origin"); + } + catch(e) { + header = "no-header"; + } + setState("originHeader", header); + + + // if there is an xhr-request waiting, return the header now. + getObjectState("xhr-response", function(xhrResponse) { + if (!xhrResponse) { + return; + } + setState("originHeader", ""); + xhrResponse.write(header); + xhrResponse.finish(); + }); +} diff --git a/dom/tests/mochitest/beacon/beacon-preflight-handler.sjs b/dom/tests/mochitest/beacon/beacon-preflight-handler.sjs new file mode 100644 index 000000000..6a760cb84 --- /dev/null +++ b/dom/tests/mochitest/beacon/beacon-preflight-handler.sjs @@ -0,0 +1,39 @@ +function handleRequest(request, response) +{ + response.setHeader("Cache-Control", "no-cache, must-revalidate", false); + + if (request.queryString === "verify") { + var preflightState = getState("preflight"); + response.write(preflightState === "done" ? "green" : "red"); + return; + } + + var originHeader = request.getHeader("origin"); + 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); + + if (request.queryString === "beacon") { + if (request.method == "OPTIONS") { + setState("preflight", "done"); + response.setStatusLine(null, 200, "OK"); + return; + } + response.setStatusLine(null, 200, "OK"); + response.write("DONE"); + return; + } + + if (request.queryString === "fail") { + if (request.method == "OPTIONS") { + setState("preflight", "done"); + response.setStatusLine(null, 400, "Bad Request"); + return; + } + setState("preflight", "oops"); + response.setStatusLine(null, 200, "OK"); + response.write("DONE"); + return; + } +} diff --git a/dom/tests/mochitest/beacon/beacon-redirect-handler.sjs b/dom/tests/mochitest/beacon/beacon-redirect-handler.sjs new file mode 100644 index 000000000..bb7e50dba --- /dev/null +++ b/dom/tests/mochitest/beacon/beacon-redirect-handler.sjs @@ -0,0 +1,47 @@ +/* + * TestSever customized specifically for the needs of: + * Bug 1280692 - sendBeacon() should follow 30x redirect + * + * Here is a sequence of the test: + * [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 3] + if (request.queryString === "verifyRedirectDidSucceed") { + var redirectState = getState("redirectState"); + response.write(redirectState); + return; + } + + // [Sequence 1] + if (request.queryString === "beacon") { + setState("redirectState", "reset"); + var newLocation = + "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 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"); +} diff --git a/dom/tests/mochitest/beacon/beacon-set-cookie.sjs b/dom/tests/mochitest/beacon/beacon-set-cookie.sjs new file mode 100644 index 000000000..341620eae --- /dev/null +++ b/dom/tests/mochitest/beacon/beacon-set-cookie.sjs @@ -0,0 +1,8 @@ +function handleRequest(request, response) +{ + response.setHeader("Set-Cookie", "cookie="+ request.host + "~" + Math.random()); + response.setHeader("Content-Type", "text/plain", false); + response.setHeader("Cache-Control", "no-cache", false); + + response.setStatusLine(request.httpVersion, 200, "OK"); +} diff --git a/dom/tests/mochitest/beacon/chrome.ini b/dom/tests/mochitest/beacon/chrome.ini new file mode 100644 index 000000000..ff5afd546 --- /dev/null +++ b/dom/tests/mochitest/beacon/chrome.ini @@ -0,0 +1,6 @@ +[DEFAULT] +skip-if = os == 'android' + +[test_beaconCookies.html] +support-files = beacon-set-cookie.sjs + file_beaconCookies.html diff --git a/dom/tests/mochitest/beacon/file_beaconCookies.html b/dom/tests/mochitest/beacon/file_beaconCookies.html new file mode 100644 index 000000000..aeecb2263 --- /dev/null +++ b/dom/tests/mochitest/beacon/file_beaconCookies.html @@ -0,0 +1,8 @@ + + diff --git a/dom/tests/mochitest/beacon/mochitest.ini b/dom/tests/mochitest/beacon/mochitest.ini new file mode 100644 index 000000000..0093ceed7 --- /dev/null +++ b/dom/tests/mochitest/beacon/mochitest.ini @@ -0,0 +1,13 @@ +[DEFAULT] +support-files = beacon-frame.html + beacon-handler.sjs + beacon-preflight-handler.sjs + beacon-originheader-handler.sjs + beacon-redirect-handler.sjs + +[test_beacon.html] +[test_beaconFrame.html] +[test_beaconPreflightWithCustomContentType.html] +[test_beaconContentPolicy.html] +[test_beaconOriginHeader.html] +[test_beaconRedirect.html] diff --git a/dom/tests/mochitest/beacon/test_beacon.html b/dom/tests/mochitest/beacon/test_beacon.html new file mode 100644 index 000000000..697431bca --- /dev/null +++ b/dom/tests/mochitest/beacon/test_beacon.html @@ -0,0 +1,60 @@ + + + + + Test whether sendBeacon fails for non-HTTP URIs and syntactically incorrect calls + + + + +Mozilla Bug 936340 +

+ +
+
+
+
+
+ + + diff --git a/dom/tests/mochitest/beacon/test_beaconContentPolicy.html b/dom/tests/mochitest/beacon/test_beaconContentPolicy.html new file mode 100644 index 000000000..87e44ae64 --- /dev/null +++ b/dom/tests/mochitest/beacon/test_beaconContentPolicy.html @@ -0,0 +1,102 @@ + + + + + Test that sendBeacon obeys content policy directives + + + + +Mozilla Bug 936340 +

+ +
+
+
+ + diff --git a/dom/tests/mochitest/beacon/test_beaconCookies.html b/dom/tests/mochitest/beacon/test_beaconCookies.html new file mode 100644 index 000000000..e2c4f3b7d --- /dev/null +++ b/dom/tests/mochitest/beacon/test_beaconCookies.html @@ -0,0 +1,89 @@ + + + + + Test whether sendBeacon sets cookies + + + + +Mozilla Bug 936340 +

+ +
+
+
+ + diff --git a/dom/tests/mochitest/beacon/test_beaconFrame.html b/dom/tests/mochitest/beacon/test_beaconFrame.html new file mode 100644 index 000000000..1bcdcca05 --- /dev/null +++ b/dom/tests/mochitest/beacon/test_beaconFrame.html @@ -0,0 +1,118 @@ + + + + + Test for beacon + + + + +Mozilla Bug 936340 +

+ +
+
+ +
+
+
+ + + diff --git a/dom/tests/mochitest/beacon/test_beaconOriginHeader.html b/dom/tests/mochitest/beacon/test_beaconOriginHeader.html new file mode 100644 index 000000000..4594b7a8b --- /dev/null +++ b/dom/tests/mochitest/beacon/test_beaconOriginHeader.html @@ -0,0 +1,67 @@ + + + + Bug 1280692 - navigator.sendBeacon() should not send origin header + + + + + +

+ + + + + + diff --git a/dom/tests/mochitest/beacon/test_beaconPreflightWithCustomContentType.html b/dom/tests/mochitest/beacon/test_beaconPreflightWithCustomContentType.html new file mode 100644 index 000000000..e8e2add11 --- /dev/null +++ b/dom/tests/mochitest/beacon/test_beaconPreflightWithCustomContentType.html @@ -0,0 +1,57 @@ + + + + + Test for Bug 1210302 + + + + +Mozilla Bug 936340 +

+ +
+
+
+ + diff --git a/dom/tests/mochitest/beacon/test_beaconRedirect.html b/dom/tests/mochitest/beacon/test_beaconRedirect.html new file mode 100644 index 000000000..614e3b5b3 --- /dev/null +++ b/dom/tests/mochitest/beacon/test_beaconRedirect.html @@ -0,0 +1,62 @@ + + + + Bug 1280692 - sendBeacon() should follow 30x redirect + + + + + +

+ + + + + + -- cgit v1.2.3