Bug 939038 - [DSDS] Follow-up to Bug 814629: add test case for iccchange event. r=hsinyi

This commit is contained in:
Jessica Jong 2014-01-14 02:19:00 +08:00
parent 1d99a3a60b
commit 2e25fd93e2
2 changed files with 85 additions and 0 deletions

View File

@ -20,4 +20,5 @@ disabled = Bug 808783
[test_call_barring_change_password.js]
[test_mobile_set_radio.js]
[test_mobile_last_known_network.js]
[test_mobile_icc_change.js]
[test_mobile_connections_array_uninitialized.js]

View File

@ -0,0 +1,84 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 30000;
SpecialPowers.addPermission("mobileconnection", true, document);
// Permission changes can't change existing Navigator.prototype
// objects, so grab our objects from a new Navigator
let ifr = document.createElement("iframe");
let connection;
ifr.onload = function() {
connection = ifr.contentWindow.navigator.mozMobileConnections[0];
ok(connection instanceof ifr.contentWindow.MozMobileConnection,
"connection is instanceof " + connection.constructor);
// The emulator's hard coded iccid value.
// See it here {B2G_HOME}/external/qemu/telephony/sim_card.c.
is(connection.iccId, 89014103211118510720);
runNextTest();
};
document.body.appendChild(ifr);
function waitForIccChange(callback) {
connection.addEventListener("iccchange", function handler() {
connection.removeEventListener("iccchange", handler);
callback();
});
}
function setRadioEnabled(enabled) {
let request = connection.setRadioEnabled(enabled);
request.onsuccess = function onsuccess() {
log('setRadioEnabled: ' + enabled);
};
request.onerror = function onerror() {
ok(false, "setRadioEnabled should be ok");
};
}
function testIccChangeOnRadioPowerOff() {
// Turn off radio
setRadioEnabled(false);
waitForIccChange(function() {
is(connection.iccId, null);
runNextTest();
});
}
function testIccChangeOnRadioPowerOn() {
// Turn on radio
setRadioEnabled(true);
waitForIccChange(function() {
// The emulator's hard coded iccid value.
is(connection.iccId, 89014103211118510720);
runNextTest();
});
}
let tests = [
testIccChangeOnRadioPowerOff,
testIccChangeOnRadioPowerOn
];
function runNextTest() {
let test = tests.shift();
if (!test) {
cleanUp();
return;
}
test();
}
function cleanUp() {
SpecialPowers.removePermission("mobileconnection", document);
finish();
}