OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Test Context Menu Key, Shift+F10 behavior when preventing default</title> |
| 3 <script src="../../resources/testharness.js"></script> |
| 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 <a href="#" id="anchor">Anchor</a> |
| 6 <script> |
| 7 test(function() { |
| 8 assert_not_equals(window.eventSender, undefined, 'This test requires eventSe
nder.'); |
| 9 |
| 10 var contextMenuFired = false; |
| 11 var preventKeydown = false; |
| 12 var preventKeyup = false; |
| 13 var anchor = document.getElementById('anchor'); |
| 14 anchor.addEventListener('contextmenu', () => contextMenuFired = true); |
| 15 anchor.addEventListener('keydown', event => preventKeydown ? event.preventDe
fault() : true); |
| 16 anchor.addEventListener('keyup', event => preventKeyup ? event.preventDefaul
t() : true); |
| 17 |
| 18 function testContextMenuEvent(key, modifiers, shouldFire, shouldPreventKeydo
wn, shouldPreventKeyup) { |
| 19 contextMenuFired = false; |
| 20 preventKeydown = shouldPreventKeydown; |
| 21 preventKeyup = shouldPreventKeyup; |
| 22 anchor.focus(); |
| 23 eventSender.keyDown(key, modifiers); |
| 24 // Esc key to hide context menu |
| 25 eventSender.keyDown("Escape"); |
| 26 assert_equals(contextMenuFired, shouldFire, `${key}+${modifiers} opens C
ontext Menu:${shouldFire} PreventKeydown:${shouldPreventKeydown} PreventKeyup:${
shouldPreventKeyup}.`); |
| 27 } |
| 28 |
| 29 // Shift+F10 should always bind to keydown. |
| 30 testContextMenuEvent('F10', ['shiftKey'], true, false, false); |
| 31 testContextMenuEvent('F10', ['shiftKey'], false, true, false); |
| 32 testContextMenuEvent('F10', ['shiftKey'], true, false, true); |
| 33 |
| 34 // ContextMenu key should bind to keyup on Windows and keydown on other plat
forms. |
| 35 testContextMenuEvent('ContextMenu', [], true, false, false); |
| 36 const isWin = navigator.platform.indexOf('Win') == 0; |
| 37 if (isWin) { |
| 38 testContextMenuEvent('ContextMenu', [], true, true, false); |
| 39 testContextMenuEvent('ContextMenu', [], false, false, true); |
| 40 } else { |
| 41 testContextMenuEvent('ContextMenu', [], false, true, false); |
| 42 testContextMenuEvent('ContextMenu', [], true, false, true); |
| 43 } |
| 44 }, 'Shift+F10 should bind to keydown, ContextMenu key should bind to keyup only
on Windows.'); |
| 45 </script> |
OLD | NEW |