tor-browser

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

test_groupLimit.js (2057B)


      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 groupLimitKB = 10 * 1024;
      8 
      9  const globalLimitKB = groupLimitKB * 5;
     10 
     11  const originLimit = 10 * 1024;
     12 
     13  const urls = [
     14    "http://example.com",
     15    "http://test1.example.com",
     16    "https://test2.example.com",
     17    "http://test3.example.com:8080",
     18  ];
     19 
     20  const data = {};
     21  data.sizeKB = 5 * 1024;
     22  data.key = "A";
     23  data.value = repeatChar(data.sizeKB * 1024 - data.key.length, ".");
     24  data.urlCount = groupLimitKB / data.sizeKB;
     25 
     26  info("Setting pref");
     27 
     28  Services.prefs.setBoolPref(
     29    "dom.storage.enable_unsupported_legacy_implementation",
     30    false
     31  );
     32  Services.prefs.setBoolPref("dom.storage.snapshot_reusing", false);
     33 
     34  info("Setting limits");
     35 
     36  setGlobalLimit(globalLimitKB);
     37 
     38  let request = clear();
     39  await requestFinished(request);
     40 
     41  setOriginLimit(originLimit);
     42 
     43  info("Getting storages");
     44 
     45  let storages = [];
     46  for (let i = 0; i < urls.length; i++) {
     47    let storage = getLocalStorage(getPrincipal(urls[i]));
     48    storages.push(storage);
     49  }
     50 
     51  info("Filling up the whole group");
     52 
     53  for (let i = 0; i < data.urlCount; i++) {
     54    storages[i].setItem(data.key, data.value);
     55    await returnToEventLoop();
     56  }
     57 
     58  info("Verifying no more data can be written");
     59 
     60  for (let i = 0; i < urls.length; i++) {
     61    try {
     62      storages[i].setItem("B", "");
     63      ok(false, "Should have thrown");
     64    } catch (ex) {
     65      ok(true, "Did throw");
     66      ok(DOMException.isInstance(ex), "Threw DOMException");
     67      is(ex.name, "QuotaExceededError", "Threw right DOMException");
     68      is(ex.code, NS_ERROR_DOM_QUOTA_EXCEEDED_ERR, "Threw with right code");
     69    }
     70  }
     71 
     72  info("Clearing first origin");
     73 
     74  storages[0].clear();
     75 
     76  // Let the internal snapshot finish (usage is not descreased until all
     77  // snapshots finish)..
     78  await returnToEventLoop();
     79 
     80  info("Verifying more data can be written");
     81 
     82  for (let i = 0; i < urls.length; i++) {
     83    storages[i].setItem("B", "");
     84  }
     85 });