diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /toolkit/components/alerts/test/test_multiple_alerts.html | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/alerts/test/test_multiple_alerts.html')
-rw-r--r-- | toolkit/components/alerts/test/test_multiple_alerts.html | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/toolkit/components/alerts/test/test_multiple_alerts.html b/toolkit/components/alerts/test/test_multiple_alerts.html new file mode 100644 index 0000000000..95843b2e89 --- /dev/null +++ b/toolkit/components/alerts/test/test_multiple_alerts.html @@ -0,0 +1,99 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Test for multiple alerts</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> +</head> +<body> +<pre id="test"> +<script class="testbody" type="text/javascript"> +const Cc = SpecialPowers.Cc; +const Ci = SpecialPowers.Ci; + +const chromeScript = SpecialPowers.loadChromeScript(_ => { + /* eslint-env mozilla/chrome-script */ + const {clearTimeout, setTimeout} = ChromeUtils.importESModule( + "resource://gre/modules/Timer.sys.mjs" + ); + + const alertService = Cc["@mozilla.org/alerts-service;1"] + .getService(Ci.nsIAlertsService); + + addMessageListener("waitForPosition", function() { + var timer = setTimeout(function() { + Services.ww.unregisterNotification(windowObserver); + sendAsyncMessage("waitedForPosition", null); + }, 2000); + + var windowObserver = function(win, aTopic, aData) { + if (aTopic != "domwindowopened") { + return; + } + + // Alerts are implemented using XUL. + clearTimeout(timer); + + Services.ww.unregisterNotification(windowObserver); + + win.addEventListener("pageshow", function() { + var x = win.screenX; + var y = win.screenY; + + win.addEventListener("pagehide", function() { + sendAsyncMessage("waitedForPosition", { x, y }); + }, {once: true}); + + alertService.closeAlert(); + }, {once: true}); + }; + + Services.ww.registerNotification(windowObserver); + }); +}); + +function promiseAlertPosition(alertService) { + return new Promise(resolve => { + chromeScript.addMessageListener("waitedForPosition", function waitedForPosition(result) { + chromeScript.removeMessageListener("waitedForPosition", waitedForPosition); + resolve(result); + }); + chromeScript.sendAsyncMessage("waitForPosition"); + + alertService.showAlertNotification(null, "title", "body"); + ok(true, "Alert shown."); + }); +} + +add_task(async function test_multiple_alerts() { + if (!("@mozilla.org/alerts-service;1" in Cc)) { + todo(false, "Alerts service does not exist in this application."); + return; + } + + ok(true, "Alerts service exists in this application."); + + var alertService; + try { + alertService = Cc["@mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService); + ok(true, "Alerts service is available."); + } catch (ex) { + todo(false, "Alerts service is not available."); + return; + } + + var firstAlertPosition = await promiseAlertPosition(alertService); + if (!firstAlertPosition) { + ok(true, "Platform does not use XUL alerts."); + return; + } + + var secondAlertPosition = await promiseAlertPosition(alertService); + is(secondAlertPosition.x, firstAlertPosition.x, "Second alert should be opened in the same position."); + is(secondAlertPosition.y, firstAlertPosition.y, "Second alert should be opened in the same position."); +}); + +</script> +</pre> +</body> +</html> |