Bug 979134 (follow-up): convert test_call_barring_change_password.js to Promise. r=vicamo

This commit is contained in:
Edgar Chen 2014-06-19 16:27:15 +08:00
parent 95ebdf0d5b
commit 6a5cd449a7
2 changed files with 54 additions and 52 deletions

View File

@ -566,7 +566,7 @@ function sendMMI(aMmi) {
* Query current voice privacy mode. * Query current voice privacy mode.
* *
* Fulfill params: * Fulfill params:
A boolean indicates the current voice privacy mode. * A boolean indicates the current voice privacy mode.
* Reject params: * Reject params:
* 'RadioNotAvailable', 'RequestNotSupported', or 'GenericFailure'. * 'RadioNotAvailable', 'RequestNotSupported', or 'GenericFailure'.
* *
@ -578,6 +578,21 @@ function sendMMI(aMmi) {
.then(() => request.result, () => { throw request.error }); .then(() => request.result, () => { throw request.error });
} }
/**
* Change call barring facility password.
*
* Fulfill params: (none)
* Reject params:
* 'RadioNotAvailable', 'RequestNotSupported', or 'GenericFailure'.
*
* @return A deferred promise.
*/
function changeCallBarringPassword(aOptions) {
let request = mobileConnection.changeCallBarringPassword(aOptions);
return wrapDomRequestAsPromise(request)
.then(null, () => { throw request.error });
}
/** /**
* Set data connection enabling state and wait for "datachange" event. * Set data connection enabling state and wait for "datachange" event.
* *

View File

@ -2,62 +2,49 @@
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 60000; MARIONETTE_TIMEOUT = 60000;
MARIONETTE_HEAD_JS = "head.js";
SpecialPowers.addPermission("mobileconnection", true, document); const TEST_DATA = [
// [<pin>, <new pin>, <expected error>]
// Permission changes can't change existing Navigator.prototype // Test passing an invalid pin or newPin.
// objects, so grab our objects from a new Navigator [null, "0000", "InvalidPassword"],
let ifr = document.createElement("iframe"); ["0000", null, "InvalidPassword"],
let connection; [null, null, "InvalidPassword"],
ifr.onload = function() {
connection = ifr.contentWindow.navigator.mozMobileConnections[0];
ok(connection instanceof ifr.contentWindow.MozMobileConnection, // Test passing mismatched newPin.
"connection is instanceof " + connection.constructor); ["000", "0000", "InvalidPassword"],
["00000", "1111", "InvalidPassword"],
["abcd", "efgh", "InvalidPassword"],
setTimeout(testChangeCallBarringPasswordWithFailure, 0); // TODO: Bug 906603 - B2G RIL: Support Change Call Barring Password on Emulator.
}; // Currently emulator doesn't support REQUEST_CHANGE_BARRING_PASSWORD, so we
document.body.appendChild(ifr); // expect to get a 'RequestNotSupported' error here.
["1234", "1234", "RequestNotSupported"]
function testChangeCallBarringPasswordWithFailure() {
// Incorrect parameters, expect onerror callback.
let options = [
{pin: null, newPin: '0000'},
{pin: '0000', newPin: null},
{pin: null, newPin: null},
{pin: '000', newPin: '0000'},
{pin: '00000', newPin: '1111'},
{pin: 'abcd', newPin: 'efgh'},
]; ];
function do_test() { function testChangeCallBarringPassword(aPin, aNewPin, aExpectedError) {
for (let i = 0; i < options.length; i++) { log("Test changing call barring password to " + aPin + "/" + aNewPin);
let request = connection.changeCallBarringPassword(options[i]);
request.onsuccess = function() { let options = {
ok(false, 'Unexpected result.'); pin: aPin,
setTimeout(cleanUp , 0); newPin: aNewPin
}; };
return changeCallBarringPassword(options)
request.onerror = function() { .then(function resolve() {
ok(request.error.name === 'InvalidPassword', 'InvalidPassword'); ok(!aExpectedError, "changeCallBarringPassword success");
if (i >= options.length) { }, function reject(aError) {
setTimeout(testChangeCallBarringPasswordWithSuccess, 0); is(aError.name, aExpectedError, "failed to changeCallBarringPassword");
} });
};
}
} }
do_test(); // Start tests
} startTestCommon(function() {
let promise = Promise.resolve();
function testChangeCallBarringPasswordWithSuccess() { for (let i = 0; i < TEST_DATA.length; i++) {
// TODO: Bug 906603 - B2G RIL: Support Change Call Barring Password on let data = TEST_DATA[i];
// Emulator. promise =
setTimeout(cleanUp , 0); promise.then(() => testChangeCallBarringPassword(data[0], data[1], data[2]));
}
function cleanUp() {
SpecialPowers.removePermission("mobileconnection", document);
finish();
} }
return promise;
});