tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_fontinspector.js (2487B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 requestLongerTimeout(2);
      6 
      7 const TEST_URI = URL_ROOT + "doc_browser_fontinspector.html";
      8 
      9 add_task(async function () {
     10  const { inspector, view } = await openFontInspectorForURL(TEST_URI);
     11  ok(!!view, "Font inspector document is alive.");
     12 
     13  const viewDoc = view.document;
     14 
     15  await testBodyFonts(inspector, viewDoc);
     16  await testDivFonts(inspector, viewDoc);
     17 });
     18 
     19 async function testBodyFonts(inspector, viewDoc) {
     20  const FONTS = [
     21    {
     22      familyName: "DevToolsMono",
     23      name: ["DevToolsMono Regular"],
     24    },
     25    {
     26      familyName: "bar",
     27      name: ["Ostrich Sans Medium", "Ostrich Sans Black"],
     28    },
     29    {
     30      familyName: "barnormal",
     31      name: "Ostrich Sans Medium",
     32    },
     33    {
     34      // On Linux, Arial does not exist. Liberation Sans is used instead.
     35      familyName: ["Arial", "Liberation Sans"],
     36      name: ["Arial", "Liberation Sans"],
     37    },
     38  ];
     39 
     40  await selectNode("body", inspector);
     41 
     42  const groups = getUsedFontGroupsEls(viewDoc);
     43  is(groups.length, 4, "Found 4 font families used on BODY");
     44 
     45  for (let i = 0; i < FONTS.length; i++) {
     46    const groupEL = groups[i];
     47    const font = FONTS[i];
     48 
     49    const familyName = getFamilyName(groupEL);
     50    ok(
     51      font.familyName.includes(familyName),
     52      `Font families used on BODY include: ${familyName}`
     53    );
     54 
     55    const fontName = getName(groupEL);
     56    ok(font.name.includes(fontName), `Fonts used on BODY include: ${fontName}`);
     57  }
     58 }
     59 
     60 async function testDivFonts(inspector, viewDoc) {
     61  const FONTS = [
     62    {
     63      selector: "div",
     64      familyName: "bar",
     65      name: "Ostrich Sans Medium",
     66    },
     67    {
     68      selector: ".normal-text",
     69      familyName: "barnormal",
     70      name: "Ostrich Sans Medium",
     71    },
     72    {
     73      selector: ".bold-text",
     74      familyName: "bar",
     75      name: "Ostrich Sans Black",
     76    },
     77    {
     78      selector: ".black-text",
     79      familyName: "bar",
     80      name: "Ostrich Sans Black",
     81    },
     82  ];
     83 
     84  for (let i = 0; i < FONTS.length; i++) {
     85    await selectNode(FONTS[i].selector, inspector);
     86    const groups = getUsedFontGroupsEls(viewDoc);
     87    const groupEl = groups[0];
     88    const font = FONTS[i];
     89 
     90    is(groups.length, 1, `Found 1 font on ${FONTS[i].selector}`);
     91    is(getName(groupEl), font.name, "The DIV font has the right name");
     92    is(
     93      getFamilyName(groupEl),
     94      font.familyName,
     95      `font has the right family name`
     96    );
     97  }
     98 }