Bug 1772588 [wpt PR 34302] - [wpt] Add test for block-in-inline offsetParent., a...
[gecko.git] / editor / libeditor / tests / test_bug1330796.html
blob1fe1430b786920a11dcd21ced631b3730a097e12
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=1330796
5 -->
6 <head>
7 <meta charset="utf-8">
8 <title>Test for Bug 772796</title>
9 <script src="/tests/SimpleTest/SimpleTest.js"></script>
10 <script src="/tests/SimpleTest/EventUtils.js"></script>
11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
12 <style> .pre { white-space: pre } </style>
13 </head>
14 <body>
15 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=772796">Mozilla Bug 1330796</a>
16 <p id="display"></p>
17 <div id="content" style="display: none">
18 </div>
20 <div id="editable" contenteditable></div>
22 <pre id="test">
24 <script type="application/javascript">
25 // We want to test what happens when the user splits a mail cite by clicking
26 // at the start, the middle and the end of the cite and hitting the enter key.
27 // Mail cites are spans, and since bug 1288911 they are displayed as blocks.
28 // The _moz_quote attribute is used to give the cite a blue color via CSS.
29 // As an internal attribute, it's not returned from the innerHTML.
30 // To the user the tests look like:
31 // > mailcite
32 // This text is 10 characters long, so we position at 0, 5 and 10.
33 // Althought since bug 1288911 those cites are displayed as block,
34 // the tests are repeated also for inline display.
35 // Each entry of the 'tests' array has the original HTML, the offset to click
36 // at and the expected result HTML.
37 var tests = [
38 // With style="display: block;".
39 [ "<span _moz_quote=true style=\"display: block;\">&gt; mailcite<br></span>", 0,
40 "x<br><span style=\"display: block;\">&gt; mailcite<br></span>" ],
41 [ "<span _moz_quote=true style=\"display: block;\">&gt; mailcite<br></span>", 5,
42 "<span style=\"display: block;\">&gt; mai<br></span>x<br><span style=\"display: block;\">lcite<br></span>"],
43 [ "<span _moz_quote=true style=\"display: block;\">&gt; mailcite<br></span>", 10,
44 "<span style=\"display: block;\">&gt; mailcite<br></span>x<br>" ],
45 // No <br> at the end to simulate prior deletion to the end of the quote.
46 [ "<span _moz_quote=true style=\"display: block;\">&gt; mailcite</span>", 10,
47 "<span style=\"display: block;\">&gt; mailcite<br></span>x<br>" ],
49 // Without style="display: block;".
50 [ "<span _moz_quote=true>&gt; mailcite<br></span>", 0,
51 "x<br><span>&gt; mailcite<br></span>" ],
52 [ "<span _moz_quote=true>&gt; mailcite<br></span>", 5,
53 "<span>&gt; mai</span><br>x<br><span>lcite<br></span>" ],
54 [ "<span _moz_quote=true>&gt; mailcite<br></span>", 10,
55 "<span>&gt; mailcite<br></span>x<br>" ],
56 // No <br> at the end to simulate prior deletion to the end of the quote.
57 [ "<span _moz_quote=true>&gt; mailcite</span>", 10,
58 "<span>&gt; mailcite</span><br>x<br>" ],
61 /** Test for Bug 1330796 **/
63 SimpleTest.waitForExplicitFinish();
65 SimpleTest.waitForFocus(function() {
66 var sel = window.getSelection();
67 var theEdit = document.getElementById("editable");
68 makeMailEditor();
70 for (let i = 0; i < tests.length; i++) {
71 theEdit.innerHTML = tests[i][0];
72 theEdit.focus();
73 var theText = theEdit.firstChild.firstChild;
74 // Position set at the beginning , middle and end of the text.
75 sel.collapse(theText, tests[i][1]);
77 synthesizeKey("KEY_Enter");
78 sendString("x");
79 is(theEdit.innerHTML, tests[i][2], "unexpected HTML for test " + i.toString());
82 SimpleTest.finish();
83 });
85 function makeMailEditor() {
86 var Ci = SpecialPowers.Ci;
87 var editingSession = SpecialPowers.wrap(window).docShell.editingSession;
88 var editor = editingSession.getEditorForWindow(window);
89 editor.flags |= Ci.nsIEditor.eEditorMailMask;
91 </script>
93 </pre>
94 </body>
95 </html>