OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>addRange failures</title> | 4 <title>addRange failures</title> |
5 <script src="../../resources/js-test.js"></script> | 5 <script src="../../resources/js-test.js"></script> |
6 </head> | 6 </head> |
7 <body> | 7 <body> |
8 <script> | 8 <script> |
9 description('Test error handling of Selection.addRange().'); | 9 description('Test error handling of Selection.addRange().'); |
10 | 10 |
11 var selection = window.getSelection(); | 11 var selection = window.getSelection(); |
12 | 12 |
13 function testNull() | 13 function testNull() |
14 { | 14 { |
15 shouldThrow('selection.addRange(null)'); | 15 shouldThrow('selection.addRange(null)'); |
16 } | 16 } |
17 | 17 |
18 function testDetachedRange() | 18 function testEmptyRange() |
19 { | 19 { |
20 var range = new Range(); | 20 var range = new Range(); |
21 range.detach(); | |
22 selection.addRange(range); | 21 selection.addRange(range); |
23 } | 22 } |
24 | 23 |
25 function testNotInDocumentRange() | 24 function testNotInDocumentRange() |
26 { | 25 { |
27 var range = document.createRange(); | 26 var range = document.createRange(); |
28 var notInDocument = document.createTextNode('not in document'); | 27 var notInDocument = document.createTextNode('not in document'); |
29 range.selectNodeContents(notInDocument); | 28 range.selectNodeContents(notInDocument); |
30 selection.addRange(range); | 29 selection.addRange(range); |
31 } | 30 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 testFunction(selection); | 65 testFunction(selection); |
67 | 66 |
68 // Selection should stay at the same position. | 67 // Selection should stay at the same position. |
69 shouldEvaluateTo('selection.rangeCount', 1); | 68 shouldEvaluateTo('selection.rangeCount', 1); |
70 shouldBeTrue('selection.getRangeAt(0).startContainer === document.body'); | 69 shouldBeTrue('selection.getRangeAt(0).startContainer === document.body'); |
71 shouldEvaluateTo('selection.getRangeAt(0).startOffset', 0); | 70 shouldEvaluateTo('selection.getRangeAt(0).startOffset', 0); |
72 shouldBeTrue('selection.getRangeAt(0).endContainer === document.body'); | 71 shouldBeTrue('selection.getRangeAt(0).endContainer === document.body'); |
73 shouldEvaluateTo('selection.getRangeAt(0).endOffset', 0); | 72 shouldEvaluateTo('selection.getRangeAt(0).endOffset', 0); |
74 } | 73 } |
75 | 74 |
76 var testFunctions = [testNull, testDetachedRange, testNotInDocumentRange, testOt
herDocument, testOtherDocumentFragments]; | 75 var testFunctions = [testNull, testEmptyRange, testNotInDocumentRange, testOther
Document, testOtherDocumentFragments]; |
77 testFunctions.forEach(runSingleTest); | 76 testFunctions.forEach(runSingleTest); |
78 </script> | 77 </script> |
79 </body> | 78 </body> |
80 </html> | 79 </html> |
OLD | NEW |