Bug 1271120 - Port test_bug569988.html from chrome to plain; r?masayuki draft
authorAryeh Gregor <ayg@aryeh.name>
Tue, 23 Aug 2016 15:56:48 +0300
changeset 430249 93c2b1945574a430a87fc343124e66cf48f2d861
parent 429811 5abc8618fdb52cc8a0fa63b3d006067060bbfb43
child 430250 52e430ee04cbc377ccc543b5924add67dbed3b07
push id33786
push userayg@aryeh.name
push dateThu, 27 Oct 2016 12:00:23 +0000
reviewersmasayuki
bugs1271120, 569988
milestone52.0a1
Bug 1271120 - Port test_bug569988.html from chrome to plain; r?masayuki MozReview-Commit-ID: EwpjCJf5MFX
editor/libeditor/tests/chrome.ini
editor/libeditor/tests/mochitest.ini
editor/libeditor/tests/test_bug569988.html
--- a/editor/libeditor/tests/chrome.ini
+++ b/editor/libeditor/tests/chrome.ini
@@ -5,18 +5,16 @@ support-files = green.png
 [test_bug46555.html]
 [test_bug366682.html]
 support-files = spellcheck.js
 [test_bug471319.html]
 [test_bug483651.html]
 [test_bug489202.xul]
 [test_bug490879.xul]
 subsuite = clipboard
-[test_bug569988.html]
-skip-if = buildapp == 'mulet'
 [test_bug599983.xul]
 skip-if = buildapp == 'mulet'
 [test_bug607584.xul]
 [test_bug616590.xul]
 [test_bug635636.html]
 [test_bug636465.xul]
 [test_bug646194.xul]
 [test_bug780908.xul]
--- a/editor/libeditor/tests/mochitest.ini
+++ b/editor/libeditor/tests/mochitest.ini
@@ -67,16 +67,18 @@ skip-if = toolkit == 'android'
 [test_bug549262.html]
 skip-if = toolkit == 'android'
 [test_bug550434.html]
 skip-if = android_version == '18' # bug 1147989
 [test_bug551704.html]
 subsuite = clipboard
 [test_bug552782.html]
 [test_bug567213.html]
+[test_bug569988.html]
+skip-if = buildapp == 'mulet'
 [test_bug570144.html]
 [test_bug578771.html]
 skip-if = android_version == '18' # bug 1147989
 [test_bug586662.html]
 skip-if = toolkit == 'android'
 [test_bug587461.html]
 [test_bug590554.html]
 [test_bug592592.html]
--- a/editor/libeditor/tests/test_bug569988.html
+++ b/editor/libeditor/tests/test_bug569988.html
@@ -1,77 +1,99 @@
 <!DOCTYPE HTML>
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=569988
 -->
 <head>
   <title>Test for Bug 569988</title>
- <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
-  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
- <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+  <script src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script src="/tests/SimpleTest/EventUtils.js"></script>
+  <link rel="stylesheet" href="/tests/SimpleTest/test.css">
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=569988">Mozilla Bug 569988</a>
 <p id="display"></p>
 <div id="content" style="display: none">
   
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 569988 **/
 
 SimpleTest.waitForExplicitFinish();
 SimpleTest.waitForFocus(runTest);
 
-var gPromptInput = null;
 
 function runTest()
 {
-  var os = SpecialPowers.Cc["@mozilla.org/observer-service;1"].
-             getService(SpecialPowers.Ci.nsIObserverService);
+  var script = SpecialPowers.loadChromeScript(function() {
+    var gPromptInput = null;
+    var os = Components.classes["@mozilla.org/observer-service;1"]
+                       .getService(Components.interfaces.nsIObserverService);
+
+    os.addObserver(onPromptLoad, "common-dialog-loaded", false);
+    os.addObserver(onPromptLoad, "tabmodal-dialog-loaded", false);
+
+    function onPromptLoad(subject, topic, data) {
+      sendAsyncMessage("ok", [true, "onPromptLoad is called"]);
+      gPromptInput = subject.Dialog.ui.loginTextbox;
+      gPromptInput.addEventListener("focus", onPromptFocus, false);
+      // shift focus to ensure it fires.
+      subject.Dialog.ui.button0.focus();
+      gPromptInput.focus();
+    }
+
+    function onPromptFocus() {
+      sendAsyncMessage("ok", [true, "onPromptFocus is called"]);
+      gPromptInput.removeEventListener("focus", onPromptFocus, false);
+
+      var listenerService =
+        Components.classes["@mozilla.org/eventlistenerservice;1"]
+                  .getService(Components.interfaces.nsIEventListenerService);
 
-  os.addObserver(onPromptLoad, "common-dialog-loaded", false);
-  os.addObserver(onPromptLoad, "tabmodal-dialog-loaded", false);
+      var listener = {
+        handleEvent: function _hv(aEvent) {
+          var isPrevented = aEvent.defaultPrevented;
+          sendAsyncMessage("ok", [!isPrevented,
+                           "ESC key event is prevented by editor"]);
+          listenerService.removeSystemEventListener(gPromptInput, "keypress",
+                                                    listener, false);
+        }
+      };
+      listenerService.addSystemEventListener(gPromptInput, "keypress",
+                                             listener, false);
+
+      sendAsyncMessage("info", "sending key");
+      var EventUtils = {};
+      EventUtils.window = {};
+      EventUtils._EU_Ci = Components.interfaces;
+      EventUtils._EU_Cc = Components.classes;
+      Components.classes['@mozilla.org/moz/jssubscript-loader;1']
+                .getService(Components.interfaces.mozIJSSubScriptLoader)
+                .loadSubScript("chrome://mochikit/content/tests/SimpleTest/EventUtils.js",
+                               EventUtils);
+      EventUtils.synthesizeKey("VK_ESCAPE", {},
+                               gPromptInput.ownerDocument.defaultView);
+    }
+
+    addMessageListener("destroy", function() {
+      os.removeObserver(onPromptLoad, "tabmodal-dialog-loaded");
+      os.removeObserver(onPromptLoad, "common-dialog-loaded");
+    });
+  });
+  script.addMessageListener("ok", ([val, msg]) => ok(val, msg));
+  script.addMessageListener("info", msg => info(msg));
 
   info("opening prompt...");
   prompt("summary", "text");
   info("prompt is closed");
 
-  os.removeObserver(onPromptLoad, "tabmodal-dialog-loaded");
-  os.removeObserver(onPromptLoad, "common-dialog-loaded");
-  SimpleTest.finish();
-}
-
-function onPromptLoad(subject, topic, data)
-{
-  ok(true, "onPromptLoad is called");
-  gPromptInput = subject.Dialog.ui.loginTextbox;
-  gPromptInput.addEventListener("focus", onPromptFocus, false);
-  // shift focus to ensure it fires.
-  subject.Dialog.ui.button0.focus();
-  gPromptInput.focus();
-}
+  script.sendSyncMessage("destroy");
 
-function onPromptFocus() {
-  ok(true, "onPromptFocus is called");
-  gPromptInput.removeEventListener("focus", onPromptFocus, false);
-
-  var listener = {
-    handleEvent: function _hv(aEvent)
-    {
-      var isPrevented = aEvent.defaultPrevented;
-      ok(!isPrevented, "ESC key event is prevented by editor");
-      SpecialPowers.removeSystemEventListener(gPromptInput, "keypress",
-                                              listener, false);
-    }
-  };
-  SpecialPowers.addSystemEventListener(gPromptInput, "keypress", listener,
-                                       false);
-  info("sending key");
-  synthesizeKey("VK_ESCAPE", { }, gPromptInput.ownerDocument.defaultView);
+  SimpleTest.finish();
 }
 
 </script>
 </pre>
 </body>
 </html>