layout/base/tests/test_bug394057.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial