From e458fc0332eeb33b43ded6b2b8afe1613cb6de96 Mon Sep 17 00:00:00 2001 From: Edgar Chen Date: Wed, 8 Apr 2015 18:34:11 +0800 Subject: [PATCH] Bug 1149829 - Fix the issue in RIL NetworkInterface and add test case for NetworkInterfaceListService. r=hsinyi --- dom/system/gonk/RadioInterfaceLayer.js | 13 ++- dom/system/gonk/tests/marionette/head.js | 10 +- dom/system/gonk/tests/marionette/manifest.ini | 1 + .../test_network_interface_list_service.js | 95 +++++++++++++++++++ 4 files changed, 113 insertions(+), 6 deletions(-) create mode 100644 dom/system/gonk/tests/marionette/test_network_interface_list_service.js diff --git a/dom/system/gonk/RadioInterfaceLayer.js b/dom/system/gonk/RadioInterfaceLayer.js index fd1057818c2..9eedef4f283 100644 --- a/dom/system/gonk/RadioInterfaceLayer.js +++ b/dom/system/gonk/RadioInterfaceLayer.js @@ -2923,12 +2923,16 @@ DataCall.prototype = { return isIdentical; }, - reset: function() { + resetLinkInfo: function() { this.linkInfo.cid = null; this.linkInfo.ifname = null; this.linkInfo.addresses = []; this.linkInfo.dnses = []; this.linkInfo.gateways = []; + }, + + reset: function() { + this.resetLinkInfo(); this.state = RIL.GECKO_NETWORK_STATE_UNKNOWN; @@ -3099,7 +3103,7 @@ DataCall.prototype = { deactivate: function() { let reason = RIL.DATACALL_DEACTIVATE_NO_REASON; 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); radioInterface.sendWorkerMessage("deactivateDataCall", { @@ -3108,6 +3112,7 @@ DataCall.prototype = { }, this.onDeactivateDataCallResult.bind(this)); this.state = RIL.GECKO_NETWORK_STATE_DISCONNECTING; + this.resetLinkInfo(); }, // 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++) { let [ip, prefixLength] = addresses[i].split("/"); ips.push(ip); - prefixLengths.push(); + prefixLengths.push(prefixLength); } aIps.value = ips.slice(); aPrefixLengths.value = prefixLengths.slice(); - return aIps.length; + return ips.length; }, getGateways: function(aCount) { diff --git a/dom/system/gonk/tests/marionette/head.js b/dom/system/gonk/tests/marionette/head.js index 6f3fdc55888..4e3fc91f71e 100644 --- a/dom/system/gonk/tests/marionette/head.js +++ b/dom/system/gonk/tests/marionette/head.js @@ -9,6 +9,12 @@ const SETTINGS_KEY_DATA_APN_SETTINGS = "ril.data.apnSettings"; const TOPIC_CONNECTION_STATE_CHANGED = "network-connection-state-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_MMS = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS; const NETWORK_TYPE_MOBILE_SUPL = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL; @@ -219,8 +225,8 @@ function deactivateDataCallAndWait(aNetworkType) { function startTestBase(aTestCaseMain) { Promise.resolve() .then(aTestCaseMain) - .then(finish, function() { - ok(false, 'promise rejects during test.'); + .then(finish, function(aException) { + ok(false, "promise rejects during test: " + aException); finish(); }); } diff --git a/dom/system/gonk/tests/marionette/manifest.ini b/dom/system/gonk/tests/marionette/manifest.ini index 88d42aa245a..96c8250516e 100644 --- a/dom/system/gonk/tests/marionette/manifest.ini +++ b/dom/system/gonk/tests/marionette/manifest.ini @@ -13,3 +13,4 @@ disabled = Bug 808783 [test_network_active_changed.js] [test_multiple_data_connection.js] [test_data_connection_proxy.js] +[test_network_interface_list_service.js] diff --git a/dom/system/gonk/tests/marionette/test_network_interface_list_service.js b/dom/system/gonk/tests/marionette/test_network_interface_list_service.js new file mode 100644 index 00000000000..37fa9135577 --- /dev/null +++ b/dom/system/gonk/tests/marionette/test_network_interface_list_service.js @@ -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)); +});