clipboard_pastefile.html (1389B)
1 <html><body> 2 <script> 3 async function checkPaste(event) { 4 let result = null; 5 try { 6 result = await checkPasteHelper(event); 7 } catch (e) { 8 result = e.toString(); 9 } 10 11 document.dispatchEvent(new CustomEvent('testresult', { 12 detail: { result } 13 })); 14 } 15 16 function is(a, b, msg) { 17 if (!Object.is(a, b)) { 18 throw new Error(`FAIL: expected ${b} got ${a} - ${msg}`); 19 } 20 } 21 22 async function checkPasteHelper(event) { 23 let dt = event.clipboardData; 24 25 is(dt.types.length, 2, "Correct number of types"); 26 27 // TODO: Remove application/x-moz-file from content. 28 is(dt.types[0], "application/x-moz-file", "First type") 29 is(dt.types[1], "Files", "Last type must be Files"); 30 31 is(dt.getData("text/plain"), "", "text/plain found with getData"); 32 is(dt.getData("application/x-moz-file"), "", "application/x-moz-file found with getData"); 33 34 is(dt.files.length, 1, "Correct number of files"); 35 is(dt.files[0].name, "test-file.txt", "Correct file name"); 36 is(dt.files[0].type, "text/plain", "Correct file type"); 37 38 is(dt.items.length, 1, "Correct number of items"); 39 is(dt.items[0].kind, "file", "Correct item kind"); 40 is(dt.items[0].type, "text/plain", "Correct item type"); 41 42 let file = dt.files[0]; 43 is(await file.text(), "Hello World!", "Pasted file contains right text"); 44 45 return file.name; 46 } 47 </script> 48 49 <input id="input" onpaste="checkPaste(event)"> 50 51 52 </body></html>