fune/toolkit/content/tests/browser/browser_crash_previous_frameloader.js
Kris Maglione e930b89c34 Bug 1514594: Part 3 - Change ChromeUtils.import API.
***
Bug 1514594: Part 3a - Change ChromeUtils.import to return an exports object; not pollute global. r=mccr8

This changes the behavior of ChromeUtils.import() to return an exports object,
rather than a module global, in all cases except when `null` is passed as a
second argument, and changes the default behavior not to pollute the global
scope with the module's exports. Thus, the following code written for the old
model:

  ChromeUtils.import("resource://gre/modules/Services.jsm");

is approximately the same as the following, in the new model:

  var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");

Since the two behaviors are mutually incompatible, this patch will land with a
scripted rewrite to update all existing callers to use the new model rather
than the old.
***
Bug 1514594: Part 3b - Mass rewrite all JS code to use the new ChromeUtils.import API. rs=Gijs

This was done using the followng script:

https://bitbucket.org/kmaglione/m-c-rewrites/src/tip/processors/cu-import-exports.jsm
***
Bug 1514594: Part 3c - Update ESLint plugin for ChromeUtils.import API changes. r=Standard8

Differential Revision: https://phabricator.services.mozilla.com/D16747
***
Bug 1514594: Part 3d - Remove/fix hundreds of duplicate imports from sync tests. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D16748
***
Bug 1514594: Part 3e - Remove no-op ChromeUtils.import() calls. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D16749
***
Bug 1514594: Part 3f.1 - Cleanup various test corner cases after mass rewrite. r=Gijs
***
Bug 1514594: Part 3f.2 - Cleanup various non-test corner cases after mass rewrite. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D16750

--HG--
extra : rebase_source : 359574ee3064c90f33bf36c2ebe3159a24cc8895
extra : histedit_source : b93c8f42808b1599f9122d7842d2c0b3e656a594%2C64a3a4e3359dc889e2ab2b49461bab9e27fc10a7
2019-01-17 10:18:31 -08:00

119 lines
3.9 KiB
JavaScript

"use strict";
/**
* Returns the id of the crash minidump.
*
* @param subject (nsISupports)
* The subject passed through the ipc:content-shutdown
* observer notification when a content process crash has
* occurred.
* @returns {String} The crash dump id.
*/
function getCrashDumpId(subject) {
Assert.ok(subject instanceof Ci.nsIPropertyBag2,
"Subject needs to be a nsIPropertyBag2 to clean up properly");
return subject.getPropertyAsAString("dumpID");
}
/**
* Cleans up the .dmp and .extra file from a crash.
*
* @param id {String} The crash dump id.
*/
function cleanUpMinidump(id) {
let dir = Services.dirsvc.get("ProfD", Ci.nsIFile);
dir.append("minidumps");
let file = dir.clone();
file.append(id + ".dmp");
file.remove(true);
file = dir.clone();
file.append(id + ".extra");
file.remove(true);
}
/**
* This test ensures that if a remote frameloader crashes after
* the frameloader owner swaps it out for a new frameloader,
* that a oop-browser-crashed event is not sent to the new
* frameloader's browser element.
*/
add_task(async function test_crash_in_previous_frameloader() {
// On debug builds, crashing tabs results in much thinking, which
// slows down the test and results in intermittent test timeouts,
// so we'll pump up the expected timeout for this test.
requestLongerTimeout(2);
if (!gMultiProcessBrowser) {
Assert.ok(false, "This test should only be run in multi-process mode.");
return;
}
await BrowserTestUtils.withNewTab({
gBrowser,
url: "http://example.com",
}, async function(browser) {
// First, sanity check...
Assert.ok(browser.isRemoteBrowser,
"This browser needs to be remote if this test is going to " +
"work properly.");
// We will wait for the oop-browser-crashed event to have
// a chance to appear. That event is fired when TabParents
// are destroyed, and that occurs _before_ ContentParents
// are destroyed, so we'll wait on the ipc:content-shutdown
// observer notification, which is fired when a ContentParent
// goes away. After we see this notification, oop-browser-crashed
// events should have fired.
let contentProcessGone = TestUtils.topicObserved("ipc:content-shutdown");
let sawTabCrashed = false;
let onTabCrashed = () => {
sawTabCrashed = true;
};
browser.addEventListener("oop-browser-crashed", onTabCrashed);
// The name of the game is to cause a crash in a remote browser,
// and then immediately swap out the browser for a non-remote one.
await ContentTask.spawn(browser, null, function() {
const {ctypes} = ChromeUtils.import("resource://gre/modules/ctypes.jsm");
ChromeUtils.import("resource://gre/modules/Timer.jsm");
let dies = function() {
privateNoteIntentionalCrash();
let zero = new ctypes.intptr_t(8);
let badptr = ctypes.cast(zero, ctypes.PointerType(ctypes.int32_t));
badptr.contents;
};
// When the parent flips the remoteness of the browser, the
// page should receive the pagehide event, which we'll then
// use to crash the frameloader.
addEventListener("pagehide", function() {
dump("\nEt tu, Brute?\n");
dies();
});
});
gBrowser.updateBrowserRemoteness(browser, false);
info("Waiting for content process to go away.");
let [subject /* , data */] = await contentProcessGone;
// If we don't clean up the minidump, the harness will
// complain.
let dumpID = getCrashDumpId(subject);
Assert.ok(dumpID, "There should be a dumpID");
if (dumpID) {
await Services.crashmanager.ensureCrashIsPresent(dumpID);
cleanUpMinidump(dumpID);
}
info("Content process is gone!");
Assert.ok(!sawTabCrashed,
"Should not have seen the oop-browser-crashed event.");
browser.removeEventListener("oop-browser-crashed", onTabCrashed);
});
});