tor-browser

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

browser_favicon_crossorigin.js (1829B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 const ROOT_DIR = getRootDirectory(gTestPath);
      5 
      6 const MOCHI_ROOT = ROOT_DIR.replace(
      7  "chrome://mochitests/content/",
      8  "http://mochi.test:8888/"
      9 );
     10 
     11 const EXAMPLE_NET_ROOT = ROOT_DIR.replace(
     12  "chrome://mochitests/content/",
     13  "http://example.net/"
     14 );
     15 
     16 const EXAMPLE_COM_ROOT = ROOT_DIR.replace(
     17  "chrome://mochitests/content/",
     18  "http://example.com/"
     19 );
     20 
     21 const FAVICON_URL = EXAMPLE_COM_ROOT + "crossorigin.png";
     22 
     23 function run_test(root, shouldSucceed, description) {
     24  add_task(async () => {
     25    await BrowserTestUtils.withNewTab(
     26      { gBrowser, url: "about:blank" },
     27      async browser => {
     28        const faviconPromise = waitForFaviconMessage(true, FAVICON_URL);
     29 
     30        BrowserTestUtils.startLoadingURIString(
     31          browser,
     32          `${root}crossorigin.html`
     33        );
     34        await BrowserTestUtils.browserLoaded(browser);
     35 
     36        if (shouldSucceed) {
     37          try {
     38            const result = await faviconPromise;
     39            Assert.equal(
     40              result.iconURL,
     41              FAVICON_URL,
     42              `Should have seen the icon (${description}).`
     43            );
     44          } catch (e) {
     45            Assert.ok(false, `Favicon load failed (${description}).`);
     46          }
     47        } else {
     48          await Assert.rejects(
     49            faviconPromise,
     50            result => result.iconURL == FAVICON_URL,
     51            `Should have failed to load the icon (${description}).`
     52          );
     53        }
     54      }
     55    );
     56  });
     57 }
     58 
     59 // crossorigin.png only allows CORS for MOCHI_ROOT.
     60 run_test(EXAMPLE_NET_ROOT, false, "remote origin not allowed");
     61 run_test(MOCHI_ROOT, true, "remote origin allowed");
     62 
     63 // Same-origin but with the crossorigin attribute.
     64 run_test(EXAMPLE_COM_ROOT, true, "same-origin");