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