Bug 1037560 - P2. Modify testcase to test pleasereset should not reset all tables. r=francois,gcp

MozReview-Commit-ID: Hq9iRa9M4sf

--HG--
extra : rebase_source : b8ef99b02b1ddcb22f5922a7eb1e420ed70a4698
This commit is contained in:
dimi 2016-08-23 08:25:03 +08:00
Родитель 2fa583dc0b
Коммит c71a9aa84b
2 изменённых файлов: 38 добавлений и 5 удалений

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

@ -64,11 +64,15 @@ function cleanUp() {
delFile("safebrowsing/test-block-simple.pset");
delFile("safebrowsing/test-track-simple.pset");
delFile("safebrowsing/test-trackwhite-simple.pset");
delFile("safebrowsing/moz-phish-simple.sbstore");
delFile("safebrowsing/moz-phish-simple.pset");
delFile("testLarge.pset");
delFile("testNoDelta.pset");
}
// Update uses allTables by default
var allTables = "test-phish-simple,test-malware-simple,test-unwanted-simple,test-track-simple,test-trackwhite-simple,test-block-simple";
var mozTables = "moz-phish-simple";
var dbservice = Cc["@mozilla.org/url-classifier/dbservice;1"].getService(Ci.nsIUrlClassifierDBService);
var streamUpdater = Cc["@mozilla.org/url-classifier/streamupdater;1"]
@ -129,6 +133,10 @@ function buildBlockedUpdate(chunks, hashSize) {
return buildUpdate({"test-block-simple" : chunks}, hashSize);
}
function buildMozPhishingUpdate(chunks, hashSize) {
return buildUpdate({"moz-phish-simple" : chunks}, hashSize);
}
function buildBareUpdate(chunks, hashSize) {
return buildUpdate({"" : chunks}, hashSize);
}
@ -216,15 +224,16 @@ tableData : function(expectedTables, cb)
});
},
checkUrls: function(urls, expected, cb)
checkUrls: function(urls, expected, cb, useMoz = false)
{
// work with a copy of the list.
urls = urls.slice(0);
var doLookup = function() {
if (urls.length > 0) {
var tables = useMoz ? mozTables : allTables;
var fragment = urls.shift();
var principal = secMan.createCodebasePrincipal(iosvc.newURI("http://" + fragment, null, null), {});
dbservice.lookup(principal, allTables,
dbservice.lookup(principal, tables,
function(arg) {
do_check_eq(expected, arg);
doLookup();
@ -261,6 +270,11 @@ blockedUrlsExist: function(urls, cb)
this.checkUrls(urls, 'test-block-simple', cb);
},
mozPhishingUrlsExist: function(urls, cb)
{
this.checkUrls(urls, 'moz-phish-simple', cb, true);
},
subsDontExist: function(urls, cb)
{
// XXX: there's no interface for checking items in the subs table

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

@ -195,6 +195,21 @@ QueryInterface: function(iid)
// Tests a database reset request.
function testReset() {
// The moz-phish-simple table is populated separately from the other update in
// a separate update request. Therefore it should not be reset when we run the
// updates later in this function.
var mozAddUrls = [ "moz-reset.com/a" ];
var mozUpdate = buildMozPhishingUpdate(
[
{ "chunkNum" : 1,
"urls" : mozAddUrls
}]);
var dataUpdate = "data:," + encodeURIComponent(mozUpdate);
streamUpdater.downloadUpdates(mozTables, "", true,
dataUpdate, () => {}, updateError, updateError);
var addUrls1 = [ "foo-reset.com/a", "foo-reset.com/b" ];
var update1 = buildPhishingUpdate(
[
@ -212,11 +227,15 @@ function testReset() {
}]);
var assertions = {
"tableData" : "test-phish-simple;a:3",
"urlsExist" : addUrls3,
"urlsDontExist" : addUrls1
"tableData" : "moz-phish-simple;a:1\ntest-phish-simple;a:3", // tables that should still be there.
"mozPhishingUrlsExist" : mozAddUrls, // mozAddUrls added prior to the reset
// but it should still exist after reset.
"urlsExist" : addUrls3, // addUrls3 added after the reset.
"urlsDontExist" : addUrls1 // addUrls1 added prior to the reset
};
// Use these update responses in order. The update request only
// contains test-*-simple tables so the reset will only apply to these.
doTest([update1, update2, update3], assertions, false);
}