layout/inspector/tests/chrome/test_bug467669.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/inspector/tests/chrome/test_bug467669.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,174 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
     1.6 +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
     1.7 +<?xml-stylesheet type="text/css" href="test_bug467669.css"?>
     1.8 +<!--
     1.9 +https://bugzilla.mozilla.org/show_bug.cgi?id=467669
    1.10 +-->
    1.11 +<window title="Mozilla Bug 467669"
    1.12 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    1.13 +        onload="RunTest();">
    1.14 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.15 +
    1.16 +  <!-- test code goes here -->
    1.17 +  <script type="application/javascript">
    1.18 +  <![CDATA[
    1.19 +  /** Test for Bug 467669 **/
    1.20 +
    1.21 +SimpleTest.waitForExplicitFinish();
    1.22 +
    1.23 +function RunTest() {
    1.24 +  const CI = Components.interfaces;
    1.25 +  const CC = Components.classes;
    1.26 +
    1.27 +  const kIsLinux = navigator.platform.indexOf("Linux") == 0;
    1.28 +  const kIsMac = navigator.platform.indexOf("Mac") == 0;
    1.29 +  const kIsWin = navigator.platform.indexOf("Win") == 0;
    1.30 +
    1.31 +  var domUtils =
    1.32 +    CC["@mozilla.org/inspector/dom-utils;1"].getService(CI.inIDOMUtils);
    1.33 +
    1.34 +  var rng = document.createRange();
    1.35 +  var elem, fonts, f;
    1.36 +
    1.37 +  elem = document.getElementById("test1");
    1.38 +  rng.selectNode(elem);
    1.39 +  fonts = domUtils.getUsedFontFaces(rng);
    1.40 +  is(fonts.length, 1, "number of fonts for simple Latin text");
    1.41 +  f = fonts.item(0);
    1.42 +  is(f.rule, null, "rule");
    1.43 +  is(f.srcIndex, -1, "srcIndex");
    1.44 +  is(f.localName, "", "local name");
    1.45 +  is(f.URI, "", "URI");
    1.46 +  is(f.format, "", "format string");
    1.47 +  is(f.metadata, "", "metadata");
    1.48 +//  report(elem.id, fonts);
    1.49 +
    1.50 +  elem = document.getElementById("test2");
    1.51 +  rng.selectNode(elem);
    1.52 +  fonts = domUtils.getUsedFontFaces(rng);
    1.53 +  is(fonts.length, 3, "number of fonts for mixed serif, sans and monospaced text");
    1.54 +//  report(elem.id, fonts);
    1.55 +
    1.56 +  elem = document.getElementById("test3");
    1.57 +  rng.selectNode(elem);
    1.58 +  fonts = domUtils.getUsedFontFaces(rng);
    1.59 +  is(fonts.length, 2, "number of fonts for mixed Latin & Chinese");
    1.60 +//  report(elem.id, fonts);
    1.61 +
    1.62 +  // get properties of a @font-face font
    1.63 +  elem = document.getElementById("test4");
    1.64 +  rng.selectNode(elem);
    1.65 +  fonts = domUtils.getUsedFontFaces(rng);
    1.66 +  is(fonts.length, 1, "number of fonts in @font-face test");
    1.67 +  f = fonts.item(0);
    1.68 +  isnot(f.rule, null, "missing rule");
    1.69 +  is(f.srcIndex, 1, "srcIndex");
    1.70 +  is(f.localName, "", "local name");
    1.71 +  is(f.URI, "chrome://mochitests/content/chrome/layout/inspector/tests/chrome/GentiumPlus-R.woff", "bad URI");
    1.72 +  is(f.format, "woff", "format");
    1.73 +  is(/bukva:raz/.test(f.metadata), true, "metadata");
    1.74 +//  report(elem.id, fonts);
    1.75 +
    1.76 +  elem = document.getElementById("test5").childNodes[0];
    1.77 +  // check that string length is as expected, including soft hyphens
    1.78 +  is(elem.length, 42, "string length with soft hyphens");
    1.79 +
    1.80 +  // initial latin substring...
    1.81 +  rng.setStart(elem, 0);
    1.82 +  rng.setEnd(elem, 20); // "supercalifragilistic"
    1.83 +  fonts = domUtils.getUsedFontFaces(rng);
    1.84 +  is(fonts.length, 1, "number of fonts (Latin-only)");
    1.85 +  f = fonts.item(0);
    1.86 +  is(f.name, "Gentium Plus", "font name");
    1.87 +  is(f.CSSFamilyName, "font-face-test-family", "family name");
    1.88 +  is(f.fromFontGroup, true, "font matched in font group");
    1.89 +
    1.90 +  // extend to include a chinese character
    1.91 +  rng.setEnd(elem, 21);
    1.92 +  fonts = domUtils.getUsedFontFaces(rng);
    1.93 +  is(fonts.length, 2, "number of fonts (incl Chinese)");
    1.94 +  if (kIsMac || kIsWin) { // these are only implemented by the Mac & Win font backends
    1.95 +    var i;
    1.96 +    for (i = 0; i < fonts.length; ++i) {
    1.97 +      f = fonts.item(i);
    1.98 +      if (f.rule) {
    1.99 +        is(f.fromFontGroup, true, "@font-face font matched in group");
   1.100 +        is(f.fromLanguagePrefs, false, "not from language prefs");
   1.101 +        is(f.fromSystemFallback, false, "not from system fallback");
   1.102 +      } else {
   1.103 +        is(f.fromFontGroup, false, "not matched in group");
   1.104 +        is(f.fromLanguagePrefs, true, "from language prefs");
   1.105 +        is(f.fromSystemFallback, false, "not from system fallback");
   1.106 +      }
   1.107 +    }
   1.108 +  }
   1.109 +
   1.110 +  // second half of the string includes &shy; chars to check original/skipped mapping;
   1.111 +  // select just the final character
   1.112 +  rng.setStart(elem, elem.length - 1);
   1.113 +  rng.setEnd(elem, elem.length);
   1.114 +  is(rng.toString(), "!", "content of range");
   1.115 +  fonts = domUtils.getUsedFontFaces(rng);
   1.116 +  is(fonts.length, 1, "number of fonts for last char");
   1.117 +  f = fonts.item(0);
   1.118 +  is(f.name, "Gentium Plus", "font name");
   1.119 +
   1.120 +  // include the preceding character as well
   1.121 +  rng.setStart(elem, elem.length - 2);
   1.122 +  fonts = domUtils.getUsedFontFaces(rng);
   1.123 +  is(fonts.length, 2, "number of fonts for last two chars");
   1.124 +
   1.125 +  // then trim the final one
   1.126 +  rng.setEnd(elem, elem.length - 1);
   1.127 +  fonts = domUtils.getUsedFontFaces(rng);
   1.128 +  is(fonts.length, 1, "number of fonts for Chinese char");
   1.129 +  f = fonts.item(0);
   1.130 +  isnot(f.name, "Gentium Plus", "font name for Chinese char");
   1.131 +
   1.132 +  rng.selectNode(elem);
   1.133 +  fonts = domUtils.getUsedFontFaces(rng);
   1.134 +//  report("test5", fonts);
   1.135 +
   1.136 +  elem = document.getElementById("test6");
   1.137 +  rng.selectNode(elem);
   1.138 +  fonts = domUtils.getUsedFontFaces(rng);
   1.139 +  is(fonts.length, 2, "number of font faces for regular & italic");
   1.140 +  is(fonts.item(0).CSSFamilyName, fonts.item(1).CSSFamilyName, "same family for regular & italic");
   1.141 +  isnot(fonts.item(0).name, fonts.item(1).name, "different faces for regular & italic");
   1.142 +//  report(elem.id, fonts);
   1.143 +
   1.144 +  SimpleTest.finish();
   1.145 +}
   1.146 +
   1.147 +// just for test-debugging purposes
   1.148 +function report(e, f) {
   1.149 +  var fontNames = "";
   1.150 +  var i;
   1.151 +  for (i = 0; i < f.length; ++i) {
   1.152 +    if (i == 0) {
   1.153 +      fontNames += e + " fonts: "
   1.154 +    } else {
   1.155 +      fontNames += ", ";
   1.156 +    }
   1.157 +    fontNames += f.item(i).name;
   1.158 +  }
   1.159 +  dump(fontNames + "\n");
   1.160 +}
   1.161 +
   1.162 +  ]]>
   1.163 +  </script>
   1.164 +
   1.165 +  <!-- html:body contains elements the test will inspect -->
   1.166 +  <body xmlns="http://www.w3.org/1999/xhtml">
   1.167 +  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=467669"
   1.168 +     target="_blank">Mozilla Bug 467669</a>
   1.169 +  <div id="test1">Hello world</div>
   1.170 +  <div id="test2" style="font-family:sans-serif"><span style="font-family:serif">Hello</span> <tt>cruel</tt> world</div>
   1.171 +  <div id="test3">Hello, &#x4F60;&#x597D;</div>
   1.172 +  <div id="test4" class="gentium">Hello Gentium Plus!</div>
   1.173 +  <div id="test5" class="gentium">supercalifragilistic&#x4F60;ex&#xAD;pi&#xAD;a&#xAD;li&#xAD;do&#xAD;cious&#x597D;!</div>
   1.174 +  <div id="test6" style="font-family:serif">regular and <em>italic</em> text</div>
   1.175 +  </body>
   1.176 +
   1.177 +</window>

mercurial