summaryrefslogtreecommitdiffstats
path: root/browser/extensions/pocket/test
diff options
context:
space:
mode:
Diffstat (limited to 'browser/extensions/pocket/test')
-rw-r--r--browser/extensions/pocket/test/.eslintrc.js7
-rw-r--r--browser/extensions/pocket/test/browser.ini6
-rw-r--r--browser/extensions/pocket/test/browser_pocket_ui_check.js61
-rw-r--r--browser/extensions/pocket/test/head.js67
-rw-r--r--browser/extensions/pocket/test/test.html11
5 files changed, 152 insertions, 0 deletions
diff --git a/browser/extensions/pocket/test/.eslintrc.js b/browser/extensions/pocket/test/.eslintrc.js
new file mode 100644
index 000000000..c764b133d
--- /dev/null
+++ b/browser/extensions/pocket/test/.eslintrc.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+ "extends": [
+ "../../../../testing/mochitest/browser.eslintrc.js"
+ ]
+};
diff --git a/browser/extensions/pocket/test/browser.ini b/browser/extensions/pocket/test/browser.ini
new file mode 100644
index 000000000..3e0be8736
--- /dev/null
+++ b/browser/extensions/pocket/test/browser.ini
@@ -0,0 +1,6 @@
+[DEFAULT]
+support-files =
+ head.js
+ test.html
+
+[browser_pocket_ui_check.js]
diff --git a/browser/extensions/pocket/test/browser_pocket_ui_check.js b/browser/extensions/pocket/test/browser_pocket_ui_check.js
new file mode 100644
index 000000000..12aeaffd6
--- /dev/null
+++ b/browser/extensions/pocket/test/browser_pocket_ui_check.js
@@ -0,0 +1,61 @@
+"use strict";
+
+function checkWindowProperties(expectPresent, l) {
+ for (let name of l) {
+ is(!!window.hasOwnProperty(name), expectPresent, "property " + name + (expectPresent ? " is" : " is not") + " present");
+ }
+}
+function checkElements(expectPresent, l) {
+ for (let id of l) {
+ is(!!document.getElementById(id), expectPresent, "element " + id + (expectPresent ? " is" : " is not") + " present");
+ }
+}
+
+add_task(function* test_setup() {
+ let clearValue = Services.prefs.prefHasUserValue("extensions.pocket.enabled");
+ let enabledOnStartup = Services.prefs.getBoolPref("extensions.pocket.enabled");
+ registerCleanupFunction(() => {
+ if (clearValue) {
+ Services.prefs.clearUserPref("extensions.pocket.enabled");
+ } else {
+ Services.prefs.setBoolPref("extensions.pocket.enabled", enabledOnStartup);
+ }
+ });
+});
+
+add_task(function*() {
+ yield promisePocketEnabled();
+
+ checkWindowProperties(true, ["Pocket", "pktUI", "pktUIMessaging"]);
+ checkElements(true, ["pocket-button", "panelMenu_pocket", "menu_pocket", "BMB_pocket",
+ "panelMenu_pocketSeparator", "menu_pocketSeparator",
+ "BMB_pocketSeparator"]);
+
+ // check context menu exists
+ info("checking content context menu");
+ let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "https://example.com/browser/browser/extensions/pocket/test/test.html");
+
+ let contextMenu = document.getElementById("contentAreaContextMenu");
+ let popupShown = BrowserTestUtils.waitForEvent(contextMenu, "popupshown");
+ let popupHidden = BrowserTestUtils.waitForEvent(contextMenu, "popuphidden");
+ yield BrowserTestUtils.synthesizeMouseAtCenter("body", {
+ type: "contextmenu",
+ button: 2
+ }, tab.linkedBrowser);
+ yield popupShown;
+
+ checkElements(true, ["context-pocket", "context-savelinktopocket"]);
+
+ contextMenu.hidePopup();
+ yield popupHidden;
+ yield BrowserTestUtils.removeTab(tab);
+
+ yield promisePocketDisabled();
+
+ checkWindowProperties(false, ["Pocket", "pktUI", "pktUIMessaging"]);
+ checkElements(false, ["pocket-button", "panelMenu_pocket", "menu_pocket", "BMB_pocket",
+ "panelMenu_pocketSeparator", "menu_pocketSeparator",
+ "BMB_pocketSeparator", "context-pocket", "context-savelinktopocket"]);
+
+ yield promisePocketReset();
+});
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();
+}
diff --git a/browser/extensions/pocket/test/test.html b/browser/extensions/pocket/test/test.html
new file mode 100644
index 000000000..aa08cd566
--- /dev/null
+++ b/browser/extensions/pocket/test/test.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+ <title>Page Title</title>
+ <meta charset="utf-8" />
+</head>
+
+<body>
+</body>
+</html>