Bug 977433 - Part 2 : Test cases - B2G RIL: Handling LTE signal strength. r=HsinYi

This commit is contained in:
Shawn Ku 2014-03-18 10:30:18 +08:00
Родитель e97bd245b3
Коммит af9b48013c
3 изменённых файлов: 143 добавлений и 6 удалений

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

@ -21,5 +21,6 @@ disabled = Bug 808783
[test_mobile_last_known_network.js] [test_mobile_last_known_network.js]
[test_mobile_icc_change.js] [test_mobile_icc_change.js]
[test_mobile_connections_array_uninitialized.js] [test_mobile_connections_array_uninitialized.js]
[test_mobile_signal_strength.js]
[test_mobile_data_ipv6.js] [test_mobile_data_ipv6.js]
disabled = Bug 978071 disabled = Bug 978071

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

@ -9,10 +9,16 @@ let mobileConnection = window.navigator.mozMobileConnections[0];
ok(mobileConnection instanceof MozMobileConnection, ok(mobileConnection instanceof MozMobileConnection,
"mobileConnection is instanceof " + mobileConnection.constructor); "mobileConnection is instanceof " + mobileConnection.constructor);
let _pendingEmulatorCmdCount = 0;
/* Remove permission and execute finish() */ /* Remove permission and execute finish() */
let cleanUp = function() { let cleanUp = function() {
SpecialPowers.removePermission("mobileconnection", document); waitFor(function() {
finish(); SpecialPowers.removePermission("mobileconnection", document);
finish();
}, function() {
return _pendingEmulatorCmdCount === 0;
});
}; };
/* Helper for tasks */ /* Helper for tasks */
@ -38,12 +44,10 @@ let taskHelper = {
/* Helper for emulator console command */ /* Helper for emulator console command */
let emulatorHelper = { let emulatorHelper = {
pendingCommandCount: 0,
sendCommand: function(cmd, callback) { sendCommand: function(cmd, callback) {
this.pendingCommandCount++; _pendingEmulatorCmdCount++;
runEmulatorCmd(cmd, function(results) { runEmulatorCmd(cmd, function(results) {
this.pendingCommandCount--; _pendingEmulatorCmdCount--;
let result = results[results.length - 1]; let result = results[results.length - 1];
is(result, "OK", "'"+ cmd +"' returns '" + result + "'"); is(result, "OK", "'"+ cmd +"' returns '" + result + "'");

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

@ -0,0 +1,132 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 30000;
MARIONETTE_HEAD_JS = "mobile_header.js";
/* Emulator command for GSM/UMTS signal strength */
function setEmulatorGsmSignalStrength(rssi) {
emulatorHelper.sendCommand("gsm signal " + rssi);
}
/* Emulator command for LTE signal strength */
function setEmulatorLteSignalStrength(rxlev, rsrp, rssnr) {
let lteSignal = rxlev + " " + rsrp + " " + rssnr;
emulatorHelper.sendCommand("gsm lte_signal " + lteSignal);
}
function waitForVoiceChangeEvent(callback) {
mobileConnection.addEventListener("voicechange", function onvoicechange() {
mobileConnection.removeEventListener("voicechange", onvoicechange);
if (callback && typeof callback === "function") {
callback();
}
});
}
/* Test Initial Signal Strength Info */
taskHelper.push(function testInitialSignalStrengthInfo() {
log("Test initial signal strength info");
let voice = mobileConnection.voice;
// Android emulator initializes the signal strength to -99 dBm
is(voice.signalStrength, -99, "check voice.signalStrength");
is(voice.relSignalStrength, 44, "check voice.relSignalStrength");
taskHelper.runNext();
});
/* Test Unsolicited Signal Strength Events for LTE */
taskHelper.push(function testLteSignalStrength() {
// Set emulator's LTE signal strength and wait for 'onvoicechange' event.
function doTestLteSignalStrength(input, expect, callback) {
log("Test LTE signal info with data : " + JSON.stringify(input));
waitForVoiceChangeEvent(function() {
let voice = mobileConnection.voice;
is(voice.signalStrength, expect.signalStrength,
"check voice.signalStrength");
is(voice.relSignalStrength, expect.relSignalStrength,
"check voice.relSignalStrength");
if (callback && typeof callback === "function") {
callback();
}
});
setEmulatorLteSignalStrength(input.rxlev, input.rsrp, input.rssnr);
}
let testData = [
// All invalid case.
{input: {
rxlev: 99,
rsrp: 65535,
rssnr: 65535},
expect: {
signalStrength: null,
relSignalStrength: null}
},
// Valid rxlev with max value.
{input: {
rxlev: 63,
rsrp: 65535,
rssnr: 65535},
expect: {
signalStrength: -48,
relSignalStrength: 100}
},
// Valid rxlev.
{input: {
rxlev: 12,
rsrp: 65535,
rssnr: 65535},
expect: {
signalStrength: -99,
relSignalStrength: 100}
},
// Valid rxlev with min value.
{input: {
rxlev: 0,
rsrp: 65535,
rssnr: 65535},
expect: {
signalStrength: -111,
relSignalStrength: 0}
}
];
// Run all test data.
(function do_call() {
let next = testData.shift();
if (!next) {
taskHelper.runNext();
return;
}
doTestLteSignalStrength(next.input, next.expect, do_call);
})();
});
/* Reset Signal Strength Info to default, and finsih the test */
taskHelper.push(function testResetSignalStrengthInfo() {
// Reset emulator's signal strength and wait for 'onvoicechange' event.
function doResetSignalStrength(rssi) {
waitForVoiceChangeEvent(function() {
let voice = mobileConnection.voice;
is(voice.signalStrength, -99, "check voice.signalStrength");
is(voice.relSignalStrength, 44, "check voice.relSignalStrength");
taskHelper.runNext();
});
setEmulatorGsmSignalStrength(rssi);
}
// Emulator uses rssi = 7 as default value, and we need to reset it after
// finishing test in case other test cases need those values for testing.
doResetSignalStrength(7);
});
// Start test
taskHelper.runNext();