summaryrefslogtreecommitdiffstats
path: root/dom/localstorage/test/unit/test_preloading.js
blob: c3b7c808eb98cbadb8d79a5aa70e57737f472dba (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
83
84
85
86
87
/**
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

add_task(async function testSteps() {
  const principals = [
    getPrincipal("http://example.com", {}),
    getPrincipal("http://example.com", { privateBrowsingId: 1 }),
  ];

  async function isPreloaded(principal) {
    return Services.domStorageManager.isPreloaded(principal);
  }

  info("Setting prefs");

  Services.prefs.setBoolPref(
    "dom.storage.enable_unsupported_legacy_implementation",
    false
  );
  Services.prefs.setBoolPref("dom.storage.snapshot_reusing", false);

  for (const principal of principals) {
    info("Getting storage");

    let storage = getLocalStorage(principal);

    ok(
      !(await isPreloaded(principal)),
      "Data is not preloaded after getting storage"
    );

    info("Opening storage");

    storage.open();

    ok(await isPreloaded(principal), "Data is preloaded after opening storage");

    info("Closing storage");

    storage.close();

    if (principal.privateBrowsingId > 0) {
      ok(
        await isPreloaded(principal),
        "Data is still preloaded after closing storage"
      );

      info("Closing private session");

      Services.obs.notifyObservers(null, "last-pb-context-exited");

      ok(
        !(await isPreloaded(principal)),
        "Data is not preloaded anymore after closing private session"
      );
    } else {
      ok(
        !(await isPreloaded(principal)),
        "Data is not preloaded anymore after closing storage"
      );
    }

    info("Opening storage again");

    storage.open();

    ok(
      await isPreloaded(principal),
      "Data is preloaded after opening storage again"
    );

    info("Clearing origin");

    let request = clearOrigin(
      principal,
      principal.privateBrowsingId > 0 ? "private" : "default"
    );
    await requestFinished(request);

    ok(
      !(await isPreloaded(principal)),
      "Data is not preloaded after clearing origin"
    );
  }
});