test_getBlockLineCounts.html (2014B)
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 <style> 8 .test { 9 margin: 1em; 10 font: 13px monospace; 11 width: 16ch; 12 } 13 .cols { 14 columns: 3; 15 } 16 </style> 17 </head> 18 19 <body> 20 <div class="test"><span id="test1">one two three four five six seven</span></div> 21 <div class="test"><div id="test2">one two three four five six seven</div></div> 22 <div class="test cols"><div id="test3">one two three four five six seven</div></div> 23 <div class="test"><div id="test4" class="cols">one two three four five six seven</div></div> 24 25 <script> 26 const TEST_DATA = [ 27 { 28 description: "Test line counts of a non-block element returns null", 29 testElem: "test1", 30 lineCounts: null, 31 }, 32 { 33 description: "Test line count of a non-fragmented block", 34 testElem: "test2", 35 lineCounts: [3], 36 }, 37 { 38 description: "Test line counts of a block that is fragmented across columns", 39 testElem: "test3", 40 lineCounts: [3, 3, 1], 41 }, 42 { 43 description: "Test line counts when columns are specified directly on the block", 44 testElem: "test4", 45 lineCounts: [3, 3, 1], 46 }, 47 ]; 48 49 function check(a, b) { 50 if (a === null) { 51 return b === null; 52 } 53 if (a.length !== b.length) { 54 return false; 55 } 56 for (let i = 0; i < a.length; i++) { 57 if (a[i] !== b[i]) { 58 return false; 59 } 60 } 61 return true; 62 } 63 64 function run_tests() { 65 for (const { description, testElem, lineCounts } of TEST_DATA) { 66 info(description); 67 68 let target = document.getElementById(testElem); 69 let counts = InspectorUtils.getBlockLineCounts(target); 70 71 ok(check(counts, lineCounts), "got expected line counts"); 72 } 73 74 SimpleTest.finish(); 75 } 76 77 SimpleTest.waitForExplicitFinish(); 78 window.requestAnimationFrame(run_tests); 79 </script> 80 </body>