Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / pasteboard / paste-and-sanitize.html
blobe1c423afda556a72a5fc40333f56305dcb39ddad
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <p id="description">This test checks that the paste operation trims the pasted fragment to reduce the verbosity of the markup without affecting the style. </p>
8 <div id="console"></div>
9 <script>
11 var sel = document.getSelection();
12 var root = document.createElement("root");
13 document.body.appendChild(root);
16 function createEditable(tagName, markup) {
17 var node = document.createElement(tagName);
18 node.contentEditable = true;
19 node.innerHTML = markup;
20 return node;
23 function testPaste(tagName, originalMarkup, expected) {
24 var node = createEditable(tagName, originalMarkup);
25 root.appendChild(node);
27 node.focus();
28 document.execCommand("SelectAll", false);
29 document.execCommand("Copy", false);
30 document.execCommand("Paste", false);
32 confirmedMarkup = node.innerHTML;
34 shouldBe("confirmedMarkup", "'" + expected + "'");
37 testPaste("div", "Hello", "Hello");
38 testPaste("div", "<b><i>Hello</i></b>", "<b><i>Hello</i></b>");
39 testPaste("div", "<div><b><i><span style=\"font-weight: normal\"><b><i>Hello</i></b></span></i></b></div>", "<b><i>Hello</i></b>");
40 testPaste("div", "<div><div><div>Hello</div></div></div>", "Hello");
41 testPaste("div", "<div><b><div><i>Hello</i></div></b></div>", "<b><i>Hello</i></b>");
42 testPaste("div", "<div><div style=\"text-align: center;\"><b>Hello</b></div></div>", "<div style=\"text-align: center;\"><b>Hello</b></div>");
43 testPaste("div", "<div><b><i><span style=\"font-weight: normal\"><b><i>hello</i></b></span></i></b></div><div><b><i><span style=\"font-weight: normal\"><b><i>world</i></b></span></i></b></div>",
44 "<div><b><i>hello</i></b></div><div><b><i>world</i></b></div>");
45 testPaste("div", "<div><b><i><span style=\"font-weight: normal;\"><b><i>hello1</i></b><b><i> hello2</i></b></span></i></b></div>", "<b><i><span style=\"font-weight: normal;\"><b><i>hello1</i></b><b><i>&nbsp;hello2</i></b></span></i></b>");
46 testPaste("div", "<i style=\"margin: 10px;\"><b><i style=\"margin: 10px;\">hello</i></b></i>",
47 "<i style=\"margin: 10px;\">hello</i></b></i>");
48 testPaste("div", "<div><b><i><span style=\"font-weight: normal\"><b><i>Hello <!-- comment -->world</i></b></span></i></b></div>", "<b><i>Hello&nbsp;world</i></b>");
49 testPaste("div", "<div><b><i><span style=\"font-weight: normal\">plain text<b><i>bold italic text</i></b></span></i></b></div>", "<b><i><span style=\"font-weight: normal;\">plain text<b><i>bold italic text</i></b></span></i></b>");
51 root.style.display = "none";
53 </script>
54 </body>
55 </html>