tor-browser

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

cookieStore_set_limit.https.any.js (2392B)


      1 // META: title=Cookie Store API: cookieStore.delete() return type
      2 // META: global=window,serviceworker
      3 
      4 'use strict';
      5 
      6 function cookieParamsWithNameAndValueLengths(nameLength, valueLength) {
      7  return { name: "t".repeat(nameLength), value: "1".repeat(valueLength) }
      8 }
      9 
     10 const scenarios = [
     11  {
     12    cookie: cookieParamsWithNameAndValueLengths(2048, 2048),
     13    expected: cookieParamsWithNameAndValueLengths(2048, 2048),
     14    name: "Set max-size cookie with largest possible name and value (4096 bytes)",
     15  },
     16  {
     17    cookie: cookieParamsWithNameAndValueLengths(4097, 1),
     18    name: "Ignore cookie with name larger than 4096 and 1 byte value",
     19  },
     20  {
     21    cookie: cookieParamsWithNameAndValueLengths(4096, 0),
     22    expected: cookieParamsWithNameAndValueLengths(4096, 0),
     23    name: "Set max-size value-less cookie",
     24  },
     25  {
     26    cookie: cookieParamsWithNameAndValueLengths(4097, 0),
     27    name: "Ignore value-less cookie with name larger than 4096 bytes",
     28  },
     29  {
     30    cookie: cookieParamsWithNameAndValueLengths(1, 4095),
     31    expected: cookieParamsWithNameAndValueLengths(1, 4095),
     32    name: "Set max-size cookie with largest possible value (4095 bytes)",
     33  },
     34  {
     35    cookie: cookieParamsWithNameAndValueLengths(1, 4096),
     36    name: "Ignore named cookie (with non-zero length) and value larger than 4095 bytes",
     37  },
     38  {
     39    cookie: cookieParamsWithNameAndValueLengths(4096, 1),
     40    name: "Ignore named cookie with length larger than 4095 bytes, and a non-zero value",
     41  },
     42  {
     43    cookie: cookieParamsWithNameAndValueLengths(0, 4096),
     44    expected: cookieParamsWithNameAndValueLengths(0, 4096),
     45    name: "Set max-size name-less cookie",
     46  },
     47  {
     48    cookie: cookieParamsWithNameAndValueLengths(0, 4097),
     49    name: "Ignore name-less cookie with value larger than 4096 bytes",
     50  },
     51  {
     52    cookie: cookieParamsWithNameAndValueLengths(0, 4097),
     53    name: "Ignore name-less cookie (without leading =) with value larger than 4096 bytes",
     54  },
     55 ];
     56 
     57 for (const scenario of scenarios) {
     58  promise_test(async testCase => {
     59    let value = "";
     60    try {
     61      await cookieStore.set(scenario.cookie.name, scenario.cookie.value);
     62      value = (await cookieStore.get(scenario.cookie.name))?.value;
     63      assert_equals(value, scenario.expected.value);
     64      await cookieStore.delete({ name: scenario.cookie.name });
     65    } catch(e) {
     66      assert_equals(scenario.expected, undefined);
     67    }
     68  }, scenario.name);
     69 }