Bug 584040 - Fix leaky tests [r=mconnor]

Avoid holding on to the original nsIFormHistory2 service object in FormNotifier.js and explicitly null the reference on shutdown.
This commit is contained in:
Philipp von Weitershausen 2010-08-03 19:57:53 +02:00
Родитель d3c2e2f9f5
Коммит 9c826435e5
3 изменённых файлов: 25 добавлений и 27 удалений

Просмотреть файл

@ -10,43 +10,47 @@ function FormNotifier() {
let obs = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
for (let keyval in Iterator(baseForm)) {
// Make a local copy of these values
let [key, val] = keyval;
// Don't overwrite something we already have
if (key in this)
continue;
// Make a getter to grab non-functions
if (typeof val != "function") {
this.__defineGetter__(key, function() baseForm[key]);
continue;
}
// XXX Bug 568707 Make use of "key" to prevent it from disappearing
(function(){})(key);
// Wrap the function with notifications
this[key] = function() {
function wrap(method) {
return function() {
let args = Array.slice(arguments);
let notify = function(type) {
obs.notifyObservers(null, "form-notifier", JSON.stringify({
args: args,
func: key,
func: method,
type: type
}));
};
notify("before");
try {
return val.apply(this, arguments);
return baseForm[method].apply(this, arguments);
}
finally {
notify("after");
}
};
}
this.__defineGetter__("DBConnection", function() baseForm.DBConnection);
this.__defineGetter__("hasEntries", function() baseForm.hasEntries);
this.addEntry = wrap("addEntry");
this.entryExists = wrap("entryExists");
this.nameExists = wrap("nameExists");
this.removeAllEntries = wrap("removeAllEntries");
this.removeEntriesByTimeframe = wrap("removeEntriesByTimeframe");
this.removeEntriesForName = wrap("removeEntriesForName");
this.removeEntry = wrap("removeEntry");
// Avoid leaking the base form service.
obs.addObserver({
observe: function() {
obs.removeObserver(this, "profile-before-change");
baseForm = null;
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference,
Ci.nsIObserver])
}, "profile-before-change", true);
}
FormNotifier.prototype = {
classDescription: "Form Notifier Wrapper",

Просмотреть файл

@ -3,9 +3,6 @@ Cu.import("resource://services-sync/engines/forms.js");
Cu.import("resource://services-sync/type_records/forms.js");
function run_test() {
//XXXzpao test is disabled (bug 583985)
return;
let store = new FormEngine()._store;
_("Remove any existing entries");

Просмотреть файл

@ -2,9 +2,6 @@ _("Make sure queryAsync will synchronously fetch rows for a query asyncly");
Cu.import("resource://services-sync/util.js");
function run_test() {
//XXXzpao test is disabled (bug 583985)
return;
_("Using the form service to test queries");
function c(query) Svc.Form.DBConnection.createStatement(query);