mirror of
https://github.com/classilla/tenfourfox.git
synced 2024-07-06 19:29:27 +00:00
137 lines
5.5 KiB
HTML
137 lines
5.5 KiB
HTML
<!doctype html>
|
|
<title>DOMException-throwing tests</title>
|
|
<link rel=author title="Aryeh Gregor" href=ayg@aryeh.name>
|
|
<div id=log></div>
|
|
<script src=/resources/testharness.js></script>
|
|
<script src=/resources/testharnessreport.js></script>
|
|
<script>
|
|
/**
|
|
* This file just picks one case where browsers are supposed to throw an
|
|
* exception, and tests the heck out of whether it meets the spec. In the
|
|
* future, all these checks should be in assert_throws(), but we don't want
|
|
* every browser failing every assert_throws() check until they fix every
|
|
* single bug in their exception-throwing.
|
|
*
|
|
* We don't go out of our way to test everything that's already tested by
|
|
* interfaces.html, like whether all constants are present on the object, but
|
|
* some things are duplicated.
|
|
*/
|
|
setup({explicit_done: true});
|
|
|
|
function testException(exception, global, desc) {
|
|
// https://heycam.github.io/webidl/#es-exception-objects
|
|
// (as of 2015-01-03): "The value of the internal [[Prototype]] property of a
|
|
// DOMException object MUST be the DOMException prototype object from the
|
|
// global environment the exception object is associated with."
|
|
test(function() {
|
|
assert_equals(global.Object.getPrototypeOf(exception),
|
|
global.DOMException.prototype);
|
|
}, desc + "Object.getPrototypeOf(exception) === DOMException.prototype");
|
|
|
|
|
|
// https://heycam.github.io/webidl/#es-creating-throwing-exceptions
|
|
// (as of 2015-01-03): "Call the [[DefineOwnProperty]] internal method of /O/
|
|
// passing “name”, Property Descriptor { [[Value]]: /N/, [[Writable]]: true,
|
|
// [[Enumerable]]: true, [[Configurable]]: true }, and false as arguments."
|
|
test(function() {
|
|
assert_true(exception.hasOwnProperty("name"));
|
|
}, desc + "exception.hasOwnProperty(\"name\")");
|
|
|
|
test(function() {
|
|
assert_equals(exception.name, "HierarchyRequestError");
|
|
}, desc + "exception.name === \"HierarchyRequestError\"");
|
|
|
|
test(function() {
|
|
var desc = global.Object.getOwnPropertyDescriptor(exception, "name");
|
|
assert_true(desc.writable, "must be writable");
|
|
assert_true(desc.enumerable, "must be enumerable");
|
|
assert_true(desc.configurable, "must be configurable");
|
|
}, desc + "Object.getOwnPropertyDescriptor(exception, \"name\")");
|
|
|
|
|
|
// https://heycam.github.io/webidl/#es-creating-throwing-exceptions
|
|
// (as of 2015-01-03): "If the optional user agent-defined message /M/ was
|
|
// specified, then this list has a single element whose value is the result
|
|
// of converting /M/ to a String value. Otherwise, the list is empty."
|
|
//
|
|
// https://heycam.github.io/webidl/#es-DOMException-constructor-object
|
|
// (as of 2015-01-03): "Call the [[DefineOwnProperty]] internal method of /O/
|
|
// passing “message”, Property Descriptor { [[Value]]: /S/,
|
|
// [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }, and
|
|
// false as arguments."
|
|
test(function() {
|
|
if (exception.hasOwnProperty("message")) {
|
|
var desc = global.Object.getOwnPropertyDescriptor(exception, "message");
|
|
assert_true(desc.writable, "must be writable");
|
|
assert_false(desc.enumerable, "must not be enumerable");
|
|
assert_true(desc.configurable, "must be configurable");
|
|
}
|
|
}, desc + "Object.getOwnPropertyDescriptor(exception, \"message\")");
|
|
|
|
test(function() {
|
|
if (exception.hasOwnProperty("message")) {
|
|
// Can't test anything more specific, since it's implementation-defined :(
|
|
assert_equals(typeof exception.message, "string");
|
|
} else {
|
|
// Error.prototype.message
|
|
assert_equals(exception.message, "");
|
|
}
|
|
}, desc + "typeof exception.message === \"string\"");
|
|
|
|
|
|
// https://heycam.github.io/webidl/#es-exception-objects
|
|
// (as of 2015-01-03): "The class string of a DOMException object MUST be
|
|
// “DOMException”."
|
|
test(function() {
|
|
assert_equals(global.Object.prototype.toString.call(exception),
|
|
"[object DOMException]");
|
|
}, desc + "Object.prototype.toString.call(exception) === \"[object DOMException]\"");
|
|
|
|
|
|
// https://heycam.github.io/webidl/#es-creating-throwing-exceptions
|
|
// (as of 2015-01-03): "Call the [[DefineOwnProperty]] internal method of /O/
|
|
// passing “code”, Property Descriptor { [[Value]]: /code/,
|
|
// [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }, and
|
|
// false as arguments."
|
|
test(function() {
|
|
assert_equals(exception.code, global.DOMException.HIERARCHY_REQUEST_ERR);
|
|
}, desc + "exception.code === DOMException.HIERARCHY_REQUEST_ERR");
|
|
|
|
test(function() {
|
|
var desc = global.Object.getOwnPropertyDescriptor(exception, "name");
|
|
assert_true(desc.writable, "must be writable");
|
|
assert_true(desc.enumerable, "must be enumerable");
|
|
assert_true(desc.configurable, "must be configurable");
|
|
}, desc + "Object.getOwnPropertyDescriptor(exception, \"code\")");
|
|
}
|
|
|
|
|
|
// Test in current window
|
|
var exception = null;
|
|
try {
|
|
// This should throw a HierarchyRequestError in every browser since the
|
|
// Stone Age, so we're really only testing exception-throwing details.
|
|
document.documentElement.appendChild(document);
|
|
} catch(e) {
|
|
exception = e;
|
|
}
|
|
testException(exception, window, "");
|
|
|
|
// Test in iframe
|
|
var iframe = document.createElement("iframe");
|
|
iframe.src = "about:blank";
|
|
iframe.onload = function() {
|
|
var exception = null;
|
|
try {
|
|
iframe.contentDocument.documentElement.appendChild(iframe.contentDocument);
|
|
} catch(e) {
|
|
exception = e;
|
|
}
|
|
testException(exception, iframe.contentWindow, "In iframe: ");
|
|
|
|
document.body.removeChild(iframe);
|
|
done();
|
|
};
|
|
document.body.appendChild(iframe);
|
|
</script>
|