зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1781162 - Upgrade toolkit/components/satchel/test/test_submit_on_keydown_enter.html r=dimi
Differential Revision: https://phabricator.services.mozilla.com/D152927
This commit is contained in:
Родитель
70e90f6a98
Коммит
53fd3c2c76
|
@ -13,7 +13,7 @@ Form History test: Test for keydown handler submitting the form
|
||||||
<p id="display"></p>
|
<p id="display"></p>
|
||||||
|
|
||||||
<div id="content">
|
<div id="content">
|
||||||
<form id="form1" action="javascript:handleSubmit()">
|
<form id="form1">
|
||||||
<input type="text" name="field1">
|
<input type="text" name="field1">
|
||||||
<button type="submit">Submit</button>
|
<button type="submit">Submit</button>
|
||||||
</form>
|
</form>
|
||||||
|
@ -26,15 +26,17 @@ var input = getFormElementByName(1, "field1");
|
||||||
var expectedValue = "value1";
|
var expectedValue = "value1";
|
||||||
var beforeInputFired = false;
|
var beforeInputFired = false;
|
||||||
|
|
||||||
function handleSubmit() { // eslint-disable-line no-unused-vars
|
add_task(async function setup() {
|
||||||
info("Submit");
|
await updateFormHistory([
|
||||||
ok(false, "The form should not be submitted");
|
{ op: "remove" },
|
||||||
input.removeEventListener("beforeinput", handleBeforeInput, true);
|
{ op: "add", fieldname: "field1", value: "value1" },
|
||||||
input.removeEventListener("input", handleInput, true);
|
]);
|
||||||
SimpleTest.finish();
|
});
|
||||||
}
|
|
||||||
|
|
||||||
function handleBeforeInput(aEvent) {
|
add_task(async function submitOnKeydownEnter() {
|
||||||
|
const submitTested = new Promise(resolve => {
|
||||||
|
|
||||||
|
function handleBeforeInput(aEvent) {
|
||||||
info("BeforeInput");
|
info("BeforeInput");
|
||||||
beforeInputFired = true;
|
beforeInputFired = true;
|
||||||
is(input.value, "value", "The value should've not been modified yet");
|
is(input.value, "value", "The value should've not been modified yet");
|
||||||
|
@ -52,9 +54,9 @@ function handleBeforeInput(aEvent) {
|
||||||
'dataTransfer of "beforeinput" event should be null');
|
'dataTransfer of "beforeinput" event should be null');
|
||||||
is(aEvent.getTargetRanges().length, 0,
|
is(aEvent.getTargetRanges().length, 0,
|
||||||
'getTargetRanges() of "beforeinput" event should return empty array');
|
'getTargetRanges() of "beforeinput" event should return empty array');
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleInput(aEvent) {
|
function handleInput(aEvent) {
|
||||||
info("Input");
|
info("Input");
|
||||||
ok(beforeInputFired, '"beforeinput" event should have been fired');
|
ok(beforeInputFired, '"beforeinput" event should have been fired');
|
||||||
is(input.value, expectedValue, "Check input value");
|
is(input.value, expectedValue, "Check input value");
|
||||||
|
@ -72,12 +74,15 @@ function handleInput(aEvent) {
|
||||||
'dataTransfer of "input" event should be null');
|
'dataTransfer of "input" event should be null');
|
||||||
is(aEvent.getTargetRanges().length, 0,
|
is(aEvent.getTargetRanges().length, 0,
|
||||||
'getTargetRanges() of "input" event should return empty array');
|
'getTargetRanges() of "input" event should return empty array');
|
||||||
|
removeEventListeners();
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeEventListeners() {
|
||||||
input.removeEventListener("beforeinput", handleBeforeInput, true);
|
input.removeEventListener("beforeinput", handleBeforeInput, true);
|
||||||
input.removeEventListener("input", handleInput, true);
|
input.removeEventListener("input", handleInput, true);
|
||||||
SimpleTest.finish();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function runTest() {
|
|
||||||
input.addEventListener("beforeinput", handleBeforeInput, true);
|
input.addEventListener("beforeinput", handleBeforeInput, true);
|
||||||
input.addEventListener("input", handleInput, true);
|
input.addEventListener("input", handleInput, true);
|
||||||
input.addEventListener("keydown", function handleEnterDown(e) {
|
input.addEventListener("keydown", function handleEnterDown(e) {
|
||||||
|
@ -88,30 +93,31 @@ function runTest() {
|
||||||
input.removeEventListener("keydown", handleEnterDown, true);
|
input.removeEventListener("keydown", handleEnterDown, true);
|
||||||
form.submit();
|
form.submit();
|
||||||
}, true);
|
}, true);
|
||||||
|
form.addEventListener("submit", () => {
|
||||||
registerPopupShownListener(() => {
|
info("Submit");
|
||||||
synthesizeKey("KEY_ArrowDown");
|
ok(false, "The form should not be submitted");
|
||||||
synthesizeKey("KEY_Enter"); // select the first entry in the popup
|
removeEventListeners();
|
||||||
|
resolve();
|
||||||
|
}, { once: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const autocompleteShown = promiseACShown();
|
||||||
|
|
||||||
// Focus the input before adjusting.value so that the caret goes to the end
|
// Focus the input before adjusting.value so that the caret goes to the end
|
||||||
// (since OS X doesn't show the dropdown otherwise).
|
// (since OS X doesn't show the dropdown otherwise).
|
||||||
input.focus();
|
input.focus();
|
||||||
input.value = "value";
|
input.value = "value";
|
||||||
input.focus();
|
input.focus();
|
||||||
synthesizeKey("KEY_ArrowDown");
|
synthesizeKey("KEY_ArrowDown");
|
||||||
}
|
|
||||||
|
|
||||||
function startTest() {
|
await autocompleteShown;
|
||||||
updateFormHistory([
|
|
||||||
{ op: "remove" },
|
|
||||||
{ op: "add", fieldname: "field1", value: "value1" },
|
|
||||||
], runTest);
|
|
||||||
}
|
|
||||||
|
|
||||||
window.onload = startTest;
|
synthesizeKey("KEY_ArrowDown");
|
||||||
|
synthesizeKey("KEY_Enter"); // select the first entry in the popup
|
||||||
|
|
||||||
|
await submitTested;
|
||||||
|
});
|
||||||
|
|
||||||
SimpleTest.waitForExplicitFinish();
|
|
||||||
</script>
|
</script>
|
||||||
</pre>
|
</pre>
|
||||||
</body>
|
</body>
|
||||||
|
|
Загрузка…
Ссылка в новой задаче