OLD | NEW |
1 <html> | 1 <html> |
2 <body> | 2 <body> |
3 <div id="test"><span id="span1">foo<span id="span2">bar</span></span><span id="s
pan3">baz</span></div> | 3 <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> | 4 <div id="console"></div> |
5 <script> | 5 <script> |
6 var s = window.getSelection(); | 6 var s = window.getSelection(); |
7 var testDiv = document.getElementById("test"); | 7 var testDiv = document.getElementById("test"); |
8 var span1 = document.getElementById("span1"); | 8 var span1 = document.getElementById("span1"); |
9 var span2 = document.getElementById("span2"); | 9 var span2 = document.getElementById("span2"); |
10 var span3 = document.getElementById("span3"); | 10 var span3 = document.getElementById("span3"); |
11 | 11 |
12 function log(str) { | 12 function log(str) { |
13 var li = document.createElement("li"); | 13 var li = document.createElement("li"); |
14 li.appendChild(document.createTextNode(str)); | 14 li.appendChild(document.createTextNode(str)); |
15 document.getElementById("console").appendChild(li); | 15 document.getElementById("console").appendChild(li); |
16 } | 16 } |
17 | 17 |
18 function shouldBe(expr, expected) { | 18 function shouldBe(expr, expected) { |
19 var actual = eval(expr); | 19 var actual = eval(expr); |
20 if (actual != expected) | 20 if (actual != expected) |
21 log("Failure: " + expr + " should be " + expected + ", was " + actual +
"."); | 21 log("Failure: " + expr + " should be " + expected + ", was " + actual +
"."); |
22 else | 22 else |
23 log("Success: " + expr + " is " + expected + "."); | 23 log("Success: " + expr + " is " + expected + "."); |
24 } | 24 } |
25 | 25 |
| 26 function shouldThrow(expr) { |
| 27 try { |
| 28 eval(expr); |
| 29 log("Failure: " + expr + " didn't raise an exception" + "."); |
| 30 } catch (ex) { |
| 31 log("Success: " + expr + " raised " + ex + "."); |
| 32 } |
| 33 } |
| 34 |
26 if (window.testRunner) | 35 if (window.testRunner) |
27 testRunner.dumpAsText(); | 36 testRunner.dumpAsText(); |
28 | 37 |
29 var r = document.createRange(); | 38 var r = document.createRange(); |
30 | 39 |
31 // select span2 | 40 // select span2 |
32 r.setStart(span1, 1); | 41 r.setStart(span1, 1); |
33 r.setEnd(span1, 2); | 42 r.setEnd(span1, 2); |
34 s.addRange(r); | 43 s.addRange(r); |
35 | 44 |
36 shouldBe('s.containsNode(null, false)', false); | 45 shouldThrow("s.containsNode(null, false);"); |
37 shouldBe('s.containsNode(null, true)', false); | 46 shouldThrow("s.containsNode(null, true);"); |
38 shouldBe('s.containsNode(testDiv, false)', false); | 47 shouldBe('s.containsNode(testDiv, false)', false); |
39 shouldBe('s.containsNode(testDiv, true)', true); | 48 shouldBe('s.containsNode(testDiv, true)', true); |
40 shouldBe('s.containsNode(span1, false)', false); | 49 shouldBe('s.containsNode(span1, false)', false); |
41 shouldBe('s.containsNode(span1, true)', true); | 50 shouldBe('s.containsNode(span1, true)', true); |
42 shouldBe('s.containsNode(span2.firstChild, false)', true); | 51 shouldBe('s.containsNode(span2.firstChild, false)', true); |
43 shouldBe('s.containsNode(span2.firstChild, true)', true); | 52 shouldBe('s.containsNode(span2.firstChild, true)', true); |
44 shouldBe('s.containsNode(span3.firstChild, false)', false); | 53 shouldBe('s.containsNode(span3.firstChild, false)', false); |
45 shouldBe('s.containsNode(span3.firstChild, true)', false); | 54 shouldBe('s.containsNode(span3.firstChild, true)', false); |
46 shouldBe('s.containsNode(document, false)', false); | 55 shouldBe('s.containsNode(document, false)', false); |
47 shouldBe('s.containsNode(document.body, true)', true); | 56 shouldBe('s.containsNode(document.body, true)', true); |
(...skipping 21 matching lines...) Expand all Loading... |
69 s.addRange(r); | 78 s.addRange(r); |
70 | 79 |
71 shouldBe('s.containsNode(span2, false)', true); | 80 shouldBe('s.containsNode(span2, false)', true); |
72 shouldBe('s.containsNode(span2.firstChild, false)', true); | 81 shouldBe('s.containsNode(span2.firstChild, false)', true); |
73 shouldBe('s.containsNode(span3, false)', false); | 82 shouldBe('s.containsNode(span3, false)', false); |
74 shouldBe('s.containsNode(span3, true)', true); | 83 shouldBe('s.containsNode(span3, true)', true); |
75 | 84 |
76 </script> | 85 </script> |
77 </body> | 86 </body> |
78 </html> | 87 </html> |
OLD | NEW |