From dfeafaaa0cb58385b0036d8b89ab4b65fa8f13f6 Mon Sep 17 00:00:00 2001 From: Hector Zhao Date: Tue, 26 Jan 2016 23:13:31 +0800 Subject: [PATCH] Bug 1242975 - Make services/sync eslintable. r=markh --- services/sync/modules-testing/utils.js | 4 +- services/sync/modules/browserid_identity.js | 5 +- services/sync/modules/engines.js | 65 ++++++++++----- services/sync/modules/engines/bookmarks.js | 14 +++- services/sync/modules/engines/history.js | 5 +- services/sync/modules/engines/passwords.js | 5 +- services/sync/modules/identity.js | 5 +- services/sync/modules/policies.js | 5 +- services/sync/modules/record.js | 5 +- services/sync/modules/resource.js | 10 ++- services/sync/modules/util.js | 10 ++- .../sync/tests/unit/test_bookmark_engine.js | 2 +- .../tests/unit/test_browserid_identity.js | 24 +++--- .../tests/unit/test_collections_recovery.js | 2 +- services/sync/tests/unit/test_corrupt_keys.js | 2 +- services/sync/tests/unit/test_errorhandler.js | 82 +++++++++---------- .../sync/tests/unit/test_errorhandler_eol.js | 8 +- ...test_errorhandler_sync_checkServerError.js | 16 ++-- .../tests/unit/test_fxa_node_reassignment.js | 18 ++-- .../tests/unit/test_fxa_service_cluster.js | 2 +- .../sync/tests/unit/test_interval_triggers.js | 12 +-- .../sync/tests/unit/test_node_reassignment.js | 19 +++-- .../sync/tests/unit/test_service_startOver.js | 2 +- .../tests/unit/test_service_wipeServer.js | 14 ++-- .../sync/tests/unit/test_syncscheduler.js | 52 ++++++------ .../mozmill/resource/driver/controller.js | 5 +- .../mozmill/resource/modules/assertions.js | 5 +- .../resource/stdlib/securable-module.js | 5 +- 28 files changed, 234 insertions(+), 169 deletions(-) diff --git a/services/sync/modules-testing/utils.js b/services/sync/modules-testing/utils.js index bb2729b8ece..fd945058686 100644 --- a/services/sync/modules-testing/utils.js +++ b/services/sync/modules-testing/utils.js @@ -316,7 +316,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(); @@ -324,7 +324,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(); diff --git a/services/sync/modules/browserid_identity.js b/services/sync/modules/browserid_identity.js index ac515746476..4ec08cce3a6 100644 --- a/services/sync/modules/browserid_identity.js +++ b/services/sync/modules/browserid_identity.js @@ -694,7 +694,10 @@ this.BrowserIDManager.prototype = { // expected. try { cb.wait(); - } catch (ex if !Async.isShutdownException(ex)) { + } catch (ex) { + if (Async.isShutdownException(ex)) { + throw ex; + } this._log.error("Failed to fetch a token for authentication", ex); return null; } diff --git a/services/sync/modules/engines.js b/services/sync/modules/engines.js index 43df14ce925..5321e3d4308 100644 --- a/services/sync/modules/engines.js +++ b/services/sync/modules/engines.js @@ -301,12 +301,16 @@ Store.prototype = { for (let record of records) { try { this.applyIncoming(record); - } catch (ex if (ex.code == Engine.prototype.eEngineAbortApplyIncoming)) { - // This kind of exception should have a 'cause' attribute, which is an - // originating exception. - // ex.cause will carry its stack with it when rethrown. - throw ex.cause; - } catch (ex if !Async.isShutdownException(ex)) { + } catch (ex) { + if (ex.code == Engine.prototype.eEngineAbortApplyIncoming) { + // This kind of exception should have a 'cause' attribute, which is an + // originating exception. + // ex.cause will carry its stack with it when rethrown. + throw ex.cause; + } + if (Async.isShutdownException(ex)) { + throw ex; + } this._log.warn("Failed to apply incoming record " + record.id, ex); this.engine._noteApplyFailure(); failed.push(record.id); @@ -990,7 +994,10 @@ SyncEngine.prototype = { this._tracker.ignoreAll = true; try { failed = failed.concat(this._store.applyIncomingBatch(applyBatch)); - } catch (ex if !Async.isShutdownException(ex)) { + } catch (ex) { + if (Async.isShutdownException(ex)) { + throw ex; + } // Catch any error that escapes from applyIncomingBatch. At present // those will all be abort events. this._log.warn("Got exception, aborting processIncoming", ex); @@ -1038,7 +1045,10 @@ SyncEngine.prototype = { try { try { item.decrypt(key); - } catch (ex if Utils.isHMACMismatch(ex)) { + } catch (ex) { + if (!Utils.isHMACMismatch(ex)) { + throw ex; + } let strategy = self.handleHMACMismatch(item, true); if (strategy == SyncEngine.kRecoveryStrategy.retry) { // You only get one retry. @@ -1048,7 +1058,10 @@ SyncEngine.prototype = { key = self.service.collectionKeys.keyForCollection(self.name); item.decrypt(key); strategy = null; - } catch (ex if Utils.isHMACMismatch(ex)) { + } catch (ex) { + if (!Utils.isHMACMismatch(ex)) { + throw ex; + } strategy = self.handleHMACMismatch(item, false); } } @@ -1081,16 +1094,20 @@ SyncEngine.prototype = { let shouldApply; try { shouldApply = self._reconcile(item); - } catch (ex if (ex.code == Engine.prototype.eEngineAbortApplyIncoming)) { - self._log.warn("Reconciliation failed: aborting incoming processing."); - self._noteApplyFailure(); - failed.push(item.id); - aborting = ex.cause; - } catch (ex if !Async.isShutdownException(ex)) { - self._log.warn("Failed to reconcile incoming record " + item.id, ex); - self._noteApplyFailure(); - failed.push(item.id); - return; + } catch (ex) { + if (ex.code == Engine.prototype.eEngineAbortApplyIncoming) { + self._log.warn("Reconciliation failed: aborting incoming processing."); + self._noteApplyFailure(); + failed.push(item.id); + aborting = ex.cause; + } else if (!Async.isShutdownException(ex)) { + self._log.warn("Failed to reconcile incoming record " + item.id, ex); + self._noteApplyFailure(); + failed.push(item.id); + return; + } else { + throw ex; + } } if (shouldApply) { @@ -1471,7 +1488,10 @@ SyncEngine.prototype = { out.encrypt(this.service.collectionKeys.keyForCollection(this.name)); ok = true; - } catch (ex if !Async.isShutdownException(ex)) { + } catch (ex) { + if (Async.isShutdownException(ex)) { + throw ex; + } this._log.warn("Error creating record", ex); } if (ok) { @@ -1557,7 +1577,10 @@ SyncEngine.prototype = { try { this._log.trace("Trying to decrypt a record from the server.."); test.get(); - } catch (ex if !Async.isShutdownException(ex)) { + } catch (ex) { + if (Async.isShutdownException(ex)) { + throw ex; + } this._log.debug("Failed test decrypt", ex); } diff --git a/services/sync/modules/engines/bookmarks.js b/services/sync/modules/engines/bookmarks.js index f9c5165b772..6e80457ac15 100644 --- a/services/sync/modules/engines/bookmarks.js +++ b/services/sync/modules/engines/bookmarks.js @@ -256,7 +256,10 @@ BookmarksEngine.prototype = { stmt.params.id = id; let rows = Async.querySpinningly(stmt, ["url"]); url = rows.length == 0 ? "" : rows[0].url; - } catch (ex if !Async.isShutdownException(ex)) { + } catch (ex) { + if (Async.isShutdownException(ex)) { + throw ex; + } if (ex instanceof Ci.mozIStorageError) { url = ``; } else { @@ -414,7 +417,7 @@ BookmarksEngine.prototype = { SyncEngine.prototype._syncStartup.call(this); let cb = Async.makeSpinningCallback(); - Task.spawn(function() { + Task.spawn(function* () { // For first-syncs, make a backup for the user to restore if (this.lastSync == 0) { this._log.debug("Bookmarks backup starting."); @@ -440,7 +443,10 @@ BookmarksEngine.prototype = { let guidMap; try { guidMap = this._buildGUIDMap(); - } catch (ex if !Async.isShutdownException(ex)) { + } catch (ex) { + if (Async.isShutdownException(ex)) { + throw ex; + } this._log.warn("Error while building GUID map, skipping all other incoming items", ex); throw {code: Engine.prototype.eEngineAbortApplyIncoming, cause: ex}; @@ -1367,7 +1373,7 @@ BookmarksStore.prototype = { wipe: function BStore_wipe() { let cb = Async.makeSpinningCallback(); - Task.spawn(function() { + Task.spawn(function* () { // Save a backup before clearing out all bookmarks. yield PlacesBackups.create(null, true); for (let guid of kSpecialIds.guids) diff --git a/services/sync/modules/engines/history.js b/services/sync/modules/engines/history.js index 62c999533d9..7232710f756 100644 --- a/services/sync/modules/engines/history.js +++ b/services/sync/modules/engines/history.js @@ -223,7 +223,10 @@ HistoryStore.prototype = { } else { shouldApply = this._recordToPlaceInfo(record); } - } catch (ex if !Async.isShutdownException(ex)) { + } catch (ex) { + if (Async.isShutdownException(ex)) { + throw ex; + } failed.push(record.id); shouldApply = false; } diff --git a/services/sync/modules/engines/passwords.js b/services/sync/modules/engines/passwords.js index b6d155556dc..a11d19a9b43 100644 --- a/services/sync/modules/engines/passwords.js +++ b/services/sync/modules/engines/passwords.js @@ -68,7 +68,10 @@ PasswordEngine.prototype = { // record success. Svc.Prefs.set("deletePwdFxA", true); Svc.Prefs.reset("deletePwd"); // The old prefname we previously used. - } catch (ex if !Async.isShutdownException(ex)) { + } catch (ex) { + if (Async.isShutdownException(ex)) { + throw ex; + } this._log.debug("Password deletes failed", ex); } } diff --git a/services/sync/modules/identity.js b/services/sync/modules/identity.js index f6d52bd0f79..b4da8c0bb24 100644 --- a/services/sync/modules/identity.js +++ b/services/sync/modules/identity.js @@ -446,7 +446,10 @@ IdentityManager.prototype = { // cache. try { service.recordManager.get(service.storageURL + "meta/fxa_credentials"); - } catch (ex if !Async.isShutdownException(ex)) { + } catch (ex) { + if (Async.isShutdownException(ex)) { + throw ex; + } this._log.warn("Failed to pre-fetch the migration sentinel", ex); } }, diff --git a/services/sync/modules/policies.js b/services/sync/modules/policies.js index 124cc3493d2..f1ad243f223 100644 --- a/services/sync/modules/policies.js +++ b/services/sync/modules/policies.js @@ -239,7 +239,10 @@ SyncScheduler.prototype = { this.setDefaults(); try { Svc.Idle.removeIdleObserver(this, Svc.Prefs.get("scheduler.idleTime")); - } catch (ex if (ex.result == Cr.NS_ERROR_FAILURE)) { + } catch (ex) { + if (ex.result != Cr.NS_ERROR_FAILURE) { + throw ex; + } // In all likelihood we didn't have an idle observer registered yet. // It's all good. } diff --git a/services/sync/modules/record.js b/services/sync/modules/record.js index aa80f730e15..3117320940c 100644 --- a/services/sync/modules/record.js +++ b/services/sync/modules/record.js @@ -238,7 +238,10 @@ RecordManager.prototype = { record.deserialize(this.response); return this.set(url, record); - } catch (ex if !Async.isShutdownException(ex)) { + } catch (ex) { + if (Async.isShutdownException(ex)) { + throw ex; + } this._log.debug("Failed to import record", ex); return null; } diff --git a/services/sync/modules/resource.js b/services/sync/modules/resource.js index 8556072e00b..c9b6e87ac9d 100644 --- a/services/sync/modules/resource.js +++ b/services/sync/modules/resource.js @@ -396,7 +396,10 @@ Resource.prototype = { try { this._doRequest(action, data, callback); return Async.waitForSyncCallback(cb); - } catch (ex if !Async.isShutdownException(ex)) { + } catch (ex) { + if (Async.isShutdownException(ex)) { + throw ex; + } // Combine the channel stack with this request stack. Need to create // a new error object for that. let error = Error(ex.message); @@ -549,7 +552,10 @@ ChannelListener.prototype = { try { this._onProgress(); - } catch (ex if !Async.isShutdownException(ex)) { + } catch (ex) { + if (Async.isShutdownException(ex)) { + throw ex; + } this._log.warn("Got exception calling onProgress handler during fetch of " + req.URI.spec, ex); this._log.trace("Rethrowing; expect a failure code from the HTTP channel."); diff --git a/services/sync/modules/util.js b/services/sync/modules/util.js index 67da28180af..748e05196ec 100644 --- a/services/sync/modules/util.js +++ b/services/sync/modules/util.js @@ -336,11 +336,13 @@ this.Utils = { try { json = yield CommonUtils.readJSON(path); - } catch (e if e instanceof OS.File.Error && e.becauseNoSuchFile) { - // Ignore non-existent files. } catch (e) { - if (that._log) { - that._log.debug("Failed to load json", e); + if (e instanceof OS.File.Error && e.becauseNoSuchFile) { + // Ignore non-existent files. + } else { + if (that._log) { + that._log.debug("Failed to load json", e); + } } } diff --git a/services/sync/tests/unit/test_bookmark_engine.js b/services/sync/tests/unit/test_bookmark_engine.js index f20b6966779..97af659ae61 100644 --- a/services/sync/tests/unit/test_bookmark_engine.js +++ b/services/sync/tests/unit/test_bookmark_engine.js @@ -167,7 +167,7 @@ add_test(function test_processIncoming_error_orderChildren() { } }); -add_task(function test_restorePromptsReupload() { +add_task(function* test_restorePromptsReupload() { _("Ensure that restoring from a backup will reupload all records."); let engine = new BookmarksEngine(Service); let store = engine._store; diff --git a/services/sync/tests/unit/test_browserid_identity.js b/services/sync/tests/unit/test_browserid_identity.js index 7b83771a24a..4001a869ae1 100644 --- a/services/sync/tests/unit/test_browserid_identity.js +++ b/services/sync/tests/unit/test_browserid_identity.js @@ -76,7 +76,7 @@ add_test(function test_initial_state() { } ); -add_task(function test_initialializeWithCurrentIdentity() { +add_task(function* test_initialializeWithCurrentIdentity() { _("Verify start after initializeWithCurrentIdentity"); browseridManager.initializeWithCurrentIdentity(); yield browseridManager.whenReadyToAuthenticate.promise; @@ -86,7 +86,7 @@ add_task(function test_initialializeWithCurrentIdentity() { } ); -add_task(function test_initialializeWithAuthErrorAndDeletedAccount() { +add_task(function* test_initialializeWithAuthErrorAndDeletedAccount() { _("Verify sync unpair after initializeWithCurrentIdentity with auth error + account deleted"); browseridManager._fxaService.internal.initialize(); @@ -127,7 +127,7 @@ add_task(function test_initialializeWithAuthErrorAndDeletedAccount() { browseridManager._fetchTokenForUser = oldFetchTokenForUser; }); -add_task(function test_initialializeWithNoKeys() { +add_task(function* test_initialializeWithNoKeys() { _("Verify start after initializeWithCurrentIdentity without kA, kB or keyFetchToken"); let identityConfig = makeIdentityConfig(); delete identityConfig.fxaccount.user.kA; @@ -296,7 +296,7 @@ add_test(function test_RESTResourceAuthenticatorSkew() { run_next_test(); }); -add_task(function test_ensureLoggedIn() { +add_task(function* test_ensureLoggedIn() { configureFxAccountIdentity(browseridManager); yield browseridManager.initializeWithCurrentIdentity(); yield browseridManager.whenReadyToAuthenticate.promise; @@ -394,7 +394,7 @@ add_test(function test_computeXClientStateHeader() { run_next_test(); }); -add_task(function test_getTokenErrors() { +add_task(function* test_getTokenErrors() { _("BrowserIDManager correctly handles various failures to get a token."); _("Arrange for a 401 - Sync should reflect an auth error."); @@ -433,7 +433,7 @@ add_task(function test_getTokenErrors() { Assert.equal(keyFetchErrorCount, 0, "Should not record key fetch errors for invalid responses"); }); -add_task(function test_getTokenErrorWithRetry() { +add_task(function* test_getTokenErrorWithRetry() { _("tokenserver sends an observer notification on various backoff headers."); // Set Sync's backoffInterval to zero - after we simulated the backoff header @@ -481,7 +481,7 @@ add_task(function test_getTokenErrorWithRetry() { Assert.equal(keyFetchErrorCount, 0, "Should not record key fetch errors for 503/backoff response from FxA"); }); -add_task(function test_getKeysErrorWithBackoff() { +add_task(function* test_getKeysErrorWithBackoff() { _("Auth server (via hawk) sends an observer notification on backoff headers."); // Set Sync's backoffInterval to zero - after we simulated the backoff header @@ -518,7 +518,7 @@ add_task(function test_getKeysErrorWithBackoff() { Assert.equal(keyFetchErrorCount, 0, "Should not record key fetch errors for 503 from FxA"); }); -add_task(function test_getKeysErrorWithRetry() { +add_task(function* test_getKeysErrorWithRetry() { _("Auth server (via hawk) sends an observer notification on retry headers."); // Set Sync's backoffInterval to zero - after we simulated the backoff header @@ -555,7 +555,7 @@ add_task(function test_getKeysErrorWithRetry() { Assert.equal(keyFetchErrorCount, 0, "Should not record key fetch errors for 503 from FxA"); }); -add_task(function test_getHAWKErrors() { +add_task(function* test_getHAWKErrors() { _("BrowserIDManager correctly handles various HAWK failures."); _("Arrange for a 401 - Sync should reflect an auth error."); @@ -594,7 +594,7 @@ add_task(function test_getHAWKErrors() { Assert.equal(keyFetchErrorCount, 0, "Should not record key fetch errors for invalid response from FxA"); }); -add_task(function test_getGetKeysFailing401() { +add_task(function* test_getGetKeysFailing401() { _("BrowserIDManager correctly handles 401 responses fetching keys."); _("Arrange for a 401 - Sync should reflect an auth error."); @@ -618,7 +618,7 @@ add_task(function test_getGetKeysFailing401() { Assert.equal(keyFetchErrorCount, 1, "Should record key fetch errors for 401 from FxA"); }); -add_task(function test_getGetKeysFailing503() { +add_task(function* test_getGetKeysFailing503() { _("BrowserIDManager correctly handles 5XX responses fetching keys."); _("Arrange for a 503 - Sync should reflect a network error."); @@ -642,7 +642,7 @@ add_task(function test_getGetKeysFailing503() { Assert.equal(keyFetchErrorCount, 0, "Should not record key fetch errors for 503 from FxA"); }); -add_task(function test_getKeysMissing() { +add_task(function* test_getKeysMissing() { _("BrowserIDManager correctly handles getKeys succeeding but not returning keys."); let browseridManager = new BrowserIDManager(); diff --git a/services/sync/tests/unit/test_collections_recovery.js b/services/sync/tests/unit/test_collections_recovery.js index 06ec0ab8c16..3d1cac3116d 100644 --- a/services/sync/tests/unit/test_collections_recovery.js +++ b/services/sync/tests/unit/test_collections_recovery.js @@ -6,7 +6,7 @@ Cu.import("resource://services-sync/service.js"); Cu.import("resource://services-sync/util.js"); Cu.import("resource://testing-common/services/sync/utils.js"); -add_identity_test(this, function test_missing_crypto_collection() { +add_identity_test(this, function* test_missing_crypto_collection() { let johnHelper = track_collections_helper(); let johnU = johnHelper.with_updated_collection; let johnColls = johnHelper.collections; diff --git a/services/sync/tests/unit/test_corrupt_keys.js b/services/sync/tests/unit/test_corrupt_keys.js index cce01636170..57de922dfa1 100644 --- a/services/sync/tests/unit/test_corrupt_keys.js +++ b/services/sync/tests/unit/test_corrupt_keys.js @@ -14,7 +14,7 @@ Cu.import("resource://services-sync/util.js"); Cu.import("resource://testing-common/services/sync/utils.js"); Cu.import("resource://gre/modules/Promise.jsm"); -add_task(function test_locally_changed_keys() { +add_task(function* test_locally_changed_keys() { let passphrase = "abcdeabcdeabcdeabcdeabcdea"; let hmacErrorCount = 0; diff --git a/services/sync/tests/unit/test_errorhandler.js b/services/sync/tests/unit/test_errorhandler.js index 7a19df0d6de..fd7fd3e314e 100644 --- a/services/sync/tests/unit/test_errorhandler.js +++ b/services/sync/tests/unit/test_errorhandler.js @@ -161,7 +161,7 @@ function clean() { errorHandler.didReportProlongedError = false; } -add_identity_test(this, function test_401_logout() { +add_identity_test(this, function* test_401_logout() { let server = sync_httpd_setup(); yield setUp(server); @@ -206,7 +206,7 @@ add_identity_test(this, function test_401_logout() { yield deferred.promise; }); -add_identity_test(this, function test_credentials_changed_logout() { +add_identity_test(this, function* test_credentials_changed_logout() { let server = sync_httpd_setup(); yield setUp(server); @@ -456,7 +456,7 @@ add_identity_test(this, function test_shouldReportError() { do_check_false(errorHandler.didReportProlongedError); }); -add_identity_test(this, function test_shouldReportError_master_password() { +add_identity_test(this, function* test_shouldReportError_master_password() { _("Test error ignored due to locked master password"); let server = sync_httpd_setup(); yield setUp(server); @@ -501,7 +501,7 @@ add_identity_test(this, function test_shouldReportLoginFailureWithNoCluster() { // XXX - how to arrange for 'Service.identity.basicPassword = null;' in // an fxaccounts environment? -add_task(function test_login_syncAndReportErrors_non_network_error() { +add_task(function* test_login_syncAndReportErrors_non_network_error() { // Test non-network errors are reported // when calling syncAndReportErrors let server = sync_httpd_setup(); @@ -522,7 +522,7 @@ add_task(function test_login_syncAndReportErrors_non_network_error() { yield deferred.promise; }); -add_identity_test(this, function test_sync_syncAndReportErrors_non_network_error() { +add_identity_test(this, function* test_sync_syncAndReportErrors_non_network_error() { // Test non-network errors are reported // when calling syncAndReportErrors let server = sync_httpd_setup(); @@ -551,7 +551,7 @@ add_identity_test(this, function test_sync_syncAndReportErrors_non_network_error // XXX - how to arrange for 'Service.identity.basicPassword = null;' in // an fxaccounts environment? -add_task(function test_login_syncAndReportErrors_prolonged_non_network_error() { +add_task(function* test_login_syncAndReportErrors_prolonged_non_network_error() { // Test prolonged, non-network errors are // reported when calling syncAndReportErrors. let server = sync_httpd_setup(); @@ -572,7 +572,7 @@ add_task(function test_login_syncAndReportErrors_prolonged_non_network_error() { yield deferred.promise; }); -add_identity_test(this, function test_sync_syncAndReportErrors_prolonged_non_network_error() { +add_identity_test(this, function* test_sync_syncAndReportErrors_prolonged_non_network_error() { // Test prolonged, non-network errors are // reported when calling syncAndReportErrors. let server = sync_httpd_setup(); @@ -599,7 +599,7 @@ add_identity_test(this, function test_sync_syncAndReportErrors_prolonged_non_net yield deferred.promise; }); -add_identity_test(this, function test_login_syncAndReportErrors_network_error() { +add_identity_test(this, function* test_login_syncAndReportErrors_network_error() { // Test network errors are reported when calling syncAndReportErrors. yield configureIdentity({username: "broken.wipe"}); Service.serverURL = fakeServerUrl; @@ -637,7 +637,7 @@ add_test(function test_sync_syncAndReportErrors_network_error() { errorHandler.syncAndReportErrors(); }); -add_identity_test(this, function test_login_syncAndReportErrors_prolonged_network_error() { +add_identity_test(this, function* test_login_syncAndReportErrors_prolonged_network_error() { // Test prolonged, network errors are reported // when calling syncAndReportErrors. yield configureIdentity({username: "johndoe"}); @@ -677,7 +677,7 @@ add_test(function test_sync_syncAndReportErrors_prolonged_network_error() { errorHandler.syncAndReportErrors(); }); -add_task(function test_login_prolonged_non_network_error() { +add_task(function* test_login_prolonged_non_network_error() { // Test prolonged, non-network errors are reported let server = sync_httpd_setup(); yield setUp(server); @@ -698,7 +698,7 @@ add_task(function test_login_prolonged_non_network_error() { yield deferred.promise; }); -add_task(function test_sync_prolonged_non_network_error() { +add_task(function* test_sync_prolonged_non_network_error() { // Test prolonged, non-network errors are reported let server = sync_httpd_setup(); yield setUp(server); @@ -725,7 +725,7 @@ add_task(function test_sync_prolonged_non_network_error() { yield deferred.promise; }); -add_identity_test(this, function test_login_prolonged_network_error() { +add_identity_test(this, function* test_login_prolonged_network_error() { // Test prolonged, network errors are reported yield configureIdentity({username: "johndoe"}); Service.serverURL = fakeServerUrl; @@ -764,7 +764,7 @@ add_test(function test_sync_prolonged_network_error() { Service.sync(); }); -add_task(function test_login_non_network_error() { +add_task(function* test_login_non_network_error() { // Test non-network errors are reported let server = sync_httpd_setup(); yield setUp(server); @@ -785,7 +785,7 @@ add_task(function test_login_non_network_error() { yield deferred.promise; }); -add_task(function test_sync_non_network_error() { +add_task(function* test_sync_non_network_error() { // Test non-network errors are reported let server = sync_httpd_setup(); yield setUp(server); @@ -812,7 +812,7 @@ add_task(function test_sync_non_network_error() { yield deferred.promise; }); -add_identity_test(this, function test_login_network_error() { +add_identity_test(this, function* test_login_network_error() { yield configureIdentity({username: "johndoe"}); Service.serverURL = fakeServerUrl; Service.clusterURL = fakeServerUrl; @@ -853,7 +853,7 @@ add_test(function test_sync_network_error() { Service.sync(); }); -add_identity_test(this, function test_sync_server_maintenance_error() { +add_identity_test(this, function* test_sync_server_maintenance_error() { // Test server maintenance errors are not reported. let server = sync_httpd_setup(); yield setUp(server); @@ -889,7 +889,7 @@ add_identity_test(this, function test_sync_server_maintenance_error() { yield deferred.promise; }); -add_identity_test(this, function test_info_collections_login_server_maintenance_error() { +add_identity_test(this, function* test_info_collections_login_server_maintenance_error() { // Test info/collections server maintenance errors are not reported. let server = sync_httpd_setup(); yield setUp(server); @@ -933,7 +933,7 @@ add_identity_test(this, function test_info_collections_login_server_maintenance_ yield deferred.promise; }); -add_identity_test(this, function test_meta_global_login_server_maintenance_error() { +add_identity_test(this, function* test_meta_global_login_server_maintenance_error() { // Test meta/global server maintenance errors are not reported. let server = sync_httpd_setup(); yield setUp(server); @@ -976,7 +976,7 @@ add_identity_test(this, function test_meta_global_login_server_maintenance_error yield deferred.promise; }); -add_identity_test(this, function test_crypto_keys_login_server_maintenance_error() { +add_identity_test(this, function* test_crypto_keys_login_server_maintenance_error() { // Test crypto/keys server maintenance errors are not reported. let server = sync_httpd_setup(); yield setUp(server); @@ -1022,7 +1022,7 @@ add_identity_test(this, function test_crypto_keys_login_server_maintenance_error yield deferred.promise; }); -add_task(function test_sync_prolonged_server_maintenance_error() { +add_task(function* test_sync_prolonged_server_maintenance_error() { // Test prolonged server maintenance errors are reported. let server = sync_httpd_setup(); yield setUp(server); @@ -1051,7 +1051,7 @@ add_task(function test_sync_prolonged_server_maintenance_error() { yield deferred.promise; }); -add_identity_test(this, function test_info_collections_login_prolonged_server_maintenance_error(){ +add_identity_test(this, function* test_info_collections_login_prolonged_server_maintenance_error(){ // Test info/collections prolonged server maintenance errors are reported. let server = sync_httpd_setup(); yield setUp(server); @@ -1087,7 +1087,7 @@ add_identity_test(this, function test_info_collections_login_prolonged_server_ma yield deferred.promise; }); -add_identity_test(this, function test_meta_global_login_prolonged_server_maintenance_error(){ +add_identity_test(this, function* test_meta_global_login_prolonged_server_maintenance_error(){ // Test meta/global prolonged server maintenance errors are reported. let server = sync_httpd_setup(); yield setUp(server); @@ -1123,7 +1123,7 @@ add_identity_test(this, function test_meta_global_login_prolonged_server_mainten yield deferred.promise; }); -add_identity_test(this, function test_download_crypto_keys_login_prolonged_server_maintenance_error(){ +add_identity_test(this, function* test_download_crypto_keys_login_prolonged_server_maintenance_error(){ // Test crypto/keys prolonged server maintenance errors are reported. let server = sync_httpd_setup(); yield setUp(server); @@ -1161,7 +1161,7 @@ add_identity_test(this, function test_download_crypto_keys_login_prolonged_serve yield deferred.promise; }); -add_identity_test(this, function test_upload_crypto_keys_login_prolonged_server_maintenance_error(){ +add_identity_test(this, function* test_upload_crypto_keys_login_prolonged_server_maintenance_error(){ // Test crypto/keys prolonged server maintenance errors are reported. let server = sync_httpd_setup(); @@ -1197,7 +1197,7 @@ add_identity_test(this, function test_upload_crypto_keys_login_prolonged_server_ yield deferred.promise; }); -add_identity_test(this, function test_wipeServer_login_prolonged_server_maintenance_error(){ +add_identity_test(this, function* test_wipeServer_login_prolonged_server_maintenance_error(){ // Test that we report prolonged server maintenance errors that occur whilst // wiping the server. let server = sync_httpd_setup(); @@ -1234,7 +1234,7 @@ add_identity_test(this, function test_wipeServer_login_prolonged_server_maintena yield deferred.promise; }); -add_identity_test(this, function test_wipeRemote_prolonged_server_maintenance_error(){ +add_identity_test(this, function* test_wipeRemote_prolonged_server_maintenance_error(){ // Test that we report prolonged server maintenance errors that occur whilst // wiping all remote devices. let server = sync_httpd_setup(); @@ -1278,7 +1278,7 @@ add_identity_test(this, function test_wipeRemote_prolonged_server_maintenance_er yield deferred.promise; }); -add_task(function test_sync_syncAndReportErrors_server_maintenance_error() { +add_task(function* test_sync_syncAndReportErrors_server_maintenance_error() { // Test server maintenance errors are reported // when calling syncAndReportErrors. let server = sync_httpd_setup(); @@ -1308,7 +1308,7 @@ add_task(function test_sync_syncAndReportErrors_server_maintenance_error() { yield deferred.promise; }); -add_identity_test(this, function test_info_collections_login_syncAndReportErrors_server_maintenance_error() { +add_identity_test(this, function* test_info_collections_login_syncAndReportErrors_server_maintenance_error() { // Test info/collections server maintenance errors are reported // when calling syncAndReportErrors. let server = sync_httpd_setup(); @@ -1345,7 +1345,7 @@ add_identity_test(this, function test_info_collections_login_syncAndReportErrors yield deferred.promise; }); -add_identity_test(this, function test_meta_global_login_syncAndReportErrors_server_maintenance_error() { +add_identity_test(this, function* test_meta_global_login_syncAndReportErrors_server_maintenance_error() { // Test meta/global server maintenance errors are reported // when calling syncAndReportErrors. let server = sync_httpd_setup(); @@ -1382,7 +1382,7 @@ add_identity_test(this, function test_meta_global_login_syncAndReportErrors_serv yield deferred.promise; }); -add_identity_test(this, function test_download_crypto_keys_login_syncAndReportErrors_server_maintenance_error() { +add_identity_test(this, function* test_download_crypto_keys_login_syncAndReportErrors_server_maintenance_error() { // Test crypto/keys server maintenance errors are reported // when calling syncAndReportErrors. let server = sync_httpd_setup(); @@ -1421,7 +1421,7 @@ add_identity_test(this, function test_download_crypto_keys_login_syncAndReportEr yield deferred.promise; }); -add_identity_test(this, function test_upload_crypto_keys_login_syncAndReportErrors_server_maintenance_error() { +add_identity_test(this, function* test_upload_crypto_keys_login_syncAndReportErrors_server_maintenance_error() { // Test crypto/keys server maintenance errors are reported // when calling syncAndReportErrors. let server = sync_httpd_setup(); @@ -1458,7 +1458,7 @@ add_identity_test(this, function test_upload_crypto_keys_login_syncAndReportErro yield deferred.promise; }); -add_identity_test(this, function test_wipeServer_login_syncAndReportErrors_server_maintenance_error() { +add_identity_test(this, function* test_wipeServer_login_syncAndReportErrors_server_maintenance_error() { // Test crypto/keys server maintenance errors are reported // when calling syncAndReportErrors. let server = sync_httpd_setup(); @@ -1495,7 +1495,7 @@ add_identity_test(this, function test_wipeServer_login_syncAndReportErrors_serve yield deferred.promise; }); -add_identity_test(this, function test_wipeRemote_syncAndReportErrors_server_maintenance_error(){ +add_identity_test(this, function* test_wipeRemote_syncAndReportErrors_server_maintenance_error(){ // Test that we report prolonged server maintenance errors that occur whilst // wiping all remote devices. let server = sync_httpd_setup(); @@ -1538,7 +1538,7 @@ add_identity_test(this, function test_wipeRemote_syncAndReportErrors_server_main yield deferred.promise; }); -add_task(function test_sync_syncAndReportErrors_prolonged_server_maintenance_error() { +add_task(function* test_sync_syncAndReportErrors_prolonged_server_maintenance_error() { // Test prolonged server maintenance errors are // reported when calling syncAndReportErrors. let server = sync_httpd_setup(); @@ -1570,7 +1570,7 @@ add_task(function test_sync_syncAndReportErrors_prolonged_server_maintenance_err yield deferred.promise; }); -add_identity_test(this, function test_info_collections_login_syncAndReportErrors_prolonged_server_maintenance_error() { +add_identity_test(this, function* test_info_collections_login_syncAndReportErrors_prolonged_server_maintenance_error() { // Test info/collections server maintenance errors are reported // when calling syncAndReportErrors. let server = sync_httpd_setup(); @@ -1609,7 +1609,7 @@ add_identity_test(this, function test_info_collections_login_syncAndReportErrors yield deferred.promise; }); -add_identity_test(this, function test_meta_global_login_syncAndReportErrors_prolonged_server_maintenance_error() { +add_identity_test(this, function* test_meta_global_login_syncAndReportErrors_prolonged_server_maintenance_error() { // Test meta/global server maintenance errors are reported // when calling syncAndReportErrors. let server = sync_httpd_setup(); @@ -1648,7 +1648,7 @@ add_identity_test(this, function test_meta_global_login_syncAndReportErrors_prol yield deferred.promise; }); -add_identity_test(this, function test_download_crypto_keys_login_syncAndReportErrors_prolonged_server_maintenance_error() { +add_identity_test(this, function* test_download_crypto_keys_login_syncAndReportErrors_prolonged_server_maintenance_error() { // Test crypto/keys server maintenance errors are reported // when calling syncAndReportErrors. let server = sync_httpd_setup(); @@ -1689,7 +1689,7 @@ add_identity_test(this, function test_download_crypto_keys_login_syncAndReportEr yield deferred.promise; }); -add_identity_test(this, function test_upload_crypto_keys_login_syncAndReportErrors_prolonged_server_maintenance_error() { +add_identity_test(this, function* test_upload_crypto_keys_login_syncAndReportErrors_prolonged_server_maintenance_error() { // Test crypto/keys server maintenance errors are reported // when calling syncAndReportErrors. let server = sync_httpd_setup(); @@ -1728,7 +1728,7 @@ add_identity_test(this, function test_upload_crypto_keys_login_syncAndReportErro yield deferred.promise; }); -add_identity_test(this, function test_wipeServer_login_syncAndReportErrors_prolonged_server_maintenance_error() { +add_identity_test(this, function* test_wipeServer_login_syncAndReportErrors_prolonged_server_maintenance_error() { // Test crypto/keys server maintenance errors are reported // when calling syncAndReportErrors. let server = sync_httpd_setup(); @@ -1767,7 +1767,7 @@ add_identity_test(this, function test_wipeServer_login_syncAndReportErrors_prolo yield deferred.promise; }); -add_task(function test_sync_engine_generic_fail() { +add_task(function* test_sync_engine_generic_fail() { let server = sync_httpd_setup(); let engine = engineManager.get("catapult"); @@ -1873,7 +1873,7 @@ add_test(function test_logs_on_login_error_despite_shouldReportError() { // This test should be the last one since it monkeypatches the engine object // and we should only have one engine object throughout the file (bug 629664). -add_task(function test_engine_applyFailed() { +add_task(function* test_engine_applyFailed() { let server = sync_httpd_setup(); let engine = engineManager.get("catapult"); diff --git a/services/sync/tests/unit/test_errorhandler_eol.js b/services/sync/tests/unit/test_errorhandler_eol.js index 381bc72687a..c8d2ff4be0c 100644 --- a/services/sync/tests/unit/test_errorhandler_eol.js +++ b/services/sync/tests/unit/test_errorhandler_eol.js @@ -43,7 +43,7 @@ function sync_httpd_setup(infoHandler) { return httpd_setup(handlers); } -function setUp(server) { +function* setUp(server) { yield configureIdentity({username: "johndoe"}); Service.serverURL = server.baseURI + "/"; Service.clusterURL = server.baseURI + "/"; @@ -66,7 +66,7 @@ function do_check_hard_eol(eh, start) { do_check_true(Status.eol); } -add_identity_test(this, function test_200_hard() { +add_identity_test(this, function* test_200_hard() { let eh = Service.errorHandler; let start = Date.now(); let server = sync_httpd_setup(handler200("hard-eol")); @@ -88,7 +88,7 @@ add_identity_test(this, function test_200_hard() { yield deferred.promise; }); -add_identity_test(this, function test_513_hard() { +add_identity_test(this, function* test_513_hard() { let eh = Service.errorHandler; let start = Date.now(); let server = sync_httpd_setup(handler513); @@ -114,7 +114,7 @@ add_identity_test(this, function test_513_hard() { yield deferred.promise; }); -add_identity_test(this, function test_200_soft() { +add_identity_test(this, function* test_200_soft() { let eh = Service.errorHandler; let start = Date.now(); let server = sync_httpd_setup(handler200("soft-eol")); diff --git a/services/sync/tests/unit/test_errorhandler_sync_checkServerError.js b/services/sync/tests/unit/test_errorhandler_sync_checkServerError.js index 89c666631ff..e2ab1603fb5 100644 --- a/services/sync/tests/unit/test_errorhandler_sync_checkServerError.js +++ b/services/sync/tests/unit/test_errorhandler_sync_checkServerError.js @@ -59,7 +59,7 @@ function sync_httpd_setup() { return httpd_setup(handlers); } -function setUp(server) { +function* setUp(server) { yield configureIdentity({username: "johndoe"}); Service.serverURL = server.baseURI + "/"; Service.clusterURL = server.baseURI + "/"; @@ -75,7 +75,7 @@ function generateAndUploadKeys(server) { } -add_identity_test(this, function test_backoff500() { +add_identity_test(this, function* test_backoff500() { _("Test: HTTP 500 sets backoff status."); let server = sync_httpd_setup(); yield setUp(server); @@ -102,7 +102,7 @@ add_identity_test(this, function test_backoff500() { yield promiseStopServer(server); }); -add_identity_test(this, function test_backoff503() { +add_identity_test(this, function* test_backoff503() { _("Test: HTTP 503 with Retry-After header leads to backoff notification and sets backoff status."); let server = sync_httpd_setup(); yield setUp(server); @@ -138,7 +138,7 @@ add_identity_test(this, function test_backoff503() { yield promiseStopServer(server); }); -add_identity_test(this, function test_overQuota() { +add_identity_test(this, function* test_overQuota() { _("Test: HTTP 400 with body error code 14 means over quota."); let server = sync_httpd_setup(); yield setUp(server); @@ -167,7 +167,7 @@ add_identity_test(this, function test_overQuota() { yield promiseStopServer(server); }); -add_identity_test(this, function test_service_networkError() { +add_identity_test(this, function* test_service_networkError() { _("Test: Connection refused error from Service.sync() leads to the right status code."); let server = sync_httpd_setup(); yield setUp(server); @@ -193,7 +193,7 @@ add_identity_test(this, function test_service_networkError() { yield deferred.promise; }); -add_identity_test(this, function test_service_offline() { +add_identity_test(this, function* test_service_offline() { _("Test: Wanting to sync in offline mode leads to the right status code but does not increment the ignorable error count."); let server = sync_httpd_setup(); yield setUp(server); @@ -221,7 +221,7 @@ add_identity_test(this, function test_service_offline() { yield deferred.promise; }); -add_identity_test(this, function test_engine_networkError() { +add_identity_test(this, function* test_engine_networkError() { _("Test: Network related exceptions from engine.sync() lead to the right status code."); let server = sync_httpd_setup(); yield setUp(server); @@ -248,7 +248,7 @@ add_identity_test(this, function test_engine_networkError() { yield promiseStopServer(server); }); -add_identity_test(this, function test_resource_timeout() { +add_identity_test(this, function* test_resource_timeout() { let server = sync_httpd_setup(); yield setUp(server); diff --git a/services/sync/tests/unit/test_fxa_node_reassignment.js b/services/sync/tests/unit/test_fxa_node_reassignment.js index c019d61f661..408be4b53b6 100644 --- a/services/sync/tests/unit/test_fxa_node_reassignment.js +++ b/services/sync/tests/unit/test_fxa_node_reassignment.js @@ -93,9 +93,10 @@ function prepareServer(cbAfterTokenFetch) { function getReassigned() { try { return Services.prefs.getBoolPref("services.sync.lastSyncReassigned"); - } catch (ex if (ex.result == Cr.NS_ERROR_UNEXPECTED)) { - return false; } catch (ex) { + if (ex.result == Cr.NS_ERROR_UNEXPECTED) { + return false; + } do_throw("Got exception retrieving lastSyncReassigned: " + Log.exceptionStr(ex)); } @@ -107,7 +108,7 @@ function getReassigned() { * Runs `between` between the two. This can be used to undo deliberate failure * setup, detach observers, etc. */ -function syncAndExpectNodeReassignment(server, firstNotification, between, +function* syncAndExpectNodeReassignment(server, firstNotification, between, secondNotification, url) { _("Starting syncAndExpectNodeReassignment\n"); let deferred = Promise.defer(); @@ -155,7 +156,7 @@ function syncAndExpectNodeReassignment(server, firstNotification, between, yield deferred.promise; } -add_task(function test_momentary_401_engine() { +add_task(function* test_momentary_401_engine() { _("Test a failure for engine URLs that's resolved by reassignment."); let server = yield prepareServer(); let john = server.user("johndoe"); @@ -207,7 +208,7 @@ add_task(function test_momentary_401_engine() { }); // This test ends up being a failing info fetch *after we're already logged in*. -add_task(function test_momentary_401_info_collections_loggedin() { +add_task(function* test_momentary_401_info_collections_loggedin() { _("Test a failure for info/collections after login that's resolved by reassignment."); let server = yield prepareServer(); @@ -235,7 +236,7 @@ add_task(function test_momentary_401_info_collections_loggedin() { // This test ends up being a failing info fetch *before we're logged in*. // In this case we expect to recover during the login phase - so the first // sync succeeds. -add_task(function test_momentary_401_info_collections_loggedout() { +add_task(function* test_momentary_401_info_collections_loggedout() { _("Test a failure for info/collections before login that's resolved by reassignment."); let oldHandler; @@ -269,7 +270,7 @@ add_task(function test_momentary_401_info_collections_loggedout() { }); // This test ends up being a failing meta/global fetch *after we're already logged in*. -add_task(function test_momentary_401_storage_loggedin() { +add_task(function* test_momentary_401_storage_loggedin() { _("Test a failure for any storage URL after login that's resolved by" + "reassignment."); let server = yield prepareServer(); @@ -296,7 +297,7 @@ add_task(function test_momentary_401_storage_loggedin() { }); // This test ends up being a failing meta/global fetch *before we've logged in*. -add_task(function test_momentary_401_storage_loggedout() { +add_task(function* test_momentary_401_storage_loggedout() { _("Test a failure for any storage URL before login, not just engine parts. " + "Resolved by reassignment."); let server = yield prepareServer(); @@ -318,4 +319,3 @@ add_task(function test_momentary_401_storage_loggedout() { "weave:service:sync:finish", Service.storageURL + "meta/global"); }); - diff --git a/services/sync/tests/unit/test_fxa_service_cluster.js b/services/sync/tests/unit/test_fxa_service_cluster.js index b8ffc1175e4..b4f83a7fe66 100644 --- a/services/sync/tests/unit/test_fxa_service_cluster.js +++ b/services/sync/tests/unit/test_fxa_service_cluster.js @@ -6,7 +6,7 @@ Cu.import("resource://services-sync/util.js"); Cu.import("resource://testing-common/services/sync/fxa_utils.js"); Cu.import("resource://testing-common/services/sync/utils.js"); -add_task(function test_findCluster() { +add_task(function* test_findCluster() { _("Test FxA _findCluster()"); _("_findCluster() throws on 500 errors."); diff --git a/services/sync/tests/unit/test_interval_triggers.js b/services/sync/tests/unit/test_interval_triggers.js index 6f944edf8aa..071ba63d380 100644 --- a/services/sync/tests/unit/test_interval_triggers.js +++ b/services/sync/tests/unit/test_interval_triggers.js @@ -41,7 +41,7 @@ function sync_httpd_setup() { }); } -function setUp(server) { +function* setUp(server) { yield configureIdentity({username: "johndoe"}); Service.serverURL = server.baseURI + "/"; Service.clusterURL = server.baseURI + "/"; @@ -60,7 +60,7 @@ function run_test() { run_next_test(); } -add_identity_test(this, function test_successful_sync_adjustSyncInterval() { +add_identity_test(this, function* test_successful_sync_adjustSyncInterval() { _("Test successful sync calling adjustSyncInterval"); let syncSuccesses = 0; function onSyncFinish() { @@ -159,7 +159,7 @@ add_identity_test(this, function test_successful_sync_adjustSyncInterval() { yield promiseStopServer(server); }); -add_identity_test(this, function test_unsuccessful_sync_adjustSyncInterval() { +add_identity_test(this, function* test_unsuccessful_sync_adjustSyncInterval() { _("Test unsuccessful sync calling adjustSyncInterval"); let syncFailures = 0; @@ -264,7 +264,7 @@ add_identity_test(this, function test_unsuccessful_sync_adjustSyncInterval() { yield promiseStopServer(server); }); -add_identity_test(this, function test_back_triggers_sync() { +add_identity_test(this, function* test_back_triggers_sync() { let server = sync_httpd_setup(); yield setUp(server); @@ -296,7 +296,7 @@ add_identity_test(this, function test_back_triggers_sync() { yield deferred.promise; }); -add_identity_test(this, function test_adjust_interval_on_sync_error() { +add_identity_test(this, function* test_adjust_interval_on_sync_error() { let server = sync_httpd_setup(); yield setUp(server); @@ -327,7 +327,7 @@ add_identity_test(this, function test_adjust_interval_on_sync_error() { yield promiseStopServer(server); }); -add_identity_test(this, function test_bug671378_scenario() { +add_identity_test(this, function* test_bug671378_scenario() { // Test scenario similar to bug 671378. This bug appeared when a score // update occurred that wasn't large enough to trigger a sync so // scheduleNextSync() was called without a time interval parameter, diff --git a/services/sync/tests/unit/test_node_reassignment.js b/services/sync/tests/unit/test_node_reassignment.js index 351e1bfcda1..c9dd12e939b 100644 --- a/services/sync/tests/unit/test_node_reassignment.js +++ b/services/sync/tests/unit/test_node_reassignment.js @@ -92,9 +92,10 @@ function prepareServer() { function getReassigned() { try { return Services.prefs.getBoolPref("services.sync.lastSyncReassigned"); - } catch (ex if (ex.result == Cr.NS_ERROR_UNEXPECTED)) { - return false; } catch (ex) { + if (ex.result == Cr.NS_ERROR_UNEXPECTED) { + return false; + } do_throw("Got exception retrieving lastSyncReassigned: " + Log.exceptionStr(ex)); } @@ -106,7 +107,7 @@ function getReassigned() { * Runs `between` between the two. This can be used to undo deliberate failure * setup, detach observers, etc. */ -function syncAndExpectNodeReassignment(server, firstNotification, between, +function* syncAndExpectNodeReassignment(server, firstNotification, between, secondNotification, url) { let deferred = Promise.defer(); function onwards() { @@ -160,7 +161,7 @@ function syncAndExpectNodeReassignment(server, firstNotification, between, yield deferred.promise; } -add_task(function test_momentary_401_engine() { +add_task(function* test_momentary_401_engine() { _("Test a failure for engine URLs that's resolved by reassignment."); let server = yield prepareServer(); let john = server.user("johndoe"); @@ -212,7 +213,7 @@ add_task(function test_momentary_401_engine() { }); // This test ends up being a failing fetch *after we're already logged in*. -add_task(function test_momentary_401_info_collections() { +add_task(function* test_momentary_401_info_collections() { _("Test a failure for info/collections that's resolved by reassignment."); let server = yield prepareServer(); @@ -235,7 +236,7 @@ add_task(function test_momentary_401_info_collections() { Service.infoURL); }); -add_task(function test_momentary_401_storage_loggedin() { +add_task(function* test_momentary_401_storage_loggedin() { _("Test a failure for any storage URL, not just engine parts. " + "Resolved by reassignment."); let server = yield prepareServer(); @@ -260,7 +261,7 @@ add_task(function test_momentary_401_storage_loggedin() { Service.storageURL + "meta/global"); }); -add_task(function test_momentary_401_storage_loggedout() { +add_task(function* test_momentary_401_storage_loggedout() { _("Test a failure for any storage URL, not just engine parts. " + "Resolved by reassignment."); let server = yield prepareServer(); @@ -282,7 +283,7 @@ add_task(function test_momentary_401_storage_loggedout() { Service.storageURL + "meta/global"); }); -add_task(function test_loop_avoidance_storage() { +add_task(function* test_loop_avoidance_storage() { _("Test that a repeated failure doesn't result in a sync loop " + "if node reassignment cannot resolve the failure."); @@ -382,7 +383,7 @@ add_task(function test_loop_avoidance_storage() { yield deferred.promise; }); -add_task(function test_loop_avoidance_engine() { +add_task(function* test_loop_avoidance_engine() { _("Test that a repeated 401 in an engine doesn't result in a sync loop " + "if node reassignment cannot resolve the failure."); let server = yield prepareServer(); diff --git a/services/sync/tests/unit/test_service_startOver.js b/services/sync/tests/unit/test_service_startOver.js index 6fb0a66d7d6..8994205480f 100644 --- a/services/sync/tests/unit/test_service_startOver.js +++ b/services/sync/tests/unit/test_service_startOver.js @@ -28,7 +28,7 @@ function run_test() { run_next_test(); } -add_identity_test(this, function test_resetLocalData() { +add_identity_test(this, function* test_resetLocalData() { yield configureIdentity(); Service.status.enforceBackoff = true; Service.status.backoffInterval = 42; diff --git a/services/sync/tests/unit/test_service_wipeServer.js b/services/sync/tests/unit/test_service_wipeServer.js index 3fc45cf86b5..9320f4b88ac 100644 --- a/services/sync/tests/unit/test_service_wipeServer.js +++ b/services/sync/tests/unit/test_service_wipeServer.js @@ -31,7 +31,7 @@ FakeCollection.prototype = { } }; -function setUpTestFixtures(server) { +function* setUpTestFixtures(server) { let cryptoService = new FakeCryptoService(); Service.serverURL = server.baseURI + "/"; @@ -52,7 +52,7 @@ function promiseStopServer(server) { return deferred.promise; } -add_identity_test(this, function test_wipeServer_list_success() { +add_identity_test(this, function* test_wipeServer_list_success() { _("Service.wipeServer() deletes collections given as argument."); let steam_coll = new FakeCollection(); @@ -86,7 +86,7 @@ add_identity_test(this, function test_wipeServer_list_success() { } }); -add_identity_test(this, function test_wipeServer_list_503() { +add_identity_test(this, function* test_wipeServer_list_503() { _("Service.wipeServer() deletes collections given as argument."); let steam_coll = new FakeCollection(); @@ -127,7 +127,7 @@ add_identity_test(this, function test_wipeServer_list_503() { } }); -add_identity_test(this, function test_wipeServer_all_success() { +add_identity_test(this, function* test_wipeServer_all_success() { _("Service.wipeServer() deletes all the things."); /** @@ -157,7 +157,7 @@ add_identity_test(this, function test_wipeServer_all_success() { Svc.Prefs.resetBranch(""); }); -add_identity_test(this, function test_wipeServer_all_404() { +add_identity_test(this, function* test_wipeServer_all_404() { _("Service.wipeServer() accepts a 404."); /** @@ -189,7 +189,7 @@ add_identity_test(this, function test_wipeServer_all_404() { Svc.Prefs.resetBranch(""); }); -add_identity_test(this, function test_wipeServer_all_503() { +add_identity_test(this, function* test_wipeServer_all_503() { _("Service.wipeServer() throws if it encounters a non-200/404 response."); /** @@ -221,7 +221,7 @@ add_identity_test(this, function test_wipeServer_all_503() { Svc.Prefs.resetBranch(""); }); -add_identity_test(this, function test_wipeServer_all_connectionRefused() { +add_identity_test(this, function* test_wipeServer_all_connectionRefused() { _("Service.wipeServer() throws if it encounters a network problem."); let server = httpd_setup({}); yield setUpTestFixtures(server); diff --git a/services/sync/tests/unit/test_syncscheduler.js b/services/sync/tests/unit/test_syncscheduler.js index f9beddb2cc9..cb04c926a77 100644 --- a/services/sync/tests/unit/test_syncscheduler.js +++ b/services/sync/tests/unit/test_syncscheduler.js @@ -156,7 +156,7 @@ add_test(function test_prefAttributes() { run_next_test(); }); -add_identity_test(this, function test_updateClientMode() { +add_identity_test(this, function* test_updateClientMode() { _("Test updateClientMode adjusts scheduling attributes based on # of clients appropriately"); do_check_eq(scheduler.syncThreshold, SINGLE_USER_THRESHOLD); do_check_eq(scheduler.syncInterval, scheduler.singleDeviceInterval); @@ -186,7 +186,7 @@ add_identity_test(this, function test_updateClientMode() { yield cleanUpAndGo(); }); -add_identity_test(this, function test_masterpassword_locked_retry_interval() { +add_identity_test(this, function* test_masterpassword_locked_retry_interval() { _("Test Status.login = MASTER_PASSWORD_LOCKED results in reschedule at MASTER_PASSWORD interval"); let loginFailed = false; Svc.Obs.add("weave:service:login:error", function onLoginError() { @@ -223,7 +223,7 @@ add_identity_test(this, function test_masterpassword_locked_retry_interval() { yield cleanUpAndGo(server); }); -add_identity_test(this, function test_calculateBackoff() { +add_identity_test(this, function* test_calculateBackoff() { do_check_eq(Status.backoffInterval, 0); // Test no interval larger than the maximum backoff is used if @@ -245,7 +245,7 @@ add_identity_test(this, function test_calculateBackoff() { yield cleanUpAndGo(); }); -add_identity_test(this, function test_scheduleNextSync_nowOrPast() { +add_identity_test(this, function* test_scheduleNextSync_nowOrPast() { let deferred = Promise.defer(); Svc.Obs.add("weave:service:sync:finish", function onSyncFinish() { Svc.Obs.remove("weave:service:sync:finish", onSyncFinish); @@ -260,7 +260,7 @@ add_identity_test(this, function test_scheduleNextSync_nowOrPast() { yield deferred.promise; }); -add_identity_test(this, function test_scheduleNextSync_future_noBackoff() { +add_identity_test(this, function* test_scheduleNextSync_future_noBackoff() { _("scheduleNextSync() uses the current syncInterval if no interval is provided."); // Test backoffInterval is 0 as expected. do_check_eq(Status.backoffInterval, 0); @@ -309,7 +309,7 @@ add_identity_test(this, function test_scheduleNextSync_future_noBackoff() { yield cleanUpAndGo(); }); -add_identity_test(this, function test_scheduleNextSync_future_backoff() { +add_identity_test(this, function* test_scheduleNextSync_future_backoff() { _("scheduleNextSync() will honour backoff in all scheduling requests."); // Let's take a backoff interval that's bigger than the default sync interval. const BACKOFF = 7337; @@ -359,7 +359,7 @@ add_identity_test(this, function test_scheduleNextSync_future_backoff() { yield cleanUpAndGo(); }); -add_identity_test(this, function test_handleSyncError() { +add_identity_test(this, function* test_handleSyncError() { let server = sync_httpd_setup(); yield setUp(server); @@ -425,7 +425,7 @@ add_identity_test(this, function test_handleSyncError() { yield deferred.promise; }); -add_identity_test(this, function test_client_sync_finish_updateClientMode() { +add_identity_test(this, function* test_client_sync_finish_updateClientMode() { let server = sync_httpd_setup(); yield setUp(server); @@ -459,7 +459,7 @@ add_identity_test(this, function test_client_sync_finish_updateClientMode() { yield cleanUpAndGo(server); }); -add_identity_test(this, function test_autoconnect_nextSync_past() { +add_identity_test(this, function* test_autoconnect_nextSync_past() { let deferred = Promise.defer(); // nextSync will be 0 by default, so it's way in the past. @@ -475,7 +475,7 @@ add_identity_test(this, function test_autoconnect_nextSync_past() { yield deferred.promise; }); -add_identity_test(this, function test_autoconnect_nextSync_future() { +add_identity_test(this, function* test_autoconnect_nextSync_future() { let deferred = Promise.defer(); let previousSync = Date.now() + scheduler.syncInterval / 2; scheduler.nextSync = previousSync; @@ -504,7 +504,7 @@ add_identity_test(this, function test_autoconnect_nextSync_future() { // XXX - this test can't be run with the browserid identity as it relies // on the syncKey getter behaving in a certain way... -add_task(function test_autoconnect_mp_locked() { +add_task(function* test_autoconnect_mp_locked() { let server = sync_httpd_setup(); yield setUp(server); @@ -541,7 +541,7 @@ add_task(function test_autoconnect_mp_locked() { yield deferred.promise; }); -add_identity_test(this, function test_no_autoconnect_during_wizard() { +add_identity_test(this, function* test_no_autoconnect_during_wizard() { let server = sync_httpd_setup(); yield setUp(server); @@ -564,7 +564,7 @@ add_identity_test(this, function test_no_autoconnect_during_wizard() { yield deferred.promise; }); -add_identity_test(this, function test_no_autoconnect_status_not_ok() { +add_identity_test(this, function* test_no_autoconnect_status_not_ok() { let server = sync_httpd_setup(); // Ensure we don't actually try to sync (or log in for that matter). @@ -587,7 +587,7 @@ add_identity_test(this, function test_no_autoconnect_status_not_ok() { yield deferred.promise; }); -add_identity_test(this, function test_autoconnectDelay_pref() { +add_identity_test(this, function* test_autoconnectDelay_pref() { let deferred = Promise.defer(); Svc.Obs.add("weave:service:sync:finish", function onSyncFinish() { Svc.Obs.remove("weave:service:sync:finish", onSyncFinish); @@ -607,7 +607,7 @@ add_identity_test(this, function test_autoconnectDelay_pref() { yield deferred.promise; }); -add_identity_test(this, function test_idle_adjustSyncInterval() { +add_identity_test(this, function* test_idle_adjustSyncInterval() { // Confirm defaults. do_check_eq(scheduler.idle, false); @@ -627,7 +627,7 @@ add_identity_test(this, function test_idle_adjustSyncInterval() { yield cleanUpAndGo(); }); -add_identity_test(this, function test_back_triggersSync() { +add_identity_test(this, function* test_back_triggersSync() { // Confirm defaults. do_check_false(scheduler.idle); do_check_eq(Status.backoffInterval, 0); @@ -650,7 +650,7 @@ add_identity_test(this, function test_back_triggersSync() { yield deferred.promise; }); -add_identity_test(this, function test_active_triggersSync_observesBackoff() { +add_identity_test(this, function* test_active_triggersSync_observesBackoff() { // Confirm defaults. do_check_false(scheduler.idle); @@ -681,7 +681,7 @@ add_identity_test(this, function test_active_triggersSync_observesBackoff() { yield deferred.promise; }); -add_identity_test(this, function test_back_debouncing() { +add_identity_test(this, function* test_back_debouncing() { _("Ensure spurious back-then-idle events, as observed on OS X, don't trigger a sync."); // Confirm defaults. @@ -709,7 +709,7 @@ add_identity_test(this, function test_back_debouncing() { yield deferred.promise; }); -add_identity_test(this, function test_no_sync_node() { +add_identity_test(this, function* test_no_sync_node() { // Test when Status.sync == NO_SYNC_NODE_FOUND // it is not overwritten on sync:finish let server = sync_httpd_setup(); @@ -724,7 +724,7 @@ add_identity_test(this, function test_no_sync_node() { yield cleanUpAndGo(server); }); -add_identity_test(this, function test_sync_failed_partial_500s() { +add_identity_test(this, function* test_sync_failed_partial_500s() { _("Test a 5xx status calls handleSyncError."); scheduler._syncErrors = MAX_ERROR_COUNT_BEFORE_BACKOFF; let server = sync_httpd_setup(); @@ -751,7 +751,7 @@ add_identity_test(this, function test_sync_failed_partial_500s() { yield cleanUpAndGo(server); }); -add_identity_test(this, function test_sync_failed_partial_400s() { +add_identity_test(this, function* test_sync_failed_partial_400s() { _("Test a non-5xx status doesn't call handleSyncError."); scheduler._syncErrors = MAX_ERROR_COUNT_BEFORE_BACKOFF; let server = sync_httpd_setup(); @@ -781,7 +781,7 @@ add_identity_test(this, function test_sync_failed_partial_400s() { yield cleanUpAndGo(server); }); -add_identity_test(this, function test_sync_X_Weave_Backoff() { +add_identity_test(this, function* test_sync_X_Weave_Backoff() { let server = sync_httpd_setup(); yield setUp(server); @@ -836,7 +836,7 @@ add_identity_test(this, function test_sync_X_Weave_Backoff() { yield cleanUpAndGo(server); }); -add_identity_test(this, function test_sync_503_Retry_After() { +add_identity_test(this, function* test_sync_503_Retry_After() { let server = sync_httpd_setup(); yield setUp(server); @@ -895,7 +895,7 @@ add_identity_test(this, function test_sync_503_Retry_After() { yield cleanUpAndGo(server); }); -add_identity_test(this, function test_loginError_recoverable_reschedules() { +add_identity_test(this, function* test_loginError_recoverable_reschedules() { _("Verify that a recoverable login error schedules a new sync."); yield configureIdentity({username: "johndoe"}); Service.serverURL = "http://localhost:1234/"; @@ -939,7 +939,7 @@ add_identity_test(this, function test_loginError_recoverable_reschedules() { yield deferred.promise; }); -add_identity_test(this, function test_loginError_fatal_clearsTriggers() { +add_identity_test(this, function* test_loginError_fatal_clearsTriggers() { _("Verify that a fatal login error clears sync triggers."); yield configureIdentity({username: "johndoe"}); @@ -986,7 +986,7 @@ add_identity_test(this, function test_loginError_fatal_clearsTriggers() { yield deferred.promise; }); -add_identity_test(this, function test_proper_interval_on_only_failing() { +add_identity_test(this, function* test_proper_interval_on_only_failing() { _("Ensure proper behavior when only failed records are applied."); // If an engine reports that no records succeeded, we shouldn't decrease the diff --git a/services/sync/tps/extensions/mozmill/resource/driver/controller.js b/services/sync/tps/extensions/mozmill/resource/driver/controller.js index 6acc078e7fe..6ec059164c2 100644 --- a/services/sync/tps/extensions/mozmill/resource/driver/controller.js +++ b/services/sync/tps/extensions/mozmill/resource/driver/controller.js @@ -977,7 +977,10 @@ function browserAdditions (controller) { return windows.map.hasPageLoaded(utils.getWindowId(win)); }, "Timeout", timeout, aInterval); } - catch (ex if ex instanceof errors.TimeoutError) { + catch (ex) { + if (!ex instanceof errors.TimeoutError) { + throw ex; + } timed_out = true; } finally { diff --git a/services/sync/tps/extensions/mozmill/resource/modules/assertions.js b/services/sync/tps/extensions/mozmill/resource/modules/assertions.js index 32877f6e534..c9991acf060 100644 --- a/services/sync/tps/extensions/mozmill/resource/modules/assertions.js +++ b/services/sync/tps/extensions/mozmill/resource/modules/assertions.js @@ -658,7 +658,10 @@ Expect.prototype.waitFor = function Expect_waitFor(aCallback, aMessage, aTimeout try { Assert.prototype.waitFor.apply(this, arguments); } - catch (ex if ex instanceof errors.AssertionError) { + catch (ex) { + if (!ex instanceof errors.AssertionError) { + throw ex; + } message = ex.message; condition = false; } diff --git a/services/sync/tps/extensions/mozmill/resource/stdlib/securable-module.js b/services/sync/tps/extensions/mozmill/resource/stdlib/securable-module.js index 8fc17f01217..2648afd274d 100644 --- a/services/sync/tps/extensions/mozmill/resource/stdlib/securable-module.js +++ b/services/sync/tps/extensions/mozmill/resource/stdlib/securable-module.js @@ -321,7 +321,10 @@ }); try { channel.open2().close(); - } catch (e if e.result == Cr.NS_ERROR_FILE_NOT_FOUND) { + } catch (e) { + if (e.result != Cr.NS_ERROR_FILE_NOT_FOUND) { + throw e; + } return null; } return newURI.spec;