mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 979134: convert test_mobile_operator_names.js to Promise. r=hsinyi
This commit is contained in:
parent
02df5e8a12
commit
a31a423313
@ -496,6 +496,81 @@ function setEmulatorGsmLocation(aLac, aCid) {
|
||||
return runEmulatorCmdSafe(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get emulator operators info.
|
||||
*
|
||||
* Fulfill params:
|
||||
* An array of { longName: <string>, shortName: <string>, mccMnc: <string> }.
|
||||
* Reject params:
|
||||
* result -- an array of emulator response lines.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function getEmulatorOperatorNames() {
|
||||
let cmd = "operator dumpall";
|
||||
return runEmulatorCmdSafe(cmd)
|
||||
.then(function(aResults) {
|
||||
let operators = [];
|
||||
|
||||
for (let i = 0; i < aResults.length - 1; i++) {
|
||||
let names = aResults[i].split(',');
|
||||
operators.push({
|
||||
longName: names[0],
|
||||
shortName: names[1],
|
||||
mccMnc: names[2],
|
||||
});
|
||||
}
|
||||
|
||||
ok(true, "emulator operators list: " + JSON.stringify(operators));
|
||||
return operators;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set emulator operators info.
|
||||
*
|
||||
* Fulfill params: (none)
|
||||
* Reject params:
|
||||
* result -- an array of emulator response lines.
|
||||
*
|
||||
* @param aOperator
|
||||
* "home" or "roaming".
|
||||
* @param aLongName
|
||||
* A string.
|
||||
* @param aShortName
|
||||
* A string.
|
||||
* @param aMcc [optional]
|
||||
* A string.
|
||||
* @param aMnc [optional]
|
||||
* A string.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function setEmulatorOperatorNames(aOperator, aLongName, aShortName, aMcc, aMnc) {
|
||||
const EMULATOR_OPERATORS = [ "home", "roaming" ];
|
||||
|
||||
let index = EMULATOR_OPERATORS.indexOf(aOperator);
|
||||
if (index < 0) {
|
||||
throw "invalid operator";
|
||||
}
|
||||
|
||||
let cmd = "operator set " + index + " " + aLongName + "," + aShortName;
|
||||
if (aMcc && aMnc) {
|
||||
cmd = cmd + "," + aMcc + aMnc;
|
||||
}
|
||||
return runEmulatorCmdSafe(cmd)
|
||||
.then(function(aResults) {
|
||||
let exp = "^" + aLongName + "," + aShortName + ",";
|
||||
if (aMcc && aMnc) {
|
||||
cmd = cmd + aMcc + aMnc;
|
||||
}
|
||||
|
||||
let re = new RegExp(exp);
|
||||
ok(aResults[index].match(new RegExp(exp)),
|
||||
"Long/short name and/or mcc/mnc should be changed.");
|
||||
});
|
||||
}
|
||||
|
||||
let _networkManager;
|
||||
|
||||
/**
|
||||
|
@ -7,6 +7,8 @@ qemu = true
|
||||
[test_mobile_voice_state.js]
|
||||
[test_mobile_voice_location.js]
|
||||
[test_mobile_operator_names.js]
|
||||
[test_mobile_operator_names_plmnlist.js]
|
||||
[test_mobile_operator_names_roaming.js]
|
||||
[test_mobile_preferred_network_type.js]
|
||||
[test_mobile_data_connection.js]
|
||||
[test_mobile_data_location.js]
|
||||
|
@ -2,217 +2,38 @@
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
MARIONETTE_HEAD_JS = "head.js";
|
||||
|
||||
SpecialPowers.addPermission("mobileconnection", true, document);
|
||||
function check(aLongName, aShortName) {
|
||||
let network = mobileConnection.voice.network;
|
||||
|
||||
const OPERATOR_HOME = 0;
|
||||
const OPERATOR_ROAMING = 1;
|
||||
|
||||
// Permission changes can't change existing Navigator.prototype
|
||||
// objects, so grab our objects from a new Navigator
|
||||
let ifr = document.createElement("iframe");
|
||||
let connection;
|
||||
let voice;
|
||||
let network;
|
||||
ifr.onload = function() {
|
||||
connection = ifr.contentWindow.navigator.mozMobileConnections[0];
|
||||
ok(connection instanceof ifr.contentWindow.MozMobileConnection,
|
||||
"connection is instanceof " + connection.constructor);
|
||||
|
||||
voice = connection.voice;
|
||||
ok(voice, "voice connection valid");
|
||||
|
||||
network = voice.network;
|
||||
ok(network, "voice network info valid");
|
||||
|
||||
waitFor(testMobileOperatorNames, function() {
|
||||
return voice.connected;
|
||||
});
|
||||
};
|
||||
document.body.appendChild(ifr);
|
||||
|
||||
let emulatorCmdPendingCount = 0;
|
||||
function sendEmulatorCommand(cmd, callback) {
|
||||
emulatorCmdPendingCount++;
|
||||
runEmulatorCmd(cmd, function(result) {
|
||||
emulatorCmdPendingCount--;
|
||||
|
||||
is(result[result.length - 1], "OK");
|
||||
|
||||
callback(result);
|
||||
});
|
||||
}
|
||||
|
||||
function setEmulatorOperatorNamesAndMccMnc(which, longName, shortName,
|
||||
mcc, mnc, callback) {
|
||||
let cmd = "operator set " + which + " " + longName + "," +
|
||||
shortName + "," + mcc + mnc;
|
||||
sendEmulatorCommand(cmd, function(result) {
|
||||
let re = new RegExp("^" + longName + "," +
|
||||
shortName + "," + mcc + mnc);
|
||||
ok(result[which].match(re), "Long/short name and mcc/mnc should be changed.");
|
||||
|
||||
if (callback) {
|
||||
window.setTimeout(callback, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function setEmulatorOperatorNames(which, longName, shortName, callback) {
|
||||
let cmd = "operator set " + which + " " + longName + "," + shortName;
|
||||
sendEmulatorCommand(cmd, function(result) {
|
||||
let re = new RegExp("^" + longName + "," + shortName + ",");
|
||||
ok(result[which].match(re), "Long/short name should be changed.");
|
||||
|
||||
if (callback) {
|
||||
window.setTimeout(callback, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function setEmulatorRoaming(roaming, callback) {
|
||||
let cmd = "gsm voice " + (roaming ? "roaming" : "home");
|
||||
sendEmulatorCommand(cmd, function(result) {
|
||||
is(result[0], "OK");
|
||||
|
||||
if (callback) {
|
||||
window.setTimeout(callback, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function checkValidMccMnc() {
|
||||
is(network.longName, aLongName, "network.longName");
|
||||
is(network.shortName, aShortName, "network.shortName");
|
||||
is(network.mcc, "310", "network.mcc");
|
||||
is(network.mnc, "260", "network.mnc");
|
||||
}
|
||||
|
||||
function waitForVoiceChange(callback) {
|
||||
connection.addEventListener("voicechange", function onvoicechange() {
|
||||
connection.removeEventListener("voicechange", onvoicechange);
|
||||
callback();
|
||||
});
|
||||
function test(aLongName, aShortName) {
|
||||
log("Testing '" + aLongName + "', '" + aShortName + "':");
|
||||
|
||||
let promises = [];
|
||||
promises.push(waitForManagerEvent("voicechange"));
|
||||
promises.push(setEmulatorOperatorNames("home", aLongName, aShortName));
|
||||
return Promise.all(promises)
|
||||
.then(() => check(aLongName, aShortName));
|
||||
}
|
||||
|
||||
function doTestMobileOperatorNames(longName, shortName, callback) {
|
||||
log("Testing '" + longName + "', '" + shortName + "':");
|
||||
startTestCommon(function() {
|
||||
return getEmulatorOperatorNames()
|
||||
.then(function(aOperators) {
|
||||
return Promise.resolve()
|
||||
|
||||
checkValidMccMnc();
|
||||
.then(() => test("Mozilla", "B2G"))
|
||||
.then(() => test("Mozilla", ""))
|
||||
.then(() => test("", "B2G"))
|
||||
.then(() => test("", ""))
|
||||
|
||||
waitForVoiceChange(function() {
|
||||
is(network.longName, longName, "network.longName");
|
||||
is(network.shortName, shortName, "network.shortName");
|
||||
|
||||
checkValidMccMnc();
|
||||
|
||||
window.setTimeout(callback, 0);
|
||||
});
|
||||
|
||||
setEmulatorOperatorNames(OPERATOR_HOME, longName, shortName);
|
||||
}
|
||||
|
||||
function testMobileOperatorNames() {
|
||||
doTestMobileOperatorNames("Mozilla", "B2G", function() {
|
||||
doTestMobileOperatorNames("Mozilla", "", function() {
|
||||
doTestMobileOperatorNames("", "B2G", function() {
|
||||
doTestMobileOperatorNames("", "", function() {
|
||||
doTestMobileOperatorNames("Android", "Android", testOperatorPLMNList);
|
||||
});
|
||||
});
|
||||
// Reset back to initial values.
|
||||
.then(() => test(aOperators[0].longName, aOperators[0].shortName));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function doTestOperatorPLMNList(mcc, mnc, expectedLongName,
|
||||
expectedShortName, callback) {
|
||||
log("Testing mcc = " + mcc + ", mnc = " + mnc + ":");
|
||||
|
||||
waitForVoiceChange(function() {
|
||||
is(network.longName, expectedLongName, "network.longName");
|
||||
is(network.shortName, expectedShortName, "network.shortName");
|
||||
is(network.mcc, mcc, "network.mcc");
|
||||
is(network.mnc, mnc, "network.mnc");
|
||||
window.setTimeout(callback, 0);
|
||||
});
|
||||
|
||||
setEmulatorOperatorNamesAndMccMnc(OPERATOR_HOME, "Android", "Android", mcc, mnc);
|
||||
}
|
||||
|
||||
function testOperatorPLMNList() {
|
||||
doTestOperatorPLMNList("123", "456", "Android", "Android", function() {
|
||||
doTestOperatorPLMNList("310", "070", "AT&T", "", function() {
|
||||
doTestOperatorPLMNList("310", "260", "Android", "Android", testRoamingCheck);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// See bug 797972 - B2G RIL: False roaming situation
|
||||
//
|
||||
// Steps to test:
|
||||
// 1. set roaming operator names
|
||||
// 2. set emulator roaming
|
||||
// 3. wait for onvoicechange event and test passing conditions
|
||||
// 4. set emulator roaming back to false
|
||||
// 5. wait for onvoicechange event again and callback
|
||||
function doTestRoamingCheck(longName, shortName, callback) {
|
||||
log("Testing roaming check '" + longName + "', '" + shortName + "':");
|
||||
|
||||
setEmulatorOperatorNames(OPERATOR_ROAMING, longName, shortName,
|
||||
window.setTimeout.bind(window, function() {
|
||||
let done = false;
|
||||
function resetRoaming() {
|
||||
if (!done) {
|
||||
window.setTimeout(resetRoaming, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
waitForVoiceChange(callback);
|
||||
setEmulatorRoaming(false);
|
||||
}
|
||||
|
||||
waitForVoiceChange(function() {
|
||||
is(network.longName, longName, "network.longName");
|
||||
is(network.shortName, shortName, "network.shortName");
|
||||
is(voice.roaming, false, "voice.roaming");
|
||||
|
||||
resetRoaming();
|
||||
});
|
||||
|
||||
setEmulatorRoaming(true, function() {
|
||||
done = true;
|
||||
});
|
||||
}, 3000) // window.setTimeout.bind
|
||||
); // setEmulatorOperatorNames
|
||||
}
|
||||
|
||||
function testRoamingCheck() {
|
||||
// If Either long name or short name of current registered operator matches
|
||||
// SPN("Android"), then the `roaming` attribute should be set to false.
|
||||
doTestRoamingCheck("Android", "Android", function() {
|
||||
doTestRoamingCheck("Android", "android", function() {
|
||||
doTestRoamingCheck("Android", "Xxx", function() {
|
||||
doTestRoamingCheck("android", "Android", function() {
|
||||
doTestRoamingCheck("android", "android", function() {
|
||||
doTestRoamingCheck("android", "Xxx", function() {
|
||||
doTestRoamingCheck("Xxx", "Android", function() {
|
||||
doTestRoamingCheck("Xxx", "android", function() {
|
||||
setEmulatorOperatorNames(OPERATOR_ROAMING, "TelKila", "TelKila",
|
||||
window.setTimeout.bind(window, cleanUp, 3000));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
if (emulatorCmdPendingCount > 0) {
|
||||
setTimeout(cleanUp, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
SpecialPowers.removePermission("mobileconnection", document);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
@ -0,0 +1,40 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
MARIONETTE_HEAD_JS = "head.js";
|
||||
|
||||
function check(aLongName, aShortName, aMcc, aMnc) {
|
||||
let network = mobileConnection.voice.network;
|
||||
|
||||
is(network.longName, aLongName, "network.longName");
|
||||
is(network.shortName, aShortName, "network.shortName");
|
||||
is(network.mcc, aMcc, "network.mcc");
|
||||
is(network.mnc, aMnc, "network.mnc");
|
||||
}
|
||||
|
||||
function test(aLongName, aShortName, aMcc, aMnc, aExpectedLongName,
|
||||
aExpectedShortName) {
|
||||
log("Testing mcc = " + aMcc + ", mnc = " + aMnc + ":");
|
||||
|
||||
let promises = [];
|
||||
promises.push(waitForManagerEvent("voicechange"));
|
||||
promises.push(setEmulatorOperatorNames("home", aLongName, aShortName, aMcc, aMnc));
|
||||
return Promise.all(promises)
|
||||
.then(() => check(aExpectedLongName, aExpectedShortName, aMcc, aMnc));
|
||||
}
|
||||
|
||||
startTestCommon(function() {
|
||||
return getEmulatorOperatorNames()
|
||||
.then(function(aOperators) {
|
||||
let {longName: longName, shortName: shortName} = aOperators[0];
|
||||
let {mcc: mcc, mnc: mnc} = mobileConnection.voice.network;
|
||||
return Promise.resolve()
|
||||
|
||||
.then(() => test(longName, shortName, "123", "456", longName, shortName))
|
||||
.then(() => test(longName, shortName, "310", "070", "AT&T", ""))
|
||||
|
||||
// Reset back to initial values.
|
||||
.then(() => test(longName, shortName, mcc, mnc, longName, shortName));
|
||||
});
|
||||
});
|
@ -0,0 +1,69 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
MARIONETTE_HEAD_JS = "head.js";
|
||||
|
||||
function check(aLongName, aShortName, aRoaming) {
|
||||
let voice = mobileConnection.voice;
|
||||
let network = voice.network;
|
||||
|
||||
is(network.longName, aLongName, "network.longName");
|
||||
is(network.shortName, aShortName, "network.shortName");
|
||||
is(voice.roaming, aRoaming, "voice.roaming");
|
||||
}
|
||||
|
||||
function setEmulatorOperatorNamesAndWait(aWhich, aLongName, aShortName) {
|
||||
let promises = [];
|
||||
promises.push(waitForManagerEvent("voicechange"));
|
||||
promises.push(setEmulatorOperatorNames(aWhich, aLongName, aShortName));
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
// See bug 797972 - B2G RIL: False roaming situation
|
||||
//
|
||||
// Steps to test:
|
||||
// 1. set roaming operator names
|
||||
// 2. set emulator roaming
|
||||
// 3. wait for onvoicechange event and test passing conditions
|
||||
// 4. set emulator roaming back to false
|
||||
// 5. wait for onvoicechange event again and callback
|
||||
function test(aLongName, aShortName, aRoaming) {
|
||||
log("Testing roaming check '" + aLongName + "', '" + aShortName + "':");
|
||||
|
||||
return Promise.resolve()
|
||||
|
||||
// We should not have voicechange here, but, yes, we do.
|
||||
.then(() => setEmulatorOperatorNamesAndWait("roaming", aLongName, aShortName))
|
||||
|
||||
.then(() => setEmulatorVoiceDataStateAndWait("voice", "roaming"))
|
||||
.then(() => check(aLongName, aShortName, aRoaming))
|
||||
.then(() => setEmulatorVoiceDataStateAndWait("voice", "home"));
|
||||
}
|
||||
|
||||
startTestCommon(function() {
|
||||
return getEmulatorOperatorNames()
|
||||
.then(function(aOperators) {
|
||||
let {longName: longName, shortName: shortName} = aOperators[0];
|
||||
|
||||
return Promise.resolve()
|
||||
|
||||
// If Either long name or short name of current registered operator
|
||||
// matches SPN("Android"), then the `roaming` attribute should be set
|
||||
// to false.
|
||||
.then(() => test(longName, shortName, false))
|
||||
.then(() => test(longName, shortName.toLowerCase(), false))
|
||||
.then(() => test(longName, "Bar", false))
|
||||
.then(() => test(longName.toLowerCase(), shortName, false))
|
||||
.then(() => test(longName.toLowerCase(), shortName.toLowerCase(), false))
|
||||
.then(() => test(longName.toLowerCase(), "Bar", false))
|
||||
.then(() => test("Foo", shortName, false))
|
||||
.then(() => test("Foo", shortName.toLowerCase(), false))
|
||||
.then(() => test("Foo", "Bar", true))
|
||||
|
||||
// Reset roaming operator.
|
||||
.then(() => setEmulatorOperatorNamesAndWait("roaming",
|
||||
aOperators[1].longName,
|
||||
aOperators[1].shortName));
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user