diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2018-10-06 06:57:51 +0200 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-10-06 06:57:51 +0200 |
commit | 0c47c83e1b3b7d95681a43fbb0de0e17b2cd5b25 (patch) | |
tree | c321601f04cbfd02fb6e12878e745dc49a612c86 /services/sync/modules-testing | |
parent | 8860eddcee1417483cafd114f3a9ec127e0f1f74 (diff) | |
download | UXP-0c47c83e1b3b7d95681a43fbb0de0e17b2cd5b25.tar UXP-0c47c83e1b3b7d95681a43fbb0de0e17b2cd5b25.tar.gz UXP-0c47c83e1b3b7d95681a43fbb0de0e17b2cd5b25.tar.lz UXP-0c47c83e1b3b7d95681a43fbb0de0e17b2cd5b25.tar.xz UXP-0c47c83e1b3b7d95681a43fbb0de0e17b2cd5b25.zip |
Import Tycho weave client
Diffstat (limited to 'services/sync/modules-testing')
-rw-r--r-- | services/sync/modules-testing/fakeservices.js | 34 | ||||
-rw-r--r-- | services/sync/modules-testing/fxa_utils.js | 2 | ||||
-rw-r--r-- | services/sync/modules-testing/rotaryengine.js | 12 | ||||
-rw-r--r-- | services/sync/modules-testing/utils.js | 129 |
4 files changed, 29 insertions, 148 deletions
diff --git a/services/sync/modules-testing/fakeservices.js b/services/sync/modules-testing/fakeservices.js index 2895736df..0e265937b 100644 --- a/services/sync/modules-testing/fakeservices.js +++ b/services/sync/modules-testing/fakeservices.js @@ -11,31 +11,17 @@ this.EXPORTED_SYMBOLS = [ "fakeSHA256HMAC", ]; -var {utils: Cu} = Components; +const {utils: Cu} = Components; Cu.import("resource://services-sync/record.js"); Cu.import("resource://services-sync/util.js"); -var btoa = Cu.import("resource://gre/modules/Log.jsm").btoa; +let btoa = Cu.import("resource://gre/modules/Log.jsm").btoa; this.FakeFilesystemService = function FakeFilesystemService(contents) { this.fakeContents = contents; let self = this; - // Save away the unmocked versions of the functions we replace here for tests - // that really want the originals. As this may be called many times per test, - // we must be careful to not replace them with ones we previously replaced. - // (And WTF are we bothering with these mocks in the first place? Is the - // performance of the filesystem *really* such that it outweighs the downside - // of not running our real JSON functions in the tests? Eg, these mocks don't - // always throw exceptions when the real ones do. Anyway...) - for (let name of ["jsonSave", "jsonLoad", "jsonMove", "jsonRemove"]) { - let origName = "_real_" + name; - if (!Utils[origName]) { - Utils[origName] = Utils[name]; - } - } - Utils.jsonSave = function jsonSave(filePath, that, obj, callback) { let json = typeof obj == "function" ? obj.call(that) : obj; self.fakeContents["weave/" + filePath + ".json"] = JSON.stringify(json); @@ -50,18 +36,6 @@ this.FakeFilesystemService = function FakeFilesystemService(contents) { } cb.call(that, obj); }; - - Utils.jsonMove = function jsonMove(aFrom, aTo, that) { - const fromPath = "weave/" + aFrom + ".json"; - self.fakeContents["weave/" + aTo + ".json"] = self.fakeContents[fromPath]; - delete self.fakeContents[fromPath]; - return Promise.resolve(); - }; - - Utils.jsonRemove = function jsonRemove(filePath, that) { - delete self.fakeContents["weave/" + filePath + ".json"]; - return Promise.resolve(); - }; }; this.fakeSHA256HMAC = function fakeSHA256HMAC(message) { @@ -76,9 +50,7 @@ this.FakeGUIDService = function FakeGUIDService() { let latestGUID = 0; Utils.makeGUID = function makeGUID() { - // ensure that this always returns a unique 12 character string - let nextGUID = "fake-guid-" + String(latestGUID++).padStart(2, "0"); - return nextGUID.slice(nextGUID.length-12, nextGUID.length); + return "fake-guid-" + latestGUID++; }; } diff --git a/services/sync/modules-testing/fxa_utils.js b/services/sync/modules-testing/fxa_utils.js index 70aa17b03..4c622660a 100644 --- a/services/sync/modules-testing/fxa_utils.js +++ b/services/sync/modules-testing/fxa_utils.js @@ -4,7 +4,7 @@ this.EXPORTED_SYMBOLS = [ "initializeIdentityWithTokenServerResponse",
];
-var {utils: Cu} = Components;
+const {utils: Cu} = Components;
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://services-sync/main.js");
diff --git a/services/sync/modules-testing/rotaryengine.js b/services/sync/modules-testing/rotaryengine.js index 9d3bf723d..d86c1a75e 100644 --- a/services/sync/modules-testing/rotaryengine.js +++ b/services/sync/modules-testing/rotaryengine.js @@ -11,7 +11,7 @@ this.EXPORTED_SYMBOLS = [ "RotaryTracker", ]; -var {utils: Cu} = Components; +const {utils: Cu} = Components; Cu.import("resource://services-sync/engines.js"); Cu.import("resource://services-sync/record.js"); @@ -32,8 +32,8 @@ RotaryRecord.prototype = { }; Utils.deferGetSet(RotaryRecord, "cleartext", ["denomination"]); -this.RotaryStore = function RotaryStore(name, engine) { - Store.call(this, name, engine); +this.RotaryStore = function RotaryStore(engine) { + Store.call(this, "Rotary", engine); this.items = {}; } RotaryStore.prototype = { @@ -88,8 +88,8 @@ RotaryStore.prototype = { } }; -this.RotaryTracker = function RotaryTracker(name, engine) { - Tracker.call(this, name, engine); +this.RotaryTracker = function RotaryTracker(engine) { + Tracker.call(this, "Rotary", engine); } RotaryTracker.prototype = { __proto__: Tracker.prototype @@ -115,7 +115,7 @@ RotaryEngine.prototype = { return "DUPE_LOCAL"; } - for (let [id, value] of Object.entries(this._store.items)) { + for (let [id, value] in Iterator(this._store.items)) { if (item.denomination == value) { return id; } diff --git a/services/sync/modules-testing/utils.js b/services/sync/modules-testing/utils.js index 261c2bb21..faea8fb04 100644 --- a/services/sync/modules-testing/utils.js +++ b/services/sync/modules-testing/utils.js @@ -7,23 +7,18 @@ this.EXPORTED_SYMBOLS = [ "btoa", // It comes from a module import. "encryptPayload", - "isConfiguredWithLegacyIdentity", "ensureLegacyIdentityManager", "setBasicCredentials", "makeIdentityConfig", - "makeFxAccountsInternalMock", "configureFxAccountIdentity", "configureIdentity", "SyncTestingInfrastructure", "waitForZeroTimer", "Promise", // from a module import "add_identity_test", - "MockFxaStorageManager", - "AccountState", // from a module import - "sumHistogram", ]; -var {utils: Cu} = Components; +const {utils: Cu} = Components; Cu.import("resource://services-sync/status.js"); Cu.import("resource://services-sync/identity.js"); @@ -34,49 +29,8 @@ Cu.import("resource://services-sync/browserid_identity.js"); Cu.import("resource://testing-common/services/common/logging.js"); Cu.import("resource://testing-common/services/sync/fakeservices.js"); Cu.import("resource://gre/modules/FxAccounts.jsm"); -Cu.import("resource://gre/modules/FxAccountsClient.jsm"); Cu.import("resource://gre/modules/FxAccountsCommon.js"); Cu.import("resource://gre/modules/Promise.jsm"); -Cu.import("resource://gre/modules/Services.jsm"); - -// and grab non-exported stuff via a backstage pass. -const {AccountState} = Cu.import("resource://gre/modules/FxAccounts.jsm", {}); - -// A mock "storage manager" for FxAccounts that doesn't actually write anywhere. -function MockFxaStorageManager() { -} - -MockFxaStorageManager.prototype = { - promiseInitialized: Promise.resolve(), - - initialize(accountData) { - this.accountData = accountData; - }, - - finalize() { - return Promise.resolve(); - }, - - getAccountData() { - return Promise.resolve(this.accountData); - }, - - updateAccountData(updatedFields) { - for (let [name, value] of Object.entries(updatedFields)) { - if (value == null) { - delete this.accountData[name]; - } else { - this.accountData[name] = value; - } - } - return Promise.resolve(); - }, - - deleteAccountData() { - this.accountData = null; - return Promise.resolve(); - } -} /** * First wait >100ms (nsITimers can take up to that much time to fire, so @@ -97,18 +51,6 @@ this.waitForZeroTimer = function waitForZeroTimer(callback) { } /** - * Return true if Sync is configured with the "legacy" identity provider. - */ -this.isConfiguredWithLegacyIdentity = function() { - let ns = {}; - Cu.import("resource://services-sync/service.js", ns); - - // We can't use instanceof as BrowserIDManager (the "other" identity) inherits - // from IdentityManager so that would return true - so check the prototype. - return Object.getPrototypeOf(ns.Service.identity) === IdentityManager.prototype; -} - -/** * Ensure Sync is configured with the "legacy" identity provider. */ this.ensureLegacyIdentityManager = function() { @@ -145,15 +87,14 @@ this.makeIdentityConfig = function(overrides) { kA: 'kA', kB: 'kB', sessionToken: 'sessionToken', - uid: "a".repeat(32), + uid: 'user_uid', verified: true, }, token: { - endpoint: null, + endpoint: Svc.Prefs.get("tokenServerURI"), duration: 300, id: "id", key: "key", - hashed_fxa_uid: "f".repeat(32), // used during telemetry validation // uid will be set to the username. } }, @@ -181,47 +122,27 @@ this.makeIdentityConfig = function(overrides) { return result; } -this.makeFxAccountsInternalMock = function(config) { - return { - newAccountState(credentials) { - // We only expect this to be called with null indicating the (mock) - // storage should be read. - if (credentials) { - throw new Error("Not expecting to have credentials passed"); - } - let storageManager = new MockFxaStorageManager(); - storageManager.initialize(config.fxaccount.user); - let accountState = new AccountState(storageManager); - return accountState; - }, - _getAssertion(audience) { - return Promise.resolve("assertion"); - }, - }; -}; - // Configure an instance of an FxAccount identity provider with the specified // config (or the default config if not specified). this.configureFxAccountIdentity = function(authService, - config = makeIdentityConfig(), - fxaInternal = makeFxAccountsInternalMock(config)) { + config = makeIdentityConfig()) { + let MockInternal = {}; + let fxa = new FxAccounts(MockInternal); + // until we get better test infrastructure for bid_identity, we set the // signedin user's "email" to the username, simply as many tests rely on this. config.fxaccount.user.email = config.username; - - let fxa = new FxAccounts(fxaInternal); - - let MockFxAccountsClient = function() { - FxAccountsClient.apply(this); + fxa.internal.currentAccountState.signedInUser = { + version: DATA_FORMAT_VERSION, + accountData: config.fxaccount.user }; - MockFxAccountsClient.prototype = { - __proto__: FxAccountsClient.prototype, - accountStatus() { - return Promise.resolve(true); - } + fxa.internal.currentAccountState.getCertificate = function(data, keyPair, mustBeValidUntil) { + this.cert = { + validUntil: fxa.internal.now() + CERT_LIFETIME, + cert: "certificate", + }; + return Promise.resolve(this.cert.cert); }; - let mockFxAClient = new MockFxAccountsClient(); - fxa.internal._fxAccountsClient = mockFxAClient; let mockTSC = { // TokenServerClient getTokenFromBrowserIDAssertion: function(uri, assertion, cb) { @@ -233,7 +154,7 @@ this.configureFxAccountIdentity = function(authService, authService._tokenServerClient = mockTSC; // Set the "account" of the browserId manager to be the "email" of the // logged in user of the mockFXA service. - authService._signedInUser = config.fxaccount.user; + authService._signedInUser = fxa.internal.currentAccountState.signedInUser.accountData; authService._account = config.fxaccount.user.email; } @@ -320,7 +241,7 @@ this.add_identity_test = function(test, testFunction) { let ns = {}; Cu.import("resource://services-sync/service.js", ns); // one task for the "old" identity manager. - test.add_task(function* () { + test.add_task(function() { note("sync"); let oldIdentity = Status._authManager; ensureLegacyIdentityManager(); @@ -328,7 +249,7 @@ this.add_identity_test = function(test, testFunction) { Status.__authManager = ns.Service.identity = oldIdentity; }); // another task for the FxAccounts identity manager. - test.add_task(function* () { + test.add_task(function() { note("FxAccounts"); let oldIdentity = Status._authManager; Status.__authManager = ns.Service.identity = new BrowserIDManager(); @@ -336,15 +257,3 @@ this.add_identity_test = function(test, testFunction) { Status.__authManager = ns.Service.identity = oldIdentity; }); } - -this.sumHistogram = function(name, options = {}) { - let histogram = options.key ? Services.telemetry.getKeyedHistogramById(name) : - Services.telemetry.getHistogramById(name); - let snapshot = histogram.snapshot(options.key); - let sum = -Infinity; - if (snapshot) { - sum = snapshot.sum; - } - histogram.clear(); - return sum; -} |