Bug 1504323 - P2 Enable ESLint for netwerk/test/httpserver/ (manual changes) r=Standard8,dragana

Differential Revision: https://phabricator.services.mozilla.com/D10986

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Junior Hsu 2018-11-09 11:28:32 +00:00
parent 964925b6fe
commit 1dbcaab155
14 changed files with 113 additions and 132 deletions

View file

@ -30,7 +30,6 @@ memory/replace/dmd/test/**
modules/** modules/**
netwerk/cookie/test/browser/** netwerk/cookie/test/browser/**
netwerk/test/browser/** netwerk/test/browser/**
netwerk/test/httpserver/**
netwerk/test/mochitests/** netwerk/test/mochitests/**
netwerk/test/unit*/** netwerk/test/unit*/**
parser/** parser/**

View file

@ -50,6 +50,8 @@ var DEBUG_TIMESTAMP = false; // non-const so tweakable in server tests
var gGlobalObject = Cu.getGlobalForObject(this); var gGlobalObject = Cu.getGlobalForObject(this);
ChromeUtils.import("resource://gre/modules/Services.jsm");
/** /**
* Asserts that the given condition holds. If it doesn't, the given message is * Asserts that the given condition holds. If it doesn't, the given message is
* dumped, a stack trace is printed, and an exception is thrown to attempt to * dumped, a stack trace is printed, and an exception is thrown to attempt to
@ -185,16 +187,6 @@ function dumpStack() {
/** The XPCOM thread manager. */ /** The XPCOM thread manager. */
var gThreadManager = null; var gThreadManager = null;
/** The XPCOM prefs service. */
var gRootPrefBranch = null;
function getRootPrefBranch() {
if (!gRootPrefBranch) {
gRootPrefBranch = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefBranch);
}
return gRootPrefBranch;
}
/** /**
* JavaScript constructors for commonly-used classes; precreating these is a * JavaScript constructors for commonly-used classes; precreating these is a
* speedup over doing the same from base principles. See the docs at * speedup over doing the same from base principles. See the docs at
@ -487,15 +479,14 @@ nsHttpServer.prototype =
// network.http.max-persistent-connections-per-proxy concurrent // network.http.max-persistent-connections-per-proxy concurrent
// connections, plus a safety margin in case some other process is // connections, plus a safety margin in case some other process is
// talking to the server as well. // talking to the server as well.
var prefs = getRootPrefBranch();
var maxConnections = 5 + Math.max( var maxConnections = 5 + Math.max(
prefs.getIntPref("network.http.max-persistent-connections-per-server"), Services.prefs.getIntPref("network.http.max-persistent-connections-per-server"),
prefs.getIntPref("network.http.max-persistent-connections-per-proxy")); Services.prefs.getIntPref("network.http.max-persistent-connections-per-proxy"));
try { try {
var loopback = true; var loopback = true;
if (this._host != "127.0.0.1" && this._host != "localhost") { if (this._host != "127.0.0.1" && this._host != "localhost") {
var loopback = false; loopback = false;
} }
// When automatically selecting a port, sometimes the chosen port is // When automatically selecting a port, sometimes the chosen port is
@ -503,15 +494,13 @@ nsHttpServer.prototype =
// tests will intermittently fail. So, we simply keep trying to to // tests will intermittently fail. So, we simply keep trying to to
// get a server socket until a valid port is obtained. We limit // get a server socket until a valid port is obtained. We limit
// ourselves to finite attempts just so we don't loop forever. // ourselves to finite attempts just so we don't loop forever.
var ios = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
var socket; var socket;
for (var i = 100; i; i--) { for (var i = 100; i; i--) {
var temp = new ServerSocket(this._port, var temp = new ServerSocket(this._port,
loopback, // true = localhost, false = everybody loopback, // true = localhost, false = everybody
maxConnections); maxConnections);
var allowed = ios.allowPort(temp.port, "http"); var allowed = Services.io.allowPort(temp.port, "http");
if (!allowed) { if (!allowed) {
dumpn(">>>Warning: obtained ServerSocket listens on a blocked " + dumpn(">>>Warning: obtained ServerSocket listens on a blocked " +
"port: " + temp.port); "port: " + temp.port);
@ -1601,9 +1590,7 @@ RequestReader.prototype =
} }
try { try {
var uri = Cc["@mozilla.org/network/io-service;1"] var uri = Services.io.newURI(fullPath);
.getService(Ci.nsIIOService)
.newURI(fullPath);
fullPath = uri.pathQueryRef; fullPath = uri.pathQueryRef;
scheme = uri.scheme; scheme = uri.scheme;
host = metadata._host = uri.asciiHost; host = metadata._host = uri.asciiHost;
@ -1899,7 +1886,7 @@ function defaultIndexHandler(metadata, response) {
var files = directory.directoryEntries; var files = directory.directoryEntries;
while (files.hasMoreElements()) { while (files.hasMoreElements()) {
var f = files.nextFile; var f = files.nextFile;
var name = f.leafName; let name = f.leafName;
if (!f.isHidden() && if (!f.isHidden() &&
(name.charAt(name.length - 1) != HIDDEN_CHAR || (name.charAt(name.length - 1) != HIDDEN_CHAR ||
name.charAt(name.length - 2) == HIDDEN_CHAR)) name.charAt(name.length - 2) == HIDDEN_CHAR))
@ -1911,7 +1898,7 @@ function defaultIndexHandler(metadata, response) {
for (var i = 0; i < fileList.length; i++) { for (var i = 0; i < fileList.length; i++) {
var file = fileList[i]; var file = fileList[i];
try { try {
var name = file.leafName; let name = file.leafName;
if (name.charAt(name.length - 1) == HIDDEN_CHAR) if (name.charAt(name.length - 1) == HIDDEN_CHAR)
name = name.substring(0, name.length - 1); name = name.substring(0, name.length - 1);
var sep = file.isDirectory() ? "/" : ""; var sep = file.isDirectory() ? "/" : "";
@ -2477,11 +2464,10 @@ ServerHandler.prototype =
var type = this._getTypeFromFile(file); var type = this._getTypeFromFile(file);
if (type === SJS_TYPE) { if (type === SJS_TYPE) {
var fis = new FileInputStream(file, PR_RDONLY, PERMS_READONLY, let fis = new FileInputStream(file, PR_RDONLY, PERMS_READONLY,
Ci.nsIFileInputStream.CLOSE_ON_EOF); Ci.nsIFileInputStream.CLOSE_ON_EOF);
try { try {
var sis = new ScriptableInputStream(fis);
var s = Cu.Sandbox(gGlobalObject); var s = Cu.Sandbox(gGlobalObject);
s.importFunction(dump, "dump"); s.importFunction(dump, "dump");
s.importFunction(atob, "atob"); s.importFunction(atob, "atob");
@ -2523,12 +2509,8 @@ ServerHandler.prototype =
// getting the line number where we evaluate the SJS file. Don't // getting the line number where we evaluate the SJS file. Don't
// separate these two lines! // separate these two lines!
var line = new Error().lineNumber; var line = new Error().lineNumber;
let uri = Cc["@mozilla.org/network/io-service;1"] let uri = Services.io.newFileURI(file);
.getService(Ci.nsIIOService) Services.scriptloader.loadSubScript(uri.spec, s);
.newFileURI(file);
let scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Ci.mozIJSSubScriptLoader);
scriptLoader.loadSubScript(uri.spec, s);
} catch (e) { } catch (e) {
dumpn("*** syntax error in SJS at " + file.path + ": " + e); dumpn("*** syntax error in SJS at " + file.path + ": " + e);
throw HTTP_500; throw HTTP_500;
@ -2558,7 +2540,7 @@ ServerHandler.prototype =
maybeAddHeaders(file, metadata, response); maybeAddHeaders(file, metadata, response);
response.setHeader("Content-Length", "" + count, false); response.setHeader("Content-Length", "" + count, false);
var fis = new FileInputStream(file, PR_RDONLY, PERMS_READONLY, let fis = new FileInputStream(file, PR_RDONLY, PERMS_READONLY,
Ci.nsIFileInputStream.CLOSE_ON_EOF); Ci.nsIFileInputStream.CLOSE_ON_EOF);
offset = offset || 0; offset = offset || 0;
@ -3726,7 +3708,7 @@ Response.prototype =
QueryInterface: ChromeUtils.generateQI(["nsIRequestObserver"]), QueryInterface: ChromeUtils.generateQI(["nsIRequestObserver"]),
}; };
var headerCopier = this._asyncCopier = this._asyncCopier =
new WriteThroughCopier(responseHeadPipe.inputStream, new WriteThroughCopier(responseHeadPipe.inputStream,
this._connection.output, this._connection.output,
copyObserver, null); copyObserver, null);
@ -3943,15 +3925,16 @@ WriteThroughCopier.prototype =
if (bytesWanted === 0) if (bytesWanted === 0)
throw Components.Exception("", Cr.NS_BASE_STREAM_CLOSED); throw Components.Exception("", Cr.NS_BASE_STREAM_CLOSED);
} catch (e) { } catch (e) {
let rv;
if (streamClosed(e)) { if (streamClosed(e)) {
dumpn("*** input stream closed"); dumpn("*** input stream closed");
e = bytesWanted === 0 ? Cr.NS_OK : Cr.NS_ERROR_UNEXPECTED; rv = bytesWanted === 0 ? Cr.NS_OK : Cr.NS_ERROR_UNEXPECTED;
} else { } else {
dumpn("!!! unexpected error reading from input, canceling: " + e); dumpn("!!! unexpected error reading from input, canceling: " + e);
e = Cr.NS_ERROR_UNEXPECTED; rv = Cr.NS_ERROR_UNEXPECTED;
} }
this._doneReadingSource(e); this._doneReadingSource(rv);
return; return;
} }
@ -4524,9 +4507,9 @@ nsHttpHeaders.prototype =
var name = headerUtils.normalizeFieldName(fieldName); var name = headerUtils.normalizeFieldName(fieldName);
var value = headerUtils.normalizeFieldValue(fieldValue); var value = headerUtils.normalizeFieldValue(fieldValue);
if (name in this._headers) { if (name in this._headers) {
this._headers[name].push(fieldValue); this._headers[name].push(value);
} else { } else {
this._headers[name] = [fieldValue]; this._headers[name] = [value];
} }
}, },

View file

@ -3,13 +3,15 @@
/* This Source Code Form is subject to the terms of the Mozilla Public /* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* global __LOCATION__ */
/* import-globals-from ../httpd.js */
var _HTTPD_JS_PATH = __LOCATION__.parent; var _HTTPD_JS_PATH = __LOCATION__.parent;
_HTTPD_JS_PATH.append("httpd.js"); _HTTPD_JS_PATH.append("httpd.js");
load(_HTTPD_JS_PATH.path); load(_HTTPD_JS_PATH.path);
// if these tests fail, we'll want the debug output // if these tests fail, we'll want the debug output
DEBUG = true; var linDEBUG = true;
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
@ -75,7 +77,7 @@ function fileContents(file) {
* includes a final empty line if data ended with a CRLF * includes a final empty line if data ended with a CRLF
*/ */
function* LineIterator(data) { function* LineIterator(data) {
var start = 0, index = 0; var index = 0;
do { do {
index = data.indexOf("\r\n"); index = data.indexOf("\r\n");
if (index >= 0) if (index >= 0)
@ -253,7 +255,7 @@ function runHttpTests(testArray, done) {
} catch (e) { } catch (e) {
try { try {
do_report_unexpected_exception(e, "testArray[" + testIndex + "].initChannel(ch)"); do_report_unexpected_exception(e, "testArray[" + testIndex + "].initChannel(ch)");
} catch (e) { } catch (x) {
/* swallow and let tests continue */ /* swallow and let tests continue */
} }
} }
@ -354,6 +356,8 @@ function RawTest(host, port, data, responseCheck) {
data = [data]; data = [data];
if (data.length <= 0) if (data.length <= 0)
throw "bad data length"; throw "bad data length";
// eslint-disable-next-line no-control-regex
if (!data.every(function(v) { return /^[\x00-\xff]*$/.test(v); })) if (!data.every(function(v) { return /^[\x00-\xff]*$/.test(v); }))
throw "bad data contained non-byte-valued character"; throw "bad data contained non-byte-valued character";

View file

@ -4,6 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* /*
* Ensures that data a request handler writes out in response is sent only as * Ensures that data a request handler writes out in response is sent only as
* quickly as the client can receive it, without racing ahead and being forced * quickly as the client can receive it, without racing ahead and being forced
@ -323,10 +324,10 @@ function sinkAndSourceClosedWithPendingData(next) {
/** Returns the sum of the elements in arr. */ /** Returns the sum of the elements in arr. */
function sum(arr) { function sum(arr) {
var sum = 0; var s = 0;
for (var i = 0, sz = arr.length; i < sz; i++) for (var i = 0, sz = arr.length; i < sz; i++)
sum += arr[i]; s += arr[i];
return sum; return s;
} }
/** /**
@ -1447,7 +1448,6 @@ CopyTest.prototype =
} }
var task = this._tasks[this._currentTask++]; var task = this._tasks[this._currentTask++];
var self = this;
var event = var event =
{ {
run: function run() { run: function run() {

View file

@ -8,6 +8,8 @@
* Basic functionality test, from the client programmer's POV. * Basic functionality test, from the client programmer's POV.
*/ */
ChromeUtils.import("resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyGetter(this, "port", function() { XPCOMUtils.defineLazyGetter(this, "port", function() {
return srv.identity.primaryPort; return srv.identity.primaryPort;
}); });
@ -32,9 +34,7 @@ function run_test() {
// base path // base path
// XXX should actually test this works with a file by comparing streams! // XXX should actually test this works with a file by comparing streams!
var dirServ = Cc["@mozilla.org/file/directory_service;1"] var path = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
.getService(Ci.nsIProperties);
var path = dirServ.get("CurWorkD", Ci.nsIFile);
srv.registerDirectory("/", path); srv.registerDirectory("/", path);
// register a few test paths // register a few test paths

View file

@ -8,7 +8,9 @@
// escaping checks -- highly dependent on the default index handler output // escaping checks -- highly dependent on the default index handler output
// format // format
var srv, dir, dirEntries; ChromeUtils.import("resource://gre/modules/Services.jsm");
var srv, dir, gDirEntries;
XPCOMUtils.defineLazyGetter(this, "BASE_URL", function() { XPCOMUtils.defineLazyGetter(this, "BASE_URL", function() {
return "http://localhost:" + srv.identity.primaryPort + "/"; return "http://localhost:" + srv.identity.primaryPort + "/";
@ -37,9 +39,7 @@ function run_test() {
} }
function createTestDirectory() { function createTestDirectory() {
dir = Cc["@mozilla.org/file/directory_service;1"] dir = Services.dirsvc.get("TmpD", Ci.nsIFile);
.getService(Ci.nsIProperties)
.get("TmpD", Ci.nsIFile);
dir.append("index_handler_test_" + Math.random()); dir.append("index_handler_test_" + Math.random());
dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0o744); dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0o744);
@ -62,7 +62,7 @@ function createTestDirectory() {
makeFile("zf%200h", false, dir, files); makeFile("zf%200h", false, dir, files);
makeFile("zg>m", false, dir, files); makeFile("zg>m", false, dir, files);
dirEntries = [files]; gDirEntries = [files];
var subdir = dir.clone(); var subdir = dir.clone();
subdir.append("foo"); subdir.append("foo");
@ -74,7 +74,7 @@ function createTestDirectory() {
makeFile("AA_file.txt", false, subdir, files); makeFile("AA_file.txt", false, subdir, files);
makeFile("test.txt", false, subdir, files); makeFile("test.txt", false, subdir, files);
dirEntries.push(files); gDirEntries.push(files);
} }
function destroyTestDirectory() { function destroyTestDirectory() {
@ -116,10 +116,7 @@ function hiddenDataCheck(bytes, uri, path) {
Assert.equal(lst.length, 1); Assert.equal(lst.length, 1);
var items = lst[0].getElementsByTagName("li"); var items = lst[0].getElementsByTagName("li");
var ios = Cc["@mozilla.org/network/io-service;1"] var top = Services.io.newURI(uri);
.getService(Ci.nsIIOService);
var top = ios.newURI(uri);
// N.B. No ERROR_IF_SEE_THIS.txt^ file! // N.B. No ERROR_IF_SEE_THIS.txt^ file!
var dirEntries = [{name: "file.txt", isDirectory: false}, var dirEntries = [{name: "file.txt", isDirectory: false},
@ -133,7 +130,7 @@ function hiddenDataCheck(bytes, uri, path) {
Assert.equal(link.textContent, f.name + sep); Assert.equal(link.textContent, f.name + sep);
uri = ios.newURI(link.getAttribute("href"), null, top); uri = Services.io.newURI(link.getAttribute("href"), null, top);
Assert.equal(decodeURIComponent(uri.pathQueryRef), path + f.name + sep); Assert.equal(decodeURIComponent(uri.pathQueryRef), path + f.name + sep);
} }
} }
@ -184,11 +181,6 @@ function dataCheck(bytes, uri, path, dirEntries) {
Assert.equal(lst.length, 1); Assert.equal(lst.length, 1);
var items = lst[0].getElementsByTagName("li"); var items = lst[0].getElementsByTagName("li");
var ios = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
var dirURI = ios.newURI(uri);
for (var i = 0; i < items.length; i++) { for (var i = 0; i < items.length; i++) {
var link = items[i].childNodes[0]; var link = items[i].childNodes[0];
var f = dirEntries[i]; var f = dirEntries[i];
@ -197,7 +189,7 @@ function dataCheck(bytes, uri, path, dirEntries) {
Assert.equal(link.textContent, f.name + sep); Assert.equal(link.textContent, f.name + sep);
uri = ios.newURI(link.getAttribute("href"), null, top); uri = Services.io.newURI(link.getAttribute("href"), null, top);
Assert.equal(decodeURIComponent(uri.pathQueryRef), path + f.name + sep); Assert.equal(decodeURIComponent(uri.pathQueryRef), path + f.name + sep);
} }
} }
@ -235,12 +227,12 @@ function start(ch) {
Assert.equal(ch.getResponseHeader("Content-Type"), "text/html;charset=utf-8"); Assert.equal(ch.getResponseHeader("Content-Type"), "text/html;charset=utf-8");
} }
function stopRootDirectory(ch, cx, status, data) { function stopRootDirectory(ch, cx, status, data) {
dataCheck(data, BASE_URL, "/", dirEntries[0]); dataCheck(data, BASE_URL, "/", gDirEntries[0]);
} }
// check non-top-level, too // check non-top-level, too
function stopFooDirectory(ch, cx, status, data) { function stopFooDirectory(ch, cx, status, data) {
dataCheck(data, BASE_URL + "foo/", "/foo/", dirEntries[1]); dataCheck(data, BASE_URL + "foo/", "/foo/", gDirEntries[1]);
} }
// trailing-caret leaf with hidden files // trailing-caret leaf with hidden files

View file

@ -72,5 +72,5 @@ function register400Handler(ch) {
// /throws/exception (and also a 404 and 400 error handler) // /throws/exception (and also a 404 and 400 error handler)
function throwsException(metadata, response) { function throwsException(metadata, response) {
throw "this shouldn't cause an exit..."; throw "this shouldn't cause an exit...";
do_throw("Not reached!"); do_throw("Not reached!"); // eslint-disable-line no-unreachable
} }

View file

@ -100,7 +100,7 @@ function testGetHeader() {
Assert.equal(c, "text/html"); Assert.equal(c, "text/html");
headers.setHeader("test", "FOO", false); headers.setHeader("test", "FOO", false);
var c = headers.getHeader("test"); c = headers.getHeader("test");
Assert.equal(c, "FOO"); Assert.equal(c, "FOO");
try { try {
@ -140,9 +140,9 @@ function testHeaderEnumerator() {
delete heads[it.toLowerCase()]; delete heads[it.toLowerCase()];
} }
for (var i in heads) if (Object.keys(heads).length != 0) {
do_throw("still have properties in heads!?!?"); do_throw("still have properties in heads!?!?");
}
} }
function testHasHeader() { function testHasHeader() {

View file

@ -209,13 +209,13 @@ function run_test_3() {
* Verifies that all .primary* getters on a server identity correctly throw * Verifies that all .primary* getters on a server identity correctly throw
* NS_ERROR_NOT_INITIALIZED. * NS_ERROR_NOT_INITIALIZED.
* *
* @param id : nsIHttpServerIdentity * @param aId : nsIHttpServerIdentity
* the server identity to test * the server identity to test
*/ */
function checkPrimariesThrow(id) { function checkPrimariesThrow(aId) {
var threw = false; var threw = false;
try { try {
id.primaryScheme; aId.primaryScheme;
} catch (e) { } catch (e) {
threw = e.result === Cr.NS_ERROR_NOT_INITIALIZED; threw = e.result === Cr.NS_ERROR_NOT_INITIALIZED;
} }
@ -223,7 +223,7 @@ function checkPrimariesThrow(id) {
threw = false; threw = false;
try { try {
id.primaryHost; aId.primaryHost;
} catch (e) { } catch (e) {
threw = e.result === Cr.NS_ERROR_NOT_INITIALIZED; threw = e.result === Cr.NS_ERROR_NOT_INITIALIZED;
} }
@ -231,7 +231,7 @@ function checkPrimariesThrow(id) {
threw = false; threw = false;
try { try {
id.primaryPort; aId.primaryPort;
} catch (e) { } catch (e) {
threw = e.result === Cr.NS_ERROR_NOT_INITIALIZED; threw = e.result === Cr.NS_ERROR_NOT_INITIALIZED;
} }
@ -241,8 +241,8 @@ function checkPrimariesThrow(id) {
/** /**
* Utility function to check for a 400 response. * Utility function to check for a 400 response.
*/ */
function check400(data) { function check400(aData) {
var iter = LineIterator(data); var iter = LineIterator(aData);
// Status-Line // Status-Line
var { value: firstLine } = iter.next(); var { value: firstLine } = iter.next();
@ -268,8 +268,8 @@ function http10Request(request, response) {
} }
data = "GET /http/1.0-request HTTP/1.0\r\n" + data = "GET /http/1.0-request HTTP/1.0\r\n" +
"\r\n"; "\r\n";
function check10(data) { function check10(aData) {
var iter = LineIterator(data); var iter = LineIterator(aData);
// Status-Line // Status-Line
Assert.equal(iter.next().value, "HTTP/1.0 200 TEST PASSED"); Assert.equal(iter.next().value, "HTTP/1.0 200 TEST PASSED");
@ -290,7 +290,7 @@ function check10(data) {
expectLines(iter, body); expectLines(iter, body);
} }
test = new RawTest("localhost", PORT, data, check10), test = new RawTest("localhost", PORT, data, check10);
tests.push(test); tests.push(test);
@ -298,7 +298,7 @@ tests.push(test);
data = "GET /http/1.1-request HTTP/1.1\r\n" + data = "GET /http/1.1-request HTTP/1.1\r\n" +
"\r\n"; "\r\n";
test = new RawTest("localhost", PORT, data, check400), test = new RawTest("localhost", PORT, data, check400);
tests.push(test); tests.push(test);
@ -307,7 +307,7 @@ tests.push(test);
data = "GET /http/1.1-request HTTP/1.1\r\n" + data = "GET /http/1.1-request HTTP/1.1\r\n" +
"Host: not-localhost\r\n" + "Host: not-localhost\r\n" +
"\r\n"; "\r\n";
test = new RawTest("localhost", PORT, data, check400), test = new RawTest("localhost", PORT, data, check400);
tests.push(test); tests.push(test);
@ -316,7 +316,7 @@ tests.push(test);
data = "GET /http/1.1-request HTTP/1.1\r\n" + data = "GET /http/1.1-request HTTP/1.1\r\n" +
"Host: not-localhost:4444\r\n" + "Host: not-localhost:4444\r\n" +
"\r\n"; "\r\n";
test = new RawTest("localhost", PORT, data, check400), test = new RawTest("localhost", PORT, data, check400);
tests.push(test); tests.push(test);
@ -325,7 +325,7 @@ tests.push(test);
data = "GET /http/1.1-request HTTP/1.1\r\n" + data = "GET /http/1.1-request HTTP/1.1\r\n" +
"Host: 127.0.0.1\r\n" + "Host: 127.0.0.1\r\n" +
"\r\n"; "\r\n";
test = new RawTest("localhost", PORT, data, check400), test = new RawTest("localhost", PORT, data, check400);
tests.push(test); tests.push(test);
@ -334,7 +334,7 @@ tests.push(test);
data = "GET http://127.0.0.1/http/1.1-request HTTP/1.1\r\n" + data = "GET http://127.0.0.1/http/1.1-request HTTP/1.1\r\n" +
"Host: 127.0.0.1\r\n" + "Host: 127.0.0.1\r\n" +
"\r\n"; "\r\n";
test = new RawTest("localhost", PORT, data, check400), test = new RawTest("localhost", PORT, data, check400);
tests.push(test); tests.push(test);
@ -343,7 +343,7 @@ tests.push(test);
data = "GET http://localhost:31337/http/1.1-request HTTP/1.1\r\n" + data = "GET http://localhost:31337/http/1.1-request HTTP/1.1\r\n" +
"Host: localhost:31337\r\n" + "Host: localhost:31337\r\n" +
"\r\n"; "\r\n";
test = new RawTest("localhost", PORT, data, check400), test = new RawTest("localhost", PORT, data, check400);
tests.push(test); tests.push(test);
@ -352,7 +352,7 @@ tests.push(test);
data = "GET https://localhost:4444/http/1.1-request HTTP/1.1\r\n" + data = "GET https://localhost:4444/http/1.1-request HTTP/1.1\r\n" +
"Host: localhost:4444\r\n" + "Host: localhost:4444\r\n" +
"\r\n"; "\r\n";
test = new RawTest("localhost", PORT, data, check400), test = new RawTest("localhost", PORT, data, check400);
tests.push(test); tests.push(test);
@ -365,8 +365,8 @@ function http11goodHost(request, response) {
data = "GET /http/1.1-good-host HTTP/1.1\r\n" + data = "GET /http/1.1-good-host HTTP/1.1\r\n" +
"Host: localhost:4444\r\n" + "Host: localhost:4444\r\n" +
"\r\n"; "\r\n";
function check11goodHost(data) { function check11goodHost(aData) {
var iter = LineIterator(data); var iter = LineIterator(aData);
// Status-Line // Status-Line
Assert.equal(iter.next().value, "HTTP/1.1 200 TEST PASSED"); Assert.equal(iter.next().value, "HTTP/1.1 200 TEST PASSED");
@ -387,7 +387,7 @@ function check11goodHost(data) {
expectLines(iter, body); expectLines(iter, body);
} }
test = new RawTest("localhost", PORT, data, check11goodHost), test = new RawTest("localhost", PORT, data, check11goodHost);
tests.push(test); tests.push(test);
@ -400,8 +400,8 @@ function http11ipHost(request, response) {
data = "GET /http/1.1-ip-host HTTP/1.1\r\n" + data = "GET /http/1.1-ip-host HTTP/1.1\r\n" +
"Host: 127.0.0.1:4444\r\n" + "Host: 127.0.0.1:4444\r\n" +
"\r\n"; "\r\n";
function check11ipHost(data) { function check11ipHost(aData) {
var iter = LineIterator(data); var iter = LineIterator(aData);
// Status-Line // Status-Line
Assert.equal(iter.next().value, "HTTP/1.1 200 TEST PASSED"); Assert.equal(iter.next().value, "HTTP/1.1 200 TEST PASSED");
@ -422,7 +422,7 @@ function check11ipHost(data) {
expectLines(iter, body); expectLines(iter, body);
} }
test = new RawTest("localhost", PORT, data, check11ipHost), test = new RawTest("localhost", PORT, data, check11ipHost);
tests.push(test); tests.push(test);
@ -433,7 +433,7 @@ tests.push(test);
data = "GET http://localhost:4444/http/1.1-good-host HTTP/1.1\r\n" + data = "GET http://localhost:4444/http/1.1-good-host HTTP/1.1\r\n" +
"Host: localhost:4444\r\n" + "Host: localhost:4444\r\n" +
"\r\n"; "\r\n";
test = new RawTest("localhost", PORT, data, check11goodHost), test = new RawTest("localhost", PORT, data, check11goodHost);
tests.push(test); tests.push(test);
@ -444,7 +444,7 @@ tests.push(test);
data = "GET http://localhost:4444/http/1.1-good-host HTTP/1.1\r\n" + data = "GET http://localhost:4444/http/1.1-good-host HTTP/1.1\r\n" +
"Host: localhost:1234\r\n" + "Host: localhost:1234\r\n" +
"\r\n"; "\r\n";
test = new RawTest("localhost", PORT, data, check11goodHost), test = new RawTest("localhost", PORT, data, check11goodHost);
tests.push(test); tests.push(test);
@ -455,7 +455,7 @@ tests.push(test);
data = "GET http://localhost:4444/http/1.1-good-host HTTP/1.1\r\n" + data = "GET http://localhost:4444/http/1.1-good-host HTTP/1.1\r\n" +
"Host: not-localhost:4444\r\n" + "Host: not-localhost:4444\r\n" +
"\r\n"; "\r\n";
test = new RawTest("localhost", PORT, data, check11goodHost), test = new RawTest("localhost", PORT, data, check11goodHost);
tests.push(test); tests.push(test);
@ -466,13 +466,13 @@ tests.push(test);
data = "GET http://localhost:4444/http/1.1-good-host HTTP/1.1\r\n" + data = "GET http://localhost:4444/http/1.1-good-host HTTP/1.1\r\n" +
"Host: yippity-skippity\r\n" + "Host: yippity-skippity\r\n" +
"\r\n"; "\r\n";
function checkInaccurate(data) { function checkInaccurate(aData) {
check11goodHost(data); check11goodHost(aData);
// dynamism setup // dynamism setup
srv.identity.setPrimary("http", "127.0.0.1", 4444); srv.identity.setPrimary("http", "127.0.0.1", 4444);
} }
test = new RawTest("localhost", PORT, data, checkInaccurate), test = new RawTest("localhost", PORT, data, checkInaccurate);
tests.push(test); tests.push(test);
@ -483,8 +483,8 @@ tests.push(test);
data = "GET /http/1.0-request HTTP/1.0\r\n" + data = "GET /http/1.0-request HTTP/1.0\r\n" +
"Host: not-localhost:4444\r\n" + "Host: not-localhost:4444\r\n" +
"\r\n"; "\r\n";
function check10ip(data) { function check10ip(aData) {
var iter = LineIterator(data); var iter = LineIterator(aData);
// Status-Line // Status-Line
Assert.equal(iter.next().value, "HTTP/1.0 200 TEST PASSED"); Assert.equal(iter.next().value, "HTTP/1.0 200 TEST PASSED");
@ -505,7 +505,7 @@ function check10ip(data) {
expectLines(iter, body); expectLines(iter, body);
} }
test = new RawTest("localhost", PORT, data, check10ip), test = new RawTest("localhost", PORT, data, check10ip);
tests.push(test); tests.push(test);
@ -518,8 +518,8 @@ function http11goodHostWackyPort(request, response) {
data = "GET /http/1.1-good-host-wacky-port HTTP/1.1\r\n" + data = "GET /http/1.1-good-host-wacky-port HTTP/1.1\r\n" +
"Host: localhost\r\n" + "Host: localhost\r\n" +
"\r\n"; "\r\n";
function check11goodHostWackyPort(data) { function check11goodHostWackyPort(aData) {
var iter = LineIterator(data); var iter = LineIterator(aData);
// Status-Line // Status-Line
Assert.equal(iter.next().value, "HTTP/1.1 200 TEST PASSED"); Assert.equal(iter.next().value, "HTTP/1.1 200 TEST PASSED");
@ -540,7 +540,7 @@ function check11goodHostWackyPort(data) {
expectLines(iter, body); expectLines(iter, body);
} }
test = new RawTest("localhost", PORT, data, check11goodHostWackyPort), test = new RawTest("localhost", PORT, data, check11goodHostWackyPort);
tests.push(test); tests.push(test);
@ -549,7 +549,7 @@ tests.push(test);
data = "GET /http/1.1-good-host-wacky-port HTTP/1.1\r\n" + data = "GET /http/1.1-good-host-wacky-port HTTP/1.1\r\n" +
"Host: localhost:\r\n" + "Host: localhost:\r\n" +
"\r\n"; "\r\n";
test = new RawTest("localhost", PORT, data, check11goodHostWackyPort), test = new RawTest("localhost", PORT, data, check11goodHostWackyPort);
tests.push(test); tests.push(test);
@ -558,7 +558,7 @@ tests.push(test);
data = "GET http://localhost/http/1.1-good-host-wacky-port HTTP/1.1\r\n" + data = "GET http://localhost/http/1.1-good-host-wacky-port HTTP/1.1\r\n" +
"Host: localhost\r\n" + "Host: localhost\r\n" +
"\r\n"; "\r\n";
test = new RawTest("localhost", PORT, data, check11goodHostWackyPort), test = new RawTest("localhost", PORT, data, check11goodHostWackyPort);
tests.push(test); tests.push(test);
@ -567,7 +567,7 @@ tests.push(test);
data = "GET http://localhost:/http/1.1-good-host-wacky-port HTTP/1.1\r\n" + data = "GET http://localhost:/http/1.1-good-host-wacky-port HTTP/1.1\r\n" +
"Host: localhost\r\n" + "Host: localhost\r\n" +
"\r\n"; "\r\n";
test = new RawTest("localhost", PORT, data, check11goodHostWackyPort), test = new RawTest("localhost", PORT, data, check11goodHostWackyPort);
tests.push(test); tests.push(test);
@ -576,7 +576,7 @@ tests.push(test);
data = "GET http://localhost:80/http/1.1-good-host-wacky-port HTTP/1.1\r\n" + data = "GET http://localhost:80/http/1.1-good-host-wacky-port HTTP/1.1\r\n" +
"Host: who-cares\r\n" + "Host: who-cares\r\n" +
"\r\n"; "\r\n";
test = new RawTest("localhost", PORT, data, check11goodHostWackyPort), test = new RawTest("localhost", PORT, data, check11goodHostWackyPort);
tests.push(test); tests.push(test);
@ -585,7 +585,7 @@ tests.push(test);
data = "GET is-this-the-real-life-is-this-just-fantasy HTTP/1.1\r\n" + data = "GET is-this-the-real-life-is-this-just-fantasy HTTP/1.1\r\n" +
"Host: localhost:4444\r\n" + "Host: localhost:4444\r\n" +
"\r\n"; "\r\n";
test = new RawTest("localhost", PORT, data, check400), test = new RawTest("localhost", PORT, data, check400);
tests.push(test); tests.push(test);
@ -594,7 +594,7 @@ tests.push(test);
data = "GET /http/1.1-request HTTP/1.1\r\n" + data = "GET /http/1.1-request HTTP/1.1\r\n" +
"Host: la la la\r\n" + "Host: la la la\r\n" +
"\r\n"; "\r\n";
test = new RawTest("localhost", PORT, data, check400), test = new RawTest("localhost", PORT, data, check400);
tests.push(test); tests.push(test);
@ -603,7 +603,7 @@ tests.push(test);
data = "GET http://localhost:4444/http/1.1-good-host HTTP/1.1\r\n" + data = "GET http://localhost:4444/http/1.1-good-host HTTP/1.1\r\n" +
"Host: la la la\r\n" + "Host: la la la\r\n" +
"\r\n"; "\r\n";
test = new RawTest("localhost", PORT, data, check11goodHost), test = new RawTest("localhost", PORT, data, check11goodHost);
tests.push(test); tests.push(test);
@ -612,7 +612,7 @@ tests.push(test);
data = "GET http://localhost:4444/http/1.1-request HTTP/1.0\r\n" + data = "GET http://localhost:4444/http/1.1-request HTTP/1.0\r\n" +
"Host: localhost:4444\r\n" + "Host: localhost:4444\r\n" +
"\r\n"; "\r\n";
test = new RawTest("localhost", PORT, data, check400), test = new RawTest("localhost", PORT, data, check400);
tests.push(test); tests.push(test);
@ -621,7 +621,7 @@ tests.push(test);
data = "GET http://not-localhost:4444/http/1.1-request HTTP/1.1\r\n" + data = "GET http://not-localhost:4444/http/1.1-request HTTP/1.1\r\n" +
"Host: not-localhost:4444\r\n" + "Host: not-localhost:4444\r\n" +
"\r\n"; "\r\n";
test = new RawTest("localhost", PORT, data, check400), test = new RawTest("localhost", PORT, data, check400);
tests.push(test); tests.push(test);
@ -630,5 +630,5 @@ tests.push(test);
data = "GET http://not-localhost:4444/http/1.1-request HTTP/1.1\r\n" + data = "GET http://not-localhost:4444/http/1.1-request HTTP/1.1\r\n" +
"Host: localhost:4444\r\n" + "Host: localhost:4444\r\n" +
"\r\n"; "\r\n";
test = new RawTest("localhost", PORT, data, check400), test = new RawTest("localhost", PORT, data, check400);
tests.push(test); tests.push(test);

View file

@ -4,6 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* /*
* Tests for correct behavior of asynchronous responses. * Tests for correct behavior of asynchronous responses.
*/ */
@ -122,8 +123,8 @@ function handleAsync2(request, response) {
response.setHeader("X-Custom-Header", "value", false); response.setHeader("X-Custom-Header", "value", false);
callLater(startToHeaderDelay, function() { callLater(startToHeaderDelay, function() {
var body = "BO"; var preBody = "BO";
response.bodyOutputStream.write(body, body.length); response.bodyOutputStream.write(preBody, preBody.length);
try { try {
response.setStatusLine(request.httpVersion, 500, "after body write"); response.setStatusLine(request.httpVersion, 500, "after body write");
@ -139,8 +140,8 @@ function handleAsync2(request, response) {
} }
callLater(startToFinishedDelay - startToHeaderDelay, function() { callLater(startToFinishedDelay - startToHeaderDelay, function() {
var body = "DY"; var postBody = "DY";
response.bodyOutputStream.write(body, body.length); response.bodyOutputStream.write(postBody, postBody.length);
response.finish(); response.finish();
response.finish(); // idempotency response.finish(); // idempotency

View file

@ -3,6 +3,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public /* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* eslint-disable no-control-regex */
/* /*
* Verify the presence of explicit QueryInterface methods on XPCOM objects * Verify the presence of explicit QueryInterface methods on XPCOM objects
@ -24,9 +25,8 @@ var srv;
function run_test() { function run_test() {
srv = createServer(); srv = createServer();
var qi;
try { try {
qi = srv.identity.QueryInterface(Ci.nsIHttpServerIdentity); srv.identity.QueryInterface(Ci.nsIHttpServerIdentity);
} catch (e) { } catch (e) {
var exstr = ("" + e).split(/[\x09\x20-\x7f\x81-\xff]+/)[0]; var exstr = ("" + e).split(/[\x09\x20-\x7f\x81-\xff]+/)[0];
do_throw("server identity didn't QI: " + exstr); do_throw("server identity didn't QI: " + exstr);

View file

@ -28,7 +28,7 @@ function run_test() {
* BEGIN TESTS * * BEGIN TESTS *
***************/ ***************/
var test, data, str; var test, gData, str;
var tests = []; var tests = [];
@ -51,9 +51,9 @@ if (reallyLong.length !== 524288)
str = "GET /very-long-request-line?" + reallyLong + " HTTP/1.1\r\n" + str = "GET /very-long-request-line?" + reallyLong + " HTTP/1.1\r\n" +
"Host: localhost:" + PORT + "\r\n" + "Host: localhost:" + PORT + "\r\n" +
"\r\n"; "\r\n";
data = []; gData = [];
for (var i = 0; i < str.length; i += 16384) for (let i = 0; i < str.length; i += 16384)
data.push(str.substr(i, 16384)); gData.push(str.substr(i, 16384));
function checkVeryLongRequestLine(data) { function checkVeryLongRequestLine(data) {
var iter = LineIterator(data); var iter = LineIterator(data);
@ -80,7 +80,7 @@ function checkVeryLongRequestLine(data) {
expectLines(iter, body); expectLines(iter, body);
} }
test = new RawTest("localhost", PORT, data, checkVeryLongRequestLine), test = new RawTest("localhost", PORT, gData, checkVeryLongRequestLine);
tests.push(test); tests.push(test);
@ -90,15 +90,15 @@ function lotsOfLeadingBlankLines(request, response) {
} }
var blankLines = "\r\n"; var blankLines = "\r\n";
for (var i = 0; i < 14; i++) for (let i = 0; i < 14; i++)
blankLines += blankLines; blankLines += blankLines;
str = blankLines + str = blankLines +
"GET /lots-of-leading-blank-lines HTTP/1.1\r\n" + "GET /lots-of-leading-blank-lines HTTP/1.1\r\n" +
"Host: localhost:" + PORT + "\r\n" + "Host: localhost:" + PORT + "\r\n" +
"\r\n"; "\r\n";
data = []; gData = [];
for (var i = 0; i < str.length; i += 100) for (let i = 0; i < str.length; i += 100)
data.push(str.substr(i, 100)); gData.push(str.substr(i, 100));
function checkLotsOfLeadingBlankLines(data) { function checkLotsOfLeadingBlankLines(data) {
var iter = LineIterator(data); var iter = LineIterator(data);
@ -126,5 +126,5 @@ function checkLotsOfLeadingBlankLines(data) {
expectLines(iter, body); expectLines(iter, body);
} }
test = new RawTest("localhost", PORT, data, checkLotsOfLeadingBlankLines), test = new RawTest("localhost", PORT, gData, checkLotsOfLeadingBlankLines);
tests.push(test); tests.push(test);

View file

@ -173,6 +173,7 @@ function checkForFinish() {
try { try {
do_throw("uh-oh, how are we being finished twice?!?!"); do_throw("uh-oh, how are we being finished twice?!?!");
} finally { } finally {
// eslint-disable-next-line no-undef
quit(1); quit(1);
} }
} }

View file

@ -23,6 +23,7 @@ module.exports = {
"do_load_child_test_harness": false, "do_load_child_test_harness": false,
"do_load_manifest": false, "do_load_manifest": false,
"do_load_module": false, "do_load_module": false,
"do_note_exception": false,
"do_parse_document": false, "do_parse_document": false,
"do_report_unexpected_exception": false, "do_report_unexpected_exception": false,
"do_send_remote_message": false, "do_send_remote_message": false,