tor-browser

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

browser_pbrowser_creation_failure.js (2019B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 add_task(async function test_subframe_pbrowser_creation_failure() {
      7  await BrowserTestUtils.withNewTab(
      8    "https://example.com/document-builder.sjs?html=<iframe></iframe>",
      9    async browser => {
     10      let bcid = await SpecialPowers.spawn(browser, [], () => {
     11        return content.document.body.querySelector("iframe").browsingContext.id;
     12      });
     13 
     14      // We currently have no known way to trigger PBrowser creation failure,
     15      // other than to use this custom pref for the purpose.
     16      info(`enabling failPBrowserCreation for browsingContext: ${bcid}`);
     17      await SpecialPowers.pushPrefEnv({
     18        set: [
     19          ["browser.tabs.remote.testOnly.failPBrowserCreation.enabled", true],
     20          [
     21            "browser.tabs.remote.testOnly.failPBrowserCreation.browsingContext",
     22            `${bcid}`,
     23          ],
     24        ],
     25      });
     26 
     27      let eventFiredPromise = BrowserTestUtils.waitForEvent(
     28        browser,
     29        "oop-browser-crashed"
     30      );
     31 
     32      info("triggering navigation which will fail pbrowser creation");
     33      await SpecialPowers.spawn(browser, [], () => {
     34        content.document.body.querySelector("iframe").src =
     35          "https://example.org/document-builder.sjs?html=frame";
     36      });
     37 
     38      info("Waiting for oop-browser-crashed event.");
     39      let event = await eventFiredPromise;
     40      ok(!event.isTopFrame, "should be reporting subframe crash");
     41      Assert.equal(
     42        event.childID,
     43        0,
     44        "childID should be zero, as no process actually crashed"
     45      );
     46      is(event.browsingContextId, bcid, "bcid should match");
     47 
     48      let { subject: windowGlobal } = await BrowserUtils.promiseObserved(
     49        "window-global-created",
     50        wgp => wgp.documentURI.spec.startsWith("about:framecrashed")
     51      );
     52      is(windowGlobal.browsingContext.id, bcid, "bcid is correct");
     53 
     54      await SpecialPowers.popPrefEnv();
     55    }
     56  );
     57 });