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() {
|
|
|
|
connection = ifr.contentWindow.navigator.mozMobileConnection;
|
|
|
|
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++;
|
2012-08-07 12:11:48 -07: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++;
|
2012-08-15 18:37:05 -07: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
|
|
|
|
|
|
|
testUnregistered();
|
|
|
|
});
|
|
|
|
|
|
|
|
setEmulatorGsmLocation(100, 100);
|
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");
|
|
|
|
is(connection.voice.emergencyCallsOnly, false);
|
|
|
|
is(connection.voice.roaming, false);
|
2013-07-18 02:59:21 -07:00
|
|
|
is(connection.voice.cell, 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");
|
|
|
|
is(connection.voice.emergencyCallsOnly, false);
|
|
|
|
is(connection.voice.roaming, false);
|
2013-07-18 02:59:21 -07:00
|
|
|
is(connection.voice.cell, 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");
|
|
|
|
is(connection.voice.emergencyCallsOnly, false);
|
|
|
|
is(connection.voice.roaming, false);
|
2013-07-18 02:59:21 -07:00
|
|
|
is(connection.voice.cell, 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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|