tor-browser

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

browser_inspector_remove-iframe-during-load.js (2986B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Testing that the inspector doesn't go blank when navigating to a page that
      6 // deletes an iframe while loading.
      7 
      8 const TEST_URL = URL_ROOT + "doc_inspector_remove-iframe-during-load.html";
      9 
     10 add_task(async function () {
     11  const { inspector, tab } = await openInspectorForURL("about:blank");
     12  await selectNode("body", inspector);
     13 
     14  // Before we start navigating, attach a listener on the reloaded event.
     15  const onInspectorReloaded = inspector.once("reloaded");
     16 
     17  // Note: here we don't want to use the `navigateTo` helper from shared-head.js
     18  // because we want to modify the page as early as possible after the
     19  // navigation, ideally before the inspector has fully initialized.
     20  // See next comments.
     21  const browser = tab.linkedBrowser;
     22  const onBrowserLoaded = BrowserTestUtils.browserLoaded(browser);
     23  BrowserTestUtils.startLoadingURIString(browser, TEST_URL);
     24  await onBrowserLoaded;
     25 
     26  // We do not want to wait for the inspector to be fully ready before testing
     27  // so we load TEST_URL and just wait for the content window to be done loading
     28  await SpecialPowers.spawn(browser, [], async function () {
     29    await content.wrappedJSObject.readyPromise;
     30  });
     31 
     32  // The content doc contains a script that creates iframes and deletes them
     33  // immediately after. It does this before the load event, after
     34  // DOMContentLoaded and after load. This is what used to make the inspector go
     35  // blank when navigating to that page.
     36  // At this stage, there should be no iframes in the page anymore.
     37  ok(
     38    !(await contentPageHasNode(browser, "iframe")),
     39    "Iframes added by the content page should have been removed"
     40  );
     41 
     42  // Create/remove an extra one now, after the load event.
     43  info("Creating and removing an iframe.");
     44  await SpecialPowers.spawn(browser, [], async function () {
     45    const iframe = content.document.createElement("iframe");
     46    content.document.body.appendChild(iframe);
     47    iframe.remove();
     48  });
     49 
     50  ok(
     51    !(await contentPageHasNode(browser, "iframe")),
     52    "The after-load iframe should have been removed."
     53  );
     54 
     55  // Assert that the markup-view is displayed and works
     56  ok(!(await contentPageHasNode(browser, "iframe")), "Iframe has been removed");
     57 
     58  const expectedText = await SpecialPowers.spawn(
     59    browser,
     60    [],
     61    async function () {
     62      return content.document.querySelector("#yay").textContent;
     63    }
     64  );
     65  is(expectedText, "load", "Load event fired.");
     66 
     67  info("Wait for the inspector to be properly reloaded");
     68  await onInspectorReloaded;
     69 
     70  // Smoke test to check that the inspector can still select nodes and hasn't
     71  // gone blank.
     72  await selectNode("#yay", inspector);
     73 });
     74 
     75 function contentPageHasNode(browser, selector) {
     76  return SpecialPowers.spawn(
     77    browser,
     78    [selector],
     79    async function (selectorChild) {
     80      return !!content.document.querySelector(selectorChild);
     81    }
     82  );
     83 }