tor-browser

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

browser_storage_basic.js (5331B)


      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 // Entries that should be present in the tree for this test
      9 // Format for each entry in the array :
     10 // [
     11 //   ["path", "to", "tree", "item"], - The path to the tree item to click formed
     12 //                                     by id of each item
     13 //   ["key_value1", "key_value2", ...] - The value of the first (unique) column
     14 //                                       for each row in the table corresponding
     15 //                                       to the tree item selected.
     16 // ]
     17 // These entries are formed by the cookies, local storage, session storage and
     18 // indexedDB entries created in storage-listings.html,
     19 // storage-secured-iframe.html and storage-unsecured-iframe.html
     20 
     21 "use strict";
     22 
     23 const testCases = [
     24  [
     25    ["cookies", "http://test1.example.org"],
     26    [
     27      getCookieId("c1", "test1.example.org", "/browser"),
     28      getCookieId("cs2", ".example.org", "/"),
     29      getCookieId("c3", "test1.example.org", "/"),
     30      getCookieId("c4", ".example.org", "/"),
     31      getCookieId("uc1", ".example.org", "/"),
     32      getCookieId("uc2", ".example.org", "/"),
     33    ],
     34  ],
     35  [
     36    ["cookies", "https://sectest1.example.org"],
     37    [
     38      getCookieId("uc1", ".example.org", "/"),
     39      getCookieId("uc2", ".example.org", "/"),
     40      getCookieId("cs2", ".example.org", "/"),
     41      getCookieId("c4", ".example.org", "/"),
     42      getCookieId(
     43        "sc1",
     44        "sectest1.example.org",
     45        "/browser/devtools/client/storage/test"
     46      ),
     47      getCookieId(
     48        "sc2",
     49        "sectest1.example.org",
     50        "/browser/devtools/client/storage/test"
     51      ),
     52    ],
     53  ],
     54  [
     55    ["localStorage", "http://test1.example.org"],
     56    ["key", "ls1", "ls2"],
     57  ],
     58  [["localStorage", "http://sectest1.example.org"], ["iframe-u-ls1"]],
     59  [["localStorage", "https://sectest1.example.org"], ["iframe-s-ls1"]],
     60  [
     61    ["sessionStorage", "http://test1.example.org"],
     62    ["key", "ss1"],
     63  ],
     64  [
     65    ["sessionStorage", "http://sectest1.example.org"],
     66    ["iframe-u-ss1", "iframe-u-ss2"],
     67  ],
     68  [["sessionStorage", "https://sectest1.example.org"], ["iframe-s-ss1"]],
     69  [
     70    ["indexedDB", "http://test1.example.org"],
     71    ["idb1 (default)", "idb2 (default)"],
     72  ],
     73  [
     74    ["indexedDB", "http://test1.example.org", "idb1 (default)"],
     75    ["obj1", "obj2"],
     76  ],
     77  [["indexedDB", "http://test1.example.org", "idb2 (default)"], ["obj3"]],
     78  [
     79    ["indexedDB", "http://test1.example.org", "idb1 (default)", "obj1"],
     80    [1, 2, 3],
     81  ],
     82  [["indexedDB", "http://test1.example.org", "idb1 (default)", "obj2"], [1]],
     83  [["indexedDB", "http://test1.example.org", "idb2 (default)", "obj3"], []],
     84  [["indexedDB", "http://sectest1.example.org"], []],
     85  [
     86    ["indexedDB", "https://sectest1.example.org"],
     87    ["idb-s1 (default)", "idb-s2 (default)"],
     88  ],
     89  [
     90    ["indexedDB", "https://sectest1.example.org", "idb-s1 (default)"],
     91    ["obj-s1"],
     92  ],
     93  [
     94    ["indexedDB", "https://sectest1.example.org", "idb-s2 (default)"],
     95    ["obj-s2"],
     96  ],
     97  [
     98    ["indexedDB", "https://sectest1.example.org", "idb-s1 (default)", "obj-s1"],
     99    [6, 7],
    100  ],
    101  [
    102    ["indexedDB", "https://sectest1.example.org", "idb-s2 (default)", "obj-s2"],
    103    [16],
    104  ],
    105  [
    106    ["Cache", "http://test1.example.org", "plop"],
    107    [
    108      MAIN_DOMAIN + "404_cached_file.js",
    109      MAIN_DOMAIN + "browser_storage_basic.js",
    110    ],
    111  ],
    112 ];
    113 
    114 /**
    115 * Test that the desired number of tree items are present
    116 */
    117 function testTree() {
    118  const doc = gPanelWindow.document;
    119  for (const [item] of testCases) {
    120    ok(
    121      doc.querySelector("[data-id='" + JSON.stringify(item) + "']"),
    122      `Tree item ${item.toSource()} should be present in the storage tree`
    123    );
    124  }
    125 }
    126 
    127 /**
    128 * Test that correct table entries are shown for each of the tree item
    129 */
    130 async function testTables() {
    131  const doc = gPanelWindow.document;
    132  // Expand all nodes so that the synthesized click event actually works
    133  gUI.tree.expandAll();
    134 
    135  // First tree item is already selected so no clicking and waiting for update
    136  for (const id of testCases[0][1]) {
    137    ok(
    138      doc.querySelector(".table-widget-cell[data-id='" + id + "']"),
    139      "Table item " + id + " should be present"
    140    );
    141  }
    142 
    143  // Click rest of the tree items and wait for the table to be updated
    144  for (const [treeItem, items] of testCases.slice(1)) {
    145    await selectTreeItem(treeItem);
    146 
    147    // Check whether correct number of items are present in the table
    148    is(
    149      doc.querySelectorAll(
    150        ".table-widget-column:first-of-type .table-widget-cell"
    151      ).length,
    152      items.length,
    153      "Number of items in table is correct"
    154    );
    155 
    156    // Check if all the desired items are present in the table
    157    for (const id of items) {
    158      ok(
    159        doc.querySelector(".table-widget-cell[data-id='" + id + "']"),
    160        "Table item " + id + " should be present"
    161      );
    162    }
    163  }
    164 }
    165 
    166 add_task(async function () {
    167  await pushPref("dom.security.https_first", false);
    168  await openTabAndSetupStorage(MAIN_DOMAIN + "storage-listings.html");
    169 
    170  testTree();
    171  await testTables();
    172 });