tor-browser

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

browser_storage_search.js (3097B)


      1 // Tests the filter search box in the storage inspector
      2 "use strict";
      3 
      4 add_task(async function () {
      5  await openTabAndSetupStorage(MAIN_DOMAIN_SECURED + "storage-search.html");
      6 
      7  gUI.tree.expandAll();
      8  await selectTreeItem(["cookies", "https://test1.example.org"]);
      9 
     10  showColumn("expires", false);
     11  showColumn("host", false);
     12  showColumn("isHttpOnly", false);
     13  showColumn("lastAccessed", false);
     14  showColumn("path", false);
     15 
     16  // Results: 0=hidden, 1=visible
     17  const testcases = [
     18    // Test that search isn't case-sensitive
     19    {
     20      value: "FoO",
     21      results: [0, 0, 1, 1, 0, 1, 0],
     22    },
     23    {
     24      value: "OR",
     25      results: [0, 1, 0, 0, 0, 1, 0],
     26    },
     27    {
     28      value: "aNImAl",
     29      results: [0, 1, 0, 0, 0, 0, 0],
     30    },
     31    // Test numbers
     32    {
     33      value: "01",
     34      results: [1, 0, 0, 0, 0, 0, 1],
     35    },
     36    {
     37      value: "2016",
     38      results: [0, 0, 0, 0, 0, 0, 1],
     39    },
     40    {
     41      value: "56789",
     42      results: [1, 0, 0, 0, 0, 0, 0],
     43    },
     44    // Test filtering by value
     45    {
     46      value: "horse",
     47      results: [0, 1, 0, 0, 0, 0, 0],
     48    },
     49    {
     50      value: "$$$",
     51      results: [0, 0, 0, 0, 1, 0, 0],
     52    },
     53    {
     54      value: "bar",
     55      results: [0, 0, 1, 1, 0, 0, 0],
     56    },
     57    // Test input with whitespace
     58    {
     59      value: "energy b",
     60      results: [0, 0, 1, 0, 0, 0, 0],
     61    },
     62    // Test no input at all
     63    {
     64      value: "",
     65      results: [1, 1, 1, 1, 1, 1, 1],
     66    },
     67    // Test input that matches nothing
     68    {
     69      value: "input that matches nothing",
     70      results: [0, 0, 0, 0, 0, 0, 0],
     71    },
     72  ];
     73 
     74  const testcasesAfterHiding = [
     75    // Test that search isn't case-sensitive
     76    {
     77      value: "OR",
     78      results: [0, 0, 0, 0, 0, 1, 0],
     79    },
     80    {
     81      value: "01",
     82      results: [1, 0, 0, 0, 0, 0, 0],
     83    },
     84    {
     85      value: "2016",
     86      results: [0, 0, 0, 0, 0, 0, 0],
     87    },
     88    {
     89      value: "56789",
     90      results: [0, 0, 0, 0, 0, 0, 0],
     91    },
     92    // Test filtering by value
     93    {
     94      value: "horse",
     95      results: [0, 0, 0, 0, 0, 0, 0],
     96    },
     97    {
     98      value: "$$$",
     99      results: [0, 0, 0, 0, 0, 0, 0],
    100    },
    101    {
    102      value: "bar",
    103      results: [0, 0, 0, 0, 0, 0, 0],
    104    },
    105    // Test input with whitespace
    106    {
    107      value: "energy b",
    108      results: [0, 0, 0, 0, 0, 0, 0],
    109    },
    110  ];
    111 
    112  runTests(testcases);
    113  showColumn("value", false);
    114  runTests(testcasesAfterHiding);
    115 });
    116 
    117 function runTests(testcases) {
    118  const $$ = sel => gPanelWindow.document.querySelectorAll(sel);
    119  const names = $$("#name .table-widget-cell");
    120  const rows = $$("#value .table-widget-cell");
    121  for (const testcase of testcases) {
    122    const { value, results } = testcase;
    123 
    124    info(`Testing input: ${value}`);
    125 
    126    gUI.searchBox.value = value;
    127    gUI.filterItems();
    128 
    129    for (let i = 0; i < rows.length; i++) {
    130      info(`Testing row ${i} for "${value}"`);
    131      info(`key: ${names[i].value}, value: ${rows[i].value}`);
    132      const state = results[i] ? "visible" : "hidden";
    133      is(
    134        rows[i].hasAttribute("hidden"),
    135        !results[i],
    136        `Row ${i} should be ${state}`
    137      );
    138    }
    139  }
    140 }