layout/inspector/tests/chrome/test_bug467669.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial