summaryrefslogtreecommitdiffstats
path: root/dom/quota/test/modules/system/Utils.sys.mjs
blob: 8c5430aa0658d54a33dca80837621a5dd85a3adc (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
/**
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

import {
  getUsageForOrigin,
  resetStorage,
} from "resource://testing-common/dom/quota/test/modules/StorageUtils.sys.mjs";

export const Utils = {
  async getCachedOriginUsage() {
    const principal = Cc["@mozilla.org/systemprincipal;1"].createInstance(
      Ci.nsIPrincipal
    );
    const result = await getUsageForOrigin(principal, true);
    return result.usage;
  },

  async shrinkStorageSize(size) {
    Services.prefs.setIntPref(
      "dom.quotaManager.temporaryStorage.fixedLimit",
      size
    );

    const result = await resetStorage();
    return result;
  },

  async restoreStorageSize() {
    Services.prefs.clearUserPref(
      "dom.quotaManager.temporaryStorage.fixedLimit"
    );

    const result = await resetStorage();
    return result;
  },
};