tor-browser

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

browser_jsonview_favicon.js (1247B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Check that, if browser.chrome.guess_favicon is enabled, the favicon.ico will
      7 // be loaded for the JSON viewer. The favicon could be prevented from loading
      8 // by a too strict CSP (Bug 1872504).
      9 
     10 const { HttpServer } = ChromeUtils.importESModule(
     11  "resource://testing-common/httpd.sys.mjs"
     12 );
     13 
     14 add_task(async function test_favicon() {
     15  await SpecialPowers.pushPrefEnv({
     16    set: [["browser.chrome.guess_favicon", true]],
     17  });
     18 
     19  const httpServer = new HttpServer();
     20 
     21  httpServer.registerPathHandler("/", (_, response) => {
     22    response.setHeader("Content-Type", "application/json");
     23    response.write("{}");
     24  });
     25 
     26  const faviconPromise = new Promise(resolve => {
     27    httpServer.registerPathHandler("/favicon.ico", () => {
     28      resolve();
     29    });
     30  });
     31 
     32  httpServer.start(-1);
     33 
     34  const tab = await BrowserTestUtils.openNewForegroundTab({
     35    gBrowser,
     36    url: `http://localhost:${httpServer.identity.primaryPort}/`,
     37  });
     38 
     39  info("Waiting for favicon request to be received by server");
     40  await faviconPromise;
     41  ok("Server got request for favicon");
     42 
     43  BrowserTestUtils.removeTab(tab);
     44 
     45  httpServer.stop();
     46 });