Backed out 2 changesets (bug 1423839) for xpcshell failures on netwerk/test/unit/test_NetUtil.js

Backed out changeset 501fffbf872d (bug 1423839)
Backed out changeset 406ca9722ffa (bug 1423839)
This commit is contained in:
Dorel Luca 2018-10-23 00:49:18 +03:00
parent c6f2578c07
commit c366888702
7 changed files with 113 additions and 80 deletions

View File

@ -26,7 +26,9 @@ 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

@ -12,18 +12,19 @@ var EXPORTED_SYMBOLS = [
* Necko utilities
*/
// //////////////////////////////////////////////////////////////////////////////
// // Constants
////////////////////////////////////////////////////////////////////////////////
//// Constants
const PR_UINT32_MAX = 0xffffffff;
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");
const BinaryInputStream = Components.Constructor("@mozilla.org/binaryinputstream;1",
"nsIBinaryInputStream", "setInputStream");
// //////////////////////////////////////////////////////////////////////////////
// // NetUtil Object
////////////////////////////////////////////////////////////////////////////////
//// NetUtil Object
var NetUtil = {
/**
@ -44,7 +45,8 @@ 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",
@ -65,11 +67,11 @@ var NetUtil = {
var observer;
if (aCallback) {
observer = {
onStartRequest(aRequest, aContext) {},
onStopRequest(aRequest, aContext, aStatusCode) {
onStartRequest: function(aRequest, aContext) {},
onStopRequest: function(aRequest, aContext, aStatusCode) {
aCallback(aStatusCode);
},
};
}
}
} else {
observer = null;
}
@ -97,7 +99,8 @@ 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",
@ -117,11 +120,11 @@ var NetUtil = {
let listener = Cc["@mozilla.org/network/simple-stream-listener;1"].
createInstance(Ci.nsISimpleStreamListener);
listener.init(pipe.outputStream, {
onStartRequest(aRequest, aContext) {},
onStopRequest(aRequest, aContext, aStatusCode) {
onStartRequest: function(aRequest, aContext) {},
onStopRequest: function(aRequest, aContext, aStatusCode) {
pipe.outputStream.close();
aCallback(pipe.inputStream, aStatusCode, aRequest);
},
}
});
// Input streams are handled slightly differently from everything else.
@ -144,7 +147,8 @@ 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
@ -154,7 +158,8 @@ 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,
@ -181,7 +186,8 @@ 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",
@ -192,10 +198,10 @@ var NetUtil = {
}
if (aTarget instanceof Ci.nsIFile) {
return Services.io.newFileURI(aTarget);
return this.ioService.newFileURI(aTarget);
}
return Services.io.newURI(aTarget, aOriginCharset, aBaseURI);
return this.ioService.newURI(aTarget, aOriginCharset, aBaseURI);
},
/**
@ -230,7 +236,8 @@ 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(
@ -315,12 +322,12 @@ var NetUtil = {
contentPolicyType = Ci.nsIContentPolicy.TYPE_OTHER;
}
return Services.io.newChannelFromURI2(uri,
loadingNode || null,
loadingPrincipal || null,
triggeringPrincipal || null,
securityFlags,
contentPolicyType);
return this.ioService.newChannelFromURI2(uri,
loadingNode || null,
loadingPrincipal || null,
triggeringPrincipal || null,
securityFlags,
contentPolicyType);
},
/**
@ -348,7 +355,8 @@ 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",
@ -386,7 +394,8 @@ 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);
@ -398,7 +407,8 @@ 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);
@ -421,7 +431,8 @@ 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",
@ -440,4 +451,16 @@ var NetUtil = {
stream.readArrayBuffer(result.byteLength, result);
return result;
},
/**
* Returns a reference to nsIIOService.
*
* @return a reference to nsIIOService.
*/
get ioService()
{
delete this.ioService;
return this.ioService = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
},
};

View File

@ -14,52 +14,52 @@ 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
});
}
function setCookie(value, expected) {
function setCookieInternal(valueInternal, expectedInternal = null) {
function setCookieInternal(value, expected = null) {
function observer(subject, topic, data) {
if (!expectedInternal) {
if (!expected) {
do_throw("no notification expected");
return;
}
// Check we saw the right notification.
Assert.equal(data, expectedInternal.type);
Assert.equal(data, expected.type);
// Check cookie details.
let cookie = subject.QueryInterface(Ci.nsICookie2);
Assert.equal(cookie.isSession, expectedInternal.isSession);
Assert.equal(cookie.isSecure, expectedInternal.isSecure);
Assert.equal(cookie.isHttpOnly, expectedInternal.isHttpOnly);
Assert.equal(cookie.isSession, expected.isSession);
Assert.equal(cookie.isSecure, expected.isSecure);
Assert.equal(cookie.isHttpOnly, expected.isHttpOnly);
}
Services.obs.addObserver(observer, "cookie-changed");
cs.setCookieStringFromHttp(URI, null, null, valueInternal, null, null);
cs.setCookieStringFromHttp(URI, null, null, value, null, null);
Services.obs.removeObserver(observer, "cookie-changed");
}

View File

@ -1,12 +1,14 @@
ChromeUtils.import("resource://gre/modules/Services.jsm");
do_get_profile();
const dirSvc = Services.dirsvc;
const dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties);
let dbFile = dirSvc.get("ProfD", Ci.nsIFile);
dbFile.append("cookies.sqlite");
let storage = Services.storage;
let storage = Cc["@mozilla.org/storage/service;1"].
getService(Ci.mozIStorageService);
let properties = Cc["@mozilla.org/hash-property-bag;1"].
createInstance(Ci.nsIWritablePropertyBag);
properties.setProperty("shared", true);
@ -47,7 +49,8 @@ conn.executeSimpleSQL("INSERT INTO moz_cookies(" +
// Now start the cookie service, and then check the fields in the table.
// Get sessionEnumerator to wait for the initialization in cookie thread
const enumerator = Services.cookies.sessionEnumerator;
const enumerator = Cc["@mozilla.org/cookieService;1"].
getService(Ci.nsICookieManager).sessionEnumerator;
Assert.equal(conn.schemaVersion, 9);
let stmt = conn.createStatement("SELECT sql FROM sqlite_master " +

View File

@ -7,6 +7,7 @@ const cs = Cc["@mozilla.org/cookieService;1"].getService(Ci.nsICookieService);
const cm = cs.QueryInterface(Ci.nsICookieManager);
function run_test() {
var tests = [];
Services.prefs.setIntPref("network.cookie.staleThreshold", 0);
add_task(async function() {
await test_basic_eviction("example.org");
@ -29,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
@ -92,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);
}
@ -110,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) {
@ -140,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);
});
})
}

View File

@ -2,7 +2,9 @@ ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");
function inChildProcess() {
return Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
return Cc["@mozilla.org/xre/app-info;1"]
.getService(Ci.nsIXULRuntime)
.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
}
function run_test() {

View File

@ -2,7 +2,9 @@ ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");
function inChildProcess() {
return Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
return Cc["@mozilla.org/xre/app-info;1"]
.getService(Ci.nsIXULRuntime)
.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
}
function run_test() {