From 436f06fda43d5a650a32e5d14ac1e2cb6b8cd851 Mon Sep 17 00:00:00 2001 From: Dan Banner Date: Wed, 2 Aug 2017 16:12:07 +0100 Subject: [PATCH] Bug 1386684 - Enable ESLint for toolkit/components/url-classifier (automatic fixes). r=hchang MozReview-Commit-ID: F0Z8dRaYOku --HG-- extra : rebase_source : 3ebc9ab6ea9f1741d8a986c9217575644411e2a1 --- .eslintignore | 3 - .../url-classifier/SafeBrowsing.jsm | 36 +- .../nsUrlClassifierHashCompleter.js | 60 ++-- .../url-classifier/nsUrlClassifierLib.js | 2 +- .../nsUrlClassifierListManager.js | 17 +- .../tests/UrlClassifierTestUtils.jsm | 4 +- .../tests/browser/classifierHelper.js | 25 +- .../tests/browser/classifierTester.js | 32 +- .../mochitest/allowlistAnnotatedFrame.html | 10 +- .../mochitest/classifiedAnnotatedFrame.html | 10 +- .../tests/mochitest/classifierCommon.js | 21 +- .../tests/mochitest/classifierFrame.html | 2 +- .../tests/mochitest/classifierHelper.js | 10 +- .../tests/mochitest/cleanWorker.js | 2 +- .../url-classifier/tests/mochitest/dnt.html | 2 +- .../tests/mochitest/test_advisory_link.html | 4 +- .../test_allowlisted_annotations.html | 6 +- .../tests/mochitest/test_bug1254766.html | 27 +- .../tests/mochitest/test_cachemiss.html | 14 +- .../test_classified_annotations.html | 2 +- .../tests/mochitest/test_classifier.html | 14 +- .../test_classifier_changetablepref.html | 12 +- .../mochitest/test_classifier_match.html | 10 +- .../mochitest/test_classifier_worker.html | 13 +- .../tests/mochitest/test_classify_ping.html | 6 +- .../tests/mochitest/test_donottrack.html | 26 +- .../tests/mochitest/test_gethash.html | 2 +- ...st_privatebrowsing_trackingprotection.html | 6 +- .../tests/mochitest/test_reporturl.html | 24 +- .../test_trackingprotection_bug1157081.html | 14 +- .../test_trackingprotection_bug1312515.html | 12 +- .../test_trackingprotection_whitelist.html | 10 +- .../url-classifier/tests/mochitest/tracker.js | 2 +- .../tests/mochitest/trackingRequest.js | 3 +- .../tests/unit/head_urlclassifier.js | 120 +++---- .../url-classifier/tests/unit/test_addsub.js | 318 +++++++++--------- .../unit/test_bug1274685_unowned_list.js | 4 +- .../tests/unit/test_dbservice.js | 20 +- .../tests/unit/test_hashcompleter.js | 10 +- .../tests/unit/test_listmanager.js | 10 +- .../url-classifier/tests/unit/test_partial.js | 297 ++++++++-------- .../url-classifier/tests/unit/test_pref.js | 2 +- .../tests/unit/test_prefixset.js | 22 +- .../tests/unit/test_safebrowsing_protobuf.js | 2 +- .../tests/unit/test_streamupdater.js | 129 ++++--- .../tests/unit/test_threat_type_conversion.js | 2 +- 46 files changed, 658 insertions(+), 721 deletions(-) diff --git a/.eslintignore b/.eslintignore index b9a1f9418d14..99d2db5d5dba 100644 --- a/.eslintignore +++ b/.eslintignore @@ -340,9 +340,6 @@ toolkit/components/workerloader/tests/moduleF-syntax-error.js # Tests old non-star function generators toolkit/modules/tests/xpcshell/test_task.js -# Not yet updated -toolkit/components/url-classifier/** - # External code: toolkit/components/microformats/test/** toolkit/components/microformats/microformat-shiv.js diff --git a/toolkit/components/url-classifier/SafeBrowsing.jsm b/toolkit/components/url-classifier/SafeBrowsing.jsm index 4689c8d7b1f4..16444e5901c3 100644 --- a/toolkit/components/url-classifier/SafeBrowsing.jsm +++ b/toolkit/components/url-classifier/SafeBrowsing.jsm @@ -55,7 +55,7 @@ const tablePreferences = [ this.SafeBrowsing = { - init: function() { + init() { if (this.initialized) { log("Already initialized"); return; @@ -75,7 +75,7 @@ this.SafeBrowsing = { log("init() finished"); }, - registerTableWithURLs: function(listname) { + registerTableWithURLs(listname) { let listManager = Cc["@mozilla.org/url-classifier/listmanager;1"]. getService(Ci.nsIUrlListManager); @@ -96,7 +96,7 @@ this.SafeBrowsing = { listManager.registerTable(listname, providerName, provider.updateURL, provider.gethashURL); }, - registerTables: function() { + registerTables() { for (let i = 0; i < this.phishingLists.length; ++i) { this.registerTableWithURLs(this.phishingLists[i]); } @@ -151,7 +151,7 @@ this.SafeBrowsing = { reportURL: null, - getReportURL: function(kind, info) { + getReportURL(kind, info) { let pref; switch (kind) { case "Phish": @@ -187,7 +187,7 @@ this.SafeBrowsing = { return reportUrl; }, - observe: function(aSubject, aTopic, aData) { + observe(aSubject, aTopic, aData) { // skip nextupdatetime and lastupdatetime if (aData.indexOf("lastupdatetime") >= 0 || aData.indexOf("nextupdatetime") >= 0) { return; @@ -201,7 +201,7 @@ this.SafeBrowsing = { this.readPrefs(); }, - readPrefs: function() { + readPrefs() { loggingEnabled = Services.prefs.getBoolPref(PREF_DEBUG_ENABLED); log("reading prefs"); @@ -249,10 +249,10 @@ this.SafeBrowsing = { }, - updateProviderURLs: function() { + updateProviderURLs() { try { var clientID = Services.prefs.getCharPref("browser.safebrowsing.id"); - } catch(e) { + } catch (e) { clientID = Services.appinfo.name; } @@ -295,8 +295,8 @@ this.SafeBrowsing = { let googleKey = Services.urlFormatter.formatURL("%GOOGLE_API_KEY%").trim(); if ((provider == "google" || provider == "google4") && (!googleKey || googleKey == "no-google-api-key")) { - updateURL= ""; - gethashURL= ""; + updateURL = ""; + gethashURL = ""; } log("Provider: " + provider + " updateURL=" + updateURL); @@ -318,7 +318,7 @@ this.SafeBrowsing = { }, this); }, - controlUpdateChecking: function() { + controlUpdateChecking() { log("phishingEnabled:", this.phishingEnabled, "malwareEnabled:", this.malwareEnabled, "trackingEnabled:", this.trackingEnabled, "blockedEnabled:", this.blockedEnabled, "trackingAnnotations", @@ -395,7 +395,7 @@ this.SafeBrowsing = { }, - addMozEntries: function() { + addMozEntries() { // Add test entries to the DB. // XXX bug 779008 - this could be done by DB itself? const phishURL = "itisatrap.org/firefox/its-a-trap.html"; @@ -414,7 +414,7 @@ this.SafeBrowsing = { malwareURL + "\n"; update += "n:1000\ni:test-phish-simple\nad:1\n" + "a:1:32:" + phishURL.length + "\n" + - phishURL + "\n"; + phishURL + "\n"; update += "n:1000\ni:test-unwanted-simple\nad:1\n" + "a:1:32:" + unwantedURL.length + "\n" + unwantedURL + "\n"; @@ -440,14 +440,14 @@ this.SafeBrowsing = { // nsIUrlClassifierUpdateObserver let dummyListener = { - updateUrlRequested: function() { }, - streamFinished: function() { }, + updateUrlRequested() { }, + streamFinished() { }, // We notify observers when we're done in order to be able to make perf // test results more consistent - updateError: function() { + updateError() { Services.obs.notifyObservers(db, "mozentries-update-finished", "error"); }, - updateSuccess: function() { + updateSuccess() { Services.obs.notifyObservers(db, "mozentries-update-finished", "success"); } }; @@ -459,7 +459,7 @@ this.SafeBrowsing = { db.updateStream(update); db.finishStream(); db.finishUpdate(); - } catch(ex) { + } catch (ex) { // beginUpdate will throw harmlessly if there's an existing update in progress, ignore failures. log("addMozEntries failed!", ex); Services.obs.notifyObservers(db, "mozentries-update-finished", "exception"); diff --git a/toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js b/toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js index eac72dadabd3..025071f0a200 100644 --- a/toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js +++ b/toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js @@ -21,13 +21,13 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/NetUtil.jsm"); -XPCOMUtils.defineLazyServiceGetter(this, 'gDbService', - '@mozilla.org/url-classifier/dbservice;1', - 'nsIUrlClassifierDBService'); +XPCOMUtils.defineLazyServiceGetter(this, "gDbService", + "@mozilla.org/url-classifier/dbservice;1", + "nsIUrlClassifierDBService"); -XPCOMUtils.defineLazyServiceGetter(this, 'gUrlUtil', - '@mozilla.org/url-classifier/utils;1', - 'nsIUrlClassifierUtils'); +XPCOMUtils.defineLazyServiceGetter(this, "gUrlUtil", + "@mozilla.org/url-classifier/utils;1", + "nsIUrlClassifierUtils"); let loggingEnabled = false; @@ -147,7 +147,7 @@ function httpStatusToBucket(httpStatus) { break; default: statusBucket = 15; - }; + } return statusBucket; } @@ -160,9 +160,9 @@ function FullHashMatch(table, hash, duration) { FullHashMatch.prototype = { QueryInterface: XPCOMUtils.generateQI([Ci.nsIFullHashMatch]), - tableName : null, - fullHash : null, - cacheDuration : null, + tableName: null, + fullHash: null, + cacheDuration: null, }; function HashCompleter() { @@ -240,7 +240,7 @@ HashCompleter.prototype = { // This is called after several calls to |complete|, or after the // currentRequest has finished. It starts off the HTTP request by making a // |begin| call to the HashCompleterRequest. - run: function() { + run() { // Clear everything on shutdown if (this._shuttingDown) { this._currentRequest = null; @@ -273,13 +273,13 @@ HashCompleter.prototype = { // Pass the server response status to the RequestBackoff for the given // gethashUrl and fetch the next pending request, if there is one. - finishRequest: function(url, aStatus) { + finishRequest(url, aStatus) { this._backoffs[url].noteServerResponse(aStatus); Services.tm.dispatchToMainThread(this); }, // Returns true if we can make a request from the given url, false otherwise. - canMakeRequest: function(aGethashUrl) { + canMakeRequest(aGethashUrl) { return this._backoffs[aGethashUrl].canMakeRequest() && Date.now() >= this._nextGethashTimeMs[aGethashUrl]; }, @@ -287,7 +287,7 @@ HashCompleter.prototype = { // 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, // and finishRequest must be called once the response is received. - noteRequest: function(aGethashUrl) { + noteRequest(aGethashUrl) { return this._backoffs[aGethashUrl].noteRequest(); }, @@ -339,17 +339,17 @@ HashCompleterRequest.prototype = { partialHash: aPartialHash, callback: aCallback, tableName: aTableName, - response: { matches:[] }, + response: { matches: [] }, }); if (aTableName) { - let isTableNameV4 = aTableName.endsWith('-proto'); + let isTableNameV4 = aTableName.endsWith("-proto"); if (0 === this.tableNames.size) { // Decide if this request is v4 by the first added partial hash. this.isV4 = isTableNameV4; } else if (this.isV4 !== isTableNameV4) { log('ERROR: Cannot mix "proto" tables with other types within ' + - 'the same gethash URL.'); + "the same gethash URL."); } this.tableNames.set(aTableName); @@ -403,8 +403,7 @@ HashCompleterRequest.prototype = { // Notify the RequestBackoff if opening the channel succeeded. At this // point, finishRequest must be called. this._completer.noteRequest(this.gethashUrl); - } - catch (err) { + } catch (err) { this.notifyFailure(err); throw err; } @@ -490,8 +489,8 @@ HashCompleterRequest.prototype = { this._requests.forEach(r => prefixSet.add(btoa(r.partialHash))); let prefixArray = Array.from(prefixSet).sort(); - log("Build v4 gethash request with " + JSON.stringify(tableNameArray) + ', ' - + JSON.stringify(stateArray) + ', ' + log("Build v4 gethash request with " + JSON.stringify(tableNameArray) + ", " + + JSON.stringify(stateArray) + ", " + JSON.stringify(prefixArray)); return gUrlUtil.makeFindFullHashRequestV4(tableNameArray, @@ -522,7 +521,7 @@ HashCompleterRequest.prototype = { body = PARTIAL_LENGTH + ":" + (PARTIAL_LENGTH * prefixes.length) + "\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; }, @@ -563,9 +562,9 @@ HashCompleterRequest.prototype = { let callback = { // onCompleteHashFound will be called for each fullhash found in // FullHashResponse. - onCompleteHashFound : (aCompleteHash, - aTableNames, - aPerHashCacheDuration) => { + onCompleteHashFound: (aCompleteHash, + aTableNames, + aPerHashCacheDuration) => { log("V4 fullhash response complete hash found callback: " + JSON.stringify(aCompleteHash) + ", " + aTableNames + ", CacheDuration(" + aPerHashCacheDuration + ")"); @@ -592,8 +591,8 @@ HashCompleterRequest.prototype = { // onResponseParsed will be called no matter if there is match in // FullHashResponse, the callback is mainly used to pass negative cache // duration and minimum wait duration. - onResponseParsed : (aMinWaitDuration, - aNegCacheDuration) => { + onResponseParsed: (aMinWaitDuration, + aNegCacheDuration) => { log("V4 fullhash response parsed callback: " + "MinWaitDuration(" + aMinWaitDuration + "), " + "NegativeCacheDuration(" + aNegCacheDuration + ")"); @@ -644,7 +643,7 @@ HashCompleterRequest.prototype = { let addChunk = parseInt(entries[1]); 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 || dataLength == 0 || dataLength > body.length - (newlineIndex + 1)) { @@ -761,7 +760,7 @@ HashCompleterRequest.prototype = { } } 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"). add(this.telemetryProvider, httpStatusToBucket(httpStatus)); @@ -779,8 +778,7 @@ HashCompleterRequest.prototype = { if (success) { try { this.handleResponse(); - } - catch (err) { + } catch (err) { log(err.stack); aStatusCode = err.value; success = false; diff --git a/toolkit/components/url-classifier/nsUrlClassifierLib.js b/toolkit/components/url-classifier/nsUrlClassifierLib.js index c3e8133ba19f..e2457d85474c 100644 --- a/toolkit/components/url-classifier/nsUrlClassifierLib.js +++ b/toolkit/components/url-classifier/nsUrlClassifierLib.js @@ -59,7 +59,7 @@ this.BindToObject = function BindToObject(fn, self, opt_args) { // back off for TIMEOUT_INCREMENT minutes. If we get another error // immediately after we restart, we double the timeout and add // TIMEOUT_INCREMENT minutes, etc. -// +// // This is similar to the logic used by the search suggestion service. // HTTP responses that count as an error. We also include any 5xx response diff --git a/toolkit/components/url-classifier/nsUrlClassifierListManager.js b/toolkit/components/url-classifier/nsUrlClassifierListManager.js index 3b85d51862b4..e0c32bd18c30 100644 --- a/toolkit/components/url-classifier/nsUrlClassifierListManager.js +++ b/toolkit/components/url-classifier/nsUrlClassifierListManager.js @@ -212,9 +212,8 @@ PROT_ListManager.prototype.requireTableUpdates = function() { /** * Set timer to check update after delay */ -PROT_ListManager.prototype.setUpdateCheckTimer = function (updateUrl, - delay) -{ +PROT_ListManager.prototype.setUpdateCheckTimer = function(updateUrl, + delay) { this.updateCheckers_[updateUrl] = Cc["@mozilla.org/timer;1"] .createInstance(Ci.nsITimer); this.updateCheckers_[updateUrl].initWithCallback(() => { @@ -225,8 +224,7 @@ PROT_ListManager.prototype.setUpdateCheckTimer = function (updateUrl, /** * Acts as a nsIUrlClassifierCallback for getTables. */ -PROT_ListManager.prototype.kickoffUpdate_ = function (onDiskTableData) -{ +PROT_ListManager.prototype.kickoffUpdate_ = function(onDiskTableData) { this.startingUpdate_ = false; var initialUpdateDelay = 3000; // 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.) // We use the table name 'goog-*-proto' and an additional provider "google4" // to describe the v4 settings. - let isCurTableProto = tableName.endsWith('-proto'); + let isCurTableProto = tableName.endsWith("-proto"); if (!onceThru) { useProtobuf = isCurTableProto; onceThru = true; } else if (useProtobuf !== isCurTableProto) { 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]) { @@ -648,13 +646,12 @@ function Init() { modScope.Init = function() {}; } -function RegistrationData() -{ +function RegistrationData() { } RegistrationData.prototype = { classID: Components.ID("{ca168834-cc00-48f9-b83c-fd018e58cae3}"), _xpcom_factory: { - createInstance: function(outer, iid) { + createInstance(outer, iid) { if (outer != null) throw Components.results.NS_ERROR_NO_AGGREGATION; Init(); diff --git a/toolkit/components/url-classifier/tests/UrlClassifierTestUtils.jsm b/toolkit/components/url-classifier/tests/UrlClassifierTestUtils.jsm index 6cc32081ea48..478299fe9244 100644 --- a/toolkit/components/url-classifier/tests/UrlClassifierTestUtils.jsm +++ b/toolkit/components/url-classifier/tests/UrlClassifierTestUtils.jsm @@ -97,7 +97,7 @@ this.UrlClassifierTestUtils = { updateUrlRequested: url => { }, streamFinished: status => { }, updateError: errorCode => { - reject('Got updateError when updating ' + table.name); + reject("Got updateError when updating " + table.name); }, updateSuccess: requestedTimeout => { resolve(); @@ -111,7 +111,7 @@ this.UrlClassifierTestUtils = { dbService.finishStream(); dbService.finishUpdate(); } catch (e) { - reject('Failed to update with dbService: ' + table.name); + reject("Failed to update with dbService: " + table.name); } }); }, diff --git a/toolkit/components/url-classifier/tests/browser/classifierHelper.js b/toolkit/components/url-classifier/tests/browser/classifierHelper.js index 728157d4f2c9..62f9e76a48c8 100644 --- a/toolkit/components/url-classifier/tests/browser/classifierHelper.js +++ b/toolkit/components/url-classifier/tests/browser/classifierHelper.js @@ -17,9 +17,9 @@ if (typeof(classifierHelper) == "undefined") { const HASHLEN = 32; const PREFS = { - PROVIDER_LISTS : "browser.safebrowsing.provider.mozilla.lists", - DISALLOW_COMPLETIONS : "urlclassifier.disallow_completions", - PROVIDER_GETHASHURL : "browser.safebrowsing.provider.mozilla.gethashURL" + PROVIDER_LISTS: "browser.safebrowsing.provider.mozilla.lists", + DISALLOW_COMPLETIONS: "urlclassifier.disallow_completions", + PROVIDER_GETHASHURL: "browser.safebrowsing.provider.mozilla.gethashURL" }; classifierHelper._curAddChunkNum = 1; @@ -53,16 +53,14 @@ classifierHelper.waitForInit = function() { }, "mozentries-update-finished"); let listener = { - QueryInterface: function(iid) - { + QueryInterface(iid) { if (iid.equals(Ci.nsISupports) || iid.equals(Ci.nsIUrlClassifierUpdateObserver)) return this; throw Cr.NS_ERROR_NO_INTERFACE; }, - handleEvent: function(value) - { + handleEvent(value) { if (value === table) { resolve(); } @@ -146,20 +144,19 @@ classifierHelper._update = function(update) { try { await new Promise((resolve, reject) => { let listener = { - QueryInterface: function(iid) - { + QueryInterface(iid) { if (iid.equals(Ci.nsISupports) || iid.equals(Ci.nsIUrlClassifierUpdateObserver)) return this; throw Cr.NS_ERROR_NO_INTERFACE; }, - updateUrlRequested: function(url) { }, - streamFinished: function(status) { }, - updateError: function(errorCode) { + updateUrlRequested(url) { }, + streamFinished(status) { }, + updateError(errorCode) { reject(errorCode); }, - updateSuccess: function(requestedTimeout) { + updateSuccess(requestedTimeout) { resolve(); } }; @@ -170,7 +167,7 @@ classifierHelper._update = function(update) { dbService.finishUpdate(); }); success = true; - } catch(e) { + } catch (e) { // Wait 1 second before trying again. await new Promise(resolve => setTimeout(resolve, 1000)); } diff --git a/toolkit/components/url-classifier/tests/browser/classifierTester.js b/toolkit/components/url-classifier/tests/browser/classifierTester.js index 089224691e43..df1af3e673fb 100644 --- a/toolkit/components/url-classifier/tests/browser/classifierTester.js +++ b/toolkit/components/url-classifier/tests/browser/classifierTester.js @@ -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) { let DBs = []; @@ -69,7 +69,7 @@ var classifierTester = { Services.prefs.setBoolPref(classifierTester.ALLOW_CTA_PREF, true); }, - unsetPrefs: function () { + unsetPrefs() { for (let dbData of classifierTester.dbUrls) { Services.prefs.clearUserPref(dbData.pref); } @@ -184,8 +184,8 @@ var classifierTester = { // Returns null if this value should not be verified given the combination // of inputs - expectedPluginFallbackType: function (classification, flashSetting) { - switch(classification) { + expectedPluginFallbackType(classification, flashSetting) { + switch (classification) { case "unknown": if (flashSetting == classifierTester.ALWAYS_ACTIVATE_PREF_VALUE) { return null; @@ -208,8 +208,8 @@ var classifierTester = { // Returns null if this value should not be verified given the combination // of inputs - expectedActivated: function (classification, flashSetting) { - switch(classification) { + expectedActivated(classification, flashSetting) { + switch (classification) { case "unknown": return (flashSetting == classifierTester.ALWAYS_ACTIVATE_PREF_VALUE); case "allowed": @@ -222,8 +222,8 @@ var classifierTester = { // Returns null if this value should not be verified given the combination // of inputs - expectedHasRunningPlugin: function (classification, flashSetting) { - switch(classification) { + expectedHasRunningPlugin(classification, flashSetting) { + switch (classification) { case "unknown": return (flashSetting == classifierTester.ALWAYS_ACTIVATE_PREF_VALUE); case "allowed": @@ -236,12 +236,12 @@ var classifierTester = { // Returns null if this value should not be verified given the combination // of inputs - expectedPluginListed: function (classification, flashSetting) { + expectedPluginListed(classification, flashSetting) { 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; } - switch(classification) { + switch (classification) { case "unknown": case "allowed": return (flashSetting != classifierTester.NEVER_ACTIVATE_PREF_VALUE); @@ -251,7 +251,7 @@ var classifierTester = { throw new Error("Invalid classification or flash setting"); }, - buildTestCaseInNewTab: function (browser, testCase) { + buildTestCaseInNewTab(browser, testCase) { return (async function() { let iframeDomains = testCase.domains.slice(); let pageDomain = iframeDomains.shift(); @@ -265,7 +265,7 @@ var classifierTester = { let url = domain + classifierTester.URL_PATH + "?date=" + Date.now() + "rand=" + Math.random(); 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}) { let doc = content.document; for (let i = 0; i < depth; ++i) { @@ -281,9 +281,9 @@ var classifierTester = { })(); }, - getPluginInfo: function (browser, depth) { + getPluginInfo(browser, depth) { return ContentTask.spawn(browser, - {iframeId: classifierTester.IFRAME_ID, depth: depth}, + {iframeId: classifierTester.IFRAME_ID, depth}, async function({iframeId, depth}) { let doc = content.document; let win = content.window; @@ -307,7 +307,7 @@ var classifierTester = { }); }, - checkPluginInfo: function (pluginInfo, expectedClassification, flashSetting) { + checkPluginInfo(pluginInfo, expectedClassification, flashSetting) { is(pluginInfo.flashClassification, expectedClassification, "Page's classification should match expected"); diff --git a/toolkit/components/url-classifier/tests/mochitest/allowlistAnnotatedFrame.html b/toolkit/components/url-classifier/tests/mochitest/allowlistAnnotatedFrame.html index 9aae1b841552..f59d941f321f 100644 --- a/toolkit/components/url-classifier/tests/mochitest/allowlistAnnotatedFrame.html +++ b/toolkit/components/url-classifier/tests/mochitest/allowlistAnnotatedFrame.html @@ -88,21 +88,21 @@ v.addEventListener("error", function() { var newScript = document.createElement("script"); newScript.id = "badscript2"; 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); -/// Try loading from a tracking image URI (2) +// / Try loading from a tracking image URI (2) var newImage = document.createElement("img"); newImage.id = "badimage2"; 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); // Try loading from a tracking iframe URI (2) var newFrame = document.createElement("iframe"); newFrame.id = "badframe2"; 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); // Try doing an XHR against a tracking domain (bug 1216793) @@ -127,7 +127,7 @@ oReq.send(); // Fetch from a tracking domain 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"; loaded("fetch"); } else { diff --git a/toolkit/components/url-classifier/tests/mochitest/classifiedAnnotatedFrame.html b/toolkit/components/url-classifier/tests/mochitest/classifiedAnnotatedFrame.html index e8b42c4af574..6fe965b2f398 100644 --- a/toolkit/components/url-classifier/tests/mochitest/classifiedAnnotatedFrame.html +++ b/toolkit/components/url-classifier/tests/mochitest/classifiedAnnotatedFrame.html @@ -154,21 +154,21 @@ v.addEventListener("error", function() { var newScript = document.createElement("script"); newScript.id = "badscript2"; 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); -/// Try loading from a tracking image URI (2) +// Try loading from a tracking image URI (2) var newImage = document.createElement("img"); newImage.id = "badimage2"; 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); // Try loading from a tracking iframe URI (2) var newFrame = document.createElement("iframe"); newFrame.id = "badframe2"; 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); // Try doing an XHR against a tracking domain (bug 1216793) @@ -193,7 +193,7 @@ oReq.send(); // Fetch from a tracking domain 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"; loaded("fetch"); } else { diff --git a/toolkit/components/url-classifier/tests/mochitest/classifierCommon.js b/toolkit/components/url-classifier/tests/mochitest/classifierCommon.js index 3295a452ee0c..2f8b3d028626 100644 --- a/toolkit/components/url-classifier/tests/mochitest/classifierCommon.js +++ b/toolkit/components/url-classifier/tests/mochitest/classifierCommon.js @@ -16,20 +16,19 @@ function setTimeout(callback, delay) { function doUpdate(update) { let listener = { - QueryInterface: function(iid) - { + QueryInterface(iid) { if (iid.equals(Ci.nsISupports) || iid.equals(Ci.nsIUrlClassifierUpdateObserver)) return this; throw Cr.NS_ERROR_NO_INTERFACE; }, - updateUrlRequested: function(url) { }, - streamFinished: function(status) { }, - updateError: function(errorCode) { + updateUrlRequested(url) { }, + streamFinished(status) { }, + updateError(errorCode) { sendAsyncMessage("updateError", errorCode); }, - updateSuccess: function(requestedTimeout) { + updateSuccess(requestedTimeout) { sendAsyncMessage("updateSuccess"); } }; @@ -43,7 +42,7 @@ function doUpdate(update) { dbService.updateStream(update); dbService.finishStream(); dbService.finishUpdate(); - } catch(e) { + } catch (e) { // beginUpdate may fail if there's an existing update in progress // retry until success or testcase timeout. setTimeout(() => { doUpdate(update); }, 1000); @@ -54,7 +53,7 @@ function doReload() { try { dbService.reloadDatabase(); sendAsyncMessage("reloadSuccess"); - } catch(e) { + } catch (e) { setTimeout(() => { doReload(); }, 1000); } } @@ -84,16 +83,14 @@ function waitForInit() { iosvc.newURI(url), {}); let listener = { - QueryInterface: function(iid) - { + QueryInterface(iid) { if (iid.equals(Ci.nsISupports) || iid.equals(Ci.nsIUrlClassifierUpdateObserver)) return this; throw Cr.NS_ERROR_NO_INTERFACE; }, - handleEvent: function(value) - { + handleEvent(value) { if (value === table) { sendAsyncMessage("safeBrowsingInited"); } diff --git a/toolkit/components/url-classifier/tests/mochitest/classifierFrame.html b/toolkit/components/url-classifier/tests/mochitest/classifierFrame.html index c950ee784306..237c270b6165 100644 --- a/toolkit/components/url-classifier/tests/mochitest/classifierFrame.html +++ b/toolkit/components/url-classifier/tests/mochitest/classifierFrame.html @@ -33,7 +33,7 @@ function checkLoads() { } 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), "Timeout set from main script should not be considered as tracking"); let timer2 = getTrackerTimeout(); diff --git a/toolkit/components/url-classifier/tests/mochitest/classifierHelper.js b/toolkit/components/url-classifier/tests/mochitest/classifierHelper.js index 40988cbf65cc..80c2a64fdf64 100644 --- a/toolkit/components/url-classifier/tests/mochitest/classifierHelper.js +++ b/toolkit/components/url-classifier/tests/mochitest/classifierHelper.js @@ -8,9 +8,9 @@ var gScript = SpecialPowers.loadChromeScript(CLASSIFIER_COMMON_URL); const HASHLEN = 32; const PREFS = { - PROVIDER_LISTS : "browser.safebrowsing.provider.mozilla.lists", - DISALLOW_COMPLETIONS : "urlclassifier.disallow_completions", - PROVIDER_GETHASHURL : "browser.safebrowsing.provider.mozilla.gethashURL" + PROVIDER_LISTS: "browser.safebrowsing.provider.mozilla.lists", + DISALLOW_COMPLETIONS: "urlclassifier.disallow_completions", + PROVIDER_GETHASHURL: "browser.safebrowsing.provider.mozilla.gethashURL" }; classifierHelper._curAddChunkNum = 1; @@ -109,7 +109,7 @@ classifierHelper.resetDatabase = function() { classifierHelper.reloadDatabase = function() { return new Promise(function(resolve, reject) { gScript.addMessageListener("reloadSuccess", function handler() { - gScript.removeMessageListener('reloadSuccess', handler); + gScript.removeMessageListener("reloadSuccess", handler); resolve(); }); @@ -150,7 +150,7 @@ classifierHelper._updateError = function(errorCode) { }; classifierHelper._inited = function() { - classifierHelper._initsCB.forEach(function (cb) { + classifierHelper._initsCB.forEach(function(cb) { cb(); }); classifierHelper._initsCB = []; diff --git a/toolkit/components/url-classifier/tests/mochitest/cleanWorker.js b/toolkit/components/url-classifier/tests/mochitest/cleanWorker.js index 6856483730a1..67ba147d74be 100644 --- a/toolkit/components/url-classifier/tests/mochitest/cleanWorker.js +++ b/toolkit/components/url-classifier/tests/mochitest/cleanWorker.js @@ -1,7 +1,7 @@ onmessage = function() { try { importScripts("evilWorker.js"); - } catch(ex) { + } catch (ex) { postMessage("success"); return; } diff --git a/toolkit/components/url-classifier/tests/mochitest/dnt.html b/toolkit/components/url-classifier/tests/mochitest/dnt.html index effc3a4f8ce4..224626368870 100644 --- a/toolkit/components/url-classifier/tests/mochitest/dnt.html +++ b/toolkit/components/url-classifier/tests/mochitest/dnt.html @@ -6,7 +6,7 @@ function makeXHR(url, callback) { var xhr = new XMLHttpRequest(); - xhr.open('GET', url, true); + xhr.open("GET", url, true); xhr.onload = function() { callback(xhr.response); }; diff --git a/toolkit/components/url-classifier/tests/mochitest/test_advisory_link.html b/toolkit/components/url-classifier/tests/mochitest/test_advisory_link.html index 4b4cbdb64d01..ed4a6bf4248f 100644 --- a/toolkit/components/url-classifier/tests/mochitest/test_advisory_link.html +++ b/toolkit/components/url-classifier/tests/mochitest/test_advisory_link.html @@ -82,7 +82,7 @@ function setupTestData(data) { } function testOnWindow(aTestData) { - return new Promise(resolve => { + return new Promise(resolve => { let win = mainWindow.OpenBrowserWindow(); (async function() { @@ -117,7 +117,7 @@ function testOnWindow(aTestData) { } SpecialPowers.pushPrefEnv( - {"set" : [["browser.safebrowsing.phishing.enabled", true]]}, + {"set": [["browser.safebrowsing.phishing.enabled", true]]}, test); function test() { diff --git a/toolkit/components/url-classifier/tests/mochitest/test_allowlisted_annotations.html b/toolkit/components/url-classifier/tests/mochitest/test_allowlisted_annotations.html index ba9c86f95e6b..e6369b544416 100644 --- a/toolkit/components/url-classifier/tests/mochitest/test_allowlisted_annotations.html +++ b/toolkit/components/url-classifier/tests/mochitest/test_allowlisted_annotations.html @@ -33,9 +33,9 @@ function clearPermissions() { } SpecialPowers.pushPrefEnv( - {"set" : [["urlclassifier.trackingTable", "test-track-simple"], - ["privacy.trackingprotection.enabled", true], - ["channelclassifier.allowlist_example", true]]}, + {"set": [["urlclassifier.trackingTable", "test-track-simple"], + ["privacy.trackingprotection.enabled", true], + ["channelclassifier.allowlist_example", true]]}, test); function test() { diff --git a/toolkit/components/url-classifier/tests/mochitest/test_bug1254766.html b/toolkit/components/url-classifier/tests/mochitest/test_bug1254766.html index 84bdb77d7c2d..86b558c6f02c 100644 --- a/toolkit/components/url-classifier/tests/mochitest/test_bug1254766.html +++ b/toolkit/components/url-classifier/tests/mochitest/test_bug1254766.html @@ -139,10 +139,12 @@ function testGethash() { .then(addPrefixToDB) .then(loadTestFrame) .then(() => { - ok(gCurGethashCounter > gPreGethashCounter, "Gethash request is triggered."); }) + ok(gCurGethashCounter > gPreGethashCounter, "Gethash request is triggered."); +}) .then(loadTestFrame) .then(() => { - ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); }) + ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); +}) .then(reset); } @@ -155,7 +157,8 @@ function testUpdate() { .then(addCompletionToDB) .then(loadTestFrame) .then(() => { - ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); }) + ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); +}) .then(reset); } @@ -170,11 +173,13 @@ function testUpdateNotClearCompletions() { .then(addCompletionToDB) .then(loadTestFrame) .then(() => { - ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); }) + ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); +}) .then(updateUnusedUrl) .then(loadTestFrame) .then(() => { - ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); }) + ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); +}) .then(reset); } @@ -189,7 +194,8 @@ function testUpdateCompletionsAfterReload() { .then(classifierHelper.reloadDatabase) .then(loadTestFrame) .then(() => { - ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); }) + ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); +}) .then(reset); } @@ -205,14 +211,17 @@ function testGethashCompletionsAfterReload() { .then(addPrefixToDB) .then(loadTestFrame) .then(() => { - ok(gCurGethashCounter > gPreGethashCounter, "Gethash request is triggered."); }) + ok(gCurGethashCounter > gPreGethashCounter, "Gethash request is triggered."); +}) .then(loadTestFrame) .then(() => { - ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); }) + ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is not triggered."); +}) .then(classifierHelper.reloadDatabase) .then(loadTestFrame) .then(() => { - ok(gCurGethashCounter > gPreGethashCounter, "Gethash request is triggered."); }) + ok(gCurGethashCounter > gPreGethashCounter, "Gethash request is triggered."); +}) .then(reset); } diff --git a/toolkit/components/url-classifier/tests/mochitest/test_cachemiss.html b/toolkit/components/url-classifier/tests/mochitest/test_cachemiss.html index 5a9d455680b7..846701c174db 100644 --- a/toolkit/components/url-classifier/tests/mochitest/test_cachemiss.html +++ b/toolkit/components/url-classifier/tests/mochitest/test_cachemiss.html @@ -61,7 +61,7 @@ function getGethashCounter() { // add 4-bytes prefixes to local database, so when we access the url, // it will trigger gethash request. function addPrefixToDB(list, url) { - var testData = [{ db: list, url: url, len: 4 }]; + var testData = [{ db: list, url, len: 4 }]; return classifierHelper.addUrlToDB(testData) .catch(function(err) { @@ -96,11 +96,13 @@ function testNegativeCache() { .then(setup) .then(() => loadTestFrame()) .then(() => { - ok(gCurGethashCounter > gPreGethashCounter, "Gethash request is triggered."); }) + ok(gCurGethashCounter > gPreGethashCounter, "Gethash request is triggered."); +}) // Second load should not trigger gethash request because cache. .then(() => loadTestFrame()) .then(() => { - ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is nottriggered."); }) + ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is nottriggered."); +}) .then(reset); } @@ -122,11 +124,13 @@ function testPositiveCache() { .then(setup) .then(() => loadTestFrame()) .then(() => { - ok(gCurGethashCounter > gPreGethashCounter, "Gethash request is triggered."); }) + ok(gCurGethashCounter > gPreGethashCounter, "Gethash request is triggered."); +}) // Second load should not trigger gethash request because cache. .then(() => loadTestFrame()) .then(() => { - ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is nottriggered."); }) + ok(gCurGethashCounter == gPreGethashCounter, "Gethash request is nottriggered."); +}) .then(reset); } diff --git a/toolkit/components/url-classifier/tests/mochitest/test_classified_annotations.html b/toolkit/components/url-classifier/tests/mochitest/test_classified_annotations.html index 5814fff000b9..3d21b4848a09 100644 --- a/toolkit/components/url-classifier/tests/mochitest/test_classified_annotations.html +++ b/toolkit/components/url-classifier/tests/mochitest/test_classified_annotations.html @@ -25,7 +25,7 @@ function cleanup() { } SpecialPowers.pushPrefEnv( - {"set" : [["urlclassifier.trackingTable", "test-track-simple"]]}, + {"set": [["urlclassifier.trackingTable", "test-track-simple"]]}, test); function test() { diff --git a/toolkit/components/url-classifier/tests/mochitest/test_classifier.html b/toolkit/components/url-classifier/tests/mochitest/test_classifier.html index 9ed91d32eda0..de5865993450 100644 --- a/toolkit/components/url-classifier/tests/mochitest/test_classifier.html +++ b/toolkit/components/url-classifier/tests/mochitest/test_classifier.html @@ -125,7 +125,7 @@ SimpleTest.waitForExplicitFinish(); function updateSuccess() { return SpecialPowers.pushPrefEnv( - {"set" : [["browser.safebrowsing.malware.enabled", true]]}); + {"set": [["browser.safebrowsing.malware.enabled", true]]}); } function updateError(errorCode) { @@ -171,12 +171,12 @@ function testService() { } SpecialPowers.pushPrefEnv( - {"set" : [["urlclassifier.malwareTable", "test-malware-simple,test-unwanted-simple,test-harmful-simple"], - ["urlclassifier.phishTable", "test-phish-simple"], - ["urlclassifier.downloadBlockTable", "test-block-simple"], - ["urlclassifier.trackingTable", "test-track-simple"], - ["browser.safebrowsing.debug", true], - ["privacy.trackingprotection.annotate_channels", true]]}, + {"set": [["urlclassifier.malwareTable", "test-malware-simple,test-unwanted-simple,test-harmful-simple"], + ["urlclassifier.phishTable", "test-phish-simple"], + ["urlclassifier.downloadBlockTable", "test-block-simple"], + ["urlclassifier.trackingTable", "test-track-simple"], + ["browser.safebrowsing.debug", true], + ["privacy.trackingprotection.annotate_channels", true]]}, function() { classifierHelper.waitForInit() .then(() => classifierHelper.addUrlToDB(testData)) diff --git a/toolkit/components/url-classifier/tests/mochitest/test_classifier_changetablepref.html b/toolkit/components/url-classifier/tests/mochitest/test_classifier_changetablepref.html index b0e45d648c7f..1440638bcdda 100644 --- a/toolkit/components/url-classifier/tests/mochitest/test_classifier_changetablepref.html +++ b/toolkit/components/url-classifier/tests/mochitest/test_classifier_changetablepref.html @@ -78,7 +78,7 @@ function runTest() { * url specified in the table will be blocked after update. */ var pushPrefPromise = SpecialPowers.pushPrefEnv( - {"set" : [["urlclassifier.trackingTable", testTable]]}); + {"set": [["urlclassifier.trackingTable", testTable]]}); // To make sure url is not blocked by an already blocked 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 SpecialPowers.pushPrefEnv( - {"set" : [["privacy.trackingprotection.enabled", true], - ["channelclassifier.allowlist_example", true], - ["browser.safebrowsing.provider.mozilla.nextupdatetime", "1"], - ["browser.safebrowsing.provider.mozilla.lists", testTable], - ["browser.safebrowsing.provider.mozilla.updateURL", UPDATE_URL]]}, + {"set": [["privacy.trackingprotection.enabled", true], + ["channelclassifier.allowlist_example", true], + ["browser.safebrowsing.provider.mozilla.nextupdatetime", "1"], + ["browser.safebrowsing.provider.mozilla.lists", testTable], + ["browser.safebrowsing.provider.mozilla.updateURL", UPDATE_URL]]}, runTest); // Expected finish() call is in "bug_1281083.html". diff --git a/toolkit/components/url-classifier/tests/mochitest/test_classifier_match.html b/toolkit/components/url-classifier/tests/mochitest/test_classifier_match.html index 5398c683d00e..fed94d41d522 100644 --- a/toolkit/components/url-classifier/tests/mochitest/test_classifier_match.html +++ b/toolkit/components/url-classifier/tests/mochitest/test_classifier_match.html @@ -72,7 +72,7 @@ var testDatas = [ expect: { error: Cr.NS_ERROR_BLOCKED_URI, table: "mochi-block-simple", provider: "", - prefix: (function(){ + prefix: (function() { return hashPrefix("malware.example.com/"); })(), } @@ -82,7 +82,7 @@ var testDatas = [ expect: { error: Cr.NS_ERROR_MALWARE_URI, table: "mochi1-malware-simple", provider: "mozilla", - prefix: (function(){ + prefix: (function() { return hashPrefix("malware1.example.com/"); })(), } @@ -92,7 +92,7 @@ var testDatas = [ expect: { error: Cr.NS_ERROR_MALWARE_URI, table: "mochi2-malware-simple", provider: "mozilla", - prefix: (function(){ + prefix: (function() { return hashPrefix("malware2.example.com/"); })(), } @@ -102,7 +102,7 @@ var testDatas = [ expect: { error: Cr.NS_ERROR_MALWARE_URI, table: "mochig3-malware-simple", provider: "google", - prefix: (function(){ + prefix: (function() { return hashPrefix("malware3.example.com/"); })(), } @@ -171,7 +171,7 @@ function runTest() { } SpecialPowers.pushPrefEnv( - {"set" : [["browser.safebrowsing.malware.enabled", true]]}, + {"set": [["browser.safebrowsing.malware.enabled", true]]}, function() { classifierHelper.waitForInit() .then(() => setupTestData(inputDatas)) diff --git a/toolkit/components/url-classifier/tests/mochitest/test_classifier_worker.html b/toolkit/components/url-classifier/tests/mochitest/test_classifier_worker.html index fc9fa02d85c4..7c942d78f6a6 100644 --- a/toolkit/components/url-classifier/tests/mochitest/test_classifier_worker.html +++ b/toolkit/components/url-classifier/tests/mochitest/test_classifier_worker.html @@ -29,9 +29,8 @@ function loadTestFrame() { "http://example.com/tests/toolkit/components/url-classifier/tests/mochitest/workerFrame.html"; } -function onmessage(event) -{ - var pieces = event.data.split(':'); +function onmessage(event) { + var pieces = event.data.split(":"); if (pieces[0] == "finish") { SimpleTest.finish(); return; @@ -42,7 +41,7 @@ function onmessage(event) function updateSuccess() { SpecialPowers.pushPrefEnv( - {"set" : [["browser.safebrowsing.malware.enabled", true]]}, + {"set": [["browser.safebrowsing.malware.enabled", true]]}, loadTestFrame); } @@ -50,11 +49,11 @@ function updateError(errorCode) { ok(false, "Couldn't update classifier. Error code: " + errorCode); // Abort test. SimpleTest.finish(); -}; +} SpecialPowers.pushPrefEnv( - {"set" : [["urlclassifier.malwareTable", "test-malware-simple,test-unwanted-simple"], - ["urlclassifier.phishTable", "test-phish-simple"]]}, + {"set": [["urlclassifier.malwareTable", "test-malware-simple,test-unwanted-simple"], + ["urlclassifier.phishTable", "test-phish-simple"]]}, function() { classifierHelper.waitForInit() .then(() => classifierHelper.addUrlToDB(testData)) diff --git a/toolkit/components/url-classifier/tests/mochitest/test_classify_ping.html b/toolkit/components/url-classifier/tests/mochitest/test_classify_ping.html index e130f6654d0e..dac83cf81777 100644 --- a/toolkit/components/url-classifier/tests/mochitest/test_classify_ping.html +++ b/toolkit/components/url-classifier/tests/mochitest/test_classify_ping.html @@ -74,8 +74,8 @@ function ping(id, host) { var elm = document.createElement("a"); - elm.setAttribute('ping', host + path_ping + "?id=" + id); - elm.setAttribute('href', "#"); + elm.setAttribute("ping", host + path_ping + "?id=" + id); + elm.setAttribute("href", "#"); document.body.appendChild(elm); // Trigger ping. @@ -87,7 +87,7 @@ function isPingedWithRetry(id, expected, msg, callback, retryCnt) { var url = "http://mochi.test:8888/" + path_ping; var xhr = new XMLHttpRequest(); - xhr.open('GET', url + "?id=" + id); + xhr.open("GET", url + "?id=" + id); xhr.onload = function() { var isPinged = xhr.response === "ping"; let success = isPinged === expected; diff --git a/toolkit/components/url-classifier/tests/mochitest/test_donottrack.html b/toolkit/components/url-classifier/tests/mochitest/test_donottrack.html index 7f1e27d110b4..f515d23b9324 100644 --- a/toolkit/components/url-classifier/tests/mochitest/test_donottrack.html +++ b/toolkit/components/url-classifier/tests/mochitest/test_donottrack.html @@ -28,47 +28,47 @@ const tests = [ // DNT turned on and TP turned off, DNT signal sent in both private browsing // and normal mode. { - setting: {dntPref:true, tpPref:false, tppbPref:false, pbMode:true}, + setting: {dntPref: true, tpPref: false, tppbPref: false, pbMode: true}, expected: {dnt: "1"}, }, { - setting: {dntPref:true, tpPref:false, tppbPref:false, pbMode:false}, + setting: {dntPref: true, tpPref: false, tppbPref: false, pbMode: false}, expected: {dnt: "1"} }, // DNT turned off and TP turned on globally, DNT signal sent in both private // 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"} }, { - setting: {dntPref:false, tpPref:true, tppbPref:false, pbMode:false}, + setting: {dntPref: false, tpPref: true, tppbPref: false, pbMode: false}, expected: {dnt: "1"} }, // DNT turned off and TP in Private Browsing only, DNT signal sent in private // browsing mode only. { - setting: {dntPref:false, tpPref:false, tppbPref:true, pbMode:true}, + setting: {dntPref: false, tpPref: false, tppbPref: true, pbMode: true}, expected: {dnt: "1"} }, { - setting: {dntPref:false, tpPref:false, tppbPref:true, pbMode:false}, + setting: {dntPref: false, tpPref: false, tppbPref: true, pbMode: false}, expected: {dnt: "unspecified"} }, // 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"} }, { - setting: {dntPref:false, tpPref:false, tppbPref:false, pbMode:false}, + setting: {dntPref: false, tpPref: false, tppbPref: false, pbMode: false}, expected: {dnt: "unspecified"} }, ] -const DNT_PREF = 'privacy.donottrackheader.enabled'; -const TP_PREF = 'privacy.trackingprotection.enabled'; -const TP_PB_PREF = 'privacy.trackingprotection.pbmode.enabled'; +const DNT_PREF = "privacy.donottrackheader.enabled"; +const TP_PREF = "privacy.trackingprotection.enabled"; +const TP_PB_PREF = "privacy.trackingprotection.pbmode.enabled"; const contentPage = "http://mochi.test:8888/tests/toolkit/components/url-classifier/tests/mochitest/dnt.html"; @@ -85,7 +85,7 @@ function whenDelayedStartupFinished(aWindow, aCallback) { } function executeTest(test) { - SpecialPowers.pushPrefEnv({"set" : [ + SpecialPowers.pushPrefEnv({"set": [ [DNT_PREF, test.setting.dntPref], [TP_PREF, test.setting.tpPref], [TP_PB_PREF, test.setting.tppbPref] @@ -104,7 +104,7 @@ function executeTest(test) { win.removeEventListener("DOMContentLoaded", onInnerLoad, true); - win.content.addEventListener('message', function (event) { + win.content.addEventListener("message", function(event) { let [key, value] = event.data.split("="); if (key == "finish") { win.close(); diff --git a/toolkit/components/url-classifier/tests/mochitest/test_gethash.html b/toolkit/components/url-classifier/tests/mochitest/test_gethash.html index c2955f5684d6..7963a9d51198 100644 --- a/toolkit/components/url-classifier/tests/mochitest/test_gethash.html +++ b/toolkit/components/url-classifier/tests/mochitest/test_gethash.html @@ -47,7 +47,7 @@ function loadTestFrame(id) { // add 4-bytes prefixes to local database, so when we access the url, // it will trigger gethash request. function addPrefixToDB(list, url) { - var testData = [{ db: list, url: url, len: 4 }]; + var testData = [{ db: list, url, len: 4 }]; return classifierHelper.addUrlToDB(testData) .catch(function(err) { diff --git a/toolkit/components/url-classifier/tests/mochitest/test_privatebrowsing_trackingprotection.html b/toolkit/components/url-classifier/tests/mochitest/test_privatebrowsing_trackingprotection.html index fdbfca74a3bc..40f6bcf9c319 100644 --- a/toolkit/components/url-classifier/tests/mochitest/test_privatebrowsing_trackingprotection.html +++ b/toolkit/components/url-classifier/tests/mochitest/test_privatebrowsing_trackingprotection.html @@ -50,8 +50,8 @@ function testOnWindow(aPrivate, aCallback) { } win.removeEventListener("DOMContentLoaded", onInnerLoad, true); - win.content.addEventListener('load', function innerLoad2() { - win.content.removeEventListener('load', innerLoad2); + win.content.addEventListener("load", function innerLoad2() { + win.content.removeEventListener("load", innerLoad2); SimpleTest.executeSoon(function() { aCallback(win); }); }, false, true); }, true); @@ -112,7 +112,7 @@ function checkLoads(aWindow, aBlocked) { } SpecialPowers.pushPrefEnv( - {"set" : [["urlclassifier.trackingTable", "test-track-simple"], + {"set": [["urlclassifier.trackingTable", "test-track-simple"], ["privacy.trackingprotection.enabled", false], ["privacy.trackingprotection.pbmode.enabled", true], ["channelclassifier.allowlist_example", true]]}, diff --git a/toolkit/components/url-classifier/tests/mochitest/test_reporturl.html b/toolkit/components/url-classifier/tests/mochitest/test_reporturl.html index aeb798ae76f5..674ce719b3ed 100644 --- a/toolkit/components/url-classifier/tests/mochitest/test_reporturl.html +++ b/toolkit/components/url-classifier/tests/mochitest/test_reporturl.html @@ -75,7 +75,7 @@ function whenDelayedStartupFinished(aWindow, aCallback) { } function testOnWindow(aTestData, aCallback, aTestCreater) { - return new Promise(resolve => { + return new Promise(resolve => { let win = mainWindow.OpenBrowserWindow(); (async function() { @@ -116,16 +116,16 @@ var createBlockedIframe = function(aWindow, aBrowser, aTopUrl, aUrl) { await ContentTask.spawn(aBrowser, aUrl, async function(aUrl) { return new Promise(resolve => { let listener = e => { - removeEventListener('AboutBlockedLoaded', listener, false, true); + removeEventListener("AboutBlockedLoaded", listener, false, true); resolve(); }; - addEventListener('AboutBlockedLoaded', listener, false, true); + addEventListener("AboutBlockedLoaded", listener, false, true); 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"); ok(ignoreButton, "ignoreWarningButton should exist"); ignoreButton.click(); @@ -154,7 +154,7 @@ var testDatas = [ testUrl: "itisaphishingsite.org/phishing.html", list: "mochi1-phish-simple", provider: "google", - blockCreater : createBlockedPage, + blockCreater: createBlockedPage, expectedReportUri: "http://itisaphishingsite.org/phishing.html" }, @@ -165,7 +165,7 @@ var testDatas = [ testUrl: "fakeitisaphishingsite.org/phishing.html", list: "fake-phish-simple", provider: "mozilla", - blockCreater : createBlockedPage + blockCreater: createBlockedPage }, // Iframe case: @@ -177,7 +177,7 @@ var testDatas = [ testUrl: "phishing.example.com/test.html", list: "mochi2-phish-simple", provider: "google4", - blockCreater : createBlockedIframe, + blockCreater: createBlockedIframe, 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", list: "mochi3-phish-simple", provider: "google4", - blockCreater : createBlockedPage, + blockCreater: createBlockedPage, expectedReportUri: "http://prefixexample.com/chrome/toolkit/components/url-classifier/tests/mochitest/report.sjs" }, ]; SpecialPowers.pushPrefEnv( - {"set" : [["browser.safebrowsing.provider.google.reportPhishMistakeURL", BASE_URL + "action=reporturl&reporturl="], - ["browser.safebrowsing.provider.google4.reportPhishMistakeURL", BASE_URL + "action=reporturl&reporturl="], - ["browser.safebrowsing.phishing.enabled", true]]}, + {"set": [["browser.safebrowsing.provider.google.reportPhishMistakeURL", BASE_URL + "action=reporturl&reporturl="], + ["browser.safebrowsing.provider.google4.reportPhishMistakeURL", BASE_URL + "action=reporturl&reporturl="], + ["browser.safebrowsing.phishing.enabled", true]]}, test); function test() { diff --git a/toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_bug1157081.html b/toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_bug1157081.html index f64baa654112..2b391f7eb2b6 100644 --- a/toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_bug1157081.html +++ b/toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_bug1157081.html @@ -50,8 +50,8 @@ function testOnWindow(aCallback) { } win.removeEventListener("DOMContentLoaded", onInnerLoad, true); - win.content.addEventListener('load', function innerLoad2() { - win.content.removeEventListener('load', innerLoad2); + win.content.addEventListener("load", function innerLoad2() { + win.content.removeEventListener("load", innerLoad2); SimpleTest.executeSoon(function() { aCallback(win); }); }, false, true); }, true); @@ -70,11 +70,11 @@ function checkLoads(aWindow, aBlocked) { } SpecialPowers.pushPrefEnv( - {"set" : [["urlclassifier.trackingTable", "test-track-simple"], - ["privacy.trackingprotection.enabled", true], - ["browser.safebrowsing.malware.enabled", false], - ["browser.safebrowsing.phishing.enabled", false], - ["channelclassifier.allowlist_example", true]]}, + {"set": [["urlclassifier.trackingTable", "test-track-simple"], + ["privacy.trackingprotection.enabled", true], + ["browser.safebrowsing.malware.enabled", false], + ["browser.safebrowsing.phishing.enabled", false], + ["channelclassifier.allowlist_example", true]]}, test); function test() { diff --git a/toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_bug1312515.html b/toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_bug1312515.html index a958cc555350..72b1c83a7801 100644 --- a/toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_bug1312515.html +++ b/toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_bug1312515.html @@ -50,8 +50,8 @@ function testOnWindow(aPrivate, aCallback) { } win.removeEventListener("DOMContentLoaded", onInnerLoad, true); - win.content.addEventListener('load', function innerLoad2() { - win.content.removeEventListener('load', innerLoad2); + win.content.addEventListener("load", function innerLoad2() { + win.content.removeEventListener("load", innerLoad2); SimpleTest.executeSoon(function() { aCallback(win); }); }, false, true); }, true); @@ -103,10 +103,10 @@ function endTest() { } SpecialPowers.pushPrefEnv( - {"set" : [["urlclassifier.trackingTable", "test-track-simple"], - ["privacy.trackingprotection.annotate_channels", true], - ["privacy.trackingprotection.lower_network_priority", true], - ["channelclassifier.allowlist_example", true]]}, + {"set": [["urlclassifier.trackingTable", "test-track-simple"], + ["privacy.trackingprotection.annotate_channels", true], + ["privacy.trackingprotection.lower_network_priority", true], + ["channelclassifier.allowlist_example", true]]}, test); function test() { diff --git a/toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_whitelist.html b/toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_whitelist.html index 6484a78a16a1..68f028dbe300 100644 --- a/toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_whitelist.html +++ b/toolkit/components/url-classifier/tests/mochitest/test_trackingprotection_whitelist.html @@ -51,8 +51,8 @@ function testOnWindow(contentPage, aCallback) { } win.removeEventListener("DOMContentLoaded", onInnerLoad, true); - win.content.addEventListener('load', function innerLoad2() { - win.content.removeEventListener('load', innerLoad2); + win.content.addEventListener("load", function innerLoad2() { + win.content.removeEventListener("load", innerLoad2); SimpleTest.executeSoon(function() { aCallback(win); }); }, false, true); }, true); @@ -110,8 +110,8 @@ function checkLoads(aWindow, aWhitelisted) { } SpecialPowers.pushPrefEnv( - {"set" : [["privacy.trackingprotection.enabled", true], - ["channelclassifier.allowlist_example", true]]}, + {"set": [["privacy.trackingprotection.enabled", true], + ["channelclassifier.allowlist_example", true]]}, test); function test() { @@ -128,7 +128,7 @@ function test() { aWindow.close(); // Load the test from a URL on the whitelist but without the whitelist - SpecialPowers.pushPrefEnv({"set" : [["urlclassifier.trackingWhitelistTable", ""]]}, + SpecialPowers.pushPrefEnv({"set": [["urlclassifier.trackingWhitelistTable", ""]]}, function() { testOnWindow(contentPage1, function(aWindow) { checkLoads(aWindow, false); diff --git a/toolkit/components/url-classifier/tests/mochitest/tracker.js b/toolkit/components/url-classifier/tests/mochitest/tracker.js index cbe029ca750a..cedfc51793ed 100644 --- a/toolkit/components/url-classifier/tests/mochitest/tracker.js +++ b/toolkit/components/url-classifier/tests/mochitest/tracker.js @@ -1,3 +1,3 @@ function getTrackerTimeout() { - return window.setTimeout(function(){}, 0); + return window.setTimeout(function() {}, 0); } diff --git a/toolkit/components/url-classifier/tests/mochitest/trackingRequest.js b/toolkit/components/url-classifier/tests/mochitest/trackingRequest.js index b5d3ac5ada3f..97e95a73ca5c 100644 --- a/toolkit/components/url-classifier/tests/mochitest/trackingRequest.js +++ b/toolkit/components/url-classifier/tests/mochitest/trackingRequest.js @@ -4,8 +4,7 @@ window.addEventListener("message", function onMessage(evt) { var request = new XMLHttpRequest(); request.open("GET", evt.data.url, true); request.send(null); - } - else if (evt.data.type === "doFetch") { + } else if (evt.data.type === "doFetch") { fetch(evt.data.url); } }); diff --git a/toolkit/components/url-classifier/tests/unit/head_urlclassifier.js b/toolkit/components/url-classifier/tests/unit/head_urlclassifier.js index be55f6bff4e0..f52ded37c2e9 100644 --- a/toolkit/components/url-classifier/tests/unit/head_urlclassifier.js +++ b/toolkit/components/url-classifier/tests/unit/head_urlclassifier.js @@ -41,11 +41,11 @@ prefBranch.setIntPref("urlclassifier.gethash.timeout_ms", 5000); function delFile(name) { try { // Delete a previously created sqlite file - var file = dirSvc.get('ProfLD', Ci.nsIFile); + var file = dirSvc.get("ProfLD", Ci.nsIFile); file.append(name); if (file.exists()) file.remove(false); - } catch(e) { + } catch (e) { } } @@ -103,9 +103,9 @@ function buildUpdate(update, hashSize) { var chunks = update[tableName]; for (var j = 0; j < chunks.length; 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; - updateStr += chunkType + ':' + chunkNum + ':' + hashSize; + updateStr += chunkType + ":" + chunkNum + ":" + hashSize; if (chunk.urls) { var chunkData = chunk.urls.join("\n"); @@ -120,27 +120,27 @@ function buildUpdate(update, hashSize) { } function buildPhishingUpdate(chunks, hashSize) { - return buildUpdate({"test-phish-simple" : chunks}, hashSize); + return buildUpdate({"test-phish-simple": chunks}, hashSize); } function buildMalwareUpdate(chunks, hashSize) { - return buildUpdate({"test-malware-simple" : chunks}, hashSize); + return buildUpdate({"test-malware-simple": chunks}, hashSize); } function buildUnwantedUpdate(chunks, hashSize) { - return buildUpdate({"test-unwanted-simple" : chunks}, hashSize); + return buildUpdate({"test-unwanted-simple": chunks}, hashSize); } function buildBlockedUpdate(chunks, hashSize) { - return buildUpdate({"test-block-simple" : chunks}, hashSize); + return buildUpdate({"test-block-simple": chunks}, hashSize); } function buildMozPhishingUpdate(chunks, hashSize) { - return buildUpdate({"moz-phish-simple" : chunks}, hashSize); + return buildUpdate({"moz-phish-simple": 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) { var listener = { - QueryInterface: function(iid) - { + QueryInterface(iid) { if (iid.equals(Ci.nsISupports) || iid.equals(Ci.nsIUrlClassifierUpdateObserver)) return this; throw Cr.NS_ERROR_NO_INTERFACE; }, - updateUrlRequested: function(url) { }, - streamFinished: function(status) { }, - updateError: function(errorCode) { failure(errorCode); }, - updateSuccess: function(requestedTimeout) { success(requestedTimeout); } + updateUrlRequested(url) { }, + streamFinished(status) { }, + updateError(errorCode) { failure(errorCode); }, + updateSuccess(requestedTimeout) { success(requestedTimeout); } }; dbservice.beginUpdate(listener, allTables); @@ -174,18 +173,17 @@ function doSimpleUpdate(updateText, success, failure) { */ function doErrorUpdate(tables, success, failure) { var listener = { - QueryInterface: function(iid) - { + QueryInterface(iid) { if (iid.equals(Ci.nsISupports) || iid.equals(Ci.nsIUrlClassifierUpdateObserver)) return this; throw Cr.NS_ERROR_NO_INTERFACE; }, - updateUrlRequested: function(url) { }, - streamFinished: function(status) { }, - updateError: function(errorCode) { success(errorCode); }, - updateSuccess: function(requestedTimeout) { failure(requestedTimeout); } + updateUrlRequested(url) { }, + streamFinished(status) { }, + updateError(errorCode) { success(errorCode); }, + updateSuccess(requestedTimeout) { failure(requestedTimeout); } }; dbservice.beginUpdate(listener, tables, null); @@ -210,12 +208,11 @@ function doStreamUpdate(updateText, success, failure, downloadFailure) { var gAssertions = { -tableData : function(expectedTables, cb) -{ +tableData(expectedTables, cb) { dbservice.getTables(function(tables) { // rebuild the tables in a predictable order. var parts = tables.split("\n"); - while (parts[parts.length - 1] == '') { + while (parts[parts.length - 1] == "") { parts.pop(); } 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. urls = urls.slice(0); var doLookup = function() { @@ -247,13 +243,12 @@ checkUrls: function(urls, expected, cb, useMoz = false) doLookup(); }, -checkTables: function(url, expected, cb) -{ +checkTables(url, expected, cb) { var principal = secMan.createCodebasePrincipal(iosvc.newURI("http://" + url), {}); dbservice.lookup(principal, allTables, function(tables) { // Rebuild tables in a predictable order. var parts = tables.split(","); - while (parts[parts.length - 1] == '') { + while (parts[parts.length - 1] == "") { parts.pop(); } parts.sort(); @@ -263,51 +258,42 @@ checkTables: function(url, expected, cb) }, true); }, -urlsDontExist: function(urls, cb) -{ - this.checkUrls(urls, '', cb); +urlsDontExist(urls, cb) { + this.checkUrls(urls, "", cb); }, -urlsExist: function(urls, cb) -{ - this.checkUrls(urls, 'test-phish-simple', cb); +urlsExist(urls, cb) { + this.checkUrls(urls, "test-phish-simple", cb); }, -malwareUrlsExist: function(urls, cb) -{ - this.checkUrls(urls, 'test-malware-simple', cb); +malwareUrlsExist(urls, cb) { + this.checkUrls(urls, "test-malware-simple", cb); }, -unwantedUrlsExist: function(urls, cb) -{ - this.checkUrls(urls, 'test-unwanted-simple', cb); +unwantedUrlsExist(urls, cb) { + this.checkUrls(urls, "test-unwanted-simple", cb); }, -blockedUrlsExist: function(urls, cb) -{ - this.checkUrls(urls, 'test-block-simple', cb); +blockedUrlsExist(urls, cb) { + this.checkUrls(urls, "test-block-simple", cb); }, -mozPhishingUrlsExist: function(urls, cb) -{ - this.checkUrls(urls, 'moz-phish-simple', cb, true); +mozPhishingUrlsExist(urls, cb) { + 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 cb(); }, -subsExist: function(urls, cb) -{ +subsExist(urls, cb) { // XXX: there's no interface for checking items in the subs table cb(); }, -urlExistInMultipleTables: function(data, cb) -{ - this.checkTables(data["url"], data["tables"], cb); +urlExistInMultipleTables(data, 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. */ -function checkAssertions(assertions, doneCallback) -{ +function checkAssertions(assertions, doneCallback) { var checkAssertion = function() { for (var i in assertions) { var data = assertions[i]; @@ -331,8 +316,7 @@ function checkAssertions(assertions, doneCallback) checkAssertion(); } -function updateError(arg) -{ +function updateError(arg) { do_throw(arg); } @@ -357,23 +341,21 @@ function doUpdateTest(updates, assertions, successCallback, errorCallback) { var gTests; var gNextTest = 0; -function runNextTest() -{ +function runNextTest() { if (gNextTest >= gTests.length) { do_test_finished(); return; } dbservice.resetDatabase(); - dbservice.setHashCompleter('test-phish-simple', null); + dbservice.setHashCompleter("test-phish-simple", null); let test = gTests[gNextTest++]; dump("running " + test.name + "\n"); test(); } -function runTests(tests) -{ +function runTests(tests) { gTests = tests; runNextTest(); } @@ -388,13 +370,13 @@ function Timer(delay, cb) { } Timer.prototype = { -QueryInterface: function(iid) { +QueryInterface(iid) { if (!iid.equals(Ci.nsISupports) && !iid.equals(Ci.nsITimerCallback)) { throw Cr.NS_ERROR_NO_INTERFACE; } return this; }, -notify: function(timer) { +notify(timer) { this.cb(); } } @@ -414,7 +396,7 @@ function LFSRgenerator(seed) { } LFSRgenerator.prototype = { // nextNum returns a random unsigned integer of in the range [0,2^|bits|]. - nextNum: function(bits) { + nextNum(bits) { if (!bits) bits = 32; @@ -446,13 +428,13 @@ function waitUntilMetaDataSaved(expectedState, expectedChecksum, callback) { let stateBase64 = metadata[0]; let checksumBase64 = metadata[1]; - if (tableName !== 'test-phish-proto') { + if (tableName !== "test-phish-proto") { return false; // continue. } if (stateBase64 === btoa(expectedState) && 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 // |getTables| caching works correctly. diff --git a/toolkit/components/url-classifier/tests/unit/test_addsub.js b/toolkit/components/url-classifier/tests/unit/test_addsub.js index 1ed65c7baad5..f82b7acb0b7d 100644 --- a/toolkit/components/url-classifier/tests/unit/test_addsub.js +++ b/toolkit/components/url-classifier/tests/unit/test_addsub.js @@ -1,6 +1,5 @@ -function doTest(updates, assertions) -{ +function doTest(updates, assertions) { doUpdateTest(updates, assertions, runNextTest, updateError); } @@ -9,13 +8,13 @@ function testSimpleAdds() { var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; var update = buildPhishingUpdate( [ - { "chunkNum" : 1, - "urls" : addUrls + { "chunkNum": 1, + "urls": addUrls }]); var assertions = { - "tableData" : "test-phish-simple;a:1", - "urlsExist" : addUrls + "tableData": "test-phish-simple;a:1", + "urlsExist": addUrls }; doTest([update], assertions); @@ -28,39 +27,38 @@ function testMultipleAdds() { var add2Urls = [ "foo.com/b" ]; var update = buildPhishingUpdate( - [{ "chunkNum" : 1, - "urls" : add1Urls }, - { "chunkNum" : 2, - "urls" : add2Urls }]); + [{ "chunkNum": 1, + "urls": add1Urls }, + { "chunkNum": 2, + "urls": add2Urls }]); var assertions = { - "tableData" : "test-phish-simple;a:1-2", - "urlsExist" : add1Urls.concat(add2Urls) + "tableData": "test-phish-simple;a:1-2", + "urlsExist": add1Urls.concat(add2Urls) }; doTest([update], assertions); } // Test that a sub will remove an existing add -function testSimpleSub() -{ +function testSimpleSub() { var addUrls = ["foo.com/a", "bar.com/b"]; var subUrls = ["1:foo.com/a"]; 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 }]); var subUpdate = buildPhishingUpdate( - [{ "chunkNum" : 50, - "chunkType" : "s", + [{ "chunkNum": 50, + "chunkType": "s", "urls": subUrls }]); var assertions = { - "tableData" : "test-phish-simple;a:1:s:50", - "urlsExist" : [ "bar.com/b" ], + "tableData": "test-phish-simple;a:1:s:50", + "urlsExist": [ "bar.com/b" ], "urlsDontExist": ["foo.com/a" ], - "subsDontExist" : [ "foo.com/a" ] + "subsDontExist": [ "foo.com/a" ] } doTest([addUpdate, subUpdate], assertions); @@ -68,25 +66,24 @@ function testSimpleSub() } // Same as testSimpleSub(), but the sub comes in before the add. -function testSubEmptiesAdd() -{ +function testSubEmptiesAdd() { var subUrls = ["1:foo.com/a"]; var addUrls = ["foo.com/a", "bar.com/b"]; var subUpdate = buildPhishingUpdate( - [{ "chunkNum" : 50, - "chunkType" : "s", + [{ "chunkNum": 50, + "chunkType": "s", "urls": subUrls }]); var addUpdate = buildPhishingUpdate( - [{ "chunkNum" : 1, + [{ "chunkNum": 1, "urls": addUrls }]); var assertions = { - "tableData" : "test-phish-simple;a:1:s:50", - "urlsExist" : [ "bar.com/b" ], + "tableData": "test-phish-simple;a:1:s:50", + "urlsExist": [ "bar.com/b" ], "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); @@ -94,25 +91,24 @@ function testSubEmptiesAdd() // Very similar to testSubEmptiesAdd, except that the domain entry will // still have an item left over that needs to be synced. -function testSubPartiallyEmptiesAdd() -{ +function testSubPartiallyEmptiesAdd() { var subUrls = ["1:foo.com/a"]; var addUrls = ["foo.com/a", "foo.com/b", "bar.com/b"]; var subUpdate = buildPhishingUpdate( - [{ "chunkNum" : 1, - "chunkType" : "s", + [{ "chunkNum": 1, + "chunkType": "s", "urls": subUrls }]); 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 }]); var assertions = { - "tableData" : "test-phish-simple;a:1:s:1", - "urlsExist" : [ "foo.com/b", "bar.com/b" ], - "urlsDontExist" : ["foo.com/a" ], - "subsDontExist" : [ "foo.com/a" ] // this sub was found, it shouldn't exist anymore + "tableData": "test-phish-simple;a:1:s:1", + "urlsExist": [ "foo.com/b", "bar.com/b" ], + "urlsDontExist": ["foo.com/a" ], + "subsDontExist": [ "foo.com/a" ] // this sub was found, it shouldn't exist anymore } doTest([subUpdate, addUpdate], assertions); @@ -122,106 +118,102 @@ function testSubPartiallyEmptiesAdd() // 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 // then adding it twice should leave the url intact. -function testPendingSubRemoved() -{ +function testPendingSubRemoved() { var subUrls = ["1:foo.com/a", "2:foo.com/b"]; var addUrls = ["foo.com/a", "foo.com/b"]; var subUpdate = buildPhishingUpdate( - [{ "chunkNum" : 1, - "chunkType" : "s", + [{ "chunkNum": 1, + "chunkType": "s", "urls": subUrls }]); 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 }]); var addUpdate2 = buildPhishingUpdate( - [{ "chunkNum" : 2, + [{ "chunkNum": 2, "urls": addUrls }]); var assertions = { - "tableData" : "test-phish-simple;a:1-2:s:1", - "urlsExist" : [ "foo.com/a", "foo.com/b" ], - "subsDontExist" : [ "foo.com/a", "foo.com/b" ] // this sub was found, it shouldn't exist anymore + "tableData": "test-phish-simple;a:1-2:s:1", + "urlsExist": [ "foo.com/a", "foo.com/b" ], + "subsDontExist": [ "foo.com/a", "foo.com/b" ] // this sub was found, it shouldn't exist anymore } doTest([subUpdate, addUpdate1, addUpdate2], assertions); } // 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 addUrls = ["foo.com/a", "foo.com/b"]; var subUpdate = buildPhishingUpdate( - [{ "chunkNum" : 1, - "chunkType" : "s", + [{ "chunkNum": 1, + "chunkType": "s", "urls": subUrls }]); var expireUpdate = buildPhishingUpdate( - [{ "chunkNum" : 1, - "chunkType" : "sd" }]); + [{ "chunkNum": 1, + "chunkType": "sd" }]); 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 }]); var assertions = { - "tableData" : "test-phish-simple;a:1", - "urlsExist" : [ "foo.com/a", "foo.com/b" ], - "subsDontExist" : [ "foo.com/a", "foo.com/b" ] // this sub was expired + "tableData": "test-phish-simple;a:1", + "urlsExist": [ "foo.com/a", "foo.com/b" ], + "subsDontExist": [ "foo.com/a", "foo.com/b" ] // this sub was expired } doTest([subUpdate, expireUpdate, addUpdate], assertions); } // Make sure that the sub url removes from only the chunk that it specifies -function testDuplicateAdds() -{ +function testDuplicateAdds() { var urls = ["foo.com/a"]; var addUpdate1 = buildPhishingUpdate( - [{ "chunkNum" : 1, + [{ "chunkNum": 1, "urls": urls }]); var addUpdate2 = buildPhishingUpdate( - [{ "chunkNum" : 2, + [{ "chunkNum": 2, "urls": urls }]); var subUpdate = buildPhishingUpdate( - [{ "chunkNum" : 3, - "chunkType" : "s", + [{ "chunkNum": 3, + "chunkType": "s", "urls": ["2:foo.com/a"]}]); var assertions = { - "tableData" : "test-phish-simple;a:1-2:s:3", - "urlsExist" : [ "foo.com/a"], - "subsDontExist" : [ "foo.com/a"] + "tableData": "test-phish-simple;a:1-2:s:3", + "urlsExist": [ "foo.com/a"], + "subsDontExist": [ "foo.com/a"] } doTest([addUpdate1, addUpdate2, subUpdate], assertions); } // Tests a sub which matches some existing adds but leaves others. -function testSubPartiallyMatches() -{ +function testSubPartiallyMatches() { var subUrls = ["foo.com/a"]; var addUrls = ["1:foo.com/a", "2:foo.com/b"]; var addUpdate = buildPhishingUpdate( - [{ "chunkNum" : 1, - "urls" : addUrls }]); + [{ "chunkNum": 1, + "urls": addUrls }]); var subUpdate = buildPhishingUpdate( - [{ "chunkNum" : 1, - "chunkType" : "s", - "urls" : addUrls }]); + [{ "chunkNum": 1, + "chunkType": "s", + "urls": addUrls }]); var assertions = { - "tableData" : "test-phish-simple;a:1:s:1", - "urlsDontExist" : ["foo.com/a"], - "subsDontExist" : ["foo.com/a"], - "subsExist" : ["foo.com/b"] + "tableData": "test-phish-simple;a:1:s:1", + "urlsDontExist": ["foo.com/a"], + "subsDontExist": ["foo.com/a"], + "subsExist": ["foo.com/b"] }; doTest([addUpdate, subUpdate], assertions); @@ -230,29 +222,28 @@ function testSubPartiallyMatches() // 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 // because of a pending sub chunk. -function testSubPartiallyMatches2() -{ +function testSubPartiallyMatches2() { var addUrls = ["foo.com/a"]; var subUrls = ["1:foo.com/a", "2:foo.com/b"]; var addUrls2 = ["foo.com/b"]; var addUpdate = buildPhishingUpdate( - [{ "chunkNum" : 1, - "urls" : addUrls }]); + [{ "chunkNum": 1, + "urls": addUrls }]); var subUpdate = buildPhishingUpdate( - [{ "chunkNum" : 1, - "chunkType" : "s", - "urls" : subUrls }]); + [{ "chunkNum": 1, + "chunkType": "s", + "urls": subUrls }]); var addUpdate2 = buildPhishingUpdate( - [{ "chunkNum" : 2, - "urls" : addUrls2 }]); + [{ "chunkNum": 2, + "urls": addUrls2 }]); var assertions = { - "tableData" : "test-phish-simple;a:1-2:s:1", - "urlsDontExist" : ["foo.com/a", "foo.com/b"], - "subsDontExist" : ["foo.com/a", "foo.com/b"] + "tableData": "test-phish-simple;a:1-2:s:1", + "urlsDontExist": ["foo.com/a", "foo.com/b"], + "subsDontExist": ["foo.com/a", "foo.com/b"] }; doTest([addUpdate, subUpdate, addUpdate2], assertions); @@ -267,22 +258,22 @@ function testSubsDifferentChunks() { var addUrls = [ "foo.com/a", "foo.com/b", "foo.com/c" ]; var subUpdate1 = buildPhishingUpdate( - [{ "chunkNum" : 1, - "chunkType" : "s", + [{ "chunkNum": 1, + "chunkType": "s", "urls": subUrls1 }]); var subUpdate2 = buildPhishingUpdate( - [{ "chunkNum" : 2, - "chunkType" : "s", - "urls" : subUrls2 }]); + [{ "chunkNum": 2, + "chunkType": "s", + "urls": subUrls2 }]); var addUpdate = buildPhishingUpdate( - [{ "chunkNum" : 3, - "urls" : addUrls }]); + [{ "chunkNum": 3, + "urls": addUrls }]); var assertions = { - "tableData" : "test-phish-simple;a:3:s:1-2", - "urlsExist" : [ "foo.com/c" ], - "urlsDontExist" : [ "foo.com/a", "foo.com/b" ], - "subsDontExist" : [ "foo.com/a", "foo.com/b" ] + "tableData": "test-phish-simple;a:3:s:1-2", + "urlsExist": [ "foo.com/c" ], + "urlsDontExist": [ "foo.com/a", "foo.com/b" ], + "subsDontExist": [ "foo.com/a", "foo.com/b" ] }; doTest([subUpdate1, subUpdate2, addUpdate], assertions); @@ -297,24 +288,24 @@ function testSubsDifferentChunksSameHostId() { var addUrls2 = [ "foo.com/c" ]; var subUpdate1 = buildPhishingUpdate( - [{ "chunkNum" : 1, - "chunkType" : "s", + [{ "chunkNum": 1, + "chunkType": "s", "urls": subUrls1 }]); var subUpdate2 = buildPhishingUpdate( - [{ "chunkNum" : 2, - "chunkType" : "s", - "urls" : subUrls2 }]); + [{ "chunkNum": 2, + "chunkType": "s", + "urls": subUrls2 }]); var addUpdate = buildPhishingUpdate( - [{ "chunkNum" : 1, - "urls" : addUrls }]); + [{ "chunkNum": 1, + "urls": addUrls }]); var addUpdate2 = buildPhishingUpdate( - [{ "chunkNum" : 2, - "urls" : addUrls2 }]); + [{ "chunkNum": 2, + "urls": addUrls2 }]); var assertions = { - "tableData" : "test-phish-simple;a:1-2:s:1-2", - "urlsDontExist" : [ "foo.com/c", "foo.com/b", "foo.com/a", ], + "tableData": "test-phish-simple;a:1-2:s:1-2", + "urlsDontExist": [ "foo.com/c", "foo.com/b", "foo.com/a", ], }; doTest([addUpdate, addUpdate2, subUpdate1, subUpdate2], assertions); @@ -324,42 +315,42 @@ function testSubsDifferentChunksSameHostId() { function testExpireLists() { var addUpdate = buildPhishingUpdate( [ - { "chunkNum" : 1, - "urls" : [ "foo.com/a" ] + { "chunkNum": 1, + "urls": [ "foo.com/a" ] }, - { "chunkNum" : 3, - "urls" : [ "bar.com/a" ] + { "chunkNum": 3, + "urls": [ "bar.com/a" ] }, - { "chunkNum" : 4, - "urls" : [ "baz.com/a" ] + { "chunkNum": 4, + "urls": [ "baz.com/a" ] }, - { "chunkNum" : 5, - "urls" : [ "blah.com/a" ] + { "chunkNum": 5, + "urls": [ "blah.com/a" ] }, ]); var subUpdate = buildPhishingUpdate( [ - { "chunkNum" : 1, - "chunkType" : "s", - "urls" : [ "50:foo.com/1" ] + { "chunkNum": 1, + "chunkType": "s", + "urls": [ "50:foo.com/1" ] }, - { "chunkNum" : 2, - "chunkType" : "s", - "urls" : [ "50:bar.com/1" ] + { "chunkNum": 2, + "chunkType": "s", + "urls": [ "50:bar.com/1" ] }, - { "chunkNum" : 3, - "chunkType" : "s", - "urls" : [ "50:baz.com/1" ] + { "chunkNum": 3, + "chunkType": "s", + "urls": [ "50:baz.com/1" ] }, - { "chunkNum" : 5, - "chunkType" : "s", - "urls" : [ "50:blah.com/1" ] + { "chunkNum": 5, + "chunkType": "s", + "urls": [ "50:blah.com/1" ] }, ]); var expireUpdate = buildPhishingUpdate( - [ { "chunkType" : "ad:1,3-5" }, - { "chunkType" : "sd:1-3,5" }]); + [ { "chunkType": "ad:1,3-5" }, + { "chunkType": "sd:1-3,5" }]); var assertions = { // "tableData" : "test-phish-simple;" @@ -375,17 +366,17 @@ function testDuplicateAddChunks() { var addUrls2 = [ "bar.com/b" ]; var update = buildPhishingUpdate( [ - { "chunkNum" : 1, - "urls" : addUrls1 + { "chunkNum": 1, + "urls": addUrls1 }, - { "chunkNum" : 1, - "urls" : addUrls2 + { "chunkNum": 1, + "urls": addUrls2 }]); var assertions = { - "tableData" : "test-phish-simple;a:1", - "urlsExist" : addUrls1, - "urlsDontExist" : addUrls2 + "tableData": "test-phish-simple;a:1", + "urlsExist": addUrls1, + "urlsDontExist": addUrls2 }; doTest([update], assertions); @@ -396,18 +387,17 @@ function testDuplicateAddChunks() { // that we need to add the same add chunk twice, with an expiration // in the middle. This would be easier if subsDontExist actually // worked... -function testExpireWholeSub() -{ +function testExpireWholeSub() { var subUrls = ["1:foo.com/a"]; var update = buildPhishingUpdate( - [{ "chunkNum" : 5, - "chunkType" : "s", - "urls" : subUrls + [{ "chunkNum": 5, + "chunkType": "s", + "urls": subUrls }, // empty add chunk should still cause foo.com/a to go away. - { "chunkNum" : 1, - "urls" : [] + { "chunkNum": 1, + "urls": [] }, // and now adding chunk 1 again with foo.com/a should succeed, // 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. { - "chunkType" : "ad:1" + "chunkType": "ad:1" }, - { "chunkNum" : 1, - "urls" : [ "foo.com/a" ] + { "chunkNum": 1, + "urls": [ "foo.com/a" ] }]); var assertions = { - "tableData" : "test-phish-simple;a:1:s:5", - "urlsExist" : ["foo.com/a"] + "tableData": "test-phish-simple;a:1:s:5", + "urlsExist": ["foo.com/a"] }; doTest([update], assertions); @@ -433,18 +423,17 @@ function testExpireWholeSub() // This test is roughly the opposite of testExpireWholeSub(). We add // the empty add first, and make sure that it prevents a sub for that // add from being applied. -function testPreventWholeSub() -{ +function testPreventWholeSub() { var subUrls = ["1:foo.com/a"]; var update = buildPhishingUpdate( [ // empty add chunk should cause foo.com/a to not be saved - { "chunkNum" : 1, - "urls" : [] + { "chunkNum": 1, + "urls": [] }, - { "chunkNum" : 5, - "chunkType" : "s", - "urls" : subUrls + { "chunkNum": 5, + "chunkType": "s", + "urls": subUrls }, // and now adding chunk 1 again with foo.com/a should succeed, // 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. { - "chunkType" : "ad:1" + "chunkType": "ad:1" }, - { "chunkNum" : 1, - "urls" : [ "foo.com/a" ] + { "chunkNum": 1, + "urls": [ "foo.com/a" ] }]); var assertions = { - "tableData" : "test-phish-simple;a:1:s:5", - "urlsExist" : ["foo.com/a"] + "tableData": "test-phish-simple;a:1:s:5", + "urlsExist": ["foo.com/a"] }; doTest([update], assertions); } -function run_test() -{ +function run_test() { runTests([ testSimpleAdds, testMultipleAdds, diff --git a/toolkit/components/url-classifier/tests/unit/test_bug1274685_unowned_list.js b/toolkit/components/url-classifier/tests/unit/test_bug1274685_unowned_list.js index 037bc7b884d9..a8a01d3252e4 100644 --- a/toolkit/components/url-classifier/tests/unit/test_bug1274685_unowned_list.js +++ b/toolkit/components/url-classifier/tests/unit/test_bug1274685_unowned_list.js @@ -13,7 +13,7 @@ function run_test() { let origList = Services.prefs.getCharPref("browser.safebrowsing.provider.google.lists"); // 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); try { @@ -25,7 +25,7 @@ function run_test() { // SafeBrowsing.registerTables(); } 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); diff --git a/toolkit/components/url-classifier/tests/unit/test_dbservice.js b/toolkit/components/url-classifier/tests/unit/test_dbservice.js index c9fe4b7dd9ec..db5b85cf1573 100644 --- a/toolkit/components/url-classifier/tests/unit/test_dbservice.js +++ b/toolkit/components/url-classifier/tests/unit/test_dbservice.js @@ -105,8 +105,7 @@ function testFailure(arg) { do_throw(arg); } -function checkNoHost() -{ +function checkNoHost() { // Looking up a no-host uri such as a data: uri should throw an exception. var exception; try { @@ -114,7 +113,7 @@ function checkNoHost() dbservice.lookup(principal, allTables); exception = false; - } catch(e) { + } catch (e) { exception = true; } do_check_true(exception); @@ -122,8 +121,7 @@ function checkNoHost() do_test_finished(); } -function tablesCallbackWithoutSub(tables) -{ +function tablesCallbackWithoutSub(tables) { var parts = tables.split("\n"); parts.sort(); @@ -140,8 +138,7 @@ function expireSubSuccess(result) { dbservice.getTables(tablesCallbackWithoutSub); } -function tablesCallbackWithSub(tables) -{ +function tablesCallbackWithSub(tables) { var parts = tables.split("\n"); parts.sort(); @@ -159,8 +156,7 @@ function tablesCallbackWithSub(tables) doSimpleUpdate(data, expireSubSuccess, testFailure); } -function checkChunksWithSub() -{ +function checkChunksWithSub() { dbservice.getTables(tablesCallbackWithSub); } @@ -217,8 +213,7 @@ function blockedExists(result) { } } -function checkState() -{ +function checkState() { numExpecting = 0; @@ -253,8 +248,7 @@ function checkState() } } -function testSubSuccess(result) -{ +function testSubSuccess(result) { do_check_eq(result, "1000"); checkState(); } diff --git a/toolkit/components/url-classifier/tests/unit/test_hashcompleter.js b/toolkit/components/url-classifier/tests/unit/test_hashcompleter.js index 8bac2d38bf59..7f4311d23a9a 100644 --- a/toolkit/components/url-classifier/tests/unit/test_hashcompleter.js +++ b/toolkit/components/url-classifier/tests/unit/test_hashcompleter.js @@ -194,7 +194,7 @@ function getRandomCompletionSet(forceServerError) { let length = 1 + rand.nextNum(5); for (let i = 0; i < length; i++) hash += String.fromCharCode(rand.nextNum(8)); - prefix = hash.substring(0,4); + prefix = hash.substring(0, 4); } while (hashPrefixes.indexOf(prefix) != -1); hashPrefixes.push(prefix); @@ -261,8 +261,7 @@ function run_test() { let numChars = COMPLETE_LENGTH - responseCompletion.hash.length; responseCompletion.hash += (new Array(numChars + 1)).join("\u0000"); } - } - else { + } else { let numChars = COMPLETE_LENGTH - completion.hash.length; completion.hash += (new Array(numChars + 1)).join("\u0000"); } @@ -295,7 +294,7 @@ function runNextCompletion() { // Number of finished completions for this set. finishedCompletions = 0; 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. (new callback(completion))); } @@ -372,8 +371,7 @@ callback.prototype = { break; } } - } - else { + } else { // Hashes are not actually strings and can contain arbitrary data. do_check_eq(JSON.stringify(hash), JSON.stringify(this._completion.hash)); do_check_eq(table, this._completion.table); diff --git a/toolkit/components/url-classifier/tests/unit/test_listmanager.js b/toolkit/components/url-classifier/tests/unit/test_listmanager.js index d78f90f62500..8bb077deb96e 100644 --- a/toolkit/components/url-classifier/tests/unit/test_listmanager.js +++ b/toolkit/components/url-classifier/tests/unit/test_listmanager.js @@ -68,8 +68,8 @@ let gHttpServV4 = null; let gUpdatedCntForTableData = 0; // For TEST_TABLE_DATA_LIST. let gIsV4Updated = false; // For TEST_TABLE_DATA_V4. -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 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"; prefBranch.setBoolPref("browser.safebrowsing.debug", true); @@ -184,7 +184,7 @@ add_test(function test_partialUpdateV4() { // Tests nsIUrlListManager.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(TEST_TABLE_DATA_V4.tableName), @@ -245,8 +245,8 @@ function run_test() { // V4 append the base64 encoded request to the query string. 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 // send a meaningful response to test Bug 1284178 to see if the diff --git a/toolkit/components/url-classifier/tests/unit/test_partial.js b/toolkit/components/url-classifier/tests/unit/test_partial.js index 4bb375e0031e..f2fda5c0cd08 100644 --- a/toolkit/components/url-classifier/tests/unit/test_partial.js +++ b/toolkit/components/url-classifier/tests/unit/test_partial.js @@ -11,8 +11,7 @@ function DummyCompleter() { DummyCompleter.prototype = { -QueryInterface: function(iid) -{ +QueryInterface(iid) { if (!iid.equals(Ci.nsISupports) && !iid.equals(Ci.nsIUrlClassifierHashCompleter)) { throw Cr.NS_ERROR_NO_INTERFACE; @@ -20,8 +19,7 @@ QueryInterface: function(iid) return this; }, -complete: function(partialHash, gethashUrl, tableName, cb) -{ +complete(partialHash, gethashUrl, tableName, cb) { this.queries.push(partialHash); var fragments = this.fragments; var self = this; @@ -43,8 +41,7 @@ complete: function(partialHash, gethashUrl, tableName, cb) var timer = new Timer(0, doCallback); }, -getHash: function(fragment) -{ +getHash(fragment) { var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]. createInstance(Ci.nsIScriptableUnicodeConverter); converter.charset = "UTF-8"; @@ -56,22 +53,19 @@ getHash: function(fragment) return hash.slice(0, 32); }, -addFragment: function(chunkId, fragment) -{ +addFragment(chunkId, fragment) { this.addHash(chunkId, this.getHash(fragment)); }, // This method allows the caller to generate complete hashes that match the // prefix of a real fragment, but have different complete hashes. -addConflict: function(chunkId, fragment) -{ +addConflict(chunkId, fragment) { var realHash = this.getHash(fragment); var invalidHash = this.getHash("blah blah blah blah blah"); this.addHash(chunkId, realHash.slice(0, 4) + invalidHash.slice(4, 32)); }, -addHash: function(chunkId, hash) -{ +addHash(chunkId, hash) { var partial = hash.slice(0, 4); if (this.fragments[partial]) { this.fragments[partial].push([chunkId, hash]); @@ -80,8 +74,7 @@ addHash: function(chunkId, hash) } }, -compareQueries: function(fragments) -{ +compareQueries(fragments) { var expectedQueries = []; for (var i = 0; i < fragments.length; i++) { 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(); completer.tableName = table; for (var i = 0; i < hits.length; i++) { @@ -119,8 +111,7 @@ function setupCompleter(table, hits, conflicts) return completer; } -function installCompleter(table, fragments, conflictFragments) -{ +function installCompleter(table, fragments, conflictFragments) { return setupCompleter(table, fragments, conflictFragments); } @@ -131,15 +122,13 @@ function installFailingCompleter(table) { } // Helper assertion for checking dummy completer queries -gAssertions.completerQueried = function(data, cb) -{ +gAssertions.completerQueried = function(data, cb) { var completer = data[0]; completer.compareQueries(data[1]); cb(); } -function doTest(updates, assertions) -{ +function doTest(updates, assertions) { doUpdateTest(updates, assertions, runNextTest, updateError); } @@ -148,18 +137,18 @@ function testPartialAdds() { var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; var update = buildPhishingUpdate( [ - { "chunkNum" : 1, - "urls" : addUrls + { "chunkNum": 1, + "urls": addUrls }], 4); - var completer = installCompleter('test-phish-simple', [[1, addUrls]], []); + var completer = installCompleter("test-phish-simple", [[1, addUrls]], []); var assertions = { - "tableData" : "test-phish-simple;a:1", - "urlsExist" : addUrls, - "completerQueried" : [completer, addUrls] + "tableData": "test-phish-simple;a:1", + "urlsExist": addUrls, + "completerQueried": [completer, addUrls] }; @@ -170,20 +159,20 @@ function testPartialAddsWithConflicts() { var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; var update = buildPhishingUpdate( [ - { "chunkNum" : 1, - "urls" : addUrls + { "chunkNum": 1, + "urls": addUrls }], 4); // 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]]); var assertions = { - "tableData" : "test-phish-simple;a:1", - "urlsExist" : addUrls, - "completerQueried" : [completer, addUrls] + "tableData": "test-phish-simple;a:1", + "urlsExist": addUrls, + "completerQueried": [completer, addUrls] }; doTest([update], assertions); @@ -194,18 +183,18 @@ function testFragments() { var addUrls = [ "foo.com/a/b/c", "foo.net/", "foo.com/c/" ]; var update = buildPhishingUpdate( [ - { "chunkNum" : 1, - "urls" : addUrls + { "chunkNum": 1, + "urls": addUrls }], 4); - var completer = installCompleter('test-phish-simple', [[1, addUrls]], []); + var completer = installCompleter("test-phish-simple", [[1, addUrls]], []); var assertions = { - "tableData" : "test-phish-simple;a:1", - "urlsExist" : addUrls, - "completerQueried" : [completer, addUrls] + "tableData": "test-phish-simple;a:1", + "urlsExist": addUrls, + "completerQueried": [completer, addUrls] }; @@ -228,18 +217,18 @@ function testSpecFragments() { var update = buildPhishingUpdate( [ - { "chunkNum" : 1, - "urls" : addUrls + { "chunkNum": 1, + "urls": addUrls }], 4); - var completer = installCompleter('test-phish-simple', [[1, addUrls]], []); + var completer = installCompleter("test-phish-simple", [[1, addUrls]], []); var assertions = { - "tableData" : "test-phish-simple;a:1", - "urlsExist" : probeUrls, - "completerQueried" : [completer, addUrls] + "tableData": "test-phish-simple;a:1", + "urlsExist": probeUrls, + "completerQueried": [completer, addUrls] }; doTest([update], assertions); @@ -264,17 +253,17 @@ function testMoreSpecFragments() { var update = buildPhishingUpdate( [ - { "chunkNum" : 1, - "urls" : addUrls + { "chunkNum": 1, + "urls": addUrls }], 4); - var completer = installCompleter('test-phish-simple', [[1, addUrls]], []); + var completer = installCompleter("test-phish-simple", [[1, addUrls]], []); var assertions = { - "tableData" : "test-phish-simple;a:1", - "urlsExist" : probeUrls, - "completerQueried" : [completer, addUrls] + "tableData": "test-phish-simple;a:1", + "urlsExist": probeUrls, + "completerQueried": [completer, addUrls] }; doTest([update], assertions); @@ -285,19 +274,19 @@ function testFalsePositives() { var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; var update = buildPhishingUpdate( [ - { "chunkNum" : 1, - "urls" : addUrls + { "chunkNum": 1, + "urls": addUrls }], 4); // Each result will have no matching complete hashes and a non-matching // conflict - var completer = installCompleter('test-phish-simple', [], [[1, addUrls]]); + var completer = installCompleter("test-phish-simple", [], [[1, addUrls]]); var assertions = { - "tableData" : "test-phish-simple;a:1", - "urlsDontExist" : addUrls, - "completerQueried" : [completer, addUrls] + "tableData": "test-phish-simple;a:1", + "urlsDontExist": addUrls, + "completerQueried": [completer, addUrls] }; doTest([update], assertions); @@ -307,18 +296,18 @@ function testEmptyCompleter() { var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; var update = buildPhishingUpdate( [ - { "chunkNum" : 1, - "urls" : addUrls + { "chunkNum": 1, + "urls": addUrls }], 4); // Completer will never return full hashes - var completer = installCompleter('test-phish-simple', [], []); + var completer = installCompleter("test-phish-simple", [], []); var assertions = { - "tableData" : "test-phish-simple;a:1", - "urlsDontExist" : addUrls, - "completerQueried" : [completer, addUrls] + "tableData": "test-phish-simple;a:1", + "urlsDontExist": addUrls, + "completerQueried": [completer, addUrls] }; doTest([update], assertions); @@ -328,18 +317,18 @@ function testCompleterFailure() { var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; var update = buildPhishingUpdate( [ - { "chunkNum" : 1, - "urls" : addUrls + { "chunkNum": 1, + "urls": addUrls }], 4); // Completer will never return full hashes - var completer = installFailingCompleter('test-phish-simple'); + var completer = installFailingCompleter("test-phish-simple"); var assertions = { - "tableData" : "test-phish-simple;a:1", - "urlsDontExist" : addUrls, - "completerQueried" : [completer, addUrls] + "tableData": "test-phish-simple;a:1", + "urlsDontExist": addUrls, + "completerQueried": [completer, addUrls] }; doTest([update], assertions); @@ -351,24 +340,24 @@ function testMixedSizesSameDomain() { var update1 = buildPhishingUpdate( [ - { "chunkNum" : 1, - "urls" : add1Urls }], + { "chunkNum": 1, + "urls": add1Urls }], 4); var update2 = buildPhishingUpdate( [ - { "chunkNum" : 2, - "urls" : add2Urls }], + { "chunkNum": 2, + "urls": add2Urls }], 32); // 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 = { - "tableData" : "test-phish-simple;a:1-2", + "tableData": "test-phish-simple;a:1-2", // both urls should match... - "urlsExist" : add1Urls.concat(add2Urls), + "urlsExist": add1Urls.concat(add2Urls), // ... but the completer should only be queried for the partial entry - "completerQueried" : [completer, add1Urls] + "completerQueried": [completer, add1Urls] }; doTest([update1, update2], assertions); @@ -380,68 +369,66 @@ function testMixedSizesDifferentDomains() { var update1 = buildPhishingUpdate( [ - { "chunkNum" : 1, - "urls" : add1Urls }], + { "chunkNum": 1, + "urls": add1Urls }], 4); var update2 = buildPhishingUpdate( [ - { "chunkNum" : 2, - "urls" : add2Urls }], + { "chunkNum": 2, + "urls": add2Urls }], 32); // 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 = { - "tableData" : "test-phish-simple;a:1-2", + "tableData": "test-phish-simple;a:1-2", // both urls should match... - "urlsExist" : add1Urls.concat(add2Urls), + "urlsExist": add1Urls.concat(add2Urls), // ... but the completer should only be queried for the partial entry - "completerQueried" : [completer, add1Urls] + "completerQueried": [completer, add1Urls] }; doTest([update1, update2], assertions); } -function testInvalidHashSize() -{ +function testInvalidHashSize() { var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; var update = buildPhishingUpdate( [ - { "chunkNum" : 1, - "urls" : addUrls + { "chunkNum": 1, + "urls": addUrls }], 12); // only 4 and 32 are legal hash sizes var addUrls2 = [ "zaz.com/a", "xyz.com/b" ]; var update2 = buildPhishingUpdate( [ - { "chunkNum" : 2, - "urls" : addUrls2 + { "chunkNum": 2, + "urls": addUrls2 }], 4); - var completer = installCompleter('test-phish-simple', [[1, addUrls]], []); + var completer = installCompleter("test-phish-simple", [[1, addUrls]], []); var assertions = { - "tableData" : "test-phish-simple;a:2", - "urlsDontExist" : addUrls + "tableData": "test-phish-simple;a:2", + "urlsDontExist": addUrls }; // A successful update will trigger an error doUpdateTest([update2, update], assertions, updateError, runNextTest); } -function testWrongTable() -{ +function testWrongTable() { var addUrls = [ "foo.com/a" ]; var update = buildPhishingUpdate( [ - { "chunkNum" : 1, - "urls" : addUrls + { "chunkNum": 1, + "urls": addUrls }], 4); - var completer = installCompleter('test-malware-simple', // wrong table + var completer = installCompleter("test-malware-simple", // wrong table [[1, addUrls]], []); // The above installCompleter installs the completer for test-malware-simple, @@ -450,13 +437,13 @@ function testWrongTable() 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 // 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. - "urlsDontExist" : addUrls, + "urlsDontExist": addUrls, // Make sure the completer was actually queried. - "completerQueried" : [completer, addUrls] + "completerQueried": [completer, addUrls] }; doUpdateTest([update], assertions, @@ -466,34 +453,33 @@ function testWrongTable() // The miss earlier will have caused a miss to be cached. // Resetting the completer does not count as an update, // 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); var assertions = { - "urlsDontExist" : addUrls + "urlsDontExist": addUrls }; checkAssertions(assertions, runNextTest); }); }, updateError); } -function setupCachedResults(addUrls, part2) -{ +function setupCachedResults(addUrls, part2) { var update = buildPhishingUpdate( [ - { "chunkNum" : 1, - "urls" : addUrls + { "chunkNum": 1, + "urls": addUrls }], 4); - var completer = installCompleter('test-phish-simple', [[1, addUrls]], []); + var completer = installCompleter("test-phish-simple", [[1, addUrls]], []); 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. - "urlsExist" : addUrls, + "urlsExist": addUrls, // Make sure the completer was actually queried. - "completerQueried" : [completer, addUrls] + "completerQueried": [completer, addUrls] }; doUpdateTest([update], assertions, @@ -503,18 +489,17 @@ function setupCachedResults(addUrls, part2) }, updateError); } -function testCachedResults() -{ +function testCachedResults() { setupCachedResults(["foo.com/a"], function(add) { // This is called after setupCachedResults(). Verify that // checking the url again does not cause a completer request. // 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 = { - "urlsExist" : ["foo.com/a"], - "completerQueried" : [newCompleter, []] + "urlsExist": ["foo.com/a"], + "completerQueried": [newCompleter, []] }; checkAssertions(assertions, runNextTest); }); @@ -523,17 +508,17 @@ function testCachedResults() function testCachedResultsWithSub() { setupCachedResults(["foo.com/a"], function() { // 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( - [ { "chunkNum" : 2, - "chunkType" : "s", + [ { "chunkNum": 2, + "chunkType": "s", "urls": ["1:foo.com/a"] }], 4); var assertions = { - "urlsDontExist" : ["foo.com/a"], - "completerQueried" : [newCompleter, []] + "urlsDontExist": ["foo.com/a"], + "completerQueried": [newCompleter, []] } doTest([removeUpdate], assertions); @@ -543,7 +528,7 @@ function testCachedResultsWithSub() { function testCachedResultsWithExpire() { setupCachedResults(["foo.com/a"], function() { // 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 = "n:1000\n" + @@ -551,34 +536,33 @@ function testCachedResultsWithExpire() { "ad:1\n"; var assertions = { - "urlsDontExist" : ["foo.com/a"], - "completerQueried" : [newCompleter, []] + "urlsDontExist": ["foo.com/a"], + "completerQueried": [newCompleter, []] } doTest([expireUpdate], assertions); }); } -function testCachedResultsFailure() -{ +function testCachedResultsFailure() { var existUrls = ["foo.com/a"]; setupCachedResults(existUrls, function() { // This is called after setupCachedResults(). Verify that // checking the url again does not cause a completer request. // 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 = { - "urlsExist" : existUrls, - "completerQueried" : [newCompleter, []] + "urlsExist": existUrls, + "completerQueried": [newCompleter, []] }; var addUrls = ["foobar.org/a"]; var update2 = buildPhishingUpdate( [ - { "chunkNum" : 2, - "urls" : addUrls + { "chunkNum": 2, + "urls": addUrls }], 4); @@ -586,11 +570,11 @@ function testCachedResultsFailure() // Apply the update. The cached completes should be gone. doErrorUpdate("test-phish-simple,test-malware-simple", function() { // Now the completer gets queried again. - var newCompleter2 = installCompleter('test-phish-simple', [[1, existUrls]], []); + var newCompleter2 = installCompleter("test-phish-simple", [[1, existUrls]], []); var assertions2 = { - "tableData" : "test-phish-simple;a:1", - "urlsExist" : existUrls, - "completerQueried" : [newCompleter2, existUrls] + "tableData": "test-phish-simple;a:1", + "urlsExist": existUrls, + "completerQueried": [newCompleter2, existUrls] }; checkAssertions(assertions2, runNextTest); }, updateError); @@ -598,26 +582,25 @@ function testCachedResultsFailure() }); } -function testErrorList() -{ +function testErrorList() { var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ]; var update = buildPhishingUpdate( [ - { "chunkNum" : 1, - "urls" : addUrls + { "chunkNum": 1, + "urls": addUrls }], 4); // 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. - var completer = installCompleter('test-phish-simple', [[1, addUrls]], []); + var completer = installCompleter("test-phish-simple", [[1, addUrls]], []); var assertions = { - "tableData" : "test-phish-simple;a:1", - "urlsExist" : addUrls, + "tableData": "test-phish-simple;a:1", + "urlsExist": addUrls, // These are complete urls, and will only be completed if the // list is stale. - "completerQueried" : [completer, addUrls] + "completerQueried": [completer, addUrls] }; // Apply the update. @@ -634,14 +617,13 @@ function testErrorList() // Verify that different lists (test-phish-simple, // test-malware-simple) maintain their freshness separately. -function testErrorListIndependent() -{ +function testErrorListIndependent() { var phishUrls = [ "phish.com/a" ]; var malwareUrls = [ "attack.com/a" ]; var update = buildPhishingUpdate( [ - { "chunkNum" : 1, - "urls" : phishUrls + { "chunkNum": 1, + "urls": phishUrls }], 4); // These have to persist past the update failure, so they must be prefixes, @@ -649,20 +631,20 @@ function testErrorListIndependent() update += buildMalwareUpdate( [ - { "chunkNum" : 2, - "urls" : malwareUrls + { "chunkNum": 2, + "urls": malwareUrls }], 32); - var completer = installCompleter('test-phish-simple', [[1, phishUrls]], []); + var completer = installCompleter("test-phish-simple", [[1, phishUrls]], []); var assertions = { - "tableData" : "test-malware-simple;a:2\ntest-phish-simple;a:1", - "urlsExist" : phishUrls, - "malwareUrlsExist" : malwareUrls, + "tableData": "test-malware-simple;a:2\ntest-phish-simple;a:1", + "urlsExist": phishUrls, + "malwareUrlsExist": malwareUrls, // Only this phishing urls should be completed, because only the phishing // urls will be stale. - "completerQueried" : [completer, phishUrls] + "completerQueried": [completer, phishUrls] }; // Apply the update. @@ -677,8 +659,7 @@ function testErrorListIndependent() }, updateError); } -function run_test() -{ +function run_test() { runTests([ testPartialAdds, testPartialAddsWithConflicts, diff --git a/toolkit/components/url-classifier/tests/unit/test_pref.js b/toolkit/components/url-classifier/tests/unit/test_pref.js index 68030a2466f8..09e56c4bba94 100644 --- a/toolkit/components/url-classifier/tests/unit/test_pref.js +++ b/toolkit/components/url-classifier/tests/unit/test_pref.js @@ -11,4 +11,4 @@ function run_test() { // Unknown provider version will be "2.2". equal(urlUtils.getProtocolVersion("unknown-provider"), "2.2"); -} \ No newline at end of file +} diff --git a/toolkit/components/url-classifier/tests/unit/test_prefixset.js b/toolkit/components/url-classifier/tests/unit/test_prefixset.js index f2ecc9c2b30c..dc06aa263865 100644 --- a/toolkit/components/url-classifier/tests/unit/test_prefixset.js +++ b/toolkit/components/url-classifier/tests/unit/test_prefixset.js @@ -18,9 +18,9 @@ function arrContains(arr, target) { let value = arr[i]; if (value < target) - start = i+1; + start = i + 1; else if (value > target) - end = i-1; + end = i - 1; else break; } @@ -37,7 +37,7 @@ function checkContents(pset, prefixes) { outset = pset.getPrefixes(outcount); let inset = prefixes; 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++) { do_check_eq(inset[i], outset[i]); } @@ -45,7 +45,7 @@ function checkContents(pset, prefixes) { function wrappedProbe(pset, prefix) { return pset.contains(prefix); -}; +} // doRandomLookups: we use this to test for false membership with random input // over the range of prefixes (unsigned 32-bits integers). @@ -67,7 +67,7 @@ function doRandomLookups(pset, prefixes, N) { // prefixes: function doExpectedLookups(pset, prefixes, N) { for (let i = 0; i < N; i++) { - prefixes.forEach(function (x) { + prefixes.forEach(function(x) { dump("Checking " + x + "\n"); do_check_true(wrappedProbe(pset, x)); }); @@ -79,7 +79,7 @@ function doExpectedLookups(pset, prefixes, N) { function testBasicPset() { let pset = Cc["@mozilla.org/url-classifier/prefixset;1"] .createInstance(Ci.nsIUrlClassifierPrefixSet); - let prefixes = [2,50,100,2000,78000,1593203]; + let prefixes = [2, 50, 100, 2000, 78000, 1593203]; pset.setPrefixes(prefixes, prefixes.length); do_check_true(wrappedProbe(pset, 100)); @@ -95,7 +95,7 @@ function testBasicPset() { function testDuplicates() { let pset = Cc["@mozilla.org/url-classifier/prefixset;1"] .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); do_check_true(wrappedProbe(pset, 1)); @@ -111,7 +111,7 @@ function testDuplicates() { function testSimplePset() { let pset = newPset(); - let prefixes = [1,2,100,400,123456789]; + let prefixes = [1, 2, 100, 400, 123456789]; pset.setPrefixes(prefixes, prefixes.length); doRandomLookups(pset, prefixes, 100); @@ -149,7 +149,7 @@ function testLoadSaveLargeSet() { arr.push(randInt); } - arr.sort((x,y) => x - y); + arr.sort((x, y) => x - y); let pset = newPset(); pset.setPrefixes(arr, arr.length); @@ -160,7 +160,7 @@ function testLoadSaveLargeSet() { checkContents(pset, arr); // 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"); pset.storeToFile(file); @@ -205,7 +205,7 @@ function testLoadSaveNoDelta() { doExpectedLookups(pset, arr, 1); - var file = dirSvc.get('ProfLD', Ci.nsIFile); + var file = dirSvc.get("ProfLD", Ci.nsIFile); file.append("testNoDelta.pset"); pset.storeToFile(file); diff --git a/toolkit/components/url-classifier/tests/unit/test_safebrowsing_protobuf.js b/toolkit/components/url-classifier/tests/unit/test_safebrowsing_protobuf.js index 45309ba54ed8..38b9e3ed3d03 100644 --- a/toolkit/components/url-classifier/tests/unit/test_safebrowsing_protobuf.js +++ b/toolkit/components/url-classifier/tests/unit/test_safebrowsing_protobuf.js @@ -20,4 +20,4 @@ function run_test() { equal(requestNoList, requestOneInvalid); equal(requestOneValid, requestOneInvalidOneValid); -} \ No newline at end of file +} diff --git a/toolkit/components/url-classifier/tests/unit/test_streamupdater.js b/toolkit/components/url-classifier/tests/unit/test_streamupdater.js index cc1f94de1e0d..89665362cfc5 100644 --- a/toolkit/components/url-classifier/tests/unit/test_streamupdater.js +++ b/toolkit/components/url-classifier/tests/unit/test_streamupdater.js @@ -1,5 +1,4 @@ -function doTest(updates, assertions, expectError) -{ +function doTest(updates, assertions, expectError) { if (expectError) { doUpdateTest(updates, assertions, updateError, runNextTest); } else { @@ -16,13 +15,13 @@ function testFillDb() { update += "i:test-phish-simple\n"; var update1 = buildBareUpdate( - [{ "chunkNum" : 1, - "urls" : add1Urls }]); + [{ "chunkNum": 1, + "urls": add1Urls }]); update += "u:data:," + encodeURIComponent(update1) + "\n"; var assertions = { - "tableData" : "test-phish-simple;a:1", - "urlsExist" : add1Urls + "tableData": "test-phish-simple;a:1", + "urlsExist": add1Urls }; doTest([update], assertions, false); @@ -37,23 +36,23 @@ function testSimpleForward() { update += "i:test-phish-simple\n"; var update1 = buildBareUpdate( - [{ "chunkNum" : 1, - "urls" : add1Urls }]); + [{ "chunkNum": 1, + "urls": add1Urls }]); update += "u:data:," + encodeURIComponent(update1) + "\n"; var update2 = buildBareUpdate( - [{ "chunkNum" : 2, - "urls" : add2Urls }]); + [{ "chunkNum": 2, + "urls": add2Urls }]); update += "u:data:," + encodeURIComponent(update2) + "\n"; var update3 = buildBareUpdate( - [{ "chunkNum" : 3, - "urls" : add3Urls }]); + [{ "chunkNum": 3, + "urls": add3Urls }]); update += "u:data:," + encodeURIComponent(update3) + "\n"; var assertions = { - "tableData" : "test-phish-simple;a:1-3", - "urlsExist" : add1Urls.concat(add2Urls).concat(add3Urls) + "tableData": "test-phish-simple;a:1-3", + "urlsExist": add1Urls.concat(add2Urls).concat(add3Urls) }; doTest([update], assertions, false); @@ -69,23 +68,23 @@ function testNestedForward() { update += "i:test-phish-simple\n"; var update1 = buildBareUpdate( - [{ "chunkNum" : 1, - "urls" : add1Urls }]); + [{ "chunkNum": 1, + "urls": add1Urls }]); update += "u:data:," + encodeURIComponent(update1) + "\n"; var update2 = buildBareUpdate( - [{ "chunkNum" : 2 }]); + [{ "chunkNum": 2 }]); var update3 = buildBareUpdate( - [{ "chunkNum" : 3, - "urls" : add1Urls }]); + [{ "chunkNum": 3, + "urls": add1Urls }]); update2 += "u:data:," + encodeURIComponent(update3) + "\n"; update += "u:data:," + encodeURIComponent(update2) + "\n"; var assertions = { - "tableData" : "", - "urlsDontExist" : add1Urls.concat(add2Urls) + "tableData": "", + "urlsDontExist": add1Urls.concat(add2Urls) }; doTest([update], assertions, true); @@ -96,14 +95,14 @@ function testInvalidUrlForward() { var add1Urls = [ "foo-invalid.com/a", "bar-invalid.com/c" ]; var update = buildPhishingUpdate( - [{ "chunkNum" : 1, - "urls" : add1Urls }]); + [{ "chunkNum": 1, + "urls": add1Urls }]); update += "u:asdf://blah/blah\n"; // invalid URL scheme // add1Urls is present, but that is an artifact of the way we do the test. var assertions = { - "tableData" : "test-phish-simple;a:1", - "urlsExist" : add1Urls + "tableData": "test-phish-simple;a:1", + "urlsExist": add1Urls }; doTest([update], assertions, true); @@ -114,14 +113,14 @@ function testErrorUrlForward() { var add1Urls = [ "foo-forward.com/a", "bar-forward.com/c" ]; var update = buildPhishingUpdate( - [{ "chunkNum" : 1, - "urls" : add1Urls }]); + [{ "chunkNum": 1, + "urls": add1Urls }]); 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. var assertions = { - "tableData" : "test-phish-simple;a:1", - "urlsExist" : add1Urls + "tableData": "test-phish-simple;a:1", + "urlsExist": add1Urls }; doTest([update], assertions, true); @@ -138,40 +137,40 @@ function testMultipleTables() { update += "i:test-phish-simple\n"; var update1 = buildBareUpdate( - [{ "chunkNum" : 1, - "urls" : add1Urls }]); + [{ "chunkNum": 1, + "urls": add1Urls }]); update += "u:data:," + encodeURIComponent(update1) + "\n"; var update2 = buildBareUpdate( - [{ "chunkNum" : 2, - "urls" : add2Urls }]); + [{ "chunkNum": 2, + "urls": add2Urls }]); update += "u:data:," + encodeURIComponent(update2) + "\n"; update += "i:test-malware-simple\n"; var update3 = buildBareUpdate( - [{ "chunkNum" : 3, - "urls" : add3Urls }]); + [{ "chunkNum": 3, + "urls": add3Urls }]); update += "u:data:," + encodeURIComponent(update3) + "\n"; update += "i:test-unwanted-simple\n"; var update4 = buildBareUpdate( - [{ "chunkNum" : 4, - "urls" : add4Urls }]); + [{ "chunkNum": 4, + "urls": add4Urls }]); update += "u:data:," + encodeURIComponent(update4) + "\n"; update += "i:test-block-simple\n"; var update6 = buildBareUpdate( - [{ "chunkNum" : 6, - "urls" : add6Urls }]); + [{ "chunkNum": 6, + "urls": add6Urls }]); update += "u:data:," + encodeURIComponent(update6) + "\n"; var assertions = { - "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), - "malwareUrlsExist" : add3Urls, - "unwantedUrlsExist" : add4Urls, - "blockedUrlsExist" : add6Urls + "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), + "malwareUrlsExist": add3Urls, + "unwantedUrlsExist": add4Urls, + "blockedUrlsExist": add6Urls }; doTest([update], assertions, false); @@ -184,25 +183,25 @@ function testUrlInMultipleTables() { update += "i:test-phish-simple\n"; var update1 = buildBareUpdate( - [{ "chunkNum" : 1, - "urls" : add1Urls }]); + [{ "chunkNum": 1, + "urls": add1Urls }]); update += "u:data:," + encodeURIComponent(update1) + "\n"; update += "i:test-malware-simple\n"; var update2 = buildBareUpdate( - [{ "chunkNum" : 2, - "urls" : add1Urls }]); + [{ "chunkNum": 2, + "urls": add1Urls }]); update += "u:data:," + encodeURIComponent(update2) + "\n"; update += "i:test-unwanted-simple\n"; var update3 = buildBareUpdate( - [{ "chunkNum" : 3, - "urls" : add1Urls }]); + [{ "chunkNum": 3, + "urls": add1Urls }]); update += "u:data:," + encodeURIComponent(update3) + "\n"; var assertions = { - "tableData" : "test-malware-simple;a:2\ntest-phish-simple;a:1\ntest-unwanted-simple;a:3", - "urlExistInMultipleTables" : { url: add1Urls, + "tableData": "test-malware-simple;a:2\ntest-phish-simple;a:1\ntest-unwanted-simple;a:3", + "urlExistInMultipleTables": { url: add1Urls, tables: "test-malware-simple,test-phish-simple,test-unwanted-simple" } }; @@ -215,8 +214,7 @@ function Observer(callback) { Observer.prototype = { -QueryInterface: function(iid) -{ +QueryInterface(iid) { if (!iid.equals(Ci.nsISupports) && !iid.equals(Ci.nsIObserver)) { throw Cr.NS_ERROR_NO_INTERFACE; @@ -233,8 +231,8 @@ function testReset() { var mozAddUrls = [ "moz-reset.com/a" ]; var mozUpdate = buildMozPhishingUpdate( [ - { "chunkNum" : 1, - "urls" : mozAddUrls + { "chunkNum": 1, + "urls": mozAddUrls }]); var dataUpdate = "data:," + encodeURIComponent(mozUpdate); @@ -245,8 +243,8 @@ function testReset() { var addUrls1 = [ "foo-reset.com/a", "foo-reset.com/b" ]; var update1 = buildPhishingUpdate( [ - { "chunkNum" : 1, - "urls" : addUrls1 + { "chunkNum": 1, + "urls": addUrls1 }]); var update2 = "n:1000\nr:pleasereset\n"; @@ -254,16 +252,16 @@ function testReset() { var addUrls3 = [ "bar-reset.com/a", "bar-reset.com/b" ]; var update3 = buildPhishingUpdate( [ - { "chunkNum" : 3, - "urls" : addUrls3 + { "chunkNum": 3, + "urls": addUrls3 }]); var assertions = { - "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 + "tableData": "moz-phish-simple;a:1\ntest-phish-simple;a:3", // tables that should still be there. + "mozPhishingUrlsExist": mozAddUrls, // mozAddUrls added prior to the reset // but it should still exist after reset. - "urlsExist" : addUrls3, // addUrls3 added after the reset. - "urlsDontExist" : addUrls1 // addUrls1 added prior to the reset + "urlsExist": addUrls3, // addUrls3 added after the reset. + "urlsDontExist": addUrls1 // addUrls1 added prior to the reset }; // Use these update responses in order. The update request only @@ -272,8 +270,7 @@ function testReset() { } -function run_test() -{ +function run_test() { runTests([ testSimpleForward, testNestedForward, diff --git a/toolkit/components/url-classifier/tests/unit/test_threat_type_conversion.js b/toolkit/components/url-classifier/tests/unit/test_threat_type_conversion.js index 023bcab2b34f..f383f930ecd7 100644 --- a/toolkit/components/url-classifier/tests/unit/test_threat_type_conversion.js +++ b/toolkit/components/url-classifier/tests/unit/test_threat_type_conversion.js @@ -36,4 +36,4 @@ function run_test() { urlUtils.convertThreatTypeToListNames(100); ok(false, "Bad threat type should lead to exception."); } catch (e) {} -} \ No newline at end of file +}