1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/wappush/tests/test_si_pdu_helper.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,200 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +let SI = {}; 1.8 +subscriptLoader.loadSubScript("resource://gre/modules/SiPduHelper.jsm", SI); 1.9 +SI.debug = do_print; 1.10 + 1.11 +function run_test() { 1.12 + run_next_test(); 1.13 +} 1.14 + 1.15 + 1.16 +/** 1.17 + * SI in Plain text 1.18 + */ 1.19 +add_test(function test_si_parse_plain_text() { 1.20 + let contentType = ""; 1.21 + let data = {}; 1.22 + 1.23 + contentType = "text/vnd.wap.si"; 1.24 + data.array = new Uint8Array([ 1.25 + 0x3C, 0x3F, 0x78, 0x6D, 0x6C, 0x20, 0x76, 0x65, 1.26 + 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3D, 0x27, 0x31, 1.27 + 0x2E, 0x30, 0x27, 0x3F, 0x3E, 0x0A, 0x3C, 0x73, 1.28 + 0x69, 0x3E, 0x3C, 0x69, 0x6E, 0x64, 0x69, 0x63, 1.29 + 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x68, 0x72, 1.30 + 0x65, 0x66, 0x3D, 0x27, 0x68, 0x74, 0x74, 0x70, 1.31 + 0x3A, 0x2F, 0x2F, 0x77, 0x77, 0x77, 0x2E, 0x6F, 1.32 + 0x72, 0x65, 0x69, 0x6C, 0x6C, 0x79, 0x2E, 0x63, 1.33 + 0x6F, 0x6D, 0x27, 0x3E, 0x43, 0x68, 0x65, 0x63, 1.34 + 0x6B, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x77, 1.35 + 0x65, 0x62, 0x73, 0x69, 0x74, 0x65, 0x3C, 0x2F, 1.36 + 0x69, 0x6E, 0x64, 0x69, 0x63, 0x61, 0x74, 0x69, 1.37 + 0x6F, 0x6E, 0x3E, 0x3C, 0x2F, 0x73, 0x69, 0x3E 1.38 + ]); 1.39 + data.offset = 0; 1.40 + let result = "<?xml version='1.0'?>\n<si><indication href='http://www.oreilly.com'>Check this website</indication></si>"; 1.41 + let msg = SI.PduHelper.parse(data, contentType); 1.42 + do_check_eq(msg.content, result); 1.43 + 1.44 + run_next_test(); 1.45 +}); 1.46 + 1.47 +/** 1.48 + * Empty SI compressed by WBXML 1.49 + */ 1.50 +add_test(function test_si_parse_wbxml_empty() { 1.51 + let msg = {}; 1.52 + let contentType = ""; 1.53 + let data = {}; 1.54 + 1.55 + contentType = "application/vnd.wap.sic"; 1.56 + data.array = new Uint8Array([ 1.57 + 0x02, 0x05, 0x6A, 0x00, 0x05 1.58 + ]); 1.59 + data.offset = 0; 1.60 + let result = "<si/>"; 1.61 + let msg = SI.PduHelper.parse(data, contentType); 1.62 + do_check_eq(msg.content, result); 1.63 + 1.64 + run_next_test(); 1.65 +}); 1.66 + 1.67 +/** 1.68 + * Empty SI compressed by WBXML, with public ID stored in string table 1.69 + */ 1.70 +add_test(function test_si_parse_wbxml_empty_public_id_string_table() { 1.71 + let msg = {}; 1.72 + let contentType = ""; 1.73 + let data = {}; 1.74 + 1.75 + contentType = "application/vnd.wap.sic"; 1.76 + data.array = new Uint8Array([ 1.77 + 0x02, 0x00, 0x00, 0x6A, 0x1C, 0x2D, 0x2F, 0x2F, 1.78 + 0x57, 0x41, 0x50, 0x46, 0x4F, 0x52, 0x55, 0x4D, 1.79 + 0x2F, 0x2F, 0x44, 0x54, 0x44, 0x20, 0x53, 0x49, 1.80 + 0x20, 0x31, 0x2E, 0x30, 0x2F, 0x2F, 0x45, 0x4E, 1.81 + 0x00, 0x05 1.82 + ]); 1.83 + data.offset = 0; 1.84 + let result = "<si/>"; 1.85 + let msg = SI.PduHelper.parse(data, contentType); 1.86 + do_check_eq(msg.content, result); 1.87 + 1.88 + run_next_test(); 1.89 +}); 1.90 + 1.91 +/** 1.92 + * SI compressed by WBXML with href attribute 1.93 + */ 1.94 +add_test(function test_si_parse_wbxml_with_href() { 1.95 + let msg = {}; 1.96 + let contentType = ""; 1.97 + let data = {}; 1.98 + 1.99 + contentType = "application/vnd.wap.sic"; 1.100 + data.array = new Uint8Array([ 1.101 + 0x02, 0x05, 0x6A, 0x00, 0x45, 0xC6, 0x0D, 0x03, 1.102 + 0x6F, 0x72, 0x65, 0x69, 0x6C, 0x6C, 0x79, 0x00, 1.103 + 0x85, 0x01, 0x03, 0x43, 0x68, 0x65, 0x63, 0x6B, 1.104 + 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x77, 0x65, 1.105 + 0x62, 0x73, 0x69, 0x74, 0x65, 0x00, 0x01, 0x01 1.106 + ]); 1.107 + data.offset = 0; 1.108 + let result = "<si><indication href=\"http://www.oreilly.com/\">" + 1.109 + "Check this website</indication></si>"; 1.110 + let msg = SI.PduHelper.parse(data, contentType); 1.111 + do_check_eq(msg.content, result); 1.112 + 1.113 + run_next_test(); 1.114 +}); 1.115 + 1.116 +/** 1.117 + * SI compressed by WBXML with href attribute containing reserved XML character 1.118 + */ 1.119 +add_test(function test_si_parse_wbxml_with_href_reserved_char() { 1.120 + let msg = {}; 1.121 + let contentType = ""; 1.122 + let data = {}; 1.123 + 1.124 + contentType = "application/vnd.wap.sic"; 1.125 + data.array = new Uint8Array([ 1.126 + 0x02, 0x05, 0x6A, 0x00, 0x45, 0xC6, 0x0D, 0x03, 1.127 + 0x6F, 0x72, 0x65, 0x69, 0x6C, 0x6C, 0x79, 0x00, 1.128 + 0x85, 0x03, 0x66, 0x6F, 0x6F, 0x26, 0x62, 0x61, 1.129 + 0x72, 0x00, 0x01, 0x03, 0x43, 0x68, 0x65, 0x63, 1.130 + 0x6B, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x77, 1.131 + 0x65, 0x62, 0x73, 0x69, 0x74, 0x65, 0x00, 0x01, 1.132 + 0x01 1.133 + ]); 1.134 + data.offset = 0; 1.135 + let result = "<si><indication href=\"http://www.oreilly.com/foo&bar\">" + 1.136 + "Check this website</indication></si>"; 1.137 + let msg = SI.PduHelper.parse(data, contentType); 1.138 + do_check_eq(msg.content, result); 1.139 + 1.140 + run_next_test(); 1.141 +}); 1.142 + 1.143 +/** 1.144 + * SI compressed by WBXML with href and date attribute 1.145 + */ 1.146 +add_test(function test_si_parse_wbxml_with_href_date() { 1.147 + let msg = {}; 1.148 + let contentType = ""; 1.149 + let data = {}; 1.150 + 1.151 + contentType = "application/vnd.wap.sic"; 1.152 + data.array = new Uint8Array([ 1.153 + 0x02, 0x05, 0x6A, 0x00, 0x45, 0xC6, 0x0D, 0x03, 1.154 + 0x78, 0x79, 0x7A, 0x00, 0x85, 0x03, 0x65, 0x6D, 1.155 + 0x61, 0x69, 0x6C, 0x2F, 0x31, 0x32, 0x33, 0x2F, 1.156 + 0x61, 0x62, 0x63, 0x2E, 0x77, 0x6D, 0x6C, 0x00, 1.157 + 0x0A, 0xC3, 0x07, 0x19, 0x99, 0x06, 0x25, 0x15, 1.158 + 0x23, 0x15, 0x10, 0xC3, 0x04, 0x19, 0x99, 0x06, 1.159 + 0x30, 0x01, 0x03, 0x59, 0x6F, 0x75, 0x20, 0x68, 1.160 + 0x61, 0x76, 0x65, 0x20, 0x34, 0x20, 0x6E, 0x65, 1.161 + 0x77, 0x20, 0x65, 0x6D, 0x61, 0x69, 0x6C, 0x73, 1.162 + 0x00, 0x01, 0x01 1.163 + ]); 1.164 + data.offset = 0; 1.165 + let result = "<si><indication href=\"http://www.xyz.com/email/123/abc.wml\"" + 1.166 + " created=\"1999-06-25T15:23:15Z\" si-expires=\"1999-06-30T00:00:00Z\">" + 1.167 + "You have 4 new emails</indication></si>"; 1.168 + let msg = SI.PduHelper.parse(data, contentType); 1.169 + do_check_eq(msg.content, result); 1.170 + 1.171 + run_next_test(); 1.172 +}); 1.173 + 1.174 +/** 1.175 + * SI compressed by WBXML with attributes and string table 1.176 + */ 1.177 +add_test(function test_si_parse_wbxml_with_attr_string_table() { 1.178 + let msg = {}; 1.179 + let contentType = ""; 1.180 + let data = {}; 1.181 + 1.182 + contentType = "application/vnd.wap.sic"; 1.183 + data.array = new Uint8Array([ 1.184 + 0x02, 0x05, 0x6A, 0x28, 0x65, 0x6D, 0x61, 0x69, 1.185 + 0x6C, 0x2F, 0x31, 0x32, 0x33, 0x2F, 0x61, 0x62, 1.186 + 0x63, 0x2E, 0x77, 0x6D, 0x6C, 0x00, 0x59, 0x6F, 1.187 + 0x75, 0x20, 0x68, 0x61, 0x76, 0x65, 0x20, 0x34, 1.188 + 0x20, 0x6E, 0x65, 0x77, 0x20, 0x65, 0x6D, 0x61, 1.189 + 0x69, 0x6C, 0x73, 0x00, 0x45, 0xC6, 0x0D, 0x03, 1.190 + 0x78, 0x79, 0x7A, 0x00, 0x85, 0x83, 0x00, 0x0A, 1.191 + 0xC3, 0x07, 0x19, 0x99, 0x06, 0x25, 0x15, 0x23, 1.192 + 0x15, 0x10, 0xC3, 0x04, 0x19, 0x99, 0x06, 0x30, 1.193 + 0x01, 0x83, 0x12, 0x01, 0x01 1.194 + ]); 1.195 + data.offset = 0; 1.196 + let result = "<si><indication href=\"http://www.xyz.com/email/123/abc.wml\"" + 1.197 + " created=\"1999-06-25T15:23:15Z\" si-expires=\"1999-06-30T00:00:00Z\">" + 1.198 + "You have 4 new emails</indication></si>"; 1.199 + let msg = SI.PduHelper.parse(data, contentType); 1.200 + do_check_eq(msg.content, result); 1.201 + 1.202 + run_next_test(); 1.203 +});