| <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| <html> |
| <head> |
| <script src="../../resources/js-test-pre.js"></script> |
| </head> |
| <body> |
| <p id="description">This test checks that copy a selection and paste over the same selection does not create nested divs.</p> |
| <div id="console"></div> |
| <script> |
| |
| var sel = document.getSelection(); |
| var root = document.createElement("root"); |
| document.body.appendChild(root); |
| |
| |
| function createEditable(tagName, markup) { |
| var node = document.createElement(tagName); |
| node.contentEditable = true; |
| node.innerHTML = markup; |
| return node; |
| } |
| |
| function testCopyPaste(tagName, originalMarkup, expected) { |
| var node = createEditable(tagName, originalMarkup); |
| root.appendChild(node); |
| |
| node.focus(); |
| document.execCommand("SelectAll", false); |
| document.execCommand("Copy", false); |
| document.execCommand("Paste", false); |
| |
| confirmedMarkup = node.innerHTML; |
| |
| shouldBe("confirmedMarkup", "'" + expected + "'"); |
| } |
| |
| testCopyPaste("div", "Hello", "Hello"); |
| testCopyPaste("div", "Hello<br>world", "Hello<br>world"); |
| testCopyPaste("div", "<div>Hello</div><div>world</div>", "<div>Hello</div><div>world</div>"); |
| testCopyPaste("div", "<div><div>Hello</div><div>world</div></div>", "<div>Hello</div><div>world</div>"); |
| testCopyPaste("div", "<div><b><i>Hello</i></b></div><div><b><i>world</i></b></div>", "<div><b><i>Hello</i></b></div><div><b><i>world</i></b></div>"); |
| testCopyPaste("div", "<div style=\"text-align: center;\"><div><font color=\"#ff0000\"><b><i>hello</i></b></font></div><div><font color=\"#ff0000\"><b><i>world</i></b></font></div></div>", "<div style=\"text-align: center;\"><div><font color=\"#ff0000\"><b><i>hello</i></b></font></div><div><font color=\"#ff0000\"><b><i>world</i></b></font></div></div>"); |
| |
| root.style.display = "none"; |
| |
| </script> |
| <script src="../../resources/js-test-post.js"></script> |
| </body> |
| </html> |