Bug 793111 - Part 3 - Test case r=vicamo

This commit is contained in:
Vicamo Yang 2012-11-27 21:29:13 +08:00
parent f9a4e3cb65
commit 6874786b5d
2 changed files with 113 additions and 2 deletions

View File

@ -9,6 +9,39 @@ let connection = navigator.mozMobileConnection;
ok(connection instanceof MozMobileConnection,
"connection is instanceof " + connection.constructor);
let emulatorCmdPendingCount = 0;
function sendEmulatorCommand(cmd, callback) {
emulatorCmdPendingCount++;
runEmulatorCmd(cmd, function (result) {
emulatorCmdPendingCount--;
is(result[result.length - 1], "OK");
callback(result);
});
}
function setEmulatorMccMnc(mcc, mnc, callback) {
let cmd = "operator set 0 Android,Android," + mcc + mnc;
sendEmulatorCommand(cmd, function (result) {
let re = new RegExp("" + mcc + mnc + "$");
ok(result[0].match(re), "MCC/MNC should be changed.");
if (callback) {
callback();
}
});
}
function waitForIccInfoChange(callback) {
connection.addEventListener("iccinfochange", function handler() {
connection.removeEventListener("iccinfochange", handler);
callback();
});
}
function finalize() {
SpecialPowers.removePermission("mobileconnection", document);
finish();
}
// The emulator's hard coded iccid value.
// See it here {B2G_HOME}/external/qemu/telephony/sim_card.c#L299.
is(connection.iccInfo.iccid, 89014103211118510720);
@ -22,5 +55,28 @@ is(connection.iccInfo.spn, "Android");
// See {B2G_HOME}/external/qemu/telephony/sim_card.c, in asimcard_io()
is(connection.iccInfo.msisdn, "15555215554");
SpecialPowers.removePermission("mobileconnection", document);
finish();
// Test display condition change.
function testDisplayConditionChange(func, caseArray, oncomplete) {
(function do_call(index) {
let next = index < (caseArray.length - 1) ? do_call.bind(null, index + 1) : oncomplete;
caseArray[index].push(next);
func.apply(null, caseArray[index]);
})(0);
}
function testSPN(mcc, mnc, expectedIsDisplayNetworkNameRequired,
expectedIsDisplaySpnRequired, callback) {
waitForIccInfoChange(function() {
is(connection.iccInfo.isDisplayNetworkNameRequired,
expectedIsDisplayNetworkNameRequired);
is(connection.iccInfo.isDisplaySpnRequired,
expectedIsDisplaySpnRequired);
window.setTimeout(callback, 0);
});
setEmulatorMccMnc(mcc, mnc);
}
testDisplayConditionChange(testSPN, [
[123, 456, false, true], // Not in HPLMN.
[310, 260, true, false], // inside HPLMN.
], finalize);

View File

@ -468,3 +468,58 @@ add_test(function test_stk_proactive_command_event_list() {
run_next_test();
});
add_test(function test_spn_display_condition() {
let RIL = newWorker({
postRILMessage: function fakePostRILMessage(data) {
// Do nothing
},
postMessage: function fakePostMessage(message) {
// Do nothing
}
}).RIL;
// Test updateDisplayCondition runs before any of SIM file is ready.
do_check_eq(RIL.updateDisplayCondition(), true);
do_check_eq(RIL.iccInfo.isDisplayNetworkNameRequired, true);
do_check_eq(RIL.iccInfo.isDisplaySpnRequired, false);
// Test with value.
function testDisplayCondition(iccDisplayCondition,
iccMcc, iccMnc, plmnMcc, plmnMnc,
expectedIsDisplayNetworkNameRequired,
expectedIsDisplaySPNRequired,
callback) {
RIL.iccInfoPrivate.SPN = {
spnDisplayCondition: iccDisplayCondition
};
RIL.iccInfo = {
mcc: iccMcc,
mnc: iccMnc
};
RIL.operator = {
mcc: plmnMcc,
mnc: plmnMnc
};
do_check_eq(RIL.updateDisplayCondition(), true);
do_check_eq(RIL.iccInfo.isDisplayNetworkNameRequired, expectedIsDisplayNetworkNameRequired);
do_check_eq(RIL.iccInfo.isDisplaySpnRequired, expectedIsDisplaySPNRequired);
do_timeout(0, callback);
};
function testDisplayConditions(func, caseArray, oncomplete) {
(function do_call(index) {
let next = index < (caseArray.length - 1) ? do_call.bind(null, index + 1) : oncomplete;
caseArray[index].push(next);
func.apply(null, caseArray[index]);
})(0);
}
testDisplayConditions(testDisplayCondition, [
[1, 123, 456, 123, 456, true, false],
[0, 123, 456, 123, 456, false, false],
[2, 123, 456, 123, 457, false, false],
[0, 123, 456, 123, 457, false, true],
], run_next_test);
});