test_bug394057.html (2555B)
1 <!DOCTYPE HTML> 2 <html lang="en"> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=394057 5 --> 6 <head> 7 <title>Test for Bug 394057</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 10 <style type="text/css"> 11 12 #display { background: yellow; color: black; font-family: serif; } 13 14 </style> 15 </head> 16 <body> 17 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=394057">Mozilla Bug 394057</a> 18 <table id="display"><tr><td>MmMmMm...iiiIIIlll---</td></tr></table> 19 <div id="content" style="display: none"> 20 21 </div> 22 <pre id="test"> 23 <script class="testbody" type="text/javascript"> 24 25 /** Test for Bug 394057 */ 26 27 SimpleTest.waitForExplicitFinish(); 28 29 var tableElement = document.getElementById("display"); 30 31 var CC = SpecialPowers.Cc; 32 var CI = SpecialPowers.Ci; 33 34 var fe = 35 CC["@mozilla.org/gfx/fontenumerator;1"].createInstance(CI.nsIFontEnumerator); 36 var serifFonts = fe.EnumerateFonts("x-western", "serif"); 37 var monospaceFonts = fe.EnumerateFonts("x-western", "monospace"); 38 39 function table_width_for_font(font) { 40 tableElement.style.fontFamily = '"' + font + '"'; 41 var result = tableElement.offsetWidth; 42 tableElement.style.fontFamily = ""; 43 return result; 44 } 45 46 var serifIdx = 0; 47 var monospaceIdx = 0; 48 var monospaceWidth, serifWidth; 49 monospaceWidth = table_width_for_font(monospaceFonts[monospaceIdx]); 50 for (serifIdx in serifFonts) { 51 serifWidth = table_width_for_font(serifFonts[serifIdx]); 52 if (serifWidth != monospaceWidth) 53 break; 54 } 55 if (serifWidth == monospaceWidth) { 56 for (monospaceIdx in monospaceFonts) { 57 monospaceWidth = table_width_for_font(monospaceFonts[monospaceIdx]); 58 if (serifWidth != monospaceWidth) 59 break; 60 } 61 } 62 63 isnot(serifWidth, monospaceWidth, 64 "can't find serif and monospace fonts of different width"); 65 66 SpecialPowers.pushPrefEnv({'set': [['font.name.serif.x-western', serifFonts[serifIdx]]]}).then(step2); 67 68 var serifWidthFromPref; 69 function step2() { 70 serifWidthFromPref = tableElement.offsetWidth; 71 SpecialPowers.pushPrefEnv({'set': [['font.name.serif.x-western', monospaceFonts[monospaceIdx]]]}).then(step3); 72 } 73 var monospaceWidthFromPref; 74 function step3() { 75 monospaceWidthFromPref = tableElement.offsetWidth; 76 77 is(serifWidthFromPref, serifWidth, 78 "changing font pref should change width of table (serif)"); 79 is(monospaceWidthFromPref, monospaceWidth, 80 "changing font pref should change width of table (monospace)"); 81 SimpleTest.finish(); 82 } 83 84 </script> 85 </pre> 86 </body> 87 </html>