/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

// Check that the font inspector has a section for "other fonts" and that section contains
// the fonts *not* used in the currently selected element.
// Check that it's collapsed by default, but can be expanded. That it does not contain
// the fonts listed in the previous section.

const TEST_URI = URL_ROOT + "browser_fontinspector.html";

add_task(function* () {
  const { inspector, view } = yield openFontInspectorForURL(TEST_URI);
  const viewDoc = view.document;

  let otherFontsAccordion = viewDoc.querySelector("#font-container .accordion");
  ok(otherFontsAccordion, "There's an accordion in the panel");
  is(otherFontsAccordion.textContent, "Other fonts in page", "It has the right title");

  yield expandOtherFontsAccordion(viewDoc);
  let otherFontsEls = getOtherFontsEls(viewDoc);

  is(otherFontsEls.length, 1, "There is one font listed in the other fonts section");
  // On Linux Times New Roman does not exist, Liberation Serif is used instead
  let name = getName(otherFontsEls[0]);
  ok(name === "Times New Roman" || name === "Liberation Serif",
     "The other font listed is the right one");

  info("Checking that fonts of the current element aren't listed");
  yield selectNode(".bold-text", inspector);
  yield expandOtherFontsAccordion(viewDoc);
  otherFontsEls = getOtherFontsEls(viewDoc);

  for (let otherFontEl of otherFontsEls) {
    ok(![...getUsedFontsEls(viewDoc)].some(el => getName(el) === getName(otherFontEl)),
       "Other font isn't listed in the main fonts section");
  }
});
