Bug 739687. (Av1) test_classifier.html and test_classifier_worker.html: Set preference they depend on, Some rewrite and documentation. r=dcamp.
authorSerge Gautherie <sgautherie.bz@free.fr>
Tue, 03 Apr 2012 15:37:40 +0200
changeset 94205 2c8a0c3b47f4f5438e3f4ae3424acfc1f20b3490
parent 94204 c410b2d6d57095bbb39b0cba13ed2099debac44b
child 94206 f9c4e201653935d4afdfbcb680ef75ae20eb35ec
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdcamp
bugs739687
milestone14.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 739687. (Av1) test_classifier.html and test_classifier_worker.html: Set preference they depend on, Some rewrite and documentation. r=dcamp.
toolkit/components/url-classifier/tests/mochitest/classifierFrame.html
toolkit/components/url-classifier/tests/mochitest/evilWorker.js
toolkit/components/url-classifier/tests/mochitest/import.css
toolkit/components/url-classifier/tests/mochitest/test_classifier.html
toolkit/components/url-classifier/tests/mochitest/test_classifier_worker.html
toolkit/components/url-classifier/tests/mochitest/workerFrame.html
--- a/toolkit/components/url-classifier/tests/mochitest/classifierFrame.html
+++ b/toolkit/components/url-classifier/tests/mochitest/classifierFrame.html
@@ -1,34 +1,39 @@
-<html> <head>
+<html>
+<head>
 <title></title>
-</head>
 
 <script type="text/javascript">
+
 var scriptItem = "untouched";
 
 function checkLoads() {
   // Make sure the javascript did not load.
   window.parent.is(scriptItem, "untouched", "Should not load bad javascript");
 
   // Make sure the css did not load.
   var elt = document.getElementById("styleCheck");
   var style = document.defaultView.getComputedStyle(elt, "");
   window.parent.isnot(style.visibility, "hidden", "Should not load bad css");
 
+  // End (parent) test.
   window.parent.SimpleTest.finish();
 }
 
 </script>
 
 <!-- Try loading from a malware javascript URI -->
 <script type="text/javascript" src="http://malware.example.com/tests/toolkit/components/url-classifier/tests/mochitest/evil.js"></script>
 
 <!-- Try loading from a malware css URI -->
 <link rel="stylesheet" type="text/css" href="http://malware.example.com/tests/toolkit/components/url-classifier/tests/mochitest/evil.css"></link>
 
+<!-- XXX How is this part of the test supposed to work (= be checked)? -->
 <!-- Try loading a marked-as-malware css through an @import from a clean URI -->
 <link rel="stylesheet" type="text/css" href="import.css"></link>
+</head>
 
 <body onload="checkLoads()">
 The following should not be hidden:
 <div id="styleCheck">STYLE TEST</div>
-</body> </html>
+</body>
+</html>
--- a/toolkit/components/url-classifier/tests/mochitest/evilWorker.js
+++ b/toolkit/components/url-classifier/tests/mochitest/evilWorker.js
@@ -1,4 +1,3 @@
 onmessage = function() {
   postMessage("loaded bad file");
 }
-
--- a/toolkit/components/url-classifier/tests/mochitest/import.css
+++ b/toolkit/components/url-classifier/tests/mochitest/import.css
@@ -1,1 +1,3 @@
+/* malware.example.com is in the malware database.
+   classifierBad.css does not actually exist. */
 @import url("http://malware.example.com/tests/docshell/test/classifierBad.css");
--- a/toolkit/components/url-classifier/tests/mochitest/test_classifier.html
+++ b/toolkit/components/url-classifier/tests/mochitest/test_classifier.html
@@ -1,15 +1,16 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <title>Test the URI Classifier</title>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
+
 <body onload="doUpdate(testUpdate);">
 <p id="display"></p>
 <div id="content" style="display: none">
 </div>
 <pre id="test">
 
 <script class="testbody" type="text/javascript">
 
@@ -22,47 +23,53 @@ var testData = "malware.example.com/";
 var testUpdate =
   "n:1000\ni:test-malware-simple\nad:1\n" +
   "a:524:32:" + testData.length + "\n" +
   testData;
 
 var dbService = Cc["@mozilla.org/url-classifier/dbservice;1"]
                 .getService(Ci.nsIUrlClassifierDBService);
 
-var numTries = 10;
-
 function doUpdate(update) {
   var 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) {
       ok(false, "Couldn't update classifier.");
+      // Abort test.
       SimpleTest.finish();
     },
     updateSuccess: function(requestedTimeout) {
-      document.getElementById("testFrame").src = "classifierFrame.html";
+      SpecialPowers.pushPrefEnv(
+        {"set" : [["browser.safebrowsing.malware.enabled", true]]},
+        function loadTestFrame() {
+          document.getElementById("testFrame").src = "classifierFrame.html";
+        }
+      );
     }
   };
 
   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
 
   dbService.beginUpdate(listener, "test-malware-simple", "");
   dbService.beginStream("", "");
   dbService.updateStream(update);
   dbService.finishStream();
   dbService.finishUpdate();
 }
 
+// Expected finish() call is in "classifierFrame.html".
 SimpleTest.waitForExplicitFinish();
 
 </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
@@ -1,15 +1,16 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <title>Test the URI Classifier</title>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
+
 <body onload="doUpdate(testUpdate);">
 <p id="display"></p>
 <div id="content" style="display: none">
 </div>
 <pre id="test">
 
 <script class="testbody" type="text/javascript">
 
@@ -22,36 +23,41 @@ var testData = "example.com/tests/toolki
 var testUpdate =
   "n:1000\ni:test-malware-simple\nad:550\n" +
   "a:550:32:" + testData.length + "\n" +
   testData;
 
 var dbService = Cc["@mozilla.org/url-classifier/dbservice;1"]
                 .getService(Ci.nsIUrlClassifierDBService);
 
-var numTries = 10;
-
 function doUpdate(update) {
   var 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) {
       ok(false, "Couldn't update classifier.");
+      // Abort test.
       SimpleTest.finish();
     },
     updateSuccess: function(requestedTimeout) {
-      document.getElementById("testFrame").src = "http://example.com/tests/toolkit/components/url-classifier/tests/mochitest/workerFrame.html";
+      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";
+        }
+      );
     }
   };
 
   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
 
   dbService.beginUpdate(listener, "test-malware-simple", "");
   dbService.beginStream("", "");
   dbService.updateStream(update);
@@ -70,12 +76,13 @@ function onmessage(event)
   is(pieces[0], "success", pieces[1]);
 }
 
 window.addEventListener("message", onmessage, false);
 
 SimpleTest.waitForExplicitFinish();
 
 </script>
+
 </pre>
 <iframe id="testFrame" onload=""></iframe>
 </body>
 </html>
--- a/toolkit/components/url-classifier/tests/mochitest/workerFrame.html
+++ b/toolkit/components/url-classifier/tests/mochitest/workerFrame.html
@@ -1,15 +1,17 @@
-<html> <head>
+<html>
+<head>
 <title></title>
-</head>
 
 <script type="text/javascript">
+
 function startCleanWorker() {
   var worker = new Worker("cleanWorker.js");
+
   worker.onmessage = function(event) {
     if (event.data == "success") {
       window.parent.postMessage("success:blocked importScripts('evilWorker.js')", "*");
     } else {
       window.parent.postMessage("failure:failed to block importScripts('evilWorker.js')", "*");
     }
     window.parent.postMessage("finish", "*");
   };
@@ -19,25 +21,29 @@ function startCleanWorker() {
     window.parent.postMessage("finish", "*");
   };
 
   worker.postMessage("");
 }
 
 function startEvilWorker() {
   var worker = new Worker("evilWorker.js");
+
   worker.onmessage = function(event) {
     window.parent.postMessage("failure:failed to block evilWorker.js", "*");
     startCleanWorker();
   };
 
   worker.onerror = function(event) {
     window.parent.postMessage("success:blocked evilWorker.js", "*");
     startCleanWorker();
   };
 
   worker.postMessage("");
 }
 
 </script>
 
+</head>
+
 <body onload="startEvilWorker()">
-</body> </html>
+</body>
+</html>