1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/editor/libeditor/html/tests/test_bug484181.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,102 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=484181 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 484181</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=484181">Mozilla Bug 484181</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 484181 **/ 1.25 + 1.26 +SimpleTest.waitForExplicitFinish(); 1.27 +addLoadEvent(runTest); 1.28 + 1.29 +var gMisspeltWords; 1.30 + 1.31 +function getEditor() { 1.32 + var Ci = SpecialPowers.Ci; 1.33 + var win = window; 1.34 + var editingSession = SpecialPowers.wrap(win).QueryInterface(Ci.nsIInterfaceRequestor) 1.35 + .getInterface(Ci.nsIWebNavigation) 1.36 + .QueryInterface(Ci.nsIInterfaceRequestor) 1.37 + .getInterface(Ci.nsIEditingSession); 1.38 + return editingSession.getEditorForWindow(win); 1.39 +} 1.40 + 1.41 +function getSpellCheckSelection() { 1.42 + var editor = getEditor(); 1.43 + var selcon = editor.selectionController; 1.44 + return selcon.getSelection(selcon.SELECTION_SPELLCHECK); 1.45 +} 1.46 + 1.47 +function append(str) { 1.48 + 1.49 + var edit = document.getElementById("edit"); 1.50 + var editor = getEditor(); 1.51 + var sel = editor.selection; 1.52 + sel.selectAllChildren(edit); 1.53 + sel.collapseToEnd(); 1.54 + 1.55 + for (var i = 0; i < str.length; ++i) { 1.56 + synthesizeKey(str[i], {}); 1.57 + } 1.58 +} 1.59 + 1.60 +function runTest() { 1.61 + gMisspeltWords = ["haz", "cheezburger"]; 1.62 + var edit = document.getElementById("edit"); 1.63 + edit.focus(); 1.64 + 1.65 + SpecialPowers.Cu.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm", window); 1.66 + onSpellCheck(edit, function () { 1.67 + is(isSpellingCheckOk(), true, "All misspellings before editing are accounted for."); 1.68 + 1.69 + append(" becaz I'm a lolcat!"); 1.70 + onSpellCheck(edit, function () { 1.71 + gMisspeltWords.push("becaz"); 1.72 + gMisspeltWords.push("lolcat"); 1.73 + is(isSpellingCheckOk(), true, "All misspellings after typing are accounted for."); 1.74 + 1.75 + SimpleTest.finish(); 1.76 + }); 1.77 + }); 1.78 +} 1.79 + 1.80 +function isSpellingCheckOk() { 1.81 + 1.82 + var sel = getSpellCheckSelection(); 1.83 + var numWords = sel.rangeCount; 1.84 + 1.85 + is(numWords, gMisspeltWords.length, "Correct number of misspellings and words."); 1.86 + 1.87 + if (numWords != gMisspeltWords.length) 1.88 + return false; 1.89 + 1.90 + for (var i=0; i<numWords; i++) { 1.91 + var word = sel.getRangeAt(i); 1.92 + is (word, gMisspeltWords[i], "Misspelling is what we think it is."); 1.93 + if (word != gMisspeltWords[i]) 1.94 + return false; 1.95 + } 1.96 + return true; 1.97 +} 1.98 + 1.99 +</script> 1.100 +</pre> 1.101 + 1.102 +<div><div></div><div id="edit" contenteditable="true">I can haz cheezburger</div></div> 1.103 + 1.104 +</body> 1.105 +</html>