michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ */ michael@0: michael@0: // Regression test for bug 345529 - crash removing an observer during an michael@0: // nsPref:changed notification. michael@0: function run_test() { michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: const PREF_NAME = "testPref"; michael@0: michael@0: var prefs = Cc["@mozilla.org/preferences-service;1"] michael@0: .getService(Ci.nsIPrefBranch); michael@0: var observer = { michael@0: QueryInterface: function QueryInterface(aIID) { michael@0: if (aIID.equals(Ci.nsIObserver) || michael@0: aIID.equals(Ci.nsISupports)) michael@0: return this; michael@0: throw Components.results.NS_NOINTERFACE; michael@0: }, michael@0: michael@0: observe: function observe(aSubject, aTopic, aState) { michael@0: prefs.removeObserver(PREF_NAME, observer); michael@0: } michael@0: } michael@0: prefs.addObserver(PREF_NAME, observer, false); michael@0: michael@0: prefs.setCharPref(PREF_NAME, "test0") michael@0: // This second call isn't needed on a clean profile: it makes sure michael@0: // the observer gets called even if the pref already had the value michael@0: // "test0" before this test. michael@0: prefs.setCharPref(PREF_NAME, "test1") michael@0: michael@0: do_check_true(true); michael@0: }