diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /browser/components/pocket/test/head.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
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.js | 87 |
1 files changed, 87 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..fbbe981060 --- /dev/null +++ b/browser/components/pocket/test/head.js @@ -0,0 +1,87 @@ +// 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.defineModuleGetter( + this, + "pktApi", + "chrome://pocket/content/pktApi.jsm" +); +const { ContentTaskUtils } = ChromeUtils.importESModule( + "resource://testing-common/ContentTaskUtils.sys.mjs" +); +const { sinon } = ChromeUtils.import("resource://testing-common/Sinon.jsm"); + +// 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" + ); + } +} |