Bug 984172 (part 2) - replace Assert_rejects with Assert.rejects. r=ttaubert
--- a/services/sync/modules-testing/fxa_utils.js
+++ b/services/sync/modules-testing/fxa_utils.js
@@ -1,35 +1,23 @@
"use strict";
this.EXPORTED_SYMBOLS = [
- "Assert_rejects",
"initializeIdentityWithTokenServerResponse",
];
const {utils: Cu} = Components;
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://services-sync/main.js");
Cu.import("resource://services-sync/browserid_identity.js");
Cu.import("resource://services-common/tokenserverclient.js");
Cu.import("resource://testing-common/services/common/logging.js");
Cu.import("resource://testing-common/services/sync/utils.js");
-// This shouldn't be here - it should be part of the xpcshell harness.
-// Maybe as Assert.rejects - so we name it like that.
-function Assert_rejects(promise, message) {
- let deferred = Promise.defer();
- promise.then(
- () => deferred.reject(message || "Expected the promise to be rejected"),
- deferred.resolve
- );
- return deferred.promise;
-}
-
// Create a new browserid_identity object and initialize it with a
// mocked TokenServerClient which always receives the specified response.
this.initializeIdentityWithTokenServerResponse = function(response) {
// First create a mock "request" object that well' hack into the token server.
// A log for it
let requestLog = Log.repository.getLogger("testing.mock-rest");
if (!requestLog.appenders.length) { // might as well see what it says :)
requestLog.addAppender(new Log.DumpAppender());
--- a/services/sync/tests/unit/test_browserid_identity.js
+++ b/services/sync/tests/unit/test_browserid_identity.js
@@ -264,22 +264,22 @@ add_task(function test_ensureLoggedIn()
// arrange for no logged in user.
let fxa = browseridManager._fxaService
let signedInUser = fxa.internal.currentAccountState.signedInUser;
fxa.internal.currentAccountState.signedInUser = null;
browseridManager.initializeWithCurrentIdentity();
Assert.ok(!browseridManager._shouldHaveSyncKeyBundle,
"_shouldHaveSyncKeyBundle should be false so we know we are testing what we think we are.");
Status.login = LOGIN_FAILED_NO_USERNAME;
- yield Assert_rejects(browseridManager.ensureLoggedIn(), "expecting rejection due to no user");
+ yield Assert.rejects(browseridManager.ensureLoggedIn(), "expecting rejection due to no user");
Assert.ok(browseridManager._shouldHaveSyncKeyBundle,
"_shouldHaveSyncKeyBundle should always be true after ensureLogin completes.");
fxa.internal.currentAccountState.signedInUser = signedInUser;
Status.login = LOGIN_FAILED_LOGIN_REJECTED;
- yield Assert_rejects(browseridManager.ensureLoggedIn(),
+ yield Assert.rejects(browseridManager.ensureLoggedIn(),
"LOGIN_FAILED_LOGIN_REJECTED should have caused immediate rejection");
Assert.equal(Status.login, LOGIN_FAILED_LOGIN_REJECTED,
"status should remain LOGIN_FAILED_LOGIN_REJECTED");
Status.login = LOGIN_FAILED_NETWORK_ERROR;
yield browseridManager.ensureLoggedIn();
Assert.equal(Status.login, LOGIN_SUCCEEDED, "final ensureLoggedIn worked");
});
@@ -355,33 +355,33 @@ add_task(function test_getTokenErrors()
initializeIdentityWithTokenServerResponse({
status: 401,
headers: {"content-type": "application/json"},
body: JSON.stringify({}),
});
let browseridManager = Service.identity;
yield browseridManager.initializeWithCurrentIdentity();
- yield Assert_rejects(browseridManager.whenReadyToAuthenticate.promise,
+ yield Assert.rejects(browseridManager.whenReadyToAuthenticate.promise,
"should reject due to 401");
Assert.equal(Status.login, LOGIN_FAILED_LOGIN_REJECTED, "login was rejected");
// XXX - other interesting responses to return?
// And for good measure, some totally "unexpected" errors - we generally
// assume these problems are going to magically go away at some point.
_("Arrange for an empty body with a 200 response - should reflect a network error.");
initializeIdentityWithTokenServerResponse({
status: 200,
headers: [],
body: "",
});
browseridManager = Service.identity;
yield browseridManager.initializeWithCurrentIdentity();
- yield Assert_rejects(browseridManager.whenReadyToAuthenticate.promise,
+ yield Assert.rejects(browseridManager.whenReadyToAuthenticate.promise,
"should reject due to non-JSON response");
Assert.equal(Status.login, LOGIN_FAILED_NETWORK_ERROR, "login state is LOGIN_FAILED_NETWORK_ERROR");
});
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
@@ -392,17 +392,17 @@ add_task(function test_getTokenErrorWith
status: 503,
headers: {"content-type": "application/json",
"retry-after": "100"},
body: JSON.stringify({}),
});
let browseridManager = Service.identity;
yield browseridManager.initializeWithCurrentIdentity();
- yield Assert_rejects(browseridManager.whenReadyToAuthenticate.promise,
+ yield Assert.rejects(browseridManager.whenReadyToAuthenticate.promise,
"should reject due to 503");
// The observer should have fired - check it got the value in the response.
Assert.equal(Status.login, LOGIN_FAILED_NETWORK_ERROR, "login was rejected");
// Sync will have the value in ms with some slop - so check it is at least that.
Assert.ok(Status.backoffInterval >= 100000);
_("Arrange for a 200 with an X-Backoff header.");
@@ -411,17 +411,17 @@ add_task(function test_getTokenErrorWith
status: 503,
headers: {"content-type": "application/json",
"x-backoff": "200"},
body: JSON.stringify({}),
});
browseridManager = Service.identity;
yield browseridManager.initializeWithCurrentIdentity();
- yield Assert_rejects(browseridManager.whenReadyToAuthenticate.promise,
+ yield Assert.rejects(browseridManager.whenReadyToAuthenticate.promise,
"should reject due to no token in response");
// The observer should have fired - check it got the value in the response.
Assert.ok(Status.backoffInterval >= 200000);
});
add_task(function test_getKeysErrorWithBackoff() {
_("Auth server (via hawk) sends an observer notification on backoff headers.");
@@ -443,17 +443,17 @@ add_task(function test_getKeysErrorWithB
status: 503,
headers: {"content-type": "application/json",
"x-backoff": "100"},
body: "{}",
}
});
let browseridManager = Service.identity;
- yield Assert_rejects(browseridManager.whenReadyToAuthenticate.promise,
+ yield Assert.rejects(browseridManager.whenReadyToAuthenticate.promise,
"should reject due to 503");
// The observer should have fired - check it got the value in the response.
Assert.equal(Status.login, LOGIN_FAILED_NETWORK_ERROR, "login was rejected");
// Sync will have the value in ms with some slop - so check it is at least that.
Assert.ok(Status.backoffInterval >= 100000);
});
@@ -477,17 +477,17 @@ add_task(function test_getKeysErrorWithR
status: 503,
headers: {"content-type": "application/json",
"retry-after": "100"},
body: "{}",
}
});
let browseridManager = Service.identity;
- yield Assert_rejects(browseridManager.whenReadyToAuthenticate.promise,
+ yield Assert.rejects(browseridManager.whenReadyToAuthenticate.promise,
"should reject due to 503");
// The observer should have fired - check it got the value in the response.
Assert.equal(Status.login, LOGIN_FAILED_NETWORK_ERROR, "login was rejected");
// Sync will have the value in ms with some slop - so check it is at least that.
Assert.ok(Status.backoffInterval >= 100000);
});
@@ -661,17 +661,17 @@ function* initializeIdentityWithHAWKResp
let fxa = new FxAccounts(internal);
fxa.internal.currentAccountState.signedInUser = {
accountData: config.fxaccount.user,
};
browseridManager._fxaService = fxa;
browseridManager._signedInUser = null;
yield browseridManager.initializeWithCurrentIdentity();
- yield Assert_rejects(browseridManager.whenReadyToAuthenticate.promise,
+ yield Assert.rejects(browseridManager.whenReadyToAuthenticate.promise,
"expecting rejection due to hawk error");
}
function getTimestamp(hawkAuthHeader) {
return parseInt(/ts="(\d+)"/.exec(hawkAuthHeader)[1], 10) * SECOND_MS;
}
--- a/services/sync/tests/unit/test_fxa_service_cluster.js
+++ b/services/sync/tests/unit/test_fxa_service_cluster.js
@@ -12,32 +12,32 @@ add_task(function test_findCluster() {
_("_findCluster() throws on 500 errors.");
initializeIdentityWithTokenServerResponse({
status: 500,
headers: [],
body: "",
});
yield Service.identity.initializeWithCurrentIdentity();
- yield Assert_rejects(Service.identity.whenReadyToAuthenticate.promise,
+ yield Assert.rejects(Service.identity.whenReadyToAuthenticate.promise,
"should reject due to 500");
Assert.throws(function() {
Service._clusterManager._findCluster();
});
_("_findCluster() returns null on authentication errors.");
initializeIdentityWithTokenServerResponse({
status: 401,
headers: {"content-type": "application/json"},
body: "{}",
});
yield Service.identity.initializeWithCurrentIdentity();
- yield Assert_rejects(Service.identity.whenReadyToAuthenticate.promise,
+ yield Assert.rejects(Service.identity.whenReadyToAuthenticate.promise,
"should reject due to 401");
cluster = Service._clusterManager._findCluster();
Assert.strictEqual(cluster, null);
_("_findCluster() works with correct tokenserver response.");
let endpoint = "http://example.com/something";
initializeIdentityWithTokenServerResponse({