fune/dom/tests/browser/browser_cancel_keydown_keypress_event.js
Masayuki Nakano cf83ee7bb4 Bug 1438157 - part 2: Remove unnecessary second argument of EventUtils.synthesizeKey() r=smaug
Note that this patch also replaces legacy VK_* with KEY_*, and replaces
synthesizeKey() for inputting some characters with sendString() because
it's better and clearer what it does and it sets shiftKey state properly.

MozReview-Commit-ID: De4enbjux3T

--HG--
extra : rebase_source : 2296b84bff8e22f01eeb48cd8614fac5db11136a
2018-02-15 04:15:39 +09: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.ui.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 ContentTask.spawn(browser, null, 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 ContentTask.spawn(browser, null, async function() {
let result = content.document.getElementById("result").innerHTML;
info("submit result: " + result);
is(result, "not submitted", "form should not have submitted");
});
gBrowser.removeCurrentTab();
});