Bug 1252449 - Enable test_classifier.html and test_classifier_worker.html on e10s. r=gcp
authorPanos Astithas <past@mozilla.com>
Tue, 01 Mar 2016 17:28:12 +0200
changeset 286420 9789bbbc3af4e1275c0146e5dd3dfb36ad6b08ea
parent 286419 a53a8563879b2a006da0f9d4f56fed89a794f30a
child 286421 1db864e863ed710a3e51ef795b32e070fd9cc145
push id30049
push usercbook@mozilla.com
push dateThu, 03 Mar 2016 10:53:54 +0000
treeherdermozilla-central@7e43bdd93e43 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgcp
bugs1252449
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 1252449 - Enable test_classifier.html and test_classifier_worker.html on e10s. r=gcp MozReview-Commit-ID: AxKMYI7nDkD
toolkit/components/url-classifier/tests/mochitest/classifierCommon.js
toolkit/components/url-classifier/tests/mochitest/mochitest.ini
toolkit/components/url-classifier/tests/mochitest/test_classifier.html
toolkit/components/url-classifier/tests/mochitest/test_classifier_worker.html
new file mode 100644
--- /dev/null
+++ b/toolkit/components/url-classifier/tests/mochitest/classifierCommon.js
@@ -0,0 +1,38 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function doUpdate(update) {
+  const { classes: Cc, interfaces: Ci, results: Cr } = Components;
+
+  let listener = {
+    QueryInterface: function(iid)
+    {
+      if (iid.equals(Ci.nsISupports) ||
+          iid.equals(Ci.nsIUrlClassifierUpdateObserver))
+        return this;
+
+      throw Cr.NS_ERROR_NO_INTERFACE;
+    },
+    updateUrlRequested: function(url) { },
+    streamFinished: function(status) { },
+    updateError: function(errorCode) {
+      sendAsyncMessage("updateError", { errorCode });
+    },
+    updateSuccess: function(requestedTimeout) {
+      sendAsyncMessage("loadTestFrame");
+    }
+  };
+
+  let dbService = Cc["@mozilla.org/url-classifier/dbservice;1"]
+                  .getService(Ci.nsIUrlClassifierDBService);
+
+  dbService.beginUpdate(listener, "test-malware-simple,test-unwanted-simple", "");
+  dbService.beginStream("", "");
+  dbService.updateStream(update);
+  dbService.finishStream();
+  dbService.finishUpdate();
+}
+
+addMessageListener("doUpdate", ({ testUpdate }) => {
+  doUpdate(testUpdate);
+});
--- a/toolkit/components/url-classifier/tests/mochitest/mochitest.ini
+++ b/toolkit/components/url-classifier/tests/mochitest/mochitest.ini
@@ -1,12 +1,13 @@
 [DEFAULT]
-skip-if = buildapp == 'b2g' || e10s
+skip-if = buildapp == 'b2g'
 support-files =
   classifiedAnnotatedPBFrame.html
+  classifierCommon.js
   classifierFrame.html
   cleanWorker.js
   good.js
   evil.css
   evil.js
   evil.js^headers^
   evilWorker.js
   import.css
--- a/toolkit/components/url-classifier/tests/mochitest/test_classifier.html
+++ b/toolkit/components/url-classifier/tests/mochitest/test_classifier.html
@@ -8,77 +8,57 @@
 
 <p id="display"></p>
 <div id="content" style="display: none">
 </div>
 <pre id="test">
 
 <script class="testbody" type="text/javascript">
 
-var Cc = SpecialPowers.Cc;
-var Ci = SpecialPowers.Ci;
 var firstLoad = true;
 
 // Add some URLs to the malware database.
 var testData = "malware.example.com/";
 var testUpdate =
   "n:1000\ni:test-malware-simple\nad:1\n" +
   "a:524:32:" + testData.length + "\n" +
   testData;
 
 testData = "unwanted.example.com/";
 testUpdate +=
   "n:1000\ni:test-unwanted-simple\nad:1\n" +
   "a:524:32:" + testData.length + "\n" +
   testData;
 
-var dbService = Cc["@mozilla.org/url-classifier/dbservice;1"]
-                .getService(Ci.nsIUrlClassifierDBService);
-
 function loadTestFrame() {
   document.getElementById("testFrame").src = "classifierFrame.html";
 }
 
-function doUpdate(update) {
-  var listener = {
-    QueryInterface: SpecialPowers.wrapCallback(function(iid)
-    {
-      if (iid.equals(Ci.nsISupports) ||
-          iid.equals(Ci.nsIUrlClassifierUpdateObserver))
-        return this;
+const CLASSIFIER_COMMON_URL = SimpleTest.getTestFileURL("classifierCommon.js");
+let classifierCommonScript = SpecialPowers.loadChromeScript(CLASSIFIER_COMMON_URL);
+
+// Expected finish() call is in "classifierFrame.html".
+SimpleTest.waitForExplicitFinish();
 
-      throw Cr.NS_ERROR_NO_INTERFACE;
-    }),
-    updateUrlRequested: function(url) { },
-    streamFinished: function(status) { },
-    updateError: function(errorCode) {
-      ok(false, "Couldn't update classifier.");
-      // Abort test.
-      SimpleTest.finish();
-    },
-    updateSuccess: function(requestedTimeout) {
-      SpecialPowers.pushPrefEnv(
-        {"set" : [["browser.safebrowsing.malware.enabled", true]]},
-        loadTestFrame);
-    }
-  };
-
-  dbService.beginUpdate(listener, "test-malware-simple,test-unwanted-simple", "");
-  dbService.beginStream("", "");
-  dbService.updateStream(update);
-  dbService.finishStream();
-  dbService.finishUpdate();
-}
+classifierCommonScript.addMessageListener("loadTestFrame", () => {
+  SpecialPowers.pushPrefEnv(
+    {"set" : [["browser.safebrowsing.malware.enabled", true]]},
+    loadTestFrame);
+});
+classifierCommonScript.addMessageListener("updateError", ({ errorCode }) => {
+  ok(false, "Couldn't update classifier. Error code: " + errorCode);
+  // Abort test.
+  SimpleTest.finish();
+});
 
 SpecialPowers.pushPrefEnv(
   {"set" : [["urlclassifier.malwareTable", "test-malware-simple,test-unwanted-simple"],
             ["urlclassifier.phishTable", "test-phish-simple"]]},
-  function() { doUpdate(testUpdate); });
-
-// Expected finish() call is in "classifierFrame.html".
-SimpleTest.waitForExplicitFinish();
+  function() {
+    classifierCommonScript.sendAsyncMessage("doUpdate", { testUpdate });
+  });
 
 </script>
 
 </pre>
 <iframe id="testFrame" onload=""></iframe>
 </body>
 </html>
--- a/toolkit/components/url-classifier/tests/mochitest/test_classifier_worker.html
+++ b/toolkit/components/url-classifier/tests/mochitest/test_classifier_worker.html
@@ -8,85 +8,65 @@
 
 <p id="display"></p>
 <div id="content" style="display: none">
 </div>
 <pre id="test">
 
 <script class="testbody" type="text/javascript">
 
-var Cc = SpecialPowers.Cc;
-var Ci = SpecialPowers.Ci;
-
 // Add some URLs to the malware database.
 var testData = "example.com/tests/toolkit/components/url-classifier/tests/mochitest/evilWorker.js";
 var testUpdate =
   "n:1000\ni:test-malware-simple\nad:550\n" +
   "a:550:32:" + testData.length + "\n" +
   testData;
 
 testData = "example.com/tests/toolkit/components/url-classifier/tests/mochitest/unwantedWorker.js";
 testUpdate +=
   "n:1000\ni:test-unwanted-simple\nad:550\n" +
   "a:550:32:" + testData.length + "\n" +
   testData;
 
-var dbService = Cc["@mozilla.org/url-classifier/dbservice;1"]
-                .getService(Ci.nsIUrlClassifierDBService);
-
-function doUpdate(update) {
-  var listener = {
-    QueryInterface: SpecialPowers.wrapCallback(function(iid)
-    {
-      if (iid.equals(Ci.nsISupports) ||
-          iid.equals(Ci.nsIUrlClassifierUpdateObserver))
-        return this;
-
-      throw Cr.NS_ERROR_NO_INTERFACE;
-    }),
-    updateUrlRequested: function(url) { },
-    streamFinished: function(status) { },
-    updateError: function(errorCode) {
-      ok(false, "Couldn't update classifier.");
-      // Abort test.
-      SimpleTest.finish();
-    },
-    updateSuccess: function(requestedTimeout) {
-      SpecialPowers.pushPrefEnv(
-        {"set" : [["browser.safebrowsing.malware.enabled", true]]},
-        function loadTestFrame() {
-          document.getElementById("testFrame").src =
-            "http://example.com/tests/toolkit/components/url-classifier/tests/mochitest/workerFrame.html";
-        }
-      );
-    }
-  };
-
-  dbService.beginUpdate(listener, "test-malware-simple,test-unwanted-simple", "");
-  dbService.beginStream("", "");
-  dbService.updateStream(update);
-  dbService.finishStream();
-  dbService.finishUpdate();
+function loadTestFrame() {
+  document.getElementById("testFrame").src =
+    "http://example.com/tests/toolkit/components/url-classifier/tests/mochitest/workerFrame.html";
 }
 
 function onmessage(event)
 {
   var pieces = event.data.split(':');
   if (pieces[0] == "finish") {
     SimpleTest.finish();
     return;
   }
 
   is(pieces[0], "success", pieces[1]);
 }
 
+const CLASSIFIER_COMMON_URL = SimpleTest.getTestFileURL("classifierCommon.js");
+let classifierCommonScript = SpecialPowers.loadChromeScript(CLASSIFIER_COMMON_URL);
+
+classifierCommonScript.addMessageListener("loadTestFrame", () => {
+  SpecialPowers.pushPrefEnv(
+    {"set" : [["browser.safebrowsing.malware.enabled", true]]},
+    loadTestFrame);
+});
+classifierCommonScript.addMessageListener("updateError", ({ errorCode }) => {
+  ok(false, "Couldn't update classifier. Error code: " + errorCode);
+  // Abort test.
+  SimpleTest.finish();
+});
+
 SpecialPowers.pushPrefEnv(
   {"set" : [["urlclassifier.malwareTable", "test-malware-simple,test-unwanted-simple"],
             ["urlclassifier.phishTable", "test-phish-simple"]]},
-  function() { doUpdate(testUpdate); });
+  function() {
+    classifierCommonScript.sendAsyncMessage("doUpdate", { testUpdate });
+  });
 
 window.addEventListener("message", onmessage, false);
 
 SimpleTest.waitForExplicitFinish();
 
 </script>
 
 </pre>