test_bug1200533.html (5820B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1200533 5 --> 6 <head> 7 <title>Test for Bug 1200533</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" href="/tests/SimpleTest/test.css"> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1200533">Mozilla Bug 1200533</a> 13 <p id="display"></p> 14 <iframe id="content"></iframe> 15 16 </div> 17 <pre id="test"> 18 <script class="testbody" ttype="application/javascript"> 19 20 /** Test for Bug 1200533 */ 21 /** Visit the elements defined above and check the dictionary we got */ 22 SimpleTest.waitForExplicitFinish(); 23 var content = document.getElementById("content"); 24 25 var tests = [ 26 // text area, value of spellchecker.dictionary, result. 27 // Result: Document language. 28 [ "none", "", "en-US" ], 29 // Result: Element language. 30 [ "en-GB", "", "en-GB" ], 31 [ "en-gb", "", "en-GB" ], 32 // Result: Random en-* or en-US (if application locale is en-US). 33 [ "en-ZA-not-avail", "", "*" ], 34 [ "en-generic", "", "*" ], 35 [ "en", "", "*" ], 36 // Result: Locale. 37 [ "ko-not-avail", "", "en-US" ], 38 39 // Result: Preference value in all cases. 40 [ "en-ZA-not-avail", "en-AU", "en-AU" ], 41 [ "en-generic", "en-AU", "en-AU" ], 42 [ "ko-not-avail", "en-AU", "en-AU" ], 43 44 // Result: Random en-*. 45 [ "en-ZA-not-avail", "de-DE", "*" ], 46 [ "en-generic", "de-DE", "*" ], 47 // Result: Preference value. 48 [ "ko-not-avail", "de-DE", "de-DE" ], 49 ]; 50 51 var loadCount = 0; 52 var retrying = false; 53 var script; 54 55 var loadListener = async function(evt) { 56 if (loadCount == 0) { 57 script = SpecialPowers.loadChromeScript(function() { 58 /* eslint-env mozilla/chrome-script */ 59 // eslint-disable-next-line mozilla/use-services 60 var dir = Cc["@mozilla.org/file/directory_service;1"] 61 .getService(Ci.nsIProperties) 62 .get("CurWorkD", Ci.nsIFile); 63 dir.append("tests"); 64 dir.append("editor"); 65 dir.append("spellchecker"); 66 dir.append("tests"); 67 68 var hunspell = Cc["@mozilla.org/spellchecker/engine;1"] 69 .getService(Ci.mozISpellCheckingEngine); 70 71 // Install en-GB, en-AU and de-DE dictionaries. 72 var en_GB = dir.clone(); 73 var en_AU = dir.clone(); 74 var de_DE = dir.clone(); 75 en_GB.append("en-GB"); 76 en_AU.append("en-AU"); 77 de_DE.append("de-DE"); 78 hunspell.addDirectory(en_GB); 79 hunspell.addDirectory(en_AU); 80 hunspell.addDirectory(de_DE); 81 82 addMessageListener("check-existence", 83 () => [en_GB.exists(), en_AU.exists(), 84 de_DE.exists()]); 85 addMessageListener("destroy", () => { 86 hunspell.removeDirectory(en_GB); 87 hunspell.removeDirectory(en_AU); 88 hunspell.removeDirectory(de_DE); 89 }); 90 }); 91 var existenceChecks = await script.sendQuery("check-existence"); 92 is(existenceChecks[0], true, "true expected (en-GB directory should exist)"); 93 is(existenceChecks[1], true, "true expected (en-AU directory should exist)"); 94 is(existenceChecks[2], true, "true expected (de-DE directory should exist)"); 95 } 96 97 SpecialPowers.pushPrefEnv({set: [["spellchecker.dictionary", tests[loadCount][1]]]}, 98 function() { continueTest(evt); }); 99 }; 100 101 function continueTest(evt) { 102 var doc = evt.target.contentDocument; 103 var elem = doc.getElementById(tests[loadCount][0]); 104 var editor = SpecialPowers.wrap(elem).editor; 105 editor.setSpellcheckUserOverride(true); 106 var inlineSpellChecker = editor.getInlineSpellChecker(true); 107 const is_en_US = SpecialPowers.Services.locale.appLocaleAsBCP47 == "en-US"; 108 109 const { onSpellCheck } = SpecialPowers.ChromeUtils.importESModule( 110 "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs" 111 ); 112 onSpellCheck(elem, async function() { 113 var spellchecker = inlineSpellChecker.spellChecker; 114 let currentDictionaries; 115 try { 116 currentDictionaries = spellchecker.getCurrentDictionaries(); 117 } catch (e) {} 118 119 if (!currentDictionaries && !retrying) { 120 // It's possible for an asynchronous font-list update to cause a reflow 121 // that disrupts the async spell-check and results in not getting a 122 // current dictionary here; if that happens, we retry the same testcase 123 // by reloading the iframe without bumping loadCount. 124 info(`No current dictionary: retrying testcase ${loadCount}`); 125 retrying = true; 126 } else { 127 is(currentDictionaries.length, 1, "expected one dictionary"); 128 let dict = currentDictionaries[0]; 129 if (tests[loadCount][2] != "*") { 130 is(dict, tests[loadCount][2], "expected " + tests[loadCount][2]); 131 } else if (is_en_US && tests[loadCount][0].startsWith("en")) { 132 // Current application locale is en-US and content lang is en or 133 // en-unknown, so we should use en-US dictionary as default. 134 is(dict, "en-US", "expected en-US that is application locale"); 135 } else { 136 var gotEn = (dict == "en-GB" || dict == "en-AU" || dict == "en-US"); 137 is(gotEn, true, "expected en-AU or en-GB or en-US"); 138 } 139 140 loadCount++; 141 retrying = false; 142 } 143 144 if (loadCount < tests.length) { 145 // Load the iframe again. 146 content.src = "http://mochi.test:8888/tests/editor/spellchecker/tests/bug1200533_subframe.html?firstload=false"; 147 } else { 148 // Remove the fake dictionaries again, since it's otherwise picked up by later tests. 149 await script.sendQuery("destroy"); 150 151 SimpleTest.finish(); 152 } 153 }); 154 } 155 156 content.addEventListener("load", loadListener); 157 158 content.src = "http://mochi.test:8888/tests/editor/spellchecker/tests/bug1200533_subframe.html?firstload=true"; 159 160 </script> 161 </pre> 162 </body> 163 </html>