tenfourfox/dom/icc/tests/marionette/test_icc_card_lock_enable_pin.js
Cameron Kaiser c9b2922b70 hello FPR
2017-04-19 00:56:45 -07:00

60 lines
1.7 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 60000;
MARIONETTE_HEAD_JS = "head.js";
function setCardLockAndCheck(aIcc, aLockType, aPin, aEnabled, aErrorName,
aRetryCount) {
let options = {
lockType: aLockType,
enabled: aEnabled,
pin: aPin
};
return aIcc.setCardLock(options)
.then((aResult) => {
if (aErrorName) {
ok(false, "setting pin should not success");
return;
}
// Check lock state.
return aIcc.getCardLock(aLockType)
.then((aResult) => {
is(aResult.enabled, aEnabled, "result.enabled");
});
}, (aError) => {
if (!aErrorName) {
ok(false, "setting pin should not fail");
return;
}
// Check the request error.
is(aError.name, aErrorName, "error.name");
is(aError.retryCount, aRetryCount, "error.retryCount");
});
}
// Start tests
startTestCommon(function() {
let icc = getMozIcc();
let lockType = "pin";
let retryCount;
return icc.getCardLockRetryCount(lockType)
// Get current PIN-lock retry count.
.then((aResult) => {
retryCount = aResult.retryCount;
ok(true, lockType + " retryCount is " + retryCount);
})
// Test fail to enable PIN-lock by passing wrong pin.
// The retry count should be decreased by 1.
.then(() => setCardLockAndCheck(icc, lockType, "1111", true,
"IncorrectPassword", retryCount -1))
// Test enabling PIN-lock.
.then(() => setCardLockAndCheck(icc, lockType, DEFAULT_PIN, true))
// Restore pin state.
.then(() => setCardLockAndCheck(icc, lockType, DEFAULT_PIN, false));
});