1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/plugins/head.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,110 @@ 1.4 +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); 1.5 + 1.6 +XPCOMUtils.defineLazyModuleGetter(this, "Promise", 1.7 + "resource://gre/modules/Promise.jsm"); 1.8 +XPCOMUtils.defineLazyModuleGetter(this, "Task", 1.9 + "resource://gre/modules/Task.jsm"); 1.10 +XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils", 1.11 + "resource://gre/modules/PlacesUtils.jsm"); 1.12 + 1.13 +function whenDelayedStartupFinished(aWindow, aCallback) { 1.14 + Services.obs.addObserver(function observer(aSubject, aTopic) { 1.15 + if (aWindow == aSubject) { 1.16 + Services.obs.removeObserver(observer, aTopic); 1.17 + executeSoon(aCallback); 1.18 + } 1.19 + }, "browser-delayed-startup-finished", false); 1.20 +} 1.21 + 1.22 +function findChromeWindowByURI(aURI) { 1.23 + let windows = Services.wm.getEnumerator(null); 1.24 + while (windows.hasMoreElements()) { 1.25 + let win = windows.getNext(); 1.26 + if (win.location.href == aURI) 1.27 + return win; 1.28 + } 1.29 + return null; 1.30 +} 1.31 + 1.32 +function waitForCondition(condition, nextTest, errorMsg) { 1.33 + var tries = 0; 1.34 + var interval = setInterval(function() { 1.35 + if (tries >= 30) { 1.36 + ok(false, errorMsg); 1.37 + moveOn(); 1.38 + } 1.39 + var conditionPassed; 1.40 + try { 1.41 + conditionPassed = condition(); 1.42 + } catch (e) { 1.43 + ok(false, e + "\n" + e.stack); 1.44 + conditionPassed = false; 1.45 + } 1.46 + if (conditionPassed) { 1.47 + moveOn(); 1.48 + } 1.49 + tries++; 1.50 + }, 100); 1.51 + var moveOn = function() { clearInterval(interval); nextTest(); }; 1.52 +} 1.53 + 1.54 +function getTestPlugin(aName) { 1.55 + var pluginName = aName || "Test Plug-in"; 1.56 + var ph = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost); 1.57 + var tags = ph.getPluginTags(); 1.58 + 1.59 + // Find the test plugin 1.60 + for (var i = 0; i < tags.length; i++) { 1.61 + if (tags[i].name == pluginName) 1.62 + return tags[i]; 1.63 + } 1.64 + ok(false, "Unable to find plugin"); 1.65 + return null; 1.66 +} 1.67 + 1.68 +// call this to set the test plugin(s) initially expected enabled state. 1.69 +// it will automatically be reset to it's previous value after the test 1.70 +// ends 1.71 +function setTestPluginEnabledState(newEnabledState, pluginName) { 1.72 + var plugin = getTestPlugin(pluginName); 1.73 + var oldEnabledState = plugin.enabledState; 1.74 + plugin.enabledState = newEnabledState; 1.75 + SimpleTest.registerCleanupFunction(function() { 1.76 + getTestPlugin(pluginName).enabledState = oldEnabledState; 1.77 + }); 1.78 +} 1.79 + 1.80 +// after a test is done using the plugin doorhanger, we should just clear 1.81 +// any permissions that may have crept in 1.82 +function clearAllPluginPermissions() { 1.83 + let perms = Services.perms.enumerator; 1.84 + while (perms.hasMoreElements()) { 1.85 + let perm = perms.getNext(); 1.86 + if (perm.type.startsWith('plugin')) { 1.87 + Services.perms.remove(perm.host, perm.type); 1.88 + } 1.89 + } 1.90 +} 1.91 + 1.92 +function updateBlocklist(aCallback) { 1.93 + var blocklistNotifier = Cc["@mozilla.org/extensions/blocklist;1"] 1.94 + .getService(Ci.nsITimerCallback); 1.95 + var observer = function() { 1.96 + Services.obs.removeObserver(observer, "blocklist-updated"); 1.97 + SimpleTest.executeSoon(aCallback); 1.98 + }; 1.99 + Services.obs.addObserver(observer, "blocklist-updated", false); 1.100 + blocklistNotifier.notify(null); 1.101 +} 1.102 + 1.103 +var _originalTestBlocklistURL = null; 1.104 +function setAndUpdateBlocklist(aURL, aCallback) { 1.105 + if (!_originalTestBlocklistURL) 1.106 + _originalTestBlocklistURL = Services.prefs.getCharPref("extensions.blocklist.url"); 1.107 + Services.prefs.setCharPref("extensions.blocklist.url", aURL); 1.108 + updateBlocklist(aCallback); 1.109 +} 1.110 + 1.111 +function resetBlocklist() { 1.112 + Services.prefs.setCharPref("extensions.blocklist.url", _originalTestBlocklistURL); 1.113 +}