Bug 874744 - Part 4: Marionette tests for cardstate. r=allstars.chh

This commit is contained in:
Edgar Chen 2013-05-29 15:47:18 +08:00
parent 0a27223488
commit b6aa45087a
2 changed files with 62 additions and 0 deletions

View File

@ -6,6 +6,7 @@ qemu = true
[test_stk_proactive_command.js]
[test_icc_contact.js]
[test_icc_card_lock.js]
[test_icc_card_state.js]
[test_stk_refresh.js]
[test_stk_poll_off.js]
[test_stk_setup_event_list.js]

View File

@ -0,0 +1,61 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 30000;
SpecialPowers.addPermission("mobileconnection", true, document);
SpecialPowers.addPermission("settings-write", true, document);
let icc = navigator.mozIccManager;
ok(icc instanceof MozIccManager, "icc is instanceof " + icc.constructor);
is(icc.cardState, "ready");
function setAirplaneModeEnabled(enabled) {
let settings = window.navigator.mozSettings;
let setLock = settings.createLock();
let obj = {
"ril.radio.disabled": enabled
};
let setReq = setLock.set(obj);
log("set airplane mode to " + enabled);
setReq.addEventListener("success", function onSetSuccess() {
log("set 'ril.radio.disabled' to " + enabled);
});
setReq.addEventListener("error", function onSetError() {
ok(false, "cannot set 'ril.radio.disabled' to " + enabled);
});
}
function waitCardStateChangedEvent(expectedCardState, callback) {
icc.addEventListener("cardstatechange", function oncardstatechange() {
log("card state changes to " + icc.cardState);
if (icc.cardState === expectedCardState) {
log("got expected card state: " + icc.cardState);
icc.removeEventListener("cardstatechange", oncardstatechange);
callback();
}
});
}
// Test cardstatechange event by switching airplane mode
function testCardStateChange(airplaneMode, expectedCardState, callback) {
setAirplaneModeEnabled(airplaneMode);
waitCardStateChangedEvent(expectedCardState, callback);
}
function cleanUp() {
SpecialPowers.removePermission("mobileconnection", document);
SpecialPowers.removePermission("settings-write", document);
finish();
}
// Enable Airplane mode, expect got cardstatechange to null
testCardStateChange(true, null,
// Disable Airplane mode, expect got cardstatechange to 'ready'
testCardStateChange.bind(this, false, "ready", cleanUp)
);