test_bug864040.html (3120B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=864040 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 864040</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <script src="/tests/SimpleTest/EventUtils.js"></script> 11 <script src="/tests/SimpleTest/WindowSnapshot.js"></script> 12 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 13 </head> 14 <body> 15 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=864040">Mozilla Bug 864040</a> 16 <div id="display"> 17 <textarea id="ta" rows="5" cols="20" style="-moz-appearance:none"></textarea> 18 <div id="ce" contentEditable="true" style="height: 5em;"></div> 19 </div> 20 <div id="content" style="display: none"> 21 </div> 22 <pre id="test"> 23 <script type="application/javascript"> 24 /** 25 * Test for Bug 864040 26 * 27 * We use a selection event to set the selection to the end of an editor 28 * containing an ending newline. Then we test to see that the caret is 29 * actually drawn on the newline. 30 */ 31 32 async function testSelectEndOfText(elem) { 33 var tn = elem.tagName; 34 elem.focus(); 35 36 // Enter test string into editor 37 var test_string = 'test\n'; 38 sendString(test_string); 39 40 // Get the caret position after what we entered 41 var result = synthesizeQuerySelectedText(); 42 ok(result, tn + ': failed to query selection (1)'); 43 var refoffset = result.offset; 44 45 // Take a snapshot of where the caret is (on the new line) 46 referenceSnapshot = await snapshotWindow(window, true /* withCaret */); 47 ok(referenceSnapshot, tn + ': failed to take snapshot (1)'); 48 49 // Set selection to the same spot through a selection event 50 ok(await synthesizeSelectionSet(refoffset, 0, false), tn + ': failed to set selection'); 51 52 // Make sure new selection is the same 53 result = synthesizeQuerySelectedText(); 54 ok(result, tn + ': failed to query selection (2)'); 55 is(result.offset, refoffset, tn + ': caret is not at the right position'); 56 57 // Take a snapshot of where the new caret is (shoud still be on the new line) 58 testSnapshot = await snapshotWindow(window, true /* withCaret */); 59 ok(testSnapshot, tn + ': failed to take snapshot (2)'); 60 61 // Compare snapshot (should be the same) 62 result = compareSnapshots(referenceSnapshot, testSnapshot, true /* expected */) 63 ok(result, tn + ': failed to compare snapshots'); 64 // result = [correct, s1data, s2data] 65 ok(result[0], tn + ': caret is not on new line'); 66 if (!result[0]) { 67 dump('Ref: ' + result[1] + '\n'); 68 dump('Res: ' + result[2] + '\n'); 69 } 70 } 71 72 async function runTests() { 73 // we don't test regular <input> because this test is about multiline support 74 // test textarea 75 await testSelectEndOfText(document.getElementById('ta')); 76 // test contentEditable 77 await testSelectEndOfText(document.getElementById('ce')); 78 SimpleTest.finish(); 79 } 80 81 SimpleTest.waitForExplicitFinish(); 82 83 SimpleTest.waitForFocus(runTests); 84 </script> 85 </pre> 86 </body> 87 </html>