From bac3e2671cfeff820d568bb6e0a70be7c42c508e Mon Sep 17 00:00:00 2001 From: Brad Werth Date: Fri, 17 Aug 2018 18:59:36 +0000 Subject: [PATCH] Bug 1482968 Part 2: Add a test of modifier key clicks and drags on input elements. r=smaug! Depends on D3450 Differential Revision: https://phabricator.services.mozilla.com/D3451 --HG-- extra : moz-landing-system : lando --- .../forms/test_input_number_mouse_events.html | 22 +++++++++++++++++++ ...st_input_range_mouse_and_touch_events.html | 16 +++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/dom/html/test/forms/test_input_number_mouse_events.html b/dom/html/test/forms/test_input_number_mouse_events.html index 15b1eac4c6f1..32434aa393c0 100644 --- a/dom/html/test/forms/test_input_number_mouse_events.html +++ b/dom/html/test/forms/test_input_number_mouse_events.html @@ -63,6 +63,28 @@ function test() { synthesizeMouse(input, SPIN_DOWN_X, SPIN_DOWN_Y, { type: "mouseup" }); is(input.value, "0", "Test mouseup on spin-down button"); + // Test clicks with modifiers that mean we should ignore the click: + var modifiersIgnore = ["altGrKey", "fnKey", "osKey"]; + for (var modifier of modifiersIgnore) { + input.value = 0; + var eventParams = { type: "mousedown" }; + eventParams[modifier] = true; + synthesizeMouse(input, SPIN_UP_X, SPIN_UP_Y, eventParams); + is(input.value, "0", "We should ignore mousedown on spin-up button with modifier " + modifier); + synthesizeMouse(input, SPIN_UP_X, SPIN_UP_Y, { type: "mouseup" }); + } + + // Test clicks with modifiers that mean we should allow the click: + var modifiersAllow = ["shiftKey", "ctrlKey", "altKey", "metaKey"]; + for (var modifier of modifiersAllow) { + input.value = 0; + var eventParams = { type: "mousedown" }; + eventParams[modifier] = true; + synthesizeMouse(input, SPIN_UP_X, SPIN_UP_Y, eventParams); + is(input.value, "1", "We should allow mousedown on spin-up button with modifier " + modifier); + synthesizeMouse(input, SPIN_UP_X, SPIN_UP_Y, { type: "mouseup" }); + } + // Test step="any" behavior: input.value = 0; var oldStep = input.step; diff --git a/dom/html/test/forms/test_input_range_mouse_and_touch_events.html b/dom/html/test/forms/test_input_range_mouse_and_touch_events.html index aaa1efa56f6a..1169ca82c075 100644 --- a/dom/html/test/forms/test_input_range_mouse_and_touch_events.html +++ b/dom/html/test/forms/test_input_range_mouse_and_touch_events.html @@ -134,9 +134,9 @@ function test(synthesizeFunc, clickOrTap, startName, moveName, endName) { elem.style.direction = "ltr"; // reset direction flush(); - // Test mouse/touch events with modifiers are ignored: - var modifiers = ["shiftKey", "ctrlKey", "altKey", "metaKey", "accelKey", "altGrKey", "fnKey", "osKey"]; - for (var modifier of modifiers) { + // Test mouse/touch events with certain modifiers are ignored: + var modifiersIgnore = ["ctrlKey", "altGrKey", "fnKey", "osKey"]; + for (var modifier of modifiersIgnore) { elem.value = QUARTER_OF_RANGE; var eventParams = {}; eventParams[modifier] = true; @@ -144,6 +144,16 @@ function test(synthesizeFunc, clickOrTap, startName, moveName, endName) { is(elem.value, QUARTER_OF_RANGE, "Test " + clickOrTap + " in the middle of range with " + modifier + " modifier key is ignored"); } + // Test mouse/touch events with certain modifiers are allowed: + var modifiersAllow = ["shiftKey", "altKey", "metaKey"]; + for (var modifier of modifiersAllow) { + elem.value = QUARTER_OF_RANGE; + var eventParams = {}; + eventParams[modifier] = true; + synthesizeFunc(elem, midX, midY, eventParams); + is(elem.value, MIDDLE_OF_RANGE, "Test " + clickOrTap + " in the middle of range with " + modifier + " modifier key is allowed"); + } + // Test that preventDefault() works: function preventDefault(e) { e.preventDefault();