Bug 1686668 [wpt PR 27185] - Update wpt metadata, a=testonly
[gecko.git] / dom / base / test / test_bug682463.html
blob91b06b74077ab5bca1c2bcfc2cca3087caff8a2d
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=682463
5 -->
6 <head>
7 <title>Test for Bug 682463</title>
8 <script src="/tests/SimpleTest/SimpleTest.js"></script>
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
10 </head>
11 <body>
12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=682463">Mozilla Bug 682463</a>
13 <p id="display"></p>
14 <div id="content" style="display: none">
16 </div>
17 <pre id="test">
18 <script type="application/javascript">
20 /** Test for Bug 682463 **/
22 function text(s) {
23 return document.createTextNode(s);
25 function div(l,r) {
26 var d = document.createElement("DIV");
27 if (l) d.appendChild(l);
28 if (r) d.appendChild(r);
29 return d;
31 function createRange(sn,so,en,eo) {
32 var r = document.createRange();
33 r.setStart(sn,so);
34 r.setEnd(en,eo);
35 return r;
37 function verifyRange(msg,r,sn,so,en,eo) {
38 ok(r.startContainer == sn && r.startOffset == so &&
39 r.endContainer == en && r.endOffset == eo, msg);
41 function showRange(r,msg) {
42 var s = "" + r.startContainer + ": " + r.startOffset;
43 s+= '\n';
44 s += "" + r.endContainer + ": " + r.endOffset;
45 alert(msg + ':\n' + s)
48 var tests = [
49 function() {
50 var t = text("foobar");
51 var r = createRange(t,2,t,t.length);
52 var t2 = t.splitText(1);
53 verifyRange("split before, no parent",r,t2,1,t2,5);
55 function() {
56 var t = text("foobar");
57 var r = createRange(t,0,t,t.length);
58 var t2 = t.splitText(3);
59 verifyRange("split middle, no parent",r,t,0,t,3);
61 function() {
62 var t = text("foobar");
63 var r = createRange(t,0,t,t.length);
64 var n = t.length;
65 var t2 = t.splitText(n);
66 verifyRange("split after, no parent",r,t,0,t,n);
68 function() {
69 var t = text("foobar");
70 var parent = div(t);
71 var r = createRange(t,0,t,t.length);
72 var t2 = t.splitText(3);
73 verifyRange("split middle, parent",r,t,0,t2,3);
74 parent.removeChild(t);
75 verifyRange("removed left, parent",r,parent,0,t2,3);
76 var t2b = t2.splitText(1);
77 verifyRange("split middle, parent, end",r,parent,0,t2b,2);
79 function() {
80 var t0 = text("x");
81 var t = text("foobar");
82 var parent = div(t0,t);
83 var r = createRange(t,0,t,t.length);
84 var t2 = t.splitText(3);
85 parent.removeChild(t);
86 verifyRange("removed left, text sibling",r,parent,1,t2,3);
88 function() {
89 var t = text("foobar");
90 var parent = div(t);
91 var r = createRange(t,2,t,t.length);
92 var t2 = t.splitText(1);
93 verifyRange("split before, parent",r,t2,1,t2,5);
94 parent.removeChild(t2);
95 verifyRange("removed right, parent",r,parent,1,parent,1);
97 function() {
98 var t = text("foobar");
99 var parent = div(t);
100 var r = createRange(t,0,t,t.length);
101 var n = t.length;
102 var t2 = t.splitText(n);
103 verifyRange("split after, parent",r,t,0,t,n);
104 r.setEnd(t2,0);
105 verifyRange("split after, parent, extend",r,t,0,t2,0);
106 t2.splitText(0);
107 verifyRange("split after, parent, extend, split end",r,t,0,t2,0);
108 t2.textContent = "baz";
109 t2.splitText(2);
110 verifyRange("split after, parent, extend, split after end",r,t,0,t2,0);
111 r.setEnd(t2,2);
112 var t2b = t2.splitText(1);
113 verifyRange("split after, parent, split end",r,t,0,t2b,1);
115 function() {
116 var t = text("foobar");
117 var parent = div(t);
118 document.body.appendChild(parent);
119 var r = createRange(t,0,t,t.length);
120 var t2 = t.splitText(3);
121 verifyRange("split middle, in document",r,t,0,t2,3);
123 function() {
124 var t = text("foobar");
125 var parent = div(t);
126 document.body.appendChild(parent);
127 var r = createRange(t,2,t,t.length);
128 var t2 = t.splitText(1);
129 verifyRange("split before, in document",r,t2,1,t2,5);
131 function() {
132 var t = text("foobar");
133 var parent = div(t);
134 document.body.appendChild(parent);
135 var r = createRange(t,0,t,t.length);
136 var n = t.length;
137 var t2 = t.splitText(n);
138 verifyRange("split after, in document",r,t,0,t,n);
142 function runTests() {
143 var len = tests.length;
144 for (var i = 0; i < len; ++i) {
145 tests[i]();
147 SimpleTest.finish();
150 addLoadEvent(runTests);
151 SimpleTest.waitForExplicitFinish();
153 </script>
154 </pre>
155 </body>
156 </html>