michael@0: /* Any copyright is dedicated to the Public Domain.
michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0:
michael@0: let SI = {};
michael@0: subscriptLoader.loadSubScript("resource://gre/modules/SiPduHelper.jsm", SI);
michael@0: SI.debug = do_print;
michael@0:
michael@0: function run_test() {
michael@0: run_next_test();
michael@0: }
michael@0:
michael@0:
michael@0: /**
michael@0: * SI in Plain text
michael@0: */
michael@0: add_test(function test_si_parse_plain_text() {
michael@0: let contentType = "";
michael@0: let data = {};
michael@0:
michael@0: contentType = "text/vnd.wap.si";
michael@0: data.array = new Uint8Array([
michael@0: 0x3C, 0x3F, 0x78, 0x6D, 0x6C, 0x20, 0x76, 0x65,
michael@0: 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3D, 0x27, 0x31,
michael@0: 0x2E, 0x30, 0x27, 0x3F, 0x3E, 0x0A, 0x3C, 0x73,
michael@0: 0x69, 0x3E, 0x3C, 0x69, 0x6E, 0x64, 0x69, 0x63,
michael@0: 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x68, 0x72,
michael@0: 0x65, 0x66, 0x3D, 0x27, 0x68, 0x74, 0x74, 0x70,
michael@0: 0x3A, 0x2F, 0x2F, 0x77, 0x77, 0x77, 0x2E, 0x6F,
michael@0: 0x72, 0x65, 0x69, 0x6C, 0x6C, 0x79, 0x2E, 0x63,
michael@0: 0x6F, 0x6D, 0x27, 0x3E, 0x43, 0x68, 0x65, 0x63,
michael@0: 0x6B, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x77,
michael@0: 0x65, 0x62, 0x73, 0x69, 0x74, 0x65, 0x3C, 0x2F,
michael@0: 0x69, 0x6E, 0x64, 0x69, 0x63, 0x61, 0x74, 0x69,
michael@0: 0x6F, 0x6E, 0x3E, 0x3C, 0x2F, 0x73, 0x69, 0x3E
michael@0: ]);
michael@0: data.offset = 0;
michael@0: let result = "\nCheck this website";
michael@0: let msg = SI.PduHelper.parse(data, contentType);
michael@0: do_check_eq(msg.content, result);
michael@0:
michael@0: run_next_test();
michael@0: });
michael@0:
michael@0: /**
michael@0: * Empty SI compressed by WBXML
michael@0: */
michael@0: add_test(function test_si_parse_wbxml_empty() {
michael@0: let msg = {};
michael@0: let contentType = "";
michael@0: let data = {};
michael@0:
michael@0: contentType = "application/vnd.wap.sic";
michael@0: data.array = new Uint8Array([
michael@0: 0x02, 0x05, 0x6A, 0x00, 0x05
michael@0: ]);
michael@0: data.offset = 0;
michael@0: let result = "";
michael@0: let msg = SI.PduHelper.parse(data, contentType);
michael@0: do_check_eq(msg.content, result);
michael@0:
michael@0: run_next_test();
michael@0: });
michael@0:
michael@0: /**
michael@0: * Empty SI compressed by WBXML, with public ID stored in string table
michael@0: */
michael@0: add_test(function test_si_parse_wbxml_empty_public_id_string_table() {
michael@0: let msg = {};
michael@0: let contentType = "";
michael@0: let data = {};
michael@0:
michael@0: contentType = "application/vnd.wap.sic";
michael@0: data.array = new Uint8Array([
michael@0: 0x02, 0x00, 0x00, 0x6A, 0x1C, 0x2D, 0x2F, 0x2F,
michael@0: 0x57, 0x41, 0x50, 0x46, 0x4F, 0x52, 0x55, 0x4D,
michael@0: 0x2F, 0x2F, 0x44, 0x54, 0x44, 0x20, 0x53, 0x49,
michael@0: 0x20, 0x31, 0x2E, 0x30, 0x2F, 0x2F, 0x45, 0x4E,
michael@0: 0x00, 0x05
michael@0: ]);
michael@0: data.offset = 0;
michael@0: let result = "";
michael@0: let msg = SI.PduHelper.parse(data, contentType);
michael@0: do_check_eq(msg.content, result);
michael@0:
michael@0: run_next_test();
michael@0: });
michael@0:
michael@0: /**
michael@0: * SI compressed by WBXML with href attribute
michael@0: */
michael@0: add_test(function test_si_parse_wbxml_with_href() {
michael@0: let msg = {};
michael@0: let contentType = "";
michael@0: let data = {};
michael@0:
michael@0: contentType = "application/vnd.wap.sic";
michael@0: data.array = new Uint8Array([
michael@0: 0x02, 0x05, 0x6A, 0x00, 0x45, 0xC6, 0x0D, 0x03,
michael@0: 0x6F, 0x72, 0x65, 0x69, 0x6C, 0x6C, 0x79, 0x00,
michael@0: 0x85, 0x01, 0x03, 0x43, 0x68, 0x65, 0x63, 0x6B,
michael@0: 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x77, 0x65,
michael@0: 0x62, 0x73, 0x69, 0x74, 0x65, 0x00, 0x01, 0x01
michael@0: ]);
michael@0: data.offset = 0;
michael@0: let result = "" +
michael@0: "Check this website";
michael@0: let msg = SI.PduHelper.parse(data, contentType);
michael@0: do_check_eq(msg.content, result);
michael@0:
michael@0: run_next_test();
michael@0: });
michael@0:
michael@0: /**
michael@0: * SI compressed by WBXML with href attribute containing reserved XML character
michael@0: */
michael@0: add_test(function test_si_parse_wbxml_with_href_reserved_char() {
michael@0: let msg = {};
michael@0: let contentType = "";
michael@0: let data = {};
michael@0:
michael@0: contentType = "application/vnd.wap.sic";
michael@0: data.array = new Uint8Array([
michael@0: 0x02, 0x05, 0x6A, 0x00, 0x45, 0xC6, 0x0D, 0x03,
michael@0: 0x6F, 0x72, 0x65, 0x69, 0x6C, 0x6C, 0x79, 0x00,
michael@0: 0x85, 0x03, 0x66, 0x6F, 0x6F, 0x26, 0x62, 0x61,
michael@0: 0x72, 0x00, 0x01, 0x03, 0x43, 0x68, 0x65, 0x63,
michael@0: 0x6B, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x77,
michael@0: 0x65, 0x62, 0x73, 0x69, 0x74, 0x65, 0x00, 0x01,
michael@0: 0x01
michael@0: ]);
michael@0: data.offset = 0;
michael@0: let result = "" +
michael@0: "Check this website";
michael@0: let msg = SI.PduHelper.parse(data, contentType);
michael@0: do_check_eq(msg.content, result);
michael@0:
michael@0: run_next_test();
michael@0: });
michael@0:
michael@0: /**
michael@0: * SI compressed by WBXML with href and date attribute
michael@0: */
michael@0: add_test(function test_si_parse_wbxml_with_href_date() {
michael@0: let msg = {};
michael@0: let contentType = "";
michael@0: let data = {};
michael@0:
michael@0: contentType = "application/vnd.wap.sic";
michael@0: data.array = new Uint8Array([
michael@0: 0x02, 0x05, 0x6A, 0x00, 0x45, 0xC6, 0x0D, 0x03,
michael@0: 0x78, 0x79, 0x7A, 0x00, 0x85, 0x03, 0x65, 0x6D,
michael@0: 0x61, 0x69, 0x6C, 0x2F, 0x31, 0x32, 0x33, 0x2F,
michael@0: 0x61, 0x62, 0x63, 0x2E, 0x77, 0x6D, 0x6C, 0x00,
michael@0: 0x0A, 0xC3, 0x07, 0x19, 0x99, 0x06, 0x25, 0x15,
michael@0: 0x23, 0x15, 0x10, 0xC3, 0x04, 0x19, 0x99, 0x06,
michael@0: 0x30, 0x01, 0x03, 0x59, 0x6F, 0x75, 0x20, 0x68,
michael@0: 0x61, 0x76, 0x65, 0x20, 0x34, 0x20, 0x6E, 0x65,
michael@0: 0x77, 0x20, 0x65, 0x6D, 0x61, 0x69, 0x6C, 0x73,
michael@0: 0x00, 0x01, 0x01
michael@0: ]);
michael@0: data.offset = 0;
michael@0: let result = "" +
michael@0: "You have 4 new emails";
michael@0: let msg = SI.PduHelper.parse(data, contentType);
michael@0: do_check_eq(msg.content, result);
michael@0:
michael@0: run_next_test();
michael@0: });
michael@0:
michael@0: /**
michael@0: * SI compressed by WBXML with attributes and string table
michael@0: */
michael@0: add_test(function test_si_parse_wbxml_with_attr_string_table() {
michael@0: let msg = {};
michael@0: let contentType = "";
michael@0: let data = {};
michael@0:
michael@0: contentType = "application/vnd.wap.sic";
michael@0: data.array = new Uint8Array([
michael@0: 0x02, 0x05, 0x6A, 0x28, 0x65, 0x6D, 0x61, 0x69,
michael@0: 0x6C, 0x2F, 0x31, 0x32, 0x33, 0x2F, 0x61, 0x62,
michael@0: 0x63, 0x2E, 0x77, 0x6D, 0x6C, 0x00, 0x59, 0x6F,
michael@0: 0x75, 0x20, 0x68, 0x61, 0x76, 0x65, 0x20, 0x34,
michael@0: 0x20, 0x6E, 0x65, 0x77, 0x20, 0x65, 0x6D, 0x61,
michael@0: 0x69, 0x6C, 0x73, 0x00, 0x45, 0xC6, 0x0D, 0x03,
michael@0: 0x78, 0x79, 0x7A, 0x00, 0x85, 0x83, 0x00, 0x0A,
michael@0: 0xC3, 0x07, 0x19, 0x99, 0x06, 0x25, 0x15, 0x23,
michael@0: 0x15, 0x10, 0xC3, 0x04, 0x19, 0x99, 0x06, 0x30,
michael@0: 0x01, 0x83, 0x12, 0x01, 0x01
michael@0: ]);
michael@0: data.offset = 0;
michael@0: let result = "" +
michael@0: "You have 4 new emails";
michael@0: let msg = SI.PduHelper.parse(data, contentType);
michael@0: do_check_eq(msg.content, result);
michael@0:
michael@0: run_next_test();
michael@0: });