OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <script src="../../resources/testharness.js"></script> | 2 <script src="../../resources/testharness.js"></script> |
3 <script src="../../resources/testharnessreport.js"></script> | 3 <script src="../../resources/testharnessreport.js"></script> |
4 <script> | 4 <script> |
5 var contextForMenu; | 5 var contextForMenu; |
6 function catchContextMenu(event) { | 6 function catchContextMenu(event) { |
7 contextForMenu = event.currentTarget.tagName; | 7 contextForMenu = event.currentTarget.tagName; |
8 } | 8 } |
| 9 |
| 10 function focusLinkAndAssertLinkIsTargetOfContextMenu() { |
| 11 eventSender.keyDown('Escape'); // Hide menu. |
| 12 document.querySelector('A').focus(); |
| 13 contextForMenu = undefined; |
| 14 eventSender.keyDown('ContextMenu'); |
| 15 assert_equals(contextForMenu, 'A', |
| 16 'ContextMenu should use the focused link as target.'); |
| 17 } |
9 </script> | 18 </script> |
10 | 19 |
| 20 <div contenteditable oncontextmenu="catchContextMenu(event);">Some editable text
.</div> |
| 21 <span oncontextmenu="catchContextMenu(event);">Some text to select.</span> |
11 <input oncontextmenu="catchContextMenu(event);"> | 22 <input oncontextmenu="catchContextMenu(event);"> |
12 <a href="www" oncontextmenu="catchContextMenu(event);">A link</a> | 23 <a href="www" oncontextmenu="catchContextMenu(event);">A link</a> |
13 | 24 |
14 <script> | 25 <script> |
15 test(function() { | 26 test(function() { |
16 assert_exists(window, 'eventSender', 'This test requires eventSender.'); | 27 assert_exists(window, 'eventSender', 'This test requires eventSender.'); |
17 | 28 |
18 document.querySelector('INPUT').focus(); | 29 document.querySelector('INPUT').focus(); |
19 eventSender.keyDown('ContextMenu'); | 30 eventSender.keyDown('ContextMenu'); |
20 assert_equals(contextForMenu, 'INPUT', | 31 assert_equals(contextForMenu, 'INPUT', |
21 'ContextMenu should use the focused input field as context.'); | 32 'ContextMenu should use the focused input field as target.'); |
| 33 focusLinkAndAssertLinkIsTargetOfContextMenu(); |
| 34 }, 'ContextMenu should target the focused link (not the unfocused field).'); |
22 | 35 |
23 // Hide INPUT's context menu before we display A's context menu. | 36 test(function() { |
24 eventSender.keyDown('Escape'); | 37 assert_exists(window, 'eventSender', 'This test requires eventSender.'); |
25 | 38 |
26 document.querySelector('A').focus(); | 39 document.querySelector('div').focus(); |
27 eventSender.keyDown('ContextMenu'); | 40 eventSender.keyDown('ContextMenu'); |
28 assert_equals(contextForMenu, 'A', | 41 assert_equals(contextForMenu, 'DIV', |
29 'ContextMenu should use the focused link as context.'); | 42 'ContextMenu should use the editable div\'s caret as target.'); |
| 43 focusLinkAndAssertLinkIsTargetOfContextMenu(); |
| 44 }, 'ContextMenu should target the focused link (not the div\'s caret).'); |
30 | 45 |
31 }, 'ContextMenu should always follow focused element.'); | 46 test(function() { |
| 47 assert_exists(window, 'eventSender', 'This test requires eventSender.'); |
| 48 |
| 49 const div = document.querySelector('div'); |
| 50 div.focus(); |
| 51 window.getSelection().selectAllChildren(div); |
| 52 eventSender.keyDown('ContextMenu'); |
| 53 assert_equals(contextForMenu, 'DIV', |
| 54 'ContextMenu should use the editable div\'s range selection as target.'); |
| 55 focusLinkAndAssertLinkIsTargetOfContextMenu(); |
| 56 }, 'ContextMenu should target the focused link (not the div\'s selection).'); |
| 57 |
| 58 test(function() { |
| 59 assert_exists(window, 'eventSender', 'This test requires eventSender.'); |
| 60 |
| 61 const span = document.querySelector('span'); |
| 62 window.getSelection().selectAllChildren(span); |
| 63 focusLinkAndAssertLinkIsTargetOfContextMenu(); |
| 64 }, 'ContextMenu should target the focused link (not the unfocused selection).'); |
32 </script> | 65 </script> |
OLD | NEW |