fune/dom/tests/browser/browser_cancel_keydown_keypress_event.js
Kris Maglione 94e3b0bd8d Bug 1596918: Part 3a - Scripted rewrite of most ContentTask.spawn calls to SpecialPowers.spawn calls. r=mccr8,remote-protocol-reviewers,ato
This is generally pretty straightforward, and rewrites nearly all calls. It
skips the ones that it can detect using frame script globals like
`sendAsyncMessage`, though.

Differential Revision: https://phabricator.services.mozilla.com/D53740

--HG--
extra : moz-landing-system : lando
2019-12-13 20:36:16 +00:00

41 lines
1.3 KiB
JavaScript

const URL =
"https://example.com/browser/dom/tests/browser/prevent_return_key.html";
// Wait for alert dialog and dismiss it immediately.
function awaitAndCloseAlertDialog() {
return new Promise(resolve => {
function onDialogShown(node) {
Services.obs.removeObserver(onDialogShown, "tabmodal-dialog-loaded");
let button = node.querySelector(".tabmodalprompt-button0");
button.click();
resolve();
}
Services.obs.addObserver(onDialogShown, "tabmodal-dialog-loaded");
});
}
add_task(async function() {
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, URL);
let browser = tab.linkedBrowser;
// Focus and enter random text on input.
await SpecialPowers.spawn(browser, [], async function() {
let input = content.document.getElementById("input");
input.focus();
input.value = "abcd";
});
// Send return key (cross process) to submit the form implicitly.
let dialogShown = awaitAndCloseAlertDialog();
EventUtils.synthesizeKey("KEY_Enter");
await dialogShown;
// Check that the form should not have been submitted.
await SpecialPowers.spawn(browser, [], async function() {
let result = content.document.getElementById("result").innerHTML;
info("submit result: " + result);
is(result, "not submitted", "form should not have submitted");
});
gBrowser.removeCurrentTab();
});