dom/icc/tests/marionette/test_icc_info.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 MARIONETTE_TIMEOUT = 30000;
michael@0 5 MARIONETTE_HEAD_JS = "icc_header.js";
michael@0 6
michael@0 7 function setRadioEnabled(enabled) {
michael@0 8 let connection = navigator.mozMobileConnections[0];
michael@0 9 ok(connection);
michael@0 10
michael@0 11 let request = connection.setRadioEnabled(enabled);
michael@0 12
michael@0 13 request.onsuccess = function onsuccess() {
michael@0 14 log('setRadioEnabled: ' + enabled);
michael@0 15 };
michael@0 16
michael@0 17 request.onerror = function onerror() {
michael@0 18 ok(false, "setRadioEnabled should be ok");
michael@0 19 };
michael@0 20 }
michael@0 21
michael@0 22 function setEmulatorMccMnc(mcc, mnc) {
michael@0 23 let cmd = "operator set 0 Android,Android," + mcc + mnc;
michael@0 24 emulatorHelper.sendCommand(cmd, function(result) {
michael@0 25 let re = new RegExp("" + mcc + mnc + "$");
michael@0 26 ok(result[0].match(re), "MCC/MNC should be changed.");
michael@0 27 });
michael@0 28 }
michael@0 29
michael@0 30 /* Basic test */
michael@0 31 taskHelper.push(function basicTest() {
michael@0 32 let iccInfo = icc.iccInfo;
michael@0 33
michael@0 34 // The emulator's hard coded iccid value.
michael@0 35 // See it here {B2G_HOME}/external/qemu/telephony/sim_card.c#L299.
michael@0 36 is(iccInfo.iccid, 89014103211118510720);
michael@0 37
michael@0 38 if (iccInfo instanceof Ci.nsIDOMMozGsmIccInfo) {
michael@0 39 log("Test Gsm IccInfo");
michael@0 40 is(iccInfo.iccType, "sim");
michael@0 41 is(iccInfo.spn, "Android");
michael@0 42 // The emulator's hard coded mcc and mnc codes.
michael@0 43 // See it here {B2G_HOME}/external/qemu/telephony/android_modem.c#L2465.
michael@0 44 is(iccInfo.mcc, 310);
michael@0 45 is(iccInfo.mnc, 260);
michael@0 46 // Phone number is hardcoded in MSISDN
michael@0 47 // See {B2G_HOME}/external/qemu/telephony/sim_card.c, in asimcard_io()
michael@0 48 is(iccInfo.msisdn, "15555215554");
michael@0 49 } else {
michael@0 50 log("Test Cdma IccInfo");
michael@0 51 is(iccInfo.iccType, "ruim");
michael@0 52 // MDN is hardcoded as "8587777777".
michael@0 53 // See it here {B2G_HOME}/hardware/ril/reference-ril/reference-ril.c,
michael@0 54 // in requestCdmaSubscription()
michael@0 55 is(iccInfo.mdn, "8587777777");
michael@0 56 // PRL version is hardcoded as 1.
michael@0 57 // See it here {B2G_HOME}/hardware/ril/reference-ril/reference-ril.c,
michael@0 58 // in requestCdmaSubscription()
michael@0 59 is(iccInfo.prlVersion, 1);
michael@0 60 }
michael@0 61
michael@0 62 taskHelper.runNext();
michael@0 63 });
michael@0 64
michael@0 65 /* Test Gsm display condition change */
michael@0 66 taskHelper.push(function testGsmDisplayConditionChange() {
michael@0 67 function testSPN(mcc, mnc, expectedIsDisplayNetworkNameRequired,
michael@0 68 expectedIsDisplaySpnRequired, callback) {
michael@0 69 icc.addEventListener("iccinfochange", function handler() {
michael@0 70 icc.removeEventListener("iccinfochange", handler);
michael@0 71 is(icc.iccInfo.isDisplayNetworkNameRequired,
michael@0 72 expectedIsDisplayNetworkNameRequired);
michael@0 73 is(icc.iccInfo.isDisplaySpnRequired,
michael@0 74 expectedIsDisplaySpnRequired);
michael@0 75 // operatorchange will be ignored if we send commands too soon.
michael@0 76 window.setTimeout(callback, 100);
michael@0 77 });
michael@0 78 // Send emulator command to change network mcc and mnc.
michael@0 79 setEmulatorMccMnc(mcc, mnc);
michael@0 80 }
michael@0 81
michael@0 82 let testCases = [
michael@0 83 // [MCC, MNC, isDisplayNetworkNameRequired, isDisplaySpnRequired]
michael@0 84 [123, 456, false, true], // Not in HPLMN.
michael@0 85 [234, 136, true, true], // Not in HPLMN, but in PLMN specified in SPDI.
michael@0 86 [123, 456, false, true], // Not in HPLMN. Triggering iccinfochange
michael@0 87 [466, 92, true, true], // Not in HPLMN, but in another PLMN specified in SPDI.
michael@0 88 [123, 456, false, true], // Not in HPLMN. Triggering iccinfochange
michael@0 89 [310, 260, true, true], // inside HPLMN.
michael@0 90 ];
michael@0 91
michael@0 92 // Ignore this test if device is not in gsm mode.
michael@0 93 if (!(icc.iccInfo instanceof Ci.nsIDOMMozGsmIccInfo)) {
michael@0 94 taskHelper.runNext();
michael@0 95 return;
michael@0 96 }
michael@0 97
michael@0 98 (function do_call(index) {
michael@0 99 let next = index < (testCases.length - 1) ? do_call.bind(null, index + 1) : taskHelper.runNext.bind(taskHelper);
michael@0 100 testCases[index].push(next);
michael@0 101 testSPN.apply(null, testCases[index]);
michael@0 102 })(0);
michael@0 103 });
michael@0 104
michael@0 105 /* Test iccInfo when card becomes undetected */
michael@0 106 taskHelper.push(function testCardIsNotReady() {
michael@0 107 // Turn off radio.
michael@0 108 setRadioEnabled(false);
michael@0 109 icc.addEventListener("iccinfochange", function oniccinfochange() {
michael@0 110 // Expect iccInfo changes to null
michael@0 111 if (icc.iccInfo === null) {
michael@0 112 icc.removeEventListener("iccinfochange", oniccinfochange);
michael@0 113 // We should restore radio status and expect to get iccdetected event.
michael@0 114 setRadioEnabled(true);
michael@0 115 iccManager.addEventListener("iccdetected", function oniccdetected(evt) {
michael@0 116 log("icc detected: " + evt.iccId);
michael@0 117 iccManager.removeEventListener("iccdetected", oniccdetected);
michael@0 118 taskHelper.runNext();
michael@0 119 });
michael@0 120 }
michael@0 121 });
michael@0 122 });
michael@0 123
michael@0 124 // Start test
michael@0 125 taskHelper.runNext();

mercurial