|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 MARIONETTE_TIMEOUT = 60000; |
|
5 MARIONETTE_HEAD_JS = "head.js"; |
|
6 |
|
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); |
|
36 |
|
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)); |
|
42 |
|
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 } |
|
56 |
|
57 function doTestHome(aApnSettings, aProtocol) { |
|
58 log("Testing \"" + aProtocol + "\"@HOME... "); |
|
59 |
|
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; |
|
66 |
|
67 return doTest(aApnSettings, |
|
68 aProtocol === "IP" || aProtocol === "IPV4V6", |
|
69 aProtocol === "IPV4V6" || aProtocol === "IPV6"); |
|
70 } |
|
71 |
|
72 function doTestRoaming(aApnSettings, aRoaminProtocol) { |
|
73 log("Testing \"" + aRoaminProtocol + "\"@ROMAING... "); |
|
74 |
|
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; |
|
81 |
|
82 return doTest(aApnSettings, |
|
83 aRoaminProtocol === "IP" || aRoaminProtocol === "IPV4V6", |
|
84 aRoaminProtocol === "IPV4V6" || aRoaminProtocol === "IPV6"); |
|
85 } |
|
86 |
|
87 startTestCommon(function() { |
|
88 let origApnSettings; |
|
89 |
|
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 }) |
|
103 |
|
104 .then(function(aApnSettings) { |
|
105 return Promise.resolve() |
|
106 |
|
107 .then(() => doTestHome(aApnSettings, "NoSuchProtocol")) |
|
108 .then(() => doTestHome(aApnSettings, "IP")) |
|
109 .then(() => doTestHome(aApnSettings, "IPV4V6")) |
|
110 .then(() => doTestHome(aApnSettings, "IPV6")) |
|
111 |
|
112 .then(() => setEmulatorRoamingAndWait(true)) |
|
113 |
|
114 .then(() => doTestRoaming(aApnSettings, "NoSuchProtocol")) |
|
115 .then(() => doTestRoaming(aApnSettings, "IP")) |
|
116 .then(() => doTestRoaming(aApnSettings, "IPV4V6")) |
|
117 .then(() => doTestRoaming(aApnSettings, "IPV6")) |
|
118 |
|
119 .then(() => setEmulatorRoamingAndWait(false)); |
|
120 }) |
|
121 |
|
122 .then(() => setDataRoamingEnabled(false)) |
|
123 .then(function() { |
|
124 if (origApnSettings) { |
|
125 return setDataApnSettings(origApnSettings); |
|
126 } |
|
127 }); |
|
128 }, ["settings-read", "settings-write"]); |