summaryrefslogtreecommitdiffstats
path: root/devtools/client/storage/test/browser_storage_search.js
blob: 1f7c8a5c063d4882ffbf1d4f0552e8042e2208c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Tests the filter search box in the storage inspector
"use strict";

add_task(async function () {
  await openTabAndSetupStorage(MAIN_DOMAIN_SECURED + "storage-search.html");

  gUI.tree.expandAll();
  await selectTreeItem(["cookies", "https://test1.example.org"]);

  showColumn("expires", false);
  showColumn("host", false);
  showColumn("isHttpOnly", false);
  showColumn("lastAccessed", false);
  showColumn("path", false);

  // Results: 0=hidden, 1=visible
  const testcases = [
    // Test that search isn't case-sensitive
    {
      value: "FoO",
      results: [0, 0, 1, 1, 0, 1, 0],
    },
    {
      value: "OR",
      results: [0, 1, 0, 0, 0, 1, 0],
    },
    {
      value: "aNImAl",
      results: [0, 1, 0, 0, 0, 0, 0],
    },
    // Test numbers
    {
      value: "01",
      results: [1, 0, 0, 0, 0, 0, 1],
    },
    {
      value: "2016",
      results: [0, 0, 0, 0, 0, 0, 1],
    },
    {
      value: "56789",
      results: [1, 0, 0, 0, 0, 0, 0],
    },
    // Test filtering by value
    {
      value: "horse",
      results: [0, 1, 0, 0, 0, 0, 0],
    },
    {
      value: "$$$",
      results: [0, 0, 0, 0, 1, 0, 0],
    },
    {
      value: "bar",
      results: [0, 0, 1, 1, 0, 0, 0],
    },
    // Test input with whitespace
    {
      value: "energy b",
      results: [0, 0, 1, 0, 0, 0, 0],
    },
    // Test no input at all
    {
      value: "",
      results: [1, 1, 1, 1, 1, 1, 1],
    },
    // Test input that matches nothing
    {
      value: "input that matches nothing",
      results: [0, 0, 0, 0, 0, 0, 0],
    },
  ];

  const testcasesAfterHiding = [
    // Test that search isn't case-sensitive
    {
      value: "OR",
      results: [0, 0, 0, 0, 0, 1, 0],
    },
    {
      value: "01",
      results: [1, 0, 0, 0, 0, 0, 0],
    },
    {
      value: "2016",
      results: [0, 0, 0, 0, 0, 0, 0],
    },
    {
      value: "56789",
      results: [0, 0, 0, 0, 0, 0, 0],
    },
    // Test filtering by value
    {
      value: "horse",
      results: [0, 0, 0, 0, 0, 0, 0],
    },
    {
      value: "$$$",
      results: [0, 0, 0, 0, 0, 0, 0],
    },
    {
      value: "bar",
      results: [0, 0, 0, 0, 0, 0, 0],
    },
    // Test input with whitespace
    {
      value: "energy b",
      results: [0, 0, 0, 0, 0, 0, 0],
    },
  ];

  runTests(testcases);
  showColumn("value", false);
  runTests(testcasesAfterHiding);
});

function runTests(testcases) {
  const $$ = sel => gPanelWindow.document.querySelectorAll(sel);
  const names = $$("#name .table-widget-cell");
  const rows = $$("#value .table-widget-cell");
  for (const testcase of testcases) {
    const { value, results } = testcase;

    info(`Testing input: ${value}`);

    gUI.searchBox.value = value;
    gUI.filterItems();

    for (let i = 0; i < rows.length; i++) {
      info(`Testing row ${i} for "${value}"`);
      info(`key: ${names[i].value}, value: ${rows[i].value}`);
      const state = results[i] ? "visible" : "hidden";
      is(
        rows[i].hasAttribute("hidden"),
        !results[i],
        `Row ${i} should be ${state}`
      );
    }
  }
}