summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/mochitest/head_unlimitedStorage.js
blob: dfec90b3e09ffd324c6e6b619c40e8a3bdd5c62a (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
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";

/* exported checkSitePermissions */

const { Services } = SpecialPowers;
const { NetUtil } = SpecialPowers.ChromeUtils.import(
  "resource://gre/modules/NetUtil.jsm"
);

function checkSitePermissions(uuid, expectedPermAction, assertMessage) {
  if (!uuid) {
    throw new Error(
      "checkSitePermissions should not be called with an undefined uuid"
    );
  }

  const baseURI = NetUtil.newURI(`moz-extension://${uuid}/`);
  const principal = Services.scriptSecurityManager.createContentPrincipal(
    baseURI,
    {}
  );

  const sitePermissions = {
    webextUnlimitedStorage: Services.perms.testPermissionFromPrincipal(
      principal,
      "WebExtensions-unlimitedStorage"
    ),
    persistentStorage: Services.perms.testPermissionFromPrincipal(
      principal,
      "persistent-storage"
    ),
  };

  for (const [sitePermissionName, actualPermAction] of Object.entries(
    sitePermissions
  )) {
    is(
      actualPermAction,
      expectedPermAction,
      `The extension "${sitePermissionName}" SitePermission ${assertMessage} as expected`
    );
  }
}