diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /testing/web-platform/tests/WebIDL/ecmascript-binding/es-exceptions/exceptions.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/web-platform/tests/WebIDL/ecmascript-binding/es-exceptions/exceptions.html')
-rw-r--r-- | testing/web-platform/tests/WebIDL/ecmascript-binding/es-exceptions/exceptions.html | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/testing/web-platform/tests/WebIDL/ecmascript-binding/es-exceptions/exceptions.html b/testing/web-platform/tests/WebIDL/ecmascript-binding/es-exceptions/exceptions.html new file mode 100644 index 000000000..bc1d7fe63 --- /dev/null +++ b/testing/web-platform/tests/WebIDL/ecmascript-binding/es-exceptions/exceptions.html @@ -0,0 +1,136 @@ +<!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> |