diff options
author | Matt A. Tobin <email@mattatobin.com> | 2020-02-25 15:07:00 -0500 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2020-04-14 12:55:19 +0200 |
commit | eb70e6e3d0bff11c25f14b1196025791bf2308fb (patch) | |
tree | 5ef4ce17db83c74d7b05ec12c8f59e095a6dd5bd /toolkit/components/alerts/test/image_server.sjs | |
parent | 32ead795290b3399d56b4708fc75b77d296f6a1a (diff) | |
download | UXP-eb70e6e3d0bff11c25f14b1196025791bf2308fb.tar UXP-eb70e6e3d0bff11c25f14b1196025791bf2308fb.tar.gz UXP-eb70e6e3d0bff11c25f14b1196025791bf2308fb.tar.lz UXP-eb70e6e3d0bff11c25f14b1196025791bf2308fb.tar.xz UXP-eb70e6e3d0bff11c25f14b1196025791bf2308fb.zip |
Issue #439 - Remove tests from toolkit/
Diffstat (limited to 'toolkit/components/alerts/test/image_server.sjs')
-rw-r--r-- | toolkit/components/alerts/test/image_server.sjs | 82 |
1 files changed, 0 insertions, 82 deletions
diff --git a/toolkit/components/alerts/test/image_server.sjs b/toolkit/components/alerts/test/image_server.sjs deleted file mode 100644 index 622052943..000000000 --- a/toolkit/components/alerts/test/image_server.sjs +++ /dev/null @@ -1,82 +0,0 @@ -const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr, Constructor: CC } = Components; - -Cu.import("resource://gre/modules/Timer.jsm"); - -const LocalFile = CC("@mozilla.org/file/local;1", "nsILocalFile", - "initWithPath"); - -const FileInputStream = CC("@mozilla.org/network/file-input-stream;1", - "nsIFileInputStream", "init"); - -const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1", - "nsIBinaryInputStream", "setInputStream"); - -function handleRequest(request, response) { - let params = parseQueryString(request.queryString); - - response.setStatusLine(request.httpVersion, 200, "OK"); - - // Compare and increment a cookie for this request. This is used to test - // private browsing mode; the cookie should not be set if the image is - // loaded anonymously. - if (params.has("c")) { - let expectedValue = parseInt(params.get("c"), 10); - let actualValue = !request.hasHeader("Cookie") ? 0 : - parseInt(request.getHeader("Cookie") - .replace(/^counter=(\d+)/, "$1"), 10); - if (actualValue != expectedValue) { - response.setStatusLine(request.httpVersion, 400, "Wrong counter value"); - return; - } - response.setHeader("Set-Cookie", `counter=${expectedValue + 1}`, false); - } - - // Wait to send the image if a timeout is given. - let timeout = parseInt(params.get("t"), 10); - if (timeout > 0) { - response.processAsync(); - setTimeout(() => { - respond(params, request, response); - response.finish(); - }, timeout * 1000); - return; - } - - respond(params, request, response); -} - -function parseQueryString(queryString) { - return queryString.split("&").reduce((params, param) => { - let [key, value] = param.split("=", 2); - params.set(key, value); - return params; - }, new Map()); -} - -function respond(params, request, response) { - if (params.has("s")) { - let statusCode = parseInt(params.get("s"), 10); - response.setStatusLine(request.httpVersion, statusCode, "Custom status"); - return; - } - var filename = params.get("f"); - writeFile(filename, response); -} - -function writeFile(name, response) { - var file = new LocalFile(getState("__LOCATION__")).parent; - file.append(name); - - let mimeType = Cc["@mozilla.org/uriloader/external-helper-app-service;1"] - .getService(Ci.nsIMIMEService) - .getTypeFromFile(file); - - let fileStream = new FileInputStream(file, 1, 0, false); - let binaryStream = new BinaryInputStream(fileStream); - - response.setHeader("Content-Type", mimeType, false); - response.bodyOutputStream.writeFrom(binaryStream, binaryStream.available()); - - binaryStream.close(); - fileStream.close(); -} |