1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
4 <script src=
"../../resources/js-test.js"></script>
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>
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
;
23 function testPaste(tagName
, originalMarkup
, expected
) {
24 var node
= createEditable(tagName
, originalMarkup
);
25 root
.appendChild(node
);
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> 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 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";