| OLD | NEW |
| 1 <html> | 1 <html> |
| 2 <head> |
| 3 <script src="../../resources/js-test.js"></script> |
| 4 </head> |
| 2 <body> | 5 <body> |
| 3 <div id="test"><span id="span1">foo</span><span>bar</span></div> | 6 <div id="test"><span id="span1">foo</span><span>bar</span></div> |
| 4 <div id="console"></div> | 7 <div id="console"></div> |
| 5 <script> | 8 <script> |
| 6 var s = window.getSelection(); | 9 var s = window.getSelection(); |
| 7 var testDiv = document.getElementById("test"); | 10 var testDiv = document.getElementById("test"); |
| 8 var span1 = document.getElementById("span1"); | 11 var span1 = document.getElementById("span1"); |
| 9 | 12 |
| 10 function log(str) { | 13 function log(str) { |
| 11 var li = document.createElement("li"); | 14 var li = document.createElement("li"); |
| 12 li.appendChild(document.createTextNode(str)); | 15 li.appendChild(document.createTextNode(str)); |
| 13 document.getElementById("console").appendChild(li); | 16 document.getElementById("console").appendChild(li); |
| 14 } | 17 } |
| 15 | 18 |
| 16 function shouldBe(expr, expected) { | |
| 17 var actual = eval(expr); | |
| 18 if (actual != expected) | |
| 19 log("Failure: " + expr + " should be " + expected + ", was " + actual +
"."); | |
| 20 else | |
| 21 log("Success: " + expr + " is " + expected + "."); | |
| 22 } | |
| 23 | |
| 24 if (window.testRunner) | |
| 25 testRunner.dumpAsText(); | |
| 26 | |
| 27 var r = document.createRange(); | 19 var r = document.createRange(); |
| 28 | 20 |
| 29 | |
| 30 // select span1 | 21 // select span1 |
| 31 r.setStart(test, 0); | 22 r.setStart(test, 0); |
| 32 r.setEnd(test, 1); | 23 r.setEnd(test, 1); |
| 33 s.addRange(r); | 24 s.addRange(r); |
| 34 | 25 |
| 35 // replace the selection with span1's text node children | 26 // replace the selection with span1's text node children |
| 36 s.selectAllChildren(span1.firstChild); | 27 s.selectAllChildren(span1.firstChild); |
| 37 shouldBe('s.anchorNode', span1.firstChild); | 28 shouldBe('s.anchorNode', 'span1.firstChild'); |
| 38 shouldBe('s.anchorOffset', 0); | 29 shouldBe('s.anchorOffset', '0'); |
| 39 shouldBe('s.focusNode', span1.firstChild); | 30 shouldBe('s.focusNode', 'span1.firstChild'); |
| 40 shouldBe('s.focusOffset', 0); // Strange, but matches Firefox | 31 shouldBe('s.focusOffset', '0'); // Strange, but matches Firefox |
| 41 | 32 |
| 42 // replace the selection with span1's children | 33 // replace the selection with span1's children |
| 43 s.selectAllChildren(span1); | 34 s.selectAllChildren(span1); |
| 44 shouldBe('window.getSelection()', 'foo'); | 35 shouldBe('window.getSelection().toString()', '"foo"'); |
| 45 | 36 |
| 46 // replace the selection with test's children | 37 // replace the selection with test's children |
| 47 s.selectAllChildren(test); | 38 s.selectAllChildren(test); |
| 48 shouldBe('window.getSelection()', 'foobar'); | 39 shouldBe('window.getSelection().toString()', '"foobar"'); |
| 49 | 40 |
| 41 // call with types other than Node |
| 42 shouldNotThrow('s.selectAllChildren(null)'); |
| 43 shouldNotThrow('s.selectAllChildren(window)'); |
| 44 shouldNotThrow('s.selectAllChildren("")'); |
| 50 </script> | 45 </script> |
| 51 </body> | 46 </body> |
| 52 </html> | 47 </html> |
| OLD | NEW |