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.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | let SI = {}; |
michael@0 | 5 | subscriptLoader.loadSubScript("resource://gre/modules/SiPduHelper.jsm", SI); |
michael@0 | 6 | SI.debug = do_print; |
michael@0 | 7 | |
michael@0 | 8 | function run_test() { |
michael@0 | 9 | run_next_test(); |
michael@0 | 10 | } |
michael@0 | 11 | |
michael@0 | 12 | |
michael@0 | 13 | /** |
michael@0 | 14 | * SI in Plain text |
michael@0 | 15 | */ |
michael@0 | 16 | add_test(function test_si_parse_plain_text() { |
michael@0 | 17 | let contentType = ""; |
michael@0 | 18 | let data = {}; |
michael@0 | 19 | |
michael@0 | 20 | contentType = "text/vnd.wap.si"; |
michael@0 | 21 | data.array = new Uint8Array([ |
michael@0 | 22 | 0x3C, 0x3F, 0x78, 0x6D, 0x6C, 0x20, 0x76, 0x65, |
michael@0 | 23 | 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3D, 0x27, 0x31, |
michael@0 | 24 | 0x2E, 0x30, 0x27, 0x3F, 0x3E, 0x0A, 0x3C, 0x73, |
michael@0 | 25 | 0x69, 0x3E, 0x3C, 0x69, 0x6E, 0x64, 0x69, 0x63, |
michael@0 | 26 | 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x68, 0x72, |
michael@0 | 27 | 0x65, 0x66, 0x3D, 0x27, 0x68, 0x74, 0x74, 0x70, |
michael@0 | 28 | 0x3A, 0x2F, 0x2F, 0x77, 0x77, 0x77, 0x2E, 0x6F, |
michael@0 | 29 | 0x72, 0x65, 0x69, 0x6C, 0x6C, 0x79, 0x2E, 0x63, |
michael@0 | 30 | 0x6F, 0x6D, 0x27, 0x3E, 0x43, 0x68, 0x65, 0x63, |
michael@0 | 31 | 0x6B, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x77, |
michael@0 | 32 | 0x65, 0x62, 0x73, 0x69, 0x74, 0x65, 0x3C, 0x2F, |
michael@0 | 33 | 0x69, 0x6E, 0x64, 0x69, 0x63, 0x61, 0x74, 0x69, |
michael@0 | 34 | 0x6F, 0x6E, 0x3E, 0x3C, 0x2F, 0x73, 0x69, 0x3E |
michael@0 | 35 | ]); |
michael@0 | 36 | data.offset = 0; |
michael@0 | 37 | let result = "<?xml version='1.0'?>\n<si><indication href='http://www.oreilly.com'>Check this website</indication></si>"; |
michael@0 | 38 | let msg = SI.PduHelper.parse(data, contentType); |
michael@0 | 39 | do_check_eq(msg.content, result); |
michael@0 | 40 | |
michael@0 | 41 | run_next_test(); |
michael@0 | 42 | }); |
michael@0 | 43 | |
michael@0 | 44 | /** |
michael@0 | 45 | * Empty SI compressed by WBXML |
michael@0 | 46 | */ |
michael@0 | 47 | add_test(function test_si_parse_wbxml_empty() { |
michael@0 | 48 | let msg = {}; |
michael@0 | 49 | let contentType = ""; |
michael@0 | 50 | let data = {}; |
michael@0 | 51 | |
michael@0 | 52 | contentType = "application/vnd.wap.sic"; |
michael@0 | 53 | data.array = new Uint8Array([ |
michael@0 | 54 | 0x02, 0x05, 0x6A, 0x00, 0x05 |
michael@0 | 55 | ]); |
michael@0 | 56 | data.offset = 0; |
michael@0 | 57 | let result = "<si/>"; |
michael@0 | 58 | let msg = SI.PduHelper.parse(data, contentType); |
michael@0 | 59 | do_check_eq(msg.content, result); |
michael@0 | 60 | |
michael@0 | 61 | run_next_test(); |
michael@0 | 62 | }); |
michael@0 | 63 | |
michael@0 | 64 | /** |
michael@0 | 65 | * Empty SI compressed by WBXML, with public ID stored in string table |
michael@0 | 66 | */ |
michael@0 | 67 | add_test(function test_si_parse_wbxml_empty_public_id_string_table() { |
michael@0 | 68 | let msg = {}; |
michael@0 | 69 | let contentType = ""; |
michael@0 | 70 | let data = {}; |
michael@0 | 71 | |
michael@0 | 72 | contentType = "application/vnd.wap.sic"; |
michael@0 | 73 | data.array = new Uint8Array([ |
michael@0 | 74 | 0x02, 0x00, 0x00, 0x6A, 0x1C, 0x2D, 0x2F, 0x2F, |
michael@0 | 75 | 0x57, 0x41, 0x50, 0x46, 0x4F, 0x52, 0x55, 0x4D, |
michael@0 | 76 | 0x2F, 0x2F, 0x44, 0x54, 0x44, 0x20, 0x53, 0x49, |
michael@0 | 77 | 0x20, 0x31, 0x2E, 0x30, 0x2F, 0x2F, 0x45, 0x4E, |
michael@0 | 78 | 0x00, 0x05 |
michael@0 | 79 | ]); |
michael@0 | 80 | data.offset = 0; |
michael@0 | 81 | let result = "<si/>"; |
michael@0 | 82 | let msg = SI.PduHelper.parse(data, contentType); |
michael@0 | 83 | do_check_eq(msg.content, result); |
michael@0 | 84 | |
michael@0 | 85 | run_next_test(); |
michael@0 | 86 | }); |
michael@0 | 87 | |
michael@0 | 88 | /** |
michael@0 | 89 | * SI compressed by WBXML with href attribute |
michael@0 | 90 | */ |
michael@0 | 91 | add_test(function test_si_parse_wbxml_with_href() { |
michael@0 | 92 | let msg = {}; |
michael@0 | 93 | let contentType = ""; |
michael@0 | 94 | let data = {}; |
michael@0 | 95 | |
michael@0 | 96 | contentType = "application/vnd.wap.sic"; |
michael@0 | 97 | data.array = new Uint8Array([ |
michael@0 | 98 | 0x02, 0x05, 0x6A, 0x00, 0x45, 0xC6, 0x0D, 0x03, |
michael@0 | 99 | 0x6F, 0x72, 0x65, 0x69, 0x6C, 0x6C, 0x79, 0x00, |
michael@0 | 100 | 0x85, 0x01, 0x03, 0x43, 0x68, 0x65, 0x63, 0x6B, |
michael@0 | 101 | 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x77, 0x65, |
michael@0 | 102 | 0x62, 0x73, 0x69, 0x74, 0x65, 0x00, 0x01, 0x01 |
michael@0 | 103 | ]); |
michael@0 | 104 | data.offset = 0; |
michael@0 | 105 | let result = "<si><indication href=\"http://www.oreilly.com/\">" + |
michael@0 | 106 | "Check this website</indication></si>"; |
michael@0 | 107 | let msg = SI.PduHelper.parse(data, contentType); |
michael@0 | 108 | do_check_eq(msg.content, result); |
michael@0 | 109 | |
michael@0 | 110 | run_next_test(); |
michael@0 | 111 | }); |
michael@0 | 112 | |
michael@0 | 113 | /** |
michael@0 | 114 | * SI compressed by WBXML with href attribute containing reserved XML character |
michael@0 | 115 | */ |
michael@0 | 116 | add_test(function test_si_parse_wbxml_with_href_reserved_char() { |
michael@0 | 117 | let msg = {}; |
michael@0 | 118 | let contentType = ""; |
michael@0 | 119 | let data = {}; |
michael@0 | 120 | |
michael@0 | 121 | contentType = "application/vnd.wap.sic"; |
michael@0 | 122 | data.array = new Uint8Array([ |
michael@0 | 123 | 0x02, 0x05, 0x6A, 0x00, 0x45, 0xC6, 0x0D, 0x03, |
michael@0 | 124 | 0x6F, 0x72, 0x65, 0x69, 0x6C, 0x6C, 0x79, 0x00, |
michael@0 | 125 | 0x85, 0x03, 0x66, 0x6F, 0x6F, 0x26, 0x62, 0x61, |
michael@0 | 126 | 0x72, 0x00, 0x01, 0x03, 0x43, 0x68, 0x65, 0x63, |
michael@0 | 127 | 0x6B, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x77, |
michael@0 | 128 | 0x65, 0x62, 0x73, 0x69, 0x74, 0x65, 0x00, 0x01, |
michael@0 | 129 | 0x01 |
michael@0 | 130 | ]); |
michael@0 | 131 | data.offset = 0; |
michael@0 | 132 | let result = "<si><indication href=\"http://www.oreilly.com/foo&bar\">" + |
michael@0 | 133 | "Check this website</indication></si>"; |
michael@0 | 134 | let msg = SI.PduHelper.parse(data, contentType); |
michael@0 | 135 | do_check_eq(msg.content, result); |
michael@0 | 136 | |
michael@0 | 137 | run_next_test(); |
michael@0 | 138 | }); |
michael@0 | 139 | |
michael@0 | 140 | /** |
michael@0 | 141 | * SI compressed by WBXML with href and date attribute |
michael@0 | 142 | */ |
michael@0 | 143 | add_test(function test_si_parse_wbxml_with_href_date() { |
michael@0 | 144 | let msg = {}; |
michael@0 | 145 | let contentType = ""; |
michael@0 | 146 | let data = {}; |
michael@0 | 147 | |
michael@0 | 148 | contentType = "application/vnd.wap.sic"; |
michael@0 | 149 | data.array = new Uint8Array([ |
michael@0 | 150 | 0x02, 0x05, 0x6A, 0x00, 0x45, 0xC6, 0x0D, 0x03, |
michael@0 | 151 | 0x78, 0x79, 0x7A, 0x00, 0x85, 0x03, 0x65, 0x6D, |
michael@0 | 152 | 0x61, 0x69, 0x6C, 0x2F, 0x31, 0x32, 0x33, 0x2F, |
michael@0 | 153 | 0x61, 0x62, 0x63, 0x2E, 0x77, 0x6D, 0x6C, 0x00, |
michael@0 | 154 | 0x0A, 0xC3, 0x07, 0x19, 0x99, 0x06, 0x25, 0x15, |
michael@0 | 155 | 0x23, 0x15, 0x10, 0xC3, 0x04, 0x19, 0x99, 0x06, |
michael@0 | 156 | 0x30, 0x01, 0x03, 0x59, 0x6F, 0x75, 0x20, 0x68, |
michael@0 | 157 | 0x61, 0x76, 0x65, 0x20, 0x34, 0x20, 0x6E, 0x65, |
michael@0 | 158 | 0x77, 0x20, 0x65, 0x6D, 0x61, 0x69, 0x6C, 0x73, |
michael@0 | 159 | 0x00, 0x01, 0x01 |
michael@0 | 160 | ]); |
michael@0 | 161 | data.offset = 0; |
michael@0 | 162 | let result = "<si><indication href=\"http://www.xyz.com/email/123/abc.wml\"" + |
michael@0 | 163 | " created=\"1999-06-25T15:23:15Z\" si-expires=\"1999-06-30T00:00:00Z\">" + |
michael@0 | 164 | "You have 4 new emails</indication></si>"; |
michael@0 | 165 | let msg = SI.PduHelper.parse(data, contentType); |
michael@0 | 166 | do_check_eq(msg.content, result); |
michael@0 | 167 | |
michael@0 | 168 | run_next_test(); |
michael@0 | 169 | }); |
michael@0 | 170 | |
michael@0 | 171 | /** |
michael@0 | 172 | * SI compressed by WBXML with attributes and string table |
michael@0 | 173 | */ |
michael@0 | 174 | add_test(function test_si_parse_wbxml_with_attr_string_table() { |
michael@0 | 175 | let msg = {}; |
michael@0 | 176 | let contentType = ""; |
michael@0 | 177 | let data = {}; |
michael@0 | 178 | |
michael@0 | 179 | contentType = "application/vnd.wap.sic"; |
michael@0 | 180 | data.array = new Uint8Array([ |
michael@0 | 181 | 0x02, 0x05, 0x6A, 0x28, 0x65, 0x6D, 0x61, 0x69, |
michael@0 | 182 | 0x6C, 0x2F, 0x31, 0x32, 0x33, 0x2F, 0x61, 0x62, |
michael@0 | 183 | 0x63, 0x2E, 0x77, 0x6D, 0x6C, 0x00, 0x59, 0x6F, |
michael@0 | 184 | 0x75, 0x20, 0x68, 0x61, 0x76, 0x65, 0x20, 0x34, |
michael@0 | 185 | 0x20, 0x6E, 0x65, 0x77, 0x20, 0x65, 0x6D, 0x61, |
michael@0 | 186 | 0x69, 0x6C, 0x73, 0x00, 0x45, 0xC6, 0x0D, 0x03, |
michael@0 | 187 | 0x78, 0x79, 0x7A, 0x00, 0x85, 0x83, 0x00, 0x0A, |
michael@0 | 188 | 0xC3, 0x07, 0x19, 0x99, 0x06, 0x25, 0x15, 0x23, |
michael@0 | 189 | 0x15, 0x10, 0xC3, 0x04, 0x19, 0x99, 0x06, 0x30, |
michael@0 | 190 | 0x01, 0x83, 0x12, 0x01, 0x01 |
michael@0 | 191 | ]); |
michael@0 | 192 | data.offset = 0; |
michael@0 | 193 | let result = "<si><indication href=\"http://www.xyz.com/email/123/abc.wml\"" + |
michael@0 | 194 | " created=\"1999-06-25T15:23:15Z\" si-expires=\"1999-06-30T00:00:00Z\">" + |
michael@0 | 195 | "You have 4 new emails</indication></si>"; |
michael@0 | 196 | let msg = SI.PduHelper.parse(data, contentType); |
michael@0 | 197 | do_check_eq(msg.content, result); |
michael@0 | 198 | |
michael@0 | 199 | run_next_test(); |
michael@0 | 200 | }); |