modify-range-ref.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <!DOCTYPE HTML>
  2. <html class="reftest-wait"><head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  4. <title>Testcase for bug </title>
  5. <script>
  6. var tests_done = 0;
  7. var tests = [
  8. 'window.getSelection().getRangeAt(0).setEnd(document.getElementsByTagName("pre")[0].firstChild,9)',
  9. 'window.getSelection().getRangeAt(0).setEndAfter(document.getElementsByTagName("pre")[0].firstChild)',
  10. 'window.getSelection().getRangeAt(0).setEndBefore(document.getElementsByTagName("pre")[0].childNodes[1])',
  11. 'pre=document.getElementsByTagName("pre")[0]; r=window.getSelection().getRangeAt(0); r.setEnd(pre.childNodes[1],3); r.setStartAfter(pre.firstChild)',
  12. 'window.getSelection().getRangeAt(0).setStartBefore(document.getElementsByTagName("pre")[0].firstChild)',
  13. 'window.getSelection().getRangeAt(0).selectNode(document.getElementsByTagName("pre")[0].firstChild)',
  14. 'window.getSelection().getRangeAt(0).selectNodeContents(document.getElementsByTagName("pre")[0])',
  15. 'window.getSelection().getRangeAt(0).collapse(true)',
  16. 'window.getSelection().getRangeAt(0).surroundContents(document.createElement("span"))',
  17. 'window.getSelection().getRangeAt(0).setStart(document,0)',
  18. 'window.getSelection().getRangeAt(0).detach()',
  19. 'window.getSelection().getRangeAt(0).extractContents()',
  20. 'window.getSelection().getRangeAt(0).deleteContents()'
  21. ];
  22. function init_iframe(d) {
  23. var pre = d.createElement('pre');
  24. pre.appendChild(d.createTextNode('first\nfirst\n'));
  25. pre.appendChild(d.createTextNode('second'));
  26. d.documentElement.appendChild(pre);
  27. var text = pre.firstChild;
  28. var sel = d.defaultView.getSelection();
  29. var r = d.createRange();
  30. r.setStart(text,0)
  31. r.setEnd(text,3)
  32. sel.addRange(r);
  33. d.documentElement.offsetHeight;
  34. }
  35. function test_iframe(iframe, i) {
  36. iframe.contentDocument.write(
  37. '<'+'style>span { text-decoration:underline; } <'+'/style>' +
  38. '<'+'script>' +
  39. 'window.parent.init_iframe(document);' +
  40. 'setTimeout(function(){' + window.parent.tests[i] + '; sel=window.getSelection(); try{r=sel.getRangeAt(0); sel.removeRange(r); sel.addRange(r);}catch(e){}; ++window.parent.tests_done; },0)' +
  41. '<'+'/script>'
  42. );
  43. }
  44. function create_iframe(i) {
  45. var div = document.createElement('div');
  46. document.body.appendChild(div);
  47. div.innerHTML = "<iframe src='about:blank' style='height:6em; width:12em; float:left;' frameborder='0' onload='test_iframe(this,"+i+")'><iframe>"
  48. }
  49. var id;
  50. function check_if_done() {
  51. if (tests_done == tests.length) {
  52. clearInterval(id);
  53. document.documentElement.className = "";
  54. }
  55. }
  56. function test() {
  57. for (i = 0; i < tests.length; ++i) {
  58. create_iframe(i);
  59. }
  60. id = setInterval(check_if_done,500);
  61. }
  62. </script>
  63. </head>
  64. <body onload="test()"></body>
  65. </html>