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 /browser/base/content/test/tabPrompts/browser_prompt_close_event.js | |
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 'browser/base/content/test/tabPrompts/browser_prompt_close_event.js')
-rw-r--r-- | browser/base/content/test/tabPrompts/browser_prompt_close_event.js | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/browser/base/content/test/tabPrompts/browser_prompt_close_event.js b/browser/base/content/test/tabPrompts/browser_prompt_close_event.js new file mode 100644 index 0000000000..9705062cef --- /dev/null +++ b/browser/base/content/test/tabPrompts/browser_prompt_close_event.js @@ -0,0 +1,164 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/** + * Execute the provided script content by generating a dynamic script tag and + * inserting it in the page for the current selected browser. + * + * @param {string} script + * The script to execute. + * @returns {Promise} + * A promise that resolves when the script node was added and removed from + * the content page. + */ +function createScriptNode(script) { + return SpecialPowers.spawn( + gBrowser.selectedBrowser, + [script], + function (_script) { + const scriptTag = content.document.createElement("script"); + scriptTag.append(content.document.createTextNode(_script)); + content.document.body.append(scriptTag); + } + ); +} + +add_task( + async function test_close_prompt_event_detail_accepted_with_default_value() { + const closed = BrowserTestUtils.waitForEvent( + window, + "DOMModalDialogClosed" + ); + + const promptPromise = BrowserTestUtils.promiseAlertDialogOpen(); + + const defaultValue = "Default value"; + await createScriptNode( + `setTimeout(() => window.prompt('Enter your name:', '${defaultValue}'))` + ); + const promptWin = await promptPromise; + + info("accepting prompt with default value."); + promptWin.document.querySelector("dialog").acceptDialog(); + + const closedEvent = await closed; + + is( + closedEvent.detail.areLeaving, + true, + "Received correct `areLeaving` value in the event detail" + ); + is( + closedEvent.detail.value, + defaultValue, + "Received correct `value` value in the event detail" + ); + } +); + +add_task( + async function test_close_prompt_event_detail_accepted_with_amended_default_value() { + const closed = BrowserTestUtils.waitForEvent( + window, + "DOMModalDialogClosed" + ); + + const promptPromise = BrowserTestUtils.promiseAlertDialogOpen(); + + const defaultValue = "Default value"; + await createScriptNode( + `setTimeout(() => window.prompt('Enter your name:', '${defaultValue}'))` + ); + const promptWin = await promptPromise; + + const amendedValue = "Test"; + promptWin.document.getElementById("loginTextbox").value = amendedValue; + + info("accepting prompt with amended value."); + promptWin.document.querySelector("dialog").acceptDialog(); + + const closedEvent = await closed; + + is( + closedEvent.detail.areLeaving, + true, + "Received correct `areLeaving` value in the event detail" + ); + is( + closedEvent.detail.value, + amendedValue, + "Received correct `value` value in the event detail" + ); + } +); + +add_task( + async function test_close_prompt_event_detail_dismissed_with_default_value() { + const closed = BrowserTestUtils.waitForEvent( + window, + "DOMModalDialogClosed" + ); + + const promptPromise = BrowserTestUtils.promiseAlertDialogOpen(); + + const defaultValue = "Default value"; + await createScriptNode( + `setTimeout(() => window.prompt('Enter your name:', '${defaultValue}'))` + ); + const promptWin = await promptPromise; + + info("Dismissing prompt with default value."); + promptWin.document.querySelector("dialog").cancelDialog(); + + const closedEvent = await closed; + + is( + closedEvent.detail.areLeaving, + false, + "Received correct `areLeaving` value in the event detail" + ); + is( + closedEvent.detail.value, + null, + "Received correct `value` value in the event detail" + ); + } +); + +add_task( + async function test_close_prompt_event_detail_dismissed_with_amended_default_value() { + const closed = BrowserTestUtils.waitForEvent( + window, + "DOMModalDialogClosed" + ); + + const promptPromise = BrowserTestUtils.promiseAlertDialogOpen(); + + const defaultValue = "Default value"; + await createScriptNode( + `setTimeout(() => window.prompt('Enter your name:', '${defaultValue}'))` + ); + const promptWin = await promptPromise; + + const amendedValue = "Test"; + promptWin.document.getElementById("loginTextbox").value = amendedValue; + + info("Dismissing prompt with amended value."); + promptWin.document.querySelector("dialog").cancelDialog(); + + const closedEvent = await closed; + + is( + closedEvent.detail.areLeaving, + false, + "Received correct `areLeaving` value in the event detail" + ); + is( + closedEvent.detail.value, + null, + "Received correct `value` value in the event detail" + ); + } +); |