mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 874744 - Part 4: Marionette tests for cardstate. r=allstars.chh
This commit is contained in:
parent
0a27223488
commit
b6aa45087a
@ -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]
|
||||
|
61
dom/icc/tests/marionette/test_icc_card_state.js
Normal file
61
dom/icc/tests/marionette/test_icc_card_state.js
Normal 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)
|
||||
);
|
Loading…
Reference in New Issue
Block a user