Bug 1085199 - Part 2: Do not wrap the DOMRequest in a promise in dom/system/gonk tests; r=hsinyi

DOMRequest now has a .then() method compatible with Promise.
This commit is contained in:
Ehsan Akhgari 2014-10-22 09:20:34 -04:00
parent 282844d494
commit a8ad646f8b

View File

@ -17,33 +17,6 @@ ok(ril, "ril.constructor is " + ril.constructor);
let radioInterface = ril.getRadioInterface(0);
ok(radioInterface, "radioInterface.constructor is " + radioInterface.constrctor);
/**
* Wrap DOMRequest onsuccess/onerror events to Promise resolve/reject.
*
* Fulfill params: A DOMEvent.
* Reject params: A DOMEvent.
*
* @param aRequest
* A DOMRequest instance.
*
* @return A deferred promise.
*/
function wrapDomRequestAsPromise(aRequest) {
let deferred = Promise.defer();
ok(aRequest instanceof DOMRequest,
"aRequest is instanceof " + aRequest.constructor);
aRequest.addEventListener("success", function(aEvent) {
deferred.resolve(aEvent);
});
aRequest.addEventListener("error", function(aEvent) {
deferred.reject(aEvent);
});
return deferred.promise;
}
/**
* Get mozSettings value specified by @aKey.
*
@ -63,11 +36,10 @@ function wrapDomRequestAsPromise(aRequest) {
*/
function getSettings(aKey, aAllowError) {
let request = window.navigator.mozSettings.createLock().get(aKey);
return wrapDomRequestAsPromise(request)
.then(function resolve(aEvent) {
return request.then(function resolve(aValue) {
log("getSettings(" + aKey + ") - success");
return aEvent.target.result[aKey];
}, function reject(aEvent) {
return aValue[aKey];
}, function reject(aError) {
ok(aAllowError, "getSettings(" + aKey + ") - error");
});
}