Source code

Revision control

Other Tools

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
let nsTimer = Components.Constructor("@mozilla.org/timer;1", "nsITimer", "initWithCallback");
15
16
let timer;
17
18
function handleRequest(request, response) {
19
response.processAsync();
20
21
response.setHeader("Content-Type", "text/html", false);
22
response.setHeader("Cache-Control", "no-cache", false);
23
response.write(`<!DOCTYPE html>
24
<html lang="en">
25
<head>
26
<meta charset="UTF-8">
27
<title></title>
28
</head>
29
<body>
30
`);
31
32
// Note: We need to store a reference to the timer to prevent it from being
33
// canceled when it's GCed.
34
timer = new nsTimer(() => {
35
if (request.queryString.includes("with-iframe")) {
36
response.write(`<iframe src="${URL}?r=${Math.random()}"></iframe>`);
37
}
38
response.write(`</body></html>`);
39
response.finish();
40
}, DELAY, Ci.nsITimer.TYPE_ONE_SHOT);
41
}