diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /browser/components/newtab/test/browser/browser_newtab_last_LinkMenu.js | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/newtab/test/browser/browser_newtab_last_LinkMenu.js')
-rw-r--r-- | browser/components/newtab/test/browser/browser_newtab_last_LinkMenu.js | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/browser/components/newtab/test/browser/browser_newtab_last_LinkMenu.js b/browser/components/newtab/test/browser/browser_newtab_last_LinkMenu.js new file mode 100644 index 0000000000..2c58c9a48c --- /dev/null +++ b/browser/components/newtab/test/browser/browser_newtab_last_LinkMenu.js @@ -0,0 +1,151 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +async function setupPrefs() { + await setDefaultTopSites(); + await SpecialPowers.pushPrefEnv({ + set: [ + [ + "browser.newtabpage.activity-stream.discoverystream.config", + JSON.stringify({ + api_key_pref: "extensions.pocket.oAuthConsumerKey", + collapsible: true, + enabled: true, + show_spocs: false, + hardcoded_layout: false, + personalized: false, + layout_endpoint: + "https://example.com/browser/browser/components/newtab/test/browser/ds_layout.json", + }), + ], + [ + "browser.newtabpage.activity-stream.discoverystream.endpoints", + "https://example.com", + ], + ], + }); +} + +async function resetPrefs() { + // We set 5 prefs in setupPrefs, so we should reset 5 prefs. + // 1 popPrefEnv from pushPrefEnv + // and 4 popPrefEnv happen internally in setDefaultTopSites. + await SpecialPowers.popPrefEnv(); + await SpecialPowers.popPrefEnv(); + await SpecialPowers.popPrefEnv(); + await SpecialPowers.popPrefEnv(); + await SpecialPowers.popPrefEnv(); +} + +let initialHeight; +let initialWidth; +function setSize(width, height) { + initialHeight = window.innerHeight; + initialWidth = window.innerWidth; + let resizePromise = BrowserTestUtils.waitForEvent(window, "resize", false); + window.resizeTo(width, height); + return resizePromise; +} + +function resetSize() { + let resizePromise = BrowserTestUtils.waitForEvent(window, "resize", false); + window.resizeTo(initialWidth, initialHeight); + return resizePromise; +} + +add_task(async function test_newtab_last_LinkMenu() { + await setupPrefs(); + + // Open about:newtab without using the default load listener + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + "about:newtab", + false + ); + + // Specially wait for potentially preloaded browsers + let browser = tab.linkedBrowser; + await waitForPreloaded(browser); + + // Wait for React to render something + await BrowserTestUtils.waitForCondition( + () => + SpecialPowers.spawn( + browser, + [], + () => content.document.getElementById("root").children.length + ), + "Should render activity stream content" + ); + + // Set the window to a small enough size to trigger menus that might overflow. + await setSize(600, 450); + + // Test context menu position for topsites. + await SpecialPowers.spawn(browser, [], async () => { + // Topsites might not be ready, so wait for the button. + await ContentTaskUtils.waitForCondition( + () => + content.document.querySelector( + ".top-site-outer:nth-child(2n) .context-menu-button" + ), + "Wait for the Pocket card and button" + ); + const topsiteOuter = content.document.querySelector( + ".top-site-outer:nth-child(2n)" + ); + const topsiteContextMenuButton = topsiteOuter.querySelector( + ".context-menu-button" + ); + + topsiteContextMenuButton.click(); + + await ContentTaskUtils.waitForCondition( + () => topsiteOuter.classList.contains("active"), + "Wait for the menu to be active" + ); + + is( + content.window.scrollMaxX, + 0, + "there should be no horizontal scroll bar" + ); + }); + + // Test context menu position for topstories. + await SpecialPowers.spawn(browser, [], async () => { + // Pocket section might take a bit more time to load, + // so wait for the button to be ready. + await ContentTaskUtils.waitForCondition( + () => + content.document.querySelector( + ".ds-card:nth-child(1n) .context-menu-button" + ), + "Wait for the Pocket card and button" + ); + + const dsCard = content.document.querySelector(".ds-card:nth-child(1n)"); + const dsCarContextMenuButton = dsCard.querySelector(".context-menu-button"); + + dsCarContextMenuButton.click(); + + await ContentTaskUtils.waitForCondition( + () => dsCard.classList.contains("active"), + "Wait for the menu to be active" + ); + + is( + content.window.scrollMaxX, + 0, + "there should be no horizontal scroll bar" + ); + }); + + // Resetting the window size to what it was. + await resetSize(); + // Resetting prefs we set for this test. + await resetPrefs(); + BrowserTestUtils.removeTab(tab); +}); |