mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1085199 - Part 1: Do not wrap the DOMRequest in a promise in mobileconnection tests; r=hsinyi
DOMRequest now has a .then() method compatible with Promise.
This commit is contained in:
parent
178200e263
commit
282844d494
@ -77,33 +77,6 @@ function runEmulatorShellCmdSafe(aCommands) {
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
let workingFrame;
|
||||
|
||||
/**
|
||||
@ -127,11 +100,10 @@ let workingFrame;
|
||||
function getSettings(aKey, aAllowError) {
|
||||
let request =
|
||||
workingFrame.contentWindow.navigator.mozSettings.createLock().get(aKey);
|
||||
return wrapDomRequestAsPromise(request)
|
||||
.then(function resolve(aEvent) {
|
||||
return request.then(function resolve(aValue) {
|
||||
ok(true, "getSettings(" + aKey + ") - success");
|
||||
return aEvent.target.result[aKey];
|
||||
}, function reject(aEvent) {
|
||||
return aValue[aKey];
|
||||
}, function reject(aError) {
|
||||
ok(aAllowError, "getSettings(" + aKey + ") - error");
|
||||
});
|
||||
}
|
||||
@ -360,8 +332,7 @@ function waitForManagerEvent(aEventName, aServiceId) {
|
||||
*/
|
||||
function getNetworks() {
|
||||
let request = mobileConnection.getNetworks();
|
||||
return wrapDomRequestAsPromise(request)
|
||||
.then(() => request.result);
|
||||
return request.then(() => request.result);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -378,8 +349,7 @@ function getNetworks() {
|
||||
*/
|
||||
function selectNetwork(aNetwork) {
|
||||
let request = mobileConnection.selectNetwork(aNetwork);
|
||||
return wrapDomRequestAsPromise(request)
|
||||
.then(null, () => { throw request.error });
|
||||
return request.then(null, () => { throw request.error });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -414,8 +384,7 @@ function selectNetworkAndWait(aNetwork) {
|
||||
*/
|
||||
function selectNetworkAutomatically() {
|
||||
let request = mobileConnection.selectNetworkAutomatically();
|
||||
return wrapDomRequestAsPromise(request)
|
||||
.then(null, () => { throw request.error });
|
||||
return request.then(null, () => { throw request.error });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -449,8 +418,7 @@ function selectNetworkAutomaticallyAndWait() {
|
||||
*/
|
||||
function sendMMI(aMmi) {
|
||||
let request = mobileConnection.sendMMI(aMmi);
|
||||
return wrapDomRequestAsPromise(request)
|
||||
.then(() => request.result, () => { throw request.error });
|
||||
return request.then(() => request.result, () => { throw request.error });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -467,8 +435,7 @@ function sendMMI(aMmi) {
|
||||
*/
|
||||
function setRoamingPreference(aMode) {
|
||||
let request = mobileConnection.setRoamingPreference(aMode);
|
||||
return wrapDomRequestAsPromise(request)
|
||||
.then(null, () => { throw request.error });
|
||||
return request.then(null, () => { throw request.error });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -488,8 +455,7 @@ function sendMMI(aMmi) {
|
||||
*/
|
||||
function setPreferredNetworkType(aType) {
|
||||
let request = mobileConnection.setPreferredNetworkType(aType);
|
||||
return wrapDomRequestAsPromise(request)
|
||||
.then(null, () => { throw request.error });
|
||||
return request.then(null, () => { throw request.error });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -506,8 +472,7 @@ function sendMMI(aMmi) {
|
||||
*/
|
||||
function getPreferredNetworkType() {
|
||||
let request = mobileConnection.getPreferredNetworkType();
|
||||
return wrapDomRequestAsPromise(request)
|
||||
.then(() => request.result, () => { throw request.error });
|
||||
return request.then(() => request.result, () => { throw request.error });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -525,8 +490,7 @@ function sendMMI(aMmi) {
|
||||
*/
|
||||
function setCallForwardingOption(aOptions) {
|
||||
let request = mobileConnection.setCallForwardingOption(aOptions);
|
||||
return wrapDomRequestAsPromise(request)
|
||||
.then(null, () => { throw request.error });
|
||||
return request.then(null, () => { throw request.error });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -545,8 +509,7 @@ function sendMMI(aMmi) {
|
||||
*/
|
||||
function getCallForwardingOption(aReason) {
|
||||
let request = mobileConnection.getCallForwardingOption(aReason);
|
||||
return wrapDomRequestAsPromise(request)
|
||||
.then(() => request.result, () => { throw request.error });
|
||||
return request.then(() => request.result, () => { throw request.error });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -563,8 +526,7 @@ function sendMMI(aMmi) {
|
||||
*/
|
||||
function setVoicePrivacyMode(aEnabled) {
|
||||
let request = mobileConnection.setVoicePrivacyMode(aEnabled);
|
||||
return wrapDomRequestAsPromise(request)
|
||||
.then(null, () => { throw request.error });
|
||||
return request.then(null, () => { throw request.error });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -579,8 +541,7 @@ function sendMMI(aMmi) {
|
||||
*/
|
||||
function getVoicePrivacyMode() {
|
||||
let request = mobileConnection.getVoicePrivacyMode();
|
||||
return wrapDomRequestAsPromise(request)
|
||||
.then(() => request.result, () => { throw request.error });
|
||||
return request.then(() => request.result, () => { throw request.error });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -595,8 +556,7 @@ function sendMMI(aMmi) {
|
||||
*/
|
||||
function setCallBarringOption(aOptions) {
|
||||
let request = mobileConnection.setCallBarringOption(aOptions);
|
||||
return wrapDomRequestAsPromise(request)
|
||||
.then(null, () => { throw request.error });
|
||||
return request.then(null, () => { throw request.error });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -612,8 +572,7 @@ function sendMMI(aMmi) {
|
||||
*/
|
||||
function getCallBarringOption(aOptions) {
|
||||
let request = mobileConnection.getCallBarringOption(aOptions);
|
||||
return wrapDomRequestAsPromise(request)
|
||||
.then(() => request.result, () => { throw request.error });
|
||||
return request.then(() => request.result, () => { throw request.error });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -627,8 +586,7 @@ function sendMMI(aMmi) {
|
||||
*/
|
||||
function changeCallBarringPassword(aOptions) {
|
||||
let request = mobileConnection.changeCallBarringPassword(aOptions);
|
||||
return wrapDomRequestAsPromise(request)
|
||||
.then(null, () => { throw request.error });
|
||||
return request.then(null, () => { throw request.error });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -686,8 +644,7 @@ function setDataEnabledAndWait(aEnabled, aServiceId) {
|
||||
function setRadioEnabled(aEnabled, aServiceId) {
|
||||
let mobileConn = getMozMobileConnectionByServiceId(aServiceId);
|
||||
let request = mobileConn.setRadioEnabled(aEnabled);
|
||||
return wrapDomRequestAsPromise(request)
|
||||
.then(function onsuccess() {
|
||||
return request.then(function onsuccess() {
|
||||
ok(true, "setRadioEnabled " + aEnabled + " on " + aServiceId + " success.");
|
||||
}, function onerror() {
|
||||
ok(false, "setRadioEnabled " + aEnabled + " on " + aServiceId + " " +
|
||||
@ -752,8 +709,7 @@ function setClir(aMode, aServiceId) {
|
||||
ok(true, "setClir(" + aMode + ", " + aServiceId + ")");
|
||||
let mobileConn = getMozMobileConnectionByServiceId(aServiceId);
|
||||
let request = mobileConn.setCallingLineIdRestriction(aMode);
|
||||
return wrapDomRequestAsPromise(request)
|
||||
.then(null, () => { throw request.error });
|
||||
return request.then(null, () => { throw request.error });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -774,8 +730,7 @@ function getClir(aServiceId) {
|
||||
ok(true, "getClir(" + aServiceId + ")");
|
||||
let mobileConn = getMozMobileConnectionByServiceId(aServiceId);
|
||||
let request = mobileConn.getCallingLineIdRestriction();
|
||||
return wrapDomRequestAsPromise(request)
|
||||
.then(() => request.result, () => { throw request.error });
|
||||
return request.then(() => request.result, () => { throw request.error });
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user