forked from mirrors/gecko-dev
Bug 1423839 - Part 1: Enable ESLint for NetUtil.jsm and netwerk/cookie/test/unit/ (automatic changes) r=Standard8,jdm
Ran ESLint's automatic '--fix' option on the above files. Differential Revision: https://phabricator.services.mozilla.com/D9293 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
0c05448b41
commit
9204c97c31
4 changed files with 61 additions and 74 deletions
|
|
@ -26,9 +26,7 @@ image/**
|
||||||
layout/**
|
layout/**
|
||||||
memory/replace/dmd/test/**
|
memory/replace/dmd/test/**
|
||||||
modules/**
|
modules/**
|
||||||
netwerk/base/NetUtil.jsm
|
|
||||||
netwerk/cookie/test/browser/**
|
netwerk/cookie/test/browser/**
|
||||||
netwerk/cookie/test/unit/**
|
|
||||||
netwerk/protocol/**
|
netwerk/protocol/**
|
||||||
netwerk/dns/**
|
netwerk/dns/**
|
||||||
netwerk/test/browser/**
|
netwerk/test/browser/**
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ var EXPORTED_SYMBOLS = [
|
||||||
* Necko utilities
|
* Necko utilities
|
||||||
*/
|
*/
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
// //////////////////////////////////////////////////////////////////////////////
|
||||||
//// Constants
|
// // Constants
|
||||||
|
|
||||||
const PR_UINT32_MAX = 0xffffffff;
|
const PR_UINT32_MAX = 0xffffffff;
|
||||||
|
|
||||||
|
|
@ -23,8 +23,8 @@ ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||||
const BinaryInputStream = Components.Constructor("@mozilla.org/binaryinputstream;1",
|
const BinaryInputStream = Components.Constructor("@mozilla.org/binaryinputstream;1",
|
||||||
"nsIBinaryInputStream", "setInputStream");
|
"nsIBinaryInputStream", "setInputStream");
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
// //////////////////////////////////////////////////////////////////////////////
|
||||||
//// NetUtil Object
|
// // NetUtil Object
|
||||||
|
|
||||||
var NetUtil = {
|
var NetUtil = {
|
||||||
/**
|
/**
|
||||||
|
|
@ -45,8 +45,7 @@ var NetUtil = {
|
||||||
* return value if desired.
|
* return value if desired.
|
||||||
*/
|
*/
|
||||||
asyncCopy: function NetUtil_asyncCopy(aSource, aSink,
|
asyncCopy: function NetUtil_asyncCopy(aSource, aSink,
|
||||||
aCallback = null)
|
aCallback = null) {
|
||||||
{
|
|
||||||
if (!aSource || !aSink) {
|
if (!aSource || !aSink) {
|
||||||
let exception = new Components.Exception(
|
let exception = new Components.Exception(
|
||||||
"Must have a source and a sink",
|
"Must have a source and a sink",
|
||||||
|
|
@ -67,11 +66,11 @@ var NetUtil = {
|
||||||
var observer;
|
var observer;
|
||||||
if (aCallback) {
|
if (aCallback) {
|
||||||
observer = {
|
observer = {
|
||||||
onStartRequest: function(aRequest, aContext) {},
|
onStartRequest(aRequest, aContext) {},
|
||||||
onStopRequest: function(aRequest, aContext, aStatusCode) {
|
onStopRequest(aRequest, aContext, aStatusCode) {
|
||||||
aCallback(aStatusCode);
|
aCallback(aStatusCode);
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
} else {
|
} else {
|
||||||
observer = null;
|
observer = null;
|
||||||
}
|
}
|
||||||
|
|
@ -99,8 +98,7 @@ var NetUtil = {
|
||||||
* 2) The status code from opening the source.
|
* 2) The status code from opening the source.
|
||||||
* 3) Reference to the nsIRequest.
|
* 3) Reference to the nsIRequest.
|
||||||
*/
|
*/
|
||||||
asyncFetch: function NetUtil_asyncFetch(aSource, aCallback)
|
asyncFetch: function NetUtil_asyncFetch(aSource, aCallback) {
|
||||||
{
|
|
||||||
if (!aSource || !aCallback) {
|
if (!aSource || !aCallback) {
|
||||||
let exception = new Components.Exception(
|
let exception = new Components.Exception(
|
||||||
"Must have a source and a callback",
|
"Must have a source and a callback",
|
||||||
|
|
@ -120,11 +118,11 @@ var NetUtil = {
|
||||||
let listener = Cc["@mozilla.org/network/simple-stream-listener;1"].
|
let listener = Cc["@mozilla.org/network/simple-stream-listener;1"].
|
||||||
createInstance(Ci.nsISimpleStreamListener);
|
createInstance(Ci.nsISimpleStreamListener);
|
||||||
listener.init(pipe.outputStream, {
|
listener.init(pipe.outputStream, {
|
||||||
onStartRequest: function(aRequest, aContext) {},
|
onStartRequest(aRequest, aContext) {},
|
||||||
onStopRequest: function(aRequest, aContext, aStatusCode) {
|
onStopRequest(aRequest, aContext, aStatusCode) {
|
||||||
pipe.outputStream.close();
|
pipe.outputStream.close();
|
||||||
aCallback(pipe.inputStream, aStatusCode, aRequest);
|
aCallback(pipe.inputStream, aStatusCode, aRequest);
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Input streams are handled slightly differently from everything else.
|
// Input streams are handled slightly differently from everything else.
|
||||||
|
|
@ -147,8 +145,7 @@ var NetUtil = {
|
||||||
if (channel.loadInfo &&
|
if (channel.loadInfo &&
|
||||||
channel.loadInfo.securityMode != 0) {
|
channel.loadInfo.securityMode != 0) {
|
||||||
channel.asyncOpen2(listener);
|
channel.asyncOpen2(listener);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Log deprecation warning to console to make sure all channels
|
// Log deprecation warning to console to make sure all channels
|
||||||
// are created providing the correct security flags in the loadinfo.
|
// are created providing the correct security flags in the loadinfo.
|
||||||
// See nsILoadInfo for all available security flags and also the API
|
// See nsILoadInfo for all available security flags and also the API
|
||||||
|
|
@ -158,8 +155,7 @@ var NetUtil = {
|
||||||
"Please create channel using NetUtil.newChannel()");
|
"Please create channel using NetUtil.newChannel()");
|
||||||
channel.asyncOpen(listener, null);
|
channel.asyncOpen(listener, null);
|
||||||
}
|
}
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
let exception = new Components.Exception(
|
let exception = new Components.Exception(
|
||||||
"Failed to open input source '" + channel.originalURI.spec + "'",
|
"Failed to open input source '" + channel.originalURI.spec + "'",
|
||||||
e.result,
|
e.result,
|
||||||
|
|
@ -186,8 +182,7 @@ var NetUtil = {
|
||||||
*
|
*
|
||||||
* @return an nsIURI object.
|
* @return an nsIURI object.
|
||||||
*/
|
*/
|
||||||
newURI: function NetUtil_newURI(aTarget, aOriginCharset, aBaseURI)
|
newURI: function NetUtil_newURI(aTarget, aOriginCharset, aBaseURI) {
|
||||||
{
|
|
||||||
if (!aTarget) {
|
if (!aTarget) {
|
||||||
let exception = new Components.Exception(
|
let exception = new Components.Exception(
|
||||||
"Must have a non-null string spec or nsIFile object",
|
"Must have a non-null string spec or nsIFile object",
|
||||||
|
|
@ -236,8 +231,7 @@ var NetUtil = {
|
||||||
* }
|
* }
|
||||||
* @return an nsIChannel object.
|
* @return an nsIChannel object.
|
||||||
*/
|
*/
|
||||||
newChannel: function NetUtil_newChannel(aWhatToLoad)
|
newChannel: function NetUtil_newChannel(aWhatToLoad) {
|
||||||
{
|
|
||||||
// Make sure the API is called using only the options object.
|
// Make sure the API is called using only the options object.
|
||||||
if (typeof aWhatToLoad != "object" || arguments.length != 1) {
|
if (typeof aWhatToLoad != "object" || arguments.length != 1) {
|
||||||
throw new Components.Exception(
|
throw new Components.Exception(
|
||||||
|
|
@ -355,8 +349,7 @@ var NetUtil = {
|
||||||
*/
|
*/
|
||||||
readInputStreamToString: function NetUtil_readInputStreamToString(aInputStream,
|
readInputStreamToString: function NetUtil_readInputStreamToString(aInputStream,
|
||||||
aCount,
|
aCount,
|
||||||
aOptions)
|
aOptions) {
|
||||||
{
|
|
||||||
if (!(aInputStream instanceof Ci.nsIInputStream)) {
|
if (!(aInputStream instanceof Ci.nsIInputStream)) {
|
||||||
let exception = new Components.Exception(
|
let exception = new Components.Exception(
|
||||||
"First argument should be an nsIInputStream",
|
"First argument should be an nsIInputStream",
|
||||||
|
|
@ -394,8 +387,7 @@ var NetUtil = {
|
||||||
cis.readString(-1, str);
|
cis.readString(-1, str);
|
||||||
cis.close();
|
cis.close();
|
||||||
return str.value;
|
return str.value;
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
// Adjust the stack so it throws at the caller's location.
|
// Adjust the stack so it throws at the caller's location.
|
||||||
throw new Components.Exception(e.message, e.result,
|
throw new Components.Exception(e.message, e.result,
|
||||||
Components.stack.caller, e.data);
|
Components.stack.caller, e.data);
|
||||||
|
|
@ -407,8 +399,7 @@ var NetUtil = {
|
||||||
sis.init(aInputStream);
|
sis.init(aInputStream);
|
||||||
try {
|
try {
|
||||||
return sis.readBytes(aCount);
|
return sis.readBytes(aCount);
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
// Adjust the stack so it throws at the caller's location.
|
// Adjust the stack so it throws at the caller's location.
|
||||||
throw new Components.Exception(e.message, e.result,
|
throw new Components.Exception(e.message, e.result,
|
||||||
Components.stack.caller, e.data);
|
Components.stack.caller, e.data);
|
||||||
|
|
@ -431,8 +422,7 @@ var NetUtil = {
|
||||||
* @throws NS_ERROR_FAILURE if there are not enough bytes available to read
|
* @throws NS_ERROR_FAILURE if there are not enough bytes available to read
|
||||||
* aCount amount of data.
|
* aCount amount of data.
|
||||||
*/
|
*/
|
||||||
readInputStream(aInputStream, aCount)
|
readInputStream(aInputStream, aCount) {
|
||||||
{
|
|
||||||
if (!(aInputStream instanceof Ci.nsIInputStream)) {
|
if (!(aInputStream instanceof Ci.nsIInputStream)) {
|
||||||
let exception = new Components.Exception(
|
let exception = new Components.Exception(
|
||||||
"First argument should be an nsIInputStream",
|
"First argument should be an nsIInputStream",
|
||||||
|
|
@ -457,8 +447,7 @@ var NetUtil = {
|
||||||
*
|
*
|
||||||
* @return a reference to nsIIOService.
|
* @return a reference to nsIIOService.
|
||||||
*/
|
*/
|
||||||
get ioService()
|
get ioService() {
|
||||||
{
|
|
||||||
delete this.ioService;
|
delete this.ioService;
|
||||||
return this.ioService = Cc["@mozilla.org/network/io-service;1"].
|
return this.ioService = Cc["@mozilla.org/network/io-service;1"].
|
||||||
getService(Ci.nsIIOService);
|
getService(Ci.nsIIOService);
|
||||||
|
|
|
||||||
|
|
@ -14,29 +14,29 @@ function run_test() {
|
||||||
|
|
||||||
// Add a new cookie.
|
// Add a new cookie.
|
||||||
setCookie("foo=bar", {
|
setCookie("foo=bar", {
|
||||||
type: "added", isSession: true, isSecure: false, isHttpOnly: false
|
type: "added", isSession: true, isSecure: false, isHttpOnly: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update cookie with isHttpOnly=true.
|
// Update cookie with isHttpOnly=true.
|
||||||
setCookie("foo=bar; HttpOnly", {
|
setCookie("foo=bar; HttpOnly", {
|
||||||
type: "changed", isSession: true, isSecure: false, isHttpOnly: true
|
type: "changed", isSession: true, isSecure: false, isHttpOnly: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update cookie with isSecure=true.
|
// Update cookie with isSecure=true.
|
||||||
setCookie("foo=bar; Secure", {
|
setCookie("foo=bar; Secure", {
|
||||||
type: "changed", isSession: true, isSecure: true, isHttpOnly: false
|
type: "changed", isSession: true, isSecure: true, isHttpOnly: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update cookie with isSession=false.
|
// Update cookie with isSession=false.
|
||||||
let expiry = new Date();
|
let expiry = new Date();
|
||||||
expiry.setUTCFullYear(expiry.getUTCFullYear() + 2);
|
expiry.setUTCFullYear(expiry.getUTCFullYear() + 2);
|
||||||
setCookie(`foo=bar; Expires=${expiry.toGMTString()}`, {
|
setCookie(`foo=bar; Expires=${expiry.toGMTString()}`, {
|
||||||
type: "changed", isSession: false, isSecure: false, isHttpOnly: false
|
type: "changed", isSession: false, isSecure: false, isHttpOnly: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reset cookie.
|
// Reset cookie.
|
||||||
setCookie("foo=bar", {
|
setCookie("foo=bar", {
|
||||||
type: "changed", isSession: true, isSecure: false, isHttpOnly: false
|
type: "changed", isSession: true, isSecure: false, isHttpOnly: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,50 +30,50 @@ async function test_basic_eviction(base_host) {
|
||||||
await setCookie("session_foo_path_3", null, "/foo", null, FOO_PATH);
|
await setCookie("session_foo_path_3", null, "/foo", null, FOO_PATH);
|
||||||
await setCookie("session_foo_path_4", null, "/foo", null, FOO_PATH);
|
await setCookie("session_foo_path_4", null, "/foo", null, FOO_PATH);
|
||||||
await setCookie("session_foo_path_5", null, "/foo", null, FOO_PATH);
|
await setCookie("session_foo_path_5", null, "/foo", null, FOO_PATH);
|
||||||
verifyCookies(['session_foo_path_1',
|
verifyCookies(["session_foo_path_1",
|
||||||
'session_foo_path_2',
|
"session_foo_path_2",
|
||||||
'session_foo_path_3',
|
"session_foo_path_3",
|
||||||
'session_foo_path_4',
|
"session_foo_path_4",
|
||||||
'session_foo_path_5'], BASE_URI);
|
"session_foo_path_5"], BASE_URI);
|
||||||
|
|
||||||
// Check if cookies are evicted by creation time.
|
// Check if cookies are evicted by creation time.
|
||||||
await setCookie("session_foo_path_6", null, "/foo", null, FOO_PATH);
|
await setCookie("session_foo_path_6", null, "/foo", null, FOO_PATH);
|
||||||
verifyCookies(['session_foo_path_4',
|
verifyCookies(["session_foo_path_4",
|
||||||
'session_foo_path_5',
|
"session_foo_path_5",
|
||||||
'session_foo_path_6'], BASE_URI);
|
"session_foo_path_6"], BASE_URI);
|
||||||
|
|
||||||
await setCookie("session_bar_path_1", null, "/bar", null, BAR_PATH);
|
await setCookie("session_bar_path_1", null, "/bar", null, BAR_PATH);
|
||||||
await setCookie("session_bar_path_2", null, "/bar", null, BAR_PATH);
|
await setCookie("session_bar_path_2", null, "/bar", null, BAR_PATH);
|
||||||
|
|
||||||
verifyCookies(['session_foo_path_4',
|
verifyCookies(["session_foo_path_4",
|
||||||
'session_foo_path_5',
|
"session_foo_path_5",
|
||||||
'session_foo_path_6',
|
"session_foo_path_6",
|
||||||
'session_bar_path_1',
|
"session_bar_path_1",
|
||||||
'session_bar_path_2'], BASE_URI);
|
"session_bar_path_2"], BASE_URI);
|
||||||
|
|
||||||
// Check if cookies are evicted by last accessed time.
|
// Check if cookies are evicted by last accessed time.
|
||||||
cs.getCookieString(FOO_PATH, null);
|
cs.getCookieString(FOO_PATH, null);
|
||||||
await setCookie("session_foo_path_7", null, "/foo", null, FOO_PATH);
|
await setCookie("session_foo_path_7", null, "/foo", null, FOO_PATH);
|
||||||
verifyCookies(['session_foo_path_5',
|
verifyCookies(["session_foo_path_5",
|
||||||
'session_foo_path_6',
|
"session_foo_path_6",
|
||||||
'session_foo_path_7'], BASE_URI);
|
"session_foo_path_7"], BASE_URI);
|
||||||
|
|
||||||
const EXPIRED_TIME = 3;
|
const EXPIRED_TIME = 3;
|
||||||
|
|
||||||
await setCookie("non_session_expired_foo_path_1", null, "/foo", EXPIRED_TIME, FOO_PATH);
|
await setCookie("non_session_expired_foo_path_1", null, "/foo", EXPIRED_TIME, FOO_PATH);
|
||||||
await setCookie("non_session_expired_foo_path_2", null, "/foo", EXPIRED_TIME, FOO_PATH);
|
await setCookie("non_session_expired_foo_path_2", null, "/foo", EXPIRED_TIME, FOO_PATH);
|
||||||
verifyCookies(['session_foo_path_5',
|
verifyCookies(["session_foo_path_5",
|
||||||
'session_foo_path_6',
|
"session_foo_path_6",
|
||||||
'session_foo_path_7',
|
"session_foo_path_7",
|
||||||
'non_session_expired_foo_path_1',
|
"non_session_expired_foo_path_1",
|
||||||
'non_session_expired_foo_path_2'], BASE_URI);
|
"non_session_expired_foo_path_2"], BASE_URI);
|
||||||
|
|
||||||
// Check if expired cookies are evicted first.
|
// Check if expired cookies are evicted first.
|
||||||
await new Promise(resolve => do_timeout(EXPIRED_TIME * 1000, resolve));
|
await new Promise(resolve => do_timeout(EXPIRED_TIME * 1000, resolve));
|
||||||
await setCookie("session_foo_path_8", null, "/foo", null, FOO_PATH);
|
await setCookie("session_foo_path_8", null, "/foo", null, FOO_PATH);
|
||||||
verifyCookies(['session_foo_path_6',
|
verifyCookies(["session_foo_path_6",
|
||||||
'session_foo_path_7',
|
"session_foo_path_7",
|
||||||
'session_foo_path_8'], BASE_URI);
|
"session_foo_path_8"], BASE_URI);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that the given cookie names exist, and are ordered from least to most recently accessed
|
// Verify that the given cookie names exist, and are ordered from least to most recently accessed
|
||||||
|
|
@ -93,7 +93,7 @@ function verifyCookies(names, uri) {
|
||||||
return names.findIndex(function(n) {
|
return names.findIndex(function(n) {
|
||||||
return c.name == n;
|
return c.name == n;
|
||||||
}) == -1;
|
}) == -1;
|
||||||
}).map(function(c) { return c.name });
|
}).map(function(c) { return c.name; });
|
||||||
if (left.length) {
|
if (left.length) {
|
||||||
info("unexpected cookies: " + left);
|
info("unexpected cookies: " + left);
|
||||||
}
|
}
|
||||||
|
|
@ -111,29 +111,29 @@ function verifyCookies(names, uri) {
|
||||||
});
|
});
|
||||||
for (var i = 0; i < names.length; i++) {
|
for (var i = 0; i < names.length; i++) {
|
||||||
Assert.equal(names[i], actual_cookies[i].name);
|
Assert.equal(names[i], actual_cookies[i].name);
|
||||||
Assert.equal(names[i].startsWith('session'), actual_cookies[i].isSession);
|
Assert.equal(names[i].startsWith("session"), actual_cookies[i].isSession);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastValue = 0
|
var lastValue = 0;
|
||||||
function setCookie(name, domain, path, maxAge, url) {
|
function setCookie(name, domain, path, maxAge, url) {
|
||||||
let value = name + "=" + ++lastValue;
|
let value = name + "=" + ++lastValue;
|
||||||
var s = 'setting cookie ' + value;
|
var s = "setting cookie " + value;
|
||||||
if (domain) {
|
if (domain) {
|
||||||
value += "; Domain=" + domain;
|
value += "; Domain=" + domain;
|
||||||
s += ' (d=' + domain + ')';
|
s += " (d=" + domain + ")";
|
||||||
}
|
}
|
||||||
if (path) {
|
if (path) {
|
||||||
value += "; Path=" + path;
|
value += "; Path=" + path;
|
||||||
s += ' (p=' + path + ')';
|
s += " (p=" + path + ")";
|
||||||
}
|
}
|
||||||
if (maxAge) {
|
if (maxAge) {
|
||||||
value += "; Max-Age=" + maxAge;
|
value += "; Max-Age=" + maxAge;
|
||||||
s += ' (non-session)';
|
s += " (non-session)";
|
||||||
} else {
|
} else {
|
||||||
s += ' (session)';
|
s += " (session)";
|
||||||
}
|
}
|
||||||
s += ' for ' + url.spec;
|
s += " for " + url.spec;
|
||||||
info(s);
|
info(s);
|
||||||
cs.setCookieStringFromHttp(url, null, null, value, null, null);
|
cs.setCookieStringFromHttp(url, null, null, value, null, null);
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function(resolve) {
|
||||||
|
|
@ -141,5 +141,5 @@ function setCookie(name, domain, path, maxAge, url) {
|
||||||
// algorithm to produce different results from other platforms. We work around
|
// algorithm to produce different results from other platforms. We work around
|
||||||
// this by ensuring that there's a clear gap between each cookie update.
|
// this by ensuring that there's a clear gap between each cookie update.
|
||||||
do_timeout(10, resolve);
|
do_timeout(10, resolve);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue