Bug 739687. (Av1) test_classifier.html and test_classifier_worker.html: Set preference they depend on, Some rewrite and documentation. r=dcamp.

This commit is contained in:
Serge Gautherie 2012-04-03 15:37:40 +02:00
Родитель 6b58fc5e8c
Коммит b0806f2c8a
6 изменённых файлов: 41 добавлений и 15 удалений

Просмотреть файл

@ -1,8 +1,9 @@
<html> <head>
<html>
<head>
<title></title>
</head>
<script type="text/javascript">
var scriptItem = "untouched";
function checkLoads() {
@ -14,6 +15,7 @@ function checkLoads() {
var style = document.defaultView.getComputedStyle(elt, "");
window.parent.isnot(style.visibility, "hidden", "Should not load bad css");
// End (parent) test.
window.parent.SimpleTest.finish();
}
@ -25,10 +27,13 @@ function checkLoads() {
<!-- 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>

Просмотреть файл

@ -1,4 +1,3 @@
onmessage = function() {
postMessage("loaded bad file");
}

Просмотреть файл

@ -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");

Просмотреть файл

@ -5,6 +5,7 @@
<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">
@ -27,8 +28,6 @@ var testUpdate =
var dbService = Cc["@mozilla.org/url-classifier/dbservice;1"]
.getService(Ci.nsIUrlClassifierDBService);
var numTries = 10;
function doUpdate(update) {
var listener = {
QueryInterface: function(iid)
@ -36,17 +35,23 @@ function doUpdate(update) {
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";
}
);
}
};
@ -59,9 +64,11 @@ function doUpdate(update) {
dbService.finishUpdate();
}
// Expected finish() call is in "classifierFrame.html".
SimpleTest.waitForExplicitFinish();
</script>
</pre>
<iframe id="testFrame" onload=""></iframe>
</body>

Просмотреть файл

@ -5,6 +5,7 @@
<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">
@ -27,8 +28,6 @@ var testUpdate =
var dbService = Cc["@mozilla.org/url-classifier/dbservice;1"]
.getService(Ci.nsIUrlClassifierDBService);
var numTries = 10;
function doUpdate(update) {
var listener = {
QueryInterface: function(iid)
@ -36,17 +35,24 @@ function doUpdate(update) {
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";
}
);
}
};
@ -75,6 +81,7 @@ window.addEventListener("message", onmessage, false);
SimpleTest.waitForExplicitFinish();
</script>
</pre>
<iframe id="testFrame" onload=""></iframe>
</body>

Просмотреть файл

@ -1,10 +1,12 @@
<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')", "*");
@ -24,6 +26,7 @@ function startCleanWorker() {
function startEvilWorker() {
var worker = new Worker("evilWorker.js");
worker.onmessage = function(event) {
window.parent.postMessage("failure:failed to block evilWorker.js", "*");
startCleanWorker();
@ -39,5 +42,8 @@ function startEvilWorker() {
</script>
</head>
<body onload="startEvilWorker()">
</body> </html>
</body>
</html>