1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/mobilemessage/tests/test_mms_pdu_helper.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,1029 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +let MMS = {}; 1.8 +subscriptLoader.loadSubScript("resource://gre/modules/MmsPduHelper.jsm", MMS); 1.9 +MMS.debug = do_print; 1.10 + 1.11 +function run_test() { 1.12 + run_next_test(); 1.13 +} 1.14 + 1.15 +// 1.16 +// Test target: BooleanValue 1.17 +// 1.18 + 1.19 +//// BooleanValue.decode //// 1.20 + 1.21 +add_test(function test_BooleanValue_decode() { 1.22 + for (let i = 0; i < 256; i++) { 1.23 + if (i == 128) { 1.24 + wsp_decode_test(MMS.BooleanValue, [128], true); 1.25 + } else if (i == 129) { 1.26 + wsp_decode_test(MMS.BooleanValue, [129], false); 1.27 + } else { 1.28 + wsp_decode_test(MMS.BooleanValue, [i], null, "CodeError"); 1.29 + } 1.30 + } 1.31 + 1.32 + run_next_test(); 1.33 +}); 1.34 + 1.35 +//// BooleanValue.encode //// 1.36 + 1.37 +add_test(function test_BooleanValue_encode() { 1.38 + wsp_encode_test(MMS.BooleanValue, true, [128]); 1.39 + wsp_encode_test(MMS.BooleanValue, false, [129]); 1.40 + 1.41 + run_next_test(); 1.42 +}); 1.43 + 1.44 +// 1.45 +// Test target: Address 1.46 +// 1.47 + 1.48 +//// Address.decode //// 1.49 + 1.50 +add_test(function test_Address_decode() { 1.51 + // Test for PLMN address 1.52 + wsp_decode_test(MMS.Address, strToCharCodeArray("+123.456-789/TYPE=PLMN"), 1.53 + {address: "+123.456-789", type: "PLMN"}); 1.54 + wsp_decode_test(MMS.Address, strToCharCodeArray("123456789/TYPE=PLMN"), 1.55 + {address: "123456789", type: "PLMN"}); 1.56 + // Test for IPv4 1.57 + wsp_decode_test(MMS.Address, strToCharCodeArray("1.2.3.4/TYPE=IPv4"), 1.58 + {address: "1.2.3.4", type: "IPv4"}); 1.59 + // Test for IPv6 1.60 + wsp_decode_test(MMS.Address, 1.61 + strToCharCodeArray("1111:AAAA:bbbb:CdEf:1ABC:2cde:3Def:0000/TYPE=IPv6"), 1.62 + {address: "1111:AAAA:bbbb:CdEf:1ABC:2cde:3Def:0000", type: "IPv6"} 1.63 + ); 1.64 + // Test for other device-address 1.65 + wsp_decode_test(MMS.Address, strToCharCodeArray("+H-e.l%l_o/TYPE=W0r1d_"), 1.66 + {address: "+H-e.l%l_o", type: "W0r1d_"}); 1.67 + // Test for num-shortcode 1.68 + wsp_decode_test(MMS.Address, strToCharCodeArray("+123"), 1.69 + {address: "+123", type: "num"}); 1.70 + wsp_decode_test(MMS.Address, strToCharCodeArray("*123"), 1.71 + {address: "*123", type: "num"}); 1.72 + wsp_decode_test(MMS.Address, strToCharCodeArray("#123"), 1.73 + {address: "#123", type: "num"}); 1.74 + // Test for alphanum-shortcode 1.75 + wsp_decode_test(MMS.Address, strToCharCodeArray("H0wD0Y0uTurnTh1s0n"), 1.76 + {address: "H0wD0Y0uTurnTh1s0n", type: "alphanum"}); 1.77 + // Test for email address 1.78 + wsp_decode_test(MMS.Address, strToCharCodeArray("Joe User <joe@user.org>"), 1.79 + {address: "Joe User <joe@user.org>", type: "email"}); 1.80 + // Test for invalid address 1.81 + wsp_decode_test(MMS.Address, strToCharCodeArray("@@@@@"), 1.82 + null, "CodeError"); 1.83 + 1.84 + run_next_test(); 1.85 +}); 1.86 + 1.87 +//// Address.encode //// 1.88 + 1.89 +add_test(function test_Address_encode() { 1.90 + // Test for PLMN address 1.91 + wsp_encode_test(MMS.Address, {address: "+123.456-789", type: "PLMN"}, 1.92 + strToCharCodeArray("+123.456-789/TYPE=PLMN")); 1.93 + wsp_encode_test(MMS.Address, {address: "123456789", type: "PLMN"}, 1.94 + strToCharCodeArray("123456789/TYPE=PLMN")); 1.95 + // Test for IPv4 1.96 + wsp_encode_test(MMS.Address, {address: "1.2.3.4", type: "IPv4"}, 1.97 + strToCharCodeArray("1.2.3.4/TYPE=IPv4")); 1.98 + // Test for IPv6 1.99 + wsp_encode_test(MMS.Address, 1.100 + {address: "1111:AAAA:bbbb:CdEf:1ABC:2cde:3Def:0000", type: "IPv6"}, 1.101 + strToCharCodeArray("1111:AAAA:bbbb:CdEf:1ABC:2cde:3Def:0000/TYPE=IPv6") 1.102 + ); 1.103 + // Test for other device-address 1.104 + wsp_encode_test(MMS.Address, {address: "+H-e.l%l_o", type: "W0r1d_"}, 1.105 + strToCharCodeArray("+H-e.l%l_o/TYPE=W0r1d_")); 1.106 + // Test for num-shortcode 1.107 + wsp_encode_test(MMS.Address, {address: "+123", type: "num"}, 1.108 + strToCharCodeArray("+123")); 1.109 + wsp_encode_test(MMS.Address, {address: "*123", type: "num"}, 1.110 + strToCharCodeArray("*123")); 1.111 + wsp_encode_test(MMS.Address, {address: "#123", type: "num"}, 1.112 + strToCharCodeArray("#123")); 1.113 + // Test for alphanum-shortcode 1.114 + wsp_encode_test(MMS.Address, {address: "H0wD0Y0uTurnTh1s0n", type: "alphanum"}, 1.115 + strToCharCodeArray("H0wD0Y0uTurnTh1s0n")); 1.116 + // Test for email address 1.117 + wsp_encode_test(MMS.Address, {address: "Joe User <joe@user.org>", type: "email"}, 1.118 + strToCharCodeArray("Joe User <joe@user.org>")); 1.119 + 1.120 + run_next_test(); 1.121 +}); 1.122 + 1.123 +// 1.124 +// Test target: HeaderField 1.125 +// 1.126 + 1.127 +//// HeaderField.decode //// 1.128 + 1.129 +add_test(function test_HeaderField_decode() { 1.130 + wsp_decode_test(MMS.HeaderField, [65, 0, 66, 0], {name: "a", value: "B"}); 1.131 + wsp_decode_test(MMS.HeaderField, [0x80 | 0x27, 128], 1.132 + {name: "x-mms-stored", value: true}); 1.133 + 1.134 + run_next_test(); 1.135 +}); 1.136 + 1.137 +//// HeaderField.encode //// 1.138 + 1.139 +add_test(function test_HeaderField_encode() { 1.140 + // Test for MmsHeader 1.141 + wsp_encode_test(MMS.HeaderField, {name: "X-Mms-Message-Type", 1.142 + value: MMS_PDU_TYPE_SEND_REQ}, 1.143 + [0x80 | 0x0C, MMS_PDU_TYPE_SEND_REQ]); 1.144 + // Test for ApplicationHeader 1.145 + wsp_encode_test(MMS.HeaderField, {name: "a", value: "B"}, [97, 0, 66, 0]); 1.146 + 1.147 + run_next_test(); 1.148 +}); 1.149 + 1.150 +// 1.151 +// Test target: MmsHeader 1.152 +// 1.153 + 1.154 +//// MmsHeader.decode //// 1.155 + 1.156 +add_test(function test_MmsHeader_decode() { 1.157 + wsp_decode_test(MMS.MmsHeader, [0x80 | 0x00], null, "NotWellKnownEncodingError"); 1.158 + wsp_decode_test(MMS.MmsHeader, [0x80 | 0x27, 128], 1.159 + {name: "x-mms-stored", value: true}); 1.160 + wsp_decode_test(MMS.MmsHeader, [0x80 | 0x27, 255], null); 1.161 + 1.162 + run_next_test(); 1.163 +}); 1.164 + 1.165 +//// MmsHeader.encode //// 1.166 + 1.167 +add_test(function test_MmsHeader_encode() { 1.168 + // Test for empty header name: 1.169 + wsp_encode_test(MMS.MmsHeader, {name: undefined, value: null}, null, "CodeError"); 1.170 + wsp_encode_test(MMS.MmsHeader, {name: null, value: null}, null, "CodeError"); 1.171 + wsp_encode_test(MMS.MmsHeader, {name: "", value: null}, null, "CodeError"); 1.172 + // Test for non-well-known header name: 1.173 + wsp_encode_test(MMS.MmsHeader, {name: "X-No-Such-Field", value: null}, 1.174 + null, "NotWellKnownEncodingError"); 1.175 + // Test for normal header 1.176 + wsp_encode_test(MMS.MmsHeader, {name: "X-Mms-Message-Type", 1.177 + value: MMS_PDU_TYPE_SEND_REQ}, 1.178 + [0x80 | 0x0C, MMS_PDU_TYPE_SEND_REQ]); 1.179 + 1.180 + run_next_test(); 1.181 +}); 1.182 + 1.183 +// 1.184 +// Test target: CancelStatusValue 1.185 +// 1.186 + 1.187 +//// CancelStatusValue.decode //// 1.188 + 1.189 +add_test(function test_CancelStatusValue_decode() { 1.190 + for (let i = 0; i < 256; i++) { 1.191 + if ((i >= 128) && (i <= 129)) { 1.192 + wsp_decode_test(MMS.CancelStatusValue, [i], i); 1.193 + } else { 1.194 + wsp_decode_test(MMS.CancelStatusValue, [i], null, "CodeError"); 1.195 + } 1.196 + } 1.197 + 1.198 + run_next_test(); 1.199 +}); 1.200 + 1.201 +//// CancelStatusValue.encode //// 1.202 + 1.203 +add_test(function test_CancelStatusValue_encode() { 1.204 + for (let i = 0; i < 256; i++) { 1.205 + if ((i >= 128) && (i <= 129)) { 1.206 + wsp_encode_test(MMS.CancelStatusValue, i, [i]); 1.207 + } else { 1.208 + wsp_encode_test(MMS.CancelStatusValue, i, null, "CodeError"); 1.209 + } 1.210 + } 1.211 + 1.212 + run_next_test(); 1.213 +}); 1.214 + 1.215 +// 1.216 +// Test target: ContentClassValue 1.217 +// 1.218 + 1.219 +//// ContentClassValue.decode //// 1.220 + 1.221 +add_test(function test_ContentClassValue_decode() { 1.222 + for (let i = 0; i < 256; i++) { 1.223 + if ((i >= 128) && (i <= 135)) { 1.224 + wsp_decode_test(MMS.ContentClassValue, [i], i); 1.225 + } else { 1.226 + wsp_decode_test(MMS.ContentClassValue, [i], null, "CodeError"); 1.227 + } 1.228 + } 1.229 + 1.230 + run_next_test(); 1.231 +}); 1.232 + 1.233 +//// ContentClassValue.encode //// 1.234 + 1.235 +add_test(function test_ContentClassValue_encode() { 1.236 + for (let i = 0; i < 256; i++) { 1.237 + if ((i >= 128) && (i <= 135)) { 1.238 + wsp_encode_test(MMS.ContentClassValue, i, [i]); 1.239 + } else { 1.240 + wsp_encode_test(MMS.ContentClassValue, i, null, "CodeError"); 1.241 + } 1.242 + } 1.243 + 1.244 + run_next_test(); 1.245 +}); 1.246 + 1.247 +// 1.248 +// Test target: ContentLocationValue 1.249 +// 1.250 + 1.251 +//// ContentLocationValue.decode //// 1.252 + 1.253 +add_test(function test_ContentLocationValue_decode() { 1.254 + // Test for MMS_PDU_TYPE_MBOX_DELETE_CONF & MMS_PDU_TYPE_DELETE_CONF 1.255 + function test(type, statusCount, exception) { 1.256 + function decode(data) { 1.257 + let options = {}; 1.258 + if (type) { 1.259 + options["x-mms-message-type"] = type; 1.260 + } 1.261 + return MMS.ContentLocationValue.decode(data, options); 1.262 + } 1.263 + 1.264 + let uri = "http://no.such.com/path"; 1.265 + 1.266 + let data = strToCharCodeArray(uri); 1.267 + if (statusCount != null) { 1.268 + data = [data.length + 1, statusCount | 0x80].concat(data); 1.269 + } 1.270 + 1.271 + let expected; 1.272 + if (!exception) { 1.273 + expected = {}; 1.274 + if (statusCount != null) { 1.275 + expected.statusCount = statusCount; 1.276 + } 1.277 + expected.uri = uri; 1.278 + } 1.279 + 1.280 + do_print("data = " + JSON.stringify(data)); 1.281 + wsp_decode_test_ex(decode, data, expected, exception); 1.282 + } 1.283 + 1.284 + test(null, null, "FatalCodeError"); 1.285 + for (let type = MMS_PDU_TYPE_SEND_REQ; type <= MMS_PDU_TYPE_CANCEL_CONF; type++) { 1.286 + if ((type == MMS_PDU_TYPE_MBOX_DELETE_CONF) 1.287 + || (type == MMS_PDU_TYPE_DELETE_CONF)) { 1.288 + test(type, 1, null); 1.289 + } else { 1.290 + test(type, null, null); 1.291 + } 1.292 + } 1.293 + 1.294 + run_next_test(); 1.295 +}); 1.296 + 1.297 +// 1.298 +// Test target: ElementDescriptorValue 1.299 +// 1.300 + 1.301 +//// ElementDescriptorValue.decode //// 1.302 + 1.303 +add_test(function test_ElementDescriptorValue_decode() { 1.304 + wsp_decode_test(MMS.ElementDescriptorValue, [2, 97, 0], {contentReference: "a"}); 1.305 + wsp_decode_test(MMS.ElementDescriptorValue, [4, 97, 0, 0x80 | 0x02, 0x80], 1.306 + {contentReference: "a", params: {type: 0}}); 1.307 + 1.308 + run_next_test(); 1.309 +}); 1.310 + 1.311 +// 1.312 +// Test target: Parameter 1.313 +// 1.314 + 1.315 +//// Parameter.decodeParameterName //// 1.316 + 1.317 +add_test(function test_Parameter_decodeParameterName() { 1.318 + wsp_decode_test_ex(function(data) { 1.319 + return MMS.Parameter.decodeParameterName(data); 1.320 + }, [0x80 | 0x02], "type" 1.321 + ); 1.322 + wsp_decode_test_ex(function(data) { 1.323 + return MMS.Parameter.decodeParameterName(data); 1.324 + }, strToCharCodeArray("type"), "type" 1.325 + ); 1.326 + 1.327 + run_next_test(); 1.328 +}); 1.329 + 1.330 +//// Parameter.decode //// 1.331 + 1.332 +add_test(function test_Parameter_decode() { 1.333 + wsp_decode_test(MMS.Parameter, [0x80 | 0x02, 0x80 | 0x00], {name: "type", value: 0}); 1.334 + 1.335 + run_next_test(); 1.336 +}); 1.337 + 1.338 +//// Parameter.decodeMultiple //// 1.339 + 1.340 +add_test(function test_Parameter_decodeMultiple() { 1.341 + // FIXME: The following test case falls because Parameter-value decoding of 1.342 + // "type" parameters utilies WSP.ConstrainedEncoding, which in turn 1.343 + // utilies WSP.TextString, and TextString is not matual exclusive to 1.344 + // each other. 1.345 + //wsp_decode_test_ex(function(data) { 1.346 + // return MMS.Parameter.decodeMultiple(data, data.array.length); 1.347 + // }, [0x80 | 0x02, 0x80 | 0x00].concat(strToCharCodeArray("good")).concat([0x80 | 0x01]), 1.348 + // {type: 0, good: 1} 1.349 + //); 1.350 + 1.351 + run_next_test(); 1.352 +}); 1.353 + 1.354 +//// Parameter.encode //// 1.355 + 1.356 +add_test(function test_Parameter_encode() { 1.357 + // Test for invalid parameter value 1.358 + wsp_encode_test(MMS.Parameter, null, null, "CodeError"); 1.359 + wsp_encode_test(MMS.Parameter, undefined, null, "CodeError"); 1.360 + wsp_encode_test(MMS.Parameter, {}, null, "CodeError"); 1.361 + // Test for case-insensitive parameter name 1.362 + wsp_encode_test(MMS.Parameter, {name: "TYPE", value: 0}, [130, 128]); 1.363 + wsp_encode_test(MMS.Parameter, {name: "type", value: 0}, [130, 128]); 1.364 + // Test for non-well-known parameter name 1.365 + wsp_encode_test(MMS.Parameter, {name: "name", value: 0}, [110, 97, 109, 101, 0, 128]); 1.366 + // Test for constrained encoding value 1.367 + wsp_encode_test(MMS.Parameter, {name: "type", value: "0"}, [130, 48, 0]); 1.368 + 1.369 + run_next_test(); 1.370 +}); 1.371 + 1.372 +// 1.373 +// Test target: EncodedStringValue 1.374 +// 1.375 + 1.376 +//// EncodedStringValue.decode //// 1.377 + 1.378 +add_test(function test_EncodedStringValue_decode() { 1.379 + // Test for normal TextString 1.380 + wsp_decode_test(MMS.EncodedStringValue, strToCharCodeArray("Hello"), "Hello"); 1.381 + // Test for non-well-known charset 1.382 + wsp_decode_test(MMS.EncodedStringValue, [1, 0x80], null, "NotWellKnownEncodingError"); 1.383 + // Test for utf-8 1.384 + let (entry = MMS.WSP.WSP_WELL_KNOWN_CHARSETS["utf-8"]) { 1.385 + // "Mozilla" in full width. 1.386 + let str = "\uff2d\uff4f\uff5a\uff49\uff4c\uff4c\uff41"; 1.387 + 1.388 + let conv = Cc["@mozilla.org/intl/scriptableunicodeconverter"] 1.389 + .createInstance(Ci.nsIScriptableUnicodeConverter); 1.390 + conv.charset = entry.converter; 1.391 + 1.392 + let raw = conv.convertToByteArray(str).concat([0]); 1.393 + wsp_decode_test(MMS.EncodedStringValue, 1.394 + [raw.length + 2, 0x80 | entry.number, 127].concat(raw), str); 1.395 + } 1.396 + 1.397 + let (entry = MMS.WSP.WSP_WELL_KNOWN_CHARSETS["utf-16"]) { 1.398 + // "Mozilla" in full width. 1.399 + let str = "\u004d\u006F\u007A\u0069\u006C\u006C\u0061"; 1.400 + 1.401 + let conv = Cc["@mozilla.org/intl/scriptableunicodeconverter"] 1.402 + .createInstance(Ci.nsIScriptableUnicodeConverter); 1.403 + conv.charset = entry.converter; 1.404 + 1.405 + let raw = conv.convertToByteArray(str).concat([0]); 1.406 + wsp_decode_test(MMS.EncodedStringValue, 1.407 + [raw.length + 3, 2, 3, 247].concat(raw), str); 1.408 + } 1.409 + 1.410 + run_next_test(); 1.411 +}); 1.412 + 1.413 +//// EncodedStringValue.encode //// 1.414 + 1.415 +add_test(function test_EncodedStringValue_encode() { 1.416 + // Test for normal TextString 1.417 + wsp_encode_test(MMS.EncodedStringValue, "Hello", strToCharCodeArray("Hello")); 1.418 + 1.419 + // Test for utf-8 1.420 + let (entry = MMS.WSP.WSP_WELL_KNOWN_CHARSETS["utf-8"]) { 1.421 + // "Mozilla" in full width. 1.422 + let str = "\uff2d\uff4f\uff5a\uff49\uff4c\uff4c\uff41"; 1.423 + 1.424 + let conv = Cc["@mozilla.org/intl/scriptableunicodeconverter"] 1.425 + .createInstance(Ci.nsIScriptableUnicodeConverter); 1.426 + conv.charset = entry.converter; 1.427 + 1.428 + let raw = conv.convertToByteArray(str).concat([0]); 1.429 + wsp_encode_test(MMS.EncodedStringValue, str, 1.430 + [raw.length + 2, 0x80 | entry.number, 127].concat(raw)); 1.431 + 1.432 + // MMS.EncodedStringValue encodes non us-ascii characters (128 ~ 255) 1.433 + // (e.g., 'Ñ' or 'ü') by the utf-8 encoding. Otherwise, for us-ascii 1.434 + // characters (0 ~ 127), still use the normal TextString encoding. 1.435 + 1.436 + // "Ñü" in full width. 1.437 + str = "\u00d1\u00fc"; 1.438 + raw = conv.convertToByteArray(str).concat([0]); 1.439 + wsp_encode_test(MMS.EncodedStringValue, str, 1.440 + [raw.length + 2, 0x80 | entry.number, 127].concat(raw)); 1.441 + } 1.442 + 1.443 + run_next_test(); 1.444 +}); 1.445 + 1.446 +// 1.447 +// Test target: ExpiryValue 1.448 +// 1.449 + 1.450 +//// ExpiryValue.decode //// 1.451 + 1.452 +add_test(function test_ExpiryValue_decode() { 1.453 + // Test for Absolute-token Date-value 1.454 + wsp_decode_test(MMS.ExpiryValue, [3, 128, 1, 0x80], new Date(0x80 * 1000)); 1.455 + // Test for Relative-token Delta-seconds-value 1.456 + wsp_decode_test(MMS.ExpiryValue, [2, 129, 0x80], 0); 1.457 + 1.458 + run_next_test(); 1.459 +}); 1.460 + 1.461 +//// ExpiryValue.encode //// 1.462 + 1.463 +add_test(function test_ExpiryValue_encode() { 1.464 + // Test for Absolute-token Date-value 1.465 + wsp_encode_test(MMS.ExpiryValue, new Date(0x80 * 1000), [3, 128, 1, 0x80]); 1.466 + // Test for Relative-token Delta-seconds-value 1.467 + wsp_encode_test(MMS.ExpiryValue, 0, [2, 129, 0x80]); 1.468 + 1.469 + run_next_test(); 1.470 +}); 1.471 + 1.472 +// 1.473 +// Test target: PreviouslySentByValue 1.474 +// 1.475 + 1.476 +//// PreviouslySentByValue.decode //// 1.477 + 1.478 +add_test(function test_PreviouslySentByValue_decode() { 1.479 + wsp_decode_test(MMS.PreviouslySentByValue, [3, 0x80 | 0x03, 65, 0], 1.480 + {forwardedCount: 3, originator: {address: "A", 1.481 + type: "alphanum"}}); 1.482 + 1.483 + run_next_test(); 1.484 +}); 1.485 + 1.486 +// 1.487 +// Test target: PreviouslySentDateValue 1.488 +// 1.489 + 1.490 +//// PreviouslySentDateValue.decode //// 1.491 + 1.492 +add_test(function test_PreviouslySentDateValue_decode() { 1.493 + wsp_decode_test(MMS.PreviouslySentDateValue, [3, 0x80 | 0x03, 1, 4], 1.494 + {forwardedCount: 3, timestamp: new Date(4 * 1000)}); 1.495 + 1.496 + run_next_test(); 1.497 +}); 1.498 + 1.499 +// 1.500 +// Test target: FromValue 1.501 +// 1.502 + 1.503 +//// FromValue.decode //// 1.504 + 1.505 +add_test(function test_FromValue_decode() { 1.506 + // Test for Insert-address-token: 1.507 + wsp_decode_test(MMS.FromValue, [1, 129], null); 1.508 + // Test for Address-present-token: 1.509 + let (addr = strToCharCodeArray("+123/TYPE=PLMN")) { 1.510 + wsp_decode_test(MMS.FromValue, [addr.length + 1, 128].concat(addr), 1.511 + {address: "+123", type: "PLMN"}); 1.512 + } 1.513 + 1.514 + run_next_test(); 1.515 +}); 1.516 + 1.517 +//// FromValue.encode //// 1.518 + 1.519 +add_test(function test_FromValue_encode() { 1.520 + // Test for Insert-address-token: 1.521 + wsp_encode_test(MMS.FromValue, null, [1, 129]); 1.522 + // Test for Address-present-token: 1.523 + let (addr = strToCharCodeArray("+123/TYPE=PLMN")) { 1.524 + wsp_encode_test(MMS.FromValue, {address: "+123", type: "PLMN"}, 1.525 + [addr.length + 1, 128].concat(addr)); 1.526 + } 1.527 + 1.528 + run_next_test(); 1.529 +}); 1.530 + 1.531 +// 1.532 +// Test target: MessageClassValue 1.533 +// 1.534 + 1.535 +//// MessageClassValue.decodeClassIdentifier //// 1.536 + 1.537 +add_test(function test_MessageClassValue_decodeClassIdentifier() { 1.538 + let (IDs = ["personal", "advertisement", "informational", "auto"]) { 1.539 + for (let i = 0; i < 256; i++) { 1.540 + if ((i >= 128) && (i <= 131)) { 1.541 + wsp_decode_test_ex(function(data) { 1.542 + return MMS.MessageClassValue.decodeClassIdentifier(data); 1.543 + }, [i], IDs[i - 128] 1.544 + ); 1.545 + } else { 1.546 + wsp_decode_test_ex(function(data) { 1.547 + return MMS.MessageClassValue.decodeClassIdentifier(data); 1.548 + }, [i], null, "CodeError" 1.549 + ); 1.550 + } 1.551 + } 1.552 + } 1.553 + 1.554 + run_next_test(); 1.555 +}); 1.556 + 1.557 +//// MessageClassValue.decode //// 1.558 + 1.559 +add_test(function test_MessageClassValue_decode() { 1.560 + wsp_decode_test(MMS.MessageClassValue, [65, 0], "A"); 1.561 + wsp_decode_test(MMS.MessageClassValue, [128], "personal"); 1.562 + 1.563 + run_next_test(); 1.564 +}); 1.565 + 1.566 +//// MessageClassValue.encode //// 1.567 + 1.568 +add_test(function test_MessageClassValue_encode() { 1.569 + wsp_encode_test(MMS.MessageClassValue, "personal", [128]); 1.570 + wsp_encode_test(MMS.MessageClassValue, "advertisement", [129]); 1.571 + wsp_encode_test(MMS.MessageClassValue, "informational", [130]); 1.572 + wsp_encode_test(MMS.MessageClassValue, "auto", [131]); 1.573 + wsp_encode_test(MMS.MessageClassValue, "A", [65, 0]); 1.574 + 1.575 + run_next_test(); 1.576 +}); 1.577 + 1.578 +// 1.579 +// Test target: MessageTypeValue 1.580 +// 1.581 + 1.582 +//// MessageTypeValue.decode //// 1.583 + 1.584 +add_test(function test_MessageTypeValue_decode() { 1.585 + for (let i = 0; i < 256; i++) { 1.586 + if ((i >= 128) && (i <= 151)) { 1.587 + wsp_decode_test(MMS.MessageTypeValue, [i], i); 1.588 + } else { 1.589 + wsp_decode_test(MMS.MessageTypeValue, [i], null, "CodeError"); 1.590 + } 1.591 + } 1.592 + 1.593 + run_next_test(); 1.594 +}); 1.595 + 1.596 +//// MessageTypeValue.encode //// 1.597 + 1.598 +add_test(function test_MessageTypeValue_encode() { 1.599 + for (let i = 0; i < 256; i++) { 1.600 + if ((i >= 128) && (i <= 151)) { 1.601 + wsp_encode_test(MMS.MessageTypeValue, i, [i]); 1.602 + } else { 1.603 + wsp_encode_test(MMS.MessageTypeValue, i, null, "CodeError"); 1.604 + } 1.605 + } 1.606 + 1.607 + run_next_test(); 1.608 +}); 1.609 + 1.610 +// 1.611 +// Test target: MmFlagsValue 1.612 +// 1.613 + 1.614 +//// MmFlagsValue.decode //// 1.615 + 1.616 +add_test(function test_MmFlagsValue_decode() { 1.617 + for (let i = 0; i < 256; i++) { 1.618 + if ((i >= 128) && (i <= 130)) { 1.619 + wsp_decode_test(MMS.MmFlagsValue, [3, i, 65, 0], {type: i, text: "A"}); 1.620 + } else { 1.621 + wsp_decode_test(MMS.MmFlagsValue, [3, i, 65, 0], null, "CodeError"); 1.622 + } 1.623 + } 1.624 + 1.625 + run_next_test(); 1.626 +}); 1.627 + 1.628 +//// MmFlagsValue.encode //// 1.629 + 1.630 +add_test(function test_MmFlagsValue_encode() { 1.631 + for (let i = 0; i < 256; i++) { 1.632 + if ((i >= 128) && (i <= 130)) { 1.633 + wsp_encode_test(MMS.MmFlagsValue, {type: i, text: "A"}, [3, i, 65, 0]); 1.634 + } else { 1.635 + wsp_encode_test(MMS.MmFlagsValue, {type: i, text: "A"}, null, "CodeError"); 1.636 + } 1.637 + } 1.638 + 1.639 + run_next_test(); 1.640 +}); 1.641 + 1.642 +// 1.643 +// Test target: MmStateValue 1.644 +// 1.645 + 1.646 +//// MmStateValue.decode //// 1.647 + 1.648 +add_test(function test_MmStateValue_decode() { 1.649 + for (let i = 0; i < 256; i++) { 1.650 + if ((i >= 128) && (i <= 132)) { 1.651 + wsp_decode_test(MMS.MmStateValue, [i], i); 1.652 + } else { 1.653 + wsp_decode_test(MMS.MmStateValue, [i], null, "CodeError"); 1.654 + } 1.655 + } 1.656 + 1.657 + run_next_test(); 1.658 +}); 1.659 + 1.660 +//// MmStateValue.encode //// 1.661 + 1.662 +add_test(function test_MmStateValue_encode() { 1.663 + for (let i = 0; i < 256; i++) { 1.664 + if ((i >= 128) && (i <= 132)) { 1.665 + wsp_encode_test(MMS.MmStateValue, i, [i]); 1.666 + } else { 1.667 + wsp_encode_test(MMS.MmStateValue, i, null, "CodeError"); 1.668 + } 1.669 + } 1.670 + 1.671 + run_next_test(); 1.672 +}); 1.673 + 1.674 +// 1.675 +// Test target: PriorityValue 1.676 +// 1.677 + 1.678 +//// PriorityValue.decode //// 1.679 + 1.680 +add_test(function test_PriorityValue_decode() { 1.681 + for (let i = 0; i < 256; i++) { 1.682 + if ((i >= 128) && (i <= 130)) { 1.683 + wsp_decode_test(MMS.PriorityValue, [i], i); 1.684 + } else { 1.685 + wsp_decode_test(MMS.PriorityValue, [i], null, "CodeError"); 1.686 + } 1.687 + } 1.688 + 1.689 + run_next_test(); 1.690 +}); 1.691 + 1.692 +//// PriorityValue.encode //// 1.693 + 1.694 +add_test(function test_PriorityValue_encode() { 1.695 + for (let i = 0; i < 256; i++) { 1.696 + if ((i >= 128) && (i <= 130)) { 1.697 + wsp_encode_test(MMS.PriorityValue, i, [i]); 1.698 + } else { 1.699 + wsp_encode_test(MMS.PriorityValue, i, null, "CodeError"); 1.700 + } 1.701 + } 1.702 + 1.703 + run_next_test(); 1.704 +}); 1.705 + 1.706 +// 1.707 +// Test target: ReadStatusValue 1.708 +// 1.709 + 1.710 +//// ReadStatusValue.decode //// 1.711 + 1.712 +add_test(function test_ReadStatusValue_decode() { 1.713 + for (let i = 0; i < 256; i++) { 1.714 + if ((i >= 128) && (i <= 129)) { 1.715 + wsp_decode_test(MMS.ReadStatusValue, [i], i); 1.716 + } else { 1.717 + wsp_decode_test(MMS.ReadStatusValue, [i], null, "CodeError"); 1.718 + } 1.719 + } 1.720 + 1.721 + run_next_test(); 1.722 +}); 1.723 + 1.724 +//// ReadStatusValue.encode //// 1.725 + 1.726 +add_test(function test_ReadStatusValue_encode() { 1.727 + for (let i = 0; i < 256; i++) { 1.728 + if ((i >= 128) && (i <= 129)) { 1.729 + wsp_encode_test(MMS.ReadStatusValue, i, [i]); 1.730 + } else { 1.731 + wsp_encode_test(MMS.ReadStatusValue, i, null, "CodeError"); 1.732 + } 1.733 + } 1.734 + 1.735 + run_next_test(); 1.736 +}); 1.737 + 1.738 +// 1.739 +// Test target: RecommendedRetrievalModeValue 1.740 +// 1.741 + 1.742 +//// RecommendedRetrievalModeValue.decode //// 1.743 + 1.744 +add_test(function test_RecommendedRetrievalModeValue_decode() { 1.745 + for (let i = 0; i < 256; i++) { 1.746 + if (i == 128) { 1.747 + wsp_decode_test(MMS.RecommendedRetrievalModeValue, [i], i); 1.748 + } else { 1.749 + wsp_decode_test(MMS.RecommendedRetrievalModeValue, [i], null, "CodeError"); 1.750 + } 1.751 + } 1.752 + 1.753 + run_next_test(); 1.754 +}); 1.755 + 1.756 +// 1.757 +// Test target: ReplyChargingValue 1.758 +// 1.759 + 1.760 +//// ReplyChargingValue.decode //// 1.761 + 1.762 +add_test(function test_ReplyChargingValue_decode() { 1.763 + for (let i = 0; i < 256; i++) { 1.764 + if ((i >= 128) && (i <= 131)) { 1.765 + wsp_decode_test(MMS.ReplyChargingValue, [i], i); 1.766 + } else { 1.767 + wsp_decode_test(MMS.ReplyChargingValue, [i], null, "CodeError"); 1.768 + } 1.769 + } 1.770 + 1.771 + run_next_test(); 1.772 +}); 1.773 + 1.774 +//// ReplyChargingValue.encode //// 1.775 + 1.776 +add_test(function test_ReplyChargingValue_encode() { 1.777 + for (let i = 0; i < 256; i++) { 1.778 + if ((i >= 128) && (i <= 131)) { 1.779 + wsp_encode_test(MMS.ReplyChargingValue, i, [i]); 1.780 + } else { 1.781 + wsp_encode_test(MMS.ReplyChargingValue, i, null, "CodeError"); 1.782 + } 1.783 + } 1.784 + 1.785 + run_next_test(); 1.786 +}); 1.787 + 1.788 +// 1.789 +// Test target: ResponseText 1.790 +// 1.791 + 1.792 +//// ResponseText.decode //// 1.793 + 1.794 +add_test(function test_ResponseText_decode() { 1.795 + // Test for MMS_PDU_TYPE_MBOX_DELETE_CONF & MMS_PDU_TYPE_DELETE_CONF 1.796 + wsp_decode_test_ex(function(data) { 1.797 + data.array[0] = data.array.length - 1; 1.798 + 1.799 + let options = {}; 1.800 + options["x-mms-message-type"] = MMS_PDU_TYPE_MBOX_DELETE_CONF; 1.801 + return MMS.ResponseText.decode(data, options); 1.802 + }, [0, 0x80 | 0x00].concat(strToCharCodeArray("http://no.such.com/path")), 1.803 + {statusCount: 0, text: "http://no.such.com/path"} 1.804 + ); 1.805 + wsp_decode_test_ex(function(data) { 1.806 + data.array[0] = data.array.length - 1; 1.807 + 1.808 + let options = {}; 1.809 + options["x-mms-message-type"] = MMS_PDU_TYPE_DELETE_CONF; 1.810 + return MMS.ResponseText.decode(data, options); 1.811 + }, [0, 0x80 | 0x00].concat(strToCharCodeArray("http://no.such.com/path")), 1.812 + {statusCount: 0, text: "http://no.such.com/path"} 1.813 + ); 1.814 + // Test for other situations 1.815 + wsp_decode_test_ex(function(data) { 1.816 + let options = {}; 1.817 + options["x-mms-message-type"] = MMS_PDU_TYPE_SEND_REQ; 1.818 + return MMS.ResponseText.decode(data, options); 1.819 + }, strToCharCodeArray("http://no.such.com/path"), 1.820 + {text: "http://no.such.com/path"} 1.821 + ); 1.822 + 1.823 + run_next_test(); 1.824 +}); 1.825 + 1.826 +// 1.827 +// Test target: RetrieveStatusValue 1.828 +// 1.829 + 1.830 +//// RetrieveStatusValue.decode //// 1.831 + 1.832 +add_test(function test_RetrieveStatusValue_decode() { 1.833 + for (let i = 0; i < 256; i++) { 1.834 + if ((i == MMS_PDU_ERROR_OK) 1.835 + || (i >= MMS_PDU_ERROR_TRANSIENT_FAILURE)) { 1.836 + wsp_decode_test(MMS.RetrieveStatusValue, [i], i); 1.837 + } else { 1.838 + wsp_decode_test(MMS.RetrieveStatusValue, [i], 1.839 + MMS_PDU_ERROR_PERMANENT_FAILURE); 1.840 + } 1.841 + } 1.842 + 1.843 + run_next_test(); 1.844 +}); 1.845 + 1.846 +// 1.847 +// Test target: SenderVisibilityValue 1.848 +// 1.849 + 1.850 +//// SenderVisibilityValue.decode //// 1.851 + 1.852 +add_test(function test_SenderVisibilityValue_decode() { 1.853 + for (let i = 0; i < 256; i++) { 1.854 + if ((i >= 128) && (i <= 129)) { 1.855 + wsp_decode_test(MMS.SenderVisibilityValue, [i], i); 1.856 + } else { 1.857 + wsp_decode_test(MMS.SenderVisibilityValue, [i], null, "CodeError"); 1.858 + } 1.859 + } 1.860 + 1.861 + run_next_test(); 1.862 +}); 1.863 + 1.864 +//// SenderVisibilityValue.encode //// 1.865 + 1.866 +add_test(function test_SenderVisibilityValue_encode() { 1.867 + for (let i = 0; i < 256; i++) { 1.868 + if ((i >= 128) && (i <= 129)) { 1.869 + wsp_encode_test(MMS.SenderVisibilityValue, i, [i]); 1.870 + } else { 1.871 + wsp_encode_test(MMS.SenderVisibilityValue, i, null, "CodeError"); 1.872 + } 1.873 + } 1.874 + 1.875 + run_next_test(); 1.876 +}); 1.877 + 1.878 +// 1.879 +// Test target: StatusValue 1.880 +// 1.881 + 1.882 +//// StatusValue.decode //// 1.883 + 1.884 +add_test(function test_StatusValue_decode() { 1.885 + for (let i = 0; i < 256; i++) { 1.886 + if ((i >= 128) && (i <= 135)) { 1.887 + wsp_decode_test(MMS.StatusValue, [i], i); 1.888 + } else { 1.889 + wsp_decode_test(MMS.StatusValue, [i], null, "CodeError"); 1.890 + } 1.891 + } 1.892 + 1.893 + run_next_test(); 1.894 +}); 1.895 + 1.896 +//// StatusValue.encode //// 1.897 + 1.898 +add_test(function test_StatusValue_encode() { 1.899 + for (let i = 0; i < 256; i++) { 1.900 + if ((i >= 128) && (i <= 135)) { 1.901 + wsp_encode_test(MMS.StatusValue, i, [i]); 1.902 + } else { 1.903 + wsp_encode_test(MMS.StatusValue, i, null, "CodeError"); 1.904 + } 1.905 + } 1.906 + 1.907 + run_next_test(); 1.908 +}); 1.909 + 1.910 +// 1.911 +// Test target: PduHelper 1.912 +// 1.913 + 1.914 +//// PduHelper.parseHeaders //// 1.915 + 1.916 +add_test(function test_PduHelper_parseHeaders() { 1.917 + function parse(input, expect, exception) { 1.918 + let data = {array: input, offset: 0}; 1.919 + do_check_throws(wsp_test_func.bind(null, MMS.PduHelper.parseHeaders, data, expect), 1.920 + exception); 1.921 + } 1.922 + 1.923 + // Parse ends with Content-Type 1.924 + let expect = {}; 1.925 + expect["x-mms-mms-version"] = MMS_VERSION_1_3; 1.926 + expect["content-type"] = { 1.927 + media: "application/vnd.wap.multipart.related", 1.928 + params: null, 1.929 + }; 1.930 + parse([0x80 | 0x0D, 0x80 | MMS_VERSION_1_3, // X-Mms-Mms-Version: 1.3 1.931 + 0x80 | 0x04, 0x80 | 0x33, // Content-Type: application/vnd.wap.multipart.related 1.932 + 0x80 | 0x0C, MMS_PDU_TYPE_SEND_REQ // X-Mms-Message-Type: M-Send.req 1.933 + ], expect); 1.934 + 1.935 + // Parse header fields with multiple entries 1.936 + expect = { 1.937 + to: [ 1.938 + { address: "+123", type: "PLMN" }, 1.939 + { address: "+456", type: "num" }, 1.940 + ], 1.941 + }; 1.942 + expect["content-type"] = { 1.943 + media: "application/vnd.wap.multipart.related", 1.944 + params: null, 1.945 + }; 1.946 + parse(Array.concat([0x80 | 0x17]).concat(strToCharCodeArray("+123/TYPE=PLMN")) 1.947 + .concat([0x80 | 0x17]).concat(strToCharCodeArray("+456")) 1.948 + .concat([0x80 | 0x04, 0x80 | 0x33]), 1.949 + expect); 1.950 + 1.951 + run_next_test(); 1.952 +}); 1.953 + 1.954 +//// PduHelper.encodeHeader //// 1.955 + 1.956 +add_test(function test_PduHelper_encodeHeader() { 1.957 + function func(name, data, headers) { 1.958 + MMS.PduHelper.encodeHeader(data, headers, name); 1.959 + 1.960 + // Remove extra space consumed during encoding. 1.961 + while (data.array.length > data.offset) { 1.962 + data.array.pop(); 1.963 + } 1.964 + 1.965 + return data.array; 1.966 + } 1.967 + 1.968 + // Encode header fields with multiple entries 1.969 + let headers = { 1.970 + to: [ 1.971 + { address: "+123", type: "PLMN" }, 1.972 + { address: "+456", type: "num" }, 1.973 + ], 1.974 + }; 1.975 + wsp_encode_test_ex(func.bind(null, "to"), headers, 1.976 + Array.concat([0x80 | 0x17]).concat(strToCharCodeArray("+123/TYPE=PLMN")) 1.977 + .concat([0x80 | 0x17]).concat(strToCharCodeArray("+456"))); 1.978 + 1.979 + run_next_test(); 1.980 +}); 1.981 + 1.982 +//// PduHelper.encodeHeaderIfExists //// 1.983 + 1.984 +add_test(function test_PduHelper_encodeHeaderIfExists() { 1.985 + function func(name, data, headers) { 1.986 + MMS.PduHelper.encodeHeaderIfExists(data, headers, name); 1.987 + 1.988 + // Remove extra space consumed during encoding. 1.989 + while (data.array.length > data.offset) { 1.990 + data.array.pop(); 1.991 + } 1.992 + 1.993 + return data.array; 1.994 + } 1.995 + 1.996 + wsp_encode_test_ex(func.bind(null, "to"), {}, []); 1.997 + 1.998 + run_next_test(); 1.999 +}); 1.1000 + 1.1001 +//// PduHelper.encodeHeaders //// 1.1002 + 1.1003 +add_test(function test_PduHelper_encodeHeaders() { 1.1004 + function func(data, headers) { 1.1005 + MMS.PduHelper.encodeHeaders(data, headers); 1.1006 + 1.1007 + // Remove extra space consumed during encoding. 1.1008 + while (data.array.length > data.offset) { 1.1009 + data.array.pop(); 1.1010 + } 1.1011 + 1.1012 + return data.array; 1.1013 + } 1.1014 + 1.1015 + let headers = {}; 1.1016 + headers["x-mms-message-type"] = MMS_PDU_TYPE_SEND_REQ; 1.1017 + headers["x-mms-mms-version"] = MMS_VERSION_1_3; 1.1018 + headers["x-mms-transaction-id"] = "asdf"; 1.1019 + headers["to"] = { address: "+123", type: "PLMN" }; 1.1020 + headers["content-type"] = { 1.1021 + media: "application/vnd.wap.multipart.related", 1.1022 + }; 1.1023 + wsp_encode_test_ex(func, headers, 1.1024 + Array.concat([0x80 | 0x0C, MMS_PDU_TYPE_SEND_REQ]) 1.1025 + .concat([0x80 | 0x18]).concat(strToCharCodeArray(headers["x-mms-transaction-id"])) 1.1026 + .concat([0x80 | 0x0D, 0x80 | MMS_VERSION_1_3]) 1.1027 + .concat([0x80 | 0x17]).concat(strToCharCodeArray("+123/TYPE=PLMN")) 1.1028 + .concat([0x80 | 0x04, 0x80 | 0x33])); 1.1029 + 1.1030 + run_next_test(); 1.1031 +}); 1.1032 +