flutter_flutter/tests/lowlevel/createElement.sky
Elliott Sprehn 11b2b24722 Remove DOMImplementation.
Expose a Document constructor instead. This also exposes that
the TemplateBinding library might need more control over the
registration context for custom elements. For now we make all
documents share the same registration context.

R=ojan@chromium.org, abarth@chromium.org

Review URL: https://codereview.chromium.org/697363002
2014-11-03 23:18:39 -08:00

113 lines
3.7 KiB
Plaintext

<test>
<import src="../resources/chai.sky" />
<import src="../resources/mocha.sky" />
<script>
describe('createElementNS tests from mozilla, attached to webkit bug 16833', function() {
it('should behave like mozilla', function() {
function stringForExceptionCode(c)
{
var exceptionName;
switch(c) {
case DOMException.INVALID_CHARACTER_ERR:
exceptionName = "INVALID_CHARACTER_ERR";
break;
case DOMException.NAMESPACE_ERR:
exceptionName = "NAMESPACE_ERR";
}
if (exceptionName)
return exceptionName; // + "(" + c + ")";
return c;
}
function assertExceptionCode(exception, expect, m)
{
var actual = exception.code;
if (actual !== expect) {
m += "; expected " + stringForExceptionCode(expect) + ", threw " + stringForExceptionCode(actual);
assert.ok(false, m);
} else {
m += "; threw " + exception.toString();
assert.ok(true, m);
}
}
var allNoNSTests = [
{ args: [undefined] },
{ args: [null] },
{ args: [""], code: 5 },
{ args: ["<div>"], code: 5 },
{ args: ["0div"], code: 5 },
{ args: ["di v"], code: 5 },
{ args: ["di<v"], code: 5 },
{ args: ["-div"], code: 5 },
{ args: [".div"], code: 5 },
{ args: [":"], message: "valid XML name, invalid QName" },
{ args: [":div"], message: "valid XML name, invalid QName" },
{ args: ["div:"], message: "valid XML name, invalid QName" },
{ args: ["d:iv"] },
{ args: ["a:b:c"], message: "valid XML name, invalid QName" },
{ args: ["a::c"], message: "valid XML name, invalid QName" },
{ args: ["a::c:"], message: "valid XML name, invalid QName" },
{ args: ["a:0"], message: "valid XML name, not a valid QName" },
{ args: ["0:a"], code: 5, message: "0 at start makes it not a valid XML name" },
{ args: ["a:_"] },
{ args: ["a:\u0BC6"],
message: "non-ASCII character after colon is CombiningChar, which is " +
"valid in pre-namespace XML" },
{ args: ["\u0BC6:a"], code: 5, message: "not a valid start character" },
{ args: ["a:a\u0BC6"] },
{ args: ["a\u0BC6:a"] },
{ args: ["xml:test"] },
{ args: ["xmlns:test"] },
{ args: ["x:test"] },
{ args: ["xmlns:test"] },
{ args: ["SOAP-ENV:Body"] }, // From Yahoo Mail Beta
];
function sourceify(v)
{
switch (typeof v) {
case "undefined":
return v;
case "string":
return '"' + v.replace('"', '\\"') + '"';
default:
return String(v);
}
}
function sourceifyArgs(args)
{
var copy = new Array(args.length);
for (var i = 0, sz = args.length; i < sz; i++)
copy[i] = sourceify(args[i]);
return copy.join(", ");
}
function runNSTests(tests, doc, createFunctionName)
{
for (var i = 0, sz = tests.length; i < sz; i++) {
var test = tests[i];
var code = -1;
var argStr = sourceifyArgs(test.args);
var msg = createFunctionName + "(" + argStr + ")";
if ("message" in test)
msg += "; " + test.message;
try {
doc[createFunctionName].apply(doc, test.args);
assert(!("code" in test), msg);
} catch (e) {
assertExceptionCode(e, test.code || "expected no exception", msg);
}
}
}
var doc = new Document();
runNSTests(allNoNSTests, doc, "createElement");
});
});
</script>
</test>