mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
113 lines
3.7 KiB
HTML
113 lines
3.7 KiB
HTML
<test>
|
|
<link rel="import" href="../resources/chai.html" />
|
|
<link rel="import" href="../resources/mocha.html" />
|
|
<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 = document.implementation.createDocument();
|
|
runNSTests(allNoNSTests, doc, "createElement");
|
|
});
|
|
});
|
|
</script>
|
|
</test>
|