michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: michael@0: var addedTopic = "xpcom-category-entry-added"; michael@0: var removedTopic = "xpcom-category-entry-removed"; michael@0: var testCategory = "bug-test-category"; michael@0: var testEntry = "@mozilla.org/bug-test-entry;1"; michael@0: michael@0: var testValue= "check validity"; michael@0: var result = ""; michael@0: var expected = "add remove add remove "; michael@0: var timer; michael@0: michael@0: var observer = { michael@0: QueryInterface: function(iid) { michael@0: if (iid.equals(Ci.nsISupports) || iid.equals(Ci.nsIObserver)) michael@0: return this; michael@0: michael@0: throw Components.results.NS_ERROR_NO_INTERFACE; michael@0: }, michael@0: michael@0: observe: function(subject, topic, data) { michael@0: if (topic == "timer-callback") { michael@0: do_check_eq(result, expected); michael@0: michael@0: var observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService); michael@0: observerService.removeObserver(this, addedTopic); michael@0: observerService.removeObserver(this, removedTopic); michael@0: michael@0: do_test_finished(); michael@0: michael@0: timer = null; michael@0: } michael@0: michael@0: if (subject.QueryInterface(Ci.nsISupportsCString).data != testEntry || data != testCategory) michael@0: return; michael@0: michael@0: if (topic == addedTopic) michael@0: result += "add "; michael@0: else if (topic == removedTopic) michael@0: result += "remove "; michael@0: } michael@0: }; michael@0: michael@0: function run_test() { michael@0: do_test_pending(); michael@0: michael@0: var observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService); michael@0: observerService.addObserver(observer, addedTopic, false); michael@0: observerService.addObserver(observer, removedTopic, false); michael@0: michael@0: var categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager); michael@0: categoryManager.addCategoryEntry(testCategory, testEntry, testValue, false, true); michael@0: categoryManager.addCategoryEntry(testCategory, testEntry, testValue, false, true); michael@0: categoryManager.deleteCategoryEntry(testCategory, testEntry, false); michael@0: michael@0: timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); michael@0: timer.init(observer, 0, timer.TYPE_ONE_SHOT); michael@0: }