tor-browser

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

browser_storage_basic_with_fragment.js (5641B)


      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 second basic test to assert that the storage tree and table corresponding
      6 // to each item in the storage tree is correctly displayed.
      7 
      8 // This test differs from browser_storage_basic.js because the URLs we load
      9 // include fragments e.g. http://example.com/test.js#abcdefg
     10 //                                                  ^^^^^^^^
     11 //                                                  fragment
     12 
     13 // Entries that should be present in the tree for this test
     14 // Format for each entry in the array :
     15 // [
     16 //   ["path", "to", "tree", "item"], - The path to the tree item to click formed
     17 //                                     by id of each item
     18 //   ["key_value1", "key_value2", ...] - The value of the first (unique) column
     19 //                                       for each row in the table corresponding
     20 //                                       to the tree item selected.
     21 // ]
     22 // These entries are formed by the cookies, local storage, session storage and
     23 // indexedDB entries created in storage-listings.html,
     24 // storage-secured-iframe.html and storage-unsecured-iframe.html
     25 
     26 "use strict";
     27 
     28 const testCases = [
     29  [
     30    ["cookies", "http://test1.example.org"],
     31    [
     32      getCookieId("c1", "test1.example.org", "/browser"),
     33      getCookieId("cs2", ".example.org", "/"),
     34      getCookieId("c3", "test1.example.org", "/"),
     35      getCookieId("uc1", ".example.org", "/"),
     36      getCookieId("uc2", ".example.org", "/"),
     37    ],
     38  ],
     39  [
     40    ["cookies", "https://sectest1.example.org"],
     41    [
     42      getCookieId("uc1", ".example.org", "/"),
     43      getCookieId("uc2", ".example.org", "/"),
     44      getCookieId("cs2", ".example.org", "/"),
     45      getCookieId(
     46        "sc1",
     47        "sectest1.example.org",
     48        "/browser/devtools/client/storage/test"
     49      ),
     50      getCookieId(
     51        "sc2",
     52        "sectest1.example.org",
     53        "/browser/devtools/client/storage/test"
     54      ),
     55    ],
     56  ],
     57  [
     58    ["localStorage", "http://test1.example.org"],
     59    ["ls1", "ls2"],
     60  ],
     61  [["localStorage", "http://sectest1.example.org"], ["iframe-u-ls1"]],
     62  [["localStorage", "https://sectest1.example.org"], ["iframe-s-ls1"]],
     63  [["sessionStorage", "http://test1.example.org"], ["ss1"]],
     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  // storage-listings.html explicitly mixes secure and insecure frames.
    168  // We should not enforce https for tests using this page.
    169  await pushPref("dom.security.https_first", false);
    170 
    171  await openTabAndSetupStorage(
    172    MAIN_DOMAIN + "storage-listings-with-fragment.html#abc"
    173  );
    174 
    175  testTree();
    176  await testTables();
    177 });