Bug 745498 - Add testcases for DOM4 exception types. r=sicking

This commit is contained in:
Masatoshi Kimura 2012-04-26 09:42:26 -07:00
parent 12a1ff7afb
commit f17f15dabb
63 changed files with 655 additions and 569 deletions

View File

@ -347,7 +347,7 @@
var pass = false;
try {
root.querySelectorAll("");
} catch(e){ pass = e.code == DOMException.SYNTAX_ERR; }
} catch(e){ pass = e.name == "SyntaxError" && e.code == DOMException.SYNTAX_ERR; }
assert( pass, type + ".querySelectorAll Empty String" );
pass = false;
@ -372,7 +372,7 @@
pass = false;
try {
root.querySelector("");
} catch(e){ pass = e.code == DOMException.SYNTAX_ERR; }
} catch(e){ pass = e.name == "SyntaxError" && e.code == DOMException.SYNTAX_ERR; }
assert( pass, type + ".querySelector Empty String" );
pass = false;
@ -410,7 +410,7 @@
assert(expect && pass, type + ".querySelectorAll: " + query);
} catch(e){
var pass = !expect && e.code == DOMException.SYNTAX_ERR || false;
var pass = !expect && e.name == "SyntaxError" && e.code == DOMException.SYNTAX_ERR || false;
assert(pass, type + ".querySelectorAll: " + query);
}
@ -433,7 +433,7 @@
assert(expect, type + ".querySelector: " + query);
} catch(e){
var pass = !expect && e.code == DOMException.SYNTAX_ERR || false;
var pass = !expect && e.name == "SyntaxError" && e.code == DOMException.SYNTAX_ERR || false;
assert(pass, type + ".querySelector: " + query);
}
}
@ -493,8 +493,9 @@
try {
return root[select](q, resolver);
} catch(e){
if ( e.message.indexOf("ERR") > -1 || e.code == DOMException.NAMESPACE_ERR ||
e.code == DOMException.SYNTAX_ERR)
if ( e.message.indexOf("ERR") > -1 ||
(e.name == "NamespaceError" && e.code == DOMException.NAMESPACE_ERR) ||
(e.name == "SyntaxError" && e.code == DOMException.SYNTAX_ERR) )
throw e;
}
}
@ -547,7 +548,8 @@
try {
results = query(q, resolver);
} catch(e) {
pass = (e.message === "bad ERROR" || e.code == DOMException.NAMESPACE_ERR);
pass = (e.message === "bad ERROR" ||
(e.name == "NamespaceError" && e.code == DOMException.NAMESPACE_ERR));
}
assert( pass, type + ": " + name + " Bad Resolver #" + (i+1) + " (" + nq + ")" +
@ -560,7 +562,7 @@
var results = query(q);
pass = hasPassed( results, ids );
} catch(e) {
pass = e.code == DOMException.SYNTAX_ERR;
pass = e.name == "SyntaxError" && e.code == DOMException.SYNTAX_ERR;
}
assert( pass, type + ": " + name + " (" + nq + ")" +

View File

@ -67,6 +67,7 @@ function testComment(aText, aShouldSucceed)
if (aShouldSucceed) {
ok(0, "Correct functioning of comment stuff", "something broke: " + e);
} else {
is(e.name, "InvalidCharacterError", "Check exception");
is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code");
}
}
@ -79,6 +80,7 @@ function testCDATASection(aText, aShouldSucceed)
ok(0, "Invalid CDATA section creation",
"Shouldn't create CDATA sections in HTML");
} catch (e) {
is(e.name, "NotSupportedError", "Check exception");
is(e.code, DOMException.NOT_SUPPORTED_ERR, "Check exception code");
}
}
@ -111,6 +113,7 @@ function testPI(aTarget, aData, aShouldSucceed, aReason)
ok(false, "Correct functioning of processing instruction stuff",
"something broke: " + e);
} else {
is(e.name, "InvalidCharacterError", "Check exception");
is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code");
}
}

View File

@ -91,6 +91,7 @@ function testComment(aText, aShouldSucceed)
if (aShouldSucceed) {
ok(0, "Correct functioning of comment stuff", "something broke: " + e);
} else {
is(e.name, "InvalidCharacterError", "Check exception");
is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code");
}
}
@ -122,6 +123,7 @@ function testCDATASection(aText, aShouldSucceed)
ok(0, "Correct functioning of CDATA section stuff",
"something broke: " + e);
} else {
is(e.name, "InvalidCharacterError", "Check exception");
is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code");
}
}
@ -155,6 +157,7 @@ function testPI(aTarget, aData, aShouldSucceed, aReason)
ok(0, "Correct functioning of processing instruction stuff",
"something broke: " + e);
} else {
is(e.name, "InvalidCharacterError", "Check exception");
is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code");
}
}

View File

@ -60,9 +60,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=366946
var result2 = range3.compareBoundaryPoints(Range.START_TO_START, range1);
}
catch (ex) {
var error = ex.name;
var errorCode = ex.code;
}
ok(error == "WrongDocumentError",
"The WrongDocumentError exception thrown when comparing ranges from " +
"different documents ");
ok(errorCode == DOMException.WRONG_DOCUMENT_ERR,
"The exception thrown when comparing ranges from different documents " +
"has the code DOMException.WRONG_DOCUMENT_ERR");

View File

@ -35,7 +35,7 @@ function resolverTest(expr, resolver, result, extype) {
ok(false, "Should have got an exception!");
}
} catch(ex) {
is(ex.code, extype, "Wrong exception");
is(ex.name, extype, "Wrong exception");
}
}
@ -56,21 +56,20 @@ resolverTest("*", document.documentElement.firstChild.nextSibling,
// Expression should return foo element, but because of the
// resolver it may throw an exception.
var NAMESPACE_ERR = 14;
var foo = document.getElementById("test").firstChild;
// Document resolver
resolverTest("//foo:foo", document, foo, NAMESPACE_ERR);
resolverTest("//foo:foo", document, foo, "NamespaceError");
// Element resolver
resolverTest("//foo:foo", document.documentElement, foo, NAMESPACE_ERR);
resolverTest("//foo:foo", document.documentElement, foo, "NamespaceError");
// Attribute resolver
resolverTest("//foo:foo", document.documentElement.getAttributeNode("attr"),
foo, NAMESPACE_ERR);
foo, "NamespaceError");
// Text node resolver
resolverTest("//foo:foo", document.documentElement.firstChild,
foo, NAMESPACE_ERR);
foo, "NamespaceError");
// Comment node resolver
resolverTest("//foo:foo", document.documentElement.firstChild.nextSibling,
foo, NAMESPACE_ERR);
foo, "NamespaceError");
// Function resolver
resolverTest("//foo:foo",
function(p) { return (p == "foo") ? "http://www.foo.org" : ""; },

View File

@ -84,6 +84,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=454326
is(r3.toString(), "Hello ", "Wrong range!");
} catch(e) {
ex = e;
is(e.name, "InvalidStateError", "Didn't get InvalidStateError exception!");
is(Object.getPrototypeOf(e), DOMException.prototype, "Didn't get DOMException!");
is(e.code, 11, "Didn't get INVALID_STATE_ERR exception!");
}
@ -100,6 +101,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=454326
is(r3.toString(), "World!", "Wrong range!");
} catch(e) {
ex = e;
is(e.name, "InvalidStateError", "Didn't get InvalidStateError exception!");
is(Object.getPrototypeOf(e), DOMException.prototype, "Didn't get DOMException!");
is(e.code, 11, "Didn't get INVALID_STATE_ERR exception!");
}
@ -116,6 +118,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=454326
is(r4.toString(), "Hello World!", "Wrong range!");
} catch(e) {
ex = e;
is(e.name, "InvalidStateError", "Didn't get InvalidStateError exception!");
is(Object.getPrototypeOf(e), DOMException.prototype, "Didn't get DOMException!");
is(e.code, 11, "Didn't get INVALID_STATE_ERR exception!");
}

View File

@ -19,21 +19,18 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=466751
/** Test for Bug 466751 **/
var el = $("test");
var result, message;
var name, message;
try {
el.innerHTML = '<div ">bla</div>';
} catch (ex) {
// ex.toString() == [Exception... "Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER) [nsIDOMHTMLElement.innerHTML]" nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)" location: "JS frame :: file:///Users/gavin/mobile/mozilla/content/base/test/test_bug466751.xhtml :: <TOP_LEVEL> :: line 30" data: no]
// ex.result == NS_ERROR_DOM_SYNTAX_ERR
// ex.message == Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER) [nsIDOMHTMLElement.innerHTML]
result = ex.result;
name = ex.name;
message = ex.message;
}
const NS_ERROR_DOM_SYNTAX_ERR = 0x8053000C;
ok(/An invalid or illegal string was specified/.test(message), "threw NS_ERROR_DOM_SYNTAX_ERR message");
is(result, NS_ERROR_DOM_SYNTAX_ERR, "threw NS_ERROR_DOM_SYNTAX_ERR result");
ok(/An invalid or illegal string was specified/.test(message), "threw SyntaxError message");
is(name, "SyntaxError", "threw SyntaxError");
]]>
</script>

View File

@ -175,13 +175,13 @@ function testInsertNode(node) {
check(p,0,p.childNodes[1],1);
}
function testInvalidNodeType(node) {
const INVALID_NODE_TYPE_ERR = 2;
try {
testInsertNode(node);
ok(false,"Expected a RangeException::INVALID_NODE_TYPE_ERR");
ok(false,"Expected an InvalidNodeTypeError");
} catch(e) {
ok(e instanceof RangeException, "Wrong type of exception: " + e);
is(e.code, INVALID_NODE_TYPE_ERR, "Wrong exception code, expected INVALID_NODE_TYPE_ERR");
is(e.name, "InvalidNodeTypeError", "Wrong exception, expected InvalidNodeTypeError");
ok(e instanceof DOMException, "Wrong type of exception: " + e);
is(e.code, DOMException.INVALID_NODE_TYPE_ERR, "Wrong exception code, expected INVALID_NODE_TYPE_ERR");
}
}
@ -205,41 +205,38 @@ function runTest() {
// TODO: testInvalidNodeType(document.createNotation());
// BUG: testInvalidNodeType(document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null));
todo(false, "test that Range::insertNode() throws DOMException::WRONG_DOCUMENT_ERR when it should");
/* TODO: This works but shouldn't:
const WRONG_DOCUMENT_ERR = 4;
// Intentionally fails because of bug 418755.
todo(false, "test that Range::insertNode() throws WrongDocumentError when it should");
i = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null).createElement('html');
try {
testInsertNode(i);
ok(false,"Expected a DOMException::WRONG_DOCUMENT_ERR");
todo(false,"Expected a WrongDocumentError");
} catch(e) {
is(e.name, "WrongDocumentError", "Wrong exception, expected WrongDocumentError");
ok(e instanceof DOMException, "Wrong type of exception: " + e);
is(e.code, WRONG_DOCUMENT_ERR, "Wrong exception code, expected WRONG_DOCUMENT_ERR");
is(e.code, DOMException.WRONG_DOCUMENT_ERR, "Wrong exception code, expected WRONG_DOCUMENT_ERR");
}
*/
// Inserting an ancestor of the start container should throw HIERARCHY_REQUEST_ERR
todo(false, "test that Range::insertNode() throws HIERARCHY_REQUEST_ERR when it should");
/* TODO: This works but shouldn't:
const HIERARCHY_REQUEST_ERR = 3;
// Inserting an ancestor of the start container should throw HierarchyRequestError
todo(false, "test that Range::insertNode() throws HierarchyRequestError when it should");
var p = create('<b>IJK</b>');
select(p.childNodes[0],0,p.childNodes[0],1);
var sel = getSelection();
var range = sel.getRangeAt(0);
try {
range.insertNode(p);
ok(false,"Expected a DOMException::HIERARCHY_REQUEST_ERR");
ok(false,"Expected a HierarchyRequestError");
} catch(e) {
is(e.name, "HierarchyRequestError", "Wrong exception, expected HierarchyRequestError");
ok(e instanceof DOMException, "Wrong type of exception: " + e);
is(e.code, HIERARCHY_REQUEST_ERR, "Wrong exception code, expected HIERARCHY_REQUEST_ERR");
is(e.code, DOMException.HIERARCHY_REQUEST_ERR, "Wrong exception code, expected HIERARCHY_REQUEST_ERR");
}
*/
// TODO: we should also have a test for:
/// "HIERARCHY_REQUEST_ERR: Raised if the container of the start of the Range is of a type
/// "HierarchyRequestError: Raised if the container of the start of the Range is of a type
/// that does not allow children of the type of newNode"
todo(false, "INVALID_STATE_ERR test goes here...");
todo(false, "InvalidStateError test goes here...");
var sel = getSelection();
sel.removeAllRanges();

View File

@ -43,6 +43,7 @@ function filter(node) {
ex = e;
}
++testCount;
is(ex.name, "InvalidStateError", "Should have thrown an exception!");
is(ex.code, DOMException.INVALID_STATE_ERR, "Should have thrown an exception!");
recurse = false;
}

View File

@ -21,6 +21,7 @@ try {
document.doctype.appendChild(document.createTextNode("test"));
ok(false, "Should have thrown an exception");
} catch (e) {
is(e.name, "HierarchyRequestError");
ok(e instanceof DOMException, "Should be a DOMException");
is(e.code, DOMException.HIERARCHY_REQUEST_ERR);
}

View File

@ -22,7 +22,8 @@ var caught = false;
try {
elmt.mozMatchesSelector("!!");
} catch(e) {
ok(e.code == DOMException.SYNTAX_ERR, "Error should be SYNTAX_ERROR");
ok(e.name == "SyntaxError", "Error should be SyntaxError");
ok(e.code == DOMException.SYNTAX_ERR, "Error code should be SYNTAX_ERR");
caught = true;
}
ok(caught, "An exception should have been thrown");

View File

@ -25,6 +25,9 @@ for (var i = 0; i < offsets.length; i++) {
range.comparePoint(document.doctype, offset);
} catch(e) {
threw = true;
is(e.name, "InvalidNodeTypeError",
"comparePoint(document.doctype, " + offset
+ ") must throw InvalidNodeTypeError");
is(Object.getPrototypeOf(e), DOMException.prototype,
"comparePoint(document.doctype, " + offset
+ ") must throw DOMException");
@ -42,6 +45,9 @@ for (var i = 0; i < offsets.length; i++) {
range.comparePoint(document.documentElement, offset);
} catch(e) {
threw = true;
is(e.name, "IndexSizeError",
"comparePoint(document.documentElement, " + offset
+ ") must throw IndexSizeError");
is(Object.getPrototypeOf(e), DOMException.prototype,
"comparePoint(document.documentElement, " + offset
+ ") must throw DOMException");

View File

@ -17,6 +17,8 @@ try {
range.insertNode(document.head);
} catch(e) {
var threw = true;
is(e.name, "HierarchyRequestError",
"Must throw HierarchyRequestError");
is(Object.getPrototypeOf(e), DOMException.prototype,
"Must throw DOMException");
is(e.code, DOMException.HIERARCHY_REQUEST_ERR,

View File

@ -35,10 +35,9 @@ function onAttrModified(event) {
});
}
function checkModification(e, funcName, argument, expectedRes, before, after) {
var shouldThrow = typeof(after) === "number";
function checkModification(e, funcName, argument, expectedRes, before, after, expectedException) {
var shouldThrow = typeof(expectedException) === "string";
if (shouldThrow) {
var expectedException = after;
// If an exception is thrown, the class attribute shouldn't change.
after = before;
}
@ -60,7 +59,7 @@ function checkModification(e, funcName, argument, expectedRes, before, after) {
} catch (e) {
if (!shouldThrow)
ok(false, "classList modification threw an exception " + contextMsg);
is(e.code, expectedException, "wrong exception thrown " + contextMsg);
is(e.name, expectedException, "wrong exception thrown " + contextMsg);
}
e.removeEventListener("DOMAttrModified", onAttrModified, false);
if (expectedRes !== null)
@ -206,18 +205,21 @@ function testClassList(e) {
e.classList.contains("");
ok(false, "classList.contains() didn't throw");
} catch (e) {
is(e.name, "SyntaxError", "wrong exception thrown");
is(e.code, DOMException.SYNTAX_ERR, "wrong exception thrown");
}
try {
e.classList.contains(" ");
ok(false, "classList.contains() didn't throw");
} catch (e) {
is(e.name, "InvalidCharacterError", "wrong exception thrown");
is(e.code, DOMException.INVALID_CHARACTER_ERR, "wrong exception thrown");
}
try {
e.classList.contains("aa ");
ok(false, "classList.contains() didn't throw");
} catch (e) {
is(e.name, "InvalidCharacterError", "wrong exception thrown");
is(e.code, DOMException.INVALID_CHARACTER_ERR, "wrong exception thrown");
}
@ -250,13 +252,13 @@ function testClassList(e) {
// add() method
function checkAdd(before, argument, after) {
checkModification(e, "add", argument, null, before, after);
function checkAdd(before, argument, after, expectedException) {
checkModification(e, "add", argument, null, before, after, expectedException);
}
checkAdd(null, "", DOMException.SYNTAX_ERR);
checkAdd(null, " ", DOMException.INVALID_CHARACTER_ERR);
checkAdd(null, "aa ", DOMException.INVALID_CHARACTER_ERR);
checkAdd(null, "", null, "SyntaxError");
checkAdd(null, " ", null, "InvalidCharacterError");
checkAdd(null, "aa ", null, "InvalidCharacterError");
checkAdd("a", "a", "a");
checkAdd("aa", "AA", "aa AA");
@ -276,13 +278,13 @@ function testClassList(e) {
// remove() method
function checkRemove(before, argument, after) {
checkModification(e, "remove", argument, null, before, after);
function checkRemove(before, argument, after, expectedException) {
checkModification(e, "remove", argument, null, before, after, expectedException);
}
checkRemove(null, "", DOMException.SYNTAX_ERR);
checkRemove(null, " ", DOMException.INVALID_CHARACTER_ERR);
checkRemove(null, "aa ", DOMException.INVALID_CHARACTER_ERR);
checkRemove(null, "", null, "SyntaxError");
checkRemove(null, " ", null, "InvalidCharacterError");
checkRemove(null, "aa ", null, "InvalidCharacterError");
checkRemove(null, "a", null);
checkRemove("", "a", "");
@ -315,12 +317,12 @@ function testClassList(e) {
// toggle() method
function checkToggle(before, argument, expectedRes, after) {
checkModification(e, "toggle", argument, expectedRes, before, after);
function checkToggle(before, argument, expectedRes, after, expectedException) {
checkModification(e, "toggle", argument, expectedRes, before, after, expectedException);
}
checkToggle(null, "", null, DOMException.SYNTAX_ERR);
checkToggle(null, "aa ", null, DOMException.INVALID_CHARACTER_ERR);
checkToggle(null, "", null, null, "SyntaxError");
checkToggle(null, "aa ", null, null, "InvalidCharacterError");
checkToggle(null, "a", true, "a");
checkToggle("", "a", true, "a");

View File

@ -301,7 +301,7 @@ r.onabort = function (event) {
is(loadEndHasRun, false, "loadend shouldn't have fired yet");
abortHasRun = true;
is(event.target.readyState, FileReader.DONE, "should be DONE while firing onabort");
is(event.target.error.code, FileError.ABORT_ERR, "error code set to ABORT for aborted reads");
is(event.target.error.name, "AbortError", "error set to AbortError for aborted reads");
is(event.target.result, null, "file data should be null on aborted reads");
}
r.onloadend = function (event) {
@ -309,7 +309,7 @@ r.onloadend = function (event) {
is(loadEndHasRun, false, "loadend should only fire once");
loadEndHasRun = true;
is(event.target.readyState, FileReader.DONE, "should be DONE while firing onabort");
is(event.target.error.code, FileError.ABORT_ERR, "error code set to ABORT for aborted reads");
is(event.target.error.name, "AbortError", "error set to AbortError for aborted reads");
is(event.target.result, null, "file data should be null on aborted reads");
}
r.onload = function() { ok(false, "load should not fire for aborted reads") };
@ -335,7 +335,7 @@ r.onabort = function (event) {
is(reuseAbortHasRun, false, "abort should only fire once");
reuseAbortHasRun = true;
is(event.target.readyState, FileReader.DONE, "should be DONE while firing onabort");
is(event.target.error.code, FileError.ABORT_ERR, "error code set to ABORT for aborted reads");
is(event.target.error.name, "AbortError", "error set to AbortError for aborted reads");
is(event.target.result, null, "file data should be null on aborted reads");
}
r.onload = function() { ok(false, "load should not fire for aborted reads") };

View File

@ -33,6 +33,7 @@ function runTest() {
this.responseText;
ok(false, "responseText access should have thrown.");
} catch (e) {
is(e.name, "InvalidStateError", "Should have thrown InvalidStateError.");
is(e.code, 11, "Should have thrown INVALID_STATE_ERR.");
}
is(this.responseXML.getElementsByTagName("div").length, 1, "There should be one div.");

View File

@ -101,6 +101,7 @@ function runTest() {
e = ex;
}
ok(e, "Should have thrown an exception");
is(e.name, "SyntaxError", "Should have thrown SyntaxError");
is(e.code, DOMException.SYNTAX_ERR, "Should have thrown DOMException.SYNTAX_ERR");
e = null;
@ -110,6 +111,7 @@ function runTest() {
e = ex;
}
ok(e, "Should have thrown an exception");
is(e.name, "SyntaxError", "Should have thrown SyntaxError");
is(e.code, DOMException.SYNTAX_ERR, "Should have thrown DOMException.SYNTAX_ERR");
e = null;
@ -119,6 +121,7 @@ function runTest() {
e = ex;
}
ok(e, "Should have thrown an exception");
is(e.name, "SyntaxError", "Should have thrown SyntaxError");
is(e.code, DOMException.SYNTAX_ERR, "Should have thrown DOMException.SYNTAX_ERR");
e = null;
@ -128,6 +131,7 @@ function runTest() {
e = ex;
}
ok(e, "Should have thrown an exception");
is(e.name, "SyntaxError", "Should have thrown SyntaxError");
is(e.code, DOMException.SYNTAX_ERR, "Should have thrown DOMException.SYNTAX_ERR");
e = null;

View File

@ -21,23 +21,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=685518
SimpleTest.waitForExplicitFinish();
const SECURITY_ERR = 0x80530012;
const BAD_URI_ERR = 0x805303f4;
const OK = 0;
function nameForErrorCode(code) {
switch(code) {
case OK: return "no error";
case SECURITY_ERR: return "security error";
case BAD_URI_ERR: return "bad URI error"
}
return "unexpected error (" + code + ")";
}
const BAD_URI_ERR = "NS_ERROR_DOM_BAD_URI_ERR";
const OK = "";
function verifyError(actual_error, expected_error, message) {
ok(actual_error == expected_error,
message + ": expected " + nameForErrorCode(expected_error)
+ ", got " + nameForErrorCode(actual_error));
message + ": expected " + expected_error + ", got " + actual_error);
}
var number_of_tests_live = 0;
@ -49,7 +38,7 @@ function testDone() {
SimpleTest.finish();
}
function testImage(url, crossOriginAttribute, expected_result) {
function testImage(url, crossOriginAttribute, expected_error) {
++number_of_tests_live;
var image;
if (crossOriginAttribute == "just-crossOrigin-without-value") {
@ -72,15 +61,15 @@ function testImage(url, crossOriginAttribute, expected_result) {
ctx.drawImage(this, 0, 0);
var data;
var actual_result;
var actual_error;
try {
data = ctx.getImageData(0, 0, 1, 1);
actual_result = OK;
actual_error = OK;
} catch (e) {
actual_result = e.result;
actual_error = e.name;
}
verifyError(actual_result, expected_result,
verifyError(actual_error, expected_error,
"drawImage then get image data on " + url +
" with crossOrigin=" + this.crossOrigin);
@ -93,12 +82,12 @@ function testImage(url, crossOriginAttribute, expected_result) {
ctx.fillRect(0, 0, c.width, c.height);
try {
data = ctx.getImageData(0, 0, 1, 1);
actual_result = OK;
actual_error = OK;
} catch (e) {
actual_result = e.result;
actual_error = e.name;
}
verifyError(actual_result, expected_result,
verifyError(actual_error, expected_error,
"createPattern+fill then get image data on " + url +
" with crossOrigin=" + this.crossOrigin);
@ -106,7 +95,7 @@ function testImage(url, crossOriginAttribute, expected_result) {
};
image.onerror = function(event) {
verifyError(BAD_URI_ERR, expected_result,
verifyError(BAD_URI_ERR, expected_error,
"image error handler for " + url +
" with crossOrigin=" + this.crossOrigin);
@ -148,10 +137,10 @@ for (var imgIdx = 0; imgIdx < imageFiles.length; ++imgIdx) {
for (var attrValIdx = 0; attrValIdx < attrValues.length; ++attrValIdx) {
var attrValData = attrValues[attrValIdx];
// Now compute the expected result
var expected_result;
var expected_error;
if (hostnameData[1] == "same-origin") {
// Same-origin; these should all Just Work
expected_result = OK;
expected_error = OK;
} else {
// Cross-origin
is(hostnameData[1], "cross-origin",
@ -160,34 +149,34 @@ for (var imgIdx = 0; imgIdx < imageFiles.length; ++imgIdx) {
if (CORSMode == "none") {
// Doesn't matter what headers the server sends; we're not
// using CORS on our end.
expected_result = SECURITY_ERR;
expected_error = "SecurityError";
} else {
// Check whether the server will let us talk to them
var CORSHeaders = imageFiles[imgIdx][1];
// We're going to look for CORS headers from the server
if (CORSHeaders == "none") {
// No CORS headers from server; load will fail.
expected_result = BAD_URI_ERR;
expected_error = BAD_URI_ERR;
} else if (CORSHeaders == "allow-all-anon") {
// Server only allows anonymous requests
if (CORSMode == "anonymous") {
expected_result = OK;
expected_error = OK;
} else {
is(CORSMode, "use-credentials",
"What other CORS modes are there?");
// A load with credentials against a server that only
// allows anonymous loads will fail.
expected_result = BAD_URI_ERR;
expected_error = BAD_URI_ERR;
}
} else {
is(CORSHeaders, "allow-single-server-creds",
"What other CORS headers could there be?");
// Our server should allow both anonymous and non-anonymous requests
expected_result = OK;
expected_error = OK;
}
}
}
testImage(url, attrValData[0], expected_result);
testImage(url, attrValData[0], expected_error);
}
}
}

View File

@ -20,9 +20,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=682299
/** Test for Bug 682299 **/
const MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
const SECURITY_ERR = 0x80530012;
function createCanvas(width, height) {
var c = document.createElement("canvas");
c.width = width;
@ -39,7 +36,7 @@ function testCanvasDrawImage(v) {
var data = ctx.getImageData(0, 0, 1, 1);
ok(true, "drawImage '" + v.src + "' then getImageData with crossorigin='" + v.crossorigin + "' worked");
} catch(error) {
ok(!v.crossorigin && error.result === SECURITY_ERR, "drawImage '" + v.src + "' then getImageData with crossorigin='" + v.crossorigin + "' failed");
ok(!v.crossorigin && error.name === "SecurityError", "drawImage '" + v.src + "' then getImageData with crossorigin='" + v.crossorigin + "' failed");
v.tainted = true;
}
}
@ -54,7 +51,7 @@ function testCanvasCreatePattern(v) {
var data = ctx.getImageData(0, 0, 1, 1);
ok(true, "createPattern '" + v.src + "' then getImageData with crossorigin='" + v.crossorigin + "' worked");
} catch(error) {
ok(!v.crossorigin && error.result === SECURITY_ERR, "createPattern '" + v.src + "' then getImageData with crossorigin='" + v.crossorigin + "' failed");
ok(!v.crossorigin && error.name === "SecurityError", "createPattern '" + v.src + "' then getImageData with crossorigin='" + v.crossorigin + "' failed");
v.tainted = true;
}
}
@ -67,7 +64,7 @@ function testWebGL(v) {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, v);
ok(true, "createTexture from '" + v.src + "' with crossorigin='" + v.crossorigin + "' worked");
} catch (error) {
ok(!v.crossorigin && error.result === SECURITY_ERR, "createTexture from '" + v.src + "' with crossorigin='" + v.crossorigin + "' failed");
ok(!v.crossorigin && error.name === "SecurityError", "createTexture from '" + v.src + "' with crossorigin='" + v.crossorigin + "' failed");
v.tainted = true;
}
}
@ -81,7 +78,7 @@ function testTaintedCanvas(v) {
var data = ctx.getImageData(0, 0, 1, 1);
ok(false, "changing the CORS mode should not allow reading data from remote videos");
} catch (error) {
ok(error.result === SECURITY_ERR, "changing the CORS mode, drawImage '" + v.src + "' then getImageData with crossorigin='" + v.crossorigin + "' failed");
ok(error.name === "SecurityError", "changing the CORS mode, drawImage '" + v.src + "' then getImageData with crossorigin='" + v.crossorigin + "' failed");
}
}
@ -108,7 +105,7 @@ function vidLoadFailure(e) {
}
function vidErrorSuccess(e) {
ok(e.target.error.code === MEDIA_ERR_SRC_NOT_SUPPORTED,
ok(e.target.error.code === MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED,
"Load '" + e.target.src + "' with crossorigin='" + e.target.crossorigin + "'");
doneTest(e);
}

View File

@ -11,28 +11,18 @@
SimpleTest.waitForExplicitFinish();
const SECURITY_ERR = 0x80530012;
const OK = 0;
const OK = "";
var gl;
var number_of_tests_live = 0;
var all_tests_started = false;
function nameForErrorCode(code) {
switch(code) {
case OK: return "no error";
case SECURITY_ERR: return "security error";
}
return "unexpected error (" + code + ")";
}
function verifyError(actual_error, expected_error, message) {
ok(actual_error == expected_error,
message + ": expected " + nameForErrorCode(expected_error)
+ ", got " + nameForErrorCode(actual_error));
message + ": expected " + expected_error + ", got " + actual_error);
}
function testTexture(url, crossOriginAttribute, expected_result) {
function testTexture(url, crossOriginAttribute, expected_error) {
number_of_tests_live++;
var image = new Image();
if (crossOriginAttribute == "just-crossOrigin-without-value") {
@ -54,19 +44,19 @@
image.onload = function() {
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
var actual_result = OK;
var actual_error = OK;
try {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
} catch(e) {
actual_result = e.result;
actual_error = e.name;
}
verifyError(actual_result, expected_result, "texImage2D on " + url + " with crossOrigin=" + image.crossOrigin);
verifyError(actual_error, expected_error, "texImage2D on " + url + " with crossOrigin=" + image.crossOrigin);
testDone();
};
image.onerror = function(event) {
ok(expected_result != OK, "Got an error but expected OK!");
ok(expected_error != OK, "Got an error but expected OK!");
testDone();
}
@ -96,17 +86,17 @@
OK);
testTexture("http://example.com/tests/content/canvas/test/crossorigin/image.png",
"missing-value-default",
SECURITY_ERR);
"SecurityError");
testTexture("http://example.com/tests/content/canvas/test/crossorigin/image.png",
"",
SECURITY_ERR);
"SecurityError");
testTexture("http://example.com/tests/content/canvas/test/crossorigin/image.png",
"just-crossOrigin-without-value",
SECURITY_ERR);
"SecurityError");
testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-star.png",
"missing-value-default",
SECURITY_ERR);
"SecurityError");
testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-star.png",
"",
OK);
@ -118,11 +108,11 @@
OK);
testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-star.png",
"use-credentials",
SECURITY_ERR);
"SecurityError");
testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-credentials.png",
"missing-value-default",
SECURITY_ERR);
"SecurityError");
testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-credentials.png",
"",
OK);
@ -142,7 +132,7 @@
OK);
testTexture("http://example.com/tests/content/canvas/test/crossorigin/image.png",
"foobar",
SECURITY_ERR);
"SecurityError");
testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-star.png",
"foobar",
OK);

View File

@ -33,19 +33,19 @@ canvas2.width = 0;
canvas2.height = 10;
var _thrown = undefined; try {
ctx.drawImage(canvas2, 0, 0);
} catch (e) { _thrown = e }; ok(_thrown && _thrown.code == DOMException.INVALID_STATE_ERR, "should throw INVALID_STATE_ERR");
} catch (e) { _thrown = e }; ok(_thrown && _thrown.name == "InvalidStateError" && _thrown.code == DOMException.INVALID_STATE_ERR, "should throw InvalidStateError");
canvas2.width = 10;
canvas2.height = 0;
var _thrown = undefined; try {
ctx.drawImage(canvas2, 0, 0);
} catch (e) { _thrown = e }; ok(_thrown && _thrown.code == DOMException.INVALID_STATE_ERR, "should throw INVALID_STATE_ERR");
} catch (e) { _thrown = e }; ok(_thrown && _thrown.name == "InvalidStateError" && _thrown.code == DOMException.INVALID_STATE_ERR, "should throw InvalidStateError");
canvas2.width = 0;
canvas2.height = 0;
var _thrown = undefined; try {
ctx.drawImage(canvas2, 0, 0);
} catch (e) { _thrown = e }; ok(_thrown && _thrown.code == DOMException.INVALID_STATE_ERR, "should throw INVALID_STATE_ERR");
} catch (e) { _thrown = e }; ok(_thrown && _thrown.name == "InvalidStateError" && _thrown.code == DOMException.INVALID_STATE_ERR, "should throw InvalidStateError");
isPixel(ctx, 50,25, 0,255,0,255, "50,25", "0,255,0,255", 2);

View File

@ -39,11 +39,11 @@ try {
c.putImageData({ width: 1, height: 1, data: null }, 0, 0);
threw = false;
} catch(e) {
threw = e.code;
threw = e.name;
}
is(threw, DOMException.TYPE_MISMATCH_ERR,
"Should throw type error when data is not an array");
is(threw, "TypeMismatchError",
"Should throw TypeMismatchError when data is not an array");
</script>
</pre>

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@
<head>
<script type="text/javascript">
function init() {
// This will throw a NS_ERROR_DOM_WRONG_DOCUMENT_ERR exception
// This will throw a HierarchyRequestError exception
var doc = document.implementation.createDocument(null, 'DOC', null);
doc.documentElement.appendChild(doc);
}

View File

@ -3,7 +3,7 @@
<head>
<script type="text/javascript">
function init() {
// This will throw a NS_ERROR_DOM_WRONG_DOCUMENT_ERR exception
// This will throw a HierarchyRequestError exception
var doc = document.implementation.createDocument(null, 'DOC', null);
doc.documentElement.appendChild(doc);
}

View File

@ -26,10 +26,10 @@ try {
is(e.type, "", "Event type should be empty string before initialization");
document.dispatchEvent(e);
} catch(ex) {
didThrow = (ex.code == DOMException.INVALID_STATE_ERR);
didThrow = (ex.name == "InvalidStateError" && ex.code == DOMException.INVALID_STATE_ERR);
}
ok(didThrow, "Should have thrown INVALID_STATE_ERR!");
ok(didThrow, "Should have thrown InvalidStateError!");
</script>
</pre>

View File

@ -210,7 +210,8 @@ function reflectUnsignedInt(aParameters)
element[attr] = 0;
} catch(e) {
caught = true;
is(e.code, DOMException.INDEX_SIZE_ERR, "exception should be INDEX_SIZE_ERR");
is(e.name, "IndexSizeError", "exception should be IndexSizeError");
is(e.code, DOMException.INDEX_SIZE_ERR, "exception code should be INDEX_SIZE_ERR");
}
if (nonZero) {
@ -550,10 +551,12 @@ function reflectInt(aParameters)
if (nonNegative && expectedIdlAttributeResult(v) < 0) {
try {
element[attr] = v;
ok(false, element.localName + "[" + attr + "] = " + v + " should throw NS_ERROR_DOM_INDEX_SIZE_ERR");
ok(false, element.localName + "[" + attr + "] = " + v + " should throw IndexSizeError");
} catch(e) {
is(e.name, "IndexSizeError", element.localName + "[" + attr + "] = " + v +
" should throw IndexSizeError");
is(e.code, DOMException.INDEX_SIZE_ERR, element.localName + "[" + attr + "] = " + v +
" should throw NS_ERROR_DOM_INDEX_SIZE_ERR");
" should throw INDEX_SIZE_ERR");
}
} else {
element[attr] = v;

View File

@ -35,9 +35,10 @@ function checkNegativeMaxLengthException(element)
try {
element.maxLength = -20;
} catch(e) {
is(e.name, "IndexSizeError", "Should be an IndexSizeError exception");
caught = true;
}
ok(caught, "Setting negative maxLength from the DOM should throw an INDEX_SIZE_ERR exception");
ok(caught, "Setting negative maxLength from the DOM should throw an exception");
is(element.getAttribute('maxLength'), -10, "When the exception is raised, the maxLength attribute shouldn't change");
}

View File

@ -27,6 +27,8 @@ function test() {
document.open();
is(0, 1, "document.open succeeded");
} catch (e) {
is (e.name, "InvalidStateError",
"Wrong exception from document.open");
is (e.code, DOMException.INVALID_STATE_ERR,
"Wrong exception from document.open");
}
@ -35,6 +37,8 @@ function test() {
document.write("aaa");
is(0, 1, "document.write succeeded");
} catch (e) {
is (e.name, "InvalidStateError",
"Wrong exception from document.write");
is (e.code, DOMException.INVALID_STATE_ERR,
"Wrong exception from document.write");
}
@ -43,6 +47,8 @@ function test() {
document.writeln("aaa");
is(0, 1, "document.write succeeded");
} catch (e) {
is (e.name, "InvalidStateError",
"Wrong exception from document.write");
is (e.code, DOMException.INVALID_STATE_ERR,
"Wrong exception from document.write");
}
@ -51,6 +57,8 @@ function test() {
document.close();
is(0, 1, "document.close succeeded");
} catch (e) {
is (e.name, "InvalidStateError",
"Wrong exception from document.close");
is (e.code, DOMException.INVALID_STATE_ERR,
"Wrong exception from document.close");
}

View File

@ -21,6 +21,8 @@ try {
document.createElement("<div>");
ok(false, "Should throw.")
} catch (e) {
is(e.name, "InvalidCharacterError",
"Expected InvalidCharacterError.");
ok(e instanceof DOMException, "Expected DOMException.");
is(e.code, DOMException.INVALID_CHARACTER_ERR,
"Expected INVALID_CHARACTER_ERR.");

View File

@ -38,7 +38,7 @@ function ended(e) {
try {
b.start(-1);
} catch (e) {
caught = e.code == DOMException.INDEX_SIZE_ERR;
caught = e.name == "IndexSizeError" && e.code == DOMException.INDEX_SIZE_ERR;
}
is(caught, true, v._name + ": Should throw INDEX_SIZE_ERR on under start bounds range");
@ -46,7 +46,7 @@ function ended(e) {
try {
b.end(-1);
} catch (e) {
caught = e.code == DOMException.INDEX_SIZE_ERR;
caught = e.name == "IndexSizeError" && e.code == DOMException.INDEX_SIZE_ERR;
}
is(caught, true, v._name + ": Should throw INDEX_SIZE_ERR on under end bounds range");
@ -54,7 +54,7 @@ function ended(e) {
try {
b.start(b.length);
} catch (e) {
caught = e.code == DOMException.INDEX_SIZE_ERR;
caught = e.name == "IndexSizeError" && e.code == DOMException.INDEX_SIZE_ERR;
}
is(caught, true, v._name + ": Should throw INDEX_SIZE_ERR on over start bounds range");
@ -62,7 +62,7 @@ function ended(e) {
try {
b.end(b.length);
} catch (e) {
caught = e.code == DOMException.INDEX_SIZE_ERR;
caught = e.name == "IndexSizeError" && e.code == DOMException.INDEX_SIZE_ERR;
}
is(caught, true, v._name + ": Should throw INDEX_SIZE_ERR on over end bounds range");

View File

@ -11,7 +11,7 @@
<script class="testbody" type="text/javascript">
// http://www.whatwg.org/specs/web-apps/current-work/#dom-media-seek
// If the media element's readyState is HAVE_NOTHING, then the user agent
// must raise an INVALID_STATE_ERR exception.
// must raise an InvalidStateError exception.
var v = document.getElementById('v');
var passed = false;

View File

@ -167,8 +167,10 @@ function test(spec, charCode, keyCode, offset, modifiers)
"Unexpected start time for animation with begin: " + spec);
}
} catch(e) {
is(e.name, "InvalidStateError",
"Unexpected exception: " + e.name);
is(e.code, DOMException.INVALID_STATE_ERR,
"Unexpected exception code: " + e);
"Unexpected exception code: " + e.code);
gotStartTimeOk = false;
}
@ -229,6 +231,8 @@ function testOpenEnd()
is(anim.getStartTime(), 2,
"Unexpected start time for second interval of open-ended animation");
} catch(e) {
is(e.name, "InvalidStateError",
"Unexpected exception:" + e.name);
is(e.code, DOMException.INVALID_STATE_ERR,
"Unexpected exception code:" + e.code);
ok(false, "Failed to recognise accessKey as qualifying for creating an " +

View File

@ -173,7 +173,8 @@ function checkStartTime(anim, expectedStartTime, sampleTime, caseNum, id)
try {
startTime = anim.getStartTime();
} catch (e) {
if (e.code != DOMException.INVALID_STATE_ERR)
if (e.name != "InvalidStateError" ||
e.code != DOMException.INVALID_STATE_ERR)
throw e;
}

View File

@ -84,6 +84,8 @@ function noStart(elem) {
elem.getStartTime();
} catch(e) {
exceptionCaught = true;
is (e.name, "InvalidStateError",
"Unexpected exception from getStartTime.");
is (e.code, DOMException.INVALID_STATE_ERR,
"Unexpected exception code from getStartTime.");
}

View File

@ -115,6 +115,8 @@ function noStart(elem) {
elem.getStartTime();
} catch(e) {
exceptionCaught = true;
is (e.name, "InvalidStateError",
"Unexpected exception from getStartTime.");
is (e.code, DOMException.INVALID_STATE_ERR,
"Unexpected exception code from getStartTime");
}

View File

@ -68,6 +68,8 @@ function checkForException(anim, descr) {
try {
var dur = anim.getSimpleDuration();
} catch(e) {
is (e.name, "NotSupportedError",
"Wrong exception from getSimpleDuration");
is (e.code, DOMException.NOT_SUPPORTED_ERR,
"Wrong exception from getSimpleDuration");
gotException = true;

View File

@ -34,6 +34,8 @@ function main() {
anim.getStartTime();
} catch(e) {
exceptionCaught = true;
is(e.name, "InvalidStateError",
"Unexpected exception from getStartTime.");
is(e.code, DOMException.INVALID_STATE_ERR,
"Unexpected exception code from getStartTime.");
}
@ -83,6 +85,8 @@ function main() {
anim.getStartTime();
} catch(e) {
exceptionCaught = true;
is(e.name, "InvalidStateError",
"Unexpected exception from getStartTime.");
is(e.code, DOMException.INVALID_STATE_ERR,
"Unexpected exception code from getStartTime.");
}

View File

@ -44,7 +44,8 @@ function tryRestart(elem, state, expected) {
try {
restart = (elem.getStartTime() === restartTime);
} catch (e) {
if (e.code != DOMException.INVALID_STATE_ERR)
if (e.name != "InvalidStateError" ||
e.code != DOMException.INVALID_STATE_ERR)
throw e;
restart = false;
}

View File

@ -82,7 +82,8 @@ function testSpecs() {
ok(false, "Unexpected success with spec: " + spec);
}
} catch(e) {
if (e.code == DOMException.INVALID_STATE_ERR) {
if (e.name == "InvalidStateError" &&
e.code == DOMException.INVALID_STATE_ERR) {
if (typeof(expected) == 'number')
ok(false, "Failed with spec: " + spec);
else if (expected == 'todo')
@ -162,6 +163,8 @@ function noStart(elem) {
elem.getStartTime();
} catch(e) {
exceptionCaught = true;
is (e.name, "InvalidStateError",
"Unexpected exception from getStartTime.");
is (e.code, DOMException.INVALID_STATE_ERR,
"Unexpected exception code from getStartTime.");
}

View File

@ -268,7 +268,8 @@ function getStartTime(anim) {
// We round start times to 3 decimal places to make comparisons simpler
startTime = parseFloat(startTime.toFixed(3));
} catch(e) {
if (e.code == DOMException.INVALID_STATE_ERR) {
if (e.name == "InvalidStateError" &&
e.code == DOMException.INVALID_STATE_ERR) {
startTime = 'none';
} else {
ok(false, "Unexpected exception: " + e);

View File

@ -46,7 +46,8 @@ function main() {
is(anim.getSimpleDuration(), 4, "Simple duration shouldn't have changed");
is(anim.getStartTime(), 2, "Start time shouldn't have changed after seek");
} catch (e) {
if (e.code != DOMException.INVALID_STATE_ERR)
if (e.name != "InvalidStateError" ||
e.code != DOMException.INVALID_STATE_ERR)
throw e;
ok(false, "Animation ended too early, even though begin time and " +
"simple duration didn't change");

View File

@ -220,6 +220,9 @@ function testReadOnly(g)
try {
roList.consolidate();
} catch (e) {
is(e.name, "NoModificationAllowedError",
"Got unexpected exception " + e +
", expected NoModificationAllowedError");
is(e.code, DOMException.NO_MODIFICATION_ALLOWED_ERR,
"Got unexpected exception " + e +
", expected NO_MODIFICATION_ALLOWED_ERR");
@ -239,6 +242,9 @@ function testReadOnly(g)
var m = createMatrix(1, 2, 3, 4, 5, 6);
roTransform.setMatrix(m);
} catch (e) {
is(e.name, "NoModificationAllowedError",
"Got unexpected exception " + e +
", expected NoModificationAllowedError");
is(e.code, DOMException.NO_MODIFICATION_ALLOWED_ERR,
"Got unexpected exception " + e +
", expected NO_MODIFICATION_ALLOWED_ERR");
@ -294,6 +300,9 @@ function testReadOnly(g)
try {
roMatrix.a = 1;
} catch (e) {
is(e.name, "NoModificationAllowedError",
"Got unexpected exception " + e +
", expected NoModificationAllowedError");
is(e.code, DOMException.NO_MODIFICATION_ALLOWED_ERR,
"Got unexpected exception " + e +
", expected NO_MODIFICATION_ALLOWED_ERR");

View File

@ -93,7 +93,8 @@ function checkReadOnly(animLength) {
try {
animLength.animVal.value = (animLength.animVal.value == 77) ? 88 : 77;
} catch (e) {
if (e.code == DOMException.NO_MODIFICATION_ALLOWED_ERR) {
if (e.name == "NoModificationAllowedError" &&
e.code == DOMException.NO_MODIFICATION_ALLOWED_ERR) {
exceptionCaught = true;
} else {
ok(false, "Got unexpected exception " + e);

View File

@ -34,6 +34,9 @@ function runTests(text, charWidth)
}
catch (e)
{
is(e.name, "IndexSizeError",
"expected an index error for " +
"text.getSubStringLength(" + charnum + "," + nchars + ")");
is(e.code, DOMException.INDEX_SIZE_ERR,
"expected an index error for " +
"text.getSubStringLength(" + charnum + "," + nchars + ")");

View File

@ -36,7 +36,8 @@ function run()
try {
c.r.baseVal.valueAsString = 'rubbish';
} catch (e) {
is(DOMException.SYNTAX_ERR, e.code, 'syntax error expected');
is(e.name, 'SyntaxError', 'syntax error expected');
is(e.code, DOMException.SYNTAX_ERR, 'syntax error expected');
}
is(SVGAngle.SVG_ANGLETYPE_RAD, m.orientAngle.baseVal.unitType, 'unexpected units');
@ -46,7 +47,8 @@ function run()
try {
m.orientAngle.baseVal.valueAsString = 'rubbish';
} catch (e) {
is(DOMException.SYNTAX_ERR, e.code, 'syntax error expected');
is(e.name, 'SyntaxError', 'syntax error expected');
is(e.code, DOMException.SYNTAX_ERR, 'syntax error expected');
}
SimpleTest.finish();

View File

@ -35,15 +35,11 @@
* ***** END LICENSE BLOCK ***** */
const C_i = Components.interfaces;
const C_r = Components.results;
const UNORDERED_TYPE = C_i.nsIDOMXPathResult.ANY_UNORDERED_NODE_TYPE;
const INVALID_STATE_ERR = 0x8053000b; // NS_ERROR_DOM_INVALID_STATE_ERR
const INDEX_SIZE_ERR = 0x80530001; // NS_ERROR_DOM_INDEX_SIZE_ERR
const INVALID_NODE_TYPE_ERR = 0x805c0002; // NS_ERROR_DOM_INVALID_NODE_TYPE_ERR
const NOT_OBJECT_ERR = 0x805303eb; // NS_ERROR_DOM_NOT_OBJECT_ERR
const SECURITY_ERR = 0x80530012; // NS_ERROR_DOM_SECURITY_ERR
// Instantiate nsIDOMScriptObjectFactory so that DOMException is usable in xpcshell
Components.classesByID["{9eb760f0-4380-11d2-b328-00805f8a3859}"].getService(C_i.nsISupports);
/**
* Determine if the data node has only ignorable white-space.
@ -402,27 +398,24 @@ function run_miscellaneous_tests() {
try {
baseRange.setStart(null, 0);
do_throw("Should have thrown NOT_OBJECT_ERR!");
} catch (e if (e instanceof C_i.nsIException &&
e.result == NOT_OBJECT_ERR)) {
// do nothing
} catch (e) {
do_check_eq(e.name, "NS_ERROR_DOM_NOT_OBJECT_ERR");
}
// Invalid start node
try {
baseRange.setStart({}, 0);
do_throw("Should have thrown SECURITY_ERR!");
} catch (e if (e instanceof C_i.nsIException &&
e.result == SECURITY_ERR)) {
// do nothing
do_throw("Should have thrown SecurityError!");
} catch (e) {
do_check_eq(e.name, "SecurityError");
}
// Invalid index
try {
baseRange.setStart(startContainer, -1);
do_throw("Should have thrown INVALID_STATE_ERR!");
} catch (e if (e instanceof C_i.nsIException &&
e.result == INDEX_SIZE_ERR)) {
// do nothing
do_throw("Should have thrown IndexSizeError!");
} catch (e) {
do_check_eq(e.name, "IndexSizeError");
}
// Invalid index
@ -431,10 +424,9 @@ function run_miscellaneous_tests() {
startContainer.childNodes.length + 1;
try {
baseRange.setStart(startContainer, newOffset);
do_throw("Should have thrown INVALID_STATE_ERR!");
} catch (e if (e instanceof C_i.nsIException &&
e.result == INDEX_SIZE_ERR)) {
// do nothing
do_throw("Should have thrown IndexSizeError!");
} catch (e) {
do_check_eq(e.name, "IndexSizeError");
}
newOffset--;

View File

@ -94,6 +94,7 @@
stores[indexName] = objectStore;
} catch (e) {
ok("exception" in info, "should throw" + test);
is(e.name, "SyntaxError", "expect a SyntaxError" + test);
ok(e instanceof DOMException, "Got a DOM Exception" + test);
is(e.code, DOMException.SYNTAX_ERR, "expect a syntax error" + test);
continue;
@ -146,6 +147,7 @@
indexes[indexName] = index;
} catch (e) {
ok("exception" in info, "should throw" + test);
is(e.name, "SyntaxError", "expect a SyntaxError" + test);
ok(e instanceof DOMException, "Got a DOM Exception" + test);
is(e.code, DOMException.SYNTAX_ERR, "expect a syntax error" + test);
continue;
@ -232,8 +234,9 @@
}
catch(e) {
ok(true, "Did throw when creating empty-keypath autoincrement store");
is(e.name, "InvalidAccessError", "expect an InvalidAccessError when creating empty-keypath autoincrement store");
ok(e instanceof DOMException, "Got a DOMException when creating empty-keypath autoincrement store");
is(e.code, DOMException.INVALID_ACCESS_ERR, "expect a INVALID_ACCESS_ERR when creating empty-keypath autoincrement store");
is(e.code, DOMException.INVALID_ACCESS_ERR, "expect an INVALID_ACCESS_ERR when creating empty-keypath autoincrement store");
}
openRequest.onsuccess = grabEventAndContinueHandler;

View File

@ -41,6 +41,7 @@ let gSteps = [
gLock.unlock();
ok(false, "Should have thrown an error.");
} catch (e) {
is(e.name, "InvalidStateError", "double unlock should throw InvalidStateError");
is(e.code, DOMException.INVALID_STATE_ERR, "double unlock should throw InvalidStateError");
}

View File

@ -12,7 +12,8 @@ function expectInvalidState(fn, desc) {
try {
fn();
} catch(e) {
if (e.code == DOMException.INVALID_STATE_ERR) {
if (e.name == "InvalidStateError" &&
e.code == DOMException.INVALID_STATE_ERR) {
gotInvalidState = true;
}
}
@ -25,9 +26,9 @@ is(applicationCache.mozLength, 0, "applicationCache.mozLength should be 0");
is(applicationCache.status, 0, "applicationCache.status should be 0 (UNCACHED)");
expectInvalidState(function() { applicationCache.update(); },
"applicationCache.update should throw INVALID_STATE_ERR");
"applicationCache.update should throw InvalidStateError");
expectInvalidState(function() { applicationCache.swapCache(); },
"applicationCache.update should throw INVALID_STATE_ERR");
"applicationCache.update should throw InvalidStateError");
</script>

View File

@ -22,14 +22,18 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=558973
var child = document.createTextNode("a");
var text = document.createTextNode("a");
var exception = 0;
var exception = "";
var exceptionCode = 0;
try {
text.appendChild(child);
}
catch (e) {
exception = e.code;
exception = e.name;
exceptionCode = e.code;
}
is(exception, DOMException.HIERARCHY_REQUEST_ERR,
is(exception, "HierarchyRequestError",
"Expected HierarchyRequestError");
is(exceptionCode, DOMException.HIERARCHY_REQUEST_ERR,
"Expected DOMException.HIERARCHY_REQUEST_ERR");
</script>

View File

@ -49,6 +49,7 @@ function runTest() {
document.documentElement.outerHTML = "<html></html>";
ok(false, "Should have thrown an exception");
} catch(e) {
is(e.name, "NoModificationAllowedError", "outerHTML should throw NoModificationAllowedError");
is(e.code, 7, "outerHTML should throw NO_MODIFICATION_ALLOWED_ERR");
}

View File

@ -50,6 +50,7 @@ function runTest() {
document.documentElement.outerHTML = "<html></html>";
ok(false, "Should have thrown an exception");
} catch(e) {
is(e.name, "NoModificationAllowedError", "outerHTML should throw NoModificationAllowedError");
is(e.code, 7, "outerHTML should throw NO_MODIFICATION_ALLOWED_ERR");
}

View File

@ -13,8 +13,6 @@
<script type="text/javascript">
var INDEX_SIZE_ERR = 1;
function startTest()
{
try

View File

@ -36,10 +36,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=417075
SimpleTest.waitForExplicitFinish();
function errorCheck(i, called, errorCode, actualCode)
function errorCheck(i, called, error, actual)
{
ok(!called, "receiver should not have been called for test #" + i);
is(actualCode, errorCode, "wrong error thrown in test #" + i);
is(actual, error, "wrong error thrown in test #" + i);
}
var tests =
@ -48,26 +48,31 @@ var tests =
{
args: ["NOT-RECEIVED", ""],
source: "sameDomain",
name: "SyntaxError",
code: DOMException.SYNTAX_ERR
},
{
args: ["NOT-RECEIVED", "null"],
source: "sameDomain",
name: "SyntaxError",
code: DOMException.SYNTAX_ERR
},
{
args: ["NOT-RECEIVED", "a"],
source: "sameDomain",
name: "SyntaxError",
code: DOMException.SYNTAX_ERR
},
{
args: ["NOT-RECEIVED", "http :"],
source: "sameDomain",
name: "SyntaxError",
code: DOMException.SYNTAX_ERR
},
{
args: ["NOT-RECEIVED", "http: //"],
source: "sameDomain",
name: "SyntaxError",
code: DOMException.SYNTAX_ERR,
hasThrowsNoExceptionBug: true
@ -76,11 +81,13 @@ var tests =
{
args: ["NOT-RECEIVED", "http ://"],
source: "sameDomain",
name: "SyntaxError",
code: DOMException.SYNTAX_ERR
},
{
args: ["TODO", " http://localhost:8888"],
source: "sameDomain",
name: "SyntaxError",
code: DOMException.SYNTAX_ERR,
returnOrigin: "http://mochi.test:8888",
@ -89,16 +96,19 @@ var tests =
{
args: ["NOT-RECEIVED", "hä"],
source: "sameDomain",
name: "SyntaxError",
code: DOMException.SYNTAX_ERR
},
{
args: ["NOT-RECEIVED", "http://lo\0k.com"],
source: "sameDomain",
name: "SyntaxError",
code: DOMException.SYNTAX_ERR
},
{
args: ["NOT-RECEIVED", "http: //localhost:8888"],
source: "sameDomain",
name: "SyntaxError",
code: DOMException.SYNTAX_ERR,
hasThrowsNoExceptionBug: true
@ -107,11 +117,13 @@ var tests =
{
args: ["NOT-RECEIVED", "http://localhost :8888"],
source: "sameDomain",
name: "SyntaxError",
code: DOMException.SYNTAX_ERR
},
{
args: ["NOT-RECEIVED", "http:// localhost:8888"],
source: "sameDomain",
name: "SyntaxError",
code: DOMException.SYNTAX_ERR,
hasThrowsNoExceptionBug: true
@ -119,6 +131,7 @@ var tests =
{
args: ["TODO", "http://\nlocalhost:8888"],
source: "sameDomain",
name: "SyntaxError",
code: DOMException.SYNTAX_ERR,
returnOrigin: "http://mochi.test:8888",
@ -127,6 +140,7 @@ var tests =
{
args: ["TODO", "http://localhost:8888\0"],
source: "sameDomain",
name: "SyntaxError",
code: DOMException.SYNTAX_ERR,
returnOrigin: "http://mochi.test:8888",
@ -135,6 +149,7 @@ var tests =
{
args: ["TODO", "http://localhost:8888\n"],
source: "sameDomain",
name: "SyntaxError",
code: DOMException.SYNTAX_ERR,
returnOrigin: "http://mochi.test:8888",
@ -372,6 +387,7 @@ var tests =
{
args: ["NOT-RECEIVED", undefined],
source: "sameDomain",
name: "SyntaxError",
code: DOMException.SYNTAX_ERR
},
];
@ -422,6 +438,7 @@ function allTests(callback)
// Since an exception was thrown, we know at this point that we're not
// waiting on anything else in the queue of script to run, and we can just
// call nextTest directly.
errorCheck(i, called, e.name, test.name);
errorCheck(i, called, e.code, test.code);
nextTest();
return;

View File

@ -25,6 +25,7 @@ function t(n) {
ok(false, "Should not be here");
} catch(e) {
ok(e instanceof DOMException, "Should be a DOMException");
is(e.name, "IndexSizeError", "Should be an IndexSizeError");
is(e.code, DOMException.INDEX_SIZE_ERR, "Should be an INDEX_SIZE_ERR");
}
}

View File

@ -23,6 +23,7 @@ function t(m) {
sel[m]();
ok(false, "Should not be here");
} catch(e) {
is(e.name, "InvalidStateError", "Should be an InvalidStateError");
ok(e instanceof DOMException, "Should be a DOMException");
is(e.code, DOMException.INVALID_STATE_ERR, "Should be an INVALID_STATE_ERR");
}

View File

@ -15,6 +15,8 @@ try {
getSelection().extend(document.body, 0);
} catch(e) {
thrown = true;
is(e.name, "InvalidStateError",
"Need to throw InvalidStateError for extend() with no ranges");
ok(e instanceof DOMException,
"Need to throw DOMException for extend() with no ranges");
is(e.code, DOMException.INVALID_STATE_ERR,

View File

@ -4,7 +4,7 @@
Check that pausing the base time container makes dependent times unresolved.
-->
<head>
<script>
<script><!----><![CDATA[
function snapshot() {
var a = document.getElementById("svg-a");
var b = document.getElementById("svg-b");
@ -17,13 +17,14 @@ function snapshot() {
try {
document.getElementById("a").getStartTime();
} catch (e) {
if (e.code == DOMException.INVALID_STATE_ERR) {
if (e.name == "InvalidStateError" &&
e.code == DOMException.INVALID_STATE_ERR) {
wrong.style.setProperty('visibility', 'hidden', '');
}
}
document.documentElement.removeAttribute("class");
}
</script>
//]]></script>
</head>
<body onload="snapshot()">
<svg xmlns="http://www.w3.org/2000/svg" width="120px" height="120px" id="svg-a">

View File

@ -297,12 +297,12 @@
while(sheet.cssRules.length > 0)
sheet.deleteRule(0);
sheet.insertRule(testset[curTest].rule, 0);
} catch (e if e instanceof DOMException) {
ok(e.code == DOMException.SYNTAX_ERR
} catch (e) {
ok(e.name == "SyntaxError"
&& e instanceof DOMException
&& e.code == DOMException.SYNTAX_ERR
&& !('d' in testset[curTest]),
testset[curTest].rule + " syntax error thrown", e);
} catch (e) {
ok(false, testset[curTest].rule, "During prep: " + e);
}
try {

View File

@ -239,6 +239,8 @@ function run() {
ifdoc.body.mozMatchesSelector(selector);
ok(false, "selector '" + selector + "' plus EOF is parse error");
} catch(ex) {
is(ex.name, "SyntaxError",
"selector '" + selector + "' plus EOF is parse error");
is(ex.code, DOMException.SYNTAX_ERR,
"selector '" + selector + "' plus EOF is parse error");
}

View File

@ -34,6 +34,7 @@ try {
content.insertAdjacentHTML("bar", "foo");
ok(false, "insertAdjacentHTML should have thrown");
} catch (e) {
is(e.name, "SyntaxError", "insertAdjacentHTML should throw SyntaxError");
is(e.code, 12, "insertAdjacentHTML should throw SYNTAX_ERR");
}
@ -44,6 +45,7 @@ try {
child.insertAdjacentHTML("Beforebegin", "foo");
ok(false, "insertAdjacentHTML should have thrown");
} catch (e) {
is(e.name, "NoModificationAllowedError", "insertAdjacentHTML should throw NoModificationAllowedError");
is(e.code, 7, "insertAdjacentHTML should throw NO_MODIFICATION_ALLOWED_ERR");
}
@ -51,6 +53,7 @@ try {
child.insertAdjacentHTML("AfterEnd", "foo");
ok(false, "insertAdjacentHTML should have thrown");
} catch (e) {
is(e.name, "NoModificationAllowedError", "insertAdjacentHTML should throw NoModificationAllowedError");
is(e.code, 7, "insertAdjacentHTML should throw NO_MODIFICATION_ALLOWED_ERR");
}
@ -66,6 +69,7 @@ try {
document.documentElement.insertAdjacentHTML("afterend", "<div></div>");
ok(false, "insertAdjacentHTML should have thrown");
} catch (e) {
is(e.name, "NoModificationAllowedError", "insertAdjacentHTML should throw NoModificationAllowedError");
is(e.code, 7, "insertAdjacentHTML should throw NO_MODIFICATION_ALLOWED_ERR");
}

View File

@ -33,6 +33,7 @@ try {
content.insertAdjacentHTML("bar", "foo");
ok(false, "insertAdjacentHTML should have thrown");
} catch (e) {
is(e.name, "SyntaxError", "insertAdjacentHTML should throw SyntaxError");
is(e.code, 12, "insertAdjacentHTML should throw SYNTAX_ERR");
}
@ -43,6 +44,7 @@ try {
child.insertAdjacentHTML("Beforebegin", "foo");
ok(false, "insertAdjacentHTML should have thrown");
} catch (e) {
is(e.name, "NoModificationAllowedError", "insertAdjacentHTML should throw NoModificationAllowedError");
is(e.code, 7, "insertAdjacentHTML should throw NO_MODIFICATION_ALLOWED_ERR");
}
@ -50,6 +52,7 @@ try {
child.insertAdjacentHTML("AfterEnd", "foo");
ok(false, "insertAdjacentHTML should have thrown");
} catch (e) {
is(e.name, "NoModificationAllowedError", "insertAdjacentHTML should throw NoModificationAllowedError");
is(e.code, 7, "insertAdjacentHTML should throw NO_MODIFICATION_ALLOWED_ERR");
}
@ -65,6 +68,7 @@ try {
document.documentElement.insertAdjacentHTML("afterend", "<div></div>");
ok(false, "insertAdjacentHTML should have thrown");
} catch (e) {
is(e.name, "NoModificationAllowedError", "insertAdjacentHTML should throw NoModificationAllowedError");
is(e.code, 7, "insertAdjacentHTML should throw NO_MODIFICATION_ALLOWED_ERR");
}
@ -121,6 +125,7 @@ try {
content.insertAdjacentHTML("beforeend", "<p>");
ok(false, "insertAdjacentHTML should have thrown");
} catch (e) {
is(e.name, "SyntaxError", "insertAdjacentHTML should throw SyntaxError");
is(e.code, 12, "insertAdjacentHTML should throw SYNTAX_ERR");
}