Bug 1149829 - Fix the issue in RIL NetworkInterface and add test case for NetworkInterfaceListService. r=hsinyi

This commit is contained in:
Edgar Chen 2015-04-08 18:34:11 +08:00
parent 2d32a9ffc5
commit e458fc0332
4 changed files with 113 additions and 6 deletions

View File

@ -2923,12 +2923,16 @@ DataCall.prototype = {
return isIdentical; return isIdentical;
}, },
reset: function() { resetLinkInfo: function() {
this.linkInfo.cid = null; this.linkInfo.cid = null;
this.linkInfo.ifname = null; this.linkInfo.ifname = null;
this.linkInfo.addresses = []; this.linkInfo.addresses = [];
this.linkInfo.dnses = []; this.linkInfo.dnses = [];
this.linkInfo.gateways = []; this.linkInfo.gateways = [];
},
reset: function() {
this.resetLinkInfo();
this.state = RIL.GECKO_NETWORK_STATE_UNKNOWN; this.state = RIL.GECKO_NETWORK_STATE_UNKNOWN;
@ -3099,7 +3103,7 @@ DataCall.prototype = {
deactivate: function() { deactivate: function() {
let reason = RIL.DATACALL_DEACTIVATE_NO_REASON; let reason = RIL.DATACALL_DEACTIVATE_NO_REASON;
if (DEBUG) { if (DEBUG) {
this.debug("Going to disconnet data connection cid " + this.linkInfo.cid); this.debug("Going to disconnect data connection cid " + this.linkInfo.cid);
} }
let radioInterface = this.gRIL.getRadioInterface(this.clientId); let radioInterface = this.gRIL.getRadioInterface(this.clientId);
radioInterface.sendWorkerMessage("deactivateDataCall", { radioInterface.sendWorkerMessage("deactivateDataCall", {
@ -3108,6 +3112,7 @@ DataCall.prototype = {
}, this.onDeactivateDataCallResult.bind(this)); }, this.onDeactivateDataCallResult.bind(this));
this.state = RIL.GECKO_NETWORK_STATE_DISCONNECTING; this.state = RIL.GECKO_NETWORK_STATE_DISCONNECTING;
this.resetLinkInfo();
}, },
// Entry method for timer events. Used to reconnect to a failed APN // Entry method for timer events. Used to reconnect to a failed APN
@ -3184,13 +3189,13 @@ RILNetworkInterface.prototype = {
for (let i = 0; i < addresses.length; i++) { for (let i = 0; i < addresses.length; i++) {
let [ip, prefixLength] = addresses[i].split("/"); let [ip, prefixLength] = addresses[i].split("/");
ips.push(ip); ips.push(ip);
prefixLengths.push(); prefixLengths.push(prefixLength);
} }
aIps.value = ips.slice(); aIps.value = ips.slice();
aPrefixLengths.value = prefixLengths.slice(); aPrefixLengths.value = prefixLengths.slice();
return aIps.length; return ips.length;
}, },
getGateways: function(aCount) { getGateways: function(aCount) {

View File

@ -9,6 +9,12 @@ const SETTINGS_KEY_DATA_APN_SETTINGS = "ril.data.apnSettings";
const TOPIC_CONNECTION_STATE_CHANGED = "network-connection-state-changed"; const TOPIC_CONNECTION_STATE_CHANGED = "network-connection-state-changed";
const TOPIC_NETWORK_ACTIVE_CHANGED = "network-active-changed"; const TOPIC_NETWORK_ACTIVE_CHANGED = "network-active-changed";
const NETWORK_STATE_UNKNOWN = Ci.nsINetworkInterface.NETWORK_STATE_UNKNOWN;
const NETWORK_STATE_CONNECTING = Ci.nsINetworkInterface.NETWORK_STATE_CONNECTING;
const NETWORK_STATE_CONNECTED = Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED;
const NETWORK_STATE_DISCONNECTING = Ci.nsINetworkInterface.NETWORK_STATE_DISCONNECTING;
const NETWORK_STATE_DISCONNECTED = Ci.nsINetworkInterface.NETWORK_STATE_DISCONNECTED;
const NETWORK_TYPE_MOBILE = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE; const NETWORK_TYPE_MOBILE = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE;
const NETWORK_TYPE_MOBILE_MMS = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS; const NETWORK_TYPE_MOBILE_MMS = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS;
const NETWORK_TYPE_MOBILE_SUPL = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL; const NETWORK_TYPE_MOBILE_SUPL = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL;
@ -219,8 +225,8 @@ function deactivateDataCallAndWait(aNetworkType) {
function startTestBase(aTestCaseMain) { function startTestBase(aTestCaseMain) {
Promise.resolve() Promise.resolve()
.then(aTestCaseMain) .then(aTestCaseMain)
.then(finish, function() { .then(finish, function(aException) {
ok(false, 'promise rejects during test.'); ok(false, "promise rejects during test: " + aException);
finish(); finish();
}); });
} }

View File

@ -13,3 +13,4 @@ disabled = Bug 808783
[test_network_active_changed.js] [test_network_active_changed.js]
[test_multiple_data_connection.js] [test_multiple_data_connection.js]
[test_data_connection_proxy.js] [test_data_connection_proxy.js]
[test_network_interface_list_service.js]

View File

@ -0,0 +1,95 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 60000;
MARIONETTE_HEAD_JS = "head.js";
function getNetworkInterface(aType) {
let networkListService =
Cc["@mozilla.org/network/interface-list-service;1"].
getService(Ci.nsINetworkInterfaceListService);
// Get all available interfaces
let networkList = networkListService.getDataInterfaceList(0);
// Try to get nsINetworkInterface for aType.
let numberOfInterface = networkList.getNumberOfInterface();
for (let i = 0; i < numberOfInterface; i++) {
let iface = networkList.getInterface(i);
if (iface.type === aType) {
return iface;
}
}
return null;
}
// Test getDataInterfaceList by enabling/disabling mobile data.
function testGetDataInterfaceList(aMobileDataEnabled) {
log("Test getDataInterfaceList with mobile data " +
aMobileDataEnabled ? "enabled" : "disabled");
return setDataEnabledAndWait(aMobileDataEnabled)
.then(() => getNetworkInterface(NETWORK_TYPE_MOBILE))
.then((networkInterface) => {
if (!networkInterface) {
ok(false, "Should get an valid nsINetworkInterface for mobile");
return;
}
ok(networkInterface instanceof Ci.nsINetworkInterface,
"networkInterface should be an instance of nsINetworkInterface");
let ipAddresses = {};
let prefixs = {};
let numOfGateways = {};
let numOfDnses = {};
let numOfIpAddresses = networkInterface.getAddresses(ipAddresses, prefixs);
let gateways = networkInterface.getGateways(numOfGateways);
let dnses = networkInterface.getDnses(numOfDnses);
if (aMobileDataEnabled) {
// Mobile data is enabled.
is(networkInterface.state, NETWORK_STATE_CONNECTED, "check state");
ok(numOfIpAddresses > 0, "check number of ipAddresses");
ok(ipAddresses.value.length > 0, "check ipAddresses.length");
ok(prefixs.value.length > 0, "check prefixs.length");
ok(numOfGateways.value > 0, "check number of gateways");
ok(prefixs.value.length > 0, "check prefixs.length");
ok(gateways.length > 0, "check gateways.length");
ok(numOfDnses.value > 0, "check number of dnses");
ok(dnses.length > 0, "check dnses.length");
} else {
// Mobile data is disabled.
is(networkInterface.state, NETWORK_STATE_DISCONNECTED, "check state");
is(numOfIpAddresses, 0, "check number of ipAddresses");
is(ipAddresses.value.length, 0, "check ipAddresses.length");
is(prefixs.value.length, 0, "check prefixs.length");
is(numOfGateways.value, 0, "check number of gateways");
is(prefixs.value.length, 0, "check prefixs.length");
is(gateways.length, 0, "check gateways.length");
is(numOfDnses.value, 0, "check number of dnses");
is(dnses.length, 0, "check dnses.length");
}
});
}
// Start test
startTestBase(function() {
return Promise.resolve()
// Test initial State
.then(() => {
log("Test initial state");
// Data should be off before starting any test.
return getSettings(SETTINGS_KEY_DATA_ENABLED)
.then(value => {
is(value, false, "Mobile data must be off");
});
})
// Test getDataInterfaceList with mobile data enabled.
.then(() => testGetDataInterfaceList(true))
// Test getDataInterfaceList with mobile data disabled.
.then(() => testGetDataInterfaceList(false));
});