gecko-dev/toolkit/components/url-classifier/tests/mochitest/test_classifier.html
Brian Grinstead ede8c44ef2 Bug 1544322 - Part 2.1 - Remove the [type] attribute for one-liner <script> tags loading files in /tests/SimpleTest/ in everything except for dom/ r=bzbarsky
This excludes dom/, otherwise the file size is too large for phabricator to handle.

This is an autogenerated commit to handle scripts loading mochitest harness files, in
the simple case where the script src is on the same line as the tag.

This was generated with https://bug1544322.bmoattachments.org/attachment.cgi?id=9058170
using the `--part 2` argument.

Differential Revision: https://phabricator.services.mozilla.com/D27456

--HG--
extra : moz-landing-system : lando
2019-04-16 03:50:44 +00:00

139 lines
4.1 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test the URI Classifier</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="classifierHelper.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
var firstLoad = true;
// Add some URLs to the malware database.
// Note that we intentionally don't touch test-phish-simple, and will
// use the URL registered by addMozEntries(). Otherwise, classifierHelper.resetDatabase()
// will reset this table, and waitForInit() can't find the known phishing
// URL in test-phish-simple, breaking the tests following this one.
var testData = [
{ url: "malware.example.com/",
db: "test-malware-simple",
},
{ url: "unwanted.example.com/",
db: "test-unwanted-simple",
},
{ url: "blocked.example.com/",
db: "test-block-simple",
},
{ url: "harmful.example.com/",
db: "test-harmful-simple",
},
];
const Cc = SpecialPowers.Cc;
const Ci = SpecialPowers.Ci;
const Cr = SpecialPowers.Cr;
var testURLs = [
{ url: "http://example.com",
table: "",
result: Cr.NS_OK,
},
{ url: "http://malware.example.com",
table: "test-malware-simple",
result: Cr.NS_ERROR_MALWARE_URI,
},
{ url: "http://unwanted.example.com",
table: "test-unwanted-simple",
result: Cr.NS_ERROR_UNWANTED_URI,
},
{ url: "http://itisatrap.org/firefox/its-a-trap.html",
table: "test-phish-simple",
result: Cr.NS_ERROR_PHISHING_URI,
},
{ url: "http://harmful.example.com",
table: "test-harmful-simple",
result: Cr.NS_ERROR_HARMFUL_URI,
},
{ url: "http://blocked.example.com",
table: "test-block-simple",
result: Cr.NS_ERROR_BLOCKED_URI,
},
];
function loadTestFrame() {
document.getElementById("testFrame").src = "classifierFrame.html";
}
// Expected finish() call is in "classifierFrame.html".
SimpleTest.waitForExplicitFinish();
function updateSuccess() {
return SpecialPowers.pushPrefEnv(
{"set": [["browser.safebrowsing.malware.enabled", true]]});
}
function updateError(errorCode) {
ok(false, "Couldn't update classifier. Error code: " + errorCode);
// Abort test.
SimpleTest.finish();
}
function testService() {
return new Promise(resolve => {
function runNextTest() {
if (!testURLs.length) {
resolve();
return;
}
let test = testURLs.shift();
let tables = "test-malware-simple,test-unwanted-simple,test-phish-simple,test-block-simple,test-harmful-simple";
let uri = SpecialPowers.Services.io.newURI(test.url);
let prin = SpecialPowers.Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
SpecialPowers.doUrlClassify(prin, null, function(errorCode) {
is(errorCode, test.result,
`Successful asynchronous classification of ${test.url}`);
SpecialPowers.doUrlClassifyLocal(uri, tables, function(results) {
if (results.length == 0) {
is(test.table, "",
`Successful asynchronous local classification of ${test.url}`);
} else {
let result = results[0].QueryInterface(Ci.nsIUrlClassifierFeatureResult);
is(result.list, test.table,
`Successful asynchronous local classification of ${test.url}`);
}
runNextTest();
});
});
}
runNextTest(resolve);
});
}
SpecialPowers.pushPrefEnv(
{"set": [["urlclassifier.malwareTable", "test-malware-simple,test-unwanted-simple,test-harmful-simple"],
["urlclassifier.phishTable", "test-phish-simple"],
["urlclassifier.downloadBlockTable", "test-block-simple"],
["browser.safebrowsing.debug", true]]},
function() {
classifierHelper.waitForInit()
.then(() => classifierHelper.addUrlToDB(testData))
.then(updateSuccess)
.catch(err => {
updateError(err);
})
.then(testService)
.then(loadTestFrame);
});
</script>
</pre>
<iframe id="testFrame" onload=""></iframe>
</body>
</html>