test_bug467669.xhtml (6089B)
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 <?xml-stylesheet type="text/css" href="test_bug467669.css"?> 5 <!-- 6 https://bugzilla.mozilla.org/show_bug.cgi?id=467669 7 --> 8 <window title="Mozilla Bug 467669" 9 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 10 onload="RunTest();"> 11 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 12 13 <!-- test code goes here --> 14 <script type="application/javascript"> 15 <![CDATA[ 16 /** Test for Bug 467669 */ 17 18 SimpleTest.waitForExplicitFinish(); 19 20 function RunTest() { 21 const kIsLinux = navigator.platform.indexOf("Linux") == 0; 22 const kIsMac = navigator.platform.indexOf("Mac") == 0; 23 const kIsWin = navigator.platform.indexOf("Win") == 0; 24 25 var rng = document.createRange(); 26 var elem, fonts, f; 27 28 elem = document.getElementById("test1"); 29 rng.selectNode(elem); 30 fonts = InspectorUtils.getUsedFontFaces(rng); 31 is(fonts.length, 1, "number of fonts for simple Latin text"); 32 f = fonts[0]; 33 is(f.rule, null, "rule"); 34 is(f.srcIndex, -1, "srcIndex"); 35 is(f.localName, "", "local name"); 36 is(f.URI, "", "URI"); 37 is(f.format, "", "format string"); 38 is(f.metadata, "", "metadata"); 39 // report(elem.id, fonts); 40 41 elem = document.getElementById("test2"); 42 rng.selectNode(elem); 43 fonts = InspectorUtils.getUsedFontFaces(rng); 44 is(fonts.length, 3, "number of fonts for mixed serif, sans and monospaced text"); 45 // report(elem.id, fonts); 46 47 elem = document.getElementById("test3"); 48 rng.selectNode(elem); 49 fonts = InspectorUtils.getUsedFontFaces(rng); 50 is(fonts.length, 2, "number of fonts for mixed Latin & Chinese"); 51 // report(elem.id, fonts); 52 53 // get properties of a @font-face font 54 elem = document.getElementById("test4"); 55 rng.selectNode(elem); 56 fonts = InspectorUtils.getUsedFontFaces(rng); 57 is(fonts.length, 1, "number of fonts in @font-face test"); 58 f = fonts[0]; 59 isnot(f.rule, null, "missing rule"); 60 is(f.srcIndex, 1, "srcIndex"); 61 is(f.localName, "", "local name"); 62 is(f.URI, "chrome://mochitests/content/chrome/layout/inspector/tests/chrome/GentiumPlus-R.woff", "bad URI"); 63 is(f.format, "woff", "format"); 64 is(/bukva:raz/.test(f.metadata), true, "metadata"); 65 // report(elem.id, fonts); 66 67 elem = document.getElementById("test5").childNodes[0]; 68 // check that string length is as expected, including soft hyphens 69 is(elem.length, 42, "string length with soft hyphens"); 70 71 // initial latin substring... 72 rng.setStart(elem, 0); 73 rng.setEnd(elem, 20); // "supercalifragilistic" 74 fonts = InspectorUtils.getUsedFontFaces(rng); 75 is(fonts.length, 1, "number of fonts (Latin-only)"); 76 f = fonts[0]; 77 is(f.name, "Gentium Plus", "font name"); 78 is(f.CSSFamilyName, "font-face-test-family", "family name"); 79 is(f.fromFontGroup, true, "font matched in font group"); 80 81 // extend to include a chinese character 82 rng.setEnd(elem, 21); 83 fonts = InspectorUtils.getUsedFontFaces(rng); 84 is(fonts.length, 2, "number of fonts (incl Chinese)"); 85 if (kIsMac || kIsWin) { // these are only implemented by the Mac & Win font backends 86 var i; 87 for (i = 0; i < fonts.length; ++i) { 88 f = fonts[i]; 89 if (f.rule) { 90 is(f.fromFontGroup, true, "@font-face font matched in group"); 91 is(f.fromLanguagePrefs, false, "not from language prefs"); 92 is(f.fromSystemFallback, false, "not from system fallback"); 93 } else { 94 is(f.fromFontGroup, false, "not matched in group"); 95 is(f.fromLanguagePrefs, true, "from language prefs"); 96 is(f.fromSystemFallback, false, "not from system fallback"); 97 } 98 } 99 } 100 101 // second half of the string includes ­ chars to check original/skipped mapping; 102 // select just the final character 103 rng.setStart(elem, elem.length - 1); 104 rng.setEnd(elem, elem.length); 105 is(rng.toString(), "!", "content of range"); 106 fonts = InspectorUtils.getUsedFontFaces(rng); 107 is(fonts.length, 1, "number of fonts for last char"); 108 f = fonts[0]; 109 is(f.name, "Gentium Plus", "font name"); 110 111 // include the preceding character as well 112 rng.setStart(elem, elem.length - 2); 113 fonts = InspectorUtils.getUsedFontFaces(rng); 114 is(fonts.length, 2, "number of fonts for last two chars"); 115 116 // then trim the final one 117 rng.setEnd(elem, elem.length - 1); 118 fonts = InspectorUtils.getUsedFontFaces(rng); 119 is(fonts.length, 1, "number of fonts for Chinese char"); 120 f = fonts[0]; 121 isnot(f.name, "Gentium Plus", "font name for Chinese char"); 122 123 rng.selectNode(elem); 124 fonts = InspectorUtils.getUsedFontFaces(rng); 125 // report("test5", fonts); 126 127 elem = document.getElementById("test6"); 128 rng.selectNode(elem); 129 fonts = InspectorUtils.getUsedFontFaces(rng); 130 is(fonts.length, 2, "number of font faces for regular & italic"); 131 is(fonts[0].CSSFamilyName, fonts[1].CSSFamilyName, "same family for regular & italic"); 132 isnot(fonts[0].name, fonts[1].name, "different faces for regular & italic"); 133 // report(elem.id, fonts); 134 135 SimpleTest.finish(); 136 } 137 138 // just for test-debugging purposes 139 function report(e, f) { 140 var fontNames = ""; 141 var i; 142 for (i = 0; i < f.length; ++i) { 143 if (i == 0) { 144 fontNames += e + " fonts: " 145 } else { 146 fontNames += ", "; 147 } 148 fontNames += f.item(i).name; 149 } 150 dump(fontNames + "\n"); 151 } 152 153 ]]> 154 </script> 155 156 <!-- html:body contains elements the test will inspect --> 157 <body xmlns="http://www.w3.org/1999/xhtml"> 158 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=467669" 159 target="_blank">Mozilla Bug 467669</a> 160 <div id="test1">Hello world</div> 161 <div id="test2" style="font-family:sans-serif"><span style="font-family:serif">Hello</span> <tt>cruel</tt> world</div> 162 <div id="test3">Hello, 你好</div> 163 <div id="test4" class="gentium">Hello Gentium Plus!</div> 164 <div id="test5" class="gentium">supercalifragilistic你ex­pi­a­li­do­cious好!</div> 165 <div id="test6" style="font-family:serif">regular and <em>italic</em> text</div> 166 </body> 167 168 </window>