summaryrefslogtreecommitdiffstats
path: root/LayoutTests/fast/dom/DOMImplementation/script-tests/createDocumentType-err.js
blob: 9ef7e7c6b8767d7f0dd61bfc4ea0b12ef88209de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
description("createDocument tests modeled after mozilla's testing");

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 assertEquals(actual, expect, m)
{
    if (actual !== expect) {
        m += "; expected " + stringForExceptionCode(expect) + ", threw " + stringForExceptionCode(actual);
        testFailed(m);
    } else {
        m += "; threw " + stringForExceptionCode(actual);;
        testPassed(m);
    }
}

var allTests = [
   { args: [undefined, undefined], code: 5  },
   { args: [null, undefined], code: 5  },
   { args: [undefined, null], code: 5 },
   { args: [undefined, undefined, null], code: 5 },
   { args: [null, null], code: 5 },
   { args: [null, null, null], code: 5 },
   { args: [null, ""], code: 5 },
   { args: ["", null], code: 5 },
   { args: ["", ""], code: 5 },
   { args: ["a:", null, null], code: 14 },
   { args: [":foo", null, null], code: 14 },
   { args: [":", null, null], code: 14 },
   { args: ["foo", null, null] },
   { args: ["foo:bar", null, null] },
   { args: ["foo::bar", null, null], code: 14 },
   { args: ["\t:bar", null, null], code: 5 },
   { args: ["foo:\t", null, null], code: 5 },
   { args: ["foo :bar", null, null], code: 5 },
   { args: ["foo: bar", null, null], code: 5 },
   { args: ["a:b:c", null, null], code: 14, message: "valid XML name, invalid QName" },
];

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 runTests(tests, 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 {
            document.implementation[createFunctionName].apply(document.implementation, test.args);
            if ('code' in test)
                testFailed(msg + " expected exception: " + test.code);
            else
                testPassed(msg);
        } catch (e) {
            assertEquals(e.code, test.code || "expected no exception", msg);
        }
    }
}

// Moz throws a "Not enough arguments" exception in these, we don't:
shouldBeEqualToString("document.implementation.createDocumentType('foo').toString()", "[object DocumentType]");
shouldBeEqualToString("document.implementation.createDocumentType('foo', null).toString()", "[object DocumentType]");
runTests(allTests, "createDocumentType");

var successfullyParsed = true;