layout/reftests/selection/dom-mutations.html

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html class="reftest-wait">
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=619273
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 619273</title>
michael@0 8 <script type="application/javascript;version=1.7">
michael@0 9 /** Test DOM mutations inside selection **/
michael@0 10 function createDOM(doc) {
michael@0 11 let s = doc.createElement('span');
michael@0 12 s.appendChild(doc.createTextNode('|'))
michael@0 13 let s2 = doc.createElement('span');
michael@0 14 s2.appendChild(doc.createTextNode('z'))
michael@0 15 s.appendChild(s2)
michael@0 16 return s;
michael@0 17 }
michael@0 18
michael@0 19 var tests_done = 0;
michael@0 20 var tests = [
michael@0 21 function(win,doc,sel) {
michael@0 22 doc.body.innerHTML = 'I<br>B<br>C'
michael@0 23 let a = doc.body.firstChild;
michael@0 24 let r = doc.createRange();
michael@0 25 r.setStart(a, 0);
michael@0 26 r.setEnd(a, 1);
michael@0 27 sel.addRange(r);
michael@0 28 doc.body.insertBefore(doc.createTextNode('.'), a);
michael@0 29 doc.body.appendChild(createDOM(doc));
michael@0 30 },
michael@0 31 function(win,doc,sel) {
michael@0 32 doc.body.innerHTML = 'I<br>B<br>C'
michael@0 33 let a = doc.body.firstChild;
michael@0 34 let r = doc.createRange();
michael@0 35 r.setStart(doc.firstChild, 0);
michael@0 36 r.setEnd(a, 1);
michael@0 37 sel.addRange(r);
michael@0 38 doc.body.insertBefore(doc.createTextNode('.'), a);
michael@0 39 doc.body.appendChild(createDOM(doc));
michael@0 40 },
michael@0 41 function(win,doc,sel) {
michael@0 42 doc.body.innerHTML = 'I<br>B<br>C'
michael@0 43 let a = doc.body.firstChild;
michael@0 44 let b = doc.body.childNodes[2];
michael@0 45 let c = doc.body.childNodes[4];
michael@0 46 let r = doc.createRange();
michael@0 47 r.setStart(a, 0);
michael@0 48 r.setEnd(c, 1);
michael@0 49 sel.addRange(r);
michael@0 50 doc.body.insertBefore(doc.createTextNode('.'), b);
michael@0 51 doc.body.appendChild(createDOM(doc));
michael@0 52 },
michael@0 53 function(win,doc,sel) {
michael@0 54 doc.body.innerHTML = 'I<br>B<br>C'
michael@0 55 let b = doc.body.childNodes[2];
michael@0 56 let c = doc.body.childNodes[4];
michael@0 57 let r = doc.createRange();
michael@0 58 r.setStart(doc.body, 0);
michael@0 59 r.setEnd(c, 1);
michael@0 60 sel.addRange(r);
michael@0 61 doc.body.insertBefore(doc.createTextNode('.'), b);
michael@0 62 doc.body.appendChild(createDOM(doc));
michael@0 63 },
michael@0 64 function(win,doc,sel) {
michael@0 65 doc.body.innerHTML = 'I<br>B<br>C'
michael@0 66 let b = doc.body.childNodes[2];
michael@0 67 let c = doc.body.childNodes[4];
michael@0 68 let r = doc.createRange();
michael@0 69 r.setStart(doc, 0);
michael@0 70 r.setEnd(c, 1);
michael@0 71 sel.addRange(r);
michael@0 72 doc.body.insertBefore(doc.createTextNode('.'), b);
michael@0 73 doc.body.appendChild(createDOM(doc));
michael@0 74 },
michael@0 75 function(win,doc,sel) {
michael@0 76 doc.body.innerHTML = 'I<br>B<br>C'
michael@0 77 let a = doc.body.firstChild;
michael@0 78 let c = doc.body.childNodes[4];
michael@0 79 let r = doc.createRange();
michael@0 80 r.setStart(a, 0);
michael@0 81 r.setEnd(c, 1);
michael@0 82 sel.addRange(r);
michael@0 83 doc.body.insertBefore(doc.createTextNode('.'), c);
michael@0 84 doc.body.appendChild(createDOM(doc));
michael@0 85 },
michael@0 86
michael@0 87 function(win,doc,sel) {
michael@0 88 doc.body.innerHTML = 'I<br>B<br>C'
michael@0 89 let a = doc.body.firstChild;
michael@0 90 let r = doc.createRange();
michael@0 91 r.setStart(a, 0);
michael@0 92 r.setEnd(a, 1);
michael@0 93 sel.addRange(r);
michael@0 94 let span = createDOM(doc);
michael@0 95 doc.body.insertBefore(span, a);
michael@0 96 span.appendChild(createDOM(doc));
michael@0 97 },
michael@0 98 function(win,doc,sel) {
michael@0 99 doc.body.innerHTML = 'I<br>B<br>C'
michael@0 100 let a = doc.body.firstChild;
michael@0 101 let r = doc.createRange();
michael@0 102 r.setStart(doc.firstChild, 0);
michael@0 103 r.setEnd(a, 1);
michael@0 104 sel.addRange(r);
michael@0 105 let span = createDOM(doc);
michael@0 106 doc.body.insertBefore(span, a);
michael@0 107 span.appendChild(createDOM(doc));
michael@0 108 },
michael@0 109 function(win,doc,sel) {
michael@0 110 doc.body.innerHTML = 'I<br>B<br>C'
michael@0 111 let a = doc.body.firstChild;
michael@0 112 let b = doc.body.childNodes[2];
michael@0 113 let c = doc.body.childNodes[4];
michael@0 114 let r = doc.createRange();
michael@0 115 r.setStart(a, 0);
michael@0 116 r.setEnd(c, 1);
michael@0 117 sel.addRange(r);
michael@0 118 let span = createDOM(doc);
michael@0 119 doc.body.insertBefore(span, b);
michael@0 120 span.appendChild(createDOM(doc));
michael@0 121 },
michael@0 122 function(win,doc,sel) {
michael@0 123 doc.body.innerHTML = 'I<br>B<br>C'
michael@0 124 let b = doc.body.childNodes[2];
michael@0 125 let c = doc.body.childNodes[4];
michael@0 126 let r = doc.createRange();
michael@0 127 r.setStart(doc.body, 0);
michael@0 128 r.setEnd(c, 1);
michael@0 129 sel.addRange(r);
michael@0 130 let span = createDOM(doc);
michael@0 131 doc.body.insertBefore(span, b);
michael@0 132 span.appendChild(createDOM(doc));
michael@0 133 },
michael@0 134 function(win,doc,sel) {
michael@0 135 doc.body.innerHTML = 'I<br>B<br>C'
michael@0 136 let b = doc.body.childNodes[2];
michael@0 137 let c = doc.body.childNodes[4];
michael@0 138 let r = doc.createRange();
michael@0 139 r.setStart(doc, 0);
michael@0 140 r.setEnd(c, 1);
michael@0 141 sel.addRange(r);
michael@0 142 let span = createDOM(doc);
michael@0 143 doc.body.insertBefore(span, b);
michael@0 144 span.appendChild(createDOM(doc));
michael@0 145 },
michael@0 146 function(win,doc,sel) {
michael@0 147 doc.body.innerHTML = 'I<br>B<br>C'
michael@0 148 let a = doc.body.firstChild;
michael@0 149 let c = doc.body.childNodes[4];
michael@0 150 let r = doc.createRange();
michael@0 151 r.setStart(a, 0);
michael@0 152 r.setEnd(c, 1);
michael@0 153 sel.addRange(r);
michael@0 154 let span = createDOM(doc);
michael@0 155 doc.body.insertBefore(span, c);
michael@0 156 span.appendChild(createDOM(doc));
michael@0 157 },
michael@0 158
michael@0 159 function(win,doc,sel) {
michael@0 160 doc.body.innerHTML = 'I<br>B<br>C'
michael@0 161 let a = doc.body.firstChild;
michael@0 162 let r = doc.createRange();
michael@0 163 r.setStart(a, 0);
michael@0 164 r.setEnd(a, 1);
michael@0 165 sel.addRange(r);
michael@0 166 doc.body.appendChild(a);
michael@0 167 },
michael@0 168 function(win,doc,sel) {
michael@0 169 doc.body.innerHTML = 'I<br>B<br>C'
michael@0 170 let a = doc.body.firstChild;
michael@0 171 let r = doc.createRange();
michael@0 172 r.setStart(a, 0);
michael@0 173 r.setEnd(a, 1);
michael@0 174 sel.addRange(r);
michael@0 175 document.adoptNode(a);
michael@0 176 document.body.appendChild(a);
michael@0 177 document.body.appendChild(document.createTextNode(' '));
michael@0 178 },
michael@0 179 function(win,doc,sel) {
michael@0 180 doc.body.innerHTML = 'I<br>B<br>C'
michael@0 181 let a = doc.body.firstChild;
michael@0 182 let c = doc.body.childNodes[4];
michael@0 183 let r = doc.createRange();
michael@0 184 r.setStart(a, 0);
michael@0 185 r.setEnd(c, 1);
michael@0 186 sel.addRange(r);
michael@0 187 let span = createDOM(doc);
michael@0 188 doc.body.insertBefore(span, c);
michael@0 189 document.adoptNode(span);
michael@0 190 document.body.appendChild(span);
michael@0 191 },
michael@0 192
michael@0 193 function(win,doc,sel) {
michael@0 194 doc.body.innerHTML = 'I'
michael@0 195 let a = doc.body.firstChild;
michael@0 196 let span = createDOM(doc);
michael@0 197 let r = doc.createRange();
michael@0 198 r.setStart(span, 0);
michael@0 199 r.setEnd(span, 1);
michael@0 200 sel.addRange(r);
michael@0 201 doc.body.appendChild(span);
michael@0 202 },
michael@0 203
michael@0 204 function(win,doc,sel) {
michael@0 205 doc.body.innerHTML = 'I'
michael@0 206 let a = doc.body.firstChild;
michael@0 207 let span = createDOM(doc);
michael@0 208 let r = doc.createRange();
michael@0 209 r.setStart(span.firstChild, 0);
michael@0 210 r.setEnd(span.firstChild, 1);
michael@0 211 sel.addRange(r);
michael@0 212 doc.body.appendChild(span);
michael@0 213 doc.body.appendChild(span.firstChild);
michael@0 214 r.setEnd(span.firstChild, 1);
michael@0 215 },
michael@0 216 ]
michael@0 217
michael@0 218 function runTestInIframe(run,t) {
michael@0 219 let f = document.createElement('iframe');
michael@0 220 f.setAttribute('frameborder','0');
michael@0 221 f.setAttribute('height','100');
michael@0 222 f.setAttribute('width','200');
michael@0 223 f.src = 'data:text/html,<body style="margin:0;padding:0;font-family:monospace">';
michael@0 224 f.onload = function () {
michael@0 225 try {
michael@0 226 run(f.contentWindow, f.contentDocument, f.contentWindow.getSelection());
michael@0 227 } finally { ++tests_done; }
michael@0 228 }
michael@0 229 return f;
michael@0 230 }
michael@0 231
michael@0 232 var id;
michael@0 233 function checkFinished() {
michael@0 234 if (window.frames.length == tests_done) {
michael@0 235 clearInterval(id);
michael@0 236 document.documentElement.className = "";
michael@0 237 }
michael@0 238 }
michael@0 239
michael@0 240 function runTest() {
michael@0 241 for (let i=0; i < tests.length; ++i) {
michael@0 242 let t = tests[i];
michael@0 243 document.body.appendChild(runTestInIframe(t));
michael@0 244 }
michael@0 245 id = setInterval(checkFinished,500);
michael@0 246 }
michael@0 247 </script>
michael@0 248 </head>
michael@0 249 <body onload="runTest()"></body>
michael@0 250 </html>

mercurial