Bug 1375277 - Test case for new error code NS_ERROR_HARMFUL_URI. r=francois

The test is based on "test-harmful-simple" so we can add testing entries
in a human-readable way.

MozReview-Commit-ID: IJcYrp04uFs
This commit is contained in:
Henry Chang
2017-07-28 17:38:01 +08:00
parent 325a9e1bb5
commit 53064b6aa0
4 changed files with 22 additions and 4 deletions

View File

@@ -33,7 +33,10 @@ var testData = [
},
{ url: "blocked.example.com/",
db: "test-block-simple"
}
},
{ url: "harmful.example.com/",
db: "test-harmful-simple"
},
];
const Cc = SpecialPowers.Cc;
@@ -81,6 +84,16 @@ var testURLs = [
table: "test-phish-simple",
result: Cr.NS_ERROR_PHISHING_URI
},
{ url: "http://harmful.example.com",
trackingProtection: false,
table: "test-harmful-simple",
result: Cr.NS_ERROR_HARMFUL_URI
},
{ url: "http://harmful.example.com",
trackingProtection: true,
table: "test-harmful-simple",
result: Cr.NS_ERROR_HARMFUL_URI
},
{ url: "http://tracking.example.com",
trackingProtection: false,
table: "test-track-simple",
@@ -135,7 +148,7 @@ function testService() {
return;
}
let test = testURLs.shift();
let tables = "test-malware-simple,test-unwanted-simple,test-phish-simple,test-track-simple,test-block-simple";
let tables = "test-malware-simple,test-unwanted-simple,test-phish-simple,test-track-simple,test-block-simple,test-harmful-simple";
let uri = ios.newURI(test.url);
let prin = ssm.createCodebasePrincipal(uri, {});
is(service.classifyLocal(uri, tables), test.table,
@@ -158,10 +171,11 @@ function testService() {
}
SpecialPowers.pushPrefEnv(
{"set" : [["urlclassifier.malwareTable", "test-malware-simple,test-unwanted-simple"],
{"set" : [["urlclassifier.malwareTable", "test-malware-simple,test-unwanted-simple,test-harmful-simple"],
["urlclassifier.phishTable", "test-phish-simple"],
["urlclassifier.downloadBlockTable", "test-block-simple"],
["urlclassifier.trackingTable", "test-track-simple"],
["browser.safebrowsing.debug", true],
["privacy.trackingprotection.annotate_channels", true]]},
function() {
classifierHelper.waitForInit()

View File

@@ -56,12 +56,14 @@ function cleanUp() {
delFile("safebrowsing/test-malware-simple.sbstore");
delFile("safebrowsing/test-unwanted-simple.sbstore");
delFile("safebrowsing/test-block-simple.sbstore");
delFile("safebrowsing/test-harmful-simple.sbstore");
delFile("safebrowsing/test-track-simple.sbstore");
delFile("safebrowsing/test-trackwhite-simple.sbstore");
delFile("safebrowsing/test-phish-simple.pset");
delFile("safebrowsing/test-malware-simple.pset");
delFile("safebrowsing/test-unwanted-simple.pset");
delFile("safebrowsing/test-block-simple.pset");
delFile("safebrowsing/test-harmful-simple.pset");
delFile("safebrowsing/test-track-simple.pset");
delFile("safebrowsing/test-trackwhite-simple.pset");
delFile("safebrowsing/moz-phish-simple.sbstore");

View File

@@ -7,6 +7,7 @@ function run_test() {
equal(urlUtils.convertListNameToThreatType("goog-malware-proto"), 1);
equal(urlUtils.convertListNameToThreatType("googpub-phish-proto"), 2);
equal(urlUtils.convertListNameToThreatType("goog-unwanted-proto"), 3);
equal(urlUtils.convertListNameToThreatType("goog-harmful-proto"), 4);
equal(urlUtils.convertListNameToThreatType("goog-phish-proto"), 5);
try {
@@ -23,6 +24,7 @@ function run_test() {
equal(urlUtils.convertThreatTypeToListNames(1), "goog-malware-proto");
equal(urlUtils.convertThreatTypeToListNames(2), "googpub-phish-proto,test-phish-proto");
equal(urlUtils.convertThreatTypeToListNames(3), "goog-unwanted-proto,test-unwanted-proto");
equal(urlUtils.convertThreatTypeToListNames(4), "goog-harmful-proto");
equal(urlUtils.convertThreatTypeToListNames(5), "goog-phish-proto");
try {