OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <title>Selection.setBaseAndExtent() tests</title> |
| 3 <div id=log></div> |
| 4 <script src=/resources/testharness.js></script> |
| 5 <script src=/resources/testharnessreport.js></script> |
| 6 <script src=common.js></script> |
| 7 <script> |
| 8 "use strict"; |
| 9 |
| 10 for (var i = 0; i < testRanges.length; i++) { |
| 11 test(function() { |
| 12 var data = eval(testRanges[i]); |
| 13 selection.setBaseAndExtent(data[0], data[1], data[2], data[3]); |
| 14 assert_equals(selection.rangeCount, 1, |
| 15 "selection.rangeCount must equal 1"); |
| 16 assert_equals(selection.anchorNode, data[0], |
| 17 "anchorNode must equal the requested anchor node"); |
| 18 assert_equals(selection.anchorOffset, data[1], |
| 19 "anchorOffset must equal the requested anchor offset"); |
| 20 assert_equals(selection.focusNode, data[2], |
| 21 "focusNode must equal the requested focus node"); |
| 22 assert_equals(selection.focusOffset, data[3], |
| 23 "focusOffset must equal the requested focus offset"); |
| 24 }, "Range " + i + " " + testRanges[i] + " setBaseAndExtent()"); |
| 25 |
| 26 test(function() { |
| 27 var data = eval(testRanges[i]); |
| 28 selection.setBaseAndExtent(data[2], data[3], data[0], data[1]); |
| 29 assert_equals(selection.rangeCount, 1, |
| 30 "selection.rangeCount must equal 1"); |
| 31 assert_equals(selection.anchorNode, data[2], |
| 32 "anchorNode must equal the requested focus node"); |
| 33 assert_equals(selection.anchorOffset, data[3], |
| 34 "anchorOffset must equal the requested focus offset"); |
| 35 assert_equals(selection.focusNode, data[0], |
| 36 "focusNode must equal the requested anchor node"); |
| 37 assert_equals(selection.focusOffset, data[1], |
| 38 "focusOffset must equal the requested anchor offset"); |
| 39 }, "Reverse range " + i + " " + testRanges[i] + " setBaseAndExtent()"); |
| 40 } |
| 41 |
| 42 test(function() { |
| 43 var title = document.getElementsByTagName('title')[0]; |
| 44 try { |
| 45 selection.setBaseAndExtent(title, 0, title, 99); |
| 46 assert_true(false, "focus offset, must throw an IndexSizeError exception
") |
| 47 } catch (e) { |
| 48 assert_equals(e.name, "IndexSizeError", "focus offset, got an IndexSizeE
rror exception") |
| 49 } |
| 50 try { |
| 51 selection.setBaseAndExtent(title, 99, title, 0); |
| 52 assert_true(false, "anchor offset, must throw an IndexSizeError exceptio
n") |
| 53 } catch (e) { |
| 54 assert_equals(e.name, "IndexSizeError", "anchor offset, got an IndexSize
Error exception") |
| 55 } |
| 56 }, "setBaseAndExtent() with index larger than length"); |
| 57 |
| 58 test(function() { |
| 59 var title = document.getElementsByTagName('title')[0]; |
| 60 try { |
| 61 selection.setBaseAndExtent(title, 0, title, -1); |
| 62 assert_true(false, "focus offset, must throw an IndexSizeError exception
") |
| 63 } catch (e) { |
| 64 assert_equals(e.name, "IndexSizeError", "focus offset, got an IndexSizeE
rror exception") |
| 65 } |
| 66 try { |
| 67 selection.setBaseAndExtent(title, -1, title, 0); |
| 68 assert_true(false, "anchor offset, must throw an IndexSizeError exceptio
n") |
| 69 } catch (e) { |
| 70 assert_equals(e.name, "IndexSizeError", "anchor offset, got an IndexSize
Error exception") |
| 71 } |
| 72 }, "setBaseAndExtent() with negative index"); |
| 73 |
| 74 test(function() { |
| 75 var title = document.getElementsByTagName('title')[0]; |
| 76 try { |
| 77 selection.setBaseAndExtent(title, 0, null, 0); |
| 78 assert_true(false, "focus node, must throw an TypeError exception") |
| 79 } catch (e) { |
| 80 assert_equals(e.name, "TypeError", "focus node, got an TypeError excepti
on") |
| 81 } |
| 82 try { |
| 83 selection.setBaseAndExtent(null, 0, title, 0); |
| 84 assert_true(false, "anchor node, must throw an TypeError exception") |
| 85 } catch (e) { |
| 86 assert_equals(e.name, "TypeError", "anchor node, got an TypeError except
ion") |
| 87 } |
| 88 try { |
| 89 selection.setBaseAndExtent(null, 0, null, 0); |
| 90 assert_true(false, "both nodes, must throw an TypeError exception") |
| 91 } catch (e) { |
| 92 assert_equals(e.name, "TypeError", "both nodes, got an TypeError excepti
on") |
| 93 } |
| 94 }, "setBaseAndExtent() with null nodes"); |
| 95 |
| 96 test(function() { |
| 97 var title = document.getElementsByTagName('title')[0]; |
| 98 try { |
| 99 selection.setBaseAndExtent(title, 0, title); |
| 100 assert_true(false, "focus offset, must throw an TypeError exception") |
| 101 } catch (e) { |
| 102 assert_equals(e.name, "TypeError", "focus offset, got an TypeError excep
tion") |
| 103 } |
| 104 try { |
| 105 selection.setBaseAndExtent(title, 0); |
| 106 assert_true(false, "focus node, must throw an TypeError exception") |
| 107 } catch (e) { |
| 108 assert_equals(e.name, "TypeError", "focus node, got an TypeError excepti
on") |
| 109 } |
| 110 try { |
| 111 selection.setBaseAndExtent(title); |
| 112 assert_true(false, "anchor offset, must throw an TypeError exception") |
| 113 } catch (e) { |
| 114 assert_equals(e.name, "TypeError", "anchor offset, got an TypeError exce
ption") |
| 115 } |
| 116 }, "setBaseAndExtent() with too few params"); |
| 117 |
| 118 testDiv.style.display = "none"; |
| 119 |
| 120 </script> |
OLD | NEW |