Bug 997584 - part 2 - test clir on radio off. r=vicamo

This commit is contained in:
Hsin-Yi Tsai 2014-04-21 11:17:26 +08:00
parent 47b9f71492
commit 6d1d95be2b
3 changed files with 167 additions and 16 deletions

View File

@ -265,6 +265,24 @@ function ensureMobileConnection(aAdditionalPermissions, aServiceId) {
return deferred.promise;
}
/**
* Get MozMobileConnection by ServiceId
*
* @param aServiceId [optional]
* A numeric DSDS service id. Default: the one indicated in
* start*TestCommon() or 0 if not indicated.
*
* @return A MozMobileConnection.
*/
function getMozMobileConnectionByServiceId(aServiceId) {
let mobileConn = mobileConnection;
if (aServiceId !== undefined) {
mobileConn =
workingFrame.contentWindow.navigator.mozMobileConnections[aServiceId];
}
return mobileConn;
}
/**
* Wait for one named MobileConnection event.
*
@ -283,11 +301,7 @@ function ensureMobileConnection(aAdditionalPermissions, aServiceId) {
function waitForManagerEvent(aEventName, aServiceId) {
let deferred = Promise.defer();
let mobileConn = mobileConnection;
if (aServiceId !== undefined) {
mobileConn =
workingFrame.contentWindow.navigator.mozMobileConnections[aServiceId];
}
let mobileConn = getMozMobileConnectionByServiceId(aServiceId);
mobileConn.addEventListener(aEventName, function onevent(aEvent) {
mobileConn.removeEventListener(aEventName, onevent);
@ -409,11 +423,7 @@ function setDataEnabledAndWait(aEnabled, aServiceId) {
promises.push(waitForManagerEvent("datachange", aServiceId));
promises.push(setDataEnabled(aEnabled));
Promise.all(promises).then(function keepWaiting() {
let mobileConn = mobileConnection;
if (aServiceId !== undefined) {
mobileConn =
workingFrame.contentWindow.navigator.mozMobileConnections[aServiceId];
}
let mobileConn = getMozMobileConnectionByServiceId(aServiceId);
// To ignore some transient states, we only resolve that deferred promise
// when the |connected| state equals to the expected one and never rejects.
let connected = mobileConn.data.connected;
@ -428,6 +438,114 @@ function setDataEnabledAndWait(aEnabled, aServiceId) {
return deferred.promise;
}
/**
* Set radio enabling state.
*
* Resolve no matter the request succeeds or fails. Never reject.
*
* Fulfill params: (none)
*
* @param aEnabled
* A boolean state.
* @param aServiceId [optional]
* A numeric DSDS service id. Default: the one indicated in
* start*TestCommon() or 0 if not indicated.
*
* @return A deferred promise.
*/
function setRadioEnabled(aEnabled, aServiceId) {
let mobileConn = getMozMobileConnectionByServiceId(aServiceId);
let request = mobileConn.setRadioEnabled(aEnabled);
return wrapDomRequestAsPromise(request)
.then(function onsuccess() {
ok(true, "setRadioEnabled " + aEnabled + " on " + aServiceId + " success.");
}, function onerror() {
ok(false, "setRadioEnabled " + aEnabled + " on " + aServiceId + " " +
request.error.name);
});
}
/**
* Set radio enabling state and wait for "radiostatechange" event.
*
* Resolve if radio state changed to the expected one. Never reject.
*
* Fulfill params: (none)
*
* @param aEnabled
* A boolean state.
* @param aServiceId [optional]
* A numeric DSDS service id. Default: the one indicated in
* start*TestCommon() or 0 if not indicated.
*
* @return A deferred promise.
*/
function setRadioEnabledAndWait(aEnabled, aServiceId) {
let deferred = Promise.defer();
let promises = [];
promises.push(waitForManagerEvent("radiostatechange", aServiceId));
promises.push(setRadioEnabled(aEnabled, aServiceId));
Promise.all(promises).then(function keepWaiting() {
let mobileConn = getMozMobileConnectionByServiceId(aServiceId);
// To ignore some transient states, we only resolve that deferred promise
// when |radioState| equals to the expected one and never rejects.
let state = mobileConn.radioState;
aEnabled = aEnabled ? "enabled" : "disabled";
if (state == aEnabled) {
deferred.resolve();
return;
}
return waitForManagerEvent("radiostatechange", aServiceId).then(keepWaiting);
});
return deferred.promise;
}
/**
* Set CLIR (calling line id restriction).
*
* Fulfill params: (none)
* Reject params:
* 'RadioNotAvailable', 'RequestNotSupported', or 'GenericFailure'
*
* @param aMode
* A short number.
* @param aServiceId [optional]
* A numeric DSDS service id. Default: the one indicated in
* start*TestCommon() or 0 if not indicated.
*
* @return A deferred promise.
*/
function setClir(aMode, aServiceId) {
ok(true, "setClir(" + aMode + ", " + aServiceId + ")");
let mobileConn = getMozMobileConnectionByServiceId(aServiceId);
let request = mobileConn.setCallingLineIdRestriction(aMode);
return wrapDomRequestAsPromise(request);
}
/**
* Get CLIR (calling line id restriction).
*
* Fulfill params:
* CLIR mode.
* Reject params:
* 'RadioNotAvailable', 'RequestNotSupported', or 'GenericFailure'
*
* @param aServiceId [optional]
* A numeric DSDS service id. Default: the one indicated in
* start*TestCommon() or 0 if not indicated.
*
* @return A deferred promise.
*/
function getClir(aServiceId) {
ok(true, "getClir(" + aServiceId + ")");
let mobileConn = getMozMobileConnectionByServiceId(aServiceId);
let request = mobileConn.getCallingLineIdRestriction();
return wrapDomRequestAsPromise(request);
}
/**
* Set voice/data state and wait for state change.
*
@ -470,11 +588,7 @@ function setEmulatorRoamingAndWait(aRoaming, aServiceId) {
let state = (aRoaming ? "roaming" : "home");
return setEmulatorVoiceDataStateAndWait(aWhich, state, aServiceId)
.then(() => {
let mobileConn = mobileConnection;
if (aServiceId !== undefined) {
mobileConn =
workingFrame.contentWindow.navigator.mozMobileConnections[aServiceId];
}
let mobileConn = getMozMobileConnectionByServiceId(aServiceId);
is(mobileConn[aWhich].roaming, aRoaming,
aWhich + ".roaming")
});

View File

@ -25,4 +25,5 @@ qemu = true
[test_mobile_signal_strength.js]
[test_mobile_data_ipv6.js]
disabled = Bug 979137
[test_dsds_mobile_data_connection.js]
[test_dsds_mobile_data_connection.js]
[test_mobile_clir_radio_off.js]

View File

@ -0,0 +1,36 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 60000;
MARIONETTE_HEAD_JS = "head.js";
function testSetClirOnRadioOff(aMode) {
log("testSetClirOnRadioOff (set to mode: " + aMode + ")");
return Promise.resolve()
.then(() => setClir(aMode))
.then(() => {
ok(false, "shouldn't resolve");
}, (evt) => {
is(evt.target.error.name, "RadioNotAvailable");
});
}
function testGetClirOnRadioOff() {
log("testGetClirOnRadioOff");
return Promise.resolve()
.then(() => getClir())
.then(() => {
ok(false, "shouldn't resolve");
}, (evt) => {
is(evt.target.error.name, "RadioNotAvailable");
});
}
startTestCommon(function() {
return setRadioEnabledAndWait(false)
.then(() => testSetClirOnRadioOff(0))
.then(() => testGetClirOnRadioOff())
// Restore radio state.
.then(() => setRadioEnabledAndWait(true),
() => setRadioEnabledAnWait(true));
});