devtools/shared/heapsnapshot/tests/mochitest/test_saveHeapSnapshot_e10s_01.html
author Jim Chen <nchen@mozilla.com>
Tue, 09 Oct 2018 16:30:46 +0000
changeset 499061 70505741627fe29e79facb7fab0e3297320f0421
parent 477580 e8599930659ec05c16fe6e71f43b708c5ab3b2c2
child 499073 0bd0dc3c8183e67a37fd08617a5b456049bf444b
permissions -rw-r--r--
Bug 1496220 - 3. Disable Necko IPC security for test_saveHeapSnapshot_e10s_01; r=fitzgen The use of <iframe mozbrowser> in test_saveHeapSnapshot_e10s_01.html has implicitly depended on the "network.disable.ipc.security" pref set to false, which is the default for desktop and not applicable for Fennec. With the new mobile test harness, this pref needs to be set explicitly by the test. Differential Revision: https://phabricator.services.mozilla.com/D7786

<!DOCTYPE HTML>
<!--
Bug 1201597 - Sanity test that we can take a heap snapshot in an e10s child process.
-->
<html>
<head>
  <title>saveHeapSnapshot in e10s child processes</title>
  <script type="application/javascript"
          src="/tests/SimpleTest/SimpleTest.js">
  </script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
    <script type="application/javascript">
    "use strict";
    window.onerror = function(msg, url, line, col, err) {
      ok(false, "@" + url + ":" + line + ":" + col + ": " + msg + "\n" + err.stack);
    };

    SimpleTest.waitForExplicitFinish();

    var childFrameURL = "file_saveHeapSnapshot_e10s_01.html";

    // This function is stringified and loaded in the child process as a frame
    // script.
    function childFrameScript() {
      try {
        ChromeUtils.saveHeapSnapshot({ runtime: true });
      } catch (err) {
        sendAsyncMessage("testSaveHeapSnapshot:error",
                          { error: err.toString() });
        return;
      }

      sendAsyncMessage("testSaveHeapSnapshot:done", {});
    }

    // Kick everything off on load.
    window.onload = function() {
      info("window.onload fired");
      SpecialPowers.addPermission("browser", true, document);
      SpecialPowers.pushPrefEnv({
         "set": [
             ["dom.ipc.browser_frames.oop_by_default", true],
             ["dom.mozBrowserFramesEnabled", true],
             ["browser.pagethumbnails.capturing_disabled", true],
             ["network.disable.ipc.security", true],
         ]
      }, function() {
        const iframe = document.createElement("iframe");
        SpecialPowers.wrap(iframe).mozbrowser = true;
        iframe.id = "iframe";
        iframe.src = childFrameURL;

        iframe.addEventListener("mozbrowserloadend", function() {
          info("iframe done loading");

          const mm = SpecialPowers.getBrowserFrameMessageManager(iframe);

          function onError(e) {
            ok(false, e.data.error);
          }
          mm.addMessageListener("testSaveHeapSnapshot:error", onError);

          mm.addMessageListener("testSaveHeapSnapshot:done", function onMsg() {
            mm.removeMessageListener("testSaveHeapSnapshot:done", onMsg);
            mm.removeMessageListener("testSaveHeapSnapshot:error", onError);
            ok(true, "Saved heap snapshot in child process");
            SimpleTest.finish();
          });

          info("Loading frame script to save heap snapshot");
          mm.loadFrameScript("data:,(" + encodeURI(childFrameScript.toString()) + ")();",
                            false);
        }, {once: true});

        info("Loading iframe");
        document.body.appendChild(iframe);
      });
    };
  </script>
</window>