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:
James Lee 2018-10-22 19:41:33 +00:00
parent f5b084ac24
commit d001a272ab
4 changed files with 61 additions and 74 deletions

View File

@ -26,9 +26,7 @@ image/**
layout/**
memory/replace/dmd/test/**
modules/**
netwerk/base/NetUtil.jsm
netwerk/cookie/test/browser/**
netwerk/cookie/test/unit/**
netwerk/protocol/**
netwerk/dns/**
netwerk/test/browser/**

View File

@ -45,8 +45,7 @@ var NetUtil = {
* return value if desired.
*/
asyncCopy: function NetUtil_asyncCopy(aSource, aSink,
aCallback = null)
{
aCallback = null) {
if (!aSource || !aSink) {
let exception = new Components.Exception(
"Must have a source and a sink",
@ -67,11 +66,11 @@ var NetUtil = {
var observer;
if (aCallback) {
observer = {
onStartRequest: function(aRequest, aContext) {},
onStopRequest: function(aRequest, aContext, aStatusCode) {
onStartRequest(aRequest, aContext) {},
onStopRequest(aRequest, aContext, aStatusCode) {
aCallback(aStatusCode);
}
}
},
};
} else {
observer = null;
}
@ -99,8 +98,7 @@ var NetUtil = {
* 2) The status code from opening the source.
* 3) Reference to the nsIRequest.
*/
asyncFetch: function NetUtil_asyncFetch(aSource, aCallback)
{
asyncFetch: function NetUtil_asyncFetch(aSource, aCallback) {
if (!aSource || !aCallback) {
let exception = new Components.Exception(
"Must have a source and a callback",
@ -120,11 +118,11 @@ var NetUtil = {
let listener = Cc["@mozilla.org/network/simple-stream-listener;1"].
createInstance(Ci.nsISimpleStreamListener);
listener.init(pipe.outputStream, {
onStartRequest: function(aRequest, aContext) {},
onStopRequest: function(aRequest, aContext, aStatusCode) {
onStartRequest(aRequest, aContext) {},
onStopRequest(aRequest, aContext, aStatusCode) {
pipe.outputStream.close();
aCallback(pipe.inputStream, aStatusCode, aRequest);
}
},
});
// Input streams are handled slightly differently from everything else.
@ -147,8 +145,7 @@ var NetUtil = {
if (channel.loadInfo &&
channel.loadInfo.securityMode != 0) {
channel.asyncOpen2(listener);
}
else {
} else {
// Log deprecation warning to console to make sure all channels
// are created providing the correct security flags in the loadinfo.
// See nsILoadInfo for all available security flags and also the API
@ -158,8 +155,7 @@ var NetUtil = {
"Please create channel using NetUtil.newChannel()");
channel.asyncOpen(listener, null);
}
}
catch (e) {
} catch (e) {
let exception = new Components.Exception(
"Failed to open input source '" + channel.originalURI.spec + "'",
e.result,
@ -186,8 +182,7 @@ var NetUtil = {
*
* @return an nsIURI object.
*/
newURI: function NetUtil_newURI(aTarget, aOriginCharset, aBaseURI)
{
newURI: function NetUtil_newURI(aTarget, aOriginCharset, aBaseURI) {
if (!aTarget) {
let exception = new Components.Exception(
"Must have a non-null string spec or nsIFile object",
@ -236,8 +231,7 @@ var NetUtil = {
* }
* @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.
if (typeof aWhatToLoad != "object" || arguments.length != 1) {
throw new Components.Exception(
@ -355,8 +349,7 @@ var NetUtil = {
*/
readInputStreamToString: function NetUtil_readInputStreamToString(aInputStream,
aCount,
aOptions)
{
aOptions) {
if (!(aInputStream instanceof Ci.nsIInputStream)) {
let exception = new Components.Exception(
"First argument should be an nsIInputStream",
@ -394,8 +387,7 @@ var NetUtil = {
cis.readString(-1, str);
cis.close();
return str.value;
}
catch (e) {
} catch (e) {
// Adjust the stack so it throws at the caller's location.
throw new Components.Exception(e.message, e.result,
Components.stack.caller, e.data);
@ -407,8 +399,7 @@ var NetUtil = {
sis.init(aInputStream);
try {
return sis.readBytes(aCount);
}
catch (e) {
} catch (e) {
// Adjust the stack so it throws at the caller's location.
throw new Components.Exception(e.message, e.result,
Components.stack.caller, e.data);
@ -431,8 +422,7 @@ var NetUtil = {
* @throws NS_ERROR_FAILURE if there are not enough bytes available to read
* aCount amount of data.
*/
readInputStream(aInputStream, aCount)
{
readInputStream(aInputStream, aCount) {
if (!(aInputStream instanceof Ci.nsIInputStream)) {
let exception = new Components.Exception(
"First argument should be an nsIInputStream",
@ -457,8 +447,7 @@ var NetUtil = {
*
* @return a reference to nsIIOService.
*/
get ioService()
{
get ioService() {
delete this.ioService;
return this.ioService = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);

View File

@ -14,29 +14,29 @@ function run_test() {
// Add a new cookie.
setCookie("foo=bar", {
type: "added", isSession: true, isSecure: false, isHttpOnly: false
type: "added", isSession: true, isSecure: false, isHttpOnly: false,
});
// Update cookie with isHttpOnly=true.
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.
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.
let expiry = new Date();
expiry.setUTCFullYear(expiry.getUTCFullYear() + 2);
setCookie(`foo=bar; Expires=${expiry.toGMTString()}`, {
type: "changed", isSession: false, isSecure: false, isHttpOnly: false
type: "changed", isSession: false, isSecure: false, isHttpOnly: false,
});
// Reset cookie.
setCookie("foo=bar", {
type: "changed", isSession: true, isSecure: false, isHttpOnly: false
type: "changed", isSession: true, isSecure: false, isHttpOnly: false,
});
}

View File

@ -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_4", null, "/foo", null, FOO_PATH);
await setCookie("session_foo_path_5", null, "/foo", null, FOO_PATH);
verifyCookies(['session_foo_path_1',
'session_foo_path_2',
'session_foo_path_3',
'session_foo_path_4',
'session_foo_path_5'], BASE_URI);
verifyCookies(["session_foo_path_1",
"session_foo_path_2",
"session_foo_path_3",
"session_foo_path_4",
"session_foo_path_5"], BASE_URI);
// Check if cookies are evicted by creation time.
await setCookie("session_foo_path_6", null, "/foo", null, FOO_PATH);
verifyCookies(['session_foo_path_4',
'session_foo_path_5',
'session_foo_path_6'], BASE_URI);
verifyCookies(["session_foo_path_4",
"session_foo_path_5",
"session_foo_path_6"], BASE_URI);
await setCookie("session_bar_path_1", null, "/bar", null, BAR_PATH);
await setCookie("session_bar_path_2", null, "/bar", null, BAR_PATH);
verifyCookies(['session_foo_path_4',
'session_foo_path_5',
'session_foo_path_6',
'session_bar_path_1',
'session_bar_path_2'], BASE_URI);
verifyCookies(["session_foo_path_4",
"session_foo_path_5",
"session_foo_path_6",
"session_bar_path_1",
"session_bar_path_2"], BASE_URI);
// Check if cookies are evicted by last accessed time.
cs.getCookieString(FOO_PATH, null);
await setCookie("session_foo_path_7", null, "/foo", null, FOO_PATH);
verifyCookies(['session_foo_path_5',
'session_foo_path_6',
'session_foo_path_7'], BASE_URI);
verifyCookies(["session_foo_path_5",
"session_foo_path_6",
"session_foo_path_7"], BASE_URI);
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_2", null, "/foo", EXPIRED_TIME, FOO_PATH);
verifyCookies(['session_foo_path_5',
'session_foo_path_6',
'session_foo_path_7',
'non_session_expired_foo_path_1',
'non_session_expired_foo_path_2'], BASE_URI);
verifyCookies(["session_foo_path_5",
"session_foo_path_6",
"session_foo_path_7",
"non_session_expired_foo_path_1",
"non_session_expired_foo_path_2"], BASE_URI);
// Check if expired cookies are evicted first.
await new Promise(resolve => do_timeout(EXPIRED_TIME * 1000, resolve));
await setCookie("session_foo_path_8", null, "/foo", null, FOO_PATH);
verifyCookies(['session_foo_path_6',
'session_foo_path_7',
'session_foo_path_8'], BASE_URI);
verifyCookies(["session_foo_path_6",
"session_foo_path_7",
"session_foo_path_8"], BASE_URI);
}
// 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 c.name == n;
}) == -1;
}).map(function(c) { return c.name });
}).map(function(c) { return c.name; });
if (left.length) {
info("unexpected cookies: " + left);
}
@ -111,29 +111,29 @@ function verifyCookies(names, uri) {
});
for (var i = 0; i < names.length; i++) {
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) {
let value = name + "=" + ++lastValue;
var s = 'setting cookie ' + value;
var s = "setting cookie " + value;
if (domain) {
value += "; Domain=" + domain;
s += ' (d=' + domain + ')';
s += " (d=" + domain + ")";
}
if (path) {
value += "; Path=" + path;
s += ' (p=' + path + ')';
s += " (p=" + path + ")";
}
if (maxAge) {
value += "; Max-Age=" + maxAge;
s += ' (non-session)';
s += " (non-session)";
} else {
s += ' (session)';
s += " (session)";
}
s += ' for ' + url.spec;
s += " for " + url.spec;
info(s);
cs.setCookieStringFromHttp(url, null, null, value, null, null);
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
// this by ensuring that there's a clear gap between each cookie update.
do_timeout(10, resolve);
})
});
}