test_bug1330796.html (3615B)
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> 19 20 <div id="editable" contenteditable></div> 21 22 <pre id="test"> 23 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;\">> mailcite<br></span>", 0, 40 "x<span style=\"display: block;\">> mailcite<br></span>" ], 41 [ "<span _moz_quote=true style=\"display: block;\">> mailcite<br></span>", 5, 42 "<span style=\"display: block;\">> mai<br></span>x<span style=\"display: block;\">lcite<br></span>"], 43 [ "<span _moz_quote=true style=\"display: block;\">> mailcite<br></span>", 10, 44 "<span style=\"display: block;\">> mailcite<br></span>x" ], 45 // No <br> at the end to simulate prior deletion to the end of the quote. 46 [ "<span _moz_quote=true style=\"display: block;\">> mailcite</span>", 10, 47 "<span style=\"display: block;\">> mailcite<br></span>x" ], 48 49 // Without style="display: block;". 50 [ "<span _moz_quote=true>> mailcite<br></span>", 0, 51 "x<br><span>> mailcite<br></span>" ], 52 [ "<span _moz_quote=true>> mailcite<br></span>", 5, 53 "<span>> mai</span><br>x<br><span>lcite<br></span>" ], 54 [ "<span _moz_quote=true>> mailcite<br></span>", 10, 55 "<span>> mailcite<br></span>x" ], 56 // No <br> at the end to simulate prior deletion to the end of the quote. 57 [ "<span _moz_quote=true>> mailcite</span>", 10, 58 "<span>> mailcite</span><br>x" ], 59 ]; 60 61 /** Test for Bug 1330796 */ 62 63 SimpleTest.waitForExplicitFinish(); 64 65 SimpleTest.waitForFocus(function() { 66 var sel = window.getSelection(); 67 var theEdit = document.getElementById("editable"); 68 makeMailEditor(); 69 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]); 76 77 synthesizeKey("KEY_Enter"); 78 sendString("x"); 79 is(theEdit.innerHTML, tests[i][2], "unexpected HTML for test " + i.toString()); 80 } 81 82 SimpleTest.finish(); 83 }); 84 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; 90 } 91 </script> 92 93 </pre> 94 </body> 95 </html>