зеркало из https://github.com/mozilla/gecko-dev.git
Bug 979134: convert test_mobile_data_state.js to Promise. r=hsinyi
This commit is contained in:
Родитель
4ae502dbf1
Коммит
d9c4d5b84d
|
@ -1,101 +1,32 @@
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
MARIONETTE_TIMEOUT = 30000;
|
MARIONETTE_TIMEOUT = 60000;
|
||||||
MARIONETTE_HEAD_JS = "mobile_header.js";
|
MARIONETTE_HEAD_JS = "head.js";
|
||||||
|
|
||||||
function setEmulatorDataState(state) {
|
const INITIAL_STATES = {
|
||||||
emulatorHelper.sendCommand("gsm data " + state);
|
state: "registered",
|
||||||
}
|
connected: false,
|
||||||
|
emergencyCallsOnly: false,
|
||||||
|
roaming: false,
|
||||||
|
signalStrength: -99,
|
||||||
|
relSignalStrength: 44,
|
||||||
|
|
||||||
function waitForDataChangeEvent(callback) {
|
cell: {
|
||||||
mobileConnection.addEventListener("datachange", function ondatachange() {
|
gsmLocationAreaCode: 65535,
|
||||||
mobileConnection.removeEventListener("datachange", ondatachange);
|
gsmCellId: 268435455,
|
||||||
|
cdmaBaseStationId: -1,
|
||||||
if (callback && typeof callback === "function") {
|
cdmaBaseStationLatitude: -2147483648,
|
||||||
callback();
|
cdmaBaseStationLongitude: -2147483648,
|
||||||
}
|
cdmaSystemId: -1,
|
||||||
});
|
cdmaNetworkId: -1,
|
||||||
}
|
|
||||||
|
|
||||||
/* 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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
setEmulatorDataState(state);
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let testData = [
|
const TEST_DATA = [{
|
||||||
// Test state becomes to "unregistered"
|
// Test state becomes to "unregistered"
|
||||||
{state: "unregistered",
|
state: "unregistered",
|
||||||
expect: {
|
expected: {
|
||||||
state: "notSearching",
|
state: "notSearching",
|
||||||
connected: false,
|
connected: false,
|
||||||
emergencyCallsOnly: true,
|
emergencyCallsOnly: true,
|
||||||
|
@ -103,10 +34,11 @@ taskHelper.push(function testDataStateUpdate() {
|
||||||
signalStrength: null,
|
signalStrength: null,
|
||||||
relSignalStrength: null,
|
relSignalStrength: null,
|
||||||
cell: null
|
cell: null
|
||||||
}},
|
}
|
||||||
|
}, {
|
||||||
// Test state becomes to "searching"
|
// Test state becomes to "searching"
|
||||||
{state: "searching",
|
state: "searching",
|
||||||
expect: {
|
expected: {
|
||||||
state: "searching",
|
state: "searching",
|
||||||
connected: false,
|
connected: false,
|
||||||
emergencyCallsOnly: true,
|
emergencyCallsOnly: true,
|
||||||
|
@ -114,10 +46,11 @@ taskHelper.push(function testDataStateUpdate() {
|
||||||
signalStrength: null,
|
signalStrength: null,
|
||||||
relSignalStrength: null,
|
relSignalStrength: null,
|
||||||
cell: null
|
cell: null
|
||||||
}},
|
}
|
||||||
|
}, {
|
||||||
// Test state becomes to "denied"
|
// Test state becomes to "denied"
|
||||||
{state: "denied",
|
state: "denied",
|
||||||
expect: {
|
expected: {
|
||||||
state: "denied",
|
state: "denied",
|
||||||
connected: false,
|
connected: false,
|
||||||
emergencyCallsOnly: true,
|
emergencyCallsOnly: true,
|
||||||
|
@ -125,13 +58,14 @@ taskHelper.push(function testDataStateUpdate() {
|
||||||
signalStrength: null,
|
signalStrength: null,
|
||||||
relSignalStrength: null,
|
relSignalStrength: null,
|
||||||
cell: null
|
cell: null
|
||||||
}},
|
}
|
||||||
|
}, {
|
||||||
// Test state becomes to "roaming"
|
// Test state becomes to "roaming"
|
||||||
// Set emulator's data state to "roaming" won't change the operator's
|
// 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
|
// long_name/short_name/mcc/mnc, so that the |data.roaming| will still
|
||||||
// report false. Please see bug 787967.
|
// report false. Please see bug 787967.
|
||||||
{state: "roaming",
|
state: "roaming",
|
||||||
expect: {
|
expected: {
|
||||||
state: "registered",
|
state: "registered",
|
||||||
connected: false,
|
connected: false,
|
||||||
emergencyCallsOnly: false,
|
emergencyCallsOnly: false,
|
||||||
|
@ -141,32 +75,68 @@ taskHelper.push(function testDataStateUpdate() {
|
||||||
cell: {
|
cell: {
|
||||||
gsmLocationAreaCode: 65535,
|
gsmLocationAreaCode: 65535,
|
||||||
gsmCellId: 268435455
|
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
|
|
||||||
}}}
|
|
||||||
];
|
|
||||||
|
|
||||||
// Run all test data.
|
|
||||||
(function do_call() {
|
|
||||||
let next = testData.shift();
|
|
||||||
if (!next) {
|
|
||||||
taskHelper.runNext();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
doTestDataState(next.state, next.expect, do_call);
|
}, {
|
||||||
})();
|
// Reset state to default value.
|
||||||
});
|
state: "home",
|
||||||
|
expected: {
|
||||||
|
state: "registered",
|
||||||
|
connected: false,
|
||||||
|
emergencyCallsOnly: false,
|
||||||
|
roaming: false,
|
||||||
|
signalStrength: -99,
|
||||||
|
relSignalStrength: 44,
|
||||||
|
cell: {
|
||||||
|
gsmLocationAreaCode: 65535,
|
||||||
|
gsmCellId: 268435455
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
// Start test
|
function compareTo(aPrefix, aFrom, aTo) {
|
||||||
taskHelper.runNext();
|
for (let field in aTo) {
|
||||||
|
let fullName = aPrefix + field;
|
||||||
|
|
||||||
|
let lhs = aFrom[field];
|
||||||
|
let rhs = aTo[field];
|
||||||
|
ok(true, "lhs=" + JSON.stringify(lhs) + ", rhs=" + JSON.stringify(rhs));
|
||||||
|
if (typeof rhs !== "object") {
|
||||||
|
is(lhs, rhs, fullName);
|
||||||
|
} else if (rhs) {
|
||||||
|
ok(lhs, fullName);
|
||||||
|
compareTo(fullName + ".", lhs, rhs);
|
||||||
|
} else {
|
||||||
|
is(lhs, null, fullName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function verifyDataInfo(aExpected) {
|
||||||
|
compareTo("data.", mobileConnection.data, aExpected);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Test Data State Changed */
|
||||||
|
function testDataStateUpdate(aNewState, aExpected) {
|
||||||
|
log("Test data info with state='" + aNewState + "'");
|
||||||
|
|
||||||
|
// Set emulator's lac/cid and wait for 'ondatachange' event.
|
||||||
|
return setEmulatorVoiceDataStateAndWait("data", aNewState)
|
||||||
|
.then(() => verifyDataInfo(aExpected));
|
||||||
|
}
|
||||||
|
|
||||||
|
startTestCommon(function() {
|
||||||
|
log("Test initial data connection info");
|
||||||
|
|
||||||
|
verifyDataInfo(INITIAL_STATES);
|
||||||
|
|
||||||
|
let promise = Promise.resolve();
|
||||||
|
for (let i = 0; i < TEST_DATA.length; i++) {
|
||||||
|
let entry = TEST_DATA[i];
|
||||||
|
promise =
|
||||||
|
promise.then(testDataStateUpdate.bind(null, entry.state, entry.expected));
|
||||||
|
}
|
||||||
|
|
||||||
|
return promise;
|
||||||
|
});
|
||||||
|
|
Загрузка…
Ссылка в новой задаче