Bug 981248 - Fix test_input_number_mouse_events.html to not dispatch mouse events from input events. r=masayuki

The test fails with my <input type=number> rewrite because editor fails to
dispatch one input event caused by these mouse events.

The reason for this is that we schedule them from an input event, which fires
from here:

  https://searchfox.org/mozilla-central/rev/6305f6935f496b3a302c7afcc579399a4217729c/editor/libeditor/EditorBase.cpp#965

Not how at that point we still haven't decremented mPlaceholderBatch. That means
that other stuff that triggers input events from there will not dispatch events.

I think that's a bit unexpected, but it is a preexisting problem, and can't
happen for users because mouse events go through the event loop.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-12-20 13:54:48 +00:00
Родитель ea808c81bb
Коммит ff130db72b
1 изменённых файлов: 13 добавлений и 3 удалений

Просмотреть файл

@ -54,6 +54,7 @@ function checkInputEvent(aEvent, aDescription) {
todo(aEvent instanceof InputEvent, `"input" event should be dispatched with InputEvent interface on input element whose type is number ${aDescription}`); todo(aEvent instanceof InputEvent, `"input" event should be dispatched with InputEvent interface on input element whose type is number ${aDescription}`);
is(aEvent.cancelable, false, `"input" event should be never cancelable on input element whose type is number ${aDescription}`); is(aEvent.cancelable, false, `"input" event should be never cancelable on input element whose type is number ${aDescription}`);
is(aEvent.bubbles, true, `"input" event should always bubble on input element whose type is number ${aDescription}`); is(aEvent.bubbles, true, `"input" event should always bubble on input element whose type is number ${aDescription}`);
info(`Data: ${aEvent.data}, value: ${aEvent.target.value}`);
} }
function test() { function test() {
@ -132,6 +133,10 @@ function runNextSpinTest() {
nextTest(); nextTest();
} }
function waitForTick() {
return new Promise(SimpleTest.executeSoon);
}
const SETTIMEOUT_DELAY = 500; const SETTIMEOUT_DELAY = 500;
var spinTests = [ var spinTests = [
@ -140,15 +145,17 @@ var spinTests = [
function() { function() {
var inputEventCount = 0; var inputEventCount = 0;
input.value = 0; input.value = 0;
input.addEventListener("input", function(evt) { input.addEventListener("input", async function(evt) {
++inputEventCount; ++inputEventCount;
checkInputEvent(evt, "#1"); checkInputEvent(evt, "#1");
if (inputEventCount == 3) { if (inputEventCount == 3) {
is(input.value, "3", "Testing spin-up button"); is(input.value, "3", "Testing spin-up button");
await waitForTick();
synthesizeMouse(input, SPIN_DOWN_X, SPIN_DOWN_Y, { type: "mousemove" }); synthesizeMouse(input, SPIN_DOWN_X, SPIN_DOWN_Y, { type: "mousemove" });
} else if (inputEventCount == 6) { } else if (inputEventCount == 6) {
is(input.value, "0", "Testing spin direction is reversed after mouse moves from spin-up button to spin-down button"); is(input.value, "0", "Testing spin direction is reversed after mouse moves from spin-up button to spin-down button");
input.removeEventListener("input", arguments.callee); input.removeEventListener("input", arguments.callee);
await waitForTick();
synthesizeMouse(input, SPIN_DOWN_X, SPIN_DOWN_Y, { type: "mouseup" }); synthesizeMouse(input, SPIN_DOWN_X, SPIN_DOWN_Y, { type: "mouseup" });
runNextSpinTest(); runNextSpinTest();
} }
@ -161,15 +168,17 @@ var spinTests = [
function() { function() {
var inputEventCount = 0; var inputEventCount = 0;
input.value = 0; input.value = 0;
input.addEventListener("input", function(evt) { input.addEventListener("input", async function(evt) {
++inputEventCount; ++inputEventCount;
checkInputEvent(evt, "#2"); checkInputEvent(evt, "#2");
if (inputEventCount == 3) { if (inputEventCount == 3) {
is(input.value, "-3", "Testing spin-down button"); is(input.value, "-3", "Testing spin-down button");
await waitForTick();
synthesizeMouse(input, SPIN_UP_X, SPIN_UP_Y, { type: "mousemove" }); synthesizeMouse(input, SPIN_UP_X, SPIN_UP_Y, { type: "mousemove" });
} else if (inputEventCount == 6) { } else if (inputEventCount == 6) {
is(input.value, "0", "Testing spin direction is reversed after mouse moves from spin-down button to spin-up button"); is(input.value, "0", "Testing spin direction is reversed after mouse moves from spin-down button to spin-up button");
input.removeEventListener("input", arguments.callee); input.removeEventListener("input", arguments.callee);
await waitForTick();
synthesizeMouse(input, SPIN_UP_X, SPIN_UP_Y, { type: "mouseup" }); synthesizeMouse(input, SPIN_UP_X, SPIN_UP_Y, { type: "mouseup" });
runNextSpinTest(); runNextSpinTest();
} }
@ -182,10 +191,11 @@ var spinTests = [
function() { function() {
var inputEventCount = 0; var inputEventCount = 0;
input.value = 0; input.value = 0;
input.addEventListener("input", function(evt) { input.addEventListener("input", async function(evt) {
++inputEventCount; ++inputEventCount;
checkInputEvent(evt, "#3"); checkInputEvent(evt, "#3");
if (inputEventCount == 3) { if (inputEventCount == 3) {
await waitForTick();
synthesizeMouse(input, -1, -1, { type: "mousemove" }); synthesizeMouse(input, -1, -1, { type: "mousemove" });
var eventHandler = arguments.callee; var eventHandler = arguments.callee;
setTimeout(function() { setTimeout(function() {