summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/dom/xmlserializer-serialize-to-string-exception.html
blob: 34675f9117a31a76fa9e7b28058386c8c6aea1e4 (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
101
102
103
104
105
106
<html>
<head>
<style>
.failed {
    color: red;
    font-weight: bold;
}

.passed {
    color: green;
    font-weight: bold;
}
</style>
<script>
if (window.testRunner)
    window.testRunner.dumpAsText();
var count = 0;

function shouldThrowException(node)
{
    document.body.appendChild(document.createElement("br"));
    var header = document.createElement("div");
    header.textContent = ++count + ". Verifying XMLSerializer.serializeToString() should THROW exception with " + (arguments.length ? "argument " + node : "no argument");
    document.body.appendChild(header);

    var xs = new XMLSerializer();
    try {
        var str = xs.serializeToString.apply(xs, arguments);

        var result = document.createElement("div");
        result.className = "failed"
        result.textContent = "FAIL";
        document.body.appendChild(result);
    } catch (exception) {
        var err = "Exception thrown = [" + exception.name + ": " + exception.message + "]";
        var content = document.createElement("div");
        content.textContent = err;
        document.body.appendChild(content);

        var result = document.createElement("div");
        result.className = "passed"
        result.textContent = "PASS";
        document.body.appendChild(result);
    }
}

function shouldNOTThrowException(node)
{
    document.body.appendChild(document.createElement("br"));
    var header = document.createElement("div");
    header.textContent = ++count + ". Verifying XMLSerializer.serializeToString() should NOT-THROW exception with argument " + node;
    document.body.appendChild(header);

    var xs = new XMLSerializer();
    try {
        var str = xs.serializeToString(node);

        var result = document.createElement("div");
        result.className = "passed"
        result.textContent = "PASS";
        document.body.appendChild(result);
    } catch (exception) {
        var err = "Exception thrown = [" + exception.name + ": " + exception.message + "]";
        var content = document.createElement("div");
        content.textContent = err;
        document.body.appendChild(content);

        var result = document.createElement("div");
        result.className = "failed"
        result.textContent = "FAIL";
        document.body.appendChild(result);
    }
}

function runTest()
{
    shouldThrowException();
    shouldThrowException(null);
    shouldThrowException(undefined);
    shouldThrowException("<html><title>Hello World</title></html>");
    shouldThrowException(document.children);

    shouldNOTThrowException(document);
    shouldNOTThrowException(document.documentElement);
    shouldNOTThrowException(document.firstChild);
    shouldNOTThrowException(document.createElement("div"));
    shouldNOTThrowException(document.getElementById("heading"));
    shouldNOTThrowException(document.createElement("custom"));

    var domParser = new DOMParser();

    var htmlDoc = domParser.parseFromString("<html/>", "text/html");
    shouldNOTThrowException(htmlDoc);
    shouldNOTThrowException(htmlDoc.firstChild);

    var xmlDoc = domParser.parseFromString("<root/>", "text/xml");
    shouldNOTThrowException(xmlDoc);
    shouldNOTThrowException(xmlDoc.lastChild);
}
</script>
</head>
<body onload="runTest();">
This tests XMLSerializer.serializeToString() throwing exception when node value is invalid and passing otherwise.
<h1 id="heading"/>
</body>
</html>