summaryrefslogtreecommitdiffstats
path: root/toolkit/components/aboutwindowsmessages/tests/browser
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /toolkit/components/aboutwindowsmessages/tests/browser
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/aboutwindowsmessages/tests/browser')
-rw-r--r--toolkit/components/aboutwindowsmessages/tests/browser/browser.ini1
-rw-r--r--toolkit/components/aboutwindowsmessages/tests/browser/browser_aboutwindowsmessages.js86
2 files changed, 87 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..38f4f1c78c
--- /dev/null
+++ b/toolkit/components/aboutwindowsmessages/tests/browser/browser_aboutwindowsmessages.js
@@ -0,0 +1,86 @@
+/* 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"
+ );
+ }
+ }
+ );
+});