dom-mutations.html 6.7 KB

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