undo-insertparagraph-after-moving-split-nodes.html (3359B)
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <meta name="timeout" content="long"> 6 <title>Undo after splitting nodes are moved</title> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="/resources/testdriver.js"></script> 10 <script src="/resources/testdriver-vendor.js"></script> 11 <script src="/resources/testdriver-actions.js"></script> 12 <script src="../include/editor-test-utils.js"></script> 13 </head> 14 <body> 15 <div contenteditable></div> 16 <script> 17 "use strict"; 18 19 document.execCommand("defaultParagraphSeparator", false, "div"); 20 const utils = 21 new EditorTestUtils(document.querySelector("div[contenteditable]")); 22 23 promise_test(async t => { 24 utils.setupEditingHost( 25 `<div>abc[]def</div><p>ghi</p>` 26 ); 27 await utils.sendEnterKey(); 28 const right = utils.editingHost.querySelector("div + div"); 29 utils.editingHost.appendChild(right); 30 // Now, the right <div> is after the <p>, it should be merged into the left 31 // <div> before the <p>. 32 document.execCommand("undo"); 33 assert_in_array( 34 utils.editingHost.innerHTML, 35 [ 36 "<div>abcdef</div><p>ghi</p>", 37 "<div>abcdef<br></div><p>ghi</p>", 38 ] 39 ); 40 }, "Undo insertParagraph after moving right node to different paragraph"); 41 42 promise_test(async () => { 43 utils.setupEditingHost( 44 `<p>abc</p><div>def[]ghi</div>` 45 ); 46 await utils.sendEnterKey(); 47 const left = utils.editingHost.querySelector("div"); 48 utils.editingHost.insertBefore(left, document.querySelector("p")); 49 // Now, the left <div> is before the <p>, the right <div> after the <p> should 50 // be merged into it. 51 document.execCommand("undo"); 52 assert_in_array( 53 utils.editingHost.innerHTML, 54 [ 55 "<div>defghi</div><p>abc</p>", 56 "<div>defghi<br></div><p>abc</p>", 57 ] 58 ); 59 }, "Undo insertParagraph after moving left node to different paragraph"); 60 61 promise_test(async () => { 62 utils.setupEditingHost( 63 `<div>abc[]def</div>` 64 ); 65 await utils.sendEnterKey(); 66 const left = utils.editingHost.querySelector("div"); 67 const right = utils.editingHost.querySelector("div + div"); 68 left.insertBefore(right, left.firstChild); 69 // Now, the right <div> is a child node of the left <div>. Its children 70 // should be merged to the parent. 71 document.execCommand("undo"); 72 assert_in_array( 73 utils.editingHost.innerHTML, 74 [ 75 "<div>abcdef</div>", 76 "<div>abcdef<br></div>", 77 ] 78 ); 79 }, "Undo insertParagraph after moving right node into the left node"); 80 81 promise_test(async () => { 82 utils.setupEditingHost( 83 `<div>abc[]def</div>` 84 ); 85 await utils.sendEnterKey(); 86 const left = utils.editingHost.querySelector("div"); 87 const right = utils.editingHost.querySelector("div + div"); 88 right.appendChild(left); 89 // Now, the right <div> is parent of the left <div>. The children of the 90 // right <div> should be moved to the child left <div>, but the right <div> 91 // should be removed. 92 document.execCommand("undo"); 93 assert_equals( 94 utils.editingHost.innerHTML, 95 "", 96 "The right <div> containing the left <div> should be removed" 97 ); 98 assert_in_array( 99 left.innerHTML, 100 [ 101 "abcdef", 102 "abcdef<br>", 103 ], 104 "The left <div> which was disconnected should have the original content" 105 ); 106 }, "Undo insertParagraph after moving left node into the right node"); 107 </script> 108 </body> 109 </html>