summaryrefslogtreecommitdiffstats
path: root/devtools/client/storage/test/browser_storage_values.js
blob: 69dbacf5924c38fcf056e2509ce17f61ee65b21f (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// Test to verify that the values shown in sidebar are correct

// Format: [
//   <id of the table item to click> or <id array for tree item to select> or
//     null do click nothing,
//   null to skip checking value in variables view or a key value pair object
//     which will be asserted to exist in the storage sidebar,
//   true if the check is to be made in the parsed value section
// ]

"use strict";

const LONG_WORD = "a".repeat(1000);

const testCases = [
  [
    getCookieId("cs2", ".example.org", "/"),
    [
      { name: "cs2", value: "sessionCookie" },
      { name: "cs2.Path", value: "/" },
      { name: "cs2.HostOnly", value: "false" },
      { name: "cs2.HttpOnly", value: "false" },
      { name: "cs2.Domain", value: ".example.org" },
      { name: "cs2.Expires / Max-Age", value: "Session" },
      { name: "cs2.Secure", value: "false" },
    ],
  ],
  [
    getCookieId("c1", "test1.example.org", "/browser"),
    [
      { name: "c1", value: JSON.stringify(["foo", "Bar", { foo: "Bar" }]) },
      { name: "c1.Path", value: "/browser" },
      { name: "c1.HostOnly", value: "true" },
      { name: "c1.HttpOnly", value: "false" },
      { name: "c1.Domain", value: "test1.example.org" },
      {
        name: "c1.Expires / Max-Age",
        value: new Date(2000000000000).toUTCString(),
      },
      { name: "c1.Secure", value: "false" },
    ],
  ],
  [
    null,
    [
      { name: "c1", value: "Array" },
      { name: "c1.0", value: "foo" },
      { name: "c1.1", value: "Bar" },
      { name: "c1.2", value: "Object" },
      { name: "c1.2.foo", value: "Bar" },
    ],
    true,
  ],
  [
    getCookieId(
      "c_encoded",
      "test1.example.org",
      "/browser/devtools/client/storage/test"
    ),
    [
      {
        name: "c_encoded",
        value: encodeURIComponent(JSON.stringify({ foo: { foo1: "bar" } })),
      },
    ],
  ],
  [
    null,
    [
      { name: "c_encoded", value: "Object" },
      { name: "c_encoded.foo", value: "Object" },
      { name: "c_encoded.foo.foo1", value: "bar" },
    ],
    true,
  ],
  [["localStorage", "https://test1.example.org"]],
  ["ls2", [{ name: "ls2", value: "foobar-2" }]],
  [
    "ls1",
    [
      {
        name: "ls1",
        value: JSON.stringify({
          es6: "for",
          the: "win",
          baz: [
            0,
            2,
            3,
            {
              deep: "down",
              nobody: "cares",
            },
          ],
        }),
      },
    ],
  ],
  [
    null,
    [
      { name: "ls1", value: "Object" },
      { name: "ls1.es6", value: "for" },
      { name: "ls1.the", value: "win" },
      { name: "ls1.baz", value: "Array" },
      { name: "ls1.baz.0", value: "0" },
      { name: "ls1.baz.1", value: "2" },
      { name: "ls1.baz.2", value: "3" },
      { name: "ls1.baz.3", value: "Object" },
      { name: "ls1.baz.3.deep", value: "down" },
      { name: "ls1.baz.3.nobody", value: "cares" },
    ],
    true,
  ],
  ["ls3", [{ name: "ls3", value: "http://foobar.com/baz.php" }]],
  [
    null,
    [{ name: "ls3", value: "http://foobar.com/baz.php", dontMatch: true }],
    true,
  ],
  ["ls4", [{ name: "ls4", value: "0x1" }], false],
  [["sessionStorage", "https://test1.example.org"]],
  ["ss1", [{ name: "ss1", value: "This#is#an#array" }]],
  [
    null,
    [
      { name: "ss1", value: "Array" },
      { name: "ss1.0", value: "This" },
      { name: "ss1.1", value: "is" },
      { name: "ss1.2", value: "an" },
      { name: "ss1.3", value: "array" },
    ],
    true,
  ],
  [
    "ss2",
    [
      { name: "ss2", value: "Array" },
      { name: "ss2.0", value: "This" },
      { name: "ss2.1", value: "is" },
      { name: "ss2.2", value: "another" },
      { name: "ss2.3", value: "array" },
    ],
    true,
  ],
  [
    "ss3",
    [
      { name: "ss3", value: "Object" },
      { name: "ss3.this", value: "is" },
      { name: "ss3.an", value: "object" },
      { name: "ss3.foo", value: "bar" },
    ],
    true,
  ],
  [
    "ss4",
    [
      { name: "ss4", value: "Array" },
      { name: "ss4.0", value: "" },
      { name: "ss4.1", value: "array" },
      { name: "ss4.2", value: "" },
      { name: "ss4.3", value: "with" },
      { name: "ss4.4", value: "empty" },
      { name: "ss4.5", value: "items" },
    ],
    true,
  ],
  [
    "ss5",
    [
      { name: "ss5", value: "Array" },
      { name: "ss5.0", value: LONG_WORD },
      { name: "ss5.1", value: LONG_WORD },
      { name: "ss5.2", value: LONG_WORD },
      { name: "ss5.3", value: `${LONG_WORD}&${LONG_WORD}` },
      { name: "ss5.4", value: `${LONG_WORD}&${LONG_WORD}` },
    ],
    true,
  ],
  [["indexedDB", "https://test1.example.org", "idb1 (default)", "obj1"]],
  [
    1,
    [
      {
        name: 1,
        value: JSON.stringify({ id: 1, name: "foo", email: "foo@bar.com" }),
      },
    ],
  ],
  [
    null,
    [
      { name: "1.id", value: "1" },
      { name: "1.name", value: "foo" },
      { name: "1.email", value: "foo@bar.com" },
    ],
    true,
  ],
  [["indexedDB", "https://test1.example.org", "idb1 (default)", "obj2"]],
  [
    1,
    [
      {
        name: 1,
        value: JSON.stringify({
          id2: 1,
          name: "foo",
          email: "foo@bar.com",
          extra: "baz".repeat(10000),
        }),
      },
    ],
  ],
  [
    null,
    [
      { name: "1.id2", value: "1" },
      { name: "1.name", value: "foo" },
      { name: "1.email", value: "foo@bar.com" },
      { name: "1.extra", value: "baz".repeat(10000) },
    ],
    true,
  ],
];

add_task(async function () {
  await SpecialPowers.pushPrefEnv({
    set: [["privacy.documentCookies.maxage", 0]],
  });

  await openTabAndSetupStorage(
    MAIN_DOMAIN_SECURED + "storage-complex-values.html"
  );

  gUI.tree.expandAll();

  for (const item of testCases) {
    info("clicking for item " + item);
    const [path, ruleArray, parsed] = item;
    const start = performance.now();

    if (Array.isArray(path)) {
      await selectTreeItem(path);
      continue;
    } else if (path) {
      await selectTableItem(path);
    }

    // Parsing "0x1" used to be very slow and memory intensive.
    // Check that each test case completes in less than 15000ms.
    const time = performance.now() - start;
    ok(time < 15000, `item ${item} completed in less than 15000ms ${time}`);

    await findVariableViewProperties(ruleArray, parsed);
  }
});