michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: MARIONETTE_TIMEOUT = 30000; michael@0: MARIONETTE_HEAD_JS = "icc_header.js"; michael@0: michael@0: function setRadioEnabled(enabled) { michael@0: let connection = navigator.mozMobileConnections[0]; michael@0: ok(connection); michael@0: michael@0: let request = connection.setRadioEnabled(enabled); michael@0: michael@0: request.onsuccess = function onsuccess() { michael@0: log('setRadioEnabled: ' + enabled); michael@0: }; michael@0: michael@0: request.onerror = function onerror() { michael@0: ok(false, "setRadioEnabled should be ok"); michael@0: }; michael@0: } michael@0: michael@0: function setEmulatorMccMnc(mcc, mnc) { michael@0: let cmd = "operator set 0 Android,Android," + mcc + mnc; michael@0: emulatorHelper.sendCommand(cmd, function(result) { michael@0: let re = new RegExp("" + mcc + mnc + "$"); michael@0: ok(result[0].match(re), "MCC/MNC should be changed."); michael@0: }); michael@0: } michael@0: michael@0: /* Basic test */ michael@0: taskHelper.push(function basicTest() { michael@0: let iccInfo = icc.iccInfo; michael@0: michael@0: // The emulator's hard coded iccid value. michael@0: // See it here {B2G_HOME}/external/qemu/telephony/sim_card.c#L299. michael@0: is(iccInfo.iccid, 89014103211118510720); michael@0: michael@0: if (iccInfo instanceof Ci.nsIDOMMozGsmIccInfo) { michael@0: log("Test Gsm IccInfo"); michael@0: is(iccInfo.iccType, "sim"); michael@0: is(iccInfo.spn, "Android"); michael@0: // The emulator's hard coded mcc and mnc codes. michael@0: // See it here {B2G_HOME}/external/qemu/telephony/android_modem.c#L2465. michael@0: is(iccInfo.mcc, 310); michael@0: is(iccInfo.mnc, 260); michael@0: // Phone number is hardcoded in MSISDN michael@0: // See {B2G_HOME}/external/qemu/telephony/sim_card.c, in asimcard_io() michael@0: is(iccInfo.msisdn, "15555215554"); michael@0: } else { michael@0: log("Test Cdma IccInfo"); michael@0: is(iccInfo.iccType, "ruim"); michael@0: // MDN is hardcoded as "8587777777". michael@0: // See it here {B2G_HOME}/hardware/ril/reference-ril/reference-ril.c, michael@0: // in requestCdmaSubscription() michael@0: is(iccInfo.mdn, "8587777777"); michael@0: // PRL version is hardcoded as 1. michael@0: // See it here {B2G_HOME}/hardware/ril/reference-ril/reference-ril.c, michael@0: // in requestCdmaSubscription() michael@0: is(iccInfo.prlVersion, 1); michael@0: } michael@0: michael@0: taskHelper.runNext(); michael@0: }); michael@0: michael@0: /* Test Gsm display condition change */ michael@0: taskHelper.push(function testGsmDisplayConditionChange() { michael@0: function testSPN(mcc, mnc, expectedIsDisplayNetworkNameRequired, michael@0: expectedIsDisplaySpnRequired, callback) { michael@0: icc.addEventListener("iccinfochange", function handler() { michael@0: icc.removeEventListener("iccinfochange", handler); michael@0: is(icc.iccInfo.isDisplayNetworkNameRequired, michael@0: expectedIsDisplayNetworkNameRequired); michael@0: is(icc.iccInfo.isDisplaySpnRequired, michael@0: expectedIsDisplaySpnRequired); michael@0: // operatorchange will be ignored if we send commands too soon. michael@0: window.setTimeout(callback, 100); michael@0: }); michael@0: // Send emulator command to change network mcc and mnc. michael@0: setEmulatorMccMnc(mcc, mnc); michael@0: } michael@0: michael@0: let testCases = [ michael@0: // [MCC, MNC, isDisplayNetworkNameRequired, isDisplaySpnRequired] michael@0: [123, 456, false, true], // Not in HPLMN. michael@0: [234, 136, true, true], // Not in HPLMN, but in PLMN specified in SPDI. michael@0: [123, 456, false, true], // Not in HPLMN. Triggering iccinfochange michael@0: [466, 92, true, true], // Not in HPLMN, but in another PLMN specified in SPDI. michael@0: [123, 456, false, true], // Not in HPLMN. Triggering iccinfochange michael@0: [310, 260, true, true], // inside HPLMN. michael@0: ]; michael@0: michael@0: // Ignore this test if device is not in gsm mode. michael@0: if (!(icc.iccInfo instanceof Ci.nsIDOMMozGsmIccInfo)) { michael@0: taskHelper.runNext(); michael@0: return; michael@0: } michael@0: michael@0: (function do_call(index) { michael@0: let next = index < (testCases.length - 1) ? do_call.bind(null, index + 1) : taskHelper.runNext.bind(taskHelper); michael@0: testCases[index].push(next); michael@0: testSPN.apply(null, testCases[index]); michael@0: })(0); michael@0: }); michael@0: michael@0: /* Test iccInfo when card becomes undetected */ michael@0: taskHelper.push(function testCardIsNotReady() { michael@0: // Turn off radio. michael@0: setRadioEnabled(false); michael@0: icc.addEventListener("iccinfochange", function oniccinfochange() { michael@0: // Expect iccInfo changes to null michael@0: if (icc.iccInfo === null) { michael@0: icc.removeEventListener("iccinfochange", oniccinfochange); michael@0: // We should restore radio status and expect to get iccdetected event. michael@0: setRadioEnabled(true); michael@0: iccManager.addEventListener("iccdetected", function oniccdetected(evt) { michael@0: log("icc detected: " + evt.iccId); michael@0: iccManager.removeEventListener("iccdetected", oniccdetected); michael@0: taskHelper.runNext(); michael@0: }); michael@0: } michael@0: }); michael@0: }); michael@0: michael@0: // Start test michael@0: taskHelper.runNext();