summaryrefslogtreecommitdiffstats
path: root/browser/components/sessionstore/test/browser_global_store.js
blob: 99aa6721804d573fb677d2aa99db27a03752d894 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Tests the API for saving global session data.
add_task(async function () {
  const key1 = "Unique name 1: " + Date.now();
  const key2 = "Unique name 2: " + Date.now();
  const value1 = "Unique value 1: " + Math.random();
  const value2 = "Unique value 2: " + Math.random();

  let global = {};
  global[key1] = value1;

  const testState = {
    windows: [
      {
        tabs: [
          { entries: [{ url: "about:blank", triggeringPrincipal_base64 }] },
        ],
      },
    ],
    global,
  };

  function testRestoredState() {
    is(
      ss.getCustomGlobalValue(key1),
      value1,
      "restored state has global value"
    );
  }

  function testGlobalStore() {
    is(ss.getCustomGlobalValue(key2), "", "global value initially not set");

    ss.setCustomGlobalValue(key2, value1);
    is(ss.getCustomGlobalValue(key2), value1, "retreived value matches stored");

    ss.setCustomGlobalValue(key2, value2);
    is(
      ss.getCustomGlobalValue(key2),
      value2,
      "previously stored value was overwritten"
    );

    ss.deleteCustomGlobalValue(key2);
    is(ss.getCustomGlobalValue(key2), "", "global value was deleted");
  }

  await promiseBrowserState(testState);
  testRestoredState();
  testGlobalStore();
});