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