2016-12-02 10:35:28 +03:00
|
|
|
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");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-06-22 13:51:42 +03:00
|
|
|
add_task(async function() {
|
|
|
|
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, URL);
|
2016-12-02 10:35:28 +03:00
|
|
|
let browser = tab.linkedBrowser;
|
|
|
|
|
|
|
|
// Focus and enter random text on input.
|
2017-06-22 13:51:42 +03:00
|
|
|
await ContentTask.spawn(browser, null, async function() {
|
2016-12-02 10:35:28 +03:00
|
|
|
let input = content.document.getElementById("input");
|
|
|
|
input.focus();
|
|
|
|
input.value = "abcd";
|
|
|
|
});
|
|
|
|
|
|
|
|
// Send return key (cross process) to submit the form implicitly.
|
|
|
|
let dialogShown = awaitAndCloseAlertDialog();
|
2018-02-14 22:15:39 +03:00
|
|
|
EventUtils.synthesizeKey("KEY_Enter");
|
2017-06-22 13:51:42 +03:00
|
|
|
await dialogShown;
|
2016-12-02 10:35:28 +03:00
|
|
|
|
|
|
|
// Check that the form should not have been submitted.
|
2017-06-22 13:51:42 +03:00
|
|
|
await ContentTask.spawn(browser, null, async function() {
|
2016-12-02 10:35:28 +03:00
|
|
|
let result = content.document.getElementById("result").innerHTML;
|
|
|
|
info("submit result: " + result);
|
|
|
|
is(result, "not submitted", "form should not have submitted");
|
|
|
|
});
|
|
|
|
|
|
|
|
gBrowser.removeCurrentTab();
|
|
|
|
});
|