summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/editing/pasteboard/paste-and-sanitize.html
blob: eb0374c7516209a66df91a2f6d65386b78a5b147 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../fast/js/resources/js-test-pre.js"></script>
</head>
<body>
<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>
<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 testPaste(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 + "'");
}

testPaste("div", "Hello", "Hello");
testPaste("div", "<b><i>Hello</i></b>", "<b><i>Hello</i></b>");
testPaste("div", "<div><b><i><span style=\"font-weight: normal\"><b><i>Hello</i></b></span></i></b></div>", "<b><i>Hello</i></b>");
testPaste("div", "<div><div><div>Hello</div></div></div>", "Hello");
testPaste("div", "<div><b><div><i>Hello</i></div></b></div>", "<b><i>Hello</i></b>");
testPaste("div", "<div><div style=\"text-align: center;\"><b>Hello</b></div></div>", "<div style=\"text-align: center;\"><b>Hello</b></div>");
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>", 
          "<div><b><i>hello</i></b></div><div><b><i>world</i></b></div>");
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>");
testPaste("div", "<i style=\"margin: 10px;\"><b><i style=\"margin: 10px;\">hello</i></b></i>",
          "<i style=\"margin: 10px;\">hello</i></b></i>");
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>");
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>");

root.style.display = "none";

</script>
</body>
</html>