Bug 1330014 - Add .eslintrc.js file to /services and run eslint --fix to automatically fix most of the errors. --fix brings the error count down from 4083 to 321 errors. r=markh,standard8

MozReview-Commit-ID: EjyAssqiQk8

--HG--
extra : rebase_source : d783829bc7fced3044d0d076c4786a6957d29bb6
This commit is contained in:
Jared Wein 2017-01-10 12:09:02 -05:00
Родитель 2797c83264
Коммит 81cb5e57b9
199 изменённых файлов: 1827 добавлений и 1873 удалений

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

@ -184,6 +184,12 @@ mobile/android/modules/HomeProvider.jsm
# Uses `#filter substitution`
services/sync/modules/constants.js
# Third party services
services/sync/tps/extensions/mozmill/resource/stdlib/json2.js
services/common/kinto-http-client.js
services/common/kinto-offline-client.js
services/sync/tps/extensions/mozmill
# toolkit/ exclusions
# Not part of the default build

29
services/.eslintrc.js Normal file
Просмотреть файл

@ -0,0 +1,29 @@
"use strict";
module.exports = {
"extends": [
"../toolkit/.eslintrc.js"
],
rules: {
/* These rules are only set to warn temporarily
until they get fixed, at which point their
respective line in this file should be removed. */
"brace-style": "warn",
"consistent-return": "warn",
"no-cond-assign": "warn",
"no-else-return": "warn",
"no-empty": "warn",
"no-ex-assign": "warn",
"no-func-assign": "warn",
"no-irregular-whitespace": "warn",
"no-mixed-spaces-and-tabs": "warn",
"no-native-reassign": "warn",
"no-nested-ternary": "warn",
"no-octal": "warn",
"no-redeclare": "warn",
"no-unreachable": "warn",
"no-unsafe-finally": "warn",
"no-unused-vars": "warn",
"no-useless-call": "warn"
}
};

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

@ -19,13 +19,13 @@ XPCOMUtils.defineLazyModuleGetter(this, "Tabs",
var API_VERSION = 1;
var _CloudSync = function () {
var _CloudSync = function() {
};
_CloudSync.prototype = {
_adapters: null,
get adapters () {
get adapters() {
if (!this._adapters) {
this._adapters = new Adapters();
}
@ -34,7 +34,7 @@ _CloudSync.prototype = {
_bookmarks: null,
get bookmarks () {
get bookmarks() {
if (!this._bookmarks) {
this._bookmarks = new Bookmarks();
}
@ -43,7 +43,7 @@ _CloudSync.prototype = {
_local: null,
get local () {
get local() {
if (!this._local) {
this._local = new Local();
}
@ -52,28 +52,28 @@ _CloudSync.prototype = {
_tabs: null,
get tabs () {
get tabs() {
if (!this._tabs) {
this._tabs = new Tabs();
}
return this._tabs;
},
get tabsReady () {
return this._tabs ? true: false;
get tabsReady() {
return this._tabs ? true : false;
},
get version () {
get version() {
return API_VERSION;
},
};
this.CloudSync = function CloudSync () {
this.CloudSync = function CloudSync() {
return _cloudSyncInternal.instance;
};
Object.defineProperty(CloudSync, "ready", {
get: function () {
get() {
return _cloudSyncInternal.ready;
}
});
@ -83,7 +83,7 @@ var _cloudSyncInternal = {
ready: false,
};
XPCOMUtils.defineLazyGetter(_cloudSyncInternal, "instance", function () {
XPCOMUtils.defineLazyGetter(_cloudSyncInternal, "instance", function() {
_cloudSyncInternal.ready = true;
return new _CloudSync();
}.bind(this));
});

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

@ -9,43 +9,43 @@ this.EXPORTED_SYMBOLS = ["Adapters"];
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/CloudSyncEventSource.jsm");
this.Adapters = function () {
this.Adapters = function() {
let eventTypes = [
"sync",
];
let suspended = true;
let suspend = function () {
let suspend = function() {
if (!suspended) {
Services.obs.removeObserver(observer, "cloudsync:user-sync");
suspended = true;
}
}.bind(this);
};
let resume = function () {
let resume = function() {
if (suspended) {
Services.obs.addObserver(observer, "cloudsync:user-sync", false);
suspended = false;
}
}.bind(this);
};
let eventSource = new EventSource(eventTypes, suspend, resume);
let registeredAdapters = new Map();
function register (name, opts) {
function register(name, opts) {
opts = opts || {};
registeredAdapters.set(name, opts);
}
function unregister (name) {
function unregister(name) {
if (!registeredAdapters.has(name)) {
throw new Error("adapter is not registered: " + name)
}
registeredAdapters.delete(name);
}
function getAdapterNames () {
function getAdapterNames() {
let result = [];
for (let name of registeredAdapters.keys()) {
result.push(name);
@ -53,19 +53,19 @@ this.Adapters = function () {
return result;
}
function getAdapter (name) {
function getAdapter(name) {
if (!registeredAdapters.has(name)) {
throw new Error("adapter is not registered: " + name)
}
return registeredAdapters.get(name);
}
function countAdapters () {
function countAdapters() {
return registeredAdapters.size;
}
let observer = {
observe: function (subject, topic, data) {
observe(subject, topic, data) {
switch (topic) {
case "cloudsync:user-sync":
eventSource.emit("sync");

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

@ -49,18 +49,18 @@ function asyncCallback(ctx, func, args) {
CommonUtils.nextTick(invoke);
}
var Record = function (params) {
var Record = function(params) {
this.id = params.guid;
this.parent = params.parent || null;
this.index = params.position;
this.title = params.title;
this.dateAdded = Math.floor(params.dateAdded/1000);
this.lastModified = Math.floor(params.lastModified/1000);
this.dateAdded = Math.floor(params.dateAdded / 1000);
this.lastModified = Math.floor(params.lastModified / 1000);
this.uri = params.url;
let annos = params.annos || {};
Object.defineProperty(this, "annos", {
get: function () {
get() {
return annos;
},
enumerable: false
@ -95,8 +95,8 @@ Record.prototype = {
version: DATA_VERSION,
};
var Bookmarks = function () {
let createRootFolder = function (name) {
var Bookmarks = function() {
let createRootFolder = function(name) {
let ROOT_FOLDER_ANNO = "cloudsync/rootFolder/" + name;
let ROOT_SHORTCUT_ANNO = "cloudsync/rootShortcut/" + name;
@ -142,7 +142,7 @@ var Bookmarks = function () {
return deferred.promise;
};
let getRootFolder = function (name) {
let getRootFolder = function(name) {
let ROOT_FOLDER_ANNO = "cloudsync/rootFolder/" + name;
let ROOT_SHORTCUT_ANNO = "cloudsync/rootShortcut/" + name;
let deferred = Promise.defer();
@ -166,7 +166,7 @@ var Bookmarks = function () {
return deferred.promise;
};
let deleteRootFolder = function (name) {
let deleteRootFolder = function(name) {
let ROOT_FOLDER_ANNO = "cloudsync/rootFolder/" + name;
let ROOT_SHORTCUT_ANNO = "cloudsync/rootShortcut/" + name;
@ -197,7 +197,7 @@ var Bookmarks = function () {
let rootFolderId = folderIds[0];
PlacesWrapper.removeFolderChildren(rootFolderId).then(
function () {
function() {
return PlacesWrapper.removeItem(rootFolderId);
}
).then(deleteFolderDeferred.resolve, deleteFolderDeferred.reject);
@ -221,23 +221,23 @@ var Bookmarks = function () {
this.Bookmarks = Bookmarks;
var RootFolder = function (rootId, rootName) {
var RootFolder = function(rootId, rootName) {
let suspended = true;
let ignoreAll = false;
let suspend = function () {
let suspend = function() {
if (!suspended) {
PlacesUtils.bookmarks.removeObserver(observer);
suspended = true;
}
}.bind(this);
};
let resume = function () {
let resume = function() {
if (suspended) {
PlacesUtils.bookmarks.addObserver(observer, false);
suspended = false;
}
}.bind(this);
};
let eventTypes = [
"add",
@ -251,7 +251,7 @@ var RootFolder = function (rootId, rootName) {
let folderCache = new FolderCache;
folderCache.insert(rootId, null);
let getCachedFolderIds = function (cache, roots) {
let getCachedFolderIds = function(cache, roots) {
let nodes = [...roots];
let results = [];
@ -264,7 +264,7 @@ var RootFolder = function (rootId, rootName) {
return results;
};
let getLocalItems = function () {
let getLocalItems = function() {
let deferred = Promise.defer();
let folders = getCachedFolderIds(folderCache, folderCache.getChildren(rootId));
@ -288,9 +288,9 @@ var RootFolder = function (rootId, rootName) {
function getParentGuids(results) {
results = Array.prototype.concat.apply([], results);
let promises = [];
results.map(function (result) {
results.map(function(result) {
let promise = PlacesWrapper.localIdToGuid(result.parent).then(
function (guidResult) {
function(guidResult) {
result.parent = guidResult;
return Promise.resolve(result);
},
@ -304,9 +304,9 @@ var RootFolder = function (rootId, rootName) {
function getAnnos(results) {
results = Array.prototype.concat.apply([], results);
let promises = [];
results.map(function (result) {
results.map(function(result) {
let promise = PlacesWrapper.getItemAnnotationsForLocalId(result.id).then(
function (annos) {
function(annos) {
result.annos = annos;
return Promise.resolve(result);
},
@ -325,7 +325,7 @@ var RootFolder = function (rootId, rootName) {
Promise.all(promises)
.then(getParentGuids)
.then(getAnnos)
.then(function (results) {
.then(function(results) {
results = results.map((result) => new Record(result));
deferred.resolve(results);
},
@ -334,7 +334,7 @@ var RootFolder = function (rootId, rootName) {
return deferred.promise;
};
let getLocalItemsById = function (guids) {
let getLocalItemsById = function(guids) {
let deferred = Promise.defer();
let types = [
@ -346,9 +346,9 @@ var RootFolder = function (rootId, rootName) {
function getParentGuids(results) {
let promises = [];
results.map(function (result) {
results.map(function(result) {
let promise = PlacesWrapper.localIdToGuid(result.parent).then(
function (guidResult) {
function(guidResult) {
result.parent = guidResult;
return Promise.resolve(result);
},
@ -361,7 +361,7 @@ var RootFolder = function (rootId, rootName) {
PlacesWrapper.getItemsByGuid(guids, types)
.then(getParentGuids)
.then(function (results) {
.then(function(results) {
results = results.map((result) => new Record(result));
deferred.resolve(results);
},
@ -370,7 +370,7 @@ var RootFolder = function (rootId, rootName) {
return deferred.promise;
};
let _createItem = function (item) {
let _createItem = function(item) {
let deferred = Promise.defer();
function getFolderId() {
@ -432,11 +432,11 @@ var RootFolder = function (rootId, rootName) {
return deferred.promise;
};
let _deleteItem = function (item) {
let _deleteItem = function(item) {
let deferred = Promise.defer();
PlacesWrapper.guidToLocalId(item.id).then(
function (localId) {
function(localId) {
folderCache.remove(localId);
return PlacesWrapper.removeItem(localId);
}
@ -445,11 +445,11 @@ var RootFolder = function (rootId, rootName) {
return deferred.promise;
};
let _updateItem = function (item) {
let _updateItem = function(item) {
let deferred = Promise.defer();
PlacesWrapper.guidToLocalId(item.id).then(
function (localId) {
function(localId) {
let promises = [];
if (item.hasOwnProperty("dateAdded")) {
@ -472,7 +472,7 @@ var RootFolder = function (rootId, rootName) {
let deferred = Promise.defer();
PlacesWrapper.guidToLocalId(item.parent)
.then(
function (parent) {
function(parent) {
let index = item.hasOwnProperty("index") ? item.index : PlacesUtils.bookmarks.DEFAULT_INDEX;
if (CS_FOLDER & item.type) {
folderCache.setParent(localId, parent);
@ -504,7 +504,7 @@ var RootFolder = function (rootId, rootName) {
return deferred.promise;
};
let mergeRemoteItems = function (items) {
let mergeRemoteItems = function(items) {
ignoreAll = true;
let deferred = Promise.defer();
@ -513,10 +513,10 @@ var RootFolder = function (rootId, rootName) {
let updatedItems = [];
let deletedItems = [];
let sortItems = function () {
let sortItems = function() {
let promises = [];
let exists = function (item) {
let exists = function(item) {
let existsDeferred = Promise.defer();
if (!item.id) {
Object.defineProperty(item, "__exists__", {
@ -526,7 +526,7 @@ var RootFolder = function (rootId, rootName) {
existsDeferred.resolve(item);
} else {
PlacesWrapper.guidToLocalId(item.id).then(
function (localId) {
function(localId) {
Object.defineProperty(item, "__exists__", {
value: localId ? true : false,
enumerable: false
@ -539,7 +539,7 @@ var RootFolder = function (rootId, rootName) {
return existsDeferred.promise;
}
let handleSortedItem = function (item) {
let handleSortedItem = function(item) {
if (!item.__exists__ && !item.deleted) {
if (CS_FOLDER == item.type) {
newFolders[item.id] = item;
@ -566,7 +566,7 @@ var RootFolder = function (rootId, rootName) {
return Promise.all(promises);
}
let processNewFolders = function () {
let processNewFolders = function() {
let newFolderGuids = Object.keys(newFolders);
let newFolderRoots = [];
@ -578,14 +578,14 @@ var RootFolder = function (rootId, rootName) {
} else {
newFolderRoots.push(guid);
}
};
}
let promises = [];
for (let guid of newFolderRoots) {
let root = newFolders[guid];
let promise = Promise.resolve();
promise = promise.then(
function () {
function() {
return _createItem(root);
},
Promise.reject.bind(Promise)
@ -596,7 +596,7 @@ var RootFolder = function (rootId, rootName) {
let item = newFolders[items.shift()];
items = items.concat(item._children);
promise = promise.then(
function () {
function() {
return _createItem(item);
},
Promise.reject.bind(Promise)
@ -608,7 +608,7 @@ var RootFolder = function (rootId, rootName) {
return Promise.all(promises);
}
let processItems = function () {
let processItems = function() {
let promises = [];
for (let item of newItems) {
@ -628,11 +628,11 @@ var RootFolder = function (rootId, rootName) {
sortItems().then(processNewFolders)
.then(processItems)
.then(function () {
.then(function() {
ignoreAll = false;
deferred.resolve(items);
},
function (err) {
function(err) {
ignoreAll = false;
deferred.reject(err);
});
@ -640,7 +640,7 @@ var RootFolder = function (rootId, rootName) {
return deferred.promise;
};
let ignore = function (id, parent) {
let ignore = function(id, parent) {
if (ignoreAll) {
return true;
}
@ -652,7 +652,7 @@ var RootFolder = function (rootId, rootName) {
return true;
};
let handleItemAdded = function (id, parent, index, type, uri, title, dateAdded, guid, parentGuid) {
let handleItemAdded = function(id, parent, index, type, uri, title, dateAdded, guid, parentGuid) {
let deferred = Promise.defer();
if (PlacesUtils.bookmarks.TYPE_FOLDER == type) {
@ -665,7 +665,7 @@ var RootFolder = function (rootId, rootName) {
return deferred.promise;
};
let handleItemRemoved = function (id, parent, index, type, uri, guid, parentGuid) {
let handleItemRemoved = function(id, parent, index, type, uri, guid, parentGuid) {
let deferred = Promise.defer();
if (PlacesUtils.bookmarks.TYPE_FOLDER == type) {
@ -678,7 +678,7 @@ var RootFolder = function (rootId, rootName) {
return deferred.promise;
};
let handleItemChanged = function (id, property, isAnnotation, newValue, lastModified, type, parent, guid, parentGuid) {
let handleItemChanged = function(id, property, isAnnotation, newValue, lastModified, type, parent, guid, parentGuid) {
let deferred = Promise.defer();
eventSource.emit('change', guid);
@ -687,7 +687,7 @@ var RootFolder = function (rootId, rootName) {
return deferred.promise;
};
let handleItemMoved = function (id, oldParent, oldIndex, newParent, newIndex, type, guid, oldParentGuid, newParentGuid) {
let handleItemMoved = function(id, oldParent, oldIndex, newParent, newIndex, type, guid, oldParentGuid, newParentGuid) {
let deferred = Promise.defer();
function complete() {
@ -718,13 +718,13 @@ var RootFolder = function (rootId, rootName) {
};
let observer = {
onBeginBatchUpdate: function () {
onBeginBatchUpdate() {
},
onEndBatchUpdate: function () {
onEndBatchUpdate() {
},
onItemAdded: function (id, parent, index, type, uri, title, dateAdded, guid, parentGuid) {
onItemAdded(id, parent, index, type, uri, title, dateAdded, guid, parentGuid) {
if (ignore(id, parent)) {
return;
}
@ -732,7 +732,7 @@ var RootFolder = function (rootId, rootName) {
asyncCallback(this, handleItemAdded, Array.prototype.slice.call(arguments));
},
onItemRemoved: function (id, parent, index, type, uri, guid, parentGuid) {
onItemRemoved(id, parent, index, type, uri, guid, parentGuid) {
if (ignore(id, parent)) {
return;
}
@ -740,7 +740,7 @@ var RootFolder = function (rootId, rootName) {
asyncCallback(this, handleItemRemoved, Array.prototype.slice.call(arguments));
},
onItemChanged: function (id, property, isAnnotation, newValue, lastModified, type, parent, guid, parentGuid) {
onItemChanged(id, property, isAnnotation, newValue, lastModified, type, parent, guid, parentGuid) {
if (ignore(id, parent)) {
return;
}
@ -748,7 +748,7 @@ var RootFolder = function (rootId, rootName) {
asyncCallback(this, handleItemChanged, Array.prototype.slice.call(arguments));
},
onItemMoved: function (id, oldParent, oldIndex, newParent, newIndex, type, guid, oldParentGuid, newParentGuid) {
onItemMoved(id, oldParent, oldIndex, newParent, newIndex, type, guid, oldParentGuid, newParentGuid) {
if (ignore(id, oldParent) && ignore(id, newParent)) {
return;
}
@ -765,20 +765,20 @@ var RootFolder = function (rootId, rootName) {
this.mergeRemoteItems = mergeRemoteItems.bind(this);
let rootGuid = null; // resolved before becoming ready (below)
this.__defineGetter__("id", function () {
this.__defineGetter__("id", function() {
return rootGuid;
});
this.__defineGetter__("name", function () {
this.__defineGetter__("name", function() {
return rootName;
});
let deferred = Promise.defer();
let getGuidForRootFolder = function () {
let getGuidForRootFolder = function() {
return PlacesWrapper.localIdToGuid(rootId);
}
PlacesWrapper.updateCachedFolderIds(folderCache, rootId)
.then(getGuidForRootFolder, getGuidForRootFolder)
.then(function (guid) {
.then(function(guid) {
rootGuid = guid;
deferred.resolve(this);
}.bind(this),

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

@ -7,16 +7,16 @@
this.EXPORTED_SYMBOLS = ["FolderCache"];
// Cache for bookmarks folder heirarchy.
var FolderCache = function () {
var FolderCache = function() {
this.cache = new Map();
}
FolderCache.prototype = {
has: function (id) {
has(id) {
return this.cache.has(id);
},
insert: function (id, parentId) {
insert(id, parentId) {
if (this.cache.has(id)) {
return;
}
@ -35,7 +35,7 @@ FolderCache.prototype = {
}
},
remove: function (id) {
remove(id) {
if (!(this.cache.has(id))) {
throw new Error("remote :: id not found in cache: " + id);
}
@ -52,7 +52,7 @@ FolderCache.prototype = {
this.cache.delete(id);
},
setParent: function (id, parentId) {
setParent(id, parentId) {
if (!(this.cache.has(id))) {
throw new Error("setParent :: id not found in cache: " + id);
}
@ -71,7 +71,7 @@ FolderCache.prototype = {
return true;
},
getParent: function (id) {
getParent(id) {
if (this.cache.has(id)) {
return this.cache.get(id).parent;
}
@ -79,7 +79,7 @@ FolderCache.prototype = {
throw new Error("getParent :: id not found in cache: " + id);
},
getChildren: function (id) {
getChildren(id) {
if (this.cache.has(id)) {
return this.cache.get(id).children;
}
@ -87,7 +87,7 @@ FolderCache.prototype = {
throw new Error("getChildren :: id not found in cache: " + id);
},
setChildren: function (id, children) {
setChildren(id, children) {
for (let child of children) {
if (!this.cache.has(child)) {
this.insert(child, id);
@ -97,7 +97,7 @@ FolderCache.prototype = {
}
},
dump: function () {
dump() {
dump("FolderCache: " + JSON.stringify(this.cache) + "\n");
},
};

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

@ -6,21 +6,21 @@ this.EXPORTED_SYMBOLS = ["EventSource"];
Components.utils.import("resource://services-common/utils.js");
var EventSource = function (types, suspendFunc, resumeFunc) {
var EventSource = function(types, suspendFunc, resumeFunc) {
this.listeners = new Map();
for (let type of types) {
this.listeners.set(type, new Set());
}
this.suspend = suspendFunc || function () {};
this.resume = resumeFunc || function () {};
this.suspend = suspendFunc || function() {};
this.resume = resumeFunc || function() {};
this.addEventListener = this.addEventListener.bind(this);
this.removeEventListener = this.removeEventListener.bind(this);
};
EventSource.prototype = {
addEventListener: function (type, listener) {
addEventListener(type, listener) {
if (!this.listeners.has(type)) {
return;
}
@ -28,7 +28,7 @@ EventSource.prototype = {
this.resume();
},
removeEventListener: function (type, listener) {
removeEventListener(type, listener) {
if (!this.listeners.has(type)) {
return;
}
@ -38,7 +38,7 @@ EventSource.prototype = {
}
},
hasListeners: function () {
hasListeners() {
for (let l of this.listeners.values()) {
if (l.size > 0) {
return true;
@ -47,12 +47,12 @@ EventSource.prototype = {
return false;
},
emit: function (type, arg) {
emit(type, arg) {
if (!this.listeners.has(type)) {
return;
}
CommonUtils.nextTick(
function () {
function() {
for (let listener of this.listeners.get(type)) {
listener.call(undefined, arg);
}

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

@ -29,9 +29,9 @@ function makeGUID() {
return CommonUtils.encodeBase64URL(CryptoUtils.generateRandomBytes(9));
}
this.Local = function () {
this.Local = function() {
let prefs = new Preferences("services.cloudsync.");
this.__defineGetter__("prefs", function () {
this.__defineGetter__("prefs", function() {
return prefs;
});
};
@ -39,7 +39,7 @@ this.Local = function () {
Local.prototype = {
get id() {
let clientId = this.prefs.get("client.GUID", "");
return clientId == "" ? this.id = makeGUID(): clientId;
return clientId == "" ? this.id = makeGUID() : clientId;
},
set id(value) {

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

@ -14,13 +14,13 @@ Cu.import("resource://gre/modules/PlacesUtils.jsm");
Cu.import("resource:///modules/PlacesUIUtils.jsm");
Cu.import("resource://services-common/utils.js");
var PlacesQueries = function () {
var PlacesQueries = function() {
}
PlacesQueries.prototype = {
cachedStmts: {},
getQuery: function (queryString) {
getQuery(queryString) {
if (queryString in this.cachedStmts) {
return this.cachedStmts[queryString];
}
@ -30,13 +30,13 @@ PlacesQueries.prototype = {
}
};
var PlacesWrapper = function () {
var PlacesWrapper = function() {
}
PlacesWrapper.prototype = {
placesQueries: new PlacesQueries(),
guidToLocalId: function (guid) {
guidToLocalId(guid) {
let deferred = Promise.defer();
let stmt = "SELECT id AS item_id " +
@ -58,7 +58,7 @@ PlacesWrapper.prototype = {
return deferred.promise;
},
localIdToGuid: function (id) {
localIdToGuid(id) {
let deferred = Promise.defer();
let stmt = "SELECT guid " +
@ -80,7 +80,7 @@ PlacesWrapper.prototype = {
return deferred.promise;
},
getItemsById: function (ids, types) {
getItemsById(ids, types) {
let deferred = Promise.defer();
let stmt = "SELECT b.id, b.type, b.parent, b.position, b.title, b.guid, b.dateAdded, b.lastModified, p.url " +
"FROM moz_bookmarks b " +
@ -95,7 +95,7 @@ PlacesWrapper.prototype = {
return deferred.promise;
},
getItemsByParentId: function (parents, types) {
getItemsByParentId(parents, types) {
let deferred = Promise.defer();
let stmt = "SELECT b.id, b.type, b.parent, b.position, b.title, b.guid, b.dateAdded, b.lastModified, p.url " +
"FROM moz_bookmarks b " +
@ -110,7 +110,7 @@ PlacesWrapper.prototype = {
return deferred.promise;
},
getItemsByGuid: function (guids, types) {
getItemsByGuid(guids, types) {
let deferred = Promise.defer();
guids = guids.map(JSON.stringify);
let stmt = "SELECT b.id, b.type, b.parent, b.position, b.title, b.guid, b.dateAdded, b.lastModified, p.url " +
@ -126,7 +126,7 @@ PlacesWrapper.prototype = {
return deferred.promise;
},
updateCachedFolderIds: function (folderCache, folder) {
updateCachedFolderIds(folderCache, folder) {
let deferred = Promise.defer();
let stmt = "SELECT id, guid " +
"FROM moz_bookmarks " +
@ -137,7 +137,7 @@ PlacesWrapper.prototype = {
query.params.item_type = PlacesUtils.bookmarks.TYPE_FOLDER;
this.asyncQuery(query, ["id", "guid"]).then(
function (items) {
function(items) {
let previousIds = folderCache.getChildren(folder);
let currentIds = new Set();
for (let item of items) {
@ -175,7 +175,7 @@ PlacesWrapper.prototype = {
return deferred.promise;
},
getLocalIdsWithAnnotation: function (anno) {
getLocalIdsWithAnnotation(anno) {
let deferred = Promise.defer();
let stmt = "SELECT a.item_id " +
"FROM moz_anno_attributes n " +
@ -186,7 +186,7 @@ PlacesWrapper.prototype = {
query.params.anno_name = anno.toString();
this.asyncQuery(query, ["item_id"])
.then(function (items) {
.then(function(items) {
let results = [];
for (let item of items) {
results.push(item.item_id);
@ -198,7 +198,7 @@ PlacesWrapper.prototype = {
return deferred.promise;
},
getItemAnnotationsForLocalId: function (id) {
getItemAnnotationsForLocalId(id) {
let deferred = Promise.defer();
let stmt = "SELECT a.name, b.content " +
"FROM moz_anno_attributes a " +
@ -209,7 +209,7 @@ PlacesWrapper.prototype = {
query.params.item_id = id;
this.asyncQuery(query, ["name", "content"])
.then(function (results) {
.then(function(results) {
let annos = {};
for (let result of results) {
annos[result.name] = result.content;
@ -221,7 +221,7 @@ PlacesWrapper.prototype = {
return deferred.promise;
},
insertBookmark: function (parent, uri, index, title, guid) {
insertBookmark(parent, uri, index, title, guid) {
let parsedURI;
try {
parsedURI = CommonUtils.makeURI(uri)
@ -237,7 +237,7 @@ PlacesWrapper.prototype = {
}
},
setItemAnnotation: function (item, anno, value, flags, exp) {
setItemAnnotation(item, anno, value, flags, exp) {
try {
return Promise.resolve(PlacesUtils.annotations.setItemAnnotation(item, anno, value, flags, exp));
} catch (e) {
@ -245,7 +245,7 @@ PlacesWrapper.prototype = {
}
},
itemHasAnnotation: function (item, anno) {
itemHasAnnotation(item, anno) {
try {
return Promise.resolve(PlacesUtils.annotations.itemHasAnnotation(item, anno));
} catch (e) {
@ -253,7 +253,7 @@ PlacesWrapper.prototype = {
}
},
createFolder: function (parent, name, index, guid) {
createFolder(parent, name, index, guid) {
try {
return Promise.resolve(PlacesUtils.bookmarks.createFolder(parent, name, index, guid));
} catch (e) {
@ -261,7 +261,7 @@ PlacesWrapper.prototype = {
}
},
removeFolderChildren: function (folder) {
removeFolderChildren(folder) {
try {
PlacesUtils.bookmarks.removeFolderChildren(folder);
return Promise.resolve();
@ -270,7 +270,7 @@ PlacesWrapper.prototype = {
}
},
insertSeparator: function (parent, index, guid) {
insertSeparator(parent, index, guid) {
try {
return Promise.resolve(PlacesUtils.bookmarks.insertSeparator(parent, index, guid));
} catch (e) {
@ -278,7 +278,7 @@ PlacesWrapper.prototype = {
}
},
removeItem: function (item) {
removeItem(item) {
try {
return Promise.resolve(PlacesUtils.bookmarks.removeItem(item));
} catch (e) {
@ -286,7 +286,7 @@ PlacesWrapper.prototype = {
}
},
setItemDateAdded: function (item, dateAdded) {
setItemDateAdded(item, dateAdded) {
try {
return Promise.resolve(PlacesUtils.bookmarks.setItemDateAdded(item, dateAdded));
} catch (e) {
@ -294,7 +294,7 @@ PlacesWrapper.prototype = {
}
},
setItemLastModified: function (item, lastModified) {
setItemLastModified(item, lastModified) {
try {
return Promise.resolve(PlacesUtils.bookmarks.setItemLastModified(item, lastModified));
} catch (e) {
@ -302,7 +302,7 @@ PlacesWrapper.prototype = {
}
},
setItemTitle: function (item, title) {
setItemTitle(item, title) {
try {
return Promise.resolve(PlacesUtils.bookmarks.setItemTitle(item, title));
} catch (e) {
@ -310,7 +310,7 @@ PlacesWrapper.prototype = {
}
},
changeBookmarkURI: function (item, uri) {
changeBookmarkURI(item, uri) {
try {
uri = CommonUtils.makeURI(uri);
return Promise.resolve(PlacesUtils.bookmarks.changeBookmarkURI(item, uri));
@ -319,7 +319,7 @@ PlacesWrapper.prototype = {
}
},
moveItem: function (item, parent, index) {
moveItem(item, parent, index) {
try {
return Promise.resolve(PlacesUtils.bookmarks.moveItem(item, parent, index));
} catch (e) {
@ -327,7 +327,7 @@ PlacesWrapper.prototype = {
}
},
setItemIndex: function (item, index) {
setItemIndex(item, index) {
try {
return Promise.resolve(PlacesUtils.bookmarks.setItemIndex(item, index));
} catch (e) {
@ -335,11 +335,11 @@ PlacesWrapper.prototype = {
}
},
asyncQuery: function (query, names) {
asyncQuery(query, names) {
let deferred = Promise.defer();
let storageCallback = {
results: [],
handleResult: function (results) {
handleResult(results) {
if (!names) {
return;
}
@ -354,11 +354,11 @@ PlacesWrapper.prototype = {
}
},
handleError: function (error) {
handleError(error) {
deferred.reject(error);
},
handleCompletion: function (reason) {
handleCompletion(reason) {
if (REASON_ERROR == reason) {
return;
}

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

@ -19,7 +19,7 @@ XPCOMUtils.defineLazyServiceGetter(this, "Session", "@mozilla.org/browser/sessio
const DATA_VERSION = 1;
var ClientRecord = function (params) {
var ClientRecord = function(params) {
this.id = params.id;
this.name = params.name || "?";
this.tabs = new Set();
@ -28,7 +28,7 @@ var ClientRecord = function (params) {
ClientRecord.prototype = {
version: DATA_VERSION,
update: function (params) {
update(params) {
if (this.id !== params.id) {
throw new Error("expected " + this.id + " to equal " + params.id);
}
@ -37,7 +37,7 @@ ClientRecord.prototype = {
}
};
var TabRecord = function (params) {
var TabRecord = function(params) {
this.url = params.url || "";
this.update(params);
};
@ -45,7 +45,7 @@ var TabRecord = function (params) {
TabRecord.prototype = {
version: DATA_VERSION,
update: function (params) {
update(params) {
if (this.url && this.url !== params.url) {
throw new Error("expected " + this.url + " to equal " + params.url);
}
@ -60,13 +60,13 @@ TabRecord.prototype = {
},
};
var TabCache = function () {
var TabCache = function() {
this.tabs = new Map();
this.clients = new Map();
};
TabCache.prototype = {
merge: function (client, tabs) {
merge(client, tabs) {
if (!client || !client.id) {
return;
}
@ -113,7 +113,7 @@ TabCache.prototype = {
}
},
clear: function (client) {
clear(client) {
if (client) {
this.clients.delete(client.id);
} else {
@ -122,7 +122,7 @@ TabCache.prototype = {
}
},
get: function () {
get() {
let results = [];
for (let client of this.clients.values()) {
results.push(client);
@ -130,13 +130,13 @@ TabCache.prototype = {
return results;
},
isEmpty: function () {
isEmpty() {
return 0 == this.clients.size;
},
};
this.Tabs = function () {
this.Tabs = function() {
let suspended = true;
let topics = [
@ -146,7 +146,7 @@ this.Tabs = function () {
"TabSelect",
];
let update = function (event) {
let update = function(event) {
if (event.originalTarget.linkedBrowser) {
if (PrivateBrowsingUtils.isBrowserPrivate(event.originalTarget.linkedBrowser) &&
!PrivateBrowsingUtils.permanentPrivateBrowsing) {
@ -157,26 +157,26 @@ this.Tabs = function () {
eventSource.emit("change");
};
let registerListenersForWindow = function (window) {
let registerListenersForWindow = function(window) {
for (let topic of topics) {
window.addEventListener(topic, update, false);
}
window.addEventListener("unload", unregisterListeners, false);
};
let unregisterListenersForWindow = function (window) {
let unregisterListenersForWindow = function(window) {
window.removeEventListener("unload", unregisterListeners, false);
for (let topic of topics) {
window.removeEventListener(topic, update, false);
}
};
let unregisterListeners = function (event) {
let unregisterListeners = function(event) {
unregisterListenersForWindow(event.target);
};
let observer = {
observe: function (subject, topic, data) {
observe(subject, topic, data) {
switch (topic) {
case "domwindowopened":
let onLoad = () => {
@ -192,7 +192,7 @@ this.Tabs = function () {
}
};
let resume = function () {
let resume = function() {
if (suspended) {
Observers.add("domwindowopened", observer);
let wins = Services.wm.getEnumerator("navigator:browser");
@ -200,9 +200,9 @@ this.Tabs = function () {
registerListenersForWindow(wins.getNext());
}
}
}.bind(this);
};
let suspend = function () {
let suspend = function() {
if (!suspended) {
Observers.remove("domwindowopened", observer);
let wins = Services.wm.getEnumerator("navigator:browser");
@ -210,7 +210,7 @@ this.Tabs = function () {
unregisterListenersForWindow(wins.getNext());
}
}
}.bind(this);
};
let eventTypes = [
"change",
@ -220,20 +220,20 @@ this.Tabs = function () {
let tabCache = new TabCache();
let getWindowEnumerator = function () {
let getWindowEnumerator = function() {
return Services.wm.getEnumerator("navigator:browser");
};
let shouldSkipWindow = function (win) {
let shouldSkipWindow = function(win) {
return win.closed ||
PrivateBrowsingUtils.isWindowPrivate(win);
};
let getTabState = function (tab) {
let getTabState = function(tab) {
return JSON.parse(Session.getTabState(tab));
};
let getLocalTabs = function (filter) {
let getLocalTabs = function(filter) {
let deferred = Promise.defer();
filter = (undefined === filter) ? true : filter;
@ -242,11 +242,11 @@ this.Tabs = function () {
let allTabs = [];
let currentState = JSON.parse(Session.getBrowserState());
currentState.windows.forEach(function (window) {
currentState.windows.forEach(function(window) {
if (window.isPrivate) {
return;
}
window.tabs.forEach(function (tab) {
window.tabs.forEach(function(tab) {
if (!tab.entries.length) {
return;
}
@ -273,7 +273,7 @@ this.Tabs = function () {
return deferred.promise;
};
let mergeRemoteTabs = function (client, tabs) {
let mergeRemoteTabs = function(client, tabs) {
let deferred = Promise.defer();
deferred.resolve(tabCache.merge(client, tabs));
@ -282,7 +282,7 @@ this.Tabs = function () {
return deferred.promise;
};
let clearRemoteTabs = function (client) {
let clearRemoteTabs = function(client) {
let deferred = Promise.defer();
deferred.resolve(tabCache.clear(client));
@ -291,7 +291,7 @@ this.Tabs = function () {
return deferred.promise;
};
let getRemoteTabs = function () {
let getRemoteTabs = function() {
let deferred = Promise.defer();
deferred.resolve(tabCache.get());
@ -299,7 +299,7 @@ this.Tabs = function () {
return deferred.promise;
};
let hasRemoteTabs = function () {
let hasRemoteTabs = function() {
return !tabCache.isEmpty();
};

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

@ -17,30 +17,30 @@ function test() {
let testURL = "chrome://mochitests/content/browser/services/cloudsync/tests/mochitest/other_window.html";
let expected = [
testURL,
testURL+"?x=1",
testURL+"?x=%20a",
testURL + "?x=1",
testURL + "?x=%20a",
// testURL+"?x=å",
];
let nevents = 0;
let nflushed = 0;
function handleTabChangeEvent () {
function handleTabChangeEvent() {
cloudSync.tabs.removeEventListener("change", handleTabChangeEvent);
++ nevents;
++nevents;
info("tab change event " + nevents);
next();
}
function getLocalTabs() {
cloudSync.tabs.getLocalTabs().then(
function (tabs) {
function(tabs) {
for (let tab of tabs) {
ok(expected.indexOf(tab.url) >= 0, "found an expected tab");
}
is(tabs.length, expected.length, "found the right number of tabs");
opentabs.forEach(function (tab) {
opentabs.forEach(function(tab) {
gBrowser.removeTab(tab);
});
@ -59,7 +59,7 @@ function test() {
function flush() {
tab.linkedBrowser.removeEventListener("load", flush, true);
local.TabStateFlusher.flush(tab.linkedBrowser).then(() => {
++ nflushed;
++nflushed;
info("flushed " + nflushed);
next();
});

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

@ -5,6 +5,6 @@ var {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
"use strict";
(function initCloudSyncTestingInfrastructure () {
(function initCloudSyncTestingInfrastructure() {
do_get_profile();
}).call(this);

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

@ -5,22 +5,22 @@
Cu.import("resource://gre/modules/CloudSync.jsm");
function run_test () {
function run_test() {
run_next_test();
}
function cleanup () {
function cleanup() {
}
add_task(function* test_merge_bookmarks_flat () {
add_task(function* test_merge_bookmarks_flat() {
try {
let rootFolder = yield CloudSync().bookmarks.getRootFolder("TEST");
ok(rootFolder.id, "root folder id is ok");
let items = [
{"id":"G_UL4ZhOyX8m","type":rootFolder.BOOKMARK,"title":"reddit: the front page of the internet 1","uri":"http://www.reddit.com",index:2},
{"id":"G_UL4ZhOyX8n","type":rootFolder.BOOKMARK,"title":"reddit: the front page of the internet 2","uri":"http://www.reddit.com?1",index:1},
{"id":"G_UL4ZhOyX8m", "type":rootFolder.BOOKMARK, "title":"reddit: the front page of the internet 1", "uri":"http://www.reddit.com", index:2},
{"id":"G_UL4ZhOyX8n", "type":rootFolder.BOOKMARK, "title":"reddit: the front page of the internet 2", "uri":"http://www.reddit.com?1", index:1},
];
yield rootFolder.mergeRemoteItems(items);
@ -31,15 +31,15 @@ add_task(function* test_merge_bookmarks_flat () {
}
});
add_task(function* test_merge_bookmarks_in_folders () {
add_task(function* test_merge_bookmarks_in_folders() {
try {
let rootFolder = yield CloudSync().bookmarks.getRootFolder("TEST");
ok(rootFolder.id, "root folder id is ok");
let items = [
{"id":"G_UL4ZhOyX8m","type":rootFolder.BOOKMARK,"title":"reddit: the front page of the internet 1","uri":"http://www.reddit.com",index:2},
{"id":"G_UL4ZhOyX8n","type":rootFolder.BOOKMARK,parent:"G_UL4ZhOyX8x","title":"reddit: the front page of the internet 2","uri":"http://www.reddit.com/?a=å%20ä%20ö",index:1},
{"id":"G_UL4ZhOyX8x","type":rootFolder.FOLDER},
{"id":"G_UL4ZhOyX8m", "type":rootFolder.BOOKMARK, "title":"reddit: the front page of the internet 1", "uri":"http://www.reddit.com", index:2},
{"id":"G_UL4ZhOyX8n", "type":rootFolder.BOOKMARK, parent:"G_UL4ZhOyX8x", "title":"reddit: the front page of the internet 2", "uri":"http://www.reddit.com/?a=å%20ä%20ö", index:1},
{"id":"G_UL4ZhOyX8x", "type":rootFolder.FOLDER},
];
yield rootFolder.mergeRemoteItems(items);
@ -70,4 +70,4 @@ add_task(function* test_merge_bookmarks_in_folders () {
} finally {
yield CloudSync().bookmarks.deleteRootFolder("TEST");
}
});
});

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

@ -5,11 +5,11 @@
Cu.import("resource://gre/modules/CloudSync.jsm");
function run_test () {
function run_test() {
run_next_test();
}
add_task(function test_module_load () {
add_task(function test_module_load() {
ok(CloudSync);
let cloudSync = CloudSync();
ok(cloudSync.adapters);

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

@ -5,11 +5,11 @@
Cu.import("resource://gre/modules/CloudSync.jsm");
function run_test () {
function run_test() {
run_next_test();
}
add_task(function* test_get_remote_tabs () {
add_task(function* test_get_remote_tabs() {
let cloudSync = CloudSync();
let clients = yield cloudSync.tabs.getRemoteTabs();
equal(clients.length, 0);
@ -17,9 +17,9 @@ add_task(function* test_get_remote_tabs () {
yield cloudSync.tabs.mergeRemoteTabs({
id: "001",
name: "FakeClient",
},[
{url:"https://www.google.ca?a=å%20ä%20ö",title:"Google Canada",icon:"https://www.google.ca/favicon.ico",lastUsed:0},
{url:"http://www.reddit.com",title:"Reddit",icon:"http://www.reddit.com/favicon.ico",lastUsed:1},
}, [
{url:"https://www.google.ca?a=å%20ä%20ö", title:"Google Canada", icon:"https://www.google.ca/favicon.ico", lastUsed:0},
{url:"http://www.reddit.com", title:"Reddit", icon:"http://www.reddit.com/favicon.ico", lastUsed:1},
]);
ok(cloudSync.tabs.hasRemoteTabs());

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

@ -226,7 +226,7 @@ this.Async = {
promiseSpinningly(promise) {
let cb = Async.makeSpinningCallback();
promise.then(result => {
promise.then(result => {
cb(null, result);
}, err => {
cb(err || new Error("Promise rejected without explicit error"));

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

@ -92,7 +92,7 @@ function kintoClient(connection, bucket) {
let config = {
remote: base,
bucket: bucket,
bucket,
adapter: FirefoxAdapter,
adapterOptions: {sqliteHandle: connection},
};
@ -280,7 +280,7 @@ function* updatePinningList(records) {
// write each KeyPin entry to the preload list
for (let item of records) {
try {
const {pinType, pins=[], versions} = item;
const {pinType, pins = [], versions} = item;
if (versions.indexOf(appInfo.version) != -1) {
if (pinType == "KeyPin" && pins.length) {
siteSecurityService.setKeyPins(item.hostName,
@ -301,8 +301,6 @@ function* updatePinningList(records) {
// 1254099.
}
}
} else {
return;
}
}
@ -320,9 +318,9 @@ function* updateJSONBlocklist(filename, records) {
yield OS.File.writeAtomic(path, serialized, {tmpPath: path + ".tmp"});
// Notify change to `nsBlocklistService`
const eventData = {filename: filename};
const eventData = {filename};
Services.cpmm.sendAsyncMessage("Blocklist:reload-from-disk", eventData);
} catch(e) {
} catch (e) {
Cu.reportError(e);
}
}

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

@ -114,9 +114,9 @@ this.HawkClient.prototype = {
* @param error
* A string or object describing the error
*/
_constructError: function(restResponse, error) {
_constructError(restResponse, error) {
let errorObj = {
error: error,
error,
// This object is likely to be JSON.stringify'd, but neither Error()
// objects nor Components.Exception objects do the right thing there,
// so we add a new element which is simply the .toString() version of
@ -156,12 +156,12 @@ this.HawkClient.prototype = {
* For HAWK clock skew and replay protection, see
* https://github.com/hueniverse/hawk#replay-protection
*/
_updateClockOffset: function(dateString) {
_updateClockOffset(dateString) {
try {
let serverDateMsec = Date.parse(dateString);
this._localtimeOffsetMsec = serverDateMsec - this.now();
log.debug("Clock offset vs " + this.host + ": " + this._localtimeOffsetMsec);
} catch(err) {
} catch (err) {
log.warn("Bad date header in server response: " + dateString);
}
},
@ -180,7 +180,7 @@ this.HawkClient.prototype = {
/*
* return current time in milliseconds
*/
now: function() {
now() {
return Date.now();
},
@ -203,8 +203,8 @@ this.HawkClient.prototype = {
* as JSON and contains an 'error' property, the promise will be
* rejected with this JSON-parsed response.
*/
request: function(path, method, credentials=null, payloadObj={}, extraHeaders = {},
retryOK=true) {
request(path, method, credentials = null, payloadObj = {}, extraHeaders = {},
retryOK = true) {
method = method.toLowerCase();
let deferred = Promise.defer();
@ -263,7 +263,7 @@ this.HawkClient.prototype = {
let jsonResponse = {};
try {
jsonResponse = JSON.parse(restResponse.body);
} catch(notJSON) {}
} catch (notJSON) {}
let okResponse = (200 <= status && status < 300);
if (!okResponse || jsonResponse.error) {
@ -275,7 +275,7 @@ this.HawkClient.prototype = {
// It's up to the caller to know how to decode the response.
// We just return the whole response.
deferred.resolve(this.response);
};
}
function onComplete(error) {
try {
@ -319,7 +319,7 @@ this.HawkClient.prototype = {
observerPrefix: null,
// Given an optional header value, notify that a backoff has been requested.
_maybeNotifyBackoff: function (response, headerName) {
_maybeNotifyBackoff(response, headerName) {
if (!this.observerPrefix || !response.headers) {
return;
}
@ -339,7 +339,7 @@ this.HawkClient.prototype = {
},
// override points for testing.
newHAWKAuthenticatedRESTRequest: function(uri, credentials, extra) {
newHAWKAuthenticatedRESTRequest(uri, credentials, extra) {
return new HAWKAuthenticatedRESTRequest(uri, credentials, extra);
},

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

@ -53,7 +53,7 @@ const Prefs = new Preferences("services.common.rest.");
*/
this.HAWKAuthenticatedRESTRequest =
function HawkAuthenticatedRESTRequest(uri, credentials, extra={}) {
function HawkAuthenticatedRESTRequest(uri, credentials, extra = {}) {
RESTRequest.call(this, uri);
this.credentials = credentials;
@ -79,7 +79,7 @@ HAWKAuthenticatedRESTRequest.prototype = {
localtimeOffsetMsec: this.localtimeOffsetMsec,
credentials: this.credentials,
payload: data && JSON.stringify(data) || "",
contentType: contentType,
contentType,
};
let header = CryptoUtils.computeHAWK(this.uri, method, options);
this.setHeader("Authorization", header.field);
@ -157,19 +157,19 @@ this.Intl = function Intl() {
};
this.Intl.prototype = {
init: function() {
init() {
Services.prefs.addObserver("intl.accept_languages", this, false);
},
uninit: function() {
uninit() {
Services.prefs.removeObserver("intl.accept_languages", this);
},
observe: function(subject, topic, data) {
observe(subject, topic, data) {
this.readPref();
},
readPref: function() {
readPref() {
this._everRead = true;
try {
this._accepted = Services.prefs.getComplexValue(

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

@ -329,7 +329,7 @@ class FirefoxAdapter extends Kinto.adapters.BaseAdapter {
yield connection.executeTransaction(function* doImport() {
for (let record of records) {
const params = {
collection_name: collection_name,
collection_name,
record_id: record.id,
record: JSON.stringify(record),
};
@ -337,7 +337,7 @@ class FirefoxAdapter extends Kinto.adapters.BaseAdapter {
}
const lastModified = Math.max(...records.map(record => record.last_modified));
const params = {
collection_name: collection_name,
collection_name,
};
const previousLastModified = yield connection.execute(
statements.getLastModified, params).then(result => {
@ -347,7 +347,7 @@ class FirefoxAdapter extends Kinto.adapters.BaseAdapter {
});
if (lastModified > previousLastModified) {
const params = {
collection_name: collection_name,
collection_name,
last_modified: lastModified,
};
yield connection.execute(statements.saveLastModified, params);
@ -393,15 +393,14 @@ class FirefoxAdapter extends Kinto.adapters.BaseAdapter {
return this._connection.executeTransaction(function* (conn) {
const promises = [];
yield conn.execute(statements.scanAllRecords, null, function (row) {
yield conn.execute(statements.scanAllRecords, null, function(row) {
const record = JSON.parse(row.getResultByName("record"));
const record_id = row.getResultByName("record_id");
const collection_name = row.getResultByName("collection_name");
if (record._status === "deleted") {
// Garbage collect deleted records.
promises.push(conn.execute(statements.deleteData, { collection_name, record_id }));
}
else {
} else {
const newRecord = Object.assign({}, record, {
_status: "created",
last_modified: undefined,

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

@ -275,7 +275,7 @@ ServerBSO.prototype = {
* collection. This should be in the format returned by new_timestamp().
*/
this.StorageServerCollection =
function StorageServerCollection(bsos, acceptNew, timestamp=new_timestamp()) {
function StorageServerCollection(bsos, acceptNew, timestamp = new_timestamp()) {
this._bsos = bsos || {};
this.acceptNew = acceptNew || false;
@ -577,7 +577,7 @@ StorageServerCollection.prototype = {
failed[record.id] = "Exception when processing.";
}
}
return {success: success, failed: failed};
return {success, failed};
},
delete: function delete_(options) {
@ -805,7 +805,7 @@ StorageServerCollection.prototype = {
let self = this;
return function(request, response) {
switch(request.method) {
switch (request.method) {
case "GET":
return self.getHandler(request, response);
@ -845,9 +845,9 @@ StorageServerCollection.prototype = {
};
//===========================================================================//
// ===========================================================================//
// httpd.js-based Storage server. //
//===========================================================================//
// ===========================================================================//
/**
* In general, the preferred way of using StorageServer is to directly
@ -946,7 +946,7 @@ StorageServer.prototype = {
* The numeric port on which to start. The default is to choose
* any available port.
*/
startSynchronous: function startSynchronous(port=-1) {
startSynchronous: function startSynchronous(port = -1) {
let cb = Async.makeSpinningCallback();
this.start(port, cb);
cb.wait();
@ -996,7 +996,7 @@ StorageServer.prototype = {
this._log.info("Registering new user with server: " + username);
this.users[username] = {
password: password,
password,
collections: {},
quota: this.DEFAULT_QUOTA,
};
@ -1186,18 +1186,18 @@ StorageServer.prototype = {
let collection = this.getCollection.bind(this, username);
let createCollection = this.createCollection.bind(this, username);
let createContents = this.createContents.bind(this, username);
let modified = function (collectionName) {
let modified = function(collectionName) {
return collection(collectionName).timestamp;
}
let deleteCollections = this.deleteCollections.bind(this, username);
let quota = this.getQuota.bind(this, username);
return {
collection: collection,
createCollection: createCollection,
createContents: createContents,
deleteCollections: deleteCollections,
modified: modified,
quota: quota,
collection,
createCollection,
createContents,
deleteCollections,
modified,
quota,
};
},

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

@ -33,7 +33,7 @@ this.Observers = {
*
* @returns the observer
*/
add: function(topic, callback, thisObject) {
add(topic, callback, thisObject) {
let observer = new Observer(topic, callback, thisObject);
this._cache.push(observer);
this._service.addObserver(observer, topic, true);
@ -53,13 +53,13 @@ this.Observers = {
* @param thisObject {Object} [optional]
* the object being used as |this| when calling a Function callback
*/
remove: function(topic, callback, thisObject) {
remove(topic, callback, thisObject) {
// This seems fairly inefficient, but I'm not sure how much better
// we can make it. We could index by topic, but we can't index by callback
// or thisObject, as far as I know, since the keys to JavaScript hashes
// (a.k.a. objects) can apparently only be primitive values.
let [observer] = this._cache.filter(v => v.topic == topic &&
v.callback == callback &&
let [observer] = this._cache.filter(v => v.topic == topic &&
v.callback == callback &&
v.thisObject == thisObject);
if (observer) {
this._service.removeObserver(observer, topic);
@ -83,9 +83,9 @@ this.Observers = {
* the observer, wrap them in an object and pass them via the subject
* parameter (i.e.: { foo: 1, bar: "some string", baz: myObject })
*/
notify: function(topic, subject, data) {
notify(topic, subject, data) {
subject = (typeof subject == "undefined") ? null : new Subject(subject);
data = (typeof data == "undefined") ? null : data;
data = (typeof data == "undefined") ? null : data;
this._service.notifyObservers(subject, topic, data);
},
@ -114,7 +114,7 @@ function Observer(topic, callback, thisObject) {
Observer.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
observe: function(subject, topic, data) {
observe(subject, topic, data) {
// Extract the wrapped object for subjects that are one of our wrappers
// around a JS object. This way we support both wrapped subjects created
// using this module and those that are real XPCOM components.
@ -128,8 +128,7 @@ Observer.prototype = {
this.callback.call(this.thisObject, subject, data);
else
this.callback(subject, data);
}
else // typeof this.callback == "object" (nsIObserver)
} else // typeof this.callback == "object" (nsIObserver)
this.callback.observe(subject, topic, data);
}
}
@ -140,11 +139,11 @@ function Subject(object) {
// as one of our wrappers to distinguish between subjects that are one of our
// wrappers (which we should unwrap when notifying our observers) and those
// that are real JS XPCOM components (which we should pass through unaltered).
this.wrappedJSObject = { observersModuleSubjectWrapper: true, object: object };
this.wrappedJSObject = { observersModuleSubjectWrapper: true, object };
}
Subject.prototype = {
QueryInterface: XPCOMUtils.generateQI([]),
getScriptableHelper: function() {},
getInterfaces: function() {}
getScriptableHelper() {},
getInterfaces() {}
};

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

@ -102,7 +102,7 @@ RESTRequest.prototype = {
Ci.nsIChannelEventSink
]),
/*** Public API: ***/
/** * Public API: ***/
/**
* A constant boolean that indicates whether this object will automatically
@ -293,7 +293,7 @@ RESTRequest.prototype = {
}
},
/*** Implementation stuff ***/
/** * Implementation stuff ***/
dispatch: function dispatch(method, data, onComplete, onProgress) {
if (this.status != this.NOT_SENT) {
@ -412,7 +412,7 @@ RESTRequest.prototype = {
this.onComplete(error);
},
/*** nsIStreamListener ***/
/** * nsIStreamListener ***/
onStartRequest: function onStartRequest(channel) {
if (this.status == this.ABORTED) {
@ -573,13 +573,13 @@ RESTRequest.prototype = {
this.delayTimeout();
},
/*** nsIInterfaceRequestor ***/
/** * nsIInterfaceRequestor ***/
getInterface: function(aIID) {
getInterface(aIID) {
return this.QueryInterface(aIID);
},
/*** nsIBadCertListener2 ***/
/** * nsIBadCertListener2 ***/
notifyCertProblem: function notifyCertProblem(socketInfo, sslStatus, targetHost) {
this._log.warn("Invalid HTTPS certificate encountered!");
@ -601,7 +601,7 @@ RESTRequest.prototype = {
return isInternal && isSameURI;
},
/*** nsIChannelEventSink ***/
/** * nsIChannelEventSink ***/
asyncOnChannelRedirect:
function asyncOnChannelRedirect(oldChannel, newChannel, flags, callback) {
@ -707,7 +707,7 @@ RESTResponse.prototype = {
try {
this._log.trace("Processing response headers.");
let channel = this.request.channel.QueryInterface(Ci.nsIHttpChannel);
channel.visitResponseHeaders(function (header, value) {
channel.visitResponseHeaders(function(header, value) {
headers[header.toLowerCase()] = value;
});
} catch (ex) {

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

@ -45,8 +45,7 @@ StringBundle.prototype = {
return Cc["@mozilla.org/intl/nslocaleservice;1"].
getService(Ci.nsILocaleService).
getApplicationLocale();
}
catch(ex) {
} catch (ex) {
return null;
}
},
@ -90,7 +89,7 @@ StringBundle.prototype = {
*
* @returns {String} the value of the string
*/
get: function(key, args) {
get(key, args) {
if (args)
return this.stringBundle.formatStringFromName(key, args, args.length);
else
@ -103,7 +102,7 @@ StringBundle.prototype = {
* @returns {Array}
* an array of objects with key and value properties
*/
getAll: function() {
getAll() {
let strings = [];
// FIXME: for performance, return an enumerable array that wraps the string
@ -170,7 +169,7 @@ StringBundle.prototype = {
* @returns {String}
* the value of the string
*/
getString: function(key) {
getString(key) {
return this.get(key);
},
@ -186,7 +185,7 @@ StringBundle.prototype = {
* @returns {String}
* the formatted value of the string
*/
getFormattedString: function(key, args) {
getFormattedString(key, args) {
return this.get(key, args);
},

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

@ -69,7 +69,7 @@ var _ = function(some, debug, text, to) {
print(Array.slice(arguments).join(" "));
};
function httpd_setup (handlers, port=-1) {
function httpd_setup(handlers, port = -1) {
let server = new HttpServer();
for (let path in handlers) {
server.registerPathHandler(path, handlers[path]);

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

@ -7,17 +7,17 @@ function run_test() {
_("Chain a few async methods, making sure the 'this' object is correct.");
let methods = {
save: function(x, callback) {
save(x, callback) {
this.x = x;
callback(x);
},
addX: function(x, callback) {
addX(x, callback) {
callback(x + this.x);
},
double: function(x, callback) {
double(x, callback) {
callback(x * 2);
},
neg: function(x, callback) {
neg(x, callback) {
callback(-x);
}
};

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

@ -85,10 +85,10 @@ function run_test() {
_("Generate an execution error");
let query = "INSERT INTO moz_formhistory (fieldname, value) VALUES ('one', NULL)";
let stmt = Svc.Form.DBConnection.createStatement(query);
let r11, except; ;
let r11, except;
try {
r11 = Async.querySpinningly(stmt);
} catch(e) {
} catch (e) {
except = e;
}
stmt.finalize()

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

@ -31,7 +31,7 @@ function do_get_kinto_collection(collectionName, sqliteHandle) {
// correctly and that simple kinto operations are working as expected. There
// are more tests for core Kinto.js (and its storage adapter) in the
// xpcshell tests under /services/common
add_task(function* test_something(){
add_task(function* test_something() {
const configPath = "/v1/";
const recordsPath = "/v1/buckets/blocklists/collections/certificates/records";
@ -39,7 +39,7 @@ add_task(function* test_something(){
`http://localhost:${server.identity.primaryPort}/v1`);
// register a handler
function handleResponse (request, response) {
function handleResponse(request, response) {
try {
const sample = getSampleResponse(request, server.identity.primaryPort);
if (!sample) {
@ -179,7 +179,7 @@ function getSampleResponse(req, port) {
"serialNumber":"ATFpsA==",
"id":"dabafde9-df4a-ddba-2548-748da04cc02c",
"last_modified":4000
},{
}, {
"subject":"MCIxIDAeBgNVBAMMF0Fub3RoZXIgVGVzdCBFbmQtZW50aXR5",
"pubKeyHash":"VCIlmPM9NkgFQtrs4Oa5TeFcDu6MWRTKSNdePEhOgD8=",
"id":"dabafde9-df4a-ddba-2548-748da04cc02d",
@ -200,12 +200,12 @@ function getSampleResponse(req, port) {
"serialNumber":"not a base64 encoded serial",
"id":"dabafde9-df4a-ddba-2548-748da04cc02e",
"last_modified":5000
},{
}, {
"subject":"not a base64 encoded subject",
"pubKeyHash":"not a base64 encoded pubKeyHash",
"id":"dabafde9-df4a-ddba-2548-748da04cc02f",
"last_modified":5000
},{
}, {
"subject":"MCIxIDAeBgNVBAMMF0Fub3RoZXIgVGVzdCBFbmQtZW50aXR5",
"pubKeyHash":"VCIlmPM9NkgFQtrs4Oa5TeFcDu6MWRTKSNdePEhOgD8=",
"id":"dabafde9-df4a-ddba-2548-748da04cc02g",

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

@ -17,9 +17,9 @@ const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1",
const kintoFilename = "kinto.sqlite";
const gBlocklistClients = [
{client: BlocklistClients.AddonBlocklistClient, filename: BlocklistClients.FILENAME_ADDONS_JSON, testData: ["i808","i720", "i539"]},
{client: BlocklistClients.PluginBlocklistClient, filename: BlocklistClients.FILENAME_PLUGINS_JSON, testData: ["p1044","p32","p28"]},
{client: BlocklistClients.GfxBlocklistClient, filename: BlocklistClients.FILENAME_GFX_JSON, testData: ["g204","g200","g36"]},
{client: BlocklistClients.AddonBlocklistClient, filename: BlocklistClients.FILENAME_ADDONS_JSON, testData: ["i808", "i720", "i539"]},
{client: BlocklistClients.PluginBlocklistClient, filename: BlocklistClients.FILENAME_PLUGINS_JSON, testData: ["p1044", "p32", "p28"]},
{client: BlocklistClients.GfxBlocklistClient, filename: BlocklistClients.FILENAME_GFX_JSON, testData: ["g204", "g200", "g36"]},
];
@ -118,7 +118,7 @@ function run_test() {
});
}
add_task(function* test_records_obtained_from_server_are_stored_in_db(){
add_task(function* test_records_obtained_from_server_are_stored_in_db() {
for (let {client} of gBlocklistClients) {
// Test an empty db populates
let result = yield client.maybeSync(2000, Date.now());
@ -134,7 +134,7 @@ add_task(function* test_records_obtained_from_server_are_stored_in_db(){
});
add_task(clear_state);
add_task(function* test_list_is_written_to_file_in_profile(){
add_task(function* test_list_is_written_to_file_in_profile() {
for (let {client, filename, testData} of gBlocklistClients) {
const profFile = FileUtils.getFile(KEY_PROFILEDIR, [filename]);
strictEqual(profFile.exists(), false);
@ -148,7 +148,7 @@ add_task(function* test_list_is_written_to_file_in_profile(){
});
add_task(clear_state);
add_task(function* test_current_server_time_is_saved_in_pref(){
add_task(function* test_current_server_time_is_saved_in_pref() {
for (let {client} of gBlocklistClients) {
const before = Services.prefs.getIntPref(client.lastCheckTimePref);
const serverTime = Date.now();
@ -159,7 +159,7 @@ add_task(function* test_current_server_time_is_saved_in_pref(){
});
add_task(clear_state);
add_task(function* test_update_json_file_when_addons_has_changes(){
add_task(function* test_update_json_file_when_addons_has_changes() {
for (let {client, filename, testData} of gBlocklistClients) {
yield client.maybeSync(2000, Date.now() - 1000);
const before = Services.prefs.getIntPref(client.lastCheckTimePref);
@ -180,7 +180,7 @@ add_task(function* test_update_json_file_when_addons_has_changes(){
});
add_task(clear_state);
add_task(function* test_sends_reload_message_when_blocklist_has_changes(){
add_task(function* test_sends_reload_message_when_blocklist_has_changes() {
for (let {client, filename} of gBlocklistClients) {
let received = yield new Promise((resolve, reject) => {
Services.ppmm.addMessageListener("Blocklist:reload-from-disk", {
@ -195,7 +195,7 @@ add_task(function* test_sends_reload_message_when_blocklist_has_changes(){
});
add_task(clear_state);
add_task(function* test_do_nothing_when_blocklist_is_up_to_date(){
add_task(function* test_do_nothing_when_blocklist_is_up_to_date() {
for (let {client, filename} of gBlocklistClients) {
yield client.maybeSync(2000, Date.now() - 1000);
const before = Services.prefs.getIntPref(client.lastCheckTimePref);

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

@ -24,7 +24,7 @@ Cu.import("resource://testing-common/AppInfo.jsm", this);
updateAppInfo({
name: appName,
ID: id,
version: version,
version,
platformVersion: platformVersion ? platformVersion : "1.0",
crashReporter: true,
});
@ -49,7 +49,7 @@ function do_get_kinto_collection(connection, collectionName) {
// Some simple tests to demonstrate that the core preload sync operations work
// correctly and that simple kinto operations are working as expected.
add_task(function* test_something(){
add_task(function* test_something() {
// set the collection name explicitly - since there will be version
// specific collection names in prefs
Services.prefs.setCharPref(PREF_BLOCKLIST_PINNING_COLLECTION,
@ -64,7 +64,7 @@ add_task(function* test_something(){
`http://localhost:${server.identity.primaryPort}/v1`);
// register a handler
function handleResponse (request, response) {
function handleResponse(request, response) {
try {
const sample = getSampleResponse(request, server.identity.primaryPort);
if (!sample) {
@ -245,7 +245,7 @@ function getSampleResponse(req, port) {
"versions" : [appInfo.version],
"id":"dabafde9-df4a-ddba-2548-748da04cc02c",
"last_modified":4000
},{
}, {
"pinType": "KeyPin",
"hostName": "three.example.com",
"includeSubdomains": false,
@ -255,7 +255,7 @@ function getSampleResponse(req, port) {
"versions" : [appInfo.version, "some other version that won't match"],
"id":"dabafde9-df4a-ddba-2548-748da04cc02d",
"last_modified":4000
},{
}, {
"pinType": "KeyPin",
"hostName": "four.example.com",
"includeSubdomains": false,
@ -265,7 +265,7 @@ function getSampleResponse(req, port) {
"versions" : ["some version that won't match"],
"id":"dabafde9-df4a-ddba-2548-748da04cc02e",
"last_modified":4000
},{
}, {
"pinType": "STSPin",
"hostName": "five.example.com",
"includeSubdomains": false,
@ -289,16 +289,16 @@ function getSampleResponse(req, port) {
"pinType": "KeyPin",
"id":"dabafde9-df4a-ddba-2548-748da04cc02f",
"last_modified":5000
},{
}, {
"irrelevant":"this entry has data of the wrong type",
"pinType": "KeyPin",
"hostName": 3,
"includeSubdomains": "nonsense",
"expires": "more nonsense",
"pins" : [1,2,3,4],
"pins" : [1, 2, 3, 4],
"id":"dabafde9-df4a-ddba-2548-748da04cc030",
"last_modified":5000
},{
}, {
"irrelevant":"this entry is missing the actual pins",
"pinType": "KeyPin",
"hostName": "missingpins.example.com",
@ -307,7 +307,7 @@ function getSampleResponse(req, port) {
"versions" : [appInfo.version],
"id":"dabafde9-df4a-ddba-2548-748da04cc031",
"last_modified":5000
},{
}, {
"pinType": "STSPin",
"hostName": "five.example.com",
"includeSubdomains": true,

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

@ -65,7 +65,7 @@ function* checkRecordCount(count) {
const sqliteHandle = yield FirefoxAdapter.openConnection({path: kintoFilename});
const config = {
remote: base,
bucket: bucket,
bucket,
adapter: FirefoxAdapter,
adapterOptions: {sqliteHandle},
};
@ -83,7 +83,7 @@ function* checkRecordCount(count) {
// Check to ensure maybeSync is called with correct values when a changes
// document contains information on when a collection was last modified
add_task(function* test_check_signatures(){
add_task(function* test_check_signatures() {
const port = server.identity.primaryPort;
// a response to give the client when the cert chain is expected
@ -97,7 +97,7 @@ add_task(function* test_check_signatures(){
public_key: "fake",
"content-signature": `x5u=http://localhost:${port}/test_blocklist_signatures/test_cert_chain.pem;p384ecdsa=${signature}`,
signature_encoding: "rs_base64url",
signature: signature,
signature,
hash_algorithm: "sha384",
ref: "1yryrnmzou5rf31ou80znpnq8n"
}
@ -107,7 +107,7 @@ add_task(function* test_check_signatures(){
function makeMetaResponse(eTag, body, comment) {
return {
comment: comment,
comment,
sampleHeaders: [
"Content-Type: application/json; charset=UTF-8",
`ETag: \"${eTag}\"`
@ -117,8 +117,8 @@ add_task(function* test_check_signatures(){
};
}
function registerHandlers(responses){
function handleResponse (serverTimeMillis, request, response) {
function registerHandlers(responses) {
function handleResponse(serverTimeMillis, request, response) {
const key = `${request.method}:${request.path}?${request.queryString}`;
const available = responses[key];
const sampled = available.length > 1 ? available.shift() : available[0];

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

@ -9,11 +9,11 @@ const PREF_CLOCK_SKEW_SECONDS = "services.blocklist.clock_skew_seconds";
// Check to ensure maybeSync is called with correct values when a changes
// document contains information on when a collection was last modified
add_task(function* test_check_maybeSync(){
add_task(function* test_check_maybeSync() {
const changesPath = "/v1/buckets/monitor/collections/changes/records";
// register a handler
function handleResponse (serverTimeMillis, request, response) {
function handleResponse(serverTimeMillis, request, response) {
try {
const sampled = getSampleResponse(request, server.identity.primaryPort);
if (!sampled) {
@ -87,7 +87,7 @@ add_task(function* test_check_maybeSync(){
Services.prefs.setIntPref(PREF_LAST_UPDATE, 0);
// If server has no change, a 304 is received, maybeSync() is not called.
updater.addTestBlocklistClient("test-collection", {
maybeSync: () => {throw new Error("Should not be called");}
maybeSync: () => { throw new Error("Should not be called"); }
});
yield updater.checkVersions();
// Last update is overwritten
@ -95,7 +95,7 @@ add_task(function* test_check_maybeSync(){
// Simulate a server error.
function simulateErrorResponse (request, response) {
function simulateErrorResponse(request, response) {
response.setHeader("Date", (new Date(3000)).toUTCString());
response.setHeader("Content-Type", "application/json; charset=UTF-8");
response.write(JSON.stringify({

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

@ -156,7 +156,7 @@ add_task(function* test_server_error() {
try {
yield client.request("/foo", method, TEST_CREDS);
do_throw("Expected an error");
} catch(err) {
} catch (err) {
do_check_eq(418, err.code);
do_check_eq("I am a Teapot", err.message);
}
@ -179,7 +179,7 @@ add_task(function* test_server_error_json() {
try {
yield client.request("/foo", method, TEST_CREDS);
do_throw("Expected an error");
} catch(err) {
} catch (err) {
do_check_eq("Cannot get ye flask.", err.error);
}
@ -312,7 +312,7 @@ add_task(function* test_retry_request_on_fail() {
let message = "i love you!!!";
response.setStatusLine(request.httpVersion, 200, "OK");
response.bodyOutputStream.write(message, message.length);
return;
}
});
@ -417,7 +417,7 @@ add_task(function* test_500_no_retry() {
try {
yield client.request("/no-shutup", method, credentials);
do_throw("Expected an error");
} catch(err) {
} catch (err) {
do_check_eq(err.code, 500);
}
@ -461,7 +461,7 @@ add_task(function* test_401_then_500() {
let message = "Cannot get ye flask.";
response.setStatusLine(request.httpVersion, 500, "Internal server error");
response.bodyOutputStream.write(message, message.length);
return;
}
});
@ -480,7 +480,7 @@ add_task(function* test_401_then_500() {
// Request will have bad timestamp; client will retry once
try {
yield client.request("/maybe", method, credentials);
} catch(err) {
} catch (err) {
do_check_eq(err.code, 500);
}
do_check_eq(attempts, 2);
@ -493,7 +493,7 @@ add_task(function* throw_if_not_json_body() {
try {
yield client.request("/bogus", "GET", {}, "I am not json");
do_throw("Expected an error");
} catch(err) {
} catch (err) {
do_check_true(!!err.message);
}
});
@ -501,7 +501,7 @@ add_task(function* throw_if_not_json_body() {
// End of tests.
// Utility functions follow
function getTimestampDelta(authHeader, now=Date.now()) {
function getTimestampDelta(authHeader, now = Date.now()) {
let tsMS = new Date(
parseInt(/ts="(\d+)"/.exec(authHeader)[1], 10) * SECOND_MS);
return Math.abs(tsMS - now);

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

@ -9,13 +9,13 @@ Cu.import("resource://services-common/hawkrequest.js");
// https://github.com/mozilla/fxa-auth-server/wiki/onepw-protocol#wiki-use-session-certificatesign-etc
var SESSION_KEYS = {
sessionToken: h("a0a1a2a3a4a5a6a7 a8a9aaabacadaeaf"+
sessionToken: h("a0a1a2a3a4a5a6a7 a8a9aaabacadaeaf" +
"b0b1b2b3b4b5b6b7 b8b9babbbcbdbebf"),
tokenID: h("c0a29dcf46174973 da1378696e4c82ae"+
tokenID: h("c0a29dcf46174973 da1378696e4c82ae" +
"10f723cf4f4d9f75 e39f4ae3851595ab"),
reqHMACkey: h("9d8f22998ee7f579 8b887042466b72d5"+
reqHMACkey: h("9d8f22998ee7f579 8b887042466b72d5" +
"3e56ab0c094388bf 65831f702d2febc0"),
};
@ -75,7 +75,7 @@ add_test(function test_intl_accept_language() {
do_print("Checked " + testCount + " languages. Removing checkLanguagePref as pref observer.");
Services.prefs.removeObserver("intl.accept_languages", checkLanguagePref);
run_next_test();
return;
});
}
});
@ -201,7 +201,7 @@ add_test(function test_hawk_language_pref_changed() {
do_check_eq(languages[0], request._intl.accept_languages);
// Change the language pref ...
setLanguage(languages[1]);
setLanguage(languages[1]);
CommonUtils.nextTick(testRequest);
}

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

@ -17,7 +17,7 @@ function do_get_kinto_sqliteHandle() {
return FirefoxAdapter.openConnection({path: kintoFilename});
}
function do_get_kinto_collection(sqliteHandle, collection="test_collection") {
function do_get_kinto_collection(sqliteHandle, collection = "test_collection") {
let config = {
remote:`http://localhost:${server.identity.primaryPort}/v1/`,
headers: {Authorization: "Basic " + btoa("user:pass")},
@ -154,7 +154,7 @@ add_task(function* test_kinto_clear() {
add_task(clear_collection);
add_task(function* test_kinto_delete(){
add_task(function* test_kinto_delete() {
let sqliteHandle;
try {
sqliteHandle = yield do_get_kinto_sqliteHandle();
@ -180,7 +180,7 @@ add_task(function* test_kinto_delete(){
}
});
add_task(function* test_kinto_list(){
add_task(function* test_kinto_list() {
let sqliteHandle;
try {
sqliteHandle = yield do_get_kinto_sqliteHandle();
@ -214,7 +214,7 @@ add_task(function* test_kinto_list(){
add_task(clear_collection);
add_task(function* test_loadDump_ignores_already_imported_records(){
add_task(function* test_loadDump_ignores_already_imported_records() {
let sqliteHandle;
try {
sqliteHandle = yield do_get_kinto_sqliteHandle();
@ -230,7 +230,7 @@ add_task(function* test_loadDump_ignores_already_imported_records(){
add_task(clear_collection);
add_task(function* test_loadDump_should_overwrite_old_records(){
add_task(function* test_loadDump_should_overwrite_old_records() {
let sqliteHandle;
try {
sqliteHandle = yield do_get_kinto_sqliteHandle();
@ -247,7 +247,7 @@ add_task(function* test_loadDump_should_overwrite_old_records(){
add_task(clear_collection);
add_task(function* test_loadDump_should_not_overwrite_unsynced_records(){
add_task(function* test_loadDump_should_not_overwrite_unsynced_records() {
let sqliteHandle;
try {
sqliteHandle = yield do_get_kinto_sqliteHandle();
@ -264,7 +264,7 @@ add_task(function* test_loadDump_should_not_overwrite_unsynced_records(){
add_task(clear_collection);
add_task(function* test_loadDump_should_not_overwrite_records_without_last_modified(){
add_task(function* test_loadDump_should_not_overwrite_records_without_last_modified() {
let sqliteHandle;
try {
sqliteHandle = yield do_get_kinto_sqliteHandle();
@ -284,11 +284,11 @@ add_task(clear_collection);
// Now do some sanity checks against a server - we're not looking to test
// core kinto.js functionality here (there is excellent test coverage in
// kinto.js), more making sure things are basically working as expected.
add_task(function* test_kinto_sync(){
add_task(function* test_kinto_sync() {
const configPath = "/v1/";
const recordsPath = "/v1/buckets/default/collections/test_collection/records";
// register a handler
function handleResponse (request, response) {
function handleResponse(request, response) {
try {
const sampled = getSampleResponse(request, server.identity.primaryPort);
if (!sampled) {

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

@ -25,7 +25,7 @@ const non_android_test_modules = [
"storageserver.js",
];
function expectImportsToSucceed(mm, base=MODULE_BASE) {
function expectImportsToSucceed(mm, base = MODULE_BASE) {
for (let m of mm) {
let resource = base + m;
let succeeded = false;
@ -40,7 +40,7 @@ function expectImportsToSucceed(mm, base=MODULE_BASE) {
}
}
function expectImportsToFail(mm, base=MODULE_BASE) {
function expectImportsToFail(mm, base = MODULE_BASE) {
for (let m of mm) {
let resource = base + m;
let succeeded = false;

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

@ -36,7 +36,7 @@ add_test(function test_function_observer() {
add_test(function test_method_observer() {
let obj = {
foo: false,
onFoo: function(subject, data) {
onFoo(subject, data) {
this.foo = !this.foo;
do_check_eq(subject, gSubject);
do_check_eq(data, "some data");
@ -59,7 +59,7 @@ add_test(function test_method_observer() {
add_test(function test_object_observer() {
let obj = {
foo: false,
observe: function(subject, topic, data) {
observe(subject, topic, data) {
this.foo = !this.foo;
do_check_eq(subject, gSubject);

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

@ -76,7 +76,7 @@ add_test(function test_proxy_auth_redirect() {
installFakePAC();
let res = new RESTRequest(server.baseURI + "/original");
res.get(function (error) {
res.get(function(error) {
do_check_true(pacFetched);
do_check_true(fetched);
do_check_true(!error);
@ -110,7 +110,7 @@ add_test(function test_simple_get() {
let handler = httpd_handler(200, "OK", "Huzzah!");
let server = httpd_setup({"/resource": handler});
let request = new RESTRequest(server.baseURI + "/resource").get(function (error) {
let request = new RESTRequest(server.baseURI + "/resource").get(function(error) {
do_check_eq(error, null);
do_check_eq(this.status, this.COMPLETED);
@ -134,7 +134,7 @@ add_test(function test_get() {
let request = new RESTRequest(server.baseURI + "/resource");
do_check_eq(request.status, request.NOT_SENT);
request.onProgress = request.onComplete = function () {
request.onProgress = request.onComplete = function() {
do_throw("This function should have been overwritten!");
};
@ -146,7 +146,7 @@ add_test(function test_get() {
do_check_true(!!(this.channel.loadFlags & Ci.nsIRequest.LOAD_BYPASS_CACHE));
do_check_true(!!(this.channel.loadFlags & Ci.nsIRequest.INHIBIT_CACHING));
};
}
function onComplete(error) {
do_check_eq(error, null);
@ -158,17 +158,17 @@ add_test(function test_get() {
do_check_eq(handler.request.method, "GET");
do_check_true(onProgress_called);
CommonUtils.nextTick(function () {
CommonUtils.nextTick(function() {
do_check_eq(request.onComplete, null);
do_check_eq(request.onProgress, null);
server.stop(run_next_test);
});
};
}
do_check_eq(request.get(onComplete, onProgress), request);
do_check_eq(request.status, request.SENT);
do_check_eq(request.method, "GET");
do_check_throws(function () {
do_check_throws(function() {
request.get();
});
});
@ -315,7 +315,7 @@ function check_posting_data(method) {
let request = new RESTRequest(server.baseURI + "/resource");
do_check_eq(request.status, request.NOT_SENT);
request.onProgress = request.onComplete = function () {
request.onProgress = request.onComplete = function() {
do_throw("This function should have been overwritten!");
};
@ -324,7 +324,7 @@ function check_posting_data(method) {
onProgress_called = true;
do_check_eq(this.status, request.IN_PROGRESS);
do_check_true(this.response.body.length > 0);
};
}
function onComplete(error) {
do_check_eq(error, null);
@ -339,17 +339,17 @@ function check_posting_data(method) {
do_check_eq(handler.request.getHeader("Content-Type"), "text/plain");
do_check_true(onProgress_called);
CommonUtils.nextTick(function () {
CommonUtils.nextTick(function() {
do_check_eq(request.onComplete, null);
do_check_eq(request.onProgress, null);
server.stop(run_next_test);
});
};
}
do_check_eq(request[funcName]("Hullo?", onComplete, onProgress), request);
do_check_eq(request.status, request.SENT);
do_check_eq(request.method, method);
do_check_throws(function () {
do_check_throws(function() {
request[funcName]("Hai!");
});
}
@ -385,7 +385,7 @@ add_test(function test_delete() {
let request = new RESTRequest(server.baseURI + "/resource");
do_check_eq(request.status, request.NOT_SENT);
request.onProgress = request.onComplete = function () {
request.onProgress = request.onComplete = function() {
do_throw("This function should have been overwritten!");
};
@ -394,7 +394,7 @@ add_test(function test_delete() {
onProgress_called = true;
do_check_eq(this.status, request.IN_PROGRESS);
do_check_true(this.response.body.length > 0);
};
}
function onComplete(error) {
do_check_eq(error, null);
@ -406,17 +406,17 @@ add_test(function test_delete() {
do_check_eq(handler.request.method, "DELETE");
do_check_true(onProgress_called);
CommonUtils.nextTick(function () {
CommonUtils.nextTick(function() {
do_check_eq(request.onComplete, null);
do_check_eq(request.onProgress, null);
server.stop(run_next_test);
});
};
}
do_check_eq(request.delete(onComplete, onProgress), request);
do_check_eq(request.status, request.SENT);
do_check_eq(request.method, "DELETE");
do_check_throws(function () {
do_check_throws(function() {
request.delete();
});
});
@ -429,7 +429,7 @@ add_test(function test_get_404() {
let server = httpd_setup({"/resource": handler});
let request = new RESTRequest(server.baseURI + "/resource");
request.get(function (error) {
request.get(function(error) {
do_check_eq(error, null);
do_check_eq(this.status, this.COMPLETED);
@ -455,7 +455,7 @@ add_test(function test_put_json() {
number: 42
};
let request = new RESTRequest(server.baseURI + "/resource");
request.put(sample_data, function (error) {
request.put(sample_data, function(error) {
do_check_eq(error, null);
do_check_eq(this.status, this.COMPLETED);
@ -485,7 +485,7 @@ add_test(function test_post_json() {
number: 42
};
let request = new RESTRequest(server.baseURI + "/resource");
request.post(sample_data, function (error) {
request.post(sample_data, function(error) {
do_check_eq(error, null);
do_check_eq(this.status, this.COMPLETED);
@ -511,7 +511,7 @@ add_test(function test_post_json() {
let sample_data = "hello";
let request = new RESTRequest(server.baseURI + "/resource");
request.post(sample_data, function (error) {
request.post(sample_data, function(error) {
do_check_eq(error, null);
do_check_eq(this.status, this.COMPLETED);
@ -536,7 +536,7 @@ add_test(function test_put_override_content_type() {
let request = new RESTRequest(server.baseURI + "/resource");
request.setHeader("Content-Type", "application/lolcat");
request.put("O HAI!!1!", function (error) {
request.put("O HAI!!1!", function(error) {
do_check_eq(error, null);
do_check_eq(this.status, this.COMPLETED);
@ -561,7 +561,7 @@ add_test(function test_post_override_content_type() {
let request = new RESTRequest(server.baseURI + "/resource");
request.setHeader("Content-Type", "application/lolcat");
request.post("O HAI!!1!", function (error) {
request.post("O HAI!!1!", function(error) {
do_check_eq(error, null);
do_check_eq(this.status, this.COMPLETED);
@ -589,7 +589,7 @@ add_test(function test_get_no_headers() {
"connection", "pragma", "cache-control",
"content-length"];
new RESTRequest(server.baseURI + "/resource").get(function (error) {
new RESTRequest(server.baseURI + "/resource").get(function(error) {
do_check_eq(error, null);
do_check_eq(this.response.status, 200);
@ -616,7 +616,7 @@ add_test(function test_changing_uri() {
let request = new RESTRequest("http://localhost:1234/the-wrong-resource");
request.uri = CommonUtils.makeURI(server.baseURI + "/resource");
request.get(function (error) {
request.get(function(error) {
do_check_eq(error, null);
do_check_eq(this.response.status, 200);
server.stop(run_next_test);
@ -636,7 +636,7 @@ add_test(function test_request_setHeader() {
request.setHeader("X-WHAT-is-Weave", "more awesomer");
request.setHeader("Another-Header", "Hello World");
request.get(function (error) {
request.get(function(error) {
do_check_eq(error, null);
do_check_eq(this.response.status, 200);
@ -661,7 +661,7 @@ add_test(function test_response_headers() {
let server = httpd_setup({"/resource": handler});
let request = new RESTRequest(server.baseURI + "/resource");
request.get(function (error) {
request.get(function(error) {
do_check_eq(error, null);
do_check_eq(this.response.status, 200);
@ -683,7 +683,7 @@ add_test(function test_connection_refused() {
request.onProgress = function onProgress() {
do_throw("Shouldn't have called request.onProgress()!");
};
request.get(function (error) {
request.get(function(error) {
do_check_eq(error.result, Cr.NS_ERROR_CONNECTION_REFUSED);
do_check_eq(error.message, "NS_ERROR_CONNECTION_REFUSED");
do_check_eq(this.status, this.COMPLETED);
@ -704,23 +704,23 @@ add_test(function test_abort() {
let request = new RESTRequest(server.baseURI + "/resource");
// Aborting a request that hasn't been sent yet is pointless and will throw.
do_check_throws(function () {
do_check_throws(function() {
request.abort();
});
request.onProgress = request.onComplete = function () {
request.onProgress = request.onComplete = function() {
do_throw("Shouldn't have gotten here!");
};
request.get();
request.abort();
// Aborting an already aborted request is pointless and will throw.
do_check_throws(function () {
do_check_throws(function() {
request.abort();
});
do_check_eq(request.status, request.ABORTED);
CommonUtils.nextTick(function () {
CommonUtils.nextTick(function() {
server.stop(run_next_test);
});
});
@ -746,7 +746,7 @@ add_test(function test_timeout() {
let request = new RESTRequest(uri + "/resource");
request.timeout = 0.1; // 100 milliseconds
request.get(function (error) {
request.get(function(error) {
do_check_eq(error.result, Cr.NS_ERROR_NET_TIMEOUT);
do_check_eq(this.status, this.ABORTED);
@ -818,7 +818,7 @@ add_test(function test_new_channel() {
redirectURL = server2.baseURI + "/resource";
function advance() {
server1.stop(function () {
server1.stop(function() {
server2.stop(run_next_test);
});
}
@ -863,7 +863,7 @@ add_test(function test_not_sending_cookie() {
cookieSer.setCookieString(uri, null, "test=test; path=/;", null);
let res = new RESTRequest(server.baseURI + "/test");
res.get(function (error) {
res.get(function(error) {
do_check_null(error);
do_check_true(this.response.success);
do_check_eq("COOKIE!", this.response.body);

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

@ -23,7 +23,7 @@ function do_get_kinto_db() {
}
function cleanup_kinto() {
add_test(function cleanup_kinto_files(){
add_test(function cleanup_kinto_files() {
let kintoDB = do_get_kinto_db();
// clean up the db
kintoDB.remove(false);
@ -251,7 +251,7 @@ add_test(function test_creation_from_empty_db() {
let kintoDB = do_get_kinto_db();
let emptyDB = do_get_file("test_storage_adapter/empty.sqlite");
emptyDB.copyTo(profile,kintoFilename);
emptyDB.copyTo(profile, kintoFilename);
run_next_test();
});

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

@ -12,7 +12,7 @@ const DEFAULT_PASSWORD = "password";
/**
* Helper function to prepare a RESTRequest against the server.
*/
function localRequest(server, path, user=DEFAULT_USER, password=DEFAULT_PASSWORD) {
function localRequest(server, path, user = DEFAULT_USER, password = DEFAULT_PASSWORD) {
_("localRequest: " + path);
let identity = server.server.identity;
let url = identity.primaryScheme + "://" + identity.primaryHost + ":" +
@ -121,7 +121,7 @@ add_test(function test_creation() {
});
do_check_true(!!server);
server.start(-1, function () {
server.start(-1, function() {
_("Started on " + server.port);
server.stop(run_next_test);
});
@ -191,7 +191,7 @@ add_test(function test_basic_http() {
do_check_eq(server.requestCount, 0);
let req = localRequest(server, "/2.0/storage/crypto/keys");
_("req is " + req);
req.get(function (err) {
req.get(function(err) {
do_check_eq(null, err);
do_check_eq(server.requestCount, 1);
server.stop(run_next_test);
@ -593,11 +593,11 @@ add_test(function test_x_num_records() {
});
server.startSynchronous();
let bso = localRequest(server, "/2.0/123/storage/crypto/foos");
bso.get(function (err) {
bso.get(function(err) {
// BSO fetches don't have one.
do_check_false("x-num-records" in this.response.headers);
let col = localRequest(server, "/2.0/123/storage/crypto");
col.get(function (err) {
col.get(function(err) {
// Collection fetches do.
do_check_eq(this.response.headers["x-num-records"], "2");
server.stop(run_next_test);

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

@ -24,7 +24,7 @@ add_test(function test_authenticated_request() {
let nonce = btoa(CryptoUtils.generateRandomBytes(16));
let ts = Math.floor(Date.now() / 1000);
let extra = {ts: ts, nonce: nonce};
let extra = {ts, nonce};
let auth;
@ -40,7 +40,7 @@ add_test(function test_authenticated_request() {
let sig = CryptoUtils.computeHTTPMACSHA1(id, key, method, uri, extra);
auth = sig.getHeader();
let req = new TokenAuthenticatedRESTRequest(uri, {id: id, key: key}, extra);
let req = new TokenAuthenticatedRESTRequest(uri, {id, key}, extra);
let cb = Async.makeSpinningCallback();
req.get(cb);
let result = cb.wait();

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

@ -30,7 +30,7 @@ add_test(function test_working_bid_exchange() {
key: "key",
api_endpoint: service,
uid: "uid",
duration: duration,
duration,
});
response.bodyOutputStream.write(body, body.length);
}
@ -87,7 +87,7 @@ add_test(function test_conditions_required_response_handling() {
response.setHeader("Content-Type", "application/json");
let body = JSON.stringify({
errors: [{description: description, location: "body", name: ""}],
errors: [{description, location: "body", name: ""}],
urls: {tos: tosURL}
});
response.bodyOutputStream.write(body, body.length);
@ -221,7 +221,7 @@ add_test(function test_send_extra_headers() {
key: "key",
api_endpoint: "http://example.com/",
uid: "uid",
duration: duration,
duration,
});
response.bodyOutputStream.write(body, body.length);
}
@ -408,7 +408,7 @@ add_test(function test_rich_media_types() {
key: "key",
api_endpoint: "foo",
uid: "uid",
duration: duration,
duration,
});
response.bodyOutputStream.write(body, body.length);
}
@ -437,7 +437,7 @@ add_test(function test_exception_during_callback() {
key: "key",
api_endpoint: "foo",
uid: "uid",
duration: duration,
duration,
});
response.bodyOutputStream.write(body, body.length);
}

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

@ -8,21 +8,21 @@ Cu.import("resource://services-common/utils.js");
// A wise line of Greek verse, and the utf-8 byte encoding.
// N.b., Greek begins at utf-8 ce 91
const TEST_STR = "πόλλ' οἶδ' ἀλώπηξ, ἀλλ' ἐχῖνος ἓν μέγα";
const TEST_HEX = h("cf 80 cf 8c ce bb ce bb 27 20 ce bf e1 bc b6 ce"+
"b4 27 20 e1 bc 80 ce bb cf 8e cf 80 ce b7 ce be"+
"2c 20 e1 bc 80 ce bb ce bb 27 20 e1 bc 90 cf 87"+
"e1 bf 96 ce bd ce bf cf 82 20 e1 bc 93 ce bd 20"+
const TEST_HEX = h("cf 80 cf 8c ce bb ce bb 27 20 ce bf e1 bc b6 ce" +
"b4 27 20 e1 bc 80 ce bb cf 8e cf 80 ce b7 ce be" +
"2c 20 e1 bc 80 ce bb ce bb 27 20 e1 bc 90 cf 87" +
"e1 bf 96 ce bd ce bf cf 82 20 e1 bc 93 ce bd 20" +
"ce bc ce ad ce b3 ce b1");
// Integer byte values for the above
const TEST_BYTES = [207,128,207,140,206,187,206,187,
39, 32,206,191,225,188,182,206,
180, 39, 32,225,188,128,206,187,
207,142,207,128,206,183,206,190,
44, 32,225,188,128,206,187,206,
187, 39, 32,225,188,144,207,135,
225,191,150,206,189,206,191,207,
130, 32,225,188,147,206,189, 32,
206,188,206,173,206,179,206,177];
const TEST_BYTES = [207, 128, 207, 140, 206, 187, 206, 187,
39, 32, 206, 191, 225, 188, 182, 206,
180, 39, 32, 225, 188, 128, 206, 187,
207, 142, 207, 128, 206, 183, 206, 190,
44, 32, 225, 188, 128, 206, 187, 206,
187, 39, 32, 225, 188, 144, 207, 135,
225, 191, 150, 206, 189, 206, 191, 207,
130, 32, 225, 188, 147, 206, 189, 32,
206, 188, 206, 173, 206, 179, 206, 177];
function run_test() {
run_next_test();

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

@ -13,7 +13,7 @@ add_test(function test_simple() {
"<>?": "PD4_",
};
for (let [k,v] of Object.entries(expected)) {
for (let [k, v] of Object.entries(expected)) {
do_check_eq(CommonUtils.encodeBase64URL(k), v);
}

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

@ -27,7 +27,7 @@ add_test(function test_writeJSON_readJSON() {
do_check_eq(contents.d, json.d);
do_check_eq(contents.e, json.e);
run_next_test();
};
}
function doRead() {
CommonUtils.readJSON(path)

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

@ -13,7 +13,7 @@ add_test(function test_required_args() {
do_throw("Shouldn't fire.");
}, 0);
do_throw("Should have thrown!");
} catch(ex) {
} catch (ex) {
run_next_test();
}
});

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

@ -99,7 +99,7 @@ TokenServerClientNetworkError.prototype._toStringFields = function() {
* (string) Error message.
*/
this.TokenServerClientServerError =
function TokenServerClientServerError(message, cause="general") {
function TokenServerClientServerError(message, cause = "general") {
this.now = new Date().toISOString(); // may be useful to diagnose time-skew issues.
this.name = "TokenServerClientServerError";
this.message = message || "Server error.";
@ -244,7 +244,7 @@ TokenServerClient.prototype = {
* (bool) Whether to send acceptance to service conditions.
*/
getTokenFromBrowserIDAssertion:
function getTokenFromBrowserIDAssertion(url, assertion, cb, addHeaders={}) {
function getTokenFromBrowserIDAssertion(url, assertion, cb, addHeaders = {}) {
if (!url) {
throw new TokenServerClientError("url argument is not valid.");
}
@ -436,7 +436,7 @@ TokenServerClient.prototype = {
observerPrefix: null,
// Given an optional header value, notify that a backoff has been requested.
_maybeNotifyBackoff: function (response, headerName) {
_maybeNotifyBackoff(response, headerName) {
if (!this.observerPrefix) {
return;
}
@ -456,7 +456,7 @@ TokenServerClient.prototype = {
},
// override points for testing.
newRESTRequest: function(url) {
newRESTRequest(url) {
return new RESTRequest(url);
}
};

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

@ -21,7 +21,7 @@ this.CommonUtils = {
/**
* Return elements of `a` or `b`.
*/
union: function (a, b) {
union(a, b) {
let out = new Set(a);
for (let x of b) {
out.add(x);
@ -32,7 +32,7 @@ this.CommonUtils = {
/**
* Return elements of `a` that are not present in `b`.
*/
difference: function (a, b) {
difference(a, b) {
let out = new Set(a);
for (let x of b) {
out.delete(x);
@ -43,7 +43,7 @@ this.CommonUtils = {
/**
* Return elements of `a` that are also in `b`.
*/
intersection: function (a, b) {
intersection(a, b) {
let out = new Set();
for (let x of a) {
if (b.has(x)) {
@ -57,7 +57,7 @@ this.CommonUtils = {
* Return true if `a` and `b` are the same size, and
* every element of `a` is in `b`.
*/
setEqual: function (a, b) {
setEqual(a, b) {
if (a.size != b.size) {
return false;
}
@ -78,7 +78,7 @@ this.CommonUtils = {
* (bool) Whether to include padding characters (=). Defaults
* to true for historical reasons.
*/
encodeBase64URL: function encodeBase64URL(bytes, pad=true) {
encodeBase64URL: function encodeBase64URL(bytes, pad = true) {
let s = btoa(bytes).replace(/\+/g, "-").replace(/\//g, "_");
if (!pad) {
@ -125,7 +125,7 @@ this.CommonUtils = {
* accumulation and prevents callers from accidentally relying on
* same-tick promise resolution.
*/
laterTickResolvingPromise: function (value, prototype) {
laterTickResolvingPromise(value, prototype) {
let deferred = Promise.defer(prototype);
this.nextTick(deferred.resolve.bind(deferred, value));
return deferred.promise;
@ -142,7 +142,7 @@ this.CommonUtils = {
this.nextTick(cb);
Async.waitForSyncCallback(cb);
return;
},
/**
@ -380,7 +380,7 @@ this.CommonUtils = {
* @param path the file to read. Will be passed to `OS.File.read()`.
* @return a promise that resolves to the JSON contents of the named file.
*/
readJSON: function(path) {
readJSON(path) {
return OS.File.read(path, { encoding: "utf-8" }).then((data) => {
return JSON.parse(data);
});
@ -393,7 +393,7 @@ this.CommonUtils = {
* @param path the path of the file to write.
* @return a promise, as produced by OS.File.writeAtomic.
*/
writeJSON: function(contents, path) {
writeJSON(contents, path) {
let data = JSON.stringify(contents);
return OS.File.writeAtomic(path, data, {encoding: "utf-8", tmpPath: path + ".tmp"});
},
@ -492,7 +492,7 @@ this.CommonUtils = {
* @param log
* (Log.Logger) Logger to write warnings to.
*/
getEpochPref: function getEpochPref(branch, pref, def=0, log=null) {
getEpochPref: function getEpochPref(branch, pref, def = 0, log = null) {
if (!Number.isInteger(def)) {
throw new Error("Default value is not a number: " + def);
}
@ -537,8 +537,8 @@ this.CommonUtils = {
* @param oldestYear
* (Number) Oldest year to accept in read values.
*/
getDatePref: function getDatePref(branch, pref, def=0, log=null,
oldestYear=2010) {
getDatePref: function getDatePref(branch, pref, def = 0, log = null,
oldestYear = 2010) {
let valueInt = this.getEpochPref(branch, pref, def, log);
let date = new Date(valueInt);
@ -572,7 +572,7 @@ this.CommonUtils = {
* @param oldestYear
* (Number) The oldest year to accept for values.
*/
setDatePref: function setDatePref(branch, pref, date, oldestYear=2010) {
setDatePref: function setDatePref(branch, pref, date, oldestYear = 2010) {
if (date.getFullYear() < oldestYear) {
throw new Error("Trying to set " + pref + " to a very old time: " +
date + ". The current time is " + new Date() +

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

@ -8,7 +8,7 @@ function do_check_throws(func) {
let have_error = false;
try {
func();
} catch(ex) {
} catch (ex) {
dump("Was expecting an exception. Caught: " + ex + "\n");
have_error = true;
}
@ -199,7 +199,7 @@ function test_x4_zero() {
a_gx2.value, a_gv2.value, a_r2.value, b_A, b_gva, b_ra);
});
};
// g^x is NIST 3072's p + 1, (p + 1) mod p == 1, x == 0
test("90066455B5CFC38F9CAA4A48B4281F292C260FEEF01FD61037E56258A7795A1C"
+ "7AD46076982CE6BB956936C6AB4DCFE05E6784586940CA544B9B2140E1EB523F"
@ -246,7 +246,7 @@ function test_x4_zero() {
}
function test_invalid_input_round2() {
let a = Cc["@mozilla.org/services-crypto/sync-jpake;1"]
let a = Cc["@mozilla.org/services-crypto/sync-jpake;1"]
.createInstance(Ci.nsISyncJPAKE);
a.round1("alice", {}, {}, {}, {}, {}, {});

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

@ -120,7 +120,7 @@ WeaveCrypto.prototype = {
? crypto.subtle.encrypt
: crypto.subtle.decrypt)
.bind(crypto.subtle);
let algo = { name: CRYPT_ALGO, iv: iv };
let algo = { name: CRYPT_ALGO, iv };
return Async.promiseSpinningly(
@ -245,7 +245,7 @@ WeaveCrypto.prototype = {
let importAlgo = { name: KEY_DERIVATION_ALGO };
let deriveAlgo = {
name: KEY_DERIVATION_ALGO,
salt: salt,
salt,
iterations: KEY_DERIVATION_ITERATIONS,
hash: { name: KEY_DERIVATION_HASHING_ALGO },
};

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

@ -15,7 +15,7 @@ this.CryptoUtils = {
let bytes = [];
if (a.length != b.length) {
throw new Error("can't xor unequal length strings: "+a.length+" vs "+b.length);
throw new Error("can't xor unequal length strings: " + a.length + " vs " + b.length);
}
for (let i = 0; i < a.length; i++) {
@ -71,7 +71,7 @@ this.CryptoUtils = {
* with a single hasher, but eventually you must extract the result
* yourself.
*/
updateUTF8: function(message, hasher) {
updateUTF8(message, hasher) {
let bytes = this._utf8Converter.convertToByteArray(message, {});
hasher.update(bytes, bytes.length);
},
@ -136,10 +136,10 @@ this.CryptoUtils = {
hkdf: function hkdf(ikm, xts, info, len) {
const BLOCKSIZE = 256 / 8;
if (typeof xts === undefined)
xts = String.fromCharCode(0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0);
xts = String.fromCharCode(0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0);
let h = CryptoUtils.makeHMACHasher(Ci.nsICryptoHMAC.SHA256,
CryptoUtils.makeHMACKey(xts));
let prk = CryptoUtils.digestBytes(ikm, h);
@ -155,7 +155,7 @@ this.CryptoUtils = {
CryptoUtils.makeHMACKey(prk));
let T = "";
let Tn = "";
let iterations = Math.ceil(len/BLOCKSIZE);
let iterations = Math.ceil(len / BLOCKSIZE);
for (let i = 0; i < iterations; i++) {
Tn = CryptoUtils.digestBytes(Tn + info + String.fromCharCode(i + 1), h);
T += Tn;
@ -184,7 +184,7 @@ this.CryptoUtils = {
* can encode as you wish.
*/
pbkdf2Generate : function pbkdf2Generate(P, S, c, dkLen,
hmacAlg=Ci.nsICryptoHMAC.SHA1, hmacLen=20) {
hmacAlg = Ci.nsICryptoHMAC.SHA1, hmacLen = 20) {
// We don't have a default in the algo itself, as NSS does.
// Use the constant.
@ -247,7 +247,7 @@ this.CryptoUtils = {
}
let ret = "";
for (let i = 0; i < l-1;) {
for (let i = 0; i < l - 1;) {
ret += T[i++];
}
ret += T[l - 1].substr(0, r);
@ -261,8 +261,7 @@ this.CryptoUtils = {
forceJS) {
if (Svc.Crypto.deriveKeyFromPassphrase && !forceJS) {
return Svc.Crypto.deriveKeyFromPassphrase(passphrase, salt, keyLength);
}
else {
} else {
// Fall back to JS implementation.
// 4096 is hardcoded in WeaveCrypto, so do so here.
return CryptoUtils.pbkdf2Generate(passphrase, atob(salt), 4096,
@ -334,12 +333,12 @@ this.CryptoUtils = {
let ext = (extra && extra.ext) ? extra.ext : "";
let requestString = ts.toString(10) + "\n" +
nonce + "\n" +
usedMethod + "\n" +
uri.path + "\n" +
host + "\n" +
port + "\n" +
ext + "\n";
nonce + "\n" +
usedMethod + "\n" +
uri.path + "\n" +
host + "\n" +
port + "\n" +
ext + "\n";
let hasher = CryptoUtils.makeHMACHasher(Ci.nsICryptoHMAC.SHA1,
CryptoUtils.makeHMACKey(key));
@ -351,16 +350,16 @@ this.CryptoUtils = {
}
return {
identifier: identifier,
key: key,
identifier,
key,
method: usedMethod,
hostname: host,
port: port,
mac: mac,
nonce: nonce,
ts: ts,
ext: ext,
getHeader: getHeader
port,
mac,
nonce,
ts,
ext,
getHeader
};
},
@ -383,23 +382,23 @@ this.CryptoUtils = {
*/
getHTTPMACSHA1Header: function getHTTPMACSHA1Header(identifier, ts, nonce,
mac, ext) {
let header ='MAC id="' + identifier + '", ' +
'ts="' + ts + '", ' +
'nonce="' + nonce + '", ' +
'mac="' + btoa(mac) + '"';
let header = 'MAC id="' + identifier + '", ' +
'ts="' + ts + '", ' +
'nonce="' + nonce + '", ' +
'mac="' + btoa(mac) + '"';
if (!ext) {
return header;
}
return header += ', ext="' + ext +'"';
return header += ', ext="' + ext + '"';
},
/**
* Given an HTTP header value, strip out any attributes.
*/
stripHeaderAttributes: function(value) {
stripHeaderAttributes(value) {
value = value || "";
let i = value.indexOf(";");
return value.substring(0, (i >= 0) ? i : undefined).trim().toLowerCase();
@ -458,7 +457,7 @@ this.CryptoUtils = {
* ext - (string) app-specific data
* MAC - (string) request MAC (base64)
*/
computeHAWK: function(uri, method, options) {
computeHAWK(uri, method, options) {
let credentials = options.credentials;
let ts = options.ts || Math.floor(((options.now || Date.now()) +
(options.localtimeOffsetMsec || 0))
@ -487,7 +486,7 @@ this.CryptoUtils = {
}
let artifacts = {
ts: ts,
ts,
nonce: options.nonce || btoa(CryptoUtils.generateRandomBytes(8)),
method: method.toUpperCase(),
resource: uri.path, // This includes both path and search/queryarg.
@ -505,7 +504,7 @@ this.CryptoUtils = {
.createInstance(Ci.nsICryptoHash);
hasher.init(hash_algo);
CryptoUtils.updateUTF8("hawk.1.payload\n", hasher);
CryptoUtils.updateUTF8(contentType+"\n", hasher);
CryptoUtils.updateUTF8(contentType + "\n", hasher);
CryptoUtils.updateUTF8(options.payload, hasher);
CryptoUtils.updateUTF8("\n", hasher);
let hash = hasher.finish(false);
@ -515,13 +514,13 @@ this.CryptoUtils = {
artifacts.hash = hash_b64;
}
let requestString = ("hawk.1.header" + "\n" +
let requestString = ("hawk.1.header" + "\n" +
artifacts.ts.toString(10) + "\n" +
artifacts.nonce + "\n" +
artifacts.method + "\n" +
artifacts.resource + "\n" +
artifacts.host + "\n" +
artifacts.port + "\n" +
artifacts.nonce + "\n" +
artifacts.method + "\n" +
artifacts.resource + "\n" +
artifacts.host + "\n" +
artifacts.port + "\n" +
(artifacts.hash || "") + "\n");
if (artifacts.ext) {
requestString += artifacts.ext.replace("\\", "\\\\").replace("\n", "\\n");
@ -544,7 +543,7 @@ this.CryptoUtils = {
(artifacts.ext ? ('ext="' + escape(artifacts.ext) + '", ') : "") +
'mac="' + artifacts.mac + '"');
return {
artifacts: artifacts,
artifacts,
field: header,
};
},

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

@ -8,8 +8,7 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
try {
// In the context of xpcshell tests, there won't be a default AppInfo
Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo);
}
catch(ex) {
} catch (ex) {
// Make sure to provide the right OS so crypto loads the right binaries
var OS = "XPCShell";
@ -26,7 +25,7 @@ updateAppInfo({
ID: "{3e3ba16c-1675-4e88-b9c8-afef81b3d2ef}",
version: "1",
platformVersion: "",
OS: OS,
OS,
});
}

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

@ -29,8 +29,8 @@ add_test(function test_hawk() {
let uri_http = CommonUtils.makeURI("http://example.net/somewhere/over/the/rainbow");
let sha1_opts = { credentials: credentials_sha1,
ext: "Bazinga!",
ts: ts,
nonce: nonce,
ts,
nonce,
payload: "something to write about",
};
result = compute(uri_http, method, sha1_opts);
@ -60,8 +60,8 @@ add_test(function test_hawk() {
let uri_https = CommonUtils.makeURI("https://example.net/somewhere/over/the/rainbow");
let sha256_opts = { credentials: credentials_sha256,
ext: "Bazinga!",
ts: ts,
nonce: nonce,
ts,
nonce,
payload: "something to write about",
contentType: "text/plain",
};
@ -83,8 +83,8 @@ add_test(function test_hawk() {
do_check_eq(result.artifacts.ext, "Bazinga!");
let sha256_opts_noext = { credentials: credentials_sha256,
ts: ts,
nonce: nonce,
ts,
nonce,
payload: "something to write about",
contentType: "text/plain",
};
@ -116,8 +116,8 @@ add_test(function test_hawk() {
/* The HAWK spec calls for seconds-since-epoch, not ms-since-epoch.
* Warning: this test will fail in the year 33658, and for time travellers
* who journey earlier than 2001. Please plan accordingly. */
do_check_true(result.artifacts.ts > 1000*1000*1000);
do_check_true(result.artifacts.ts < 1000*1000*1000*1000);
do_check_true(result.artifacts.ts > 1000 * 1000 * 1000);
do_check_true(result.artifacts.ts < 1000 * 1000 * 1000 * 1000);
do_check_true(fields[3].startsWith('nonce="'));
do_check_eq(fields[3].length, ('nonce="12345678901=",').length);
do_check_eq(result.artifacts.nonce.length, ("12345678901=").length);
@ -159,7 +159,7 @@ add_test(function test_hawk() {
result = compute(uri_https, method, { credentials: credentials_sha256,
now: 1378848968650,
localtimeOffsetMsec: 1000*1000,
localtimeOffsetMsec: 1000 * 1000,
});
do_check_eq(result.artifacts.ts, 1378848968 + 1000);

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

@ -22,7 +22,7 @@ add_test(function test_sha1() {
let uri = CommonUtils.makeURI("http://10.250.2.176/alias/");
let result = CryptoUtils.computeHTTPMACSHA1(id, key, method, uri,
{ts: ts, nonce: nonce});
{ts, nonce});
do_check_eq(btoa(result.mac), "jzh5chjQc2zFEvLbyHnPdX11Yck=");
@ -33,7 +33,7 @@ add_test(function test_sha1() {
let ext = "EXTRA DATA; foo,bar=1";
result = CryptoUtils.computeHTTPMACSHA1(id, key, method, uri,
{ts: ts, nonce: nonce, ext: ext});
{ts, nonce, ext});
do_check_eq(btoa(result.mac), "bNf4Fnt5k6DnhmyipLPkuZroH68=");
do_check_eq(result.getHeader(),
'MAC id="vmo1txkttblmn51u2p3zk2xiy16hgvm5ok8qiv1yyi86ffjzy9zj0ez9x6wnvbx7", ' +

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

@ -30,8 +30,8 @@ add_task(function test_pbkdf2_hmac_sha1() {
S: "salt", // (4 octets)
c: 1,
dkLen: 20,
DK: h("0c 60 c8 0f 96 1f 0e 71"+
"f3 a9 b5 24 af 60 12 06"+
DK: h("0c 60 c8 0f 96 1f 0e 71" +
"f3 a9 b5 24 af 60 12 06" +
"2f e0 37 a6"), // (20 octets)
},
@ -39,8 +39,8 @@ add_task(function test_pbkdf2_hmac_sha1() {
S: "salt", // (4 octets)
c: 2,
dkLen: 20,
DK: h("ea 6c 01 4d c7 2d 6f 8c"+
"cd 1e d9 2a ce 1d 41 f0"+
DK: h("ea 6c 01 4d c7 2d 6f 8c" +
"cd 1e d9 2a ce 1d 41 f0" +
"d8 de 89 57"), // (20 octets)
},
@ -48,8 +48,8 @@ add_task(function test_pbkdf2_hmac_sha1() {
S: "salt", // (4 octets)
c: 4096,
dkLen: 20,
DK: h("4b 00 79 01 b7 65 48 9a"+
"be ad 49 d9 26 f7 21 d0"+
DK: h("4b 00 79 01 b7 65 48 9a" +
"be ad 49 d9 26 f7 21 d0" +
"65 a4 29 c1"), // (20 octets)
},
@ -72,9 +72,9 @@ add_task(function test_pbkdf2_hmac_sha1() {
S: "saltSALTsaltSALTsaltSALTsaltSALTsalt", // (36 octets)
c: 4096,
dkLen: 25,
DK: h("3d 2e ec 4f e4 1c 84 9b"+
"80 c8 d8 36 62 c0 e4 4a"+
"8b 29 1a 96 4c f2 f0 70"+
DK: h("3d 2e ec 4f e4 1c 84 9b" +
"80 c8 d8 36 62 c0 e4 4a" +
"8b 29 1a 96 4c f2 f0 70" +
"38"), // (25 octets)
},
@ -83,7 +83,7 @@ add_task(function test_pbkdf2_hmac_sha1() {
S: "sa\0lt", // (5 octets)
c: 4096,
dkLen: 16,
DK: h("56 fa 6a a7 55 48 09 9d"+
DK: h("56 fa 6a a7 55 48 09 9d" +
"cc 37 d7 f0 34 25 e0 c3"), // (16 octets)
},
];
@ -104,9 +104,9 @@ add_task(function test_pbkdf2_hmac_sha256() {
S: "salt", // (4 octets)
c: 1,
dkLen: 32,
DK: h("12 0f b6 cf fc f8 b3 2c"+
"43 e7 22 52 56 c4 f8 37"+
"a8 65 48 c9 2c cc 35 48"+
DK: h("12 0f b6 cf fc f8 b3 2c" +
"43 e7 22 52 56 c4 f8 37" +
"a8 65 48 c9 2c cc 35 48" +
"08 05 98 7c b7 0b e1 7b"), // (32 octets)
},
@ -114,9 +114,9 @@ add_task(function test_pbkdf2_hmac_sha256() {
S: "salt", // (4 octets)
c: 2,
dkLen: 32,
DK: h("ae 4d 0c 95 af 6b 46 d3"+
"2d 0a df f9 28 f0 6d d0"+
"2a 30 3f 8e f3 c2 51 df"+
DK: h("ae 4d 0c 95 af 6b 46 d3" +
"2d 0a df f9 28 f0 6d d0" +
"2a 30 3f 8e f3 c2 51 df" +
"d6 e2 d8 5a 95 47 4c 43"), // (32 octets)
},
@ -124,9 +124,9 @@ add_task(function test_pbkdf2_hmac_sha256() {
S: "salt", // (4 octets)
c: 4096,
dkLen: 32,
DK: h("c5 e4 78 d5 92 88 c8 41"+
"aa 53 0d b6 84 5c 4c 8d"+
"96 28 93 a0 01 ce 4e 11"+
DK: h("c5 e4 78 d5 92 88 c8 41" +
"aa 53 0d b6 84 5c 4c 8d" +
"96 28 93 a0 01 ce 4e 11" +
"a4 96 38 73 aa 98 13 4a"), // (32 octets)
},
@ -134,10 +134,10 @@ add_task(function test_pbkdf2_hmac_sha256() {
S: "saltSALTsaltSALTsaltSALTsaltSALTsalt", // (36 octets)
c: 4096,
dkLen: 40,
DK: h("34 8c 89 db cb d3 2b 2f"+
"32 d8 14 b8 11 6e 84 cf"+
"2b 17 34 7e bc 18 00 18"+
"1c 4e 2a 1f b8 dd 53 e1"+
DK: h("34 8c 89 db cb d3 2b 2f" +
"32 d8 14 b8 11 6e 84 cf" +
"2b 17 34 7e bc 18 00 18" +
"1c 4e 2a 1f b8 dd 53 e1" +
"c6 35 51 8c 7d ac 47 e9"), // (40 octets)
},
@ -145,7 +145,7 @@ add_task(function test_pbkdf2_hmac_sha256() {
S: "sa\0lt", // (5 octets)
c: 4096,
dkLen: 16,
DK: h("89 b6 9d 05 16 f8 29 89"+
DK: h("89 b6 9d 05 16 f8 29 89" +
"3c 69 62 26 65 0a 86 87"), // (16 octets)
},
];

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

@ -50,13 +50,13 @@ this.Credentials = Object.freeze({
* Make constants accessible to tests
*/
constants: {
PROTOCOL_VERSION: PROTOCOL_VERSION,
PBKDF2_ROUNDS: PBKDF2_ROUNDS,
STRETCHED_PW_LENGTH_BYTES: STRETCHED_PW_LENGTH_BYTES,
HKDF_SALT: HKDF_SALT,
HKDF_LENGTH: HKDF_LENGTH,
HMAC_ALGORITHM: HMAC_ALGORITHM,
HMAC_LENGTH: HMAC_LENGTH,
PROTOCOL_VERSION,
PBKDF2_ROUNDS,
STRETCHED_PW_LENGTH_BYTES,
HKDF_SALT,
HKDF_LENGTH,
HMAC_ALGORITHM,
HMAC_LENGTH,
},
/**
@ -72,7 +72,7 @@ this.Credentials = Object.freeze({
* Note that PROTOCOL_VERSION does not refer in any way to the version of the
* Firefox Accounts API.
*/
keyWord: function(context) {
keyWord(context) {
return CommonUtils.stringToBytes(PROTOCOL_VERSION + context);
},
@ -89,11 +89,11 @@ this.Credentials = Object.freeze({
* Note that PROTOCOL_VERSION does not refer in any way to the version of the
* Firefox Accounts API.
*/
keyWordExtended: function(name, email) {
keyWordExtended(name, email) {
return CommonUtils.stringToBytes(PROTOCOL_VERSION + name + ':' + email);
},
setup: function(emailInput, passwordInput, options={}) {
setup(emailInput, passwordInput, options = {}) {
let deferred = Promise.defer();
log.debug("setup credentials for " + emailInput);

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

@ -166,7 +166,7 @@ AccountState.prototype = {
return this.storageManager.updateAccountData(updatedFields);
},
resolve: function(result) {
resolve(result) {
if (!this.isCurrent) {
log.info("An accountState promise was resolved, but was actually rejected" +
" due to a different user being signed in. Originally resolved" +
@ -176,7 +176,7 @@ AccountState.prototype = {
return Promise.resolve(result);
},
reject: function(error) {
reject(error) {
// It could be argued that we should just let it reject with the original
// error - but this runs the risk of the error being (eg) a 401, which
// might cause the consumer to attempt some remediation and cause other
@ -312,7 +312,7 @@ function urlsafeBase64Encode(key) {
/**
* The public API's constructor.
*/
this.FxAccounts = function (mockInternal) {
this.FxAccounts = function(mockInternal) {
let internal = new FxAccountsInternal();
let external = {};
@ -334,7 +334,7 @@ this.FxAccounts = function (mockInternal) {
if (!internal.fxaPushService) {
// internal.fxaPushService option is used in testing.
// Otherwise we load the service lazily.
XPCOMUtils.defineLazyGetter(internal, "fxaPushService", function () {
XPCOMUtils.defineLazyGetter(internal, "fxaPushService", function() {
return Components.classes["@mozilla.org/fxaccounts/push;1"]
.getService(Components.interfaces.nsISupports)
.wrappedJSObject;
@ -393,7 +393,7 @@ FxAccountsInternal.prototype = {
let profileServerUrl = Services.urlFormatter.formatURLPref("identity.fxaccounts.remote.profile.uri");
this._profile = new FxAccountsProfile({
fxa: this,
profileServerUrl: profileServerUrl,
profileServerUrl,
});
}
return this._profile;
@ -411,7 +411,7 @@ FxAccountsInternal.prototype = {
*
* @return Promise
*/
notifyDevices: function(deviceIds, payload, TTL) {
notifyDevices(deviceIds, payload, TTL) {
if (!Array.isArray(deviceIds)) {
deviceIds = [deviceIds];
}
@ -433,11 +433,11 @@ FxAccountsInternal.prototype = {
* Return the current time in milliseconds as an integer. Allows tests to
* manipulate the date to simulate certificate expiration.
*/
now: function() {
now() {
return this.fxAccountsClient.now();
},
getAccountsClient: function() {
getAccountsClient() {
return this.fxAccountsClient;
},
@ -714,7 +714,7 @@ FxAccountsInternal.prototype = {
});
},
checkVerificationStatus: function() {
checkVerificationStatus() {
log.trace('checkVerificationStatus');
let currentState = this.currentAccountState;
return currentState.getUserAccountData().then(data => {
@ -731,7 +731,7 @@ FxAccountsInternal.prototype = {
});
},
_destroyOAuthToken: function(tokenData) {
_destroyOAuthToken(tokenData) {
let client = new FxAccountsOAuthGrantClient({
serverURL: tokenData.server,
client_id: FX_OAUTH_CLIENT_ID
@ -739,7 +739,7 @@ FxAccountsInternal.prototype = {
return client.destroyToken(tokenData.token)
},
_destroyAllOAuthTokens: function(tokenInfos) {
_destroyAllOAuthTokens(tokenInfos) {
// let's just destroy them all in parallel...
let promises = [];
for (let [key, tokenInfo] of Object.entries(tokenInfos || {})) {
@ -864,7 +864,7 @@ FxAccountsInternal.prototype = {
* }
* or null if no user is signed in
*/
getKeys: function() {
getKeys() {
let currentState = this.currentAccountState;
return currentState.getUserAccountData().then((userData) => {
if (!userData) {
@ -900,7 +900,7 @@ FxAccountsInternal.prototype = {
).then(result => currentState.resolve(result));
},
fetchAndUnwrapKeys: function(keyFetchToken) {
fetchAndUnwrapKeys(keyFetchToken) {
if (logPII) {
log.debug("fetchAndUnwrapKeys: token: " + keyFetchToken);
}
@ -951,7 +951,7 @@ FxAccountsInternal.prototype = {
}.bind(this)).then(result => currentState.resolve(result));
},
getAssertionFromCert: function(data, keyPair, cert, audience) {
getAssertionFromCert(data, keyPair, cert, audience) {
log.debug("getAssertionFromCert");
let payload = {};
let d = Promise.defer();
@ -978,7 +978,7 @@ FxAccountsInternal.prototype = {
return d.promise.then(result => currentState.resolve(result));
},
getCertificateSigned: function(sessionToken, serializedPublicKey, lifetime) {
getCertificateSigned(sessionToken, serializedPublicKey, lifetime) {
log.debug("getCertificateSigned: " + !!sessionToken + " " + !!serializedPublicKey);
if (logPII) {
log.debug("getCertificateSigned: " + sessionToken + " " + serializedPublicKey);
@ -1003,7 +1003,7 @@ FxAccountsInternal.prototype = {
let ignoreCachedAuthCredentials = false;
try {
ignoreCachedAuthCredentials = Services.prefs.getBoolPref("services.sync.debug.ignoreCachedAuthCredentials");
} catch(e) {
} catch (e) {
// Pref doesn't exist
}
let mustBeValidUntil = this.now() + ASSERTION_USE_PERIOD;
@ -1074,11 +1074,11 @@ FxAccountsInternal.prototype = {
}
return {
keyPair: keyPair.rawKeyPair,
certificate: certificate,
certificate,
}
}),
getUserAccountData: function() {
getUserAccountData() {
return this.currentAccountState.getUserAccountData();
},
@ -1089,7 +1089,7 @@ FxAccountsInternal.prototype = {
/**
* Setup for and if necessary do email verification polling.
*/
loadAndPoll: function() {
loadAndPoll() {
let currentState = this.currentAccountState;
return currentState.getUserAccountData()
.then(data => {
@ -1103,7 +1103,7 @@ FxAccountsInternal.prototype = {
});
},
startVerifiedCheck: function(data) {
startVerifiedCheck(data) {
log.debug("startVerifiedCheck", data && data.verified);
if (logPII) {
log.debug("startVerifiedCheck with user data", data);
@ -1125,7 +1125,7 @@ FxAccountsInternal.prototype = {
);
},
whenVerified: function(data) {
whenVerified(data) {
let currentState = this.currentAccountState;
if (data.verified) {
log.debug("already verified");
@ -1140,7 +1140,7 @@ FxAccountsInternal.prototype = {
);
},
notifyObservers: function(topic, data) {
notifyObservers(topic, data) {
log.debug("Notifying observers of " + topic);
Services.obs.notifyObservers(null, topic, data);
},
@ -1217,7 +1217,7 @@ FxAccountsInternal.prototype = {
},
// Poll email status using truncated exponential back-off.
pollEmailStatusAgain: function (currentState, sessionToken, timeoutMs) {
pollEmailStatusAgain(currentState, sessionToken, timeoutMs) {
let ageMs = Date.now() - this.pollStartDate;
if (ageMs >= this.POLL_SESSION) {
if (currentState.whenVerifiedDeferred) {
@ -1238,11 +1238,11 @@ FxAccountsInternal.prototype = {
}, timeoutMs);
},
requiresHttps: function() {
requiresHttps() {
let allowHttp = false;
try {
allowHttp = Services.prefs.getBoolPref("identity.fxaccounts.allowHttp");
} catch(e) {
} catch (e) {
// Pref doesn't exist
}
return allowHttp !== true;
@ -1280,7 +1280,7 @@ FxAccountsInternal.prototype = {
// the current account's profile image.
// if settingToEdit is set, the profile page should hightlight that setting
// for the user to edit.
promiseAccountsChangeProfileURI: function(entrypoint, settingToEdit = null) {
promiseAccountsChangeProfileURI(entrypoint, settingToEdit = null) {
let url = Services.urlFormatter.formatURLPref("identity.fxaccounts.settings.uri");
if (settingToEdit) {
@ -1309,7 +1309,7 @@ FxAccountsInternal.prototype = {
// Returns a promise that resolves with the URL to use to manage the current
// user's FxA acct.
promiseAccountsManageURI: function(entrypoint) {
promiseAccountsManageURI(entrypoint) {
let url = Services.urlFormatter.formatURLPref("identity.fxaccounts.settings.uri");
if (this.requiresHttps() && !/^https:/.test(url)) { // Comment to un-break emacs js-mode highlighting
throw new Error("Firefox Accounts server must use HTTPS");
@ -1397,7 +1397,7 @@ FxAccountsInternal.prototype = {
let token = result.access_token;
// If we got one, cache it.
if (token) {
let entry = {token: token, server: oAuthURL};
let entry = {token, server: oAuthURL};
// But before we do, check the cache again - if we find one now, it
// means someone else concurrently requested the same scope and beat
// us to the cache write. To be nice to the server, we revoke the one
@ -1465,7 +1465,7 @@ FxAccountsInternal.prototype = {
* NO_ACCOUNT
* UNVERIFIED_ACCOUNT
*/
_errorToErrorClass: function (aError) {
_errorToErrorClass(aError) {
if (aError.errno) {
let error = SERVER_ERRNO_TO_ERROR[aError.errno];
return this._error(ERROR_TO_GENERAL_ERROR_CLASS[error] || ERROR_UNKNOWN, aError);
@ -1479,7 +1479,7 @@ FxAccountsInternal.prototype = {
return this._error(ERROR_UNKNOWN, aError);
},
_error: function(aError, aDetails) {
_error(aError, aDetails) {
log.error("FxA rejecting with error ${aError}, details: ${aDetails}", {aError, aDetails});
let reason = new Error(aError);
if (aDetails) {
@ -1510,7 +1510,7 @@ FxAccountsInternal.prototype = {
* AUTH_ERROR
* UNKNOWN_ERROR
*/
getSignedInUserProfile: function () {
getSignedInUserProfile() {
let currentState = this.currentAccountState;
return this.profile.getProfile().then(
profileData => {
@ -1589,7 +1589,7 @@ FxAccountsInternal.prototype = {
if (Services.prefs.getBoolPref("identity.fxaccounts.skipDeviceRegistration")) {
return Promise.resolve();
}
} catch(ignore) {}
} catch (ignore) {}
if (!signedInUser.sessionToken) {
return Promise.reject(new Error(

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

@ -55,7 +55,7 @@ this.FxAccountsClient.prototype = {
* Not used by this module, but made available to the FxAccounts.jsm
* that uses this client.
*/
now: function() {
now() {
return this.hawk.now();
},
@ -87,12 +87,12 @@ this.FxAccountsClient.prototype = {
* email
* }
*/
_createSession: function(path, email, password, getKeys=false,
retryOK=true) {
_createSession(path, email, password, getKeys = false,
retryOK = true) {
return Credentials.setup(email, password).then((creds) => {
let data = {
authPW: CommonUtils.bytesAsHex(creds.authPW),
email: email,
email,
};
let keys = getKeys ? "?keys=true" : "";
@ -151,7 +151,7 @@ this.FxAccountsClient.prototype = {
* password (not revealed to the FxA server)
* }
*/
signUp: function(email, password, getKeys=false) {
signUp(email, password, getKeys = false) {
return this._createSession(SIGNUP, email, password, getKeys,
false /* no retry */);
},
@ -178,7 +178,7 @@ this.FxAccountsClient.prototype = {
* verified: flag indicating verification status of the email
* }
*/
signIn: function signIn(email, password, getKeys=false) {
signIn: function signIn(email, password, getKeys = false) {
return this._createSession(SIGNIN, email, password, getKeys,
true /* retry */);
},
@ -191,7 +191,7 @@ this.FxAccountsClient.prototype = {
* @return Promise
* Resolves with a boolean indicating if the session is still valid
*/
sessionStatus: function (sessionTokenHex) {
sessionStatus(sessionTokenHex) {
return this._request("/session/status", "GET",
deriveHawkCredentials(sessionTokenHex, "sessionToken")).then(
() => Promise.resolve(true),
@ -211,7 +211,7 @@ this.FxAccountsClient.prototype = {
* The session token encoded in hex
* @return Promise
*/
signOut: function (sessionTokenHex, options = {}) {
signOut(sessionTokenHex, options = {}) {
let path = "/session/destroy";
if (options.service) {
path += "?service=" + encodeURIComponent(options.service);
@ -227,7 +227,7 @@ this.FxAccountsClient.prototype = {
* The current session token encoded in hex
* @return Promise
*/
recoveryEmailStatus: function (sessionTokenHex, options = {}) {
recoveryEmailStatus(sessionTokenHex, options = {}) {
let path = "/recovery_email/status";
if (options.reason) {
path += "?reason=" + encodeURIComponent(options.reason);
@ -244,7 +244,7 @@ this.FxAccountsClient.prototype = {
* The current token encoded in hex
* @return Promise
*/
resendVerificationEmail: function(sessionTokenHex) {
resendVerificationEmail(sessionTokenHex) {
return this._request("/recovery_email/resend_code", "POST",
deriveHawkCredentials(sessionTokenHex, "sessionToken"));
},
@ -262,7 +262,7 @@ this.FxAccountsClient.prototype = {
* user's password (bytes)
* }
*/
accountKeys: function (keyFetchTokenHex) {
accountKeys(keyFetchTokenHex) {
let creds = deriveHawkCredentials(keyFetchTokenHex, "keyFetchToken");
let keyRequestKey = creds.extra.slice(0, 32);
let morecreds = CryptoUtils.hkdf(keyRequestKey, undefined,
@ -311,7 +311,7 @@ this.FxAccountsClient.prototype = {
* wrapping any of these HTTP code/errno pairs:
* https://github.com/mozilla/fxa-auth-server/blob/master/docs/api.md#response-12
*/
signCertificate: function (sessionTokenHex, serializedPublicKey, lifetime) {
signCertificate(sessionTokenHex, serializedPublicKey, lifetime) {
let creds = deriveHawkCredentials(sessionTokenHex, "sessionToken");
let body = { publicKey: serializedPublicKey,
@ -334,7 +334,7 @@ this.FxAccountsClient.prototype = {
* The promise resolves to true if the account exists, or false
* if it doesn't. The promise is rejected on other errors.
*/
accountExists: function (email) {
accountExists(email) {
return this.signIn(email, "").then(
(cantHappen) => {
throw new Error("How did I sign in with an empty password?");
@ -362,8 +362,8 @@ this.FxAccountsClient.prototype = {
*
* Used for differentiating between password change and account deletion.
*/
accountStatus: function(uid) {
return this._request("/account/status?uid="+uid, "GET").then(
accountStatus(uid) {
return this._request("/account/status?uid=" + uid, "GET").then(
(result) => {
return result.exists;
},
@ -540,7 +540,7 @@ this.FxAccountsClient.prototype = {
return this._request(path, "GET", creds, {});
},
_clearBackoff: function() {
_clearBackoff() {
this.backoffError = null;
},

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

@ -27,12 +27,12 @@ XPCOMUtils.defineLazyServiceGetter(this, "permissionManager",
this.FxAccountsManager = {
init: function() {
init() {
Services.obs.addObserver(this, ONLOGOUT_NOTIFICATION, false);
Services.obs.addObserver(this, ON_FXA_UPDATE_NOTIFICATION, false);
},
observe: function(aSubject, aTopic, aData) {
observe(aSubject, aTopic, aData) {
// Both topics indicate our cache is invalid
this._activeSession = null;
@ -67,7 +67,7 @@ this.FxAccountsManager = {
}
},
_error: function(aError, aDetails) {
_error(aError, aDetails) {
log.error(aError);
let reason = {
error: aError
@ -78,7 +78,7 @@ this.FxAccountsManager = {
return Promise.reject(reason);
},
_getError: function(aServerResponse) {
_getError(aServerResponse) {
if (!aServerResponse || !aServerResponse.error || !aServerResponse.error.errno) {
return;
}
@ -86,7 +86,7 @@ this.FxAccountsManager = {
return error;
},
_serverError: function(aServerResponse) {
_serverError(aServerResponse) {
let error = this._getError({ error: aServerResponse });
return this._error(error ? error : ERROR_SERVER_ERROR, aServerResponse);
},
@ -96,11 +96,11 @@ this.FxAccountsManager = {
// client used by the fxAccounts object because deep down they should have
// access to the same hawk request object which will enable them to share
// local clock skeq data.
_getFxAccountsClient: function() {
_getFxAccountsClient() {
return this._fxAccounts.getAccountsClient();
},
_signInSignUp: function(aMethod, aEmail, aPassword, aFetchKeys) {
_signInSignUp(aMethod, aEmail, aPassword, aFetchKeys) {
if (Services.io.offline) {
return this._error(ERROR_OFFLINE);
}
@ -135,7 +135,7 @@ this.FxAccountsManager = {
let error = this._getError(user);
if (!user || !user.uid || !user.sessionToken || error) {
return this._error(error ? error : ERROR_INTERNAL_INVALID_USER, {
user: user
user
});
}
@ -199,7 +199,7 @@ this.FxAccountsManager = {
* FxAccountsClient.signCertificate()
* See the latter method for possible (error code, errno) pairs.
*/
_handleGetAssertionError: function(reason, aAudience, aPrincipal) {
_handleGetAssertionError(reason, aAudience, aPrincipal) {
log.debug("FxAccountsManager._handleGetAssertionError()");
let errno = (reason ? reason.errno : NaN) || NaN;
// If the previously valid email/password pair is no longer valid ...
@ -236,7 +236,7 @@ this.FxAccountsManager = {
return Promise.reject(reason.message ? { error: reason.message } : reason);
},
_getAssertion: function(aAudience, aPrincipal) {
_getAssertion(aAudience, aPrincipal) {
return this._fxAccounts.getAssertion(aAudience).then(
(result) => {
if (aPrincipal) {
@ -260,8 +260,8 @@ this.FxAccountsManager = {
* 2) The person typing can't prove knowledge of the password used
* to log in. Failure should do nothing.
*/
_refreshAuthentication: function(aAudience, aEmail, aPrincipal,
logoutOnFailure=false) {
_refreshAuthentication(aAudience, aEmail, aPrincipal,
logoutOnFailure = false) {
this._refreshing = true;
return this._uiRequest(UI_REQUEST_REFRESH_AUTH,
aAudience, aPrincipal, aEmail).then(
@ -283,11 +283,11 @@ this.FxAccountsManager = {
);
},
_localSignOut: function() {
_localSignOut() {
return this._fxAccounts.signOut(true);
},
_signOut: function() {
_signOut() {
if (!this._activeSession) {
return Promise.resolve();
}
@ -326,7 +326,7 @@ this.FxAccountsManager = {
);
},
_uiRequest: function(aRequest, aAudience, aPrincipal, aParams) {
_uiRequest(aRequest, aAudience, aPrincipal, aParams) {
if (Services.io.offline) {
return this._error(ERROR_OFFLINE);
}
@ -358,7 +358,7 @@ this.FxAccountsManager = {
);
},
_addPermission: function(aPrincipal) {
_addPermission(aPrincipal) {
// This will fail from tests cause we are running them in the child
// process until we have chrome tests in b2g. Bug 797164.
try {
@ -371,15 +371,15 @@ this.FxAccountsManager = {
// -- API --
signIn: function(aEmail, aPassword, aFetchKeys) {
signIn(aEmail, aPassword, aFetchKeys) {
return this._signInSignUp("signIn", aEmail, aPassword, aFetchKeys);
},
signUp: function(aEmail, aPassword, aFetchKeys) {
signUp(aEmail, aPassword, aFetchKeys) {
return this._signInSignUp("signUp", aEmail, aPassword, aFetchKeys);
},
signOut: function() {
signOut() {
if (!this._activeSession) {
// If there is no cached active session, we try to get it from the
// account storage.
@ -395,7 +395,7 @@ this.FxAccountsManager = {
return this._signOut();
},
resendVerificationEmail: function() {
resendVerificationEmail() {
return this._fxAccounts.resendVerificationEmail().then(
(result) => {
return result;
@ -406,7 +406,7 @@ this.FxAccountsManager = {
);
},
getAccount: function() {
getAccount() {
// We check first if we have session details cached.
if (this._activeSession) {
// If our cache says that the account is not yet verified,
@ -452,7 +452,7 @@ this.FxAccountsManager = {
);
},
queryAccount: function(aEmail) {
queryAccount(aEmail) {
log.debug("queryAccount " + aEmail);
if (Services.io.offline) {
return this._error(ERROR_OFFLINE);
@ -481,7 +481,7 @@ this.FxAccountsManager = {
);
},
verificationStatus: function() {
verificationStatus() {
log.debug("verificationStatus");
if (!this._activeSession || !this._activeSession.sessionToken) {
this._error(ERROR_NO_TOKEN_SESSION);
@ -545,7 +545,7 @@ this.FxAccountsManager = {
* silent - (bool) Prevent any UI interaction.
* I.e., try to get an automatic assertion.
*/
getAssertion: function(aAudience, aPrincipal, aOptions) {
getAssertion(aAudience, aPrincipal, aOptions) {
if (!aAudience) {
return this._error(ERROR_INVALID_AUDIENCE);
}
@ -561,7 +561,7 @@ this.FxAccountsManager = {
// Three have-user cases to consider. First: are we unverified?
if (!user.verified) {
return this._error(ERROR_UNVERIFIED_ACCOUNT, {
user: user
user
});
}
// Second case: do we need to refresh?
@ -620,11 +620,11 @@ this.FxAccountsManager = {
);
},
getKeys: function() {
getKeys() {
let syncEnabled = false;
try {
syncEnabled = Services.prefs.getBoolPref("services.sync.enabled");
} catch(e) {
} catch (e) {
dump("Sync is disabled, so you won't get the keys. " + e + "\n");
}
@ -641,7 +641,7 @@ this.FxAccountsManager = {
if (!user.verified) {
return this._error(ERROR_UNVERIFIED_ACCOUNT, {
user: user
user
});
}

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

@ -116,7 +116,7 @@ this.FxAccountsOAuthClient.prototype = {
* Opens a tab at "this._fxaOAuthStartUrl".
* Registers a WebChannel listener and sets up a callback if needed.
*/
launchWebFlow: function () {
launchWebFlow() {
if (!this._channelCallback) {
this._registerChannel();
}
@ -132,7 +132,7 @@ this.FxAccountsOAuthClient.prototype = {
/**
* Release all resources that are in use.
*/
tearDown: function() {
tearDown() {
this.onComplete = null;
this.onError = null;
this._complete = true;
@ -145,7 +145,7 @@ this.FxAccountsOAuthClient.prototype = {
*
* @private
*/
_configureChannel: function() {
_configureChannel() {
this._webChannelId = "oauth_" + this.parameters.client_id;
// if this.parameters.content_uri is present but not a valid URI, then this will throw an error.
@ -160,7 +160,7 @@ this.FxAccountsOAuthClient.prototype = {
* Create a new channel with the WebChannelBroker, setup a callback listener
* @private
*/
_registerChannel: function() {
_registerChannel() {
/**
* Processes messages that are called back from the FxAccountsChannel
*
@ -172,7 +172,7 @@ this.FxAccountsOAuthClient.prototype = {
* Channel message event sendingContext
* @private
*/
let listener = function (webChannelId, message, sendingContext) {
let listener = function(webChannelId, message, sendingContext) {
if (message) {
let command = message.command;
let data = message.data;
@ -251,7 +251,7 @@ this.FxAccountsOAuthClient.prototype = {
* OAuth client options
* @private
*/
_validateOptions: function (options) {
_validateOptions(options) {
if (!options || !options.parameters) {
throw new Error("Missing 'parameters' configuration option");
}

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

@ -59,7 +59,7 @@ this.FxAccountsOAuthGrantClient.prototype = {
* @return Promise
* Resolves: {Object} Object with access_token property
*/
getTokenFromAssertion: function (assertion, scope) {
getTokenFromAssertion(assertion, scope) {
if (!assertion) {
throw new Error("Missing 'assertion' parameter");
}
@ -67,9 +67,9 @@ this.FxAccountsOAuthGrantClient.prototype = {
throw new Error("Missing 'scope' parameter");
}
let params = {
scope: scope,
scope,
client_id: this.parameters.client_id,
assertion: assertion,
assertion,
response_type: "token"
};
@ -84,12 +84,12 @@ this.FxAccountsOAuthGrantClient.prototype = {
* Resolves: {Object} with the server response, which is typically
* ignored.
*/
destroyToken: function (token) {
destroyToken(token) {
if (!token) {
throw new Error("Missing 'token' parameter");
}
let params = {
token: token,
token,
};
return this._createRequest(DESTROY_ENDPOINT, "POST", params);
@ -102,7 +102,7 @@ this.FxAccountsOAuthGrantClient.prototype = {
* OAuth client options
* @private
*/
_validateOptions: function (options) {
_validateOptions(options) {
if (!options) {
throw new Error("Missing configuration options");
}
@ -131,7 +131,7 @@ this.FxAccountsOAuthGrantClient.prototype = {
* Rejects: {FxAccountsOAuthGrantClientError} Profile client error.
* @private
*/
_createRequest: function(path, method = "POST", params) {
_createRequest(path, method = "POST", params) {
return new Promise((resolve, reject) => {
let profileDataUrl = this.serverURL + path;
let request = new this._Request(profileDataUrl);
@ -140,7 +140,7 @@ this.FxAccountsOAuthGrantClient.prototype = {
request.setHeader("Accept", "application/json");
request.setHeader("Content-Type", "application/json");
request.onComplete = function (error) {
request.onComplete = function(error) {
if (error) {
return reject(new FxAccountsOAuthGrantClientError({
error: ERROR_NETWORK,

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

@ -71,7 +71,7 @@ function hasChanged(oldData, newData) {
return !deepEqual(oldData, newData);
}
this.FxAccountsProfile = function (options = {}) {
this.FxAccountsProfile = function(options = {}) {
this._cachedProfile = null;
this._cachedAt = 0; // when we saved the cached version.
this._currentFetchPromise = null;
@ -106,20 +106,20 @@ this.FxAccountsProfile.prototype = {
}
},
tearDown: function () {
tearDown() {
this.fxa = null;
this.client = null;
this._cachedProfile = null;
Services.obs.removeObserver(this, ON_PROFILE_CHANGE_NOTIFICATION);
},
_getCachedProfile: function () {
_getCachedProfile() {
// The cached profile will end up back in the generic accountData
// once bug 1157529 is fixed.
return Promise.resolve(this._cachedProfile);
},
_notifyProfileChange: function (uid) {
_notifyProfileChange(uid) {
this._isNotifying = true;
Services.obs.notifyObservers(null, ON_PROFILE_CHANGE_NOTIFICATION, uid);
this._isNotifying = false;
@ -127,7 +127,7 @@ this.FxAccountsProfile.prototype = {
// Cache fetched data if it is different from what's in the cache.
// Send out a notification if it has changed so that UI can update.
_cacheProfile: function (profileData) {
_cacheProfile(profileData) {
if (!hasChanged(this._cachedProfile, profileData)) {
log.debug("fetched profile matches cached copy");
return Promise.resolve(null); // indicates no change (but only tests care)
@ -142,7 +142,7 @@ this.FxAccountsProfile.prototype = {
});
},
_fetchAndCacheProfile: function () {
_fetchAndCacheProfile() {
if (!this._currentFetchPromise) {
this._currentFetchPromise = this.client.fetchProfile().then(profile => {
return this._cacheProfile(profile).then(() => {
@ -162,7 +162,7 @@ this.FxAccountsProfile.prototype = {
// Returns cached data right away if available, then fetches the latest profile
// data in the background. After data is fetched a notification will be sent
// out if the profile has changed.
getProfile: function () {
getProfile() {
return this._getCachedProfile()
.then(cachedProfile => {
if (cachedProfile) {

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

@ -128,7 +128,7 @@ this.FxAccountsProfileClient.prototype = {
* Rejects: {FxAccountsProfileClientError} Profile client error.
* @private
*/
_rawRequest: function(path, method, token) {
_rawRequest(path, method, token) {
return new Promise((resolve, reject) => {
let profileDataUrl = this.serverURL + path;
let request = new this._Request(profileDataUrl);
@ -137,7 +137,7 @@ this.FxAccountsProfileClient.prototype = {
request.setHeader("Authorization", "Bearer " + token);
request.setHeader("Accept", "application/json");
request.onComplete = function (error) {
request.onComplete = function(error) {
if (error) {
return reject(new FxAccountsProfileClientError({
error: ERROR_NETWORK,
@ -192,7 +192,7 @@ this.FxAccountsProfileClient.prototype = {
* Resolves: {Object} Successful response from the '/profile' endpoint.
* Rejects: {FxAccountsProfileClientError} profile client error.
*/
fetchProfile: function () {
fetchProfile() {
log.debug("FxAccountsProfileClient: Requested profile");
return this._createRequest("/profile", "GET");
},
@ -204,7 +204,7 @@ this.FxAccountsProfileClient.prototype = {
* Resolves: {Object} Successful response from the '/avatar' endpoint.
* Rejects: {FxAccountsProfileClientError} profile client error.
*/
fetchProfileImage: function () {
fetchProfileImage() {
log.debug("FxAccountsProfileClient: Requested avatar");
return this._createRequest("/avatar", "GET");
}

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

@ -240,4 +240,4 @@ const components = [FxAccountsPushService];
this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
// The following registration below helps with testing this service.
this.EXPORTED_SYMBOLS=["FxAccountsPushService"];
this.EXPORTED_SYMBOLS = ["FxAccountsPushService"];

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

@ -274,7 +274,7 @@ this.FxAccountsStorageManager.prototype = {
let got;
try {
got = yield this.plainStorage.get();
} catch(err) {
} catch (err) {
// File hasn't been created yet. That will be done
// when write is called.
if (!(err instanceof OS.File.Error) || !err.becauseNoSuchFile) {
@ -444,25 +444,25 @@ this.FxAccountsStorageManager.prototype = {
function JSONStorage(options) {
this.baseDir = options.baseDir;
this.path = OS.Path.join(options.baseDir, options.filename);
};
}
JSONStorage.prototype = {
set: function(contents) {
set(contents) {
log.trace("starting write of json user data", contents ? Object.keys(contents.accountData) : "null");
let start = Date.now();
return OS.File.makeDir(this.baseDir, {ignoreExisting: true})
.then(CommonUtils.writeJSON.bind(null, contents, this.path))
.then(result => {
log.trace("finished write of json user data - took", Date.now()-start);
log.trace("finished write of json user data - took", Date.now() - start);
return result;
});
},
get: function() {
get() {
log.trace("starting fetch of json user data");
let start = Date.now();
return CommonUtils.readJSON(this.path).then(result => {
log.trace("finished fetch of json user data - took", Date.now()-start);
log.trace("finished fetch of json user data - took", Date.now() - start);
return result;
});
},

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

@ -157,7 +157,7 @@ this.FxAccountsWebChannel.prototype = {
let canLinkAccount = this._helpers.shouldAllowRelink(data.email);
let response = {
command: command,
command,
messageId: message.messageId,
data: { ok: canLinkAccount }
};

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

@ -93,7 +93,7 @@ function MockFxAccountsClient() {
// mock calls up to the auth server to determine whether the
// user account has been verified
this.recoveryEmailStatus = function (sessionToken) {
this.recoveryEmailStatus = function(sessionToken) {
// simulate a call to /recovery_email/status
return Promise.resolve({
email: this._email,
@ -107,7 +107,7 @@ function MockFxAccountsClient() {
return deferred.promise;
};
this.accountKeys = function (keyFetchToken) {
this.accountKeys = function(keyFetchToken) {
let deferred = Promise.defer();
do_timeout(50, () => {
@ -149,7 +149,7 @@ function MockFxAccounts() {
_getCertificateSigned_calls: [],
_d_signCertificate: Promise.defer(),
_now_is: new Date(),
now: function () {
now() {
return this._now_is;
},
newAccountState(credentials) {
@ -158,7 +158,7 @@ function MockFxAccounts() {
storage.initialize(credentials);
return new AccountState(storage);
},
getCertificateSigned: function (sessionToken, serializedPublicKey) {
getCertificateSigned(sessionToken, serializedPublicKey) {
_("mock getCertificateSigned\n");
this._getCertificateSigned_calls.push([sessionToken, serializedPublicKey]);
return this._d_signCertificate.promise;
@ -334,7 +334,7 @@ add_task(function* test_getCertificateOffline() {
do_check_eq(err, "Error: OFFLINE");
}
);
yield fxa.signOut(/*localOnly = */true);
yield fxa.signOut(/* localOnly = */true);
});
add_task(function* test_getCertificateCached() {
@ -361,7 +361,7 @@ add_task(function* test_getCertificateCached() {
// should have the same keypair and cert.
do_check_eq(keyPair, credentials.keyPair.rawKeyPair);
do_check_eq(certificate, credentials.cert.rawCert);
yield fxa.signOut(/*localOnly = */true);
yield fxa.signOut(/* localOnly = */true);
});
add_task(function* test_getCertificateExpiredCert() {
@ -392,7 +392,7 @@ add_task(function* test_getCertificateExpiredCert() {
// should have the same keypair but a new cert.
do_check_eq(keyPair, credentials.keyPair.rawKeyPair);
do_check_neq(certificate, credentials.cert.rawCert);
yield fxa.signOut(/*localOnly = */true);
yield fxa.signOut(/* localOnly = */true);
});
add_task(function* test_getCertificateExpiredKeypair() {
@ -425,7 +425,7 @@ add_task(function* test_getCertificateExpiredKeypair() {
// should have fetched both.
do_check_neq(keyPair, credentials.keyPair.rawKeyPair);
do_check_neq(certificate, credentials.cert.rawCert);
yield fxa.signOut(/*localOnly = */true);
yield fxa.signOut(/* localOnly = */true);
});
// Sanity-check that our mocked client is working correctly
@ -834,7 +834,7 @@ add_task(function* test_resend_email_not_signed_in() {
try {
yield fxa.resendVerificationEmail();
} catch(err) {
} catch (err) {
do_check_eq(err.message,
"Cannot resend verification email; no signed-in user");
return;
@ -964,11 +964,11 @@ add_task(function* test_sign_out_with_device() {
signOutAndDeviceDestroy: { count: 0, args: [] }
};
const client = fxa.internal.fxAccountsClient;
client.signOut = function () {
client.signOut = function() {
spy.signOut.count += 1;
return Promise.resolve();
};
client.signOutAndDestroyDevice = function () {
client.signOutAndDestroyDevice = function() {
spy.signOutAndDeviceDestroy.count += 1;
spy.signOutAndDeviceDestroy.args.push(arguments);
return Promise.resolve();
@ -1011,12 +1011,12 @@ add_task(function* test_sign_out_without_device() {
signOutAndDeviceDestroy: { count: 0 }
};
const client = fxa.internal.fxAccountsClient;
client.signOut = function () {
client.signOut = function() {
spy.signOut.count += 1;
spy.signOut.args.push(arguments);
return Promise.resolve();
};
client.signOutAndDestroyDevice = function () {
client.signOutAndDestroyDevice = function() {
spy.signOutAndDeviceDestroy.count += 1;
return Promise.resolve();
};
@ -1079,14 +1079,14 @@ add_test(function test_getOAuthToken() {
serverURL: "http://example.com/v1",
client_id: "abc123"
});
client.getTokenFromAssertion = function () {
client.getTokenFromAssertion = function() {
getTokenFromAssertionCalled = true;
return Promise.resolve({ access_token: "token" });
};
fxa.setSignedInUser(alice).then(
() => {
fxa.getOAuthToken({ scope: "profile", client: client }).then(
fxa.getOAuthToken({ scope: "profile", client }).then(
(result) => {
do_check_true(getTokenFromAssertionCalled);
do_check_eq(result, "token");
@ -1111,7 +1111,7 @@ add_test(function test_getOAuthTokenScoped() {
serverURL: "http://example.com/v1",
client_id: "abc123"
});
client.getTokenFromAssertion = function (assertion, scopeString) {
client.getTokenFromAssertion = function(assertion, scopeString) {
equal(scopeString, "foo bar");
getTokenFromAssertionCalled = true;
return Promise.resolve({ access_token: "token" });
@ -1119,7 +1119,7 @@ add_test(function test_getOAuthTokenScoped() {
fxa.setSignedInUser(alice).then(
() => {
fxa.getOAuthToken({ scope: ["foo", "bar"], client: client }).then(
fxa.getOAuthToken({ scope: ["foo", "bar"], client }).then(
(result) => {
do_check_true(getTokenFromAssertionCalled);
do_check_eq(result, "token");
@ -1144,22 +1144,22 @@ add_task(function* test_getOAuthTokenCached() {
serverURL: "http://example.com/v1",
client_id: "abc123"
});
client.getTokenFromAssertion = function () {
client.getTokenFromAssertion = function() {
numTokenFromAssertionCalls += 1;
return Promise.resolve({ access_token: "token" });
};
yield fxa.setSignedInUser(alice);
let result = yield fxa.getOAuthToken({ scope: "profile", client: client, service: "test-service" });
let result = yield fxa.getOAuthToken({ scope: "profile", client, service: "test-service" });
do_check_eq(numTokenFromAssertionCalls, 1);
do_check_eq(result, "token");
// requesting it again should not re-fetch the token.
result = yield fxa.getOAuthToken({ scope: "profile", client: client, service: "test-service" });
result = yield fxa.getOAuthToken({ scope: "profile", client, service: "test-service" });
do_check_eq(numTokenFromAssertionCalls, 1);
do_check_eq(result, "token");
// But requesting the same service and a different scope *will* get a new one.
result = yield fxa.getOAuthToken({ scope: "something-else", client: client, service: "test-service" });
result = yield fxa.getOAuthToken({ scope: "something-else", client, service: "test-service" });
do_check_eq(numTokenFromAssertionCalls, 2);
do_check_eq(result, "token");
});
@ -1177,26 +1177,26 @@ add_task(function* test_getOAuthTokenCachedScopeNormalization() {
serverURL: "http://example.com/v1",
client_id: "abc123"
});
client.getTokenFromAssertion = function () {
client.getTokenFromAssertion = function() {
numTokenFromAssertionCalls += 1;
return Promise.resolve({ access_token: "token" });
};
yield fxa.setSignedInUser(alice);
let result = yield fxa.getOAuthToken({ scope: ["foo", "bar"], client: client, service: "test-service" });
let result = yield fxa.getOAuthToken({ scope: ["foo", "bar"], client, service: "test-service" });
do_check_eq(numTokenFromAssertionCalls, 1);
do_check_eq(result, "token");
// requesting it again with the scope array in a different order not re-fetch the token.
result = yield fxa.getOAuthToken({ scope: ["bar", "foo"], client: client, service: "test-service" });
result = yield fxa.getOAuthToken({ scope: ["bar", "foo"], client, service: "test-service" });
do_check_eq(numTokenFromAssertionCalls, 1);
do_check_eq(result, "token");
// requesting it again with the scope array in different case not re-fetch the token.
result = yield fxa.getOAuthToken({ scope: ["Bar", "Foo"], client: client, service: "test-service" });
result = yield fxa.getOAuthToken({ scope: ["Bar", "Foo"], client, service: "test-service" });
do_check_eq(numTokenFromAssertionCalls, 1);
do_check_eq(result, "token");
// But requesting with a new entry in the array does fetch one.
result = yield fxa.getOAuthToken({ scope: ["foo", "bar", "etc"], client: client, service: "test-service" });
result = yield fxa.getOAuthToken({ scope: ["foo", "bar", "etc"], client, service: "test-service" });
do_check_eq(numTokenFromAssertionCalls, 2);
do_check_eq(result, "token");
});
@ -1239,7 +1239,7 @@ add_test(function test_getOAuthToken_misconfigure_oauth_uri() {
add_test(function test_getOAuthToken_no_account() {
let fxa = new MockFxAccounts();
fxa.internal.currentAccountState.getUserAccountData = function () {
fxa.internal.currentAccountState.getUserAccountData = function() {
return Promise.resolve(null);
};
@ -1275,7 +1275,7 @@ add_test(function test_getOAuthToken_network_error() {
serverURL: "http://example.com/v1",
client_id: "abc123"
});
client.getTokenFromAssertion = function () {
client.getTokenFromAssertion = function() {
return Promise.reject(new FxAccountsOAuthGrantClientError({
error: ERROR_NETWORK,
errno: ERRNO_NETWORK
@ -1283,7 +1283,7 @@ add_test(function test_getOAuthToken_network_error() {
};
fxa.setSignedInUser(alice).then(() => {
fxa.getOAuthToken({ scope: "profile", client: client })
fxa.getOAuthToken({ scope: "profile", client })
.then(null, err => {
do_check_eq(err.message, "NETWORK_ERROR");
do_check_eq(err.details.errno, ERRNO_NETWORK);
@ -1304,7 +1304,7 @@ add_test(function test_getOAuthToken_auth_error() {
serverURL: "http://example.com/v1",
client_id: "abc123"
});
client.getTokenFromAssertion = function () {
client.getTokenFromAssertion = function() {
return Promise.reject(new FxAccountsOAuthGrantClientError({
error: ERROR_INVALID_FXA_ASSERTION,
errno: ERRNO_INVALID_FXA_ASSERTION
@ -1312,7 +1312,7 @@ add_test(function test_getOAuthToken_auth_error() {
};
fxa.setSignedInUser(alice).then(() => {
fxa.getOAuthToken({ scope: "profile", client: client })
fxa.getOAuthToken({ scope: "profile", client })
.then(null, err => {
do_check_eq(err.message, "AUTH_ERROR");
do_check_eq(err.details.errno, ERRNO_INVALID_FXA_ASSERTION);
@ -1333,12 +1333,12 @@ add_test(function test_getOAuthToken_unknown_error() {
serverURL: "http://example.com/v1",
client_id: "abc123"
});
client.getTokenFromAssertion = function () {
client.getTokenFromAssertion = function() {
return Promise.reject("boom");
};
fxa.setSignedInUser(alice).then(() => {
fxa.getOAuthToken({ scope: "profile", client: client })
fxa.getOAuthToken({ scope: "profile", client })
.then(null, err => {
do_check_eq(err.message, "UNKNOWN_ERROR");
run_next_test();
@ -1351,10 +1351,10 @@ add_test(function test_getSignedInUserProfile() {
alice.verified = true;
let mockProfile = {
getProfile: function () {
getProfile() {
return Promise.resolve({ avatar: "image" });
},
tearDown: function() {},
tearDown() {},
};
let fxa = new FxAccounts({
_signOutServer() { return Promise.resolve(); },
@ -1377,17 +1377,17 @@ add_test(function test_getSignedInUserProfile_error_uses_account_data() {
let alice = getTestUser("alice");
alice.verified = true;
fxa.internal.getSignedInUser = function () {
fxa.internal.getSignedInUser = function() {
return Promise.resolve({ email: "foo@bar.com" });
};
let teardownCalled = false;
fxa.setSignedInUser(alice).then(() => {
fxa.internal._profile = {
getProfile: function () {
getProfile() {
return Promise.reject("boom");
},
tearDown: function() {
tearDown() {
teardownCalled = true;
}
};
@ -1420,7 +1420,7 @@ add_test(function test_getSignedInUserProfile_unverified_account() {
add_test(function test_getSignedInUserProfile_no_account_data() {
let fxa = new MockFxAccounts();
fxa.internal.getSignedInUser = function () {
fxa.internal.getSignedInUser = function() {
return Promise.resolve(null);
};
@ -1469,11 +1469,11 @@ function expandHex(two_hex) {
let eight_hex = two_hex + two_hex + two_hex + two_hex;
let thirtytwo_hex = eight_hex + eight_hex + eight_hex + eight_hex;
return thirtytwo_hex + thirtytwo_hex;
};
}
function expandBytes(two_hex) {
return CommonUtils.hexToBytes(expandHex(two_hex));
};
}
function getTestUser(name) {
return {
@ -1493,7 +1493,7 @@ function makeObserver(aObserveTopic, aObserveFunc) {
// nsIObserver is to be an observer
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports, Ci.nsIObserver]),
observe: function (aSubject, aTopic, aData) {
observe(aSubject, aTopic, aData) {
log.debug("observed " + aTopic + " " + aData);
if (aTopic == aObserveTopic) {
removeMe();
@ -1511,8 +1511,7 @@ function makeObserver(aObserveTopic, aObserveFunc) {
return removeMe;
}
function do_check_throws(func, result, stack)
{
function do_check_throws(func, result, stack) {
if (!stack)
stack = Components.stack.caller;

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

@ -69,7 +69,7 @@ function MockFxAccountsClient(device) {
// mock calls up to the auth server to determine whether the
// user account has been verified
this.recoveryEmailStatus = function (sessionToken) {
this.recoveryEmailStatus = function(sessionToken) {
// simulate a call to /recovery_email/status
return Promise.resolve({
email: this._email,
@ -110,7 +110,7 @@ function MockFxAccounts(device = {}) {
return new Promise((resolve) => {
resolve({
endpoint: "http://mochi.test:8888",
getKey: function(type) {
getKey(type) {
return ChromeUtils.base64URLDecode(
type === "auth" ? BOGUS_AUTHKEY : BOGUS_PUBLICKEY,
{ padding: "ignore" });
@ -138,7 +138,7 @@ add_task(function* test_updateDeviceRegistration_with_new_device() {
getDeviceList: { count: 0, args: [] }
};
const client = fxa.internal.fxAccountsClient;
client.registerDevice = function () {
client.registerDevice = function() {
spy.registerDevice.count += 1;
spy.registerDevice.args.push(arguments);
return Promise.resolve({
@ -148,12 +148,12 @@ add_task(function* test_updateDeviceRegistration_with_new_device() {
type: deviceType
});
};
client.updateDevice = function () {
client.updateDevice = function() {
spy.updateDevice.count += 1;
spy.updateDevice.args.push(arguments);
return Promise.resolve({});
};
client.getDeviceList = function () {
client.getDeviceList = function() {
spy.getDeviceList.count += 1;
spy.getDeviceList.args.push(arguments);
return Promise.resolve([]);
@ -194,12 +194,12 @@ add_task(function* test_updateDeviceRegistration_with_existing_device() {
getDeviceList: { count: 0, args: [] }
};
const client = fxa.internal.fxAccountsClient;
client.registerDevice = function () {
client.registerDevice = function() {
spy.registerDevice.count += 1;
spy.registerDevice.args.push(arguments);
return Promise.resolve({});
};
client.updateDevice = function () {
client.updateDevice = function() {
spy.updateDevice.count += 1;
spy.updateDevice.args.push(arguments);
return Promise.resolve({
@ -207,7 +207,7 @@ add_task(function* test_updateDeviceRegistration_with_existing_device() {
name: deviceName
});
};
client.getDeviceList = function () {
client.getDeviceList = function() {
spy.getDeviceList.count += 1;
spy.getDeviceList.args.push(arguments);
return Promise.resolve([]);
@ -247,7 +247,7 @@ add_task(function* test_updateDeviceRegistration_with_unknown_device_error() {
getDeviceList: { count: 0, args: [] }
};
const client = fxa.internal.fxAccountsClient;
client.registerDevice = function () {
client.registerDevice = function() {
spy.registerDevice.count += 1;
spy.registerDevice.args.push(arguments);
return Promise.resolve({
@ -257,7 +257,7 @@ add_task(function* test_updateDeviceRegistration_with_unknown_device_error() {
type: deviceType
});
};
client.updateDevice = function () {
client.updateDevice = function() {
spy.updateDevice.count += 1;
spy.updateDevice.args.push(arguments);
return Promise.reject({
@ -265,7 +265,7 @@ add_task(function* test_updateDeviceRegistration_with_unknown_device_error() {
errno: ERRNO_UNKNOWN_DEVICE
});
};
client.getDeviceList = function () {
client.getDeviceList = function() {
spy.getDeviceList.count += 1;
spy.getDeviceList.args.push(arguments);
return Promise.resolve([]);
@ -307,12 +307,12 @@ add_task(function* test_updateDeviceRegistration_with_device_session_conflict_er
getDeviceList: { count: 0, args: [] }
};
const client = fxa.internal.fxAccountsClient;
client.registerDevice = function () {
client.registerDevice = function() {
spy.registerDevice.count += 1;
spy.registerDevice.args.push(arguments);
return Promise.resolve({});
};
client.updateDevice = function () {
client.updateDevice = function() {
spy.updateDevice.count += 1;
spy.updateDevice.args.push(arguments);
spy.updateDevice.time = Date.now();
@ -327,7 +327,7 @@ add_task(function* test_updateDeviceRegistration_with_device_session_conflict_er
name: deviceName
});
};
client.getDeviceList = function () {
client.getDeviceList = function() {
spy.getDeviceList.count += 1;
spy.getDeviceList.args.push(arguments);
spy.getDeviceList.time = Date.now();
@ -376,7 +376,7 @@ add_task(function* test_updateDeviceRegistration_with_unrecoverable_error() {
getDeviceList: { count: 0, args: [] }
};
const client = fxa.internal.fxAccountsClient;
client.registerDevice = function () {
client.registerDevice = function() {
spy.registerDevice.count += 1;
spy.registerDevice.args.push(arguments);
return Promise.reject({
@ -384,12 +384,12 @@ add_task(function* test_updateDeviceRegistration_with_unrecoverable_error() {
errno: ERRNO_TOO_MANY_CLIENT_REQUESTS
});
};
client.updateDevice = function () {
client.updateDevice = function() {
spy.updateDevice.count += 1;
spy.updateDevice.args.push(arguments);
return Promise.resolve({});
};
client.getDeviceList = function () {
client.getDeviceList = function() {
spy.getDeviceList.count += 1;
spy.getDeviceList.args.push(arguments);
return Promise.resolve([]);
@ -420,7 +420,7 @@ add_task(function* test_getDeviceId_with_no_device_id_invokes_device_registratio
fxa.internal.currentAccountState.getUserAccountData =
() => Promise.resolve({ email: credentials.email,
deviceRegistrationVersion: DEVICE_REGISTRATION_VERSION });
fxa.internal._registerOrUpdateDevice = function () {
fxa.internal._registerOrUpdateDevice = function() {
spy.count += 1;
spy.args.push(arguments);
return Promise.resolve("bar");
@ -444,7 +444,7 @@ add_task(function* test_getDeviceId_with_registration_version_outdated_invokes_d
const spy = { count: 0, args: [] };
fxa.internal.currentAccountState.getUserAccountData =
() => Promise.resolve({ deviceId: credentials.deviceId, deviceRegistrationVersion: 0 });
fxa.internal._registerOrUpdateDevice = function () {
fxa.internal._registerOrUpdateDevice = function() {
spy.count += 1;
spy.args.push(arguments);
return Promise.resolve("wibble");
@ -467,7 +467,7 @@ add_task(function* test_getDeviceId_with_device_id_and_uptodate_registration_ver
const spy = { count: 0 };
fxa.internal.currentAccountState.getUserAccountData =
() => Promise.resolve({ deviceId: credentials.deviceId, deviceRegistrationVersion: DEVICE_REGISTRATION_VERSION });
fxa.internal._registerOrUpdateDevice = function () {
fxa.internal._registerOrUpdateDevice = function() {
spy.count += 1;
return Promise.resolve("bar");
};
@ -487,7 +487,7 @@ add_task(function* test_getDeviceId_with_device_id_and_with_no_registration_vers
const spy = { count: 0, args: [] };
fxa.internal.currentAccountState.getUserAccountData =
() => Promise.resolve({ deviceId: credentials.deviceId });
fxa.internal._registerOrUpdateDevice = function () {
fxa.internal._registerOrUpdateDevice = function() {
spy.count += 1;
spy.args.push(arguments);
return Promise.resolve("wibble");
@ -506,11 +506,11 @@ function expandHex(two_hex) {
let eight_hex = two_hex + two_hex + two_hex + two_hex;
let thirtytwo_hex = eight_hex + eight_hex + eight_hex + eight_hex;
return thirtytwo_hex + thirtytwo_hex;
};
}
function expandBytes(two_hex) {
return CommonUtils.hexToBytes(expandHex(two_hex));
};
}
function getTestUser(name) {
return {

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

@ -17,20 +17,20 @@ function run_test() {
// https://wiki.mozilla.org/Identity/AttachedServices/KeyServerProtocol#.2Faccount.2Fkeys
var ACCOUNT_KEYS = {
keyFetch: h("8081828384858687 88898a8b8c8d8e8f"+
keyFetch: h("8081828384858687 88898a8b8c8d8e8f" +
"9091929394959697 98999a9b9c9d9e9f"),
response: h("ee5c58845c7c9412 b11bbd20920c2fdd"+
"d83c33c9cd2c2de2 d66b222613364636"+
"c2c0f8cfbb7c6304 72c0bd88451342c6"+
"c05b14ce342c5ad4 6ad89e84464c993c"+
"3927d30230157d08 17a077eef4b20d97"+
response: h("ee5c58845c7c9412 b11bbd20920c2fdd" +
"d83c33c9cd2c2de2 d66b222613364636" +
"c2c0f8cfbb7c6304 72c0bd88451342c6" +
"c05b14ce342c5ad4 6ad89e84464c993c" +
"3927d30230157d08 17a077eef4b20d97" +
"6f7a97363faf3f06 4c003ada7d01aa70"),
kA: h("2021222324252627 28292a2b2c2d2e2f"+
kA: h("2021222324252627 28292a2b2c2d2e2f" +
"3031323334353637 38393a3b3c3d3e3f"),
wrapKB: h("4041424344454647 48494a4b4c4d4e4f"+
wrapKB: h("4041424344454647 48494a4b4c4d4e4f" +
"5051525354555657 58595a5b5c5d5e5f"),
};
@ -238,7 +238,7 @@ add_task(function* test_signUp() {
try {
result = yield client.signUp(unicodeUsername, unicodePassword);
do_throw("Expected to catch an exception");
} catch(expectedError) {
} catch (expectedError) {
do_check_eq(101, expectedError.errno);
}
@ -279,29 +279,26 @@ add_task(function* test_signIn() {
response.setStatusLine(request.httpVersion, 200, "OK");
response.bodyOutputStream.write(sessionMessage_noKey,
sessionMessage_noKey.length);
return;
}
else if (jsonBody.email == "you@example.com") {
} else if (jsonBody.email == "you@example.com") {
do_check_eq("keys=true", request._queryString);
do_check_eq(jsonBody.authPW, "93d20ec50304d496d0707ec20d7e8c89459b6396ec5dd5b9e92809c5e42856c7");
response.setStatusLine(request.httpVersion, 200, "OK");
response.bodyOutputStream.write(sessionMessage_withKey,
sessionMessage_withKey.length);
return;
}
else if (jsonBody.email == "You@example.com") {
} else if (jsonBody.email == "You@example.com") {
// Error trying to sign in with a wrong capitalization
response.setStatusLine(request.httpVersion, 400, "Bad request");
response.bodyOutputStream.write(errorMessage_wrongCap,
errorMessage_wrongCap.length);
return;
}
else {
} else {
// Error trying to sign in to nonexistent account
response.setStatusLine(request.httpVersion, 400, "Bad request");
response.bodyOutputStream.write(errorMessage_notExistent,
errorMessage_notExistent.length);
return;
}
},
});
@ -357,7 +354,7 @@ add_task(function* test_signOut() {
// Error trying to sign out of nonexistent account
response.setStatusLine(request.httpVersion, 400, "Bad request");
response.bodyOutputStream.write(errorMessage, errorMessage.length);
return;
},
});
@ -369,7 +366,7 @@ add_task(function* test_signOut() {
try {
result = yield client.signOut("FakeSession");
do_throw("Expected to catch an exception");
} catch(expectedError) {
} catch (expectedError) {
do_check_eq(102, expectedError.errno);
}
@ -396,7 +393,7 @@ add_task(function* test_recoveryEmailStatus() {
// Second call gets an error trying to query a nonexistent account
response.setStatusLine(request.httpVersion, 400, "Bad request");
response.bodyOutputStream.write(errorMessage, errorMessage.length);
return;
},
});
@ -408,7 +405,7 @@ add_task(function* test_recoveryEmailStatus() {
try {
result = yield client.recoveryEmailStatus("some bogus session");
do_throw("Expected to catch an exception");
} catch(expectedError) {
} catch (expectedError) {
do_check_eq(102, expectedError.errno);
}
@ -425,7 +422,7 @@ add_task(function* test_recoveryEmailStatusWithReason() {
response.setStatusLine(request.httpVersion, 200, "OK");
response.bodyOutputStream.write(emailStatus, emailStatus.length);
return;
},
});
@ -455,7 +452,7 @@ add_task(function* test_resendVerificationEmail() {
// Second call gets an error trying to query a nonexistent account
response.setStatusLine(request.httpVersion, 400, "Bad request");
response.bodyOutputStream.write(errorMessage, errorMessage.length);
return;
},
});
@ -467,7 +464,7 @@ add_task(function* test_resendVerificationEmail() {
try {
result = yield client.resendVerificationEmail("some bogus session");
do_throw("Expected to catch an exception");
} catch(expectedError) {
} catch (expectedError) {
do_check_eq(102, expectedError.errno);
}
@ -489,7 +486,7 @@ add_task(function* test_accountKeys() {
do_check_true(request.hasHeader("Authorization"));
attempt += 1;
switch(attempt) {
switch (attempt) {
case 1:
// First time succeeds
response.setStatusLine(request.httpVersion, 200, "OK");
@ -532,7 +529,7 @@ add_task(function* test_accountKeys() {
try {
result = yield client.accountKeys(ACCOUNT_KEYS.keyFetch);
do_throw("Expected to catch an exception");
} catch(expectedError) {
} catch (expectedError) {
do_check_eq(expectedError.message, "failed to retrieve keys");
}
@ -540,7 +537,7 @@ add_task(function* test_accountKeys() {
try {
result = yield client.accountKeys(ACCOUNT_KEYS.keyFetch);
do_throw("Expected to catch an exception");
} catch(expectedError) {
} catch (expectedError) {
do_check_eq(expectedError.message, "error unbundling encryption keys");
}
@ -548,7 +545,7 @@ add_task(function* test_accountKeys() {
try {
result = yield client.accountKeys(ACCOUNT_KEYS.keyFetch);
do_throw("Expected to catch an exception");
} catch(expectedError) {
} catch (expectedError) {
do_check_eq(102, expectedError.errno);
}
@ -578,7 +575,7 @@ add_task(function* test_signCertificate() {
// Second attempt, trigger error
response.setStatusLine(request.httpVersion, 400, "Bad request");
response.bodyOutputStream.write(errorMessage, errorMessage.length);
return;
},
});
@ -590,7 +587,7 @@ add_task(function* test_signCertificate() {
try {
result = yield client.signCertificate("bogus", JSON.stringify({foo: "bar"}), 600);
do_throw("Expected to catch an exception");
} catch(expectedError) {
} catch (expectedError) {
do_check_eq(102, expectedError.errno);
}
@ -651,7 +648,7 @@ add_task(function* test_accountExists() {
try {
result = yield client.accountExists("i.break.things@example.com");
do_throw("Expected to catch an exception");
} catch(unexpectedError) {
} catch (unexpectedError) {
do_check_eq(unexpectedError.code, 500);
}
@ -702,7 +699,7 @@ add_task(function* test_registerDevice() {
try {
yield client.registerDevice(FAKE_SESSION_TOKEN, ERROR_NAME, DEVICE_TYPE);
do_throw("Expected to catch an exception");
} catch(unexpectedError) {
} catch (unexpectedError) {
do_check_eq(unexpectedError.code, 500);
}
@ -746,7 +743,7 @@ add_task(function* test_updateDevice() {
try {
yield client.updateDevice(FAKE_SESSION_TOKEN, ERROR_ID, DEVICE_NAME);
do_throw("Expected to catch an exception");
} catch(unexpectedError) {
} catch (unexpectedError) {
do_check_eq(unexpectedError.code, 500);
}
@ -785,7 +782,7 @@ add_task(function* test_signOutAndDestroyDevice() {
try {
yield client.signOutAndDestroyDevice(FAKE_SESSION_TOKEN, ERROR_ID);
do_throw("Expected to catch an exception");
} catch(unexpectedError) {
} catch (unexpectedError) {
do_check_eq(unexpectedError.code, 500);
}
@ -818,7 +815,7 @@ add_task(function* test_getDeviceList() {
canReturnDevices = false;
yield client.getDeviceList(FAKE_SESSION_TOKEN);
do_throw("Expected to catch an exception");
} catch(unexpectedError) {
} catch (unexpectedError) {
do_check_eq(unexpectedError.code, 500);
}

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

@ -20,11 +20,11 @@ const STATUS_SUCCESS = 200;
* Mocked raw response from the server
* @returns {Function}
*/
var mockResponse = function (response) {
return function () {
var mockResponse = function(response) {
return function() {
return {
setHeader: function () {},
post: function () {
setHeader() {},
post() {
this.response = response;
this.onComplete();
}
@ -38,18 +38,18 @@ var mockResponse = function (response) {
* Error object
* @returns {Function}
*/
var mockResponseError = function (error) {
return function () {
var mockResponseError = function(error) {
return function() {
return {
setHeader: function () {},
post: function () {
setHeader() {},
post() {
this.onComplete(error);
}
};
};
};
add_test(function missingParams () {
add_test(function missingParams() {
let client = new FxAccountsOAuthGrantClient(CLIENT_OPTIONS);
try {
client.getTokenFromAssertion()
@ -66,7 +66,7 @@ add_test(function missingParams () {
run_next_test();
});
add_test(function successfulResponse () {
add_test(function successfulResponse() {
let client = new FxAccountsOAuthGrantClient(CLIENT_OPTIONS);
let response = {
success: true,
@ -77,14 +77,14 @@ add_test(function successfulResponse () {
client._Request = new mockResponse(response);
client.getTokenFromAssertion("assertion", "scope")
.then(
function (result) {
function(result) {
do_check_eq(result.access_token, "http://example.com/image.jpeg");
run_next_test();
}
);
});
add_test(function successfulDestroy () {
add_test(function successfulDestroy() {
let client = new FxAccountsOAuthGrantClient(CLIENT_OPTIONS);
let response = {
success: true,
@ -96,7 +96,7 @@ add_test(function successfulDestroy () {
client.destroyToken("deadbeef").then(run_next_test);
});
add_test(function parseErrorResponse () {
add_test(function parseErrorResponse() {
let client = new FxAccountsOAuthGrantClient(CLIENT_OPTIONS);
let response = {
success: true,
@ -108,7 +108,7 @@ add_test(function parseErrorResponse () {
client.getTokenFromAssertion("assertion", "scope")
.then(
null,
function (e) {
function(e) {
do_check_eq(e.name, "FxAccountsOAuthGrantClientError");
do_check_eq(e.code, STATUS_SUCCESS);
do_check_eq(e.errno, ERRNO_PARSE);
@ -119,7 +119,7 @@ add_test(function parseErrorResponse () {
);
});
add_test(function serverErrorResponse () {
add_test(function serverErrorResponse() {
let client = new FxAccountsOAuthGrantClient(CLIENT_OPTIONS);
let response = {
status: 400,
@ -130,7 +130,7 @@ add_test(function serverErrorResponse () {
client.getTokenFromAssertion("blah", "scope")
.then(
null,
function (e) {
function(e) {
do_check_eq(e.name, "FxAccountsOAuthGrantClientError");
do_check_eq(e.code, 400);
do_check_eq(e.errno, ERRNO_INVALID_FXA_ASSERTION);
@ -141,7 +141,7 @@ add_test(function serverErrorResponse () {
);
});
add_test(function networkErrorResponse () {
add_test(function networkErrorResponse() {
let client = new FxAccountsOAuthGrantClient({
serverURL: "http://",
client_id: "abc123"
@ -150,7 +150,7 @@ add_test(function networkErrorResponse () {
client.getTokenFromAssertion("assertion", "scope")
.then(
null,
function (e) {
function(e) {
do_check_eq(e.name, "FxAccountsOAuthGrantClientError");
do_check_eq(e.code, null);
do_check_eq(e.errno, ERRNO_NETWORK);
@ -161,13 +161,13 @@ add_test(function networkErrorResponse () {
Services.prefs.clearUserPref("identity.fxaccounts.skipDeviceRegistration"));
});
add_test(function unsupportedMethod () {
add_test(function unsupportedMethod() {
let client = new FxAccountsOAuthGrantClient(CLIENT_OPTIONS);
return client._createRequest("/", "PUT")
.then(
null,
function (e) {
function(e) {
do_check_eq(e.name, "FxAccountsOAuthGrantClientError");
do_check_eq(e.code, ERROR_CODE_METHOD_NOT_ALLOWED);
do_check_eq(e.errno, ERRNO_NETWORK);
@ -178,13 +178,13 @@ add_test(function unsupportedMethod () {
);
});
add_test(function onCompleteRequestError () {
add_test(function onCompleteRequestError() {
let client = new FxAccountsOAuthGrantClient(CLIENT_OPTIONS);
client._Request = new mockResponseError(new Error("onComplete error"));
client.getTokenFromAssertion("assertion", "scope")
.then(
null,
function (e) {
function(e) {
do_check_eq(e.name, "FxAccountsOAuthGrantClientError");
do_check_eq(e.code, null);
do_check_eq(e.errno, ERRNO_NETWORK);
@ -206,7 +206,7 @@ add_test(function incorrectErrno() {
client.getTokenFromAssertion("blah", "scope")
.then(
null,
function (e) {
function(e) {
do_check_eq(e.name, "FxAccountsOAuthGrantClientError");
do_check_eq(e.code, 400);
do_check_eq(e.errno, ERRNO_UNKNOWN_ERROR);

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

@ -50,7 +50,7 @@ function promiseStopServer(server) {
});
}
add_task(function* getAndRevokeToken () {
add_task(function* getAndRevokeToken() {
let server = startServer();
let clientOptions = {
serverURL: "http://localhost:" + server.identity.primaryPort + "/v1",

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

@ -82,7 +82,7 @@ MockFxAccountsClient.prototype = {
__proto__: FxAccountsClient.prototype
}
function MockFxAccounts(device={}) {
function MockFxAccounts(device = {}) {
return new FxAccounts({
fxAccountsClient: new MockFxAccountsClient(),
newAccountState(credentials) {

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

@ -89,7 +89,7 @@ function MockFxAccounts(mockGrantClient) {
storage.initialize(credentials);
return new AccountState(storage);
},
_destroyOAuthToken: function(tokenData) {
_destroyOAuthToken(tokenData) {
// somewhat sad duplication of _destroyOAuthToken, but hard to avoid.
return mockGrantClient.destroyToken(tokenData.token).then( () => {
Services.obs.notifyObservers(null, "testhelper-fxa-revoke-complete", null);
@ -156,7 +156,7 @@ MockFxAccountsOAuthGrantClient.prototype = {
add_task(function* testRevoke() {
let client = new MockFxAccountsOAuthGrantClient();
let tokenOptions = { scope: "test-scope", client: client };
let tokenOptions = { scope: "test-scope", client };
let fxa = yield createMockFxA(client);
// get our first token and check we hit the mock.
@ -186,13 +186,13 @@ add_task(function* testSignOutDestroysTokens() {
let fxa = yield createMockFxA(client);
// get our first token and check we hit the mock.
let token1 = yield fxa.getOAuthToken({ scope: "test-scope", client: client });
let token1 = yield fxa.getOAuthToken({ scope: "test-scope", client });
equal(client.numTokenFetches, 1);
equal(client.activeTokens.size, 1);
ok(token1, "got a token");
// get another
let token2 = yield fxa.getOAuthToken({ scope: "test-scope-2", client: client });
let token2 = yield fxa.getOAuthToken({ scope: "test-scope-2", client });
equal(client.numTokenFetches, 2);
equal(client.activeTokens.size, 2);
ok(token2, "got a token");
@ -222,10 +222,10 @@ add_task(function* testTokenRaces() {
promiseNotification("testhelper-fxa-revoke-complete"),
]);
let results = yield Promise.all([
fxa.getOAuthToken({scope: "test-scope", client: client}),
fxa.getOAuthToken({scope: "test-scope", client: client}),
fxa.getOAuthToken({scope: "test-scope-2", client: client}),
fxa.getOAuthToken({scope: "test-scope-2", client: client}),
fxa.getOAuthToken({scope: "test-scope", client}),
fxa.getOAuthToken({scope: "test-scope", client}),
fxa.getOAuthToken({scope: "test-scope-2", client}),
fxa.getOAuthToken({scope: "test-scope-2", client}),
]);
equal(client.numTokenFetches, 4, "should have fetched 4 tokens.");

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

@ -19,13 +19,13 @@ const STATUS_SUCCESS = 200;
* Mocked raw response from the server
* @returns {Function}
*/
var mockResponse = function (response) {
let Request = function (requestUri) {
var mockResponse = function(response) {
let Request = function(requestUri) {
// Store the request uri so tests can inspect it
Request._requestUri = requestUri;
return {
setHeader: function () {},
head: function () {
setHeader() {},
head() {
this.response = response;
this.onComplete();
}
@ -41,21 +41,21 @@ var mockResponse = function (response) {
* Error object
* @returns {Function}
*/
var mockResponseError = function (error) {
return function () {
var mockResponseError = function(error) {
return function() {
return {
setHeader: function () {},
head: function () {
setHeader() {},
head() {
this.onComplete(error);
}
};
};
};
var mockClient = function (fxa) {
var mockClient = function(fxa) {
let options = {
serverURL: "http://127.0.0.1:1111/v1",
fxa: fxa,
fxa,
}
return new FxAccountsProfileClient(options);
};
@ -74,7 +74,7 @@ FxaMock.prototype = {
}
},
getSignedInUser: function () {
getSignedInUser() {
return Promise.resolve(ACCOUNT_DATA);
}
};
@ -88,7 +88,7 @@ function CreateFxAccountsProfile(fxa = null, client = null) {
fxa = mockFxa();
}
let options = {
fxa: fxa,
fxa,
profileServerUrl: "http://127.0.0.1:1111/v1"
}
if (client) {
@ -103,7 +103,7 @@ add_test(function getCachedProfile() {
profile._cachedProfile = { avatar: "myurl" };
return profile._getCachedProfile()
.then(function (cached) {
.then(function(cached) {
do_check_eq(cached.avatar, "myurl");
run_next_test();
});
@ -121,7 +121,7 @@ add_test(function cacheProfile_change() {
*/
let profile = CreateFxAccountsProfile(fxa);
makeObserver(ON_PROFILE_CHANGE_NOTIFICATION, function (subject, topic, data) {
makeObserver(ON_PROFILE_CHANGE_NOTIFICATION, function(subject, topic, data) {
do_check_eq(data, ACCOUNT_DATA.uid);
// do_check_true(setUserAccountDataCalled); - bug 1157529
run_next_test();
@ -136,7 +136,7 @@ add_test(function cacheProfile_no_change() {
profile._cachedProfile = { avatar: "myurl" };
// XXX - saving is disabled (but we can leave that in for now as we are
// just checking it is *not* called)
fxa.setSignedInUser = function (data) {
fxa.setSignedInUser = function(data) {
throw new Error("should not update account data");
};
@ -149,12 +149,12 @@ add_test(function cacheProfile_no_change() {
add_test(function fetchAndCacheProfile_ok() {
let client = mockClient(mockFxa());
client.fetchProfile = function () {
client.fetchProfile = function() {
return Promise.resolve({ avatar: "myimg"});
};
let profile = CreateFxAccountsProfile(null, client);
profile._cacheProfile = function (toCache) {
profile._cacheProfile = function(toCache) {
do_check_eq(toCache.avatar, "myimg");
return Promise.resolve();
};
@ -177,7 +177,7 @@ add_task(function* fetchAndCacheProfileOnce() {
});
let numFetches = 0;
let client = mockClient(mockFxa());
client.fetchProfile = function () {
client.fetchProfile = function() {
numFetches += 1;
return promiseProfile;
};
@ -209,12 +209,12 @@ add_task(function* fetchAndCacheProfileOnce() {
// A promise that remains unresolved while we fire off 2 requests for
// a profile.
let rejectProfile;
let promiseProfile = new Promise((resolve,reject) => {
let promiseProfile = new Promise((resolve, reject) => {
rejectProfile = reject;
});
let numFetches = 0;
let client = mockClient(mockFxa());
client.fetchProfile = function () {
client.fetchProfile = function() {
numFetches += 1;
return promiseProfile;
};
@ -249,7 +249,7 @@ add_task(function* fetchAndCacheProfileOnce() {
}
// but a new request should work.
client.fetchProfile = function () {
client.fetchProfile = function() {
return Promise.resolve({ avatar: "myimg"});
};
@ -262,7 +262,7 @@ add_task(function* fetchAndCacheProfileOnce() {
add_task(function* fetchAndCacheProfileAfterThreshold() {
let numFetches = 0;
let client = mockClient(mockFxa());
client.fetchProfile = function () {
client.fetchProfile = function() {
numFetches += 1;
return Promise.resolve({ avatar: "myimg"});
};
@ -289,7 +289,7 @@ add_task(function* fetchAndCacheProfileAfterThreshold() {
add_task(function* fetchAndCacheProfileBeforeThresholdOnNotification() {
let numFetches = 0;
let client = mockClient(mockFxa());
client.fetchProfile = function () {
client.fetchProfile = function() {
numFetches += 1;
return Promise.resolve({ avatar: "myimg"});
};
@ -323,11 +323,11 @@ add_test(function getProfile_ok() {
let didFetch = false;
let profile = CreateFxAccountsProfile();
profile._getCachedProfile = function () {
profile._getCachedProfile = function() {
return Promise.resolve({ avatar: cachedUrl });
};
profile._fetchAndCacheProfile = function () {
profile._fetchAndCacheProfile = function() {
didFetch = true;
return Promise.resolve();
};
@ -343,11 +343,11 @@ add_test(function getProfile_ok() {
add_test(function getProfile_no_cache() {
let fetchedUrl = "newUrl";
let profile = CreateFxAccountsProfile();
profile._getCachedProfile = function () {
profile._getCachedProfile = function() {
return Promise.resolve();
};
profile._fetchAndCacheProfile = function () {
profile._fetchAndCacheProfile = function() {
return Promise.resolve({ avatar: fetchedUrl });
};
@ -363,7 +363,7 @@ add_test(function getProfile_has_cached_fetch_deleted() {
let fxa = mockFxa();
let client = mockClient(fxa);
client.fetchProfile = function () {
client.fetchProfile = function() {
return Promise.resolve({ avatar: null });
};
@ -372,7 +372,7 @@ add_test(function getProfile_has_cached_fetch_deleted() {
// instead of checking this in a mocked "save" function, just check after the
// observer
makeObserver(ON_PROFILE_CHANGE_NOTIFICATION, function (subject, topic, data) {
makeObserver(ON_PROFILE_CHANGE_NOTIFICATION, function(subject, topic, data) {
profile.getProfile()
.then(profileData => {
do_check_null(profileData.avatar);
@ -391,7 +391,7 @@ function run_test() {
}
function makeObserver(aObserveTopic, aObserveFunc) {
let callback = function (aSubject, aTopic, aData) {
let callback = function(aSubject, aTopic, aData) {
log.debug("observed " + aTopic + " " + aData);
if (aTopic == aObserveTopic) {
removeMe();

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

@ -14,13 +14,13 @@ const STATUS_SUCCESS = 200;
* Mocked raw response from the server
* @returns {Function}
*/
var mockResponse = function (response) {
let Request = function (requestUri) {
var mockResponse = function(response) {
let Request = function(requestUri) {
// Store the request uri so tests can inspect it
Request._requestUri = requestUri;
return {
setHeader: function () {},
get: function () {
setHeader() {},
get() {
this.response = response;
this.onComplete();
}
@ -51,18 +51,18 @@ const PROFILE_OPTIONS = {
* Error object
* @returns {Function}
*/
var mockResponseError = function (error) {
return function () {
var mockResponseError = function(error) {
return function() {
return {
setHeader: function () {},
get: function () {
setHeader() {},
get() {
this.onComplete(error);
}
};
};
};
add_test(function successfulResponse () {
add_test(function successfulResponse() {
let client = new FxAccountsProfileClient(PROFILE_OPTIONS);
let response = {
success: true,
@ -73,7 +73,7 @@ add_test(function successfulResponse () {
client._Request = new mockResponse(response);
client.fetchProfile()
.then(
function (result) {
function(result) {
do_check_eq(client._Request._requestUri, "http://127.0.0.1:1111/v1/profile");
do_check_eq(result.email, "someone@restmail.net");
do_check_eq(result.uid, "0d5c1a89b8c54580b8e3e8adadae864a");
@ -82,7 +82,7 @@ add_test(function successfulResponse () {
);
});
add_test(function parseErrorResponse () {
add_test(function parseErrorResponse() {
let client = new FxAccountsProfileClient(PROFILE_OPTIONS);
let response = {
success: true,
@ -94,7 +94,7 @@ add_test(function parseErrorResponse () {
client.fetchProfile()
.then(
null,
function (e) {
function(e) {
do_check_eq(e.name, "FxAccountsProfileClientError");
do_check_eq(e.code, STATUS_SUCCESS);
do_check_eq(e.errno, ERRNO_PARSE);
@ -105,7 +105,7 @@ add_test(function parseErrorResponse () {
);
});
add_test(function serverErrorResponse () {
add_test(function serverErrorResponse() {
let client = new FxAccountsProfileClient(PROFILE_OPTIONS);
let response = {
status: 500,
@ -116,7 +116,7 @@ add_test(function serverErrorResponse () {
client.fetchProfile()
.then(
null,
function (e) {
function(e) {
do_check_eq(e.name, "FxAccountsProfileClientError");
do_check_eq(e.code, 500);
do_check_eq(e.errno, 100);
@ -129,7 +129,7 @@ add_test(function serverErrorResponse () {
// Test that we get a token, then if we get a 401 we revoke it, get a new one
// and retry.
add_test(function server401ResponseThenSuccess () {
add_test(function server401ResponseThenSuccess() {
// The last token we handed out.
let lastToken = -1;
// The number of times our removeCachedOAuthToken function was called.
@ -171,13 +171,13 @@ add_test(function server401ResponseThenSuccess () {
// Like mockResponse but we want access to headers etc.
client._Request = function(requestUri) {
return {
setHeader: function (name, value) {
setHeader(name, value) {
if (name == "Authorization") {
numAuthHeaders++;
do_check_eq(value, "Bearer " + lastToken);
}
},
get: function () {
get() {
this.response = responses[numRequests];
++numRequests;
this.onComplete();
@ -202,7 +202,7 @@ add_test(function server401ResponseThenSuccess () {
// Test that we get a token, then if we get a 401 we revoke it, get a new one
// and retry - but we *still* get a 401 on the retry, so the caller sees that.
add_test(function server401ResponsePersists () {
add_test(function server401ResponsePersists() {
// The last token we handed out.
let lastToken = -1;
// The number of times our removeCachedOAuthToken function was called.
@ -235,13 +235,13 @@ add_test(function server401ResponsePersists () {
let numAuthHeaders = 0;
client._Request = function(requestUri) {
return {
setHeader: function (name, value) {
setHeader(name, value) {
if (name == "Authorization") {
numAuthHeaders++;
do_check_eq(value, "Bearer " + lastToken);
}
},
get: function () {
get() {
this.response = response;
++numRequests;
this.onComplete();
@ -251,7 +251,7 @@ add_test(function server401ResponsePersists () {
client.fetchProfile().then(
null,
function (e) {
function(e) {
do_check_eq(e.name, "FxAccountsProfileClientError");
do_check_eq(e.code, 401);
do_check_eq(e.errno, 100);
@ -266,7 +266,7 @@ add_test(function server401ResponsePersists () {
);
});
add_test(function networkErrorResponse () {
add_test(function networkErrorResponse() {
let client = new FxAccountsProfileClient({
serverURL: "http://",
fxa: mockFxa,
@ -274,7 +274,7 @@ add_test(function networkErrorResponse () {
client.fetchProfile()
.then(
null,
function (e) {
function(e) {
do_check_eq(e.name, "FxAccountsProfileClientError");
do_check_eq(e.code, null);
do_check_eq(e.errno, ERRNO_NETWORK);
@ -284,13 +284,13 @@ add_test(function networkErrorResponse () {
);
});
add_test(function unsupportedMethod () {
add_test(function unsupportedMethod() {
let client = new FxAccountsProfileClient(PROFILE_OPTIONS);
return client._createRequest("/profile", "PUT")
.then(
null,
function (e) {
function(e) {
do_check_eq(e.name, "FxAccountsProfileClientError");
do_check_eq(e.code, ERROR_CODE_METHOD_NOT_ALLOWED);
do_check_eq(e.errno, ERRNO_NETWORK);
@ -301,13 +301,13 @@ add_test(function unsupportedMethod () {
);
});
add_test(function onCompleteRequestError () {
add_test(function onCompleteRequestError() {
let client = new FxAccountsProfileClient(PROFILE_OPTIONS);
client._Request = new mockResponseError(new Error("onComplete error"));
client.fetchProfile()
.then(
null,
function (e) {
function(e) {
do_check_eq(e.name, "FxAccountsProfileClientError");
do_check_eq(e.code, null);
do_check_eq(e.errno, ERRNO_NETWORK);
@ -318,7 +318,7 @@ add_test(function onCompleteRequestError () {
);
});
add_test(function fetchProfileImage_successfulResponse () {
add_test(function fetchProfileImage_successfulResponse() {
let client = new FxAccountsProfileClient(PROFILE_OPTIONS);
let response = {
success: true,
@ -329,7 +329,7 @@ add_test(function fetchProfileImage_successfulResponse () {
client._Request = new mockResponse(response);
client.fetchProfileImage()
.then(
function (result) {
function(result) {
do_check_eq(client._Request._requestUri, "http://127.0.0.1:1111/v1/avatar");
do_check_eq(result.avatar, "http://example.com/image.jpg");
do_check_eq(result.id, "0d5c1a89b8c54580b8e3e8adadae864a");

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

@ -106,7 +106,7 @@ add_task(function* unsubscribeFailure() {
add_test(function observeLogout() {
let customLog = Object.assign(mockLog, {
trace: function (msg) {
trace(msg) {
if (msg === "FxAccountsPushService unsubscribe") {
// logout means we unsubscribe
run_next_test();
@ -124,12 +124,12 @@ add_test(function observeLogout() {
add_test(function observePushTopicVerify() {
let emptyMsg = {
QueryInterface: function() {
QueryInterface() {
return this;
}
};
let customAccounts = Object.assign(mockFxAccounts, {
checkVerificationStatus: function () {
checkVerificationStatus() {
// checking verification status on push messages without data
run_next_test();
}
@ -153,7 +153,7 @@ add_test(function observePushTopicDeviceConnected() {
}
})
},
QueryInterface: function() {
QueryInterface() {
return this;
}
};
@ -182,12 +182,12 @@ add_test(function observePushTopicDeviceDisconnected() {
}
})
},
QueryInterface: function() {
QueryInterface() {
return this;
}
};
let customAccounts = Object.assign(mockFxAccounts, {
handleDeviceDisconnection: function () {
handleDeviceDisconnection() {
// checking verification status on push messages without data
run_next_test();
}
@ -208,7 +208,7 @@ add_test(function observePushTopicPasswordChanged() {
command: ON_PASSWORD_CHANGED_NOTIFICATION
})
},
QueryInterface: function() {
QueryInterface() {
return this;
}
};
@ -217,7 +217,7 @@ add_test(function observePushTopicPasswordChanged() {
pushService: mockPushService,
});
pushService._onPasswordChanged = function () {
pushService._onPasswordChanged = function() {
run_next_test();
}
@ -231,7 +231,7 @@ add_test(function observePushTopicPasswordReset() {
command: ON_PASSWORD_RESET_NOTIFICATION
})
},
QueryInterface: function() {
QueryInterface() {
return this;
}
};
@ -240,7 +240,7 @@ add_test(function observePushTopicPasswordReset() {
pushService: mockPushService
});
pushService._onPasswordChanged = function () {
pushService._onPasswordChanged = function() {
run_next_test();
}
@ -249,7 +249,7 @@ add_test(function observePushTopicPasswordReset() {
add_test(function observeSubscriptionChangeTopic() {
let customAccounts = Object.assign(mockFxAccounts, {
updateDeviceRegistration: function () {
updateDeviceRegistration() {
// subscription change means updating the device registration
run_next_test();
}

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

@ -22,7 +22,7 @@ function MockedPlainStorage(accountData) {
if (accountData) {
data = {
version: DATA_FORMAT_VERSION,
accountData: accountData,
accountData,
}
}
this.data = data;
@ -45,7 +45,7 @@ function MockedSecureStorage(accountData) {
if (accountData) {
data = {
version: DATA_FORMAT_VERSION,
accountData: accountData,
accountData,
}
}
this.data = data;
@ -55,7 +55,7 @@ function MockedSecureStorage(accountData) {
MockedSecureStorage.prototype = {
fetchCount: 0,
locked: false,
STORAGE_LOCKED: function() {},
STORAGE_LOCKED() {},
get: Task.async(function* (uid, email) {
this.fetchCount++;
if (this.locked) {

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

@ -15,7 +15,7 @@ const mockSendingContext = {
eventTarget: {}
};
add_test(function () {
add_test(function() {
validationHelper(undefined,
"Error: Missing configuration options");
@ -118,7 +118,7 @@ add_test(function test_profile_image_change_message() {
data: { uid: "foo" }
};
makeObserver(ON_PROFILE_CHANGE_NOTIFICATION, function (subject, topic, data) {
makeObserver(ON_PROFILE_CHANGE_NOTIFICATION, function(subject, topic, data) {
do_check_eq(data, "foo");
run_next_test();
});
@ -141,7 +141,7 @@ add_test(function test_login_message() {
channel_id: WEBCHANNEL_ID,
content_uri: URL_STRING,
helpers: {
login: function (accountData) {
login(accountData) {
do_check_eq(accountData.email, 'testuser@testuser.com');
run_next_test();
return Promise.resolve();
@ -162,7 +162,7 @@ add_test(function test_logout_message() {
channel_id: WEBCHANNEL_ID,
content_uri: URL_STRING,
helpers: {
logout: function (uid) {
logout(uid) {
do_check_eq(uid, 'foo');
run_next_test();
return Promise.resolve();
@ -183,7 +183,7 @@ add_test(function test_delete_message() {
channel_id: WEBCHANNEL_ID,
content_uri: URL_STRING,
helpers: {
logout: function (uid) {
logout(uid) {
do_check_eq(uid, 'foo');
run_next_test();
return Promise.resolve();
@ -204,7 +204,7 @@ add_test(function test_can_link_account_message() {
channel_id: WEBCHANNEL_ID,
content_uri: URL_STRING,
helpers: {
shouldAllowRelink: function (email) {
shouldAllowRelink(email) {
do_check_eq(email, 'testuser@testuser.com');
run_next_test();
}
@ -224,7 +224,7 @@ add_test(function test_sync_preferences_message() {
channel_id: WEBCHANNEL_ID,
content_uri: URL_STRING,
helpers: {
openSyncPreferences: function (browser, entryPoint) {
openSyncPreferences(browser, entryPoint) {
do_check_eq(entryPoint, 'fxa:verification_complete');
do_check_eq(browser, mockSendingContext.browser);
run_next_test();
@ -279,7 +279,7 @@ add_test(function test_helpers_should_allow_relink_different_email() {
add_task(function* test_helpers_login_without_customize_sync() {
let helpers = new FxAccountsWebChannelHelpers({
fxAccounts: {
setSignedInUser: function(accountData) {
setSignedInUser(accountData) {
return new Promise(resolve => {
// ensure fxAccounts is informed of the new user being signed in.
do_check_eq(accountData.email, 'testuser@testuser.com');
@ -315,7 +315,7 @@ add_task(function* test_helpers_login_without_customize_sync() {
add_task(function* test_helpers_login_with_customize_sync() {
let helpers = new FxAccountsWebChannelHelpers({
fxAccounts: {
setSignedInUser: function(accountData) {
setSignedInUser(accountData) {
return new Promise(resolve => {
// ensure fxAccounts is informed of the new user being signed in.
do_check_eq(accountData.email, 'testuser@testuser.com');
@ -345,7 +345,7 @@ add_task(function* test_helpers_login_with_customize_sync() {
add_task(function* test_helpers_login_with_customize_sync_and_declined_engines() {
let helpers = new FxAccountsWebChannelHelpers({
fxAccounts: {
setSignedInUser: function(accountData) {
setSignedInUser(accountData) {
return new Promise(resolve => {
// ensure fxAccounts is informed of the new user being signed in.
do_check_eq(accountData.email, 'testuser@testuser.com');
@ -468,7 +468,7 @@ function run_test() {
}
function makeObserver(aObserveTopic, aObserveFunc) {
let callback = function (aSubject, aTopic, aData) {
let callback = function(aSubject, aTopic, aData) {
log.debug("observed " + aTopic + " " + aData);
if (aTopic == aObserveTopic) {
removeMe();

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

@ -71,7 +71,7 @@ WeaveService.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
Ci.nsISupportsWeakReference]),
ensureLoaded: function () {
ensureLoaded() {
// If we are loaded and not using FxA, load the migration module.
if (!this.fxAccountsEnabled) {
Cu.import("resource://services-sync/FxaMigrator.jsm");
@ -83,7 +83,7 @@ WeaveService.prototype = {
Weave.Service;
},
whenLoaded: function() {
whenLoaded() {
if (this.ready) {
return Promise.resolve();
}
@ -127,7 +127,7 @@ WeaveService.prototype = {
return prefs.prefHasUserValue("username");
},
observe: function (subject, topic, data) {
observe(subject, topic, data) {
switch (topic) {
case "app-startup":
let os = Cc["@mozilla.org/observer-service;1"].
@ -172,11 +172,11 @@ AboutWeaveLog.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule,
Ci.nsISupportsWeakReference]),
getURIFlags: function(aURI) {
getURIFlags(aURI) {
return 0;
},
newChannel: function(aURI, aLoadInfo) {
newChannel(aURI, aLoadInfo) {
let dir = FileUtils.getDir("ProfD", ["weave", "logs"], true);
let uri = Services.io.newFileURI(dir);
let channel = Services.io.newChannelFromURIWithLoadInfo(uri, aLoadInfo);

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

@ -84,7 +84,7 @@ this.FakeGUIDService = function FakeGUIDService() {
Utils.makeGUID = function makeGUID() {
// ensure that this always returns a unique 12 character string
let nextGUID = "fake-guid-" + String(latestGUID++).padStart(2, "0");
return nextGUID.slice(nextGUID.length-12, nextGUID.length);
return nextGUID.slice(nextGUID.length - 12, nextGUID.length);
};
}

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

@ -1,58 +1,58 @@
"use strict";
this.EXPORTED_SYMBOLS = [
"initializeIdentityWithTokenServerResponse",
];
var {utils: Cu} = Components;
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://services-sync/main.js");
Cu.import("resource://services-sync/browserid_identity.js");
Cu.import("resource://services-common/tokenserverclient.js");
Cu.import("resource://testing-common/services/common/logging.js");
Cu.import("resource://testing-common/services/sync/utils.js");
// Create a new browserid_identity object and initialize it with a
// mocked TokenServerClient which always receives the specified response.
this.initializeIdentityWithTokenServerResponse = function(response) {
// First create a mock "request" object that well' hack into the token server.
// A log for it
let requestLog = Log.repository.getLogger("testing.mock-rest");
if (!requestLog.appenders.length) { // might as well see what it says :)
requestLog.addAppender(new Log.DumpAppender());
requestLog.level = Log.Level.Trace;
}
// A mock request object.
function MockRESTRequest(url) {};
MockRESTRequest.prototype = {
_log: requestLog,
setHeader: function() {},
get: function(callback) {
this.response = response;
callback.call(this);
}
}
// The mocked TokenServer client which will get the response.
function MockTSC() { }
MockTSC.prototype = new TokenServerClient();
MockTSC.prototype.constructor = MockTSC;
MockTSC.prototype.newRESTRequest = function(url) {
return new MockRESTRequest(url);
}
// Arrange for the same observerPrefix as browserid_identity uses.
MockTSC.prototype.observerPrefix = "weave:service";
// tie it all together.
Weave.Status.__authManager = Weave.Service.identity = new BrowserIDManager();
Weave.Service._clusterManager = Weave.Service.identity.createClusterManager(Weave.Service);
let browseridManager = Weave.Service.identity;
// a sanity check
if (!(browseridManager instanceof BrowserIDManager)) {
throw new Error("sync isn't configured for browserid_identity");
}
let mockTSC = new MockTSC()
configureFxAccountIdentity(browseridManager);
browseridManager._tokenServerClient = mockTSC;
}
"use strict";
this.EXPORTED_SYMBOLS = [
"initializeIdentityWithTokenServerResponse",
];
var {utils: Cu} = Components;
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://services-sync/main.js");
Cu.import("resource://services-sync/browserid_identity.js");
Cu.import("resource://services-common/tokenserverclient.js");
Cu.import("resource://testing-common/services/common/logging.js");
Cu.import("resource://testing-common/services/sync/utils.js");
// Create a new browserid_identity object and initialize it with a
// mocked TokenServerClient which always receives the specified response.
this.initializeIdentityWithTokenServerResponse = function(response) {
// First create a mock "request" object that well' hack into the token server.
// A log for it
let requestLog = Log.repository.getLogger("testing.mock-rest");
if (!requestLog.appenders.length) { // might as well see what it says :)
requestLog.addAppender(new Log.DumpAppender());
requestLog.level = Log.Level.Trace;
}
// A mock request object.
function MockRESTRequest(url) {}
MockRESTRequest.prototype = {
_log: requestLog,
setHeader() {},
get(callback) {
this.response = response;
callback.call(this);
}
}
// The mocked TokenServer client which will get the response.
function MockTSC() { }
MockTSC.prototype = new TokenServerClient();
MockTSC.prototype.constructor = MockTSC;
MockTSC.prototype.newRESTRequest = function(url) {
return new MockRESTRequest(url);
}
// Arrange for the same observerPrefix as browserid_identity uses.
MockTSC.prototype.observerPrefix = "weave:service";
// tie it all together.
Weave.Status.__authManager = Weave.Service.identity = new BrowserIDManager();
Weave.Service._clusterManager = Weave.Service.identity.createClusterManager(Weave.Service);
let browseridManager = Weave.Service.identity;
// a sanity check
if (!(browseridManager instanceof BrowserIDManager)) {
throw new Error("sync isn't configured for browserid_identity");
}
let mockTSC = new MockTSC()
configureFxAccountIdentity(browseridManager);
browseridManager._tokenServerClient = mockTSC;
}

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

@ -238,7 +238,7 @@ this.configureFxAccountIdentity = function(authService,
fxa.internal._fxAccountsClient = mockFxAClient;
let mockTSC = { // TokenServerClient
getTokenFromBrowserIDAssertion: function(uri, assertion, cb) {
getTokenFromBrowserIDAssertion(uri, assertion, cb) {
config.fxaccount.token.uid = config.username;
cb(null, config.fxaccount.token);
},
@ -293,7 +293,7 @@ this.configureIdentity = async function(identityOverrides, server) {
setBasicCredentials(config.username, config.sync.password, config.sync.syncKey);
}
this.SyncTestingInfrastructure = async function (server, username, password) {
this.SyncTestingInfrastructure = async function(server, username, password) {
let ns = {};
Cu.import("resource://services-sync/service.js", ns);

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

@ -181,7 +181,7 @@ let SyncedTabsInternal = {
} catch (ex) {
log.error("Sync failed", ex);
reject(ex);
};
}
}, Ci.nsIThread.DISPATCH_NORMAL);
});
},

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

@ -252,8 +252,7 @@ AddonsReconciler.prototype = {
for (let [k, v] of Object.entries(record)) {
if (k == "modified") {
state.addons[id][k] = v.getTime();
}
else {
} else {
state.addons[id][k] = v;
}
}
@ -348,7 +347,7 @@ AddonsReconciler.prototype = {
let installs;
AddonManager.getAllAddons(function (addons) {
AddonManager.getAllAddons(function(addons) {
let ids = {};
for (let addon of addons) {
@ -427,9 +426,9 @@ AddonsReconciler.prototype = {
if (!(id in this._addons)) {
let record = {
id: id,
guid: guid,
enabled: enabled,
id,
guid,
enabled,
installed: true,
modified: now,
type: addon.type,
@ -634,8 +633,7 @@ AddonsReconciler.prototype = {
this.saveState(null, cb);
cb.wait();
}
}
catch (ex) {
} catch (ex) {
this._log.warn("Exception", ex);
}
},

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

@ -114,7 +114,7 @@ AddonUtilsInternal.prototype = {
}
if (options.syncGUID) {
log.info("Setting syncGUID of " + install.name +": " +
log.info("Setting syncGUID of " + install.name + ": " +
options.syncGUID);
install.addon.syncGUID = options.syncGUID;
}
@ -127,17 +127,17 @@ AddonUtilsInternal.prototype = {
install.addon.userDisabled = true;
}
},
onInstallEnded: function(install, addon) {
onInstallEnded(install, addon) {
install.removeListener(listener);
cb(null, {id: addon.id, install: install, addon: addon});
cb(null, {id: addon.id, install, addon});
},
onInstallFailed: function(install) {
onInstallFailed(install) {
install.removeListener(listener);
cb(new Error("Install failed: " + install.error), null);
},
onDownloadFailed: function(install) {
onDownloadFailed(install) {
install.removeListener(listener);
cb(new Error("Download failed: " + install.error), null);
@ -145,8 +145,7 @@ AddonUtilsInternal.prototype = {
};
install.addListener(listener);
install.install();
}
catch (ex) {
} catch (ex) {
this._log.error("Error installing add-on", ex);
cb(ex, null);
}
@ -164,7 +163,7 @@ AddonUtilsInternal.prototype = {
*/
uninstallAddon: function uninstallAddon(addon, cb) {
let listener = {
onUninstalling: function(uninstalling, needsRestart) {
onUninstalling(uninstalling, needsRestart) {
if (addon.id != uninstalling.id) {
return;
}
@ -180,7 +179,7 @@ AddonUtilsInternal.prototype = {
AddonManager.removeAddonListener(listener);
cb(null, addon);
},
onUninstalled: function(uninstalled) {
onUninstalled(uninstalled) {
if (addon.id != uninstalled.id) {
return;
}
@ -273,7 +272,7 @@ AddonUtilsInternal.prototype = {
cb(null, ourResult);
}
}
}.bind(this);
};
let toInstall = [];
@ -494,7 +493,7 @@ AddonUtilsInternal.prototype = {
if (!addon.appDisabled) {
cb(null, addon);
return;
}
// Else the listener will handle invoking the callback.
},

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

@ -337,12 +337,10 @@ class BookmarkValidator {
}
if (record.deleted) {
deletedItemIds.add(record.id);
} else {
if (idToRecord.has(record.id)) {
} else if (idToRecord.has(record.id)) {
problemData.duplicates.push(record.id);
continue;
}
}
idToRecord.set(record.id, record);
if (record.children) {
@ -768,7 +766,7 @@ class BookmarkValidator {
let serverRecordCount = serverState.length;
let result = self.compareServerWithClient(serverState, clientTree);
let end = Date.now();
let duration = end-start;
let duration = end - start;
return {
duration,
version: self.version,
@ -778,7 +776,7 @@ class BookmarkValidator {
});
}
};
}
BookmarkValidator.prototype.version = BOOKMARK_VALIDATOR_VERSION;

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

@ -52,7 +52,7 @@ const PREF_SYNC_SHOW_CUSTOMIZATION = "services.sync-setup.ui.showCustomizationDi
function deriveKeyBundle(kB) {
let out = CryptoUtils.hkdf(kB, undefined,
"identity.mozilla.com/picl/v1/oldsync", 2*32);
"identity.mozilla.com/picl/v1/oldsync", 2 * 32);
let bundle = new BulkKeyBundle();
// [encryptionKey, hmacKey]
bundle.keyPair = [out.slice(0, 32), out.slice(32, 64)];
@ -72,7 +72,7 @@ function AuthenticationError(details, source) {
}
AuthenticationError.prototype = {
toString: function() {
toString() {
return "AuthenticationError(" + this.details + ")";
}
}
@ -134,7 +134,7 @@ this.BrowserIDManager.prototype = {
return this._signedInUser && this._signedInUser.deviceId;
},
initialize: function() {
initialize() {
for (let topic of OBSERVER_TOPICS) {
Services.obs.addObserver(this, topic, false);
}
@ -157,7 +157,7 @@ this.BrowserIDManager.prototype = {
* Ensure the user is logged in. Returns a promise that resolves when
* the user is logged in, or is rejected if the login attempt has failed.
*/
ensureLoggedIn: function() {
ensureLoggedIn() {
if (!this._shouldHaveSyncKeyBundle && this.whenReadyToAuthenticate) {
// We are already in the process of logging in.
return this.whenReadyToAuthenticate.promise;
@ -181,7 +181,7 @@ this.BrowserIDManager.prototype = {
return this.whenReadyToAuthenticate.promise;
},
finalize: function() {
finalize() {
// After this is called, we can expect Service.identity != this.
for (let topic of OBSERVER_TOPICS) {
Services.obs.removeObserver(this, topic);
@ -190,7 +190,7 @@ this.BrowserIDManager.prototype = {
this._signedInUser = null;
},
offerSyncOptions: function () {
offerSyncOptions() {
// If the user chose to "Customize sync options" when signing
// up with Firefox Accounts, ask them to choose what to sync.
const url = "chrome://browser/content/sync/customize.xul";
@ -203,7 +203,7 @@ this.BrowserIDManager.prototype = {
return data;
},
initializeWithCurrentIdentity: function(isInitialSync=false) {
initializeWithCurrentIdentity(isInitialSync = false) {
// While this function returns a promise that resolves once we've started
// the auth process, that process is complete when
// this.whenReadyToAuthenticate.promise resolves.
@ -284,7 +284,7 @@ this.BrowserIDManager.prototype = {
});
},
_updateSignedInUser: function(userData) {
_updateSignedInUser(userData) {
// This object should only ever be used for a single user. It is an
// error to update the data if the user changes (but updates are still
// necessary, as each call may add more attributes to the user).
@ -295,7 +295,7 @@ this.BrowserIDManager.prototype = {
this._signedInUser = userData;
},
logout: function() {
logout() {
// This will be called when sync fails (or when the account is being
// unlinked etc). It may have failed because we got a 401 from a sync
// server, so we nuke the token. Next time sync runs and wants an
@ -304,7 +304,7 @@ this.BrowserIDManager.prototype = {
this._token = null;
},
observe: function (subject, topic, data) {
observe(subject, topic, data) {
this._log.debug("observed " + topic);
switch (topic) {
case fxAccountsCommon.ONLOGIN_NOTIFICATION:
@ -338,7 +338,7 @@ this.BrowserIDManager.prototype = {
/**
* Compute the sha256 of the message bytes. Return bytes.
*/
_sha256: function(message) {
_sha256(message) {
let hasher = Cc["@mozilla.org/security/hash;1"]
.createInstance(Ci.nsICryptoHash);
hasher.init(hasher.SHA256);
@ -350,14 +350,14 @@ this.BrowserIDManager.prototype = {
*
* Return string: hex(first16Bytes(sha256(kBbytes)))
*/
_computeXClientState: function(kBbytes) {
_computeXClientState(kBbytes) {
return CommonUtils.bytesAsHex(this._sha256(kBbytes).slice(0, 16), false);
},
/**
* Provide override point for testing token expiration.
*/
_now: function() {
_now() {
return this._fxaService.now()
},
@ -365,7 +365,7 @@ this.BrowserIDManager.prototype = {
return this._fxaService.localtimeOffsetMsec;
},
usernameFromAccount: function(val) {
usernameFromAccount(val) {
// we don't differentiate between "username" and "account"
return val;
},
@ -407,8 +407,7 @@ this.BrowserIDManager.prototype = {
// field directly and instead call a isSyncKeyValid() function
// that we can override.
return "99999999999999999999999999";
}
else {
} else {
return null;
}
},
@ -424,7 +423,7 @@ this.BrowserIDManager.prototype = {
/**
* Resets/Drops all credentials we hold for the current user.
*/
resetCredentials: function() {
resetCredentials() {
this.resetSyncKey();
this._token = null;
this._hashedUID = null;
@ -436,7 +435,7 @@ this.BrowserIDManager.prototype = {
/**
* Resets/Drops the sync key we hold for the current user.
*/
resetSyncKey: function() {
resetSyncKey() {
this._syncKey = null;
this._syncKeyBundle = null;
this._syncKeyUpdated = true;
@ -449,14 +448,14 @@ this.BrowserIDManager.prototype = {
* allows us to avoid a network request for when we actually need the
* migration info.
*/
prefetchMigrationSentinel: function(service) {
prefetchMigrationSentinel(service) {
// nothing to do here until we decide to migrate away from FxA.
},
/**
* Return credentials hosts for this identity only.
*/
_getSyncCredentialsHosts: function() {
_getSyncCredentialsHosts() {
return Utils.getSyncCredentialsHostsFxA();
},
@ -486,7 +485,7 @@ this.BrowserIDManager.prototype = {
// Do we currently have keys, or do we have enough that we should be able
// to successfully fetch them?
_canFetchKeys: function() {
_canFetchKeys() {
let userData = this._signedInUser;
// a keyFetchToken means we can almost certainly grab them.
// kA and kB means we already have them.
@ -499,7 +498,7 @@ this.BrowserIDManager.prototype = {
* Returns a promise that resolves with the current auth state after
* attempting to unlock.
*/
unlockAndVerifyAuthState: function() {
unlockAndVerifyAuthState() {
if (this._canFetchKeys()) {
log.debug("unlockAndVerifyAuthState already has (or can fetch) sync keys");
return Promise.resolve(STATUS_OK);
@ -534,13 +533,13 @@ this.BrowserIDManager.prototype = {
* Do we have a non-null, not yet expired token for the user currently
* signed in?
*/
hasValidToken: function() {
hasValidToken() {
// If pref is set to ignore cached authentication credentials for debugging,
// then return false to force the fetching of a new token.
let ignoreCachedAuthCredentials = false;
try {
ignoreCachedAuthCredentials = Svc.Prefs.get("debug.ignoreCachedAuthCredentials");
} catch(e) {
} catch (e) {
// Pref doesn't exist
}
if (ignoreCachedAuthCredentials) {
@ -573,7 +572,7 @@ this.BrowserIDManager.prototype = {
// Refresh the sync token for our user. Returns a promise that resolves
// with a token (which may be null in one sad edge-case), or rejects with an
// error.
_fetchTokenForUser: function() {
_fetchTokenForUser() {
// tokenServerURI is mis-named - convention is uri means nsISomething...
let tokenServerURI = this._tokenServerUrl;
let log = this._log;
@ -607,7 +606,7 @@ this.BrowserIDManager.prototype = {
let getToken = assertion => {
log.debug("Getting a token");
let deferred = Promise.defer();
let cb = function (err, token) {
let cb = function(err, token) {
if (err) {
return deferred.reject(err);
}
@ -694,7 +693,7 @@ this.BrowserIDManager.prototype = {
// Returns a promise that is resolved when we have a valid token for the
// current user stored in this._token. When resolved, this._token is valid.
_ensureValidToken: function() {
_ensureValidToken() {
if (this.hasValidToken()) {
this._log.debug("_ensureValidToken already has one");
return Promise.resolve();
@ -723,14 +722,14 @@ this.BrowserIDManager.prototype = {
);
},
getResourceAuthenticator: function () {
getResourceAuthenticator() {
return this._getAuthenticationHeader.bind(this);
},
/**
* Obtain a function to be used for adding auth to RESTRequest instances.
*/
getRESTRequestAuthenticator: function() {
getRESTRequestAuthenticator() {
return this._addAuthenticationHeader.bind(this);
},
@ -738,7 +737,7 @@ this.BrowserIDManager.prototype = {
* @return a Hawk HTTP Authorization Header, lightly wrapped, for the .uri
* of a RESTRequest or AsyncResponse object.
*/
_getAuthenticationHeader: function(httpObject, method) {
_getAuthenticationHeader(httpObject, method) {
let cb = Async.makeSpinningCallback();
this._ensureValidToken().then(cb, cb);
// Note that in failure states we return null, causing the request to be
@ -768,14 +767,14 @@ this.BrowserIDManager.prototype = {
let options = {
now: this._now(),
localtimeOffsetMsec: this._localtimeOffsetMsec,
credentials: credentials,
credentials,
};
let headerValue = CryptoUtils.computeHAWK(httpObject.uri, method, options);
return {headers: {authorization: headerValue.field}};
},
_addAuthenticationHeader: function(request, method) {
_addAuthenticationHeader(request, method) {
let header = this._getAuthenticationHeader(request, method);
if (!header) {
return null;
@ -784,7 +783,7 @@ this.BrowserIDManager.prototype = {
return request;
},
createClusterManager: function(service) {
createClusterManager(service) {
return new BrowserIDClusterManager(service);
},
@ -809,7 +808,7 @@ function BrowserIDClusterManager(service) {
BrowserIDClusterManager.prototype = {
__proto__: ClusterManager.prototype,
_findCluster: function() {
_findCluster() {
let endPointFromIdentityToken = function() {
// The only reason (in theory ;) that we can end up with a null token
// is when this.identity._canFetchKeys() returned false. In turn, this
@ -852,7 +851,7 @@ BrowserIDClusterManager.prototype = {
}.bind(this);
let cb = Async.makeSpinningCallback();
promiseClusterURL().then(function (clusterURL) {
promiseClusterURL().then(function(clusterURL) {
cb(null, clusterURL);
}).then(
null, err => {
@ -880,7 +879,7 @@ BrowserIDClusterManager.prototype = {
return cb.wait();
},
getUserBaseURL: function() {
getUserBaseURL() {
// Legacy Sync and FxA Sync construct the userBaseURL differently. Legacy
// Sync appends path components onto an empty path, and in FxA Sync the
// token server constructs this for us in an opaque manner. Since the

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

@ -163,7 +163,7 @@ class CollectionValidator {
if (combined) {
combined.client = record;
} else {
allRecords.set(id, { client: record, server: null });
allRecords.set(id, { client: record, server: null });
}
}

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

@ -105,7 +105,7 @@ Tracker.prototype = {
},
// Should be called by service everytime a sync has been done for an engine
resetScore: function () {
resetScore() {
this._score = 0;
},
@ -123,12 +123,12 @@ Tracker.prototype = {
// being processed, or that shouldn't be synced.
// But note: not persisted to disk
ignoreID: function (id) {
ignoreID(id) {
this.unignoreID(id);
this._ignored.push(id);
},
unignoreID: function (id) {
unignoreID(id) {
let index = this._ignored.indexOf(id);
if (index != -1)
this._ignored.splice(index, 1);
@ -140,7 +140,7 @@ Tracker.prototype = {
this._saveChangedIDs();
},
addChangedID: function (id, when) {
addChangedID(id, when) {
if (!id) {
this._log.warn("Attempted to add undefined ID to tracker");
return false;
@ -163,7 +163,7 @@ Tracker.prototype = {
return true;
},
removeChangedID: function (...ids) {
removeChangedID(...ids) {
if (!ids.length || this.ignoreAll) {
return false;
}
@ -185,7 +185,7 @@ Tracker.prototype = {
return true;
},
clearChangedIDs: function () {
clearChangedIDs() {
this._log.trace("Clearing changed ID list");
this._storage.data = {};
this._saveChangedIDs();
@ -198,13 +198,13 @@ Tracker.prototype = {
_isTracking: false,
// Override these in your subclasses.
startTracking: function () {
startTracking() {
},
stopTracking: function () {
stopTracking() {
},
engineIsEnabled: function () {
engineIsEnabled() {
if (!this.engine) {
// Can't tell -- we must be running in a test!
return true;
@ -212,7 +212,7 @@ Tracker.prototype = {
return this.engine.enabled;
},
onEngineEnabledChanged: function (engineEnabled) {
onEngineEnabledChanged(engineEnabled) {
if (engineEnabled == this._isTracking) {
return;
}
@ -227,7 +227,7 @@ Tracker.prototype = {
}
},
observe: function (subject, topic, data) {
observe(subject, topic, data) {
switch (topic) {
case "weave:engine:start-tracking":
if (!this.engineIsEnabled()) {
@ -250,7 +250,7 @@ Tracker.prototype = {
if (data == PREFS_BRANCH + "engine." + this.engine.prefName) {
this.onEngineEnabledChanged(this.engine.enabled);
}
return;
}
}
};
@ -317,7 +317,7 @@ Store.prototype = {
* @param records Array of records to apply
* @return Array of record IDs which did not apply cleanly
*/
applyIncomingBatch: function (records) {
applyIncomingBatch(records) {
let failed = [];
for (let record of records) {
try {
@ -336,7 +336,7 @@ Store.prototype = {
this.engine._noteApplyFailure();
failed.push(record.id);
}
};
}
return failed;
},
@ -353,7 +353,7 @@ Store.prototype = {
* @param record
* Record to apply
*/
applyIncoming: function (record) {
applyIncoming(record) {
if (record.deleted)
this.remove(record);
else if (!this.itemExists(record.id))
@ -373,7 +373,7 @@ Store.prototype = {
* @param record
* The store record to create an item from
*/
create: function (record) {
create(record) {
throw "override create in a subclass";
},
@ -386,7 +386,7 @@ Store.prototype = {
* @param record
* The store record to delete an item from
*/
remove: function (record) {
remove(record) {
throw "override remove in a subclass";
},
@ -399,7 +399,7 @@ Store.prototype = {
* @param record
* The record to use to update an item from
*/
update: function (record) {
update(record) {
throw "override update in a subclass";
},
@ -413,7 +413,7 @@ Store.prototype = {
* string record ID
* @return boolean indicating whether record exists locally
*/
itemExists: function (id) {
itemExists(id) {
throw "override itemExists in a subclass";
},
@ -431,7 +431,7 @@ Store.prototype = {
* constructor for the newly-created record.
* @return record type for this engine
*/
createRecord: function (id, collection) {
createRecord(id, collection) {
throw "override createRecord in a subclass";
},
@ -443,7 +443,7 @@ Store.prototype = {
* @param newID
* string new record ID
*/
changeItemID: function (oldID, newID) {
changeItemID(oldID, newID) {
throw "override changeItemID in a subclass";
},
@ -453,7 +453,7 @@ Store.prototype = {
* @return Object with ID strings as keys and values of true. The values
* are ignored.
*/
getAllIDs: function () {
getAllIDs() {
throw "override getAllIDs in a subclass";
},
@ -467,7 +467,7 @@ Store.prototype = {
* can be thought of as clearing out all state and restoring the "new
* browser" state.
*/
wipe: function () {
wipe() {
throw "override wipe in a subclass";
}
};
@ -483,7 +483,7 @@ this.EngineManager = function EngineManager(service) {
this._log.level = Log.Level[Svc.Prefs.get("log.logger.service.engines", "Debug")];
}
EngineManager.prototype = {
get: function (name) {
get(name) {
// Return an array of engines if we have an array of names
if (Array.isArray(name)) {
let engines = [];
@ -506,7 +506,7 @@ EngineManager.prototype = {
return engine;
},
getAll: function () {
getAll() {
let engines = [];
for (let [, engine] of Object.entries(this._engines)) {
engines.push(engine);
@ -517,7 +517,7 @@ EngineManager.prototype = {
/**
* N.B., does not pay attention to the declined list.
*/
getEnabled: function () {
getEnabled() {
return this.getAll()
.filter((engine) => engine.enabled)
.sort((a, b) => a.syncPriority - b.syncPriority);
@ -527,37 +527,37 @@ EngineManager.prototype = {
return this.getEnabled().map(e => e.name);
},
persistDeclined: function () {
persistDeclined() {
Svc.Prefs.set("declinedEngines", [...this._declined].join(","));
},
/**
* Returns an array.
*/
getDeclined: function () {
getDeclined() {
return [...this._declined];
},
setDeclined: function (engines) {
setDeclined(engines) {
this._declined = new Set(engines);
this.persistDeclined();
},
isDeclined: function (engineName) {
isDeclined(engineName) {
return this._declined.has(engineName);
},
/**
* Accepts a Set or an array.
*/
decline: function (engines) {
decline(engines) {
for (let e of engines) {
this._declined.add(e);
}
this.persistDeclined();
},
undecline: function (engines) {
undecline(engines) {
for (let e of engines) {
this._declined.delete(e);
}
@ -569,7 +569,7 @@ EngineManager.prototype = {
*
* This is useful after initial customization during setup.
*/
declineDisabled: function () {
declineDisabled() {
for (let e of this.getAll()) {
if (!e.enabled) {
this._log.debug("Declining disabled engine " + e.name);
@ -587,7 +587,7 @@ EngineManager.prototype = {
* Engine object used to get an instance of the engine
* @return The engine object if anything failed
*/
register: function (engineObject) {
register(engineObject) {
if (Array.isArray(engineObject)) {
return engineObject.map(this.register, this);
}
@ -610,7 +610,7 @@ EngineManager.prototype = {
}
},
unregister: function (val) {
unregister(val) {
let name = val;
if (val instanceof Engine) {
name = val.name;
@ -618,7 +618,7 @@ EngineManager.prototype = {
delete this._engines[name];
},
clear: function () {
clear() {
for (let name in this._engines) {
delete this._engines[name];
}
@ -685,7 +685,7 @@ Engine.prototype = {
return tracker;
},
sync: function () {
sync() {
if (!this.enabled) {
return;
}
@ -700,7 +700,7 @@ Engine.prototype = {
/**
* Get rid of any local meta-data.
*/
resetClient: function () {
resetClient() {
if (!this._resetClient) {
throw "engine does not implement _resetClient method";
}
@ -708,7 +708,7 @@ Engine.prototype = {
this._notify("reset-client", this.name, this._resetClient)();
},
_wipeClient: function () {
_wipeClient() {
this.resetClient();
this._log.debug("Deleting all local data");
this._tracker.ignoreAll = true;
@ -717,7 +717,7 @@ Engine.prototype = {
this._tracker.clearChangedIDs();
},
wipeClient: function () {
wipeClient() {
this._notify("wipe-client", this.name, this._wipeClient)();
},
@ -726,7 +726,7 @@ Engine.prototype = {
* must have a `validate(engine)` method that returns a promise to an object
* with a getSummary method). Otherwise return null.
*/
getValidator: function () {
getValidator() {
return null;
}
};
@ -810,7 +810,7 @@ SyncEngine.prototype = {
// Store the value as a string to keep floating point precision
Svc.Prefs.set(this.name + ".lastSync", value.toString());
},
resetLastSync: function () {
resetLastSync() {
this._log.debug("Resetting " + this.name + " last sync time");
Svc.Prefs.reset(this.name + ".lastSync");
Svc.Prefs.set(this.name + ".lastSync", "0");
@ -831,12 +831,12 @@ SyncEngine.prototype = {
return;
}
this._toFetch = val;
Utils.namedTimer(function () {
Utils.namedTimer(function() {
Utils.jsonSave("toFetch/" + this.name, this, val, cb);
}, 0, this, "_toFetchDelay");
},
loadToFetch: function () {
loadToFetch() {
// Initialize to empty if there's no file.
this._toFetch = [];
Utils.jsonLoad("toFetch/" + this.name, this, function(toFetch) {
@ -862,12 +862,12 @@ SyncEngine.prototype = {
return;
}
this._previousFailed = val;
Utils.namedTimer(function () {
Utils.namedTimer(function() {
Utils.jsonSave("failed/" + this.name, this, val, cb);
}, 0, this, "_previousFailedDelay");
},
loadPreviousFailed: function () {
loadPreviousFailed() {
// Initialize to empty if there's no file
this._previousFailed = [];
Utils.jsonLoad("failed/" + this.name, this, function(previousFailed) {
@ -892,12 +892,12 @@ SyncEngine.prototype = {
* Returns a changeset for this sync. Engine implementations can override this
* method to bypass the tracker for certain or all changed items.
*/
getChangedIDs: function () {
getChangedIDs() {
return this._tracker.changedIDs;
},
// Create a new record using the store and add in crypto fields.
_createRecord: function (id) {
_createRecord(id) {
let record = this._store.createRecord(id, this.name);
record.id = id;
record.collection = this.name;
@ -905,7 +905,7 @@ SyncEngine.prototype = {
},
// Any setup that needs to happen at the beginning of each sync.
_syncStartup: function () {
_syncStartup() {
// Determine if we need to wipe on outdated versions
let metaGlobal = this.service.recordManager.get(this.metaURL);
@ -942,7 +942,7 @@ SyncEngine.prototype = {
this._log.debug("Engine syncIDs: " + [engineData.syncID, this.syncID]);
this.syncID = engineData.syncID;
this._resetClient();
};
}
// Delete any existing data and reupload on bad version or missing meta.
// No crypto component here...? We could regenerate per-collection keys...
@ -978,7 +978,7 @@ SyncEngine.prototype = {
* A tiny abstraction to make it easier to test incoming record
* application.
*/
itemSource: function () {
itemSource() {
return new Collection(this.engineURL, this._recordObj, this.service);
},
@ -987,7 +987,7 @@ SyncEngine.prototype = {
* In the most awful and untestable way possible.
* This now accepts something that makes testing vaguely less impossible.
*/
_processIncoming: function (newitems) {
_processIncoming(newitems) {
this._log.trace("Downloading & applying server changes");
// Figure out how many total items to fetch this sync; do less on mobile.
@ -1281,11 +1281,11 @@ SyncEngine.prototype = {
return false;
},
_noteApplyFailure: function () {
_noteApplyFailure() {
// here would be a good place to record telemetry...
},
_noteApplyNewFailure: function () {
_noteApplyNewFailure() {
// here would be a good place to record telemetry...
},
@ -1295,7 +1295,7 @@ SyncEngine.prototype = {
*
* @return GUID of the similar item; falsy otherwise
*/
_findDupe: function (item) {
_findDupe(item) {
// By default, assume there's no dupe items for the engine
},
@ -1309,7 +1309,7 @@ SyncEngine.prototype = {
return true;
},
_deleteId: function (id) {
_deleteId(id) {
this._tracker.removeChangedID(id);
this._noteDeletedId(id);
},
@ -1344,7 +1344,7 @@ SyncEngine.prototype = {
* @return boolean
* Truthy if incoming record should be applied. False if not.
*/
_reconcile: function (item) {
_reconcile(item) {
if (this._log.level <= Log.Level.Trace) {
this._log.trace("Incoming: " + item);
}
@ -1512,7 +1512,7 @@ SyncEngine.prototype = {
},
// Upload outgoing records.
_uploadOutgoing: function () {
_uploadOutgoing() {
this._log.trace("Uploading local changes to server.");
let modifiedIDs = this._modified.ids();
@ -1612,7 +1612,7 @@ SyncEngine.prototype = {
// Any cleanup necessary.
// Save the current snapshot so as to calculate changes at next sync
_syncFinish: function () {
_syncFinish() {
this._log.trace("Finishing up sync");
this._tracker.resetScore();
@ -1639,7 +1639,7 @@ SyncEngine.prototype = {
}
},
_syncCleanup: function () {
_syncCleanup() {
if (!this._modified) {
return;
}
@ -1652,7 +1652,7 @@ SyncEngine.prototype = {
}
},
_sync: function () {
_sync() {
try {
this._syncStartup();
Observers.notify("weave:engine:sync:status", "process-incoming");
@ -1665,7 +1665,7 @@ SyncEngine.prototype = {
}
},
canDecrypt: function () {
canDecrypt() {
// Report failure even if there's nothing to decrypt
let canDecrypt = false;
@ -1679,7 +1679,7 @@ SyncEngine.prototype = {
test.recordHandler = function recordHandler(record) {
record.decrypt(key);
canDecrypt = true;
}.bind(this);
};
// Any failure fetching/decrypting will just result in false
try {
@ -1695,13 +1695,13 @@ SyncEngine.prototype = {
return canDecrypt;
},
_resetClient: function () {
_resetClient() {
this.resetLastSync();
this.previousFailed = [];
this.toFetch = [];
},
wipeServer: function () {
wipeServer() {
let response = this.service.resource(this.engineURL).delete();
if (response.status != 200 && response.status != 404) {
throw response;
@ -1709,7 +1709,7 @@ SyncEngine.prototype = {
this._resetClient();
},
removeClientData: function () {
removeClientData() {
// Implement this method in engines that store client specific data
// on the server.
},
@ -1730,7 +1730,7 @@ SyncEngine.prototype = {
*
* All return values will be part of the kRecoveryStrategy enumeration.
*/
handleHMACMismatch: function (item, mayRetry) {
handleHMACMismatch(item, mayRetry) {
// By default we either try again, or bail out noisily.
return (this.service.handleHMACEvent() && mayRetry) ?
SyncEngine.kRecoveryStrategy.retry :

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

@ -503,7 +503,7 @@ AddonsStore.prototype = {
}
},
/***************************************************************************
/** *************************************************************************
* Functions below are unique to this store and not part of the Store API *
***************************************************************************/
@ -732,7 +732,7 @@ AddonsTracker.prototype = {
this.score += SCORE_INCREMENT_XLARGE;
},
startTracking: function() {
startTracking() {
if (this.engine.enabled) {
this.reconciler.startListening();
}
@ -740,7 +740,7 @@ AddonsTracker.prototype = {
this.reconciler.addChangeListener(this);
},
stopTracking: function() {
stopTracking() {
this.reconciler.removeChangeListener(this);
this.reconciler.stopListening();
},

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

@ -312,7 +312,7 @@ BookmarksEngine.prototype = {
let guidMap = {};
let tree = Async.promiseSpinningly(PlacesUtils.promiseBookmarksTree(""));
function* walkBookmarksTree(tree, parent=null) {
function* walkBookmarksTree(tree, parent = null) {
if (tree) {
// Skip root node
if (parent) {
@ -362,7 +362,7 @@ BookmarksEngine.prototype = {
key = "s" + node.index;
break;
default:
this._log.error("Unknown place type: '"+placeType+"'");
this._log.error("Unknown place type: '" + placeType + "'");
continue;
}
@ -522,7 +522,7 @@ BookmarksEngine.prototype = {
return false;
},
_processIncoming: function (newitems) {
_processIncoming(newitems) {
try {
SyncEngine.prototype._processIncoming.call(this, newitems);
} finally {
@ -785,7 +785,7 @@ BookmarksStore.prototype = {
},
_stmts: {},
_getStmt: function(query) {
_getStmt(query) {
if (query in this._stmts) {
return this._stmts[query];
}
@ -866,7 +866,7 @@ function BookmarksTracker(name, engine) {
BookmarksTracker.prototype = {
__proto__: Tracker.prototype,
//`_ignore` checks the change source for each observer notification, so we
// `_ignore` checks the change source for each observer notification, so we
// don't want to let the engine ignore all changes during a sync.
get ignoreAll() {
return false;
@ -880,14 +880,14 @@ BookmarksTracker.prototype = {
// in Places.
persistChangedIDs: false,
startTracking: function() {
startTracking() {
PlacesUtils.bookmarks.addObserver(this, true);
Svc.Obs.add("bookmarks-restore-begin", this);
Svc.Obs.add("bookmarks-restore-success", this);
Svc.Obs.add("bookmarks-restore-failed", this);
},
stopTracking: function() {
stopTracking() {
PlacesUtils.bookmarks.removeObserver(this);
Svc.Obs.remove("bookmarks-restore-begin", this);
Svc.Obs.remove("bookmarks-restore-success", this);
@ -1018,7 +1018,7 @@ BookmarksTracker.prototype = {
this._upScore();
},
onItemRemoved: function (itemId, parentId, index, type, uri,
onItemRemoved(itemId, parentId, index, type, uri,
guid, parentGuid, source) {
if (IGNORED_SOURCES.includes(source)) {
return;
@ -1095,7 +1095,7 @@ BookmarksTracker.prototype = {
return;
this._log.trace("onItemChanged: " + itemId +
(", " + property + (isAnno? " (anno)" : "")) +
(", " + property + (isAnno ? " (anno)" : "")) +
(value ? (" = \"" + value + "\"") : ""));
this._upScore();
},
@ -1112,16 +1112,16 @@ BookmarksTracker.prototype = {
this._upScore();
},
onBeginUpdateBatch: function () {
onBeginUpdateBatch() {
++this._batchDepth;
},
onEndUpdateBatch: function () {
onEndUpdateBatch() {
if (--this._batchDepth === 0 && this._batchSawScoreIncrement) {
this.score += SCORE_INCREMENT_XLARGE;
this._batchSawScoreIncrement = false;
}
},
onItemVisited: function () {}
onItemVisited() {}
};
class BookmarksChangeset extends Changeset {

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

@ -490,8 +490,8 @@ ClientEngine.prototype = {
}
let action = {
command: command,
args: args,
command,
args,
flowID: flowID || Utils.makeGUID(), // used for telemetry.
};
@ -705,7 +705,7 @@ ClientStore.prototype = {
fxAccounts.getDeviceId().then(id => cb(null, id), cb);
try {
record.fxaDeviceId = cb.wait();
} catch(error) {
} catch (error) {
this._log.warn("failed to get fxa device id", error);
}
record.name = this.engine.localName;

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

@ -43,7 +43,7 @@ ExtensionStorageEngine.prototype = {
syncPriority: 10,
allowSkippedRecord: false,
_sync: function () {
_sync() {
return Async.promiseSpinningly(ExtensionStorageSync.syncAll());
},
@ -68,15 +68,15 @@ function ExtensionStorageTracker(name, engine) {
ExtensionStorageTracker.prototype = {
__proto__: Tracker.prototype,
startTracking: function () {
startTracking() {
Svc.Obs.add("ext.storage.sync-changed", this);
},
stopTracking: function () {
stopTracking() {
Svc.Obs.remove("ext.storage.sync-changed", this);
},
observe: function (subject, topic, data) {
observe(subject, topic, data) {
Tracker.prototype.observe.call(this, subject, topic, data);
if (this.ignoreAll) {
@ -94,15 +94,15 @@ ExtensionStorageTracker.prototype = {
// Override a bunch of methods which don't do anything for us.
// This is a performance hack.
ignoreID: function() {
ignoreID() {
},
unignoreID: function() {
unignoreID() {
},
addChangedID: function() {
addChangedID() {
},
removeChangedID: function() {
removeChangedID() {
},
clearChangedIDs: function() {
clearChangedIDs() {
},
};
@ -221,7 +221,7 @@ class KeyRingEncryptionRemoteTransformer extends EncryptionRemoteTransformer {
let kB = Utils.hexToBytes(user.kB);
let keyMaterial = CryptoUtils.hkdf(kB, undefined,
"identity.mozilla.com/picl/v1/chrome.storage.sync", 2*32);
"identity.mozilla.com/picl/v1/chrome.storage.sync", 2 * 32);
let bundle = new BulkKeyBundle();
// [encryptionKey, hmacKey]
bundle.keyPair = [keyMaterial.slice(0, 32), keyMaterial.slice(32, 64)];

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

@ -37,7 +37,7 @@ var FormWrapper = {
_getEntryCols: ["fieldname", "value"],
_guidCols: ["guid"],
_promiseSearch: function(terms, searchData) {
_promiseSearch(terms, searchData) {
return new Promise(resolve => {
let results = [];
let callbacks = {
@ -53,17 +53,17 @@ var FormWrapper = {
},
// Do a "sync" search by spinning the event loop until it completes.
_searchSpinningly: function(terms, searchData) {
_searchSpinningly(terms, searchData) {
return Async.promiseSpinningly(this._promiseSearch(terms, searchData));
},
_updateSpinningly: function(changes) {
_updateSpinningly(changes) {
if (!Svc.FormHistory.enabled) {
return; // update isn't going to do anything.
}
let cb = Async.makeSpinningCallback();
let callbacks = {
handleCompletion: function(reason) {
handleCompletion(reason) {
cb();
}
};
@ -71,27 +71,27 @@ var FormWrapper = {
return cb.wait();
},
getEntry: function (guid) {
let results = this._searchSpinningly(this._getEntryCols, {guid: guid});
getEntry(guid) {
let results = this._searchSpinningly(this._getEntryCols, {guid});
if (!results.length) {
return null;
}
return {name: results[0].fieldname, value: results[0].value};
},
getGUID: function (name, value) {
getGUID(name, value) {
// Query for the provided entry.
let query = { fieldname: name, value: value };
let query = { fieldname: name, value };
let results = this._searchSpinningly(this._guidCols, query);
return results.length ? results[0].guid : null;
},
hasGUID: function (guid) {
hasGUID(guid) {
// We could probably use a count function here, but searchSpinningly exists...
return this._searchSpinningly(this._guidCols, {guid: guid}).length != 0;
return this._searchSpinningly(this._guidCols, {guid}).length != 0;
},
replaceGUID: function (oldGUID, newGUID) {
replaceGUID(oldGUID, newGUID) {
let changes = {
op: "update",
guid: oldGUID,
@ -129,7 +129,7 @@ function FormStore(name, engine) {
FormStore.prototype = {
__proto__: Store.prototype,
_processChange: function (change) {
_processChange(change) {
// If this._changes is defined, then we are applying a batch, so we
// can defer it.
if (this._changes) {
@ -141,7 +141,7 @@ FormStore.prototype = {
FormWrapper._updateSpinningly(change);
},
applyIncomingBatch: function (records) {
applyIncomingBatch(records) {
// We collect all the changes to be made then apply them all at once.
this._changes = [];
let failures = Store.prototype.applyIncomingBatch.call(this, records);
@ -152,7 +152,7 @@ FormStore.prototype = {
return failures;
},
getAllIDs: function () {
getAllIDs() {
let results = FormWrapper._searchSpinningly(["guid"], [])
let guids = {};
for (let result of results) {
@ -161,15 +161,15 @@ FormStore.prototype = {
return guids;
},
changeItemID: function (oldID, newID) {
changeItemID(oldID, newID) {
FormWrapper.replaceGUID(oldID, newID);
},
itemExists: function (id) {
itemExists(id) {
return FormWrapper.hasGUID(id);
},
createRecord: function (id, collection) {
createRecord(id, collection) {
let record = new FormRec(collection, id);
let entry = FormWrapper.getEntry(id);
if (entry != null) {
@ -181,7 +181,7 @@ FormStore.prototype = {
return record;
},
create: function (record) {
create(record) {
this._log.trace("Adding form record for " + record.name);
let change = {
op: "add",
@ -191,7 +191,7 @@ FormStore.prototype = {
this._processChange(change);
},
remove: function (record) {
remove(record) {
this._log.trace("Removing form record: " + record.id);
let change = {
op: "remove",
@ -200,11 +200,11 @@ FormStore.prototype = {
this._processChange(change);
},
update: function (record) {
update(record) {
this._log.trace("Ignoring form record update request!");
},
wipe: function () {
wipe() {
let change = {
op: "remove"
};
@ -222,15 +222,15 @@ FormTracker.prototype = {
Ci.nsIObserver,
Ci.nsISupportsWeakReference]),
startTracking: function() {
startTracking() {
Svc.Obs.add("satchel-storage-changed", this);
},
stopTracking: function() {
stopTracking() {
Svc.Obs.remove("satchel-storage-changed", this);
},
observe: function (subject, topic, data) {
observe(subject, topic, data) {
Tracker.prototype.observe.call(this, subject, topic, data);
if (this.ignoreAll) {
return;
@ -245,7 +245,7 @@ FormTracker.prototype = {
}
},
trackEntry: function (guid) {
trackEntry(guid) {
this.addChangedID(guid);
this.score += SCORE_INCREMENT_MEDIUM;
},
@ -302,4 +302,4 @@ class FormValidator extends CollectionValidator {
return res;
}
}
}

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

@ -45,7 +45,7 @@ HistoryEngine.prototype = {
syncPriority: 7,
_processIncoming: function (newitems) {
_processIncoming(newitems) {
// We want to notify history observers that a batch operation is underway
// so they don't do lots of work for each incoming record.
let observers = PlacesUtils.history.getObservers();
@ -134,7 +134,7 @@ HistoryStore.prototype = {
},
_stmts: {},
_getStmt: function(query) {
_getStmt(query) {
if (query in this._stmts) {
return this._stmts[query];
}
@ -292,7 +292,7 @@ HistoryStore.prototype = {
return failed;
}
let updatePlacesCallback = {
let updatePlacesCallback = {
handleResult: function handleResult() {},
handleError: function handleError(resultCode, placeInfo) {
failed.push(placeInfo.guid);
@ -306,7 +306,7 @@ HistoryStore.prototype = {
/**
* Converts a Sync history record to a mozIPlaceInfo.
*
*
* Throws if an invalid record is encountered (invalid URI, etc.),
* returns true if the record is to be applied, false otherwise
* (no visits to add, etc.),
@ -420,7 +420,7 @@ HistoryStore.prototype = {
wipe: function HistStore_wipe() {
let cb = Async.makeSyncCallback();
PlacesUtils.history.clear().then(result => {cb(null, result)}, err => {cb(err)});
PlacesUtils.history.clear().then(result => { cb(null, result) }, err => { cb(err) });
return Async.waitForSyncCallback(cb);
}
};
@ -431,12 +431,12 @@ function HistoryTracker(name, engine) {
HistoryTracker.prototype = {
__proto__: Tracker.prototype,
startTracking: function() {
startTracking() {
this._log.info("Adding Places observer.");
PlacesUtils.history.addObserver(this, true);
},
stopTracking: function() {
stopTracking() {
this._log.info("Removing Places observer.");
PlacesUtils.history.removeObserver(this);
},
@ -446,7 +446,7 @@ HistoryTracker.prototype = {
Ci.nsISupportsWeakReference
]),
onDeleteAffectsGUID: function (uri, guid, reason, source, increment) {
onDeleteAffectsGUID(uri, guid, reason, source, increment) {
if (this.ignoreAll || reason == Ci.nsINavHistoryObserver.REASON_EXPIRED) {
return;
}
@ -456,15 +456,15 @@ HistoryTracker.prototype = {
}
},
onDeleteVisits: function (uri, visitTime, guid, reason) {
onDeleteVisits(uri, visitTime, guid, reason) {
this.onDeleteAffectsGUID(uri, guid, reason, "onDeleteVisits", SCORE_INCREMENT_SMALL);
},
onDeleteURI: function (uri, guid, reason) {
onDeleteURI(uri, guid, reason) {
this.onDeleteAffectsGUID(uri, guid, reason, "onDeleteURI", SCORE_INCREMENT_XLARGE);
},
onVisit: function (uri, vid, time, session, referrer, trans, guid) {
onVisit(uri, vid, time, session, referrer, trans, guid) {
if (this.ignoreAll) {
this._log.trace("ignoreAll: ignoring visit for " + guid);
return;
@ -476,7 +476,7 @@ HistoryTracker.prototype = {
}
},
onClearHistory: function () {
onClearHistory() {
this._log.trace("onClearHistory");
// Note that we're going to trigger a sync, but none of the cleared
// pages are tracked, so the deletions will not be propagated.
@ -484,9 +484,9 @@ HistoryTracker.prototype = {
this.score += SCORE_INCREMENT_XLARGE;
},
onBeginUpdateBatch: function () {},
onEndUpdateBatch: function () {},
onPageChanged: function () {},
onTitleChanged: function () {},
onBeforeDeleteURI: function () {},
onBeginUpdateBatch() {},
onEndUpdateBatch() {},
onPageChanged() {},
onTitleChanged() {},
onBeforeDeleteURI() {},
};

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

@ -41,7 +41,7 @@ PasswordEngine.prototype = {
syncPriority: 2,
_syncFinish: function () {
_syncFinish() {
SyncEngine.prototype._syncFinish.call(this);
// Delete the Weave credentials from the server once.
@ -78,7 +78,7 @@ PasswordEngine.prototype = {
}
},
_findDupe: function (item) {
_findDupe(item) {
let login = this._store._nsLoginInfoFromRecord(item);
if (!login) {
return;
@ -104,14 +104,14 @@ function PasswordStore(name, engine) {
PasswordStore.prototype = {
__proto__: Store.prototype,
_newPropertyBag: function () {
_newPropertyBag() {
return Cc["@mozilla.org/hash-property-bag;1"].createInstance(Ci.nsIWritablePropertyBag2);
},
/**
* Return an instance of nsILoginInfo (and, implicitly, nsILoginMetaInfo).
*/
_nsLoginInfoFromRecord: function (record) {
_nsLoginInfoFromRecord(record) {
function nullUndefined(x) {
return (x == undefined) ? null : x;
}
@ -144,7 +144,7 @@ PasswordStore.prototype = {
return info;
},
_getLoginFromGUID: function (id) {
_getLoginFromGUID(id) {
let prop = this._newPropertyBag();
prop.setPropertyAsAUTF8String("guid", id);
@ -160,7 +160,7 @@ PasswordStore.prototype = {
return null;
},
getAllIDs: function () {
getAllIDs() {
let items = {};
let logins = Services.logins.getAllLogins({});
@ -177,7 +177,7 @@ PasswordStore.prototype = {
return items;
},
changeItemID: function (oldID, newID) {
changeItemID(oldID, newID) {
this._log.trace("Changing item ID: " + oldID + " to " + newID);
let oldLogin = this._getLoginFromGUID(oldID);
@ -196,11 +196,11 @@ PasswordStore.prototype = {
Services.logins.modifyLogin(oldLogin, prop);
},
itemExists: function (id) {
itemExists(id) {
return !!this._getLoginFromGUID(id);
},
createRecord: function (id, collection) {
createRecord(id, collection) {
let record = new LoginRec(collection, id);
let login = this._getLoginFromGUID(id);
@ -225,7 +225,7 @@ PasswordStore.prototype = {
return record;
},
create: function (record) {
create(record) {
let login = this._nsLoginInfoFromRecord(record);
if (!login) {
return;
@ -236,12 +236,12 @@ PasswordStore.prototype = {
"formSubmitURL: " + JSON.stringify(login.formSubmitURL));
try {
Services.logins.addLogin(login);
} catch(ex) {
} catch (ex) {
this._log.debug(`Adding record ${record.id} resulted in exception`, ex);
}
},
remove: function (record) {
remove(record) {
this._log.trace("Removing login " + record.id);
let loginItem = this._getLoginFromGUID(record.id);
@ -253,7 +253,7 @@ PasswordStore.prototype = {
Services.logins.removeLogin(loginItem);
},
update: function (record) {
update(record) {
let loginItem = this._getLoginFromGUID(record.id);
if (!loginItem) {
this._log.debug("Skipping update for unknown item: " + record.hostname);
@ -268,12 +268,12 @@ PasswordStore.prototype = {
try {
Services.logins.modifyLogin(loginItem, newinfo);
} catch(ex) {
} catch (ex) {
this._log.debug(`Modifying record ${record.id} resulted in exception; not modifying`, ex);
}
},
wipe: function () {
wipe() {
Services.logins.removeAllLogins();
},
};
@ -286,15 +286,15 @@ function PasswordTracker(name, engine) {
PasswordTracker.prototype = {
__proto__: Tracker.prototype,
startTracking: function () {
startTracking() {
Svc.Obs.add("passwordmgr-storage-changed", this);
},
stopTracking: function () {
stopTracking() {
Svc.Obs.remove("passwordmgr-storage-changed", this);
},
observe: function (subject, topic, data) {
observe(subject, topic, data) {
Tracker.prototype.observe.call(this, subject, topic, data);
if (this.ignoreAll) {

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

@ -44,7 +44,7 @@ PrefsEngine.prototype = {
syncPriority: 1,
allowSkippedRecord: false,
getChangedIDs: function () {
getChangedIDs() {
// No need for a proper timestamp (no conflict resolution needed).
let changedIDs = {};
if (this._tracker.modified)
@ -52,12 +52,12 @@ PrefsEngine.prototype = {
return changedIDs;
},
_wipeClient: function () {
_wipeClient() {
SyncEngine.prototype._wipeClient.call(this);
this.justWiped = true;
},
_reconcile: function (item) {
_reconcile(item) {
// Apply the incoming item if we don't care about the local data
if (this.justWiped) {
this.justWiped = false;
@ -70,7 +70,7 @@ PrefsEngine.prototype = {
function PrefStore(name, engine) {
Store.call(this, name, engine);
Svc.Obs.add("profile-before-change", function () {
Svc.Obs.add("profile-before-change", function() {
this.__prefs = null;
}, this);
}
@ -85,7 +85,7 @@ PrefStore.prototype = {
return this.__prefs;
},
_getSyncPrefs: function () {
_getSyncPrefs() {
let syncPrefs = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefService)
.getBranch(PREF_SYNC_PREFS_PREFIX)
@ -95,12 +95,12 @@ PrefStore.prototype = {
return controlPrefs.concat(syncPrefs);
},
_isSynced: function (pref) {
_isSynced(pref) {
return pref.startsWith(PREF_SYNC_PREFS_PREFIX) ||
this._prefs.get(PREF_SYNC_PREFS_PREFIX + pref, false);
},
_getAllPrefs: function () {
_getAllPrefs() {
let values = {};
for (let pref of this._getSyncPrefs()) {
if (this._isSynced(pref)) {
@ -111,7 +111,7 @@ PrefStore.prototype = {
return values;
},
_updateLightWeightTheme (themeID) {
_updateLightWeightTheme(themeID) {
let themeObject = null;
if (themeID) {
themeObject = LightweightThemeManager.getUsedTheme(themeID);
@ -119,7 +119,7 @@ PrefStore.prototype = {
LightweightThemeManager.currentTheme = themeObject;
},
_setAllPrefs: function (values) {
_setAllPrefs(values) {
let selectedThemeIDPref = "lightweightThemes.selectedThemeID";
let selectedThemeIDBefore = this._prefs.get(selectedThemeIDPref, null);
let selectedThemeIDAfter = selectedThemeIDBefore;
@ -148,7 +148,7 @@ PrefStore.prototype = {
} else {
try {
this._prefs.set(pref, value);
} catch(ex) {
} catch (ex) {
this._log.trace("Failed to set pref: " + pref + ": " + ex);
}
}
@ -161,22 +161,22 @@ PrefStore.prototype = {
}
},
getAllIDs: function () {
getAllIDs() {
/* We store all prefs in just one WBO, with just one GUID */
let allprefs = {};
allprefs[PREFS_GUID] = true;
return allprefs;
},
changeItemID: function (oldID, newID) {
changeItemID(oldID, newID) {
this._log.trace("PrefStore GUID is constant!");
},
itemExists: function (id) {
itemExists(id) {
return (id === PREFS_GUID);
},
createRecord: function (id, collection) {
createRecord(id, collection) {
let record = new PrefRec(collection, id);
if (id == PREFS_GUID) {
@ -188,15 +188,15 @@ PrefStore.prototype = {
return record;
},
create: function (record) {
create(record) {
this._log.trace("Ignoring create request");
},
remove: function (record) {
remove(record) {
this._log.trace("Ignoring remove request");
},
update: function (record) {
update(record) {
// Silently ignore pref updates that are for other apps.
if (record.id != PREFS_GUID)
return;
@ -205,7 +205,7 @@ PrefStore.prototype = {
this._setAllPrefs(record.value);
},
wipe: function () {
wipe() {
this._log.trace("Ignoring wipe request");
}
};
@ -238,16 +238,16 @@ PrefTracker.prototype = {
return this.__prefs;
},
startTracking: function () {
startTracking() {
Services.prefs.addObserver("", this, false);
},
stopTracking: function () {
stopTracking() {
this.__prefs = null;
Services.prefs.removeObserver("", this);
},
observe: function (subject, topic, data) {
observe(subject, topic, data) {
Tracker.prototype.observe.call(this, subject, topic, data);
switch (topic) {

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

@ -51,7 +51,7 @@ TabEngine.prototype = {
syncPriority: 3,
getChangedIDs: function () {
getChangedIDs() {
// No need for a proper timestamp (no conflict resolution needed).
let changedIDs = {};
if (this._tracker.modified)
@ -60,22 +60,22 @@ TabEngine.prototype = {
},
// API for use by Sync UI code to give user choices of tabs to open.
getAllClients: function () {
getAllClients() {
return this._store._remoteClients;
},
getClientById: function (id) {
getClientById(id) {
return this._store._remoteClients[id];
},
_resetClient: function () {
_resetClient() {
SyncEngine.prototype._resetClient.call(this);
this._store.wipe();
this._tracker.modified = true;
this.hasSyncedThisSession = false;
},
removeClientData: function () {
removeClientData() {
let url = this.engineURL + "/" + this.service.clientsEngine.localID;
this.service.resource(url).delete();
},
@ -83,7 +83,7 @@ TabEngine.prototype = {
/**
* Return a Set of open URLs.
*/
getOpenURLs: function () {
getOpenURLs() {
let urls = new Set();
for (let entry of this._store.getAllTabs()) {
urls.add(entry.urlHistory[0]);
@ -91,7 +91,7 @@ TabEngine.prototype = {
return urls;
},
_reconcile: function (item) {
_reconcile(item) {
// Skip our own record.
// TabStore.itemExists tests only against our local client ID.
if (this._store.itemExists(item.id)) {
@ -115,24 +115,24 @@ function TabStore(name, engine) {
TabStore.prototype = {
__proto__: Store.prototype,
itemExists: function (id) {
itemExists(id) {
return id == this.engine.service.clientsEngine.localID;
},
getWindowEnumerator: function () {
getWindowEnumerator() {
return Services.wm.getEnumerator("navigator:browser");
},
shouldSkipWindow: function (win) {
shouldSkipWindow(win) {
return win.closed ||
PrivateBrowsingUtils.isWindowPrivate(win);
},
getTabState: function (tab) {
getTabState(tab) {
return JSON.parse(Svc.Session.getTabState(tab));
},
getAllTabs: function (filter) {
getAllTabs(filter) {
let filteredUrls = new RegExp(Svc.Prefs.get("engine.tabs.filteredUrls"), "i");
let allTabs = [];
@ -200,12 +200,12 @@ TabStore.prototype = {
return allTabs;
},
createRecord: function (id, collection) {
createRecord(id, collection) {
let record = new TabSetRecord(collection, id);
record.clientName = this.engine.service.clientsEngine.localName;
// Sort tabs in descending-used order to grab the most recently used
let tabs = this.getAllTabs(true).sort(function (a, b) {
let tabs = this.getAllTabs(true).sort(function(a, b) {
return b.lastUsed - a.lastUsed;
});
@ -225,7 +225,7 @@ TabStore.prototype = {
}
this._log.trace("Created tabs " + tabs.length + " of " + origLength);
tabs.forEach(function (tab) {
tabs.forEach(function(tab) {
this._log.trace("Wrapping tab: " + JSON.stringify(tab));
}, this);
@ -233,7 +233,7 @@ TabStore.prototype = {
return record;
},
getAllIDs: function () {
getAllIDs() {
// Don't report any tabs if all windows are in private browsing for
// first syncs.
let ids = {};
@ -259,18 +259,18 @@ TabStore.prototype = {
return ids;
},
wipe: function () {
wipe() {
this._remoteClients = {};
},
create: function (record) {
create(record) {
this._log.debug("Adding remote tabs from " + record.clientName);
this._remoteClients[record.id] = Object.assign({}, record.cleartext, {
lastModified: record.modified
});
},
update: function (record) {
update(record) {
this._log.trace("Ignoring tab updates as local ones win");
},
};
@ -290,13 +290,13 @@ TabTracker.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
clearChangedIDs: function () {
clearChangedIDs() {
this.modified = false;
},
_topics: ["pageshow", "TabOpen", "TabClose", "TabSelect"],
_registerListenersForWindow: function (window) {
_registerListenersForWindow(window) {
this._log.trace("Registering tab listeners in window");
for (let topic of this._topics) {
window.addEventListener(topic, this.onTab, false);
@ -308,11 +308,11 @@ TabTracker.prototype = {
}
},
_unregisterListeners: function (event) {
_unregisterListeners(event) {
this._unregisterListenersForWindow(event.target);
},
_unregisterListenersForWindow: function (window) {
_unregisterListenersForWindow(window) {
this._log.trace("Removing tab listeners in window");
window.removeEventListener("unload", this._unregisterListeners, false);
for (let topic of this._topics) {
@ -323,7 +323,7 @@ TabTracker.prototype = {
}
},
startTracking: function () {
startTracking() {
Svc.Obs.add("domwindowopened", this);
let wins = Services.wm.getEnumerator("navigator:browser");
while (wins.hasMoreElements()) {
@ -331,7 +331,7 @@ TabTracker.prototype = {
}
},
stopTracking: function () {
stopTracking() {
Svc.Obs.remove("domwindowopened", this);
let wins = Services.wm.getEnumerator("navigator:browser");
while (wins.hasMoreElements()) {
@ -339,7 +339,7 @@ TabTracker.prototype = {
}
},
observe: function (subject, topic, data) {
observe(subject, topic, data) {
Tracker.prototype.observe.call(this, subject, topic, data);
switch (topic) {
@ -356,7 +356,7 @@ TabTracker.prototype = {
}
},
onTab: function (event) {
onTab(event) {
if (event.originalTarget.linkedBrowser) {
let browser = event.originalTarget.linkedBrowser;
if (PrivateBrowsingUtils.isBrowserPrivate(browser) &&
@ -378,7 +378,7 @@ TabTracker.prototype = {
},
// web progress listeners.
onLocationChange: function (webProgress, request, location, flags) {
onLocationChange(webProgress, request, location, flags) {
// We only care about top-level location changes which are not in the same
// document.
if (webProgress.isTopLevel &&

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

@ -87,18 +87,18 @@ IdentityManager.prototype = {
/**
* Initialize the identity provider.
*/
initialize: function() {
initialize() {
// Nothing to do for this identity provider.
},
finalize: function() {
finalize() {
// Nothing to do for this identity provider.
},
/**
* Called whenever Service.logout() is called.
*/
logout: function() {
logout() {
// nothing to do for this identity provider.
},
@ -106,7 +106,7 @@ IdentityManager.prototype = {
* Ensure the user is logged in. Returns a promise that resolves when
* the user is logged in, or is rejected if the login attempt has failed.
*/
ensureLoggedIn: function() {
ensureLoggedIn() {
// nothing to do for this identity provider
return Promise.resolve();
},
@ -169,7 +169,7 @@ IdentityManager.prototype = {
/**
* Resets/Drops all credentials we hold for the current user.
*/
resetCredentials: function() {
resetCredentials() {
this.basicPassword = null;
this.resetSyncKey();
},
@ -177,7 +177,7 @@ IdentityManager.prototype = {
/**
* Resets/Drops the sync key we hold for the current user.
*/
resetSyncKey: function() {
resetSyncKey() {
this.syncKey = null;
// syncKeyBundle cleared as a result of setting syncKey.
},
@ -372,7 +372,7 @@ IdentityManager.prototype = {
* Returns a promise that resolves with the current auth state after
* attempting to unlock.
*/
unlockAndVerifyAuthState: function() {
unlockAndVerifyAuthState() {
// Try to fetch the passphrase - this will prompt for MP unlock as a
// side-effect...
try {
@ -441,7 +441,7 @@ IdentityManager.prototype = {
* allows us to avoid a network request for when we actually need the
* migration info.
*/
prefetchMigrationSentinel: function(service) {
prefetchMigrationSentinel(service) {
// Try and fetch the migration sentinel - it will end up in the recordManager
// cache.
try {
@ -495,7 +495,7 @@ IdentityManager.prototype = {
/**
* Return credentials hosts for this identity only.
*/
_getSyncCredentialsHosts: function() {
_getSyncCredentialsHosts() {
return Utils.getSyncCredentialsHostsLegacy();
},
@ -584,12 +584,12 @@ IdentityManager.prototype = {
request.setHeader("authorization", "Basic " + btoa(up));
},
createClusterManager: function(service) {
createClusterManager(service) {
Cu.import("resource://services-sync/stages/cluster.js");
return new ClusterManager(service);
},
offerSyncOptions: function () {
offerSyncOptions() {
// Do nothing for Sync 1.1.
return {accepted: true};
},

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

@ -24,8 +24,8 @@ const JPAKE_VERIFY_VALUE = "0123456789ABCDEF";
/**
* Client to exchange encrypted data using the J-PAKE algorithm.
* The exchange between two clients of this type looks like this:
*
*
*
*
* Mobile Server Desktop
* ===================================================================
* |
@ -59,26 +59,26 @@ const JPAKE_VERIFY_VALUE = "0123456789ABCDEF";
* decrypt credentials |
* delete session ----------------->|
* start syncing |
*
*
*
*
* Create a client object like so:
*
*
* let client = new JPAKEClient(controller);
*
*
* The 'controller' object must implement the following methods:
*
*
* displayPIN(pin) -- Called when a PIN has been generated and is ready to
* be displayed to the user. Only called on the client where the pairing
* was initiated with 'receiveNoPIN()'.
*
*
* onPairingStart() -- Called when the pairing has started and messages are
* being sent back and forth over the channel. Only called on the client
* where the pairing was initiated with 'receiveNoPIN()'.
*
*
* onPaired() -- Called when the device pairing has been established and
* we're ready to send the credentials over. To do that, the controller
* must call 'sendAndComplete()' while the channel is active.
*
*
* onComplete(data) -- Called after transfer has been completed. On
* the sending side this is called with no parameter and as soon as the
* data has been uploaded. This does not mean the receiving side has
@ -86,28 +86,28 @@ const JPAKE_VERIFY_VALUE = "0123456789ABCDEF";
*
* onAbort(error) -- Called whenever an error is encountered. All errors lead
* to an abort and the process has to be started again on both sides.
*
*
* To start the data transfer on the receiving side, call
*
*
* client.receiveNoPIN();
*
*
* This will allocate a new channel on the server, generate a PIN, have it
* displayed and then do the transfer once the protocol has been completed
* with the sending side.
*
*
* To initiate the transfer from the sending side, call
*
*
* client.pairWithPIN(pin, true);
*
*
* Once the pairing has been established, the controller's 'onPaired()' method
* will be called. To then transmit the data, call
*
*
* client.sendAndComplete(data);
*
*
* To abort the process, call
*
*
* client.abort();
*
*
* Note that after completion or abort, the 'client' instance may not be reused.
* You will have to create a new one in case you'd like to restart the process.
*/
@ -141,7 +141,7 @@ JPAKEClient.prototype = {
/**
* Initiate pairing and receive data without providing a PIN. The PIN will
* be generated and passed on to the controller to be displayed to the user.
*
*
* This is typically called on mobile devices where typing is tedious.
*/
receiveNoPIN: function receiveNoPIN() {
@ -185,10 +185,10 @@ JPAKEClient.prototype = {
/**
* Initiate pairing based on the PIN entered by the user.
*
*
* This is typically called on desktop devices where typing is easier than
* on mobile.
*
*
* @param pin
* 12 character string (in human-friendly base32) containing the PIN
* entered by the user.
@ -208,7 +208,7 @@ JPAKEClient.prototype = {
this._chain(this._computeStepOne,
this._getStep,
function (callback) {
function(callback) {
// Ensure that the other client can deal with a delay for
// the last message if that's requested by the caller.
if (!expectDelay) {
@ -230,7 +230,7 @@ JPAKEClient.prototype = {
/**
* Send data after a successful pairing.
*
*
* @param obj
* Object containing the data to send. It will be serialized as JSON.
*/
@ -249,7 +249,7 @@ JPAKEClient.prototype = {
* Abort the current pairing. The channel on the server will be deleted
* if the abort wasn't due to a network or server error. The controller's
* 'onAbort()' method is notified in all cases.
*
*
* @param error [optional]
* Error constant indicating the reason for the abort. Defaults to
* user abort.
@ -350,7 +350,7 @@ JPAKEClient.prototype = {
} else {
request.setHeader("If-None-Match", "*");
}
request.put(this._outgoing, Utils.bind2(this, function (error) {
request.put(this._outgoing, Utils.bind2(this, function(error) {
if (this._finished) {
return;
}
@ -369,7 +369,7 @@ JPAKEClient.prototype = {
// There's no point in returning early here since the next step will
// always be a GET so let's pause for twice the poll interval.
this._my_etag = request.response.headers["etag"];
Utils.namedTimer(function () { callback(); }, this._pollInterval * 2,
Utils.namedTimer(function() { callback(); }, this._pollInterval * 2,
this, "_pollTimer");
}));
},
@ -383,7 +383,7 @@ JPAKEClient.prototype = {
request.setHeader("If-None-Match", this._my_etag);
}
request.get(Utils.bind2(this, function (error) {
request.get(Utils.bind2(this, function(error) {
if (this._finished) {
return;
}
@ -445,7 +445,7 @@ JPAKEClient.prototype = {
let request = this._newRequest(this._serverURL + "report");
request.setHeader("X-KeyExchange-Cid", this._channel);
request.setHeader("X-KeyExchange-Log", reason);
request.post("", Utils.bind2(this, function (error) {
request.post("", Utils.bind2(this, function(error) {
if (error) {
this._log.warn("Report failed: " + error);
} else if (request.response.status != 200) {
@ -572,7 +572,7 @@ JPAKEClient.prototype = {
}
this._outgoing = {type: this._my_signerid + "3",
version: KEYEXCHANGE_VERSION,
payload: {ciphertext: ciphertext, IV: iv}};
payload: {ciphertext, IV: iv}};
this._log.trace("Generated message " + this._outgoing.type);
callback();
},
@ -601,7 +601,7 @@ JPAKEClient.prototype = {
this._log.debug("Verified pairing!");
this._paired = true;
Utils.nextTick(function () { this.controller.onPaired(); }, this);
Utils.nextTick(function() { this.controller.onPaired(); }, this);
callback();
},
@ -619,7 +619,7 @@ JPAKEClient.prototype = {
}
this._outgoing = {type: this._my_signerid + "3",
version: KEYEXCHANGE_VERSION,
payload: {ciphertext: ciphertext, IV: iv, hmac: hmac}};
payload: {ciphertext, IV: iv, hmac}};
this._log.trace("Generated message " + this._outgoing.type);
callback();
},
@ -647,7 +647,7 @@ JPAKEClient.prototype = {
this._log.trace("Decrypting data.");
let cleartext;
try {
try {
cleartext = Svc.Crypto.decrypt(step3.ciphertext, this._crypto_key,
step3.IV);
} catch (ex) {
@ -671,7 +671,7 @@ JPAKEClient.prototype = {
_complete: function _complete() {
this._log.debug("Exchange completed.");
this._finished = true;
Utils.nextTick(function () { this.controller.onComplete(this._newData); },
Utils.nextTick(function() { this.controller.onComplete(this._newData); },
this);
}
@ -710,8 +710,8 @@ this.SendCredentialsController =
// this device's sync configuration, in case that happens while we
// haven't finished the first sync yet.
Services.obs.addObserver(this, "weave:service:sync:finish", false);
Services.obs.addObserver(this, "weave:service:sync:error", false);
Services.obs.addObserver(this, "weave:service:start-over", false);
Services.obs.addObserver(this, "weave:service:sync:error", false);
Services.obs.addObserver(this, "weave:service:start-over", false);
}
SendCredentialsController.prototype = {

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше