diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /toolkit/components/aboutwindowsmessages/tests | |
parent | Initial commit. (diff) | |
download | firefox-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 'toolkit/components/aboutwindowsmessages/tests')
-rw-r--r-- | toolkit/components/aboutwindowsmessages/tests/browser/browser.ini | 1 | ||||
-rw-r--r-- | toolkit/components/aboutwindowsmessages/tests/browser/browser_aboutwindowsmessages.js | 85 |
2 files changed, 86 insertions, 0 deletions
diff --git a/toolkit/components/aboutwindowsmessages/tests/browser/browser.ini b/toolkit/components/aboutwindowsmessages/tests/browser/browser.ini new file mode 100644 index 0000000000..debdaaa026 --- /dev/null +++ b/toolkit/components/aboutwindowsmessages/tests/browser/browser.ini @@ -0,0 +1 @@ +[browser_aboutwindowsmessages.js] diff --git a/toolkit/components/aboutwindowsmessages/tests/browser/browser_aboutwindowsmessages.js b/toolkit/components/aboutwindowsmessages/tests/browser/browser_aboutwindowsmessages.js new file mode 100644 index 0000000000..7c667891d6 --- /dev/null +++ b/toolkit/components/aboutwindowsmessages/tests/browser/browser_aboutwindowsmessages.js @@ -0,0 +1,85 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +async function resizeWindow(windowToResize, width, height) { + let resizePromise = BrowserTestUtils.waitForEvent( + windowToResize, + "resize", + false + ); + windowToResize.resizeTo(width, height); + await resizePromise; +} + +add_task(async () => { + const TEST_LINK = "https://example.com/"; + let originalBrowserWindow = + Services.wm.getMostRecentWindow("navigator:browser"); + let originalBrowser = originalBrowserWindow.gBrowser; + // Resize this window so we can check for WM_NCCALCSIZE events below + await resizeWindow(originalBrowserWindow, 500, 400); + await resizeWindow(originalBrowserWindow, 600, 500); + await resizeWindow(originalBrowserWindow, 700, 600); + let newWindow = await BrowserTestUtils.openNewBrowserWindow({ + url: TEST_LINK, + }); + registerCleanupFunction(async function () { + await BrowserTestUtils.closeWindow(newWindow); + }); + await BrowserTestUtils.withNewTab( + { gBrowser: originalBrowser, url: "about:windows-messages" }, + async browser => { + let messagesList = content.document.getElementById("windows-div"); + // This is tricky because the test framework has its own windows + Assert.greaterOrEqual( + messagesList.childNodes.length, + 2, + "should have enough window entries" + ); + + let firstList = true; + for (let sublist of messagesList.childNodes) { + const messages = Array.from(sublist.querySelectorAll("li.message")); + const numberOfMessages = messages.length; + // Every window gets a few window messages when it opens, so there + // should be at least a few here. + Assert.greaterOrEqual( + numberOfMessages, + 3, + "should have enough messages for the current window" + ); + if (firstList) { + // It would be nice if we could check for a less obscure event. + // However, since we're resizing the window programatically we don't + // get WM_SIZE or WM_SIZING events. + Assert.greaterOrEqual( + messages.filter(messageLi => + messageLi.innerHTML.includes("WM_NCCALCSIZE") + ).length, + 5, + "active window should have enough WM_NCCALCSIZE events" + ); + firstList = false; + } + let buttons = sublist.querySelectorAll("button"); + Assert.equal(buttons.length, 1, "should have only one button"); + let clipboardButton = buttons[0]; + clipboardButton.click(); + // Wait until copying is done and the button becomes clickable. + await BrowserTestUtils.waitForMutationCondition( + clipboardButton, + { attributes: true }, + () => !clipboardButton.disabled + ); + const clipboardText = await navigator.clipboard.readText(); + const numberOfLines = Array.from(clipboardText.matchAll("\n")).length; + Assert.equal( + numberOfLines, + numberOfMessages, + "should copy the right number of lines to the clipboard" + ); + } + } + ); +}); |