tor-browser

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

browser_storage_basic_usercontextid_2.js (4719B)


      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 // A test to check that the storage inspector is working correctly with
      6 // userContextId.
      7 
      8 "use strict";
      9 
     10 const testCasesUserContextId = [
     11  [
     12    ["cookies", "http://test1.example.org"],
     13    [
     14      getCookieId("c1uc1", "test1.example.org", "/browser"),
     15      getCookieId("cs2uc1", ".example.org", "/"),
     16      getCookieId("c3uc1", "test1.example.org", "/"),
     17      getCookieId("uc1uc1", ".example.org", "/"),
     18    ],
     19  ],
     20  [
     21    ["cookies", "https://sectest1.example.org"],
     22    [
     23      getCookieId("uc1uc1", ".example.org", "/"),
     24      getCookieId("cs2uc1", ".example.org", "/"),
     25      getCookieId(
     26        "sc1uc1",
     27        "sectest1.example.org",
     28        "/browser/devtools/client/storage/test"
     29      ),
     30    ],
     31  ],
     32  [
     33    ["localStorage", "http://test1.example.org"],
     34    ["ls1uc1", "ls2uc1"],
     35  ],
     36  [["localStorage", "http://sectest1.example.org"], ["iframe-u-ls1uc1"]],
     37  [["localStorage", "https://sectest1.example.org"], ["iframe-s-ls1uc1"]],
     38  [["sessionStorage", "http://test1.example.org"], ["ss1uc1"]],
     39  [
     40    ["sessionStorage", "http://sectest1.example.org"],
     41    ["iframe-u-ss1uc1", "iframe-u-ss2uc1"],
     42  ],
     43  [["sessionStorage", "https://sectest1.example.org"], ["iframe-s-ss1uc1"]],
     44  [
     45    ["indexedDB", "http://test1.example.org"],
     46    ["idb1uc1 (default)", "idb2uc1 (default)"],
     47  ],
     48  [
     49    ["indexedDB", "http://test1.example.org", "idb1uc1 (default)"],
     50    ["obj1uc1", "obj2uc1"],
     51  ],
     52  [["indexedDB", "http://test1.example.org", "idb2uc1 (default)"], ["obj3uc1"]],
     53  [
     54    ["indexedDB", "http://test1.example.org", "idb1uc1 (default)", "obj1uc1"],
     55    [1, 2, 3],
     56  ],
     57  [
     58    ["indexedDB", "http://test1.example.org", "idb1uc1 (default)", "obj2uc1"],
     59    [1],
     60  ],
     61  [
     62    ["indexedDB", "http://test1.example.org", "idb2uc1 (default)", "obj3uc1"],
     63    [],
     64  ],
     65  [["indexedDB", "http://sectest1.example.org"], []],
     66  [
     67    ["indexedDB", "https://sectest1.example.org"],
     68    ["idb-s1uc1 (default)", "idb-s2uc1 (default)"],
     69  ],
     70  [
     71    ["indexedDB", "https://sectest1.example.org", "idb-s1uc1 (default)"],
     72    ["obj-s1uc1"],
     73  ],
     74  [
     75    ["indexedDB", "https://sectest1.example.org", "idb-s2uc1 (default)"],
     76    ["obj-s2uc1"],
     77  ],
     78  [
     79    [
     80      "indexedDB",
     81      "https://sectest1.example.org",
     82      "idb-s1uc1 (default)",
     83      "obj-s1uc1",
     84    ],
     85    [6, 7],
     86  ],
     87  [
     88    [
     89      "indexedDB",
     90      "https://sectest1.example.org",
     91      "idb-s2uc1 (default)",
     92      "obj-s2uc1",
     93    ],
     94    [16],
     95  ],
     96  [
     97    ["Cache", "http://test1.example.org", "plopuc1"],
     98    [
     99      MAIN_DOMAIN + "404_cached_file.js",
    100      MAIN_DOMAIN + "browser_storage_basic.js",
    101    ],
    102  ],
    103 ];
    104 
    105 /**
    106 * Test that the desired number of tree items are present
    107 */
    108 function testTree(tests) {
    109  const doc = gPanelWindow.document;
    110  for (const [item] of tests) {
    111    ok(
    112      doc.querySelector("[data-id='" + JSON.stringify(item) + "']"),
    113      `Tree item ${item.toSource()} should be present in the storage tree`
    114    );
    115  }
    116 }
    117 
    118 /**
    119 * Test that correct table entries are shown for each of the tree item
    120 */
    121 async function testTables(tests) {
    122  const doc = gPanelWindow.document;
    123  // Expand all nodes so that the synthesized click event actually works
    124  gUI.tree.expandAll();
    125 
    126  // First tree item is already selected so no clicking and waiting for update
    127  for (const id of tests[0][1]) {
    128    ok(
    129      doc.querySelector(".table-widget-cell[data-id='" + id + "']"),
    130      "Table item " + id + " should be present"
    131    );
    132  }
    133 
    134  // Click rest of the tree items and wait for the table to be updated
    135  for (const [treeItem, items] of tests.slice(1)) {
    136    await selectTreeItem(treeItem);
    137 
    138    // Check whether correct number of items are present in the table
    139    is(
    140      doc.querySelectorAll(
    141        ".table-widget-column:first-of-type .table-widget-cell"
    142      ).length,
    143      items.length,
    144      "Number of items in table is correct"
    145    );
    146 
    147    // Check if all the desired items are present in the table
    148    for (const id of items) {
    149      ok(
    150        doc.querySelector(".table-widget-cell[data-id='" + id + "']"),
    151        "Table item " + id + " should be present"
    152      );
    153    }
    154  }
    155 }
    156 
    157 add_task(async function () {
    158  // storage-listings.html explicitly mixes secure and insecure frames.
    159  // We should not enforce https for tests using this page.
    160  await pushPref("dom.security.https_first", false);
    161 
    162  await openTabAndSetupStorage(
    163    MAIN_DOMAIN + "storage-listings-usercontextid.html",
    164    { userContextId: 1 }
    165  );
    166 
    167  testTree(testCasesUserContextId);
    168  await testTables(testCasesUserContextId);
    169 });