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
parent 2797c83264
commit 81cb5e57b9
199 changed files with 1827 additions and 1873 deletions

View file

@ -184,6 +184,12 @@ mobile/android/modules/HomeProvider.jsm
# Uses `#filter substitution` # Uses `#filter substitution`
services/sync/modules/constants.js 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 # toolkit/ exclusions
# Not part of the default build # Not part of the default build

29
services/.eslintrc.js Normal file
View 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"
}
};

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -5,22 +5,22 @@
Cu.import("resource://gre/modules/CloudSync.jsm"); Cu.import("resource://gre/modules/CloudSync.jsm");
function run_test () { function run_test() {
run_next_test(); run_next_test();
} }
function cleanup () { function cleanup() {
} }
add_task(function* test_merge_bookmarks_flat () { add_task(function* test_merge_bookmarks_flat() {
try { try {
let rootFolder = yield CloudSync().bookmarks.getRootFolder("TEST"); let rootFolder = yield CloudSync().bookmarks.getRootFolder("TEST");
ok(rootFolder.id, "root folder id is ok"); ok(rootFolder.id, "root folder id is ok");
let items = [ 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_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_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); 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 { try {
let rootFolder = yield CloudSync().bookmarks.getRootFolder("TEST"); let rootFolder = yield CloudSync().bookmarks.getRootFolder("TEST");
ok(rootFolder.id, "root folder id is ok"); ok(rootFolder.id, "root folder id is ok");
let items = [ 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_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_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_UL4ZhOyX8x", "type":rootFolder.FOLDER},
]; ];
yield rootFolder.mergeRemoteItems(items); yield rootFolder.mergeRemoteItems(items);
@ -70,4 +70,4 @@ add_task(function* test_merge_bookmarks_in_folders () {
} finally { } finally {
yield CloudSync().bookmarks.deleteRootFolder("TEST"); yield CloudSync().bookmarks.deleteRootFolder("TEST");
} }
}); });

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -17,7 +17,7 @@ function do_get_kinto_sqliteHandle() {
return FirefoxAdapter.openConnection({path: kintoFilename}); 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 = { let config = {
remote:`http://localhost:${server.identity.primaryPort}/v1/`, remote:`http://localhost:${server.identity.primaryPort}/v1/`,
headers: {Authorization: "Basic " + btoa("user:pass")}, headers: {Authorization: "Basic " + btoa("user:pass")},
@ -154,7 +154,7 @@ add_task(function* test_kinto_clear() {
add_task(clear_collection); add_task(clear_collection);
add_task(function* test_kinto_delete(){ add_task(function* test_kinto_delete() {
let sqliteHandle; let sqliteHandle;
try { try {
sqliteHandle = yield do_get_kinto_sqliteHandle(); 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; let sqliteHandle;
try { try {
sqliteHandle = yield do_get_kinto_sqliteHandle(); sqliteHandle = yield do_get_kinto_sqliteHandle();
@ -214,7 +214,7 @@ add_task(function* test_kinto_list(){
add_task(clear_collection); add_task(clear_collection);
add_task(function* test_loadDump_ignores_already_imported_records(){ add_task(function* test_loadDump_ignores_already_imported_records() {
let sqliteHandle; let sqliteHandle;
try { try {
sqliteHandle = yield do_get_kinto_sqliteHandle(); 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(clear_collection);
add_task(function* test_loadDump_should_overwrite_old_records(){ add_task(function* test_loadDump_should_overwrite_old_records() {
let sqliteHandle; let sqliteHandle;
try { try {
sqliteHandle = yield do_get_kinto_sqliteHandle(); 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(clear_collection);
add_task(function* test_loadDump_should_not_overwrite_unsynced_records(){ add_task(function* test_loadDump_should_not_overwrite_unsynced_records() {
let sqliteHandle; let sqliteHandle;
try { try {
sqliteHandle = yield do_get_kinto_sqliteHandle(); 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(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; let sqliteHandle;
try { try {
sqliteHandle = yield do_get_kinto_sqliteHandle(); 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 // 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 // core kinto.js functionality here (there is excellent test coverage in
// kinto.js), more making sure things are basically working as expected. // 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 configPath = "/v1/";
const recordsPath = "/v1/buckets/default/collections/test_collection/records"; const recordsPath = "/v1/buckets/default/collections/test_collection/records";
// register a handler // register a handler
function handleResponse (request, response) { function handleResponse(request, response) {
try { try {
const sampled = getSampleResponse(request, server.identity.primaryPort); const sampled = getSampleResponse(request, server.identity.primaryPort);
if (!sampled) { if (!sampled) {

View file

@ -25,7 +25,7 @@ const non_android_test_modules = [
"storageserver.js", "storageserver.js",
]; ];
function expectImportsToSucceed(mm, base=MODULE_BASE) { function expectImportsToSucceed(mm, base = MODULE_BASE) {
for (let m of mm) { for (let m of mm) {
let resource = base + m; let resource = base + m;
let succeeded = false; 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) { for (let m of mm) {
let resource = base + m; let resource = base + m;
let succeeded = false; let succeeded = false;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -8,7 +8,7 @@ function do_check_throws(func) {
let have_error = false; let have_error = false;
try { try {
func(); func();
} catch(ex) { } catch (ex) {
dump("Was expecting an exception. Caught: " + ex + "\n"); dump("Was expecting an exception. Caught: " + ex + "\n");
have_error = true; 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); 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 // g^x is NIST 3072's p + 1, (p + 1) mod p == 1, x == 0
test("90066455B5CFC38F9CAA4A48B4281F292C260FEEF01FD61037E56258A7795A1C" test("90066455B5CFC38F9CAA4A48B4281F292C260FEEF01FD61037E56258A7795A1C"
+ "7AD46076982CE6BB956936C6AB4DCFE05E6784586940CA544B9B2140E1EB523F" + "7AD46076982CE6BB956936C6AB4DCFE05E6784586940CA544B9B2140E1EB523F"
@ -246,7 +246,7 @@ function test_x4_zero() {
} }
function test_invalid_input_round2() { 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); .createInstance(Ci.nsISyncJPAKE);
a.round1("alice", {}, {}, {}, {}, {}, {}); a.round1("alice", {}, {}, {}, {}, {}, {});

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -43,7 +43,7 @@ ExtensionStorageEngine.prototype = {
syncPriority: 10, syncPriority: 10,
allowSkippedRecord: false, allowSkippedRecord: false,
_sync: function () { _sync() {
return Async.promiseSpinningly(ExtensionStorageSync.syncAll()); return Async.promiseSpinningly(ExtensionStorageSync.syncAll());
}, },
@ -68,15 +68,15 @@ function ExtensionStorageTracker(name, engine) {
ExtensionStorageTracker.prototype = { ExtensionStorageTracker.prototype = {
__proto__: Tracker.prototype, __proto__: Tracker.prototype,
startTracking: function () { startTracking() {
Svc.Obs.add("ext.storage.sync-changed", this); Svc.Obs.add("ext.storage.sync-changed", this);
}, },
stopTracking: function () { stopTracking() {
Svc.Obs.remove("ext.storage.sync-changed", this); 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); Tracker.prototype.observe.call(this, subject, topic, data);
if (this.ignoreAll) { if (this.ignoreAll) {
@ -94,15 +94,15 @@ ExtensionStorageTracker.prototype = {
// Override a bunch of methods which don't do anything for us. // Override a bunch of methods which don't do anything for us.
// This is a performance hack. // 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 kB = Utils.hexToBytes(user.kB);
let keyMaterial = CryptoUtils.hkdf(kB, undefined, 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(); let bundle = new BulkKeyBundle();
// [encryptionKey, hmacKey] // [encryptionKey, hmacKey]
bundle.keyPair = [keyMaterial.slice(0, 32), keyMaterial.slice(32, 64)]; bundle.keyPair = [keyMaterial.slice(0, 32), keyMaterial.slice(32, 64)];

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

Some files were not shown because too many files have changed in this diff Show more