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.
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 | const LEN_7BIT = 160; |
michael@0 | 7 | const LEN_7BIT_WITH_8BIT_REF = 153; |
michael@0 | 8 | const LEN_7BIT_WITH_16BIT_REF = 152; |
michael@0 | 9 | const LEN_UCS2 = 70; |
michael@0 | 10 | const LEN_UCS2_WITH_8BIT_REF = 67; |
michael@0 | 11 | const LEN_UCS2_WITH_16BIT_REF = 66; |
michael@0 | 12 | |
michael@0 | 13 | SpecialPowers.setBoolPref("dom.sms.enabled", true); |
michael@0 | 14 | let currentStrict7BitEncoding = false; |
michael@0 | 15 | SpecialPowers.setBoolPref("dom.sms.strict7BitEncoding", |
michael@0 | 16 | currentStrict7BitEncoding); |
michael@0 | 17 | SpecialPowers.addPermission("sms", true, document); |
michael@0 | 18 | |
michael@0 | 19 | let manager = window.navigator.mozMobileMessage; |
michael@0 | 20 | ok(manager instanceof MozMobileMessageManager, |
michael@0 | 21 | "manager is instance of " + manager.constructor); |
michael@0 | 22 | |
michael@0 | 23 | function times(str, n) { |
michael@0 | 24 | return (new Array(n + 1)).join(str); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | let tasks = { |
michael@0 | 28 | // List of test fuctions. Each of them should call |tasks.next()| when |
michael@0 | 29 | // completed or |tasks.finish()| to jump to the last one. |
michael@0 | 30 | _tasks: [], |
michael@0 | 31 | _nextTaskIndex: 0, |
michael@0 | 32 | |
michael@0 | 33 | push: function(func) { |
michael@0 | 34 | this._tasks.push(func); |
michael@0 | 35 | }, |
michael@0 | 36 | |
michael@0 | 37 | next: function() { |
michael@0 | 38 | let index = this._nextTaskIndex++; |
michael@0 | 39 | let task = this._tasks[index]; |
michael@0 | 40 | try { |
michael@0 | 41 | task(); |
michael@0 | 42 | } catch (ex) { |
michael@0 | 43 | ok(false, "test task[" + index + "] throws: " + ex); |
michael@0 | 44 | // Run last task as clean up if possible. |
michael@0 | 45 | if (index != this._tasks.length - 1) { |
michael@0 | 46 | this.finish(); |
michael@0 | 47 | } |
michael@0 | 48 | } |
michael@0 | 49 | }, |
michael@0 | 50 | |
michael@0 | 51 | finish: function() { |
michael@0 | 52 | this._tasks[this._tasks.length - 1](); |
michael@0 | 53 | }, |
michael@0 | 54 | |
michael@0 | 55 | run: function() { |
michael@0 | 56 | this.next(); |
michael@0 | 57 | } |
michael@0 | 58 | }; |
michael@0 | 59 | |
michael@0 | 60 | function addTest(text, strict7BitEncoding, expected) { |
michael@0 | 61 | tasks.push(function() { |
michael@0 | 62 | if (strict7BitEncoding != currentStrict7BitEncoding) { |
michael@0 | 63 | currentStrict7BitEncoding = strict7BitEncoding; |
michael@0 | 64 | SpecialPowers.setBoolPref("dom.sms.strict7BitEncoding", |
michael@0 | 65 | currentStrict7BitEncoding); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | let domRequest = manager.getSegmentInfoForText(text); |
michael@0 | 69 | ok(domRequest, "DOMRequest object returned."); |
michael@0 | 70 | |
michael@0 | 71 | domRequest.onsuccess = function(e) { |
michael@0 | 72 | log("Received 'onsuccess' DOMRequest event."); |
michael@0 | 73 | |
michael@0 | 74 | let result = e.target.result; |
michael@0 | 75 | if (!result) { |
michael@0 | 76 | ok(false, "getSegmentInfoForText() result is not valid."); |
michael@0 | 77 | tasks.finish(); |
michael@0 | 78 | return; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | is(result.segments, expected[0], "segments"); |
michael@0 | 82 | is(result.charsPerSegment, expected[1], "charsPerSegment"); |
michael@0 | 83 | is(result.charsAvailableInLastSegment, expected[2], |
michael@0 | 84 | "charsAvailableInLastSegment"); |
michael@0 | 85 | |
michael@0 | 86 | tasks.next(); |
michael@0 | 87 | }; |
michael@0 | 88 | |
michael@0 | 89 | domRequest.onerror = function(e) { |
michael@0 | 90 | ok(false, "Failed to call getSegmentInfoForText()."); |
michael@0 | 91 | tasks.finish(); |
michael@0 | 92 | }; |
michael@0 | 93 | }); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | // GSM 7Bit Alphabets: |
michael@0 | 97 | // |
michael@0 | 98 | // 'a' is in GSM default locking shift table, so it takes 1 septet. |
michael@0 | 99 | addTest("a", false, [1, LEN_7BIT, LEN_7BIT - 1]); |
michael@0 | 100 | // '\u20ac' is in GSM default single shift table, so it takes 2 septets. |
michael@0 | 101 | addTest("\u20ac", false, [1, LEN_7BIT, LEN_7BIT - 2]); |
michael@0 | 102 | // SP is defined in both locking shift and single shift tables. |
michael@0 | 103 | addTest(" ", false, [1, LEN_7BIT, LEN_7BIT - 1]); |
michael@0 | 104 | // Some combinations. |
michael@0 | 105 | addTest("a\u20ac", false, [1, LEN_7BIT, LEN_7BIT - 3]); |
michael@0 | 106 | addTest("a ", false, [1, LEN_7BIT, LEN_7BIT - 2]); |
michael@0 | 107 | addTest("\u20aca", false, [1, LEN_7BIT, LEN_7BIT - 3]); |
michael@0 | 108 | addTest("\u20ac ", false, [1, LEN_7BIT, LEN_7BIT - 3]); |
michael@0 | 109 | addTest(" \u20ac", false, [1, LEN_7BIT, LEN_7BIT - 3]); |
michael@0 | 110 | addTest(" a", false, [1, LEN_7BIT, LEN_7BIT - 2]); |
michael@0 | 111 | |
michael@0 | 112 | // GSM 7Bit Alphabets (multipart): |
michael@0 | 113 | // |
michael@0 | 114 | // Exactly 160 locking shift table chararacters. |
michael@0 | 115 | addTest(times("a", LEN_7BIT), false, [1, LEN_7BIT, 0]); |
michael@0 | 116 | // 161 locking shift table chararacters. We'll have |161 - 153 = 8| septets in |
michael@0 | 117 | // the 2nd segment. |
michael@0 | 118 | addTest(times("a", LEN_7BIT + 1), false, |
michael@0 | 119 | [2, LEN_7BIT_WITH_8BIT_REF, LEN_7BIT_WITH_8BIT_REF - 8]); |
michael@0 | 120 | // |LEN_7BIT_WITH_8BIT_REF * 2| locking shift table chararacters. |
michael@0 | 121 | addTest(times("a", LEN_7BIT_WITH_8BIT_REF * 2), false, |
michael@0 | 122 | [2, LEN_7BIT_WITH_8BIT_REF, 0]); |
michael@0 | 123 | // |LEN_7BIT_WITH_8BIT_REF * 2 + 1| locking shift table chararacters. |
michael@0 | 124 | addTest(times("a", LEN_7BIT_WITH_8BIT_REF * 2 + 1), false, |
michael@0 | 125 | [3, LEN_7BIT_WITH_8BIT_REF, LEN_7BIT_WITH_8BIT_REF - 1]); |
michael@0 | 126 | // Exactly 80 single shift table chararacters. |
michael@0 | 127 | addTest(times("\u20ac", LEN_7BIT / 2), false, [1, LEN_7BIT, 0]); |
michael@0 | 128 | // 81 single shift table chararacters. Because |Math.floor(153 / 2) = 76|, it |
michael@0 | 129 | // should left 5 septets in the 2nd segment. |
michael@0 | 130 | addTest(times("\u20ac", LEN_7BIT / 2 + 1), false, |
michael@0 | 131 | [2, LEN_7BIT_WITH_8BIT_REF, LEN_7BIT_WITH_8BIT_REF - 10]); |
michael@0 | 132 | // |1 + 2 * 76| single shift table chararacters. We have only |153 - 76 * 2 = 1| |
michael@0 | 133 | // space left, but each single shift table character takes 2, so it will be |
michael@0 | 134 | // filled in the 3rd segment. |
michael@0 | 135 | addTest(times("\u20ac", 1 + 2 * Math.floor(LEN_7BIT_WITH_8BIT_REF / 2)), false, |
michael@0 | 136 | [3, LEN_7BIT_WITH_8BIT_REF, LEN_7BIT_WITH_8BIT_REF - 2]); |
michael@0 | 137 | // |2 * 76| single shift table chararacters + 1 locking shift table chararacter. |
michael@0 | 138 | addTest("a" + times("\u20ac", 2 * Math.floor(LEN_7BIT_WITH_8BIT_REF / 2)), false, |
michael@0 | 139 | [2, LEN_7BIT_WITH_8BIT_REF, 1]); |
michael@0 | 140 | addTest(times("\u20ac", 2 * Math.floor(LEN_7BIT_WITH_8BIT_REF / 2)) + "a", false, |
michael@0 | 141 | [2, LEN_7BIT_WITH_8BIT_REF, 0]); |
michael@0 | 142 | |
michael@0 | 143 | // UCS2: |
michael@0 | 144 | // |
michael@0 | 145 | // '\u6afb' should be encoded as UCS2. |
michael@0 | 146 | addTest("\u6afb", false, [1, LEN_UCS2, LEN_UCS2 - 1]); |
michael@0 | 147 | // Combination of GSM 7bit alphabets. |
michael@0 | 148 | addTest("\u6afba", false, [1, LEN_UCS2, LEN_UCS2 - 2]); |
michael@0 | 149 | addTest("\u6afb\u20ac", false, [1, LEN_UCS2, LEN_UCS2 - 2]); |
michael@0 | 150 | addTest("\u6afb ", false, [1, LEN_UCS2, LEN_UCS2 - 2]); |
michael@0 | 151 | |
michael@0 | 152 | // UCS2 (multipart): |
michael@0 | 153 | // |
michael@0 | 154 | // Exactly 70 UCS2 chararacters. |
michael@0 | 155 | addTest(times("\u6afb", LEN_UCS2), false, [1, LEN_UCS2, 0]); |
michael@0 | 156 | // 71 UCS2 chararacters. We'll have |71 - 67 = 4| chararacters in the 2nd |
michael@0 | 157 | // segment. |
michael@0 | 158 | addTest(times("\u6afb", LEN_UCS2 + 1), false, |
michael@0 | 159 | [2, LEN_UCS2_WITH_8BIT_REF, LEN_UCS2_WITH_8BIT_REF - 4]); |
michael@0 | 160 | // |LEN_UCS2_WITH_8BIT_REF * 2| ucs2 chararacters. |
michael@0 | 161 | addTest(times("\u6afb", LEN_UCS2_WITH_8BIT_REF * 2), false, |
michael@0 | 162 | [2, LEN_UCS2_WITH_8BIT_REF, 0]); |
michael@0 | 163 | // |LEN_7BIT_WITH_8BIT_REF * 2 + 1| ucs2 chararacters. |
michael@0 | 164 | addTest(times("\u6afb", LEN_UCS2_WITH_8BIT_REF * 2 + 1), false, |
michael@0 | 165 | [3, LEN_UCS2_WITH_8BIT_REF, LEN_UCS2_WITH_8BIT_REF - 1]); |
michael@0 | 166 | |
michael@0 | 167 | // Strict 7-Bit Encoding: |
michael@0 | 168 | // |
michael@0 | 169 | // Should have no effect on GSM default alphabet characters. |
michael@0 | 170 | addTest("\u0041", true, [1, LEN_7BIT, LEN_7BIT - 1]); |
michael@0 | 171 | // "\u00c0"(À) should be mapped to "\u0041"(A). |
michael@0 | 172 | addTest("\u00c0", true, [1, LEN_7BIT, LEN_7BIT - 1]); |
michael@0 | 173 | // Mixing mapped characters with unmapped ones. |
michael@0 | 174 | addTest("\u00c0\u0041", true, [1, LEN_7BIT, LEN_7BIT - 2]); |
michael@0 | 175 | addTest("\u0041\u00c0", true, [1, LEN_7BIT, LEN_7BIT - 2]); |
michael@0 | 176 | // UCS2 characters should be mapped to '*'. |
michael@0 | 177 | addTest("\u1234", true, [1, LEN_7BIT, LEN_7BIT - 1]); |
michael@0 | 178 | |
michael@0 | 179 | |
michael@0 | 180 | // WARNING: All tasks should be pushed before this!!! |
michael@0 | 181 | tasks.push(function cleanUp() { |
michael@0 | 182 | SpecialPowers.removePermission("sms", document); |
michael@0 | 183 | SpecialPowers.clearUserPref("dom.sms.enabled"); |
michael@0 | 184 | SpecialPowers.clearUserPref("dom.sms.strict7BitEncoding"); |
michael@0 | 185 | finish(); |
michael@0 | 186 | }); |
michael@0 | 187 | |
michael@0 | 188 | tasks.run(); |