Bug 1271120 - Port test_bug569988.html from chrome to plain; r=masayuki
authorAryeh Gregor <ayg@aryeh.name>
Tue, 23 Aug 2016 15:56:48 +0300
changeset 432283 fe1a0812871c3e44645180330534a4292a56ebae
parent 432282 1334f6bb2ea03f9449dbc2319e1add4a9f972cd5
child 432284 c8ff4e1962fbdcb265f36458cd7a82e886971012
push id34240
push userbmo:ttromey@mozilla.com
push dateTue, 01 Nov 2016 14:41:32 +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
@@ -1,15 +1,13 @@
 [DEFAULT]
 skip-if = buildapp == 'b2g' || os == 'android'
 support-files = green.png
 
 [test_bug489202.xul]
-[test_bug569988.html]
-skip-if = buildapp == 'mulet'
 [test_bug599983.xul]
 skip-if = buildapp == 'mulet'
 [test_bug607584.xul]
 [test_bug616590.xul]
 [test_bug636465.xul]
 [test_bug780908.xul]
 [test_bug1102906.html]
 [test_contenteditable_text_input_handling.html]
--- a/editor/libeditor/tests/mochitest.ini
+++ b/editor/libeditor/tests/mochitest.ini
@@ -75,16 +75,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 = os == 'android'
 [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>