From 367d77ee9a6df15cacaf1a1f4032f834e972b335 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Thu, 7 Mar 2019 14:32:42 +0100 Subject: Part 2: Add tests Tag #993. --- netwerk/test/mochitests/mochitest.ini | 2 + netwerk/test/mochitests/test_accept_header.html | 106 ++++++++++++++++++++++++ netwerk/test/mochitests/test_accept_header.sjs | 48 +++++++++++ 3 files changed, 156 insertions(+) create mode 100644 netwerk/test/mochitests/test_accept_header.html create mode 100644 netwerk/test/mochitests/test_accept_header.sjs (limited to 'netwerk/test') diff --git a/netwerk/test/mochitests/mochitest.ini b/netwerk/test/mochitests/mochitest.ini index f8a919031..3cd5a674b 100644 --- a/netwerk/test/mochitests/mochitest.ini +++ b/netwerk/test/mochitests/mochitest.ini @@ -25,3 +25,5 @@ support-files = [test_viewsource_unlinkable.html] [test_xhr_method_case.html] [test_1396395.html] +[test_accept_header.html] +support-files = test_accept_header.sjs diff --git a/netwerk/test/mochitests/test_accept_header.html b/netwerk/test/mochitests/test_accept_header.html new file mode 100644 index 000000000..b8434230f --- /dev/null +++ b/netwerk/test/mochitests/test_accept_header.html @@ -0,0 +1,106 @@ + + + + Accept header + + + + + + + diff --git a/netwerk/test/mochitests/test_accept_header.sjs b/netwerk/test/mochitests/test_accept_header.sjs new file mode 100644 index 000000000..035c886aa --- /dev/null +++ b/netwerk/test/mochitests/test_accept_header.sjs @@ -0,0 +1,48 @@ +function handleRequest(request, response) { + response.setStatusLine(request.httpVersion, "200", "OK"); + + if (request.queryString == "worker") { + response.setHeader("Content-Type", "application/json", false); + response.write("postMessage(42)"); + + setState("data", JSON.stringify({type: "worker", accept: request.getHeader("Accept") })); + return; + } + + if (request.queryString == "image") { + // A 1x1 PNG image. + // Source: https://commons.wikimedia.org/wiki/File:1x1.png (Public Domain) + const IMAGE = atob("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAA" + + "ACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII="); + + response.setHeader("Content-Type", "image/png", false); + response.write(IMAGE); + + setState("data", JSON.stringify({type: "image", accept: request.getHeader("Accept") })); + return; + } + + if (request.queryString == "style") { + response.setHeader("Content-Type", "text/css", false); + response.write(""); + + setState("data", JSON.stringify({type: "style", accept: request.getHeader("Accept") })); + return; + } + + if (request.queryString == "iframe") { + response.setHeader("Content-Type", "text/html", false); + response.write("

Hello world!

"); + + setState("data", JSON.stringify({type: "iframe", accept: request.getHeader("Accept") })); + return; + } + + if (request.queryString == "get") { + response.setHeader("Content-Type", "text/javascript", false); + response.write(getState("data")); + + setState("data", ""); + return; + } +} -- cgit v1.2.3