Bug 1252462 - Enable the test_unsafeBidiChars.xhtml test for e10s, r=paolo.
authorFlorian Quèze <florian@queze.net>
Wed, 02 Mar 2016 14:35:06 +0100
changeset 322757 1db864e863ed710a3e51ef795b32e070fd9cc145
parent 322756 9789bbbc3af4e1275c0146e5dd3dfb36ad6b08ea
child 322758 99aeeaac03ac1fc77dc5e0943b1b663899716766
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspaolo
bugs1252462
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1252462 - Enable the test_unsafeBidiChars.xhtml test for e10s, r=paolo.
uriloader/exthandler/tests/mochitest/mochitest.ini
uriloader/exthandler/tests/mochitest/test_unsafeBidiChars.xhtml
uriloader/exthandler/tests/mochitest/unsafeBidi_chromeScript.js
--- a/uriloader/exthandler/tests/mochitest/mochitest.ini
+++ b/uriloader/exthandler/tests/mochitest/mochitest.ini
@@ -1,12 +1,12 @@
 [DEFAULT]
 skip-if = buildapp == 'b2g'
 support-files =
   handlerApp.xhtml
   handlerApps.js
+  unsafeBidi_chromeScript.js
   unsafeBidiFileName.sjs
 
 [test_badMimeType.html]
 [test_handlerApps.xhtml]
 skip-if = (toolkit == 'android' || os == 'mac') || e10s # OS X: bug 786938
 [test_unsafeBidiChars.xhtml]
-skip-if = e10s
--- a/uriloader/exthandler/tests/mochitest/test_unsafeBidiChars.xhtml
+++ b/uriloader/exthandler/tests/mochitest/test_unsafeBidiChars.xhtml
@@ -1,27 +1,28 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
   <title>Test for Handling of unsafe bidi chars</title>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
-<body onload="load();">
+<body>
 <p id="display"></p>
 <iframe id="test"></iframe>
 <script type="text/javascript">
 <![CDATA[
 
-var unsafeBidiChars = {
-  LRE: "\xe2\x80\xaa",
-  RLE: "\xe2\x80\xab",
-  PDF: "\xe2\x80\xac",
-  LRO: "\xe2\x80\xad",
-  RLO: "\xe2\x80\xae"
-};
+var unsafeBidiChars = [
+  "\xe2\x80\xaa", // LRE
+  "\xe2\x80\xab", // RLE
+  "\xe2\x80\xac", // PDF
+  "\xe2\x80\xad", // LRO
+  "\xe2\x80\xae"  // RLO
+];
 
 var tests = [
   "{1}.test",
   "{1}File.test",
   "Fi{1}le.test",
   "File{1}.test",
   "File.{1}test",
   "File.te{1}st",
@@ -32,105 +33,45 @@ var tests = [
 function replace(name, x) {
   return name.replace(/\{1\}/, x);
 }
 
 function sanitize(name) {
   return replace(name, '_');
 }
 
-var gTests = [];
-function make_test(param, expected) {
-  gTests.push({
-    param: param,
-    expected: expected,
-  });
-}
-
-SimpleTest.waitForExplicitFinish();
-
-function load() {
-  var iframe = document.getElementById("test");
-  var gCallback = null;
-  function run_test(test, cb) {
-    var url = "unsafeBidiFileName.sjs?name=" + encodeURIComponent(test.param);
-    gCallback = cb;
-    iframe.src = url;
-  }
-
-  var gCounter = -1;
-  function run_next_test() {
-    if (++gCounter == gTests.length)
-      finish_test();
-    else
-      run_test(gTests[gCounter], run_next_test);
-  }
-
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
-  const HELPERAPP_DIALOG_CONTRACT = "@mozilla.org/helperapplauncherdialog;1";
-  const HELPERAPP_DIALOG_CID = SpecialPowers.wrap(SpecialPowers.Components).ID(SpecialPowers.Cc[HELPERAPP_DIALOG_CONTRACT].number);
-
-  const FAKE_CID = SpecialPowers.Cc["@mozilla.org/uuid-generator;1"].
-    getService(SpecialPowers.Ci.nsIUUIDGenerator).generateUUID();
+add_task(function* () {
+  let url = SimpleTest.getTestFileURL("unsafeBidi_chromeScript.js");
+  let chromeScript = SpecialPowers.loadChromeScript(url);
 
-  function HelperAppLauncherDialog() {}
-  HelperAppLauncherDialog.prototype = {
-    REASON_CANTHANDLE: 0,
-    REASON_SERVERREQUEST: 1,
-    REASON_TYPESNIFFED: 2,
-    show: function(aLauncher, aWindowContext, aReason) {
-      netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-      var test = gTests[gCounter];
-      is(aLauncher.suggestedFileName, test.expected,
-         "The filename should be correctly sanitized");
-      gCallback();
-    },
-    QueryInterface: function(aIID) {
-      netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-      if (aIID.equals(SpecialPowers.Ci.nsISupports) ||
-          aIID.equals(SpecialPowers.Ci.nsIHelperAppLauncherDialog))
-        return this;
-      throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE;
-    }
-  };
-
-  var factory = {
-    createInstance: function(aOuter, aIID) {
-      netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-      if (aOuter != null)
-        throw SpecialPowers.Cr.NS_ERROR_NO_AGGREGATION;
-      return new HelperAppLauncherDialog().QueryInterface(aIID);
-    }
-  };
-
-  SpecialPowers.wrap(SpecialPowers.Components).manager
-            .QueryInterface(SpecialPowers.Ci.nsIComponentRegistrar)
-            .registerFactory(FAKE_CID, "",
-                             HELPERAPP_DIALOG_CONTRACT,
-                             factory);
-
-  function finish_test() {
-    SpecialPowers.wrap(SpecialPowers.Components).manager
-              .QueryInterface(SpecialPowers.Ci.nsIComponentRegistrar)
-              .registerFactory(HELPERAPP_DIALOG_CID, "",
-                               HELPERAPP_DIALOG_CONTRACT,
-                               null);
-    SimpleTest.finish();
-  }
-
-  var i,j;
-
-  for (i = 0; i < tests.length; ++i) {
-    for (j in unsafeBidiChars) {
-      make_test(replace(tests[i], unsafeBidiChars[j]),
-                sanitize(tests[i]));
+  for (let test of tests) {
+    for (let char of unsafeBidiChars) {
+      let promiseName = new Promise(function(resolve) {
+        chromeScript.addMessageListener("suggestedFileName",
+                                        function listener(data) {
+          chromeScript.removeMessageListener("suggestedFileName", listener);
+          resolve(data);
+        });
+      });
+      let name = replace(test, char);
+      let expected = sanitize(test);
+      document.getElementById("test").src =
+        "unsafeBidiFileName.sjs?name=" + encodeURIComponent(name);
+      is((yield promiseName), expected, "got the expected sanitized name");
     }
   }
 
-  run_next_test();
-}
+  let promise = new Promise(function(resolve) {
+    chromeScript.addMessageListener("unregistered", function listener() {
+      chromeScript.removeMessageListener("unregistered", listener);
+      resolve();
+    });
+  });
+  chromeScript.sendAsyncMessage("unregister");
+  yield promise;
+
+  chromeScript.destroy();
+});
 
 ]]>
 </script>
 </body>
 </html>
-
new file mode 100644
--- /dev/null
+++ b/uriloader/exthandler/tests/mochitest/unsafeBidi_chromeScript.js
@@ -0,0 +1,28 @@
+const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+const HELPERAPP_DIALOG_CONTRACT = "@mozilla.org/helperapplauncherdialog;1";
+const HELPERAPP_DIALOG_CID =
+  Components.ID(Cc[HELPERAPP_DIALOG_CONTRACT].number);
+
+const FAKE_CID = Cc["@mozilla.org/uuid-generator;1"].
+                   getService(Ci.nsIUUIDGenerator).generateUUID();
+
+function HelperAppLauncherDialog() {}
+HelperAppLauncherDialog.prototype = {
+  show: function(aLauncher, aWindowContext, aReason) {
+    sendAsyncMessage("suggestedFileName", aLauncher.suggestedFileName);
+  },
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIHelperAppLauncherDialog])
+};
+
+var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
+registrar.registerFactory(FAKE_CID, "", HELPERAPP_DIALOG_CONTRACT,
+                          XPCOMUtils._getFactory(HelperAppLauncherDialog));
+
+addMessageListener("unregister", function() {
+  registrar.registerFactory(HELPERAPP_DIALOG_CID, "",
+                            HELPERAPP_DIALOG_CONTRACT, null);
+  sendAsyncMessage("unregistered");
+});