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