Repository: mozilla/pdf.js
File: test/integration/accessibility_spec.mjs (JavaScript)

Code before:
    });
  });

  describe("MathML in AF entry from LaTeX", () => {
    let pages;

    beforeEach(async () => {
      pages = await loadAndWait("bug1937438_af_from_latex.pdf", ".textLayer");
    });

    afterEach(async () => {
      await closePages(pages);
    });

    it("must check that the MathML is correctly inserted", async () => {
      await Promise.all(
        pages.map(async ([browserName, page]) => {
          const isSanitizerSupported = await page.evaluate(() =>
            (() => {
              try {
                // eslint-disable-next-line no-undef
                return typeof Sanitizer !== "undefined";
              } catch {
                return false;
              }
            })()
          );
          if (isSanitizerSupported) {
            const mathML = await page.$eval(
              "span.structTree span[aria-owns='p58R_mc13'] > math",
              el => el?.innerHTML ?? ""
            );
            expect(mathML)
              .withContext(`In ${browserName}`)
              .toEqual(
                " <msqrt><msup><mi>x</mi><mn>2</mn></msup></msqrt> <mo>=</mo> <mrow><mo>|</mo><mi>x</mi><mo>|</mo></mrow> "
              );
          }
        })
      );
    });
  });

  describe("MathML tags in the struct tree", () => {
    let pages;

    beforeEach(async () => {
      pages = await loadAndWait("bug1937438_mml_from_latex.pdf", ".textLayer");
    });

    afterEach(async () => {

Review comment (bug):

Does this test actually run at the moment, seeing that the browser compatibility matrix at https://developer.mozilla.org/en-US/docs/Web/API/Sanitizer#browser_compatibility doesn't look particularly great yet for this feature? If we do want to use this, we might need to explicitly set `dom.security.sanitizer.enabled⁩⁨`  to `true` when starting Puppeteer for Firefox so that this API can at least be used in Firefox in the tests.


Edit: I just noticed that https://bugzilla.mozilla.org/show_bug.cgi?id=1954437 landed today to enable the `Sanitizer` API by default in Nightly, so we need to make sure to have that on the bots first but after we ensured that we should be good here without changes to Firefox preferences in Puppeteer.

Code after:
    });
  });

  describe("MathML in AF entry from LaTeX", () => {
    let pages;

    beforeEach(async () => {
      pages = await loadAndWait("bug1937438_af_from_latex.pdf", ".textLayer");
    });

    afterEach(async () => {
      await closePages(pages);
    });

    it("must check that the MathML is correctly inserted", async () => {
      await Promise.all(
        pages.map(async ([browserName, page]) => {
          const isSanitizerSupported = await page.evaluate(() => {
            try {
              // eslint-disable-next-line no-undef
              return typeof Sanitizer !== "undefined";
            } catch {
              return false;
            }
          });
          if (isSanitizerSupported) {
            const mathML = await page.$eval(
              "span.structTree span[aria-owns='p58R_mc13'] > math",
              el => el?.innerHTML ?? ""
            );
            expect(mathML)
              .withContext(`In ${browserName}`)
              .toEqual(
                " <msqrt><msup><mi>x</mi><mn>2</mn></msup></msqrt> <mo>=</mo> <mrow><mo>|</mo><mi>x</mi><mo>|</mo></mrow> "
              );
          } else {
            pending(`Sanitizer API (in ${browserName}) is not supported`);
          }
        })
      );
    });
  });

  describe("MathML tags in the struct tree", () => {
    let pages;

    beforeEach(async () => {
      pages = await loadAndWait("bug1937438_mml_from_latex.pdf", ".textLayer");
    });

    afterEach(async () => {