Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 6039273

Browse files
committed
Bug 1837183 - Load httpd.js as a module for mochitest's server.js. r=ahal,necko-reviewers,valentin
Differential Revision: https://phabricator.services.mozilla.com/D181157
1 parent 9a8498a commit 6039273

File tree

5 files changed

+66
-35
lines changed

5 files changed

+66
-35
lines changed

layout/tools/reftest/remotereftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ def start(self):
103103
args = [
104104
"-g",
105105
self.xrePath,
106-
"-f",
107-
os.path.join(self.httpdPath, "httpd.js"),
108106
"-e",
109107
"const _PROFILE_PATH = '%(profile)s';const _SERVER_PORT = "
110-
"'%(port)s'; const _SERVER_ADDR ='%(server)s';"
108+
"'%(port)s'; const _SERVER_ADDR ='%(server)s'; "
109+
"const _HTTPD_PATH = '%(httpdPath)s';"
111110
% {
111+
"httpdPath": self.httpdPath.replace("\\", "\\\\"),
112112
"profile": self.profileDir.replace("\\", "\\\\"),
113113
"port": self.httpPort,
114114
"server": self.webServer,

netwerk/test/httpserver/httpd.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var EXPORTED_SYMBOLS = [
4242
"nsHttpHeaders",
4343
"overrideBinaryStreamsForTests",
4444
"WriteThroughCopier",
45+
"setDebuggingStatus",
4546
];
4647

4748
const CC = Components.Constructor;
@@ -54,6 +55,19 @@ var DEBUG = false; // non-const *only* so tweakable in server tests
5455
/** True if debugging output should be timestamped. */
5556
var DEBUG_TIMESTAMP = false; // non-const so tweakable in server tests
5657

58+
/**
59+
* Sets the debugging status, intended for tweaking in server tests.
60+
*
61+
* @param {boolean} debug
62+
* Enables debugging output
63+
* @param {boolean} debugTimestamp
64+
* Enables timestamping of the debugging output.
65+
*/
66+
function setDebuggingStatus(debug, debugTimestamp) {
67+
DEBUG = debug;
68+
DEBUG_TIMESTAMP = debugTimestamp;
69+
}
70+
5771
const { AppConstants } = ChromeUtils.importESModule(
5872
"resource://gre/modules/AppConstants.sys.mjs"
5973
);

testing/mochitest/runtests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,13 +546,13 @@ def start(self):
546546
args = [
547547
"-g",
548548
self._xrePath,
549-
"-f",
550-
os.path.join(self._httpdPath, "httpd.js"),
551549
"-e",
552550
"const _PROFILE_PATH = '%(profile)s'; const _SERVER_PORT = '%(port)s'; "
553551
"const _SERVER_ADDR = '%(server)s'; const _TEST_PREFIX = %(testPrefix)s; "
554-
"const _DISPLAY_RESULTS = %(displayResults)s;"
552+
"const _DISPLAY_RESULTS = %(displayResults)s; "
553+
"const _HTTPD_PATH = '%(httpdPath)s';"
555554
% {
555+
"httpdPath": self._httpdPath.replace("\\", "\\\\"),
556556
"profile": self._profileDir.replace("\\", "\\\\"),
557557
"port": self.httpPort,
558558
"server": self.webServer,

testing/mochitest/server.js

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,50 @@
66

77
// We expect these to be defined in the global scope by runtest.py.
88
/* global __LOCATION__, _PROFILE_PATH, _SERVER_PORT, _SERVER_ADDR, _DISPLAY_RESULTS,
9-
_TEST_PREFIX */
9+
_TEST_PREFIX, _HTTPD_PATH */
1010
// Defined by xpcshell
1111
/* global quit */
1212

13-
/* import-globals-from ../../netwerk/test/httpserver/httpd.js */
1413
/* eslint-disable mozilla/use-chromeutils-generateqi */
1514

1615
// Set up a protocol substituion so that we can load the httpd.js file.
1716
let protocolHandler = Services.io
1817
.getProtocolHandler("resource")
1918
.QueryInterface(Ci.nsIResProtocolHandler);
20-
let httpdJSPath = __LOCATION__.parent;
21-
let modulesURI = Services.io.newFileURI(httpdJSPath);
22-
protocolHandler.setSubstitution("mochitest-server", modulesURI);
19+
let httpdJSPath = PathUtils.toFileURI(_HTTPD_PATH);
20+
protocolHandler.setSubstitution(
21+
"httpd-server",
22+
Services.io.newURI(httpdJSPath)
23+
);
24+
25+
const { HttpServer, dumpn, setDebuggingStatus } = ChromeUtils.import(
26+
"resource://httpd-server/httpd.js"
27+
);
28+
29+
protocolHandler.setSubstitution(
30+
"mochitest-server",
31+
Services.io.newFileURI(__LOCATION__.parent)
32+
);
2333

2434
/* import-globals-from mochitestListingsUtils.js */
2535
Services.scriptloader.loadSubScript(
2636
"resource://mochitest-server/mochitestListingsUtils.js",
2737
this
2838
);
2939

40+
const CC = Components.Constructor;
41+
42+
const FileInputStream = CC(
43+
"@mozilla.org/network/file-input-stream;1",
44+
"nsIFileInputStream",
45+
"init"
46+
);
47+
const ConverterInputStream = CC(
48+
"@mozilla.org/intl/converter-input-stream;1",
49+
"nsIConverterInputStream",
50+
"init"
51+
);
52+
3053
// Disable automatic network detection, so tests work correctly when
3154
// not connected to a network.
3255
// eslint-disable-next-line mozilla/use-services
@@ -43,24 +66,21 @@ function serverStopped() {
4366
_quitting = true;
4467
}
4568

46-
// only run the "main" section if httpd.js was loaded ahead of us
47-
if (this.nsHttpServer) {
48-
//
49-
// SCRIPT CODE
50-
//
51-
runServer();
52-
53-
// We can only have gotten here if the /server/shutdown path was requested.
54-
if (_quitting) {
55-
dumpn("HTTP server stopped, all pending requests complete");
56-
quit(0);
57-
}
69+
//
70+
// SCRIPT CODE
71+
//
72+
runServer();
5873

59-
// Impossible as the stop callback should have been called, but to be safe...
60-
dumpn("TEST-UNEXPECTED-FAIL | failure to correctly shut down HTTP server");
61-
quit(1);
74+
// We can only have gotten here if the /server/shutdown path was requested.
75+
if (_quitting) {
76+
dumpn("HTTP server stopped, all pending requests complete");
77+
quit(0);
6278
}
6379

80+
// Impossible as the stop callback should have been called, but to be safe...
81+
dumpn("TEST-UNEXPECTED-FAIL | failure to correctly shut down HTTP server");
82+
quit(1);
83+
6484
var serverBasePath;
6585
var displayResults = true;
6686

@@ -170,7 +190,7 @@ function runServer() {
170190

171191
/** Creates and returns an HTTP server configured to serve Mochitests. */
172192
function createMochitestServer(serverBasePath) {
173-
var server = new nsHttpServer();
193+
var server = new HttpServer();
174194

175195
server.registerDirectory("/", serverBasePath);
176196
server.registerPathHandler("/server/shutdown", serverShutdown);
@@ -308,16 +328,13 @@ function serverDebug(metadata, response) {
308328
if (metadata.queryString === "0") {
309329
// do this now so it gets logged with the old mode
310330
dumpn("Server debug logs disabled.");
311-
DEBUG = false;
312-
DEBUG_TIMESTAMP = false;
331+
setDebuggingStatus(false, false);
313332
mode = "disabled";
314333
} else if (metadata.queryString === "1") {
315-
DEBUG = true;
316-
DEBUG_TIMESTAMP = false;
334+
setDebuggingStatus(true, false);
317335
mode = "enabled";
318336
} else if (metadata.queryString === "2") {
319-
DEBUG = true;
320-
DEBUG_TIMESTAMP = true;
337+
setDebuggingStatus(true, true);
321338
mode = "enabled, with timestamps";
322339
} else {
323340
return;

testing/xpcshell/remotexpcshelltests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,8 @@ def setupUtilities(self):
638638
file=sys.stderr,
639639
)
640640

641-
local = os.path.join(self.localBin, "components/httpd.js")
642-
remoteFile = posixpath.join(self.remoteComponentsDir, "httpd.js")
641+
local = os.path.join(self.localBin, "components/httpd.sys.mjs")
642+
remoteFile = posixpath.join(self.remoteComponentsDir, "httpd.sys.mjs")
643643
self.device.push(local, remoteFile)
644644
self.device.chmod(remoteFile)
645645

0 commit comments

Comments
 (0)