dom/mobileconnection/tests/marionette/test_mobile_data_ipv6.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 MARIONETTE_TIMEOUT = 60000;
     5 MARIONETTE_HEAD_JS = "head.js";
     7 /**
     8  * Test resulting IP address format with given APN settings.
     9  *
    10  * This test utility function performs following steps:
    11  *
    12  *   1) set "ril.data.apnSettings" to a given settings object,
    13  *   2) enable data connection and wait for a "datachange" event,
    14  *   3) check the IP address type of the active network interface,
    15  *   4) disable data connection.
    16  *
    17  * Fulfill params: (none)
    18  * Reject params: (none)
    19  *
    20  * @param aApnSettings
    21  *        An APN settings value.
    22  * @param aIsIPv6
    23  *        A boolean value indicating whether we're expecting an IPv6 address.
    24  *
    25  * @return A deferred promise.
    26  */
    27 function doTest(aApnSettings, aHaveV4Address, aHaveV6Address) {
    28   return setDataApnSettings([])
    29     .then(() => setDataApnSettings(aApnSettings))
    30     .then(() => setDataEnabledAndWait(true))
    31     .then(function() {
    32       let nm = getNetworkManager();
    33       let active = nm.active;
    34       ok(active, "Active network interface");
    35       log("  Interface: " + active.name);
    37       let ips = {}, prefixLengths = {};
    38       let num = active.getAddresses(ips, prefixLengths);
    39       log("  Num addresses: " + num);
    40       log("  Addresses: " + JSON.stringify(ips.value));
    41       log("  PrefixLengths: " + JSON.stringify(prefixLengths.value));
    43       if (aHaveV4Address) {
    44         ok(ips.value.reduce(function(aFound, aAddress) {
    45           return aFound || aAddress.indexOf(":") < 0;
    46         }), "IPv4 address");
    47       }
    48       if (aHaveV6Address) {
    49         ok(ips.value.reduce(function(aFound, aAddress) {
    50           return aFound || aAddress.indexOf(":") > 0;
    51         }), "IPv6 address");
    52       }
    53     })
    54     .then(() => setDataEnabledAndWait(false));
    55 }
    57 function doTestHome(aApnSettings, aProtocol) {
    58   log("Testing \"" + aProtocol + "\"@HOME... ");
    60   // aApnSettings is a double-array of per PDP context settings.  The first
    61   // index is a DSDS service ID, and the second one is the index of pre-defined
    62   // PDP context settings of a specified radio interface.  We use 0 for both as
    63   // default here.
    64   aApnSettings[0][0].protocol = aProtocol;
    65   delete aApnSettings[0][0].roaming_protocol;
    67   return doTest(aApnSettings,
    68                 aProtocol === "IP" || aProtocol === "IPV4V6",
    69                 aProtocol === "IPV4V6" || aProtocol === "IPV6");
    70 }
    72 function doTestRoaming(aApnSettings, aRoaminProtocol) {
    73   log("Testing \"" + aRoaminProtocol + "\"@ROMAING... ");
    75   // aApnSettings is a double-array of per PDP context settings.  The first
    76   // index is a DSDS service ID, and the second one is the index of pre-defined
    77   // PDP context settings of a specified radio interface.  We use 0 for both as
    78   // default here.
    79   delete aApnSettings[0][0].protocol;
    80   aApnSettings[0][0].roaming_protocol = aRoaminProtocol;
    82   return doTest(aApnSettings,
    83                 aRoaminProtocol === "IP" || aRoaminProtocol === "IPV4V6",
    84                 aRoaminProtocol === "IPV4V6" || aRoaminProtocol === "IPV6");
    85 }
    87 startTestCommon(function() {
    88   let origApnSettings;
    90   return setDataRoamingEnabled(true)
    91     .then(getDataApnSettings)
    92     .then(function(aResult) {
    93       // If already set, then save original APN settings.
    94       origApnSettings = JSON.parse(JSON.stringify(aResult));
    95       return aResult;
    96     }, function() {
    97       // Return our own default value.
    98       return [[{ "carrier": "T-Mobile US",
    99                  "apn": "epc.tmobile.com",
   100                  "mmsc": "http://mms.msg.eng.t-mobile.com/mms/wapenc",
   101                  "types": ["default", "supl", "mms"] }]];
   102     })
   104     .then(function(aApnSettings) {
   105       return Promise.resolve()
   107         .then(() => doTestHome(aApnSettings, "NoSuchProtocol"))
   108         .then(() => doTestHome(aApnSettings, "IP"))
   109         .then(() => doTestHome(aApnSettings, "IPV4V6"))
   110         .then(() => doTestHome(aApnSettings, "IPV6"))
   112         .then(() => setEmulatorRoamingAndWait(true))
   114         .then(() => doTestRoaming(aApnSettings, "NoSuchProtocol"))
   115         .then(() => doTestRoaming(aApnSettings, "IP"))
   116         .then(() => doTestRoaming(aApnSettings, "IPV4V6"))
   117         .then(() => doTestRoaming(aApnSettings, "IPV6"))
   119         .then(() => setEmulatorRoamingAndWait(false));
   120     })
   122     .then(() => setDataRoamingEnabled(false))
   123     .then(function() {
   124       if (origApnSettings) {
   125         return setDataApnSettings(origApnSettings);
   126       }
   127     });
   128 }, ["settings-read", "settings-write"]);

mercurial