summaryrefslogtreecommitdiffstats
path: root/browser/components/pocket/test/head.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /browser/components/pocket/test/head.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/pocket/test/head.js')
-rw-r--r--browser/components/pocket/test/head.js85
1 files changed, 85 insertions, 0 deletions
diff --git a/browser/components/pocket/test/head.js b/browser/components/pocket/test/head.js
new file mode 100644
index 0000000000..c3ce73e42e
--- /dev/null
+++ b/browser/components/pocket/test/head.js
@@ -0,0 +1,85 @@
+// 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;
+
+ChromeUtils.defineESModuleGetters(this, {
+ pktApi: "chrome://pocket/content/pktApi.sys.mjs",
+});
+
+const { sinon } = ChromeUtils.importESModule(
+ "resource://testing-common/Sinon.sys.mjs"
+);
+
+// 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");
+ Services.prefs.setBoolPref("extensions.pocket.enabled", true);
+ return BrowserTestUtils.waitForCondition(() => {
+ return !!CustomizableUI.getWidget("save-to-pocket-button");
+ });
+}
+
+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);
+ }
+ info("reset pocket enabled pref");
+ // testing/profiles/common/user.js uses user_pref to disable pocket, set
+ // back to false.
+ Services.prefs.setBoolPref("extensions.pocket.enabled", false);
+ return BrowserTestUtils.waitForCondition(() => {
+ return !CustomizableUI.getWidget("save-to-pocket-button");
+ });
+}
+
+function promisePocketReset() {
+ if (enabledOnStartup) {
+ info("reset is enabling pocket addon");
+ return promisePocketEnabled();
+ }
+ info("reset is disabling pocket addon");
+ return promisePocketDisabled();
+}
+
+function checkElements(expectPresent, l, win = window) {
+ for (let id of l) {
+ let el =
+ win.document.getElementById(id) ||
+ win.gNavToolbox.palette.querySelector("#" + id);
+ is(
+ !!el && !el.hidden,
+ expectPresent,
+ "element " + id + (expectPresent ? " is" : " is not") + " present"
+ );
+ }
+}
+
+function checkElementsShown(expectPresent, l, win = window) {
+ for (let id of l) {
+ let el =
+ win.document.getElementById(id) ||
+ win.gNavToolbox.palette.querySelector("#" + id);
+ let elShown = !!el && window.getComputedStyle(el).display != "none";
+ is(
+ elShown,
+ expectPresent,
+ "element " + id + (expectPresent ? " is" : " is not") + " present"
+ );
+ }
+}