michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: const Cu = Components.utils; michael@0: const Cr = Components.results; michael@0: michael@0: Cu.import("resource://testing-common/httpd.js"); michael@0: michael@0: const nsIBLS = Ci.nsIBlocklistService; michael@0: const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul"; michael@0: michael@0: var gBlocklist = null; michael@0: var gPrefs = null; michael@0: var gTestserver = null; michael@0: michael@0: var gNextTestPart = null; michael@0: michael@0: michael@0: var PLUGINS = [{ michael@0: // Tests a plugin whose state goes from not-blocked, to outdated michael@0: name: "test_bug514327_outdated", michael@0: version: "5", michael@0: disabled: false, michael@0: blocklisted: false michael@0: }, { michael@0: // Used to trigger the blocklist dialog, which indicates the blocklist has updated michael@0: name: "test_bug514327_1", michael@0: version: "5", michael@0: disabled: false, michael@0: blocklisted: false michael@0: }, { michael@0: // Used to trigger the blocklist dialog, which indicates the blocklist has updated michael@0: name: "test_bug514327_2", michael@0: version: "5", michael@0: disabled: false, michael@0: blocklisted: false michael@0: } ]; michael@0: michael@0: michael@0: // A fake plugin host for the blocklist service to use michael@0: var PluginHost = { michael@0: getPluginTags: function(countRef) { michael@0: countRef.value = PLUGINS.length; michael@0: return PLUGINS; michael@0: }, michael@0: michael@0: QueryInterface: function(iid) { michael@0: if (iid.equals(Ci.nsIPluginHost) michael@0: || iid.equals(Ci.nsISupports)) michael@0: return this; michael@0: michael@0: throw Components.results.NS_ERROR_NO_INTERFACE; michael@0: } michael@0: } michael@0: michael@0: var PluginHostFactory = { michael@0: createInstance: function (outer, iid) { michael@0: if (outer != null) michael@0: throw Components.results.NS_ERROR_NO_AGGREGATION; michael@0: return PluginHost.QueryInterface(iid); michael@0: } michael@0: }; michael@0: michael@0: // Don't need the full interface, attempts to call other methods will just michael@0: // throw which is just fine michael@0: var WindowWatcher = { michael@0: openWindow: function(parent, url, name, features, arguments) { michael@0: // Should be called to list the newly blocklisted items michael@0: do_check_eq(url, URI_EXTENSION_BLOCKLIST_DIALOG); michael@0: // Should only include one item michael@0: do_check_eq(arguments.wrappedJSObject.list.length, 1); michael@0: // And that item should be the blocked plugin, not the outdated one michael@0: var item = arguments.wrappedJSObject.list[0]; michael@0: do_check_true(item.item instanceof Ci.nsIPluginTag); michael@0: do_check_neq(item.name, "test_bug514327_outdated"); michael@0: michael@0: // Call the next test after the blocklist has finished up michael@0: do_timeout(0, gNextTestPart); michael@0: }, michael@0: michael@0: QueryInterface: function(iid) { michael@0: if (iid.equals(Ci.nsIWindowWatcher) michael@0: || iid.equals(Ci.nsISupports)) michael@0: return this; michael@0: michael@0: throw Cr.NS_ERROR_NO_INTERFACE; michael@0: } michael@0: } michael@0: michael@0: var WindowWatcherFactory = { michael@0: createInstance: function createInstance(outer, iid) { michael@0: if (outer != null) michael@0: throw Components.results.NS_ERROR_NO_AGGREGATION; michael@0: return WindowWatcher.QueryInterface(iid); michael@0: } michael@0: }; michael@0: michael@0: var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); michael@0: registrar.registerFactory(Components.ID("{721c3e73-969e-474b-a6dc-059fd288c428}"), michael@0: "Fake Plugin Host", michael@0: "@mozilla.org/plugin/host;1", PluginHostFactory); michael@0: registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), michael@0: "Fake Window Watcher", michael@0: "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory); michael@0: michael@0: michael@0: function do_update_blocklist(aDatafile, aNextPart) { michael@0: gNextTestPart = aNextPart; michael@0: michael@0: gPrefs.setCharPref("extensions.blocklist.url", "http://localhost:" + gPort + "/data/" + aDatafile); michael@0: gBlocklist.QueryInterface(Ci.nsITimerCallback).notify(null); michael@0: } michael@0: michael@0: function run_test() { michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); michael@0: michael@0: gTestserver = new HttpServer(); michael@0: gTestserver.registerDirectory("/data/", do_get_file("data")); michael@0: gTestserver.start(-1); michael@0: gPort = gTestserver.identity.primaryPort; michael@0: michael@0: startupManager(); michael@0: michael@0: // initialize the blocklist with no entries michael@0: copyBlocklistToProfile(do_get_file("data/test_bug514327_3_empty.xml")); michael@0: michael@0: gPrefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); michael@0: gBlocklist = Cc["@mozilla.org/extensions/blocklist;1"].getService(nsIBLS); michael@0: michael@0: // should NOT be marked as outdated by the blocklist michael@0: do_check_true(gBlocklist.getPluginBlocklistState(PLUGINS[0], "1", "1.9") == nsIBLS.STATE_NOT_BLOCKED); michael@0: michael@0: do_test_pending(); michael@0: michael@0: // update blocklist with data that marks the plugin as outdated michael@0: do_update_blocklist("test_bug514327_3_outdated_1.xml", test_part_1); michael@0: } michael@0: michael@0: function test_part_1() { michael@0: // plugin should now be marked as outdated michael@0: do_check_true(gBlocklist.getPluginBlocklistState(PLUGINS[0], "1", "1.9") == nsIBLS.STATE_OUTDATED); michael@0: // and the notifyUser pref should be set to true michael@0: do_check_true(gPrefs.getBoolPref("plugins.update.notifyUser")); michael@0: michael@0: // preternd the user has been notified, reset the pref michael@0: gPrefs.setBoolPref("plugins.update.notifyUser", false); michael@0: michael@0: // update blocklist with data that marks the plugin as outdated michael@0: do_update_blocklist("test_bug514327_3_outdated_2.xml", test_part_2); michael@0: } michael@0: michael@0: function test_part_2() { michael@0: // plugin should still be marked as outdated michael@0: do_check_true(gBlocklist.getPluginBlocklistState(PLUGINS[0], "1", "1.9") == nsIBLS.STATE_OUTDATED); michael@0: // and the notifyUser pref should NOT be set to true, as the plugin was already outdated michael@0: do_check_false(gPrefs.getBoolPref("plugins.update.notifyUser")); michael@0: michael@0: finish(); michael@0: } michael@0: michael@0: function finish() { michael@0: gTestserver.stop(do_test_finished); michael@0: }