mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-24 10:45:42 +00:00
3148018ed7
This patch removes the C++ code used to run the minidump analyzer when a content process crashes, and replaces it with JS code within the CrashService object. This removes the need for a separate shutdown blocker in C++ code and allows end-to-end testing of the crash service functionality. Additionally the exception handler code can be simplified since it's now only used to run the crash reporter client. The test added to test_crash_service.js covers computing the minidump SHA256 hash (bug 1322611) and of the minidump analyzer itself (bug 1280477). MozReview-Commit-ID: LO5w839NHev
204 lines
7.4 KiB
JavaScript
204 lines
7.4 KiB
JavaScript
/*
|
|
Any copyright is dedicated to the Public Domain.
|
|
http://creativecommons.org/publicdomain/zero/1.0/
|
|
*/
|
|
|
|
// This must be loaded in the remote process for this test to be useful
|
|
const TEST_URL = "http://example.com/browser/netwerk/test/browser/dummy.html";
|
|
|
|
const expectedRemote = gMultiProcessBrowser ? "true" : "";
|
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
|
const resProtocol = Cc["@mozilla.org/network/protocol;1?name=resource"]
|
|
.getService(Ci.nsIResProtocolHandler);
|
|
|
|
function frameScript() {
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
|
let resProtocol = Components.classes["@mozilla.org/network/protocol;1?name=resource"]
|
|
.getService(Components.interfaces.nsIResProtocolHandler);
|
|
|
|
addMessageListener("Test:ResolveURI", function({ data: uri }) {
|
|
uri = Services.io.newURI(uri);
|
|
try {
|
|
let resolved = resProtocol.resolveURI(uri);
|
|
sendAsyncMessage("Test:ResolvedURI", resolved);
|
|
}
|
|
catch (e) {
|
|
sendAsyncMessage("Test:ResolvedURI", null);
|
|
}
|
|
});
|
|
}
|
|
|
|
function waitForEvent(obj, name, capturing, chromeEvent) {
|
|
info("Waiting for " + name);
|
|
return new Promise((resolve) => {
|
|
function listener(event) {
|
|
info("Saw " + name);
|
|
obj.removeEventListener(name, listener, capturing, chromeEvent);
|
|
resolve(event);
|
|
}
|
|
|
|
obj.addEventListener(name, listener, capturing, chromeEvent);
|
|
});
|
|
}
|
|
|
|
function resolveURI(uri) {
|
|
uri = Services.io.newURI(uri);
|
|
try {
|
|
return resProtocol.resolveURI(uri);
|
|
}
|
|
catch (e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function remoteResolveURI(uri) {
|
|
return new Promise((resolve) => {
|
|
let manager = gBrowser.selectedBrowser.messageManager;
|
|
|
|
function listener({ data: resolved }) {
|
|
manager.removeMessageListener("Test:ResolvedURI", listener);
|
|
resolve(resolved);
|
|
}
|
|
|
|
manager.addMessageListener("Test:ResolvedURI", listener);
|
|
manager.sendAsyncMessage("Test:ResolveURI", uri);
|
|
});
|
|
}
|
|
|
|
var loadTestTab = Task.async(function*() {
|
|
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, TEST_URL);
|
|
let browser = gBrowser.selectedBrowser;
|
|
yield BrowserTestUtils.browserLoaded(browser);
|
|
browser.messageManager.loadFrameScript("data:,(" + frameScript.toString() + ")();", true);
|
|
return browser;
|
|
});
|
|
|
|
// Restarts the child process by crashing it then reloading the tab
|
|
var restart = Task.async(function*() {
|
|
let browser = gBrowser.selectedBrowser;
|
|
// If the tab isn't remote this would crash the main process so skip it
|
|
if (browser.getAttribute("remote") != "true")
|
|
return browser;
|
|
|
|
yield BrowserTestUtils.crashBrowser(browser);
|
|
|
|
browser.reload();
|
|
|
|
yield BrowserTestUtils.browserLoaded(browser);
|
|
is(browser.getAttribute("remote"), expectedRemote, "Browser should be in the right process");
|
|
browser.messageManager.loadFrameScript("data:,(" + frameScript.toString() + ")();", true);
|
|
return browser;
|
|
});
|
|
|
|
// Sanity check that this test is going to be useful
|
|
add_task(function*() {
|
|
let browser = yield loadTestTab();
|
|
|
|
// This must be loaded in the remote process for this test to be useful
|
|
is(browser.getAttribute("remote"), expectedRemote, "Browser should be in the right process");
|
|
|
|
let local = resolveURI("resource://gre/modules/Services.jsm");
|
|
let remote = yield remoteResolveURI("resource://gre/modules/Services.jsm");
|
|
is(local, remote, "Services.jsm should resolve in both processes");
|
|
|
|
gBrowser.removeCurrentTab();
|
|
});
|
|
|
|
// Add a mapping, update it then remove it
|
|
add_task(function*() {
|
|
let browser = yield loadTestTab();
|
|
|
|
info("Set");
|
|
resProtocol.setSubstitution("testing", Services.io.newURI("chrome://global/content"));
|
|
let local = resolveURI("resource://testing/test.js");
|
|
let remote = yield remoteResolveURI("resource://testing/test.js");
|
|
is(local, "chrome://global/content/test.js", "Should resolve in main process");
|
|
is(remote, "chrome://global/content/test.js", "Should resolve in child process");
|
|
|
|
info("Change");
|
|
resProtocol.setSubstitution("testing", Services.io.newURI("chrome://global/skin"));
|
|
local = resolveURI("resource://testing/test.js");
|
|
remote = yield remoteResolveURI("resource://testing/test.js");
|
|
is(local, "chrome://global/skin/test.js", "Should resolve in main process");
|
|
is(remote, "chrome://global/skin/test.js", "Should resolve in child process");
|
|
|
|
info("Clear");
|
|
resProtocol.setSubstitution("testing", null);
|
|
local = resolveURI("resource://testing/test.js");
|
|
remote = yield remoteResolveURI("resource://testing/test.js");
|
|
is(local, null, "Shouldn't resolve in main process");
|
|
is(remote, null, "Shouldn't resolve in child process");
|
|
|
|
gBrowser.removeCurrentTab();
|
|
});
|
|
|
|
// Add a mapping, restart the child process then check it is still there
|
|
add_task(function*() {
|
|
let browser = yield loadTestTab();
|
|
|
|
info("Set");
|
|
resProtocol.setSubstitution("testing", Services.io.newURI("chrome://global/content"));
|
|
let local = resolveURI("resource://testing/test.js");
|
|
let remote = yield remoteResolveURI("resource://testing/test.js");
|
|
is(local, "chrome://global/content/test.js", "Should resolve in main process");
|
|
is(remote, "chrome://global/content/test.js", "Should resolve in child process");
|
|
|
|
yield restart();
|
|
|
|
local = resolveURI("resource://testing/test.js");
|
|
remote = yield remoteResolveURI("resource://testing/test.js");
|
|
is(local, "chrome://global/content/test.js", "Should resolve in main process");
|
|
is(remote, "chrome://global/content/test.js", "Should resolve in child process");
|
|
|
|
info("Change");
|
|
resProtocol.setSubstitution("testing", Services.io.newURI("chrome://global/skin"));
|
|
|
|
yield restart();
|
|
|
|
local = resolveURI("resource://testing/test.js");
|
|
remote = yield remoteResolveURI("resource://testing/test.js");
|
|
is(local, "chrome://global/skin/test.js", "Should resolve in main process");
|
|
is(remote, "chrome://global/skin/test.js", "Should resolve in child process");
|
|
|
|
info("Clear");
|
|
resProtocol.setSubstitution("testing", null);
|
|
|
|
yield restart();
|
|
|
|
local = resolveURI("resource://testing/test.js");
|
|
remote = yield remoteResolveURI("resource://testing/test.js");
|
|
is(local, null, "Shouldn't resolve in main process");
|
|
is(remote, null, "Shouldn't resolve in child process");
|
|
|
|
gBrowser.removeCurrentTab();
|
|
});
|
|
|
|
// Adding a mapping to a resource URI should work
|
|
add_task(function*() {
|
|
let browser = yield loadTestTab();
|
|
|
|
info("Set");
|
|
resProtocol.setSubstitution("testing", Services.io.newURI("chrome://global/content"));
|
|
resProtocol.setSubstitution("testing2", Services.io.newURI("resource://testing"));
|
|
let local = resolveURI("resource://testing2/test.js");
|
|
let remote = yield remoteResolveURI("resource://testing2/test.js");
|
|
is(local, "chrome://global/content/test.js", "Should resolve in main process");
|
|
is(remote, "chrome://global/content/test.js", "Should resolve in child process");
|
|
|
|
info("Clear");
|
|
resProtocol.setSubstitution("testing", null);
|
|
local = resolveURI("resource://testing2/test.js");
|
|
remote = yield remoteResolveURI("resource://testing2/test.js");
|
|
is(local, "chrome://global/content/test.js", "Should resolve in main process");
|
|
is(remote, "chrome://global/content/test.js", "Should resolve in child process");
|
|
|
|
resProtocol.setSubstitution("testing2", null);
|
|
local = resolveURI("resource://testing2/test.js");
|
|
remote = yield remoteResolveURI("resource://testing2/test.js");
|
|
is(local, null, "Shouldn't resolve in main process");
|
|
is(remote, null, "Shouldn't resolve in child process");
|
|
|
|
gBrowser.removeCurrentTab();
|
|
});
|