summaryrefslogtreecommitdiffstats
path: root/netwerk/test/mochitests/test_accept_header.sjs
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2019-03-07 14:32:42 +0100
committerwolfbeast <mcwerewolf@wolfbeast.com>2019-03-07 14:32:42 +0100
commit367d77ee9a6df15cacaf1a1f4032f834e972b335 (patch)
tree199b2463784bb7910d8bbe69984c7894a8378049 /netwerk/test/mochitests/test_accept_header.sjs
parentb00b0763776f9ae47b1843d025ecb50c4b997bca (diff)
downloadUXP-367d77ee9a6df15cacaf1a1f4032f834e972b335.tar
UXP-367d77ee9a6df15cacaf1a1f4032f834e972b335.tar.gz
UXP-367d77ee9a6df15cacaf1a1f4032f834e972b335.tar.lz
UXP-367d77ee9a6df15cacaf1a1f4032f834e972b335.tar.xz
UXP-367d77ee9a6df15cacaf1a1f4032f834e972b335.zip
Part 2: Add tests
Tag #993.
Diffstat (limited to 'netwerk/test/mochitests/test_accept_header.sjs')
-rw-r--r--netwerk/test/mochitests/test_accept_header.sjs48
1 files changed, 48 insertions, 0 deletions
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("<h1>Hello world!</h1>");
+
+ 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;
+ }
+}