tor-browser

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

browser_loadURI_forceMediaDocument.js (1618B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 const TEST_PATH = getRootDirectory(gTestPath).replace(
      5  "chrome://mochitests/content",
      6  "https://example.com"
      7 );
      8 
      9 function doLoad(url, forceMediaDocument, contentFn) {
     10  return BrowserTestUtils.withNewTab({ gBrowser }, async function (browser) {
     11    browser.loadURI(Services.io.newURI(url), {
     12      triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
     13      forceMediaDocument,
     14    });
     15 
     16    await BrowserTestUtils.browserLoaded(browser, false, url);
     17 
     18    await SpecialPowers.spawn(browser, [], contentFn);
     19  });
     20 }
     21 
     22 add_task(async function test_img() {
     23  await doLoad(TEST_PATH + "file_image_header.sjs?imagePNG", "image", () => {
     24    // The image was successfully displayed inline, which means
     25    // we sent the right Accept header and ignored the Content-Disposition.
     26    let img = content.document.querySelector("img");
     27    is(img.width, 1, "PNG width");
     28    is(img.height, 1, "PNG height");
     29  });
     30 });
     31 
     32 add_task(async function test_img() {
     33  await doLoad(
     34    TEST_PATH + "file_image_header.sjs?imageSVG",
     35    "image",
     36    async () => {
     37      let img = content.document.querySelector("img");
     38 
     39      // Work around for intermittent failures.
     40      for (let i = 0; i < 10; i++) {
     41        if (img.width === 100) {
     42          break;
     43        }
     44 
     45        // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
     46        await new Promise(resolve => content.setTimeout(resolve, 100));
     47      }
     48 
     49      is(img.width, 100, "SVG width");
     50      is(img.height, 100, "SVG height");
     51    }
     52  );
     53 });