From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- dom/tests/mochitest/beacon/beacon-frame.html | 24 ++++ dom/tests/mochitest/beacon/beacon-handler.sjs | 149 +++++++++++++++++++++ .../beacon/beacon-originheader-handler.sjs | 45 +++++++ .../mochitest/beacon/beacon-preflight-handler.sjs | 38 ++++++ .../mochitest/beacon/beacon-redirect-handler.sjs | 46 +++++++ dom/tests/mochitest/beacon/beacon-set-cookie.sjs | 10 ++ dom/tests/mochitest/beacon/chrome.ini | 10 ++ dom/tests/mochitest/beacon/file_beaconCookies.html | 8 ++ .../mochitest/beacon/file_beaconSafelist.html | 11 ++ dom/tests/mochitest/beacon/mochitest.ini | 22 +++ dom/tests/mochitest/beacon/test_beacon.html | 60 +++++++++ .../mochitest/beacon/test_beaconContentPolicy.html | 103 ++++++++++++++ dom/tests/mochitest/beacon/test_beaconCookies.html | 82 ++++++++++++ dom/tests/mochitest/beacon/test_beaconFrame.html | 118 ++++++++++++++++ .../mochitest/beacon/test_beaconOriginHeader.html | 66 +++++++++ .../test_beaconPreflightWithCustomContentType.html | 57 ++++++++ .../mochitest/beacon/test_beaconRedirect.html | 57 ++++++++ .../test_beaconWithSafelistedContentType.html | 102 ++++++++++++++ 18 files changed, 1008 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/file_beaconSafelist.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 create mode 100644 dom/tests/mochitest/beacon/test_beaconWithSafelistedContentType.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 0000000000..f50e04e90a --- /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 0000000000..a1e851ac5b --- /dev/null +++ b/dom/tests/mochitest/beacon/beacon-handler.sjs @@ -0,0 +1,149 @@ +/* -*- 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, + QueryInterface(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, + 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 "getLastBeaconCors": + // Allow CORS responses of the last beacon + 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); + // fallthrough + 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 = ""; + if (request.hasHeader("Content-Type")) { + 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 0000000000..96304187a8 --- /dev/null +++ b/dom/tests/mochitest/beacon/beacon-originheader-handler.sjs @@ -0,0 +1,45 @@ +/* + * 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 0000000000..f4a89b9828 --- /dev/null +++ b/dom/tests/mochitest/beacon/beacon-preflight-handler.sjs @@ -0,0 +1,38 @@ +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 0000000000..5496353588 --- /dev/null +++ b/dom/tests/mochitest/beacon/beacon-redirect-handler.sjs @@ -0,0 +1,46 @@ +/* + * 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 0000000000..e2dce0b3c6 --- /dev/null +++ b/dom/tests/mochitest/beacon/beacon-set-cookie.sjs @@ -0,0 +1,10 @@ +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 0000000000..27f8f93952 --- /dev/null +++ b/dom/tests/mochitest/beacon/chrome.ini @@ -0,0 +1,10 @@ +[DEFAULT] +skip-if = os == 'android' + +[test_beaconCookies.html] +skip-if = (verify && !debug && (os == 'win')) +support-files = beacon-set-cookie.sjs + file_beaconCookies.html +[test_beaconWithSafelistedContentType.html] +support-files = beacon-handler.sjs + file_beaconSafelist.html diff --git a/dom/tests/mochitest/beacon/file_beaconCookies.html b/dom/tests/mochitest/beacon/file_beaconCookies.html new file mode 100644 index 0000000000..aeecb2263e --- /dev/null +++ b/dom/tests/mochitest/beacon/file_beaconCookies.html @@ -0,0 +1,8 @@ + + diff --git a/dom/tests/mochitest/beacon/file_beaconSafelist.html b/dom/tests/mochitest/beacon/file_beaconSafelist.html new file mode 100644 index 0000000000..0079ed5074 --- /dev/null +++ b/dom/tests/mochitest/beacon/file_beaconSafelist.html @@ -0,0 +1,11 @@ + + diff --git a/dom/tests/mochitest/beacon/mochitest.ini b/dom/tests/mochitest/beacon/mochitest.ini new file mode 100644 index 0000000000..9f51091c52 --- /dev/null +++ b/dom/tests/mochitest/beacon/mochitest.ini @@ -0,0 +1,22 @@ +[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] +skip-if = + http3 +[test_beaconPreflightWithCustomContentType.html] +skip-if = + http3 +[test_beaconContentPolicy.html] +[test_beaconOriginHeader.html] +skip-if = + verify + http3 +[test_beaconRedirect.html] +skip-if = + http3 diff --git a/dom/tests/mochitest/beacon/test_beacon.html b/dom/tests/mochitest/beacon/test_beacon.html new file mode 100644 index 0000000000..4df99cfe8e --- /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 0000000000..0e1bce574e --- /dev/null +++ b/dom/tests/mochitest/beacon/test_beaconContentPolicy.html @@ -0,0 +1,103 @@ + + + + + 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 0000000000..192e1395f5 --- /dev/null +++ b/dom/tests/mochitest/beacon/test_beaconCookies.html @@ -0,0 +1,82 @@ + + + + + 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 0000000000..940cb9ecf6 --- /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 0000000000..177ca94dba --- /dev/null +++ b/dom/tests/mochitest/beacon/test_beaconOriginHeader.html @@ -0,0 +1,66 @@ + + + + Bug 1280692 - navigator.sendBeacon() should 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 0000000000..d1007b78c5 --- /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 0000000000..210b7a1e98 --- /dev/null +++ b/dom/tests/mochitest/beacon/test_beaconRedirect.html @@ -0,0 +1,57 @@ + + + + Bug 1280692 - sendBeacon() should follow 30x redirect + + + + + +

+ + + + + + diff --git a/dom/tests/mochitest/beacon/test_beaconWithSafelistedContentType.html b/dom/tests/mochitest/beacon/test_beaconWithSafelistedContentType.html new file mode 100644 index 0000000000..d2348d7892 --- /dev/null +++ b/dom/tests/mochitest/beacon/test_beaconWithSafelistedContentType.html @@ -0,0 +1,102 @@ + + + + + Test for Bug 1557386 + + + + +Mozilla Bug 1557386 +

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