editor/libeditor/html/tests/test_bug551704.html

changeset 2
7e26c7da4463
equal deleted inserted replaced
-1:000000000000 0:ada99edd0174
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=551704
5 -->
6 <head>
7 <title>Test for Bug 551704</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=551704">Mozilla Bug 551704</a>
14 <p id="display"></p>
15 <div id="content">
16 <div id="preformatted" style="white-space: pre" contenteditable>a&#10;b</div>
17 <div id="test1" contenteditable><br></div>
18 <div id="test2" contenteditable>a<br></div>
19 <div id="test3" contenteditable style="white-space: pre"><br></div>
20 <div id="test4" contenteditable style="white-space: pre">a<br></div>
21 <div id="test5" contenteditable></div>
22 <div id="test6" contenteditable>a</div>
23 <div id="test7" contenteditable style="white-space: pre"></div>
24 <div id="test8" contenteditable style="white-space: pre">a</div>
25 </div>
26 <pre id="test">
27 <script type="application/javascript">
28
29 function testLineBreak(div, type, expectedText, expectedHTML, callback)
30 {
31 div.focus();
32 getSelection().collapse(div, 0);
33 type();
34 is(div.innerHTML, expectedHTML, "The expected HTML after editing should be correct");
35 SimpleTest.waitForClipboard(expectedText,
36 function() {
37 getSelection().selectAllChildren(div);
38 synthesizeKey("C", {accelKey: true});
39 },
40 function() {
41 var t = document.createElement("textarea");
42 document.body.appendChild(t);
43 t.focus();
44 synthesizeKey("V", {accelKey: true});
45 is(t.value, expectedText, "The expected text should be copied to the clipboard");
46 callback();
47 },
48 function() {
49 SimpleTest.finish();
50 }
51 );
52 }
53
54 function typeABCDEF() {
55 synthesizeKey("a", {});
56 typeBCDEF_chars();
57 }
58
59 function typeBCDEF() {
60 synthesizeKey("VK_RIGHT", {});
61 typeBCDEF_chars();
62 }
63
64 function typeBCDEF_chars() {
65 synthesizeKey("b", {});
66 synthesizeKey("c", {});
67 synthesizeKey("VK_RETURN", {});
68 synthesizeKey("d", {});
69 synthesizeKey("e", {});
70 synthesizeKey("f", {});
71 }
72
73 /** Test for Bug 551704 **/
74 SimpleTest.waitForExplicitFinish();
75 SimpleTest.waitForFocus(function() {
76 var preformatted = document.getElementById("preformatted");
77 is(preformatted.innerHTML, "a\nb", "No BR node should be injected for preformatted editable fields");
78
79 var iframe = document.createElement("iframe");
80 iframe.addEventListener("load", function() {
81 var sel = iframe.contentWindow.getSelection();
82 is(sel.rangeCount, 0, "There should be no range in the selection initially");
83 iframe.contentDocument.designMode = "on";
84 sel = iframe.contentWindow.getSelection();
85 is(sel.rangeCount, 1, "There should be a single range in the selection after setting designMode");
86 var range = sel.getRangeAt(0);
87 ok(range.collapsed, "The range should be collapsed");
88 is(range.startContainer, iframe.contentDocument.body.firstChild, "The range should start on the text");
89 is(range.startOffset, 0, "The start offset should be zero");
90
91 continueTest();
92 }, false);
93 iframe.src = "data:text/html,foo";
94 document.getElementById("content").appendChild(iframe);
95 });
96
97 function continueTest() {
98 var divs = [];
99 for (var i = 0; i < 8; ++i) {
100 divs[i] = document.getElementById("test" + (i+1));
101 }
102 var current = 0;
103 function doNextTest() {
104 if (current == divs.length) {
105 SimpleTest.finish();
106 return;
107 }
108 var div = divs[current++];
109 if (div.textContent == "a") {
110 var type = typeBCDEF;
111 } else {
112 var type = typeABCDEF;
113 }
114 var expectedHTML = "abc<br>def<br>";
115 var expectedText = "abc\ndef";
116 testLineBreak(div, type, expectedText, expectedHTML, doNextTest);
117 }
118
119 doNextTest();
120 }
121
122 </script>
123 </pre>
124 </body>
125 </html>

mercurial