2012-08-07 12:11:48 -07:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
|
|
|
MARIONETTE_TIMEOUT = 30000;
|
|
|
|
|
2012-08-16 17:42:26 -07:00
|
|
|
SpecialPowers.addPermission("mobileconnection", true, document);
|
2012-08-07 12:11:48 -07:00
|
|
|
|
2013-07-12 07:37:23 -07:00
|
|
|
// Permission changes can't change existing Navigator.prototype
|
|
|
|
// objects, so grab our objects from a new Navigator
|
|
|
|
let ifr = document.createElement("iframe");
|
|
|
|
let connection;
|
|
|
|
ifr.onload = function() {
|
2013-11-13 00:51:43 -08:00
|
|
|
connection = ifr.contentWindow.navigator.mozMobileConnections[0];
|
2013-07-12 07:37:23 -07:00
|
|
|
ok(connection instanceof ifr.contentWindow.MozMobileConnection,
|
|
|
|
"connection is instanceof " + connection.constructor);
|
|
|
|
testConnectionInfo();
|
|
|
|
};
|
|
|
|
document.body.appendChild(ifr);
|
2012-08-07 12:11:48 -07:00
|
|
|
|
2012-08-19 20:18:25 -07:00
|
|
|
let emulatorCmdPendingCount = 0;
|
2012-08-07 12:11:48 -07:00
|
|
|
function setEmulatorVoiceState(state) {
|
2012-08-19 20:18:25 -07:00
|
|
|
emulatorCmdPendingCount++;
|
2014-01-12 18:44:33 -08:00
|
|
|
runEmulatorCmd("gsm voice " + state, function(result) {
|
2012-08-19 20:18:25 -07:00
|
|
|
emulatorCmdPendingCount--;
|
2012-08-07 12:11:48 -07:00
|
|
|
is(result[0], "OK");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-08-15 18:37:05 -07:00
|
|
|
function setEmulatorGsmLocation(lac, cid) {
|
2012-08-19 20:18:25 -07:00
|
|
|
emulatorCmdPendingCount++;
|
2014-01-12 18:44:33 -08:00
|
|
|
runEmulatorCmd("gsm location " + lac + " " + cid, function(result) {
|
2012-08-19 20:18:25 -07:00
|
|
|
emulatorCmdPendingCount--;
|
2012-08-15 18:37:05 -07:00
|
|
|
is(result[0], "OK");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-08-07 12:11:48 -07:00
|
|
|
function testConnectionInfo() {
|
|
|
|
let voice = connection.voice;
|
|
|
|
is(voice.connected, true);
|
|
|
|
is(voice.state, "registered");
|
|
|
|
is(voice.emergencyCallsOnly, false);
|
|
|
|
is(voice.roaming, false);
|
|
|
|
|
2012-08-15 18:37:05 -07:00
|
|
|
testCellLocation();
|
|
|
|
}
|
|
|
|
|
|
|
|
function testCellLocation() {
|
2013-07-18 02:59:21 -07:00
|
|
|
let cell = connection.voice.cell;
|
2012-08-15 18:37:05 -07:00
|
|
|
|
|
|
|
// Emulator always reports valid lac/cid value because its AT command parser
|
|
|
|
// insists valid value for every complete response. See source file
|
|
|
|
// hardare/ril/reference-ril/at_tok.c, function at_tok_nexthexint().
|
2013-07-18 02:59:21 -07:00
|
|
|
ok(cell, "location available");
|
2012-08-15 18:37:05 -07:00
|
|
|
|
2013-07-18 02:59:21 -07:00
|
|
|
// Initial LAC/CID. Android emulator initializes both value to 0xffff/0xffffffff.
|
|
|
|
is(cell.gsmLocationAreaCode, 65535);
|
|
|
|
is(cell.gsmCellId, 268435455);
|
|
|
|
is(cell.cdmaBaseStationId, -1);
|
|
|
|
is(cell.cdmaBaseStationLatitude, -2147483648);
|
|
|
|
is(cell.cdmaBaseStationLongitude, -2147483648);
|
|
|
|
is(cell.cdmaSystemId, -1);
|
|
|
|
is(cell.cdmaNetworkId, -1);
|
2012-08-15 18:37:05 -07:00
|
|
|
|
|
|
|
connection.addEventListener("voicechange", function onvoicechange() {
|
|
|
|
connection.removeEventListener("voicechange", onvoicechange);
|
|
|
|
|
2013-07-18 02:59:21 -07:00
|
|
|
is(cell.gsmLocationAreaCode, 100);
|
|
|
|
is(cell.gsmCellId, 100);
|
|
|
|
is(cell.cdmaBaseStationId, -1);
|
|
|
|
is(cell.cdmaBaseStationLatitude, -2147483648);
|
|
|
|
is(cell.cdmaBaseStationLongitude, -2147483648);
|
|
|
|
is(cell.cdmaSystemId, -1);
|
|
|
|
is(cell.cdmaNetworkId, -1);
|
2012-08-15 18:37:05 -07:00
|
|
|
|
2013-07-23 02:41:18 -07:00
|
|
|
testSignalStrength();
|
2012-08-15 18:37:05 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
setEmulatorGsmLocation(100, 100);
|
2012-08-07 12:11:48 -07:00
|
|
|
}
|
|
|
|
|
2013-07-23 02:41:18 -07:00
|
|
|
function testSignalStrength() {
|
|
|
|
// Android emulator initializes the signal strength to -99 dBm
|
|
|
|
is(connection.voice.signalStrength, -99);
|
|
|
|
is(connection.voice.relSignalStrength, 44);
|
|
|
|
|
|
|
|
testUnregistered();
|
|
|
|
}
|
|
|
|
|
2012-08-07 12:11:48 -07:00
|
|
|
function testUnregistered() {
|
|
|
|
setEmulatorVoiceState("unregistered");
|
|
|
|
|
|
|
|
connection.addEventListener("voicechange", function onvoicechange() {
|
|
|
|
connection.removeEventListener("voicechange", onvoicechange);
|
|
|
|
|
|
|
|
is(connection.voice.connected, false);
|
|
|
|
is(connection.voice.state, "notSearching");
|
2013-11-27 23:21:02 -08:00
|
|
|
is(connection.voice.emergencyCallsOnly, true);
|
2012-08-07 12:11:48 -07:00
|
|
|
is(connection.voice.roaming, false);
|
2013-07-18 02:59:21 -07:00
|
|
|
is(connection.voice.cell, null);
|
2013-08-11 21:15:23 -07:00
|
|
|
is(connection.voice.signalStrength, null);
|
|
|
|
is(connection.voice.relSignalStrength, null);
|
2012-08-07 12:11:48 -07:00
|
|
|
|
|
|
|
testSearching();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function testSearching() {
|
|
|
|
setEmulatorVoiceState("searching");
|
|
|
|
|
|
|
|
connection.addEventListener("voicechange", function onvoicechange() {
|
|
|
|
connection.removeEventListener("voicechange", onvoicechange);
|
|
|
|
|
|
|
|
is(connection.voice.connected, false);
|
|
|
|
is(connection.voice.state, "searching");
|
2013-11-27 23:21:02 -08:00
|
|
|
is(connection.voice.emergencyCallsOnly, true);
|
2012-08-07 12:11:48 -07:00
|
|
|
is(connection.voice.roaming, false);
|
2013-07-18 02:59:21 -07:00
|
|
|
is(connection.voice.cell, null);
|
2013-08-11 21:15:23 -07:00
|
|
|
is(connection.voice.signalStrength, null);
|
|
|
|
is(connection.voice.relSignalStrength, null);
|
2012-08-07 12:11:48 -07:00
|
|
|
|
|
|
|
testDenied();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function testDenied() {
|
|
|
|
setEmulatorVoiceState("denied");
|
|
|
|
|
|
|
|
connection.addEventListener("voicechange", function onvoicechange() {
|
|
|
|
connection.removeEventListener("voicechange", onvoicechange);
|
|
|
|
|
|
|
|
is(connection.voice.connected, false);
|
|
|
|
is(connection.voice.state, "denied");
|
2013-11-27 23:21:02 -08:00
|
|
|
is(connection.voice.emergencyCallsOnly, true);
|
2012-08-07 12:11:48 -07:00
|
|
|
is(connection.voice.roaming, false);
|
2013-07-18 02:59:21 -07:00
|
|
|
is(connection.voice.cell, null);
|
2013-08-11 21:15:23 -07:00
|
|
|
is(connection.voice.signalStrength, null);
|
|
|
|
is(connection.voice.relSignalStrength, null);
|
2012-08-07 12:11:48 -07:00
|
|
|
|
|
|
|
testRoaming();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function testRoaming() {
|
|
|
|
setEmulatorVoiceState("roaming");
|
|
|
|
|
|
|
|
connection.addEventListener("voicechange", function onvoicechange() {
|
|
|
|
connection.removeEventListener("voicechange", onvoicechange);
|
|
|
|
|
|
|
|
is(connection.voice.connected, true);
|
|
|
|
is(connection.voice.state, "registered");
|
|
|
|
is(connection.voice.emergencyCallsOnly, false);
|
|
|
|
is(connection.voice.roaming, true);
|
|
|
|
|
2013-08-11 21:15:23 -07:00
|
|
|
// Android emulator initializes the signal strength to -99 dBm
|
|
|
|
is(connection.voice.signalStrength, -99);
|
|
|
|
is(connection.voice.relSignalStrength, 44);
|
|
|
|
|
2012-08-07 12:11:48 -07:00
|
|
|
testHome();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function testHome() {
|
|
|
|
setEmulatorVoiceState("home");
|
|
|
|
|
|
|
|
connection.addEventListener("voicechange", function onvoicechange() {
|
|
|
|
connection.removeEventListener("voicechange", onvoicechange);
|
|
|
|
|
|
|
|
is(connection.voice.connected, true);
|
|
|
|
is(connection.voice.state, "registered");
|
|
|
|
is(connection.voice.emergencyCallsOnly, false);
|
|
|
|
is(connection.voice.roaming, false);
|
|
|
|
|
2013-08-11 21:15:23 -07:00
|
|
|
// Android emulator initializes the signal strength to -99 dBm
|
|
|
|
is(connection.voice.signalStrength, -99);
|
|
|
|
is(connection.voice.relSignalStrength, 44);
|
|
|
|
|
2012-08-07 12:11:48 -07:00
|
|
|
cleanUp();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanUp() {
|
2012-08-19 20:18:25 -07:00
|
|
|
if (emulatorCmdPendingCount > 0) {
|
|
|
|
setTimeout(cleanUp, 100);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-16 17:42:26 -07:00
|
|
|
SpecialPowers.removePermission("mobileconnection", document);
|
2012-08-07 12:11:48 -07:00
|
|
|
finish();
|
|
|
|
}
|