Bug 1407695 - Do not return expiry key for session cookies; r?whimboo
MozReview-Commit-ID: 1iTfO2xdHLs
--- a/testing/marionette/cookie.js
+++ b/testing/marionette/cookie.js
@@ -201,22 +201,27 @@ cookie.iter = function* (host, currentPa
let en = cookie.manager.getCookiesFromHost(host, {});
while (en.hasMoreElements()) {
let cookie = en.getNext().QueryInterface(Ci.nsICookie2);
// take the hostname and progressively shorten
let hostname = host;
do {
if ((cookie.host == "." + hostname || cookie.host == hostname) &&
isForCurrentPath(cookie.path)) {
- yield {
+ let data = {
"name": cookie.name,
"value": cookie.value,
"path": cookie.path,
"domain": cookie.host,
"secure": cookie.isSecure,
"httpOnly": cookie.isHttpOnly,
- "expiry": cookie.expiry,
};
+
+ if (!cookie.isSession) {
+ data["expiry"] = cookie.expiry;
+ }
+
+ yield data;
}
hostname = hostname.replace(/^.*?\./, "");
} while (hostname.indexOf(".") != -1);
}
};
--- a/testing/marionette/test_cookie.js
+++ b/testing/marionette/test_cookie.js
@@ -19,17 +19,17 @@ cookie.manager = {
isHttpOnly: httpOnly,
isSession: session,
expiry: expiry,
originAttributes: originAttributes,
};
cookie.manager.cookies.push(newCookie);
},
- remove: function (host, name, path, blocked, originAttributes) {;
+ remove: function (host, name, path, blocked, originAttributes) {
for (let i = 0; i < this.cookies.length; ++i) {
let candidate = this.cookies[i];
if (candidate.host === host &&
candidate.name === name &&
candidate.path === path) {
return this.cookies.splice(i, 1);
}
}
@@ -243,16 +243,44 @@ add_test(function test_remove() {
equal(undefined, cookie.manager.cookies[0]);
run_next_test();
});
add_test(function test_iter() {
cookie.manager.cookies = [];
- cookie.add({name: "0", value: "", domain: "foo.example.com"});
- cookie.add({name: "1", value: "", domain: "bar.example.com"});
+ cookie.add({
+ session: false,
+ name: "0",
+ value: "",
+ domain: "foo.example.com",
+ });
+ cookie.add({
+ session: false,
+ name: "1",
+ value: "",
+ domain: "bar.example.com",
+ });
+
let fooCookies = [...cookie.iter("foo.example.com")];
equal(1, fooCookies.length);
equal(".foo.example.com", fooCookies[0].domain);
+ equal(true, fooCookies[0].hasOwnProperty("expiry"));
+
+ // here we're explicitly setting session to true as a workaround until
+ // bug 1408962 has been fixed. when that bug has been fixed the cookie
+ // will be created as session cookie simply by leaving out the 'expiry'
+ // property.
+ cookie.add({
+ session: true,
+ name: "aSessionCookie",
+ value: "",
+ domain: "session.com",
+ });
+
+ let sessionCookies = [...cookie.iter("session.com")];
+ equal(1, sessionCookies.length);
+ equal("aSessionCookie", sessionCookies[0].name);
+ equal(false, sessionCookies[0].hasOwnProperty("expiry"));
run_next_test();
});