Range-stringifier.html (1404B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <title>Range stringifier</title> 4 <link rel="author" title="KiChjang" href="mailto:kungfukeith11@gmail.com"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <div id=test>Test div</div> 8 <div id=another>Another div</div> 9 <div id=last>Last div</div> 10 <div id=log></div> 11 <script> 12 test(function() { 13 var r = new Range(); 14 var testDiv = document.getElementById("test"); 15 test(function() { 16 r.selectNodeContents(testDiv); 17 assert_equals(r.collapsed, false); 18 assert_equals(r.toString(), testDiv.textContent); 19 }, "Node contents of a single div"); 20 21 var textNode = testDiv.childNodes[0]; 22 test(function() { 23 r.setStart(textNode, 5); 24 r.setEnd(textNode, 7); 25 assert_equals(r.collapsed, false); 26 assert_equals(r.toString(), "di"); 27 }, "Text node with offsets"); 28 29 var anotherDiv = document.getElementById("another"); 30 test(function() { 31 r.setStart(testDiv, 0); 32 r.setEnd(anotherDiv, 0); 33 assert_equals(r.toString(), "Test div\n"); 34 }, "Two nodes, each with a text node"); 35 36 var lastDiv = document.getElementById("last"); 37 var lastText = lastDiv.childNodes[0]; 38 test(function() { 39 r.setStart(textNode, 5); 40 r.setEnd(lastText, 4); 41 assert_equals(r.toString(), "div\nAnother div\nLast"); 42 }, "Three nodes with start offset and end offset on text nodes"); 43 }); 44 </script>