Bug 1492766 - Part 3: Update the test_pointer_event.html for test of pointer id spoofing r=masayuki,arthuredelstein

This test add a check for pointer id to make sure it always reply the
spoofed pointer id when resistfingerpritning is enabled. It also extend
the original test of pointer capture events into a test which tests
mouse and touch interfaces to make sure pointer capture events is
correctly filed even with the spoofed interface id. In addition, it also
adds test for that set/releasePointerCapture only accepts spoofed
pointer id when fingerprinting resistance is enabled.

Depends on D9532

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Tim Huang 2018-11-14 07:17:51 +00:00
Родитель 6df9f5c18d
Коммит cf769d5a6d
1 изменённых файлов: 61 добавлений и 8 удалений

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

@ -24,6 +24,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1363508
// A helper function to check that whether the pointer is spoofed correctly.
function checkPointerEvent(aEvent) {
is(aEvent.pointerId, utils.DEFAULT_MOUSE_POINTER_ID,
"The spoofed pointer event should always have the mouse pointer id.");
is(aEvent.width, 1, "The spoofed pointer event should always have width as 1.");
is(aEvent.height, 1, "The spoofed pointer event should always have width as 1.");
if (aEvent.buttons === 0) {
@ -111,13 +113,65 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1363508
}
// A test for gotpointercapture and lostpointercapture events.
// We would also test releasePointerCapture for only accepting spoofed pointer
// Id here.
async function doTestForPointerCapture() {
// We test for both mouse and touch to see whether the capture events are
// filed properly. We don't check pen here since it won't file capture
// events.
let inputSources = [ MouseEvent.MOZ_SOURCE_MOUSE,
MouseEvent.MOZ_SOURCE_TOUCH ];
for (let inputSource of inputSources) {
function eventHandler(event) {
checkPointerEvent(event);
if (event.type === "pointerdown") {
target0.setPointerCapture(event.pointerId);
} else if (event.type === "pointermove") {
if (inputSource === MouseEvent.MOZ_SOURCE_TOUCH) {
try {
target0.releasePointerCapture(utils.DEFAULT_TOUCH_POINTER_ID);
ok(false, "The releasePointerCapture should fail here, but it is not.");
} catch (e) {
ok(true, "The releasePointerCapture fails properly.");
}
}
target0.releasePointerCapture(event.pointerId);
}
}
let eventPromises = [
promiseForEvent("pointerover", eventHandler),
promiseForEvent("pointerenter", eventHandler),
promiseForEvent("pointerdown", eventHandler),
promiseForEvent("gotpointercapture", eventHandler),
promiseForEvent("pointermove", eventHandler),
promiseForEvent("lostpointercapture", eventHandler),
promiseForEvent("pointerup", eventHandler),
promiseForEvent("pointerout", eventHandler),
promiseForEvent("pointerleave", eventHandler),
];
synthesizeMouse(target0, 5, 5, { type: "mousedown", inputSource });
synthesizeMouse(target0, 5, 5, { type: "mousemove", inputSource });
synthesizeMouse(target0, 5, 5, { type: "mouseup", inputSource });
synthesizeMouse(target1, 5, 5, { type: "mousemove", inputSource });
await Promise.all(eventPromises);
}
}
// A test for setPointerCapture() for only accepting spoofed pointer id.
async function doTestForSetPointerCapture() {
function eventHandler(event) {
checkPointerEvent(event);
if (event.type === "pointerdown") {
target0.setPointerCapture(event.pointerId);
} else if (event.type === "pointermove") {
target0.releasePointerCapture(event.pointerId);
try {
target0.setPointerCapture(utils.DEFAULT_TOUCH_POINTER_ID);
ok(false, "The setPointerCapture should fail here, but it is not.");
} catch (e) {
ok(true, "The setPointerCapture fails properly.");
}
}
}
@ -125,17 +179,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1363508
promiseForEvent("pointerover", eventHandler),
promiseForEvent("pointerenter", eventHandler),
promiseForEvent("pointerdown", eventHandler),
promiseForEvent("gotpointercapture", eventHandler),
promiseForEvent("pointermove", eventHandler),
promiseForEvent("lostpointercapture", eventHandler),
promiseForEvent("pointerup", eventHandler),
promiseForEvent("pointerout", eventHandler),
promiseForEvent("pointerleave", eventHandler),
];
synthesizeMouse(target0, 5, 5, { type: "mousedown", inputSource: MouseEvent.MOZ_SOURCE_TOUCH, pressure: 0.75 });
synthesizeMouse(target0, 5, 5, { type: "mousemove", inputSource: MouseEvent.MOZ_SOURCE_TOUCH, pressure: 0.75 });
synthesizeMouse(target0, 5, 5, { type: "mouseup", inputSource: MouseEvent.MOZ_SOURCE_TOUCH, pressure: 0.75 });
synthesizeMouse(target0, 5, 5, { type: "mousedown", inputSource: MouseEvent.MOZ_SOURCE_TOUCH });
synthesizeMouse(target0, 5, 5, { type: "mousemove", inputSource: MouseEvent.MOZ_SOURCE_TOUCH });
synthesizeMouse(target0, 5, 5, { type: "mouseup", inputSource: MouseEvent.MOZ_SOURCE_TOUCH });
await Promise.all(eventPromises);
}
@ -175,6 +227,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1363508
await doTestForTouchPointerCancelEvent();
await doTestForPenPointerEvent();
await doTestForPointerCapture();
await doTestForSetPointerCapture();
await doTestNoSpoofingForScriptGeneratedEvent();
SimpleTest.finish();