summaryrefslogtreecommitdiffstats
path: root/browser/extensions/pocket/test/head.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /browser/extensions/pocket/test/head.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'browser/extensions/pocket/test/head.js')
-rw-r--r--browser/extensions/pocket/test/head.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/browser/extensions/pocket/test/head.js b/browser/extensions/pocket/test/head.js
new file mode 100644
index 000000000..e044a42c7
--- /dev/null
+++ b/browser/extensions/pocket/test/head.js
@@ -0,0 +1,67 @@
+// Currently Pocket is disabled in tests. We want these tests to work under
+// either case that Pocket is disabled or enabled on startup of the browser,
+// and that at the end we're reset to the correct state.
+let enabledOnStartup = false;
+
+// PocketEnabled/Disabled promises return true if it was already
+// Enabled/Disabled, and false if it need to Enable/Disable.
+function promisePocketEnabled() {
+ if (Services.prefs.getPrefType("extensions.pocket.enabled") != Services.prefs.PREF_INVALID &&
+ Services.prefs.getBoolPref("extensions.pocket.enabled")) {
+ info( "pocket was already enabled, assuming enabled by default for tests");
+ enabledOnStartup = true;
+ return Promise.resolve(true);
+ }
+ info( "pocket is not enabled");
+ return new Promise((resolve, reject) => {
+ let listener = {
+ onWidgetAfterCreation(widgetid) {
+ if (widgetid == "pocket-button") {
+ info("pocket-button created");
+ CustomizableUI.removeListener(listener);
+ resolve(false);
+ }
+ }
+ }
+ CustomizableUI.addListener(listener);
+ Services.prefs.setBoolPref("extensions.pocket.enabled", true);
+ });
+}
+
+function promisePocketDisabled() {
+ if (Services.prefs.getPrefType("extensions.pocket.enabled") == Services.prefs.PREF_INVALID ||
+ !Services.prefs.getBoolPref("extensions.pocket.enabled")) {
+ info("pocket-button already disabled");
+ return Promise.resolve(true);
+ }
+ return new Promise((resolve, reject) => {
+ let listener = {
+ onWidgetDestroyed: function(widgetid) {
+ if (widgetid == "pocket-button") {
+ CustomizableUI.removeListener(listener);
+ info( "pocket-button destroyed");
+ // wait for a full unload of pocket
+ BrowserTestUtils.waitForCondition(() => {
+ return !window.hasOwnProperty("pktUI");
+ }, "pocket properties removed from window").then(() => {
+ resolve(false);
+ })
+ }
+ }
+ }
+ CustomizableUI.addListener(listener);
+ info("reset pocket enabled pref");
+ // testing/profiles/prefs_general.js uses user_pref to disable pocket, set
+ // back to false.
+ Services.prefs.setBoolPref("extensions.pocket.enabled", false);
+ });
+}
+
+function promisePocketReset() {
+ if (enabledOnStartup) {
+ info("reset is enabling pocket addon");
+ return promisePocketEnabled();
+ }
+ info("reset is disabling pocket addon");
+ return promisePocketDisabled();
+}