tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_global_store.js (1354B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Tests the API for saving global session data.
      5 add_task(async function () {
      6  const key1 = "Unique name 1: " + Date.now();
      7  const key2 = "Unique name 2: " + Date.now();
      8  const value1 = "Unique value 1: " + Math.random();
      9  const value2 = "Unique value 2: " + Math.random();
     10 
     11  let global = {};
     12  global[key1] = value1;
     13 
     14  const testState = {
     15    windows: [
     16      {
     17        tabs: [
     18          { entries: [{ url: "about:blank", triggeringPrincipal_base64 }] },
     19        ],
     20      },
     21    ],
     22    global,
     23  };
     24 
     25  function testRestoredState() {
     26    is(
     27      ss.getCustomGlobalValue(key1),
     28      value1,
     29      "restored state has global value"
     30    );
     31  }
     32 
     33  function testGlobalStore() {
     34    is(ss.getCustomGlobalValue(key2), "", "global value initially not set");
     35 
     36    ss.setCustomGlobalValue(key2, value1);
     37    is(ss.getCustomGlobalValue(key2), value1, "retreived value matches stored");
     38 
     39    ss.setCustomGlobalValue(key2, value2);
     40    is(
     41      ss.getCustomGlobalValue(key2),
     42      value2,
     43      "previously stored value was overwritten"
     44    );
     45 
     46    ss.deleteCustomGlobalValue(key2);
     47    is(ss.getCustomGlobalValue(key2), "", "global value was deleted");
     48  }
     49 
     50  await promiseBrowserState(testState);
     51  testRestoredState();
     52  testGlobalStore();
     53 });