test_sanitizer_on_paste.html (1431B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Test pasting table rows</title> 6 <script src="/tests/SimpleTest/SimpleTest.js"></script> 7 <script src="/tests/SimpleTest/EventUtils.js"></script> 8 <link rel="stylesheet" href="/tests/SimpleTest/test.css"/> 9 </head> 10 <body> 11 <textarea></textarea> 12 <div contenteditable="true">Paste target</div> 13 <script> 14 SimpleTest.waitForExplicitFinish(); 15 function fail() { 16 ok(false, "Should not run event handlers."); 17 } 18 document.addEventListener('copy', ev => { 19 dump("IN LISTENER\n"); 20 const payload = `<svg><style><image href=file_sanitizer_on_paste.sjs onerror=fail() onload=fail()>` 21 22 ev.preventDefault(); 23 ev.clipboardData.setData('text/html', payload); 24 ev.clipboardData.setData('text/plain', payload); 25 }); 26 27 document.getElementsByTagName("textarea")[0].focus(); 28 synthesizeKey("c", { accelKey: true } /* aEvent*/); 29 30 let div = document.getElementsByTagName("div")[0]; 31 div.focus(); 32 synthesizeKey("v", { accelKey: true } /* aEvent*/); 33 34 let svg = div.firstChild; 35 is(svg.nodeName, "svg", "Node name should be svg"); 36 37 let style = svg.firstChild; 38 if (style) { 39 is(style.firstChild, null, "Style should not have child nodes."); 40 } else { 41 ok(false, "Should have gotten a node."); 42 } 43 44 var s = document.createElement("script"); 45 s.src = "file_sanitizer_on_paste.sjs?report=1"; 46 document.body.appendChild(s); 47 </script> 48 </body>