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 id="span2">bar</span></span><span id="s
pan3">baz</span></div> | 6 <div id="test"><span id="span1">foo<span id="span2">bar</span></span><span id="s
pan3">baz</span></div> |
4 <div id="console"></div> | |
5 <script> | 7 <script> |
6 var s = window.getSelection(); | 8 var s = window.getSelection(); |
7 var testDiv = document.getElementById("test"); | 9 var testDiv = document.getElementById("test"); |
8 var span1 = document.getElementById("span1"); | 10 var span1 = document.getElementById("span1"); |
9 var span2 = document.getElementById("span2"); | 11 var span2 = document.getElementById("span2"); |
10 var span3 = document.getElementById("span3"); | 12 var span3 = document.getElementById("span3"); |
11 | 13 |
12 function log(str) { | |
13 var li = document.createElement("li"); | |
14 li.appendChild(document.createTextNode(str)); | |
15 document.getElementById("console").appendChild(li); | |
16 } | |
17 | |
18 function shouldBe(expr, expected) { | |
19 var actual = eval(expr); | |
20 if (actual != expected) | |
21 log("Failure: " + expr + " should be " + expected + ", was " + actual +
"."); | |
22 else | |
23 log("Success: " + expr + " is " + expected + "."); | |
24 } | |
25 | |
26 if (window.testRunner) | |
27 testRunner.dumpAsText(); | |
28 | |
29 var r = document.createRange(); | 14 var r = document.createRange(); |
30 | 15 |
31 | 16 |
32 // delete a collapsed selection | 17 // delete a collapsed selection |
33 r.setStart(span2.firstChild, 1); | 18 r.setStart(span2.firstChild, 1); |
34 r.setEnd(span2.firstChild, 1); | 19 r.setEnd(span2.firstChild, 1); |
35 s.addRange(r); | 20 s.addRange(r); |
36 | 21 |
37 s.deleteFromDocument() | 22 s.deleteFromDocument() |
38 shouldBe('span1.textContent', 'fooar'); | 23 shouldBeEqualToString("span1.textContent", "foobar"); |
39 try { | |
40 s.deleteFromDocument() | |
41 shouldBe('span1.textContent', 'foar'); | |
42 } catch (ex) { | |
43 log(ex); | |
44 } | |
45 | |
46 | 24 |
47 // try to delete a collapsed selection at the start | 25 // try to delete a collapsed selection at the start |
48 r.setStart(span1.firstChild, 0); | 26 r.setStart(span1.firstChild, 0); |
49 r.setEnd(span1.firstChild, 0); | 27 r.setEnd(span1.firstChild, 0); |
50 s.removeAllRanges(); | 28 s.removeAllRanges(); |
51 s.addRange(r); | 29 s.addRange(r); |
52 | 30 |
53 try { | 31 s.deleteFromDocument() |
54 s.deleteFromDocument() | 32 shouldBeEqualToString("span1.textContent", "foobar"); |
55 shouldBe('span1.textContent', 'foar'); | |
56 } catch (ex) { | |
57 log(ex); | |
58 } | |
59 | 33 |
60 | 34 |
61 // delete whole contents | 35 // delete whole contents |
62 r.setStart(span2.firstChild, 0); | 36 r.setStart(span2.firstChild, 0); |
63 r.setEnd(span2.firstChild, 2); | 37 r.setEnd(span2.firstChild, 3); |
64 s.removeAllRanges(); | 38 s.removeAllRanges(); |
65 s.addRange(r); | 39 s.addRange(r); |
66 | 40 |
67 s.deleteFromDocument() | 41 s.deleteFromDocument() |
68 shouldBe('span1.firstChild.nextSibling.id', 'span2'); | 42 shouldBeEqualToString("span1.firstChild.nextSibling.id", "span2"); |
69 shouldBe('span1.firstChild.nextSibling.firstChild.nodeValue', ''); | 43 shouldBeEqualToString("span1.firstChild.nextSibling.firstChild.nodeValue", ""); |
70 | |
71 | 44 |
72 // partially delete two nodes | 45 // partially delete two nodes |
73 r.setStart(span1.firstChild, 1); | 46 r.setStart(span1.firstChild, 1); |
74 r.setEnd(span3.firstChild, 2); | 47 r.setEnd(span3.firstChild, 2); |
75 s.removeAllRanges(); | 48 s.removeAllRanges(); |
76 s.addRange(r); | 49 s.addRange(r); |
77 | 50 |
78 s.deleteFromDocument() | 51 s.deleteFromDocument() |
79 shouldBe('test.textContent', 'fz'); | 52 shouldBeEqualToString("test.textContent", "fz"); |
80 | 53 |
81 </script> | 54 </script> |
82 </body> | 55 </body> |
83 </html> | 56 </html> |
OLD | NEW |