Bug 1291381 - Fix helper_long_tap.html and helper_tap_passive.html to work with the Windows long-press event sequence. r=botond

MozReview-Commit-ID: ENJjgJ9dhCd
This commit is contained in:
Kartikaya Gupta 2016-10-07 15:10:46 -04:00
Родитель 758d479cf5
Коммит 102b429267
2 изменённых файлов: 54 добавлений и 17 удалений

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

@ -17,22 +17,50 @@ function longPressLink() {
var eventsFired = 0;
function recordEvent(e) {
switch (eventsFired) {
case 0: is(e.type, 'touchstart', 'Got a touchstart'); break;
case 1: is(e.type, 'contextmenu', 'Got a contextmenu'); e.preventDefault(); break;
case 2: is(e.type, 'touchcancel', 'Got a touchcancel'); break;
default: ok(false, 'Got an unexpected event of type ' + e.type); break;
}
eventsFired++;
if (getPlatform() == "windows") {
// On Windows we get a mouselongtap event once the long-tap has been detected
// by APZ, and that's what we use as the trigger to lift the finger. That then
// triggers the contextmenu. This matches the platform convention.
switch (eventsFired) {
case 0: is(e.type, 'touchstart', 'Got a touchstart'); break;
case 1:
is(e.type, 'mouselongtap', 'Got a mouselongtap');
synthesizeNativeTouch(document.getElementById('b'), 5, 5, SpecialPowers.DOMWindowUtils.TOUCH_REMOVE);
break;
case 2: is(e.type, 'touchend', 'Got a touchend'); break;
case 3: is(e.type, 'contextmenu', 'Got a contextmenu'); e.preventDefault(); break;
default: ok(false, 'Got an unexpected event of type ' + e.type); break;
}
eventsFired++;
if (eventsFired == 3) {
synthesizeNativeTouch(document.getElementById('b'), 5, 5, SpecialPowers.DOMWindowUtils.TOUCH_REMOVE, function() {
dump("Finished synthesizing touch-end, doing an APZ flush to see if any more unexpected events come through...\n");
if (eventsFired == 4) {
dump("Finished waiting for events, doing an APZ flush to see if any more unexpected events come through...\n");
flushApzRepaints(function() {
dump("Done APZ flush, ending test...\n");
subtestDone(); // closing the window should dismiss the context menu dialog
subtestDone();
});
});
}
} else {
// On non-Windows platforms we get a contextmenu event once the long-tap has
// been detected. Since we prevent-default that, we don't get a mouselongtap
// event at all, and instead get a touchcancel.
switch (eventsFired) {
case 0: is(e.type, 'touchstart', 'Got a touchstart'); break;
case 1: is(e.type, 'contextmenu', 'Got a contextmenu'); e.preventDefault(); break;
case 2: is(e.type, 'touchcancel', 'Got a touchcancel'); break;
default: ok(false, 'Got an unexpected event of type ' + e.type); break;
}
eventsFired++;
if (eventsFired == 3) {
synthesizeNativeTouch(document.getElementById('b'), 5, 5, SpecialPowers.DOMWindowUtils.TOUCH_REMOVE, function() {
dump("Finished synthesizing touch-end, doing an APZ flush to see if any more unexpected events come through...\n");
flushApzRepaints(function() {
dump("Done APZ flush, ending test...\n");
subtestDone();
});
});
}
}
}
@ -40,6 +68,7 @@ window.addEventListener('touchstart', recordEvent, { passive: true, capture: tru
window.addEventListener('touchend', recordEvent, { passive: true, capture: true });
window.addEventListener('touchcancel', recordEvent, true);
window.addEventListener('contextmenu', recordEvent, true);
SpecialPowers.addChromeEventListener('mouselongtap', recordEvent, true);
waitUntilApzStable()
.then(longPressLink);

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

@ -30,10 +30,14 @@ function recordEvent(e) {
// it needs to wait until both the touchstart and touchmove event are handled
// by the main thread. In this case there is no touchmove at all, so APZ would
// end up waiting indefinitely and time out the test. The fact that we get this
// contextmenu event at all means that APZ decided not to wait for the content
// response, which is the desired behaviour, since the touchstart listener was
// registered as a passive listener.
is(e.type, 'contextmenu', 'Got a contextmenu');
// contextmenu event (mouselongtap on Windows) at all means that APZ decided
// not to wait for the content response, which is the desired behaviour, since
// the touchstart listener was registered as a passive listener.
if (getPlatform() == "windows") {
is(e.type, 'mouselongtap', 'Got a mouselongtap');
} else {
is(e.type, 'contextmenu', 'Got a contextmenu');
}
e.preventDefault();
synthesizeNativeTouch(document.getElementById('b'), 5, 5, SpecialPowers.DOMWindowUtils.TOUCH_REMOVE, function() {
@ -43,7 +47,11 @@ function recordEvent(e) {
}
window.addEventListener('touchstart', recordEvent, { passive: true, capture: true });
window.addEventListener('contextmenu', recordEvent, true);
if (getPlatform() == "windows") {
SpecialPowers.addChromeEventListener('mouselongtap', recordEvent, true);
} else {
window.addEventListener('contextmenu', recordEvent, true);
}
waitUntilApzStable()
.then(longPressLink);