michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: MARIONETTE_TIMEOUT = 60000; michael@0: MARIONETTE_HEAD_JS = "head.js"; michael@0: michael@0: /** michael@0: * Test resulting IP address format with given APN settings. michael@0: * michael@0: * This test utility function performs following steps: michael@0: * michael@0: * 1) set "ril.data.apnSettings" to a given settings object, michael@0: * 2) enable data connection and wait for a "datachange" event, michael@0: * 3) check the IP address type of the active network interface, michael@0: * 4) disable data connection. michael@0: * michael@0: * Fulfill params: (none) michael@0: * Reject params: (none) michael@0: * michael@0: * @param aApnSettings michael@0: * An APN settings value. michael@0: * @param aIsIPv6 michael@0: * A boolean value indicating whether we're expecting an IPv6 address. michael@0: * michael@0: * @return A deferred promise. michael@0: */ michael@0: function doTest(aApnSettings, aHaveV4Address, aHaveV6Address) { michael@0: return setDataApnSettings([]) michael@0: .then(() => setDataApnSettings(aApnSettings)) michael@0: .then(() => setDataEnabledAndWait(true)) michael@0: .then(function() { michael@0: let nm = getNetworkManager(); michael@0: let active = nm.active; michael@0: ok(active, "Active network interface"); michael@0: log(" Interface: " + active.name); michael@0: michael@0: let ips = {}, prefixLengths = {}; michael@0: let num = active.getAddresses(ips, prefixLengths); michael@0: log(" Num addresses: " + num); michael@0: log(" Addresses: " + JSON.stringify(ips.value)); michael@0: log(" PrefixLengths: " + JSON.stringify(prefixLengths.value)); michael@0: michael@0: if (aHaveV4Address) { michael@0: ok(ips.value.reduce(function(aFound, aAddress) { michael@0: return aFound || aAddress.indexOf(":") < 0; michael@0: }), "IPv4 address"); michael@0: } michael@0: if (aHaveV6Address) { michael@0: ok(ips.value.reduce(function(aFound, aAddress) { michael@0: return aFound || aAddress.indexOf(":") > 0; michael@0: }), "IPv6 address"); michael@0: } michael@0: }) michael@0: .then(() => setDataEnabledAndWait(false)); michael@0: } michael@0: michael@0: function doTestHome(aApnSettings, aProtocol) { michael@0: log("Testing \"" + aProtocol + "\"@HOME... "); michael@0: michael@0: // aApnSettings is a double-array of per PDP context settings. The first michael@0: // index is a DSDS service ID, and the second one is the index of pre-defined michael@0: // PDP context settings of a specified radio interface. We use 0 for both as michael@0: // default here. michael@0: aApnSettings[0][0].protocol = aProtocol; michael@0: delete aApnSettings[0][0].roaming_protocol; michael@0: michael@0: return doTest(aApnSettings, michael@0: aProtocol === "IP" || aProtocol === "IPV4V6", michael@0: aProtocol === "IPV4V6" || aProtocol === "IPV6"); michael@0: } michael@0: michael@0: function doTestRoaming(aApnSettings, aRoaminProtocol) { michael@0: log("Testing \"" + aRoaminProtocol + "\"@ROMAING... "); michael@0: michael@0: // aApnSettings is a double-array of per PDP context settings. The first michael@0: // index is a DSDS service ID, and the second one is the index of pre-defined michael@0: // PDP context settings of a specified radio interface. We use 0 for both as michael@0: // default here. michael@0: delete aApnSettings[0][0].protocol; michael@0: aApnSettings[0][0].roaming_protocol = aRoaminProtocol; michael@0: michael@0: return doTest(aApnSettings, michael@0: aRoaminProtocol === "IP" || aRoaminProtocol === "IPV4V6", michael@0: aRoaminProtocol === "IPV4V6" || aRoaminProtocol === "IPV6"); michael@0: } michael@0: michael@0: startTestCommon(function() { michael@0: let origApnSettings; michael@0: michael@0: return setDataRoamingEnabled(true) michael@0: .then(getDataApnSettings) michael@0: .then(function(aResult) { michael@0: // If already set, then save original APN settings. michael@0: origApnSettings = JSON.parse(JSON.stringify(aResult)); michael@0: return aResult; michael@0: }, function() { michael@0: // Return our own default value. michael@0: return [[{ "carrier": "T-Mobile US", michael@0: "apn": "epc.tmobile.com", michael@0: "mmsc": "http://mms.msg.eng.t-mobile.com/mms/wapenc", michael@0: "types": ["default", "supl", "mms"] }]]; michael@0: }) michael@0: michael@0: .then(function(aApnSettings) { michael@0: return Promise.resolve() michael@0: michael@0: .then(() => doTestHome(aApnSettings, "NoSuchProtocol")) michael@0: .then(() => doTestHome(aApnSettings, "IP")) michael@0: .then(() => doTestHome(aApnSettings, "IPV4V6")) michael@0: .then(() => doTestHome(aApnSettings, "IPV6")) michael@0: michael@0: .then(() => setEmulatorRoamingAndWait(true)) michael@0: michael@0: .then(() => doTestRoaming(aApnSettings, "NoSuchProtocol")) michael@0: .then(() => doTestRoaming(aApnSettings, "IP")) michael@0: .then(() => doTestRoaming(aApnSettings, "IPV4V6")) michael@0: .then(() => doTestRoaming(aApnSettings, "IPV6")) michael@0: michael@0: .then(() => setEmulatorRoamingAndWait(false)); michael@0: }) michael@0: michael@0: .then(() => setDataRoamingEnabled(false)) michael@0: .then(function() { michael@0: if (origApnSettings) { michael@0: return setDataApnSettings(origApnSettings); michael@0: } michael@0: }); michael@0: }, ["settings-read", "settings-write"]);