Update web-platform-tests to revision 0d318188757a9c996e20b82db201fd04de5aa255

This commit is contained in:
James Graham 2015-03-27 09:15:38 +00:00
parent b2a5225831
commit 1a81b18b9f
12321 changed files with 544385 additions and 6 deletions

View file

@ -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>

View file

@ -0,0 +1,73 @@
<!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(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", "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');
</script>

View file

@ -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>

View file

@ -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();
}

View file

@ -0,0 +1,3 @@
importScripts("/resources/testharness.js")
importScripts("constructor-object.js")
run_test();

View file

@ -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>