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/windowwatcher/test/test_alwaysOnTop_windows.html | |
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/windowwatcher/test/test_alwaysOnTop_windows.html')
-rw-r--r-- | toolkit/components/windowwatcher/test/test_alwaysOnTop_windows.html | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/toolkit/components/windowwatcher/test/test_alwaysOnTop_windows.html b/toolkit/components/windowwatcher/test/test_alwaysOnTop_windows.html new file mode 100644 index 0000000000..bc2b80cbfd --- /dev/null +++ b/toolkit/components/windowwatcher/test/test_alwaysOnTop_windows.html @@ -0,0 +1,82 @@ +<!DOCTYPE HTML> +<html> +<!-- +Tests the alwaysOnTop window feature for the Windows OS. +--> +<head> + <meta charset="utf-8"> + <title>Test an alwaysOnTop window on Windows</title> + + <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> + + <script type="application/javascript"> + + const {BrowserTestUtils} = ChromeUtils.import("resource://testing-common/BrowserTestUtils.jsm"); + const {ctypes} = ChromeUtils.import("resource://gre/modules/ctypes.jsm"); + + function assertAlwaysOnTop(win, expected) { + let docShell = win.docShell; + let chromeFlags = docShell.treeOwner + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIAppWindow) + .chromeFlags; + let hasFlag = !!(chromeFlags & Ci.nsIWebBrowserChrome.CHROME_ALWAYS_ON_TOP); + is(hasFlag, expected, "Window should have CHROME_ALWAYS_ON_TOP flag."); + + const hWND = Number(win.docShell.treeOwner.nsIBaseWindow.nativeHandle); + const WS_EX_TOPMOST = 0x00000008; + const GWL_EXSTYLE = -20; + + let lib = ctypes.open("user32.dll"); + // On 32-bit systems, the function we need to call is GetWindowLongW. On + // 64-bit systems, the function is GetWindowLongPtrW. Interestingly, + // the MSDN page[1] for GetWindowLongPtrW claims that calling it should work + // on both 32-bit and 64-bit, but that didn't appear to be the case here + // with local testing, hence the conditional. + // + // [1]: https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getwindowlongptrw + let GetWindowFuncSymbol = Services.appinfo.is64Bit ? "GetWindowLongPtrW" + : "GetWindowLongW"; + let GetWindowFunc = lib.declare(GetWindowFuncSymbol, ctypes.winapi_abi, + ctypes.intptr_t, ctypes.uintptr_t, + ctypes.int); + + let styles = GetWindowFunc(hWND, GWL_EXSTYLE); + let isAlwaysOnTop = !!(styles & WS_EX_TOPMOST); + is(isAlwaysOnTop, expected, "Window should be always on top."); + lib.close(); + } + + if (Services.appinfo.OS != "WINNT") { + ok(false, "This test is only designed to run on Windows."); + } else { + add_task(async function() { + let normalWinOpened = BrowserTestUtils.domWindowOpenedAndLoaded(); + window.openDialog("about:blank", + "_blank", "chrome,width=100,height=100,noopener", null); + let normalWin = await normalWinOpened; + ok(normalWin, "Normal window opened"); + assertAlwaysOnTop(normalWin, false); + await BrowserTestUtils.closeWindow(normalWin); + + let alwaysOnTopWinOpened = BrowserTestUtils.domWindowOpenedAndLoaded(); + window.openDialog("about:blank", + "_blank", "chrome,width=100,height=100,alwaysOnTop,noopener", null); + let alwaysOnTopWin = await alwaysOnTopWinOpened; + ok(alwaysOnTopWin, "AlwaysOnTop window opened"); + assertAlwaysOnTop(alwaysOnTopWin, true); + await BrowserTestUtils.closeWindow(alwaysOnTopWin); + }); + } + + </script> +</head> +<body> +<p id="display"></p> +<div id="content" style="display: none"> +</div> +<pre id="test"> +</pre> +</body> +</html> |