tor-browser

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

browser_fontinspector_edit-previews.js (2349B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Test that previews change when the preview text changes. It doesn't check the
      6 // exact preview images because they are drawn on a canvas causing them to vary
      7 // between systems, platforms and software versions.
      8 
      9 const TEST_URI = URL_ROOT + "doc_browser_fontinspector.html";
     10 
     11 add_task(async function () {
     12  const { view, inspector } = await openFontInspectorForURL(TEST_URI);
     13  const viewDoc = view.document;
     14  await selectNode("div", inspector);
     15  await expandFontsAccordion(viewDoc);
     16 
     17  const previews = viewDoc.querySelectorAll("#font-container .font-preview");
     18  const initialPreviews = [...previews].map(p => p.src);
     19 
     20  info("Typing 'Abc' to check that the reference previews are correct.");
     21  await updatePreviewText(view, "Abc");
     22  checkPreviewImages(viewDoc, initialPreviews, true);
     23 
     24  info("Typing something else to the preview box.");
     25  await updatePreviewText(view, "The quick brown");
     26  checkPreviewImages(viewDoc, initialPreviews, false);
     27 
     28  info("Blanking the input to restore default previews.");
     29  await updatePreviewText(view, "");
     30  checkPreviewImages(viewDoc, initialPreviews, true);
     31 });
     32 
     33 /**
     34 * Compares the previous preview image URIs to the current URIs.
     35 *
     36 * @param {Document} viewDoc
     37 *        The FontInspector document.
     38 * @param {Array[String]} originalURIs
     39 *        An array of URIs to compare with the current URIs.
     40 * @param {boolean} assertIdentical
     41 *        If true, this method asserts that the previous and current URIs are
     42 *        identical. If false, this method asserts that the previous and current
     43 *        URI's are different.
     44 */
     45 function checkPreviewImages(viewDoc, originalURIs, assertIdentical) {
     46  const previews = viewDoc.querySelectorAll("#font-container .font-preview");
     47  const newURIs = [...previews].map(p => p.src);
     48 
     49  is(
     50    newURIs.length,
     51    originalURIs.length,
     52    "The number of previews has not changed."
     53  );
     54 
     55  for (let i = 0; i < newURIs.length; ++i) {
     56    if (assertIdentical) {
     57      is(
     58        newURIs[i],
     59        originalURIs[i],
     60        `The preview image at index ${i} has stayed the same.`
     61      );
     62    } else {
     63      isnot(
     64        newURIs[i],
     65        originalURIs[i],
     66        `The preview image at index ${i} has changed.`
     67      );
     68    }
     69  }
     70 }