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