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.
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 let MMS = {};
5 subscriptLoader.loadSubScript("resource://gre/modules/MmsPduHelper.jsm", MMS);
6 MMS.debug = do_print;
8 function run_test() {
9 run_next_test();
10 }
12 //
13 // Test target: BooleanValue
14 //
16 //// BooleanValue.decode ////
18 add_test(function test_BooleanValue_decode() {
19 for (let i = 0; i < 256; i++) {
20 if (i == 128) {
21 wsp_decode_test(MMS.BooleanValue, [128], true);
22 } else if (i == 129) {
23 wsp_decode_test(MMS.BooleanValue, [129], false);
24 } else {
25 wsp_decode_test(MMS.BooleanValue, [i], null, "CodeError");
26 }
27 }
29 run_next_test();
30 });
32 //// BooleanValue.encode ////
34 add_test(function test_BooleanValue_encode() {
35 wsp_encode_test(MMS.BooleanValue, true, [128]);
36 wsp_encode_test(MMS.BooleanValue, false, [129]);
38 run_next_test();
39 });
41 //
42 // Test target: Address
43 //
45 //// Address.decode ////
47 add_test(function test_Address_decode() {
48 // Test for PLMN address
49 wsp_decode_test(MMS.Address, strToCharCodeArray("+123.456-789/TYPE=PLMN"),
50 {address: "+123.456-789", type: "PLMN"});
51 wsp_decode_test(MMS.Address, strToCharCodeArray("123456789/TYPE=PLMN"),
52 {address: "123456789", type: "PLMN"});
53 // Test for IPv4
54 wsp_decode_test(MMS.Address, strToCharCodeArray("1.2.3.4/TYPE=IPv4"),
55 {address: "1.2.3.4", type: "IPv4"});
56 // Test for IPv6
57 wsp_decode_test(MMS.Address,
58 strToCharCodeArray("1111:AAAA:bbbb:CdEf:1ABC:2cde:3Def:0000/TYPE=IPv6"),
59 {address: "1111:AAAA:bbbb:CdEf:1ABC:2cde:3Def:0000", type: "IPv6"}
60 );
61 // Test for other device-address
62 wsp_decode_test(MMS.Address, strToCharCodeArray("+H-e.l%l_o/TYPE=W0r1d_"),
63 {address: "+H-e.l%l_o", type: "W0r1d_"});
64 // Test for num-shortcode
65 wsp_decode_test(MMS.Address, strToCharCodeArray("+123"),
66 {address: "+123", type: "num"});
67 wsp_decode_test(MMS.Address, strToCharCodeArray("*123"),
68 {address: "*123", type: "num"});
69 wsp_decode_test(MMS.Address, strToCharCodeArray("#123"),
70 {address: "#123", type: "num"});
71 // Test for alphanum-shortcode
72 wsp_decode_test(MMS.Address, strToCharCodeArray("H0wD0Y0uTurnTh1s0n"),
73 {address: "H0wD0Y0uTurnTh1s0n", type: "alphanum"});
74 // Test for email address
75 wsp_decode_test(MMS.Address, strToCharCodeArray("Joe User <joe@user.org>"),
76 {address: "Joe User <joe@user.org>", type: "email"});
77 // Test for invalid address
78 wsp_decode_test(MMS.Address, strToCharCodeArray("@@@@@"),
79 null, "CodeError");
81 run_next_test();
82 });
84 //// Address.encode ////
86 add_test(function test_Address_encode() {
87 // Test for PLMN address
88 wsp_encode_test(MMS.Address, {address: "+123.456-789", type: "PLMN"},
89 strToCharCodeArray("+123.456-789/TYPE=PLMN"));
90 wsp_encode_test(MMS.Address, {address: "123456789", type: "PLMN"},
91 strToCharCodeArray("123456789/TYPE=PLMN"));
92 // Test for IPv4
93 wsp_encode_test(MMS.Address, {address: "1.2.3.4", type: "IPv4"},
94 strToCharCodeArray("1.2.3.4/TYPE=IPv4"));
95 // Test for IPv6
96 wsp_encode_test(MMS.Address,
97 {address: "1111:AAAA:bbbb:CdEf:1ABC:2cde:3Def:0000", type: "IPv6"},
98 strToCharCodeArray("1111:AAAA:bbbb:CdEf:1ABC:2cde:3Def:0000/TYPE=IPv6")
99 );
100 // Test for other device-address
101 wsp_encode_test(MMS.Address, {address: "+H-e.l%l_o", type: "W0r1d_"},
102 strToCharCodeArray("+H-e.l%l_o/TYPE=W0r1d_"));
103 // Test for num-shortcode
104 wsp_encode_test(MMS.Address, {address: "+123", type: "num"},
105 strToCharCodeArray("+123"));
106 wsp_encode_test(MMS.Address, {address: "*123", type: "num"},
107 strToCharCodeArray("*123"));
108 wsp_encode_test(MMS.Address, {address: "#123", type: "num"},
109 strToCharCodeArray("#123"));
110 // Test for alphanum-shortcode
111 wsp_encode_test(MMS.Address, {address: "H0wD0Y0uTurnTh1s0n", type: "alphanum"},
112 strToCharCodeArray("H0wD0Y0uTurnTh1s0n"));
113 // Test for email address
114 wsp_encode_test(MMS.Address, {address: "Joe User <joe@user.org>", type: "email"},
115 strToCharCodeArray("Joe User <joe@user.org>"));
117 run_next_test();
118 });
120 //
121 // Test target: HeaderField
122 //
124 //// HeaderField.decode ////
126 add_test(function test_HeaderField_decode() {
127 wsp_decode_test(MMS.HeaderField, [65, 0, 66, 0], {name: "a", value: "B"});
128 wsp_decode_test(MMS.HeaderField, [0x80 | 0x27, 128],
129 {name: "x-mms-stored", value: true});
131 run_next_test();
132 });
134 //// HeaderField.encode ////
136 add_test(function test_HeaderField_encode() {
137 // Test for MmsHeader
138 wsp_encode_test(MMS.HeaderField, {name: "X-Mms-Message-Type",
139 value: MMS_PDU_TYPE_SEND_REQ},
140 [0x80 | 0x0C, MMS_PDU_TYPE_SEND_REQ]);
141 // Test for ApplicationHeader
142 wsp_encode_test(MMS.HeaderField, {name: "a", value: "B"}, [97, 0, 66, 0]);
144 run_next_test();
145 });
147 //
148 // Test target: MmsHeader
149 //
151 //// MmsHeader.decode ////
153 add_test(function test_MmsHeader_decode() {
154 wsp_decode_test(MMS.MmsHeader, [0x80 | 0x00], null, "NotWellKnownEncodingError");
155 wsp_decode_test(MMS.MmsHeader, [0x80 | 0x27, 128],
156 {name: "x-mms-stored", value: true});
157 wsp_decode_test(MMS.MmsHeader, [0x80 | 0x27, 255], null);
159 run_next_test();
160 });
162 //// MmsHeader.encode ////
164 add_test(function test_MmsHeader_encode() {
165 // Test for empty header name:
166 wsp_encode_test(MMS.MmsHeader, {name: undefined, value: null}, null, "CodeError");
167 wsp_encode_test(MMS.MmsHeader, {name: null, value: null}, null, "CodeError");
168 wsp_encode_test(MMS.MmsHeader, {name: "", value: null}, null, "CodeError");
169 // Test for non-well-known header name:
170 wsp_encode_test(MMS.MmsHeader, {name: "X-No-Such-Field", value: null},
171 null, "NotWellKnownEncodingError");
172 // Test for normal header
173 wsp_encode_test(MMS.MmsHeader, {name: "X-Mms-Message-Type",
174 value: MMS_PDU_TYPE_SEND_REQ},
175 [0x80 | 0x0C, MMS_PDU_TYPE_SEND_REQ]);
177 run_next_test();
178 });
180 //
181 // Test target: CancelStatusValue
182 //
184 //// CancelStatusValue.decode ////
186 add_test(function test_CancelStatusValue_decode() {
187 for (let i = 0; i < 256; i++) {
188 if ((i >= 128) && (i <= 129)) {
189 wsp_decode_test(MMS.CancelStatusValue, [i], i);
190 } else {
191 wsp_decode_test(MMS.CancelStatusValue, [i], null, "CodeError");
192 }
193 }
195 run_next_test();
196 });
198 //// CancelStatusValue.encode ////
200 add_test(function test_CancelStatusValue_encode() {
201 for (let i = 0; i < 256; i++) {
202 if ((i >= 128) && (i <= 129)) {
203 wsp_encode_test(MMS.CancelStatusValue, i, [i]);
204 } else {
205 wsp_encode_test(MMS.CancelStatusValue, i, null, "CodeError");
206 }
207 }
209 run_next_test();
210 });
212 //
213 // Test target: ContentClassValue
214 //
216 //// ContentClassValue.decode ////
218 add_test(function test_ContentClassValue_decode() {
219 for (let i = 0; i < 256; i++) {
220 if ((i >= 128) && (i <= 135)) {
221 wsp_decode_test(MMS.ContentClassValue, [i], i);
222 } else {
223 wsp_decode_test(MMS.ContentClassValue, [i], null, "CodeError");
224 }
225 }
227 run_next_test();
228 });
230 //// ContentClassValue.encode ////
232 add_test(function test_ContentClassValue_encode() {
233 for (let i = 0; i < 256; i++) {
234 if ((i >= 128) && (i <= 135)) {
235 wsp_encode_test(MMS.ContentClassValue, i, [i]);
236 } else {
237 wsp_encode_test(MMS.ContentClassValue, i, null, "CodeError");
238 }
239 }
241 run_next_test();
242 });
244 //
245 // Test target: ContentLocationValue
246 //
248 //// ContentLocationValue.decode ////
250 add_test(function test_ContentLocationValue_decode() {
251 // Test for MMS_PDU_TYPE_MBOX_DELETE_CONF & MMS_PDU_TYPE_DELETE_CONF
252 function test(type, statusCount, exception) {
253 function decode(data) {
254 let options = {};
255 if (type) {
256 options["x-mms-message-type"] = type;
257 }
258 return MMS.ContentLocationValue.decode(data, options);
259 }
261 let uri = "http://no.such.com/path";
263 let data = strToCharCodeArray(uri);
264 if (statusCount != null) {
265 data = [data.length + 1, statusCount | 0x80].concat(data);
266 }
268 let expected;
269 if (!exception) {
270 expected = {};
271 if (statusCount != null) {
272 expected.statusCount = statusCount;
273 }
274 expected.uri = uri;
275 }
277 do_print("data = " + JSON.stringify(data));
278 wsp_decode_test_ex(decode, data, expected, exception);
279 }
281 test(null, null, "FatalCodeError");
282 for (let type = MMS_PDU_TYPE_SEND_REQ; type <= MMS_PDU_TYPE_CANCEL_CONF; type++) {
283 if ((type == MMS_PDU_TYPE_MBOX_DELETE_CONF)
284 || (type == MMS_PDU_TYPE_DELETE_CONF)) {
285 test(type, 1, null);
286 } else {
287 test(type, null, null);
288 }
289 }
291 run_next_test();
292 });
294 //
295 // Test target: ElementDescriptorValue
296 //
298 //// ElementDescriptorValue.decode ////
300 add_test(function test_ElementDescriptorValue_decode() {
301 wsp_decode_test(MMS.ElementDescriptorValue, [2, 97, 0], {contentReference: "a"});
302 wsp_decode_test(MMS.ElementDescriptorValue, [4, 97, 0, 0x80 | 0x02, 0x80],
303 {contentReference: "a", params: {type: 0}});
305 run_next_test();
306 });
308 //
309 // Test target: Parameter
310 //
312 //// Parameter.decodeParameterName ////
314 add_test(function test_Parameter_decodeParameterName() {
315 wsp_decode_test_ex(function(data) {
316 return MMS.Parameter.decodeParameterName(data);
317 }, [0x80 | 0x02], "type"
318 );
319 wsp_decode_test_ex(function(data) {
320 return MMS.Parameter.decodeParameterName(data);
321 }, strToCharCodeArray("type"), "type"
322 );
324 run_next_test();
325 });
327 //// Parameter.decode ////
329 add_test(function test_Parameter_decode() {
330 wsp_decode_test(MMS.Parameter, [0x80 | 0x02, 0x80 | 0x00], {name: "type", value: 0});
332 run_next_test();
333 });
335 //// Parameter.decodeMultiple ////
337 add_test(function test_Parameter_decodeMultiple() {
338 // FIXME: The following test case falls because Parameter-value decoding of
339 // "type" parameters utilies WSP.ConstrainedEncoding, which in turn
340 // utilies WSP.TextString, and TextString is not matual exclusive to
341 // each other.
342 //wsp_decode_test_ex(function(data) {
343 // return MMS.Parameter.decodeMultiple(data, data.array.length);
344 // }, [0x80 | 0x02, 0x80 | 0x00].concat(strToCharCodeArray("good")).concat([0x80 | 0x01]),
345 // {type: 0, good: 1}
346 //);
348 run_next_test();
349 });
351 //// Parameter.encode ////
353 add_test(function test_Parameter_encode() {
354 // Test for invalid parameter value
355 wsp_encode_test(MMS.Parameter, null, null, "CodeError");
356 wsp_encode_test(MMS.Parameter, undefined, null, "CodeError");
357 wsp_encode_test(MMS.Parameter, {}, null, "CodeError");
358 // Test for case-insensitive parameter name
359 wsp_encode_test(MMS.Parameter, {name: "TYPE", value: 0}, [130, 128]);
360 wsp_encode_test(MMS.Parameter, {name: "type", value: 0}, [130, 128]);
361 // Test for non-well-known parameter name
362 wsp_encode_test(MMS.Parameter, {name: "name", value: 0}, [110, 97, 109, 101, 0, 128]);
363 // Test for constrained encoding value
364 wsp_encode_test(MMS.Parameter, {name: "type", value: "0"}, [130, 48, 0]);
366 run_next_test();
367 });
369 //
370 // Test target: EncodedStringValue
371 //
373 //// EncodedStringValue.decode ////
375 add_test(function test_EncodedStringValue_decode() {
376 // Test for normal TextString
377 wsp_decode_test(MMS.EncodedStringValue, strToCharCodeArray("Hello"), "Hello");
378 // Test for non-well-known charset
379 wsp_decode_test(MMS.EncodedStringValue, [1, 0x80], null, "NotWellKnownEncodingError");
380 // Test for utf-8
381 let (entry = MMS.WSP.WSP_WELL_KNOWN_CHARSETS["utf-8"]) {
382 // "Mozilla" in full width.
383 let str = "\uff2d\uff4f\uff5a\uff49\uff4c\uff4c\uff41";
385 let conv = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
386 .createInstance(Ci.nsIScriptableUnicodeConverter);
387 conv.charset = entry.converter;
389 let raw = conv.convertToByteArray(str).concat([0]);
390 wsp_decode_test(MMS.EncodedStringValue,
391 [raw.length + 2, 0x80 | entry.number, 127].concat(raw), str);
392 }
394 let (entry = MMS.WSP.WSP_WELL_KNOWN_CHARSETS["utf-16"]) {
395 // "Mozilla" in full width.
396 let str = "\u004d\u006F\u007A\u0069\u006C\u006C\u0061";
398 let conv = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
399 .createInstance(Ci.nsIScriptableUnicodeConverter);
400 conv.charset = entry.converter;
402 let raw = conv.convertToByteArray(str).concat([0]);
403 wsp_decode_test(MMS.EncodedStringValue,
404 [raw.length + 3, 2, 3, 247].concat(raw), str);
405 }
407 run_next_test();
408 });
410 //// EncodedStringValue.encode ////
412 add_test(function test_EncodedStringValue_encode() {
413 // Test for normal TextString
414 wsp_encode_test(MMS.EncodedStringValue, "Hello", strToCharCodeArray("Hello"));
416 // Test for utf-8
417 let (entry = MMS.WSP.WSP_WELL_KNOWN_CHARSETS["utf-8"]) {
418 // "Mozilla" in full width.
419 let str = "\uff2d\uff4f\uff5a\uff49\uff4c\uff4c\uff41";
421 let conv = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
422 .createInstance(Ci.nsIScriptableUnicodeConverter);
423 conv.charset = entry.converter;
425 let raw = conv.convertToByteArray(str).concat([0]);
426 wsp_encode_test(MMS.EncodedStringValue, str,
427 [raw.length + 2, 0x80 | entry.number, 127].concat(raw));
429 // MMS.EncodedStringValue encodes non us-ascii characters (128 ~ 255)
430 // (e.g., 'Ñ' or 'ü') by the utf-8 encoding. Otherwise, for us-ascii
431 // characters (0 ~ 127), still use the normal TextString encoding.
433 // "Ñü" in full width.
434 str = "\u00d1\u00fc";
435 raw = conv.convertToByteArray(str).concat([0]);
436 wsp_encode_test(MMS.EncodedStringValue, str,
437 [raw.length + 2, 0x80 | entry.number, 127].concat(raw));
438 }
440 run_next_test();
441 });
443 //
444 // Test target: ExpiryValue
445 //
447 //// ExpiryValue.decode ////
449 add_test(function test_ExpiryValue_decode() {
450 // Test for Absolute-token Date-value
451 wsp_decode_test(MMS.ExpiryValue, [3, 128, 1, 0x80], new Date(0x80 * 1000));
452 // Test for Relative-token Delta-seconds-value
453 wsp_decode_test(MMS.ExpiryValue, [2, 129, 0x80], 0);
455 run_next_test();
456 });
458 //// ExpiryValue.encode ////
460 add_test(function test_ExpiryValue_encode() {
461 // Test for Absolute-token Date-value
462 wsp_encode_test(MMS.ExpiryValue, new Date(0x80 * 1000), [3, 128, 1, 0x80]);
463 // Test for Relative-token Delta-seconds-value
464 wsp_encode_test(MMS.ExpiryValue, 0, [2, 129, 0x80]);
466 run_next_test();
467 });
469 //
470 // Test target: PreviouslySentByValue
471 //
473 //// PreviouslySentByValue.decode ////
475 add_test(function test_PreviouslySentByValue_decode() {
476 wsp_decode_test(MMS.PreviouslySentByValue, [3, 0x80 | 0x03, 65, 0],
477 {forwardedCount: 3, originator: {address: "A",
478 type: "alphanum"}});
480 run_next_test();
481 });
483 //
484 // Test target: PreviouslySentDateValue
485 //
487 //// PreviouslySentDateValue.decode ////
489 add_test(function test_PreviouslySentDateValue_decode() {
490 wsp_decode_test(MMS.PreviouslySentDateValue, [3, 0x80 | 0x03, 1, 4],
491 {forwardedCount: 3, timestamp: new Date(4 * 1000)});
493 run_next_test();
494 });
496 //
497 // Test target: FromValue
498 //
500 //// FromValue.decode ////
502 add_test(function test_FromValue_decode() {
503 // Test for Insert-address-token:
504 wsp_decode_test(MMS.FromValue, [1, 129], null);
505 // Test for Address-present-token:
506 let (addr = strToCharCodeArray("+123/TYPE=PLMN")) {
507 wsp_decode_test(MMS.FromValue, [addr.length + 1, 128].concat(addr),
508 {address: "+123", type: "PLMN"});
509 }
511 run_next_test();
512 });
514 //// FromValue.encode ////
516 add_test(function test_FromValue_encode() {
517 // Test for Insert-address-token:
518 wsp_encode_test(MMS.FromValue, null, [1, 129]);
519 // Test for Address-present-token:
520 let (addr = strToCharCodeArray("+123/TYPE=PLMN")) {
521 wsp_encode_test(MMS.FromValue, {address: "+123", type: "PLMN"},
522 [addr.length + 1, 128].concat(addr));
523 }
525 run_next_test();
526 });
528 //
529 // Test target: MessageClassValue
530 //
532 //// MessageClassValue.decodeClassIdentifier ////
534 add_test(function test_MessageClassValue_decodeClassIdentifier() {
535 let (IDs = ["personal", "advertisement", "informational", "auto"]) {
536 for (let i = 0; i < 256; i++) {
537 if ((i >= 128) && (i <= 131)) {
538 wsp_decode_test_ex(function(data) {
539 return MMS.MessageClassValue.decodeClassIdentifier(data);
540 }, [i], IDs[i - 128]
541 );
542 } else {
543 wsp_decode_test_ex(function(data) {
544 return MMS.MessageClassValue.decodeClassIdentifier(data);
545 }, [i], null, "CodeError"
546 );
547 }
548 }
549 }
551 run_next_test();
552 });
554 //// MessageClassValue.decode ////
556 add_test(function test_MessageClassValue_decode() {
557 wsp_decode_test(MMS.MessageClassValue, [65, 0], "A");
558 wsp_decode_test(MMS.MessageClassValue, [128], "personal");
560 run_next_test();
561 });
563 //// MessageClassValue.encode ////
565 add_test(function test_MessageClassValue_encode() {
566 wsp_encode_test(MMS.MessageClassValue, "personal", [128]);
567 wsp_encode_test(MMS.MessageClassValue, "advertisement", [129]);
568 wsp_encode_test(MMS.MessageClassValue, "informational", [130]);
569 wsp_encode_test(MMS.MessageClassValue, "auto", [131]);
570 wsp_encode_test(MMS.MessageClassValue, "A", [65, 0]);
572 run_next_test();
573 });
575 //
576 // Test target: MessageTypeValue
577 //
579 //// MessageTypeValue.decode ////
581 add_test(function test_MessageTypeValue_decode() {
582 for (let i = 0; i < 256; i++) {
583 if ((i >= 128) && (i <= 151)) {
584 wsp_decode_test(MMS.MessageTypeValue, [i], i);
585 } else {
586 wsp_decode_test(MMS.MessageTypeValue, [i], null, "CodeError");
587 }
588 }
590 run_next_test();
591 });
593 //// MessageTypeValue.encode ////
595 add_test(function test_MessageTypeValue_encode() {
596 for (let i = 0; i < 256; i++) {
597 if ((i >= 128) && (i <= 151)) {
598 wsp_encode_test(MMS.MessageTypeValue, i, [i]);
599 } else {
600 wsp_encode_test(MMS.MessageTypeValue, i, null, "CodeError");
601 }
602 }
604 run_next_test();
605 });
607 //
608 // Test target: MmFlagsValue
609 //
611 //// MmFlagsValue.decode ////
613 add_test(function test_MmFlagsValue_decode() {
614 for (let i = 0; i < 256; i++) {
615 if ((i >= 128) && (i <= 130)) {
616 wsp_decode_test(MMS.MmFlagsValue, [3, i, 65, 0], {type: i, text: "A"});
617 } else {
618 wsp_decode_test(MMS.MmFlagsValue, [3, i, 65, 0], null, "CodeError");
619 }
620 }
622 run_next_test();
623 });
625 //// MmFlagsValue.encode ////
627 add_test(function test_MmFlagsValue_encode() {
628 for (let i = 0; i < 256; i++) {
629 if ((i >= 128) && (i <= 130)) {
630 wsp_encode_test(MMS.MmFlagsValue, {type: i, text: "A"}, [3, i, 65, 0]);
631 } else {
632 wsp_encode_test(MMS.MmFlagsValue, {type: i, text: "A"}, null, "CodeError");
633 }
634 }
636 run_next_test();
637 });
639 //
640 // Test target: MmStateValue
641 //
643 //// MmStateValue.decode ////
645 add_test(function test_MmStateValue_decode() {
646 for (let i = 0; i < 256; i++) {
647 if ((i >= 128) && (i <= 132)) {
648 wsp_decode_test(MMS.MmStateValue, [i], i);
649 } else {
650 wsp_decode_test(MMS.MmStateValue, [i], null, "CodeError");
651 }
652 }
654 run_next_test();
655 });
657 //// MmStateValue.encode ////
659 add_test(function test_MmStateValue_encode() {
660 for (let i = 0; i < 256; i++) {
661 if ((i >= 128) && (i <= 132)) {
662 wsp_encode_test(MMS.MmStateValue, i, [i]);
663 } else {
664 wsp_encode_test(MMS.MmStateValue, i, null, "CodeError");
665 }
666 }
668 run_next_test();
669 });
671 //
672 // Test target: PriorityValue
673 //
675 //// PriorityValue.decode ////
677 add_test(function test_PriorityValue_decode() {
678 for (let i = 0; i < 256; i++) {
679 if ((i >= 128) && (i <= 130)) {
680 wsp_decode_test(MMS.PriorityValue, [i], i);
681 } else {
682 wsp_decode_test(MMS.PriorityValue, [i], null, "CodeError");
683 }
684 }
686 run_next_test();
687 });
689 //// PriorityValue.encode ////
691 add_test(function test_PriorityValue_encode() {
692 for (let i = 0; i < 256; i++) {
693 if ((i >= 128) && (i <= 130)) {
694 wsp_encode_test(MMS.PriorityValue, i, [i]);
695 } else {
696 wsp_encode_test(MMS.PriorityValue, i, null, "CodeError");
697 }
698 }
700 run_next_test();
701 });
703 //
704 // Test target: ReadStatusValue
705 //
707 //// ReadStatusValue.decode ////
709 add_test(function test_ReadStatusValue_decode() {
710 for (let i = 0; i < 256; i++) {
711 if ((i >= 128) && (i <= 129)) {
712 wsp_decode_test(MMS.ReadStatusValue, [i], i);
713 } else {
714 wsp_decode_test(MMS.ReadStatusValue, [i], null, "CodeError");
715 }
716 }
718 run_next_test();
719 });
721 //// ReadStatusValue.encode ////
723 add_test(function test_ReadStatusValue_encode() {
724 for (let i = 0; i < 256; i++) {
725 if ((i >= 128) && (i <= 129)) {
726 wsp_encode_test(MMS.ReadStatusValue, i, [i]);
727 } else {
728 wsp_encode_test(MMS.ReadStatusValue, i, null, "CodeError");
729 }
730 }
732 run_next_test();
733 });
735 //
736 // Test target: RecommendedRetrievalModeValue
737 //
739 //// RecommendedRetrievalModeValue.decode ////
741 add_test(function test_RecommendedRetrievalModeValue_decode() {
742 for (let i = 0; i < 256; i++) {
743 if (i == 128) {
744 wsp_decode_test(MMS.RecommendedRetrievalModeValue, [i], i);
745 } else {
746 wsp_decode_test(MMS.RecommendedRetrievalModeValue, [i], null, "CodeError");
747 }
748 }
750 run_next_test();
751 });
753 //
754 // Test target: ReplyChargingValue
755 //
757 //// ReplyChargingValue.decode ////
759 add_test(function test_ReplyChargingValue_decode() {
760 for (let i = 0; i < 256; i++) {
761 if ((i >= 128) && (i <= 131)) {
762 wsp_decode_test(MMS.ReplyChargingValue, [i], i);
763 } else {
764 wsp_decode_test(MMS.ReplyChargingValue, [i], null, "CodeError");
765 }
766 }
768 run_next_test();
769 });
771 //// ReplyChargingValue.encode ////
773 add_test(function test_ReplyChargingValue_encode() {
774 for (let i = 0; i < 256; i++) {
775 if ((i >= 128) && (i <= 131)) {
776 wsp_encode_test(MMS.ReplyChargingValue, i, [i]);
777 } else {
778 wsp_encode_test(MMS.ReplyChargingValue, i, null, "CodeError");
779 }
780 }
782 run_next_test();
783 });
785 //
786 // Test target: ResponseText
787 //
789 //// ResponseText.decode ////
791 add_test(function test_ResponseText_decode() {
792 // Test for MMS_PDU_TYPE_MBOX_DELETE_CONF & MMS_PDU_TYPE_DELETE_CONF
793 wsp_decode_test_ex(function(data) {
794 data.array[0] = data.array.length - 1;
796 let options = {};
797 options["x-mms-message-type"] = MMS_PDU_TYPE_MBOX_DELETE_CONF;
798 return MMS.ResponseText.decode(data, options);
799 }, [0, 0x80 | 0x00].concat(strToCharCodeArray("http://no.such.com/path")),
800 {statusCount: 0, text: "http://no.such.com/path"}
801 );
802 wsp_decode_test_ex(function(data) {
803 data.array[0] = data.array.length - 1;
805 let options = {};
806 options["x-mms-message-type"] = MMS_PDU_TYPE_DELETE_CONF;
807 return MMS.ResponseText.decode(data, options);
808 }, [0, 0x80 | 0x00].concat(strToCharCodeArray("http://no.such.com/path")),
809 {statusCount: 0, text: "http://no.such.com/path"}
810 );
811 // Test for other situations
812 wsp_decode_test_ex(function(data) {
813 let options = {};
814 options["x-mms-message-type"] = MMS_PDU_TYPE_SEND_REQ;
815 return MMS.ResponseText.decode(data, options);
816 }, strToCharCodeArray("http://no.such.com/path"),
817 {text: "http://no.such.com/path"}
818 );
820 run_next_test();
821 });
823 //
824 // Test target: RetrieveStatusValue
825 //
827 //// RetrieveStatusValue.decode ////
829 add_test(function test_RetrieveStatusValue_decode() {
830 for (let i = 0; i < 256; i++) {
831 if ((i == MMS_PDU_ERROR_OK)
832 || (i >= MMS_PDU_ERROR_TRANSIENT_FAILURE)) {
833 wsp_decode_test(MMS.RetrieveStatusValue, [i], i);
834 } else {
835 wsp_decode_test(MMS.RetrieveStatusValue, [i],
836 MMS_PDU_ERROR_PERMANENT_FAILURE);
837 }
838 }
840 run_next_test();
841 });
843 //
844 // Test target: SenderVisibilityValue
845 //
847 //// SenderVisibilityValue.decode ////
849 add_test(function test_SenderVisibilityValue_decode() {
850 for (let i = 0; i < 256; i++) {
851 if ((i >= 128) && (i <= 129)) {
852 wsp_decode_test(MMS.SenderVisibilityValue, [i], i);
853 } else {
854 wsp_decode_test(MMS.SenderVisibilityValue, [i], null, "CodeError");
855 }
856 }
858 run_next_test();
859 });
861 //// SenderVisibilityValue.encode ////
863 add_test(function test_SenderVisibilityValue_encode() {
864 for (let i = 0; i < 256; i++) {
865 if ((i >= 128) && (i <= 129)) {
866 wsp_encode_test(MMS.SenderVisibilityValue, i, [i]);
867 } else {
868 wsp_encode_test(MMS.SenderVisibilityValue, i, null, "CodeError");
869 }
870 }
872 run_next_test();
873 });
875 //
876 // Test target: StatusValue
877 //
879 //// StatusValue.decode ////
881 add_test(function test_StatusValue_decode() {
882 for (let i = 0; i < 256; i++) {
883 if ((i >= 128) && (i <= 135)) {
884 wsp_decode_test(MMS.StatusValue, [i], i);
885 } else {
886 wsp_decode_test(MMS.StatusValue, [i], null, "CodeError");
887 }
888 }
890 run_next_test();
891 });
893 //// StatusValue.encode ////
895 add_test(function test_StatusValue_encode() {
896 for (let i = 0; i < 256; i++) {
897 if ((i >= 128) && (i <= 135)) {
898 wsp_encode_test(MMS.StatusValue, i, [i]);
899 } else {
900 wsp_encode_test(MMS.StatusValue, i, null, "CodeError");
901 }
902 }
904 run_next_test();
905 });
907 //
908 // Test target: PduHelper
909 //
911 //// PduHelper.parseHeaders ////
913 add_test(function test_PduHelper_parseHeaders() {
914 function parse(input, expect, exception) {
915 let data = {array: input, offset: 0};
916 do_check_throws(wsp_test_func.bind(null, MMS.PduHelper.parseHeaders, data, expect),
917 exception);
918 }
920 // Parse ends with Content-Type
921 let expect = {};
922 expect["x-mms-mms-version"] = MMS_VERSION_1_3;
923 expect["content-type"] = {
924 media: "application/vnd.wap.multipart.related",
925 params: null,
926 };
927 parse([0x80 | 0x0D, 0x80 | MMS_VERSION_1_3, // X-Mms-Mms-Version: 1.3
928 0x80 | 0x04, 0x80 | 0x33, // Content-Type: application/vnd.wap.multipart.related
929 0x80 | 0x0C, MMS_PDU_TYPE_SEND_REQ // X-Mms-Message-Type: M-Send.req
930 ], expect);
932 // Parse header fields with multiple entries
933 expect = {
934 to: [
935 { address: "+123", type: "PLMN" },
936 { address: "+456", type: "num" },
937 ],
938 };
939 expect["content-type"] = {
940 media: "application/vnd.wap.multipart.related",
941 params: null,
942 };
943 parse(Array.concat([0x80 | 0x17]).concat(strToCharCodeArray("+123/TYPE=PLMN"))
944 .concat([0x80 | 0x17]).concat(strToCharCodeArray("+456"))
945 .concat([0x80 | 0x04, 0x80 | 0x33]),
946 expect);
948 run_next_test();
949 });
951 //// PduHelper.encodeHeader ////
953 add_test(function test_PduHelper_encodeHeader() {
954 function func(name, data, headers) {
955 MMS.PduHelper.encodeHeader(data, headers, name);
957 // Remove extra space consumed during encoding.
958 while (data.array.length > data.offset) {
959 data.array.pop();
960 }
962 return data.array;
963 }
965 // Encode header fields with multiple entries
966 let headers = {
967 to: [
968 { address: "+123", type: "PLMN" },
969 { address: "+456", type: "num" },
970 ],
971 };
972 wsp_encode_test_ex(func.bind(null, "to"), headers,
973 Array.concat([0x80 | 0x17]).concat(strToCharCodeArray("+123/TYPE=PLMN"))
974 .concat([0x80 | 0x17]).concat(strToCharCodeArray("+456")));
976 run_next_test();
977 });
979 //// PduHelper.encodeHeaderIfExists ////
981 add_test(function test_PduHelper_encodeHeaderIfExists() {
982 function func(name, data, headers) {
983 MMS.PduHelper.encodeHeaderIfExists(data, headers, name);
985 // Remove extra space consumed during encoding.
986 while (data.array.length > data.offset) {
987 data.array.pop();
988 }
990 return data.array;
991 }
993 wsp_encode_test_ex(func.bind(null, "to"), {}, []);
995 run_next_test();
996 });
998 //// PduHelper.encodeHeaders ////
1000 add_test(function test_PduHelper_encodeHeaders() {
1001 function func(data, headers) {
1002 MMS.PduHelper.encodeHeaders(data, headers);
1004 // Remove extra space consumed during encoding.
1005 while (data.array.length > data.offset) {
1006 data.array.pop();
1007 }
1009 return data.array;
1010 }
1012 let headers = {};
1013 headers["x-mms-message-type"] = MMS_PDU_TYPE_SEND_REQ;
1014 headers["x-mms-mms-version"] = MMS_VERSION_1_3;
1015 headers["x-mms-transaction-id"] = "asdf";
1016 headers["to"] = { address: "+123", type: "PLMN" };
1017 headers["content-type"] = {
1018 media: "application/vnd.wap.multipart.related",
1019 };
1020 wsp_encode_test_ex(func, headers,
1021 Array.concat([0x80 | 0x0C, MMS_PDU_TYPE_SEND_REQ])
1022 .concat([0x80 | 0x18]).concat(strToCharCodeArray(headers["x-mms-transaction-id"]))
1023 .concat([0x80 | 0x0D, 0x80 | MMS_VERSION_1_3])
1024 .concat([0x80 | 0x17]).concat(strToCharCodeArray("+123/TYPE=PLMN"))
1025 .concat([0x80 | 0x04, 0x80 | 0x33]));
1027 run_next_test();
1028 });