Bug 983913 - ensure failure to reject a promise is actually reported. r=ttaubert

This commit is contained in:
Mark Hammond 2014-03-14 18:02:01 -07:00
parent 81f99357c4
commit 1dd0bb7d86

View File

@ -21,6 +21,17 @@ const SECOND_MS = 1000;
const MINUTE_MS = SECOND_MS * 60;
const HOUR_MS = MINUTE_MS * 60;
// 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;
}
let identityConfig = makeIdentityConfig();
let browseridManager = new BrowserIDManager();
configureFxAccountIdentity(browseridManager, identityConfig);
@ -254,20 +265,13 @@ add_task(function test_ensureLoggedIn() {
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;
try {
yield browseridManager.ensureLoggedIn();
Assert.ok(false, "promise should have been rejected.")
} catch(_) {
}
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;
try {
yield browseridManager.ensureLoggedIn();
Assert.ok(false, "LOGIN_FAILED_LOGIN_REJECTED should have caused immediate rejection");
} catch (_) {
}
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;
@ -501,10 +505,8 @@ function* initializeIdentityWithTokenServerFailure(response) {
browseridManager._tokenServerClient = mockTSC;
yield browseridManager.initializeWithCurrentIdentity();
try {
yield browseridManager.whenReadyToAuthenticate.promise;
Assert.ok(false, "expecting this promise to resolve with an error");
} catch (ex) {}
yield Assert_rejects(browseridManager.whenReadyToAuthenticate.promise,
"expecting rejection due to tokenserver error");
}
@ -546,10 +548,8 @@ function* initializeIdentityWithHAWKFailure(response) {
browseridManager._fxaService = fxa;
browseridManager._signedInUser = null;
yield browseridManager.initializeWithCurrentIdentity();
try {
yield browseridManager.whenReadyToAuthenticate.promise;
Assert.ok(false, "expecting this promise to resolve with an error");
} catch (ex) {}
yield Assert_rejects(browseridManager.whenReadyToAuthenticate.promise,
"expecting rejection due to hawk error");
}