tor-browser

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

test_stringLength.js (1859B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 add_task(async function testSteps() {
      7  const principal = getPrincipal("http://example.org");
      8 
      9  const data = {};
     10  data.key = "foobar";
     11  data.secondKey = "foobaz";
     12  data.value = {
     13    length: 25637,
     14  };
     15  data.usage = data.key.length + data.value.length;
     16 
     17  async function checkUsage(expectedUsage) {
     18    info("Checking usage");
     19 
     20    // This forces any pending changes to be flushed to disk.  It also forces
     21    // data to be reloaded from disk at next localStorage API call.
     22    request = resetClient(principal);
     23    await requestFinished(request);
     24 
     25    request = getOriginUsage(principal);
     26    await requestFinished(request);
     27 
     28    is(request.result.usage, expectedUsage, "Correct usage");
     29  }
     30 
     31  info("Setting pref");
     32 
     33  Services.prefs.setBoolPref(
     34    "dom.storage.enable_unsupported_legacy_implementation",
     35    false
     36  );
     37 
     38  info("Stage 1 - Checking usage after profile installation");
     39 
     40  info("Clearing");
     41 
     42  let request = clear();
     43  await requestFinished(request);
     44 
     45  info("Installing package");
     46 
     47  // The profile contains storage.sqlite and webappsstore.sqlite.
     48  installPackage("stringLength_profile");
     49 
     50  await checkUsage(0);
     51 
     52  info("Stage 2 - Checking usage after archived data migration");
     53 
     54  info("Opening database");
     55 
     56  let storage = getLocalStorage(principal);
     57  storage.open();
     58 
     59  await checkUsage(data.usage);
     60 
     61  info("Stage 3 - Checking usage after copying the value");
     62 
     63  info("Adding a second copy of the value");
     64 
     65  let value = storage.getItem(data.key);
     66  storage.setItem(data.secondKey, value);
     67 
     68  await checkUsage(2 * data.usage);
     69 
     70  info("Stage 4 - Checking length of the copied value");
     71 
     72  value = storage.getItem(data.secondKey);
     73  Assert.strictEqual(value.length, data.value.length, "Correct string length");
     74 });