test_bug1200533.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. </div>
  16. <pre id="test">
  17. <script class="testbody" ttype="application/javascript">
  18. /** Test for Bug 1200533 **/
  19. /** Visit the elements defined above and check the dictionary we got **/
  20. SimpleTest.waitForExplicitFinish();
  21. var content = document.getElementById('content');
  22. var tests = [
  23. // text area, value of spellchecker.dictionary, result.
  24. // Result: Document language.
  25. [ "none", "", "en-US" ],
  26. // Result: Element language.
  27. [ "en-GB", "", "en-GB" ],
  28. [ "en-gb", "", "en-GB" ],
  29. // Result: Random en-*.
  30. [ "en-ZA-not-avail", "", "*" ],
  31. [ "en-generic", "", "*" ],
  32. // Result: Locale.
  33. [ "ko-not-avail", "", "en-US" ],
  34. // Result: Preference value in all cases.
  35. [ "en-ZA-not-avail", "en-AU", "en-AU" ],
  36. [ "en-generic", "en-AU", "en-AU" ],
  37. [ "ko-not-avail", "en-AU", "en-AU" ],
  38. // Result: Random en-*.
  39. [ "en-ZA-not-avail", "de-DE", "*" ],
  40. [ "en-generic", "de-DE", "*" ],
  41. // Result: Preference value.
  42. [ "ko-not-avail", "de-DE", "de-DE" ],
  43. ];
  44. var loadCount = 0;
  45. var script;
  46. var loadListener = function(evt) {
  47. if (loadCount == 0) {
  48. script = SpecialPowers.loadChromeScript(function() {
  49. var dir = Components.classes["@mozilla.org/file/directory_service;1"]
  50. .getService(Components.interfaces.nsIProperties)
  51. .get("CurWorkD", Components.interfaces.nsIFile);
  52. dir.append("tests");
  53. dir.append("editor");
  54. dir.append("composer");
  55. dir.append("test");
  56. var hunspell = Components.classes["@mozilla.org/spellchecker/engine;1"]
  57. .getService(Components.interfaces.mozISpellCheckingEngine);
  58. // Install en-GB, en-AU and de-DE dictionaries.
  59. var en_GB = dir.clone();
  60. var en_AU = dir.clone();
  61. var de_DE = dir.clone();
  62. en_GB.append("en-GB");
  63. en_AU.append("en-AU");
  64. de_DE.append("de-DE");
  65. hunspell.addDirectory(en_GB);
  66. hunspell.addDirectory(en_AU);
  67. hunspell.addDirectory(de_DE);
  68. addMessageListener("check-existence",
  69. () => [en_GB.exists(), en_AU.exists(),
  70. de_DE.exists()]);
  71. addMessageListener("destroy", () => {
  72. hunspell.removeDirectory(en_GB);
  73. hunspell.removeDirectory(en_AU);
  74. hunspell.removeDirectory(de_DE);
  75. });
  76. });
  77. var existenceChecks = script.sendSyncMessage("check-existence")[0][0];
  78. is(existenceChecks[0], true, "true expected (en-GB directory should exist)");
  79. is(existenceChecks[1], true, "true expected (en-AU directory should exist)");
  80. is(existenceChecks[2], true, "true expected (de-DE directory should exist)");
  81. }
  82. SpecialPowers.pushPrefEnv({set: [["spellchecker.dictionary", tests[loadCount][1]]]},
  83. function() { continueTest(evt) });
  84. }
  85. function continueTest(evt) {
  86. var doc = evt.target.contentDocument;
  87. var elem = doc.getElementById(tests[loadCount][0]);
  88. var editor = SpecialPowers.wrap(elem).QueryInterface(SpecialPowers.Ci.nsIDOMNSEditableElement).editor;
  89. editor.setSpellcheckUserOverride(true);
  90. var inlineSpellChecker = editor.getInlineSpellChecker(true);
  91. SpecialPowers.Cu.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm")
  92. .onSpellCheck(elem, function () {
  93. var spellchecker = inlineSpellChecker.spellChecker;
  94. try {
  95. var dict = spellchecker.GetCurrentDictionary();
  96. } catch(e) {}
  97. if (tests[loadCount][2] != "*") {
  98. is (dict, tests[loadCount][2], "expected " + tests[loadCount][2]);
  99. } else {
  100. var gotEn = (dict == "en-GB" || dict == "en-AU" || dict == "en-US");
  101. is (gotEn, true, "expected en-AU or en-GB or en-US");
  102. }
  103. loadCount++;
  104. if (loadCount < tests.length) {
  105. // Load the iframe again.
  106. content.src = 'http://mochi.test:8888/tests/editor/composer/test/bug1200533_subframe.html?firstload=false';
  107. } else {
  108. // Remove the fake dictionaries again, since it's otherwise picked up by later tests.
  109. script.sendSyncMessage("destroy");
  110. SimpleTest.finish();
  111. }
  112. });
  113. }
  114. content.addEventListener('load', loadListener, false);
  115. content.src = 'http://mochi.test:8888/tests/editor/composer/test/bug1200533_subframe.html?firstload=true';
  116. </script>
  117. </pre>
  118. </body>
  119. </html>