Bug 1605209 - Extending BrowserTestUtils to allow out-of-stack crashing;r=mconley
☠☠ backed out by 6daca7282599 ☠ ☠
authorDavid Teller <dteller@mozilla.com>
Thu, 16 Apr 2020 08:58:21 +0000
changeset 524585 d81b566ad94f0dc3dca206a8b3556b631ef7ec42
parent 524584 e0e6dbf1d48da58434c44c3a218a46635e95c6b9
child 524586 6eb1cc169dbf3f258bed8cb747ced0ebfb15188d
push id113269
push userdteller@mozilla.com
push dateFri, 17 Apr 2020 08:44:43 +0000
treeherderautoland@6eb1cc169dbf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1605209
milestone77.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1605209 - Extending BrowserTestUtils to allow out-of-stack crashing;r=mconley Differential Revision: https://phabricator.services.mozilla.com/D70191
testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
testing/mochitest/BrowserTestUtils/BrowserTestUtilsChild.jsm
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -1627,16 +1627,18 @@ var BrowserTestUtils = {
    *        True if the minidumps left behind by the crash should be removed.
    * @param (BrowsingContext) browsingContext
    *        The context where the frame leaves. Default to
    *        top level context if not supplied.
    * @param (object?) options
    *        An object with any of the following fields:
    *          crashType: "CRASH_INVALID_POINTER_DEREF" | "CRASH_OOM"
    *            The type of crash. If unspecified, default to "CRASH_INVALID_POINTER_DEREF"
+   *          asyncCrash: bool
+   *            If specified and `true`, cause the crash asynchronously.
    *
    * @returns (Promise)
    * @resolves An Object with key-value pairs representing the data from the
    *           crash report's extra file (if applicable).
    */
   async crashFrame(
     browser,
     shouldShowTabCrashPage = true,
@@ -1774,16 +1776,17 @@ var BrowserTestUtils = {
     }
 
     // Trigger crash by sending a message to BrowserTestUtils actor.
     this.sendAsyncMessage(
       browsingContext || browser.browsingContext,
       "BrowserTestUtils:CrashFrame",
       {
         crashType: options.crashType || "",
+        asyncCrash: options.asyncCrash || false,
       }
     );
 
     await Promise.all(expectedPromises);
 
     if (shouldShowTabCrashPage) {
       let gBrowser = browser.ownerGlobal.gBrowser;
       let tab = gBrowser.getTabForBrowser(browser);
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtilsChild.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtilsChild.jsm
@@ -214,16 +214,17 @@ class BrowserTestUtilsChild extends JSWi
         // should happen immediately
         // upon loading this frame script.
 
         const { ctypes } = ChromeUtils.import(
           "resource://gre/modules/ctypes.jsm"
         );
 
         let dies = function() {
+          dump("\nEt tu, Brute?\n");
           ChromeUtils.privateNoteIntentionalCrash();
 
           switch (aMessage.data.crashType) {
             case "CRASH_OOM": {
               let debug = Cc["@mozilla.org/xpcom/debug;1"].getService(
                 Ci.nsIDebug2
               );
               debug.crashWithOOM();
@@ -237,18 +238,25 @@ class BrowserTestUtilsChild extends JSWi
                 zero,
                 ctypes.PointerType(ctypes.int32_t)
               );
               badptr.contents;
             }
           }
         };
 
-        dump("\nEt tu, Brute?\n");
-        dies();
+        if (aMessage.data.asyncCrash) {
+          let { setTimeout } = ChromeUtils.import(
+            "resource://gre/modules/Timer.jsm"
+          );
+          // Get out of the stack.
+          setTimeout(dies, 0);
+        } else {
+          dies();
+        }
       }
     }
 
     return undefined;
   }
 
   handleEvent(aEvent) {
     switch (aEvent.type) {