summaryrefslogtreecommitdiffstats
path: root/LayoutTests/fast/dom/Node/normalize.html
blob: a8b61cb55338875a9e1431dc19e531fbfb188f68 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<html>

<head>

<title>Test of DOM Node.normalize()</title>

<script>

function logLine(message)
{
    var console = document.getElementById("console");
    console.appendChild(document.createTextNode(message));
    console.appendChild(document.createElement('br'));
}

function log(message)
{
    var console = document.getElementById("console");
    console.appendChild(document.createTextNode(message));
}


function prepare_test1(testDiv)
{
    testDiv.firstChild.splitText(4);
    return testDiv.childNodes.length == 2;
}
function check_test1(testDiv)
{
    return testDiv.childNodes.length == 1;
}

function prepare_test2(testDiv)
{
    testDiv.firstChild.splitText(9);
    testDiv.firstChild.splitText(4);
    return testDiv.childNodes.length == 3;
}
function check_test2(testDiv)
{
    return testDiv.childNodes.length == 1;
}

function prepare_test3(testDiv)
{
    testDiv.childNodes[1].splitText(4);
    testDiv.childNodes[4].splitText(3);
    return testDiv.childNodes.length == 6;
}
function check_test3(testDiv)
{
    return testDiv.childNodes.length == 4;
}

function prepare_test4(testDiv)
{
    testDiv.childNodes[0].data = "";
    return testDiv.childNodes.length == 1;
}
function check_test4(testDiv)
{
    return testDiv.childNodes.length == 0;
}

function prepare_test5(testDiv)
{
    testDiv.childNodes[1].data = "";
    return testDiv.childNodes.length == 3;
}
function check_test5(testDiv)
{
    return testDiv.childNodes.length == 2;
}

function prepare_test6(testDiv)
{
    testDiv.childNodes[0].splitText(0);
    testDiv.childNodes[0].splitText(0);
    return testDiv.childNodes.length == 3;
}
function check_test6(testDiv)
{
    return testDiv.childNodes.length == 1;
}

function prepare_test7(testDiv)
{
    testDiv.childNodes[0].splitText(4);
    testDiv.childNodes[0].splitText(4);
    testDiv.childNodes[0].splitText(4);
    return testDiv.childNodes.length == 4;
}
function check_test7(testDiv)
{
    return testDiv.childNodes.length == 1;
}

function prepare_test8(testDiv)
{
    testDiv.childNodes[0].splitText(4);
    testDiv.childNodes[0].splitText(4);
    return testDiv.childNodes.length == 3;
}
function check_test8(testDiv)
{
    return testDiv.childNodes.length == 1;
}

function prepare_test9(testDiv)
{
    testDiv.childNodes[1].splitText(4);
    testDiv.childNodes[1].splitText(0);    // empty text node before other text nodes
    testDiv.childNodes[5].splitText(3);
    testDiv.childNodes[5].splitText(3);    // empty text node between other text nodes
    testDiv.childNodes[7].splitText(2);    // empty text node after other text nodes
    return testDiv.childNodes.length == 9;
}
function check_test9(testDiv)
{
    return testDiv.childNodes.length == 4;
}

function prepare_test10(testDiv)
{
    testDiv.childNodes[0].childNodes[0].splitText(2);
    testDiv.childNodes[1].splitText(4);
    testDiv.childNodes[3].childNodes[0].data = "";    // empty first text node of the second bold node
    testDiv.childNodes[3].childNodes[1].childNodes[0].data = "";    // empty text node of the italic node
    testDiv.childNodes[4].splitText(1);
    return testDiv.childNodes.length == 6;
}
function check_test10(testDiv)
{
    return testDiv.childNodes.length == 4
        && testDiv.childNodes[0].childNodes.length == 1        // first bold node must have single text node child
        && testDiv.childNodes[2].childNodes.length == 1        // first bold node must have single italic node child
        && testDiv.childNodes[2].childNodes[0].childNodes.length == 0;    // italic node must be empty
}

function runTest(testDiv, testName)
{
    if (self["prepare_"+testName](testDiv)) {
        var oldHTML = testDiv.innerHTML;
        testDiv.normalize();
        if (testDiv.innerHTML != oldHTML) {
            log("FAILED: innerHTML changed from \"" + oldHTML + "\" to \"" + testDiv.innerHTML + "\"");
        } else {
            if (self["check_"+testName](testDiv))
                log("PASSED");
            else
                log("FAILED");
        }        
    } else {
        log("FAILED in test preparation");
    }
}

function runTests()
{
    if (window.layoutTestController)
        layoutTestController.dumpAsText();

    try {
        var tests = document.getElementById("tests").childNodes;
        for (i = 0; i < tests.length; i++) {
            var testDiv = tests[i];
            // Skip formatting text nodes
            if (testDiv.nodeType == Node.ELEMENT_NODE) {
                var testName = testDiv.getAttribute("name");
                
                log(testName + " (" + testDiv.getAttribute("description") + "): ");
                
                try {
                    runTest(testDiv, testName);
                } catch(e) {
                    log("FAILED with exception: " + e);
                }
                
                logLine("")
            }
        }

    } catch(e) {
        logLine("FAILED, exception thrown during tests: " + e);
    }
}

</script>

</head>

<body onload="runTests()">

<div id="description">Several tests of the DOM normalize() function.</div>

<div id="tests" style="display:none">
    <div name="test1" description="two non-empty text nodes">some text</div>
    <div name="test2" description="three non-empty text nodes">some more text</div>
    <div name="test3" description="non-empty text nodes mixed with elements"><b></b>some more<b></b> text</div>
    <div name="test4" description="single empty text node">text</div>
    <div name="test5" description="empty text node between elements"><b></b>text<i></i></div>
    <div name="test6" description="empty text nodes before non-empty node">text</div>
    <div name="test7" description="empty text nodes after non-empty node">text</div>
    <div name="test8" description="empty text nodes between non-empty nodes">some text</div>
    <div name="test9" description="empty and non-empty text nodes mixed with elements"><b></b>some more<b></b> text</div>
    <div name="test10" description="mixed cases including deeper nested text nodes"><b>text</b>text <b>text<i>text</i></b> text</div>
</div>

<div id="console"></div>

</body>

</html>