summaryrefslogtreecommitdiffstats
path: root/netwerk/test/mochitests/file_documentcookie_maxage_chromescript.js
blob: dc1e8eb05f3568b46765e69ae3ea569ded414d42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* eslint-env mozilla/chrome-script */

"use strict";

function getCookieService() {
  // eslint-disable-next-line mozilla/use-services
  return Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager);
}

function getCookies(cs) {
  let cookies = [];
  for (let cookie of cs.cookies) {
    cookies.push({
      host: cookie.host,
      path: cookie.path,
      name: cookie.name,
      value: cookie.value,
      expires: cookie.expires,
    });
  }
  return cookies;
}

function removeAllCookies(cs) {
  cs.removeAll();
}

addMessageListener("init", _ => {
  let cs = getCookieService();
  removeAllCookies(cs);
  sendAsyncMessage("init:return");
});

addMessageListener("getCookies", _ => {
  let cs = getCookieService();
  let cookies = getCookies(cs);
  removeAllCookies(cs);
  sendAsyncMessage("getCookies:return", { cookies });
});

addMessageListener("shutdown", _ => {
  let cs = getCookieService();
  removeAllCookies(cs);
  sendAsyncMessage("shutdown:return");
});