test_system_font_serialization.html (2510B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=475214 5 --> 6 <head> 7 <title>Test for Bug 475214</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=475214">Mozilla Bug 475214</a> 13 <p id="display"></p> 14 <div id="content"> 15 16 </div> 17 <pre id="test"> 18 <script type="application/javascript"> 19 20 /* Helper copied from property_database.js */ 21 function IsCSSPropertyPrefEnabled(prefName) 22 { 23 try { 24 if (SpecialPowers.getBoolPref(prefName)) { 25 return true; 26 } 27 } catch (ex) { 28 ok(false, "Failed to look up property-controlling pref '" + 29 prefName + "' (" + ex + ")"); 30 } 31 32 return false; 33 } 34 35 /** Test for Bug 475214 */ 36 37 var e = document.getElementById("content"); 38 var s = e.style; 39 40 e.style.font = "menu"; 41 is(e.style.cssText, "font: menu;", "serialize system font alone"); 42 is(e.style.font, "menu", "font getter returns value"); 43 44 e.style.fontFamily = "inherit"; 45 is(e.style.font, "", "font getter should be empty"); 46 47 e.style.font = "message-box"; 48 is(e.style.cssText, "font: message-box;", "serialize system font alone"); 49 is(e.style.font, "message-box", "font getter returns value"); 50 51 e.setAttribute("style", "font-weight:bold;font:caption;line-height:3;"); 52 is(e.style.font, "", "font getter should be empty"); 53 54 e.setAttribute("style", "font: menu; font-weight: -moz-use-system-font"); 55 is(e.style.cssText, "font: menu;", "serialize system font alone"); 56 is(e.style.font, "menu", "font getter returns value"); 57 58 e.setAttribute("style", "font: inherit; font-family: Helvetica;"); 59 EXPECTED_DECLS = [ 60 "font-family: Helvetica;", 61 "font-feature-settings: inherit;", 62 "font-kerning: inherit;", 63 "font-language-override: inherit;", 64 "font-size-adjust: inherit;", 65 "font-size: inherit;", 66 "font-stretch: inherit;", 67 "font-style: inherit;", 68 "font-variant: inherit;", 69 "font-weight: inherit;", 70 "line-height: inherit;", 71 ]; 72 if (IsCSSPropertyPrefEnabled("layout.css.font-variations.enabled")) { 73 EXPECTED_DECLS.push("font-optical-sizing: inherit;"); 74 EXPECTED_DECLS.push("font-variation-settings: inherit;"); 75 } 76 EXPECTED_DECLS = EXPECTED_DECLS.sort().join(" "); 77 let sortedDecls = e.style.cssText.split(/ (?=font-|line-)/).sort().join(" "); 78 is(sortedDecls, EXPECTED_DECLS, "don't serialize system font for font:inherit"); 79 is(e.style.font, "", "font getter returns nothing"); 80 81 </script> 82 </pre> 83 </body> 84 </html>