mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 11:55:49 +00:00
Bug 1057386 - Provide an API to let the shutdown leak detector wait until resources are properly destroyed r=adw
This commit is contained in:
parent
f20cb9b88b
commit
3f1bbb16fd
@ -87,21 +87,30 @@ this.ContentSearch = {
|
||||
// { controller, previousFormHistoryResult }. See _onMessageGetSuggestions.
|
||||
_suggestionMap: new WeakMap(),
|
||||
|
||||
// Resolved when we finish shutting down.
|
||||
_destroyedPromise: null,
|
||||
|
||||
init: function () {
|
||||
Cc["@mozilla.org/globalmessagemanager;1"].
|
||||
getService(Ci.nsIMessageListenerManager).
|
||||
addMessageListener(INBOUND_MESSAGE, this);
|
||||
Services.obs.addObserver(this, "browser-search-engine-modified", false);
|
||||
Services.obs.addObserver(this, "shutdown-leaks-before-check", false);
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
if (this._destroyedPromise) {
|
||||
return this._destroyedPromise;
|
||||
}
|
||||
|
||||
Cc["@mozilla.org/globalmessagemanager;1"].
|
||||
getService(Ci.nsIMessageListenerManager).
|
||||
removeMessageListener(INBOUND_MESSAGE, this);
|
||||
Services.obs.removeObserver(this, "browser-search-engine-modified");
|
||||
Services.obs.removeObserver(this, "shutdown-leaks-before-check");
|
||||
|
||||
this._eventQueue.length = 0;
|
||||
return Promise.resolve(this._currentEventPromise);
|
||||
return this._destroyedPromise = Promise.resolve(this._currentEventPromise);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -148,6 +157,10 @@ this.ContentSearch = {
|
||||
});
|
||||
this._processEventQueue();
|
||||
break;
|
||||
case "shutdown-leaks-before-check":
|
||||
subj.wrappedJSObject.client.addBlocker(
|
||||
"ContentSearch: Wait until the service is destroyed", () => this.destroy());
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -458,7 +458,6 @@ Tester.prototype = {
|
||||
// is invoked to start the tests.
|
||||
this.waitForWindowsState((function () {
|
||||
if (this.done) {
|
||||
let promise = Promise.resolve();
|
||||
|
||||
// Uninitialize a few things explicitly so that they can clean up
|
||||
// frames and browser intentionally kept alive until shutdown to
|
||||
@ -489,15 +488,8 @@ Tester.prototype = {
|
||||
SocialFlyout.unload();
|
||||
SocialShare.uninit();
|
||||
TabView.uninit();
|
||||
|
||||
// Destroying ContentSearch is asynchronous.
|
||||
promise = ContentSearch.destroy();
|
||||
}
|
||||
|
||||
// Simulate memory pressure so that we're forced to free more resources
|
||||
// and thus get rid of more false leaks like already terminated workers.
|
||||
Services.obs.notifyObservers(null, "memory-pressure", "heap-minimize");
|
||||
|
||||
// Schedule GC and CC runs before finishing in order to detect
|
||||
// DOM windows leaked by our tests or the tested code. Note that we
|
||||
// use a shrinking GC so that the JS engine will discard JIT code and
|
||||
@ -527,7 +519,19 @@ Tester.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
promise.then(() => {
|
||||
let {AsyncShutdown} =
|
||||
Cu.import("resource://gre/modules/AsyncShutdown.jsm", {});
|
||||
|
||||
let barrier = new AsyncShutdown.Barrier(
|
||||
"ShutdownLeaks: Wait for cleanup to be finished before checking for leaks");
|
||||
Services.obs.notifyObservers({wrappedJSObject: barrier},
|
||||
"shutdown-leaks-before-check", null);
|
||||
|
||||
barrier.wait().then(() => {
|
||||
// Simulate memory pressure so that we're forced to free more resources
|
||||
// and thus get rid of more false leaks like already terminated workers.
|
||||
Services.obs.notifyObservers(null, "memory-pressure", "heap-minimize");
|
||||
|
||||
checkForLeakedGlobalWindows(aResults => {
|
||||
if (aResults.length == 0) {
|
||||
this.finish();
|
||||
|
Loading…
Reference in New Issue
Block a user