browser/base/content/test/plugins/head.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 2
michael@0 3 XPCOMUtils.defineLazyModuleGetter(this, "Promise",
michael@0 4 "resource://gre/modules/Promise.jsm");
michael@0 5 XPCOMUtils.defineLazyModuleGetter(this, "Task",
michael@0 6 "resource://gre/modules/Task.jsm");
michael@0 7 XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
michael@0 8 "resource://gre/modules/PlacesUtils.jsm");
michael@0 9
michael@0 10 function whenDelayedStartupFinished(aWindow, aCallback) {
michael@0 11 Services.obs.addObserver(function observer(aSubject, aTopic) {
michael@0 12 if (aWindow == aSubject) {
michael@0 13 Services.obs.removeObserver(observer, aTopic);
michael@0 14 executeSoon(aCallback);
michael@0 15 }
michael@0 16 }, "browser-delayed-startup-finished", false);
michael@0 17 }
michael@0 18
michael@0 19 function findChromeWindowByURI(aURI) {
michael@0 20 let windows = Services.wm.getEnumerator(null);
michael@0 21 while (windows.hasMoreElements()) {
michael@0 22 let win = windows.getNext();
michael@0 23 if (win.location.href == aURI)
michael@0 24 return win;
michael@0 25 }
michael@0 26 return null;
michael@0 27 }
michael@0 28
michael@0 29 function waitForCondition(condition, nextTest, errorMsg) {
michael@0 30 var tries = 0;
michael@0 31 var interval = setInterval(function() {
michael@0 32 if (tries >= 30) {
michael@0 33 ok(false, errorMsg);
michael@0 34 moveOn();
michael@0 35 }
michael@0 36 var conditionPassed;
michael@0 37 try {
michael@0 38 conditionPassed = condition();
michael@0 39 } catch (e) {
michael@0 40 ok(false, e + "\n" + e.stack);
michael@0 41 conditionPassed = false;
michael@0 42 }
michael@0 43 if (conditionPassed) {
michael@0 44 moveOn();
michael@0 45 }
michael@0 46 tries++;
michael@0 47 }, 100);
michael@0 48 var moveOn = function() { clearInterval(interval); nextTest(); };
michael@0 49 }
michael@0 50
michael@0 51 function getTestPlugin(aName) {
michael@0 52 var pluginName = aName || "Test Plug-in";
michael@0 53 var ph = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
michael@0 54 var tags = ph.getPluginTags();
michael@0 55
michael@0 56 // Find the test plugin
michael@0 57 for (var i = 0; i < tags.length; i++) {
michael@0 58 if (tags[i].name == pluginName)
michael@0 59 return tags[i];
michael@0 60 }
michael@0 61 ok(false, "Unable to find plugin");
michael@0 62 return null;
michael@0 63 }
michael@0 64
michael@0 65 // call this to set the test plugin(s) initially expected enabled state.
michael@0 66 // it will automatically be reset to it's previous value after the test
michael@0 67 // ends
michael@0 68 function setTestPluginEnabledState(newEnabledState, pluginName) {
michael@0 69 var plugin = getTestPlugin(pluginName);
michael@0 70 var oldEnabledState = plugin.enabledState;
michael@0 71 plugin.enabledState = newEnabledState;
michael@0 72 SimpleTest.registerCleanupFunction(function() {
michael@0 73 getTestPlugin(pluginName).enabledState = oldEnabledState;
michael@0 74 });
michael@0 75 }
michael@0 76
michael@0 77 // after a test is done using the plugin doorhanger, we should just clear
michael@0 78 // any permissions that may have crept in
michael@0 79 function clearAllPluginPermissions() {
michael@0 80 let perms = Services.perms.enumerator;
michael@0 81 while (perms.hasMoreElements()) {
michael@0 82 let perm = perms.getNext();
michael@0 83 if (perm.type.startsWith('plugin')) {
michael@0 84 Services.perms.remove(perm.host, perm.type);
michael@0 85 }
michael@0 86 }
michael@0 87 }
michael@0 88
michael@0 89 function updateBlocklist(aCallback) {
michael@0 90 var blocklistNotifier = Cc["@mozilla.org/extensions/blocklist;1"]
michael@0 91 .getService(Ci.nsITimerCallback);
michael@0 92 var observer = function() {
michael@0 93 Services.obs.removeObserver(observer, "blocklist-updated");
michael@0 94 SimpleTest.executeSoon(aCallback);
michael@0 95 };
michael@0 96 Services.obs.addObserver(observer, "blocklist-updated", false);
michael@0 97 blocklistNotifier.notify(null);
michael@0 98 }
michael@0 99
michael@0 100 var _originalTestBlocklistURL = null;
michael@0 101 function setAndUpdateBlocklist(aURL, aCallback) {
michael@0 102 if (!_originalTestBlocklistURL)
michael@0 103 _originalTestBlocklistURL = Services.prefs.getCharPref("extensions.blocklist.url");
michael@0 104 Services.prefs.setCharPref("extensions.blocklist.url", aURL);
michael@0 105 updateBlocklist(aCallback);
michael@0 106 }
michael@0 107
michael@0 108 function resetBlocklist() {
michael@0 109 Services.prefs.setCharPref("extensions.blocklist.url", _originalTestBlocklistURL);
michael@0 110 }

mercurial