test_fontFaceGeneric.xhtml (2247B)
1 <?xml version="1.0"?> 2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?> 3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> 4 <window title="CSSGeneric attribute of InspectorFontFace" 5 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 6 onload="RunTest();"> 7 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 8 9 <script type="application/javascript"> 10 <![CDATA[ 11 12 SimpleTest.waitForExplicitFinish(); 13 14 function RunTest() { 15 var rng = document.createRange(); 16 var elem, fonts; 17 18 elem = document.getElementById("test1"); 19 rng.selectNode(elem); 20 fonts = InspectorUtils.getUsedFontFaces(rng); 21 is(fonts.length, 1, "one font found"); 22 is(fonts[0].CSSGeneric, "serif", "font " + fonts[0].name + " was specified as CSS generic"); 23 var serifFamily = fonts[0].CSSFamilyName; 24 25 elem = document.getElementById("test2"); 26 elem.style.fontFamily = serifFamily + ", serif"; 27 rng.selectNode(elem); 28 fonts = InspectorUtils.getUsedFontFaces(rng); 29 is(fonts.length, 1, "one font found"); 30 is(fonts[0].CSSFamilyName, serifFamily, "used the expected family (" + serifFamily + ")"); 31 is(fonts[0].CSSGeneric, "", "font " + fonts[0].name + " was specified by name"); 32 33 elem = document.getElementById("test3"); 34 elem.getElementsByTagName("span")[0].style.fontFamily = serifFamily + ", serif"; 35 rng.selectNode(elem); 36 fonts = InspectorUtils.getUsedFontFaces(rng); 37 is(fonts.length, 2, "two fonts found"); 38 var checked = 0; 39 fonts.forEach(function(f) { 40 if (f.CSSFamilyName == serifFamily) { 41 is(f.CSSGeneric, "", "serif font " + f.name + " was specified by name"); 42 checked++; 43 } else { 44 is(f.CSSGeneric, "monospace", "monospace font " + f.name + " was specified as generic"); 45 checked++; 46 } 47 }); 48 is(checked, 2, "two fonts checked"); 49 50 SimpleTest.finish(); 51 } 52 ]]> 53 </script> 54 55 <!-- html:body contains elements the test will inspect --> 56 <body xmlns="http://www.w3.org/1999/xhtml"> 57 <div id="test1" style="font-family: serif">test one</div> 58 <div id="test2" style="font-family: monospace">test two</div> 59 <div id="test3" style="font-family: monospace">test <span>three</span></div> 60 </body> 61 62 </window>