tor-browser

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

browser_bug1869938.js (2363B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 /*
      6 * This test opens a private browsing window, then opens a content page in it
      7 * that sets a favicon that is a data uri containing a svg file, which
      8 * contains an image element that refers to a data uri containing a png image.
      9 * This tests that we don't hit an assert when loading the png in the favicon
     10 * in the parent process with this setup.
     11 */
     12 
     13 function waitForLinkAvailable(browser, win) {
     14  let resolve, reject;
     15 
     16  let listener = {
     17    onLinkIconAvailable(b, dataURI, iconURI) {
     18      // Ignore icons for other browsers or empty icons.
     19      if (browser !== b || !iconURI) {
     20        return;
     21      }
     22 
     23      win.gBrowser.removeTabsProgressListener(listener);
     24      resolve(iconURI);
     25    },
     26  };
     27 
     28  let promise = new Promise((res, rej) => {
     29    resolve = res;
     30    reject = rej;
     31 
     32    win.gBrowser.addTabsProgressListener(listener);
     33  });
     34 
     35  promise.cancel = () => {
     36    win.gBrowser.removeTabsProgressListener(listener);
     37 
     38    reject();
     39  };
     40 
     41  return promise;
     42 }
     43 
     44 add_task(async function test() {
     45  function httpURL(filename) {
     46    let chromeURL = getRootDirectory(gTestPath) + filename;
     47    return chromeURL.replace(
     48      "chrome://mochitests/content/",
     49      "http://mochi.test:8888/"
     50    );
     51  }
     52 
     53  let win = await BrowserTestUtils.openNewBrowserWindow({ private: true });
     54 
     55  const pageUrl = httpURL("helper1869938.html");
     56 
     57  let tab = (win.gBrowser.selectedTab = BrowserTestUtils.addTab(
     58    win.gBrowser,
     59    "about:blank"
     60  ));
     61 
     62  await BrowserTestUtils.browserLoaded(tab.linkedBrowser, {
     63    wantLoad: "about:blank",
     64  });
     65 
     66  let faviconPromise = waitForLinkAvailable(tab.linkedBrowser, win);
     67 
     68  BrowserTestUtils.startLoadingURIString(tab.linkedBrowser, pageUrl);
     69 
     70  await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
     71 
     72  await new Promise(resolve => {
     73    waitForFocus(resolve, win);
     74  });
     75 
     76  await faviconPromise;
     77 
     78  // do a couple rafs here to ensure its loaded and displayed
     79  await new Promise(r => requestAnimationFrame(r));
     80  await new Promise(r => requestAnimationFrame(r));
     81 
     82  await BrowserTestUtils.closeWindow(win);
     83 
     84  win = null;
     85  tab = null;
     86  faviconPromise = null;
     87 
     88  ok(true, "we got here and didn't crash/assert");
     89 });