Skip to content

Commit

Permalink
Port test_bug411103.html to wpt;
Browse files Browse the repository at this point in the history
This allows other UAs to use it, removes duplicated checks, and
increases the chance of us noticing if the spec changes.  Some of the
expected values in our mochitest were contrary to the spec.

I checked the new expected failures against the spec and the other UAs.
I filed a spec bug for one group because it was contrary to all UAs
(although IMO the spec makes more sense and the UAs are buggy), and the
others are fixed in the next patch.

MozReview-Commit-ID: 1j11XgfuErB

Upstreamed from https://bugzilla.mozilla.org/show_bug.cgi?id=1298818
  • Loading branch information
ayg authored and jgraham committed Nov 2, 2016
1 parent 17e59f9 commit 5423dce
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 105 deletions.
2 changes: 2 additions & 0 deletions common/dummy.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!DOCTYPE html>
<html><head><title>Dummy XHTML document</title></head><body /></html>
1 change: 1 addition & 0 deletions common/dummy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<foo>Dummy XML document</foo>
186 changes: 129 additions & 57 deletions dom/nodes/Document-createElement.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<iframe src="/common/dummy.xml"></iframe>
<iframe src="/common/dummy.xhtml"></iframe>
<script>
function toASCIIUppercase(str) {
var diff = "a".charCodeAt(0) - "A".charCodeAt(0);
Expand All @@ -22,64 +24,134 @@
}
return res;
}
test(function() {
var HTMLNS = "http://www.w3.org/1999/xhtml",
valid = [
//[input, localName],
[undefined, "undefined"],
[null, "null"],
["foo", "foo"],
["f1oo", "f1oo"],
["foo1", "foo1"],
["f\u0300oo", "f\u0300oo"],
["foo\u0300", "foo\u0300"],
[":foo", ":foo"],
["f:oo", "f:oo"],
["foo:", "foo:"],
["xml", "xml"],
["xmlns", "xmlns"],
["xmlfoo", "xmlfoo"],
["xml:foo", "xml:foo"],
["xmlns:foo", "xmlns:foo"],
["xmlfoo:bar", "xmlfoo:bar"],
["svg", "svg"],
["math", "math"],
["FOO", "foo"],
["mar\u212a", "mar\u212a"],
["\u0130nput", "\u0130nput"],
["\u0131nput", "\u0131nput"]
],
invalid = [
"",
"1foo",
"\u0300foo",
"}foo",
"f}oo",
"foo}",
"\ufffffoo",
"f\uffffoo",
"foo\uffff",
"<foo",
"foo>",
"<foo>",
"f<oo"
]
function toASCIILowercase(str) {
var diff = "a".charCodeAt(0) - "A".charCodeAt(0);
var res = "";
for (var i = 0; i < str.length; ++i) {
if ("A" <= str[i] && str[i] <= "Z") {
res += String.fromCharCode(str.charCodeAt(i) + diff);
} else {
res += str[i];
}
}
return res;
}
var HTMLNS = "http://www.w3.org/1999/xhtml",
valid = [
undefined,
null,
"foo",
"f1oo",
"foo1",
"f\u0BC6",
"foo\u0BC6",
":",
":foo",
"f:oo",
"foo:",
"f:o:o",
"f::oo",
"f::oo:",
"foo:0",
"foo:_",
// combining char after :, invalid QName but valid Name
"foo:\u0BC6",
"foo:foo\u0BC6",
"foo\u0BC6:foo",
"xml",
"xmlns",
"xmlfoo",
"xml:foo",
"xmlns:foo",
"xmlfoo:bar",
"svg",
"math",
"FOO",
// Test that non-ASCII chars don't get uppercased/lowercased
"mar\u212a",
"\u0130nput",
"\u0131nput",
],
invalid = [
"",
"1foo",
"1:foo",
"fo o",
"\u0BC6foo",
"}foo",
"f}oo",
"foo}",
"\ufffffoo",
"f\uffffoo",
"foo\uffff",
"<foo",
"foo>",
"<foo>",
"f<oo",
"-foo",
".foo",
"\u0BC6",
]

var xmlIframe = document.querySelector('[src="/common/dummy.xml"]');
var xhtmlIframe = document.querySelector('[src="/common/dummy.xhtml"]');

function getWin(desc) {
if (desc == "HTML document") {
return window;
}
if (desc == "XML document") {
assert_equals(xmlIframe.contentDocument.documentElement.textContent,
"Dummy XML document", "XML document didn't load");
return xmlIframe.contentWindow;
}
if (desc == "XHTML document") {
assert_equals(xhtmlIframe.contentDocument.documentElement.textContent,
"Dummy XHTML document", "XHTML document didn't load");
return xhtmlIframe.contentWindow;
}
}


valid.forEach(function(t) {
test(function() {
var elt = document.createElement(t[0])
assert_true(elt instanceof Element)
assert_true(elt instanceof Node)
assert_equals(elt.localName, t[1])
assert_equals(elt.tagName, toASCIIUppercase(t[1]))
assert_equals(elt.prefix, null)
assert_equals(elt.namespaceURI, HTMLNS)
}, "createElement(" + format_value(t[0]) + ")");
valid.forEach(function(t) {
["HTML document", "XML document", "XHTML document"].forEach(function(desc) {
async_test(function(testObj) {
window.addEventListener("load", function() {
testObj.step(function() {
var win = getWin(desc);
var doc = win.document;
var elt = doc.createElement(t)
assert_true(elt instanceof win.Element, "instanceof Element")
assert_true(elt instanceof win.Node, "instanceof Node")
assert_equals(elt.localName,
desc == "HTML document" ? toASCIILowercase(String(t))
: String(t),
"localName")
assert_equals(elt.tagName,
desc == "HTML document" ? toASCIIUppercase(String(t))
: String(t),
"tagName")
assert_equals(elt.prefix, null, "prefix")
assert_equals(elt.namespaceURI,
desc == "XML document" ? null : HTMLNS, "namespaceURI")
});
testObj.done();
});
}, "createElement(" + format_value(t) + ") in " + desc);
});
invalid.forEach(function(arg) {
test(function() {
assert_throws("INVALID_CHARACTER_ERR", function() { document.createElement(arg) })
}, "createElement(" + format_value(arg) + ")");
});
invalid.forEach(function(arg) {
["HTML document", "XML document", "XHTML document"].forEach(function(desc) {
async_test(function(testObj) {
window.addEventListener("load", function() {
testObj.step(function() {
var doc = getWin(desc).document;
assert_throws("InvalidCharacterError",
function() { doc.createElement(arg) })
});
testObj.done();
});
}, "createElement(" + format_value(arg) + ") in " + desc);
});
})
});
</script>
122 changes: 75 additions & 47 deletions dom/nodes/Document-createElementNS.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,87 @@
<script src="/resources/testharnessreport.js"></script>
<script src="Document-createElementNS.js"></script>
<div id="log"></div>
<iframe src="/common/dummy.xml"></iframe>
<iframe src="/common/dummy.xhtml"></iframe>
<script>
test(function() {
var tests = createElementNS_tests.concat([
/* Arrays with three elements:
* the namespace argument
* the qualifiedName argument
* the expected exception, or null if none
*/
["", "", "INVALID_CHARACTER_ERR"],
[null, null, null],
[null, "", "INVALID_CHARACTER_ERR"],
[undefined, null, null],
[undefined, "", "INVALID_CHARACTER_ERR"],
["http://example.com/", null, null],
["http://example.com/", "", "INVALID_CHARACTER_ERR"],
["/", null, null],
["/", "", "INVALID_CHARACTER_ERR"],
["http://www.w3.org/XML/1998/namespace", null, null],
["http://www.w3.org/XML/1998/namespace", "", "INVALID_CHARACTER_ERR"],
["http://www.w3.org/2000/xmlns/", null, "NAMESPACE_ERR"],
["http://www.w3.org/2000/xmlns/", "", "INVALID_CHARACTER_ERR"],
["foo:", null, null],
["foo:", "", "INVALID_CHARACTER_ERR"],
])
var tests = createElementNS_tests.concat([
/* Arrays with three elements:
* the namespace argument
* the qualifiedName argument
* the expected exception, or null if none
*/
["", "", "INVALID_CHARACTER_ERR"],
[null, null, null],
[null, "", "INVALID_CHARACTER_ERR"],
[undefined, null, null],
[undefined, "", "INVALID_CHARACTER_ERR"],
["http://example.com/", null, null],
["http://example.com/", "", "INVALID_CHARACTER_ERR"],
["/", null, null],
["/", "", "INVALID_CHARACTER_ERR"],
["http://www.w3.org/XML/1998/namespace", null, null],
["http://www.w3.org/XML/1998/namespace", "", "INVALID_CHARACTER_ERR"],
["http://www.w3.org/2000/xmlns/", null, "NAMESPACE_ERR"],
["http://www.w3.org/2000/xmlns/", "", "INVALID_CHARACTER_ERR"],
["foo:", null, null],
["foo:", "", "INVALID_CHARACTER_ERR"],
])

var xmlIframe = document.querySelector('[src="/common/dummy.xml"]');
var xhtmlIframe = document.querySelector('[src="/common/dummy.xhtml"]');

tests.forEach(function(t, i) {
test(function() {
var namespace = t[0], qualifiedName = t[1], expected = t[2]
if (expected != null) {
assert_throws(expected, function() { document.createElementNS(namespace, qualifiedName) })
} else {
var element = document.createElementNS(namespace, qualifiedName)
assert_not_equals(element, null)
assert_equals(element.nodeType, Node.ELEMENT_NODE)
assert_equals(element.nodeType, element.ELEMENT_NODE)
assert_equals(element.nodeValue, null)
assert_equals(element.ownerDocument, document)
var qualified = String(qualifiedName), names = []
if (qualified.indexOf(":") >= 0) {
names = qualified.split(":", 2)
function runTest(t, i, desc) {
async_test(function(testObj) {
window.addEventListener("load", function() {
testObj.step(function() {
var doc;
if (desc == "HTML document") {
doc = document;
} else if (desc == "XML document") {
doc = xmlIframe.contentDocument;
// Make sure we're testing the right document
assert_equals(doc.documentElement.textContent, "Dummy XML document");
} else if (desc == "XHTML document") {
doc = xhtmlIframe.contentDocument;
assert_equals(doc.documentElement.textContent, "Dummy XHTML document");
}
var namespace = t[0], qualifiedName = t[1], expected = t[2]
if (expected != null) {
assert_throws(expected, function() { doc.createElementNS(namespace, qualifiedName) })
} else {
names = [null, qualified]
var element = doc.createElementNS(namespace, qualifiedName)
assert_not_equals(element, null)
assert_equals(element.nodeType, Node.ELEMENT_NODE)
assert_equals(element.nodeType, element.ELEMENT_NODE)
assert_equals(element.nodeValue, null)
assert_equals(element.ownerDocument, doc)
var qualified = String(qualifiedName), names = []
if (qualified.indexOf(":") >= 0) {
names = qualified.split(":", 2)
} else {
names = [null, qualified]
}
assert_equals(element.prefix, names[0])
assert_equals(element.localName, names[1])
assert_equals(element.tagName, qualified)
assert_equals(element.nodeName, qualified)
assert_equals(element.namespaceURI,
namespace === undefined || namespace === "" ? null
: namespace)
}
assert_equals(element.prefix, names[0])
assert_equals(element.localName, names[1])
assert_equals(element.tagName, qualified)
assert_equals(element.nodeName, qualified)
assert_equals(element.namespaceURI, namespace === undefined ? null : namespace)
}
}, "createElementNS test: " + t.map(format_value))
})
});
testObj.done();
});
}, "createElementNS test in " + desc + ": " + t.map(format_value))
}

tests.forEach(function(t, i) {
runTest(t, i, "HTML document")
runTest(t, i, "XML document")
runTest(t, i, "XHTML document")
})


test(function() {
var HTMLNS = "http://www.w3.org/1999/xhtml";
var element = document.createElementNS(HTMLNS, "span");
Expand Down
Loading

0 comments on commit 5423dce

Please sign in to comment.