dom/mobilemessage/tests/marionette/test_strict_7bit_encoding.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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.

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

mercurial