1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/editor/libeditor/text/tests/test_bug596333.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,143 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=596333 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 596333</title> 1.11 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.13 + <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=596333">Mozilla Bug 596333</a> 1.17 +<p id="display"></p> 1.18 +<div id="content" style="display: none"> 1.19 + 1.20 +</div> 1.21 +<pre id="test"> 1.22 +<script type="application/javascript"> 1.23 + 1.24 +/** Test for Bug 596333 **/ 1.25 +const Ci = SpecialPowers.Ci; 1.26 + 1.27 +SimpleTest.waitForExplicitFinish(); 1.28 +addLoadEvent(runTest); 1.29 + 1.30 +var gMisspeltWords; 1.31 + 1.32 +function getEditor() { 1.33 + return SpecialPowers.wrap(document.getElementById("edit")).editor; 1.34 +} 1.35 + 1.36 +function getSpellCheckSelection() { 1.37 + var editor = getEditor(); 1.38 + var selcon = editor.selectionController; 1.39 + return selcon.getSelection(selcon.SELECTION_SPELLCHECK); 1.40 +} 1.41 + 1.42 +function append(str) { 1.43 + var edit = document.getElementById("edit"); 1.44 + edit.focus(); 1.45 + edit.selectionStart = edit.selectionEnd = edit.value.length; 1.46 + var editor = getEditor(); 1.47 + 1.48 + for (var i = 0; i < str.length; ++i) { 1.49 + synthesizeKey(str[i], {}); 1.50 + } 1.51 +} 1.52 + 1.53 +function getLoadContext() { 1.54 + return SpecialPowers.wrap(window) 1.55 + .QueryInterface(Ci.nsIInterfaceRequestor) 1.56 + .getInterface(Ci.nsIWebNavigation) 1.57 + .QueryInterface(Ci.nsILoadContext); 1.58 +} 1.59 + 1.60 +function paste(str) { 1.61 + var edit = document.getElementById("edit"); 1.62 + var Cc = SpecialPowers.Cc, Ci = SpecialPowers.Ci; 1.63 + var trans = Cc["@mozilla.org/widget/transferable;1"].createInstance(Ci.nsITransferable); 1.64 + trans.init(getLoadContext()); 1.65 + var s = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString); 1.66 + s.data = str; 1.67 + trans.setTransferData("text/unicode", s, str.length * 2); 1.68 + 1.69 + getEditor().pasteTransferable(trans); 1.70 +} 1.71 + 1.72 +function runOnFocus() { 1.73 + var edit = document.getElementById("edit"); 1.74 + 1.75 + gMisspeltWords = ["haz", "cheezburger"]; 1.76 + is(isSpellingCheckOk(), true, "All misspellings before editing are accounted for."); 1.77 + append(" becaz I'm a lolcat!"); 1.78 + onSpellCheck(edit, function () { 1.79 + gMisspeltWords.push("becaz"); 1.80 + gMisspeltWords.push("lolcat"); 1.81 + is(isSpellingCheckOk(), true, "All misspellings after typing are accounted for."); 1.82 + 1.83 + // Now, type an invalid word, and instead of hitting "space" at the end, just blur 1.84 + // the textarea and see if the spell check after the blur event catches it. 1.85 + append(" workd"); 1.86 + edit.blur(); 1.87 + onSpellCheck(edit, function () { 1.88 + gMisspeltWords.push("workd"); 1.89 + is(isSpellingCheckOk(), true, "All misspellings after blur are accounted for."); 1.90 + 1.91 + // Also, test the case when we're entering the first word in a textarea 1.92 + gMisspeltWords = ["workd"]; 1.93 + edit.value = ""; 1.94 + append("workd "); 1.95 + onSpellCheck(edit, function () { 1.96 + is(isSpellingCheckOk(), true, "Misspelling in the first entered word is accounted for."); 1.97 + 1.98 + // Make sure that pasting would also trigger spell checking for the previous word 1.99 + gMisspeltWords = ["workd"]; 1.100 + edit.value = ""; 1.101 + append("workd"); 1.102 + paste(" x"); 1.103 + onSpellCheck(edit, function () { 1.104 + is(isSpellingCheckOk(), true, "Misspelling is accounted for after pasting."); 1.105 + 1.106 + SimpleTest.finish(); 1.107 + }); 1.108 + }); 1.109 + }); 1.110 + }); 1.111 +} 1.112 + 1.113 +function runTest() 1.114 +{ 1.115 + var edit = document.getElementById("edit"); 1.116 + edit.focus(); 1.117 + 1.118 + SpecialPowers.Cu.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm", window); 1.119 + onSpellCheck(edit, runOnFocus); 1.120 +} 1.121 + 1.122 +function isSpellingCheckOk() { 1.123 + var sel = getSpellCheckSelection(); 1.124 + var numWords = sel.rangeCount; 1.125 + 1.126 + is(numWords, gMisspeltWords.length, "Correct number of misspellings and words."); 1.127 + 1.128 + if (numWords != gMisspeltWords.length) 1.129 + return false; 1.130 + 1.131 + for (var i=0; i<numWords; i++) { 1.132 + var word = sel.getRangeAt(i); 1.133 + is (word, gMisspeltWords[i], "Misspelling is what we think it is."); 1.134 + if (word != gMisspeltWords[i]) 1.135 + return false; 1.136 + } 1.137 + return true; 1.138 +} 1.139 + 1.140 +</script> 1.141 +</pre> 1.142 + 1.143 +<textarea id="edit">I can haz cheezburger</textarea> 1.144 + 1.145 +</body> 1.146 +</html>