Bug 333894 (for tony@ponderer.org) r+a=ben

flesh out details interfaces for managing black/white lists


git-svn-id: svn://10.0.0.236/trunk@195845 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
brettw%gmail.com 2006-05-02 21:57:35 +00:00
parent 2cd39f979b
commit e30bf22488
11 changed files with 263 additions and 102 deletions

View File

@ -42,6 +42,9 @@
// This class does _not_ embody semantics, defaults, or the like. If we
// need something that does, we'll add our own preference registry.
//
// TODO: These values are actually specific to SafeBrowsing, not url
// classifier, so this file should be moved into
// browser/components/safebrowsing
// TODO: The code needs to fail more gracefully if these values aren't set
// E.g., createInstance should fail for listmanager without these.
@ -60,27 +63,154 @@ PROT_GlobalStore.getPref_ = function(prefname) {
}
/**
* @returns The name of the directory in which we should store data.
* @returns The name of the pref determining whether phishing protection
* is enabled (i.e., whether SafeBrowsing is enabled)
*/
PROT_GlobalStore.getPhishWardenEnabledPrefName = function() {
return "safebrowsing.enabled";
}
/**
* @returns The name of the pref determining whether we enable remote
* checking (advanced protection)
*/
PROT_GlobalStore.getServerCheckEnabledPrefName = function() {
return "safebrowsing.remoteLookups";
}
/**
* @returns The name of the pref determining whether we send reports
* about user actions
*/
PROT_GlobalStore.getSendUserReportsPrefName = function() {
// We send reports iff advanced protection mode is on
return PROT_GlobalStore.getServerCheckEnabledPrefName();
}
/**
* @returns The name of the directory in which we should store data (like
* blacklists and whitelists). This is relative to the user's
* profile.
*/
PROT_GlobalStore.getAppDirectoryName = function() {
return PROT_GlobalStore.getPref_("safebrowsing.datadirectory");
return "safebrowsing_data";
}
/**
* @returns String giving url to use for updates, e.g.,
* http://www.google.com/safebrowsing/update?
* @returns String containing the URL to nav to when the user clicks
* "get me out of here"
*/
PROT_GlobalStore.getGetMeOutOfHereURL = function() {
// Try to get their homepage from prefs.
var prefs = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefService).getBranch(null);
var url = "about:blank";
try {
url = prefs.getComplexValue("browser.startup.homepage",
Ci.nsIPrefLocalizedString).data;
} catch(e) {
G_Debug(this, "Couldn't get homepage pref: " + e);
}
return url;
}
/**
* TODO: maybe deprecate because antiphishing.org isn't localized
* @returns String containing the URL to nav to when the user clicks
* the link to antiphishing.org in the bubble.
*/
PROT_GlobalStore.getAntiPhishingURL = function() {
return "http://antiphishing.org/";
}
/**
* @returns String containing the URL to nav to when the user clicks
* on the policy link in the preferences.
*/
PROT_GlobalStore.getPolicyURL = function() {
return "TODO";
}
/**
* @returns String containing the URL to nav to when the user wants to
* submit a generic phishing report (we're not sure if they
* want to report a false positive or negative).
*/
PROT_GlobalStore.getGenericPhishSubmitURL = function() {
return PROT_GlobalStore.getPref_("safebrowsing.provider.0.genericReportURL");
}
/**
* @returns String containing the URL to nav to when the user wants to
* report a false positive (i.e. a non-phishy page)
*/
PROT_GlobalStore.getFalsePositiveURL = function() {
return PROT_GlobalStore.getPref_("safebrowsing.provider.0.reportErrorURL");
}
/**
* @returns String containing the URL to nav to when the user wants to
* report a false negative (i.e. a phishy page)
*/
PROT_GlobalStore.getSubmitUrl = function() {
return PROT_GlobalStore.getPref_("safebrowsing.provider.0.reportPhishURL");
}
/**
* TODO: maybe deprecated because no UI location for it?
* @returns String containing the URL to nav to when the user clicks
* "more info" in the bubble or the product link in the preferences.
*/
PROT_GlobalStore.getHomePageURL = function() {
return PROT_GlobalStore.getPref_("safebrowsing.provider.0.homeURL");
}
/**
* TODO: maybe deprecated because no UI location for it?
* @returns String containing the URL to nav to when the user clicks
* "phishing FAQ" in the bubble.
*/
PROT_GlobalStore.getPhishingFaqURL = function() {
return PROT_GlobalStore.getPref_("safebrowsing.provider.0.faqURL");
}
/**
* @returns String containing the URL to nav to when the user wants to
* see the test page
*/
PROT_GlobalStore.getTestURL = function() {
return PROT_GlobalStore.getPref_("safebrowsing.provider.0.testURL");
}
/**
* @returns String giving url to use for lookups (used in advanced mode)
*/
PROT_GlobalStore.getLookupserverURL = function() {
return PROT_GlobalStore.getPref_("safebrowsing.provider.0.lookupURL");
}
/**
* @returns String giving url to use for updates (diff of lists)
*/
PROT_GlobalStore.getUpdateserverURL = function() {
// TODO: handle multiple providers
return PROT_GlobalStore.getPref_("safebrowsing.provider.0.updateurl");
return PROT_GlobalStore.getPref_("safebrowsing.provider.0.updateURL");
}
/**
* @returns String giving url to use for re-keying, e.g.,
* https://www.google.com/safebrowsing/getkey?
* TODO: maybe deprecate?
* @returns String giving url to use to report actions (advanced mode only
*/
PROT_GlobalStore.getActionReportURL = function() {
return PROT_GlobalStore.getPref_("safebrowsing.provider.0.reportURL");
}
/**
* @returns String giving url to use for re-keying
*/
PROT_GlobalStore.getGetKeyURL = function() {
return PROT_GlobalStore.getPref_("safebrowsing.provider.0.keyurl");
return PROT_GlobalStore.getPref_("safebrowsing.provider.0.keyURL");
}
/**
@ -95,5 +225,9 @@ PROT_GlobalStore.getKeyFilename = function() {
* TODO: make this automatic based on build rules
*/
PROT_GlobalStore.isTesting = function() {
return true;
isTesting = false;
try {
isTesting = PROT_GlobalStore.getPref_("safebrowsing.testing")
} catch (e) {}
return isTesting;
}

View File

@ -91,7 +91,8 @@ function PROT_ListManager() {
"delay": 400,
};
this.threadQueue_ = new TH_ThreadQueue(threadConfig);
this.appDir_ = null; // appDir is set via a method call
this.appDir_ = null;
this.initAppDir_(); // appDir can be changed with setAppDir
this.currentUpdateChecker_ = null; // set when we toggle updates
this.rpcPending_ = false;
this.readingData_ = false;
@ -159,15 +160,13 @@ PROT_ListManager.prototype.registerTable = function(tableName,
* Enable updates for some tables
* @param tables - an array of table names that need updating
*/
PROT_ListManager.prototype.enableUpdateTables = function(tables) {
PROT_ListManager.prototype.enableUpdate = function(tableName) {
var changed = false;
for (var i = 0; i < tables.length; ++i) {
var table = this.tablesKnown_[tables[i]];
if (table) {
G_Debug(this, "Enabling table updates for " + tables[i]);
table.needsUpdate = true;
changed = true;
}
var table = this.tablesKnown_[tableName];
if (table) {
G_Debug(this, "Enabling table updates for " + tableName);
table.needsUpdate = true;
changed = true;
}
if (changed === true)
@ -178,15 +177,13 @@ PROT_ListManager.prototype.enableUpdateTables = function(tables) {
* Disables updates for some tables
* @param tables - an array of table names that no longer need updating
*/
PROT_ListManager.prototype.disableUpdateTables = function(tables) {
PROT_ListManager.prototype.disableUpdate = function(tableName) {
var changed = false;
for (var i = 0; i < tables.length; ++i) {
var table = this.tablesKnown_[tables[i]];
if (table) {
G_Debug(this, "Disabling table updates for " + tables[i]);
table.needsUpdate = false;
changed = true;
}
var table = this.tablesKnown_[tableName];
if (table) {
G_Debug(this, "Disabling table updates for " + tableName);
table.needsUpdate = false;
changed = true;
}
if (changed === true)
@ -277,6 +274,22 @@ PROT_ListManager.prototype.stopUpdateChecker = function() {
}
}
/**
*
*/
PROT_ListManager.prototype.initAppDir_ = function() {
var dir = G_File.getProfileFile();
dir.append(PROT_GlobalStore.getAppDirectoryName());
if (!dir.exists()) {
try {
dir.create(Ci.nsIFile.DIRECTORY_TYPE, 0700);
} catch (e) {
G_Error(this, dir.path + " couldn't be created.");
}
}
this.setAppDir(dir);
}
/**
* Set the directory in which we should serialize data
*
@ -310,14 +323,14 @@ PROT_ListManager.prototype.clearList = function(table) {
* @returns false or the value in the table corresponding to key.
* If the table name does not exist, we return false, too.
*/
PROT_ListManager.prototype.safeLookup = function(table, key) {
PROT_ListManager.prototype.safeExists = function(table, key) {
var result = false;
try {
var map = this.tablesData[table];
result = map.find(key);
result = map.exists(key);
} catch(e) {
result = false;
G_Debug(this, "Safelookup masked failure for " + table + ", key " + key + ": " + e);
G_Debug(this, "safeExists masked failure for " + table + ", key " + key + ": " + e);
}
return result;
@ -354,7 +367,7 @@ PROT_ListManager.prototype.safeInsert = function(table, key, value) {
* @param key Key for table erase
* @returns true if the value could be removed, false otherwise
*/
PROT_ListManager.prototype.safeErase = function(table, key) {
PROT_ListManager.prototype.safeRemove = function(table, key) {
if (!this.tablesKnown_[table]) {
G_Debug(this, "Unknown table: " + table);
return false;
@ -363,7 +376,7 @@ PROT_ListManager.prototype.safeErase = function(table, key) {
if (!this.tablesData[table])
return false;
return this.tablesData[table].erase(key);
return this.tablesData[table].remove(key);
}
PROT_ListManager.prototype.getTable = function(tableName) {

View File

@ -43,7 +43,7 @@
// This Map's operations are all O(1) plus the time of the native
// operations on its arrays and object. The tradeoff for this speed is
// that the size of the map is always non-decreasing. That is, when an
// item is erase()'d, it is merely marked as invalid and not actually
// item is remove()'d, it is merely marked as invalid and not actually
// removed.
//
// This map is not safe if your keys are objects (they'll get
@ -51,12 +51,12 @@
//
// Interface:
// insert(key, value)
// erase(key)
// find(key)
// remove(key)
// exists(key)
// getList() // This is our poor man's iterator
// forEach(someFunc)
// replace(otherMap) // Clones otherMap, replacing the current map
// size // readonly attribute
// count // readonly attribute
//
// TODO: we could easily have this map periodically compact itself so as
// to eliminate the size tradeoff.
@ -76,7 +76,7 @@ function G_Map(opt_name) {
// In membersMap we map from keys to indices in the membersArray
this.membersMap_ = {};
this.size_ = 0;
this.count_ = 0;
// set to true to allow list manager to update
this.needsUpdate = false;
@ -96,12 +96,12 @@ G_Map.prototype.insert = function(key, value) {
if (value === undefined)
throw new Error("Can't store undefined values in this map");
// Get rid of the old value, if there was one, and increment size if not
// Get rid of the old value, if there was one, and increment count if not
var oldIndexInArray = this.membersMap_[key];
if (typeof oldIndexInArray == "number")
this.membersArray_[oldIndexInArray] = undefined;
else
this.size_++;
this.count_++;
var indexInArray = this.membersArray_.length;
this.membersArray_.push({ "key": key, "value": value});
@ -114,13 +114,13 @@ G_Map.prototype.insert = function(key, value) {
* @param key The key to remove
* @returns Boolean indicating if the key was removed
*/
G_Map.prototype.erase = function(key) {
G_Map.prototype.remove = function(key) {
var indexInArray = this.membersMap_[key];
if (indexInArray === undefined)
return false;
this.size_--;
this.count_--;
delete this.membersMap_[key];
// We could slice here, but that could be expensive if the map large
this.membersArray_[indexInArray] = undefined;
@ -147,7 +147,7 @@ G_Map.prototype.find_ = function(key) {
* @param key The key to look up
* @returns The value at that key or undefined if it doesn't exist
*/
G_Map.prototype.find = function(key) {
G_Map.prototype.exists = function(key) {
return this.find_(key);
}
@ -196,7 +196,7 @@ G_Map.prototype.replace = function(other) {
this.membersArray_.push(otherList[i]);
this.membersMap_[otherList[i].key] = index;
}
this.size_ = other.size;
this.count_ = other.count;
}
/**
@ -215,7 +215,7 @@ G_Map.prototype.forEach = function(func) {
}
G_Map.prototype.QueryInterface = function(iid) {
if (iid.equals(Components.interfaces.nsISample) ||
if (iid.equals(Components.interfaces.nsISupports) ||
iid.equals(Components.interfaces.nsIUrlClassifierTable))
return this;
@ -224,9 +224,9 @@ G_Map.prototype.QueryInterface = function(iid) {
}
/**
* Readonly size attribute.
* Readonly count attribute.
* @returns The number of keys in the map
*/
G_Map.prototype.__defineGetter__('size', function() {
return this.size_;
G_Map.prototype.__defineGetter__('count', function() {
return this.count_;
});

View File

@ -450,7 +450,7 @@ PROT_WireFormatReader.prototype.processUpdateTable_ = function(line) {
this.tablesData_[this.vParser_.type].insert(key, value);
this.insert_++;
} else {
this.tablesData_[this.vParser_.type].erase(key);
this.tablesData_[this.vParser_.type].remove(key);
this.remove_++;
}
}
@ -646,27 +646,27 @@ function TEST_PROT_WireFormat() {
// Table has malformed data
G_Assert(z, tablesKnown["test1-black-url"].minor == "-1",
"test table 1 didn't get reset");
G_Assert(z, !!tablesData["test1-black-url"].find("foo1"),
G_Assert(z, !!tablesData["test1-black-url"].exists("foo1"),
"test table 1 didn't set keys before the error");
G_Assert(z, !!tablesData["test1-black-url"].find("foo3"),
G_Assert(z, !!tablesData["test1-black-url"].exists("foo3"),
"test table 1 didn't set keys after the error");
// Table should be good
G_Assert(z, tablesKnown["test2-black-url"].minor == "2",
"test table 1 didnt get correct version number");
G_Assert(z, !!tablesData["test2-black-url"].find("foo4"),
G_Assert(z, !!tablesData["test2-black-url"].exists("foo4"),
"test table 2 didnt parse properly");
// Table is malformed
G_Assert(z, tablesKnown["test3-black-url"].minor == "-1",
"test table 3 didn't get reset");
G_Assert(z, !tablesData["test3-black-url"].find("foo4"),
G_Assert(z, !tablesData["test3-black-url"].exists("foo4"),
"test table 3 somehow has its malformed line?");
// Table should be good
G_Assert(z, tablesKnown["test4-black-url"].minor == "4",
"test table 4 didn't get correct version number");
G_Assert(z, !!tablesData["test2-black-url"].find("foo4"),
G_Assert(z, !!tablesData["test2-black-url"].exists("foo4"),
"test table 4 didnt parse properly");
// Table is malformed and should be unknown
@ -714,14 +714,14 @@ function TEST_PROT_WireFormat() {
for (var i = 0; i < 100; i++)
if (i != 50)
G_Assert(z,
tablesData[tableName].find("http://exists" + i) == "1",
tablesData[tableName].exists("http://exists" + i) == "1",
"Item addition broken");
G_Assert(z,
!tablesData[tableName].find("http://exists50"),
!tablesData[tableName].exists("http://exists50"),
"Item removal broken");
G_Assert(z,
!tablesData[tableName].find("http://exists666"),
!tablesData[tableName].exists("http://exists666"),
"Non-existent item");
G_Assert(z, tablesKnown[tableName].major == "1", "Major parsing broke");
@ -734,7 +734,7 @@ function TEST_PROT_WireFormat() {
function data2cb(tablesKnown, tablesData) {
for (var i = 0; i < 100; i++)
G_Assert(z,
!tablesData[tableName].find("http://exists" + i),
!tablesData[tableName].exists("http://exists" + i),
"Tables merge broken");
G_Assert(z, tablesKnown[tableName].major == "1", "Major parsing broke");

View File

@ -43,12 +43,12 @@
[scriptable, uuid(fd1f8334-1859-472d-b01f-4ac6b1121ce4)]
interface nsIUrlClassifierTable : nsISupports
{
readonly attribute long size;
readonly attribute long count;
/**
* The name used to identify this table
*/
attribute string name;
attribute ACString name;
/**
* Set to false if we don't want to update this table.
@ -56,27 +56,27 @@ interface nsIUrlClassifierTable : nsISupports
attribute boolean needsUpdate;
/**
* In the simple case, find just looks up the string in the
* In the simple case, exists just looks up the string in the
* table and returns true if it is found. However, it could
* do something more complex (e.g., canonicalize the url).
*/
boolean find(in string key);
boolean exists(in ACString key);
/**
* In the simple case, key is a url and value is 1. However,
* value could be more complicated (e.g., hashed value based
* on site domain).
*/
void insert(in string key, in string value);
void insert(in ACString key, in ACString value);
boolean erase(in string key);
void remove(in ACString key);
// TEMPORARY: used to help serialize the table to disk. May be removed.
void getKeys(out unsigned long size,
[retval,array,size_is(size)] out string keys);
// TEMPORARY: used to help serialize the table to disk. May be removed.
void findValue(in string key);
void findValue(in ACString key);
// TODO: merge data
// void replace(in nsIUrlClassifierTable);

View File

@ -56,32 +56,36 @@ interface nsIUrlListManager : nsISupports
* string of the format provider_name-semantic_type-table_type. For
* example, goog-white-enchash or goog-black-url.
*/
boolean registerTable(in string tableName,
boolean registerTable(in ACString tableName,
in boolean requireMac);
/**
* For each table that is enabled, check for updates during
* during the scheduled interval.
* Turn on update checking for a table. I.e., during the next server
* check, download updates for this table.
*/
void startUpdateChecker();
void enableUpdate(in ACString tableName);
/**
* Stop checking for all updates.
* Turn off update checking for a table.
*/
void stopUpdateChecker();
void disableUpdate(in ACString tableName);
/**
* Lookup a key in a table. Should not raise exceptions.
* Lookup a key in a table. Should not raise exceptions. Returns
* true if the key was found into the table.
*/
boolean safeLookup(in string tableName, in string key);
boolean safeExists(in ACString tableName, in ACString key);
/**
* Insert a key in a table. Should not raise exceptions.
* Insert a key in a table. Should not raise exceptions. Returns
* true if the key was inserted into the table.
*/
boolean safeInsert(in string tableName, in string key, in string value);
boolean safeInsert(in ACString tableName, in ACString key,
in ACString value);
/**
* Remove a key from a table. Should not raise exceptions.
* Remove a key from a table. Should not raise exceptions. Returns
* true if the key was removed from the table.
*/
boolean safeErase(in string tableName, in string key);
boolean safeRemove(in ACString tableName, in string key);
};

View File

@ -34,7 +34,7 @@ UrlClassifierTableDomain.inherits(G_Map);
*
* @returns Boolean true if the url domain is in the table
*/
UrlClassifierTableDomain.prototype.find = function(url) {
UrlClassifierTableDomain.prototype.exists = function(url) {
var urlObj = Cc["@mozilla.org/network/standard-url;1"]
.createInstance(Ci.nsIURL);
urlObj.spec = url;

View File

@ -40,7 +40,7 @@ UrlClassifierTableEnchash.inherits(G_Map);
* @returns Boolean indicating whether the URL matches the regular
* expression contained in the table value
*/
UrlClassifierTableEnchash.prototype.find = function(url) {
UrlClassifierTableEnchash.prototype.exists = function(url) {
var host = this.enchashDecrypter_.getCanonicalHost(url);
for (var i = 0; i < PROT_EnchashDecrypter.MAX_DOTS + 1; i++) {

View File

@ -37,7 +37,7 @@ UrlClassifierTableSite.inherits(G_Map);
* @returns Boolean true if URL matches in table, we normalize based on
* part of the path
*/
UrlClassifierTableSite.prototype.find = function(url) {
UrlClassifierTableSite.prototype.exists = function(url) {
var nsIURI = this.ioService_.newURI(url, null, null);
var host = nsIURI.asciiHost;
var hostComponents = host.split(".");

View File

@ -35,7 +35,7 @@ UrlClassifierTableUrl.inherits(G_Map);
*
* @returns Boolean true if the canonicalized url is in the table
*/
UrlClassifierTableUrl.prototype.find = function(url) {
UrlClassifierTableUrl.prototype.exists = function(url) {
var canonicalized = PROT_URLCanonicalizer.canonicalizeURL_(url);
// Uncomment for debugging
G_Debug(this, "Looking up: " + url + " (" + canonicalized + ")");

View File

@ -34,12 +34,12 @@
.createInstance(Ci.nsIUrlClassifierTable);
urlTable.insert(url, "1");
urlTable.insert(url2, "1");
G_Assert(z, urlTable.find(url), "URL lookups broken");
G_Assert(z, !urlTable.find("about:config"), "about:config breaks domlook");
G_Assert(z, urlTable.find(url2), "URL lookups broken");
G_Assert(z, urlTable.find("http://%31%36%38%2e%31%38%38%2e%39%39%2e%32%36/%2E%73%65%63%75%72%65/%77%77%77%2E%65%62%61%79%2E%63%6F%6D/") == true,
G_Assert(z, urlTable.exists(url), "URL lookups broken");
G_Assert(z, !urlTable.exists("about:config"), "about:config breaks domlook");
G_Assert(z, urlTable.exists(url2), "URL lookups broken");
G_Assert(z, urlTable.exists("http://%31%36%38%2e%31%38%38%2e%39%39%2e%32%36/%2E%73%65%63%75%72%65/%77%77%77%2E%65%62%61%79%2E%63%6F%6D/") == true,
"URL Canonicalization broken");
G_Assert(z, urlTable.size == 2, 'urlTable: wrong size');
G_Assert(z, urlTable.count == 2, 'urlTable: wrong size');
var dom1 = "bar.com";
var dom2 = "amazon.co.uk";
@ -49,13 +49,13 @@
domainTable.insert(dom1, "1");
domainTable.insert(dom2, "1");
domainTable.insert(dom3, "1");
G_Assert(z, domainTable.find("http://www.bar.com/?zaz=asdf#url"),
G_Assert(z, domainTable.exists("http://www.bar.com/?zaz=asdf#url"),
"Domain lookups broken (single dot)");
G_Assert(z, domainTable.find("http://www.amazon.co.uk/?z=af#url"),
G_Assert(z, domainTable.exists("http://www.amazon.co.uk/?z=af#url"),
"Domain lookups broken (two dots)");
G_Assert(z, domainTable.find("http://127.0.0.1/?z=af#url"),
G_Assert(z, domainTable.exists("http://127.0.0.1/?z=af#url"),
"Domain lookups broken (IP)");
G_Assert(z, domainTable.size == 3, 'domainTable: wrong size');
G_Assert(z, domainTable.count == 3, 'domainTable: wrong size');
var site1 = "google.com/safebrowsing/";
var site2 = "www.foo.bar/";
@ -65,15 +65,15 @@
siteTable.insert(site1, "1");
siteTable.insert(site2, "1");
siteTable.insert(site3, "1");
G_Assert(z, siteTable.find("http://www.google.com/safebrowsing/1.php"),
G_Assert(z, siteTable.exists("http://www.google.com/safebrowsing/1.php"),
"Site lookups broken - reducing");
G_Assert(z, siteTable.find("http://www.foo.bar/some/random/path"),
G_Assert(z, siteTable.exists("http://www.foo.bar/some/random/path"),
"Site lookups broken - fqdn");
G_Assert(z, siteTable.find("http://127.0.0.1/something?hello=1"),
G_Assert(z, siteTable.exists("http://127.0.0.1/something?hello=1"),
"Site lookups broken - IP");
G_Assert(z, !siteTable.find("http://www.google.com/search/"),
G_Assert(z, !siteTable.exists("http://www.google.com/search/"),
"Site lookups broken - overreaching");
G_Assert(z, siteTable.size == 3, 'siteTable: wrong size');
G_Assert(z, siteTable.count == 3, 'siteTable: wrong size');
var url1 = "http://poseidon.marinet.gr/~eleni/eBay/index.php";
var domainHash = "01844755C8143C4579BB28DD59C23747";
@ -82,10 +82,10 @@
enchashTable.insert(domainHash, "bGtEQWJuMl9FA3Kl5RiXMpgFU8nDJl9J0hXjUck9+"
+ "mMUQwAN6llf0gJeY5DIPPc2f+a8MSBFJN17ANGJ"
+ "Zl5oZVsQfSW4i12rlScsx4tweZAE");
G_Assert(z, enchashTable.find(url1), 'enchash lookup failed');
G_Assert(z, !enchashTable.find(url1 + '/foo'),
G_Assert(z, enchashTable.exists(url1), 'enchash lookup failed');
G_Assert(z, !enchashTable.exists(url1 + '/foo'),
"enchash lookup broken - overreaching");
G_Assert(z, enchashTable.size == 1, 'enchashTable: wrong size');
G_Assert(z, enchashTable.count == 1, 'enchashTable: wrong size');
// TODO: test replace
G_Debug(z, "PASSED");
@ -95,7 +95,16 @@
var z = "listmanager UNITTEST";
G_Debug(z, "Starting");
//var tempDir = G_File.createUniqueTempDir();
// test lookup and register
var listManagerInst = Cc["@mozilla.org/url-classifier/listmanager;1"]
.createInstance(Ci.nsIUrlListManager);
var listName = 'foo-bar-url';
listManagerInst.registerTable(listName, false);
listManagerInst.safeInsert(listName, 'test', '1');
G_Assert(z, listManagerInst.safeExists(listName, 'test'),
'insert/exist failed');
// test serialization
var baseName = (new Date().getTime()) + ".tmp";
var tempDir = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
@ -104,7 +113,7 @@
tempDir.createUnique(tempDir.DIRECTORY_TYPE, 0744);
var listManager = Cc["@mozilla.org/url-classifier/listmanager;1"]
.createInstance(Ci.nsIUrlListManager);
.getService(Ci.nsIUrlListManager);
listManager.setAppDir(tempDir);
var data = "";
@ -145,19 +154,20 @@
.createInstance(Ci.nsIUrlListManager);
listManager.setAppDir(tempDir);
var tables = [ set1Name, set2Name ];
listManager.wrappedJSObject.enableUpdateTables(tables);
listManager.enableUpdate(set1Name);
listManager.enableUpdate(set2Name);
listManager.wrappedJSObject.readDataFiles();
// assert that the values match
for (var prop in set1) {
G_Assert(z,
listManager.wrappedJSObject.tablesData[set1Name].find(prop),
listManager.wrappedJSObject.tablesData[set1Name].exists(prop),
"Couldn't find member " + prop + "of set1 from disk.");
}
for (var prop in set2) {
G_Assert(z,
listManager.wrappedJSObject.tablesData[set2Name].find(prop),
listManager.wrappedJSObject.tablesData[set2Name].exists(prop),
"Couldn't find member " + prop + "of set2 from disk.");
}