Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / devtools / server / tests / chrome / inspector-delay-image-response.sjs
blob633d7e3aa694250d9fc8a44da7f95ec3ee8bbed9
1 /**
2  * Adapted from https://searchfox.org/mozilla-central/source/layout/reftests/backgrounds/delay-image-response.sjs
3  */
4 "use strict";
6 // A 1x1 PNG image.
7 // Source: https://commons.wikimedia.org/wiki/File:1x1.png (Public Domain)
8 const IMAGE = atob(
9   "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAA" +
10     "ACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII="
13 // To avoid GC.
14 let timer = null;
16 function handleRequest(request, response) {
17   const query = {};
18   request.queryString.split("&").forEach(function (val) {
19     const [name, value] = val.split("=");
20     query[name] = unescape(value);
21   });
23   response.setStatusLine(request.httpVersion, 200, "OK");
24   response.setHeader("Content-Type", "image/png", false);
26   // If there is no delay, we write the image and leave.
27   if (!("delay" in query)) {
28     response.write(IMAGE);
29     return;
30   }
32   // If there is a delay, we create a timer which, when it fires, will write
33   // image and leave.
34   response.processAsync();
35   const nsITimer = Ci.nsITimer;
37   timer = Cc["@mozilla.org/timer;1"].createInstance(nsITimer);
38   timer.initWithCallback(
39     function () {
40       response.write(IMAGE);
41       response.finish();
42     },
43     query.delay,
44     nsITimer.TYPE_ONE_SHOT
45   );