Bug 1269209 - Port test_bug678842.html from chrome to plain; r?masayuki draft
authorAryeh Gregor <ayg@aryeh.name>
Mon, 22 Aug 2016 21:03:23 +0300
changeset 430272 7ae16a4a2d7fca75801210854802f4d99b85b533
parent 430271 323910f5d69cfd67ca78b8b9ab4b9b05da5bd11c
child 430273 f72b2ee77f4b0687869dda0853b0dbc7bad7f285
push id33793
push userayg@aryeh.name
push dateThu, 27 Oct 2016 13:30:40 +0000
reviewersmasayuki
bugs1269209, 678842
milestone52.0a1
Bug 1269209 - Port test_bug678842.html from chrome to plain; r?masayuki MozReview-Commit-ID: LUSLjnMYl1I
editor/composer/test/chrome.ini
editor/composer/test/mochitest.ini
editor/composer/test/test_bug678842.html
--- a/editor/composer/test/chrome.ini
+++ b/editor/composer/test/chrome.ini
@@ -1,13 +1,12 @@
 [DEFAULT]
 skip-if = buildapp == 'b2g' || os == 'android'
 
 [test_bug434998.xul]
-[test_bug678842.html]
 [test_bug697981.html]
 [test_bug717433.html]
 [test_bug1204147.html]
 [test_bug1200533.html]
 [test_bug1205983.html]
 [test_bug1209414.html]
 [test_bug1219928.html]
 [test_bug1266815.html]
--- a/editor/composer/test/mochitest.ini
+++ b/editor/composer/test/mochitest.ini
@@ -15,9 +15,10 @@ support-files =
 
 [test_async_UpdateCurrentDictionary.html]
 [test_bug338427.html]
 [test_bug348497.html]
 [test_bug384147.html]
 [test_bug389350.html]
 skip-if = toolkit == 'android'
 [test_bug519928.html]
+[test_bug678842.html]
 [test_bug738440.html]
--- a/editor/composer/test/test_bug678842.html
+++ b/editor/composer/test/test_bug678842.html
@@ -1,17 +1,17 @@
 <!DOCTYPE html>
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=678842
 -->
 <head>
   <title>Test for Bug 678842</title>
-  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
+  <script src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" href="/tests/SimpleTest/test.css">
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=678842">Mozilla Bug 678842</a>
 <p id="display"></p>
 <iframe id="content"></iframe>
   
 </div>
 <pre id="test">
@@ -21,49 +21,52 @@ https://bugzilla.mozilla.org/show_bug.cg
 SimpleTest.waitForExplicitFinish();
 var content = document.getElementById('content');
 // load a subframe containing an editor with a defined unknown lang. At first
 // load, it will set dictionary to en-US. At second load, it will return current
 // dictionary. So, we can check, dictionary is correctly remembered between
 // loads.
 
 var firstLoad = true;
-var en_GB;
-var hunspell;
+var script;
 
 var loadListener = function(evt) {
-  Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
-  Components.utils.import("resource://gre/modules/Services.jsm");
+  if (firstLoad) {
+    script = SpecialPowers.loadChromeScript(function() {
+      var dir = Components.classes["@mozilla.org/file/directory_service;1"]
+                          .getService(Components.interfaces.nsIProperties)
+                          .get("CurWorkD", Components.interfaces.nsIFile);
+      dir.append("tests");
+      dir.append("editor");
+      dir.append("composer");
+      dir.append("test");
 
-  if (firstLoad) {
-    var dir = Components.classes["@mozilla.org/file/directory_service;1"]
-                        .getService(Components.interfaces.nsIProperties)
-                        .get("CurWorkD", Components.interfaces.nsIFile);
-    dir.append("tests");
-    dir.append("editor");
-    dir.append("composer");
-    dir.append("test");
+      var hunspell = Components.classes["@mozilla.org/spellchecker/engine;1"]
+                               .getService(Components.interfaces.mozISpellCheckingEngine);
 
-    hunspell = Components.classes["@mozilla.org/spellchecker/engine;1"]
-                         .getService(Components.interfaces.mozISpellCheckingEngine);
+      // Install en-GB dictionary.
+      en_GB = dir.clone();
+      en_GB.append("en-GB");
+      hunspell.addDirectory(en_GB);
 
-    // Install en-GB dictionary.
-    en_GB = dir.clone();
-    en_GB.append("en-GB");
-    is(en_GB.exists(), true, "true expected (en-GB directory should exist)");
-    hunspell.addDirectory(en_GB);
+      addMessageListener("en_GB-exists", () => en_GB.exists());
+      addMessageListener("destroy", () => hunspell.removeDirectory(en_GB));
+    });
+    is(script.sendSyncMessage("en_GB-exists")[0][0], true,
+       "true expected (en-GB directory should exist)");
   }
 
   var doc = evt.target.contentDocument;
   var elem = doc.getElementById('textarea');
-  var editor = elem.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).editor;
+  var editor = SpecialPowers.wrap(elem).QueryInterface(SpecialPowers.Ci.nsIDOMNSEditableElement).editor;
   editor.setSpellcheckUserOverride(true);
   var inlineSpellChecker = editor.getInlineSpellChecker(true);
 
-  onSpellCheck(elem, function () {
+  SpecialPowers.Cu.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm")
+  .onSpellCheck(elem, function () {
     var spellchecker = inlineSpellChecker.spellChecker;
     try {
       var currentDictonary = spellchecker.GetCurrentDictionary();
     } catch(e) {}
 
     if (!currentDictonary) {
       spellchecker.SetCurrentDictionary('en-US');
     }
@@ -78,17 +81,17 @@ var loadListener = function(evt) {
       spellchecker.SetCurrentDictionary("en-GB");
 
       content.src = 'http://mochi.test:8888/tests/editor/composer/test/bug678842_subframe.html?firstload=false';
     } else {
       is (currentDictonary, "en-GB", "unexpected lang " + currentDictonary + " instead of en-GB");
       content.removeEventListener('load', loadListener, false);
 
       // Remove the fake en-GB dictionary again, since it's otherwise picked up by later tests.
-      hunspell.removeDirectory(en_GB);
+      script.sendSyncMessage("destroy");
 
       // This will clear the content preferences and reset "spellchecker.dictionary".
       spellchecker.SetCurrentDictionary("");
       SimpleTest.finish();
     }
   });
 }