michael@0: Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: XPCOMUtils.defineLazyModuleGetter(this, "Promise", michael@0: "resource://gre/modules/Promise.jsm"); michael@0: XPCOMUtils.defineLazyModuleGetter(this, "Task", michael@0: "resource://gre/modules/Task.jsm"); michael@0: XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils", michael@0: "resource://gre/modules/PlacesUtils.jsm"); michael@0: michael@0: function whenDelayedStartupFinished(aWindow, aCallback) { michael@0: Services.obs.addObserver(function observer(aSubject, aTopic) { michael@0: if (aWindow == aSubject) { michael@0: Services.obs.removeObserver(observer, aTopic); michael@0: executeSoon(aCallback); michael@0: } michael@0: }, "browser-delayed-startup-finished", false); michael@0: } michael@0: michael@0: function findChromeWindowByURI(aURI) { michael@0: let windows = Services.wm.getEnumerator(null); michael@0: while (windows.hasMoreElements()) { michael@0: let win = windows.getNext(); michael@0: if (win.location.href == aURI) michael@0: return win; michael@0: } michael@0: return null; michael@0: } michael@0: michael@0: function waitForCondition(condition, nextTest, errorMsg) { michael@0: var tries = 0; michael@0: var interval = setInterval(function() { michael@0: if (tries >= 30) { michael@0: ok(false, errorMsg); michael@0: moveOn(); michael@0: } michael@0: var conditionPassed; michael@0: try { michael@0: conditionPassed = condition(); michael@0: } catch (e) { michael@0: ok(false, e + "\n" + e.stack); michael@0: conditionPassed = false; michael@0: } michael@0: if (conditionPassed) { michael@0: moveOn(); michael@0: } michael@0: tries++; michael@0: }, 100); michael@0: var moveOn = function() { clearInterval(interval); nextTest(); }; michael@0: } michael@0: michael@0: function getTestPlugin(aName) { michael@0: var pluginName = aName || "Test Plug-in"; michael@0: var ph = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost); michael@0: var tags = ph.getPluginTags(); michael@0: michael@0: // Find the test plugin michael@0: for (var i = 0; i < tags.length; i++) { michael@0: if (tags[i].name == pluginName) michael@0: return tags[i]; michael@0: } michael@0: ok(false, "Unable to find plugin"); michael@0: return null; michael@0: } michael@0: michael@0: // call this to set the test plugin(s) initially expected enabled state. michael@0: // it will automatically be reset to it's previous value after the test michael@0: // ends michael@0: function setTestPluginEnabledState(newEnabledState, pluginName) { michael@0: var plugin = getTestPlugin(pluginName); michael@0: var oldEnabledState = plugin.enabledState; michael@0: plugin.enabledState = newEnabledState; michael@0: SimpleTest.registerCleanupFunction(function() { michael@0: getTestPlugin(pluginName).enabledState = oldEnabledState; michael@0: }); michael@0: } michael@0: michael@0: // after a test is done using the plugin doorhanger, we should just clear michael@0: // any permissions that may have crept in michael@0: function clearAllPluginPermissions() { michael@0: let perms = Services.perms.enumerator; michael@0: while (perms.hasMoreElements()) { michael@0: let perm = perms.getNext(); michael@0: if (perm.type.startsWith('plugin')) { michael@0: Services.perms.remove(perm.host, perm.type); michael@0: } michael@0: } michael@0: } michael@0: michael@0: function updateBlocklist(aCallback) { michael@0: var blocklistNotifier = Cc["@mozilla.org/extensions/blocklist;1"] michael@0: .getService(Ci.nsITimerCallback); michael@0: var observer = function() { michael@0: Services.obs.removeObserver(observer, "blocklist-updated"); michael@0: SimpleTest.executeSoon(aCallback); michael@0: }; michael@0: Services.obs.addObserver(observer, "blocklist-updated", false); michael@0: blocklistNotifier.notify(null); michael@0: } michael@0: michael@0: var _originalTestBlocklistURL = null; michael@0: function setAndUpdateBlocklist(aURL, aCallback) { michael@0: if (!_originalTestBlocklistURL) michael@0: _originalTestBlocklistURL = Services.prefs.getCharPref("extensions.blocklist.url"); michael@0: Services.prefs.setCharPref("extensions.blocklist.url", aURL); michael@0: updateBlocklist(aCallback); michael@0: } michael@0: michael@0: function resetBlocklist() { michael@0: Services.prefs.setCharPref("extensions.blocklist.url", _originalTestBlocklistURL); michael@0: }