summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_bug682463.html
blob: 7fc5097d0f54bb270675400e687364297c672bcc (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=682463
-->
<head>
  <title>Test for Bug 682463</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=682463">Mozilla Bug 682463</a>
<p id="display"></p>
<div id="content" style="display: none">
  
</div>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 682463 **/

  function text(s) {
    return document.createTextNode(s);
  }
  function div(l,r) {
    var div = document.createElement("DIV");
    if (l) div.appendChild(l);
    if (r) div.appendChild(r);
    return div;
  }
  function createRange(sn,so,en,eo) {
    var r = document.createRange();
    r.setStart(sn,so);
    r.setEnd(en,eo);
    return r;
  }
  function verifyRange(msg,r,sn,so,en,eo) {
    ok(r.startContainer == sn && r.startOffset == so &&
       r.endContainer == en && r.endOffset == eo, msg);
  }
  function showRange(r,msg) {
    var s = "" + r.startContainer + ":  " + r.startOffset;
    s+= '\n';
    s += "" + r.endContainer + ":  " + r.endOffset;
    alert(msg + ':\n' + s)
  }

  var tests = [
  function() {
    var t = text("foobar");
    var r = createRange(t,2,t,t.length);
    var t2 = t.splitText(1);
    verifyRange("split before, no parent",r,t2,1,t2,5);
  },
  function() {
    var t = text("foobar");
    var r = createRange(t,0,t,t.length);
    var t2 = t.splitText(3);
    verifyRange("split middle, no parent",r,t,0,t,3);
  },
  function() {
    var t = text("foobar");
    var r = createRange(t,0,t,t.length);
    var n = t.length;
    var t2 = t.splitText(n);
    verifyRange("split after, no parent",r,t,0,t,n);
  },
  function() {
    var t = text("foobar");
    var parent = div(t);
    var r = createRange(t,0,t,t.length);
    var t2 = t.splitText(3);
    verifyRange("split middle, parent",r,t,0,t2,3);
    parent.removeChild(t);
    verifyRange("removed left, parent",r,parent,0,t2,3);
    var t2b = t2.splitText(1);
    verifyRange("split middle, parent, end",r,parent,0,t2b,2);
  },
  function() {
    var t0 = text("x");
    var t = text("foobar");
    var parent = div(t0,t);
    var r = createRange(t,0,t,t.length);
    var t2 = t.splitText(3);
    parent.removeChild(t);
    verifyRange("removed left, text sibling",r,parent,1,t2,3);
  },
  function() {
    var t = text("foobar");
    var parent = div(t);
    var r = createRange(t,2,t,t.length);
    var t2 = t.splitText(1);
    verifyRange("split before, parent",r,t2,1,t2,5);
    parent.removeChild(t2);
    verifyRange("removed right, parent",r,parent,1,parent,1);
  },
  function() {
    var t = text("foobar");
    var parent = div(t);
    var r = createRange(t,0,t,t.length);
    var n = t.length;
    var t2 = t.splitText(n);
    verifyRange("split after, parent",r,t,0,t,n);
    r.setEnd(t2,0);
    verifyRange("split after, parent, extend",r,t,0,t2,0);
    t2.splitText(0);
    verifyRange("split after, parent, extend, split end",r,t,0,t2,0);
    t2.textContent = "baz";
    t2.splitText(2);
    verifyRange("split after, parent, extend, split after end",r,t,0,t2,0);
    r.setEnd(t2,2);
    var t2b = t2.splitText(1);
    verifyRange("split after, parent, split end",r,t,0,t2b,1);
  },
  function() {
    var t = text("foobar");
    var parent = div(t);
    document.body.appendChild(parent);
    var r = createRange(t,0,t,t.length);
    var t2 = t.splitText(3);
    verifyRange("split middle, in document",r,t,0,t2,3);
  },
  function() {
    var t = text("foobar");
    var parent = div(t);
    document.body.appendChild(parent);
    var r = createRange(t,2,t,t.length);
    var t2 = t.splitText(1);
    verifyRange("split before, in document",r,t2,1,t2,5);
  },
  function() {
    var t = text("foobar");
    var parent = div(t);
    document.body.appendChild(parent);
    var r = createRange(t,0,t,t.length);
    var n = t.length;
    var t2 = t.splitText(n);
    verifyRange("split after, in document",r,t,0,t,n);
  }
  ];

  function runTests() {
    var len = tests.length;
    for (var i = 0; i < len; ++i) {
      tests[i]();
    }
    SimpleTest.finish();
  }

addLoadEvent(runTests);
SimpleTest.waitForExplicitFinish();

</script>
</pre>
</body>
</html>