summaryrefslogtreecommitdiffstats
path: root/dom/fs/test/mochitest/head.js
blob: 167e7c0c529aa4a4a82fd962a74fb806e0039839 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

async function require_module(id) {
  if (!require_module.moduleLoader) {
    const { ModuleLoader } = await import(
      "/tests/dom/quota/test/modules/ModuleLoader.mjs"
    );

    const base = window.location.href;

    const depth = "../../../../";

    const { Assert } = await import("/tests/dom/quota/test/modules/Assert.mjs");

    const { Utils } = await import("/tests/dom/quota/test/modules/Utils.mjs");

    const proto = {
      Assert,
      Cr: SpecialPowers.Cr,
      navigator,
      TextEncoder,
      Utils,
    };

    require_module.moduleLoader = new ModuleLoader(base, depth, proto);
  }

  return require_module.moduleLoader.require(id);
}

async function run_test_in_worker(script) {
  const { runTestInWorker } = await import(
    "/tests/dom/quota/test/modules/WorkerDriver.mjs"
  );

  const base = window.location.href;

  const listener = {
    onOk(value, message) {
      ok(value, message);
    },
    onIs(a, b, message) {
      is(a, b, message);
    },
    onInfo(message) {
      info(message);
    },
  };

  await runTestInWorker(script, base, listener);
}

// XXX This can be removed once we use <profile>/storage. See bug 1798015.
async function removeAllEntries() {
  const root = await navigator.storage.getDirectory();
  for await (const value of root.values()) {
    root.removeEntry(value.name, { recursive: true });
  }
}

add_setup(async function () {
  const { setStoragePrefs, clearStoragesForOrigin } = await import(
    "/tests/dom/quota/test/modules/StorageUtils.mjs"
  );

  const optionalPrefsToSet = [
    ["dom.fs.enabled", true],
    ["dom.fs.writable_file_stream.enabled", true],
    ["dom.workers.modules.enabled", true],
  ];

  await setStoragePrefs(optionalPrefsToSet);

  SimpleTest.registerCleanupFunction(async function () {
    await removeAllEntries();

    await clearStoragesForOrigin(SpecialPowers.wrap(document).nodePrincipal);
  });
});