test_getSubStringLength.xhtml (2515B)
1 <!DOCTYPE html> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=420243 5 --> 6 <head> 7 <title>Test for Bug 420243</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=420243">Mozilla Bug 420243</a> 13 <p id="display"></p> 14 <div id="content" style="display: none"></div> 15 16 <iframe id="svg" src="getSubStringLength-helper.svg"></iframe> 17 18 <pre id="test"> 19 <script class="testbody" type="application/javascript"> 20 SimpleTest.waitForExplicitFinish(); 21 22 function runTests(text, charWidth) { 23 function chars(n) { return charWidth * n; } 24 25 function expectThrow(charnum, nchars) { 26 try { 27 text.getSubStringLength(charnum, nchars); 28 ok(false, 29 "text.getSubStringLength(" + charnum + "," + nchars + ") " + 30 "should have thrown"); 31 } catch (e) { 32 is(e.name, "IndexSizeError", 33 "expected an index error for " + 34 "text.getSubStringLength(" + charnum + "," + nchars + ")"); 35 is(e.code, DOMException.INDEX_SIZE_ERR, 36 "expected an index error for " + 37 "text.getSubStringLength(" + charnum + "," + nchars + ")"); 38 } 39 } 40 41 function expectValue(charnum, nchars, expected) { 42 try { 43 isfuzzy(text.getSubStringLength(charnum, nchars), expected, 0.01, 44 "text.getSubStringLength(" + charnum + "," + nchars + ") " + 45 "returned wrong value"); 46 } catch (e) { 47 ok(false, 48 "unexpected exception for " + 49 "text.getSubStringLength(" + charnum + "," + nchars + ")"); 50 } 51 } 52 53 expectThrow(100, 2); 54 expectThrow(100, 0); 55 expectThrow(3, 0); 56 expectThrow(3, 1); 57 58 expectValue(1, 3, chars(2)); 59 expectValue(0, 4, chars(3)); 60 expectValue(0, 0, chars(0)); 61 expectValue(1, 0, chars(0)); 62 expectValue(2, 0, chars(0)); 63 expectValue(0, 1, chars(1)); 64 expectValue(1, 1, chars(1)); 65 expectValue(2, 1, chars(1)); 66 expectValue(0, 2, chars(2)); 67 expectValue(1, 2, chars(2)); 68 expectValue(0, 3, chars(3)); 69 expectValue(1, 100, chars(2)); 70 expectValue(2, 100, chars(1)); 71 } 72 73 74 function run() { 75 try { 76 var document = $("svg").contentWindow.document; 77 var text = document.getElementById("text"); 78 79 runTests(text, text.getSubStringLength(0, 1)); 80 } catch (e) { 81 ok(false, "threw error: " + e); 82 } 83 84 SimpleTest.finish(); 85 } 86 87 window.addEventListener("load", run); 88 </script> 89 </pre> 90 </body> 91 </html>