|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=410986 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 410986</title> |
|
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
|
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
11 </head> |
|
12 <body> |
|
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=410986">Mozilla Bug 410986</a> |
|
14 <p id="display"></p> |
|
15 <div id="content"> |
|
16 <div id="contents"><span style="color: green;">green text</span></div> |
|
17 <div id="editor" contenteditable="true"></div> |
|
18 </div> |
|
19 <pre id="test"> |
|
20 <script type="application/javascript"> |
|
21 |
|
22 /** Test for Bug 410986 **/ |
|
23 |
|
24 var gPasteEvents = 0; |
|
25 document.getElementById("editor").addEventListener("paste", function() { |
|
26 ++gPasteEvents; |
|
27 }, false); |
|
28 |
|
29 SimpleTest.waitForExplicitFinish(); |
|
30 SimpleTest.waitForFocus(function() { |
|
31 getSelection().selectAllChildren(document.getElementById("contents")); |
|
32 SimpleTest.waitForClipboard("green text", |
|
33 function() { |
|
34 synthesizeKey("C", {accelKey: true}); |
|
35 }, |
|
36 function() { |
|
37 var ed = document.getElementById("editor"); |
|
38 ed.focus(); |
|
39 if (navigator.platform.indexOf("Mac") >= 0) { |
|
40 synthesizeKey("V", {accelKey: true, shiftKey: true, altKey: true}); |
|
41 } else { |
|
42 synthesizeKey("V", {accelKey: true, shiftKey: true}); |
|
43 } |
|
44 is(ed.innerHTML, "green text", "Content should be pasted in plaintext format"); |
|
45 is(gPasteEvents, 1, "One paste event must be fired"); |
|
46 |
|
47 ed.innerHTML = ""; |
|
48 ed.blur(); |
|
49 getSelection().selectAllChildren(document.getElementById("contents")); |
|
50 SimpleTest.waitForClipboard("green text", |
|
51 function() { |
|
52 synthesizeKey("C", {accelKey: true}); |
|
53 }, |
|
54 function() { |
|
55 var ed = document.getElementById("editor"); |
|
56 ed.focus(); |
|
57 synthesizeKey("V", {accelKey: true}); |
|
58 isnot(ed.innerHTML.indexOf("<span style=\"color: green;\">green text</span>"), -1, |
|
59 "Content should be pasted in HTML format"); |
|
60 is(gPasteEvents, 2, "Two paste events must be fired"); |
|
61 |
|
62 SimpleTest.finish(); |
|
63 }, |
|
64 function() { |
|
65 ok(false, "Failed to copy the second item to the clipboard"); |
|
66 SimpleTest.finish(); |
|
67 } |
|
68 ); |
|
69 }, |
|
70 function() { |
|
71 ok(false, "Failed to copy the first item to the clipboard"); |
|
72 SimpleTest.finish(); |
|
73 } |
|
74 ); |
|
75 }); |
|
76 |
|
77 </script> |
|
78 </pre> |
|
79 </body> |
|
80 </html> |