dom-mutations-ref.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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|z'
  22. let a = doc.body.firstChild;
  23. let r = doc.createRange();
  24. r.setStart(a, 1);
  25. r.setEnd(a, 2);
  26. sel.addRange(r);
  27. },
  28. function(win,doc,sel) {
  29. doc.body.innerHTML = '.I<br>B<br>C|z'
  30. let a = doc.body.firstChild;
  31. let r = doc.createRange();
  32. r.setStart(doc.firstChild, 0);
  33. r.setEnd(a, 2);
  34. sel.addRange(r);
  35. },
  36. function(win,doc,sel) {
  37. doc.body.innerHTML = 'I<br>.B<br>C|z'
  38. let a = doc.body.firstChild;
  39. let b = doc.body.childNodes[2];
  40. let c = doc.body.childNodes[4];
  41. let r = doc.createRange();
  42. r.setStart(a, 0);
  43. r.setEnd(c, 1);
  44. sel.addRange(r);
  45. },
  46. function(win,doc,sel) {
  47. doc.body.innerHTML = 'I<br>.B<br>C|z'
  48. let b = doc.body.childNodes[2];
  49. let c = doc.body.childNodes[4];
  50. let r = doc.createRange();
  51. r.setStart(doc.body, 0);
  52. r.setEnd(c, 1);
  53. sel.addRange(r);
  54. },
  55. function(win,doc,sel) {
  56. doc.body.innerHTML = 'I<br>.B<br>C|z'
  57. let b = doc.body.childNodes[2];
  58. let c = doc.body.childNodes[4];
  59. let r = doc.createRange();
  60. r.setStart(doc, 0);
  61. r.setEnd(c, 1);
  62. sel.addRange(r);
  63. },
  64. function(win,doc,sel) {
  65. doc.body.innerHTML = 'I<br>B<br>.C|z'
  66. let a = doc.body.firstChild;
  67. let c = doc.body.childNodes[4];
  68. let r = doc.createRange();
  69. r.setStart(a, 0);
  70. r.setEnd(c, 2);
  71. sel.addRange(r);
  72. },
  73. function(win,doc,sel) {
  74. doc.body.innerHTML = '|z|zI<br>B<br>C'
  75. let a = doc.body.firstChild;
  76. let r = doc.createRange();
  77. r.setStart(a, 4);
  78. r.setEnd(a, 5);
  79. sel.addRange(r);
  80. },
  81. function(win,doc,sel) {
  82. doc.body.innerHTML = '|z|zI<br>B<br>C'
  83. let a = doc.body.firstChild;
  84. let r = doc.createRange();
  85. r.setStart(doc.firstChild, 0);
  86. r.setEnd(a, 5);
  87. sel.addRange(r);
  88. },
  89. function(win,doc,sel) {
  90. doc.body.innerHTML = 'I<br>|z|zB<br>C'
  91. let a = doc.body.firstChild;
  92. let b = doc.body.childNodes[2];
  93. let c = doc.body.childNodes[4];
  94. let r = doc.createRange();
  95. r.setStart(a, 0);
  96. r.setEnd(c, 1);
  97. sel.addRange(r);
  98. },
  99. function(win,doc,sel) {
  100. doc.body.innerHTML = 'I<br>|z|zB<br>C'
  101. let b = doc.body.childNodes[2];
  102. let c = doc.body.childNodes[4];
  103. let r = doc.createRange();
  104. r.setStart(doc.body, 0);
  105. r.setEnd(c, 1);
  106. sel.addRange(r);
  107. },
  108. function(win,doc,sel) {
  109. doc.body.innerHTML = 'I<br>|z|zB<br>C'
  110. let b = doc.body.childNodes[2];
  111. let c = doc.body.childNodes[4];
  112. let r = doc.createRange();
  113. r.setStart(doc, 0);
  114. r.setEnd(c, 1);
  115. sel.addRange(r);
  116. },
  117. function(win,doc,sel) {
  118. doc.body.innerHTML = 'I<br>B<br>|z|zC'
  119. let a = doc.body.firstChild;
  120. let c = doc.body.childNodes[4];
  121. let r = doc.createRange();
  122. r.setStart(a, 0);
  123. r.setEnd(c, 5);
  124. sel.addRange(r);
  125. },
  126. function(win,doc,sel) {
  127. doc.body.innerHTML = '<br>B<br>CI'
  128. },
  129. function(win,doc,sel) {
  130. doc.body.innerHTML = '<br>B<br>C'
  131. },
  132. function(win,doc,sel) {
  133. doc.body.innerHTML = 'I<br>B<br>C'
  134. let a = doc.body.firstChild;
  135. let c = doc.body.childNodes[4];
  136. let r = doc.createRange();
  137. r.setStart(a, 0);
  138. r.setEnd(c, 1);
  139. sel.addRange(r);
  140. },
  141. function(win,doc,sel) {
  142. doc.body.innerHTML = 'I|z'
  143. },
  144. function(win,doc,sel) {
  145. doc.body.innerHTML = 'Iz|'
  146. document.body.appendChild(document.createTextNode('I'));
  147. document.body.appendChild(document.createTextNode(' '));
  148. document.body.appendChild(createDOM(document));
  149. },
  150. ]
  151. function runTestInIframe(run,t) {
  152. let f = document.createElement('iframe');
  153. f.setAttribute('frameborder','0');
  154. f.setAttribute('height','100');
  155. f.setAttribute('width','200');
  156. f.src = 'data:text/html,<body style="margin:0;padding:0;font-family:monospace">';
  157. f.onload = function () {
  158. try {
  159. run(f.contentWindow, f.contentDocument, f.contentWindow.getSelection());
  160. } finally { ++tests_done; }
  161. }
  162. return f;
  163. }
  164. var id;
  165. function checkFinished() {
  166. if (window.frames.length == tests_done) {
  167. clearInterval(id);
  168. document.documentElement.className = "";
  169. }
  170. }
  171. function runTest() {
  172. for (let i=0; i < tests.length; ++i) {
  173. let t = tests[i];
  174. document.body.appendChild(runTestInIframe(t));
  175. }
  176. id = setInterval(checkFinished,500);
  177. }
  178. </script>
  179. </head>
  180. <body onload="runTest()"></body>
  181. </html>