tor-browser

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

test_bug1339722.html (2961B)


      1 <!DOCTYPE html>
      2 <html>
      3  <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1339722
      5 -->
      6  <head>
      7    <meta charset="utf-8" />
      8    <title>Test for Bug 1339722</title>
      9    <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     10    <link rel="stylesheet" type="text/css" href="chrome://global/skin" />
     11    <link
     12      rel="stylesheet"
     13      type="text/css"
     14      href="chrome://mochikit/content/tests/SimpleTest/test.css"
     15    />
     16    <script type="application/javascript">
     17      /**
     18       * Test for Bug 1339722
     19       * 1. Wait for "http-on-modify-request" or document-on-modify-request for the
     20       *    iframe load.
     21       * 2. In the observer, access it's window proxy to trigger DOMWindowCreated.
     22       * 3. In the event handler, delete the iframe so that the frameloader would be
     23       *    destroyed in the middle of ReallyStartLoading.
     24       * 4. Verify that it doesn't crash.
     25       */
     26 
     27      // This topic used to be http-on-useragent-request, but that got removed in
     28      // bug 1513574. on-modify-request is called around the same time, and should
     29      // behave similarly.
     30      const TOPIC = "document-on-modify-request";
     31      let win;
     32      const observe = (subject, topic) => {
     33        info("Got " + topic);
     34        Services.obs.removeObserver(observe, TOPIC);
     35 
     36        // Query window proxy so it triggers DOMWindowCreated.
     37        let channel;
     38        try {
     39          // We need to QI nsIHttpChannel in order to load the interface's
     40          // methods / attributes for later code that could assume we are dealing
     41          // with a nsIHttpChannel.
     42          channel = subject.QueryInterface(Ci.nsIHttpChannel);
     43        } catch (e) {
     44          channel = subject.QueryInterface(Ci.nsIIdentChannel);
     45        }
     46        win = channel.notificationCallbacks.getInterface(Ci.mozIDOMWindowProxy);
     47      };
     48 
     49      Services.obs.addObserver(observe, TOPIC);
     50 
     51      let docShell = SpecialPowers.wrap(window).docShell;
     52      docShell.chromeEventHandler.addEventListener(
     53        "DOMWindowCreated",
     54        function handler(e) {
     55          info("Got DOMWindowCreated");
     56          let iframe = document.getElementById("testFrame");
     57          is(e.target, iframe.contentDocument, "verify event target");
     58 
     59          // Remove the iframe to cause frameloader destroy.
     60          iframe.remove();
     61          setTimeout(() => {
     62            ok(!document.getElementById("testFrame"), "verify iframe removed");
     63            SimpleTest.finish();
     64          }, 0);
     65        },
     66        { once: true }
     67      );
     68 
     69      SimpleTest.waitForExplicitFinish();
     70    </script>
     71  </head>
     72  <body>
     73    <a
     74      target="_blank"
     75      href="https://bugzilla.mozilla.org/show_bug.cgi?id=1339722"
     76      >Mozilla Bug 1339722</a
     77    >
     78    <p id="display"></p>
     79    <div id="content" style="display: none;"></div>
     80    <pre id="test">
     81  <div id="frameContainer">
     82    <iframe id="testFrame" src="http://www.example.com"></iframe>
     83  </div>
     84 </pre>
     85  </body>
     86 </html>