summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/fonts/test/browser_fontinspector_edit-previews.js
blob: b29be4ca3f215a963b7ac2a6849792d23de6ac19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

// Test that previews change when the preview text changes. It doesn't check the
// exact preview images because they are drawn on a canvas causing them to vary
// between systems, platforms and software versions.

const TEST_URI = URL_ROOT + "doc_browser_fontinspector.html";

add_task(async function () {
  const { view, inspector } = await openFontInspectorForURL(TEST_URI);
  const viewDoc = view.document;
  await selectNode("div", inspector);
  await expandFontsAccordion(viewDoc);

  const previews = viewDoc.querySelectorAll("#font-container .font-preview");
  const initialPreviews = [...previews].map(p => p.src);

  info("Typing 'Abc' to check that the reference previews are correct.");
  await updatePreviewText(view, "Abc");
  checkPreviewImages(viewDoc, initialPreviews, true);

  info("Typing something else to the preview box.");
  await updatePreviewText(view, "The quick brown");
  checkPreviewImages(viewDoc, initialPreviews, false);

  info("Blanking the input to restore default previews.");
  await updatePreviewText(view, "");
  checkPreviewImages(viewDoc, initialPreviews, true);
});

/**
 * Compares the previous preview image URIs to the current URIs.
 *
 * @param {Document} viewDoc
 *        The FontInspector document.
 * @param {Array[String]} originalURIs
 *        An array of URIs to compare with the current URIs.
 * @param {Boolean} assertIdentical
 *        If true, this method asserts that the previous and current URIs are
 *        identical. If false, this method asserts that the previous and current
 *        URI's are different.
 */
function checkPreviewImages(viewDoc, originalURIs, assertIdentical) {
  const previews = viewDoc.querySelectorAll("#font-container .font-preview");
  const newURIs = [...previews].map(p => p.src);

  is(
    newURIs.length,
    originalURIs.length,
    "The number of previews has not changed."
  );

  for (let i = 0; i < newURIs.length; ++i) {
    if (assertIdentical) {
      is(
        newURIs[i],
        originalURIs[i],
        `The preview image at index ${i} has stayed the same.`
      );
    } else {
      isnot(
        newURIs[i],
        originalURIs[i],
        `The preview image at index ${i} has changed.`
      );
    }
  }
}