/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
remove(host, name, path) { for (let i = 0; i < this.cookies.length; ++i) {
let candidate = this.cookies[i]; if (
candidate.host === host &&
candidate.name === name &&
candidate.path === path
) { returnthis.cookies.splice(i, 1);
}
} returnfalse;
},
getCookiesFromHost(host) {
let hostCookies = this.cookies.filter(
c => c.host === host || c.host === "." + host
);
return hostCookies;
},
};
add_task(function test_fromJSON() { // object for (let invalidType of ["foo", 42, true, [], null, undefined]) { Assert.throws(
() => cookie.fromJSON(invalidType),
/Expected "cookie" to be an object/
);
}
// name and value for (let invalidType of [42, true, [], {}, null, undefined]) { Assert.throws(
() => cookie.fromJSON({ name: invalidType }),
/Expected cookie "name" to be a string/
); Assert.throws(
() => cookie.fromJSON({ name: "foo", value: invalidType }),
/Expected cookie "value" to be a string/
);
}
// domain for (let invalidType of [42, true, [], {}, null]) {
let domainTest = {
name: "foo",
value: "bar",
domain: invalidType,
}; Assert.throws(
() => cookie.fromJSON(domainTest),
/Expected cookie "domain" to be a string/
);
}
let domainTest = {
name: "foo",
value: "bar",
domain: "domain",
};
let parsedCookie = cookie.fromJSON(domainTest);
equal(parsedCookie.domain, "domain");
// path for (let invalidType of [42, true, [], {}, null]) {
let pathTest = {
name: "foo",
value: "bar",
path: invalidType,
}; Assert.throws(
() => cookie.fromJSON(pathTest),
/Expected cookie "path" to be a string/
);
}
// secure for (let invalidType of ["foo", 42, [], {}, null]) {
let secureTest = {
name: "foo",
value: "bar",
secure: invalidType,
}; Assert.throws(
() => cookie.fromJSON(secureTest),
/Expected cookie "secure" to be a boolean/
);
}
// httpOnly for (let invalidType of ["foo", 42, [], {}, null]) {
let httpOnlyTest = {
name: "foo",
value: "bar",
httpOnly: invalidType,
}; Assert.throws(
() => cookie.fromJSON(httpOnlyTest),
/Expected cookie "httpOnly" to be a boolean/
);
}
// expiry for (let invalidType of [
-1,
Number.MAX_SAFE_INTEGER + 1, "foo", true,
[],
{}, null,
]) {
let expiryTest = {
name: "foo",
value: "bar",
expiry: invalidType,
}; Assert.throws(
() => cookie.fromJSON(expiryTest),
/Expected cookie "expiry" to be a positive integer/
);
}
// sameSite for (let invalidType of ["foo", 42, [], {}, null]) { const sameSiteTest = {
name: "foo",
value: "bar",
sameSite: invalidType,
}; Assert.throws(
() => cookie.fromJSON(sameSiteTest),
/Expected cookie "sameSite" to be one of None,Lax,Strict/
);
}
// bare requirements
let bare = cookie.fromJSON({ name: "name", value: "value" });
equal("name", bare.name);
equal("value", bare.value); for (let missing of [ "path", "secure", "httpOnly", "session", "expiry", "sameSite",
]) {
ok(!bare.hasOwnProperty(missing));
}
Assert.throws(() => {
let biscuit = { name: "name3", value: "value3", domain: "domain3" };
cookie.add(biscuit, { restrictToHost: "other domain" });
}, /Cookies may only be set for the current domain/);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.