Bug 1269209 - Port test_bug1204147.html from chrome to plain; r=masayuki
☠☠ backed out by 4d44d784fa15 ☠ ☠
authorAryeh Gregor <ayg@aryeh.name>
Mon, 22 Aug 2016 21:06:41 +0300
changeset 319734 2ebb8eab38341fad5e3ca3ad00ffefc3aada26a9
parent 319733 dda3cfcd2b5c96bc42b9ca481f21d0fa8fea63a7
child 319735 5f63100d5531dd4ce5d53bc1f0afac0957cff670
push id20748
push userphilringnalda@gmail.com
push dateFri, 28 Oct 2016 03:39:55 +0000
treeherderfx-team@715360440695 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1269209, 1204147
milestone52.0a1
Bug 1269209 - Port test_bug1204147.html from chrome to plain; r=masayuki MozReview-Commit-ID: KBeFI73j1Jx
editor/composer/test/chrome.ini
editor/composer/test/mochitest.ini
editor/composer/test/test_bug1204147.html
--- a/editor/composer/test/chrome.ini
+++ b/editor/composer/test/chrome.ini
@@ -1,10 +1,9 @@
 [DEFAULT]
 skip-if = buildapp == 'b2g' || os == 'android'
 
 [test_bug434998.xul]
-[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
@@ -19,8 +19,9 @@ support-files =
 [test_bug384147.html]
 [test_bug389350.html]
 skip-if = toolkit == 'android'
 [test_bug519928.html]
 [test_bug678842.html]
 [test_bug697981.html]
 [test_bug717433.html]
 [test_bug738440.html]
+[test_bug1204147.html]
--- a/editor/composer/test/test_bug1204147.html
+++ b/editor/composer/test/test_bug1204147.html
@@ -1,17 +1,17 @@
 <!DOCTYPE html>
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=1204147
 -->
 <head>
   <title>Test for Bug 1204147</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=1204147">Mozilla Bug 1204147</a>
 <p id="display"></p>
 <iframe id="content"></iframe>
 </div>
 
 <pre id="test">
@@ -22,54 +22,58 @@ SimpleTest.waitForExplicitFinish();
 var content = document.getElementById('content');
 // Load a subframe containing an editor with using "en-GB". At first
 // load, it will set the dictionary to "en-GB". The bug was that a content preference
 // was also created. At second load, we check the dictionary for another element,
 // one that should use "en-US". With the bug corrected, we get "en-US", before
 // we got "en-GB" from the content preference.
 
 var firstLoad = true;
-var en_GB;
-var hunspell;
+var script;
 
 var loadListener = function(evt) {
-  Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.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;
   if (firstLoad) {
     elem = doc.getElementById('en-GB');
   } else {
     elem = doc.getElementById('en-US');
   }
 
-  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 (firstLoad) {
       firstLoad = false;
 
@@ -85,17 +89,17 @@ var loadListener = function(evt) {
       content.src = 'http://mochi.test:8888/tests/editor/composer/test/bug1204147_subframe2.html?firstload=false';
     } else {
       // Second time around, the element should default to en-US.
       // Without the fix, the first run sets the content preference to en-GB for the whole site.
       is (currentDictonary, "en-US", "unexpected lang " + currentDictonary + " instead of en-US");
       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");
 
       // Reset the preference, so the last value we set doesn't collide with the next test.
       SimpleTest.finish();
     }
   });
 }
 
 content.addEventListener('load', loadListener, false);