Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 MARIONETTE_TIMEOUT = 60000;
6 // Copied from ril_consts.js. Some entries are commented out in ril_const.js,
7 // but we still want to test them here.
8 const GSM_SMS_STRICT_7BIT_CHARMAP = {
9 "\u0024": "\u0024", // "$" => "$", already in default alphabet
10 "\u00a5": "\u00a5", // "¥" => "¥", already in default alphabet
11 "\u00c0": "\u0041", // "À" => "A"
12 "\u00c1": "\u0041", // "Á" => "A"
13 "\u00c2": "\u0041", // "Â" => "A"
14 "\u00c3": "\u0041", // "Ã" => "A"
15 "\u00c4": "\u00c4", // "Ä" => "Ä", already in default alphabet
16 "\u00c5": "\u00c5", // "Å" => "Å", already in default alphabet
17 "\u00c6": "\u00c6", // "Æ" => "Æ", already in default alphabet
18 "\u00c7": "\u00c7", // "Ç" => "Ç", already in default alphabet
19 "\u00c8": "\u0045", // "È" => "E"
20 "\u00c9": "\u00c9", // "É" => "É", already in default alphabet
21 "\u00ca": "\u0045", // "Ê" => "E"
22 "\u00cb": "\u0045", // "Ë" => "E"
23 "\u00cc": "\u0049", // "Ì" => "I"
24 "\u00cd": "\u0049", // "Í" => "I"
25 "\u00ce": "\u0049", // "Î" => "I"
26 "\u00cf": "\u0049", // "Ï" => "I"
27 "\u00d1": "\u00d1", // "Ñ" => "Ñ", already in default alphabet
28 "\u00d2": "\u004f", // "Ò" => "O"
29 "\u00d3": "\u004f", // "Ó" => "O"
30 "\u00d4": "\u004f", // "Ô" => "O"
31 "\u00d5": "\u004f", // "Õ" => "O"
32 "\u00d6": "\u00d6", // "Ö" => "Ö", already in default alphabet
33 "\u00d9": "\u0055", // "Ù" => "U"
34 "\u00da": "\u0055", // "Ú" => "U"
35 "\u00db": "\u0055", // "Û" => "U"
36 "\u00dc": "\u00dc", // "Ü" => "Ü", already in default alphabet
37 "\u00df": "\u00df", // "ß" => "ß", already in default alphabet
38 "\u00e0": "\u00e0", // "à" => "à", already in default alphabet
39 "\u00e1": "\u0061", // "á" => "a"
40 "\u00e2": "\u0061", // "â" => "a"
41 "\u00e3": "\u0061", // "ã" => "a"
42 "\u00e4": "\u00e4", // "ä" => "ä", already in default alphabet
43 "\u00e5": "\u00e5", // "å" => "å", already in default alphabet
44 "\u00e6": "\u00e6", // "æ" => "æ", already in default alphabet
45 "\u00e7": "\u00c7", // "ç" => "Ç"
46 "\u00e8": "\u00e8", // "è" => "è", already in default alphabet
47 "\u00e9": "\u00e9", // "é" => "é", already in default alphabet
48 "\u00ea": "\u0065", // "ê" => "e"
49 "\u00eb": "\u0065", // "ë" => "e"
50 "\u00ec": "\u00ec", // "ì" => "ì", already in default alphabet
51 "\u00ed": "\u0069", // "í" => "i"
52 "\u00ee": "\u0069", // "î" => "i"
53 "\u00ef": "\u0069", // "ï" => "i"
54 "\u00f1": "\u00f1", // "ñ" => "ñ", already in default alphabet
55 "\u00f2": "\u00f2", // "ò" => "ò", already in default alphabet
56 "\u00f3": "\u006f", // "ó" => "o"
57 "\u00f4": "\u006f", // "ô" => "o"
58 "\u00f5": "\u006f", // "õ" => "o"
59 "\u00f6": "\u00f6", // "ö" => "ö", already in default alphabet
60 "\u00f8": "\u00f8", // "ø" => "ø", already in default alphabet
61 "\u00f9": "\u00f9", // "ù" => "ù", already in default alphabet
62 "\u00fa": "\u0075", // "ú" => "u"
63 "\u00fb": "\u0075", // "û" => "u"
64 "\u00fc": "\u00fc", // "ü" => "ü", already in default alphabet
65 "\u00fe": "\u0074", // "þ" => "t"
66 "\u0100": "\u0041", // "Ā" => "A"
67 "\u0101": "\u0061", // "ā" => "a"
68 "\u0106": "\u0043", // "Ć" => "C"
69 "\u0107": "\u0063", // "ć" => "c"
70 "\u010c": "\u0043", // "Č" => "C"
71 "\u010d": "\u0063", // "č" => "c"
72 "\u010f": "\u0064", // "ď" => "d"
73 "\u0110": "\u0044", // "Đ" => "D"
74 "\u0111": "\u0064", // "đ" => "d"
75 "\u0112": "\u0045", // "Ē" => "E"
76 "\u0113": "\u0065", // "ē" => "e"
77 "\u0118": "\u0045", // "Ę" => "E"
78 "\u0119": "\u0065", // "ę" => "e"
79 "\u0128": "\u0049", // "Ĩ" => "I"
80 "\u0129": "\u0069", // "ĩ" => "i"
81 "\u012a": "\u0049", // "Ī" => "I"
82 "\u012b": "\u0069", // "ī" => "i"
83 "\u012e": "\u0049", // "Į" => "I"
84 "\u012f": "\u0069", // "į" => "i"
85 "\u0141": "\u004c", // "Ł" => "L"
86 "\u0142": "\u006c", // "ł" => "l"
87 "\u0143": "\u004e", // "Ń" => "N"
88 "\u0144": "\u006e", // "ń" => "n"
89 "\u0147": "\u004e", // "Ň" => "N"
90 "\u0148": "\u006e", // "ň" => "n"
91 "\u014c": "\u004f", // "Ō" => "O"
92 "\u014d": "\u006f", // "ō" => "o"
93 "\u0152": "\u004f", // "Œ" => "O"
94 "\u0153": "\u006f", // "œ" => "o"
95 "\u0158": "\u0052", // "Ř" => "R"
96 "\u0159": "\u0072", // "ř" => "r"
97 "\u0160": "\u0053", // "Š" => "S"
98 "\u0161": "\u0073", // "š" => "s"
99 "\u0165": "\u0074", // "ť" => "t"
100 "\u0168": "\u0055", // "Ū" => "U"
101 "\u0169": "\u0075", // "ū" => "u"
102 "\u016a": "\u0055", // "Ū" => "U"
103 "\u016b": "\u0075", // "ū" => "u"
104 "\u0178": "\u0059", // "Ÿ" => "Y"
105 "\u0179": "\u005a", // "Ź" => "Z"
106 "\u017a": "\u007a", // "ź" => "z"
107 "\u017b": "\u005a", // "Ż" => "Z"
108 "\u017c": "\u007a", // "ż" => "z"
109 "\u017d": "\u005a", // "Ž" => "Z"
110 "\u017e": "\u007a", // "ž" => "z"
111 "\u025b": "\u0045", // "ɛ" => "E"
112 "\u0398": "\u0398", // "Θ" => "Θ", already in default alphabet
113 "\u1e7c": "\u0056", // "Ṽ" => "V"
114 "\u1e7d": "\u0076", // "ṽ" => "v"
115 "\u1ebc": "\u0045", // "Ẽ" => "E"
116 "\u1ebd": "\u0065", // "ẽ" => "e"
117 "\u1ef8": "\u0059", // "Ỹ" => "Y"
118 "\u1ef9": "\u0079", // "ỹ" => "y"
119 "\u20a4": "\u00a3", // "₤" => "£"
120 "\u20ac": "\u20ac", // "€" => "€", already in default alphabet
121 };
123 // Emulator will loop back the outgoing SMS if the phone number equals to its
124 // control port, which is 5554 for the first emulator instance.
125 const SELF = "5554";
127 SpecialPowers.setBoolPref("dom.sms.enabled", true);
128 SpecialPowers.addPermission("sms", true, document);
130 let manager = window.navigator.mozMobileMessage;
131 ok(manager instanceof MozMobileMessageManager,
132 "manager is instance of " + manager.constructor);
134 let tasks = {
135 // List of test fuctions. Each of them should call |tasks.next()| when
136 // completed or |tasks.finish()| to jump to the last one.
137 _tasks: [],
138 _nextTaskIndex: 0,
140 push: function(func) {
141 this._tasks.push(func);
142 },
144 next: function() {
145 let index = this._nextTaskIndex++;
146 let task = this._tasks[index];
147 try {
148 task();
149 } catch (ex) {
150 ok(false, "test task[" + index + "] throws: " + ex);
151 // Run last task as clean up if possible.
152 if (index != this._tasks.length - 1) {
153 this.finish();
154 }
155 }
156 },
158 finish: function() {
159 this._tasks[this._tasks.length - 1]();
160 },
162 run: function() {
163 this.next();
164 }
165 };
167 function testStrict7BitEncodingHelper(sent, received) {
168 // The log message contains unicode and Marionette seems unable to process
169 // it and throws: |UnicodeEncodeError: 'ascii' codec can't encode character
170 // u'\xa5' in position 14: ordinal not in range(128)|.
171 //
172 //log("Testing '" + sent + "' => '" + received + "'");
174 let count = 0;
175 function done(step) {
176 count += step;
177 if (count >= 2) {
178 window.setTimeout(tasks.next.bind(tasks), 0);
179 }
180 }
182 manager.addEventListener("received", function onReceived(event) {
183 event.target.removeEventListener("received", onReceived);
185 let message = event.message;
186 is(message.body, received, "received message.body");
188 done(1);
189 });
191 let request = manager.send(SELF, sent);
192 request.addEventListener("success", function onRequestSuccess(event) {
193 let message = event.target.result;
194 is(message.body, sent, "sent message.body");
196 done(1);
197 });
198 request.addEventListener("error", function onRequestError(event) {
199 ok(false, "Can't send message out!!!");
200 done(2);
201 });
202 }
204 // Bug 877141 - If you send several spaces together in a sms, the other
205 // dipositive receives a "*" for each space.
206 //
207 // This function is called twice, with strict 7bit encoding enabled or
208 // disabled. Expect the same result in both sent and received text and with
209 // either strict 7bit encoding enabled or disabled.
210 function testBug877141() {
211 log("Testing bug 877141");
212 let sent = "1 2 3";
213 testStrict7BitEncodingHelper(sent, sent);
214 }
216 tasks.push(function() {
217 log("Testing with dom.sms.strict7BitEncoding enabled");
218 SpecialPowers.setBoolPref("dom.sms.strict7BitEncoding", true);
219 tasks.next();
220 });
223 // Test for combined string.
224 tasks.push(function() {
225 let sent = "", received = "";
226 for (let c in GSM_SMS_STRICT_7BIT_CHARMAP) {
227 sent += c;
228 received += GSM_SMS_STRICT_7BIT_CHARMAP[c];
229 }
230 testStrict7BitEncodingHelper(sent, received);
231 });
233 // When strict7BitEncoding is enabled, we should replace characters that
234 // can't be encoded with GSM 7-Bit alphabets with '*'.
235 tasks.push(function() {
236 // "Happy New Year" in Chinese.
237 let sent = "\u65b0\u5e74\u5feb\u6a02", received = "****";
238 testStrict7BitEncodingHelper(sent, received);
239 });
241 tasks.push(testBug877141);
243 tasks.push(function() {
244 log("Testing with dom.sms.strict7BitEncoding disabled");
245 SpecialPowers.setBoolPref("dom.sms.strict7BitEncoding", false);
246 tasks.next();
247 });
249 // Test for combined string.
250 tasks.push(function() {
251 let sent = "";
252 for (let c in GSM_SMS_STRICT_7BIT_CHARMAP) {
253 sent += c;
254 }
255 testStrict7BitEncodingHelper(sent, sent);
256 });
258 tasks.push(function() {
259 // "Happy New Year" in Chinese.
260 let sent = "\u65b0\u5e74\u5feb\u6a02";
261 testStrict7BitEncodingHelper(sent, sent);
262 });
264 tasks.push(testBug877141);
266 // WARNING: All tasks should be pushed before this!!!
267 tasks.push(function cleanUp() {
268 SpecialPowers.removePermission("sms", document);
269 SpecialPowers.clearUserPref("dom.sms.enabled");
270 SpecialPowers.clearUserPref("dom.sms.strict7BitEncoding");
272 finish();
273 });
275 tasks.run();