file_slowed_document.sjs (1282B)
1 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */ 2 /* vim: set sts=2 sw=2 et tw=80 ft=javascript: */ 3 "use strict"; 4 5 // This script slows the load of an HTML document so that we can reliably test 6 // all phases of the load cycle supported by the extension API. 7 8 /* eslint-disable no-unused-vars */ 9 10 const URL = "file_slowed_document.sjs"; 11 12 const DELAY = 2 * 1000; // Delay one second before completing the request. 13 14 const nsTimer = Components.Constructor( 15 "@mozilla.org/timer;1", 16 "nsITimer", 17 "initWithCallback" 18 ); 19 20 let timer; 21 22 function handleRequest(request, response) { 23 response.processAsync(); 24 25 response.setHeader("Content-Type", "text/html", false); 26 response.setHeader("Cache-Control", "no-cache", false); 27 response.write(`<!DOCTYPE html> 28 <html lang="en"> 29 <head> 30 <meta charset="UTF-8"> 31 <title></title> 32 </head> 33 <body> 34 `); 35 36 // Note: We need to store a reference to the timer to prevent it from being 37 // canceled when it's GCed. 38 timer = new nsTimer( 39 () => { 40 if (request.queryString.includes("with-iframe")) { 41 response.write(`<iframe src="${URL}?r=${Math.random()}"></iframe>`); 42 } 43 response.write(`</body></html>`); 44 response.finish(); 45 }, 46 DELAY, 47 Ci.nsITimer.TYPE_ONE_SHOT 48 ); 49 }