Bug 1255569 - Add coverage for cookie eviction events for expired cookies, r=kmag

Fix bug in ext-cookies.js that was reporting expired cookies as evicted

MozReview-Commit-ID: 2it2YwbQAzh

--HG--
extra : transplant_source : %C3%03%5B%B0.eNJ%E6%B8%8B%815%7B%E6%93%BE%A3%D0D
This commit is contained in:
bsilverberg 2016-03-29 17:20:58 -04:00
Родитель 4072b45037
Коммит c8faee2e69
2 изменённых файлов: 53 добавлений и 1 удалений

Просмотреть файл

@ -338,7 +338,7 @@ extensions.registerSchemaAPI("cookies", "cookies", (extension, context) => {
subject.QueryInterface(Ci.nsIArray);
for (let i = 0; i < subject.length; i++) {
let cookie = subject.queryElementAt(i, Ci.nsICookie2);
if (!cookie.isSession && (cookie.expiry + 1) * 1000 <= Date.now()) {
if (!cookie.isSession && cookie.expiry * 1000 <= Date.now()) {
notify(true, cookie, "expired");
} else {
notify(true, cookie, "evicted");

Просмотреть файл

@ -181,6 +181,58 @@ add_task(function* test_cookies() {
info("extension unloaded");
});
add_task(function* test_cookies_expiry() {
function background() {
let expectedEvents = [];
browser.cookies.onChanged.addListener(event => {
expectedEvents.push(`${event.removed}:${event.cause}`);
if (expectedEvents.length === 1) {
browser.test.assertEq("true:expired", expectedEvents[0], "expired cookie removed");
browser.test.assertEq("first", event.cookie.name, "expired cookie has the expected name");
browser.test.assertEq("one", event.cookie.value, "expired cookie has the expected value");
} else {
browser.test.assertEq("false:explicit", expectedEvents[1], "new cookie added");
browser.test.assertEq("first", event.cookie.name, "new cookie has the expected name");
browser.test.assertEq("one-again", event.cookie.value, "new cookie has the expected value");
browser.test.notifyPass("cookie-expiry");
}
});
setTimeout(() => {
browser.test.sendMessage("change-cookies");
}, 1000);
}
let domain = ".example.com";
let extension = ExtensionTestUtils.loadExtension({
manifest: {
"permissions": ["http://example.com/", "cookies"],
},
background: `(${background})()`,
});
let cookieSvc = SpecialPowers.Services.cookies;
let cookie = {
host: domain,
name: "first",
path: "/",
};
do {
cookieSvc.add(cookie.host, cookie.path, cookie.name, "one", false, false, false, Date.now() / 1000 + 1);
} while (!cookieSvc.cookieExists(cookie));
yield extension.startup();
yield extension.awaitMessage("change-cookies");
cookieSvc.add(cookie.host, cookie.path, cookie.name, "one-again", false, false, false, Date.now() / 1000 + 10);
yield extension.awaitFinish("cookie-expiry");
yield extension.unload();
});
</script>
</body>