diff options
author | Matt A. Tobin <email@mattatobin.com> | 2018-02-10 02:49:12 -0500 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2018-02-10 02:49:12 -0500 |
commit | 4fb11cd5966461bccc3ed1599b808237be6b0de9 (patch) | |
tree | d7f0ccd49cebb3544d52635ff1bd6ed4d763823f /toolkit/mozapps/webextensions/test/addons/test_symbol | |
parent | f164d9124708b50789dbb6959e1de96cc5697c48 (diff) | |
download | UXP-4fb11cd5966461bccc3ed1599b808237be6b0de9.tar UXP-4fb11cd5966461bccc3ed1599b808237be6b0de9.tar.gz UXP-4fb11cd5966461bccc3ed1599b808237be6b0de9.tar.lz UXP-4fb11cd5966461bccc3ed1599b808237be6b0de9.tar.xz UXP-4fb11cd5966461bccc3ed1599b808237be6b0de9.zip |
Move WebExtensions enabled Add-ons Manager
Diffstat (limited to 'toolkit/mozapps/webextensions/test/addons/test_symbol')
-rw-r--r-- | toolkit/mozapps/webextensions/test/addons/test_symbol/bootstrap.js | 62 | ||||
-rw-r--r-- | toolkit/mozapps/webextensions/test/addons/test_symbol/install.rdf | 28 |
2 files changed, 90 insertions, 0 deletions
diff --git a/toolkit/mozapps/webextensions/test/addons/test_symbol/bootstrap.js b/toolkit/mozapps/webextensions/test/addons/test_symbol/bootstrap.js new file mode 100644 index 000000000..4eb8b4875 --- /dev/null +++ b/toolkit/mozapps/webextensions/test/addons/test_symbol/bootstrap.js @@ -0,0 +1,62 @@ +Components.utils.import("resource://gre/modules/Services.jsm"); +Components.utils.import("resource://gre/modules/AddonManager.jsm"); + +const PASS_PREF = "symboltest.instanceid.pass"; +const FAIL_BOGUS_PREF = "symboltest.instanceid.fail_bogus"; +const FAIL_ID_PREF = "symboltest.instanceid.fail_bogus"; +const ADDON_ID = "test_symbol@tests.mozilla.org"; + +function install(data, reason) {} + +// normally we would use BootstrapMonitor here, but we need a reference to +// the symbol inside `XPIProvider.jsm`. +function startup(data, reason) { + Services.prefs.setBoolPref(PASS_PREF, false); + Services.prefs.setBoolPref(FAIL_BOGUS_PREF, false); + Services.prefs.setBoolPref(FAIL_ID_PREF, false); + + // test with the correct symbol + if (data.hasOwnProperty("instanceID") && data.instanceID) { + AddonManager.getAddonByInstanceID(data.instanceID) + .then(addon => { + if (addon.id == ADDON_ID) { + Services.prefs.setBoolPref(PASS_PREF, true); + } + }).catch(err => { + throw Error("no addon found for symbol"); + }); + + } + + // test with a totally bogus symbol + AddonManager.getAddonByInstanceID(Symbol("bad symbol")) + .then(addon => { + // there is no symbol by this name, so null should be returned + if (addon == null) { + Services.prefs.setBoolPref(FAIL_BOGUS_PREF, true); + } else { + throw Error("bad symbol should not match:", addon); + } + }).catch(err => { + throw Error("promise should not have rejected: " + err); + }); + + // try to make a matching symbol - this should fail because it's not a + // reference to the same symbol stored inside the addons manager. + AddonManager.getAddonByInstanceID(Symbol(ADDON_ID)) + .then(addon => { + // there is no symbol by this name, so null should be returned + if (addon == null) { + Services.prefs.setBoolPref(FAIL_ID_PREF, true); + } else { + throw Error("bad symbol should not match:", addon); + } + }).catch(err => { + throw Error("promise should not have rejected: " + err); + }); + +} + +function shutdown(data, reason) {} + +function uninstall(data, reason) {} diff --git a/toolkit/mozapps/webextensions/test/addons/test_symbol/install.rdf b/toolkit/mozapps/webextensions/test/addons/test_symbol/install.rdf new file mode 100644 index 000000000..adccda552 --- /dev/null +++ b/toolkit/mozapps/webextensions/test/addons/test_symbol/install.rdf @@ -0,0 +1,28 @@ +<?xml version="1.0"?> + +<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:em="http://www.mozilla.org/2004/em-rdf#"> + + <Description about="urn:mozilla:install-manifest"> + <em:id>test_symbol@tests.mozilla.org</em:id> + <em:version>1.0</em:version> + <em:bootstrap>true</em:bootstrap> + + <!-- Front End MetaData --> + <em:name>Test Symbol</em:name> + <em:description>Test Description</em:description> + + <em:iconURL>chrome://foo/skin/icon.png</em:iconURL> + <em:aboutURL>chrome://foo/content/about.xul</em:aboutURL> + <em:optionsURL>chrome://foo/content/options.xul</em:optionsURL> + + <em:targetApplication> + <Description> + <em:id>xpcshell@tests.mozilla.org</em:id> + <em:minVersion>1</em:minVersion> + <em:maxVersion>1</em:maxVersion> + </Description> + </em:targetApplication> + + </Description> +</RDF> |