tor-browser

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

browser_storage_empty_objectstores.js (2758B)


      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 assert that the storage tree and table corresponding to each
      6 // item in the storage tree is correctly displayed.
      7 
      8 "use strict";
      9 
     10 // Entries that should be present in the tree for this test
     11 // Format for each entry in the array:
     12 // [
     13 //   ["path", "to", "tree", "item"],
     14 //   - The path to the tree item to click formed by id of each item
     15 //   ["key_value1", "key_value2", ...]
     16 //   - The value of the first (unique) column for each row in the table
     17 //     corresponding to the tree item selected.
     18 // ]
     19 // These entries are formed by the cookies, local storage, session storage and
     20 // indexedDB entries created in storage-listings.html,
     21 // storage-secured-iframe.html and storage-unsecured-iframe.html
     22 const storeItems = [
     23  [
     24    ["indexedDB", "https://test1.example.org"],
     25    ["idb1 (default)", "idb2 (default)"],
     26  ],
     27  [
     28    ["indexedDB", "https://test1.example.org", "idb1 (default)"],
     29    ["obj1", "obj2"],
     30  ],
     31  [["indexedDB", "https://test1.example.org", "idb2 (default)"], []],
     32  [
     33    ["indexedDB", "https://test1.example.org", "idb1 (default)", "obj1"],
     34    [1, 2, 3],
     35  ],
     36  [["indexedDB", "https://test1.example.org", "idb1 (default)", "obj2"], [1]],
     37 ];
     38 
     39 /**
     40 * Test that the desired number of tree items are present
     41 */
     42 function testTree() {
     43  const doc = gPanelWindow.document;
     44  for (const [item] of storeItems) {
     45    ok(
     46      doc.querySelector(`[data-id='${JSON.stringify(item)}']`),
     47      `Tree item ${item} should be present in the storage tree`
     48    );
     49  }
     50 }
     51 
     52 /**
     53 * Test that correct table entries are shown for each of the tree item
     54 */
     55 const testTables = async function () {
     56  const doc = gPanelWindow.document;
     57  // Expand all nodes so that the synthesized click event actually works
     58  gUI.tree.expandAll();
     59 
     60  // Click the tree items and wait for the table to be updated
     61  for (const [item, ids] of storeItems) {
     62    await selectTreeItem(item);
     63 
     64    // Check whether correct number of items are present in the table
     65    is(
     66      doc.querySelectorAll(
     67        ".table-widget-column:first-of-type .table-widget-cell"
     68      ).length,
     69      ids.length,
     70      "Number of items in table is correct"
     71    );
     72 
     73    // Check if all the desired items are present in the table
     74    for (const id of ids) {
     75      ok(
     76        doc.querySelector(".table-widget-cell[data-id='" + id + "']"),
     77        `Table item ${id} should be present`
     78      );
     79    }
     80  }
     81 };
     82 
     83 add_task(async function () {
     84  await openTabAndSetupStorage(
     85    MAIN_DOMAIN_SECURED + "storage-empty-objectstores.html"
     86  );
     87 
     88  testTree();
     89  await testTables();
     90 });