diff --git a/toolkit/mozapps/extensions/nsBlocklistService.js b/toolkit/mozapps/extensions/nsBlocklistService.js index bb7a2e4c38f9..883fba0e6b19 100644 --- a/toolkit/mozapps/extensions/nsBlocklistService.js +++ b/toolkit/mozapps/extensions/nsBlocklistService.js @@ -47,6 +47,7 @@ const Cr = Components.results; Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); Components.utils.import("resource://gre/modules/FileUtils.jsm"); Components.utils.import("resource://gre/modules/AddonManager.jsm"); +Components.utils.import("resource://gre/modules/Services.jsm"); const TOOLKIT_ID = "toolkit@mozilla.org" const KEY_PROFILEDIR = "ProfD"; @@ -637,10 +638,25 @@ Blocklist.prototype = { } var childNodes = doc.documentElement.childNodes; - this._addonEntries = this._processItemNodes(childNodes, "em", - this._handleEmItemNode); - this._pluginEntries = this._processItemNodes(childNodes, "plugin", - this._handlePluginItemNode); + for (var i = 0; i < childNodes.length; ++i) { + var element = childNodes[i]; + if (!(element instanceof Ci.nsIDOMElement)) + continue; + switch (element.localName) { + case "emItems": + this._processItemNodes(element.childNodes, "em", + this._handleEmItemNode); + break; + case "pluginItems": + this._processItemNodes(element.childNodes, "plugin", + this._handleEmItemNode); + break; + default: + Services.obs.notifyObservers(element, + "blocklist-data-" + element.localName, + null); + } + } } catch (e) { LOG("Blocklist::_loadBlocklistFromFile: Error constructing blocklist " + e); @@ -649,21 +665,8 @@ Blocklist.prototype = { fileStream.close(); }, - _processItemNodes: function(deChildNodes, prefix, handler) { + _processItemNodes: function(itemNodes, prefix, handler) { var result = []; - var itemNodes; - var containerName = prefix + "Items"; - for (var i = 0; i < deChildNodes.length; ++i) { - var emItemsElement = deChildNodes.item(i); - if (emItemsElement instanceof Ci.nsIDOMElement && - emItemsElement.localName == containerName) { - itemNodes = emItemsElement.childNodes; - break; - } - } - if (!itemNodes) - return result; - var itemName = prefix + "Item"; for (var i = 0; i < itemNodes.length; ++i) { var blocklistElement = itemNodes.item(i); diff --git a/toolkit/mozapps/extensions/test/xpcshell/data/test_bug619730.xml b/toolkit/mozapps/extensions/test/xpcshell/data/test_bug619730.xml new file mode 100644 index 000000000000..f2511c0de68d --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/data/test_bug619730.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bug619730.js b/toolkit/mozapps/extensions/test/xpcshell/test_bug619730.js new file mode 100644 index 000000000000..a55735787f96 --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug619730.js @@ -0,0 +1,53 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +// Tests whether +do_load_httpd_js(); + +var gTestserver = null; + +function load_blocklist(file) { + Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:4444/data/" + file); + var blocklist = Cc["@mozilla.org/extensions/blocklist;1"]. + getService(Ci.nsITimerCallback); + blocklist.notify(null); +} + +var gSawGFX = false; +var gSawTest = false; + +// Performs the initial setup +function run_test() { + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "3", "8"); + startupManager(); + + gTestserver = new nsHttpServer(); + gTestserver.registerDirectory("/data/", do_get_file("data")); + gTestserver.start(4444); + + do_test_pending(); + + Services.obs.addObserver(function(aSubject, aTopic, aData) { + do_check_true(aSubject instanceof AM_Ci.nsIDOMElement); + do_check_eq(aSubject.getAttribute("testattr"), "GFX"); + do_check_eq(aSubject.childNodes.length, 2); + gSawGFX = true; + }, "blocklist-data-gfxItems", false); + + Services.obs.addObserver(function(aSubject, aTopic, aData) { + do_check_true(aSubject instanceof AM_Ci.nsIDOMElement); + do_check_eq(aSubject.getAttribute("testattr"), "FOO"); + do_check_eq(aSubject.childNodes.length, 3); + gSawTest = true; + }, "blocklist-data-testItems", false); + + Services.obs.addObserver(function(aSubject, aTopic, aData) { + do_check_true(gSawGFX); + do_check_true(gSawTest); + + gTestserver.stop(do_test_finished); + }, "blocklist-data-fooItems", false); + + load_blocklist("test_bug619730.xml"); +}