Bug 962522 - Part 2: Refactor test_mobile_{voice|data}_state.js and add more tests for data roaming status. r=hsinyi

This commit is contained in:
Edgar Chen 2014-01-24 16:44:11 +08:00
Родитель 870b77cb5f
Коммит 404b590377
5 изменённых файлов: 450 добавлений и 278 удалений

Просмотреть файл

@ -6,6 +6,7 @@ qemu = true
[test_mobile_networks.js]
disabled = Bug 808783
[test_mobile_voice_state.js]
[test_mobile_voice_location.js]
[test_mobile_operator_names.js]
[test_mobile_preferred_network_type.js]
[test_mobile_preferred_network_type_by_setting.js]

Просмотреть файл

@ -0,0 +1,56 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
SpecialPowers.addPermission("mobileconnection", true, document);
// In single sim scenario, there is only one mobileConnection, we can always use
// the first instance.
let mobileConnection = window.navigator.mozMobileConnections[0];
ok(mobileConnection instanceof MozMobileConnection,
"mobileConnection is instanceof " + mobileConnection.constructor);
/* Remove permission and execute finish() */
let cleanUp = function() {
SpecialPowers.removePermission("mobileconnection", document);
finish();
};
/* Helper for tasks */
let taskHelper = {
tasks: [],
push: function(task) {
this.tasks.push(task);
},
runNext: function() {
let task = this.tasks.shift();
if (!task) {
cleanUp();
return;
}
if (typeof task === "function") {
task();
}
},
};
/* Helper for emulator console command */
let emulatorHelper = {
pendingCommandCount: 0,
sendCommand: function(cmd, callback) {
this.pendingCommandCount++;
runEmulatorCmd(cmd, function(results) {
this.pendingCommandCount--;
let result = results[results.length - 1];
is(result, "OK", "'"+ cmd +"' returns '" + result + "'");
if (callback && typeof callback === "function") {
callback(results);
}
});
},
};

Просмотреть файл

@ -2,122 +2,171 @@
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 30000;
MARIONETTE_HEAD_JS = "mobile_header.js";
SpecialPowers.addPermission("mobileconnection", true, document);
// Permission changes can't change existing Navigator.prototype
// objects, so grab our objects from a new Navigator
let ifr = document.createElement("iframe");
let mobileConnection;
ifr.onload = function() {
mobileConnection = ifr.contentWindow.navigator.mozMobileConnections[0];
// Start the test
verifyInitialState();
};
document.body.appendChild(ifr);
function verifyInitialState() {
log("Verifying initial state.");
ok(mobileConnection instanceof MozMobileConnection,
"mobileConnection is instanceof " + mobileConnection.constructor);
// Want to start test with mobileConnection.data.state 'registered'
// This is the default state; if it is not currently this value then set it
log("Starting mobileConnection.data.state is: '"
+ mobileConnection.data.state + "'.");
if (mobileConnection.data.state != "registered") {
changeDataStateAndVerify("home", "registered", testUnregistered);
} else {
testUnregistered();
}
function setEmulatorDataState(state) {
emulatorHelper.sendCommand("gsm data " + state);
}
function changeDataStateAndVerify(dataState, expected, nextFunction) {
let gotCallback = false;
// Change the mobileConnection.data.state via 'gsm data' command
log("Changing emulator data state to '" + dataState
+ "' and waiting for 'ondatachange' event.");
// Setup 'ondatachange' event handler
function waitForDataChangeEvent(callback) {
mobileConnection.addEventListener("datachange", function ondatachange() {
mobileConnection.removeEventListener("datachange", ondatachange);
log("Received 'ondatachange' event.");
log("mobileConnection.data.state is now '"
+ mobileConnection.data.state + "'.");
is(mobileConnection.data.state, expected, "data.state");
waitFor(nextFunction, function() {
return(gotCallback);
if (callback && typeof callback === "function") {
callback();
}
});
}
/* Test Initial Connection Info */
taskHelper.push(function testInitialDataInfo() {
log("Test initial data connection info");
let data = mobileConnection.data;
// |data.connected| reports true only if the "default" data connection is
// established.
is(data.connected, false, "check data.connected");
is(data.state, "registered", "check data.state");
is(data.emergencyCallsOnly, false, "check data.emergencyCallsOnly");
is(data.roaming, false, "check data.roaming");
// Android emulator initializes the signal strength to -99 dBm
is(data.signalStrength, -99, "check data.signalStrength");
is(data.relSignalStrength, 44, "check data.relSignalStrength");
let cell = data.cell;
ok(data.cell, "location available");
// Initial LAC/CID. Android emulator initializes both value to
// 0xffff/0xffffffff.
is(cell.gsmLocationAreaCode, 65535, "check data.cell.gsmLocationAreaCode");
is(cell.gsmCellId, 268435455, "check data.cell.gsmCellId");
is(cell.cdmaBaseStationId, -1, "check data.cell.cdmaBaseStationId");
is(cell.cdmaBaseStationLatitude, -2147483648,
"check data.cell.cdmaBaseStationLatitude");
is(cell.cdmaBaseStationLongitude, -2147483648,
"check data.cell.cdmaBaseStationLongitude");
is(cell.cdmaSystemId, -1, "check data.cell.cdmaSystemId");
is(cell.cdmaNetworkId, -1, "check data.cell.cdmaNetworkId");
taskHelper.runNext();
});
/* Test Data State Changed */
taskHelper.push(function testDataStateUpdate() {
// Set emulator's lac/cid and wait for 'ondatachange' event.
function doTestDataState(state, expect, callback) {
log("Test data info with state='" + state + "'");
waitForDataChangeEvent(function() {
let data = mobileConnection.data;
is(data.state, expect.state, "check data.state");
is(data.connected, expect.connected, "check data.connected");
is(data.emergencyCallsOnly, expect.emergencyCallsOnly,
"check data.emergencyCallsOnly");
is(data.roaming, expect.roaming, "check data.roaming");
is(data.signalStrength, expect.signalStrength,
"check data.signalStrength");
is(data.relSignalStrength, expect.relSignalStrength,
"check data.relSignalStrength");
let cell = data.cell;
if (!expect.cell) {
ok(!cell, "check data.cell");
} else {
is(cell.gsmLocationAreaCode, expect.cell.gsmLocationAreaCode,
"check data.cell.gsmLocationAreaCode");
is(cell.gsmCellId, expect.cell.gsmCellId, "check data.cell.gsmCellId");
is(cell.cdmaBaseStationId, -1, "check data.cell.cdmaBaseStationId");
is(cell.cdmaBaseStationLatitude, -2147483648,
"check data.cell.cdmaBaseStationLatitude");
is(cell.cdmaBaseStationLongitude, -2147483648,
"check data.cell.cdmaBaseStationLongitude");
is(cell.cdmaSystemId, -1, "check data.cell.cdmaSystemId");
is(cell.cdmaNetworkId, -1, "check data.cell.cdmaNetworkId");
}
if (callback && typeof callback === "function") {
callback();
}
});
});
// Change the emulator data state
gotCallback = false;
runEmulatorCmd("gsm data " + dataState, function(result) {
is(result[0], "OK");
log("Emulator callback complete.");
gotCallback = true;
});
}
setEmulatorDataState(state);
}
function testUnregistered() {
log("Test 1: Unregistered.");
// Set emulator data state to 'unregistered' and verify
// Expect mobileConnection.data.state to be 'notsearching'
changeDataStateAndVerify("unregistered", "notSearching", testRoaming);
}
let testData = [
// Test state becomes to "unregistered"
{state: "unregistered",
expect: {
state: "notSearching",
connected: false,
emergencyCallsOnly: true,
roaming: false,
signalStrength: null,
relSignalStrength: null,
cell: null
}},
// Test state becomes to "searching"
{state: "searching",
expect: {
state: "searching",
connected: false,
emergencyCallsOnly: true,
roaming: false,
signalStrength: null,
relSignalStrength: null,
cell: null
}},
// Test state becomes to "denied"
{state: "denied",
expect: {
state: "denied",
connected: false,
emergencyCallsOnly: true,
roaming: false,
signalStrength: null,
relSignalStrength: null,
cell: null
}},
// Test state becomes to "roaming"
// Set emulator's data state to "roaming" won't change the operator's
// long_name/short_name/mcc/mnc, so that the |data.roaming| will still
// report false. Please see bug 787967.
{state: "roaming",
expect: {
state: "registered",
connected: false,
emergencyCallsOnly: false,
roaming: false,
signalStrength: -99,
relSignalStrength: 44,
cell: {
gsmLocationAreaCode: 65535,
gsmCellId: 268435455
}}},
// Reset state to default value.
{state: "home",
expect: {
state: "registered",
connected: false,
emergencyCallsOnly: false,
roaming: false,
signalStrength: -99,
relSignalStrength: 44,
cell: {
gsmLocationAreaCode: 65535,
gsmCellId: 268435455
}}}
];
function testRoaming() {
log("Test 2: Roaming.");
// Set emulator data state to 'roaming' and verify
// Expect mobileConnection.data.state to be 'registered'
changeDataStateAndVerify("roaming", "registered", testOff);
}
// Run all test data.
(function do_call() {
let next = testData.shift();
if (!next) {
taskHelper.runNext();
return;
}
doTestDataState(next.state, next.expect, do_call);
})();
});
function testOff() {
log("Test 3: Off.");
// Set emulator data state to 'off' and verify
// Expect mobileConnection.data.state to be 'notsearching'
changeDataStateAndVerify("off", "notSearching", testSearching);
}
function testSearching() {
log("Test 4: Searching.");
// Set emulator data state to 'searching' and verify
// Expect mobileConnection.data.state to be 'searching'
changeDataStateAndVerify("searching", "searching", testDenied);
}
function testDenied() {
log("Test 5: Denied.");
// Set emulator data state to 'denied' and verify
// Expect mobileConnection.data.state to be 'denied'
changeDataStateAndVerify("denied", "denied", testOn);
}
function testOn() {
log("Test 6: On.");
// Set emulator data state to 'on' and verify
// Expect mobileConnection.data.state to be 'registered'
changeDataStateAndVerify("on", "registered", testOffAgain);
}
function testOffAgain() {
log("Test 7: Off again.");
// Set emulator data state to 'off' and verify
// Expect mobileConnection.data.state to be 'notsearching'
changeDataStateAndVerify("off", "notSearching", testHome);
}
function testHome() {
log("Test 8: Home.");
// Set emulator data state to 'home' and verify
// Expect mobileConnection.data.state to be 'registered'
changeDataStateAndVerify("home", "registered", cleanUp);
}
function cleanUp() {
mobileConnection.ondatachange = null;
SpecialPowers.removePermission("mobileconnection", document);
finish();
}
// Start test
taskHelper.runNext();

Просмотреть файл

@ -0,0 +1,88 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 20000;
MARIONETTE_HEAD_JS = "mobile_header.js";
function setEmulatorGsmLocation(lac, cid) {
emulatorHelper.sendCommand("gsm location " + lac + " " + cid);
}
function waitForVoiceChangeEvent(callback) {
mobileConnection.addEventListener("voicechange", function onvoicechange() {
mobileConnection.removeEventListener("voicechange", onvoicechange);
if (callback && typeof callback === "function") {
callback();
}
});
}
/* Test Initial Voice Cell Location Info */
taskHelper.push(function testInitialVoiceCellLocationInfo() {
log("Test initial voice location info");
let cell = mobileConnection.voice.cell;
ok(cell, "location available");
// Initial LAC/CID. Android emulator initializes both value to
// 0xffff/0xffffffff.
is(cell.gsmLocationAreaCode, 65535, "check voice.cell.gsmLocationAreaCode");
is(cell.gsmCellId, 268435455, "check voice.cell.gsmCellId");
is(cell.cdmaBaseStationId, -1, "check voice.cell.cdmaBaseStationId");
is(cell.cdmaBaseStationLatitude, -2147483648,
"check voice.cell.cdmaBaseStationLatitude");
is(cell.cdmaBaseStationLongitude, -2147483648,
"check voice.cell.cdmaBaseStationLongitude");
is(cell.cdmaSystemId, -1, "check voice.cell.cdmaSystemId");
is(cell.cdmaNetworkId, -1, "check voice.cell.cdmaNetworkId");
taskHelper.runNext();
});
/* Test Voice Cell Location Info Change */
taskHelper.push(function testVoiceCellLocationUpdate() {
// Set emulator's lac/cid and wait for 'onvoicechange' event.
function doTestVoiceCellLocation(lac, cid, callback) {
log("Test cell location with lac=" + lac + " and cid=" + cid);
waitForVoiceChangeEvent(function() {
let cell = mobileConnection.voice.cell;
is(cell.gsmLocationAreaCode, lac, "check voice.cell.gsmLocationAreaCode");
is(cell.gsmCellId, cid, "check voice.cell.gsmCellId");
// cdma information won't change.
is(cell.cdmaBaseStationId, -1, "check voice.cell.cdmaBaseStationId");
is(cell.cdmaBaseStationLatitude, -2147483648,
"check voice.cell.cdmaBaseStationLatitude");
is(cell.cdmaBaseStationLongitude, -2147483648,
"check voice.cell.cdmaBaseStationLongitude");
is(cell.cdmaSystemId, -1, "check voice.cell.cdmaSystemId");
is(cell.cdmaNetworkId, -1, "check voice.cell.cdmaNetworkId");
if (callback && typeof callback === "function") {
callback();
}
});
setEmulatorGsmLocation(lac, cid);
}
let testData = [
{lac: 100, cid: 100},
{lac: 2000, cid: 2000},
// Reset lac/cid to default value.
{lac: 65535, cid: 268435455}
];
// Run all test data.
(function do_call() {
let next = testData.shift();
if (!next) {
taskHelper.runNext();
return;
}
doTestVoiceCellLocation(next.lac, next.cid, do_call);
})();
});
// Start test
taskHelper.runNext();

Просмотреть файл

@ -2,188 +2,166 @@
http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 30000;
MARIONETTE_HEAD_JS = "mobile_header.js";
SpecialPowers.addPermission("mobileconnection", true, document);
// 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.mozMobileConnections[0];
ok(connection instanceof ifr.contentWindow.MozMobileConnection,
"connection is instanceof " + connection.constructor);
testConnectionInfo();
};
document.body.appendChild(ifr);
let emulatorCmdPendingCount = 0;
function setEmulatorVoiceState(state) {
emulatorCmdPendingCount++;
runEmulatorCmd("gsm voice " + state, function(result) {
emulatorCmdPendingCount--;
is(result[0], "OK");
emulatorHelper.sendCommand("gsm voice " + state);
}
function waitForVoiceChangeEvent(callback) {
mobileConnection.addEventListener("voicechange", function onvoicechange() {
mobileConnection.removeEventListener("voicechange", onvoicechange);
if (callback && typeof callback === "function") {
callback();
}
});
}
function setEmulatorGsmLocation(lac, cid) {
emulatorCmdPendingCount++;
runEmulatorCmd("gsm location " + lac + " " + cid, function(result) {
emulatorCmdPendingCount--;
is(result[0], "OK");
});
}
/* Test Initial Connection Info */
taskHelper.push(function testInitialVoiceInfo() {
log("Test initial voice connection info");
function testConnectionInfo() {
let voice = connection.voice;
is(voice.connected, true);
is(voice.state, "registered");
is(voice.emergencyCallsOnly, false);
is(voice.roaming, false);
testCellLocation();
}
function testCellLocation() {
let cell = connection.voice.cell;
// 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().
ok(cell, "location available");
// 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);
connection.addEventListener("voicechange", function onvoicechange() {
connection.removeEventListener("voicechange", onvoicechange);
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);
testSignalStrength();
});
setEmulatorGsmLocation(100, 100);
}
function testSignalStrength() {
let voice = mobileConnection.voice;
is(voice.state, "registered", "check voice.state");
is(voice.connected, true, "check voice.connected");
is(voice.emergencyCallsOnly, false, "check voice.emergencyCallsOnly");
is(voice.roaming, false, "check voice.roaming");
// Android emulator initializes the signal strength to -99 dBm
is(connection.voice.signalStrength, -99);
is(connection.voice.relSignalStrength, 44);
is(voice.signalStrength, -99, "check voice.signalStrength");
is(voice.relSignalStrength, 44, "check voice.relSignalStrength");
testUnregistered();
}
let cell = voice.cell;
ok(cell, "location available");
// Initial LAC/CID. Android emulator initializes both value to
// 0xffff/0xffffffff.
is(cell.gsmLocationAreaCode, 65535, "check voice.cell.gsmLocationAreaCode");
is(cell.gsmCellId, 268435455, "check voice.cell.gsmCellId");
is(cell.cdmaBaseStationId, -1, "check voice.cell.cdmaBaseStationId");
is(cell.cdmaBaseStationLatitude, -2147483648,
"check voice.cell.cdmaBaseStationLatitude");
is(cell.cdmaBaseStationLongitude, -2147483648,
"check voice.cell.cdmaBaseStationLongitude");
is(cell.cdmaSystemId, -1, "check voice.cell.cdmaSystemId");
is(cell.cdmaNetworkId, -1, "check voice.cell.cdmaNetworkId");
function testUnregistered() {
setEmulatorVoiceState("unregistered");
taskHelper.runNext();
});
connection.addEventListener("voicechange", function onvoicechange() {
connection.removeEventListener("voicechange", onvoicechange);
/* Test Voice State Changed */
taskHelper.push(function testVoiceStateUpdate() {
// Set emulator's lac/cid and wait for 'onvoicechange' event.
function doTestVoiceState(state, expect, callback) {
log("Test voice info with state='" + state + "'");
is(connection.voice.connected, false);
is(connection.voice.state, "notSearching");
is(connection.voice.emergencyCallsOnly, true);
is(connection.voice.roaming, false);
is(connection.voice.cell, null);
is(connection.voice.signalStrength, null);
is(connection.voice.relSignalStrength, null);
waitForVoiceChangeEvent(function() {
let voice = mobileConnection.voice;
is(voice.state, expect.state, "check voice.state");
is(voice.connected, expect.connected, "check voice.connected");
is(voice.emergencyCallsOnly, expect.emergencyCallsOnly,
"check voice.emergencyCallsOnly");
is(voice.roaming, expect.roaming, "check voice.roaming");
is(voice.signalStrength, expect.signalStrength,
"check voice.signalStrength");
is(voice.relSignalStrength, expect.relSignalStrength,
"check voice.relSignalStrength");
testSearching();
});
}
let cell = voice.cell;
if (!expect.cell) {
ok(!cell, "check voice.cell");
} else {
is(cell.gsmLocationAreaCode, expect.cell.gsmLocationAreaCode,
"check voice.cell.gsmLocationAreaCode");
is(cell.gsmCellId, expect.cell.gsmCellId, "check voice.cell.gsmCellId");
is(cell.cdmaBaseStationId, -1, "check voice.cell.cdmaBaseStationId");
is(cell.cdmaBaseStationLatitude, -2147483648,
"check voice.cell.cdmaBaseStationLatitude");
is(cell.cdmaBaseStationLongitude, -2147483648,
"check voice.cell.cdmaBaseStationLongitude");
is(cell.cdmaSystemId, -1, "check voice.cell.cdmaSystemId");
is(cell.cdmaNetworkId, -1, "check voice.cell.cdmaNetworkId");
}
function testSearching() {
setEmulatorVoiceState("searching");
if (callback && typeof callback === "function") {
callback();
}
});
connection.addEventListener("voicechange", function onvoicechange() {
connection.removeEventListener("voicechange", onvoicechange);
is(connection.voice.connected, false);
is(connection.voice.state, "searching");
is(connection.voice.emergencyCallsOnly, true);
is(connection.voice.roaming, false);
is(connection.voice.cell, null);
is(connection.voice.signalStrength, null);
is(connection.voice.relSignalStrength, null);
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, true);
is(connection.voice.roaming, false);
is(connection.voice.cell, null);
is(connection.voice.signalStrength, null);
is(connection.voice.relSignalStrength, null);
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);
// Android emulator initializes the signal strength to -99 dBm
is(connection.voice.signalStrength, -99);
is(connection.voice.relSignalStrength, 44);
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);
// Android emulator initializes the signal strength to -99 dBm
is(connection.voice.signalStrength, -99);
is(connection.voice.relSignalStrength, 44);
cleanUp();
});
}
function cleanUp() {
if (emulatorCmdPendingCount > 0) {
setTimeout(cleanUp, 100);
return;
setEmulatorVoiceState(state);
}
SpecialPowers.removePermission("mobileconnection", document);
finish();
}
let testData = [
// Test state becomes to "unregistered"
{state: "unregistered",
expect: {
state: "notSearching",
connected: false,
emergencyCallsOnly: true,
roaming: false,
signalStrength: null,
relSignalStrength: null,
cell: null
}},
// Test state becomes to "searching"
{state: "searching",
expect: {
state: "searching",
connected: false,
emergencyCallsOnly: true,
roaming: false,
signalStrength: null,
relSignalStrength: null,
cell: null
}},
// Test state becomes to "denied"
{state: "denied",
expect: {
state: "denied",
connected: false,
emergencyCallsOnly: true,
roaming: false,
signalStrength: null,
relSignalStrength: null,
cell: null
}},
// Test state becomes to "roaming"
{state: "roaming",
expect: {
state: "registered",
connected: true,
emergencyCallsOnly: false,
roaming: true,
signalStrength: -99,
relSignalStrength: 44,
cell: {
gsmLocationAreaCode: 65535,
gsmCellId: 268435455
}}},
// Reset state to default value.
{state: "home",
expect: {
state: "registered",
connected: true,
emergencyCallsOnly: false,
roaming: false,
signalStrength: -99,
relSignalStrength: 44,
cell: {
gsmLocationAreaCode: 65535,
gsmCellId: 268435455
}}}
];
// Run all test data.
(function do_call() {
let next = testData.shift();
if (!next) {
taskHelper.runNext();
return;
}
doTestVoiceState(next.state, next.expect, do_call);
})();
});
// Start test
taskHelper.runNext();