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
|
/* 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/. */
"use strict";
Services.scriptloader.loadSubScript(
"chrome://mochitests/content/browser/devtools/client/shared/test/shared-head.js",
this
);
function checkObject(object, expected) {
for (const name of Object.keys(expected)) {
const expectedValue = expected[name];
const value = object[name];
checkValue(name, value, expectedValue);
}
}
function checkValue(name, value, expected) {
if (expected === null) {
is(value, null, "'" + name + "' is null");
} else if (value === null) {
ok(false, "'" + name + "' is null");
} else if (value === undefined) {
ok(false, "'" + name + "' is undefined");
} else if (
typeof expected == "string" ||
typeof expected == "number" ||
typeof expected == "boolean"
) {
is(value, expected, "property '" + name + "'");
} else if (expected instanceof RegExp) {
ok(expected.test(value), name + ": " + expected + " matched " + value);
} else if (Array.isArray(expected)) {
info("checking array for property '" + name + "'");
checkObject(value, expected);
} else if (typeof expected == "object") {
info("checking object for property '" + name + "'");
checkObject(value, expected);
}
}
function checkHeadersOrCookies(array, expected) {
const foundHeaders = {};
for (const elem of array) {
if (!(elem.name in expected)) {
continue;
}
foundHeaders[elem.name] = true;
info("checking value of header " + elem.name);
checkValue(elem.name, elem.value, expected[elem.name]);
}
for (const header in expected) {
if (!(header in foundHeaders)) {
ok(false, header + " was not found");
}
}
}
|