2009-01-14 23:41:32 -08:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Test the URI Classifier</title>
|
2009-05-06 13:46:04 -07:00
|
|
|
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
2009-01-14 23:41:32 -08:00
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
2009-03-10 14:57:59 -07:00
|
|
|
<body onload="doUpdate(testUpdate);">
|
2009-01-14 23:41:32 -08:00
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var Cc = Components.classes;
|
|
|
|
var Ci = Components.interfaces;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
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.");
|
|
|
|
SimpleTest.finish();
|
|
|
|
},
|
|
|
|
updateSuccess: function(requestedTimeout) {
|
|
|
|
document.getElementById("testFrame").src = "http://example.com/tests/toolkit/components/url-classifier/tests/mochitest/workerFrame.html";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
|
2009-06-17 03:47:08 -07:00
|
|
|
dbService.beginUpdate(listener, "test-malware-simple", "");
|
|
|
|
dbService.beginStream("", "");
|
|
|
|
dbService.updateStream(update);
|
|
|
|
dbService.finishStream();
|
|
|
|
dbService.finishUpdate();
|
2009-01-14 23:41:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function onmessage(event)
|
|
|
|
{
|
|
|
|
var pieces = event.data.split(':');
|
|
|
|
if (pieces[0] == "finish") {
|
|
|
|
SimpleTest.finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
is(pieces[0], "success", pieces[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener("message", onmessage, false);
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
<iframe id="testFrame" onload=""></iframe>
|
|
|
|
</body>
|
|
|
|
</html>
|