| <html> |
| <body> |
| <div id="test"><span id="span1">foo</span><span>bar</span></div> |
| <div id="console"></div> |
| <script> |
| var s = window.getSelection(); |
| var testDiv = document.getElementById("test"); |
| var span1 = document.getElementById("span1"); |
| |
| function log(str) { |
| var li = document.createElement("li"); |
| li.appendChild(document.createTextNode(str)); |
| document.getElementById("console").appendChild(li); |
| } |
| |
| function shouldBe(expr, expected) { |
| var actual = eval(expr); |
| if (actual != expected) |
| log("Failure: " + expr + " should be " + expected + ", was " + actual + "."); |
| else |
| log("Success: " + expr + " is " + expected + "."); |
| } |
| |
| if (window.testRunner) |
| testRunner.dumpAsText(); |
| |
| var r = document.createRange(); |
| |
| |
| // select span1 |
| r.setStart(test, 0); |
| r.setEnd(test, 1); |
| s.addRange(r); |
| |
| // replace the selection with span1's text node children |
| s.selectAllChildren(span1.firstChild); |
| shouldBe('s.anchorNode', span1.firstChild); |
| shouldBe('s.anchorOffset', 0); |
| shouldBe('s.focusNode', span1.firstChild); |
| shouldBe('s.focusOffset', 0); // Strange, but matches Firefox |
| |
| // replace the selection with span1's children |
| s.selectAllChildren(span1); |
| shouldBe('window.getSelection()', 'foo'); |
| |
| // replace the selection with test's children |
| s.selectAllChildren(test); |
| shouldBe('window.getSelection()', 'foobar'); |
| |
| </script> |
| </body> |
| </html> |