forked from mirrors/gecko-dev
		
	Bug 1386684 - Enable ESLint for toolkit/components/url-classifier (automatic fixes). r=hchang
MozReview-Commit-ID: F0Z8dRaYOku --HG-- extra : rebase_source : 3ebc9ab6ea9f1741d8a986c9217575644411e2a1
This commit is contained in:
		
							parent
							
								
									414b33cce2
								
							
						
					
					
						commit
						436f06fda4
					
				
					 46 changed files with 658 additions and 721 deletions
				
			
		|  | @ -340,9 +340,6 @@ toolkit/components/workerloader/tests/moduleF-syntax-error.js | ||||||
| # Tests old non-star function generators | # Tests old non-star function generators | ||||||
| toolkit/modules/tests/xpcshell/test_task.js | toolkit/modules/tests/xpcshell/test_task.js | ||||||
| 
 | 
 | ||||||
| # Not yet updated |  | ||||||
| toolkit/components/url-classifier/** |  | ||||||
| 
 |  | ||||||
| # External code: | # External code: | ||||||
| toolkit/components/microformats/test/** | toolkit/components/microformats/test/** | ||||||
| toolkit/components/microformats/microformat-shiv.js | toolkit/components/microformats/microformat-shiv.js | ||||||
|  |  | ||||||
|  | @ -55,7 +55,7 @@ const tablePreferences = [ | ||||||
| 
 | 
 | ||||||
| this.SafeBrowsing = { | this.SafeBrowsing = { | ||||||
| 
 | 
 | ||||||
|   init: function() { |   init() { | ||||||
|     if (this.initialized) { |     if (this.initialized) { | ||||||
|       log("Already initialized"); |       log("Already initialized"); | ||||||
|       return; |       return; | ||||||
|  | @ -75,7 +75,7 @@ this.SafeBrowsing = { | ||||||
|     log("init() finished"); |     log("init() finished"); | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   registerTableWithURLs: function(listname) { |   registerTableWithURLs(listname) { | ||||||
|     let listManager = Cc["@mozilla.org/url-classifier/listmanager;1"]. |     let listManager = Cc["@mozilla.org/url-classifier/listmanager;1"]. | ||||||
|       getService(Ci.nsIUrlListManager); |       getService(Ci.nsIUrlListManager); | ||||||
| 
 | 
 | ||||||
|  | @ -96,7 +96,7 @@ this.SafeBrowsing = { | ||||||
|     listManager.registerTable(listname, providerName, provider.updateURL, provider.gethashURL); |     listManager.registerTable(listname, providerName, provider.updateURL, provider.gethashURL); | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   registerTables: function() { |   registerTables() { | ||||||
|     for (let i = 0; i < this.phishingLists.length; ++i) { |     for (let i = 0; i < this.phishingLists.length; ++i) { | ||||||
|       this.registerTableWithURLs(this.phishingLists[i]); |       this.registerTableWithURLs(this.phishingLists[i]); | ||||||
|     } |     } | ||||||
|  | @ -151,7 +151,7 @@ this.SafeBrowsing = { | ||||||
| 
 | 
 | ||||||
|   reportURL:             null, |   reportURL:             null, | ||||||
| 
 | 
 | ||||||
|   getReportURL: function(kind, info) { |   getReportURL(kind, info) { | ||||||
|     let pref; |     let pref; | ||||||
|     switch (kind) { |     switch (kind) { | ||||||
|       case "Phish": |       case "Phish": | ||||||
|  | @ -187,7 +187,7 @@ this.SafeBrowsing = { | ||||||
|     return reportUrl; |     return reportUrl; | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   observe: function(aSubject, aTopic, aData) { |   observe(aSubject, aTopic, aData) { | ||||||
|     // skip nextupdatetime and lastupdatetime
 |     // skip nextupdatetime and lastupdatetime
 | ||||||
|     if (aData.indexOf("lastupdatetime") >= 0 || aData.indexOf("nextupdatetime") >= 0) { |     if (aData.indexOf("lastupdatetime") >= 0 || aData.indexOf("nextupdatetime") >= 0) { | ||||||
|       return; |       return; | ||||||
|  | @ -201,7 +201,7 @@ this.SafeBrowsing = { | ||||||
|     this.readPrefs(); |     this.readPrefs(); | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   readPrefs: function() { |   readPrefs() { | ||||||
|     loggingEnabled = Services.prefs.getBoolPref(PREF_DEBUG_ENABLED); |     loggingEnabled = Services.prefs.getBoolPref(PREF_DEBUG_ENABLED); | ||||||
|     log("reading prefs"); |     log("reading prefs"); | ||||||
| 
 | 
 | ||||||
|  | @ -249,10 +249,10 @@ this.SafeBrowsing = { | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|   updateProviderURLs: function() { |   updateProviderURLs() { | ||||||
|     try { |     try { | ||||||
|       var clientID = Services.prefs.getCharPref("browser.safebrowsing.id"); |       var clientID = Services.prefs.getCharPref("browser.safebrowsing.id"); | ||||||
|     } catch(e) { |     } catch (e) { | ||||||
|       clientID = Services.appinfo.name; |       clientID = Services.appinfo.name; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -295,8 +295,8 @@ this.SafeBrowsing = { | ||||||
|       let googleKey = Services.urlFormatter.formatURL("%GOOGLE_API_KEY%").trim(); |       let googleKey = Services.urlFormatter.formatURL("%GOOGLE_API_KEY%").trim(); | ||||||
|       if ((provider == "google" || provider == "google4") && |       if ((provider == "google" || provider == "google4") && | ||||||
|           (!googleKey || googleKey == "no-google-api-key")) { |           (!googleKey || googleKey == "no-google-api-key")) { | ||||||
|         updateURL= ""; |         updateURL = ""; | ||||||
|         gethashURL= ""; |         gethashURL = ""; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       log("Provider: " + provider + " updateURL=" + updateURL); |       log("Provider: " + provider + " updateURL=" + updateURL); | ||||||
|  | @ -318,7 +318,7 @@ this.SafeBrowsing = { | ||||||
|     }, this); |     }, this); | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   controlUpdateChecking: function() { |   controlUpdateChecking() { | ||||||
|     log("phishingEnabled:", this.phishingEnabled, "malwareEnabled:", |     log("phishingEnabled:", this.phishingEnabled, "malwareEnabled:", | ||||||
|         this.malwareEnabled, "trackingEnabled:", this.trackingEnabled, |         this.malwareEnabled, "trackingEnabled:", this.trackingEnabled, | ||||||
|         "blockedEnabled:", this.blockedEnabled, "trackingAnnotations", |         "blockedEnabled:", this.blockedEnabled, "trackingAnnotations", | ||||||
|  | @ -395,7 +395,7 @@ this.SafeBrowsing = { | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|   addMozEntries: function() { |   addMozEntries() { | ||||||
|     // Add test entries to the DB.
 |     // Add test entries to the DB.
 | ||||||
|     // XXX bug 779008 - this could be done by DB itself?
 |     // XXX bug 779008 - this could be done by DB itself?
 | ||||||
|     const phishURL    = "itisatrap.org/firefox/its-a-trap.html"; |     const phishURL    = "itisatrap.org/firefox/its-a-trap.html"; | ||||||
|  | @ -414,7 +414,7 @@ this.SafeBrowsing = { | ||||||
|                  malwareURL + "\n"; |                  malwareURL + "\n"; | ||||||
|     update += "n:1000\ni:test-phish-simple\nad:1\n" + |     update += "n:1000\ni:test-phish-simple\nad:1\n" + | ||||||
|               "a:1:32:" + phishURL.length + "\n" + |               "a:1:32:" + phishURL.length + "\n" + | ||||||
|               phishURL  + "\n"; |               phishURL + "\n"; | ||||||
|     update += "n:1000\ni:test-unwanted-simple\nad:1\n" + |     update += "n:1000\ni:test-unwanted-simple\nad:1\n" + | ||||||
|               "a:1:32:" + unwantedURL.length + "\n" + |               "a:1:32:" + unwantedURL.length + "\n" + | ||||||
|               unwantedURL + "\n"; |               unwantedURL + "\n"; | ||||||
|  | @ -440,14 +440,14 @@ this.SafeBrowsing = { | ||||||
| 
 | 
 | ||||||
|     // nsIUrlClassifierUpdateObserver
 |     // nsIUrlClassifierUpdateObserver
 | ||||||
|     let dummyListener = { |     let dummyListener = { | ||||||
|       updateUrlRequested: function() { }, |       updateUrlRequested() { }, | ||||||
|       streamFinished:     function() { }, |       streamFinished() { }, | ||||||
|       // We notify observers when we're done in order to be able to make perf
 |       // We notify observers when we're done in order to be able to make perf
 | ||||||
|       // test results more consistent
 |       // test results more consistent
 | ||||||
|       updateError:        function() { |       updateError() { | ||||||
|         Services.obs.notifyObservers(db, "mozentries-update-finished", "error"); |         Services.obs.notifyObservers(db, "mozentries-update-finished", "error"); | ||||||
|       }, |       }, | ||||||
|       updateSuccess:      function() { |       updateSuccess() { | ||||||
|         Services.obs.notifyObservers(db, "mozentries-update-finished", "success"); |         Services.obs.notifyObservers(db, "mozentries-update-finished", "success"); | ||||||
|       } |       } | ||||||
|     }; |     }; | ||||||
|  | @ -459,7 +459,7 @@ this.SafeBrowsing = { | ||||||
|       db.updateStream(update); |       db.updateStream(update); | ||||||
|       db.finishStream(); |       db.finishStream(); | ||||||
|       db.finishUpdate(); |       db.finishUpdate(); | ||||||
|     } catch(ex) { |     } catch (ex) { | ||||||
|       // beginUpdate will throw harmlessly if there's an existing update in progress, ignore failures.
 |       // beginUpdate will throw harmlessly if there's an existing update in progress, ignore failures.
 | ||||||
|       log("addMozEntries failed!", ex); |       log("addMozEntries failed!", ex); | ||||||
|       Services.obs.notifyObservers(db, "mozentries-update-finished", "exception"); |       Services.obs.notifyObservers(db, "mozentries-update-finished", "exception"); | ||||||
|  |  | ||||||
|  | @ -21,13 +21,13 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | ||||||
| Cu.import("resource://gre/modules/Services.jsm"); | Cu.import("resource://gre/modules/Services.jsm"); | ||||||
| Cu.import("resource://gre/modules/NetUtil.jsm"); | Cu.import("resource://gre/modules/NetUtil.jsm"); | ||||||
| 
 | 
 | ||||||
| XPCOMUtils.defineLazyServiceGetter(this, 'gDbService', | XPCOMUtils.defineLazyServiceGetter(this, "gDbService", | ||||||
|                                    '@mozilla.org/url-classifier/dbservice;1', |                                    "@mozilla.org/url-classifier/dbservice;1", | ||||||
|                                    'nsIUrlClassifierDBService'); |                                    "nsIUrlClassifierDBService"); | ||||||
| 
 | 
 | ||||||
| XPCOMUtils.defineLazyServiceGetter(this, 'gUrlUtil', | XPCOMUtils.defineLazyServiceGetter(this, "gUrlUtil", | ||||||
|                                    '@mozilla.org/url-classifier/utils;1', |                                    "@mozilla.org/url-classifier/utils;1", | ||||||
|                                    'nsIUrlClassifierUtils'); |                                    "nsIUrlClassifierUtils"); | ||||||
| 
 | 
 | ||||||
| let loggingEnabled = false; | let loggingEnabled = false; | ||||||
| 
 | 
 | ||||||
|  | @ -147,7 +147,7 @@ function httpStatusToBucket(httpStatus) { | ||||||
|     break; |     break; | ||||||
|   default: |   default: | ||||||
|     statusBucket = 15; |     statusBucket = 15; | ||||||
|   }; |   } | ||||||
|   return statusBucket; |   return statusBucket; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -160,9 +160,9 @@ function FullHashMatch(table, hash, duration) { | ||||||
| FullHashMatch.prototype = { | FullHashMatch.prototype = { | ||||||
|   QueryInterface: XPCOMUtils.generateQI([Ci.nsIFullHashMatch]), |   QueryInterface: XPCOMUtils.generateQI([Ci.nsIFullHashMatch]), | ||||||
| 
 | 
 | ||||||
|   tableName : null, |   tableName: null, | ||||||
|   fullHash : null, |   fullHash: null, | ||||||
|   cacheDuration : null, |   cacheDuration: null, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| function HashCompleter() { | function HashCompleter() { | ||||||
|  | @ -240,7 +240,7 @@ HashCompleter.prototype = { | ||||||
|   // This is called after several calls to |complete|, or after the
 |   // This is called after several calls to |complete|, or after the
 | ||||||
|   // currentRequest has finished.  It starts off the HTTP request by making a
 |   // currentRequest has finished.  It starts off the HTTP request by making a
 | ||||||
|   // |begin| call to the HashCompleterRequest.
 |   // |begin| call to the HashCompleterRequest.
 | ||||||
|   run: function() { |   run() { | ||||||
|     // Clear everything on shutdown
 |     // Clear everything on shutdown
 | ||||||
|     if (this._shuttingDown) { |     if (this._shuttingDown) { | ||||||
|       this._currentRequest = null; |       this._currentRequest = null; | ||||||
|  | @ -273,13 +273,13 @@ HashCompleter.prototype = { | ||||||
| 
 | 
 | ||||||
|   // Pass the server response status to the RequestBackoff for the given
 |   // Pass the server response status to the RequestBackoff for the given
 | ||||||
|   // gethashUrl and fetch the next pending request, if there is one.
 |   // gethashUrl and fetch the next pending request, if there is one.
 | ||||||
|   finishRequest: function(url, aStatus) { |   finishRequest(url, aStatus) { | ||||||
|     this._backoffs[url].noteServerResponse(aStatus); |     this._backoffs[url].noteServerResponse(aStatus); | ||||||
|     Services.tm.dispatchToMainThread(this); |     Services.tm.dispatchToMainThread(this); | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   // Returns true if we can make a request from the given url, false otherwise.
 |   // Returns true if we can make a request from the given url, false otherwise.
 | ||||||
|   canMakeRequest: function(aGethashUrl) { |   canMakeRequest(aGethashUrl) { | ||||||
|     return this._backoffs[aGethashUrl].canMakeRequest() && |     return this._backoffs[aGethashUrl].canMakeRequest() && | ||||||
|            Date.now() >= this._nextGethashTimeMs[aGethashUrl]; |            Date.now() >= this._nextGethashTimeMs[aGethashUrl]; | ||||||
|   }, |   }, | ||||||
|  | @ -287,7 +287,7 @@ HashCompleter.prototype = { | ||||||
|   // Notifies the RequestBackoff of a new request so we can throttle based on
 |   // Notifies the RequestBackoff of a new request so we can throttle based on
 | ||||||
|   // max requests/time period. This must be called before a channel is opened,
 |   // max requests/time period. This must be called before a channel is opened,
 | ||||||
|   // and finishRequest must be called once the response is received.
 |   // and finishRequest must be called once the response is received.
 | ||||||
|   noteRequest: function(aGethashUrl) { |   noteRequest(aGethashUrl) { | ||||||
|     return this._backoffs[aGethashUrl].noteRequest(); |     return this._backoffs[aGethashUrl].noteRequest(); | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|  | @ -339,17 +339,17 @@ HashCompleterRequest.prototype = { | ||||||
|       partialHash: aPartialHash, |       partialHash: aPartialHash, | ||||||
|       callback: aCallback, |       callback: aCallback, | ||||||
|       tableName: aTableName, |       tableName: aTableName, | ||||||
|       response: { matches:[] }, |       response: { matches: [] }, | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     if (aTableName) { |     if (aTableName) { | ||||||
|       let isTableNameV4 = aTableName.endsWith('-proto'); |       let isTableNameV4 = aTableName.endsWith("-proto"); | ||||||
|       if (0 === this.tableNames.size) { |       if (0 === this.tableNames.size) { | ||||||
|         // Decide if this request is v4 by the first added partial hash.
 |         // Decide if this request is v4 by the first added partial hash.
 | ||||||
|         this.isV4 = isTableNameV4; |         this.isV4 = isTableNameV4; | ||||||
|       } else if (this.isV4 !== isTableNameV4) { |       } else if (this.isV4 !== isTableNameV4) { | ||||||
|         log('ERROR: Cannot mix "proto" tables with other types within ' + |         log('ERROR: Cannot mix "proto" tables with other types within ' + | ||||||
|             'the same gethash URL.'); |             "the same gethash URL."); | ||||||
|       } |       } | ||||||
|       this.tableNames.set(aTableName); |       this.tableNames.set(aTableName); | ||||||
| 
 | 
 | ||||||
|  | @ -403,8 +403,7 @@ HashCompleterRequest.prototype = { | ||||||
|         // Notify the RequestBackoff if opening the channel succeeded. At this
 |         // Notify the RequestBackoff if opening the channel succeeded. At this
 | ||||||
|         // point, finishRequest must be called.
 |         // point, finishRequest must be called.
 | ||||||
|         this._completer.noteRequest(this.gethashUrl); |         this._completer.noteRequest(this.gethashUrl); | ||||||
|       } |       } catch (err) { | ||||||
|       catch (err) { |  | ||||||
|         this.notifyFailure(err); |         this.notifyFailure(err); | ||||||
|         throw err; |         throw err; | ||||||
|       } |       } | ||||||
|  | @ -490,8 +489,8 @@ HashCompleterRequest.prototype = { | ||||||
|     this._requests.forEach(r => prefixSet.add(btoa(r.partialHash))); |     this._requests.forEach(r => prefixSet.add(btoa(r.partialHash))); | ||||||
|     let prefixArray = Array.from(prefixSet).sort(); |     let prefixArray = Array.from(prefixSet).sort(); | ||||||
| 
 | 
 | ||||||
|     log("Build v4 gethash request with " + JSON.stringify(tableNameArray) + ', ' |     log("Build v4 gethash request with " + JSON.stringify(tableNameArray) + ", " | ||||||
|                                          + JSON.stringify(stateArray) + ', ' |                                          + JSON.stringify(stateArray) + ", " | ||||||
|                                          + JSON.stringify(prefixArray)); |                                          + JSON.stringify(prefixArray)); | ||||||
| 
 | 
 | ||||||
|     return gUrlUtil.makeFindFullHashRequestV4(tableNameArray, |     return gUrlUtil.makeFindFullHashRequestV4(tableNameArray, | ||||||
|  | @ -522,7 +521,7 @@ HashCompleterRequest.prototype = { | ||||||
|     body = PARTIAL_LENGTH + ":" + (PARTIAL_LENGTH * prefixes.length) + |     body = PARTIAL_LENGTH + ":" + (PARTIAL_LENGTH * prefixes.length) + | ||||||
|            "\n" + prefixes.join(""); |            "\n" + prefixes.join(""); | ||||||
| 
 | 
 | ||||||
|     log('Requesting completions for ' + prefixes.length + ' ' + PARTIAL_LENGTH + '-byte prefixes: ' + body); |     log("Requesting completions for " + prefixes.length + " " + PARTIAL_LENGTH + "-byte prefixes: " + body); | ||||||
|     return body; |     return body; | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|  | @ -563,9 +562,9 @@ HashCompleterRequest.prototype = { | ||||||
|     let callback = { |     let callback = { | ||||||
|       // onCompleteHashFound will be called for each fullhash found in
 |       // onCompleteHashFound will be called for each fullhash found in
 | ||||||
|       // FullHashResponse.
 |       // FullHashResponse.
 | ||||||
|       onCompleteHashFound : (aCompleteHash, |       onCompleteHashFound: (aCompleteHash, | ||||||
|                              aTableNames, |                             aTableNames, | ||||||
|                              aPerHashCacheDuration) => { |                             aPerHashCacheDuration) => { | ||||||
|         log("V4 fullhash response complete hash found callback: " + |         log("V4 fullhash response complete hash found callback: " + | ||||||
|             JSON.stringify(aCompleteHash) + ", " + |             JSON.stringify(aCompleteHash) + ", " + | ||||||
|             aTableNames + ", CacheDuration(" + aPerHashCacheDuration + ")"); |             aTableNames + ", CacheDuration(" + aPerHashCacheDuration + ")"); | ||||||
|  | @ -592,8 +591,8 @@ HashCompleterRequest.prototype = { | ||||||
|       // onResponseParsed will be called no matter if there is match in
 |       // onResponseParsed will be called no matter if there is match in
 | ||||||
|       // FullHashResponse, the callback is mainly used to pass negative cache
 |       // FullHashResponse, the callback is mainly used to pass negative cache
 | ||||||
|       // duration and minimum wait duration.
 |       // duration and minimum wait duration.
 | ||||||
|       onResponseParsed : (aMinWaitDuration, |       onResponseParsed: (aMinWaitDuration, | ||||||
|                           aNegCacheDuration) => { |                         aNegCacheDuration) => { | ||||||
|         log("V4 fullhash response parsed callback: " + |         log("V4 fullhash response parsed callback: " + | ||||||
|             "MinWaitDuration(" + aMinWaitDuration + "), " + |             "MinWaitDuration(" + aMinWaitDuration + "), " + | ||||||
|             "NegativeCacheDuration(" + aNegCacheDuration + ")"); |             "NegativeCacheDuration(" + aNegCacheDuration + ")"); | ||||||
|  | @ -644,7 +643,7 @@ HashCompleterRequest.prototype = { | ||||||
|     let addChunk = parseInt(entries[1]); |     let addChunk = parseInt(entries[1]); | ||||||
|     let dataLength = parseInt(entries[2]); |     let dataLength = parseInt(entries[2]); | ||||||
| 
 | 
 | ||||||
|     log('Response includes add chunks for ' + list + ': ' + addChunk); |     log("Response includes add chunks for " + list + ": " + addChunk); | ||||||
|     if (dataLength % COMPLETE_LENGTH != 0 || |     if (dataLength % COMPLETE_LENGTH != 0 || | ||||||
|         dataLength == 0 || |         dataLength == 0 || | ||||||
|         dataLength > body.length - (newlineIndex + 1)) { |         dataLength > body.length - (newlineIndex + 1)) { | ||||||
|  | @ -761,7 +760,7 @@ HashCompleterRequest.prototype = { | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|     let success = Components.isSuccessCode(aStatusCode); |     let success = Components.isSuccessCode(aStatusCode); | ||||||
|     log('Received a ' + httpStatus + ' status code from the gethash server (success=' + success + ').'); |     log("Received a " + httpStatus + " status code from the gethash server (success=" + success + ")."); | ||||||
| 
 | 
 | ||||||
|     Services.telemetry.getKeyedHistogramById("URLCLASSIFIER_COMPLETE_REMOTE_STATUS2"). |     Services.telemetry.getKeyedHistogramById("URLCLASSIFIER_COMPLETE_REMOTE_STATUS2"). | ||||||
|       add(this.telemetryProvider, httpStatusToBucket(httpStatus)); |       add(this.telemetryProvider, httpStatusToBucket(httpStatus)); | ||||||
|  | @ -779,8 +778,7 @@ HashCompleterRequest.prototype = { | ||||||
|     if (success) { |     if (success) { | ||||||
|       try { |       try { | ||||||
|         this.handleResponse(); |         this.handleResponse(); | ||||||
|       } |       } catch (err) { | ||||||
|       catch (err) { |  | ||||||
|         log(err.stack); |         log(err.stack); | ||||||
|         aStatusCode = err.value; |         aStatusCode = err.value; | ||||||
|         success = false; |         success = false; | ||||||
|  |  | ||||||
|  | @ -212,9 +212,8 @@ PROT_ListManager.prototype.requireTableUpdates = function() { | ||||||
| /** | /** | ||||||
|  *  Set timer to check update after delay |  *  Set timer to check update after delay | ||||||
|  */ |  */ | ||||||
| PROT_ListManager.prototype.setUpdateCheckTimer = function (updateUrl, | PROT_ListManager.prototype.setUpdateCheckTimer = function(updateUrl, | ||||||
|                                                            delay) |                                                           delay) { | ||||||
| { |  | ||||||
|   this.updateCheckers_[updateUrl] = Cc["@mozilla.org/timer;1"] |   this.updateCheckers_[updateUrl] = Cc["@mozilla.org/timer;1"] | ||||||
|                                     .createInstance(Ci.nsITimer); |                                     .createInstance(Ci.nsITimer); | ||||||
|   this.updateCheckers_[updateUrl].initWithCallback(() => { |   this.updateCheckers_[updateUrl].initWithCallback(() => { | ||||||
|  | @ -225,8 +224,7 @@ PROT_ListManager.prototype.setUpdateCheckTimer = function (updateUrl, | ||||||
| /** | /** | ||||||
|  * Acts as a nsIUrlClassifierCallback for getTables. |  * Acts as a nsIUrlClassifierCallback for getTables. | ||||||
|  */ |  */ | ||||||
| PROT_ListManager.prototype.kickoffUpdate_ = function (onDiskTableData) | PROT_ListManager.prototype.kickoffUpdate_ = function(onDiskTableData) { | ||||||
| { |  | ||||||
|   this.startingUpdate_ = false; |   this.startingUpdate_ = false; | ||||||
|   var initialUpdateDelay = 3000; |   var initialUpdateDelay = 3000; | ||||||
|   // Add a fuzz of 0-1 minutes for both v2 and v4 according to Bug 1305478.
 |   // Add a fuzz of 0-1 minutes for both v2 and v4 according to Bug 1305478.
 | ||||||
|  | @ -371,13 +369,13 @@ PROT_ListManager.prototype.makeUpdateRequest_ = function(updateUrl, tableData) { | ||||||
|     // Check if |updateURL| is for 'proto'. (only v4 uses protobuf for now.)
 |     // Check if |updateURL| is for 'proto'. (only v4 uses protobuf for now.)
 | ||||||
|     // We use the table name 'goog-*-proto' and an additional provider "google4"
 |     // We use the table name 'goog-*-proto' and an additional provider "google4"
 | ||||||
|     // to describe the v4 settings.
 |     // to describe the v4 settings.
 | ||||||
|     let isCurTableProto = tableName.endsWith('-proto'); |     let isCurTableProto = tableName.endsWith("-proto"); | ||||||
|     if (!onceThru) { |     if (!onceThru) { | ||||||
|       useProtobuf = isCurTableProto; |       useProtobuf = isCurTableProto; | ||||||
|       onceThru = true; |       onceThru = true; | ||||||
|     } else if (useProtobuf !== isCurTableProto) { |     } else if (useProtobuf !== isCurTableProto) { | ||||||
|       log('ERROR: Cannot mix "proto" tables with other types ' + |       log('ERROR: Cannot mix "proto" tables with other types ' + | ||||||
|           'within the same provider.'); |           "within the same provider."); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (this.needsUpdate_[this.tablesData[tableName].updateUrl][tableName]) { |     if (this.needsUpdate_[this.tablesData[tableName].updateUrl][tableName]) { | ||||||
|  | @ -648,13 +646,12 @@ function Init() { | ||||||
|   modScope.Init = function() {}; |   modScope.Init = function() {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function RegistrationData() | function RegistrationData() { | ||||||
| { |  | ||||||
| } | } | ||||||
| RegistrationData.prototype = { | RegistrationData.prototype = { | ||||||
|     classID: Components.ID("{ca168834-cc00-48f9-b83c-fd018e58cae3}"), |     classID: Components.ID("{ca168834-cc00-48f9-b83c-fd018e58cae3}"), | ||||||
|     _xpcom_factory: { |     _xpcom_factory: { | ||||||
|         createInstance: function(outer, iid) { |         createInstance(outer, iid) { | ||||||
|             if (outer != null) |             if (outer != null) | ||||||
|                 throw Components.results.NS_ERROR_NO_AGGREGATION; |                 throw Components.results.NS_ERROR_NO_AGGREGATION; | ||||||
|             Init(); |             Init(); | ||||||
|  |  | ||||||
|  | @ -97,7 +97,7 @@ this.UrlClassifierTestUtils = { | ||||||
|         updateUrlRequested: url => { }, |         updateUrlRequested: url => { }, | ||||||
|         streamFinished: status => { }, |         streamFinished: status => { }, | ||||||
|         updateError: errorCode => { |         updateError: errorCode => { | ||||||
|           reject('Got updateError when updating ' + table.name); |           reject("Got updateError when updating " + table.name); | ||||||
|         }, |         }, | ||||||
|         updateSuccess: requestedTimeout => { |         updateSuccess: requestedTimeout => { | ||||||
|           resolve(); |           resolve(); | ||||||
|  | @ -111,7 +111,7 @@ this.UrlClassifierTestUtils = { | ||||||
|         dbService.finishStream(); |         dbService.finishStream(); | ||||||
|         dbService.finishUpdate(); |         dbService.finishUpdate(); | ||||||
|       } catch (e) { |       } catch (e) { | ||||||
|         reject('Failed to update with dbService: ' + table.name); |         reject("Failed to update with dbService: " + table.name); | ||||||
|       } |       } | ||||||
|     }); |     }); | ||||||
|   }, |   }, | ||||||
|  |  | ||||||
|  | @ -17,9 +17,9 @@ if (typeof(classifierHelper) == "undefined") { | ||||||
| const HASHLEN = 32; | const HASHLEN = 32; | ||||||
| 
 | 
 | ||||||
| const PREFS = { | const PREFS = { | ||||||
|   PROVIDER_LISTS : "browser.safebrowsing.provider.mozilla.lists", |   PROVIDER_LISTS: "browser.safebrowsing.provider.mozilla.lists", | ||||||
|   DISALLOW_COMPLETIONS : "urlclassifier.disallow_completions", |   DISALLOW_COMPLETIONS: "urlclassifier.disallow_completions", | ||||||
|   PROVIDER_GETHASHURL : "browser.safebrowsing.provider.mozilla.gethashURL" |   PROVIDER_GETHASHURL: "browser.safebrowsing.provider.mozilla.gethashURL" | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| classifierHelper._curAddChunkNum = 1; | classifierHelper._curAddChunkNum = 1; | ||||||
|  | @ -53,16 +53,14 @@ classifierHelper.waitForInit = function() { | ||||||
|     }, "mozentries-update-finished"); |     }, "mozentries-update-finished"); | ||||||
| 
 | 
 | ||||||
|     let listener = { |     let listener = { | ||||||
|       QueryInterface: function(iid) |       QueryInterface(iid) { | ||||||
|       { |  | ||||||
|         if (iid.equals(Ci.nsISupports) || |         if (iid.equals(Ci.nsISupports) || | ||||||
|           iid.equals(Ci.nsIUrlClassifierUpdateObserver)) |           iid.equals(Ci.nsIUrlClassifierUpdateObserver)) | ||||||
|           return this; |           return this; | ||||||
|         throw Cr.NS_ERROR_NO_INTERFACE; |         throw Cr.NS_ERROR_NO_INTERFACE; | ||||||
|       }, |       }, | ||||||
| 
 | 
 | ||||||
|       handleEvent: function(value) |       handleEvent(value) { | ||||||
|       { |  | ||||||
|         if (value === table) { |         if (value === table) { | ||||||
|           resolve(); |           resolve(); | ||||||
|         } |         } | ||||||
|  | @ -146,20 +144,19 @@ classifierHelper._update = function(update) { | ||||||
|       try { |       try { | ||||||
|         await new Promise((resolve, reject) => { |         await new Promise((resolve, reject) => { | ||||||
|           let listener = { |           let listener = { | ||||||
|             QueryInterface: function(iid) |             QueryInterface(iid) { | ||||||
|             { |  | ||||||
|               if (iid.equals(Ci.nsISupports) || |               if (iid.equals(Ci.nsISupports) || | ||||||
|                   iid.equals(Ci.nsIUrlClassifierUpdateObserver)) |                   iid.equals(Ci.nsIUrlClassifierUpdateObserver)) | ||||||
|                 return this; |                 return this; | ||||||
| 
 | 
 | ||||||
|               throw Cr.NS_ERROR_NO_INTERFACE; |               throw Cr.NS_ERROR_NO_INTERFACE; | ||||||
|             }, |             }, | ||||||
|             updateUrlRequested: function(url) { }, |             updateUrlRequested(url) { }, | ||||||
|             streamFinished: function(status) { }, |             streamFinished(status) { }, | ||||||
|             updateError: function(errorCode) { |             updateError(errorCode) { | ||||||
|               reject(errorCode); |               reject(errorCode); | ||||||
|             }, |             }, | ||||||
|             updateSuccess: function(requestedTimeout) { |             updateSuccess(requestedTimeout) { | ||||||
|               resolve(); |               resolve(); | ||||||
|             } |             } | ||||||
|           }; |           }; | ||||||
|  | @ -170,7 +167,7 @@ classifierHelper._update = function(update) { | ||||||
|           dbService.finishUpdate(); |           dbService.finishUpdate(); | ||||||
|         }); |         }); | ||||||
|         success = true; |         success = true; | ||||||
|       } catch(e) { |       } catch (e) { | ||||||
|         // Wait 1 second before trying again.
 |         // Wait 1 second before trying again.
 | ||||||
|         await new Promise(resolve => setTimeout(resolve, 1000)); |         await new Promise(resolve => setTimeout(resolve, 1000)); | ||||||
|       } |       } | ||||||
|  |  | ||||||
|  | @ -48,7 +48,7 @@ var classifierTester = { | ||||||
|     } |     } | ||||||
|   ], |   ], | ||||||
| 
 | 
 | ||||||
|   setPrefs: function ({setDBs = true, flashBlockEnable = true, flashSetting = classifierTester.ALWAYS_ACTIVATE_PREF_VALUE} = {}) { |   setPrefs({setDBs = true, flashBlockEnable = true, flashSetting = classifierTester.ALWAYS_ACTIVATE_PREF_VALUE} = {}) { | ||||||
|     if (setDBs) { |     if (setDBs) { | ||||||
|       let DBs = []; |       let DBs = []; | ||||||
| 
 | 
 | ||||||
|  | @ -69,7 +69,7 @@ var classifierTester = { | ||||||
|     Services.prefs.setBoolPref(classifierTester.ALLOW_CTA_PREF, true); |     Services.prefs.setBoolPref(classifierTester.ALLOW_CTA_PREF, true); | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   unsetPrefs: function () { |   unsetPrefs() { | ||||||
|     for (let dbData of classifierTester.dbUrls) { |     for (let dbData of classifierTester.dbUrls) { | ||||||
|       Services.prefs.clearUserPref(dbData.pref); |       Services.prefs.clearUserPref(dbData.pref); | ||||||
|     } |     } | ||||||
|  | @ -184,8 +184,8 @@ var classifierTester = { | ||||||
| 
 | 
 | ||||||
|   // Returns null if this value should not be verified given the combination
 |   // Returns null if this value should not be verified given the combination
 | ||||||
|   // of inputs
 |   // of inputs
 | ||||||
|   expectedPluginFallbackType: function (classification, flashSetting) { |   expectedPluginFallbackType(classification, flashSetting) { | ||||||
|     switch(classification) { |     switch (classification) { | ||||||
|       case "unknown": |       case "unknown": | ||||||
|         if (flashSetting == classifierTester.ALWAYS_ACTIVATE_PREF_VALUE) { |         if (flashSetting == classifierTester.ALWAYS_ACTIVATE_PREF_VALUE) { | ||||||
|           return null; |           return null; | ||||||
|  | @ -208,8 +208,8 @@ var classifierTester = { | ||||||
| 
 | 
 | ||||||
|   // Returns null if this value should not be verified given the combination
 |   // Returns null if this value should not be verified given the combination
 | ||||||
|   // of inputs
 |   // of inputs
 | ||||||
|   expectedActivated: function (classification, flashSetting) { |   expectedActivated(classification, flashSetting) { | ||||||
|     switch(classification) { |     switch (classification) { | ||||||
|       case "unknown": |       case "unknown": | ||||||
|         return (flashSetting == classifierTester.ALWAYS_ACTIVATE_PREF_VALUE); |         return (flashSetting == classifierTester.ALWAYS_ACTIVATE_PREF_VALUE); | ||||||
|       case "allowed": |       case "allowed": | ||||||
|  | @ -222,8 +222,8 @@ var classifierTester = { | ||||||
| 
 | 
 | ||||||
|   // Returns null if this value should not be verified given the combination
 |   // Returns null if this value should not be verified given the combination
 | ||||||
|   // of inputs
 |   // of inputs
 | ||||||
|   expectedHasRunningPlugin: function (classification, flashSetting) { |   expectedHasRunningPlugin(classification, flashSetting) { | ||||||
|     switch(classification) { |     switch (classification) { | ||||||
|       case "unknown": |       case "unknown": | ||||||
|         return (flashSetting == classifierTester.ALWAYS_ACTIVATE_PREF_VALUE); |         return (flashSetting == classifierTester.ALWAYS_ACTIVATE_PREF_VALUE); | ||||||
|       case "allowed": |       case "allowed": | ||||||
|  | @ -236,12 +236,12 @@ var classifierTester = { | ||||||
| 
 | 
 | ||||||
|   // Returns null if this value should not be verified given the combination
 |   // Returns null if this value should not be verified given the combination
 | ||||||
|   // of inputs
 |   // of inputs
 | ||||||
|   expectedPluginListed: function (classification, flashSetting) { |   expectedPluginListed(classification, flashSetting) { | ||||||
|     if (flashSetting == classifierTester.ASK_TO_ACTIVATE_PREF_VALUE && |     if (flashSetting == classifierTester.ASK_TO_ACTIVATE_PREF_VALUE && | ||||||
|         Services.prefs.getCharPref('plugins.navigator.hidden_ctp_plugin') == "Shockwave Flash") { |         Services.prefs.getCharPref("plugins.navigator.hidden_ctp_plugin") == "Shockwave Flash") { | ||||||
|       return false; |       return false; | ||||||
|     } |     } | ||||||
|     switch(classification) { |     switch (classification) { | ||||||
|       case "unknown": |       case "unknown": | ||||||
|       case "allowed": |       case "allowed": | ||||||
|         return (flashSetting != classifierTester.NEVER_ACTIVATE_PREF_VALUE); |         return (flashSetting != classifierTester.NEVER_ACTIVATE_PREF_VALUE); | ||||||
|  | @ -251,7 +251,7 @@ var classifierTester = { | ||||||
|     throw new Error("Invalid classification or flash setting"); |     throw new Error("Invalid classification or flash setting"); | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   buildTestCaseInNewTab: function (browser, testCase) { |   buildTestCaseInNewTab(browser, testCase) { | ||||||
|     return (async function() { |     return (async function() { | ||||||
|       let iframeDomains = testCase.domains.slice(); |       let iframeDomains = testCase.domains.slice(); | ||||||
|       let pageDomain = iframeDomains.shift(); |       let pageDomain = iframeDomains.shift(); | ||||||
|  | @ -265,7 +265,7 @@ var classifierTester = { | ||||||
|         let url = domain + classifierTester.URL_PATH + "?date=" + Date.now() + "rand=" + Math.random(); |         let url = domain + classifierTester.URL_PATH + "?date=" + Date.now() + "rand=" + Math.random(); | ||||||
|         let domainLoaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser, true, url); |         let domainLoaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser, true, url); | ||||||
| 
 | 
 | ||||||
|         ContentTask.spawn(tab.linkedBrowser, {iframeId: classifierTester.IFRAME_ID, url: url, depth: depth}, |         ContentTask.spawn(tab.linkedBrowser, {iframeId: classifierTester.IFRAME_ID, url, depth}, | ||||||
|                           async function({iframeId, url, depth}) { |                           async function({iframeId, url, depth}) { | ||||||
|           let doc = content.document; |           let doc = content.document; | ||||||
|           for (let i = 0; i < depth; ++i) { |           for (let i = 0; i < depth; ++i) { | ||||||
|  | @ -281,9 +281,9 @@ var classifierTester = { | ||||||
|     })(); |     })(); | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   getPluginInfo: function (browser, depth) { |   getPluginInfo(browser, depth) { | ||||||
|     return ContentTask.spawn(browser, |     return ContentTask.spawn(browser, | ||||||
|                              {iframeId: classifierTester.IFRAME_ID, depth: depth}, |                              {iframeId: classifierTester.IFRAME_ID, depth}, | ||||||
|                              async function({iframeId, depth}) { |                              async function({iframeId, depth}) { | ||||||
|       let doc = content.document; |       let doc = content.document; | ||||||
|       let win = content.window; |       let win = content.window; | ||||||
|  | @ -307,7 +307,7 @@ var classifierTester = { | ||||||
|     }); |     }); | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   checkPluginInfo: function (pluginInfo, expectedClassification, flashSetting) { |   checkPluginInfo(pluginInfo, expectedClassification, flashSetting) { | ||||||
|     is(pluginInfo.flashClassification, expectedClassification, |     is(pluginInfo.flashClassification, expectedClassification, | ||||||
|        "Page's classification should match expected"); |        "Page's classification should match expected"); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -88,21 +88,21 @@ v.addEventListener("error", function() { | ||||||
| var newScript = document.createElement("script"); | var newScript = document.createElement("script"); | ||||||
| newScript.id = "badscript2"; | newScript.id = "badscript2"; | ||||||
| newScript.src = "http://tracking.example.com/tests/toolkit/components/url-classifier/tests/mochitest/evil.js"; | newScript.src = "http://tracking.example.com/tests/toolkit/components/url-classifier/tests/mochitest/evil.js"; | ||||||
| newScript.addEventListener("load", function onload() {scriptItem2 = 'spoiled';}); | newScript.addEventListener("load", function onload() { scriptItem2 = "spoiled"; }); | ||||||
| document.body.appendChild(newScript); | document.body.appendChild(newScript); | ||||||
| 
 | 
 | ||||||
| /// Try loading from a tracking image URI (2) | // / Try loading from a tracking image URI (2) | ||||||
| var newImage = document.createElement("img"); | var newImage = document.createElement("img"); | ||||||
| newImage.id = "badimage2"; | newImage.id = "badimage2"; | ||||||
| newImage.src = "http://tracking.example.com/tests/toolkit/components/url-classifier/tests/mochitest/raptor.jpg"; | newImage.src = "http://tracking.example.com/tests/toolkit/components/url-classifier/tests/mochitest/raptor.jpg"; | ||||||
| newImage.addEventListener("load", function onload() {imageItem2 = 'spoiled'}); | newImage.addEventListener("load", function onload() { imageItem2 = "spoiled" }); | ||||||
| document.body.appendChild(newImage); | document.body.appendChild(newImage); | ||||||
| 
 | 
 | ||||||
| // Try loading from a tracking iframe URI (2) | // Try loading from a tracking iframe URI (2) | ||||||
| var newFrame = document.createElement("iframe"); | var newFrame = document.createElement("iframe"); | ||||||
| newFrame.id = "badframe2"; | newFrame.id = "badframe2"; | ||||||
| newFrame.src = "http://tracking.example.com/tests/toolkit/components/url-classifier/tests/mochitest/track.html" | newFrame.src = "http://tracking.example.com/tests/toolkit/components/url-classifier/tests/mochitest/track.html" | ||||||
| newFrame.addEventListener("load", function onload() {frameItem2 = 'spoiled'}); | newFrame.addEventListener("load", function onload() { frameItem2 = "spoiled" }); | ||||||
| document.body.appendChild(newFrame); | document.body.appendChild(newFrame); | ||||||
| 
 | 
 | ||||||
| // Try doing an XHR against a tracking domain (bug 1216793) | // Try doing an XHR against a tracking domain (bug 1216793) | ||||||
|  | @ -127,7 +127,7 @@ oReq.send(); | ||||||
| 
 | 
 | ||||||
| // Fetch from a tracking domain | // Fetch from a tracking domain | ||||||
| fetch("http://tracking.example.com/tests/toolkit/components/url-classifier/tests/mochitest/evil.js").then(function(response) { | fetch("http://tracking.example.com/tests/toolkit/components/url-classifier/tests/mochitest/evil.js").then(function(response) { | ||||||
|     if(response.ok) { |     if (response.ok) { | ||||||
|         fetchItem = "loaded"; |         fetchItem = "loaded"; | ||||||
|         loaded("fetch"); |         loaded("fetch"); | ||||||
|     } else { |     } else { | ||||||
|  |  | ||||||
|  | @ -154,21 +154,21 @@ v.addEventListener("error", function() { | ||||||
| var newScript = document.createElement("script"); | var newScript = document.createElement("script"); | ||||||
| newScript.id = "badscript2"; | newScript.id = "badscript2"; | ||||||
| newScript.src = "http://tracking.example.com/tests/toolkit/components/url-classifier/tests/mochitest/evil.js"; | newScript.src = "http://tracking.example.com/tests/toolkit/components/url-classifier/tests/mochitest/evil.js"; | ||||||
| newScript.addEventListener("load", function() {scriptItem2 = scriptItem;}); | newScript.addEventListener("load", function() { scriptItem2 = scriptItem; }); | ||||||
| document.body.appendChild(newScript); | document.body.appendChild(newScript); | ||||||
| 
 | 
 | ||||||
| /// Try loading from a tracking image URI (2) | // Try loading from a tracking image URI (2) | ||||||
| var newImage = document.createElement("img"); | var newImage = document.createElement("img"); | ||||||
| newImage.id = "badimage2"; | newImage.id = "badimage2"; | ||||||
| newImage.src = "http://tracking.example.com/tests/toolkit/components/url-classifier/tests/mochitest/raptor.jpg?reload=true"; | newImage.src = "http://tracking.example.com/tests/toolkit/components/url-classifier/tests/mochitest/raptor.jpg?reload=true"; | ||||||
| newImage.addEventListener("load", function() {imageItem2 = 'spoiled'}); | newImage.addEventListener("load", function() { imageItem2 = "spoiled" }); | ||||||
| document.body.appendChild(newImage); | document.body.appendChild(newImage); | ||||||
| 
 | 
 | ||||||
| // Try loading from a tracking iframe URI (2) | // Try loading from a tracking iframe URI (2) | ||||||
| var newFrame = document.createElement("iframe"); | var newFrame = document.createElement("iframe"); | ||||||
| newFrame.id = "badframe2"; | newFrame.id = "badframe2"; | ||||||
| newFrame.src = "http://tracking.example.com/tests/toolkit/components/url-classifier/tests/mochitest/track.html" | newFrame.src = "http://tracking.example.com/tests/toolkit/components/url-classifier/tests/mochitest/track.html" | ||||||
| newFrame.addEventListener("load", function() {frameItem2 = 'spoiled'}); | newFrame.addEventListener("load", function() { frameItem2 = "spoiled" }); | ||||||
| document.body.appendChild(newFrame); | document.body.appendChild(newFrame); | ||||||
| 
 | 
 | ||||||
| // Try doing an XHR against a tracking domain (bug 1216793) | // Try doing an XHR against a tracking domain (bug 1216793) | ||||||
|  | @ -193,7 +193,7 @@ oReq.send(); | ||||||
| 
 | 
 | ||||||
| // Fetch from a tracking domain | // Fetch from a tracking domain | ||||||
| fetch("http://tracking.example.com/tests/toolkit/components/url-classifier/tests/mochitest/evil.js").then(function(response) { | fetch("http://tracking.example.com/tests/toolkit/components/url-classifier/tests/mochitest/evil.js").then(function(response) { | ||||||
|     if(response.ok) { |     if (response.ok) { | ||||||
|         fetchItem = "loaded"; |         fetchItem = "loaded"; | ||||||
|         loaded("fetch"); |         loaded("fetch"); | ||||||
|     } else { |     } else { | ||||||
|  |  | ||||||
|  | @ -16,20 +16,19 @@ function setTimeout(callback, delay) { | ||||||
| 
 | 
 | ||||||
| function doUpdate(update) { | function doUpdate(update) { | ||||||
|   let listener = { |   let listener = { | ||||||
|     QueryInterface: function(iid) |     QueryInterface(iid) { | ||||||
|     { |  | ||||||
|       if (iid.equals(Ci.nsISupports) || |       if (iid.equals(Ci.nsISupports) || | ||||||
|           iid.equals(Ci.nsIUrlClassifierUpdateObserver)) |           iid.equals(Ci.nsIUrlClassifierUpdateObserver)) | ||||||
|         return this; |         return this; | ||||||
| 
 | 
 | ||||||
|       throw Cr.NS_ERROR_NO_INTERFACE; |       throw Cr.NS_ERROR_NO_INTERFACE; | ||||||
|     }, |     }, | ||||||
|     updateUrlRequested: function(url) { }, |     updateUrlRequested(url) { }, | ||||||
|     streamFinished: function(status) { }, |     streamFinished(status) { }, | ||||||
|     updateError: function(errorCode) { |     updateError(errorCode) { | ||||||
|       sendAsyncMessage("updateError", errorCode); |       sendAsyncMessage("updateError", errorCode); | ||||||
|     }, |     }, | ||||||
|     updateSuccess: function(requestedTimeout) { |     updateSuccess(requestedTimeout) { | ||||||
|       sendAsyncMessage("updateSuccess"); |       sendAsyncMessage("updateSuccess"); | ||||||
|     } |     } | ||||||
|   }; |   }; | ||||||
|  | @ -43,7 +42,7 @@ function doUpdate(update) { | ||||||
|     dbService.updateStream(update); |     dbService.updateStream(update); | ||||||
|     dbService.finishStream(); |     dbService.finishStream(); | ||||||
|     dbService.finishUpdate(); |     dbService.finishUpdate(); | ||||||
|   } catch(e) { |   } catch (e) { | ||||||
|     // beginUpdate may fail if there's an existing update in progress
 |     // beginUpdate may fail if there's an existing update in progress
 | ||||||
|     // retry until success or testcase timeout.
 |     // retry until success or testcase timeout.
 | ||||||
|     setTimeout(() => { doUpdate(update); }, 1000); |     setTimeout(() => { doUpdate(update); }, 1000); | ||||||
|  | @ -54,7 +53,7 @@ function doReload() { | ||||||
|   try { |   try { | ||||||
|     dbService.reloadDatabase(); |     dbService.reloadDatabase(); | ||||||
|     sendAsyncMessage("reloadSuccess"); |     sendAsyncMessage("reloadSuccess"); | ||||||
|   } catch(e) { |   } catch (e) { | ||||||
|     setTimeout(() => { doReload(); }, 1000); |     setTimeout(() => { doReload(); }, 1000); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | @ -84,16 +83,14 @@ function waitForInit() { | ||||||
|     iosvc.newURI(url), {}); |     iosvc.newURI(url), {}); | ||||||
| 
 | 
 | ||||||
|   let listener = { |   let listener = { | ||||||
|     QueryInterface: function(iid) |     QueryInterface(iid) { | ||||||
|     { |  | ||||||
|       if (iid.equals(Ci.nsISupports) || |       if (iid.equals(Ci.nsISupports) || | ||||||
|         iid.equals(Ci.nsIUrlClassifierUpdateObserver)) |         iid.equals(Ci.nsIUrlClassifierUpdateObserver)) | ||||||
|         return this; |         return this; | ||||||
|       throw Cr.NS_ERROR_NO_INTERFACE; |       throw Cr.NS_ERROR_NO_INTERFACE; | ||||||
|     }, |     }, | ||||||
| 
 | 
 | ||||||
|     handleEvent: function(value) |     handleEvent(value) { | ||||||
|     { |  | ||||||
|       if (value === table) { |       if (value === table) { | ||||||
|         sendAsyncMessage("safeBrowsingInited"); |         sendAsyncMessage("safeBrowsingInited"); | ||||||
|       } |       } | ||||||
|  |  | ||||||
|  | @ -33,7 +33,7 @@ function checkLoads() { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   let dwu = window.parent.SpecialPowers.getDOMWindowUtils(window); |   let dwu = window.parent.SpecialPowers.getDOMWindowUtils(window); | ||||||
|   let timer1 = window.setTimeout(function(){}, 0); |   let timer1 = window.setTimeout(function() {}, 0); | ||||||
|   window.parent.ok(!dwu.isTimeoutTracking(timer1), |   window.parent.ok(!dwu.isTimeoutTracking(timer1), | ||||||
|                    "Timeout set from main script should not be considered as tracking"); |                    "Timeout set from main script should not be considered as tracking"); | ||||||
|   let timer2 = getTrackerTimeout(); |   let timer2 = getTrackerTimeout(); | ||||||
|  |  | ||||||
|  | @ -8,9 +8,9 @@ var gScript = SpecialPowers.loadChromeScript(CLASSIFIER_COMMON_URL); | ||||||
| const HASHLEN = 32; | const HASHLEN = 32; | ||||||
| 
 | 
 | ||||||
| const PREFS = { | const PREFS = { | ||||||
|   PROVIDER_LISTS : "browser.safebrowsing.provider.mozilla.lists", |   PROVIDER_LISTS: "browser.safebrowsing.provider.mozilla.lists", | ||||||
|   DISALLOW_COMPLETIONS : "urlclassifier.disallow_completions", |   DISALLOW_COMPLETIONS: "urlclassifier.disallow_completions", | ||||||
|   PROVIDER_GETHASHURL : "browser.safebrowsing.provider.mozilla.gethashURL" |   PROVIDER_GETHASHURL: "browser.safebrowsing.provider.mozilla.gethashURL" | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| classifierHelper._curAddChunkNum = 1; | classifierHelper._curAddChunkNum = 1; | ||||||
|  | @ -109,7 +109,7 @@ classifierHelper.resetDatabase = function() { | ||||||
| classifierHelper.reloadDatabase = function() { | classifierHelper.reloadDatabase = function() { | ||||||
|   return new Promise(function(resolve, reject) { |   return new Promise(function(resolve, reject) { | ||||||
|     gScript.addMessageListener("reloadSuccess", function handler() { |     gScript.addMessageListener("reloadSuccess", function handler() { | ||||||
|       gScript.removeMessageListener('reloadSuccess', handler); |       gScript.removeMessageListener("reloadSuccess", handler); | ||||||
|       resolve(); |       resolve(); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|  | @ -150,7 +150,7 @@ classifierHelper._updateError = function(errorCode) { | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| classifierHelper._inited = function() { | classifierHelper._inited = function() { | ||||||
|   classifierHelper._initsCB.forEach(function (cb) { |   classifierHelper._initsCB.forEach(function(cb) { | ||||||
|     cb(); |     cb(); | ||||||
|   }); |   }); | ||||||
|   classifierHelper._initsCB = []; |   classifierHelper._initsCB = []; | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| onmessage = function() { | onmessage = function() { | ||||||
|   try { |   try { | ||||||
|     importScripts("evilWorker.js"); |     importScripts("evilWorker.js"); | ||||||
|   } catch(ex) { |   } catch (ex) { | ||||||
|     postMessage("success"); |     postMessage("success"); | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -6,7 +6,7 @@ | ||||||
| 
 | 
 | ||||||
| function makeXHR(url, callback) { | function makeXHR(url, callback) { | ||||||
|   var xhr = new XMLHttpRequest(); |   var xhr = new XMLHttpRequest(); | ||||||
|   xhr.open('GET', url, true); |   xhr.open("GET", url, true); | ||||||
|   xhr.onload = function() { |   xhr.onload = function() { | ||||||
|     callback(xhr.response); |     callback(xhr.response); | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|  | @ -82,7 +82,7 @@ function setupTestData(data) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function testOnWindow(aTestData) { | function testOnWindow(aTestData) { | ||||||
|   return new Promise(resolve  => { |   return new Promise(resolve => { | ||||||
|     let win = mainWindow.OpenBrowserWindow(); |     let win = mainWindow.OpenBrowserWindow(); | ||||||
| 
 | 
 | ||||||
|     (async function() { |     (async function() { | ||||||
|  | @ -117,7 +117,7 @@ function testOnWindow(aTestData) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| SpecialPowers.pushPrefEnv( | SpecialPowers.pushPrefEnv( | ||||||
|   {"set" : [["browser.safebrowsing.phishing.enabled", true]]}, |   {"set": [["browser.safebrowsing.phishing.enabled", true]]}, | ||||||
|   test); |   test); | ||||||
| 
 | 
 | ||||||
| function test() { | function test() { | ||||||
|  |  | ||||||
|  | @ -33,9 +33,9 @@ function clearPermissions() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| SpecialPowers.pushPrefEnv( | SpecialPowers.pushPrefEnv( | ||||||
|   {"set" : [["urlclassifier.trackingTable", "test-track-simple"], |   {"set": [["urlclassifier.trackingTable", "test-track-simple"], | ||||||
|             ["privacy.trackingprotection.enabled", true], |            ["privacy.trackingprotection.enabled", true], | ||||||
|             ["channelclassifier.allowlist_example", true]]}, |            ["channelclassifier.allowlist_example", true]]}, | ||||||
|   test); |   test); | ||||||
| 
 | 
 | ||||||
| function test() { | function test() { | ||||||
|  |  | ||||||
|  | @ -139,10 +139,12 @@ function testGethash() { | ||||||
|     .then(addPrefixToDB) |     .then(addPrefixToDB) | ||||||
|     .then(loadTestFrame) |     .then(loadTestFrame) | ||||||
|     .then(() => { |     .then(() => { | ||||||
|        ok(gCurGethashCounter > gPreGethashCounter, "Gethash request is triggered."); }) |        ok(gCurGethashCounter > gPreGethashCounter, "Gethash request is triggered."); | ||||||
|  | }) | ||||||
|     .then(loadTestFrame) |     .then(loadTestFrame) | ||||||
|     .then(() => { |     .then(() => { | ||||||
|       ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); }) |       ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); | ||||||
|  | }) | ||||||
|     .then(reset); |     .then(reset); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -155,7 +157,8 @@ function testUpdate() { | ||||||
|     .then(addCompletionToDB) |     .then(addCompletionToDB) | ||||||
|     .then(loadTestFrame) |     .then(loadTestFrame) | ||||||
|     .then(() => { |     .then(() => { | ||||||
|       ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); }) |       ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); | ||||||
|  | }) | ||||||
|     .then(reset); |     .then(reset); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -170,11 +173,13 @@ function testUpdateNotClearCompletions() { | ||||||
|     .then(addCompletionToDB) |     .then(addCompletionToDB) | ||||||
|     .then(loadTestFrame) |     .then(loadTestFrame) | ||||||
|     .then(() => { |     .then(() => { | ||||||
|       ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); }) |       ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); | ||||||
|  | }) | ||||||
|     .then(updateUnusedUrl) |     .then(updateUnusedUrl) | ||||||
|     .then(loadTestFrame) |     .then(loadTestFrame) | ||||||
|     .then(() => { |     .then(() => { | ||||||
|       ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); }) |       ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); | ||||||
|  | }) | ||||||
|     .then(reset); |     .then(reset); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -189,7 +194,8 @@ function testUpdateCompletionsAfterReload() { | ||||||
|     .then(classifierHelper.reloadDatabase) |     .then(classifierHelper.reloadDatabase) | ||||||
|     .then(loadTestFrame) |     .then(loadTestFrame) | ||||||
|     .then(() => { |     .then(() => { | ||||||
|       ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); }) |       ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); | ||||||
|  | }) | ||||||
|     .then(reset); |     .then(reset); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -205,14 +211,17 @@ function testGethashCompletionsAfterReload() { | ||||||
|     .then(addPrefixToDB) |     .then(addPrefixToDB) | ||||||
|     .then(loadTestFrame) |     .then(loadTestFrame) | ||||||
|     .then(() => { |     .then(() => { | ||||||
|        ok(gCurGethashCounter > gPreGethashCounter, "Gethash request is triggered."); }) |        ok(gCurGethashCounter > gPreGethashCounter, "Gethash request is triggered."); | ||||||
|  | }) | ||||||
|     .then(loadTestFrame) |     .then(loadTestFrame) | ||||||
|     .then(() => { |     .then(() => { | ||||||
|       ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); }) |       ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); | ||||||
|  | }) | ||||||
|     .then(classifierHelper.reloadDatabase) |     .then(classifierHelper.reloadDatabase) | ||||||
|     .then(loadTestFrame) |     .then(loadTestFrame) | ||||||
|     .then(() => { |     .then(() => { | ||||||
|        ok(gCurGethashCounter > gPreGethashCounter, "Gethash request is triggered."); }) |        ok(gCurGethashCounter > gPreGethashCounter, "Gethash request is triggered."); | ||||||
|  | }) | ||||||
|     .then(reset); |     .then(reset); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -61,7 +61,7 @@ function getGethashCounter() { | ||||||
| // add 4-bytes prefixes to local database, so when we access the url, | // add 4-bytes prefixes to local database, so when we access the url, | ||||||
| // it will trigger gethash request. | // it will trigger gethash request. | ||||||
| function addPrefixToDB(list, url) { | function addPrefixToDB(list, url) { | ||||||
|   var testData = [{ db: list, url: url, len: 4 }]; |   var testData = [{ db: list, url, len: 4 }]; | ||||||
| 
 | 
 | ||||||
|   return classifierHelper.addUrlToDB(testData) |   return classifierHelper.addUrlToDB(testData) | ||||||
|     .catch(function(err) { |     .catch(function(err) { | ||||||
|  | @ -96,11 +96,13 @@ function testNegativeCache() { | ||||||
|     .then(setup) |     .then(setup) | ||||||
|     .then(() => loadTestFrame()) |     .then(() => loadTestFrame()) | ||||||
|     .then(() => { |     .then(() => { | ||||||
|        ok(gCurGethashCounter > gPreGethashCounter, "Gethash request is triggered."); }) |        ok(gCurGethashCounter > gPreGethashCounter, "Gethash request is triggered."); | ||||||
|  | }) | ||||||
|     // Second load should not trigger gethash request because cache. |     // Second load should not trigger gethash request because cache. | ||||||
|     .then(() => loadTestFrame()) |     .then(() => loadTestFrame()) | ||||||
|     .then(() => { |     .then(() => { | ||||||
|        ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is nottriggered."); }) |        ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is nottriggered."); | ||||||
|  | }) | ||||||
|     .then(reset); |     .then(reset); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -122,11 +124,13 @@ function testPositiveCache() { | ||||||
|     .then(setup) |     .then(setup) | ||||||
|     .then(() => loadTestFrame()) |     .then(() => loadTestFrame()) | ||||||
|     .then(() => { |     .then(() => { | ||||||
|        ok(gCurGethashCounter > gPreGethashCounter, "Gethash request is triggered."); }) |        ok(gCurGethashCounter > gPreGethashCounter, "Gethash request is triggered."); | ||||||
|  | }) | ||||||
|     // Second load should not trigger gethash request because cache. |     // Second load should not trigger gethash request because cache. | ||||||
|     .then(() => loadTestFrame()) |     .then(() => loadTestFrame()) | ||||||
|     .then(() => { |     .then(() => { | ||||||
|        ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is nottriggered."); }) |        ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is nottriggered."); | ||||||
|  | }) | ||||||
|     .then(reset); |     .then(reset); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -25,7 +25,7 @@ function cleanup() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| SpecialPowers.pushPrefEnv( | SpecialPowers.pushPrefEnv( | ||||||
|   {"set" : [["urlclassifier.trackingTable", "test-track-simple"]]}, |   {"set": [["urlclassifier.trackingTable", "test-track-simple"]]}, | ||||||
|   test); |   test); | ||||||
| 
 | 
 | ||||||
| function test() { | function test() { | ||||||
|  |  | ||||||
|  | @ -125,7 +125,7 @@ SimpleTest.waitForExplicitFinish(); | ||||||
| 
 | 
 | ||||||
| function updateSuccess() { | function updateSuccess() { | ||||||
|   return SpecialPowers.pushPrefEnv( |   return SpecialPowers.pushPrefEnv( | ||||||
|     {"set" : [["browser.safebrowsing.malware.enabled", true]]}); |     {"set": [["browser.safebrowsing.malware.enabled", true]]}); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function updateError(errorCode) { | function updateError(errorCode) { | ||||||
|  | @ -171,12 +171,12 @@ function testService() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| SpecialPowers.pushPrefEnv( | SpecialPowers.pushPrefEnv( | ||||||
|   {"set" : [["urlclassifier.malwareTable", "test-malware-simple,test-unwanted-simple,test-harmful-simple"], |   {"set": [["urlclassifier.malwareTable", "test-malware-simple,test-unwanted-simple,test-harmful-simple"], | ||||||
|             ["urlclassifier.phishTable", "test-phish-simple"], |            ["urlclassifier.phishTable", "test-phish-simple"], | ||||||
|             ["urlclassifier.downloadBlockTable", "test-block-simple"], |            ["urlclassifier.downloadBlockTable", "test-block-simple"], | ||||||
|             ["urlclassifier.trackingTable", "test-track-simple"], |            ["urlclassifier.trackingTable", "test-track-simple"], | ||||||
|             ["browser.safebrowsing.debug", true], |            ["browser.safebrowsing.debug", true], | ||||||
|             ["privacy.trackingprotection.annotate_channels", true]]}, |            ["privacy.trackingprotection.annotate_channels", true]]}, | ||||||
|   function() { |   function() { | ||||||
|     classifierHelper.waitForInit() |     classifierHelper.waitForInit() | ||||||
|       .then(() => classifierHelper.addUrlToDB(testData)) |       .then(() => classifierHelper.addUrlToDB(testData)) | ||||||
|  |  | ||||||
|  | @ -78,7 +78,7 @@ function runTest() { | ||||||
|    * url specified in the table will be blocked after update. |    * url specified in the table will be blocked after update. | ||||||
|    */ |    */ | ||||||
|   var pushPrefPromise = SpecialPowers.pushPrefEnv( |   var pushPrefPromise = SpecialPowers.pushPrefEnv( | ||||||
|     {"set" : [["urlclassifier.trackingTable", testTable]]}); |     {"set": [["urlclassifier.trackingTable", testTable]]}); | ||||||
| 
 | 
 | ||||||
|   // To make sure url is not blocked by an already blocked url. |   // To make sure url is not blocked by an already blocked url. | ||||||
|   // Here we use non-tracking.example.com as a tracked url. |   // Here we use non-tracking.example.com as a tracked url. | ||||||
|  | @ -94,11 +94,11 @@ function runTest() { | ||||||
| 
 | 
 | ||||||
| // Set nextupdatetime to 1 to trigger an update | // Set nextupdatetime to 1 to trigger an update | ||||||
| SpecialPowers.pushPrefEnv( | SpecialPowers.pushPrefEnv( | ||||||
|   {"set" : [["privacy.trackingprotection.enabled", true], |   {"set": [["privacy.trackingprotection.enabled", true], | ||||||
|             ["channelclassifier.allowlist_example", true], |            ["channelclassifier.allowlist_example", true], | ||||||
|             ["browser.safebrowsing.provider.mozilla.nextupdatetime", "1"], |            ["browser.safebrowsing.provider.mozilla.nextupdatetime", "1"], | ||||||
|             ["browser.safebrowsing.provider.mozilla.lists", testTable], |            ["browser.safebrowsing.provider.mozilla.lists", testTable], | ||||||
|             ["browser.safebrowsing.provider.mozilla.updateURL", UPDATE_URL]]}, |            ["browser.safebrowsing.provider.mozilla.updateURL", UPDATE_URL]]}, | ||||||
|   runTest); |   runTest); | ||||||
| 
 | 
 | ||||||
| // Expected finish() call is in "bug_1281083.html". | // Expected finish() call is in "bug_1281083.html". | ||||||
|  |  | ||||||
|  | @ -72,7 +72,7 @@ var testDatas = [ | ||||||
|     expect: { error: Cr.NS_ERROR_BLOCKED_URI, |     expect: { error: Cr.NS_ERROR_BLOCKED_URI, | ||||||
|               table: "mochi-block-simple", |               table: "mochi-block-simple", | ||||||
|               provider: "", |               provider: "", | ||||||
|               prefix: (function(){ |               prefix: (function() { | ||||||
|                 return hashPrefix("malware.example.com/"); |                 return hashPrefix("malware.example.com/"); | ||||||
|               })(), |               })(), | ||||||
|             } |             } | ||||||
|  | @ -82,7 +82,7 @@ var testDatas = [ | ||||||
|     expect: { error: Cr.NS_ERROR_MALWARE_URI, |     expect: { error: Cr.NS_ERROR_MALWARE_URI, | ||||||
|               table: "mochi1-malware-simple", |               table: "mochi1-malware-simple", | ||||||
|               provider: "mozilla", |               provider: "mozilla", | ||||||
|               prefix: (function(){ |               prefix: (function() { | ||||||
|                 return hashPrefix("malware1.example.com/"); |                 return hashPrefix("malware1.example.com/"); | ||||||
|               })(), |               })(), | ||||||
|             } |             } | ||||||
|  | @ -92,7 +92,7 @@ var testDatas = [ | ||||||
|     expect: { error: Cr.NS_ERROR_MALWARE_URI, |     expect: { error: Cr.NS_ERROR_MALWARE_URI, | ||||||
|               table: "mochi2-malware-simple", |               table: "mochi2-malware-simple", | ||||||
|               provider: "mozilla", |               provider: "mozilla", | ||||||
|               prefix: (function(){ |               prefix: (function() { | ||||||
|                 return hashPrefix("malware2.example.com/"); |                 return hashPrefix("malware2.example.com/"); | ||||||
|               })(), |               })(), | ||||||
|             } |             } | ||||||
|  | @ -102,7 +102,7 @@ var testDatas = [ | ||||||
|     expect: { error: Cr.NS_ERROR_MALWARE_URI, |     expect: { error: Cr.NS_ERROR_MALWARE_URI, | ||||||
|               table: "mochig3-malware-simple", |               table: "mochig3-malware-simple", | ||||||
|               provider: "google", |               provider: "google", | ||||||
|               prefix: (function(){ |               prefix: (function() { | ||||||
|                 return hashPrefix("malware3.example.com/"); |                 return hashPrefix("malware3.example.com/"); | ||||||
|               })(), |               })(), | ||||||
|             } |             } | ||||||
|  | @ -171,7 +171,7 @@ function runTest() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| SpecialPowers.pushPrefEnv( | SpecialPowers.pushPrefEnv( | ||||||
|   {"set" : [["browser.safebrowsing.malware.enabled", true]]}, |   {"set": [["browser.safebrowsing.malware.enabled", true]]}, | ||||||
|   function() { |   function() { | ||||||
|     classifierHelper.waitForInit() |     classifierHelper.waitForInit() | ||||||
|       .then(() => setupTestData(inputDatas)) |       .then(() => setupTestData(inputDatas)) | ||||||
|  |  | ||||||
|  | @ -29,9 +29,8 @@ function loadTestFrame() { | ||||||
|     "http://example.com/tests/toolkit/components/url-classifier/tests/mochitest/workerFrame.html"; |     "http://example.com/tests/toolkit/components/url-classifier/tests/mochitest/workerFrame.html"; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function onmessage(event) | function onmessage(event) { | ||||||
| { |   var pieces = event.data.split(":"); | ||||||
|   var pieces = event.data.split(':'); |  | ||||||
|   if (pieces[0] == "finish") { |   if (pieces[0] == "finish") { | ||||||
|     SimpleTest.finish(); |     SimpleTest.finish(); | ||||||
|     return; |     return; | ||||||
|  | @ -42,7 +41,7 @@ function onmessage(event) | ||||||
| 
 | 
 | ||||||
| function updateSuccess() { | function updateSuccess() { | ||||||
|   SpecialPowers.pushPrefEnv( |   SpecialPowers.pushPrefEnv( | ||||||
|     {"set" : [["browser.safebrowsing.malware.enabled", true]]}, |     {"set": [["browser.safebrowsing.malware.enabled", true]]}, | ||||||
|     loadTestFrame); |     loadTestFrame); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -50,11 +49,11 @@ function updateError(errorCode) { | ||||||
|   ok(false, "Couldn't update classifier. Error code: " + errorCode); |   ok(false, "Couldn't update classifier. Error code: " + errorCode); | ||||||
|   // Abort test. |   // Abort test. | ||||||
|   SimpleTest.finish(); |   SimpleTest.finish(); | ||||||
| }; | } | ||||||
| 
 | 
 | ||||||
| SpecialPowers.pushPrefEnv( | SpecialPowers.pushPrefEnv( | ||||||
|   {"set" : [["urlclassifier.malwareTable", "test-malware-simple,test-unwanted-simple"], |   {"set": [["urlclassifier.malwareTable", "test-malware-simple,test-unwanted-simple"], | ||||||
|             ["urlclassifier.phishTable", "test-phish-simple"]]}, |            ["urlclassifier.phishTable", "test-phish-simple"]]}, | ||||||
|   function() { |   function() { | ||||||
|     classifierHelper.waitForInit() |     classifierHelper.waitForInit() | ||||||
|       .then(() => classifierHelper.addUrlToDB(testData)) |       .then(() => classifierHelper.addUrlToDB(testData)) | ||||||
|  |  | ||||||
|  | @ -74,8 +74,8 @@ | ||||||
| 
 | 
 | ||||||
|   function ping(id, host) { |   function ping(id, host) { | ||||||
|     var elm = document.createElement("a"); |     var elm = document.createElement("a"); | ||||||
|     elm.setAttribute('ping', host + path_ping + "?id=" + id); |     elm.setAttribute("ping", host + path_ping + "?id=" + id); | ||||||
|     elm.setAttribute('href', "#"); |     elm.setAttribute("href", "#"); | ||||||
|     document.body.appendChild(elm); |     document.body.appendChild(elm); | ||||||
| 
 | 
 | ||||||
|     // Trigger ping. |     // Trigger ping. | ||||||
|  | @ -87,7 +87,7 @@ | ||||||
|   function isPingedWithRetry(id, expected, msg, callback, retryCnt) { |   function isPingedWithRetry(id, expected, msg, callback, retryCnt) { | ||||||
|     var url = "http://mochi.test:8888/" + path_ping; |     var url = "http://mochi.test:8888/" + path_ping; | ||||||
|     var xhr = new XMLHttpRequest(); |     var xhr = new XMLHttpRequest(); | ||||||
|     xhr.open('GET', url + "?id=" + id); |     xhr.open("GET", url + "?id=" + id); | ||||||
|     xhr.onload = function() { |     xhr.onload = function() { | ||||||
|       var isPinged = xhr.response === "ping"; |       var isPinged = xhr.response === "ping"; | ||||||
|       let success = isPinged === expected; |       let success = isPinged === expected; | ||||||
|  |  | ||||||
|  | @ -28,47 +28,47 @@ const tests = [ | ||||||
|   // DNT turned on and TP turned off, DNT signal sent in both private browsing |   // DNT turned on and TP turned off, DNT signal sent in both private browsing | ||||||
|   // and normal mode. |   // and normal mode. | ||||||
|   { |   { | ||||||
|     setting:  {dntPref:true, tpPref:false, tppbPref:false, pbMode:true}, |     setting:  {dntPref: true, tpPref: false, tppbPref: false, pbMode: true}, | ||||||
|     expected: {dnt: "1"}, |     expected: {dnt: "1"}, | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|     setting:  {dntPref:true,  tpPref:false, tppbPref:false, pbMode:false}, |     setting:  {dntPref: true,  tpPref: false, tppbPref: false, pbMode: false}, | ||||||
|     expected: {dnt: "1"} |     expected: {dnt: "1"} | ||||||
|   }, |   }, | ||||||
|   // DNT turned off and TP turned on globally, DNT signal sent in both private |   // DNT turned off and TP turned on globally, DNT signal sent in both private | ||||||
|   // browsing and normal mode. |   // browsing and normal mode. | ||||||
|   { |   { | ||||||
|     setting:  {dntPref:false, tpPref:true,  tppbPref:false, pbMode:true}, |     setting:  {dntPref: false, tpPref: true,  tppbPref: false, pbMode: true}, | ||||||
|     expected: {dnt: "1"} |     expected: {dnt: "1"} | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|     setting:  {dntPref:false, tpPref:true,  tppbPref:false, pbMode:false}, |     setting:  {dntPref: false, tpPref: true,  tppbPref: false, pbMode: false}, | ||||||
|     expected: {dnt: "1"} |     expected: {dnt: "1"} | ||||||
|   }, |   }, | ||||||
|   // DNT turned off and TP in Private Browsing only, DNT signal sent in private |   // DNT turned off and TP in Private Browsing only, DNT signal sent in private | ||||||
|   // browsing mode only. |   // browsing mode only. | ||||||
|   { |   { | ||||||
|     setting:  {dntPref:false, tpPref:false, tppbPref:true,  pbMode:true}, |     setting:  {dntPref: false, tpPref: false, tppbPref: true,  pbMode: true}, | ||||||
|     expected: {dnt: "1"} |     expected: {dnt: "1"} | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|     setting:  {dntPref:false, tpPref:false, tppbPref:true,  pbMode:false}, |     setting:  {dntPref: false, tpPref: false, tppbPref: true,  pbMode: false}, | ||||||
|     expected: {dnt: "unspecified"} |     expected: {dnt: "unspecified"} | ||||||
|   }, |   }, | ||||||
|   // DNT turned off and TP turned off, DNT signal is never sent. |   // DNT turned off and TP turned off, DNT signal is never sent. | ||||||
|   { |   { | ||||||
|     setting:  {dntPref:false, tpPref:false, tppbPref:false, pbMode:true}, |     setting:  {dntPref: false, tpPref: false, tppbPref: false, pbMode: true}, | ||||||
|     expected: {dnt: "unspecified"} |     expected: {dnt: "unspecified"} | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|     setting:  {dntPref:false, tpPref:false, tppbPref:false, pbMode:false}, |     setting:  {dntPref: false, tpPref: false, tppbPref: false, pbMode: false}, | ||||||
|     expected: {dnt: "unspecified"} |     expected: {dnt: "unspecified"} | ||||||
|   }, |   }, | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
| const DNT_PREF = 'privacy.donottrackheader.enabled'; | const DNT_PREF = "privacy.donottrackheader.enabled"; | ||||||
| const TP_PREF = 'privacy.trackingprotection.enabled'; | const TP_PREF = "privacy.trackingprotection.enabled"; | ||||||
| const TP_PB_PREF = 'privacy.trackingprotection.pbmode.enabled'; | const TP_PB_PREF = "privacy.trackingprotection.pbmode.enabled"; | ||||||
| 
 | 
 | ||||||
| const contentPage = | const contentPage = | ||||||
|   "http://mochi.test:8888/tests/toolkit/components/url-classifier/tests/mochitest/dnt.html"; |   "http://mochi.test:8888/tests/toolkit/components/url-classifier/tests/mochitest/dnt.html"; | ||||||
|  | @ -85,7 +85,7 @@ function whenDelayedStartupFinished(aWindow, aCallback) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function executeTest(test) { | function executeTest(test) { | ||||||
|   SpecialPowers.pushPrefEnv({"set" : [ |   SpecialPowers.pushPrefEnv({"set": [ | ||||||
|    [DNT_PREF, test.setting.dntPref], |    [DNT_PREF, test.setting.dntPref], | ||||||
|    [TP_PREF, test.setting.tpPref], |    [TP_PREF, test.setting.tpPref], | ||||||
|    [TP_PB_PREF, test.setting.tppbPref] |    [TP_PB_PREF, test.setting.tppbPref] | ||||||
|  | @ -104,7 +104,7 @@ function executeTest(test) { | ||||||
| 
 | 
 | ||||||
|           win.removeEventListener("DOMContentLoaded", onInnerLoad, true); |           win.removeEventListener("DOMContentLoaded", onInnerLoad, true); | ||||||
| 
 | 
 | ||||||
|           win.content.addEventListener('message', function (event) { |           win.content.addEventListener("message", function(event) { | ||||||
|             let [key, value] = event.data.split("="); |             let [key, value] = event.data.split("="); | ||||||
|             if (key == "finish") { |             if (key == "finish") { | ||||||
|               win.close(); |               win.close(); | ||||||
|  |  | ||||||
|  | @ -47,7 +47,7 @@ function loadTestFrame(id) { | ||||||
| // add 4-bytes prefixes to local database, so when we access the url, | // add 4-bytes prefixes to local database, so when we access the url, | ||||||
| // it will trigger gethash request. | // it will trigger gethash request. | ||||||
| function addPrefixToDB(list, url) { | function addPrefixToDB(list, url) { | ||||||
|   var testData = [{ db: list, url: url, len: 4 }]; |   var testData = [{ db: list, url, len: 4 }]; | ||||||
| 
 | 
 | ||||||
|   return classifierHelper.addUrlToDB(testData) |   return classifierHelper.addUrlToDB(testData) | ||||||
|     .catch(function(err) { |     .catch(function(err) { | ||||||
|  |  | ||||||
|  | @ -50,8 +50,8 @@ function testOnWindow(aPrivate, aCallback) { | ||||||
|         } |         } | ||||||
|         win.removeEventListener("DOMContentLoaded", onInnerLoad, true); |         win.removeEventListener("DOMContentLoaded", onInnerLoad, true); | ||||||
| 
 | 
 | ||||||
|         win.content.addEventListener('load', function innerLoad2() { |         win.content.addEventListener("load", function innerLoad2() { | ||||||
|           win.content.removeEventListener('load', innerLoad2); |           win.content.removeEventListener("load", innerLoad2); | ||||||
|           SimpleTest.executeSoon(function() { aCallback(win); }); |           SimpleTest.executeSoon(function() { aCallback(win); }); | ||||||
|         }, false, true); |         }, false, true); | ||||||
|       }, true); |       }, true); | ||||||
|  | @ -112,7 +112,7 @@ function checkLoads(aWindow, aBlocked) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| SpecialPowers.pushPrefEnv( | SpecialPowers.pushPrefEnv( | ||||||
|   {"set" : [["urlclassifier.trackingTable", "test-track-simple"], |   {"set": [["urlclassifier.trackingTable", "test-track-simple"], | ||||||
|             ["privacy.trackingprotection.enabled", false], |             ["privacy.trackingprotection.enabled", false], | ||||||
|             ["privacy.trackingprotection.pbmode.enabled", true], |             ["privacy.trackingprotection.pbmode.enabled", true], | ||||||
|             ["channelclassifier.allowlist_example", true]]}, |             ["channelclassifier.allowlist_example", true]]}, | ||||||
|  |  | ||||||
|  | @ -75,7 +75,7 @@ function whenDelayedStartupFinished(aWindow, aCallback) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function testOnWindow(aTestData, aCallback, aTestCreater) { | function testOnWindow(aTestData, aCallback, aTestCreater) { | ||||||
|   return new Promise(resolve  => { |   return new Promise(resolve => { | ||||||
|     let win = mainWindow.OpenBrowserWindow(); |     let win = mainWindow.OpenBrowserWindow(); | ||||||
| 
 | 
 | ||||||
|     (async function() { |     (async function() { | ||||||
|  | @ -116,16 +116,16 @@ var createBlockedIframe = function(aWindow, aBrowser, aTopUrl, aUrl) { | ||||||
|     await ContentTask.spawn(aBrowser, aUrl, async function(aUrl) { |     await ContentTask.spawn(aBrowser, aUrl, async function(aUrl) { | ||||||
|       return new Promise(resolve => { |       return new Promise(resolve => { | ||||||
|         let listener = e => { |         let listener = e => { | ||||||
|           removeEventListener('AboutBlockedLoaded', listener, false, true); |           removeEventListener("AboutBlockedLoaded", listener, false, true); | ||||||
|           resolve(); |           resolve(); | ||||||
|         }; |         }; | ||||||
|         addEventListener('AboutBlockedLoaded', listener, false, true); |         addEventListener("AboutBlockedLoaded", listener, false, true); | ||||||
|         let frame = content.document.getElementById("phishingFrame"); |         let frame = content.document.getElementById("phishingFrame"); | ||||||
|         frame.setAttribute('src', "http://" + aUrl); |         frame.setAttribute("src", "http://" + aUrl); | ||||||
|       }); |       }); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     let doc = aWindow.gBrowser.contentDocument.getElementsByTagName('iframe')[0].contentDocument; |     let doc = aWindow.gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument; | ||||||
|     let ignoreButton = doc.getElementById("ignoreWarningButton"); |     let ignoreButton = doc.getElementById("ignoreWarningButton"); | ||||||
|     ok(ignoreButton, "ignoreWarningButton should exist"); |     ok(ignoreButton, "ignoreWarningButton should exist"); | ||||||
|     ignoreButton.click(); |     ignoreButton.click(); | ||||||
|  | @ -154,7 +154,7 @@ var testDatas = [ | ||||||
|     testUrl: "itisaphishingsite.org/phishing.html", |     testUrl: "itisaphishingsite.org/phishing.html", | ||||||
|     list: "mochi1-phish-simple", |     list: "mochi1-phish-simple", | ||||||
|     provider: "google", |     provider: "google", | ||||||
|     blockCreater : createBlockedPage, |     blockCreater: createBlockedPage, | ||||||
|     expectedReportUri: "http://itisaphishingsite.org/phishing.html" |     expectedReportUri: "http://itisaphishingsite.org/phishing.html" | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|  | @ -165,7 +165,7 @@ var testDatas = [ | ||||||
|     testUrl: "fakeitisaphishingsite.org/phishing.html", |     testUrl: "fakeitisaphishingsite.org/phishing.html", | ||||||
|     list: "fake-phish-simple", |     list: "fake-phish-simple", | ||||||
|     provider: "mozilla", |     provider: "mozilla", | ||||||
|     blockCreater : createBlockedPage |     blockCreater: createBlockedPage | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   // Iframe case: |   // Iframe case: | ||||||
|  | @ -177,7 +177,7 @@ var testDatas = [ | ||||||
|     testUrl: "phishing.example.com/test.html", |     testUrl: "phishing.example.com/test.html", | ||||||
|     list: "mochi2-phish-simple", |     list: "mochi2-phish-simple", | ||||||
|     provider: "google4", |     provider: "google4", | ||||||
|     blockCreater : createBlockedIframe, |     blockCreater: createBlockedIframe, | ||||||
|     expectedReportUri: "http://phishing.example.com/test.html" |     expectedReportUri: "http://phishing.example.com/test.html" | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|  | @ -190,16 +190,16 @@ var testDatas = [ | ||||||
|     testUrl: "prefixexample.com/chrome/toolkit/components/url-classifier/tests/mochitest/report.sjs?action=create-blocked-redirect", |     testUrl: "prefixexample.com/chrome/toolkit/components/url-classifier/tests/mochitest/report.sjs?action=create-blocked-redirect", | ||||||
|     list: "mochi3-phish-simple", |     list: "mochi3-phish-simple", | ||||||
|     provider: "google4", |     provider: "google4", | ||||||
|     blockCreater : createBlockedPage, |     blockCreater: createBlockedPage, | ||||||
|     expectedReportUri: "http://prefixexample.com/chrome/toolkit/components/url-classifier/tests/mochitest/report.sjs" |     expectedReportUri: "http://prefixexample.com/chrome/toolkit/components/url-classifier/tests/mochitest/report.sjs" | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
| ]; | ]; | ||||||
| 
 | 
 | ||||||
| SpecialPowers.pushPrefEnv( | SpecialPowers.pushPrefEnv( | ||||||
|   {"set" : [["browser.safebrowsing.provider.google.reportPhishMistakeURL", BASE_URL + "action=reporturl&reporturl="], |   {"set": [["browser.safebrowsing.provider.google.reportPhishMistakeURL", BASE_URL + "action=reporturl&reporturl="], | ||||||
|             ["browser.safebrowsing.provider.google4.reportPhishMistakeURL", BASE_URL + "action=reporturl&reporturl="], |            ["browser.safebrowsing.provider.google4.reportPhishMistakeURL", BASE_URL + "action=reporturl&reporturl="], | ||||||
|             ["browser.safebrowsing.phishing.enabled", true]]}, |            ["browser.safebrowsing.phishing.enabled", true]]}, | ||||||
|   test); |   test); | ||||||
| 
 | 
 | ||||||
| function test() { | function test() { | ||||||
|  |  | ||||||
|  | @ -50,8 +50,8 @@ function testOnWindow(aCallback) { | ||||||
|         } |         } | ||||||
|         win.removeEventListener("DOMContentLoaded", onInnerLoad, true); |         win.removeEventListener("DOMContentLoaded", onInnerLoad, true); | ||||||
| 
 | 
 | ||||||
|         win.content.addEventListener('load', function innerLoad2() { |         win.content.addEventListener("load", function innerLoad2() { | ||||||
|           win.content.removeEventListener('load', innerLoad2); |           win.content.removeEventListener("load", innerLoad2); | ||||||
|           SimpleTest.executeSoon(function() { aCallback(win); }); |           SimpleTest.executeSoon(function() { aCallback(win); }); | ||||||
|         }, false, true); |         }, false, true); | ||||||
|       }, true); |       }, true); | ||||||
|  | @ -70,11 +70,11 @@ function checkLoads(aWindow, aBlocked) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| SpecialPowers.pushPrefEnv( | SpecialPowers.pushPrefEnv( | ||||||
|   {"set" : [["urlclassifier.trackingTable", "test-track-simple"], |   {"set": [["urlclassifier.trackingTable", "test-track-simple"], | ||||||
|             ["privacy.trackingprotection.enabled", true], |            ["privacy.trackingprotection.enabled", true], | ||||||
|             ["browser.safebrowsing.malware.enabled", false], |            ["browser.safebrowsing.malware.enabled", false], | ||||||
|             ["browser.safebrowsing.phishing.enabled", false], |            ["browser.safebrowsing.phishing.enabled", false], | ||||||
|             ["channelclassifier.allowlist_example", true]]}, |            ["channelclassifier.allowlist_example", true]]}, | ||||||
|   test); |   test); | ||||||
| 
 | 
 | ||||||
| function test() { | function test() { | ||||||
|  |  | ||||||
|  | @ -50,8 +50,8 @@ function testOnWindow(aPrivate, aCallback) { | ||||||
|         } |         } | ||||||
|         win.removeEventListener("DOMContentLoaded", onInnerLoad, true); |         win.removeEventListener("DOMContentLoaded", onInnerLoad, true); | ||||||
| 
 | 
 | ||||||
|         win.content.addEventListener('load', function innerLoad2() { |         win.content.addEventListener("load", function innerLoad2() { | ||||||
|           win.content.removeEventListener('load', innerLoad2); |           win.content.removeEventListener("load", innerLoad2); | ||||||
|           SimpleTest.executeSoon(function() { aCallback(win); }); |           SimpleTest.executeSoon(function() { aCallback(win); }); | ||||||
|         }, false, true); |         }, false, true); | ||||||
|       }, true); |       }, true); | ||||||
|  | @ -103,10 +103,10 @@ function endTest() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| SpecialPowers.pushPrefEnv( | SpecialPowers.pushPrefEnv( | ||||||
|   {"set" : [["urlclassifier.trackingTable", "test-track-simple"], |   {"set": [["urlclassifier.trackingTable", "test-track-simple"], | ||||||
|             ["privacy.trackingprotection.annotate_channels", true], |            ["privacy.trackingprotection.annotate_channels", true], | ||||||
|             ["privacy.trackingprotection.lower_network_priority", true], |            ["privacy.trackingprotection.lower_network_priority", true], | ||||||
|             ["channelclassifier.allowlist_example", true]]}, |            ["channelclassifier.allowlist_example", true]]}, | ||||||
|   test); |   test); | ||||||
| 
 | 
 | ||||||
| function test() { | function test() { | ||||||
|  |  | ||||||
|  | @ -51,8 +51,8 @@ function testOnWindow(contentPage, aCallback) { | ||||||
|         } |         } | ||||||
|         win.removeEventListener("DOMContentLoaded", onInnerLoad, true); |         win.removeEventListener("DOMContentLoaded", onInnerLoad, true); | ||||||
| 
 | 
 | ||||||
|         win.content.addEventListener('load', function innerLoad2() { |         win.content.addEventListener("load", function innerLoad2() { | ||||||
|           win.content.removeEventListener('load', innerLoad2); |           win.content.removeEventListener("load", innerLoad2); | ||||||
|           SimpleTest.executeSoon(function() { aCallback(win); }); |           SimpleTest.executeSoon(function() { aCallback(win); }); | ||||||
|         }, false, true); |         }, false, true); | ||||||
|       }, true); |       }, true); | ||||||
|  | @ -110,8 +110,8 @@ function checkLoads(aWindow, aWhitelisted) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| SpecialPowers.pushPrefEnv( | SpecialPowers.pushPrefEnv( | ||||||
|   {"set" : [["privacy.trackingprotection.enabled", true], |   {"set": [["privacy.trackingprotection.enabled", true], | ||||||
|             ["channelclassifier.allowlist_example", true]]}, |            ["channelclassifier.allowlist_example", true]]}, | ||||||
|   test); |   test); | ||||||
| 
 | 
 | ||||||
| function test() { | function test() { | ||||||
|  | @ -128,7 +128,7 @@ function test() { | ||||||
|         aWindow.close(); |         aWindow.close(); | ||||||
| 
 | 
 | ||||||
|         // Load the test from a URL on the whitelist but without the whitelist |         // Load the test from a URL on the whitelist but without the whitelist | ||||||
|         SpecialPowers.pushPrefEnv({"set" : [["urlclassifier.trackingWhitelistTable", ""]]}, |         SpecialPowers.pushPrefEnv({"set": [["urlclassifier.trackingWhitelistTable", ""]]}, | ||||||
|           function() { |           function() { | ||||||
|             testOnWindow(contentPage1, function(aWindow) { |             testOnWindow(contentPage1, function(aWindow) { | ||||||
|               checkLoads(aWindow, false); |               checkLoads(aWindow, false); | ||||||
|  |  | ||||||
|  | @ -1,3 +1,3 @@ | ||||||
| function getTrackerTimeout() { | function getTrackerTimeout() { | ||||||
|   return window.setTimeout(function(){}, 0); |   return window.setTimeout(function() {}, 0); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -4,8 +4,7 @@ window.addEventListener("message", function onMessage(evt) { | ||||||
|     var request = new XMLHttpRequest(); |     var request = new XMLHttpRequest(); | ||||||
|     request.open("GET", evt.data.url, true); |     request.open("GET", evt.data.url, true); | ||||||
|     request.send(null); |     request.send(null); | ||||||
|   } |   } else if (evt.data.type === "doFetch") { | ||||||
|   else if (evt.data.type === "doFetch") { |  | ||||||
|     fetch(evt.data.url); |     fetch(evt.data.url); | ||||||
|   } |   } | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | @ -41,11 +41,11 @@ prefBranch.setIntPref("urlclassifier.gethash.timeout_ms", 5000); | ||||||
| function delFile(name) { | function delFile(name) { | ||||||
|   try { |   try { | ||||||
|     // Delete a previously created sqlite file
 |     // Delete a previously created sqlite file
 | ||||||
|     var file = dirSvc.get('ProfLD', Ci.nsIFile); |     var file = dirSvc.get("ProfLD", Ci.nsIFile); | ||||||
|     file.append(name); |     file.append(name); | ||||||
|     if (file.exists()) |     if (file.exists()) | ||||||
|       file.remove(false); |       file.remove(false); | ||||||
|   } catch(e) { |   } catch (e) { | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -103,9 +103,9 @@ function buildUpdate(update, hashSize) { | ||||||
|     var chunks = update[tableName]; |     var chunks = update[tableName]; | ||||||
|     for (var j = 0; j < chunks.length; j++) { |     for (var j = 0; j < chunks.length; j++) { | ||||||
|       var chunk = chunks[j]; |       var chunk = chunks[j]; | ||||||
|       var chunkType = chunk.chunkType ? chunk.chunkType : 'a'; |       var chunkType = chunk.chunkType ? chunk.chunkType : "a"; | ||||||
|       var chunkNum = chunk.chunkNum ? chunk.chunkNum : j; |       var chunkNum = chunk.chunkNum ? chunk.chunkNum : j; | ||||||
|       updateStr += chunkType + ':' + chunkNum + ':' + hashSize; |       updateStr += chunkType + ":" + chunkNum + ":" + hashSize; | ||||||
| 
 | 
 | ||||||
|       if (chunk.urls) { |       if (chunk.urls) { | ||||||
|         var chunkData = chunk.urls.join("\n"); |         var chunkData = chunk.urls.join("\n"); | ||||||
|  | @ -120,27 +120,27 @@ function buildUpdate(update, hashSize) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function buildPhishingUpdate(chunks, hashSize) { | function buildPhishingUpdate(chunks, hashSize) { | ||||||
|   return buildUpdate({"test-phish-simple" : chunks}, hashSize); |   return buildUpdate({"test-phish-simple": chunks}, hashSize); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function buildMalwareUpdate(chunks, hashSize) { | function buildMalwareUpdate(chunks, hashSize) { | ||||||
|   return buildUpdate({"test-malware-simple" : chunks}, hashSize); |   return buildUpdate({"test-malware-simple": chunks}, hashSize); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function buildUnwantedUpdate(chunks, hashSize) { | function buildUnwantedUpdate(chunks, hashSize) { | ||||||
|   return buildUpdate({"test-unwanted-simple" : chunks}, hashSize); |   return buildUpdate({"test-unwanted-simple": chunks}, hashSize); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function buildBlockedUpdate(chunks, hashSize) { | function buildBlockedUpdate(chunks, hashSize) { | ||||||
|   return buildUpdate({"test-block-simple" : chunks}, hashSize); |   return buildUpdate({"test-block-simple": chunks}, hashSize); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function buildMozPhishingUpdate(chunks, hashSize) { | function buildMozPhishingUpdate(chunks, hashSize) { | ||||||
|   return buildUpdate({"moz-phish-simple" : chunks}, hashSize); |   return buildUpdate({"moz-phish-simple": chunks}, hashSize); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function buildBareUpdate(chunks, hashSize) { | function buildBareUpdate(chunks, hashSize) { | ||||||
|   return buildUpdate({"" : chunks}, hashSize); |   return buildUpdate({"": chunks}, hashSize); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  | @ -148,18 +148,17 @@ function buildBareUpdate(chunks, hashSize) { | ||||||
|  */ |  */ | ||||||
| function doSimpleUpdate(updateText, success, failure) { | function doSimpleUpdate(updateText, success, failure) { | ||||||
|   var listener = { |   var listener = { | ||||||
|     QueryInterface: function(iid) |     QueryInterface(iid) { | ||||||
|     { |  | ||||||
|       if (iid.equals(Ci.nsISupports) || |       if (iid.equals(Ci.nsISupports) || | ||||||
|           iid.equals(Ci.nsIUrlClassifierUpdateObserver)) |           iid.equals(Ci.nsIUrlClassifierUpdateObserver)) | ||||||
|         return this; |         return this; | ||||||
|       throw Cr.NS_ERROR_NO_INTERFACE; |       throw Cr.NS_ERROR_NO_INTERFACE; | ||||||
|     }, |     }, | ||||||
| 
 | 
 | ||||||
|     updateUrlRequested: function(url) { }, |     updateUrlRequested(url) { }, | ||||||
|     streamFinished: function(status) { }, |     streamFinished(status) { }, | ||||||
|     updateError: function(errorCode) { failure(errorCode); }, |     updateError(errorCode) { failure(errorCode); }, | ||||||
|     updateSuccess: function(requestedTimeout) { success(requestedTimeout); } |     updateSuccess(requestedTimeout) { success(requestedTimeout); } | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   dbservice.beginUpdate(listener, allTables); |   dbservice.beginUpdate(listener, allTables); | ||||||
|  | @ -174,18 +173,17 @@ function doSimpleUpdate(updateText, success, failure) { | ||||||
|  */ |  */ | ||||||
| function doErrorUpdate(tables, success, failure) { | function doErrorUpdate(tables, success, failure) { | ||||||
|   var listener = { |   var listener = { | ||||||
|     QueryInterface: function(iid) |     QueryInterface(iid) { | ||||||
|     { |  | ||||||
|       if (iid.equals(Ci.nsISupports) || |       if (iid.equals(Ci.nsISupports) || | ||||||
|           iid.equals(Ci.nsIUrlClassifierUpdateObserver)) |           iid.equals(Ci.nsIUrlClassifierUpdateObserver)) | ||||||
|         return this; |         return this; | ||||||
|       throw Cr.NS_ERROR_NO_INTERFACE; |       throw Cr.NS_ERROR_NO_INTERFACE; | ||||||
|     }, |     }, | ||||||
| 
 | 
 | ||||||
|     updateUrlRequested: function(url) { }, |     updateUrlRequested(url) { }, | ||||||
|     streamFinished: function(status) { }, |     streamFinished(status) { }, | ||||||
|     updateError: function(errorCode) { success(errorCode); }, |     updateError(errorCode) { success(errorCode); }, | ||||||
|     updateSuccess: function(requestedTimeout) { failure(requestedTimeout); } |     updateSuccess(requestedTimeout) { failure(requestedTimeout); } | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   dbservice.beginUpdate(listener, tables, null); |   dbservice.beginUpdate(listener, tables, null); | ||||||
|  | @ -210,12 +208,11 @@ function doStreamUpdate(updateText, success, failure, downloadFailure) { | ||||||
| 
 | 
 | ||||||
| var gAssertions = { | var gAssertions = { | ||||||
| 
 | 
 | ||||||
| tableData : function(expectedTables, cb) | tableData(expectedTables, cb) { | ||||||
| { |  | ||||||
|   dbservice.getTables(function(tables) { |   dbservice.getTables(function(tables) { | ||||||
|       // rebuild the tables in a predictable order.
 |       // rebuild the tables in a predictable order.
 | ||||||
|       var parts = tables.split("\n"); |       var parts = tables.split("\n"); | ||||||
|       while (parts[parts.length - 1] == '') { |       while (parts[parts.length - 1] == "") { | ||||||
|         parts.pop(); |         parts.pop(); | ||||||
|       } |       } | ||||||
|       parts.sort(); |       parts.sort(); | ||||||
|  | @ -226,8 +223,7 @@ tableData : function(expectedTables, cb) | ||||||
|     }); |     }); | ||||||
| }, | }, | ||||||
| 
 | 
 | ||||||
| checkUrls: function(urls, expected, cb, useMoz = false) | checkUrls(urls, expected, cb, useMoz = false) { | ||||||
| { |  | ||||||
|   // work with a copy of the list.
 |   // work with a copy of the list.
 | ||||||
|   urls = urls.slice(0); |   urls = urls.slice(0); | ||||||
|   var doLookup = function() { |   var doLookup = function() { | ||||||
|  | @ -247,13 +243,12 @@ checkUrls: function(urls, expected, cb, useMoz = false) | ||||||
|   doLookup(); |   doLookup(); | ||||||
| }, | }, | ||||||
| 
 | 
 | ||||||
| checkTables: function(url, expected, cb) | checkTables(url, expected, cb) { | ||||||
| { |  | ||||||
|   var principal = secMan.createCodebasePrincipal(iosvc.newURI("http://" + url), {}); |   var principal = secMan.createCodebasePrincipal(iosvc.newURI("http://" + url), {}); | ||||||
|   dbservice.lookup(principal, allTables, function(tables) { |   dbservice.lookup(principal, allTables, function(tables) { | ||||||
|     // Rebuild tables in a predictable order.
 |     // Rebuild tables in a predictable order.
 | ||||||
|     var parts = tables.split(","); |     var parts = tables.split(","); | ||||||
|     while (parts[parts.length - 1] == '') { |     while (parts[parts.length - 1] == "") { | ||||||
|       parts.pop(); |       parts.pop(); | ||||||
|     } |     } | ||||||
|     parts.sort(); |     parts.sort(); | ||||||
|  | @ -263,51 +258,42 @@ checkTables: function(url, expected, cb) | ||||||
|   }, true); |   }, true); | ||||||
| }, | }, | ||||||
| 
 | 
 | ||||||
| urlsDontExist: function(urls, cb) | urlsDontExist(urls, cb) { | ||||||
| { |   this.checkUrls(urls, "", cb); | ||||||
|   this.checkUrls(urls, '', cb); |  | ||||||
| }, | }, | ||||||
| 
 | 
 | ||||||
| urlsExist: function(urls, cb) | urlsExist(urls, cb) { | ||||||
| { |   this.checkUrls(urls, "test-phish-simple", cb); | ||||||
|   this.checkUrls(urls, 'test-phish-simple', cb); |  | ||||||
| }, | }, | ||||||
| 
 | 
 | ||||||
| malwareUrlsExist: function(urls, cb) | malwareUrlsExist(urls, cb) { | ||||||
| { |   this.checkUrls(urls, "test-malware-simple", cb); | ||||||
|   this.checkUrls(urls, 'test-malware-simple', cb); |  | ||||||
| }, | }, | ||||||
| 
 | 
 | ||||||
| unwantedUrlsExist: function(urls, cb) | unwantedUrlsExist(urls, cb) { | ||||||
| { |   this.checkUrls(urls, "test-unwanted-simple", cb); | ||||||
|   this.checkUrls(urls, 'test-unwanted-simple', cb); |  | ||||||
| }, | }, | ||||||
| 
 | 
 | ||||||
| blockedUrlsExist: function(urls, cb) | blockedUrlsExist(urls, cb) { | ||||||
| { |   this.checkUrls(urls, "test-block-simple", cb); | ||||||
|   this.checkUrls(urls, 'test-block-simple', cb); |  | ||||||
| }, | }, | ||||||
| 
 | 
 | ||||||
| mozPhishingUrlsExist: function(urls, cb) | mozPhishingUrlsExist(urls, cb) { | ||||||
| { |   this.checkUrls(urls, "moz-phish-simple", cb, true); | ||||||
|   this.checkUrls(urls, 'moz-phish-simple', cb, true); |  | ||||||
| }, | }, | ||||||
| 
 | 
 | ||||||
| subsDontExist: function(urls, cb) | subsDontExist(urls, cb) { | ||||||
| { |  | ||||||
|   // XXX: there's no interface for checking items in the subs table
 |   // XXX: there's no interface for checking items in the subs table
 | ||||||
|   cb(); |   cb(); | ||||||
| }, | }, | ||||||
| 
 | 
 | ||||||
| subsExist: function(urls, cb) | subsExist(urls, cb) { | ||||||
| { |  | ||||||
|   // XXX: there's no interface for checking items in the subs table
 |   // XXX: there's no interface for checking items in the subs table
 | ||||||
|   cb(); |   cb(); | ||||||
| }, | }, | ||||||
| 
 | 
 | ||||||
| urlExistInMultipleTables: function(data, cb) | urlExistInMultipleTables(data, cb) { | ||||||
| { |   this.checkTables(data.url, data.tables, cb); | ||||||
|   this.checkTables(data["url"], data["tables"], cb); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| }; | }; | ||||||
|  | @ -315,8 +301,7 @@ urlExistInMultipleTables: function(data, cb) | ||||||
| /** | /** | ||||||
|  * Check a set of assertions against the gAssertions table. |  * Check a set of assertions against the gAssertions table. | ||||||
|  */ |  */ | ||||||
| function checkAssertions(assertions, doneCallback) | function checkAssertions(assertions, doneCallback) { | ||||||
| { |  | ||||||
|   var checkAssertion = function() { |   var checkAssertion = function() { | ||||||
|     for (var i in assertions) { |     for (var i in assertions) { | ||||||
|       var data = assertions[i]; |       var data = assertions[i]; | ||||||
|  | @ -331,8 +316,7 @@ function checkAssertions(assertions, doneCallback) | ||||||
|   checkAssertion(); |   checkAssertion(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function updateError(arg) | function updateError(arg) { | ||||||
| { |  | ||||||
|   do_throw(arg); |   do_throw(arg); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -357,23 +341,21 @@ function doUpdateTest(updates, assertions, successCallback, errorCallback) { | ||||||
| var gTests; | var gTests; | ||||||
| var gNextTest = 0; | var gNextTest = 0; | ||||||
| 
 | 
 | ||||||
| function runNextTest() | function runNextTest() { | ||||||
| { |  | ||||||
|   if (gNextTest >= gTests.length) { |   if (gNextTest >= gTests.length) { | ||||||
|     do_test_finished(); |     do_test_finished(); | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   dbservice.resetDatabase(); |   dbservice.resetDatabase(); | ||||||
|   dbservice.setHashCompleter('test-phish-simple', null); |   dbservice.setHashCompleter("test-phish-simple", null); | ||||||
| 
 | 
 | ||||||
|   let test = gTests[gNextTest++]; |   let test = gTests[gNextTest++]; | ||||||
|   dump("running " + test.name + "\n"); |   dump("running " + test.name + "\n"); | ||||||
|   test(); |   test(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function runTests(tests) | function runTests(tests) { | ||||||
| { |  | ||||||
|   gTests = tests; |   gTests = tests; | ||||||
|   runNextTest(); |   runNextTest(); | ||||||
| } | } | ||||||
|  | @ -388,13 +370,13 @@ function Timer(delay, cb) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Timer.prototype = { | Timer.prototype = { | ||||||
| QueryInterface: function(iid) { | QueryInterface(iid) { | ||||||
|     if (!iid.equals(Ci.nsISupports) && !iid.equals(Ci.nsITimerCallback)) { |     if (!iid.equals(Ci.nsISupports) && !iid.equals(Ci.nsITimerCallback)) { | ||||||
|       throw Cr.NS_ERROR_NO_INTERFACE; |       throw Cr.NS_ERROR_NO_INTERFACE; | ||||||
|     } |     } | ||||||
|     return this; |     return this; | ||||||
|   }, |   }, | ||||||
| notify: function(timer) { | notify(timer) { | ||||||
|     this.cb(); |     this.cb(); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | @ -414,7 +396,7 @@ function LFSRgenerator(seed) { | ||||||
| } | } | ||||||
| LFSRgenerator.prototype = { | LFSRgenerator.prototype = { | ||||||
|   // nextNum returns a random unsigned integer of in the range [0,2^|bits|].
 |   // nextNum returns a random unsigned integer of in the range [0,2^|bits|].
 | ||||||
|   nextNum: function(bits) { |   nextNum(bits) { | ||||||
|     if (!bits) |     if (!bits) | ||||||
|       bits = 32; |       bits = 32; | ||||||
| 
 | 
 | ||||||
|  | @ -446,13 +428,13 @@ function waitUntilMetaDataSaved(expectedState, expectedChecksum, callback) { | ||||||
|       let stateBase64 = metadata[0]; |       let stateBase64 = metadata[0]; | ||||||
|       let checksumBase64 = metadata[1]; |       let checksumBase64 = metadata[1]; | ||||||
| 
 | 
 | ||||||
|       if (tableName !== 'test-phish-proto') { |       if (tableName !== "test-phish-proto") { | ||||||
|         return false; // continue.
 |         return false; // continue.
 | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       if (stateBase64 === btoa(expectedState) && |       if (stateBase64 === btoa(expectedState) && | ||||||
|           checksumBase64 === btoa(expectedChecksum)) { |           checksumBase64 === btoa(expectedChecksum)) { | ||||||
|         do_print('State has been saved to disk!'); |         do_print("State has been saved to disk!"); | ||||||
| 
 | 
 | ||||||
|         // We slightly defer the callback to see if the in-memory
 |         // We slightly defer the callback to see if the in-memory
 | ||||||
|         // |getTables| caching works correctly.
 |         // |getTables| caching works correctly.
 | ||||||
|  |  | ||||||
|  | @ -1,6 +1,5 @@ | ||||||
| 
 | 
 | ||||||
| function doTest(updates, assertions) | function doTest(updates, assertions) { | ||||||
| { |  | ||||||
|   doUpdateTest(updates, assertions, runNextTest, updateError); |   doUpdateTest(updates, assertions, runNextTest, updateError); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -9,13 +8,13 @@ function testSimpleAdds() { | ||||||
|   var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; |   var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; | ||||||
|   var update = buildPhishingUpdate( |   var update = buildPhishingUpdate( | ||||||
|         [ |         [ | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "urls" : addUrls |             "urls": addUrls | ||||||
|           }]); |           }]); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1", |     "tableData": "test-phish-simple;a:1", | ||||||
|     "urlsExist" : addUrls |     "urlsExist": addUrls | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([update], assertions); |   doTest([update], assertions); | ||||||
|  | @ -28,39 +27,38 @@ function testMultipleAdds() { | ||||||
|   var add2Urls = [ "foo.com/b" ]; |   var add2Urls = [ "foo.com/b" ]; | ||||||
| 
 | 
 | ||||||
|   var update = buildPhishingUpdate( |   var update = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 1, |     [{ "chunkNum": 1, | ||||||
|        "urls" : add1Urls }, |        "urls": add1Urls }, | ||||||
|       { "chunkNum" : 2, |       { "chunkNum": 2, | ||||||
|         "urls" : add2Urls }]); |         "urls": add2Urls }]); | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1-2", |     "tableData": "test-phish-simple;a:1-2", | ||||||
|     "urlsExist" : add1Urls.concat(add2Urls) |     "urlsExist": add1Urls.concat(add2Urls) | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([update], assertions); |   doTest([update], assertions); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Test that a sub will remove an existing add
 | // Test that a sub will remove an existing add
 | ||||||
| function testSimpleSub() | function testSimpleSub() { | ||||||
| { |  | ||||||
|   var addUrls = ["foo.com/a", "bar.com/b"]; |   var addUrls = ["foo.com/a", "bar.com/b"]; | ||||||
|   var subUrls = ["1:foo.com/a"]; |   var subUrls = ["1:foo.com/a"]; | ||||||
| 
 | 
 | ||||||
|   var addUpdate = buildPhishingUpdate( |   var addUpdate = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 1, // adds and subtracts don't share a chunk numbering space
 |     [{ "chunkNum": 1, // adds and subtracts don't share a chunk numbering space
 | ||||||
|        "urls": addUrls }]); |        "urls": addUrls }]); | ||||||
| 
 | 
 | ||||||
|   var subUpdate = buildPhishingUpdate( |   var subUpdate = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 50, |     [{ "chunkNum": 50, | ||||||
|        "chunkType" : "s", |        "chunkType": "s", | ||||||
|        "urls": subUrls }]); |        "urls": subUrls }]); | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1:s:50", |     "tableData": "test-phish-simple;a:1:s:50", | ||||||
|     "urlsExist" : [ "bar.com/b" ], |     "urlsExist": [ "bar.com/b" ], | ||||||
|     "urlsDontExist": ["foo.com/a" ], |     "urlsDontExist": ["foo.com/a" ], | ||||||
|     "subsDontExist" : [ "foo.com/a" ] |     "subsDontExist": [ "foo.com/a" ] | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   doTest([addUpdate, subUpdate], assertions); |   doTest([addUpdate, subUpdate], assertions); | ||||||
|  | @ -68,25 +66,24 @@ function testSimpleSub() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Same as testSimpleSub(), but the sub comes in before the add.
 | // Same as testSimpleSub(), but the sub comes in before the add.
 | ||||||
| function testSubEmptiesAdd() | function testSubEmptiesAdd() { | ||||||
| { |  | ||||||
|   var subUrls = ["1:foo.com/a"]; |   var subUrls = ["1:foo.com/a"]; | ||||||
|   var addUrls = ["foo.com/a", "bar.com/b"]; |   var addUrls = ["foo.com/a", "bar.com/b"]; | ||||||
| 
 | 
 | ||||||
|   var subUpdate = buildPhishingUpdate( |   var subUpdate = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 50, |     [{ "chunkNum": 50, | ||||||
|        "chunkType" : "s", |        "chunkType": "s", | ||||||
|        "urls": subUrls }]); |        "urls": subUrls }]); | ||||||
| 
 | 
 | ||||||
|   var addUpdate = buildPhishingUpdate( |   var addUpdate = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 1, |     [{ "chunkNum": 1, | ||||||
|        "urls": addUrls }]); |        "urls": addUrls }]); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1:s:50", |     "tableData": "test-phish-simple;a:1:s:50", | ||||||
|     "urlsExist" : [ "bar.com/b" ], |     "urlsExist": [ "bar.com/b" ], | ||||||
|     "urlsDontExist": ["foo.com/a" ], |     "urlsDontExist": ["foo.com/a" ], | ||||||
|     "subsDontExist" : [ "foo.com/a" ] // this sub was found, it shouldn't exist anymore
 |     "subsDontExist": [ "foo.com/a" ] // this sub was found, it shouldn't exist anymore
 | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   doTest([subUpdate, addUpdate], assertions); |   doTest([subUpdate, addUpdate], assertions); | ||||||
|  | @ -94,25 +91,24 @@ function testSubEmptiesAdd() | ||||||
| 
 | 
 | ||||||
| // Very similar to testSubEmptiesAdd, except that the domain entry will
 | // Very similar to testSubEmptiesAdd, except that the domain entry will
 | ||||||
| // still have an item left over that needs to be synced.
 | // still have an item left over that needs to be synced.
 | ||||||
| function testSubPartiallyEmptiesAdd() | function testSubPartiallyEmptiesAdd() { | ||||||
| { |  | ||||||
|   var subUrls = ["1:foo.com/a"]; |   var subUrls = ["1:foo.com/a"]; | ||||||
|   var addUrls = ["foo.com/a", "foo.com/b", "bar.com/b"]; |   var addUrls = ["foo.com/a", "foo.com/b", "bar.com/b"]; | ||||||
| 
 | 
 | ||||||
|   var subUpdate = buildPhishingUpdate( |   var subUpdate = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 1, |     [{ "chunkNum": 1, | ||||||
|        "chunkType" : "s", |        "chunkType": "s", | ||||||
|        "urls": subUrls }]); |        "urls": subUrls }]); | ||||||
| 
 | 
 | ||||||
|   var addUpdate = buildPhishingUpdate( |   var addUpdate = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 1, // adds and subtracts don't share a chunk numbering space
 |     [{ "chunkNum": 1, // adds and subtracts don't share a chunk numbering space
 | ||||||
|        "urls": addUrls }]); |        "urls": addUrls }]); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1:s:1", |     "tableData": "test-phish-simple;a:1:s:1", | ||||||
|     "urlsExist" : [ "foo.com/b", "bar.com/b" ], |     "urlsExist": [ "foo.com/b", "bar.com/b" ], | ||||||
|     "urlsDontExist" : ["foo.com/a" ], |     "urlsDontExist": ["foo.com/a" ], | ||||||
|     "subsDontExist" : [ "foo.com/a" ] // this sub was found, it shouldn't exist anymore
 |     "subsDontExist": [ "foo.com/a" ] // this sub was found, it shouldn't exist anymore
 | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   doTest([subUpdate, addUpdate], assertions); |   doTest([subUpdate, addUpdate], assertions); | ||||||
|  | @ -122,106 +118,102 @@ function testSubPartiallyEmptiesAdd() | ||||||
| // subsDontExist assertions.  Since we don't have a good interface for getting
 | // subsDontExist assertions.  Since we don't have a good interface for getting
 | ||||||
| // at sub entries, we'll verify it by side-effect.  Subbing a url once
 | // at sub entries, we'll verify it by side-effect.  Subbing a url once
 | ||||||
| // then adding it twice should leave the url intact.
 | // then adding it twice should leave the url intact.
 | ||||||
| function testPendingSubRemoved() | function testPendingSubRemoved() { | ||||||
| { |  | ||||||
|   var subUrls = ["1:foo.com/a", "2:foo.com/b"]; |   var subUrls = ["1:foo.com/a", "2:foo.com/b"]; | ||||||
|   var addUrls = ["foo.com/a", "foo.com/b"]; |   var addUrls = ["foo.com/a", "foo.com/b"]; | ||||||
| 
 | 
 | ||||||
|   var subUpdate = buildPhishingUpdate( |   var subUpdate = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 1, |     [{ "chunkNum": 1, | ||||||
|        "chunkType" : "s", |        "chunkType": "s", | ||||||
|        "urls": subUrls }]); |        "urls": subUrls }]); | ||||||
| 
 | 
 | ||||||
|   var addUpdate1 = buildPhishingUpdate( |   var addUpdate1 = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 1, // adds and subtracts don't share a chunk numbering space
 |     [{ "chunkNum": 1, // adds and subtracts don't share a chunk numbering space
 | ||||||
|        "urls": addUrls }]); |        "urls": addUrls }]); | ||||||
| 
 | 
 | ||||||
|   var addUpdate2 = buildPhishingUpdate( |   var addUpdate2 = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 2, |     [{ "chunkNum": 2, | ||||||
|        "urls": addUrls }]); |        "urls": addUrls }]); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1-2:s:1", |     "tableData": "test-phish-simple;a:1-2:s:1", | ||||||
|     "urlsExist" : [ "foo.com/a", "foo.com/b" ], |     "urlsExist": [ "foo.com/a", "foo.com/b" ], | ||||||
|     "subsDontExist" : [ "foo.com/a", "foo.com/b" ] // this sub was found, it shouldn't exist anymore
 |     "subsDontExist": [ "foo.com/a", "foo.com/b" ] // this sub was found, it shouldn't exist anymore
 | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   doTest([subUpdate, addUpdate1, addUpdate2], assertions); |   doTest([subUpdate, addUpdate1, addUpdate2], assertions); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Make sure that a saved sub is removed when the sub chunk is expired.
 | // Make sure that a saved sub is removed when the sub chunk is expired.
 | ||||||
| function testPendingSubExpire() | function testPendingSubExpire() { | ||||||
| { |  | ||||||
|   var subUrls = ["1:foo.com/a", "1:foo.com/b"]; |   var subUrls = ["1:foo.com/a", "1:foo.com/b"]; | ||||||
|   var addUrls = ["foo.com/a", "foo.com/b"]; |   var addUrls = ["foo.com/a", "foo.com/b"]; | ||||||
| 
 | 
 | ||||||
|   var subUpdate = buildPhishingUpdate( |   var subUpdate = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 1, |     [{ "chunkNum": 1, | ||||||
|        "chunkType" : "s", |        "chunkType": "s", | ||||||
|        "urls": subUrls }]); |        "urls": subUrls }]); | ||||||
| 
 | 
 | ||||||
|   var expireUpdate = buildPhishingUpdate( |   var expireUpdate = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 1, |     [{ "chunkNum": 1, | ||||||
|        "chunkType" : "sd" }]); |        "chunkType": "sd" }]); | ||||||
| 
 | 
 | ||||||
|   var addUpdate = buildPhishingUpdate( |   var addUpdate = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 1, // adds and subtracts don't share a chunk numbering space
 |     [{ "chunkNum": 1, // adds and subtracts don't share a chunk numbering space
 | ||||||
|        "urls": addUrls }]); |        "urls": addUrls }]); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1", |     "tableData": "test-phish-simple;a:1", | ||||||
|     "urlsExist" : [ "foo.com/a", "foo.com/b" ], |     "urlsExist": [ "foo.com/a", "foo.com/b" ], | ||||||
|     "subsDontExist" : [ "foo.com/a", "foo.com/b" ] // this sub was expired
 |     "subsDontExist": [ "foo.com/a", "foo.com/b" ] // this sub was expired
 | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   doTest([subUpdate, expireUpdate, addUpdate], assertions); |   doTest([subUpdate, expireUpdate, addUpdate], assertions); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Make sure that the sub url removes from only the chunk that it specifies
 | // Make sure that the sub url removes from only the chunk that it specifies
 | ||||||
| function testDuplicateAdds() | function testDuplicateAdds() { | ||||||
| { |  | ||||||
|   var urls = ["foo.com/a"]; |   var urls = ["foo.com/a"]; | ||||||
| 
 | 
 | ||||||
|   var addUpdate1 = buildPhishingUpdate( |   var addUpdate1 = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 1, |     [{ "chunkNum": 1, | ||||||
|        "urls": urls }]); |        "urls": urls }]); | ||||||
|   var addUpdate2 = buildPhishingUpdate( |   var addUpdate2 = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 2, |     [{ "chunkNum": 2, | ||||||
|        "urls": urls }]); |        "urls": urls }]); | ||||||
|   var subUpdate = buildPhishingUpdate( |   var subUpdate = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 3, |     [{ "chunkNum": 3, | ||||||
|        "chunkType" : "s", |        "chunkType": "s", | ||||||
|        "urls": ["2:foo.com/a"]}]); |        "urls": ["2:foo.com/a"]}]); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1-2:s:3", |     "tableData": "test-phish-simple;a:1-2:s:3", | ||||||
|     "urlsExist" : [ "foo.com/a"], |     "urlsExist": [ "foo.com/a"], | ||||||
|     "subsDontExist" : [ "foo.com/a"] |     "subsDontExist": [ "foo.com/a"] | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   doTest([addUpdate1, addUpdate2, subUpdate], assertions); |   doTest([addUpdate1, addUpdate2, subUpdate], assertions); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Tests a sub which matches some existing adds but leaves others.
 | // Tests a sub which matches some existing adds but leaves others.
 | ||||||
| function testSubPartiallyMatches() | function testSubPartiallyMatches() { | ||||||
| { |  | ||||||
|   var subUrls = ["foo.com/a"]; |   var subUrls = ["foo.com/a"]; | ||||||
|   var addUrls = ["1:foo.com/a", "2:foo.com/b"]; |   var addUrls = ["1:foo.com/a", "2:foo.com/b"]; | ||||||
| 
 | 
 | ||||||
|   var addUpdate = buildPhishingUpdate( |   var addUpdate = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 1, |     [{ "chunkNum": 1, | ||||||
|        "urls" : addUrls }]); |        "urls": addUrls }]); | ||||||
| 
 | 
 | ||||||
|   var subUpdate = buildPhishingUpdate( |   var subUpdate = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 1, |     [{ "chunkNum": 1, | ||||||
|        "chunkType" : "s", |        "chunkType": "s", | ||||||
|        "urls" : addUrls }]); |        "urls": addUrls }]); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1:s:1", |     "tableData": "test-phish-simple;a:1:s:1", | ||||||
|     "urlsDontExist" : ["foo.com/a"], |     "urlsDontExist": ["foo.com/a"], | ||||||
|     "subsDontExist" : ["foo.com/a"], |     "subsDontExist": ["foo.com/a"], | ||||||
|     "subsExist" : ["foo.com/b"] |     "subsExist": ["foo.com/b"] | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([addUpdate, subUpdate], assertions); |   doTest([addUpdate, subUpdate], assertions); | ||||||
|  | @ -230,29 +222,28 @@ function testSubPartiallyMatches() | ||||||
| // XXX: because subsExist isn't actually implemented, this is the same
 | // XXX: because subsExist isn't actually implemented, this is the same
 | ||||||
| // test as above but with a second add chunk that should fail to be added
 | // test as above but with a second add chunk that should fail to be added
 | ||||||
| // because of a pending sub chunk.
 | // because of a pending sub chunk.
 | ||||||
| function testSubPartiallyMatches2() | function testSubPartiallyMatches2() { | ||||||
| { |  | ||||||
|   var addUrls = ["foo.com/a"]; |   var addUrls = ["foo.com/a"]; | ||||||
|   var subUrls = ["1:foo.com/a", "2:foo.com/b"]; |   var subUrls = ["1:foo.com/a", "2:foo.com/b"]; | ||||||
|   var addUrls2 = ["foo.com/b"]; |   var addUrls2 = ["foo.com/b"]; | ||||||
| 
 | 
 | ||||||
|   var addUpdate = buildPhishingUpdate( |   var addUpdate = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 1, |     [{ "chunkNum": 1, | ||||||
|        "urls" : addUrls }]); |        "urls": addUrls }]); | ||||||
| 
 | 
 | ||||||
|   var subUpdate = buildPhishingUpdate( |   var subUpdate = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 1, |     [{ "chunkNum": 1, | ||||||
|        "chunkType" : "s", |        "chunkType": "s", | ||||||
|        "urls" : subUrls }]); |        "urls": subUrls }]); | ||||||
| 
 | 
 | ||||||
|   var addUpdate2 = buildPhishingUpdate( |   var addUpdate2 = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 2, |     [{ "chunkNum": 2, | ||||||
|        "urls" : addUrls2 }]); |        "urls": addUrls2 }]); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1-2:s:1", |     "tableData": "test-phish-simple;a:1-2:s:1", | ||||||
|     "urlsDontExist" : ["foo.com/a", "foo.com/b"], |     "urlsDontExist": ["foo.com/a", "foo.com/b"], | ||||||
|     "subsDontExist" : ["foo.com/a", "foo.com/b"] |     "subsDontExist": ["foo.com/a", "foo.com/b"] | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([addUpdate, subUpdate, addUpdate2], assertions); |   doTest([addUpdate, subUpdate, addUpdate2], assertions); | ||||||
|  | @ -267,22 +258,22 @@ function testSubsDifferentChunks() { | ||||||
|   var addUrls = [ "foo.com/a", "foo.com/b", "foo.com/c" ]; |   var addUrls = [ "foo.com/a", "foo.com/b", "foo.com/c" ]; | ||||||
| 
 | 
 | ||||||
|   var subUpdate1 = buildPhishingUpdate( |   var subUpdate1 = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 1, |     [{ "chunkNum": 1, | ||||||
|        "chunkType" : "s", |        "chunkType": "s", | ||||||
|        "urls": subUrls1 }]); |        "urls": subUrls1 }]); | ||||||
|   var subUpdate2 = buildPhishingUpdate( |   var subUpdate2 = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 2, |     [{ "chunkNum": 2, | ||||||
|        "chunkType" : "s", |        "chunkType": "s", | ||||||
|        "urls" : subUrls2 }]); |        "urls": subUrls2 }]); | ||||||
|   var addUpdate = buildPhishingUpdate( |   var addUpdate = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 3, |     [{ "chunkNum": 3, | ||||||
|        "urls" : addUrls }]); |        "urls": addUrls }]); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:3:s:1-2", |     "tableData": "test-phish-simple;a:3:s:1-2", | ||||||
|     "urlsExist" : [ "foo.com/c" ], |     "urlsExist": [ "foo.com/c" ], | ||||||
|     "urlsDontExist" : [ "foo.com/a", "foo.com/b" ], |     "urlsDontExist": [ "foo.com/a", "foo.com/b" ], | ||||||
|     "subsDontExist" : [ "foo.com/a", "foo.com/b" ] |     "subsDontExist": [ "foo.com/a", "foo.com/b" ] | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([subUpdate1, subUpdate2, addUpdate], assertions); |   doTest([subUpdate1, subUpdate2, addUpdate], assertions); | ||||||
|  | @ -297,24 +288,24 @@ function testSubsDifferentChunksSameHostId() { | ||||||
|   var addUrls2 = [ "foo.com/c" ]; |   var addUrls2 = [ "foo.com/c" ]; | ||||||
| 
 | 
 | ||||||
|   var subUpdate1 = buildPhishingUpdate( |   var subUpdate1 = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 1, |     [{ "chunkNum": 1, | ||||||
|        "chunkType" : "s", |        "chunkType": "s", | ||||||
|        "urls": subUrls1 }]); |        "urls": subUrls1 }]); | ||||||
|   var subUpdate2 = buildPhishingUpdate( |   var subUpdate2 = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 2, |     [{ "chunkNum": 2, | ||||||
|        "chunkType" : "s", |        "chunkType": "s", | ||||||
|        "urls" : subUrls2 }]); |        "urls": subUrls2 }]); | ||||||
| 
 | 
 | ||||||
|   var addUpdate = buildPhishingUpdate( |   var addUpdate = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 1, |     [{ "chunkNum": 1, | ||||||
|        "urls" : addUrls }]); |        "urls": addUrls }]); | ||||||
|   var addUpdate2 = buildPhishingUpdate( |   var addUpdate2 = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 2, |     [{ "chunkNum": 2, | ||||||
|        "urls" : addUrls2 }]); |        "urls": addUrls2 }]); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1-2:s:1-2", |     "tableData": "test-phish-simple;a:1-2:s:1-2", | ||||||
|     "urlsDontExist" : [ "foo.com/c", "foo.com/b", "foo.com/a", ], |     "urlsDontExist": [ "foo.com/c", "foo.com/b", "foo.com/a", ], | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([addUpdate, addUpdate2, subUpdate1, subUpdate2], assertions); |   doTest([addUpdate, addUpdate2, subUpdate1, subUpdate2], assertions); | ||||||
|  | @ -324,42 +315,42 @@ function testSubsDifferentChunksSameHostId() { | ||||||
| function testExpireLists() { | function testExpireLists() { | ||||||
|   var addUpdate = buildPhishingUpdate( |   var addUpdate = buildPhishingUpdate( | ||||||
|         [ |         [ | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "urls" : [ "foo.com/a" ] |             "urls": [ "foo.com/a" ] | ||||||
|           }, |           }, | ||||||
|           { "chunkNum" : 3, |           { "chunkNum": 3, | ||||||
|             "urls" : [ "bar.com/a" ] |             "urls": [ "bar.com/a" ] | ||||||
|           }, |           }, | ||||||
|           { "chunkNum" : 4, |           { "chunkNum": 4, | ||||||
|             "urls" : [ "baz.com/a" ] |             "urls": [ "baz.com/a" ] | ||||||
|           }, |           }, | ||||||
|           { "chunkNum" : 5, |           { "chunkNum": 5, | ||||||
|             "urls" : [ "blah.com/a" ] |             "urls": [ "blah.com/a" ] | ||||||
|           }, |           }, | ||||||
|           ]); |           ]); | ||||||
|   var subUpdate = buildPhishingUpdate( |   var subUpdate = buildPhishingUpdate( | ||||||
|         [ |         [ | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "chunkType" : "s", |             "chunkType": "s", | ||||||
|             "urls" : [ "50:foo.com/1" ] |             "urls": [ "50:foo.com/1" ] | ||||||
|           }, |           }, | ||||||
|           { "chunkNum" : 2, |           { "chunkNum": 2, | ||||||
|             "chunkType" : "s", |             "chunkType": "s", | ||||||
|             "urls" : [ "50:bar.com/1" ] |             "urls": [ "50:bar.com/1" ] | ||||||
|           }, |           }, | ||||||
|           { "chunkNum" : 3, |           { "chunkNum": 3, | ||||||
|             "chunkType" : "s", |             "chunkType": "s", | ||||||
|             "urls" : [ "50:baz.com/1" ] |             "urls": [ "50:baz.com/1" ] | ||||||
|           }, |           }, | ||||||
|           { "chunkNum" : 5, |           { "chunkNum": 5, | ||||||
|             "chunkType" : "s", |             "chunkType": "s", | ||||||
|             "urls" : [ "50:blah.com/1" ] |             "urls": [ "50:blah.com/1" ] | ||||||
|           }, |           }, | ||||||
|           ]); |           ]); | ||||||
| 
 | 
 | ||||||
|   var expireUpdate = buildPhishingUpdate( |   var expireUpdate = buildPhishingUpdate( | ||||||
|     [ { "chunkType" : "ad:1,3-5" }, |     [ { "chunkType": "ad:1,3-5" }, | ||||||
|       { "chunkType" : "sd:1-3,5" }]); |       { "chunkType": "sd:1-3,5" }]); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     //    "tableData" : "test-phish-simple;"
 |     //    "tableData" : "test-phish-simple;"
 | ||||||
|  | @ -375,17 +366,17 @@ function testDuplicateAddChunks() { | ||||||
|   var addUrls2 = [ "bar.com/b" ]; |   var addUrls2 = [ "bar.com/b" ]; | ||||||
|   var update = buildPhishingUpdate( |   var update = buildPhishingUpdate( | ||||||
|         [ |         [ | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "urls" : addUrls1 |             "urls": addUrls1 | ||||||
|           }, |           }, | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "urls" : addUrls2 |             "urls": addUrls2 | ||||||
|           }]); |           }]); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1", |     "tableData": "test-phish-simple;a:1", | ||||||
|     "urlsExist" : addUrls1, |     "urlsExist": addUrls1, | ||||||
|     "urlsDontExist" : addUrls2 |     "urlsDontExist": addUrls2 | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([update], assertions); |   doTest([update], assertions); | ||||||
|  | @ -396,18 +387,17 @@ function testDuplicateAddChunks() { | ||||||
| // that we need to add the same add chunk twice, with an expiration
 | // that we need to add the same add chunk twice, with an expiration
 | ||||||
| // in the middle.  This would be easier if subsDontExist actually
 | // in the middle.  This would be easier if subsDontExist actually
 | ||||||
| // worked...
 | // worked...
 | ||||||
| function testExpireWholeSub() | function testExpireWholeSub() { | ||||||
| { |  | ||||||
|   var subUrls = ["1:foo.com/a"]; |   var subUrls = ["1:foo.com/a"]; | ||||||
| 
 | 
 | ||||||
|   var update = buildPhishingUpdate( |   var update = buildPhishingUpdate( | ||||||
|         [{ "chunkNum" : 5, |         [{ "chunkNum": 5, | ||||||
|            "chunkType" : "s", |            "chunkType": "s", | ||||||
|            "urls" : subUrls |            "urls": subUrls | ||||||
|           }, |           }, | ||||||
|           // empty add chunk should still cause foo.com/a to go away.
 |           // empty add chunk should still cause foo.com/a to go away.
 | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "urls" : [] |             "urls": [] | ||||||
|           }, |           }, | ||||||
|           // and now adding chunk 1 again with foo.com/a should succeed,
 |           // and now adding chunk 1 again with foo.com/a should succeed,
 | ||||||
|           // because the sub should have been expired with the empty
 |           // because the sub should have been expired with the empty
 | ||||||
|  | @ -415,15 +405,15 @@ function testExpireWholeSub() | ||||||
| 
 | 
 | ||||||
|           // we need to expire this chunk to let us add chunk 1 again.
 |           // we need to expire this chunk to let us add chunk 1 again.
 | ||||||
|           { |           { | ||||||
|             "chunkType" : "ad:1" |             "chunkType": "ad:1" | ||||||
|           }, |           }, | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "urls" : [ "foo.com/a" ] |             "urls": [ "foo.com/a" ] | ||||||
|           }]); |           }]); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1:s:5", |     "tableData": "test-phish-simple;a:1:s:5", | ||||||
|     "urlsExist" : ["foo.com/a"] |     "urlsExist": ["foo.com/a"] | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([update], assertions); |   doTest([update], assertions); | ||||||
|  | @ -433,18 +423,17 @@ function testExpireWholeSub() | ||||||
| // This test is roughly the opposite of testExpireWholeSub().  We add
 | // This test is roughly the opposite of testExpireWholeSub().  We add
 | ||||||
| // the empty add first, and make sure that it prevents a sub for that
 | // the empty add first, and make sure that it prevents a sub for that
 | ||||||
| // add from being applied.
 | // add from being applied.
 | ||||||
| function testPreventWholeSub() | function testPreventWholeSub() { | ||||||
| { |  | ||||||
|   var subUrls = ["1:foo.com/a"]; |   var subUrls = ["1:foo.com/a"]; | ||||||
| 
 | 
 | ||||||
|   var update = buildPhishingUpdate( |   var update = buildPhishingUpdate( | ||||||
|         [  // empty add chunk should cause foo.com/a to not be saved
 |         [  // empty add chunk should cause foo.com/a to not be saved
 | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "urls" : [] |             "urls": [] | ||||||
|           }, |           }, | ||||||
|           { "chunkNum" : 5, |           { "chunkNum": 5, | ||||||
|            "chunkType" : "s", |            "chunkType": "s", | ||||||
|            "urls" : subUrls |            "urls": subUrls | ||||||
|           }, |           }, | ||||||
|           // and now adding chunk 1 again with foo.com/a should succeed,
 |           // and now adding chunk 1 again with foo.com/a should succeed,
 | ||||||
|           // because the sub should have been expired with the empty
 |           // because the sub should have been expired with the empty
 | ||||||
|  | @ -452,22 +441,21 @@ function testPreventWholeSub() | ||||||
| 
 | 
 | ||||||
|           // we need to expire this chunk to let us add chunk 1 again.
 |           // we need to expire this chunk to let us add chunk 1 again.
 | ||||||
|           { |           { | ||||||
|             "chunkType" : "ad:1" |             "chunkType": "ad:1" | ||||||
|           }, |           }, | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "urls" : [ "foo.com/a" ] |             "urls": [ "foo.com/a" ] | ||||||
|           }]); |           }]); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1:s:5", |     "tableData": "test-phish-simple;a:1:s:5", | ||||||
|     "urlsExist" : ["foo.com/a"] |     "urlsExist": ["foo.com/a"] | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([update], assertions); |   doTest([update], assertions); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function run_test() | function run_test() { | ||||||
| { |  | ||||||
|   runTests([ |   runTests([ | ||||||
|     testSimpleAdds, |     testSimpleAdds, | ||||||
|     testMultipleAdds, |     testMultipleAdds, | ||||||
|  |  | ||||||
|  | @ -13,7 +13,7 @@ function run_test() { | ||||||
|   let origList = Services.prefs.getCharPref("browser.safebrowsing.provider.google.lists"); |   let origList = Services.prefs.getCharPref("browser.safebrowsing.provider.google.lists"); | ||||||
| 
 | 
 | ||||||
|   // Remove 'goog-malware-shavar' from the original.
 |   // Remove 'goog-malware-shavar' from the original.
 | ||||||
|   let trimmedList = origList.replace('goog-malware-shavar,', ''); |   let trimmedList = origList.replace("goog-malware-shavar,", ""); | ||||||
|   Services.prefs.setCharPref("browser.safebrowsing.provider.google.lists", trimmedList); |   Services.prefs.setCharPref("browser.safebrowsing.provider.google.lists", trimmedList); | ||||||
| 
 | 
 | ||||||
|   try { |   try { | ||||||
|  | @ -25,7 +25,7 @@ function run_test() { | ||||||
|     //
 |     //
 | ||||||
|     SafeBrowsing.registerTables(); |     SafeBrowsing.registerTables(); | ||||||
|   } catch (e) { |   } catch (e) { | ||||||
|     ok(false, 'Exception thrown due to ' + e.toString()); |     ok(false, "Exception thrown due to " + e.toString()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   Services.prefs.setCharPref("browser.safebrowsing.provider.google.lists", origList); |   Services.prefs.setCharPref("browser.safebrowsing.provider.google.lists", origList); | ||||||
|  |  | ||||||
|  | @ -105,8 +105,7 @@ function testFailure(arg) { | ||||||
|   do_throw(arg); |   do_throw(arg); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function checkNoHost() | function checkNoHost() { | ||||||
| { |  | ||||||
|   // Looking up a no-host uri such as a data: uri should throw an exception.
 |   // Looking up a no-host uri such as a data: uri should throw an exception.
 | ||||||
|   var exception; |   var exception; | ||||||
|   try { |   try { | ||||||
|  | @ -114,7 +113,7 @@ function checkNoHost() | ||||||
|     dbservice.lookup(principal, allTables); |     dbservice.lookup(principal, allTables); | ||||||
| 
 | 
 | ||||||
|     exception = false; |     exception = false; | ||||||
|   } catch(e) { |   } catch (e) { | ||||||
|     exception = true; |     exception = true; | ||||||
|   } |   } | ||||||
|   do_check_true(exception); |   do_check_true(exception); | ||||||
|  | @ -122,8 +121,7 @@ function checkNoHost() | ||||||
|   do_test_finished(); |   do_test_finished(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function tablesCallbackWithoutSub(tables) | function tablesCallbackWithoutSub(tables) { | ||||||
| { |  | ||||||
|   var parts = tables.split("\n"); |   var parts = tables.split("\n"); | ||||||
|   parts.sort(); |   parts.sort(); | ||||||
| 
 | 
 | ||||||
|  | @ -140,8 +138,7 @@ function expireSubSuccess(result) { | ||||||
|   dbservice.getTables(tablesCallbackWithoutSub); |   dbservice.getTables(tablesCallbackWithoutSub); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function tablesCallbackWithSub(tables) | function tablesCallbackWithSub(tables) { | ||||||
| { |  | ||||||
|   var parts = tables.split("\n"); |   var parts = tables.split("\n"); | ||||||
|   parts.sort(); |   parts.sort(); | ||||||
| 
 | 
 | ||||||
|  | @ -159,8 +156,7 @@ function tablesCallbackWithSub(tables) | ||||||
|   doSimpleUpdate(data, expireSubSuccess, testFailure); |   doSimpleUpdate(data, expireSubSuccess, testFailure); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function checkChunksWithSub() | function checkChunksWithSub() { | ||||||
| { |  | ||||||
|   dbservice.getTables(tablesCallbackWithSub); |   dbservice.getTables(tablesCallbackWithSub); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -217,8 +213,7 @@ function blockedExists(result) { | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function checkState() | function checkState() { | ||||||
| { |  | ||||||
|   numExpecting = 0; |   numExpecting = 0; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -253,8 +248,7 @@ function checkState() | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function testSubSuccess(result) | function testSubSuccess(result) { | ||||||
| { |  | ||||||
|   do_check_eq(result, "1000"); |   do_check_eq(result, "1000"); | ||||||
|   checkState(); |   checkState(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -194,7 +194,7 @@ function getRandomCompletionSet(forceServerError) { | ||||||
|       let length = 1 + rand.nextNum(5); |       let length = 1 + rand.nextNum(5); | ||||||
|       for (let i = 0; i < length; i++) |       for (let i = 0; i < length; i++) | ||||||
|         hash += String.fromCharCode(rand.nextNum(8)); |         hash += String.fromCharCode(rand.nextNum(8)); | ||||||
|       prefix = hash.substring(0,4); |       prefix = hash.substring(0, 4); | ||||||
|     } while (hashPrefixes.indexOf(prefix) != -1); |     } while (hashPrefixes.indexOf(prefix) != -1); | ||||||
| 
 | 
 | ||||||
|     hashPrefixes.push(prefix); |     hashPrefixes.push(prefix); | ||||||
|  | @ -261,8 +261,7 @@ function run_test() { | ||||||
|           let numChars = COMPLETE_LENGTH - responseCompletion.hash.length; |           let numChars = COMPLETE_LENGTH - responseCompletion.hash.length; | ||||||
|           responseCompletion.hash += (new Array(numChars + 1)).join("\u0000"); |           responseCompletion.hash += (new Array(numChars + 1)).join("\u0000"); | ||||||
|         } |         } | ||||||
|       } |       } else { | ||||||
|       else { |  | ||||||
|         let numChars = COMPLETE_LENGTH - completion.hash.length; |         let numChars = COMPLETE_LENGTH - completion.hash.length; | ||||||
|         completion.hash += (new Array(numChars + 1)).join("\u0000"); |         completion.hash += (new Array(numChars + 1)).join("\u0000"); | ||||||
|       } |       } | ||||||
|  | @ -295,7 +294,7 @@ function runNextCompletion() { | ||||||
|   // Number of finished completions for this set.
 |   // Number of finished completions for this set.
 | ||||||
|   finishedCompletions = 0; |   finishedCompletions = 0; | ||||||
|   for (let completion of completionSets[currentCompletionSet]) { |   for (let completion of completionSets[currentCompletionSet]) { | ||||||
|     completer.complete(completion.hash.substring(0,4), gethashUrl, |     completer.complete(completion.hash.substring(0, 4), gethashUrl, | ||||||
|                        "test-phish-shavar", // Could be arbitrary v2 table name.
 |                        "test-phish-shavar", // Could be arbitrary v2 table name.
 | ||||||
|                        (new callback(completion))); |                        (new callback(completion))); | ||||||
|   } |   } | ||||||
|  | @ -372,8 +371,7 @@ callback.prototype = { | ||||||
|           break; |           break; | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|     } |     } else { | ||||||
|     else { |  | ||||||
|       // Hashes are not actually strings and can contain arbitrary data.
 |       // Hashes are not actually strings and can contain arbitrary data.
 | ||||||
|       do_check_eq(JSON.stringify(hash), JSON.stringify(this._completion.hash)); |       do_check_eq(JSON.stringify(hash), JSON.stringify(this._completion.hash)); | ||||||
|       do_check_eq(table, this._completion.table); |       do_check_eq(table, this._completion.table); | ||||||
|  |  | ||||||
|  | @ -68,8 +68,8 @@ let gHttpServV4 = null; | ||||||
| let gUpdatedCntForTableData = 0; // For TEST_TABLE_DATA_LIST.
 | let gUpdatedCntForTableData = 0; // For TEST_TABLE_DATA_LIST.
 | ||||||
| let gIsV4Updated = false;   // For TEST_TABLE_DATA_V4.
 | let gIsV4Updated = false;   // For TEST_TABLE_DATA_V4.
 | ||||||
| 
 | 
 | ||||||
| const NEW_CLIENT_STATE = 'sta\0te'; | const NEW_CLIENT_STATE = "sta\0te"; | ||||||
| const CHECKSUM = '\x30\x67\xc7\x2c\x5e\x50\x1c\x31\xe3\xfe\xca\x73\xf0\x47\xdc\x34\x1a\x95\x63\x99\xec\x70\x5e\x0a\xee\x9e\xfb\x17\xa1\x55\x35\x78'; | const CHECKSUM = "\x30\x67\xc7\x2c\x5e\x50\x1c\x31\xe3\xfe\xca\x73\xf0\x47\xdc\x34\x1a\x95\x63\x99\xec\x70\x5e\x0a\xee\x9e\xfb\x17\xa1\x55\x35\x78"; | ||||||
| 
 | 
 | ||||||
| prefBranch.setBoolPref("browser.safebrowsing.debug", true); | prefBranch.setBoolPref("browser.safebrowsing.debug", true); | ||||||
| 
 | 
 | ||||||
|  | @ -184,7 +184,7 @@ add_test(function test_partialUpdateV4() { | ||||||
| 
 | 
 | ||||||
| // Tests nsIUrlListManager.getGethashUrl.
 | // Tests nsIUrlListManager.getGethashUrl.
 | ||||||
| add_test(function test_getGethashUrl() { | add_test(function test_getGethashUrl() { | ||||||
|   TEST_TABLE_DATA_LIST.forEach(function (t) { |   TEST_TABLE_DATA_LIST.forEach(function(t) { | ||||||
|     equal(gListManager.getGethashUrl(t.tableName), t.gethashUrl); |     equal(gListManager.getGethashUrl(t.tableName), t.gethashUrl); | ||||||
|   }); |   }); | ||||||
|   equal(gListManager.getGethashUrl(TEST_TABLE_DATA_V4.tableName), |   equal(gListManager.getGethashUrl(TEST_TABLE_DATA_V4.tableName), | ||||||
|  | @ -245,8 +245,8 @@ function run_test() { | ||||||
| 
 | 
 | ||||||
|     // V4 append the base64 encoded request to the query string.
 |     // V4 append the base64 encoded request to the query string.
 | ||||||
|     equal(request.queryString, gExpectedQueryV4); |     equal(request.queryString, gExpectedQueryV4); | ||||||
|     equal(request.queryString.indexOf('+'), -1); |     equal(request.queryString.indexOf("+"), -1); | ||||||
|     equal(request.queryString.indexOf('/'), -1); |     equal(request.queryString.indexOf("/"), -1); | ||||||
| 
 | 
 | ||||||
|     // Respond a V2 compatible content for now. In the future we can
 |     // Respond a V2 compatible content for now. In the future we can
 | ||||||
|     // send a meaningful response to test Bug 1284178 to see if the
 |     // send a meaningful response to test Bug 1284178 to see if the
 | ||||||
|  |  | ||||||
|  | @ -11,8 +11,7 @@ function DummyCompleter() { | ||||||
| 
 | 
 | ||||||
| DummyCompleter.prototype = | DummyCompleter.prototype = | ||||||
| { | { | ||||||
| QueryInterface: function(iid) | QueryInterface(iid) { | ||||||
| { |  | ||||||
|   if (!iid.equals(Ci.nsISupports) && |   if (!iid.equals(Ci.nsISupports) && | ||||||
|       !iid.equals(Ci.nsIUrlClassifierHashCompleter)) { |       !iid.equals(Ci.nsIUrlClassifierHashCompleter)) { | ||||||
|     throw Cr.NS_ERROR_NO_INTERFACE; |     throw Cr.NS_ERROR_NO_INTERFACE; | ||||||
|  | @ -20,8 +19,7 @@ QueryInterface: function(iid) | ||||||
|   return this; |   return this; | ||||||
| }, | }, | ||||||
| 
 | 
 | ||||||
| complete: function(partialHash, gethashUrl, tableName, cb) | complete(partialHash, gethashUrl, tableName, cb) { | ||||||
| { |  | ||||||
|   this.queries.push(partialHash); |   this.queries.push(partialHash); | ||||||
|   var fragments = this.fragments; |   var fragments = this.fragments; | ||||||
|   var self = this; |   var self = this; | ||||||
|  | @ -43,8 +41,7 @@ complete: function(partialHash, gethashUrl, tableName, cb) | ||||||
|   var timer = new Timer(0, doCallback); |   var timer = new Timer(0, doCallback); | ||||||
| }, | }, | ||||||
| 
 | 
 | ||||||
| getHash: function(fragment) | getHash(fragment) { | ||||||
| { |  | ||||||
|   var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]. |   var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]. | ||||||
|   createInstance(Ci.nsIScriptableUnicodeConverter); |   createInstance(Ci.nsIScriptableUnicodeConverter); | ||||||
|   converter.charset = "UTF-8"; |   converter.charset = "UTF-8"; | ||||||
|  | @ -56,22 +53,19 @@ getHash: function(fragment) | ||||||
|   return hash.slice(0, 32); |   return hash.slice(0, 32); | ||||||
| }, | }, | ||||||
| 
 | 
 | ||||||
| addFragment: function(chunkId, fragment) | addFragment(chunkId, fragment) { | ||||||
| { |  | ||||||
|   this.addHash(chunkId, this.getHash(fragment)); |   this.addHash(chunkId, this.getHash(fragment)); | ||||||
| }, | }, | ||||||
| 
 | 
 | ||||||
| // This method allows the caller to generate complete hashes that match the
 | // This method allows the caller to generate complete hashes that match the
 | ||||||
| // prefix of a real fragment, but have different complete hashes.
 | // prefix of a real fragment, but have different complete hashes.
 | ||||||
| addConflict: function(chunkId, fragment) | addConflict(chunkId, fragment) { | ||||||
| { |  | ||||||
|   var realHash = this.getHash(fragment); |   var realHash = this.getHash(fragment); | ||||||
|   var invalidHash = this.getHash("blah blah blah blah blah"); |   var invalidHash = this.getHash("blah blah blah blah blah"); | ||||||
|   this.addHash(chunkId, realHash.slice(0, 4) + invalidHash.slice(4, 32)); |   this.addHash(chunkId, realHash.slice(0, 4) + invalidHash.slice(4, 32)); | ||||||
| }, | }, | ||||||
| 
 | 
 | ||||||
| addHash: function(chunkId, hash) | addHash(chunkId, hash) { | ||||||
| { |  | ||||||
|   var partial = hash.slice(0, 4); |   var partial = hash.slice(0, 4); | ||||||
|   if (this.fragments[partial]) { |   if (this.fragments[partial]) { | ||||||
|     this.fragments[partial].push([chunkId, hash]); |     this.fragments[partial].push([chunkId, hash]); | ||||||
|  | @ -80,8 +74,7 @@ addHash: function(chunkId, hash) | ||||||
|   } |   } | ||||||
| }, | }, | ||||||
| 
 | 
 | ||||||
| compareQueries: function(fragments) | compareQueries(fragments) { | ||||||
| { |  | ||||||
|   var expectedQueries = []; |   var expectedQueries = []; | ||||||
|   for (var i = 0; i < fragments.length; i++) { |   for (var i = 0; i < fragments.length; i++) { | ||||||
|     expectedQueries.push(this.getHash(fragments[i]).slice(0, 4)); |     expectedQueries.push(this.getHash(fragments[i]).slice(0, 4)); | ||||||
|  | @ -95,8 +88,7 @@ compareQueries: function(fragments) | ||||||
| } | } | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| function setupCompleter(table, hits, conflicts) | function setupCompleter(table, hits, conflicts) { | ||||||
| { |  | ||||||
|   var completer = new DummyCompleter(); |   var completer = new DummyCompleter(); | ||||||
|   completer.tableName = table; |   completer.tableName = table; | ||||||
|   for (var i = 0; i < hits.length; i++) { |   for (var i = 0; i < hits.length; i++) { | ||||||
|  | @ -119,8 +111,7 @@ function setupCompleter(table, hits, conflicts) | ||||||
|   return completer; |   return completer; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function installCompleter(table, fragments, conflictFragments) | function installCompleter(table, fragments, conflictFragments) { | ||||||
| { |  | ||||||
|   return setupCompleter(table, fragments, conflictFragments); |   return setupCompleter(table, fragments, conflictFragments); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -131,15 +122,13 @@ function installFailingCompleter(table) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Helper assertion for checking dummy completer queries
 | // Helper assertion for checking dummy completer queries
 | ||||||
| gAssertions.completerQueried = function(data, cb) | gAssertions.completerQueried = function(data, cb) { | ||||||
| { |  | ||||||
|   var completer = data[0]; |   var completer = data[0]; | ||||||
|   completer.compareQueries(data[1]); |   completer.compareQueries(data[1]); | ||||||
|   cb(); |   cb(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function doTest(updates, assertions) | function doTest(updates, assertions) { | ||||||
| { |  | ||||||
|   doUpdateTest(updates, assertions, runNextTest, updateError); |   doUpdateTest(updates, assertions, runNextTest, updateError); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -148,18 +137,18 @@ function testPartialAdds() { | ||||||
|   var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; |   var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; | ||||||
|   var update = buildPhishingUpdate( |   var update = buildPhishingUpdate( | ||||||
|         [ |         [ | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "urls" : addUrls |             "urls": addUrls | ||||||
|           }], |           }], | ||||||
|     4); |     4); | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|   var completer = installCompleter('test-phish-simple', [[1, addUrls]], []); |   var completer = installCompleter("test-phish-simple", [[1, addUrls]], []); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1", |     "tableData": "test-phish-simple;a:1", | ||||||
|     "urlsExist" : addUrls, |     "urlsExist": addUrls, | ||||||
|     "completerQueried" : [completer, addUrls] |     "completerQueried": [completer, addUrls] | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -170,20 +159,20 @@ function testPartialAddsWithConflicts() { | ||||||
|   var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; |   var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; | ||||||
|   var update = buildPhishingUpdate( |   var update = buildPhishingUpdate( | ||||||
|         [ |         [ | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "urls" : addUrls |             "urls": addUrls | ||||||
|           }], |           }], | ||||||
|     4); |     4); | ||||||
| 
 | 
 | ||||||
|   // Each result will have both a real match and a conflict
 |   // Each result will have both a real match and a conflict
 | ||||||
|   var completer = installCompleter('test-phish-simple', |   var completer = installCompleter("test-phish-simple", | ||||||
|                                    [[1, addUrls]], |                                    [[1, addUrls]], | ||||||
|                                    [[1, addUrls]]); |                                    [[1, addUrls]]); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1", |     "tableData": "test-phish-simple;a:1", | ||||||
|     "urlsExist" : addUrls, |     "urlsExist": addUrls, | ||||||
|     "completerQueried" : [completer, addUrls] |     "completerQueried": [completer, addUrls] | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([update], assertions); |   doTest([update], assertions); | ||||||
|  | @ -194,18 +183,18 @@ function testFragments() { | ||||||
|   var addUrls = [ "foo.com/a/b/c", "foo.net/", "foo.com/c/" ]; |   var addUrls = [ "foo.com/a/b/c", "foo.net/", "foo.com/c/" ]; | ||||||
|   var update = buildPhishingUpdate( |   var update = buildPhishingUpdate( | ||||||
|         [ |         [ | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "urls" : addUrls |             "urls": addUrls | ||||||
|           }], |           }], | ||||||
|     4); |     4); | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|   var completer = installCompleter('test-phish-simple', [[1, addUrls]], []); |   var completer = installCompleter("test-phish-simple", [[1, addUrls]], []); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1", |     "tableData": "test-phish-simple;a:1", | ||||||
|     "urlsExist" : addUrls, |     "urlsExist": addUrls, | ||||||
|     "completerQueried" : [completer, addUrls] |     "completerQueried": [completer, addUrls] | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -228,18 +217,18 @@ function testSpecFragments() { | ||||||
| 
 | 
 | ||||||
|   var update = buildPhishingUpdate( |   var update = buildPhishingUpdate( | ||||||
|         [ |         [ | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "urls" : addUrls |             "urls": addUrls | ||||||
|           }], |           }], | ||||||
|     4); |     4); | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|   var completer = installCompleter('test-phish-simple', [[1, addUrls]], []); |   var completer = installCompleter("test-phish-simple", [[1, addUrls]], []); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1", |     "tableData": "test-phish-simple;a:1", | ||||||
|     "urlsExist" : probeUrls, |     "urlsExist": probeUrls, | ||||||
|     "completerQueried" : [completer, addUrls] |     "completerQueried": [completer, addUrls] | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([update], assertions); |   doTest([update], assertions); | ||||||
|  | @ -264,17 +253,17 @@ function testMoreSpecFragments() { | ||||||
| 
 | 
 | ||||||
|   var update = buildPhishingUpdate( |   var update = buildPhishingUpdate( | ||||||
|         [ |         [ | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "urls" : addUrls |             "urls": addUrls | ||||||
|           }], |           }], | ||||||
|     4); |     4); | ||||||
| 
 | 
 | ||||||
|   var completer = installCompleter('test-phish-simple', [[1, addUrls]], []); |   var completer = installCompleter("test-phish-simple", [[1, addUrls]], []); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1", |     "tableData": "test-phish-simple;a:1", | ||||||
|     "urlsExist" : probeUrls, |     "urlsExist": probeUrls, | ||||||
|     "completerQueried" : [completer, addUrls] |     "completerQueried": [completer, addUrls] | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([update], assertions); |   doTest([update], assertions); | ||||||
|  | @ -285,19 +274,19 @@ function testFalsePositives() { | ||||||
|   var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; |   var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; | ||||||
|   var update = buildPhishingUpdate( |   var update = buildPhishingUpdate( | ||||||
|         [ |         [ | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "urls" : addUrls |             "urls": addUrls | ||||||
|           }], |           }], | ||||||
|     4); |     4); | ||||||
| 
 | 
 | ||||||
|   // Each result will have no matching complete hashes and a non-matching
 |   // Each result will have no matching complete hashes and a non-matching
 | ||||||
|   // conflict
 |   // conflict
 | ||||||
|   var completer = installCompleter('test-phish-simple', [], [[1, addUrls]]); |   var completer = installCompleter("test-phish-simple", [], [[1, addUrls]]); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1", |     "tableData": "test-phish-simple;a:1", | ||||||
|     "urlsDontExist" : addUrls, |     "urlsDontExist": addUrls, | ||||||
|     "completerQueried" : [completer, addUrls] |     "completerQueried": [completer, addUrls] | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([update], assertions); |   doTest([update], assertions); | ||||||
|  | @ -307,18 +296,18 @@ function testEmptyCompleter() { | ||||||
|   var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; |   var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; | ||||||
|   var update = buildPhishingUpdate( |   var update = buildPhishingUpdate( | ||||||
|         [ |         [ | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "urls" : addUrls |             "urls": addUrls | ||||||
|           }], |           }], | ||||||
|     4); |     4); | ||||||
| 
 | 
 | ||||||
|   // Completer will never return full hashes
 |   // Completer will never return full hashes
 | ||||||
|   var completer = installCompleter('test-phish-simple', [], []); |   var completer = installCompleter("test-phish-simple", [], []); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1", |     "tableData": "test-phish-simple;a:1", | ||||||
|     "urlsDontExist" : addUrls, |     "urlsDontExist": addUrls, | ||||||
|     "completerQueried" : [completer, addUrls] |     "completerQueried": [completer, addUrls] | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([update], assertions); |   doTest([update], assertions); | ||||||
|  | @ -328,18 +317,18 @@ function testCompleterFailure() { | ||||||
|   var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; |   var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; | ||||||
|   var update = buildPhishingUpdate( |   var update = buildPhishingUpdate( | ||||||
|         [ |         [ | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "urls" : addUrls |             "urls": addUrls | ||||||
|           }], |           }], | ||||||
|     4); |     4); | ||||||
| 
 | 
 | ||||||
|   // Completer will never return full hashes
 |   // Completer will never return full hashes
 | ||||||
|   var completer = installFailingCompleter('test-phish-simple'); |   var completer = installFailingCompleter("test-phish-simple"); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1", |     "tableData": "test-phish-simple;a:1", | ||||||
|     "urlsDontExist" : addUrls, |     "urlsDontExist": addUrls, | ||||||
|     "completerQueried" : [completer, addUrls] |     "completerQueried": [completer, addUrls] | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([update], assertions); |   doTest([update], assertions); | ||||||
|  | @ -351,24 +340,24 @@ function testMixedSizesSameDomain() { | ||||||
| 
 | 
 | ||||||
|   var update1 = buildPhishingUpdate( |   var update1 = buildPhishingUpdate( | ||||||
|     [ |     [ | ||||||
|       { "chunkNum" : 1, |       { "chunkNum": 1, | ||||||
|         "urls" : add1Urls }], |         "urls": add1Urls }], | ||||||
|     4); |     4); | ||||||
|   var update2 = buildPhishingUpdate( |   var update2 = buildPhishingUpdate( | ||||||
|     [ |     [ | ||||||
|       { "chunkNum" : 2, |       { "chunkNum": 2, | ||||||
|         "urls" : add2Urls }], |         "urls": add2Urls }], | ||||||
|     32); |     32); | ||||||
| 
 | 
 | ||||||
|   // We should only need to complete the partial hashes
 |   // We should only need to complete the partial hashes
 | ||||||
|   var completer = installCompleter('test-phish-simple', [[1, add1Urls]], []); |   var completer = installCompleter("test-phish-simple", [[1, add1Urls]], []); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1-2", |     "tableData": "test-phish-simple;a:1-2", | ||||||
|     // both urls should match...
 |     // both urls should match...
 | ||||||
|     "urlsExist" : add1Urls.concat(add2Urls), |     "urlsExist": add1Urls.concat(add2Urls), | ||||||
|     // ... but the completer should only be queried for the partial entry
 |     // ... but the completer should only be queried for the partial entry
 | ||||||
|     "completerQueried" : [completer, add1Urls] |     "completerQueried": [completer, add1Urls] | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([update1, update2], assertions); |   doTest([update1, update2], assertions); | ||||||
|  | @ -380,68 +369,66 @@ function testMixedSizesDifferentDomains() { | ||||||
| 
 | 
 | ||||||
|   var update1 = buildPhishingUpdate( |   var update1 = buildPhishingUpdate( | ||||||
|     [ |     [ | ||||||
|       { "chunkNum" : 1, |       { "chunkNum": 1, | ||||||
|         "urls" : add1Urls }], |         "urls": add1Urls }], | ||||||
|     4); |     4); | ||||||
|   var update2 = buildPhishingUpdate( |   var update2 = buildPhishingUpdate( | ||||||
|     [ |     [ | ||||||
|       { "chunkNum" : 2, |       { "chunkNum": 2, | ||||||
|         "urls" : add2Urls }], |         "urls": add2Urls }], | ||||||
|     32); |     32); | ||||||
| 
 | 
 | ||||||
|   // We should only need to complete the partial hashes
 |   // We should only need to complete the partial hashes
 | ||||||
|   var completer = installCompleter('test-phish-simple', [[1, add1Urls]], []); |   var completer = installCompleter("test-phish-simple", [[1, add1Urls]], []); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1-2", |     "tableData": "test-phish-simple;a:1-2", | ||||||
|     // both urls should match...
 |     // both urls should match...
 | ||||||
|     "urlsExist" : add1Urls.concat(add2Urls), |     "urlsExist": add1Urls.concat(add2Urls), | ||||||
|     // ... but the completer should only be queried for the partial entry
 |     // ... but the completer should only be queried for the partial entry
 | ||||||
|     "completerQueried" : [completer, add1Urls] |     "completerQueried": [completer, add1Urls] | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([update1, update2], assertions); |   doTest([update1, update2], assertions); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function testInvalidHashSize() | function testInvalidHashSize() { | ||||||
| { |  | ||||||
|   var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; |   var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; | ||||||
|   var update = buildPhishingUpdate( |   var update = buildPhishingUpdate( | ||||||
|         [ |         [ | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "urls" : addUrls |             "urls": addUrls | ||||||
|           }], |           }], | ||||||
|         12); // only 4 and 32 are legal hash sizes
 |         12); // only 4 and 32 are legal hash sizes
 | ||||||
| 
 | 
 | ||||||
|   var addUrls2 = [ "zaz.com/a", "xyz.com/b" ]; |   var addUrls2 = [ "zaz.com/a", "xyz.com/b" ]; | ||||||
|   var update2 = buildPhishingUpdate( |   var update2 = buildPhishingUpdate( | ||||||
|         [ |         [ | ||||||
|           { "chunkNum" : 2, |           { "chunkNum": 2, | ||||||
|             "urls" : addUrls2 |             "urls": addUrls2 | ||||||
|           }], |           }], | ||||||
|         4); |         4); | ||||||
| 
 | 
 | ||||||
|   var completer = installCompleter('test-phish-simple', [[1, addUrls]], []); |   var completer = installCompleter("test-phish-simple", [[1, addUrls]], []); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:2", |     "tableData": "test-phish-simple;a:2", | ||||||
|     "urlsDontExist" : addUrls |     "urlsDontExist": addUrls | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   // A successful update will trigger an error
 |   // A successful update will trigger an error
 | ||||||
|   doUpdateTest([update2, update], assertions, updateError, runNextTest); |   doUpdateTest([update2, update], assertions, updateError, runNextTest); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function testWrongTable() | function testWrongTable() { | ||||||
| { |  | ||||||
|   var addUrls = [ "foo.com/a" ]; |   var addUrls = [ "foo.com/a" ]; | ||||||
|   var update = buildPhishingUpdate( |   var update = buildPhishingUpdate( | ||||||
|         [ |         [ | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "urls" : addUrls |             "urls": addUrls | ||||||
|           }], |           }], | ||||||
|         4); |         4); | ||||||
|   var completer = installCompleter('test-malware-simple', // wrong table
 |   var completer = installCompleter("test-malware-simple", // wrong table
 | ||||||
|                                    [[1, addUrls]], []); |                                    [[1, addUrls]], []); | ||||||
| 
 | 
 | ||||||
|   // The above installCompleter installs the completer for test-malware-simple,
 |   // The above installCompleter installs the completer for test-malware-simple,
 | ||||||
|  | @ -450,13 +437,13 @@ function testWrongTable() | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1", |     "tableData": "test-phish-simple;a:1", | ||||||
|     // The urls were added as phishing urls, but the completer is claiming
 |     // The urls were added as phishing urls, but the completer is claiming
 | ||||||
|     // that they are malware urls, and we trust the completer in this case.
 |     // that they are malware urls, and we trust the completer in this case.
 | ||||||
|     // The result will be discarded, so we can only check for non-existence.
 |     // The result will be discarded, so we can only check for non-existence.
 | ||||||
|     "urlsDontExist" : addUrls, |     "urlsDontExist": addUrls, | ||||||
|     // Make sure the completer was actually queried.
 |     // Make sure the completer was actually queried.
 | ||||||
|     "completerQueried" : [completer, addUrls] |     "completerQueried": [completer, addUrls] | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doUpdateTest([update], assertions, |   doUpdateTest([update], assertions, | ||||||
|  | @ -466,34 +453,33 @@ function testWrongTable() | ||||||
|                      // The miss earlier will have caused a miss to be cached.
 |                      // The miss earlier will have caused a miss to be cached.
 | ||||||
|                      // Resetting the completer does not count as an update,
 |                      // Resetting the completer does not count as an update,
 | ||||||
|                      // so we will not be probed again.
 |                      // so we will not be probed again.
 | ||||||
|                      var newCompleter = installCompleter('test-malware-simple', [[1, addUrls]], []);                     dbservice.setHashCompleter("test-phish-simple", |                      var newCompleter = installCompleter("test-malware-simple", [[1, addUrls]], []); dbservice.setHashCompleter("test-phish-simple", | ||||||
|                                                 newCompleter); |                                                 newCompleter); | ||||||
| 
 | 
 | ||||||
|                      var assertions = { |                      var assertions = { | ||||||
|                        "urlsDontExist" : addUrls |                        "urlsDontExist": addUrls | ||||||
|                      }; |                      }; | ||||||
|                      checkAssertions(assertions, runNextTest); |                      checkAssertions(assertions, runNextTest); | ||||||
|                    }); |                    }); | ||||||
|                }, updateError); |                }, updateError); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function setupCachedResults(addUrls, part2) | function setupCachedResults(addUrls, part2) { | ||||||
| { |  | ||||||
|   var update = buildPhishingUpdate( |   var update = buildPhishingUpdate( | ||||||
|         [ |         [ | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "urls" : addUrls |             "urls": addUrls | ||||||
|           }], |           }], | ||||||
|         4); |         4); | ||||||
| 
 | 
 | ||||||
|   var completer = installCompleter('test-phish-simple', [[1, addUrls]], []); |   var completer = installCompleter("test-phish-simple", [[1, addUrls]], []); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1", |     "tableData": "test-phish-simple;a:1", | ||||||
|     // Request the add url.  This should cause the completion to be cached.
 |     // Request the add url.  This should cause the completion to be cached.
 | ||||||
|     "urlsExist" : addUrls, |     "urlsExist": addUrls, | ||||||
|     // Make sure the completer was actually queried.
 |     // Make sure the completer was actually queried.
 | ||||||
|     "completerQueried" : [completer, addUrls] |     "completerQueried": [completer, addUrls] | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doUpdateTest([update], assertions, |   doUpdateTest([update], assertions, | ||||||
|  | @ -503,18 +489,17 @@ function setupCachedResults(addUrls, part2) | ||||||
|                }, updateError); |                }, updateError); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function testCachedResults() | function testCachedResults() { | ||||||
| { |  | ||||||
|   setupCachedResults(["foo.com/a"], function(add) { |   setupCachedResults(["foo.com/a"], function(add) { | ||||||
|       // This is called after setupCachedResults().  Verify that
 |       // This is called after setupCachedResults().  Verify that
 | ||||||
|       // checking the url again does not cause a completer request.
 |       // checking the url again does not cause a completer request.
 | ||||||
| 
 | 
 | ||||||
|       // install a new completer, this one should never be queried.
 |       // install a new completer, this one should never be queried.
 | ||||||
|       var newCompleter = installCompleter('test-phish-simple', [[1, []]], []); |       var newCompleter = installCompleter("test-phish-simple", [[1, []]], []); | ||||||
| 
 | 
 | ||||||
|       var assertions = { |       var assertions = { | ||||||
|         "urlsExist" : ["foo.com/a"], |         "urlsExist": ["foo.com/a"], | ||||||
|         "completerQueried" : [newCompleter, []] |         "completerQueried": [newCompleter, []] | ||||||
|       }; |       }; | ||||||
|       checkAssertions(assertions, runNextTest); |       checkAssertions(assertions, runNextTest); | ||||||
|     }); |     }); | ||||||
|  | @ -523,17 +508,17 @@ function testCachedResults() | ||||||
| function testCachedResultsWithSub() { | function testCachedResultsWithSub() { | ||||||
|   setupCachedResults(["foo.com/a"], function() { |   setupCachedResults(["foo.com/a"], function() { | ||||||
|       // install a new completer, this one should never be queried.
 |       // install a new completer, this one should never be queried.
 | ||||||
|       var newCompleter = installCompleter('test-phish-simple', [[1, []]], []); |       var newCompleter = installCompleter("test-phish-simple", [[1, []]], []); | ||||||
| 
 | 
 | ||||||
|       var removeUpdate = buildPhishingUpdate( |       var removeUpdate = buildPhishingUpdate( | ||||||
|         [ { "chunkNum" : 2, |         [ { "chunkNum": 2, | ||||||
|             "chunkType" : "s", |             "chunkType": "s", | ||||||
|             "urls": ["1:foo.com/a"] }], |             "urls": ["1:foo.com/a"] }], | ||||||
|         4); |         4); | ||||||
| 
 | 
 | ||||||
|       var assertions = { |       var assertions = { | ||||||
|         "urlsDontExist" : ["foo.com/a"], |         "urlsDontExist": ["foo.com/a"], | ||||||
|         "completerQueried" : [newCompleter, []] |         "completerQueried": [newCompleter, []] | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       doTest([removeUpdate], assertions); |       doTest([removeUpdate], assertions); | ||||||
|  | @ -543,7 +528,7 @@ function testCachedResultsWithSub() { | ||||||
| function testCachedResultsWithExpire() { | function testCachedResultsWithExpire() { | ||||||
|   setupCachedResults(["foo.com/a"], function() { |   setupCachedResults(["foo.com/a"], function() { | ||||||
|       // install a new completer, this one should never be queried.
 |       // install a new completer, this one should never be queried.
 | ||||||
|       var newCompleter = installCompleter('test-phish-simple', [[1, []]], []); |       var newCompleter = installCompleter("test-phish-simple", [[1, []]], []); | ||||||
| 
 | 
 | ||||||
|       var expireUpdate = |       var expireUpdate = | ||||||
|         "n:1000\n" + |         "n:1000\n" + | ||||||
|  | @ -551,34 +536,33 @@ function testCachedResultsWithExpire() { | ||||||
|         "ad:1\n"; |         "ad:1\n"; | ||||||
| 
 | 
 | ||||||
|       var assertions = { |       var assertions = { | ||||||
|         "urlsDontExist" : ["foo.com/a"], |         "urlsDontExist": ["foo.com/a"], | ||||||
|         "completerQueried" : [newCompleter, []] |         "completerQueried": [newCompleter, []] | ||||||
|       } |       } | ||||||
|       doTest([expireUpdate], assertions); |       doTest([expireUpdate], assertions); | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function testCachedResultsFailure() | function testCachedResultsFailure() { | ||||||
| { |  | ||||||
|   var existUrls = ["foo.com/a"]; |   var existUrls = ["foo.com/a"]; | ||||||
|   setupCachedResults(existUrls, function() { |   setupCachedResults(existUrls, function() { | ||||||
|     // This is called after setupCachedResults().  Verify that
 |     // This is called after setupCachedResults().  Verify that
 | ||||||
|     // checking the url again does not cause a completer request.
 |     // checking the url again does not cause a completer request.
 | ||||||
| 
 | 
 | ||||||
|     // install a new completer, this one should never be queried.
 |     // install a new completer, this one should never be queried.
 | ||||||
|     var newCompleter = installCompleter('test-phish-simple', [[1, []]], []); |     var newCompleter = installCompleter("test-phish-simple", [[1, []]], []); | ||||||
| 
 | 
 | ||||||
|     var assertions = { |     var assertions = { | ||||||
|       "urlsExist" : existUrls, |       "urlsExist": existUrls, | ||||||
|       "completerQueried" : [newCompleter, []] |       "completerQueried": [newCompleter, []] | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     var addUrls = ["foobar.org/a"]; |     var addUrls = ["foobar.org/a"]; | ||||||
| 
 | 
 | ||||||
|     var update2 = buildPhishingUpdate( |     var update2 = buildPhishingUpdate( | ||||||
|         [ |         [ | ||||||
|           { "chunkNum" : 2, |           { "chunkNum": 2, | ||||||
|             "urls" : addUrls |             "urls": addUrls | ||||||
|           }], |           }], | ||||||
|         4); |         4); | ||||||
| 
 | 
 | ||||||
|  | @ -586,11 +570,11 @@ function testCachedResultsFailure() | ||||||
|       // Apply the update. The cached completes should be gone.
 |       // Apply the update. The cached completes should be gone.
 | ||||||
|       doErrorUpdate("test-phish-simple,test-malware-simple", function() { |       doErrorUpdate("test-phish-simple,test-malware-simple", function() { | ||||||
|         // Now the completer gets queried again.
 |         // Now the completer gets queried again.
 | ||||||
|         var newCompleter2 = installCompleter('test-phish-simple', [[1, existUrls]], []); |         var newCompleter2 = installCompleter("test-phish-simple", [[1, existUrls]], []); | ||||||
|         var assertions2 = { |         var assertions2 = { | ||||||
|           "tableData" : "test-phish-simple;a:1", |           "tableData": "test-phish-simple;a:1", | ||||||
|           "urlsExist" : existUrls, |           "urlsExist": existUrls, | ||||||
|           "completerQueried" : [newCompleter2, existUrls] |           "completerQueried": [newCompleter2, existUrls] | ||||||
|         }; |         }; | ||||||
|         checkAssertions(assertions2, runNextTest); |         checkAssertions(assertions2, runNextTest); | ||||||
|       }, updateError); |       }, updateError); | ||||||
|  | @ -598,26 +582,25 @@ function testCachedResultsFailure() | ||||||
|   }); |   }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function testErrorList() | function testErrorList() { | ||||||
| { |  | ||||||
|   var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; |   var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; | ||||||
|   var update = buildPhishingUpdate( |   var update = buildPhishingUpdate( | ||||||
|         [ |         [ | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "urls" : addUrls |             "urls": addUrls | ||||||
|           }], |           }], | ||||||
|     4); |     4); | ||||||
|   // The update failure should will kill the completes, so the above
 |   // The update failure should will kill the completes, so the above
 | ||||||
|   // must be a prefix to get any hit at all past the update failure.
 |   // must be a prefix to get any hit at all past the update failure.
 | ||||||
| 
 | 
 | ||||||
|   var completer = installCompleter('test-phish-simple', [[1, addUrls]], []); |   var completer = installCompleter("test-phish-simple", [[1, addUrls]], []); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1", |     "tableData": "test-phish-simple;a:1", | ||||||
|     "urlsExist" : addUrls, |     "urlsExist": addUrls, | ||||||
|     // These are complete urls, and will only be completed if the
 |     // These are complete urls, and will only be completed if the
 | ||||||
|     // list is stale.
 |     // list is stale.
 | ||||||
|     "completerQueried" : [completer, addUrls] |     "completerQueried": [completer, addUrls] | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   // Apply the update.
 |   // Apply the update.
 | ||||||
|  | @ -634,14 +617,13 @@ function testErrorList() | ||||||
| 
 | 
 | ||||||
| // Verify that different lists (test-phish-simple,
 | // Verify that different lists (test-phish-simple,
 | ||||||
| // test-malware-simple) maintain their freshness separately.
 | // test-malware-simple) maintain their freshness separately.
 | ||||||
| function testErrorListIndependent() | function testErrorListIndependent() { | ||||||
| { |  | ||||||
|   var phishUrls = [ "phish.com/a" ]; |   var phishUrls = [ "phish.com/a" ]; | ||||||
|   var malwareUrls = [ "attack.com/a" ]; |   var malwareUrls = [ "attack.com/a" ]; | ||||||
|   var update = buildPhishingUpdate( |   var update = buildPhishingUpdate( | ||||||
|         [ |         [ | ||||||
|           { "chunkNum" : 1, |           { "chunkNum": 1, | ||||||
|             "urls" : phishUrls |             "urls": phishUrls | ||||||
|           }], |           }], | ||||||
|     4); |     4); | ||||||
|   // These have to persist past the update failure, so they must be prefixes,
 |   // These have to persist past the update failure, so they must be prefixes,
 | ||||||
|  | @ -649,20 +631,20 @@ function testErrorListIndependent() | ||||||
| 
 | 
 | ||||||
|   update += buildMalwareUpdate( |   update += buildMalwareUpdate( | ||||||
|         [ |         [ | ||||||
|           { "chunkNum" : 2, |           { "chunkNum": 2, | ||||||
|             "urls" : malwareUrls |             "urls": malwareUrls | ||||||
|           }], |           }], | ||||||
|     32); |     32); | ||||||
| 
 | 
 | ||||||
|   var completer = installCompleter('test-phish-simple', [[1, phishUrls]], []); |   var completer = installCompleter("test-phish-simple", [[1, phishUrls]], []); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-malware-simple;a:2\ntest-phish-simple;a:1", |     "tableData": "test-malware-simple;a:2\ntest-phish-simple;a:1", | ||||||
|     "urlsExist" : phishUrls, |     "urlsExist": phishUrls, | ||||||
|     "malwareUrlsExist" : malwareUrls, |     "malwareUrlsExist": malwareUrls, | ||||||
|     // Only this phishing urls should be completed, because only the phishing
 |     // Only this phishing urls should be completed, because only the phishing
 | ||||||
|     // urls will be stale.
 |     // urls will be stale.
 | ||||||
|     "completerQueried" : [completer, phishUrls] |     "completerQueried": [completer, phishUrls] | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   // Apply the update.
 |   // Apply the update.
 | ||||||
|  | @ -677,8 +659,7 @@ function testErrorListIndependent() | ||||||
|     }, updateError); |     }, updateError); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function run_test() | function run_test() { | ||||||
| { |  | ||||||
|   runTests([ |   runTests([ | ||||||
|       testPartialAdds, |       testPartialAdds, | ||||||
|       testPartialAddsWithConflicts, |       testPartialAddsWithConflicts, | ||||||
|  |  | ||||||
|  | @ -18,9 +18,9 @@ function arrContains(arr, target) { | ||||||
|     let value = arr[i]; |     let value = arr[i]; | ||||||
| 
 | 
 | ||||||
|     if (value < target) |     if (value < target) | ||||||
|       start = i+1; |       start = i + 1; | ||||||
|     else if (value > target) |     else if (value > target) | ||||||
|       end = i-1; |       end = i - 1; | ||||||
|     else |     else | ||||||
|       break; |       break; | ||||||
|   } |   } | ||||||
|  | @ -37,7 +37,7 @@ function checkContents(pset, prefixes) { | ||||||
|   outset = pset.getPrefixes(outcount); |   outset = pset.getPrefixes(outcount); | ||||||
|   let inset = prefixes; |   let inset = prefixes; | ||||||
|   do_check_eq(inset.length, outset.length); |   do_check_eq(inset.length, outset.length); | ||||||
|   inset.sort((x,y) => x - y); |   inset.sort((x, y) => x - y); | ||||||
|   for (let i = 0; i < inset.length; i++) { |   for (let i = 0; i < inset.length; i++) { | ||||||
|     do_check_eq(inset[i], outset[i]); |     do_check_eq(inset[i], outset[i]); | ||||||
|   } |   } | ||||||
|  | @ -45,7 +45,7 @@ function checkContents(pset, prefixes) { | ||||||
| 
 | 
 | ||||||
| function wrappedProbe(pset, prefix) { | function wrappedProbe(pset, prefix) { | ||||||
|   return pset.contains(prefix); |   return pset.contains(prefix); | ||||||
| }; | } | ||||||
| 
 | 
 | ||||||
| // doRandomLookups: we use this to test for false membership with random input
 | // doRandomLookups: we use this to test for false membership with random input
 | ||||||
| // over the range of prefixes (unsigned 32-bits integers).
 | // over the range of prefixes (unsigned 32-bits integers).
 | ||||||
|  | @ -67,7 +67,7 @@ function doRandomLookups(pset, prefixes, N) { | ||||||
| //    prefixes:
 | //    prefixes:
 | ||||||
| function doExpectedLookups(pset, prefixes, N) { | function doExpectedLookups(pset, prefixes, N) { | ||||||
|   for (let i = 0; i < N; i++) { |   for (let i = 0; i < N; i++) { | ||||||
|     prefixes.forEach(function (x) { |     prefixes.forEach(function(x) { | ||||||
|       dump("Checking " + x + "\n"); |       dump("Checking " + x + "\n"); | ||||||
|       do_check_true(wrappedProbe(pset, x)); |       do_check_true(wrappedProbe(pset, x)); | ||||||
|     }); |     }); | ||||||
|  | @ -79,7 +79,7 @@ function doExpectedLookups(pset, prefixes, N) { | ||||||
| function testBasicPset() { | function testBasicPset() { | ||||||
|   let pset = Cc["@mozilla.org/url-classifier/prefixset;1"] |   let pset = Cc["@mozilla.org/url-classifier/prefixset;1"] | ||||||
|                .createInstance(Ci.nsIUrlClassifierPrefixSet); |                .createInstance(Ci.nsIUrlClassifierPrefixSet); | ||||||
|   let prefixes = [2,50,100,2000,78000,1593203]; |   let prefixes = [2, 50, 100, 2000, 78000, 1593203]; | ||||||
|   pset.setPrefixes(prefixes, prefixes.length); |   pset.setPrefixes(prefixes, prefixes.length); | ||||||
| 
 | 
 | ||||||
|   do_check_true(wrappedProbe(pset, 100)); |   do_check_true(wrappedProbe(pset, 100)); | ||||||
|  | @ -95,7 +95,7 @@ function testBasicPset() { | ||||||
| function testDuplicates() { | function testDuplicates() { | ||||||
|   let pset = Cc["@mozilla.org/url-classifier/prefixset;1"] |   let pset = Cc["@mozilla.org/url-classifier/prefixset;1"] | ||||||
|                .createInstance(Ci.nsIUrlClassifierPrefixSet); |                .createInstance(Ci.nsIUrlClassifierPrefixSet); | ||||||
|   let prefixes = [1,1,2,2,2,3,3,3,3,3,3,5,6,6,7,7,9,9,9]; |   let prefixes = [1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 5, 6, 6, 7, 7, 9, 9, 9]; | ||||||
|   pset.setPrefixes(prefixes, prefixes.length); |   pset.setPrefixes(prefixes, prefixes.length); | ||||||
| 
 | 
 | ||||||
|   do_check_true(wrappedProbe(pset, 1)); |   do_check_true(wrappedProbe(pset, 1)); | ||||||
|  | @ -111,7 +111,7 @@ function testDuplicates() { | ||||||
| 
 | 
 | ||||||
| function testSimplePset() { | function testSimplePset() { | ||||||
|   let pset = newPset(); |   let pset = newPset(); | ||||||
|   let prefixes = [1,2,100,400,123456789]; |   let prefixes = [1, 2, 100, 400, 123456789]; | ||||||
|   pset.setPrefixes(prefixes, prefixes.length); |   pset.setPrefixes(prefixes, prefixes.length); | ||||||
| 
 | 
 | ||||||
|   doRandomLookups(pset, prefixes, 100); |   doRandomLookups(pset, prefixes, 100); | ||||||
|  | @ -149,7 +149,7 @@ function testLoadSaveLargeSet() { | ||||||
|     arr.push(randInt); |     arr.push(randInt); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   arr.sort((x,y) => x - y); |   arr.sort((x, y) => x - y); | ||||||
| 
 | 
 | ||||||
|   let pset = newPset(); |   let pset = newPset(); | ||||||
|   pset.setPrefixes(arr, arr.length); |   pset.setPrefixes(arr, arr.length); | ||||||
|  | @ -160,7 +160,7 @@ function testLoadSaveLargeSet() { | ||||||
|   checkContents(pset, arr); |   checkContents(pset, arr); | ||||||
| 
 | 
 | ||||||
|   // Now try to save, restore, and redo the lookups
 |   // Now try to save, restore, and redo the lookups
 | ||||||
|   var file = dirSvc.get('ProfLD', Ci.nsIFile); |   var file = dirSvc.get("ProfLD", Ci.nsIFile); | ||||||
|   file.append("testLarge.pset"); |   file.append("testLarge.pset"); | ||||||
| 
 | 
 | ||||||
|   pset.storeToFile(file); |   pset.storeToFile(file); | ||||||
|  | @ -205,7 +205,7 @@ function testLoadSaveNoDelta() { | ||||||
| 
 | 
 | ||||||
|   doExpectedLookups(pset, arr, 1); |   doExpectedLookups(pset, arr, 1); | ||||||
| 
 | 
 | ||||||
|   var file = dirSvc.get('ProfLD', Ci.nsIFile); |   var file = dirSvc.get("ProfLD", Ci.nsIFile); | ||||||
|   file.append("testNoDelta.pset"); |   file.append("testNoDelta.pset"); | ||||||
| 
 | 
 | ||||||
|   pset.storeToFile(file); |   pset.storeToFile(file); | ||||||
|  |  | ||||||
|  | @ -1,5 +1,4 @@ | ||||||
| function doTest(updates, assertions, expectError) | function doTest(updates, assertions, expectError) { | ||||||
| { |  | ||||||
|   if (expectError) { |   if (expectError) { | ||||||
|     doUpdateTest(updates, assertions, updateError, runNextTest); |     doUpdateTest(updates, assertions, updateError, runNextTest); | ||||||
|   } else { |   } else { | ||||||
|  | @ -16,13 +15,13 @@ function testFillDb() { | ||||||
|   update += "i:test-phish-simple\n"; |   update += "i:test-phish-simple\n"; | ||||||
| 
 | 
 | ||||||
|   var update1 = buildBareUpdate( |   var update1 = buildBareUpdate( | ||||||
|     [{ "chunkNum" : 1, |     [{ "chunkNum": 1, | ||||||
|        "urls" : add1Urls }]); |        "urls": add1Urls }]); | ||||||
|   update += "u:data:," + encodeURIComponent(update1) + "\n"; |   update += "u:data:," + encodeURIComponent(update1) + "\n"; | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1", |     "tableData": "test-phish-simple;a:1", | ||||||
|     "urlsExist" : add1Urls |     "urlsExist": add1Urls | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([update], assertions, false); |   doTest([update], assertions, false); | ||||||
|  | @ -37,23 +36,23 @@ function testSimpleForward() { | ||||||
|   update += "i:test-phish-simple\n"; |   update += "i:test-phish-simple\n"; | ||||||
| 
 | 
 | ||||||
|   var update1 = buildBareUpdate( |   var update1 = buildBareUpdate( | ||||||
|     [{ "chunkNum" : 1, |     [{ "chunkNum": 1, | ||||||
|        "urls" : add1Urls }]); |        "urls": add1Urls }]); | ||||||
|   update += "u:data:," + encodeURIComponent(update1) + "\n"; |   update += "u:data:," + encodeURIComponent(update1) + "\n"; | ||||||
| 
 | 
 | ||||||
|   var update2 = buildBareUpdate( |   var update2 = buildBareUpdate( | ||||||
|     [{ "chunkNum" : 2, |     [{ "chunkNum": 2, | ||||||
|        "urls" : add2Urls }]); |        "urls": add2Urls }]); | ||||||
|   update += "u:data:," + encodeURIComponent(update2) + "\n"; |   update += "u:data:," + encodeURIComponent(update2) + "\n"; | ||||||
| 
 | 
 | ||||||
|   var update3 = buildBareUpdate( |   var update3 = buildBareUpdate( | ||||||
|     [{ "chunkNum" : 3, |     [{ "chunkNum": 3, | ||||||
|        "urls" : add3Urls }]); |        "urls": add3Urls }]); | ||||||
|   update += "u:data:," + encodeURIComponent(update3) + "\n"; |   update += "u:data:," + encodeURIComponent(update3) + "\n"; | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1-3", |     "tableData": "test-phish-simple;a:1-3", | ||||||
|     "urlsExist" : add1Urls.concat(add2Urls).concat(add3Urls) |     "urlsExist": add1Urls.concat(add2Urls).concat(add3Urls) | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([update], assertions, false); |   doTest([update], assertions, false); | ||||||
|  | @ -69,23 +68,23 @@ function testNestedForward() { | ||||||
|   update += "i:test-phish-simple\n"; |   update += "i:test-phish-simple\n"; | ||||||
| 
 | 
 | ||||||
|   var update1 = buildBareUpdate( |   var update1 = buildBareUpdate( | ||||||
|     [{ "chunkNum" : 1, |     [{ "chunkNum": 1, | ||||||
|        "urls" : add1Urls }]); |        "urls": add1Urls }]); | ||||||
|   update += "u:data:," + encodeURIComponent(update1) + "\n"; |   update += "u:data:," + encodeURIComponent(update1) + "\n"; | ||||||
| 
 | 
 | ||||||
|   var update2 = buildBareUpdate( |   var update2 = buildBareUpdate( | ||||||
|     [{ "chunkNum" : 2 }]); |     [{ "chunkNum": 2 }]); | ||||||
|   var update3 = buildBareUpdate( |   var update3 = buildBareUpdate( | ||||||
|     [{ "chunkNum" : 3, |     [{ "chunkNum": 3, | ||||||
|        "urls" : add1Urls }]); |        "urls": add1Urls }]); | ||||||
| 
 | 
 | ||||||
|   update2 += "u:data:," + encodeURIComponent(update3) + "\n"; |   update2 += "u:data:," + encodeURIComponent(update3) + "\n"; | ||||||
| 
 | 
 | ||||||
|   update += "u:data:," + encodeURIComponent(update2) + "\n"; |   update += "u:data:," + encodeURIComponent(update2) + "\n"; | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "", |     "tableData": "", | ||||||
|     "urlsDontExist" : add1Urls.concat(add2Urls) |     "urlsDontExist": add1Urls.concat(add2Urls) | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([update], assertions, true); |   doTest([update], assertions, true); | ||||||
|  | @ -96,14 +95,14 @@ function testInvalidUrlForward() { | ||||||
|   var add1Urls = [ "foo-invalid.com/a", "bar-invalid.com/c" ]; |   var add1Urls = [ "foo-invalid.com/a", "bar-invalid.com/c" ]; | ||||||
| 
 | 
 | ||||||
|   var update = buildPhishingUpdate( |   var update = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 1, |     [{ "chunkNum": 1, | ||||||
|        "urls" : add1Urls }]); |        "urls": add1Urls }]); | ||||||
|   update += "u:asdf://blah/blah\n";  // invalid URL scheme
 |   update += "u:asdf://blah/blah\n";  // invalid URL scheme
 | ||||||
| 
 | 
 | ||||||
|   // add1Urls is present, but that is an artifact of the way we do the test.
 |   // add1Urls is present, but that is an artifact of the way we do the test.
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1", |     "tableData": "test-phish-simple;a:1", | ||||||
|     "urlsExist" : add1Urls |     "urlsExist": add1Urls | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([update], assertions, true); |   doTest([update], assertions, true); | ||||||
|  | @ -114,14 +113,14 @@ function testErrorUrlForward() { | ||||||
|   var add1Urls = [ "foo-forward.com/a", "bar-forward.com/c" ]; |   var add1Urls = [ "foo-forward.com/a", "bar-forward.com/c" ]; | ||||||
| 
 | 
 | ||||||
|   var update = buildPhishingUpdate( |   var update = buildPhishingUpdate( | ||||||
|     [{ "chunkNum" : 1, |     [{ "chunkNum": 1, | ||||||
|        "urls" : add1Urls }]); |        "urls": add1Urls }]); | ||||||
|   update += "u:http://test.invalid/asdf/asdf\n";  // invalid URL scheme
 |   update += "u:http://test.invalid/asdf/asdf\n";  // invalid URL scheme
 | ||||||
| 
 | 
 | ||||||
|   // add1Urls is present, but that is an artifact of the way we do the test.
 |   // add1Urls is present, but that is an artifact of the way we do the test.
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-phish-simple;a:1", |     "tableData": "test-phish-simple;a:1", | ||||||
|     "urlsExist" : add1Urls |     "urlsExist": add1Urls | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([update], assertions, true); |   doTest([update], assertions, true); | ||||||
|  | @ -138,40 +137,40 @@ function testMultipleTables() { | ||||||
|   update += "i:test-phish-simple\n"; |   update += "i:test-phish-simple\n"; | ||||||
| 
 | 
 | ||||||
|   var update1 = buildBareUpdate( |   var update1 = buildBareUpdate( | ||||||
|     [{ "chunkNum" : 1, |     [{ "chunkNum": 1, | ||||||
|        "urls" : add1Urls }]); |        "urls": add1Urls }]); | ||||||
|   update += "u:data:," + encodeURIComponent(update1) + "\n"; |   update += "u:data:," + encodeURIComponent(update1) + "\n"; | ||||||
| 
 | 
 | ||||||
|   var update2 = buildBareUpdate( |   var update2 = buildBareUpdate( | ||||||
|     [{ "chunkNum" : 2, |     [{ "chunkNum": 2, | ||||||
|        "urls" : add2Urls }]); |        "urls": add2Urls }]); | ||||||
|   update += "u:data:," + encodeURIComponent(update2) + "\n"; |   update += "u:data:," + encodeURIComponent(update2) + "\n"; | ||||||
| 
 | 
 | ||||||
|   update += "i:test-malware-simple\n"; |   update += "i:test-malware-simple\n"; | ||||||
| 
 | 
 | ||||||
|   var update3 = buildBareUpdate( |   var update3 = buildBareUpdate( | ||||||
|     [{ "chunkNum" : 3, |     [{ "chunkNum": 3, | ||||||
|        "urls" : add3Urls }]); |        "urls": add3Urls }]); | ||||||
|   update += "u:data:," + encodeURIComponent(update3) + "\n"; |   update += "u:data:," + encodeURIComponent(update3) + "\n"; | ||||||
| 
 | 
 | ||||||
|   update += "i:test-unwanted-simple\n"; |   update += "i:test-unwanted-simple\n"; | ||||||
|   var update4 = buildBareUpdate( |   var update4 = buildBareUpdate( | ||||||
|     [{ "chunkNum" : 4, |     [{ "chunkNum": 4, | ||||||
|        "urls" : add4Urls }]); |        "urls": add4Urls }]); | ||||||
|   update += "u:data:," + encodeURIComponent(update4) + "\n"; |   update += "u:data:," + encodeURIComponent(update4) + "\n"; | ||||||
| 
 | 
 | ||||||
|   update += "i:test-block-simple\n"; |   update += "i:test-block-simple\n"; | ||||||
|   var update6 = buildBareUpdate( |   var update6 = buildBareUpdate( | ||||||
|     [{ "chunkNum" : 6, |     [{ "chunkNum": 6, | ||||||
|        "urls" : add6Urls }]); |        "urls": add6Urls }]); | ||||||
|   update += "u:data:," + encodeURIComponent(update6) + "\n"; |   update += "u:data:," + encodeURIComponent(update6) + "\n"; | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-block-simple;a:6\ntest-malware-simple;a:3\ntest-phish-simple;a:1-2\ntest-unwanted-simple;a:4", |     "tableData": "test-block-simple;a:6\ntest-malware-simple;a:3\ntest-phish-simple;a:1-2\ntest-unwanted-simple;a:4", | ||||||
|     "urlsExist" : add1Urls.concat(add2Urls), |     "urlsExist": add1Urls.concat(add2Urls), | ||||||
|     "malwareUrlsExist" : add3Urls, |     "malwareUrlsExist": add3Urls, | ||||||
|     "unwantedUrlsExist" : add4Urls, |     "unwantedUrlsExist": add4Urls, | ||||||
|     "blockedUrlsExist" : add6Urls |     "blockedUrlsExist": add6Urls | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   doTest([update], assertions, false); |   doTest([update], assertions, false); | ||||||
|  | @ -184,25 +183,25 @@ function testUrlInMultipleTables() { | ||||||
|   update += "i:test-phish-simple\n"; |   update += "i:test-phish-simple\n"; | ||||||
| 
 | 
 | ||||||
|   var update1 = buildBareUpdate( |   var update1 = buildBareUpdate( | ||||||
|     [{ "chunkNum" : 1, |     [{ "chunkNum": 1, | ||||||
|        "urls" : add1Urls }]); |        "urls": add1Urls }]); | ||||||
|   update += "u:data:," + encodeURIComponent(update1) + "\n"; |   update += "u:data:," + encodeURIComponent(update1) + "\n"; | ||||||
| 
 | 
 | ||||||
|   update += "i:test-malware-simple\n"; |   update += "i:test-malware-simple\n"; | ||||||
|   var update2 = buildBareUpdate( |   var update2 = buildBareUpdate( | ||||||
|     [{ "chunkNum" : 2, |     [{ "chunkNum": 2, | ||||||
|        "urls" : add1Urls }]); |        "urls": add1Urls }]); | ||||||
|   update += "u:data:," + encodeURIComponent(update2) + "\n"; |   update += "u:data:," + encodeURIComponent(update2) + "\n"; | ||||||
| 
 | 
 | ||||||
|   update += "i:test-unwanted-simple\n"; |   update += "i:test-unwanted-simple\n"; | ||||||
|   var update3 = buildBareUpdate( |   var update3 = buildBareUpdate( | ||||||
|     [{ "chunkNum" : 3, |     [{ "chunkNum": 3, | ||||||
|        "urls" : add1Urls }]); |        "urls": add1Urls }]); | ||||||
|   update += "u:data:," + encodeURIComponent(update3) + "\n"; |   update += "u:data:," + encodeURIComponent(update3) + "\n"; | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "test-malware-simple;a:2\ntest-phish-simple;a:1\ntest-unwanted-simple;a:3", |     "tableData": "test-malware-simple;a:2\ntest-phish-simple;a:1\ntest-unwanted-simple;a:3", | ||||||
|     "urlExistInMultipleTables" : { url: add1Urls, |     "urlExistInMultipleTables": { url: add1Urls, | ||||||
|                                    tables: "test-malware-simple,test-phish-simple,test-unwanted-simple" } |                                    tables: "test-malware-simple,test-phish-simple,test-unwanted-simple" } | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|  | @ -215,8 +214,7 @@ function Observer(callback) { | ||||||
| 
 | 
 | ||||||
| Observer.prototype = | Observer.prototype = | ||||||
| { | { | ||||||
| QueryInterface: function(iid) | QueryInterface(iid) { | ||||||
| { |  | ||||||
|   if (!iid.equals(Ci.nsISupports) && |   if (!iid.equals(Ci.nsISupports) && | ||||||
|       !iid.equals(Ci.nsIObserver)) { |       !iid.equals(Ci.nsIObserver)) { | ||||||
|     throw Cr.NS_ERROR_NO_INTERFACE; |     throw Cr.NS_ERROR_NO_INTERFACE; | ||||||
|  | @ -233,8 +231,8 @@ function testReset() { | ||||||
|   var mozAddUrls = [ "moz-reset.com/a" ]; |   var mozAddUrls = [ "moz-reset.com/a" ]; | ||||||
|   var mozUpdate = buildMozPhishingUpdate( |   var mozUpdate = buildMozPhishingUpdate( | ||||||
|     [ |     [ | ||||||
|       { "chunkNum" : 1, |       { "chunkNum": 1, | ||||||
|         "urls" : mozAddUrls |         "urls": mozAddUrls | ||||||
|       }]); |       }]); | ||||||
| 
 | 
 | ||||||
|   var dataUpdate = "data:," + encodeURIComponent(mozUpdate); |   var dataUpdate = "data:," + encodeURIComponent(mozUpdate); | ||||||
|  | @ -245,8 +243,8 @@ function testReset() { | ||||||
|   var addUrls1 = [ "foo-reset.com/a", "foo-reset.com/b" ]; |   var addUrls1 = [ "foo-reset.com/a", "foo-reset.com/b" ]; | ||||||
|   var update1 = buildPhishingUpdate( |   var update1 = buildPhishingUpdate( | ||||||
|     [ |     [ | ||||||
|       { "chunkNum" : 1, |       { "chunkNum": 1, | ||||||
|         "urls" : addUrls1 |         "urls": addUrls1 | ||||||
|       }]); |       }]); | ||||||
| 
 | 
 | ||||||
|   var update2 = "n:1000\nr:pleasereset\n"; |   var update2 = "n:1000\nr:pleasereset\n"; | ||||||
|  | @ -254,16 +252,16 @@ function testReset() { | ||||||
|   var addUrls3 = [ "bar-reset.com/a", "bar-reset.com/b" ]; |   var addUrls3 = [ "bar-reset.com/a", "bar-reset.com/b" ]; | ||||||
|   var update3 = buildPhishingUpdate( |   var update3 = buildPhishingUpdate( | ||||||
|     [ |     [ | ||||||
|       { "chunkNum" : 3, |       { "chunkNum": 3, | ||||||
|         "urls" : addUrls3 |         "urls": addUrls3 | ||||||
|       }]); |       }]); | ||||||
| 
 | 
 | ||||||
|   var assertions = { |   var assertions = { | ||||||
|     "tableData" : "moz-phish-simple;a:1\ntest-phish-simple;a:3", // tables that should still be there.
 |     "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
 |     "mozPhishingUrlsExist": mozAddUrls,                         // mozAddUrls added prior to the reset
 | ||||||
|                                                                  // but it should still exist after reset.
 |                                                                  // but it should still exist after reset.
 | ||||||
|     "urlsExist" : addUrls3,                                      // addUrls3 added after the reset.
 |     "urlsExist": addUrls3,                                      // addUrls3 added after the reset.
 | ||||||
|     "urlsDontExist" : addUrls1                                   // addUrls1 added prior to the reset
 |     "urlsDontExist": addUrls1                                   // addUrls1 added prior to the reset
 | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   // Use these update responses in order. The update request only
 |   // Use these update responses in order. The update request only
 | ||||||
|  | @ -272,8 +270,7 @@ function testReset() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| function run_test() | function run_test() { | ||||||
| { |  | ||||||
|   runTests([ |   runTests([ | ||||||
|     testSimpleForward, |     testSimpleForward, | ||||||
|     testNestedForward, |     testNestedForward, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Dan Banner
						Dan Banner