layout/inspector/tests/chrome/test_bug467669.xul

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial