content/base/test/test_bug454326.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/test_bug454326.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,135 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=454326
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 454326</title>
    1.11 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=454326">Mozilla Bug 454326</a>
    1.16 +<p id="display"></p>
    1.17 +<div id="content" style="display: none">
    1.18 +</div>
    1.19 +
    1.20 +<div id="partial-text-selection">Hello Hello <div></div>World!</div>
    1.21 +<div id="partial-element-selection"><div id="begin">Hello Hello </div><div></div><div id="end">World!</div></div>
    1.22 +<pre id="test">
    1.23 +<script class="testbody" type="text/javascript">
    1.24 +
    1.25 +/** Test for Bug 454326 **/
    1.26 +
    1.27 +  function reinitPartialTextSelection() {
    1.28 +    var pts = document.getElementById("partial-text-selection");
    1.29 +    pts.textContent = null;
    1.30 +    pts.appendChild(document.createTextNode("Hello Hello "));
    1.31 +    pts.appendChild(document.createElement("div"));
    1.32 +    pts.appendChild(document.createTextNode("World!"));
    1.33 +  }
    1.34 +
    1.35 +
    1.36 +  function doTest() {
    1.37 +    var pts = document.getElementById("partial-text-selection");
    1.38 +    var ex = null;
    1.39 +    try {
    1.40 +      var r1 = document.createRange();
    1.41 +      r1.setStart(pts.firstChild, 6);
    1.42 +      r1.setEnd(pts.lastChild, 6);
    1.43 +      is(r1.toString(), "Hello World!", "Wrong range!");
    1.44 +      r1.surroundContents(document.createElement("div"));
    1.45 +      is(r1.toString(), "Hello World!", "Wrong range!");
    1.46 +    } catch(e) {
    1.47 +      ex = e;
    1.48 +    }
    1.49 +    is(ex, null, "Unexpected exception!");
    1.50 +
    1.51 +    reinitPartialTextSelection();
    1.52 +    ex = null;
    1.53 +    try {
    1.54 +      var r2 = document.createRange();
    1.55 +      r2.setStart(pts.firstChild, 6);
    1.56 +      r2.setEnd(pts, 2);
    1.57 +      is(r2.toString(), "Hello ", "Wrong range!");
    1.58 +      r2.surroundContents(document.createElement("div"));
    1.59 +      is(r2.toString(), "Hello ", "Wrong range!");
    1.60 +    } catch(e) {
    1.61 +      ex = e;
    1.62 +    }
    1.63 +    is(ex, null, "Unexpected exception!");
    1.64 +
    1.65 +    reinitPartialTextSelection();
    1.66 +    ex = null;
    1.67 +    try {
    1.68 +      var r3 = document.createRange();
    1.69 +      r3.setStart(pts, 1);
    1.70 +      r3.setEnd(pts.lastChild, 6);
    1.71 +      is(r3.toString(), "World!", "Wrong range!");
    1.72 +      r3.surroundContents(document.createElement("div"));
    1.73 +      is(r3.toString(), "World!", "Wrong range!");
    1.74 +    } catch(e) {
    1.75 +      ex = e;
    1.76 +    }
    1.77 +    is(ex, null, "Unexpected exception!");
    1.78 +
    1.79 +    reinitPartialTextSelection();
    1.80 +    ex = null;
    1.81 +    try {
    1.82 +      var r3 = document.createRange();
    1.83 +      r3.setStart(pts.firstChild, 6);
    1.84 +      r3.setEnd(pts.firstChild.nextSibling, 0);
    1.85 +      is(r3.toString(), "Hello ", "Wrong range!");
    1.86 +      r3.surroundContents(document.createElement("div"));
    1.87 +      is(r3.toString(), "Hello ", "Wrong range!");
    1.88 +    } catch(e) {
    1.89 +      ex = e;
    1.90 +      is(e.name, "InvalidStateError", "Didn't get InvalidStateError exception!");
    1.91 +      is(Object.getPrototypeOf(e), DOMException.prototype, "Didn't get DOMException!");
    1.92 +      is(e.code, 11, "Didn't get INVALID_STATE_ERR exception!");
    1.93 +    }
    1.94 +    ok(ex, "There should have been an exception!");
    1.95 +
    1.96 +    reinitPartialTextSelection();
    1.97 +    ex = null;
    1.98 +    try {
    1.99 +      var r3 = document.createRange();
   1.100 +      r3.setStart(pts.firstChild.nextSibling, 0);
   1.101 +      r3.setEnd(pts.lastChild, 6);
   1.102 +      is(r3.toString(), "World!", "Wrong range!");
   1.103 +      r3.surroundContents(document.createElement("div"));
   1.104 +      is(r3.toString(), "World!", "Wrong range!");
   1.105 +    } catch(e) {
   1.106 +      ex = e;
   1.107 +      is(e.name, "InvalidStateError", "Didn't get InvalidStateError exception!");
   1.108 +      is(Object.getPrototypeOf(e), DOMException.prototype, "Didn't get DOMException!");
   1.109 +      is(e.code, 11, "Didn't get INVALID_STATE_ERR exception!");
   1.110 +    }
   1.111 +    ok(ex, "There should have been an exception!");
   1.112 +
   1.113 +    ex = null;
   1.114 +    try {
   1.115 +      var pes = document.getElementById("partial-element-selection");
   1.116 +      var r4 = document.createRange();
   1.117 +      r4.setStart(pes.firstChild.firstChild, 6);
   1.118 +      r4.setEnd(pes.lastChild.firstChild, 6);
   1.119 +      is(r4.toString(), "Hello World!", "Wrong range!");
   1.120 +      r4.surroundContents(document.createElement("div"));
   1.121 +      is(r4.toString(), "Hello World!", "Wrong range!");
   1.122 +    } catch(e) {
   1.123 +      ex = e;
   1.124 +      is(e.name, "InvalidStateError", "Didn't get InvalidStateError exception!");
   1.125 +      is(Object.getPrototypeOf(e), DOMException.prototype, "Didn't get DOMException!");
   1.126 +      is(e.code, 11, "Didn't get INVALID_STATE_ERR exception!");
   1.127 +    }
   1.128 +    ok(ex, "There should have been an exception!");
   1.129 +  }
   1.130 +
   1.131 +  SimpleTest.waitForExplicitFinish();
   1.132 +  addLoadEvent(doTest);
   1.133 +  addLoadEvent(SimpleTest.finish);
   1.134 +</script>
   1.135 +</pre>
   1.136 +</body>
   1.137 +</html>
   1.138 +

mercurial