paste-multiline-text-as-plaintext.tentative.https.html (2116B)
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <meta name="variant" content="?white-space=pre"> 6 <meta name="variant" content="?white-space=pre-line"> 7 <meta name="variant" content="?white-space=pre-wrap"> 8 <title>Inserting multiline text shouldn't be split to multiple Text nodes unless using br elements</title> 9 <script src="/resources/testharness.js"></script> 10 <script src="/resources/testharnessreport.js"></script> 11 <script src="/resources/testdriver.js"></script> 12 <script src="/resources/testdriver-vendor.js"></script> 13 <script src="/resources/testdriver-actions.js"></script> 14 <script src="../include/editor-test-utils.js"></script> 15 <script> 16 "use strict"; 17 18 const searchParams = new URLSearchParams(document.location.search); 19 const whiteSpace = searchParams.get("white-space"); 20 21 document.addEventListener("DOMContentLoaded", () => { 22 promise_test(async () => { 23 const editingHost = document.querySelector("div[contenteditable]"); 24 editingHost.style.whiteSpace = whiteSpace; 25 const utils = new EditorTestUtils(editingHost); 26 27 const pre = document.querySelector("pre"); 28 await test_driver.click(pre); // Ensure user activation 29 getSelection().selectAllChildren(pre); 30 await utils.sendCopyShortcutKey(); 31 32 editingHost.focus(); 33 utils.setupEditingHost("<p>{}<br></p>"); 34 await utils.sendPasteAsPlaintextShortcutKey(); 35 if (editingHost.innerHTML == "<p>abc<br>def<br>ghi</p>") { 36 // It's fine to use <br> for line breaks, at least, out of scope of this test. 37 assert_equals(editingHost.innerHTML, "<p>abc<br>def<br>ghi</p>"); 38 return; 39 } 40 41 // The form in https://discussions.apple.com/ expects that pasted text is 42 // not split at each linefeed. For backward compatibility, browsers need 43 // to keep this behavior. 44 assert_equals(editingHost.innerHTML, "<p>abc\ndef\nghi</p>"); 45 assert_equals( 46 editingHost.querySelector("p").childNodes.length, 47 1, 48 "Pasted text should be in a single Text node" 49 ); 50 }); 51 }, {once: true}); 52 </script> 53 </head> 54 <body> 55 <pre>abc 56 def 57 ghi</pre> 58 <div contenteditable="true"></div> 59 </body> 60 </html>