mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-11 05:39:41 +02:00
Automatic update from web-platform-tests Replace some "assert_throws(new FooError(), stuff)" calls with assert_throws_js. (#21354) This diff was generated by running: find . -type f -print0 | xargs -0 perl -pi -e 'BEGIN { $/ = undef; } s/assert_throws\(([ \n]*)new ([A-Za-z]*Error) *\(\) *(, *.)/assert_throws_js(\1\2\3/gs' and then: 1) Manually adjusting fullscreen/rendering/fullscreen-pseudo-class-support.html to test for the right sort of exceptions ("SyntaxError" DOMException, not a JS SyntaxError). 2) Manually adjusting performance-timeline/po-observe-type.any.js to test for the right sort of exceptions ("SyntaxError" DOMException, not a JS SyntaxError). 3) Manually adjusting performance-timeline/po-observe.any.js to test for the right sort of exceptions ("SyntaxError" DOMException, not a JS SyntaxError). 4) Manually adjusting user-timing/mark_exceptions.html to test for the right sort of exceptions ("SyntaxError" DOMException, not a JS SyntaxError). 5) Manually adjusting user-timing/measure_syntax_err.any.js to test for the right sort of exceptions ("SyntaxError" DOMException, not a JS SyntaxError). 6) Manually adjusting domxpath/lexical-structure.html to test for a "SyntaxError" DOMException, since that's what all browsers throw and there is no clear spec for this. 7) Manually adjusting workers/constructors/Worker/Worker-constructor.html to test for the right sort of exceptions ("SyntaxError" DOMException, not a JS SyntaxError). 8) Backing out the changes to resources/idlharness.js because some tests pass objects from a different window to it, and we end up with the wrong TypeError constructor in those cases. This does affect indentation poorly in cases when the first arg was on the same line as the assert_throws, there was a newline after the ',' after the first arg, and the following args were lined up with the first arg. Fixing that, especially when there are multiple lines after the first arg, is not trivial with a regexp. Co-authored-by: Boris Zbarsky <bzbarsky@mit.edu> Co-authored-by: Stephen McGruer <smcgruer@chromium.org> -- wpt-commits: 2c5c3c4c27d27a419c1fdba3e9879c2d22037074 wpt-pr: 21354
230 lines
8.2 KiB
HTML
230 lines
8.2 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Headers structure</title>
|
|
<meta name="help" href="https://fetch.spec.whatwg.org/#headers">
|
|
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
</head>
|
|
<body>
|
|
<script>
|
|
test(function() {
|
|
new Headers();
|
|
}, "Create headers from no parameter");
|
|
|
|
test(function() {
|
|
new Headers(undefined);
|
|
}, "Create headers from undefined parameter");
|
|
|
|
test(function() {
|
|
new Headers({});
|
|
}, "Create headers from empty object");
|
|
|
|
var parameters = [null, 1];
|
|
parameters.forEach(function(parameter) {
|
|
test(function() {
|
|
assert_throws_js(TypeError, function() { new Headers(parameter) });
|
|
}, "Create headers with " + parameter + " should throw");
|
|
});
|
|
|
|
var headerDict = {"name1": "value1",
|
|
"name2": "value2",
|
|
"name3": "value3",
|
|
"name4": null,
|
|
"name5": undefined,
|
|
"name6": 1,
|
|
"Content-Type": "value4"
|
|
};
|
|
|
|
var headerSeq = [];
|
|
for (var name in headerDict)
|
|
headerSeq.push([name, headerDict[name]]);
|
|
|
|
test(function() {
|
|
var headers = new Headers(headerSeq);
|
|
for (name in headerDict) {
|
|
assert_equals(headers.get(name), String(headerDict[name]),
|
|
"name: " + name + " has value: " + headerDict[name]);
|
|
}
|
|
assert_equals(headers.get("length"), null, "init should be treated as a sequence, not as a dictionary");
|
|
}, "Create headers with sequence");
|
|
|
|
test(function() {
|
|
var headers = new Headers(headerDict);
|
|
for (name in headerDict) {
|
|
assert_equals(headers.get(name), String(headerDict[name]),
|
|
"name: " + name + " has value: " + headerDict[name]);
|
|
}
|
|
}, "Create headers with record");
|
|
|
|
test(function() {
|
|
var headers = new Headers(headerDict);
|
|
var headers2 = new Headers(headers);
|
|
for (name in headerDict) {
|
|
assert_equals(headers2.get(name), String(headerDict[name]),
|
|
"name: " + name + " has value: " + headerDict[name]);
|
|
}
|
|
}, "Create headers with existing headers");
|
|
|
|
test(function() {
|
|
var headers = new Headers()
|
|
headers[Symbol.iterator] = function *() {
|
|
yield ["test", "test"]
|
|
}
|
|
var headers2 = new Headers(headers)
|
|
assert_equals(headers2.get("test"), "test")
|
|
}, "Create headers with existing headers with custom iterator");
|
|
|
|
test(function() {
|
|
var headers = new Headers();
|
|
for (name in headerDict) {
|
|
headers.append(name, headerDict[name]);
|
|
assert_equals(headers.get(name), String(headerDict[name]),
|
|
"name: " + name + " has value: " + headerDict[name]);
|
|
}
|
|
}, "Check append method");
|
|
|
|
test(function() {
|
|
var headers = new Headers();
|
|
for (name in headerDict) {
|
|
headers.set(name, headerDict[name]);
|
|
assert_equals(headers.get(name), String(headerDict[name]),
|
|
"name: " + name + " has value: " + headerDict[name]);
|
|
}
|
|
}, "Check set method");
|
|
|
|
test(function() {
|
|
var headers = new Headers(headerDict);
|
|
for (name in headerDict)
|
|
assert_true(headers.has(name),"headers has name " + name);
|
|
|
|
assert_false(headers.has("nameNotInHeaders"),"headers do not have header: nameNotInHeaders");
|
|
}, "Check has method");
|
|
|
|
test(function() {
|
|
var headers = new Headers(headerDict);
|
|
for (name in headerDict) {
|
|
assert_true(headers.has(name),"headers have a header: " + name);
|
|
headers.delete(name)
|
|
assert_true(!headers.has(name),"headers do not have anymore a header: " + name);
|
|
}
|
|
}, "Check delete method");
|
|
|
|
test(function() {
|
|
var headers = new Headers(headerDict);
|
|
for (name in headerDict)
|
|
assert_equals(headers.get(name), String(headerDict[name]),
|
|
"name: " + name + " has value: " + headerDict[name]);
|
|
|
|
assert_equals(headers.get("nameNotInHeaders"), null, "header: nameNotInHeaders has no value");
|
|
}, "Check get method");
|
|
|
|
var headerEntriesDict = {"name1": "value1",
|
|
"Name2": "value2",
|
|
"name": "value3",
|
|
"content-Type": "value4",
|
|
"Content-Typ": "value5",
|
|
"Content-Types": "value6"
|
|
};
|
|
var sortedHeaderDict = {};
|
|
var headerValues = [];
|
|
var sortedHeaderKeys = Object.keys(headerEntriesDict).map(function(value) {
|
|
sortedHeaderDict[value.toLowerCase()] = headerEntriesDict[value];
|
|
headerValues.push(headerEntriesDict[value]);
|
|
return value.toLowerCase();
|
|
}).sort();
|
|
|
|
var iteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()));
|
|
function checkIteratorProperties(iterator) {
|
|
var prototype = Object.getPrototypeOf(iterator);
|
|
assert_equals(Object.getPrototypeOf(prototype), iteratorPrototype);
|
|
|
|
var descriptor = Object.getOwnPropertyDescriptor(prototype, "next");
|
|
assert_true(descriptor.configurable, "configurable");
|
|
assert_true(descriptor.enumerable, "enumerable");
|
|
assert_true(descriptor.writable, "writable");
|
|
}
|
|
|
|
test(function() {
|
|
var headers = new Headers(headerEntriesDict);
|
|
var actual = headers.keys();
|
|
checkIteratorProperties(actual);
|
|
|
|
sortedHeaderKeys.forEach(function(key) {
|
|
entry = actual.next();
|
|
assert_false(entry.done);
|
|
assert_equals(entry.value, key);
|
|
});
|
|
assert_true(actual.next().done);
|
|
assert_true(actual.next().done);
|
|
|
|
for (key of headers.keys())
|
|
assert_true(sortedHeaderKeys.indexOf(key) != -1);
|
|
}, "Check keys method");
|
|
|
|
test(function() {
|
|
var headers = new Headers(headerEntriesDict);
|
|
var actual = headers.values();
|
|
checkIteratorProperties(actual);
|
|
|
|
sortedHeaderKeys.forEach(function(key) {
|
|
entry = actual.next();
|
|
assert_false(entry.done);
|
|
assert_equals(entry.value, sortedHeaderDict[key]);
|
|
});
|
|
assert_true(actual.next().done);
|
|
assert_true(actual.next().done);
|
|
|
|
for (value of headers.values())
|
|
assert_true(headerValues.indexOf(value) != -1);
|
|
}, "Check values method");
|
|
|
|
test(function() {
|
|
var headers = new Headers(headerEntriesDict);
|
|
var actual = headers.entries();
|
|
checkIteratorProperties(actual);
|
|
|
|
sortedHeaderKeys.forEach(function(key) {
|
|
entry = actual.next();
|
|
assert_false(entry.done);
|
|
assert_equals(entry.value[0], key);
|
|
assert_equals(entry.value[1], sortedHeaderDict[key]);
|
|
});
|
|
assert_true(actual.next().done);
|
|
assert_true(actual.next().done);
|
|
|
|
for (entry of headers.entries())
|
|
assert_equals(entry[1], sortedHeaderDict[entry[0]]);
|
|
}, "Check entries method");
|
|
|
|
test(function() {
|
|
var headers = new Headers(headerEntriesDict);
|
|
var actual = headers[Symbol.iterator]();
|
|
|
|
sortedHeaderKeys.forEach(function(key) {
|
|
entry = actual.next();
|
|
assert_false(entry.done);
|
|
assert_equals(entry.value[0], key);
|
|
assert_equals(entry.value[1], sortedHeaderDict[key]);
|
|
});
|
|
assert_true(actual.next().done);
|
|
assert_true(actual.next().done);
|
|
}, "Check Symbol.iterator method");
|
|
|
|
test(function() {
|
|
var headers = new Headers(headerEntriesDict);
|
|
var reference = sortedHeaderKeys[Symbol.iterator]();
|
|
headers.forEach(function(value, key, container) {
|
|
assert_equals(headers, container);
|
|
entry = reference.next();
|
|
assert_false(entry.done);
|
|
assert_equals(key, entry.value);
|
|
assert_equals(value, sortedHeaderDict[entry.value]);
|
|
});
|
|
assert_true(reference.next().done);
|
|
}, "Check forEach method");
|
|
</script>
|
|
</body>
|
|
</html>
|