1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/thumbnails/test/thumbnails_background.sjs Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,60 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// The timer never fires if it's not declared and set to this variable outside 1.8 +// handleRequest, as if it's getting GC'ed when handleRequest's scope goes away. 1.9 +// Shouldn't the timer thread hold a strong reference to it? 1.10 +var timer; 1.11 + 1.12 +function handleRequest(req, resp) { 1.13 + resp.processAsync(); 1.14 + resp.setHeader("Cache-Control", "no-cache, no-store", false); 1.15 + resp.setHeader("Content-Type", "text/html;charset=utf-8", false); 1.16 + 1.17 + let opts = {}; 1.18 + try { 1.19 + opts = JSON.parse(decodeURIComponent(req.queryString)); 1.20 + } 1.21 + catch (err) {} 1.22 + 1.23 + if (opts.setRedCookie) 1.24 + resp.setHeader("Set-Cookie", "red", false); 1.25 + 1.26 + if (opts.setGreenCookie) 1.27 + resp.setHeader("Set-Cookie", "green", false); 1.28 + 1.29 + if (req.hasHeader("Cookie") && 1.30 + req.getHeader("Cookie").split(";").indexOf("red") >= 0) { 1.31 + resp.write('<html style="background: #f00;"></html>'); 1.32 + resp.finish(); 1.33 + return; 1.34 + } 1.35 + 1.36 + if (req.hasHeader("Cookie") && 1.37 + req.getHeader("Cookie").split(";").indexOf("green") >= 0) { 1.38 + resp.write('<html style="background: #0f0;"></html>'); 1.39 + resp.finish(); 1.40 + return; 1.41 + } 1.42 + 1.43 + if (opts.redirect) { 1.44 + resp.setHeader("Location", opts.redirect); 1.45 + resp.setStatusLine(null, 303, null); 1.46 + resp.finish(); 1.47 + return; 1.48 + } 1.49 + 1.50 + if (opts.wait) { 1.51 + resp.write("Waiting " + opts.wait + " ms... "); 1.52 + timer = Components.classes["@mozilla.org/timer;1"]. 1.53 + createInstance(Components.interfaces.nsITimer); 1.54 + timer.init(function ding() { 1.55 + resp.write("OK!"); 1.56 + resp.finish(); 1.57 + }, opts.wait, Components.interfaces.nsITimer.TYPE_ONE_SHOT); 1.58 + return; 1.59 + } 1.60 + 1.61 + resp.write("<pre>" + JSON.stringify(opts, undefined, 2) + "</pre>"); 1.62 + resp.finish(); 1.63 +}