merge b2g-inbound to m-c a=merge

This commit is contained in:
Wes Kocher 2014-06-23 18:55:45 -07:00
commit 0c3673b6ff
93 changed files with 4755 additions and 4546 deletions

View File

@ -911,9 +911,6 @@ pref("gfx.canvas.max-size-for-skia-gl", -1);
// enable fence with readpixels for SurfaceStream
pref("gfx.gralloc.fence-with-readpixels", true);
// Cell Broadcast API
pref("ril.cellbroadcast.disabled", false);
// The url of the page used to display network error details.
pref("b2g.neterror.url", "app://system.gaiamobile.org/net_error.html");

View File

@ -664,13 +664,13 @@ let settingsToObserve = {
defaultValue: false
},
'devtools.eventlooplag.threshold': 100,
'dom.mozApps.use_reviewer_certs': false,
'layers.draw-borders': false,
'layers.draw-tile-borders': false,
'layers.dump': false,
'layers.enable-tiles': true,
'layers.simple-tiles': false,
'privacy.donottrackheader.enabled': false,
'ril.cellbroadcast.disabled': false,
'ril.radio.disabled': false,
'ril.mms.requestReadReport.enabled': {
prefName: 'dom.mms.requestReadReport',

View File

@ -40,6 +40,7 @@ category app-startup ProcessGlobal service,@mozilla.org/b2g-process-global;1
# OMAContentHandler.js
component {a6b2ab13-9037-423a-9897-dde1081be323} OMAContentHandler.js
contract @mozilla.org/uriloader/content-handler;1?type=application/vnd.oma.drm.message {a6b2ab13-9037-423a-9897-dde1081be323}
contract @mozilla.org/uriloader/content-handler;1?type=application/vnd.oma.dd+xml {a6b2ab13-9037-423a-9897-dde1081be323}
# PaymentGlue.js
component {8b83eabc-7929-47f4-8b48-4dea8d887e4b} PaymentGlue.js

View File

@ -19,13 +19,13 @@
<copyfile dest="Makefile" src="core/root.mk"/>
</project>
<project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="41cc1de26e4edbe12add0009cdc0bd292f2e94fe"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="45479c07cb6ba8c733093d6ee32c767c090c9a28"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="bbb7659d8ea2afb396f99b3dc971ab3c42da3778"/>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="platform_hardware_ril" path="hardware/ril" remote="b2g" revision="cd88d860656c31c7da7bb310d6a160d0011b0961"/>
<project name="platform_external_qemu" path="external/qemu" remote="b2g" revision="3326b51017252e09ccdd715dec6c5e12a7d1ecfe"/>
<project name="moztt" path="external/moztt" remote="b2g" revision="c510babaf88dfa2cfe2c202afb2649ee124569af"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="23db533981ee2cd04fc5d946420402aed2792381"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="c2544b1797eb5c59f484c442a24c4dc14c37e68c"/>
<!-- Stock Android things -->
<project name="platform/abi/cpp" path="abi/cpp" revision="dd924f92906085b831bf1cbbc7484d3c043d613c"/>
<project name="platform/bionic" path="bionic" revision="c72b8f6359de7ed17c11ddc9dfdde3f615d188a9"/>

View File

@ -17,10 +17,10 @@
</project>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
<project name="gaia" path="gaia" remote="mozillaorg" revision="41cc1de26e4edbe12add0009cdc0bd292f2e94fe"/>
<project name="gaia" path="gaia" remote="mozillaorg" revision="45479c07cb6ba8c733093d6ee32c767c090c9a28"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="bbb7659d8ea2afb396f99b3dc971ab3c42da3778"/>
<project name="moztt" path="external/moztt" remote="b2g" revision="c510babaf88dfa2cfe2c202afb2649ee124569af"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="23db533981ee2cd04fc5d946420402aed2792381"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="c2544b1797eb5c59f484c442a24c4dc14c37e68c"/>
<project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
<project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
<!-- Stock Android things -->

View File

@ -15,7 +15,7 @@
<project name="platform_build" path="build" remote="b2g" revision="276ce45e78b09c4a4ee643646f691d22804754c1">
<copyfile dest="Makefile" src="core/root.mk"/>
</project>
<project name="gaia" path="gaia" remote="mozillaorg" revision="41cc1de26e4edbe12add0009cdc0bd292f2e94fe"/>
<project name="gaia" path="gaia" remote="mozillaorg" revision="45479c07cb6ba8c733093d6ee32c767c090c9a28"/>
<project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="bbb7659d8ea2afb396f99b3dc971ab3c42da3778"/>
<project name="librecovery" path="librecovery" remote="b2g" revision="891e5069c0ad330d8191bf8c7b879c814258c89f"/>
@ -23,7 +23,7 @@
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
<project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="23db533981ee2cd04fc5d946420402aed2792381"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="c2544b1797eb5c59f484c442a24c4dc14c37e68c"/>
<!-- Stock Android things -->
<project groups="linux" name="platform/prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6" path="prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6" revision="f92a936f2aa97526d4593386754bdbf02db07a12"/>
<project groups="linux" name="platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6" path="prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6" revision="6e47ff2790f5656b5b074407829ceecf3e6188c4"/>

View File

@ -19,13 +19,13 @@
<copyfile dest="Makefile" src="core/root.mk"/>
</project>
<project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="41cc1de26e4edbe12add0009cdc0bd292f2e94fe"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="45479c07cb6ba8c733093d6ee32c767c090c9a28"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="bbb7659d8ea2afb396f99b3dc971ab3c42da3778"/>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="platform_hardware_ril" path="hardware/ril" remote="b2g" revision="cd88d860656c31c7da7bb310d6a160d0011b0961"/>
<project name="platform_external_qemu" path="external/qemu" remote="b2g" revision="3326b51017252e09ccdd715dec6c5e12a7d1ecfe"/>
<project name="moztt" path="external/moztt" remote="b2g" revision="c510babaf88dfa2cfe2c202afb2649ee124569af"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="23db533981ee2cd04fc5d946420402aed2792381"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="c2544b1797eb5c59f484c442a24c4dc14c37e68c"/>
<!-- Stock Android things -->
<project name="platform/abi/cpp" path="abi/cpp" revision="dd924f92906085b831bf1cbbc7484d3c043d613c"/>
<project name="platform/bionic" path="bionic" revision="c72b8f6359de7ed17c11ddc9dfdde3f615d188a9"/>

View File

@ -17,10 +17,10 @@
</project>
<project name="librecovery" path="librecovery" remote="b2g" revision="891e5069c0ad330d8191bf8c7b879c814258c89f"/>
<project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
<project name="gaia" path="gaia" remote="mozillaorg" revision="41cc1de26e4edbe12add0009cdc0bd292f2e94fe"/>
<project name="gaia" path="gaia" remote="mozillaorg" revision="45479c07cb6ba8c733093d6ee32c767c090c9a28"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="bbb7659d8ea2afb396f99b3dc971ab3c42da3778"/>
<project name="moztt" path="external/moztt" remote="b2g" revision="c510babaf88dfa2cfe2c202afb2649ee124569af"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="23db533981ee2cd04fc5d946420402aed2792381"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="c2544b1797eb5c59f484c442a24c4dc14c37e68c"/>
<project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
<project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
<!-- Stock Android things -->
@ -114,11 +114,13 @@
<project name="platform/system/netd" path="system/netd" revision="ea8103eae5642621ca8202e00620f4ca954ed413"/>
<project name="platform/system/security" path="system/security" revision="360f51f7af191316cd739f229db1c5f7233be063"/>
<project name="platform/system/vold" path="system/vold" revision="153df4d067a4149c7d78f1c92fed2ce2bd6a272e"/>
<!--original fetch url was git://github.com/t2m-foxfone/-->
<remote fetch="https://git.mozilla.org/external/t2m-foxfone" name="t2m"/>
<default remote="caf" revision="jb_3.2" sync-j="4"/>
<!-- Flame specific things -->
<project name="device/generic/armv7-a-neon" path="device/generic/armv7-a-neon" revision="e8a318f7690092e639ba88891606f4183e846d3f"/>
<project name="device/qcom/common" path="device/qcom/common" revision="34ed8345250bb97262d70a052217a92e83444ede"/>
<project name="device-flame" path="device/t2m/flame" remote="b2g" revision="243b6f3d219592a84c7318e9446cde397233ae39"/>
<project name="device-flame" path="device/t2m/flame" remote="b2g" revision="33faca8033c6f8cda0c383ab40d69c7a45e6db38"/>
<project name="codeaurora_kernel_msm" path="kernel" remote="b2g" revision="30a441fb7275fc5bc347f84ccb29e977a7eca34e"/>
<project name="kernel_lk" path="bootable/bootloader/lk" remote="b2g" revision="2b1d8b5b7a760230f4c94c02e733e3929f44253a"/>
<project name="platform_bootable_recovery" path="bootable/recovery" remote="b2g" revision="e81502511cda303c803e63f049574634bc96f9f2"/>
@ -126,7 +128,7 @@
<project name="platform/external/bluetooth/bluez" path="external/bluetooth/bluez" revision="f0689ac1914cdbc59e53bdc9edd9013dc157c299"/>
<project name="platform/external/bluetooth/glib" path="external/bluetooth/glib" revision="dd925f76e4f149c3d5571b80e12f7e24bbe89c59"/>
<project name="platform/external/dbus" path="external/dbus" revision="ea87119c843116340f5df1d94eaf8275e1055ae8"/>
<project name="platform/external/libnfc-nci" path="external/libnfc-nci" revision="494c177966fdc31183a5f7af82dc9130f523da4b"/>
<project name="platform_external_libnfc-nci" path="external/libnfc-nci" remote="t2m" revision="4186bdecb4dae911b39a8202252cc2310d91b0be"/>
<project name="platform/external/wpa_supplicant_8" path="external/wpa_supplicant_8" revision="320b05a5761eb2a4816f7529c91ea49422979b55"/>
<project name="platform/frameworks/av" path="frameworks/av" revision="5b934dc57dae25f286b0e7210dc6ff47f3244927"/>
<project name="platform/frameworks/base" path="frameworks/base" revision="af3e4fbdc9369643a92015ea2657361f3b1b46fe"/>

View File

@ -4,6 +4,6 @@
"remote": "",
"branch": ""
},
"revision": "aba00cfd579caaf205e05c269f0a8100f242f39c",
"revision": "8ac363347c96715adf6bec5fc30a975a2cfbaafd",
"repo_path": "/integration/gaia-central"
}

View File

@ -17,12 +17,12 @@
<copyfile dest="Makefile" src="core/root.mk"/>
</project>
<project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="41cc1de26e4edbe12add0009cdc0bd292f2e94fe"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="45479c07cb6ba8c733093d6ee32c767c090c9a28"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="bbb7659d8ea2afb396f99b3dc971ab3c42da3778"/>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="librecovery" path="librecovery" remote="b2g" revision="891e5069c0ad330d8191bf8c7b879c814258c89f"/>
<project name="moztt" path="external/moztt" remote="b2g" revision="c510babaf88dfa2cfe2c202afb2649ee124569af"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="23db533981ee2cd04fc5d946420402aed2792381"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="c2544b1797eb5c59f484c442a24c4dc14c37e68c"/>
<!-- Stock Android things -->
<project name="platform/abi/cpp" path="abi/cpp" revision="6426040f1be4a844082c9769171ce7f5341a5528"/>
<project name="platform/bionic" path="bionic" revision="d2eb6c7b6e1bc7643c17df2d9d9bcb1704d0b9ab"/>

View File

@ -15,7 +15,7 @@
<copyfile dest="Makefile" src="core/root.mk"/>
</project>
<project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="41cc1de26e4edbe12add0009cdc0bd292f2e94fe"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="45479c07cb6ba8c733093d6ee32c767c090c9a28"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="bbb7659d8ea2afb396f99b3dc971ab3c42da3778"/>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="librecovery" path="librecovery" remote="b2g" revision="891e5069c0ad330d8191bf8c7b879c814258c89f"/>

View File

@ -17,10 +17,10 @@
</project>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
<project name="gaia" path="gaia" remote="mozillaorg" revision="41cc1de26e4edbe12add0009cdc0bd292f2e94fe"/>
<project name="gaia" path="gaia" remote="mozillaorg" revision="45479c07cb6ba8c733093d6ee32c767c090c9a28"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="bbb7659d8ea2afb396f99b3dc971ab3c42da3778"/>
<project name="moztt" path="external/moztt" remote="b2g" revision="c510babaf88dfa2cfe2c202afb2649ee124569af"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="23db533981ee2cd04fc5d946420402aed2792381"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="c2544b1797eb5c59f484c442a24c4dc14c37e68c"/>
<project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
<project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
<!-- Stock Android things -->

View File

@ -17,12 +17,12 @@
<copyfile dest="Makefile" src="core/root.mk"/>
</project>
<project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="41cc1de26e4edbe12add0009cdc0bd292f2e94fe"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="45479c07cb6ba8c733093d6ee32c767c090c9a28"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="bbb7659d8ea2afb396f99b3dc971ab3c42da3778"/>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="librecovery" path="librecovery" remote="b2g" revision="891e5069c0ad330d8191bf8c7b879c814258c89f"/>
<project name="moztt" path="external/moztt" remote="b2g" revision="c510babaf88dfa2cfe2c202afb2649ee124569af"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="23db533981ee2cd04fc5d946420402aed2792381"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="c2544b1797eb5c59f484c442a24c4dc14c37e68c"/>
<project name="gonk-patches" path="patches" remote="b2g" revision="223a2421006e8f5da33f516f6891c87cae86b0f6"/>
<!-- Stock Android things -->
<project name="platform/abi/cpp" path="abi/cpp" revision="6426040f1be4a844082c9769171ce7f5341a5528"/>

View File

@ -36,17 +36,20 @@ AlarmDB.prototype = {
this.initDBHelper(ALARMDB_NAME, ALARMDB_VERSION, [ALARMSTORE_NAME]);
},
upgradeSchema: function upgradeSchema(aTransaction, aDb, aOldVersion, aNewVersion) {
upgradeSchema: function upgradeSchema(aTransaction, aDb,
aOldVersion, aNewVersion) {
debug("upgradeSchema()");
let objectStore = aDb.createObjectStore(ALARMSTORE_NAME, { keyPath: "id", autoIncrement: true });
let objStore =
aDb.createObjectStore(ALARMSTORE_NAME,
{ keyPath: "id", autoIncrement: true });
objectStore.createIndex("date", "date", { unique: false });
objectStore.createIndex("ignoreTimezone", "ignoreTimezone", { unique: false });
objectStore.createIndex("timezoneOffset", "timezoneOffset", { unique: false });
objectStore.createIndex("data", "data", { unique: false });
objectStore.createIndex("pageURL", "pageURL", { unique: false });
objectStore.createIndex("manifestURL", "manifestURL", { unique: false });
objStore.createIndex("date", "date", { unique: false });
objStore.createIndex("ignoreTimezone", "ignoreTimezone", { unique: false });
objStore.createIndex("timezoneOffset", "timezoneOffset", { unique: false });
objStore.createIndex("data", "data", { unique: false });
objStore.createIndex("pageURL", "pageURL", { unique: false });
objStore.createIndex("manifestURL", "manifestURL", { unique: false });
debug("Created object stores and indexes");
},
@ -62,19 +65,13 @@ AlarmDB.prototype = {
add: function add(aAlarm, aSuccessCb, aErrorCb) {
debug("add()");
this.newTxn(
"readwrite",
ALARMSTORE_NAME,
function txnCb(aTxn, aStore) {
debug("Going to add " + JSON.stringify(aAlarm));
aStore.put(aAlarm).onsuccess = function setTxnResult(aEvent) {
aTxn.result = aEvent.target.result;
debug("Request successful. New record ID: " + aTxn.result);
};
},
aSuccessCb,
aErrorCb
);
this.newTxn("readwrite", ALARMSTORE_NAME, function txnCb(aTxn, aStore) {
debug("Going to add " + JSON.stringify(aAlarm));
aStore.put(aAlarm).onsuccess = function setTxnResult(aEvent) {
aTxn.result = aEvent.target.result;
debug("Request successful. New record ID: " + aTxn.result);
};
}, aSuccessCb, aErrorCb);
},
/**
@ -92,33 +89,27 @@ AlarmDB.prototype = {
remove: function remove(aId, aManifestURL, aSuccessCb, aErrorCb) {
debug("remove()");
this.newTxn(
"readwrite",
ALARMSTORE_NAME,
function txnCb(aTxn, aStore) {
debug("Going to remove " + aId);
this.newTxn("readwrite", ALARMSTORE_NAME, function txnCb(aTxn, aStore) {
debug("Going to remove " + aId);
// Look up the existing record and compare the manifestURL
// to see if the alarm to be removed belongs to this app.
aStore.get(aId).onsuccess = function doRemove(aEvent) {
let alarm = aEvent.target.result;
// Look up the existing record and compare the manifestURL
// to see if the alarm to be removed belongs to this app.
aStore.get(aId).onsuccess = function doRemove(aEvent) {
let alarm = aEvent.target.result;
if (!alarm) {
debug("Alarm doesn't exist. No need to remove it.");
return;
}
if (!alarm) {
debug("Alarm doesn't exist. No need to remove it.");
return;
}
if (aManifestURL && aManifestURL != alarm.manifestURL) {
debug("Cannot remove the alarm added by other apps.");
return;
}
if (aManifestURL && aManifestURL != alarm.manifestURL) {
debug("Cannot remove the alarm added by other apps.");
return;
}
aStore.delete(aId);
};
},
aSuccessCb,
aErrorCb
);
aStore.delete(aId);
};
}, aSuccessCb, aErrorCb);
},
/**
@ -134,22 +125,16 @@ AlarmDB.prototype = {
getAll: function getAll(aManifestURL, aSuccessCb, aErrorCb) {
debug("getAll()");
this.newTxn(
"readonly",
ALARMSTORE_NAME,
function txnCb(aTxn, aStore) {
if (!aTxn.result) {
aTxn.result = [];
}
this.newTxn("readonly", ALARMSTORE_NAME, function txnCb(aTxn, aStore) {
if (!aTxn.result) {
aTxn.result = [];
}
let index = aStore.index("manifestURL");
index.mozGetAll(aManifestURL).onsuccess = function setTxnResult(aEvent) {
aTxn.result = aEvent.target.result;
debug("Request successful. Record count: " + aTxn.result.length);
};
},
aSuccessCb,
aErrorCb
);
let index = aStore.index("manifestURL");
index.mozGetAll(aManifestURL).onsuccess = function setTxnResult(aEvent) {
aTxn.result = aEvent.target.result;
debug("Request successful. Record count: " + aTxn.result.length);
};
}, aSuccessCb, aErrorCb);
}
};

View File

@ -29,11 +29,13 @@ XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
"nsIMessageListenerManager");
XPCOMUtils.defineLazyGetter(this, "messenger", function() {
return Cc["@mozilla.org/system-message-internal;1"].getService(Ci.nsISystemMessagesInternal);
return Cc["@mozilla.org/system-message-internal;1"]
.getService(Ci.nsISystemMessagesInternal);
});
XPCOMUtils.defineLazyGetter(this, "powerManagerService", function() {
return Cc["@mozilla.org/power/powermanagerservice;1"].getService(Ci.nsIPowerManagerService);
return Cc["@mozilla.org/power/powermanagerservice;1"]
.getService(Ci.nsIPowerManagerService);
});
/**
@ -50,14 +52,14 @@ XPCOMUtils.defineLazyGetter(this, "powerManagerService", function() {
this.AlarmService = {
init: function init() {
debug("init()");
Services.obs.addObserver(this, "profile-change-teardown", false);
Services.obs.addObserver(this, "webapps-clear-data",false);
this._currentTimezoneOffset = (new Date()).getTimezoneOffset();
let alarmHalService =
this._alarmHalService = Cc["@mozilla.org/alarmHalService;1"]
.getService(Ci.nsIAlarmHalService);
let alarmHalService = this._alarmHalService =
Cc["@mozilla.org/alarmHalService;1"].getService(Ci.nsIAlarmHalService);
alarmHalService.setAlarmFiredCb(this._onAlarmFired.bind(this));
alarmHalService.setTimezoneChangedCb(this._onTimezoneChanged.bind(this));
@ -109,6 +111,7 @@ this.AlarmService = {
debug("Got message from a child process with no 'alarms' permission.");
return null;
}
if (!aMessage.target.assertContainApp(json.manifestURL)) {
debug("Got message from a child process containing illegal manifest URL.");
return null;
@ -116,37 +119,34 @@ this.AlarmService = {
}
let mm = aMessage.target.QueryInterface(Ci.nsIMessageSender);
switch (aMessage.name) {
case "AlarmsManager:GetAll":
this._db.getAll(
json.manifestURL,
this._db.getAll(json.manifestURL,
function getAllSuccessCb(aAlarms) {
debug("Callback after getting alarms from database: " +
JSON.stringify(aAlarms));
this._sendAsyncMessage(mm, "GetAll", true, json.requestId, aAlarms);
}.bind(this),
function getAllErrorCb(aErrorMsg) {
this._sendAsyncMessage(mm, "GetAll", false, json.requestId, aErrorMsg);
}.bind(this)
);
}.bind(this));
break;
case "AlarmsManager:Add":
// Prepare a record for the new alarm to be added.
let newAlarm = {
date: json.date,
ignoreTimezone: json.ignoreTimezone,
data: json.data,
pageURL: json.pageURL,
manifestURL: json.manifestURL
};
let newAlarm = { date: json.date,
ignoreTimezone: json.ignoreTimezone,
data: json.data,
pageURL: json.pageURL,
manifestURL: json.manifestURL };
this.add(newAlarm, null,
// Receives the alarm ID as the last argument.
this._sendAsyncMessage.bind(this, mm, "Add", true, json.requestId),
// Receives the error message as the last argument.
this._sendAsyncMessage.bind(this, mm, "Add", false, json.requestId)
);
this._sendAsyncMessage.bind(this, mm, "Add", false, json.requestId));
break;
case "AlarmsManager:Remove":
@ -169,8 +169,7 @@ this.AlarmService = {
}
let json = null;
switch (aMessageName)
{
switch (aMessageName) {
case "Add":
json = aSuccess ?
{ requestId: aRequestId, id: aData } :
@ -189,7 +188,8 @@ this.AlarmService = {
}
aMessageManager.sendAsyncMessage("AlarmsManager:" + aMessageName +
":Return:" + (aSuccess ? "OK" : "KO"), json);
":Return:" + (aSuccess ? "OK" : "KO"),
json);
},
_removeAlarmFromDb: function _removeAlarmFromDb(aId, aManifestURL,
@ -204,14 +204,10 @@ this.AlarmService = {
};
}
this._db.remove(
aId,
aManifestURL,
aRemoveSuccessCb,
function removeErrorCb(aErrorMsg) {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
}
);
this._db.remove(aId, aManifestURL, aRemoveSuccessCb,
function removeErrorCb(aErrorMsg) {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
});
},
/**
@ -220,13 +216,11 @@ this.AlarmService = {
* boolean |ignoreTimezone| field.
*/
_publicAlarm: function _publicAlarm(aAlarm) {
let alarm = {
"id": aAlarm.id,
"date": aAlarm.date,
"respectTimezone": aAlarm.ignoreTimezone ?
"ignoreTimezone" : "honorTimezone",
"data": aAlarm.data
};
let alarm = { "id": aAlarm.id,
"date": aAlarm.date,
"respectTimezone": aAlarm.ignoreTimezone ?
"ignoreTimezone" : "honorTimezone",
"data": aAlarm.data };
return alarm;
},
@ -237,8 +231,10 @@ this.AlarmService = {
let manifestURI = Services.io.newURI(aAlarm.manifestURL, null, null);
let pageURI = Services.io.newURI(aAlarm.pageURL, null, null);
messenger.sendMessage("alarm", this._publicAlarm(aAlarm),
pageURI, manifestURI);
messenger.sendMessage("alarm",
this._publicAlarm(aAlarm),
pageURI,
manifestURI);
},
_notifyAlarmObserver: function _notifyAlarmObserver(aAlarm) {
@ -276,6 +272,7 @@ this.AlarmService = {
break;
}
}
this._debugCurrentAlarm();
},
@ -289,8 +286,7 @@ this.AlarmService = {
_restoreAlarmsFromDb: function _restoreAlarmsFromDb() {
debug("_restoreAlarmsFromDb()");
this._db.getAll(
null,
this._db.getAll(null,
function getAllSuccessCb(aAlarms) {
debug("Callback after getting alarms from database: " +
JSON.stringify(aAlarms));
@ -311,7 +307,7 @@ this.AlarmService = {
}
}.bind(this));
// Set the next alarm from queue.
// Set the next alarm from the queue.
if (alarmQueue.length) {
alarmQueue.sort(this._sortAlarmByTimeStamps.bind(this));
this._currentAlarm = alarmQueue.shift();
@ -321,8 +317,7 @@ this.AlarmService = {
}.bind(this),
function getAllErrorCb(aErrorMsg) {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
}
);
});
},
_getAlarmTime: function _getAlarmTime(aAlarm) {
@ -341,7 +336,8 @@ this.AlarmService = {
// is located at Paris. We can adjust the alarm UTC time by calculating
// the difference of the orginal timezone and the current timezone.
if (aAlarm.ignoreTimezone) {
alarmTime += (this._currentTimezoneOffset - aAlarm.timezoneOffset) * 60000;
alarmTime +=
(this._currentTimezoneOffset - aAlarm.timezoneOffset) * 60000;
}
return alarmTime;
},
@ -402,8 +398,7 @@ this.AlarmService = {
aNewAlarm['timezoneOffset'] = this._currentTimezoneOffset;
this._db.add(
aNewAlarm,
this._db.add(aNewAlarm,
function addSuccessCb(aNewId) {
debug("Callback after adding alarm in database.");
@ -422,7 +417,7 @@ this.AlarmService = {
}
// If the new alarm is earlier than the current alarm, swap them and
// push the previous alarm back to queue.
// push the previous alarm back to the queue.
let alarmQueue = this._alarmQueue;
let aNewAlarmTime = this._getAlarmTime(aNewAlarm);
let currentAlarmTime = this._getAlarmTime(this._currentAlarm);
@ -442,8 +437,7 @@ this.AlarmService = {
}.bind(this),
function addErrorCb(aErrorMsg) {
aErrorCb(aErrorMsg);
}.bind(this)
);
}.bind(this));
},
/*
@ -457,9 +451,8 @@ this.AlarmService = {
*/
remove: function(aAlarmId, aManifestURL) {
debug("remove(" + aAlarmId + ", " + aManifestURL + ")");
this._removeAlarmFromDb(
aAlarmId,
aManifestURL,
this._removeAlarmFromDb(aAlarmId, aManifestURL,
function removeSuccessCb() {
debug("Callback after removing alarm from database.");
@ -488,7 +481,7 @@ this.AlarmService = {
}
// The alarm to be removed is the current alarm reset the next alarm
// from queue if any.
// from the queue if any.
if (alarmQueue.length) {
this._currentAlarm = alarmQueue.shift();
this._debugCurrentAlarm();
@ -498,15 +491,17 @@ this.AlarmService = {
// No alarm waiting to be set in the queue.
this._currentAlarm = null;
this._debugCurrentAlarm();
}.bind(this)
);
}.bind(this));
},
observe: function(aSubject, aTopic, aData) {
debug("observe(): " + aTopic);
switch (aTopic) {
case "profile-change-teardown":
this.uninit();
break;
case "webapps-clear-data":
let params =
aSubject.QueryInterface(Ci.mozIApplicationClearPrivateDataParams);
@ -526,8 +521,7 @@ this.AlarmService = {
return;
}
this._db.getAll(
manifestURL,
this._db.getAll(manifestURL,
function getAllSuccessCb(aAlarms) {
aAlarms.forEach(function removeAlarm(aAlarm) {
this.remove(aAlarm.id, manifestURL);
@ -535,14 +529,14 @@ this.AlarmService = {
}.bind(this),
function getAllErrorCb(aErrorMsg) {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
}
);
});
break;
}
},
uninit: function uninit() {
debug("uninit()");
Services.obs.removeObserver(this, "profile-change-teardown");
Services.obs.removeObserver(this, "webapps-clear-data");

View File

@ -18,13 +18,11 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
function AlarmsManager()
{
function AlarmsManager() {
debug("Constructor");
}
AlarmsManager.prototype = {
__proto__: DOMRequestIpcHelper.prototype,
contractID : "@mozilla.org/alarmsManager;1",
@ -48,6 +46,7 @@ AlarmsManager.prototype = {
}
let isIgnoreTimezone = true;
switch (aRespectTimezone) {
case "honorTimezone":
isIgnoreTimezone = false;
@ -63,35 +62,30 @@ AlarmsManager.prototype = {
}
let request = this.createRequest();
this._cpmm.sendAsyncMessage(
"AlarmsManager:Add",
{ requestId: this.getRequestId(request),
date: aDate,
ignoreTimezone: isIgnoreTimezone,
data: aData,
pageURL: this._pageURL,
manifestURL: this._manifestURL }
);
this._cpmm.sendAsyncMessage("AlarmsManager:Add",
{ requestId: this.getRequestId(request),
date: aDate,
ignoreTimezone: isIgnoreTimezone,
data: aData,
pageURL: this._pageURL,
manifestURL: this._manifestURL });
return request;
},
remove: function remove(aId) {
debug("remove()");
this._cpmm.sendAsyncMessage(
"AlarmsManager:Remove",
{ id: aId, manifestURL: this._manifestURL }
);
this._cpmm.sendAsyncMessage("AlarmsManager:Remove",
{ id: aId, manifestURL: this._manifestURL });
},
getAll: function getAll() {
debug("getAll()");
let request = this.createRequest();
this._cpmm.sendAsyncMessage(
"AlarmsManager:GetAll",
{ requestId: this.getRequestId(request), manifestURL: this._manifestURL }
);
this._cpmm.sendAsyncMessage("AlarmsManager:GetAll",
{ requestId: this.getRequestId(request),
manifestURL: this._manifestURL });
return request;
},
@ -115,13 +109,14 @@ AlarmsManager.prototype = {
// We don't need to expose everything to the web content.
let alarms = [];
json.alarms.forEach(function trimAlarmInfo(aAlarm) {
let alarm = { "id": aAlarm.id,
"date": aAlarm.date,
let alarm = { "id": aAlarm.id,
"date": aAlarm.date,
"respectTimezone": aAlarm.ignoreTimezone ?
"ignoreTimezone" : "honorTimezone",
"data": aAlarm.data };
"data": aAlarm.data };
alarms.push(alarm);
});
Services.DOMRequest.fireSuccess(request,
Cu.cloneInto(alarms, this._window));
break;
@ -138,6 +133,7 @@ AlarmsManager.prototype = {
debug("Wrong message: " + aMessage.name);
break;
}
this.removeRequest(json.requestId);
},

View File

@ -11,9 +11,14 @@ interface nsIDOMMozCellBroadcastEtwsInfo;
* MozCellBroadcastMessage encapsulates Cell Broadcast short message service
* (CBS) messages.
*/
[scriptable, uuid(701e74a9-5fc4-4e2d-a324-9b7693395159)]
[scriptable, uuid(dc729df4-f1d8-11e3-b00d-d3332542c557)]
interface nsIDOMMozCellBroadcastMessage : nsISupports
{
/**
* The Service Id in the device where the message is received from.
*/
readonly attribute unsigned long serviceId;
/**
* Indication of the geographical area over which the Message Code is unique,
* and the display mode.

View File

@ -0,0 +1,229 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const {Cc: Cc, Ci: Ci, Cr: Cr, Cu: Cu} = SpecialPowers;
let Promise = Cu.import("resource://gre/modules/Promise.jsm").Promise;
/**
* Push required permissions and test if |navigator.mozCellBroadcast| exists.
* Resolve if it does, reject otherwise.
*
* Fulfill params:
* cbManager -- an reference to navigator.mozCellBroadcast.
*
* Reject params: (none)
*
* @return A deferred promise.
*/
let cbManager;
function ensureCellBroadcast() {
let deferred = Promise.defer();
let permissions = [{
"type": "cellbroadcast",
"allow": 1,
"context": document,
}];
SpecialPowers.pushPermissions(permissions, function() {
ok(true, "permissions pushed: " + JSON.stringify(permissions));
cbManager = window.navigator.mozCellBroadcast;
if (cbManager) {
log("navigator.mozCellBroadcast is instance of " + cbManager.constructor);
} else {
log("navigator.mozCellBroadcast is undefined.");
}
if (cbManager instanceof window.MozCellBroadcast) {
deferred.resolve(cbManager);
} else {
deferred.reject();
}
});
return deferred.promise;
}
/**
* Send emulator command with safe guard.
*
* We should only call |finish()| after all emulator command transactions
* end, so here comes with the pending counter. Resolve when the emulator
* gives positive response, and reject otherwise.
*
* Fulfill params:
* result -- an array of emulator response lines.
*
* Reject params:
* result -- an array of emulator response lines.
*
* @return A deferred promise.
*/
let pendingEmulatorCmdCount = 0;
function runEmulatorCmdSafe(aCommand) {
let deferred = Promise.defer();
++pendingEmulatorCmdCount;
runEmulatorCmd(aCommand, function(aResult) {
--pendingEmulatorCmdCount;
ok(true, "Emulator response: " + JSON.stringify(aResult));
if (Array.isArray(aResult) && aResult[aResult.length - 1] === "OK") {
deferred.resolve(aResult);
} else {
deferred.reject(aResult);
}
});
return deferred.promise;
}
/**
* Send raw CBS PDU to emulator.
*
* @param: aPdu
* A hex string representing the whole CBS PDU.
*
* Fulfill params:
* result -- an array of emulator response lines.
*
* Reject params:
* result -- an array of emulator response lines.
*
* @return A deferred promise.
*/
function sendRawCbsToEmulator(aPdu) {
let command = "cbs pdu " + aPdu;
return runEmulatorCmdSafe(command);
}
/**
* Wait for one named Cellbroadcast event.
*
* Resolve if that named event occurs. Never reject.
*
* Fulfill params: the DOMEvent passed.
*
* @param aEventName
* A string event name.
*
* @return A deferred promise.
*/
function waitForManagerEvent(aEventName) {
let deferred = Promise.defer();
cbManager.addEventListener(aEventName, function onevent(aEvent) {
cbManager.removeEventListener(aEventName, onevent);
ok(true, "Cellbroadcast event '" + aEventName + "' got.");
deferred.resolve(aEvent);
});
return deferred.promise;
}
/**
* Send multiple raw CB PDU to emulator and wait
*
* @param: aPdus
* A array of hex strings. Each represents a CB PDU.
* These PDUs are expected to be concatenated into single CB Message.
*
* Fulfill params:
* result -- array of resolved Promise, where
* result[0].message representing the received message.
* result[1-n] represents the response of sent emulator command.
*
* Reject params:
* result -- an array of emulator response lines.
*
* @return A deferred promise.
*/
function sendMultipleRawCbsToEmulatorAndWait(aPdus) {
let promises = [];
promises.push(waitForManagerEvent("received"));
for (let pdu of aPdus) {
promises.push(sendRawCbsToEmulator(pdu));
}
return Promise.all(promises);
}
/**
* Flush permission settings and call |finish()|.
*/
function cleanUp() {
waitFor(function() {
SpecialPowers.flushPermissions(function() {
// Use ok here so that we have at least one test run.
ok(true, "permissions flushed");
finish();
});
}, function() {
return pendingEmulatorCmdCount === 0;
});
}
/**
* Switch modem for receving upcoming emulator commands.
*
* @param: aServiceId
* The id of the modem to be switched to.
*
* Fulfill params:
* result -- an array of emulator response lines.
*
* Reject params:
* result -- an array of emulator response lines.
*
* @return A deferred promise.
*/
function selectModem(aServiceId) {
let command = "mux modem " + aServiceId;
return runEmulatorCmdSafe(command);
}
/**
* Helper to run the test case only needed in Multi-SIM environment.
*
* @param aTest
* A function which will be invoked w/o parameter.
* @return a Promise object.
*/
function runIfMultiSIM(aTest) {
let numRIL;
try {
numRIL = SpecialPowers.getIntPref("ril.numRadioInterfaces");
} catch (ex) {
numRIL = 1; // Pref not set.
}
if (numRIL > 1) {
return aTest();
} else {
log("Not a Multi-SIM environment. Test is skipped.");
return Promise.resolve();
}
}
/**
* Common test routine helper for cell broadcast tests.
*
* This function ensures global |cbManager| variable is available during the
* process and performs clean-ups as well.
*
* @param aTestCaseMain
* A function that takes no parameter.
*/
function startTestCommon(aTestCaseMain) {
Promise.resolve()
.then(ensureCellBroadcast)
.then(aTestCaseMain)
.then(cleanUp, function() {
ok(false, 'promise rejects during test.');
cleanUp();
});
}

View File

@ -5,3 +5,4 @@ qemu = true
[test_cellbroadcast_etws.js]
[test_cellbroadcast_gsm.js]
[test_cellbroadcast_multi_sim.js]

View File

@ -0,0 +1,34 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 60000;
MARIONETTE_HEAD_JS = 'head.js';
const BODY_7BITS = "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
+ "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
+ "@@@@@@@@@@@@@"; // 93 ascii chars.
const CB_PDU_SIZE = 88;
function testReceivingMultiSIM() {
let CB_PDU = "";
while (CB_PDU.length < CB_PDU_SIZE * 2) {
CB_PDU += "00";
}
let verifyCBMessage = (aMessage, aServiceId) => {
log("Verify CB message received from serviceId: " + aServiceId);
is(aMessage.body, BODY_7BITS, "Checking message body.");
is(aMessage.serviceId, aServiceId, "Checking serviceId.");
};
return selectModem(1)
.then(() => sendMultipleRawCbsToEmulatorAndWait([CB_PDU]))
.then((results) => verifyCBMessage(results[0].message, 1))
.then(() => selectModem(0))
.then(() => sendMultipleRawCbsToEmulatorAndWait([CB_PDU]))
.then((results) => verifyCBMessage(results[0].message, 0));
}
startTestCommon(function testCaseMain() {
return runIfMultiSIM(testReceivingMultiSIM);
});

View File

@ -574,7 +574,7 @@ MozInputContext.prototype = {
contextId: self._contextId,
requestId: resolverId,
text: text,
cursor: cursor || text.length,
cursor: (typeof cursor !== 'undefined') ? cursor : text.length,
clauses: clauses || null
});
});

View File

@ -305,7 +305,8 @@ MobileCallForwardingInfo.prototype = {
serviceClass: 'r'}
};
function CellBroadcastMessage(pdu) {
function CellBroadcastMessage(clientId, pdu) {
this.serviceId = clientId;
this.gsmGeographicalScope = RIL.CB_GSM_GEOGRAPHICAL_SCOPE_NAMES[pdu.geographicalScope];
this.messageCode = pdu.messageCode;
this.messageId = pdu.messageId;
@ -331,6 +332,7 @@ CellBroadcastMessage.prototype = {
}),
// nsIDOMMozCellBroadcastMessage
serviceId: -1,
gsmGeographicalScope: null,
messageCode: null,
@ -1544,13 +1546,17 @@ RILContentHelper.prototype = {
registerCellBroadcastMsg: function(listener) {
if (DEBUG) debug("Registering for Cell Broadcast related messages");
//TODO: Bug 921326 - Cellbroadcast API: support multiple sim cards
// Instead of registering multiple listeners for Multi-SIM, we reuse
// clientId 0 to route all CBS messages to single listener and provide the
// |clientId| info by |CellBroadcastMessage.serviceId|.
this.registerListener("_cellBroadcastListeners", 0, listener);
cpmm.sendAsyncMessage("RIL:RegisterCellBroadcastMsg");
},
unregisterCellBroadcastMsg: function(listener) {
//TODO: Bug 921326 - Cellbroadcast API: support multiple sim cards
// Instead of unregistering multiple listeners for Multi-SIM, we reuse
// clientId 0 to route all CBS messages to single listener and provide the
// |clientId| info by |CellBroadcastMessage.serviceId|.
this.unregisterListener("_cellBroadcastListeners", 0, listener);
},
@ -1824,8 +1830,10 @@ RILContentHelper.prototype = {
this.handleSimpleRequest(data.requestId, data.errorMsg, null);
break;
case "RIL:CellBroadcastReceived": {
let message = new CellBroadcastMessage(data);
this._deliverEvent(clientId,
// All CBS messages are to routed the listener for clientId 0 and
// provide the |clientId| info by |CellBroadcastMessage.serviceId|.
let message = new CellBroadcastMessage(clientId, data);
this._deliverEvent(0, // route to clientId 0.
"_cellBroadcastListeners",
"notifyMessageReceived",
[message]);

View File

@ -71,6 +71,7 @@ const kSysMsgListenerReadyObserverTopic = "system-message-listener-ready";
const kSysClockChangeObserverTopic = "system-clock-change";
const kScreenStateChangedTopic = "screen-state-changed";
const kSettingsCellBroadcastDisabled = "ril.cellbroadcast.disabled";
const kSettingsCellBroadcastSearchList = "ril.cellbroadcast.searchlist";
const kSettingsClockAutoUpdateEnabled = "time.clock.automatic-update.enabled";
const kSettingsClockAutoUpdateAvailable = "time.clock.automatic-update.available";
@ -79,7 +80,6 @@ const kSettingsTimezoneAutoUpdateAvailable = "time.timezone.automatic-update.ava
const NS_PREFBRANCH_PREFCHANGE_TOPIC_ID = "nsPref:changed";
const kPrefCellBroadcastDisabled = "ril.cellbroadcast.disabled";
const kPrefRilNumRadioInterfaces = "ril.numRadioInterfaces";
const kPrefRilDebuggingEnabled = "ril.debugging.enabled";
@ -1591,7 +1591,6 @@ WorkerMessenger.prototype = {
init: function() {
let options = {
debug: DEBUG,
cellBroadcastDisabled: false,
quirks: {
callstateExtraUint32:
libcutils.property_get("ro.moz.ril.callstate_extra_int", "false") === "true",
@ -1614,11 +1613,6 @@ WorkerMessenger.prototype = {
libcutils.property_get("ro.ril.ecclist")
};
try {
options.cellBroadcastDisabled =
Services.prefs.getBoolPref(kPrefCellBroadcastDisabled);
} catch(e) {}
this.send(null, "setInitialOptions", options);
},
@ -1815,8 +1809,30 @@ function RadioInterface(aClientId, aWorkerMessenger) {
// Set "time.timezone.automatic-update.available" to false when starting up.
this.setTimezoneAutoUpdateAvailable(false);
// Read the Cell Broadcast Search List setting, string of integers or integer
// ranges separated by comma, to set listening channels.
/**
* Read the settings of the toggle of Cellbroadcast Service:
*
* Simple Format: Boolean
* true if CBS is disabled. The value is applied to all RadioInterfaces.
* Enhanced Format: Array of Boolean
* Each element represents the toggle of CBS per RadioInterface.
*/
lock.get(kSettingsCellBroadcastDisabled, this);
/**
* Read the Cell Broadcast Search List setting to set listening channels:
*
* Simple Format:
* String of integers or integer ranges separated by comma.
* For example, "1, 2, 4-6"
* Enhanced Format:
* Array of Objects with search lists specified in gsm/cdma network.
* For example, [{'gsm' : "1, 2, 4-6", 'cdma' : "1, 50, 99"},
* {'cdma' : "3, 6, 8-9"}]
* This provides the possibility to
* 1. set gsm/cdma search list individually for CDMA+LTE device.
* 2. set search list per RadioInterface.
*/
lock.get(kSettingsCellBroadcastSearchList, this);
Services.obs.addObserver(this, kMozSettingsChangedObserverTopic, false);
@ -1825,7 +1841,6 @@ function RadioInterface(aClientId, aWorkerMessenger) {
Services.obs.addObserver(this, kNetworkConnStateChangedTopic, false);
Services.obs.addObserver(this, kNetworkActiveChangedTopic, false);
Services.prefs.addObserver(kPrefCellBroadcastDisabled, this, false);
this.portAddressedSmsApps = {};
this.portAddressedSmsApps[WAP.WDP_PORT_PUSH] = this.handleSmsWdpPortPush.bind(this);
@ -2493,11 +2508,18 @@ RadioInterface.prototype = {
}).bind(this));
},
setCellBroadcastSearchList: function(newSearchList) {
if ((newSearchList == this._cellBroadcastSearchList) ||
(newSearchList && this._cellBroadcastSearchList &&
newSearchList.gsm == this._cellBroadcastSearchList.gsm &&
newSearchList.cdma == this._cellBroadcastSearchList.cdma)) {
setCellBroadcastSearchList: function(settings) {
let newSearchList =
Array.isArray(settings) ? settings[this.clientId] : settings;
let oldSearchList =
Array.isArray(this._cellBroadcastSearchList) ?
this._cellBroadcastSearchList[this.clientId] :
this._cellBroadcastSearchList;
if ((newSearchList == oldSearchList) ||
(newSearchList && oldSearchList &&
newSearchList.gsm == oldSearchList.gsm &&
newSearchList.cdma == oldSearchList.cdma)) {
return;
}
@ -2509,7 +2531,7 @@ RadioInterface.prototype = {
lock.set(kSettingsCellBroadcastSearchList,
this._cellBroadcastSearchList, null);
} else {
this._cellBroadcastSearchList = response.searchList;
this._cellBroadcastSearchList = settings;
}
return false;
@ -3304,16 +3326,6 @@ RadioInterface.prototype = {
let setting = JSON.parse(data);
this.handleSettingsChange(setting.key, setting.value, setting.message);
break;
case NS_PREFBRANCH_PREFCHANGE_TOPIC_ID:
if (data === kPrefCellBroadcastDisabled) {
let value = false;
try {
value = Services.prefs.getBoolPref(kPrefCellBroadcastDisabled);
} catch(e) {}
this.workerMessenger.send("setCellBroadcastDisabled",
{ disabled: value });
}
break;
case kSysClockChangeObserverTopic:
let offset = parseInt(data, 10);
if (this._lastNitzMessage) {
@ -3475,9 +3487,19 @@ RadioInterface.prototype = {
this.debug("'" + kSettingsCellBroadcastSearchList +
"' is now " + JSON.stringify(aResult));
}
// TODO: Set searchlist for Multi-SIM. See Bug 921326.
let result = Array.isArray(aResult) ? aResult[0] : aResult;
this.setCellBroadcastSearchList(result);
this.setCellBroadcastSearchList(aResult);
break;
case kSettingsCellBroadcastDisabled:
if (DEBUG) {
this.debug("'" + kSettingsCellBroadcastDisabled +
"' is now " + JSON.stringify(aResult));
}
let setCbsDisabled =
Array.isArray(aResult) ? aResult[this.clientId] : aResult;
this.workerMessenger.send("setCellBroadcastDisabled",
{ disabled: setCbsDisabled });
break;
}
},

View File

@ -52,7 +52,6 @@ if (!this.debug) {
};
}
let RIL_CELLBROADCAST_DISABLED;
let RIL_EMERGENCY_NUMBERS;
const DEFAULT_EMERGENCY_NUMBERS = ["112", "911"];
@ -353,7 +352,6 @@ function RilObject(aContext) {
// Init properties that are only initialized once.
this.v5Legacy = RILQUIRKS_V5_LEGACY;
this.cellBroadcastDisabled = RIL_CELLBROADCAST_DISABLED;
this.pendingMO = null;
}
@ -6450,7 +6448,11 @@ RilObject.prototype[REQUEST_GSM_SET_BROADCAST_SMS_CONFIG] = function REQUEST_GSM
};
RilObject.prototype[REQUEST_GSM_SMS_BROADCAST_ACTIVATION] = null;
RilObject.prototype[REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG] = null;
RilObject.prototype[REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG] = null;
RilObject.prototype[REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG] = function REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG(length, options) {
if (options.rilRequestError == ERROR_SUCCESS) {
this.setSmsBroadcastActivation(true);
}
};
RilObject.prototype[REQUEST_CDMA_SMS_BROADCAST_ACTIVATION] = null;
RilObject.prototype[REQUEST_CDMA_SUBSCRIPTION] = function REQUEST_CDMA_SUBSCRIPTION(length, options) {
if (options.rilRequestError) {
@ -13934,8 +13936,8 @@ ICCUtilsHelperObject.prototype = {
}
} else {
// GSM family display rule.
let operatorMnc = RIL.operator.mnc;
let operatorMcc = RIL.operator.mcc;
let operatorMnc = RIL.operator ? RIL.operator.mnc : -1;
let operatorMcc = RIL.operator ? RIL.operator.mcc : -1;
// First detect if we are on HPLMN or one of the PLMN
// specified by the SIM card.
@ -14900,7 +14902,6 @@ let ContextPool = {
setInitialOptions: function(aOptions) {
DEBUG = DEBUG_WORKER || aOptions.debug;
RIL_EMERGENCY_NUMBERS = aOptions.rilEmergencyNumbers;
RIL_CELLBROADCAST_DISABLED = aOptions.cellBroadcastDisabled;
let quirks = aOptions.quirks;
RILQUIRKS_CALLSTATE_EXTRA_UINT32 = quirks.callstateExtraUint32;

View File

@ -78,6 +78,60 @@ function newWorker(custom_ns) {
return worker_ns;
}
/**
* Create a buffered RIL worker.
*
* @return A worker object that stores sending octets in a internal buffer.
*/
function newUint8Worker() {
let worker = newWorker();
let index = 0; // index for read
let buf = [];
let context = worker.ContextPool._contexts[0];
context.Buf.writeUint8 = function(value) {
buf.push(value);
};
context.Buf.readUint8 = function() {
return buf[index++];
};
context.Buf.seekIncoming = function(offset) {
index += offset;
};
context.Buf.getReadAvailable = function() {
return buf.length - index;
};
worker.debug = do_print;
return worker;
}
/**
* Create a worker that keeps posted chrome message.
*/
function newInterceptWorker() {
let postedMessage;
let worker = newWorker({
postRILMessage: function(data) {
},
postMessage: function(message) {
postedMessage = message;
}
});
return {
get postedMessage() {
return postedMessage;
},
get worker() {
return worker;
}
};
}
/**
* Create a parcel suitable for postRILMessage().
*

View File

@ -10,32 +10,6 @@ function run_test() {
const PIN = "0000";
const NEW_PIN = "1234";
/**
* Helper function.
*/
function newUint8Worker() {
let worker = newWorker();
let context = worker.ContextPool._contexts[0];
let index = 0; // index for read
let buf = [];
context.Buf.writeUint8 = function(value) {
buf.push(value);
};
context.Buf.readUint8 = function() {
return buf[index++];
};
context.Buf.seekIncoming = function(offset) {
index += offset;
};
worker.debug = do_print;
return worker;
}
add_test(function test_change_call_barring_password() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];

View File

@ -52,27 +52,8 @@ add_test(function test_toaFromString_international() {
run_next_test();
});
function _getWorker() {
let _postedMessage;
let _worker = newWorker({
postRILMessage: function(data) {
},
postMessage: function(message) {
_postedMessage = message;
}
});
return {
get postedMessage() {
return _postedMessage;
},
get worker() {
return _worker;
}
};
}
add_test(function test_setCallForward_unconditional() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
@ -99,7 +80,7 @@ add_test(function test_setCallForward_unconditional() {
});
add_test(function test_queryCallForwardStatus_unconditional() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];

View File

@ -7,27 +7,8 @@ function run_test() {
run_next_test();
}
function _getWorker() {
let _postedMessage;
let _worker = newWorker({
postRILMessage: function(data) {
},
postMessage: function(message) {
_postedMessage = message;
}
});
return {
get postedMessage() {
return _postedMessage;
},
get worker() {
return _worker;
}
};
}
add_test(function test_queryCLIP_provisioned() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
@ -56,7 +37,7 @@ add_test(function test_queryCLIP_provisioned() {
});
add_test(function test_getCLIP_error_generic_failure_invalid_length() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];

View File

@ -16,27 +16,8 @@ function run_test() {
run_next_test();
}
function _getWorker() {
let _postedMessage;
let _worker = newWorker({
postRILMessage: function(data) {
},
postMessage: function(message) {
_postedMessage = message;
}
});
return {
get postedMessage() {
return _postedMessage;
},
get worker() {
return _worker;
}
};
}
add_test(function test_setCLIR_success() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
@ -60,7 +41,7 @@ add_test(function test_setCLIR_success() {
});
add_test(function test_setCLIR_generic_failure() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
@ -84,7 +65,7 @@ add_test(function test_setCLIR_generic_failure() {
});
add_test(function test_getCLIR_n0_m1() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
@ -117,7 +98,7 @@ add_test(function test_getCLIR_n0_m1() {
});
add_test(function test_getCLIR_error_generic_failure_invalid_length() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];

View File

@ -7,27 +7,8 @@ function run_test() {
run_next_test();
}
function _getWorker() {
let _postedMessage;
let _worker = newWorker({
postRILMessage: function(data) {
},
postMessage: function(message) {
_postedMessage = message;
}
});
return {
get postedMessage() {
return _postedMessage;
},
get worker() {
return _worker;
}
};
}
add_test(function test_setCallWaiting_success() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
@ -50,7 +31,7 @@ add_test(function test_setCallWaiting_success() {
});
add_test(function test_setCallWaiting_generic_failure() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
@ -73,7 +54,7 @@ add_test(function test_setCallWaiting_generic_failure() {
});
add_test(function test_queryCallWaiting_success_enabled_true() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
@ -104,7 +85,7 @@ add_test(function test_queryCallWaiting_success_enabled_true() {
});
add_test(function test_queryCallWaiting_success_enabled_false() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];

View File

@ -7,25 +7,6 @@ function run_test() {
run_next_test();
}
function _getWorker() {
let _postedMessage;
let _worker = newWorker({
postRILMessage: function(data) {
},
postMessage: function(message) {
_postedMessage = message;
}
});
return {
get postedMessage() {
return _postedMessage;
},
get worker() {
return _worker;
}
};
}
var timeoutCallback = null;
var timeoutDelayMs = 0;
const TIMER_ID = 1234;
@ -54,7 +35,7 @@ function fireTimeout() {
}
add_test(function test_enter_emergencyCbMode() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
@ -79,7 +60,7 @@ add_test(function test_enter_emergencyCbMode() {
});
add_test(function test_exit_emergencyCbMode() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
@ -101,7 +82,7 @@ add_test(function test_exit_emergencyCbMode() {
});
add_test(function test_request_exit_emergencyCbMode_when_timeout() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
@ -127,7 +108,7 @@ add_test(function test_request_exit_emergencyCbMode_when_timeout() {
});
add_test(function test_request_exit_emergencyCbMode_when_dial() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
@ -154,7 +135,7 @@ add_test(function test_request_exit_emergencyCbMode_when_dial() {
});
add_test(function test_request_exit_emergencyCbMode_explicitly() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,87 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
function run_test() {
run_next_test();
}
// Test ICC_COMMAND_GET_RESPONSE with FCP template format.
/**
* Verify transparent structure with FCP template format.
*/
add_test(function test_fcp_template_for_transparent_structure() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let berHelper = context.BerTlvHelper;
let tag_test = [
0x62,
0x22,
0x82, 0x02, 0x41, 0x21,
0x83, 0x02, 0x2F, 0xE2,
0xA5, 0x09, 0xC1, 0x04, 0x40, 0x0F, 0xF5, 0x55, 0x92, 0x01, 0x00,
0x8A, 0x01, 0x05,
0x8B, 0x03, 0x2F, 0x06, 0x0B,
0x80, 0x02, 0x00, 0x0A,
0x88, 0x01, 0x10];
for (let i = 0; i < tag_test.length; i++) {
pduHelper.writeHexOctet(tag_test[i]);
}
let berTlv = berHelper.decode(tag_test.length);
let iter = Iterator(berTlv.value);
let tlv = berHelper.searchForNextTag(BER_FCP_FILE_DESCRIPTOR_TAG, iter);
do_check_eq(tlv.value.fileStructure, UICC_EF_STRUCTURE[EF_TYPE_TRANSPARENT]);
tlv = berHelper.searchForNextTag(BER_FCP_FILE_IDENTIFIER_TAG, iter);
do_check_eq(tlv.value.fileId, 0x2FE2);
tlv = berHelper.searchForNextTag(BER_FCP_FILE_SIZE_DATA_TAG, iter);
do_check_eq(tlv.value.fileSizeData, 0x0A);
run_next_test();
});
/**
* Verify linear fixed structure with FCP template format.
*/
add_test(function test_fcp_template_for_linear_fixed_structure() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let berHelper = context.BerTlvHelper;
let tag_test = [
0x62,
0x1E,
0x82, 0x05, 0x42, 0x21, 0x00, 0x1A, 0x01,
0x83, 0x02, 0x6F, 0x40,
0xA5, 0x03, 0x92, 0x01, 0x00,
0x8A, 0x01, 0x07,
0x8B, 0x03, 0x6F, 0x06, 0x02,
0x80, 0x02, 0x00, 0x1A,
0x88, 0x00];
for (let i = 0; i < tag_test.length; i++) {
pduHelper.writeHexOctet(tag_test[i]);
}
let berTlv = berHelper.decode(tag_test.length);
let iter = Iterator(berTlv.value);
let tlv = berHelper.searchForNextTag(BER_FCP_FILE_DESCRIPTOR_TAG, iter);
do_check_eq(tlv.value.fileStructure, UICC_EF_STRUCTURE[EF_TYPE_LINEAR_FIXED]);
do_check_eq(tlv.value.recordLength, 0x1A);
do_check_eq(tlv.value.numOfRecords, 0x01);
tlv = berHelper.searchForNextTag(BER_FCP_FILE_IDENTIFIER_TAG, iter);
do_check_eq(tlv.value.fileId, 0x6F40);
tlv = berHelper.searchForNextTag(BER_FCP_FILE_SIZE_DATA_TAG, iter);
do_check_eq(tlv.value.fileSizeData, 0x1A);
run_next_test();
});

View File

@ -0,0 +1,357 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
function run_test() {
run_next_test();
}
/**
* Verify RIL.iccGetCardLockState("fdn")
*/
add_test(function test_icc_get_card_lock_state_fdn() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
let buf = context.Buf;
buf.sendParcel = function() {
// Request Type.
do_check_eq(this.readInt32(), REQUEST_QUERY_FACILITY_LOCK)
// Token : we don't care.
this.readInt32();
// String Array Length.
do_check_eq(this.readInt32(), ril.v5Legacy ? 3 : 4);
// Facility.
do_check_eq(this.readString(), ICC_CB_FACILITY_FDN);
// Password.
do_check_eq(this.readString(), "");
// Service class.
do_check_eq(this.readString(), (ICC_SERVICE_CLASS_VOICE |
ICC_SERVICE_CLASS_DATA |
ICC_SERVICE_CLASS_FAX).toString());
if (!ril.v5Legacy) {
// AID. Ignore because it's from modem.
this.readInt32();
}
run_next_test();
};
ril.iccGetCardLockState({lockType: "fdn"});
});
add_test(function test_path_id_for_spid_and_spn() {
let worker = newWorker({
postRILMessage: function(data) {
// Do nothing
},
postMessage: function(message) {
// Do nothing
}});
let context = worker.ContextPool._contexts[0];
let RIL = context.RIL;
let ICCFileHelper = context.ICCFileHelper;
// Test SIM
RIL.appType = CARD_APPTYPE_SIM;
do_check_eq(ICCFileHelper.getEFPath(ICC_EF_SPDI),
EF_PATH_MF_SIM + EF_PATH_DF_GSM);
do_check_eq(ICCFileHelper.getEFPath(ICC_EF_SPN),
EF_PATH_MF_SIM + EF_PATH_DF_GSM);
// Test USIM
RIL.appType = CARD_APPTYPE_USIM;
do_check_eq(ICCFileHelper.getEFPath(ICC_EF_SPDI),
EF_PATH_MF_SIM + EF_PATH_ADF_USIM);
do_check_eq(ICCFileHelper.getEFPath(ICC_EF_SPDI),
EF_PATH_MF_SIM + EF_PATH_ADF_USIM);
run_next_test();
});
add_test(function test_personalization_state() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
context.ICCRecordHelper.readICCID = function fakeReadICCID() {};
function testPersonalization(isCdma, cardPersoState, geckoCardState) {
let iccStatus = {
cardState: CARD_STATE_PRESENT,
gsmUmtsSubscriptionAppIndex: (!isCdma) ? 0 : -1,
cdmaSubscriptionAppIndex: (isCdma) ? 0 : -1,
apps: [
{
app_state: CARD_APPSTATE_SUBSCRIPTION_PERSO,
perso_substate: cardPersoState
}],
};
ril._isCdma = isCdma;
ril._processICCStatus(iccStatus);
do_check_eq(ril.cardState, geckoCardState);
}
// Test GSM personalization state.
testPersonalization(false, CARD_PERSOSUBSTATE_SIM_NETWORK,
GECKO_CARDSTATE_NETWORK_LOCKED);
testPersonalization(false, CARD_PERSOSUBSTATE_SIM_CORPORATE,
GECKO_CARDSTATE_CORPORATE_LOCKED);
testPersonalization(false, CARD_PERSOSUBSTATE_SIM_SERVICE_PROVIDER,
GECKO_CARDSTATE_SERVICE_PROVIDER_LOCKED);
testPersonalization(false, CARD_PERSOSUBSTATE_SIM_NETWORK_PUK,
GECKO_CARDSTATE_NETWORK_PUK_REQUIRED);
testPersonalization(false, CARD_PERSOSUBSTATE_SIM_CORPORATE_PUK,
GECKO_CARDSTATE_CORPORATE_PUK_REQUIRED);
testPersonalization(false, CARD_PERSOSUBSTATE_SIM_SERVICE_PROVIDER_PUK,
GECKO_CARDSTATE_SERVICE_PROVIDER_PUK_REQUIRED);
testPersonalization(false, CARD_PERSOSUBSTATE_READY,
GECKO_CARDSTATE_PERSONALIZATION_READY);
// Test CDMA personalization state.
testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_NETWORK1,
GECKO_CARDSTATE_NETWORK1_LOCKED);
testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_NETWORK2,
GECKO_CARDSTATE_NETWORK2_LOCKED);
testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_HRPD,
GECKO_CARDSTATE_HRPD_NETWORK_LOCKED);
testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_CORPORATE,
GECKO_CARDSTATE_RUIM_CORPORATE_LOCKED);
testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_SERVICE_PROVIDER,
GECKO_CARDSTATE_RUIM_SERVICE_PROVIDER_LOCKED);
testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_RUIM,
GECKO_CARDSTATE_RUIM_LOCKED);
testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_NETWORK1_PUK,
GECKO_CARDSTATE_NETWORK1_PUK_REQUIRED);
testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_NETWORK2_PUK,
GECKO_CARDSTATE_NETWORK2_PUK_REQUIRED);
testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_HRPD_PUK,
GECKO_CARDSTATE_HRPD_NETWORK_PUK_REQUIRED);
testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_CORPORATE_PUK,
GECKO_CARDSTATE_RUIM_CORPORATE_PUK_REQUIRED);
testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_SERVICE_PROVIDER_PUK,
GECKO_CARDSTATE_RUIM_SERVICE_PROVIDER_PUK_REQUIRED);
testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_RUIM_PUK,
GECKO_CARDSTATE_RUIM_PUK_REQUIRED);
run_next_test();
});
/**
* Verify SIM app_state in _processICCStatus
*/
add_test(function test_card_app_state() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
context.ICCRecordHelper.readICCID = function fakeReadICCID() {};
function testCardAppState(cardAppState, geckoCardState) {
let iccStatus = {
cardState: CARD_STATE_PRESENT,
gsmUmtsSubscriptionAppIndex: 0,
apps: [
{
app_state: cardAppState
}],
};
ril._processICCStatus(iccStatus);
do_check_eq(ril.cardState, geckoCardState);
}
testCardAppState(CARD_APPSTATE_ILLEGAL,
GECKO_CARDSTATE_ILLEGAL);
testCardAppState(CARD_APPSTATE_PIN,
GECKO_CARDSTATE_PIN_REQUIRED);
testCardAppState(CARD_APPSTATE_PUK,
GECKO_CARDSTATE_PUK_REQUIRED);
testCardAppState(CARD_APPSTATE_READY,
GECKO_CARDSTATE_READY);
testCardAppState(CARD_APPSTATE_UNKNOWN,
GECKO_CARDSTATE_UNKNOWN);
testCardAppState(CARD_APPSTATE_DETECTED,
GECKO_CARDSTATE_UNKNOWN);
run_next_test();
});
/**
* Verify permanent blocked for ICC.
*/
add_test(function test_icc_permanent_blocked() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
context.ICCRecordHelper.readICCID = function fakeReadICCID() {};
function testPermanentBlocked(pin1_replaced, universalPINState, pin1) {
let iccStatus = {
cardState: CARD_STATE_PRESENT,
gsmUmtsSubscriptionAppIndex: 0,
universalPINState: universalPINState,
apps: [
{
pin1_replaced: pin1_replaced,
pin1: pin1
}]
};
ril._processICCStatus(iccStatus);
do_check_eq(ril.cardState, GECKO_CARDSTATE_PERMANENT_BLOCKED);
}
testPermanentBlocked(1,
CARD_PINSTATE_ENABLED_PERM_BLOCKED,
CARD_PINSTATE_UNKNOWN);
testPermanentBlocked(1,
CARD_PINSTATE_ENABLED_PERM_BLOCKED,
CARD_PINSTATE_ENABLED_PERM_BLOCKED);
testPermanentBlocked(0,
CARD_PINSTATE_UNKNOWN,
CARD_PINSTATE_ENABLED_PERM_BLOCKED);
run_next_test();
});
/**
* Verify iccSetCardLock - Facility Lock.
*/
add_test(function test_set_icc_card_lock_facility_lock() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let aid = "123456789";
let ril = context.RIL;
ril.aid = aid;
ril.v5Legacy = false;
let buf = context.Buf;
let GECKO_CARDLOCK_TO_FACILITIY_LOCK = {};
GECKO_CARDLOCK_TO_FACILITIY_LOCK[GECKO_CARDLOCK_PIN] = ICC_CB_FACILITY_SIM;
GECKO_CARDLOCK_TO_FACILITIY_LOCK[GECKO_CARDLOCK_FDN] = ICC_CB_FACILITY_FDN;
let GECKO_CARDLOCK_TO_PASSWORD_TYPE = {};
GECKO_CARDLOCK_TO_PASSWORD_TYPE[GECKO_CARDLOCK_PIN] = "pin";
GECKO_CARDLOCK_TO_PASSWORD_TYPE[GECKO_CARDLOCK_FDN] = "pin2";
const pin = "1234";
const pin2 = "4321";
let GECKO_CARDLOCK_TO_PASSWORD = {};
GECKO_CARDLOCK_TO_PASSWORD[GECKO_CARDLOCK_PIN] = pin;
GECKO_CARDLOCK_TO_PASSWORD[GECKO_CARDLOCK_FDN] = pin2;
const serviceClass = ICC_SERVICE_CLASS_VOICE |
ICC_SERVICE_CLASS_DATA |
ICC_SERVICE_CLASS_FAX;
function do_test(aLock, aPassword, aEnabled) {
buf.sendParcel = function fakeSendParcel () {
// Request Type.
do_check_eq(this.readInt32(), REQUEST_SET_FACILITY_LOCK);
// Token : we don't care
this.readInt32();
let parcel = this.readStringList();
do_check_eq(parcel.length, 5);
do_check_eq(parcel[0], GECKO_CARDLOCK_TO_FACILITIY_LOCK[aLock]);
do_check_eq(parcel[1], aEnabled ? "1" : "0");
do_check_eq(parcel[2], GECKO_CARDLOCK_TO_PASSWORD[aLock]);
do_check_eq(parcel[3], serviceClass.toString());
do_check_eq(parcel[4], aid);
};
let lock = {lockType: aLock,
enabled: aEnabled};
lock[GECKO_CARDLOCK_TO_PASSWORD_TYPE[aLock]] = aPassword;
ril.iccSetCardLock(lock);
}
do_test(GECKO_CARDLOCK_PIN, pin, true);
do_test(GECKO_CARDLOCK_PIN, pin, false);
do_test(GECKO_CARDLOCK_FDN, pin2, true);
do_test(GECKO_CARDLOCK_FDN, pin2, false);
run_next_test();
});
/**
* Verify iccUnlockCardLock.
*/
add_test(function test_unlock_card_lock_corporateLocked() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
let buf = context.Buf;
const pin = "12345678";
const puk = "12345678";
let GECKO_CARDLOCK_TO_PASSWORD_TYPE = {};
GECKO_CARDLOCK_TO_PASSWORD_TYPE[GECKO_CARDLOCK_NCK] = "pin";
GECKO_CARDLOCK_TO_PASSWORD_TYPE[GECKO_CARDLOCK_NCK1] = "pin";
GECKO_CARDLOCK_TO_PASSWORD_TYPE[GECKO_CARDLOCK_NCK2] = "pin";
GECKO_CARDLOCK_TO_PASSWORD_TYPE[GECKO_CARDLOCK_HNCK] = "pin";
GECKO_CARDLOCK_TO_PASSWORD_TYPE[GECKO_CARDLOCK_CCK] = "pin";
GECKO_CARDLOCK_TO_PASSWORD_TYPE[GECKO_CARDLOCK_SPCK] = "pin";
GECKO_CARDLOCK_TO_PASSWORD_TYPE[GECKO_CARDLOCK_RCCK] = "pin";
GECKO_CARDLOCK_TO_PASSWORD_TYPE[GECKO_CARDLOCK_RSPCK] = "pin";
GECKO_CARDLOCK_TO_PASSWORD_TYPE[GECKO_CARDLOCK_NCK_PUK] = "puk";
GECKO_CARDLOCK_TO_PASSWORD_TYPE[GECKO_CARDLOCK_NCK1_PUK] = "puk";
GECKO_CARDLOCK_TO_PASSWORD_TYPE[GECKO_CARDLOCK_NCK2_PUK] = "puk";
GECKO_CARDLOCK_TO_PASSWORD_TYPE[GECKO_CARDLOCK_HNCK_PUK] = "puk";
GECKO_CARDLOCK_TO_PASSWORD_TYPE[GECKO_CARDLOCK_CCK_PUK] = "puk";
GECKO_CARDLOCK_TO_PASSWORD_TYPE[GECKO_CARDLOCK_SPCK_PUK] = "puk";
GECKO_CARDLOCK_TO_PASSWORD_TYPE[GECKO_CARDLOCK_RCCK_PUK] = "puk";
GECKO_CARDLOCK_TO_PASSWORD_TYPE[GECKO_CARDLOCK_RSPCK_PUK] = "puk";
function do_test(aLock, aPassword) {
buf.sendParcel = function fakeSendParcel () {
// Request Type.
do_check_eq(this.readInt32(), REQUEST_ENTER_NETWORK_DEPERSONALIZATION_CODE);
// Token : we don't care
this.readInt32();
let lockType = GECKO_PERSO_LOCK_TO_CARD_PERSO_LOCK[aLock];
// Lock Type
do_check_eq(this.readInt32(), lockType);
// Pin/Puk.
do_check_eq(this.readString(), aPassword);
};
let lock = {lockType: aLock};
lock[GECKO_CARDLOCK_TO_PASSWORD_TYPE[aLock]] = aPassword;
ril.iccUnlockCardLock(lock);
}
do_test(GECKO_CARDLOCK_NCK, pin);
do_test(GECKO_CARDLOCK_NCK1, pin);
do_test(GECKO_CARDLOCK_NCK2, pin);
do_test(GECKO_CARDLOCK_HNCK, pin);
do_test(GECKO_CARDLOCK_CCK, pin);
do_test(GECKO_CARDLOCK_SPCK, pin);
do_test(GECKO_CARDLOCK_RCCK, pin);
do_test(GECKO_CARDLOCK_RSPCK, pin);
do_test(GECKO_CARDLOCK_NCK_PUK, puk);
do_test(GECKO_CARDLOCK_NCK1_PUK, puk);
do_test(GECKO_CARDLOCK_NCK2_PUK, puk);
do_test(GECKO_CARDLOCK_HNCK_PUK, puk);
do_test(GECKO_CARDLOCK_CCK_PUK, puk);
do_test(GECKO_CARDLOCK_SPCK_PUK, puk);
do_test(GECKO_CARDLOCK_RCCK_PUK, puk);
do_test(GECKO_CARDLOCK_RSPCK_PUK, puk);
run_next_test();
});

View File

@ -0,0 +1,79 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
function run_test() {
run_next_test();
}
/**
* Verify GsmPDUHelper.writeTimestamp
*/
add_test(function test_write_timestamp() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
// current date
let dateInput = new Date();
let dateOutput = new Date();
helper.writeTimestamp(dateInput);
dateOutput.setTime(helper.readTimestamp());
do_check_eq(dateInput.getFullYear(), dateOutput.getFullYear());
do_check_eq(dateInput.getMonth(), dateOutput.getMonth());
do_check_eq(dateInput.getDate(), dateOutput.getDate());
do_check_eq(dateInput.getHours(), dateOutput.getHours());
do_check_eq(dateInput.getMinutes(), dateOutput.getMinutes());
do_check_eq(dateInput.getSeconds(), dateOutput.getSeconds());
do_check_eq(dateInput.getTimezoneOffset(), dateOutput.getTimezoneOffset());
// 2034-01-23 12:34:56 -0800 GMT
let time = Date.UTC(2034, 1, 23, 12, 34, 56);
time = time - (8 * 60 * 60 * 1000);
dateInput.setTime(time);
helper.writeTimestamp(dateInput);
dateOutput.setTime(helper.readTimestamp());
do_check_eq(dateInput.getFullYear(), dateOutput.getFullYear());
do_check_eq(dateInput.getMonth(), dateOutput.getMonth());
do_check_eq(dateInput.getDate(), dateOutput.getDate());
do_check_eq(dateInput.getHours(), dateOutput.getHours());
do_check_eq(dateInput.getMinutes(), dateOutput.getMinutes());
do_check_eq(dateInput.getSeconds(), dateOutput.getSeconds());
do_check_eq(dateInput.getTimezoneOffset(), dateOutput.getTimezoneOffset());
run_next_test();
});
/**
* Verify GsmPDUHelper.octectToBCD and GsmPDUHelper.BCDToOctet
*/
add_test(function test_octect_BCD() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
// 23
let number = 23;
let octet = helper.BCDToOctet(number);
do_check_eq(helper.octetToBCD(octet), number);
// 56
number = 56;
octet = helper.BCDToOctet(number);
do_check_eq(helper.octetToBCD(octet), number);
// 0x23
octet = 0x23;
number = helper.octetToBCD(octet);
do_check_eq(helper.BCDToOctet(number), octet);
// 0x56
octet = 0x56;
number = helper.octetToBCD(octet);
do_check_eq(helper.BCDToOctet(number), octet);
run_next_test();
});

View File

@ -0,0 +1,590 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
function run_test() {
run_next_test();
}
/**
* Test error message returned in onerror for readICCContacts.
*/
add_test(function test_error_message_read_icc_contact () {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
function do_test(options, expectedErrorMsg) {
ril.sendChromeMessage = function(message) {
do_check_eq(message.errorMsg, expectedErrorMsg);
}
ril.readICCContacts(options);
}
// Error 1, didn't specify correct contactType.
do_test({}, CONTACT_ERR_REQUEST_NOT_SUPPORTED);
// Error 2, specifying a non-supported contactType.
ril.appType = CARD_APPTYPE_USIM;
do_test({contactType: "sdn"}, CONTACT_ERR_CONTACT_TYPE_NOT_SUPPORTED);
// Error 3, suppose we update the supported PBR fields in USIM_PBR_FIELDS,
// but forget to add implemenetations for it.
USIM_PBR_FIELDS.push("pbc");
do_test({contactType: "adn"}, CONTACT_ERR_FIELD_NOT_SUPPORTED);
run_next_test();
});
/**
* Test error message returned in onerror for updateICCContact.
*/
add_test(function test_error_message_update_icc_contact() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
const ICCID = "123456789";
ril.iccInfo.iccid = ICCID;
function do_test(options, expectedErrorMsg) {
ril.sendChromeMessage = function(message) {
do_check_eq(message.errorMsg, expectedErrorMsg);
}
ril.updateICCContact(options);
}
// Error 1, didn't specify correct contactType.
do_test({}, CONTACT_ERR_REQUEST_NOT_SUPPORTED);
// Error 2, specifying a correct contactType, but without providing 'contact'.
do_test({contactType: "adn"}, CONTACT_ERR_REQUEST_NOT_SUPPORTED);
// Error 3, specifying a non-supported contactType.
ril.appType = CARD_APPTYPE_USIM;
do_test({contactType: "sdn", contact: {}}, CONTACT_ERR_CONTACT_TYPE_NOT_SUPPORTED);
// Error 4, without supplying pin2.
do_test({contactType: "fdn", contact: {contactId: ICCID + "1"}}, GECKO_ERROR_SIM_PIN2);
// Error 5, No free record found in EF_ADN.
let record = context.ICCRecordHelper;
record.readPBR = function(onsuccess, onerror) {
onsuccess([{adn: {fileId: 0x4f3a}}]);
};
let io = context.ICCIOHelper;
io.loadLinearFixedEF = function(options) {
options.totalRecords = 1;
options.p1 = 1;
options.callback(options);
};
do_test({contactType: "adn", contact: {}}, CONTACT_ERR_NO_FREE_RECORD_FOUND);
// Error 6, ICC IO Error.
io.loadLinearFixedEF = function(options) {
ril[REQUEST_SIM_IO](0, {rilRequestError: ERROR_GENERIC_FAILURE});
};
do_test({contactType: "adn", contact: {contactId: ICCID + "1"}},
GECKO_ERROR_GENERIC_FAILURE);
// Error 7, suppose we update the supported PBR fields in USIM_PBR_FIELDS,
// but forget to add implemenetations for it.
USIM_PBR_FIELDS.push("pbc");
do_test({contactType: "adn", contact: {contactId: ICCID + "1"}},
CONTACT_ERR_FIELD_NOT_SUPPORTED);
// Error 8, EF_PBR doesn't exist.
record.readPBR = function(onsuccess, onerror) {
onsuccess([]);
};
do_test({contactType: "adn", contact: {contactId: ICCID + "1"}},
CONTACT_ERR_CANNOT_ACCESS_PHONEBOOK);
run_next_test();
});
/**
* Verify ICCContactHelper.readICCContacts
*/
add_test(function test_read_icc_contacts() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let record = context.ICCRecordHelper;
let contactHelper = context.ICCContactHelper;
let ril = context.RIL;
function do_test(aSimType, aContactType, aExpectedContact, aEnhancedPhoneBook) {
ril.appType = aSimType;
ril._isCdma = (aSimType === CARD_APPTYPE_RUIM);
ril.iccInfoPrivate.cst = (aEnhancedPhoneBook) ?
[0x0, 0x0C, 0x0, 0x0, 0x0]:
[0x0, 0x00, 0x0, 0x0, 0x0];
// Override some functions to test.
contactHelper.getContactFieldRecordId = function(pbr, contact, field, onsuccess, onerror) {
onsuccess(1);
};
record.readPBR = function readPBR(onsuccess, onerror) {
onsuccess([{adn:{fileId: 0x6f3a}, email: {}, anr0: {}}]);
};
record.readADNLike = function readADNLike(fileId, onsuccess, onerror) {
onsuccess([{recordId: 1, alphaId: "name", number: "111111"}])
};
record.readEmail = function readEmail(fileId, fileType, recordNumber, onsuccess, onerror) {
onsuccess("hello@mail.com");
};
record.readANR = function readANR(fileId, fileType, recordNumber, onsuccess, onerror) {
onsuccess("123456");
};
let onsuccess = function onsuccess(contacts) {
let contact = contacts[0];
for (let key in contact) {
do_print("check " + key);
if (Array.isArray(contact[key])) {
do_check_eq(contact[key][0], aExpectedContact[key]);
} else {
do_check_eq(contact[key], aExpectedContact[key]);
}
}
};
let onerror = function onerror(errorMsg) {
do_print("readICCContacts failed: " + errorMsg);
do_check_true(false);
};
contactHelper.readICCContacts(aSimType, aContactType, onsuccess, onerror);
}
let expectedContact1 = {
pbrIndex: 0,
recordId: 1,
alphaId: "name",
number: "111111"
};
let expectedContact2 = {
pbrIndex: 0,
recordId: 1,
alphaId: "name",
number: "111111",
email: "hello@mail.com",
anr: "123456"
};
// SIM
do_print("Test read SIM adn contacts");
do_test(CARD_APPTYPE_SIM, "adn", expectedContact1);
do_print("Test read SIM fdn contacts");
do_test(CARD_APPTYPE_SIM, "fdn", expectedContact1);
// USIM
do_print("Test read USIM adn contacts");
do_test(CARD_APPTYPE_USIM, "adn", expectedContact2);
do_print("Test read USIM fdn contacts");
do_test(CARD_APPTYPE_USIM, "fdn", expectedContact1);
// RUIM
do_print("Test read RUIM adn contacts");
do_test(CARD_APPTYPE_RUIM, "adn", expectedContact1);
do_print("Test read RUIM fdn contacts");
do_test(CARD_APPTYPE_RUIM, "fdn", expectedContact1);
// RUIM with enhanced phone book
do_print("Test read RUIM adn contacts with enhanced phone book");
do_test(CARD_APPTYPE_RUIM, "adn", expectedContact2, true);
do_print("Test read RUIM fdn contacts with enhanced phone book");
do_test(CARD_APPTYPE_RUIM, "fdn", expectedContact1, true);
run_next_test();
});
/**
* Verify ICCContactHelper.updateICCContact with appType is CARD_APPTYPE_USIM.
*/
add_test(function test_update_icc_contact() {
const ADN_RECORD_ID = 100;
const ADN_SFI = 1;
const IAP_FILE_ID = 0x4f17;
const EMAIL_FILE_ID = 0x4f50;
const EMAIL_RECORD_ID = 20;
const ANR0_FILE_ID = 0x4f11;
const ANR0_RECORD_ID = 30;
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let recordHelper = context.ICCRecordHelper;
let contactHelper = context.ICCContactHelper;
let ril = context.RIL;
function do_test(aSimType, aContactType, aContact, aPin2, aFileType, aHaveIapIndex, aEnhancedPhoneBook) {
ril.appType = aSimType;
ril._isCdma = (aSimType === CARD_APPTYPE_RUIM);
ril.iccInfoPrivate.cst = (aEnhancedPhoneBook) ? [0x0, 0x0C, 0x0, 0x0, 0x0]
: [0x0, 0x00, 0x0, 0x0, 0x0];
recordHelper.readPBR = function(onsuccess, onerror) {
if (aFileType === ICC_USIM_TYPE1_TAG) {
onsuccess([{
adn: {fileId: ICC_EF_ADN},
email: {fileId: EMAIL_FILE_ID,
fileType: ICC_USIM_TYPE1_TAG},
anr0: {fileId: ANR0_FILE_ID,
fileType: ICC_USIM_TYPE1_TAG}
}]);
} else if (aFileType === ICC_USIM_TYPE2_TAG) {
onsuccess([{
adn: {fileId: ICC_EF_ADN,
sfi: ADN_SFI},
iap: {fileId: IAP_FILE_ID},
email: {fileId: EMAIL_FILE_ID,
fileType: ICC_USIM_TYPE2_TAG,
indexInIAP: 0},
anr0: {fileId: ANR0_FILE_ID,
fileType: ICC_USIM_TYPE2_TAG,
indexInIAP: 1}
}]);
}
};
recordHelper.updateADNLike = function(fileId, contact, pin2, onsuccess, onerror) {
if (aContactType === "fdn") {
do_check_eq(fileId, ICC_EF_FDN);
} else if (aContactType === "adn") {
do_check_eq(fileId, ICC_EF_ADN);
}
do_check_eq(pin2, aPin2);
do_check_eq(contact.alphaId, aContact.alphaId);
do_check_eq(contact.number, aContact.number);
onsuccess();
};
recordHelper.readIAP = function(fileId, recordNumber, onsuccess, onerror) {
do_check_eq(fileId, IAP_FILE_ID);
do_check_eq(recordNumber, ADN_RECORD_ID);
onsuccess((aHaveIapIndex) ? [EMAIL_RECORD_ID, ANR0_RECORD_ID]
: [0xff, 0xff]);
};
recordHelper.updateIAP = function(fileId, recordNumber, iap, onsuccess, onerror) {
do_check_eq(fileId, IAP_FILE_ID);
do_check_eq(recordNumber, ADN_RECORD_ID);
onsuccess();
};
recordHelper.updateEmail = function(pbr, recordNumber, email, adnRecordId, onsuccess, onerror) {
do_check_eq(pbr.email.fileId, EMAIL_FILE_ID);
if (pbr.email.fileType === ICC_USIM_TYPE1_TAG) {
do_check_eq(recordNumber, ADN_RECORD_ID);
} else if (pbr.email.fileType === ICC_USIM_TYPE2_TAG) {
do_check_eq(recordNumber, EMAIL_RECORD_ID);
}
do_check_eq(email, aContact.email);
onsuccess();
};
recordHelper.updateANR = function(pbr, recordNumber, number, adnRecordId, onsuccess, onerror) {
do_check_eq(pbr.anr0.fileId, ANR0_FILE_ID);
if (pbr.anr0.fileType === ICC_USIM_TYPE1_TAG) {
do_check_eq(recordNumber, ADN_RECORD_ID);
} else if (pbr.anr0.fileType === ICC_USIM_TYPE2_TAG) {
do_check_eq(recordNumber, ANR0_RECORD_ID);
}
if (Array.isArray(aContact.anr)) {
do_check_eq(number, aContact.anr[0]);
}
onsuccess();
};
recordHelper.findFreeRecordId = function(fileId, onsuccess, onerror) {
let recordId = 0;
if (fileId === EMAIL_FILE_ID) {
recordId = EMAIL_RECORD_ID;
} else if (fileId === ANR0_FILE_ID) {
recordId = ANR0_RECORD_ID;
}
onsuccess(recordId);
};
let isSuccess = false;
let onsuccess = function onsuccess() {
do_print("updateICCContact success");
isSuccess = true;
};
let onerror = function onerror(errorMsg) {
do_print("updateICCContact failed: " + errorMsg);
};
contactHelper.updateICCContact(aSimType, aContactType, aContact, aPin2, onsuccess, onerror);
do_check_true(isSuccess);
}
let contacts = [
{
pbrIndex: 0,
recordId: ADN_RECORD_ID,
alphaId: "test",
number: "123456",
email: "test@mail.com",
anr: ["+654321"]
},
// a contact without email and anr.
{
pbrIndex: 0,
recordId: ADN_RECORD_ID,
alphaId: "test2",
number: "123456",
},
// a contact with email but no anr.
{
pbrIndex: 0,
recordId: ADN_RECORD_ID,
alphaId: "test3",
number: "123456",
email: "test@mail.com"
},
// a contact with anr but no email.
{
pbrIndex: 0,
recordId: ADN_RECORD_ID,
alphaId: "test4",
number: "123456",
anr: ["+654321"]
}];
for (let i = 0; i < contacts.length; i++) {
let contact = contacts[i];
// SIM
do_print("Test update SIM adn contacts");
do_test(CARD_APPTYPE_SIM, "adn", contact);
do_print("Test update SIM fdn contacts");
do_test(CARD_APPTYPE_SIM, "fdn", contact, "1234");
// USIM
do_print("Test update USIM adn contacts");
do_test(CARD_APPTYPE_USIM, "adn", contact, null, ICC_USIM_TYPE1_TAG);
do_test(CARD_APPTYPE_USIM, "adn", contact, null, ICC_USIM_TYPE2_TAG, true);
do_test(CARD_APPTYPE_USIM, "adn", contact, null, ICC_USIM_TYPE2_TAG, false);
do_print("Test update USIM fdn contacts");
do_test(CARD_APPTYPE_USIM, "fdn", contact, "1234");
// RUIM
do_print("Test update RUIM adn contacts");
do_test(CARD_APPTYPE_RUIM, "adn", contact);
do_print("Test update RUIM fdn contacts");
do_test(CARD_APPTYPE_RUIM, "fdn", contact, "1234");
// RUIM with enhanced phone book
do_print("Test update RUIM adn contacts with enhanced phone book");
do_test(CARD_APPTYPE_RUIM, "adn", contact, null, ICC_USIM_TYPE1_TAG, null, true);
do_test(CARD_APPTYPE_RUIM, "adn", contact, null, ICC_USIM_TYPE2_TAG, true, true);
do_test(CARD_APPTYPE_RUIM, "adn", contact, null, ICC_USIM_TYPE2_TAG, false, true);
do_print("Test update RUIM fdn contacts with enhanced phone book");
do_test(CARD_APPTYPE_RUIM, "fdn", contact, "1234", null, true);
}
run_next_test();
});
/**
* Verify updateICCContact with removal of anr and email with File Type 1.
*/
add_test(function test_update_icc_contact_with_remove_type1_attr() {
const ADN_RECORD_ID = 100;
const IAP_FILE_ID = 0x4f17;
const EMAIL_FILE_ID = 0x4f50;
const EMAIL_RECORD_ID = 20;
const ANR0_FILE_ID = 0x4f11;
const ANR0_RECORD_ID = 30;
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let recordHelper = context.ICCRecordHelper;
let contactHelper = context.ICCContactHelper;
recordHelper.updateADNLike = function(fileId, contact, pin2, onsuccess, onerror) {
onsuccess();
};
let contact = {
pbrIndex: 0,
recordId: ADN_RECORD_ID,
alphaId: "test2",
number: "123456",
};
recordHelper.readIAP = function(fileId, recordNumber, onsuccess, onerror) {
onsuccess([EMAIL_RECORD_ID, ANR0_RECORD_ID]);
};
recordHelper.updateEmail = function(pbr, recordNumber, email, adnRecordId, onsuccess, onerror) {
do_check_true(email == null);
onsuccess();
};
recordHelper.updateANR = function(pbr, recordNumber, number, adnRecordId, onsuccess, onerror) {
do_check_true(number == null);
onsuccess();
};
function do_test(type) {
recordHelper.readPBR = function(onsuccess, onerror) {
if (type == ICC_USIM_TYPE1_TAG) {
onsuccess([{
adn: {fileId: ICC_EF_ADN},
email: {fileId: EMAIL_FILE_ID,
fileType: ICC_USIM_TYPE1_TAG},
anr0: {fileId: ANR0_FILE_ID,
fileType: ICC_USIM_TYPE1_TAG}}]);
} else {
onsuccess([{
adn: {fileId: ICC_EF_ADN},
iap: {fileId: IAP_FILE_ID},
email: {fileId: EMAIL_FILE_ID,
fileType: ICC_USIM_TYPE2_TAG,
indexInIAP: 0},
anr0: {fileId: ANR0_FILE_ID,
fileType: ICC_USIM_TYPE2_TAG,
indexInIAP: 1}}]);
}
};
let successCb = function() {
do_check_true(true);
};
let errorCb = function(errorMsg) {
do_print(errorMsg);
do_check_true(false);
};
contactHelper.updateICCContact(CARD_APPTYPE_USIM, "adn", contact, null, successCb, errorCb);
}
do_test(ICC_USIM_TYPE1_TAG);
do_test(ICC_USIM_TYPE2_TAG);
run_next_test();
});
/**
* Verify ICCContactHelper.findFreeICCContact in SIM
*/
add_test(function test_find_free_icc_contact_sim() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let recordHelper = context.ICCRecordHelper;
let contactHelper = context.ICCContactHelper;
// Correct record Id starts with 1, so put a null element at index 0.
let records = [null];
const MAX_RECORDS = 3;
const PBR_INDEX = 0;
recordHelper.findFreeRecordId = function(fileId, onsuccess, onerror) {
if (records.length > MAX_RECORDS) {
onerror("No free record found.");
return;
}
onsuccess(records.length);
};
let successCb = function(pbrIndex, recordId) {
do_check_eq(pbrIndex, PBR_INDEX);
records[recordId] = {};
};
let errorCb = function(errorMsg) {
do_print(errorMsg);
do_check_true(false);
};
for (let i = 0; i < MAX_RECORDS; i++) {
contactHelper.findFreeICCContact(CARD_APPTYPE_SIM, "adn", successCb, errorCb);
}
// The 1st element, records[0], is null.
do_check_eq(records.length - 1, MAX_RECORDS);
// Now the EF is full, so finding a free one should result failure.
successCb = function(pbrIndex, recordId) {
do_check_true(false);
};
errorCb = function(errorMsg) {
do_check_true(errorMsg === "No free record found.");
};
contactHelper.findFreeICCContact(CARD_APPTYPE_SIM, "adn", successCb, errorCb);
run_next_test();
});
/**
* Verify ICCContactHelper.findFreeICCContact in USIM
*/
add_test(function test_find_free_icc_contact_usim() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let recordHelper = context.ICCRecordHelper;
let contactHelper = context.ICCContactHelper;
const ADN1_FILE_ID = 0x6f3a;
const ADN2_FILE_ID = 0x6f3b;
const MAX_RECORDS = 3;
// The adn in the first phonebook set has already two records, which means
// only 1 free record remained.
let pbrs = [{adn: {fileId: ADN1_FILE_ID, records: [null, {}, {}]}},
{adn: {fileId: ADN2_FILE_ID, records: [null]}}];
recordHelper.readPBR = function readPBR(onsuccess, onerror) {
onsuccess(pbrs);
};
recordHelper.findFreeRecordId = function(fileId, onsuccess, onerror) {
let pbr = (fileId == ADN1_FILE_ID ? pbrs[0]: pbrs[1]);
if (pbr.adn.records.length > MAX_RECORDS) {
onerror("No free record found.");
return;
}
onsuccess(pbr.adn.records.length);
};
let successCb = function(pbrIndex, recordId) {
do_check_eq(pbrIndex, 0);
pbrs[pbrIndex].adn.records[recordId] = {};
};
let errorCb = function(errorMsg) {
do_check_true(false);
};
contactHelper.findFreeICCContact(CARD_APPTYPE_USIM, "adn", successCb, errorCb);
// Now the EF_ADN in the 1st phonebook set is full, so the next free contact
// will come from the 2nd phonebook set.
successCb = function(pbrIndex, recordId) {
do_check_eq(pbrIndex, 1);
do_check_eq(recordId, 1);
}
contactHelper.findFreeICCContact(CARD_APPTYPE_USIM, "adn", successCb, errorCb);
run_next_test();
});

View File

@ -0,0 +1,164 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
function run_test() {
run_next_test();
}
/**
* Verify ICCIOHelper.loadLinearFixedEF with recordSize.
*/
add_test(function test_load_linear_fixed_ef() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
let io = context.ICCIOHelper;
io.getResponse = function fakeGetResponse(options) {
// When recordSize is provided, loadLinearFixedEF should call iccIO directly.
do_check_true(false);
run_next_test();
};
ril.iccIO = function fakeIccIO(options) {
do_check_true(true);
run_next_test();
};
io.loadLinearFixedEF({recordSize: 0x20});
});
/**
* Verify ICCIOHelper.loadLinearFixedEF without recordSize.
*/
add_test(function test_load_linear_fixed_ef() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
let io = context.ICCIOHelper;
io.getResponse = function fakeGetResponse(options) {
do_check_true(true);
run_next_test();
};
ril.iccIO = function fakeIccIO(options) {
// When recordSize is not provided, loadLinearFixedEF should call getResponse.
do_check_true(false);
run_next_test();
};
io.loadLinearFixedEF({});
});
/**
* Verify ICCIOHelper.processICCIOError.
*/
add_test(function test_process_icc_io_error() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let ioHelper = context.ICCIOHelper;
function do_test(errorCode, expectedErrorMsg) {
let called = false;
function errorCb(errorMsg) {
called = true;
do_check_eq(errorMsg, expectedErrorMsg);
}
ioHelper.processICCIOError({rilRequestError: errorCode,
fileId: 0xffff,
command: 0xff,
sw1: 0xff,
sw2: 0xff,
onerror: errorCb});
do_check_true(called);
}
for (let i = 0; i < ERROR_REJECTED_BY_REMOTE + 1; i++) {
do_test(i, RIL_ERROR_TO_GECKO_ERROR[i]);
}
run_next_test();
});
/**
* Verify ICCIOHelper.processICCIOGetResponse for EF_TYPE_TRANSPARENT.
*/
add_test(function test_icc_io_get_response_for_transparent_structure() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let buf = context.Buf;
let iccioHelper = context.ICCIOHelper;
let pduHelper = context.GsmPDUHelper;
let responseArray = [
// SIM response.
[0x00, 0x00, 0x00, 0x0A, 0x2F, 0xE2, 0x04, 0x00, 0x0A, 0xA0, 0xAA, 0x00,
0x02, 0x00, 0x00],
// USIM response.
[0x62, 0x22, 0x82, 0x02, 0x41, 0x21, 0x83, 0x02, 0x2F, 0xE2, 0xA5, 0x09,
0xC1, 0x04, 0x40, 0x0F, 0xF5, 0x55, 0x92, 0x01, 0x00, 0x8A, 0x01, 0x05,
0x8B, 0x03, 0x2F, 0x06, 0x0B, 0x80, 0x02, 0x00, 0x0A, 0x88, 0x01, 0x10]
];
for (let i = 0; i < responseArray.length; i++) {
let strLen = responseArray[i].length * 2;
buf.writeInt32(strLen);
for (let j = 0; j < responseArray[i].length; j++) {
pduHelper.writeHexOctet(responseArray[i][j]);
}
buf.writeStringDelimiter(strLen);
let options = {fileId: ICC_EF_ICCID,
type: EF_TYPE_TRANSPARENT};
iccioHelper.processICCIOGetResponse(options);
do_check_eq(options.fileSize, 0x0A);
}
run_next_test();
});
/**
* Verify ICCIOHelper.processICCIOGetResponse for EF_TYPE_LINEAR_FIXED.
*/
add_test(function test_icc_io_get_response_for_linear_fixed_structure() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let buf = context.Buf;
let iccioHelper = context.ICCIOHelper;
let pduHelper = context.GsmPDUHelper;
let responseArray = [
// SIM response.
[0x00, 0x00, 0x00, 0x1A, 0x6F, 0x40, 0x04, 0x00, 0x11, 0xA0, 0xAA, 0x00,
0x02, 0x01, 0x1A],
// USIM response.
[0x62, 0x1E, 0x82, 0x05, 0x42, 0x21, 0x00, 0x1A, 0x01, 0x83, 0x02, 0x6F,
0x40, 0xA5, 0x03, 0x92, 0x01, 0x00, 0x8A, 0x01, 0x07, 0x8B, 0x03, 0x6F,
0x06, 0x02, 0x80, 0x02, 0x00, 0x1A, 0x88, 0x00]
];
for (let i = 0; i < responseArray.length; i++) {
let strLen = responseArray[i].length * 2;
buf.writeInt32(strLen);
for (let j = 0; j < responseArray[i].length; j++) {
pduHelper.writeHexOctet(responseArray[i][j]);
}
buf.writeStringDelimiter(strLen);
let options = {fileId: ICC_EF_MSISDN,
type: EF_TYPE_LINEAR_FIXED};
iccioHelper.processICCIOGetResponse(options);
do_check_eq(options.fileSize, 0x1A);
do_check_eq(options.recordSize, 0x1A);
do_check_eq(options.totalRecords, 0x01);
}
run_next_test();
});

View File

@ -0,0 +1,520 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
function run_test() {
run_next_test();
}
/**
* Verify ICCPDUHelper#readICCUCS2String()
*/
add_test(function test_read_icc_ucs2_string() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
// 0x80
let text = "TEST";
helper.writeUCS2String(text);
// Also write two unused octets.
let ffLen = 2;
for (let i = 0; i < ffLen; i++) {
helper.writeHexOctet(0xff);
}
do_check_eq(iccHelper.readICCUCS2String(0x80, (2 * text.length) + ffLen), text);
// 0x81
let array = [0x08, 0xd2, 0x4d, 0x6f, 0x7a, 0x69, 0x6c, 0x6c, 0x61, 0xca,
0xff, 0xff];
let len = array.length;
for (let i = 0; i < len; i++) {
helper.writeHexOctet(array[i]);
}
do_check_eq(iccHelper.readICCUCS2String(0x81, len), "Mozilla\u694a");
// 0x82
let array2 = [0x08, 0x69, 0x00, 0x4d, 0x6f, 0x7a, 0x69, 0x6c, 0x6c, 0x61,
0xca, 0xff, 0xff];
let len2 = array2.length;
for (let i = 0; i < len2; i++) {
helper.writeHexOctet(array2[i]);
}
do_check_eq(iccHelper.readICCUCS2String(0x82, len2), "Mozilla\u694a");
run_next_test();
});
/**
* Verify ICCPDUHelper#readDiallingNumber
*/
add_test(function test_read_dialling_number() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
let str = "123456789";
helper.readHexOctet = function() {
return 0x81;
};
helper.readSwappedNibbleBcdString = function(len) {
return str.substring(0, len);
};
for (let i = 0; i < str.length; i++) {
do_check_eq(str.substring(0, i - 1), // -1 for the TON
iccHelper.readDiallingNumber(i));
}
run_next_test();
});
/**
* Verify ICCPDUHelper#read8BitUnpackedToString
*/
add_test(function test_read_8bit_unpacked_to_string() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
const langTable = PDU_NL_LOCKING_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
const langShiftTable = PDU_NL_SINGLE_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
// Test 1: Read GSM alphabets.
// Write alphabets before ESCAPE.
for (let i = 0; i < PDU_NL_EXTENDED_ESCAPE; i++) {
helper.writeHexOctet(i);
}
// Write two ESCAPEs to make it become ' '.
helper.writeHexOctet(PDU_NL_EXTENDED_ESCAPE);
helper.writeHexOctet(PDU_NL_EXTENDED_ESCAPE);
for (let i = PDU_NL_EXTENDED_ESCAPE + 1; i < langTable.length; i++) {
helper.writeHexOctet(i);
}
// Also write two unused fields.
let ffLen = 2;
for (let i = 0; i < ffLen; i++) {
helper.writeHexOctet(0xff);
}
do_check_eq(iccHelper.read8BitUnpackedToString(PDU_NL_EXTENDED_ESCAPE),
langTable.substring(0, PDU_NL_EXTENDED_ESCAPE));
do_check_eq(iccHelper.read8BitUnpackedToString(2), " ");
do_check_eq(iccHelper.read8BitUnpackedToString(langTable.length -
PDU_NL_EXTENDED_ESCAPE - 1 + ffLen),
langTable.substring(PDU_NL_EXTENDED_ESCAPE + 1));
// Test 2: Read GSM extended alphabets.
for (let i = 0; i < langShiftTable.length; i++) {
helper.writeHexOctet(PDU_NL_EXTENDED_ESCAPE);
helper.writeHexOctet(i);
}
// Read string before RESERVED_CONTROL.
do_check_eq(iccHelper.read8BitUnpackedToString(PDU_NL_RESERVED_CONTROL * 2),
langShiftTable.substring(0, PDU_NL_RESERVED_CONTROL));
// ESCAPE + RESERVED_CONTROL will become ' '.
do_check_eq(iccHelper.read8BitUnpackedToString(2), " ");
// Read string between RESERVED_CONTROL and EXTENDED_ESCAPE.
do_check_eq(iccHelper.read8BitUnpackedToString(
(PDU_NL_EXTENDED_ESCAPE - PDU_NL_RESERVED_CONTROL - 1) * 2),
langShiftTable.substring(PDU_NL_RESERVED_CONTROL + 1,
PDU_NL_EXTENDED_ESCAPE));
// ESCAPE + ESCAPE will become ' '.
do_check_eq(iccHelper.read8BitUnpackedToString(2), " ");
// Read remaining string.
do_check_eq(iccHelper.read8BitUnpackedToString(
(langShiftTable.length - PDU_NL_EXTENDED_ESCAPE - 1) * 2),
langShiftTable.substring(PDU_NL_EXTENDED_ESCAPE + 1));
run_next_test();
});
/**
* Verify ICCPDUHelper#writeStringTo8BitUnpacked.
*
* Test writing GSM 8 bit alphabets.
*/
add_test(function test_write_string_to_8bit_unpacked() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
const langTable = PDU_NL_LOCKING_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
const langShiftTable = PDU_NL_SINGLE_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
// Length of trailing 0xff.
let ffLen = 2;
let str;
// Test 1, write GSM alphabets.
iccHelper.writeStringTo8BitUnpacked(langTable.length + ffLen, langTable);
for (let i = 0; i < langTable.length; i++) {
do_check_eq(helper.readHexOctet(), i);
}
for (let i = 0; i < ffLen; i++) {
do_check_eq(helper.readHexOctet(), 0xff);
}
// Test 2, write GSM extended alphabets.
str = "\u000c\u20ac";
iccHelper.writeStringTo8BitUnpacked(4, str);
do_check_eq(iccHelper.read8BitUnpackedToString(4), str);
// Test 3, write GSM and GSM extended alphabets.
// \u000c, \u20ac are from gsm extended alphabets.
// \u00a3 is from gsm alphabet.
str = "\u000c\u20ac\u00a3";
// 2 octets * 2 = 4 octets for 2 gsm extended alphabets,
// 1 octet for 1 gsm alphabet,
// 2 octes for trailing 0xff.
// "Totally 7 octets are to be written."
iccHelper.writeStringTo8BitUnpacked(7, str);
do_check_eq(iccHelper.read8BitUnpackedToString(7), str);
run_next_test();
});
/**
* Verify ICCPDUHelper#writeStringTo8BitUnpacked with maximum octets written.
*/
add_test(function test_write_string_to_8bit_unpacked_with_max_octets_written() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
const langTable = PDU_NL_LOCKING_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
const langShiftTable = PDU_NL_SINGLE_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
// The maximum of the number of octets that can be written is 3.
// Only 3 characters shall be written even the length of the string is 4.
iccHelper.writeStringTo8BitUnpacked(3, langTable.substring(0, 4));
helper.writeHexOctet(0xff); // dummy octet.
for (let i = 0; i < 3; i++) {
do_check_eq(helper.readHexOctet(), i);
}
do_check_false(helper.readHexOctet() == 4);
// \u000c is GSM extended alphabet, 2 octets.
// \u00a3 is GSM alphabet, 1 octet.
let str = "\u000c\u00a3";
iccHelper.writeStringTo8BitUnpacked(3, str);
do_check_eq(iccHelper.read8BitUnpackedToString(3), str);
str = "\u00a3\u000c";
iccHelper.writeStringTo8BitUnpacked(3, str);
do_check_eq(iccHelper.read8BitUnpackedToString(3), str);
// 2 GSM extended alphabets cost 4 octets, but maximum is 3, so only the 1st
// alphabet can be written.
str = "\u000c\u000c";
iccHelper.writeStringTo8BitUnpacked(3, str);
helper.writeHexOctet(0xff); // dummy octet.
do_check_eq(iccHelper.read8BitUnpackedToString(4), str.substring(0, 1));
run_next_test();
});
/**
* Verify ICCPDUHelper.readAlphaIdentifier
*/
add_test(function test_read_alpha_identifier() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
// UCS2: 0x80
let text = "TEST";
helper.writeHexOctet(0x80);
helper.writeUCS2String(text);
// Also write two unused octets.
let ffLen = 2;
for (let i = 0; i < ffLen; i++) {
helper.writeHexOctet(0xff);
}
do_check_eq(iccHelper.readAlphaIdentifier(1 + (2 * text.length) + ffLen), text);
// UCS2: 0x81
let array = [0x81, 0x08, 0xd2, 0x4d, 0x6f, 0x7a, 0x69, 0x6c, 0x6c, 0x61, 0xca, 0xff, 0xff];
for (let i = 0; i < array.length; i++) {
helper.writeHexOctet(array[i]);
}
do_check_eq(iccHelper.readAlphaIdentifier(array.length), "Mozilla\u694a");
// UCS2: 0x82
let array2 = [0x82, 0x08, 0x69, 0x00, 0x4d, 0x6f, 0x7a, 0x69, 0x6c, 0x6c, 0x61, 0xca, 0xff, 0xff];
for (let i = 0; i < array2.length; i++) {
helper.writeHexOctet(array2[i]);
}
do_check_eq(iccHelper.readAlphaIdentifier(array2.length), "Mozilla\u694a");
// GSM 8 Bit Unpacked
const langTable = PDU_NL_LOCKING_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
for (let i = 0; i < PDU_NL_EXTENDED_ESCAPE; i++) {
helper.writeHexOctet(i);
}
do_check_eq(iccHelper.readAlphaIdentifier(PDU_NL_EXTENDED_ESCAPE),
langTable.substring(0, PDU_NL_EXTENDED_ESCAPE));
run_next_test();
});
/**
* Verify ICCPDUHelper.writeAlphaIdentifier
*/
add_test(function test_write_alpha_identifier() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
// Length of trailing 0xff.
let ffLen = 2;
// Removal
iccHelper.writeAlphaIdentifier(10, null);
do_check_eq(iccHelper.readAlphaIdentifier(10), "");
// GSM 8 bit
let str = "Mozilla";
iccHelper.writeAlphaIdentifier(str.length + ffLen, str);
do_check_eq(iccHelper.readAlphaIdentifier(str.length + ffLen), str);
// UCS2
str = "Mozilla\u694a";
iccHelper.writeAlphaIdentifier(str.length * 2 + ffLen, str);
// * 2 for each character will be encoded to UCS2 alphabets.
do_check_eq(iccHelper.readAlphaIdentifier(str.length * 2 + ffLen), str);
// Test with maximum octets written.
// 1 coding scheme (0x80) and 1 UCS2 character, total 3 octets.
str = "\u694a";
iccHelper.writeAlphaIdentifier(3, str);
do_check_eq(iccHelper.readAlphaIdentifier(3), str);
// 1 coding scheme (0x80) and 2 UCS2 characters, total 5 octets.
// numOctets is limited to 4, so only 1 UCS2 character can be written.
str = "\u694a\u694a";
iccHelper.writeAlphaIdentifier(4, str);
helper.writeHexOctet(0xff); // dummy octet.
do_check_eq(iccHelper.readAlphaIdentifier(5), str.substring(0, 1));
// Write 0 octet.
iccHelper.writeAlphaIdentifier(0, "1");
helper.writeHexOctet(0xff); // dummy octet.
do_check_eq(iccHelper.readAlphaIdentifier(1), "");
run_next_test();
});
/**
* Verify ICCPDUHelper.readAlphaIdDiallingNumber
*/
add_test(function test_read_alpha_id_dialling_number() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
let buf = context.Buf;
const recordSize = 32;
function testReadAlphaIdDiallingNumber(contact) {
iccHelper.readAlphaIdentifier = function() {
return contact.alphaId;
};
iccHelper.readNumberWithLength = function() {
return contact.number;
};
let strLen = recordSize * 2;
buf.writeInt32(strLen); // fake length
helper.writeHexOctet(0xff); // fake CCP
helper.writeHexOctet(0xff); // fake EXT1
buf.writeStringDelimiter(strLen);
let contactR = iccHelper.readAlphaIdDiallingNumber(recordSize);
if (contact.alphaId == "" && contact.number == "") {
do_check_eq(contactR, null);
} else {
do_check_eq(contactR.alphaId, contact.alphaId);
do_check_eq(contactR.number, contact.number);
}
}
testReadAlphaIdDiallingNumber({alphaId: "AlphaId", number: "0987654321"});
testReadAlphaIdDiallingNumber({alphaId: "", number: ""});
run_next_test();
});
/**
* Verify ICCPDUHelper.writeAlphaIdDiallingNumber
*/
add_test(function test_write_alpha_id_dialling_number() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let helper = context.ICCPDUHelper;
const recordSize = 32;
// Write a normal contact.
let contactW = {
alphaId: "Mozilla",
number: "1234567890"
};
helper.writeAlphaIdDiallingNumber(recordSize, contactW.alphaId,
contactW.number);
let contactR = helper.readAlphaIdDiallingNumber(recordSize);
do_check_eq(contactW.alphaId, contactR.alphaId);
do_check_eq(contactW.number, contactR.number);
// Write a contact with alphaId encoded in UCS2 and number has '+'.
let contactUCS2 = {
alphaId: "火狐",
number: "+1234567890"
};
helper.writeAlphaIdDiallingNumber(recordSize, contactUCS2.alphaId,
contactUCS2.number);
contactR = helper.readAlphaIdDiallingNumber(recordSize);
do_check_eq(contactUCS2.alphaId, contactR.alphaId);
do_check_eq(contactUCS2.number, contactR.number);
// Write a null contact (Removal).
helper.writeAlphaIdDiallingNumber(recordSize);
contactR = helper.readAlphaIdDiallingNumber(recordSize);
do_check_eq(contactR, null);
// Write a longer alphaId/dialling number
// Dialling Number : Maximum 20 digits(10 octets).
// Alpha Identifier: 32(recordSize) - 14 (10 octets for Dialling Number, 1
// octet for TON/NPI, 1 for number length octet, and 2 for
// Ext) = Maximum 18 octets.
let longContact = {
alphaId: "AAAAAAAAABBBBBBBBBCCCCCCCCC",
number: "123456789012345678901234567890",
};
helper.writeAlphaIdDiallingNumber(recordSize, longContact.alphaId,
longContact.number);
contactR = helper.readAlphaIdDiallingNumber(recordSize);
do_check_eq(contactR.alphaId, "AAAAAAAAABBBBBBBBB");
do_check_eq(contactR.number, "12345678901234567890");
// Add '+' to number and test again.
longContact.number = "+123456789012345678901234567890";
helper.writeAlphaIdDiallingNumber(recordSize, longContact.alphaId,
longContact.number);
contactR = helper.readAlphaIdDiallingNumber(recordSize);
do_check_eq(contactR.alphaId, "AAAAAAAAABBBBBBBBB");
do_check_eq(contactR.number, "+12345678901234567890");
run_next_test();
});
/**
* Verify ICCPDUHelper.writeDiallingNumber
*/
add_test(function test_write_dialling_number() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let helper = context.ICCPDUHelper;
// with +
let number = "+123456";
let len = 4;
helper.writeDiallingNumber(number);
do_check_eq(helper.readDiallingNumber(len), number);
// without +
number = "987654";
len = 4;
helper.writeDiallingNumber(number);
do_check_eq(helper.readDiallingNumber(len), number);
number = "9876543";
len = 5;
helper.writeDiallingNumber(number);
do_check_eq(helper.readDiallingNumber(len), number);
run_next_test();
});
/**
* Verify ICCPDUHelper.readNumberWithLength
*/
add_test(function test_read_number_with_length() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
let number = "123456789";
iccHelper.readDiallingNumber = function(numLen) {
return number.substring(0, numLen);
};
helper.writeHexOctet(number.length + 1);
helper.writeHexOctet(PDU_TOA_ISDN);
do_check_eq(iccHelper.readNumberWithLength(), number);
helper.writeHexOctet(0xff);
do_check_eq(iccHelper.readNumberWithLength(), null);
run_next_test();
});
/**
* Verify ICCPDUHelper.writeNumberWithLength
*/
add_test(function test_write_number_with_length() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
function test(number, expectedNumber) {
expectedNumber = expectedNumber || number;
iccHelper.writeNumberWithLength(number);
let numLen = helper.readHexOctet();
do_check_eq(expectedNumber, iccHelper.readDiallingNumber(numLen));
for (let i = 0; i < (ADN_MAX_BCD_NUMBER_BYTES - numLen); i++) {
do_check_eq(0xff, helper.readHexOctet());
}
}
// without +
test("123456789");
// with +
test("+987654321");
// extended BCD coding
test("1*2#3,4*5#6,");
// with + and extended BCD coding
test("+1*2#3,4*5#6,");
// non-supported characters should not be written.
test("(1)23-456+789", "123456789");
test("++(01)2*3-4#5,6+7(8)9*0#1,", "+012*34#5,6789*0#1,");
// null
iccHelper.writeNumberWithLength(null);
for (let i = 0; i < (ADN_MAX_BCD_NUMBER_BYTES + 1); i++) {
do_check_eq(0xff, helper.readHexOctet());
}
run_next_test();
});

View File

@ -0,0 +1,725 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
function run_test() {
run_next_test();
}
/**
* Verify ICCRecordHelper.readPBR
*/
add_test(function test_read_pbr() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let record = context.ICCRecordHelper;
let buf = context.Buf;
let io = context.ICCIOHelper;
io.loadLinearFixedEF = function fakeLoadLinearFixedEF(options) {
let pbr_1 = [
0xa8, 0x05, 0xc0, 0x03, 0x4f, 0x3a, 0x01
];
// Write data size
buf.writeInt32(pbr_1.length * 2);
// Write pbr
for (let i = 0; i < pbr_1.length; i++) {
helper.writeHexOctet(pbr_1[i]);
}
// Write string delimiter
buf.writeStringDelimiter(pbr_1.length * 2);
options.totalRecords = 2;
if (options.callback) {
options.callback(options);
}
};
io.loadNextRecord = function fakeLoadNextRecord(options) {
let pbr_2 = [
0xff, 0xff, 0xff, 0xff, 0xff, 0xff
];
options.p1++;
if (options.callback) {
options.callback(options);
}
};
let successCb = function successCb(pbrs) {
do_check_eq(pbrs[0].adn.fileId, 0x4f3a);
do_check_eq(pbrs.length, 1);
};
let errorCb = function errorCb(errorMsg) {
do_print("Reading EF_PBR failed, msg = " + errorMsg);
do_check_true(false);
};
record.readPBR(successCb, errorCb);
// Check cache pbrs when 2nd call
let ifLoadEF = false;
io.loadLinearFixedEF = function fakeLoadLinearFixedEF(options) {
ifLoadEF = true;
}
record.readPBR(successCb, errorCb);
do_check_false(ifLoadEF);
run_next_test();
});
/**
* Verify ICCRecordHelper.readEmail
*/
add_test(function test_read_email() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let record = context.ICCRecordHelper;
let buf = context.Buf;
let io = context.ICCIOHelper;
let recordSize;
io.loadLinearFixedEF = function fakeLoadLinearFixedEF(options) {
let email_1 = [
0x65, 0x6D, 0x61, 0x69, 0x6C,
0x00, 0x6D, 0x6F, 0x7A, 0x69,
0x6C, 0x6C, 0x61, 0x2E, 0x63,
0x6F, 0x6D, 0x02, 0x23];
// Write data size
buf.writeInt32(email_1.length * 2);
// Write email
for (let i = 0; i < email_1.length; i++) {
helper.writeHexOctet(email_1[i]);
}
// Write string delimiter
buf.writeStringDelimiter(email_1.length * 2);
recordSize = email_1.length;
options.recordSize = recordSize;
if (options.callback) {
options.callback(options);
}
};
function doTestReadEmail(type, expectedResult) {
let fileId = 0x6a75;
let recordNumber = 1;
// fileId and recordNumber are dummy arguments.
record.readEmail(fileId, type, recordNumber, function(email) {
do_check_eq(email, expectedResult);
});
};
doTestReadEmail(ICC_USIM_TYPE1_TAG, "email@mozilla.com$#");
doTestReadEmail(ICC_USIM_TYPE2_TAG, "email@mozilla.com");
do_check_eq(record._emailRecordSize, recordSize);
run_next_test();
});
/**
* Verify ICCRecordHelper.updateEmail
*/
add_test(function test_update_email() {
const recordSize = 0x20;
const recordNumber = 1;
const fileId = 0x4f50;
const NUM_TESTS = 2;
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
let ril = context.RIL;
ril.appType = CARD_APPTYPE_USIM;
let recordHelper = context.ICCRecordHelper;
let buf = context.Buf;
let ioHelper = context.ICCIOHelper;
let pbr = {email: {fileId: fileId, fileType: ICC_USIM_TYPE1_TAG},
adn: {sfi: 1}};
let count = 0;
// Override.
ioHelper.updateLinearFixedEF = function(options) {
options.pathId = context.ICCFileHelper.getEFPath(options.fileId);
options.command = ICC_COMMAND_UPDATE_RECORD;
options.p1 = options.recordNumber;
options.p2 = READ_RECORD_ABSOLUTE_MODE;
options.p3 = recordSize;
ril.iccIO(options);
};
function do_test(pbr, expectedEmail, expectedAdnRecordId) {
buf.sendParcel = function() {
count++;
// Request Type.
do_check_eq(this.readInt32(), REQUEST_SIM_IO);
// Token : we don't care
this.readInt32();
// command.
do_check_eq(this.readInt32(), ICC_COMMAND_UPDATE_RECORD);
// fileId.
do_check_eq(this.readInt32(), fileId);
// pathId.
do_check_eq(this.readString(),
EF_PATH_MF_SIM + EF_PATH_DF_TELECOM + EF_PATH_DF_PHONEBOOK);
// p1.
do_check_eq(this.readInt32(), recordNumber);
// p2.
do_check_eq(this.readInt32(), READ_RECORD_ABSOLUTE_MODE);
// p3.
do_check_eq(this.readInt32(), recordSize);
// data.
let strLen = this.readInt32();
let email;
if (pbr.email.fileType === ICC_USIM_TYPE1_TAG) {
email = iccHelper.read8BitUnpackedToString(recordSize);
} else {
email = iccHelper.read8BitUnpackedToString(recordSize - 2);
do_check_eq(pduHelper.readHexOctet(), pbr.adn.sfi);
do_check_eq(pduHelper.readHexOctet(), expectedAdnRecordId);
}
this.readStringDelimiter(strLen);
do_check_eq(email, expectedEmail);
// pin2.
do_check_eq(this.readString(), null);
if (!ril.v5Legacy) {
// AID. Ignore because it's from modem.
this.readInt32();
}
if (count == NUM_TESTS) {
run_next_test();
}
};
recordHelper.updateEmail(pbr, recordNumber, expectedEmail, expectedAdnRecordId);
}
do_test(pbr, "test@mail.com");
pbr.email.fileType = ICC_USIM_TYPE2_TAG;
do_test(pbr, "test@mail.com", 1);
});
/**
* Verify ICCRecordHelper.readANR
*/
add_test(function test_read_anr() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let record = context.ICCRecordHelper;
let buf = context.Buf;
let io = context.ICCIOHelper;
let recordSize;
io.loadLinearFixedEF = function fakeLoadLinearFixedEF(options) {
let anr_1 = [
0x01, 0x05, 0x81, 0x10, 0x32,
0x54, 0xF6, 0xFF, 0xFF];
// Write data size
buf.writeInt32(anr_1.length * 2);
// Write anr
for (let i = 0; i < anr_1.length; i++) {
helper.writeHexOctet(anr_1[i]);
}
// Write string delimiter
buf.writeStringDelimiter(anr_1.length * 2);
recordSize = anr_1.length;
options.recordSize = recordSize;
if (options.callback) {
options.callback(options);
}
};
function doTestReadAnr(fileType, expectedResult) {
let fileId = 0x4f11;
let recordNumber = 1;
// fileId and recordNumber are dummy arguments.
record.readANR(fileId, fileType, recordNumber, function(anr) {
do_check_eq(anr, expectedResult);
});
};
doTestReadAnr(ICC_USIM_TYPE1_TAG, "0123456");
do_check_eq(record._anrRecordSize, recordSize);
run_next_test();
});
/**
* Verify ICCRecordHelper.updateANR
*/
add_test(function test_update_anr() {
const recordSize = 0x20;
const recordNumber = 1;
const fileId = 0x4f11;
const NUM_TESTS = 2;
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
let ril = context.RIL;
ril.appType = CARD_APPTYPE_USIM;
let recordHelper = context.ICCRecordHelper;
let buf = context.Buf;
let ioHelper = context.ICCIOHelper;
let pbr = {anr0: {fileId: fileId, fileType: ICC_USIM_TYPE1_TAG},
adn: {sfi: 1}};
let count = 0;
// Override.
ioHelper.updateLinearFixedEF = function(options) {
options.pathId = context.ICCFileHelper.getEFPath(options.fileId);
options.command = ICC_COMMAND_UPDATE_RECORD;
options.p1 = options.recordNumber;
options.p2 = READ_RECORD_ABSOLUTE_MODE;
options.p3 = recordSize;
ril.iccIO(options);
};
function do_test(pbr, expectedANR, expectedAdnRecordId) {
buf.sendParcel = function() {
count++;
// Request Type.
do_check_eq(this.readInt32(), REQUEST_SIM_IO);
// Token : we don't care
this.readInt32();
// command.
do_check_eq(this.readInt32(), ICC_COMMAND_UPDATE_RECORD);
// fileId.
do_check_eq(this.readInt32(), fileId);
// pathId.
do_check_eq(this.readString(),
EF_PATH_MF_SIM + EF_PATH_DF_TELECOM + EF_PATH_DF_PHONEBOOK);
// p1.
do_check_eq(this.readInt32(), recordNumber);
// p2.
do_check_eq(this.readInt32(), READ_RECORD_ABSOLUTE_MODE);
// p3.
do_check_eq(this.readInt32(), recordSize);
// data.
let strLen = this.readInt32();
// EF_AAS, ignore.
pduHelper.readHexOctet();
do_check_eq(iccHelper.readNumberWithLength(), expectedANR);
// EF_CCP, ignore.
pduHelper.readHexOctet();
// EF_EXT1, ignore.
pduHelper.readHexOctet();
if (pbr.anr0.fileType === ICC_USIM_TYPE2_TAG) {
do_check_eq(pduHelper.readHexOctet(), pbr.adn.sfi);
do_check_eq(pduHelper.readHexOctet(), expectedAdnRecordId);
}
this.readStringDelimiter(strLen);
// pin2.
do_check_eq(this.readString(), null);
if (!ril.v5Legacy) {
// AID. Ignore because it's from modem.
this.readInt32();
}
if (count == NUM_TESTS) {
run_next_test();
}
};
recordHelper.updateANR(pbr, recordNumber, expectedANR, expectedAdnRecordId);
}
do_test(pbr, "+123456789");
pbr.anr0.fileType = ICC_USIM_TYPE2_TAG;
do_test(pbr, "123456789", 1);
});
/**
* Verify ICCRecordHelper.readIAP
*/
add_test(function test_read_iap() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let record = context.ICCRecordHelper;
let buf = context.Buf;
let io = context.ICCIOHelper;
let recordSize;
io.loadLinearFixedEF = function fakeLoadLinearFixedEF(options) {
let iap_1 = [0x01, 0x02];
// Write data size/
buf.writeInt32(iap_1.length * 2);
// Write iap.
for (let i = 0; i < iap_1.length; i++) {
helper.writeHexOctet(iap_1[i]);
}
// Write string delimiter.
buf.writeStringDelimiter(iap_1.length * 2);
recordSize = iap_1.length;
options.recordSize = recordSize;
if (options.callback) {
options.callback(options);
}
};
function doTestReadIAP(expectedIAP) {
const fileId = 0x4f17;
const recordNumber = 1;
let successCb = function successCb(iap) {
for (let i = 0; i < iap.length; i++) {
do_check_eq(expectedIAP[i], iap[i]);
}
run_next_test();
}.bind(this);
let errorCb = function errorCb(errorMsg) {
do_print(errorMsg);
do_check_true(false);
run_next_test();
}.bind(this);
record.readIAP(fileId, recordNumber, successCb, errorCb);
};
doTestReadIAP([1, 2]);
});
/**
* Verify ICCRecordHelper.updateIAP
*/
add_test(function test_update_iap() {
const recordSize = 2;
const recordNumber = 1;
const fileId = 0x4f17;
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let ril = context.RIL;
ril.appType = CARD_APPTYPE_USIM;
let recordHelper = context.ICCRecordHelper;
let buf = context.Buf;
let ioHelper = context.ICCIOHelper;
let count = 0;
// Override.
ioHelper.updateLinearFixedEF = function(options) {
options.pathId = context.ICCFileHelper.getEFPath(options.fileId);
options.command = ICC_COMMAND_UPDATE_RECORD;
options.p1 = options.recordNumber;
options.p2 = READ_RECORD_ABSOLUTE_MODE;
options.p3 = recordSize;
ril.iccIO(options);
};
function do_test(expectedIAP) {
buf.sendParcel = function() {
// Request Type.
do_check_eq(this.readInt32(), REQUEST_SIM_IO);
// Token : we don't care
this.readInt32();
// command.
do_check_eq(this.readInt32(), ICC_COMMAND_UPDATE_RECORD);
// fileId.
do_check_eq(this.readInt32(), fileId);
// pathId.
do_check_eq(this.readString(),
EF_PATH_MF_SIM + EF_PATH_DF_TELECOM + EF_PATH_DF_PHONEBOOK);
// p1.
do_check_eq(this.readInt32(), recordNumber);
// p2.
do_check_eq(this.readInt32(), READ_RECORD_ABSOLUTE_MODE);
// p3.
do_check_eq(this.readInt32(), recordSize);
// data.
let strLen = this.readInt32();
for (let i = 0; i < recordSize; i++) {
do_check_eq(expectedIAP[i], pduHelper.readHexOctet());
}
this.readStringDelimiter(strLen);
// pin2.
do_check_eq(this.readString(), null);
if (!ril.v5Legacy) {
// AID. Ignore because it's from modem.
this.readInt32();
}
run_next_test();
};
recordHelper.updateIAP(fileId, recordNumber, expectedIAP);
}
do_test([1, 2]);
});
/**
* Verify ICCRecordHelper.updateADNLike.
*/
add_test(function test_update_adn_like() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
let record = context.ICCRecordHelper;
let io = context.ICCIOHelper;
let pdu = context.ICCPDUHelper;
let buf = context.Buf;
ril.appType = CARD_APPTYPE_SIM;
const recordSize = 0x20;
let fileId;
// Override.
io.updateLinearFixedEF = function(options) {
options.pathId = context.ICCFileHelper.getEFPath(options.fileId);
options.command = ICC_COMMAND_UPDATE_RECORD;
options.p1 = options.recordNumber;
options.p2 = READ_RECORD_ABSOLUTE_MODE;
options.p3 = recordSize;
ril.iccIO(options);
};
buf.sendParcel = function() {
// Request Type.
do_check_eq(this.readInt32(), REQUEST_SIM_IO);
// Token : we don't care
this.readInt32();
// command.
do_check_eq(this.readInt32(), ICC_COMMAND_UPDATE_RECORD);
// fileId.
do_check_eq(this.readInt32(), fileId);
// pathId.
do_check_eq(this.readString(), EF_PATH_MF_SIM + EF_PATH_DF_TELECOM);
// p1.
do_check_eq(this.readInt32(), 1);
// p2.
do_check_eq(this.readInt32(), READ_RECORD_ABSOLUTE_MODE);
// p3.
do_check_eq(this.readInt32(), 0x20);
// data.
let contact = pdu.readAlphaIdDiallingNumber(0x20);
do_check_eq(contact.alphaId, "test");
do_check_eq(contact.number, "123456");
// pin2.
if (fileId == ICC_EF_ADN) {
do_check_eq(this.readString(), null);
} else {
do_check_eq(this.readString(), "1111");
}
if (!ril.v5Legacy) {
// AID. Ignore because it's from modem.
this.readInt32();
}
if (fileId == ICC_EF_FDN) {
run_next_test();
}
};
fileId = ICC_EF_ADN;
record.updateADNLike(fileId,
{recordId: 1, alphaId: "test", number: "123456"});
fileId = ICC_EF_FDN;
record.updateADNLike(fileId,
{recordId: 1, alphaId: "test", number: "123456"},
"1111");
});
/**
* Verify ICCRecordHelper.findFreeRecordId.
*/
add_test(function test_find_free_record_id() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let recordHelper = context.ICCRecordHelper;
let buf = context.Buf;
let io = context.ICCIOHelper;
function writeRecord (record) {
// Write data size
buf.writeInt32(record.length * 2);
for (let i = 0; i < record.length; i++) {
pduHelper.writeHexOctet(record[i]);
}
// Write string delimiter
buf.writeStringDelimiter(record.length * 2);
}
io.loadLinearFixedEF = function fakeLoadLinearFixedEF(options) {
// Some random data.
let record = [0x12, 0x34, 0x56, 0x78, 0x90];
options.p1 = 1;
options.totalRecords = 2;
writeRecord(record);
if (options.callback) {
options.callback(options);
}
};
io.loadNextRecord = function fakeLoadNextRecord(options) {
// Unused bytes.
let record = [0xff, 0xff, 0xff, 0xff, 0xff];
options.p1++;
writeRecord(record);
if (options.callback) {
options.callback(options);
}
};
let fileId = 0x0000; // Dummy.
recordHelper.findFreeRecordId(
fileId,
function(recordId) {
do_check_eq(recordId, 2);
run_next_test();
}.bind(this),
function(errorMsg) {
do_print(errorMsg);
do_check_true(false);
run_next_test();
}.bind(this));
});
/**
* Verify ICCRecordHelper.fetchICCRecords.
*/
add_test(function test_fetch_icc_recodes() {
let worker = newWorker();
let context = worker.ContextPool._contexts[0];
let RIL = context.RIL;
let iccRecord = context.ICCRecordHelper;
let simRecord = context.SimRecordHelper;
let ruimRecord = context.RuimRecordHelper;
let fetchTag = 0x00;
simRecord.fetchSimRecords = function() {
fetchTag = 0x01;
};
ruimRecord.fetchRuimRecords = function() {
fetchTag = 0x02;
};
RIL.appType = CARD_APPTYPE_SIM;
iccRecord.fetchICCRecords();
do_check_eq(fetchTag, 0x01);
RIL.appType = CARD_APPTYPE_RUIM;
iccRecord.fetchICCRecords();
do_check_eq(fetchTag, 0x02);
RIL.appType = CARD_APPTYPE_USIM;
iccRecord.fetchICCRecords();
do_check_eq(fetchTag, 0x01);
run_next_test();
});
/**
* Verify reading EF_ICCID.
*/
add_test(function test_handling_iccid() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let record = context.ICCRecordHelper;
let helper = context.GsmPDUHelper;
let ril = context.RIL;
let buf = context.Buf;
let io = context.ICCIOHelper;
ril.reportStkServiceIsRunning = function fakeReportStkServiceIsRunning() {
};
function do_test(rawICCID, expectedICCID) {
io.loadTransparentEF = function fakeLoadTransparentEF(options) {
// Write data size
buf.writeInt32(rawICCID.length);
// Write data
for (let i = 0; i < rawICCID.length; i += 2) {
helper.writeHexOctet(parseInt(rawICCID.substr(i, 2), 16));
}
// Write string delimiter
buf.writeStringDelimiter(rawICCID.length);
if (options.callback) {
options.callback(options);
}
};
record.readICCID();
do_check_eq(ril.iccInfo.iccid, expectedICCID);
}
// Invalid char at high nibbile + low nibbile contains 0xF.
do_test("9868002E90909F001519", "89860020909");
// Invalid char at low nibbile.
do_test("986800E2909090001519", "8986002090909005191");
// Valid ICCID.
do_test("98101430121181157002", "89014103211118510720");
run_next_test();
});

View File

@ -0,0 +1,236 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
function run_test() {
run_next_test();
}
/**
* Verify ICCUtilsHelper.isICCServiceAvailable.
*/
add_test(function test_is_icc_service_available() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let ICCUtilsHelper = context.ICCUtilsHelper;
let RIL = context.RIL;
function test_table(sst, geckoService, simEnabled, usimEnabled) {
RIL.iccInfoPrivate.sst = sst;
RIL.appType = CARD_APPTYPE_SIM;
do_check_eq(ICCUtilsHelper.isICCServiceAvailable(geckoService), simEnabled);
RIL.appType = CARD_APPTYPE_USIM;
do_check_eq(ICCUtilsHelper.isICCServiceAvailable(geckoService), usimEnabled);
}
test_table([0x08], "ADN", true, false);
test_table([0x08], "FDN", false, false);
test_table([0x08], "SDN", false, true);
run_next_test();
});
/**
* Verify ICCUtilsHelper.isGsm8BitAlphabet
*/
add_test(function test_is_gsm_8bit_alphabet() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let ICCUtilsHelper = context.ICCUtilsHelper;
const langTable = PDU_NL_LOCKING_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
const langShiftTable = PDU_NL_SINGLE_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
do_check_eq(ICCUtilsHelper.isGsm8BitAlphabet(langTable), true);
do_check_eq(ICCUtilsHelper.isGsm8BitAlphabet(langShiftTable), true);
do_check_eq(ICCUtilsHelper.isGsm8BitAlphabet("\uaaaa"), false);
run_next_test();
});
/**
* Verify ICCUtilsHelper.parsePbrTlvs
*/
add_test(function test_parse_pbr_tlvs() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let buf = context.Buf;
let pbrTlvs = [
{tag: ICC_USIM_TYPE1_TAG,
length: 0x0F,
value: [{tag: ICC_USIM_EFADN_TAG,
length: 0x03,
value: [0x4F, 0x3A, 0x02]},
{tag: ICC_USIM_EFIAP_TAG,
length: 0x03,
value: [0x4F, 0x25, 0x01]},
{tag: ICC_USIM_EFPBC_TAG,
length: 0x03,
value: [0x4F, 0x09, 0x04]}]
},
{tag: ICC_USIM_TYPE2_TAG,
length: 0x05,
value: [{tag: ICC_USIM_EFEMAIL_TAG,
length: 0x03,
value: [0x4F, 0x50, 0x0B]},
{tag: ICC_USIM_EFANR_TAG,
length: 0x03,
value: [0x4F, 0x11, 0x02]},
{tag: ICC_USIM_EFANR_TAG,
length: 0x03,
value: [0x4F, 0x12, 0x03]}]
},
{tag: ICC_USIM_TYPE3_TAG,
length: 0x0A,
value: [{tag: ICC_USIM_EFCCP1_TAG,
length: 0x03,
value: [0x4F, 0x3D, 0x0A]},
{tag: ICC_USIM_EFEXT1_TAG,
length: 0x03,
value: [0x4F, 0x4A, 0x03]}]
},
];
let pbr = context.ICCUtilsHelper.parsePbrTlvs(pbrTlvs);
do_check_eq(pbr.adn.fileId, 0x4F3a);
do_check_eq(pbr.iap.fileId, 0x4F25);
do_check_eq(pbr.pbc.fileId, 0x4F09);
do_check_eq(pbr.email.fileId, 0x4F50);
do_check_eq(pbr.anr0.fileId, 0x4f11);
do_check_eq(pbr.anr1.fileId, 0x4f12);
do_check_eq(pbr.ccp1.fileId, 0x4F3D);
do_check_eq(pbr.ext1.fileId, 0x4F4A);
run_next_test();
});
/**
* Verify MCC and MNC parsing
*/
add_test(function test_mcc_mnc_parsing() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let helper = context.ICCUtilsHelper;
function do_test(imsi, mncLength, expectedMcc, expectedMnc) {
let result = helper.parseMccMncFromImsi(imsi, mncLength);
if (!imsi) {
do_check_eq(result, null);
return;
}
do_check_eq(result.mcc, expectedMcc);
do_check_eq(result.mnc, expectedMnc);
}
// Test the imsi is null.
do_test(null, null, null, null);
// Test MCC is Taiwan
do_test("466923202422409", 0x02, "466", "92");
do_test("466923202422409", 0x03, "466", "923");
do_test("466923202422409", null, "466", "92");
// Test MCC is US
do_test("310260542718417", 0x02, "310", "26");
do_test("310260542718417", 0x03, "310", "260");
do_test("310260542718417", null, "310", "260");
run_next_test();
});
add_test(function test_get_network_name_from_icc() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let RIL = context.RIL;
let ICCUtilsHelper = context.ICCUtilsHelper;
function testGetNetworkNameFromICC(operatorData, expectedResult) {
let result = ICCUtilsHelper.getNetworkNameFromICC(operatorData.mcc,
operatorData.mnc,
operatorData.lac);
if (expectedResult == null) {
do_check_eq(result, expectedResult);
} else {
do_check_eq(result.fullName, expectedResult.longName);
do_check_eq(result.shortName, expectedResult.shortName);
}
}
// Before EF_OPL and EF_PNN have been loaded.
testGetNetworkNameFromICC({mcc: 123, mnc: 456, lac: 0x1000}, null);
testGetNetworkNameFromICC({mcc: 321, mnc: 654, lac: 0x2000}, null);
// Set HPLMN
RIL.iccInfo.mcc = 123;
RIL.iccInfo.mnc = 456;
RIL.voiceRegistrationState = {
cell: {
gsmLocationAreaCode: 0x1000
}
};
RIL.operator = {};
// Set EF_PNN
RIL.iccInfoPrivate = {
PNN: [
{"fullName": "PNN1Long", "shortName": "PNN1Short"},
{"fullName": "PNN2Long", "shortName": "PNN2Short"},
{"fullName": "PNN3Long", "shortName": "PNN3Short"},
{"fullName": "PNN4Long", "shortName": "PNN4Short"}
]
};
// EF_OPL isn't available and current isn't in HPLMN,
testGetNetworkNameFromICC({mcc: 321, mnc: 654, lac: 0x1000}, null);
// EF_OPL isn't available and current is in HPLMN,
// the first record of PNN should be returned.
testGetNetworkNameFromICC({mcc: 123, mnc: 456, lac: 0x1000},
{longName: "PNN1Long", shortName: "PNN1Short"});
// Set EF_OPL
RIL.iccInfoPrivate.OPL = [
{
"mcc": 123,
"mnc": 456,
"lacTacStart": 0,
"lacTacEnd": 0xFFFE,
"pnnRecordId": 4
},
{
"mcc": 321,
"mnc": 654,
"lacTacStart": 0,
"lacTacEnd": 0x0010,
"pnnRecordId": 3
},
{
"mcc": 321,
"mnc": 654,
"lacTacStart": 0x0100,
"lacTacEnd": 0x1010,
"pnnRecordId": 2
}
];
// Both EF_PNN and EF_OPL are presented, and current PLMN is HPLMN,
testGetNetworkNameFromICC({mcc: 123, mnc: 456, lac: 0x1000},
{longName: "PNN4Long", shortName: "PNN4Short"});
// Current PLMN is not HPLMN, and according to LAC, we should get
// the second PNN record.
testGetNetworkNameFromICC({mcc: 321, mnc: 654, lac: 0x1000},
{longName: "PNN2Long", shortName: "PNN2Short"});
// Current PLMN is not HPLMN, and according to LAC, we should get
// the thrid PNN record.
testGetNetworkNameFromICC({mcc: 321, mnc: 654, lac: 0x0001},
{longName: "PNN3Long", shortName: "PNN3Short"});
run_next_test();
});

View File

@ -0,0 +1,489 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
function run_test() {
run_next_test();
}
/**
* Verify reading EF_AD and parsing MCC/MNC
*/
add_test(function test_reading_ad_and_parsing_mcc_mnc() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let record = context.SimRecordHelper;
let helper = context.GsmPDUHelper;
let ril = context.RIL;
let buf = context.Buf;
let io = context.ICCIOHelper;
function do_test(mncLengthInEf, imsi, expectedMcc, expectedMnc) {
ril.iccInfoPrivate.imsi = imsi;
io.loadTransparentEF = function fakeLoadTransparentEF(options) {
let ad = [0x00, 0x00, 0x00];
if (typeof mncLengthInEf === 'number') {
ad.push(mncLengthInEf);
}
// Write data size
buf.writeInt32(ad.length * 2);
// Write data
for (let i = 0; i < ad.length; i++) {
helper.writeHexOctet(ad[i]);
}
// Write string delimiter
buf.writeStringDelimiter(ad.length * 2);
if (options.callback) {
options.callback(options);
}
};
record.readAD();
do_check_eq(ril.iccInfo.mcc, expectedMcc);
do_check_eq(ril.iccInfo.mnc, expectedMnc);
}
do_test(undefined, "466923202422409", "466", "92" );
do_test(0x00, "466923202422409", "466", "92" );
do_test(0x01, "466923202422409", "466", "92" );
do_test(0x02, "466923202422409", "466", "92" );
do_test(0x03, "466923202422409", "466", "923");
do_test(0x04, "466923202422409", "466", "92" );
do_test(0xff, "466923202422409", "466", "92" );
do_test(undefined, "310260542718417", "310", "260");
do_test(0x00, "310260542718417", "310", "260");
do_test(0x01, "310260542718417", "310", "260");
do_test(0x02, "310260542718417", "310", "26" );
do_test(0x03, "310260542718417", "310", "260");
do_test(0x04, "310260542718417", "310", "260");
do_test(0xff, "310260542718417", "310", "260");
run_next_test();
});
add_test(function test_reading_optional_efs() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let record = context.SimRecordHelper;
let gsmPdu = context.GsmPDUHelper;
let ril = context.RIL;
let buf = context.Buf;
let io = context.ICCIOHelper;
function buildSST(supportedEf) {
let sst = [];
let len = supportedEf.length;
for (let i = 0; i < len; i++) {
let index, bitmask, iccService;
if (ril.appType === CARD_APPTYPE_SIM) {
iccService = GECKO_ICC_SERVICES.sim[supportedEf[i]];
iccService -= 1;
index = Math.floor(iccService / 4);
bitmask = 2 << ((iccService % 4) << 1);
} else if (ril.appType === CARD_APPTYPE_USIM){
iccService = GECKO_ICC_SERVICES.usim[supportedEf[i]];
iccService -= 1;
index = Math.floor(iccService / 8);
bitmask = 1 << ((iccService % 8) << 0);
}
if (sst) {
sst[index] |= bitmask;
}
}
return sst;
}
ril.updateCellBroadcastConfig = function fakeUpdateCellBroadcastConfig() {
// Ignore updateCellBroadcastConfig after reading SST
};
function do_test(sst, supportedEf) {
// Clone supportedEf to local array for testing
let testEf = supportedEf.slice(0);
record.readMSISDN = function fakeReadMSISDN() {
testEf.splice(testEf.indexOf("MSISDN"), 1);
};
record.readMBDN = function fakeReadMBDN() {
testEf.splice(testEf.indexOf("MDN"), 1);
};
record.readMWIS = function fakeReadMWIS() {
testEf.splice(testEf.indexOf("MWIS"), 1);
};
io.loadTransparentEF = function fakeLoadTransparentEF(options) {
// Write data size
buf.writeInt32(sst.length * 2);
// Write data
for (let i = 0; i < sst.length; i++) {
gsmPdu.writeHexOctet(sst[i] || 0);
}
// Write string delimiter
buf.writeStringDelimiter(sst.length * 2);
if (options.callback) {
options.callback(options);
}
if (testEf.length !== 0) {
do_print("Un-handled EF: " + JSON.stringify(testEf));
do_check_true(false);
}
};
record.readSST();
}
// TODO: Add all necessary optional EFs eventually
let supportedEf = ["MSISDN", "MDN", "MWIS"];
ril.appType = CARD_APPTYPE_SIM;
do_test(buildSST(supportedEf), supportedEf);
ril.appType = CARD_APPTYPE_USIM;
do_test(buildSST(supportedEf), supportedEf);
run_next_test();
});
/**
* Verify fetchSimRecords.
*/
add_test(function test_fetch_sim_recodes() {
let worker = newWorker();
let context = worker.ContextPool._contexts[0];
let RIL = context.RIL;
let iccRecord = context.ICCRecordHelper;
let simRecord = context.SimRecordHelper;
function testFetchSimRecordes(expectCalled) {
let ifCalled = [];
RIL.getIMSI = function() {
ifCalled.push("getIMSI");
};
simRecord.readAD = function() {
ifCalled.push("readAD");
};
simRecord.readSST = function() {
ifCalled.push("readSST");
};
simRecord.fetchSimRecords();
for (let i = 0; i < expectCalled.length; i++ ) {
if (ifCalled[i] != expectCalled[i]) {
do_print(expectCalled[i] + " is not called.");
do_check_true(false);
}
}
}
let expectCalled = ["getIMSI", "readAD", "readSST"];
testFetchSimRecordes(expectCalled);
run_next_test();
});
/**
* Verify SimRecordHelper.readMWIS
*/
add_test(function test_read_mwis() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let recordHelper = context.SimRecordHelper;
let buf = context.Buf;
let io = context.ICCIOHelper;
let mwisData;
let postedMessage;
worker.postMessage = function fakePostMessage(message) {
postedMessage = message;
};
io.loadLinearFixedEF = function fakeLoadLinearFixedEF(options) {
if (mwisData) {
// Write data size
buf.writeInt32(mwisData.length * 2);
// Write MWIS
for (let i = 0; i < mwisData.length; i++) {
helper.writeHexOctet(mwisData[i]);
}
// Write string delimiter
buf.writeStringDelimiter(mwisData.length * 2);
options.recordSize = mwisData.length;
if (options.callback) {
options.callback(options);
}
} else {
do_print("mwisData[] is not set.");
}
};
function buildMwisData(isActive, msgCount) {
if (msgCount < 0 || msgCount === GECKO_VOICEMAIL_MESSAGE_COUNT_UNKNOWN) {
msgCount = 0;
} else if (msgCount > 255) {
msgCount = 255;
}
mwisData = [ (isActive) ? 0x01 : 0x00,
msgCount,
0xFF, 0xFF, 0xFF ];
}
function do_test(isActive, msgCount) {
buildMwisData(isActive, msgCount);
recordHelper.readMWIS();
do_check_eq("iccmwis", postedMessage.rilMessageType);
do_check_eq(isActive, postedMessage.mwi.active);
do_check_eq((isActive) ? msgCount : 0, postedMessage.mwi.msgCount);
}
do_test(true, GECKO_VOICEMAIL_MESSAGE_COUNT_UNKNOWN);
do_test(true, 1);
do_test(true, 255);
do_test(false, 0);
do_test(false, 255); // Test the corner case when mwi is disable with incorrect msgCount.
run_next_test();
});
/**
* Verify SimRecordHelper.updateMWIS
*/
add_test(function test_update_mwis() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let ril = context.RIL;
ril.appType = CARD_APPTYPE_USIM;
ril.iccInfoPrivate.mwis = [0x00, 0x00, 0x00, 0x00, 0x00];
let recordHelper = context.SimRecordHelper;
let buf = context.Buf;
let ioHelper = context.ICCIOHelper;
let recordSize = ril.iccInfoPrivate.mwis.length;
let recordNum = 1;
ioHelper.updateLinearFixedEF = function(options) {
options.pathId = context.ICCFileHelper.getEFPath(options.fileId);
options.command = ICC_COMMAND_UPDATE_RECORD;
options.p1 = options.recordNumber;
options.p2 = READ_RECORD_ABSOLUTE_MODE;
options.p3 = recordSize;
ril.iccIO(options);
};
function do_test(isActive, count) {
let mwis = ril.iccInfoPrivate.mwis;
let isUpdated = false;
function buildMwisData() {
let result = mwis.slice(0);
result[0] = isActive? (mwis[0] | 0x01) : (mwis[0] & 0xFE);
result[1] = (count === GECKO_VOICEMAIL_MESSAGE_COUNT_UNKNOWN) ? 0 : count;
return result;
}
buf.sendParcel = function() {
isUpdated = true;
// Request Type.
do_check_eq(this.readInt32(), REQUEST_SIM_IO);
// Token : we don't care
this.readInt32();
// command.
do_check_eq(this.readInt32(), ICC_COMMAND_UPDATE_RECORD);
// fileId.
do_check_eq(this.readInt32(), ICC_EF_MWIS);
// pathId.
do_check_eq(this.readString(),
EF_PATH_MF_SIM + ((ril.appType === CARD_APPTYPE_USIM) ? EF_PATH_ADF_USIM : EF_PATH_DF_GSM));
// p1.
do_check_eq(this.readInt32(), recordNum);
// p2.
do_check_eq(this.readInt32(), READ_RECORD_ABSOLUTE_MODE);
// p3.
do_check_eq(this.readInt32(), recordSize);
// data.
let strLen = this.readInt32();
do_check_eq(recordSize * 2, strLen);
let expectedMwis = buildMwisData();
for (let i = 0; i < recordSize; i++) {
do_check_eq(expectedMwis[i], pduHelper.readHexOctet());
}
this.readStringDelimiter(strLen);
// pin2.
do_check_eq(this.readString(), null);
if (!ril.v5Legacy) {
// AID. Ignore because it's from modem.
this.readInt32();
}
};
do_check_false(isUpdated);
recordHelper.updateMWIS({ active: isActive,
msgCount: count });
do_check_true((ril.iccInfoPrivate.mwis) ? isUpdated : !isUpdated);
}
do_test(true, GECKO_VOICEMAIL_MESSAGE_COUNT_UNKNOWN);
do_test(true, 1);
do_test(true, 255);
do_test(false, 0);
// Test if Path ID is correct for SIM.
ril.appType = CARD_APPTYPE_SIM;
do_test(false, 0);
// Test if loadLinearFixedEF() is not invoked in updateMWIS() when
// EF_MWIS is not loaded/available.
delete ril.iccInfoPrivate.mwis;
do_test(false, 0);
run_next_test();
});
/**
* Verify the call flow of receiving Class 2 SMS stored in SIM:
* 1. UNSOLICITED_RESPONSE_NEW_SMS_ON_SIM.
* 2. SimRecordHelper.readSMS().
* 3. sendChromeMessage() with rilMessageType == "sms-received".
*/
add_test(function test_read_new_sms_on_sim() {
// Instead of reusing newUint8Worker defined in this file,
// we define our own worker to fake the methods in WorkerBuffer dynamically.
function newSmsOnSimWorkerHelper() {
let _postedMessage;
let _worker = newWorker({
postRILMessage: function(data) {
},
postMessage: function(message) {
_postedMessage = message;
}
});
_worker.debug = do_print;
return {
get postedMessage() {
return _postedMessage;
},
get worker() {
return _worker;
},
fakeWokerBuffer: function() {
let context = _worker.ContextPool._contexts[0];
let index = 0; // index for read
let buf = [];
context.Buf.writeUint8 = function(value) {
buf.push(value);
};
context.Buf.readUint8 = function() {
return buf[index++];
};
context.Buf.seekIncoming = function(offset) {
index += offset;
};
context.Buf.getReadAvailable = function() {
return buf.length - index;
};
}
};
}
let workerHelper = newSmsOnSimWorkerHelper();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
context.ICCIOHelper.loadLinearFixedEF = function fakeLoadLinearFixedEF(options) {
// SimStatus: Unread, SMSC:+0123456789, Sender: +9876543210, Text: How are you?
let SimSmsPduHex = "0306911032547698040A9189674523010000208062917314080CC8F71D14969741F977FD07"
// In 4.2.25 EF_SMS Short Messages of 3GPP TS 31.102:
// 1. Record length == 176 bytes.
// 2. Any bytes in the record following the TPDU shall be filled with 'FF'.
+ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
+ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
+ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
+ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
workerHelper.fakeWokerBuffer();
context.Buf.writeString(SimSmsPduHex);
options.recordSize = 176; // Record length is fixed to 176 bytes.
if (options.callback) {
options.callback(options);
}
};
function newSmsOnSimParcel() {
let data = new Uint8Array(4 + 4); // Int32List with 1 element.
let offset = 0;
function writeInt(value) {
data[offset++] = value & 0xFF;
data[offset++] = (value >> 8) & 0xFF;
data[offset++] = (value >> 16) & 0xFF;
data[offset++] = (value >> 24) & 0xFF;
}
writeInt(1); // Length of Int32List
writeInt(1); // RecordNum = 1.
return newIncomingParcel(-1,
RESPONSE_TYPE_UNSOLICITED,
UNSOLICITED_RESPONSE_NEW_SMS_ON_SIM,
data);
}
function do_test() {
worker.onRILMessage(0, newSmsOnSimParcel());
let postedMessage = workerHelper.postedMessage;
do_check_eq("sms-received", postedMessage.rilMessageType);
do_check_eq("+0123456789", postedMessage.SMSC);
do_check_eq("+9876543210", postedMessage.sender);
do_check_eq("How are you?", postedMessage.body);
}
do_test();
run_next_test();
});

View File

@ -7,41 +7,8 @@ function run_test() {
run_next_test();
}
function parseMMI(mmi) {
let worker = newWorker({
postRILMessage: function(data) {
// Do nothing
},
postMessage: function(message) {
// Do nothing
}
});
let context = worker.ContextPool._contexts[0];
return context.RIL._parseMMI(mmi);
}
function getWorker() {
let _postedMessage;
let _worker = newWorker({
postRILMessage: function(data) {
},
postMessage: function(message) {
_postedMessage = message;
},
});
return {
get postedMessage() {
return _postedMessage;
},
get worker() {
return _worker;
}
};
}
function testSendMMI(mmi, error) {
let workerhelper = getWorker();
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
@ -56,298 +23,6 @@ function testSendMMI(mmi, error) {
do_check_eq(postedMessage.errorMsg, error);
}
add_test(function test_parseMMI_empty() {
let mmi = parseMMI("");
do_check_null(mmi);
run_next_test();
});
add_test(function test_parseMMI_undefined() {
let mmi = parseMMI();
do_check_null(mmi);
run_next_test();
});
add_test(function test_parseMMI_one_digit_short_code() {
let mmi = parseMMI("1");
do_check_eq(mmi.fullMMI, "1");
do_check_eq(mmi.procedure, undefined);
do_check_eq(mmi.serviceCode, undefined);
do_check_eq(mmi.sia, undefined);
do_check_eq(mmi.sib, undefined);
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, undefined);
run_next_test();
});
add_test(function test_parseMMI_invalid_short_code() {
let mmi = parseMMI("11");
do_check_null(mmi);
run_next_test();
});
add_test(function test_parseMMI_short_code() {
let mmi = parseMMI("21");
do_check_eq(mmi.fullMMI, "21");
do_check_eq(mmi.procedure, undefined);
do_check_eq(mmi.serviceCode, undefined);
do_check_eq(mmi.sia, undefined);
do_check_eq(mmi.sib, undefined);
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, undefined);
run_next_test();
});
add_test(function test_parseMMI_dial_string() {
let mmi = parseMMI("12345");
do_check_null(mmi);
run_next_test();
});
add_test(function test_parseMMI_USSD_without_asterisk_prefix() {
let mmi = parseMMI("123#");
do_check_eq(mmi.fullMMI, "123#");
do_check_eq(mmi.procedure, undefined);
do_check_eq(mmi.serviceCode, undefined);
do_check_eq(mmi.sia, undefined);
do_check_eq(mmi.sib, undefined);
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, undefined);
run_next_test();
});
add_test(function test_parseMMI_USSD() {
let mmi = parseMMI("*123#");
do_check_eq(mmi.fullMMI, "*123#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, undefined);
do_check_eq(mmi.sib, undefined);
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sia() {
let mmi = parseMMI("*123*1#");
do_check_eq(mmi.fullMMI, "*123*1#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, "1");
do_check_eq(mmi.sib, undefined);
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sib() {
let mmi = parseMMI("*123**1#");
do_check_eq(mmi.fullMMI, "*123**1#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, "");
do_check_eq(mmi.sib, "1");
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sic() {
let mmi = parseMMI("*123***1#");
do_check_eq(mmi.fullMMI, "*123***1#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, "");
do_check_eq(mmi.sib, "");
do_check_eq(mmi.sic, "1");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sia_sib() {
let mmi = parseMMI("*123*1*1#");
do_check_eq(mmi.fullMMI, "*123*1*1#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, "1");
do_check_eq(mmi.sib, "1");
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sia_sic() {
let mmi = parseMMI("*123*1**1#");
do_check_eq(mmi.fullMMI, "*123*1**1#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, "1");
do_check_eq(mmi.sib, "");
do_check_eq(mmi.sic, "1");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sib_sic() {
let mmi = parseMMI("*123**1*1#");
do_check_eq(mmi.fullMMI, "*123**1*1#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, "");
do_check_eq(mmi.sib, "1");
do_check_eq(mmi.sic, "1");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_pwd() {
let mmi = parseMMI("*123****1#");
do_check_eq(mmi.fullMMI, "*123****1#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, "");
do_check_eq(mmi.sib, "");
do_check_eq(mmi.sic, "");
do_check_eq(mmi.pwd, "1");
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_dial_number() {
let mmi = parseMMI("*123#345");
do_check_eq(mmi.fullMMI, "*123#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, undefined);
do_check_eq(mmi.sib, undefined);
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "345");
run_next_test();
});
/**
* MMI procedures tests
*/
add_test(function test_parseMMI_activation() {
let mmi = parseMMI("*00*12*34*56#");
do_check_eq(mmi.fullMMI, "*00*12*34*56#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "00");
do_check_eq(mmi.sia, "12");
do_check_eq(mmi.sib, "34");
do_check_eq(mmi.sic, "56");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_deactivation() {
let mmi = parseMMI("#00*12*34*56#");
do_check_eq(mmi.fullMMI, "#00*12*34*56#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_DEACTIVATION);
do_check_eq(mmi.serviceCode, "00");
do_check_eq(mmi.sia, "12");
do_check_eq(mmi.sib, "34");
do_check_eq(mmi.sic, "56");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_interrogation() {
let mmi = parseMMI("*#00*12*34*56#");
do_check_eq(mmi.fullMMI, "*#00*12*34*56#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_INTERROGATION);
do_check_eq(mmi.serviceCode, "00");
do_check_eq(mmi.sia, "12");
do_check_eq(mmi.sib, "34");
do_check_eq(mmi.sic, "56");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_registration() {
let mmi = parseMMI("**00*12*34*56#");
do_check_eq(mmi.fullMMI, "**00*12*34*56#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_REGISTRATION);
do_check_eq(mmi.serviceCode, "00");
do_check_eq(mmi.sia, "12");
do_check_eq(mmi.sib, "34");
do_check_eq(mmi.sic, "56");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_erasure() {
let mmi = parseMMI("##00*12*34*56#");
do_check_eq(mmi.fullMMI, "##00*12*34*56#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ERASURE);
do_check_eq(mmi.serviceCode, "00");
do_check_eq(mmi.sia, "12");
do_check_eq(mmi.sib, "34");
do_check_eq(mmi.sic, "56");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
/**
* sendMMI tests.
*/
@ -371,7 +46,7 @@ add_test(function test_sendMMI_invalid() {
});
add_test(function test_sendMMI_short_code() {
let workerhelper = getWorker();
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
@ -403,151 +78,8 @@ add_test(function test_sendMMI_dial_string() {
run_next_test();
});
function setCallForwardSuccess(mmi) {
let workerhelper = getWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
context.RIL.setCallForward = function fakeSetCallForward(options) {
context.RIL[REQUEST_SET_CALL_FORWARD](0, {
rilRequestError: ERROR_SUCCESS
});
};
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({mmi: mmi});
let postedMessage = workerhelper.postedMessage;
do_check_eq(postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
do_check_true(postedMessage.success);
}
add_test(function test_sendMMI_call_forwarding_activation() {
setCallForwardSuccess("*21*12345*99*10#");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_deactivation() {
setCallForwardSuccess("#21*12345*99*10#");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_interrogation() {
let workerhelper = getWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
context.Buf.readInt32 = function fakeReadUint32() {
return context.Buf.int32Array.pop();
};
context.Buf.readString = function fakeReadString() {
return "+34666222333";
};
context.RIL.queryCallForwardStatus = function fakeQueryCallForward(options) {
context.Buf.int32Array = [
0, // rules.timeSeconds
145, // rules.toa
49, // rules.serviceClass
CALL_FORWARD_REASON_UNCONDITIONAL, // rules.reason
1, // rules.active
1 // rulesLength
];
context.RIL[REQUEST_QUERY_CALL_FORWARD_STATUS](1, {
rilRequestError: ERROR_SUCCESS
});
};
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({mmi: "*#21#"});
let postedMessage = workerhelper.postedMessage;
do_check_eq(postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
do_check_true(postedMessage.success);
do_check_true(Array.isArray(postedMessage.rules));
do_check_eq(postedMessage.rules.length, 1);
do_check_true(postedMessage.rules[0].active);
do_check_eq(postedMessage.rules[0].reason, CALL_FORWARD_REASON_UNCONDITIONAL);
do_check_eq(postedMessage.rules[0].number, "+34666222333");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_interrogation_no_rules() {
let workerhelper = getWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
context.Buf.readInt32 = function fakeReadUint32() {
return 0;
};
context.RIL.queryCallForwardStatus = function fakeQueryCallForward(options) {
context.RIL[REQUEST_QUERY_CALL_FORWARD_STATUS](1, {
rilRequestError: ERROR_SUCCESS
});
};
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({mmi: "*#21#"});
let postedMessage = workerhelper.postedMessage;
do_check_eq(postedMessage.errorMsg, GECKO_ERROR_GENERIC_FAILURE);
do_check_false(postedMessage.success);
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_registration() {
setCallForwardSuccess("**21*12345*99*10#");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_erasure() {
setCallForwardSuccess("##21*12345*99#");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_CFB() {
setCallForwardSuccess("*67*12345*99*10#");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_CFNRy() {
setCallForwardSuccess("*61*12345*99*10#");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_CFNRc() {
setCallForwardSuccess("*62*12345*99*10#");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_CFAll() {
setCallForwardSuccess("*004*12345*99*10#");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_CFAllConditional() {
setCallForwardSuccess("*002*12345*99*10#");
run_next_test();
});
add_test(function test_sendMMI_change_PIN() {
let workerhelper = getWorker();
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
@ -593,7 +125,7 @@ add_test(function test_sendMMI_change_PIN_new_PIN_mismatch() {
});
add_test(function test_sendMMI_change_PIN2() {
let workerhelper = getWorker();
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
@ -639,7 +171,7 @@ add_test(function test_sendMMI_change_PIN2_new_PIN2_mismatch() {
});
add_test(function test_sendMMI_unblock_PIN() {
let workerhelper = getWorker();
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
@ -685,7 +217,7 @@ add_test(function test_sendMMI_unblock_PIN_new_PIN_mismatch() {
});
add_test(function test_sendMMI_unblock_PIN2() {
let workerhelper = getWorker();
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
@ -731,7 +263,7 @@ add_test(function test_sendMMI_unblock_PIN2_new_PIN_mismatch() {
});
add_test(function test_sendMMI_get_IMEI() {
let workerhelper = getWorker();
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
let mmiOptions;
@ -755,7 +287,7 @@ add_test(function test_sendMMI_get_IMEI() {
});
add_test(function test_sendMMI_get_IMEI_error() {
let workerhelper = getWorker();
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
let mmiOptions;
@ -779,7 +311,7 @@ add_test(function test_sendMMI_get_IMEI_error() {
});
add_test(function test_sendMMI_call_barring_BAIC_interrogation_voice() {
let workerhelper = getWorker();
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
@ -810,7 +342,7 @@ add_test(function test_sendMMI_call_barring_BAIC_interrogation_voice() {
});
add_test(function test_sendMMI_call_barring_BAIC_activation() {
let workerhelper = getWorker();
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
let mmiOptions;
@ -838,7 +370,7 @@ add_test(function test_sendMMI_call_barring_BAIC_activation() {
});
add_test(function test_sendMMI_call_barring_BAIC_deactivation() {
let workerhelper = getWorker();
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
let mmiOptions;
@ -872,7 +404,7 @@ add_test(function test_sendMMI_call_barring_BAIC_procedure_not_supported() {
});
add_test(function test_sendMMI_USSD() {
let workerhelper = getWorker();
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
let ussdOptions;
@ -898,7 +430,7 @@ add_test(function test_sendMMI_USSD() {
});
add_test(function test_sendMMI_USSD_error() {
let workerhelper = getWorker();
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
let ussdOptions;
@ -924,7 +456,7 @@ add_test(function test_sendMMI_USSD_error() {
});
function setCallWaitingSuccess(mmi) {
let workerhelper = getWorker();
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
@ -968,7 +500,7 @@ add_test(function test_sendMMI_call_waiting_erasure() {
});
add_test(function test_sendMMI_call_waiting_interrogation() {
let workerhelper = getWorker();
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];

View File

@ -0,0 +1,151 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
function run_test() {
run_next_test();
}
function setCallForwardSuccess(mmi) {
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
context.RIL.setCallForward = function fakeSetCallForward(options) {
context.RIL[REQUEST_SET_CALL_FORWARD](0, {
rilRequestError: ERROR_SUCCESS
});
};
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({mmi: mmi});
let postedMessage = workerhelper.postedMessage;
do_check_eq(postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
do_check_true(postedMessage.success);
}
add_test(function test_sendMMI_call_forwarding_activation() {
setCallForwardSuccess("*21*12345*99*10#");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_deactivation() {
setCallForwardSuccess("#21*12345*99*10#");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_interrogation() {
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
context.Buf.readInt32 = function fakeReadUint32() {
return context.Buf.int32Array.pop();
};
context.Buf.readString = function fakeReadString() {
return "+34666222333";
};
context.RIL.queryCallForwardStatus = function fakeQueryCallForward(options) {
context.Buf.int32Array = [
0, // rules.timeSeconds
145, // rules.toa
49, // rules.serviceClass
CALL_FORWARD_REASON_UNCONDITIONAL, // rules.reason
1, // rules.active
1 // rulesLength
];
context.RIL[REQUEST_QUERY_CALL_FORWARD_STATUS](1, {
rilRequestError: ERROR_SUCCESS
});
};
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({mmi: "*#21#"});
let postedMessage = workerhelper.postedMessage;
do_check_eq(postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
do_check_true(postedMessage.success);
do_check_true(Array.isArray(postedMessage.rules));
do_check_eq(postedMessage.rules.length, 1);
do_check_true(postedMessage.rules[0].active);
do_check_eq(postedMessage.rules[0].reason, CALL_FORWARD_REASON_UNCONDITIONAL);
do_check_eq(postedMessage.rules[0].number, "+34666222333");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_interrogation_no_rules() {
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
context.Buf.readInt32 = function fakeReadUint32() {
return 0;
};
context.RIL.queryCallForwardStatus = function fakeQueryCallForward(options) {
context.RIL[REQUEST_QUERY_CALL_FORWARD_STATUS](1, {
rilRequestError: ERROR_SUCCESS
});
};
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({mmi: "*#21#"});
let postedMessage = workerhelper.postedMessage;
do_check_eq(postedMessage.errorMsg, GECKO_ERROR_GENERIC_FAILURE);
do_check_false(postedMessage.success);
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_registration() {
setCallForwardSuccess("**21*12345*99*10#");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_erasure() {
setCallForwardSuccess("##21*12345*99#");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_CFB() {
setCallForwardSuccess("*67*12345*99*10#");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_CFNRy() {
setCallForwardSuccess("*61*12345*99*10#");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_CFNRc() {
setCallForwardSuccess("*62*12345*99*10#");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_CFAll() {
setCallForwardSuccess("*004*12345*99*10#");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_CFAllConditional() {
setCallForwardSuccess("*002*12345*99*10#");
run_next_test();
});

View File

@ -0,0 +1,317 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
function run_test() {
run_next_test();
}
let worker;
function parseMMI(mmi) {
if (!worker) {
worker = newWorker({
postRILMessage: function(data) {
// Do nothing
},
postMessage: function(message) {
// Do nothing
}
});
}
let context = worker.ContextPool._contexts[0];
return context.RIL._parseMMI(mmi);
}
add_test(function test_parseMMI_empty() {
let mmi = parseMMI("");
do_check_null(mmi);
run_next_test();
});
add_test(function test_parseMMI_undefined() {
let mmi = parseMMI();
do_check_null(mmi);
run_next_test();
});
add_test(function test_parseMMI_one_digit_short_code() {
let mmi = parseMMI("1");
do_check_eq(mmi.fullMMI, "1");
do_check_eq(mmi.procedure, undefined);
do_check_eq(mmi.serviceCode, undefined);
do_check_eq(mmi.sia, undefined);
do_check_eq(mmi.sib, undefined);
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, undefined);
run_next_test();
});
add_test(function test_parseMMI_invalid_short_code() {
let mmi = parseMMI("11");
do_check_null(mmi);
run_next_test();
});
add_test(function test_parseMMI_short_code() {
let mmi = parseMMI("21");
do_check_eq(mmi.fullMMI, "21");
do_check_eq(mmi.procedure, undefined);
do_check_eq(mmi.serviceCode, undefined);
do_check_eq(mmi.sia, undefined);
do_check_eq(mmi.sib, undefined);
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, undefined);
run_next_test();
});
add_test(function test_parseMMI_dial_string() {
let mmi = parseMMI("12345");
do_check_null(mmi);
run_next_test();
});
add_test(function test_parseMMI_USSD_without_asterisk_prefix() {
let mmi = parseMMI("123#");
do_check_eq(mmi.fullMMI, "123#");
do_check_eq(mmi.procedure, undefined);
do_check_eq(mmi.serviceCode, undefined);
do_check_eq(mmi.sia, undefined);
do_check_eq(mmi.sib, undefined);
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, undefined);
run_next_test();
});
add_test(function test_parseMMI_USSD() {
let mmi = parseMMI("*123#");
do_check_eq(mmi.fullMMI, "*123#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, undefined);
do_check_eq(mmi.sib, undefined);
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sia() {
let mmi = parseMMI("*123*1#");
do_check_eq(mmi.fullMMI, "*123*1#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, "1");
do_check_eq(mmi.sib, undefined);
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sib() {
let mmi = parseMMI("*123**1#");
do_check_eq(mmi.fullMMI, "*123**1#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, "");
do_check_eq(mmi.sib, "1");
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sic() {
let mmi = parseMMI("*123***1#");
do_check_eq(mmi.fullMMI, "*123***1#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, "");
do_check_eq(mmi.sib, "");
do_check_eq(mmi.sic, "1");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sia_sib() {
let mmi = parseMMI("*123*1*1#");
do_check_eq(mmi.fullMMI, "*123*1*1#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, "1");
do_check_eq(mmi.sib, "1");
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sia_sic() {
let mmi = parseMMI("*123*1**1#");
do_check_eq(mmi.fullMMI, "*123*1**1#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, "1");
do_check_eq(mmi.sib, "");
do_check_eq(mmi.sic, "1");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sib_sic() {
let mmi = parseMMI("*123**1*1#");
do_check_eq(mmi.fullMMI, "*123**1*1#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, "");
do_check_eq(mmi.sib, "1");
do_check_eq(mmi.sic, "1");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_pwd() {
let mmi = parseMMI("*123****1#");
do_check_eq(mmi.fullMMI, "*123****1#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, "");
do_check_eq(mmi.sib, "");
do_check_eq(mmi.sic, "");
do_check_eq(mmi.pwd, "1");
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_dial_number() {
let mmi = parseMMI("*123#345");
do_check_eq(mmi.fullMMI, "*123#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, undefined);
do_check_eq(mmi.sib, undefined);
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "345");
run_next_test();
});
/**
* MMI procedures tests
*/
add_test(function test_parseMMI_activation() {
let mmi = parseMMI("*00*12*34*56#");
do_check_eq(mmi.fullMMI, "*00*12*34*56#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "00");
do_check_eq(mmi.sia, "12");
do_check_eq(mmi.sib, "34");
do_check_eq(mmi.sic, "56");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_deactivation() {
let mmi = parseMMI("#00*12*34*56#");
do_check_eq(mmi.fullMMI, "#00*12*34*56#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_DEACTIVATION);
do_check_eq(mmi.serviceCode, "00");
do_check_eq(mmi.sia, "12");
do_check_eq(mmi.sib, "34");
do_check_eq(mmi.sic, "56");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_interrogation() {
let mmi = parseMMI("*#00*12*34*56#");
do_check_eq(mmi.fullMMI, "*#00*12*34*56#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_INTERROGATION);
do_check_eq(mmi.serviceCode, "00");
do_check_eq(mmi.sia, "12");
do_check_eq(mmi.sib, "34");
do_check_eq(mmi.sic, "56");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_registration() {
let mmi = parseMMI("**00*12*34*56#");
do_check_eq(mmi.fullMMI, "**00*12*34*56#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_REGISTRATION);
do_check_eq(mmi.serviceCode, "00");
do_check_eq(mmi.sia, "12");
do_check_eq(mmi.sib, "34");
do_check_eq(mmi.sic, "56");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_erasure() {
let mmi = parseMMI("##00*12*34*56#");
do_check_eq(mmi.fullMMI, "##00*12*34*56#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ERASURE);
do_check_eq(mmi.serviceCode, "00");
do_check_eq(mmi.sia, "12");
do_check_eq(mmi.sib, "34");
do_check_eq(mmi.sic, "56");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});

View File

@ -7,32 +7,6 @@ function run_test() {
run_next_test();
}
/**
* Helper function.
*/
function newUint8Worker() {
let worker = newWorker();
let context = worker.ContextPool._contexts[0];
let index = 0; // index for read
let buf = [];
context.Buf.writeUint8 = function(value) {
buf.push(value);
};
context.Buf.readUint8 = function() {
return buf[index++];
};
context.Buf.seekIncoming = function(offset) {
index += offset;
};
worker.debug = do_print;
return worker;
}
/**
* Verify RUIM Service.
*/

View File

@ -7,25 +7,6 @@ function run_test() {
run_next_test();
}
function _getWorker() {
let _postedMessage;
let _worker = newWorker({
postRILMessage: function(data) {
},
postMessage: function(message) {
_postedMessage = message;
}
});
return {
get postedMessage() {
return _postedMessage;
},
get worker() {
return _worker;
}
};
}
/*
* Helper function to covert a HEX string to a byte array.
*
@ -188,7 +169,7 @@ function pduToParcelData(cdmaPduHelper, pdu) {
* Verify CDMA SMS Delivery ACK Message.
*/
add_test(function test_processCdmaSmsStatusReport() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
@ -262,7 +243,7 @@ add_test(function test_processCdmaSmsStatusReport() {
* Verify WAP Push over CDMA SMS Message.
*/
add_test(function test_processCdmaSmsWapPush() {
let workerHelper = _getWorker(),
let workerHelper = newInterceptWorker(),
worker = workerHelper.worker,
context = worker.ContextPool._contexts[0],
bitBufferHelper = context.BitBufferHelper,

View File

@ -7,27 +7,8 @@ function run_test() {
run_next_test();
}
function _getWorker() {
let _postedMessage;
let _worker = newWorker({
postRILMessage: function(data) {
},
postMessage: function(message) {
_postedMessage = message;
}
});
return {
get postedMessage() {
return _postedMessage;
},
get worker() {
return _worker;
}
};
}
add_test(function test_notification() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];

View File

@ -10,29 +10,6 @@ function run_test() {
/**
* Helper function.
*/
function newUint8Worker() {
let worker = newWorker();
let index = 0; // index for read
let buf = [];
let context = worker.ContextPool._contexts[0];
context.Buf.writeUint8 = function(value) {
buf.push(value);
};
context.Buf.readUint8 = function() {
return buf[index++];
};
context.Buf.seekIncoming = function(offset) {
index += offset;
};
worker.debug = do_print;
return worker;
}
function newUint8SupportOutgoingIndexWorker() {
let worker = newWorker();
let index = 4; // index for read

View File

@ -7,27 +7,8 @@ function run_test() {
run_next_test();
}
function _getWorker() {
let _postedMessage;
let _worker = newWorker({
postRILMessage: function(data) {
},
postMessage: function(message) {
_postedMessage = message;
}
});
return {
get postedMessage() {
return _postedMessage;
},
get worker() {
return _worker;
}
};
}
add_test(function test_setVoicePrivacyMode_success() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
@ -49,7 +30,7 @@ add_test(function test_setVoicePrivacyMode_success() {
});
add_test(function test_setVoicePrivacyMode_generic_failure() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
@ -71,7 +52,7 @@ add_test(function test_setVoicePrivacyMode_generic_failure() {
});
add_test(function test_queryVoicePrivacyMode_success_enabled_true() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
@ -95,7 +76,7 @@ add_test(function test_queryVoicePrivacyMode_success_enabled_true() {
});
add_test(function test_queryVoicePrivacyMode_success_enabled_false() {
let workerHelper = _getWorker();
let workerHelper = newInterceptWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];

View File

@ -3,7 +3,15 @@ head = header_helpers.js
tail =
[test_ril_worker_buf.js]
[test_ril_worker_icc.js]
[test_ril_worker_icc_CardLock.js]
[test_ril_worker_icc_BerTlvHelper.js]
[test_ril_worker_icc_GsmPDUHelper.js]
[test_ril_worker_icc_ICCContactHelper.js]
[test_ril_worker_icc_ICCIOHelper.js]
[test_ril_worker_icc_ICCPDUHelper.js]
[test_ril_worker_icc_ICCRecordHelper.js]
[test_ril_worker_icc_ICCUtilsHelper.js]
[test_ril_worker_icc_SimRecordHelper.js]
[test_ril_worker_sms.js]
# Bug 916067 - B2G RIL: test_ril_worker_sms.js takes too long to finish
skip-if = true
@ -13,6 +21,8 @@ skip-if = true
[test_ril_worker_sms_gsmpduhelper.js]
[test_ril_worker_sms_segment_info.js]
[test_ril_worker_mmi.js]
[test_ril_worker_mmi_cf.js]
[test_ril_worker_mmi_parseMMI.js]
[test_ril_worker_cf.js]
[test_ril_worker_cellbroadcast_config.js]
[test_ril_worker_cellbroadcast.js]

View File

@ -16,14 +16,28 @@ let emulator = (function() {
// Overwritten it so people could not call this function directly.
runEmulatorCmd = function() {
throw "Use emulator.run(cmd, callback) instead of runEmulatorCmd";
throw "Use emulator.runWithCallback(cmd, callback) instead of runEmulatorCmd";
};
function run(cmd, callback) {
function run(cmd) {
let deferred = Promise.defer();
pendingCmdCount++;
originalRunEmulatorCmd(cmd, function(result) {
is(result[result.length - 1], "OK", "emulator command should be OK.");
pendingCmdCount--;
if (result[result.length - 1] === "OK") {
deferred.resolve(result);
} else {
is(result[result.length - 1], "OK", "emulator command result.");
deferred.reject();
}
});
return deferred.promise;
}
function runWithCallback(cmd, callback) {
run(cmd).then(result => {
if (callback && typeof callback === "function") {
callback(result);
}
@ -47,6 +61,7 @@ let emulator = (function() {
return {
run: run,
runWithCallback: runWithCallback,
waitFinish: waitFinish
};
}());
@ -75,26 +90,26 @@ let emulator = (function() {
/**
* @return Promise
*/
function clearCalls() {
function waitForNoCall() {
let deferred = Promise.defer();
log("Clear existing calls.");
emulator.run("gsm clear", function(result) {
if (result[0] == "OK") {
waitFor(function() {
deferred.resolve();
}, function() {
return telephony.calls.length === 0;
});
} else {
log("Failed to clear existing calls.");
deferred.reject();
}
waitFor(function() {
deferred.resolve();
}, function() {
return telephony.calls.length === 0;
});
return deferred.promise;
}
/**
* @return Promise
*/
function clearCalls() {
log("Clear existing calls.");
return emulator.run("gsm clear").then(waitForNoCall);
}
/**
* Provide a string with format of the emulator call list result.
*
@ -328,18 +343,12 @@ let emulator = (function() {
* @return A deferred promise.
*/
function checkEmulatorCallList(expectedCallList) {
let deferred = Promise.defer();
emulator.run("gsm list", function(result) {
log("Call list is now: " + result);
for (let i = 0; i < expectedCallList.length; ++i) {
is(result[i], expectedCallList[i], "emulator calllist");
}
is(result[expectedCallList.length], "OK", "emulator calllist");
deferred.resolve();
});
return deferred.promise;
return emulator.run("gsm list").then(result => {
log("Call list is now: " + result);
for (let i = 0; i < expectedCallList.length; ++i) {
is(result[i], expectedCallList[i], "emulator calllist");
}
});
}
/**

View File

@ -31,7 +31,7 @@ function answer() {
return(callDuration >= 2000);
});
};
emulator.run("gsm accept " + outNumber);
emulator.runWithCallback("gsm accept " + outNumber);
}
function cleanUp(){

View File

@ -7,7 +7,7 @@ MARIONETTE_HEAD_JS = 'head.js';
function muxModem(id) {
let deferred = Promise.defer();
emulator.run("mux modem " + id, function() {
emulator.runWithCallback("mux modem " + id, function() {
deferred.resolve();
});

View File

@ -7,7 +7,7 @@ MARIONETTE_HEAD_JS = 'head.js';
function muxModem(id) {
let deferred = Promise.defer();
emulator.run("mux modem " + id, function() {
emulator.runWithCallback("mux modem " + id, function() {
deferred.resolve();
});

View File

@ -28,10 +28,9 @@ function dial() {
is(outgoing.state, "alerting");
is(outgoing.emergency, true);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + number + " : ringing");
is(result[1], "OK");
answer();
});
};
@ -50,14 +49,13 @@ function answer() {
is(outgoing, telephony.active);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + number + " : active");
is(result[1], "OK");
hangUp();
});
};
emulator.run("gsm accept " + number);
emulator.runWithCallback("gsm accept " + number);
}
function hangUp() {
@ -73,13 +71,12 @@ function hangUp() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};
emulator.run("gsm cancel " + number);
emulator.runWithCallback("gsm cancel " + number);
}
function cleanUp() {

View File

@ -16,9 +16,8 @@ function dial() {
is(telephony.calls.length, 0);
is(cause, "BadNumberError");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Initial call list: " + result);
is(result[0], "OK");
cleanUp();
});
});

View File

@ -27,10 +27,9 @@ function dial() {
is(outgoingCall, event.call);
is(outgoingCall.state, "alerting");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : ringing");
is(result[1], "OK");
answer();
});
};
@ -48,10 +47,9 @@ function answer() {
is(outgoingCall.state, "connected");
is(outgoingCall, telephony.active);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : active");
is(result[1], "OK");
if(!gotOriginalConnected){
gotOriginalConnected = true;
@ -63,7 +61,7 @@ function answer() {
}
});
};
emulator.run("gsm accept " + outNumber);
emulator.runWithCallback("gsm accept " + outNumber);
}
// With one connected call already, simulate an incoming call
@ -82,15 +80,14 @@ function simulateIncoming() {
is(telephony.calls[0], outgoingCall);
is(telephony.calls[1], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : active");
is(result[1], "inbound from " + inNumber + " : incoming");
is(result[2], "OK");
answerIncoming();
});
};
emulator.run("gsm call " + inNumber);
emulator.runWithCallback("gsm call " + inNumber);
}
// Answer incoming call; original outgoing call should be held
@ -114,11 +111,10 @@ function answerIncoming() {
is(incomingCall, telephony.active);
is(outgoingCall.state, "held");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : held");
is(result[1], "inbound from " + inNumber + " : active");
is(result[2], "OK");
hangUpOutgoing();
});
};
@ -147,10 +143,9 @@ function hangUpOutgoing() {
is(telephony.calls.length, 1);
is(incomingCall.state, "connected");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : active");
is(result[1], "OK");
hangUpIncoming();
});
};
@ -179,9 +174,8 @@ function hangUpIncoming() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};

View File

@ -27,10 +27,9 @@ function dial() {
is(outgoingCall, event.call);
is(outgoingCall.state, "alerting");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : ringing");
is(result[1], "OK");
answer();
});
};
@ -48,10 +47,9 @@ function answer() {
is(outgoingCall.state, "connected");
is(outgoingCall, telephony.active);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : active");
is(result[1], "OK");
if(!gotOriginalConnected){
gotOriginalConnected = true;
@ -63,7 +61,7 @@ function answer() {
}
});
};
emulator.run("gsm accept " + outNumber);
emulator.runWithCallback("gsm accept " + outNumber);
}
function holdCall() {
@ -87,10 +85,9 @@ function holdCall() {
is(telephony.calls.length, 1);
is(telephony.calls[0], outgoingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : held");
is(result[1], "OK");
simulateIncoming();
});
};
@ -113,15 +110,14 @@ function simulateIncoming() {
is(telephony.calls[0], outgoingCall);
is(telephony.calls[1], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : held");
is(result[1], "inbound from " + inNumber + " : incoming");
is(result[2], "OK");
answerIncoming();
});
};
emulator.run("gsm call " + inNumber);
emulator.runWithCallback("gsm call " + inNumber);
}
// Answer incoming call; original outgoing call should be held
@ -145,11 +141,10 @@ function answerIncoming() {
is(incomingCall, telephony.active);
is(outgoingCall.state, "held");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : held");
is(result[1], "inbound from " + inNumber + " : active");
is(result[2], "OK");
hangUpOutgoing();
});
};
@ -178,10 +173,9 @@ function hangUpOutgoing() {
is(telephony.calls.length, 1);
is(incomingCall.state, "connected");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : active");
is(result[1], "OK");
hangUpIncoming();
});
};
@ -210,9 +204,8 @@ function hangUpIncoming() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};

View File

@ -22,14 +22,13 @@ function simulateIncoming() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incoming);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + number + " : incoming");
is(result[1], "OK");
answer();
});
};
emulator.run("gsm call " + number);
emulator.runWithCallback("gsm call " + number);
}
function answer() {
@ -51,10 +50,9 @@ function answer() {
is(incoming, telephony.active);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + number + " : active");
is(result[1], "OK");
hangUp();
});
};
@ -81,9 +79,8 @@ function hangUp() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};

View File

@ -28,15 +28,14 @@ function simulateIncoming() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incoming);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + number + " : incoming");
is(result[1], "OK");
answer();
});
};
emulator.run("gsm call " + number);
emulator.runWithCallback("gsm call " + number);
}
function answer() {
@ -61,10 +60,9 @@ function answer() {
is(incoming, telephony.active);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + number + " : active");
is(result[1], "OK");
hangUp();
});
};
@ -111,9 +109,8 @@ function hangUp() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};

View File

@ -20,14 +20,13 @@ function simulateIncoming() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : incoming");
is(result[1], "OK");
answerIncoming();
});
};
emulator.run("gsm call " + inNumber);
emulator.runWithCallback("gsm call " + inNumber);
}
function answerIncoming() {
@ -49,10 +48,9 @@ function answerIncoming() {
is(incomingCall, telephony.active);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : active");
is(result[1], "OK");
remoteHangUp();
});
};
@ -72,13 +70,12 @@ function remoteHangUp() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};
emulator.run("gsm cancel " + inNumber);
emulator.runWithCallback("gsm cancel " + inNumber);
}
function cleanUp() {

View File

@ -20,14 +20,13 @@ function simulateIncoming() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : incoming");
is(result[1], "OK");
answerIncoming();
});
};
emulator.run("gsm call " + inNumber);
emulator.runWithCallback("gsm call " + inNumber);
}
function answerIncoming() {
@ -78,9 +77,8 @@ function hangUp() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};

View File

@ -20,14 +20,13 @@ function simulateIncoming() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : incoming");
is(result[1], "OK");
answerIncoming();
});
};
emulator.run("gsm call " + inNumber);
emulator.runWithCallback("gsm call " + inNumber);
}
function answerIncoming() {
@ -60,13 +59,12 @@ function remoteHangUp() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};
emulator.run("gsm cancel " + inNumber);
emulator.runWithCallback("gsm cancel " + inNumber);
}
function cleanUp() {

View File

@ -20,14 +20,13 @@ function simulateIncoming() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : incoming");
is(result[1], "OK");
answerIncoming();
});
};
emulator.run("gsm call " + inNumber);
emulator.runWithCallback("gsm call " + inNumber);
}
function answerIncoming() {
@ -49,10 +48,9 @@ function answerIncoming() {
is(incomingCall, telephony.active);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : active");
is(result[1], "OK");
hold();
});
};
@ -80,10 +78,9 @@ function hold() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : held");
is(result[1], "OK");
hangUp();
});
};
@ -110,9 +107,8 @@ function hangUp() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};

View File

@ -21,14 +21,13 @@ function simulateIncoming() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + number + " : incoming");
is(result[1], "OK");
answer();
});
};
emulator.run("gsm call " + number);
emulator.runWithCallback("gsm call " + number);
}
function answer() {
@ -50,10 +49,9 @@ function answer() {
is(incomingCall, telephony.active);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + number + " : active");
is(result[1], "OK");
hold();
});
};
@ -81,10 +79,9 @@ function hold() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + number + " : held");
is(result[1], "OK");
// Wait on hold for a couple of seconds
log("Pausing 2 seconds while on hold");
setTimeout(resume, 2000);
@ -114,10 +111,9 @@ function resume() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + number + " : active");
is(result[1], "OK");
hangUp();
});
};
@ -144,9 +140,8 @@ function hangUp() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};

View File

@ -20,14 +20,13 @@ function simulateIncoming() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : incoming");
is(result[1], "OK");
answerIncoming();
});
};
emulator.run("gsm call " + inNumber);
emulator.runWithCallback("gsm call " + inNumber);
}
function answerIncoming() {
@ -46,10 +45,9 @@ function answerIncoming() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : active");
is(result[1], "OK");
hold();
});
}
@ -73,10 +71,9 @@ function hold() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : held");
is(result[1], "OK");
resume();
});
}
@ -100,10 +97,9 @@ function resume() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : active");
is(result[1], "OK");
hangUp();
});
}
@ -126,9 +122,8 @@ function hangUp() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
}

View File

@ -22,14 +22,13 @@ function simulateIncoming() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incoming);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + number + " : incoming");
is(result[1], "OK");
reject();
});
};
emulator.run("gsm call " + number);
emulator.runWithCallback("gsm call " + number);
}
function reject() {
@ -52,9 +51,8 @@ function reject() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};

View File

@ -20,14 +20,13 @@ function simulateIncoming() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : incoming");
is(result[1], "OK");
cancelIncoming();
});
};
emulator.run("gsm call " + inNumber);
emulator.runWithCallback("gsm call " + inNumber);
}
function cancelIncoming(){
@ -43,13 +42,12 @@ function cancelIncoming(){
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};
emulator.run("gsm cancel " + inNumber);
emulator.runWithCallback("gsm cancel " + inNumber);
}
function cleanUp() {

View File

@ -20,14 +20,13 @@ function simulateIncoming() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : incoming");
is(result[1], "OK");
answerIncoming();
});
};
emulator.run("gsm call " + inNumber);
emulator.runWithCallback("gsm call " + inNumber);
}
function answerIncoming() {
@ -49,10 +48,9 @@ function answerIncoming() {
is(incomingCall, telephony.active);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : active");
is(result[1], "OK");
hold();
});
};
@ -80,10 +78,9 @@ function hold() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : held");
is(result[1], "OK");
hangUp();
});
};
@ -103,13 +100,12 @@ function hangUp() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};
emulator.run("gsm cancel " + inNumber);
emulator.runWithCallback("gsm cancel " + inNumber);
}
function cleanUp() {

View File

@ -22,14 +22,13 @@ function simulateIncoming() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : incoming");
is(result[1], "OK");
answerIncoming();
});
};
emulator.run("gsm call " + inNumber);
emulator.runWithCallback("gsm call " + inNumber);
}
function answerIncoming() {
@ -50,10 +49,9 @@ function answerIncoming() {
ok(gotConnecting);
is(incomingCall, telephony.active);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : active");
is(result[1], "OK");
holdCall();
});
};
@ -82,10 +80,9 @@ function holdCall() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : held");
is(result[1], "OK");
dial();
});
};
@ -111,11 +108,10 @@ function dial() {
is(outgoingCall, event.call);
is(outgoingCall.state, "alerting");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : held");
is(result[1], "outbound to " + outNumber + " : ringing");
is(result[2], "OK");
answerOutgoing();
});
};
@ -133,15 +129,14 @@ function answerOutgoing() {
is(outgoingCall.state, "connected");
is(outgoingCall, telephony.active);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : held");
is(result[1], "outbound to " + outNumber + " : active");
is(result[2], "OK");
holdSecondCall();
});
};
emulator.run("gsm accept " + outNumber);
emulator.runWithCallback("gsm accept " + outNumber);
}
// With one held call and one active, hold the active one; expect the first
@ -192,11 +187,10 @@ function verifyCalls() {
is(telephony.calls[0], incomingCall);
is(telephony.calls[1], outgoingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : active");
is(result[1], "outbound to " + outNumber + " : held");
is(result[2], "OK");
hangUpIncoming();
});
}
@ -224,10 +218,9 @@ function hangUpIncoming() {
is(telephony.calls.length, 1);
is(telephony.calls[0], outgoingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : held");
is(result[1], "OK");
hangUpOutgoing();
});
};
@ -256,9 +249,8 @@ function hangUpOutgoing() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};

View File

@ -29,17 +29,15 @@ function simulateIncoming() {
};
let rcvdEmulatorCallback = false;
emulator.run("gsm call " + inNumber, function(result) {
is(result[0], "OK", "emulator callback");
emulator.runWithCallback("gsm call " + inNumber, function(result) {
rcvdEmulatorCallback = true;
});
}
function verifyCallList(){
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : incoming");
is(result[1], "OK");
answerIncoming();
});
}
@ -63,10 +61,9 @@ function answerIncoming() {
is(incomingCall, telephony.active);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : active");
is(result[1], "OK");
holdCall();
});
};
@ -95,10 +92,9 @@ function holdCall(){
is(telephony.calls.length, 1);
is(telephony.calls[0], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : held");
is(result[1], "OK");
dial();
});
};
@ -125,11 +121,10 @@ function dial() {
is(outgoingCall, event.call);
is(outgoingCall.state, "alerting");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : held");
is(result[1], "outbound to " + outNumber + " : ringing");
is(result[2], "OK");
answerOutgoing();
});
};
@ -155,18 +150,16 @@ function answerOutgoing() {
};
let rcvdEmulatorCallback = false;
emulator.run("gsm accept " + outNumber, function(result) {
is(result[0], "OK", "emulator callback");
emulator.runWithCallback("gsm accept " + outNumber, function(result) {
rcvdEmulatorCallback = true;
});
}
function checkCallList(){
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : held");
is(result[1], "outbound to " + outNumber + " : active");
is(result[2], "OK");
hangUpIncoming();
});
}
@ -194,10 +187,9 @@ function hangUpIncoming() {
is(telephony.calls.length, 1);
is(telephony.calls[0], outgoingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : active");
is(result[1], "OK");
hangUpOutgoing();
});
};
@ -226,9 +218,8 @@ function hangUpOutgoing() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};

View File

@ -27,10 +27,9 @@ function dial() {
is(outgoing, event.call);
is(outgoing.state, "alerting");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + number + " : ringing");
is(result[1], "OK");
answer();
});
};
@ -49,14 +48,13 @@ function answer() {
is(outgoing, telephony.active);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + number + " : active");
is(result[1], "OK");
hangUp();
});
};
emulator.run("gsm accept " + number);
emulator.runWithCallback("gsm accept " + number);
}
function hangUp() {
@ -72,13 +70,12 @@ function hangUp() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};
emulator.run("gsm cancel " + number);
emulator.runWithCallback("gsm cancel " + number);
}
function cleanUp() {

View File

@ -46,11 +46,10 @@ function dial() {
}
function checkCallList() {
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
if (((result[0] == "outbound to " + number + " : unknown") ||
(result[0] == "outbound to " + number + " : dialing")) &&
(result[1] == "OK")) {
(result[0] == "outbound to " + number + " : dialing"))) {
answer();
} else {
window.setTimeout(checkCallList, 100);
@ -70,20 +69,19 @@ function answer() {
is(outgoing, telephony.active);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list (after 'connected' event) is now: " + result);
is(result[0], "outbound to " + number + " : active");
is(result[1], "OK");
hangUp();
});
};
emulator.run("gsm accept " + number);
emulator.runWithCallback("gsm accept " + number);
}
function hangUp() {
log("Hanging up the outgoing call.");
emulator.run("gsm cancel " + number);
emulator.runWithCallback("gsm cancel " + number);
}
function cleanUp() {

View File

@ -26,10 +26,9 @@ function dial() {
is(outgoingCall, event.call);
is(outgoingCall.state, "alerting");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : ringing");
is(result[1], "OK");
answer();
});
};
@ -48,14 +47,13 @@ function answer() {
is(outgoingCall, telephony.active);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : active");
is(result[1], "OK");
hangUp();
});
};
emulator.run("gsm accept " + outNumber);
emulator.runWithCallback("gsm accept " + outNumber);
}
function hangUp() {
@ -78,9 +76,8 @@ function hangUp() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};

View File

@ -59,7 +59,7 @@ function remoteAnswer(call) {
is(call.state, "connected");
deferred.resolve(call);
};
emulator.run("gsm accept " + call.id.number);
emulator.runWithCallback("gsm accept " + call.id.number);
return deferred.promise;
}

View File

@ -30,9 +30,8 @@ function dial() {
ok(event.call.error);
is(event.call.error.name, "BadNumberError");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Initial call list: " + result);
is(result[0], "OK");
cleanUp();
});
};

View File

@ -25,10 +25,9 @@ function dial() {
is(outgoing, event.call);
is(outgoing.state, "alerting");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + number + " : ringing");
is(result[1], "OK");
busy();
});
};
@ -43,14 +42,13 @@ function busy() {
is(outgoing, event.call);
is(event.call.error.name, "BusyError");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};
emulator.run("gsm busy " + number);
emulator.runWithCallback("gsm busy " + number);
}
function cleanUp() {

View File

@ -24,10 +24,9 @@ function dial() {
outgoing.onalerting = function onalerting(event) {
log("Received 'alerting' call event.");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + number + " : ringing");
is(result[1], "OK");
hangUp();
});
};
@ -55,9 +54,8 @@ function hangUp() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};

View File

@ -26,10 +26,9 @@ function dial() {
is(outgoing, event.call);
is(outgoing.state, "alerting");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + number + " : ringing");
is(result[1], "OK");
answer();
});
};
@ -48,14 +47,13 @@ function answer() {
is(outgoing, telephony.active);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + number + " : active");
is(result[1], "OK");
hold();
});
};
emulator.run("gsm accept " + number);
emulator.runWithCallback("gsm accept " + number);
}
function hold() {
@ -77,10 +75,9 @@ function hold() {
is(telephony.active, null);
is(telephony.calls.length, 1);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + number + " : held");
is(result[1], "OK");
hangUp();
});
};
@ -107,9 +104,8 @@ function hangUp() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};

View File

@ -26,10 +26,9 @@ function dial() {
is(outgoingCall, event.call);
is(outgoingCall.state, "alerting");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + number + " : ringing");
is(result[1], "OK");
answer();
});
};
@ -48,14 +47,13 @@ function answer() {
is(outgoingCall, telephony.active);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + number + " : active");
is(result[1], "OK");
hold();
});
};
emulator.run("gsm accept " + number);
emulator.runWithCallback("gsm accept " + number);
}
function hold() {
@ -79,10 +77,9 @@ function hold() {
is(telephony.calls.length, 1);
is(telephony.calls[0], outgoingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + number + " : held");
is(result[1], "OK");
// Bug 781604: emulator assertion if outgoing call kept on hold
// Wait on hold for a couple of seconds
//log("Pausing 2 seconds while on hold");
@ -114,10 +111,9 @@ function resume() {
is(telephony.calls.length, 1);
is(telephony.calls[0], outgoingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + number + " : active");
is(result[1], "OK");
hangUp();
});
};
@ -144,9 +140,8 @@ function hangUp() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};

View File

@ -28,10 +28,9 @@ function dial() {
ok(expectedStates.indexOf(event.call.state) != -1);
if (event.call.state == "alerting") {
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : ringing");
is(result[1], "OK");
answer();
});
}
@ -50,14 +49,13 @@ function answer() {
is(outgoingCall.state, "connected");
is(outgoingCall, telephony.active);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : active");
is(result[1], "OK");
hold();
});
};
emulator.run("gsm accept " + outNumber);
emulator.runWithCallback("gsm accept " + outNumber);
}
function hold() {
@ -76,10 +74,9 @@ function hold() {
is(telephony.calls.length, 1);
is(telephony.calls[0], outgoingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : held");
is(result[1], "OK");
resume();
});
}
@ -103,10 +100,9 @@ function resume() {
is(telephony.calls.length, 1);
is(telephony.calls[0], outgoingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : active");
is(result[1], "OK");
hangUp();
});
}
@ -129,9 +125,8 @@ function hangUp() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
}

View File

@ -47,9 +47,8 @@ function dial(number) {
is(telephony.calls.length, 0);
is(cause, "RadioNotAvailable");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Initial call list: " + result);
is(result[0], "OK");
setRadioEnabled(true, cleanUp);
});

View File

@ -25,10 +25,9 @@ function dial() {
is(outgoing, event.call);
is(outgoing.state, "alerting");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + number + " : ringing");
is(result[1], "OK");
reject();
});
};
@ -54,16 +53,14 @@ function reject() {
};
let rcvdEmulatorCallback = false;
emulator.run("gsm cancel " + number, function(result) {
is(result[0], "OK", "emulator callback");
emulator.runWithCallback("gsm cancel " + number, function(result) {
rcvdEmulatorCallback = true;
});
}
function verifyCallList(){
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
}

View File

@ -25,10 +25,9 @@ function dial() {
is(outgoingCall, event.call);
is(outgoingCall.state, "alerting");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : ringing");
is(result[1], "OK");
answer();
});
};
@ -47,14 +46,13 @@ function answer() {
is(outgoingCall, telephony.active);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : active");
is(result[1], "OK");
hold();
});
};
emulator.run("gsm accept " + outNumber);
emulator.runWithCallback("gsm accept " + outNumber);
}
function hold() {
@ -77,10 +75,9 @@ function hold() {
is(telephony.calls.length, 1);
is(telephony.calls[0], outgoingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : held");
is(result[1], "OK");
hangUp();
});
};
@ -100,13 +97,12 @@ function hangUp() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};
emulator.run("gsm cancel " + outNumber);
emulator.runWithCallback("gsm cancel " + outNumber);
}
function cleanUp() {

View File

@ -20,14 +20,13 @@ function simulateIncoming() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : incoming");
is(result[1], "OK");
answerIncoming();
});
};
emulator.run("gsm call " + inNumber);
emulator.runWithCallback("gsm call " + inNumber);
}
function answerIncoming() {
@ -49,10 +48,9 @@ function answerIncoming() {
is(incomingCall, telephony.active);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : active");
is(result[1], "OK");
answerAlreadyConnected();
});
};
@ -102,10 +100,9 @@ function hold() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : held");
is(result[1], "OK");
holdAlreadyHeld();
});
};
@ -179,10 +176,9 @@ function resume() {
is(telephony.calls.length, 1);
is(telephony.calls[0], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : active");
is(result[1], "OK");
resumeNonHeld();
});
};
@ -231,9 +227,8 @@ function hangUp() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
answerDisconnected();
});
};

View File

@ -29,10 +29,9 @@ function dial() {
is(telephony.calls.length, 1);
is(telephony.calls[0], outgoingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : ringing");
is(result[1], "OK");
answer();
});
};
@ -50,10 +49,9 @@ function answer() {
is(outgoingCall.state, "connected");
is(outgoingCall, telephony.active);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : active");
is(result[1], "OK");
if(!gotOriginalConnected){
gotOriginalConnected = true;
@ -65,7 +63,7 @@ function answer() {
}
});
};
emulator.run("gsm accept " + outNumber);
emulator.runWithCallback("gsm accept " + outNumber);
}
function holdCall() {
@ -89,10 +87,9 @@ function holdCall() {
is(telephony.calls.length, 1);
is(telephony.calls[0], outgoingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : held");
is(result[1], "OK");
simulateIncoming();
});
};
@ -115,15 +112,14 @@ function simulateIncoming() {
is(telephony.calls[0], outgoingCall);
is(telephony.calls[1], incomingCall);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : held");
is(result[1], "inbound from " + inNumber + " : incoming");
is(result[2], "OK");
answerIncoming();
});
};
emulator.run("gsm call " + inNumber);
emulator.runWithCallback("gsm call " + inNumber);
}
// Answer incoming call; original outgoing call should be held
@ -149,11 +145,10 @@ function answerIncoming() {
is(outgoingCall.state, "held");
is(incomingCall.state, "connected");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : held");
is(result[1], "inbound from " + inNumber + " : active");
is(result[2], "OK");
swapCalls();
});
};
@ -203,7 +198,7 @@ function verifySwap() {
is(outgoingCall.state, "connected");
is(incomingCall.state, "held");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "outbound to " + outNumber + " : active");
is(result[1], "inbound from " + inNumber + " : held");
@ -235,10 +230,9 @@ function hangUpOutgoing() {
is(telephony.calls.length, 1);
is(incomingCall.state, "held");
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "inbound from " + inNumber + " : held");
is(result[1], "OK");
hangUpIncoming();
});
};
@ -267,9 +261,8 @@ function hangUpIncoming() {
is(telephony.active, null);
is(telephony.calls.length, 0);
emulator.run("gsm list", function(result) {
emulator.runWithCallback("gsm list", function(result) {
log("Call list is now: " + result);
is(result[0], "OK");
cleanUp();
});
};

View File

@ -630,7 +630,7 @@ var WifiManager = (function() {
if (!dhcpInfo) {
if (++manager.dhcpFailuresCount >= MAX_RETRIES_ON_DHCP_FAILURE) {
manager.dhcpFailuresCount = 0;
notify("disconnected", {ssid: manager.connectionInfo.ssid});
notify("disconnected", {connectionInfo: manager.connectionInfo});
return;
}
// NB: We have to call disconnect first. Otherwise, we only reauth with
@ -658,7 +658,7 @@ var WifiManager = (function() {
var driverEventMap = { STOPPED: "driverstopped", STARTED: "driverstarted", HANGED: "driverhung" };
manager.getCurrentNetworkId = function (ssid, callback) {
manager.getNetworkId = function (ssid, callback) {
manager.getConfiguredNetworks(function(networks) {
if (!networks) {
debug("Unable to get configured networks");
@ -667,9 +667,10 @@ var WifiManager = (function() {
for (let net in networks) {
let network = networks[net];
// Trying to get netId from
// 1. CURRENT network.
// 2. Trying to associate with SSID 'ssid' event
if (network.status === "CURRENT" ||
// 1. network matching SSID if SSID is provided.
// 2. current network if no SSID is provided, it's not guaranteed that
// current network matches requested SSID.
if ((!ssid && network.status === "CURRENT") ||
(ssid && ssid === dequote(network.ssid))) {
return callback(net);
}
@ -682,14 +683,20 @@ var WifiManager = (function() {
if (event.indexOf("CTRL-EVENT-EAP-FAILURE") !== -1) {
if (event.indexOf("EAP authentication failed") !== -1) {
notify("passwordmaybeincorrect");
if (manager.authenticationFailuresCount > MAX_RETRIES_ON_AUTHENTICATION_FAILURE) {
manager.authenticationFailuresCount = 0;
notify("disconnected", {connectionInfo: manager.connectionInfo});
}
}
return true;
}
if (event.indexOf("CTRL-EVENT-EAP-TLS-CERT-ERROR") !== -1) {
// Cert Error
manager.disconnect(function() {
manager.reassociate(function(){});
});
notify("passwordmaybeincorrect");
if (manager.authenticationFailuresCount > MAX_RETRIES_ON_AUTHENTICATION_FAILURE) {
manager.authenticationFailuresCount = 0;
notify("disconnected", {connectionInfo: manager.connectionInfo});
}
return true;
}
if (event.indexOf("CTRL-EVENT-EAP-STARTED") !== -1) {
@ -709,7 +716,7 @@ var WifiManager = (function() {
notify("passwordmaybeincorrect");
if (manager.authenticationFailuresCount > MAX_RETRIES_ON_AUTHENTICATION_FAILURE) {
manager.authenticationFailuresCount = 0;
notify("disconnected", {ssid: manager.connectionInfo.ssid});
notify("disconnected", {connectionInfo: manager.connectionInfo});
}
return true;
}
@ -797,7 +804,7 @@ var WifiManager = (function() {
var bssid = token.split("=")[1];
if (manager.authenticationFailuresCount > MAX_RETRIES_ON_AUTHENTICATION_FAILURE) {
manager.authenticationFailuresCount = 0;
notify("disconnected", {ssid: manager.connectionInfo.ssid});
notify("disconnected", {connectionInfo: manager.connectionInfo});
}
manager.connectionInfo.bssid = null;
manager.connectionInfo.ssid = null;
@ -809,7 +816,7 @@ var WifiManager = (function() {
notify("passwordmaybeincorrect");
if (manager.authenticationFailuresCount > MAX_RETRIES_ON_AUTHENTICATION_FAILURE) {
manager.authenticationFailuresCount = 0;
notify("disconnected", {ssid: manager.connectionInfo.ssid});
notify("disconnected", {connectionInfo: manager.connectionInfo});
}
return true;
}
@ -1223,7 +1230,7 @@ var WifiManager = (function() {
var errors = 0;
for (var n = 1; n < lines.length; ++n) {
var result = lines[n].split("\t");
var netId = result[0];
var netId = parseInt(result[0], 10);
var config = networks[netId] = { netId: netId };
switch (result[3]) {
case "[CURRENT]":
@ -1407,7 +1414,7 @@ var WifiManager = (function() {
manager.loopDetectionCount++;
}
if (manager.loopDetectionCount > MAX_SUPPLICANT_LOOP_ITERATIONS) {
notify("disconnected", {ssid: manager.connectionInfo.ssid});
notify("disconnected", {connectionInfo: manager.connectionInfo});
manager.loopDetectionCount = 0;
}
}
@ -2020,10 +2027,12 @@ function WifiWorker() {
self._needToEnableNetworks = false;
}
WifiManager.getCurrentNetworkId(this.ssid, function(netId) {
let connectionInfo = this.connectionInfo;
WifiManager.getNetworkId(connectionInfo.ssid, function(netId) {
// Trying to get netId from current network.
if (!netId &&
self.currentNetwork &&
self.currentNetwork.ssid == dequote(connectionInfo.ssid) &&
typeof self.currentNetwork.netId !== "undefined") {
netId = self.currentNetwork.netId;
}
@ -3126,6 +3135,11 @@ WifiWorker.prototype = {
this._reconnectOnDisconnect = (this.currentNetwork &&
(this.currentNetwork.ssid === ssid));
WifiManager.removeNetwork(configured.netId, function(ok) {
if (self._needToEnableNetworks) {
self._enableAllNetworks();
self._needToEnableNetworks = false;
}
if (!ok) {
self._sendMessage(message, false, "Unable to remove the network", msg);
self._reconnectOnDisconnect = false;

View File

@ -226,6 +226,70 @@ let gTestSuite = (function() {
]);
}
/**
* Forget the given network.
*
* Resolve when we successfully forget the given network; reject when any error
* occurs.
*
* Fulfill params: (none)
* Reject params: (none)
*
* @param aNetwork
* An object of MozWifiNetwork.
*
* @return A deferred promise.
*/
function forgetNetwork(aNetwork) {
let request = wifiManager.forget(aNetwork);
return wrapDomRequestAsPromise(request)
.then(event => event.target.result);
}
/**
* Forget all known networks.
*
* Resolve when we successfully forget all the known network;
* reject when any error occurs.
*
* Fulfill params: (none)
* Reject params: (none)
*
* @return A deferred promise.
*/
function forgetAllKnownNetworks() {
function createForgetNetworkChain(aNetworks) {
let chain = Promise.resolve();
aNetworks.forEach(function (aNetwork) {
chain = chain.then(() => forgetNetwork(aNetwork));
});
return chain;
}
return getKnownNetworks()
.then(networks => createForgetNetworkChain(networks));
}
/**
* Get all known networks.
*
* Resolve when we get all the known networks; reject when any error
* occurs.
*
* Fulfill params: An array of MozWifiNetwork
* Reject params: (none)
*
* @return A deferred promise.
*/
function getKnownNetworks() {
let request = wifiManager.getKnownNetworks();
return wrapDomRequestAsPromise(request)
.then(event => event.target.result);
}
/**
* Issue a request to scan all wifi available networks.
*
@ -290,6 +354,85 @@ let gTestSuite = (function() {
});
}
/**
* Test wifi association.
*
* Associate with the given network object which is obtained by
* MozWifiManager.getNetworks() (i.e. MozWifiNetwork).
* Resolve when the 'connected' status change event is received.
* Note that we might see other events like 'connecting'
* before 'connected'. So we need to call |waitForWifiManagerEventOnce|
* again whenever non 'connected' event is seen. Never reject.
*
* Fulfill params: (none)
*
* @param aNetwork
* An object of MozWifiNetwork.
*
* @return A deferred promise.
*/
function testAssociate(aNetwork) {
setPasswordIfNeeded(aNetwork);
let promises = [];
// Register the event listerner to wait for 'connected' event first
// to avoid racing issue.
promises.push(waitForConnected(aNetwork));
// Then we do the association.
let request = wifiManager.associate(aNetwork);
promises.push(wrapDomRequestAsPromise(request));
return Promise.all(promises);
}
function waitForConnected(aExpectedNetwork) {
return waitForWifiManagerEventOnce('statuschange')
.then(function onstatuschange(event) {
log("event.status: " + event.status);
log("event.network.ssid: " + (event.network ? event.network.ssid : ''));
if ("connected" === event.status &&
event.network.ssid === aExpectedNetwork.ssid) {
return; // Got expected 'connected' event from aNetwork.ssid.
}
log('Not expected "connected" statuschange event. Wait again!');
return waitForConnected(aExpectedNetwork);
});
}
/**
* Set the password for associating the given network if needed.
*
* Set the password by looking up HOSTAPD_CONFIG_LIST. This function
* will also set |keyManagement| properly.
*
* @param aNetwork
* The MozWifiNetwork object.
*/
function setPasswordIfNeeded(aNetwork) {
let i = getFirstIndexBySsid(aNetwork.ssid, HOSTAPD_CONFIG_LIST);
if (-1 === i) {
log('unknown ssid: ' + aNetwork.ssid);
return; // Unknown network. Assume insecure.
}
if (!aNetwork.security.length) {
return; // No need to set password.
}
let security = aNetwork.security[0];
if (/PSK$/.test(security)) {
aNetwork.psk = HOSTAPD_CONFIG_LIST[i].wpa_passphrase;
aNetwork.keyManagement = 'WPA-PSK';
} else if (/WEP$/.test(security)) {
aNetwork.wep = HOSTAPD_CONFIG_LIST[i].wpa_passphrase;
aNetwork.keyManagement = 'WEP';
}
}
/**
* Set mozSettings values.
*
@ -632,7 +775,9 @@ let gTestSuite = (function() {
*/
function cleanUp() {
waitFor(function() {
return ensureWifiEnabled(wifiOrigEnabled)
return ensureWifiEnabled(true)
.then(forgetAllKnownNetworks)
.then(() => ensureWifiEnabled(wifiOrigEnabled))
.then(finish);
}, function() {
return pendingEmulatorShellCount === 0;
@ -678,6 +823,12 @@ let gTestSuite = (function() {
suite.verifyNumOfProcesses = verifyNumOfProcesses;
suite.testWifiScanWithRetry = testWifiScanWithRetry;
suite.getFirstIndexBySsid = getFirstIndexBySsid;
suite.testAssociate = testAssociate;
suite.getKnownNetworks = getKnownNetworks;
suite.requestWifiScan = requestWifiScan;
suite.waitForConnected = waitForConnected;
suite.forgetNetwork = forgetNetwork;
suite.waitForTimeout = waitForTimeout;
/**
* Common test routine.

View File

@ -6,3 +6,5 @@ qemu = true
[test_wifi_enable.js]
[test_wifi_scan.js]
[test_wifi_associate.js]
[test_wifi_associate_wo_connect.js]
[test_wifi_auto_connect.js]

View File

@ -6,57 +6,6 @@ MARIONETTE_HEAD_JS = 'head.js';
const SCAN_RETRY_CNT = 5;
/**
* Test wifi association.
*
* Associate with the given network object which is obtained by
* MozWifiManager.getNetworks() (i.e. MozWifiNetwork).
* Resolve when the 'connected' status change event is received.
* Note that we might see other events like 'connecting'
* before 'connected'. So we need to call |waitForWifiManagerEventOnce|
* again whenever non 'connected' event is seen. Never reject.
*
* Fulfill params: (none)
*
* @param aNetwork
* An object of MozWifiNetwork.
*
* @return A deferred promise.
*/
function testAssociate(aNetwork) {
if (!setPasswordIfNeeded(aNetwork)) {
throw 'Failed to set password';
}
function waitForConnected() {
return gTestSuite.waitForWifiManagerEventOnce('statuschange')
.then(function onstatuschange(event) {
log("event.status: " + event.status);
log("event.network.ssid: " + (event.network ? event.network.ssid : ''));
if ("connected" === event.status &&
event.network.ssid === aNetwork.ssid) {
return; // Got expected 'connected' event from aNetwork.ssid.
}
log('Not expected "connected" statuschange event. Wait again!');
return waitForConnected();
});
}
let promises = [];
// Register the event listerner to wait for 'connected' event first
// to avoid racing issue.
promises.push(waitForConnected());
// Then we do the association.
let request = gTestSuite.getWifiManager().associate(aNetwork);
promises.push(gTestSuite.wrapDomRequestAsPromise(request));
return Promise.all(promises);
}
/**
* Convert the given MozWifiNetwork object array to testAssociate chain.
*
@ -69,47 +18,12 @@ function convertToTestAssociateChain(aNetworks) {
let chain = Promise.resolve();
aNetworks.forEach(function (aNetwork) {
chain = chain.then(() => testAssociate(aNetwork));
chain = chain.then(() => gTestSuite.testAssociate(aNetwork));
});
return chain;
}
/**
* Set the password for associating the given network if needed.
*
* Set the password by looking up HOSTAPD_CONFIG_LIST. This function
* will also set |keyManagement| properly.
*
* @param aNetwork
* The MozWifiNetwork object.
*
* @return |true| if either insesure or successfully set the password/keyManagement.
* |false| if the given network is not found in HOSTAPD_CONFIG_LIST.
*/
function setPasswordIfNeeded(aNetwork) {
let i = gTestSuite.getFirstIndexBySsid(aNetwork.ssid, HOSTAPD_CONFIG_LIST);
if (-1 === i) {
log('unknown ssid: ' + aNetwork.ssid);
return false; // Error!
}
if (!aNetwork.security.length) {
return true; // No need to set password.
}
let security = aNetwork.security[0];
if (/PSK$/.test(security)) {
aNetwork.psk = HOSTAPD_CONFIG_LIST[i].wpa_passphrase;
aNetwork.keyManagement = 'WPA-PSK';
} else if (/WEP$/.test(security)) {
aNetwork.wep = HOSTAPD_CONFIG_LIST[i].wpa_passphrase;
aNetwork.keyManagement = 'WEP';
}
return true;
}
gTestSuite.doTestWithoutStockAp(function() {
return gTestSuite.ensureWifiEnabled(true)
.then(() => gTestSuite.startHostapds(HOSTAPD_CONFIG_LIST))

View File

@ -0,0 +1,55 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 60000;
MARIONETTE_HEAD_JS = 'head.js';
/**
* Associate with the given networks but don't connect to it.
*
* Issue a association-only request, which will not have us connect
* to the network. Instead, the network config will be added as the
* known networks. After calling the "associate" API, we will wait
* a while to make sure the "connected" event is not received.
*
* Fulfill params: (none)
* Reject params: (none)
*
* @param aNetwork
* MozWifiNetwork object.
*
* @return A deferred promise.
*/
function associateButDontConnect(aNetwork) {
log('Associating with ' + aNetwork.ssid);
aNetwork.dontConnect = true;
let promises = [];
promises.push(gTestSuite.waitForTimeout(10 * 1000)
.then(() => { throw 'timeout'; }));
promises.push(gTestSuite.testAssociate(aNetwork));
return Promise.all(promises)
.then(() => { throw 'unexpected state'; },
function(aReason) {
is(typeof aReason, 'string', 'typeof aReason');
is(aReason, 'timeout', aReason);
});
}
gTestSuite.doTest(function() {
let firstNetwork;
return gTestSuite.ensureWifiEnabled(true)
.then(gTestSuite.requestWifiScan)
.then(function(aNetworks) {
firstNetwork = aNetworks[0];
return associateButDontConnect(firstNetwork);
})
.then(gTestSuite.getKnownNetworks)
.then(function(aKnownNetworks) {
is(1, aKnownNetworks.length, 'There should be only one known network!');
is(aKnownNetworks[0].ssid, firstNetwork.ssid,
'The only one known network should be ' + firstNetwork.ssid)
});
});

View File

@ -0,0 +1,18 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 60000;
MARIONETTE_HEAD_JS = 'head.js';
gTestSuite.doTest(function() {
let firstNetwork;
return gTestSuite.ensureWifiEnabled(true)
.then(gTestSuite.requestWifiScan)
.then(function(networks) {
firstNetwork = networks[0];
return gTestSuite.testAssociate(firstNetwork);
})
.then(() => gTestSuite.requestWifiEnabled(false))
.then(() => gTestSuite.requestWifiEnabled(true))
.then(() => gTestSuite.waitForConnected(firstNetwork));
});

View File

@ -27,6 +27,7 @@ skip = false
[include:../../../../../dom/nfc/tests/marionette/manifest.ini]
[include:../../../../../dom/events/test/marionette/manifest.ini]
[include:../../../../../dom/wifi/test/marionette/manifest.ini]
[include:../../../../../dom/cellbroadcast/tests/marionette/manifest.ini]
; layout tests
[include:../../../../../layout/base/tests/marionette/manifest.ini]