diff options
Diffstat (limited to 'testing/web-platform/tests/WebIDL/ecmascript-binding')
8 files changed, 500 insertions, 0 deletions
diff --git a/testing/web-platform/tests/WebIDL/ecmascript-binding/es-exceptions/DOMException-constants.html b/testing/web-platform/tests/WebIDL/ecmascript-binding/es-exceptions/DOMException-constants.html new file mode 100644 index 000000000..450b4b334 --- /dev/null +++ b/testing/web-platform/tests/WebIDL/ecmascript-binding/es-exceptions/DOMException-constants.html @@ -0,0 +1,59 @@ +<!doctype html> +<meta charset=utf-8> +<title>DOMException constants</title> +<link rel=help href="https://heycam.github.io/webidl/#es-DOMException-constructor-object"> +<link rel=help href="https://heycam.github.io/webidl/#es-DOMException-prototype-object"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +test(function() { + // https://www.w3.org/Bugs/Public/show_bug.cgi?id=27732 + var constants = [ + "INDEX_SIZE_ERR", + "DOMSTRING_SIZE_ERR", + "HIERARCHY_REQUEST_ERR", + "WRONG_DOCUMENT_ERR", + "INVALID_CHARACTER_ERR", + "NO_DATA_ALLOWED_ERR", + "NO_MODIFICATION_ALLOWED_ERR", + "NOT_FOUND_ERR", + "NOT_SUPPORTED_ERR", + "INUSE_ATTRIBUTE_ERR", + "INVALID_STATE_ERR", + "SYNTAX_ERR", + "INVALID_MODIFICATION_ERR", + "NAMESPACE_ERR", + "INVALID_ACCESS_ERR", + "VALIDATION_ERR", + "TYPE_MISMATCH_ERR", + "SECURITY_ERR", + "NETWORK_ERR", + "ABORT_ERR", + "URL_MISMATCH_ERR", + "QUOTA_EXCEEDED_ERR", + "TIMEOUT_ERR", + "INVALID_NODE_TYPE_ERR", + "DATA_CLONE_ERR" + ] + var objects = [ + [DOMException, "DOMException constructor object"], + [DOMException.prototype, "DOMException prototype object"] + ] + constants.forEach(function(name, i) { + objects.forEach(function(o) { + var object = o[0], description = o[1]; + test(function() { + assert_equals(object[name], i + 1, name) + assert_own_property(object, name) + var pd = Object.getOwnPropertyDescriptor(object, name) + assert_false("get" in pd, "property has getter") + assert_false("set" in pd, "property has setter") + assert_false(pd.writable, "not writable") + assert_true(pd.enumerable, "enumerable") + assert_false(pd.configurable, "not configurable") + }, "Constant " + name + " on " + description) + }) + }) +}) +</script> diff --git a/testing/web-platform/tests/WebIDL/ecmascript-binding/es-exceptions/DOMException-constructor.html b/testing/web-platform/tests/WebIDL/ecmascript-binding/es-exceptions/DOMException-constructor.html new file mode 100644 index 000000000..0e5ffea7d --- /dev/null +++ b/testing/web-platform/tests/WebIDL/ecmascript-binding/es-exceptions/DOMException-constructor.html @@ -0,0 +1,139 @@ +<!doctype html> +<meta charset=utf-8> +<title>DOMException constructor</title> +<link rel=help href="https://heycam.github.io/webidl/#es-DOMException-constructor-object"> +<link rel=help href="https://people.mozilla.org/~jorendorff/es6-draft.html#sec-error.prototype.message"> +<link rel=help href="https://people.mozilla.org/~jorendorff/es6-draft.html#sec-error.prototype.name"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +test(function() { + var ex = new DOMException(); + assert_equals(ex.name, "Error", + "Not passing a name should end up with 'Error' as the name"); + assert_equals(ex.message, "", + "Not passing a message should end up with empty string as the message"); +}, 'new DOMException()'); + +test(function() { + var ex = new DOMException(); + assert_false(ex.hasOwnProperty("name"), + "The name property should be inherited"); + assert_false(ex.hasOwnProperty("message"), + "The message property should be inherited"); +}, 'new DOMException(): own-ness'); + +test(function() { + var ex = new DOMException(null); + assert_equals(ex.name, "Error", + "Not passing a name should end up with 'Error' as the name"); + assert_equals(ex.message, "null", + "Passing null as message should end up with stringified 'null' as the message"); +}, 'new DOMException(null)'); + +test(function() { + var ex = new DOMException(undefined); + assert_equals(ex.name, "Error", + "Not passing a name should end up with 'Error' as the name"); + assert_equals(ex.message, "", + "Not passing a message should end up with empty string as the message"); +}, 'new DOMException(undefined)'); + +test(function() { + var ex = new DOMException(undefined); + assert_false(ex.hasOwnProperty("name"), + "The name property should be inherited"); + assert_false(ex.hasOwnProperty("message"), + "The message property should be inherited"); +}, 'new DOMException(undefined): own-ness'); + +test(function() { + var ex = new DOMException("foo"); + assert_equals(ex.name, "Error", + "Not passing a name should still end up with 'Error' as the name"); + assert_equals(ex.message, "foo", "Should be using passed-in message"); +}, 'new DOMException("foo")'); + +test(function() { + var ex = new DOMException("foo"); + assert_false(ex.hasOwnProperty("name"), + "The name property should be inherited"); + assert_true(ex.hasOwnProperty("message"), + "The message property should be own"); +}, 'new DOMException("foo"): own-ness'); + +test(function() { + var ex = new DOMException("bar", undefined); + assert_equals(ex.name, "Error", + "Passing undefined for name should end up with 'Error' as the name"); + assert_equals(ex.message, "bar", "Should still be using passed-in message"); +}, 'new DOMException("bar", undefined)'); + +test(function() { + var ex = new DOMException("bar", "NotSupportedError"); + assert_equals(ex.name, "NotSupportedError", "Should be using the passed-in name"); + assert_equals(ex.message, "bar", "Should still be using passed-in message"); + assert_equals(ex.code, DOMException.NOT_SUPPORTED_ERR, + "Should have the right exception code"); +}, 'new DOMException("bar", "NotSupportedError")'); + +test(function() { + var ex = new DOMException("bar", "NotSupportedError"); + assert_true(ex.hasOwnProperty("name"), + "The name property should be own"); + assert_true(ex.hasOwnProperty("message"), + "The message property should be own"); +}, 'new DOMException("bar", "NotSupportedError"): own-ness'); + +test(function() { + var ex = new DOMException("bar", "foo"); + assert_equals(ex.name, "foo", "Should be using the passed-in name"); + assert_equals(ex.message, "bar", "Should still be using passed-in message"); + assert_equals(ex.code, 0, + "Should have 0 for code for a name not in the exception names table"); +}, 'new DOMException("bar", "foo")'); + +[ + {name: "IndexSizeError", code: 1}, + {name: "HierarchyRequestError", code: 3}, + {name: "WrongDocumentError", code: 4}, + {name: "InvalidCharacterError", code: 5}, + {name: "NoModificationAllowedError", code: 7}, + {name: "NotFoundError", code: 8}, + {name: "NotSupportedError", code: 9}, + {name: "InUseAttributeError", code: 10}, + {name: "InvalidStateError", code: 11}, + {name: "SyntaxError", code: 12}, + {name: "InvalidModificationError", code: 13}, + {name: "NamespaceError", code: 14}, + {name: "InvalidAccessError", code: 15}, + {name: "SecurityError", code: 18}, + {name: "NetworkError", code: 19}, + {name: "AbortError", code: 20}, + {name: "URLMismatchError", code: 21}, + {name: "QuotaExceededError", code: 22}, + {name: "TimeoutError", code: 23}, + {name: "InvalidNodeTypeError", code: 24}, + {name: "DataCloneError", code: 25} +].forEach(function(test_case) { + test(function() { + var ex = new DOMException("msg", test_case.name); + assert_equals(ex.name, test_case.name, + "Should be using the passed-in name"); + assert_equals(ex.message, "msg", + "Should be using the passed-in message"); + assert_equals(ex.code, test_case.code, + "Should have matching legacy code from error names table"); + },'new DOMexception("msg", "' + test_case.name + '")'); +}); + +test(function() { + var ex = new DOMException("bar", "UnknownError"); + assert_equals(ex.name, "UnknownError", "Should be using the passed-in name"); + assert_equals(ex.message, "bar", "Should still be using passed-in message"); + assert_equals(ex.code, 0, + "Should have 0 for code for a name in the exception names table with no legacy code"); +}, 'new DOMException("bar", "UnknownError")'); + +</script> diff --git a/testing/web-platform/tests/WebIDL/ecmascript-binding/es-exceptions/constructor-object.html b/testing/web-platform/tests/WebIDL/ecmascript-binding/es-exceptions/constructor-object.html new file mode 100644 index 000000000..ddb40f4dd --- /dev/null +++ b/testing/web-platform/tests/WebIDL/ecmascript-binding/es-exceptions/constructor-object.html @@ -0,0 +1,11 @@ +<!doctype html> +<meta charset=utf-8> +<title>DOMException constructor and prototype object</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src=constructor-object.js></script> +<div id="log"></div> +<script> +setup({ explicit_done: true }) +run_test() +</script> diff --git a/testing/web-platform/tests/WebIDL/ecmascript-binding/es-exceptions/constructor-object.js b/testing/web-platform/tests/WebIDL/ecmascript-binding/es-exceptions/constructor-object.js new file mode 100644 index 000000000..e539d85db --- /dev/null +++ b/testing/web-platform/tests/WebIDL/ecmascript-binding/es-exceptions/constructor-object.js @@ -0,0 +1,111 @@ +function run_test() { + test(function() { + // "There MUST exist a property on the ECMAScript global object whose + // name is “DOMException” and value is an object called the + // DOMException constructor object, which provides access to legacy + // DOMException code constants. The property has the attributes + // { [[Writable]]: true, [[Enumerable]]: false, + // [[Configurable]]: true }." + assert_own_property(self, "DOMException", + "self does not have own property \"DOMException\""); + var desc = Object.getOwnPropertyDescriptor(self, "DOMException"); + assert_false("get" in desc, "self's property \"DOMException\" has getter"); + assert_false("set" in desc, "self's property \"DOMException\" has setter"); + assert_true(desc.writable, "self's property \"DOMException\" is not writable"); + assert_false(desc.enumerable, "self's property \"DOMException\" is enumerable"); + assert_true(desc.configurable, "self's property \"DOMException\" is not configurable"); + + // "The DOMException constructor object MUST be a function object but + // with a [[Prototype]] value of %Error% ([ECMA-262], section 6.1.7.4)." + assert_equals(Object.getPrototypeOf(self.DOMException), Error, + "prototype of self's property \"DOMException\" is not Error"); + + // "Its [[Get]] internal property is set as described in ECMA-262 + // section 9.1.8." + // Not much to test for this. + // "Its [[Construct]] internal property is set as described in ECMA-262 + // section 19.2.2.3." + // "Its @@hasInstance property is set as described in ECMA-262 section + // 19.2.3.8, unless otherwise specified." + + // String() returns something implementation-dependent, because it + // calls Function#toString. + assert_class_string(self.DOMException, "Function", + "class string of DOMException"); + + // "For every legacy code listed in the error names table, there MUST + // be a property on the DOMException constructor object whose name and + // value are as indicated in the table. The property has attributes + // { [[Writable]]: false, [[Enumerable]]: true, + // [[Configurable]]: false }." + // See DOMException-constants.html. + }, "existence and properties of DOMException"); + + test(function() { + assert_own_property(self, "DOMException", + "self does not have own property \"DOMException\""); + + // "The DOMException constructor object MUST also have a property named + // “prototype” with attributes { [[Writable]]: false, + // [[Enumerable]]: false, [[Configurable]]: false } whose value is an + // object called the DOMException prototype object. This object also + // provides access to the legacy code values." + assert_own_property(self.DOMException, "prototype", + 'exception "DOMException" does not have own property "prototype"'); + var desc = Object.getOwnPropertyDescriptor(self.DOMException, "prototype"); + assert_false("get" in desc, "DOMException.prototype has getter"); + assert_false("set" in desc, "DOMException.prototype has setter"); + assert_false(desc.writable, "DOMException.prototype is writable"); + assert_false(desc.enumerable, "DOMException.prototype is enumerable"); + assert_false(desc.configurable, "DOMException.prototype is configurable"); + + // "The DOMException prototype object MUST have an internal + // [[Prototype]] property whose value is %ErrorPrototype% ([ECMA-262], + // section 6.1.7.4)." + assert_own_property(self, "Error", + 'should inherit from Error, but self has no such property'); + assert_own_property(self.Error, "prototype", + 'should inherit from Error, but that object has no "prototype" property'); + assert_equals(Object.getPrototypeOf(self.DOMException.prototype), + self.Error.prototype, + 'prototype of DOMException.prototype is not Error.prototype'); + + // "The class string of the DOMException prototype object is + // “DOMExceptionPrototype”." + assert_class_string(self.DOMException.prototype, "DOMExceptionPrototype", + "class string of DOMException.prototype"); + }, "existence and properties of DOMException.prototype"); + + test(function() { + assert_false(self.DOMException.prototype.hasOwnProperty("name"), + "DOMException.prototype should not have an own \"name\" " + + "property."); + assert_false(self.DOMException.prototype.hasOwnProperty("code"), + "DOMException.prototype should not have an own \"name\" " + + "property."); + }, "existence of name and code properties on DOMException.prototype"); + + test(function() { + assert_own_property(self, "DOMException", + "self does not have own property \"DOMException\""); + assert_own_property(self.DOMException, "prototype", + 'interface "DOMException" does not have own property "prototype"'); + + // "There MUST be a property named “constructor” on the DOMException + // prototype object with attributes { [[Writable]]: true, + // [[Enumerable]]: false, [[Configurable]]: true } and whose value is + // the DOMException constructor object." + assert_own_property(self.DOMException.prototype, "constructor", + "DOMException" + '.prototype does not have own property "constructor"'); + var desc = Object.getOwnPropertyDescriptor(self.DOMException.prototype, "constructor"); + assert_false("get" in desc, "DOMException.prototype.constructor has getter"); + assert_false("set" in desc, "DOMException.prototype.constructor has setter"); + assert_true(desc.writable, "DOMException.prototype.constructor is not writable"); + assert_false(desc.enumerable, "DOMException.prototype.constructor is enumerable"); + assert_true(desc.configurable, "DOMException.prototype.constructor in not configurable"); + assert_equals(self.DOMException.prototype.constructor, self.DOMException, + "DOMException.prototype.constructor is not the same object as DOMException"); + }, "existence and properties of exception interface prototype object's \"constructor\" property"); + + done(); +} diff --git a/testing/web-platform/tests/WebIDL/ecmascript-binding/es-exceptions/constructor-object.worker.js b/testing/web-platform/tests/WebIDL/ecmascript-binding/es-exceptions/constructor-object.worker.js new file mode 100644 index 000000000..75149244f --- /dev/null +++ b/testing/web-platform/tests/WebIDL/ecmascript-binding/es-exceptions/constructor-object.worker.js @@ -0,0 +1,3 @@ +importScripts("/resources/testharness.js") +importScripts("constructor-object.js") +run_test(); 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> diff --git a/testing/web-platform/tests/WebIDL/ecmascript-binding/has-instance.html b/testing/web-platform/tests/WebIDL/ecmascript-binding/has-instance.html new file mode 100644 index 000000000..986d27c9b --- /dev/null +++ b/testing/web-platform/tests/WebIDL/ecmascript-binding/has-instance.html @@ -0,0 +1,13 @@ +<!doctype html> +<meta charset="utf-8"> +<title></title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +test(function() { + var obj = Object.create(Element.prototype); + assert_true(obj instanceof Element); + assert_true(obj instanceof Node); + assert_false(obj instanceof Attr); +}, "Manually-constructed prototype chains are correctly handled by instanceof"); +</script> diff --git a/testing/web-platform/tests/WebIDL/ecmascript-binding/interface-object.html b/testing/web-platform/tests/WebIDL/ecmascript-binding/interface-object.html new file mode 100644 index 000000000..132c61dda --- /dev/null +++ b/testing/web-platform/tests/WebIDL/ecmascript-binding/interface-object.html @@ -0,0 +1,28 @@ +<!doctype html> +<meta charset="utf-8"> +<title>Interface objects</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +test(function () { + assert_equals(typeof window.Blob, "function") + delete window.Blob; + assert_equals(window.Blob, undefined); +}, "An interface object deleted after it has been accessed is undefined"); + +test(function () { + delete window.File; + assert_equals(window.File, undefined); +}, "An interface object deleted before it has been defined is undefined"); + +test(function () { + delete window.ImageData; + assert_equals(Object.getOwnPropertyDescriptor(window, "ImageData"), undefined); + delete window.ImageData; + assert_equals(Object.getOwnPropertyDescriptor(window, "ImageData"), undefined); +}, "Interface objects deleted multiple times stay deleted"); + +test(function () { + assert_equals(window["abc\udc88"], undefined); +}, "Fancy property names don't break the resolve hook on Window"); +</script> |