forked from mirrors/gecko-dev
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:
parent
c6f2578c07
commit
c366888702
7 changed files with 113 additions and 80 deletions
|
|
@ -26,7 +26,9 @@ 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,18 +12,19 @@ var EXPORTED_SYMBOLS = [
|
||||||
* Necko utilities
|
* Necko utilities
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// //////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// // Constants
|
//// Constants
|
||||||
|
|
||||||
const PR_UINT32_MAX = 0xffffffff;
|
const PR_UINT32_MAX = 0xffffffff;
|
||||||
|
|
||||||
|
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
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 = {
|
||||||
/**
|
/**
|
||||||
|
|
@ -44,7 +45,8 @@ 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",
|
||||||
|
|
@ -65,11 +67,11 @@ var NetUtil = {
|
||||||
var observer;
|
var observer;
|
||||||
if (aCallback) {
|
if (aCallback) {
|
||||||
observer = {
|
observer = {
|
||||||
onStartRequest(aRequest, aContext) {},
|
onStartRequest: function(aRequest, aContext) {},
|
||||||
onStopRequest(aRequest, aContext, aStatusCode) {
|
onStopRequest: function(aRequest, aContext, aStatusCode) {
|
||||||
aCallback(aStatusCode);
|
aCallback(aStatusCode);
|
||||||
},
|
}
|
||||||
};
|
}
|
||||||
} else {
|
} else {
|
||||||
observer = null;
|
observer = null;
|
||||||
}
|
}
|
||||||
|
|
@ -97,7 +99,8 @@ 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",
|
||||||
|
|
@ -117,11 +120,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(aRequest, aContext) {},
|
onStartRequest: function(aRequest, aContext) {},
|
||||||
onStopRequest(aRequest, aContext, aStatusCode) {
|
onStopRequest: function(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.
|
||||||
|
|
@ -144,7 +147,8 @@ 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
|
||||||
|
|
@ -154,7 +158,8 @@ 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,
|
||||||
|
|
@ -181,7 +186,8 @@ 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",
|
||||||
|
|
@ -192,10 +198,10 @@ var NetUtil = {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aTarget instanceof Ci.nsIFile) {
|
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.
|
* @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(
|
||||||
|
|
@ -315,7 +322,7 @@ var NetUtil = {
|
||||||
contentPolicyType = Ci.nsIContentPolicy.TYPE_OTHER;
|
contentPolicyType = Ci.nsIContentPolicy.TYPE_OTHER;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Services.io.newChannelFromURI2(uri,
|
return this.ioService.newChannelFromURI2(uri,
|
||||||
loadingNode || null,
|
loadingNode || null,
|
||||||
loadingPrincipal || null,
|
loadingPrincipal || null,
|
||||||
triggeringPrincipal || null,
|
triggeringPrincipal || null,
|
||||||
|
|
@ -348,7 +355,8 @@ 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",
|
||||||
|
|
@ -386,7 +394,8 @@ 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);
|
||||||
|
|
@ -398,7 +407,8 @@ 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);
|
||||||
|
|
@ -421,7 +431,8 @@ 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",
|
||||||
|
|
@ -440,4 +451,16 @@ var NetUtil = {
|
||||||
stream.readArrayBuffer(result.byteLength, result);
|
stream.readArrayBuffer(result.byteLength, result);
|
||||||
return 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);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -14,52 +14,52 @@ 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
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setCookie(value, expected) {
|
function setCookie(value, expected) {
|
||||||
function setCookieInternal(valueInternal, expectedInternal = null) {
|
function setCookieInternal(value, expected = null) {
|
||||||
function observer(subject, topic, data) {
|
function observer(subject, topic, data) {
|
||||||
if (!expectedInternal) {
|
if (!expected) {
|
||||||
do_throw("no notification expected");
|
do_throw("no notification expected");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check we saw the right notification.
|
// Check we saw the right notification.
|
||||||
Assert.equal(data, expectedInternal.type);
|
Assert.equal(data, expected.type);
|
||||||
|
|
||||||
// Check cookie details.
|
// Check cookie details.
|
||||||
let cookie = subject.QueryInterface(Ci.nsICookie2);
|
let cookie = subject.QueryInterface(Ci.nsICookie2);
|
||||||
Assert.equal(cookie.isSession, expectedInternal.isSession);
|
Assert.equal(cookie.isSession, expected.isSession);
|
||||||
Assert.equal(cookie.isSecure, expectedInternal.isSecure);
|
Assert.equal(cookie.isSecure, expected.isSecure);
|
||||||
Assert.equal(cookie.isHttpOnly, expectedInternal.isHttpOnly);
|
Assert.equal(cookie.isHttpOnly, expected.isHttpOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
Services.obs.addObserver(observer, "cookie-changed");
|
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");
|
Services.obs.removeObserver(observer, "cookie-changed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||||
|
|
||||||
do_get_profile();
|
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);
|
let dbFile = dirSvc.get("ProfD", Ci.nsIFile);
|
||||||
dbFile.append("cookies.sqlite");
|
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"].
|
let properties = Cc["@mozilla.org/hash-property-bag;1"].
|
||||||
createInstance(Ci.nsIWritablePropertyBag);
|
createInstance(Ci.nsIWritablePropertyBag);
|
||||||
properties.setProperty("shared", true);
|
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.
|
// Now start the cookie service, and then check the fields in the table.
|
||||||
// Get sessionEnumerator to wait for the initialization in cookie thread
|
// 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);
|
Assert.equal(conn.schemaVersion, 9);
|
||||||
let stmt = conn.createStatement("SELECT sql FROM sqlite_master " +
|
let stmt = conn.createStatement("SELECT sql FROM sqlite_master " +
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ const cs = Cc["@mozilla.org/cookieService;1"].getService(Ci.nsICookieService);
|
||||||
const cm = cs.QueryInterface(Ci.nsICookieManager);
|
const cm = cs.QueryInterface(Ci.nsICookieManager);
|
||||||
|
|
||||||
function run_test() {
|
function run_test() {
|
||||||
|
var tests = [];
|
||||||
Services.prefs.setIntPref("network.cookie.staleThreshold", 0);
|
Services.prefs.setIntPref("network.cookie.staleThreshold", 0);
|
||||||
add_task(async function() {
|
add_task(async function() {
|
||||||
await test_basic_eviction("example.org");
|
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_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
|
||||||
|
|
@ -92,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);
|
||||||
}
|
}
|
||||||
|
|
@ -110,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) {
|
||||||
|
|
@ -140,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);
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@ ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||||
|
|
||||||
function inChildProcess() {
|
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() {
|
function run_test() {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@ ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||||
|
|
||||||
function inChildProcess() {
|
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() {
|
function run_test() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue