test_getClientRectsAndTexts.html (2084B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> 7 </head> 8 <body> 9 10 <div id="div1" style="width:200px">Here is some text that <a href="#">will wrap</a> in <a href="#">this small</a>-ish container.</div> 11 <div id="div2">Into another <a href="#">container</a></div> 12 <div id="div3">A very <span>deep <span>deep <span>deep</span></span></span> bit of text.</div> 13 14 <script> 15 if (typeof(is) == "undefined") { 16 var is = function(a, b, m) { 17 if(a != b) { 18 window.console.log("Expected '" + b + "' but got '" + a + "': " + m); 19 } 20 }; 21 } 22 23 if (typeof(todo_is) == "undefined") { 24 var todo_is = is; 25 } 26 27 function testRangeTexts(startNode, startOffset, endNode, endOffset, expectedText, todo) { 28 let r = new Range(); 29 r.setStart(startNode, startOffset); 30 r.setEnd(endNode, endOffset); 31 32 let texts = r.getClientRectsAndTexts().textList; 33 let concatText = ""; 34 for (let i = 0; i < texts.length; i++) { 35 concatText += texts[i]; 36 } 37 38 if (todo) { 39 todo_is(concatText, expectedText, "Text matches."); 40 } else { 41 is(concatText, expectedText, "Text matches."); 42 } 43 } 44 45 let d1c1 = div1.firstChild; 46 let d1c2 = d1c1.nextSibling; 47 let d1c3 = d1c2.nextSibling; 48 let d1c4 = d1c3.nextSibling; 49 let d1c5 = d1c4.nextSibling; 50 51 let link1 = d1c2.firstChild; 52 let link2 = d1c4.firstChild; 53 54 let d2c1 = div2.firstChild; 55 let d2c2 = d2c1.nextSibling; 56 57 let link3 = d2c2.firstChild; 58 59 let d3c1 = div3.firstChild; 60 let d3c2 = d3c1.nextSibling; 61 let d3c3 = d3c2.nextSibling; 62 63 let data = [ 64 [d1c1, 0, d1c1, 0, ""], 65 [d1c1, 0, d1c1, 4, "Here"], 66 [d1c1, 4, d1c1, 7, " is"], 67 [d1c1, 22, link1, 0, " "], 68 [d1c1, 22, link1, 1, " w"], 69 [d1c1, 22, d1c3, 1, " will wrap "], 70 [link1, 2, link2, 3, "ll wrap in thi"], 71 [link2, 5, link3, 3, "small-ish container.Into another con"], 72 [d3c1, 3, d3c3, 4, "ery deep deep deep bit"], 73 ]; 74 75 data.forEach(function (d) { testRangeTexts.apply(null, d); }); 76 77 </script> 78 79 </body> 80 </html>