test_dnd_with_modifiers.html (2544B)
1 <!DOCTYPE html> 2 <html> 3 <meta charset="utf-8"> 4 <title>Test dragstart, drag, dragover, drop, dragend with keyboard modifiers</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <script src="/tests/SimpleTest/EventUtils.js"></script> 7 <link rel="stylesheet" href="/tests/SimpleTest/test.css"> 8 <div id="test"></div> 9 <script> 10 SimpleTest.waitForExplicitFinish(); 11 12 SimpleTest.waitForFocus(() => { 13 let dragEvents = ["dragstart", "drag", "dragend"]; 14 let dropEvents = ["dragover", "drop"]; 15 let source = document.getElementById("source"); 16 let target = document.getElementById("target"); 17 18 dragEvents.forEach((ev, idx, array) => { 19 source.addEventListener(ev, (e) => { 20 ok(e.ctrlKey, e.type + ".ctrlKey should be true"); 21 ok(!e.shiftKey, e.type + ".shiftKey should be false"); 22 ok(e.altKey, e.type + ".altKey should be true"); 23 }, {once: true}); 24 }); 25 26 dropEvents.forEach((ev, idx, array) => { 27 target.addEventListener(ev, (e) => { 28 ok(e.ctrlKey, e.type + ".ctrlKey should be true"); 29 ok(!e.shiftKey, e.type + ".shiftKey should be false"); 30 ok(e.altKey, e.type + ".altKey should be true"); 31 }, {once: true}); 32 }); 33 34 source.addEventListener("dragstart", (e) => { 35 e.preventDefault(); 36 }, {once: true}); 37 38 source.addEventListener("dragend", (e) => { 39 SimpleTest.finish(); 40 }); 41 42 let selection = window.getSelection(); 43 selection.selectAllChildren(source); 44 45 synthesizeMouse(source, 1, 1, {type: "mousedown", ctrlKey: true, altKey: true}, window); 46 synthesizeMouse(source, 10, 10, {type: "mousemove", ctrlKey: true, altKey: true}, window); 47 synthesizeMouse(source, 10, 10, {type: "mouseup", ctrlKey: true, altKey: true}, window); 48 49 let dragEvent = { 50 type: "drag", 51 ctrlKey: true, 52 altKey: true, 53 }; 54 sendDragEvent(dragEvent, source, window); 55 56 let rect = target.getBoundingClientRect(); 57 let dropEvent = { 58 ctrlKey: true, 59 altKey: true, 60 clientX: rect.left + rect.width / 2, 61 clientY: rect.top + rect.height / 2, 62 }; 63 selection.selectAllChildren(source); 64 synthesizeDrop(source, target, [], "copy", window, window, dropEvent); 65 66 let dragEndEvent = { 67 type: "dragend", 68 ctrlKey: true, 69 altKey: true, 70 }; 71 sendDragEvent(dragEndEvent, source, window); 72 }); 73 </script> 74 <body> 75 <span id="source" style="font-size: 40px;">test</span> 76 <div id="target" contenteditable="true" width="50" height="50"></div> 77 </body> 78 </html>