tor-browser

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

browser_storage_cookies_add.js (2583B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 // Basic test to check the adding of cookies.
      6 
      7 "use strict";
      8 
      9 add_task(async function () {
     10  const TEST_URL = MAIN_DOMAIN + "storage-cookies.html";
     11  await openTabAndSetupStorage(TEST_URL);
     12  showAllColumns(true);
     13 
     14  const rowId = await performAdd(["cookies", "http://test1.example.org"]);
     15  checkCookieData(rowId);
     16 
     17  await performAdd(["cookies", "http://test1.example.org"]);
     18  await performAdd(["cookies", "http://test1.example.org"]);
     19  await performAdd(["cookies", "http://test1.example.org"]);
     20  await performAdd(["cookies", "http://test1.example.org"]);
     21 
     22  info("Check it does work in private tabs too");
     23  const privateWindow = await BrowserTestUtils.openNewBrowserWindow({
     24    private: true,
     25  });
     26  ok(PrivateBrowsingUtils.isWindowPrivate(privateWindow), "window is private");
     27  const privateTab = await addTab(TEST_URL, { window: privateWindow });
     28  await openStoragePanel({ tab: privateTab });
     29  const privateTabRowId = await performAdd([
     30    "cookies",
     31    "http://test1.example.org",
     32  ]);
     33  checkCookieData(privateTabRowId);
     34 
     35  await performAdd(["cookies", "http://test1.example.org"]);
     36  privateWindow.close();
     37 });
     38 
     39 function checkCookieData(rowId) {
     40  is(getCellValue(rowId, "value"), "value", "value is correct");
     41  is(getCellValue(rowId, "host"), "test1.example.org", "host is correct");
     42  is(getCellValue(rowId, "path"), "/", "path is correct");
     43  const actualExpiry = Math.floor(
     44    new Date(getCellValue(rowId, "expires")) / 1000
     45  );
     46  const ONE_DAY_IN_SECONDS = 60 * 60 * 24;
     47 
     48  const creationTime = Math.floor(
     49    new Date(getCellValue(rowId, "creationTime")) / 1000
     50  );
     51  Assert.lessOrEqual(
     52    actualExpiry - (creationTime + ONE_DAY_IN_SECONDS),
     53    2,
     54    "expiry is in expected range"
     55  );
     56 
     57  const updateTime = Math.floor(
     58    new Date(getCellValue(rowId, "updateTime")) / 1000
     59  );
     60  Assert.equal(
     61    creationTime,
     62    updateTime,
     63    "Update time matches the creation time"
     64  );
     65  Assert.lessOrEqual(
     66    actualExpiry - (updateTime + ONE_DAY_IN_SECONDS),
     67    2,
     68    "expiry is in expected range"
     69  );
     70 
     71  is(getCellValue(rowId, "size"), "43", "size is correct");
     72  is(getCellValue(rowId, "isHttpOnly"), "false", "httpOnly is not set");
     73  is(getCellValue(rowId, "isSecure"), "false", "secure is not set");
     74  is(getCellValue(rowId, "sameSite"), "Lax", "sameSite is Lax");
     75  is(getCellValue(rowId, "hostOnly"), "true", "hostOnly is not set");
     76 }