diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /browser/base/content/test/plugins/BlocklistTestProxy.jsm | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/base/content/test/plugins/BlocklistTestProxy.jsm')
-rw-r--r-- | browser/base/content/test/plugins/BlocklistTestProxy.jsm | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/browser/base/content/test/plugins/BlocklistTestProxy.jsm b/browser/base/content/test/plugins/BlocklistTestProxy.jsm new file mode 100644 index 0000000000..cd13352f4a --- /dev/null +++ b/browser/base/content/test/plugins/BlocklistTestProxy.jsm @@ -0,0 +1,88 @@ +var EXPORTED_SYMBOLS = ["BlocklistTestProxyChild"]; + +var Cm = Components.manager; + +const kBlocklistServiceUUID = "{66354bc9-7ed1-4692-ae1d-8da97d6b205e}"; +const kBlocklistServiceContractID = "@mozilla.org/extensions/blocklist;1"; + +let existingBlocklistFactory = null; +try { + existingBlocklistFactory = Cm.getClassObject( + Cc[kBlocklistServiceContractID], + Ci.nsIFactory + ); +} catch (ex) {} + +const { setTimeout } = ChromeUtils.import("resource://gre/modules/Timer.jsm"); + +/* + * A lightweight blocklist proxy for testing purposes. + */ +var BlocklistProxy = { + _uuid: null, + + QueryInterface: ChromeUtils.generateQI([ + "nsIObserver", + "nsIBlocklistService", + "nsITimerCallback", + ]), + + init() { + if (!this._uuid) { + this._uuid = Cc["@mozilla.org/uuid-generator;1"] + .getService(Ci.nsIUUIDGenerator) + .generateUUID(); + Cm.nsIComponentRegistrar.registerFactory( + this._uuid, + "", + "@mozilla.org/extensions/blocklist;1", + this + ); + } + }, + + uninit() { + if (this._uuid) { + Cm.nsIComponentRegistrar.unregisterFactory(this._uuid, this); + if (existingBlocklistFactory) { + Cm.nsIComponentRegistrar.registerFactory( + Components.ID(kBlocklistServiceUUID), + "Blocklist Service", + "@mozilla.org/extensions/blocklist;1", + existingBlocklistFactory + ); + } + this._uuid = null; + } + }, + + notify(aTimer) {}, + + async getAddonBlocklistState(aAddon, aAppVersion, aToolkitVersion) { + await new Promise(r => setTimeout(r, 150)); + return 0; // STATE_NOT_BLOCKED + }, + + async getPluginBlocklistState(aPluginTag, aAppVersion, aToolkitVersion) { + await new Promise(r => setTimeout(r, 150)); + return 0; // STATE_NOT_BLOCKED + }, + + async getPluginBlockURL(aPluginTag) { + await new Promise(r => setTimeout(r, 150)); + return ""; + }, +}; + +class BlocklistTestProxyChild extends JSProcessActorChild { + constructor() { + super(); + BlocklistProxy.init(); + } + + receiveMessage(message) { + if (message.name == "unload") { + BlocklistProxy.uninit(); + } + } +} |