1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/mobileconnection/tests/marionette/test_mobile_data_ipv6.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,128 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +MARIONETTE_TIMEOUT = 60000; 1.8 +MARIONETTE_HEAD_JS = "head.js"; 1.9 + 1.10 +/** 1.11 + * Test resulting IP address format with given APN settings. 1.12 + * 1.13 + * This test utility function performs following steps: 1.14 + * 1.15 + * 1) set "ril.data.apnSettings" to a given settings object, 1.16 + * 2) enable data connection and wait for a "datachange" event, 1.17 + * 3) check the IP address type of the active network interface, 1.18 + * 4) disable data connection. 1.19 + * 1.20 + * Fulfill params: (none) 1.21 + * Reject params: (none) 1.22 + * 1.23 + * @param aApnSettings 1.24 + * An APN settings value. 1.25 + * @param aIsIPv6 1.26 + * A boolean value indicating whether we're expecting an IPv6 address. 1.27 + * 1.28 + * @return A deferred promise. 1.29 + */ 1.30 +function doTest(aApnSettings, aHaveV4Address, aHaveV6Address) { 1.31 + return setDataApnSettings([]) 1.32 + .then(() => setDataApnSettings(aApnSettings)) 1.33 + .then(() => setDataEnabledAndWait(true)) 1.34 + .then(function() { 1.35 + let nm = getNetworkManager(); 1.36 + let active = nm.active; 1.37 + ok(active, "Active network interface"); 1.38 + log(" Interface: " + active.name); 1.39 + 1.40 + let ips = {}, prefixLengths = {}; 1.41 + let num = active.getAddresses(ips, prefixLengths); 1.42 + log(" Num addresses: " + num); 1.43 + log(" Addresses: " + JSON.stringify(ips.value)); 1.44 + log(" PrefixLengths: " + JSON.stringify(prefixLengths.value)); 1.45 + 1.46 + if (aHaveV4Address) { 1.47 + ok(ips.value.reduce(function(aFound, aAddress) { 1.48 + return aFound || aAddress.indexOf(":") < 0; 1.49 + }), "IPv4 address"); 1.50 + } 1.51 + if (aHaveV6Address) { 1.52 + ok(ips.value.reduce(function(aFound, aAddress) { 1.53 + return aFound || aAddress.indexOf(":") > 0; 1.54 + }), "IPv6 address"); 1.55 + } 1.56 + }) 1.57 + .then(() => setDataEnabledAndWait(false)); 1.58 +} 1.59 + 1.60 +function doTestHome(aApnSettings, aProtocol) { 1.61 + log("Testing \"" + aProtocol + "\"@HOME... "); 1.62 + 1.63 + // aApnSettings is a double-array of per PDP context settings. The first 1.64 + // index is a DSDS service ID, and the second one is the index of pre-defined 1.65 + // PDP context settings of a specified radio interface. We use 0 for both as 1.66 + // default here. 1.67 + aApnSettings[0][0].protocol = aProtocol; 1.68 + delete aApnSettings[0][0].roaming_protocol; 1.69 + 1.70 + return doTest(aApnSettings, 1.71 + aProtocol === "IP" || aProtocol === "IPV4V6", 1.72 + aProtocol === "IPV4V6" || aProtocol === "IPV6"); 1.73 +} 1.74 + 1.75 +function doTestRoaming(aApnSettings, aRoaminProtocol) { 1.76 + log("Testing \"" + aRoaminProtocol + "\"@ROMAING... "); 1.77 + 1.78 + // aApnSettings is a double-array of per PDP context settings. The first 1.79 + // index is a DSDS service ID, and the second one is the index of pre-defined 1.80 + // PDP context settings of a specified radio interface. We use 0 for both as 1.81 + // default here. 1.82 + delete aApnSettings[0][0].protocol; 1.83 + aApnSettings[0][0].roaming_protocol = aRoaminProtocol; 1.84 + 1.85 + return doTest(aApnSettings, 1.86 + aRoaminProtocol === "IP" || aRoaminProtocol === "IPV4V6", 1.87 + aRoaminProtocol === "IPV4V6" || aRoaminProtocol === "IPV6"); 1.88 +} 1.89 + 1.90 +startTestCommon(function() { 1.91 + let origApnSettings; 1.92 + 1.93 + return setDataRoamingEnabled(true) 1.94 + .then(getDataApnSettings) 1.95 + .then(function(aResult) { 1.96 + // If already set, then save original APN settings. 1.97 + origApnSettings = JSON.parse(JSON.stringify(aResult)); 1.98 + return aResult; 1.99 + }, function() { 1.100 + // Return our own default value. 1.101 + return [[{ "carrier": "T-Mobile US", 1.102 + "apn": "epc.tmobile.com", 1.103 + "mmsc": "http://mms.msg.eng.t-mobile.com/mms/wapenc", 1.104 + "types": ["default", "supl", "mms"] }]]; 1.105 + }) 1.106 + 1.107 + .then(function(aApnSettings) { 1.108 + return Promise.resolve() 1.109 + 1.110 + .then(() => doTestHome(aApnSettings, "NoSuchProtocol")) 1.111 + .then(() => doTestHome(aApnSettings, "IP")) 1.112 + .then(() => doTestHome(aApnSettings, "IPV4V6")) 1.113 + .then(() => doTestHome(aApnSettings, "IPV6")) 1.114 + 1.115 + .then(() => setEmulatorRoamingAndWait(true)) 1.116 + 1.117 + .then(() => doTestRoaming(aApnSettings, "NoSuchProtocol")) 1.118 + .then(() => doTestRoaming(aApnSettings, "IP")) 1.119 + .then(() => doTestRoaming(aApnSettings, "IPV4V6")) 1.120 + .then(() => doTestRoaming(aApnSettings, "IPV6")) 1.121 + 1.122 + .then(() => setEmulatorRoamingAndWait(false)); 1.123 + }) 1.124 + 1.125 + .then(() => setDataRoamingEnabled(false)) 1.126 + .then(function() { 1.127 + if (origApnSettings) { 1.128 + return setDataApnSettings(origApnSettings); 1.129 + } 1.130 + }); 1.131 +}, ["settings-read", "settings-write"]);