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 | <?xml version="1.0"?> |
michael@0 | 2 | |
michael@0 | 3 | <!-- Any copyright is dedicated to the Public Domain. |
michael@0 | 4 | - http://creativecommons.org/publicdomain/zero/1.0/ --> |
michael@0 | 5 | |
michael@0 | 6 | <?xml-stylesheet type="text/css" href="chrome://global/skin"?> |
michael@0 | 7 | <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> |
michael@0 | 8 | |
michael@0 | 9 | <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
michael@0 | 10 | title="Mozilla Bug 781379"> |
michael@0 | 11 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
michael@0 | 12 | <script type="application/javascript" src="head.js"/> |
michael@0 | 13 | <!-- test results are displayed in the html:body --> |
michael@0 | 14 | <body xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 15 | <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=809213" |
michael@0 | 16 | target="_blank">Mozilla Bug 809213</a> |
michael@0 | 17 | </body> |
michael@0 | 18 | |
michael@0 | 19 | <script type="application/javascript;version=1.8"> |
michael@0 | 20 | |
michael@0 | 21 | "use strict"; |
michael@0 | 22 | |
michael@0 | 23 | Components.utils.import("resource://gre/modules/PhoneNumber.jsm"); |
michael@0 | 24 | Components.utils.import("resource://gre/modules/PhoneNumberNormalizer.jsm"); |
michael@0 | 25 | |
michael@0 | 26 | function IsPlain(dial, expected) { |
michael@0 | 27 | var result = PhoneNumber.IsPlain(dial); |
michael@0 | 28 | if (result != expected) { |
michael@0 | 29 | ok(false, dial + " is " + (result ? "" : "not ") + "plain, expects otherwise."); |
michael@0 | 30 | } else { |
michael@0 | 31 | ok(true, dial + " is " + (result ? "" : "not ") + "plain as expected."); |
michael@0 | 32 | } |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | function Normalize(dial, expected) { |
michael@0 | 36 | var result = PhoneNumberNormalizer.Normalize(dial); |
michael@0 | 37 | if (result !== expected) { |
michael@0 | 38 | ok(false, "normalized " + dial + " to " + result + ", expected " + expected + " instead."); |
michael@0 | 39 | } else { |
michael@0 | 40 | ok(true, "normalized " + dial + " to " + result + " as expected."); |
michael@0 | 41 | } |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function Normalize(dial, expected) { |
michael@0 | 45 | var result = PhoneNumberNormalizer.Normalize(dial); |
michael@0 | 46 | if (result != expected) { |
michael@0 | 47 | ok(false, "Normalize error!\n"); |
michael@0 | 48 | print("expected: " + expected); |
michael@0 | 49 | print("got: " + result); |
michael@0 | 50 | } else { |
michael@0 | 51 | ok(true, "Normalization OK"); |
michael@0 | 52 | } |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | function CantParse(dial, currentRegion) { |
michael@0 | 56 | var result = PhoneNumber.Parse(dial, currentRegion); |
michael@0 | 57 | if (result) { |
michael@0 | 58 | ok(false, "Shouldn't parse!\n"); |
michael@0 | 59 | print("expected: does not parse"); |
michael@0 | 60 | print("got: " + dial + " " + currentRegion); |
michael@0 | 61 | } |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | function Parse(dial, currentRegion) { |
michael@0 | 65 | dump("try: " + dial + ", " + currentRegion + "\n"); |
michael@0 | 66 | var result = PhoneNumber.Parse(dial, currentRegion); |
michael@0 | 67 | if (!result) { |
michael@0 | 68 | ok(false, "got: " + dial + " " + currentRegion); |
michael@0 | 69 | } else { |
michael@0 | 70 | ok(true, "Parses!\n"); |
michael@0 | 71 | } |
michael@0 | 72 | return result; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | function ParseWithIntl(dial, currentRegion) { |
michael@0 | 76 | var result = PhoneNumber.Parse(dial, currentRegion); |
michael@0 | 77 | if (!result) { |
michael@0 | 78 | ok(false, "got: " + dial + " " + currentRegion); |
michael@0 | 79 | } else { |
michael@0 | 80 | ok(result.internationalNumber, "Has International!"); |
michael@0 | 81 | ok(true, "Parses!\n"); |
michael@0 | 82 | } |
michael@0 | 83 | return result; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | function Test(dial, currentRegion, nationalNumber, region) { |
michael@0 | 87 | var result = Parse(dial, currentRegion); |
michael@0 | 88 | if (result.region != region || result.nationalNumber != nationalNumber) { |
michael@0 | 89 | ok(false, "expected: " + nationalNumber + " " + region + "got: " + result.nationalNumber + " " + result.region); |
michael@0 | 90 | } else { |
michael@0 | 91 | ok(true, "Test ok!"); |
michael@0 | 92 | } |
michael@0 | 93 | return result; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | function Format(dial, currentRegion, nationalNumber, region, nationalFormat, internationalFormat) { |
michael@0 | 97 | var result = Test(dial, currentRegion, nationalNumber, region); |
michael@0 | 98 | if (result.nationalFormat != nationalFormat || |
michael@0 | 99 | result.internationalFormat != internationalFormat) { |
michael@0 | 100 | ok(false, "expected: " + nationalFormat + " " + internationalFormat + |
michael@0 | 101 | "got: " + result.nationalFormat + " " + result.internationalFormat); |
michael@0 | 102 | } |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | function TestProperties(dial, currentRegion) { |
michael@0 | 106 | var result = PhoneNumber.Parse(dial, currentRegion); |
michael@0 | 107 | if (result) { |
michael@0 | 108 | ok(true, "found it"); |
michael@0 | 109 | ok(true, "InternationalFormat: " + result.internationalFormat); |
michael@0 | 110 | ok(true, "InternationalNumber: " + result.internationalNumber); |
michael@0 | 111 | ok(true, "NationalNumber: " + result.nationalNumber); |
michael@0 | 112 | ok(true, "NationalFormat: " + result.nationalFormat); |
michael@0 | 113 | } else { |
michael@0 | 114 | ok(true, "not found"); |
michael@0 | 115 | } |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | function TestPropertiesWithExpectedCountry(dial, currentRegion, expectedRegion) { |
michael@0 | 119 | var result = PhoneNumber.Parse(dial, currentRegion); |
michael@0 | 120 | if (result) { |
michael@0 | 121 | ok(true, "found it"); |
michael@0 | 122 | ok(true, "InternationalFormat: " + result.internationalFormat); |
michael@0 | 123 | ok(true, "InternationalNumber: " + result.internationalNumber); |
michael@0 | 124 | ok(true, "NationalNumber: " + result.nationalNumber); |
michael@0 | 125 | ok(true, "NationalFormat: " + result.nationalFormat); |
michael@0 | 126 | ok(true, "CountryName: " + result.countryName); |
michael@0 | 127 | is(result.countryName, expectedRegion, "Same region"); |
michael@0 | 128 | } else { |
michael@0 | 129 | ok(true, "not found"); |
michael@0 | 130 | } |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | function AllEqual(list, currentRegion) { |
michael@0 | 134 | var first = PhoneNumber.Parse(list.shift(), currentRegion); |
michael@0 | 135 | ok(!!first, "first parses"); |
michael@0 | 136 | for (var index in list) { |
michael@0 | 137 | var other = PhoneNumber.Parse(list[index], currentRegion); |
michael@0 | 138 | ok(!!other, "other parses"); |
michael@0 | 139 | ok(first.internationalNumber == other.internationalNumber, "first and other match"); |
michael@0 | 140 | } |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | TestProperties("+0988782456"); |
michael@0 | 144 | TestProperties("+33442020", "ES"); |
michael@0 | 145 | TestProperties("+43987614", "ES"); |
michael@0 | 146 | TestProperties("+0988782456"); |
michael@0 | 147 | TestProperties("+34556657"); |
michael@0 | 148 | TestProperties("+66554433"); |
michael@0 | 149 | TestProperties("+43442075"); |
michael@0 | 150 | TestProperties("+13442074"); |
michael@0 | 151 | |
michael@0 | 152 | TestPropertiesWithExpectedCountry("+4333822222", "DE", "AT"); |
michael@0 | 153 | TestPropertiesWithExpectedCountry("+19491234567", "DE", "US"); |
michael@0 | 154 | |
michael@0 | 155 | // Test whether could a string be a phone number. |
michael@0 | 156 | IsPlain(null, false); |
michael@0 | 157 | IsPlain("", false); |
michael@0 | 158 | IsPlain("1", true); |
michael@0 | 159 | IsPlain("*2", true); // Real number used in Venezuela |
michael@0 | 160 | IsPlain("*8", true); // Real number used in Venezuela |
michael@0 | 161 | IsPlain("12", true); |
michael@0 | 162 | IsPlain("123", true); |
michael@0 | 163 | IsPlain("1a2", false); |
michael@0 | 164 | IsPlain("12a", false); |
michael@0 | 165 | IsPlain("1234", true); |
michael@0 | 166 | IsPlain("123a", false); |
michael@0 | 167 | IsPlain("+", true); |
michael@0 | 168 | IsPlain("+1", true); |
michael@0 | 169 | IsPlain("+12", true); |
michael@0 | 170 | IsPlain("+123", true); |
michael@0 | 171 | IsPlain("()123", false); |
michael@0 | 172 | IsPlain("(1)23", false); |
michael@0 | 173 | IsPlain("(12)3", false); |
michael@0 | 174 | IsPlain("(123)", false); |
michael@0 | 175 | IsPlain("(123)4", false); |
michael@0 | 176 | IsPlain("123;ext=", false); |
michael@0 | 177 | IsPlain("123;ext=1", false); |
michael@0 | 178 | IsPlain("123;ext=1234567", false); |
michael@0 | 179 | IsPlain("123;ext=12345678", false); |
michael@0 | 180 | IsPlain("123 ext:1", false); |
michael@0 | 181 | IsPlain("123 ext:1#", false); |
michael@0 | 182 | IsPlain("123-1#", false); |
michael@0 | 183 | IsPlain("123 1#", false); |
michael@0 | 184 | IsPlain("123 12345#", false); |
michael@0 | 185 | IsPlain("123 +123456#", false); |
michael@0 | 186 | IsPlain("#123#", true); |
michael@0 | 187 | IsPlain("*#004#", true); |
michael@0 | 188 | IsPlain("*30#", true); |
michael@0 | 189 | IsPlain("*#06#", true); |
michael@0 | 190 | IsPlain("123456789012345678901234567890123456789012345678901", false); // more than 50 characters |
michael@0 | 191 | |
michael@0 | 192 | // test normalization |
michael@0 | 193 | Normalize(null, ""); |
michael@0 | 194 | Normalize("", ""); |
michael@0 | 195 | Normalize("1", "1"); |
michael@0 | 196 | Normalize("*2", "*2"); // Real number used in Venezuela |
michael@0 | 197 | Normalize("*8", "*8"); // Real number used in Venezuela |
michael@0 | 198 | Normalize("12", "12"); |
michael@0 | 199 | Normalize("123", "123"); |
michael@0 | 200 | Normalize("1a2", "122"); |
michael@0 | 201 | Normalize("12a", "122"); |
michael@0 | 202 | Normalize("1234", "1234"); |
michael@0 | 203 | Normalize("123a", "1232"); |
michael@0 | 204 | Normalize("+", "+"); |
michael@0 | 205 | Normalize("+1", "+1"); |
michael@0 | 206 | Normalize("+12", "+12"); |
michael@0 | 207 | Normalize("+123", "+123"); |
michael@0 | 208 | Normalize("()123", "123"); |
michael@0 | 209 | Normalize("(1)23", "123"); |
michael@0 | 210 | Normalize("(12)3", "123"); |
michael@0 | 211 | Normalize("(123)", "123"); |
michael@0 | 212 | Normalize("(123)4", "1234"); |
michael@0 | 213 | Normalize("123-1#", "1231#"); |
michael@0 | 214 | Normalize("123 1#", "1231#"); |
michael@0 | 215 | Normalize("123 12345#", "12312345#"); |
michael@0 | 216 | Normalize("123 +123456#", "123+123456#"); |
michael@0 | 217 | Normalize("#123#", "#123#"); |
michael@0 | 218 | Normalize("*#004#", "*#004#"); |
michael@0 | 219 | Normalize("*30#", "*30#"); |
michael@0 | 220 | Normalize("*#06#", "*#06#"); |
michael@0 | 221 | |
michael@0 | 222 | // Test parsing national numbers. |
michael@0 | 223 | Parse("033316005", "NZ"); |
michael@0 | 224 | Parse("03-331 6005", "NZ"); |
michael@0 | 225 | Parse("03 331 6005", "NZ"); |
michael@0 | 226 | |
michael@0 | 227 | // Always test CA before US because CA has to load all meta-info for US. |
michael@0 | 228 | ParseWithIntl("4031234567", "CA"); |
michael@0 | 229 | Parse("(416) 585-4319", "CA"); |
michael@0 | 230 | Parse("647-967-4357", "CA"); |
michael@0 | 231 | Parse("416-716-8768", "CA"); |
michael@0 | 232 | Parse("18002684646", "CA"); |
michael@0 | 233 | Parse("416-445-9119", "CA"); |
michael@0 | 234 | Parse("1-800-668-6866", "CA"); |
michael@0 | 235 | Parse("(416) 453-6486", "CA"); |
michael@0 | 236 | Parse("(647) 268-4778", "CA"); |
michael@0 | 237 | Parse("647-218-1313", "CA"); |
michael@0 | 238 | Parse("+1 647-209-4642", "CA"); |
michael@0 | 239 | Parse("416-559-0133", "CA"); |
michael@0 | 240 | Parse("+1 647-639-4118", "CA"); |
michael@0 | 241 | Parse("+12898803664", "CA"); |
michael@0 | 242 | Parse("780-901-4687", "CA"); |
michael@0 | 243 | Parse("+14167070550", "CA"); |
michael@0 | 244 | Parse("+1-647-522-6487", "CA"); |
michael@0 | 245 | Parse("(416) 877-0880", "CA"); |
michael@0 | 246 | |
michael@0 | 247 | // Testing international prefixes. |
michael@0 | 248 | // Should strip country code. |
michael@0 | 249 | Parse("0064 3 331 6005", "NZ"); |
michael@0 | 250 | // Try again, but this time we have an international number with region rode US. It should |
michael@0 | 251 | // recognize the country code and parse accordingly. |
michael@0 | 252 | Parse("01164 3 331 6005", "US"); |
michael@0 | 253 | Parse("+64 3 331 6005", "US"); |
michael@0 | 254 | Parse("64(0)64123456", "NZ"); |
michael@0 | 255 | // Check that using a "/" is fine in a phone number. |
michael@0 | 256 | Parse("123/45678", "DE"); |
michael@0 | 257 | Parse("123-456-7890", "US"); |
michael@0 | 258 | |
michael@0 | 259 | // Test parsing international numbers. |
michael@0 | 260 | Parse("+1 (650) 333-6000", "NZ"); |
michael@0 | 261 | Parse("1-650-333-6000", "US"); |
michael@0 | 262 | // Calling the US number from Singapore by using different service providers |
michael@0 | 263 | // 1st test: calling using SingTel IDD service (IDD is 001) |
michael@0 | 264 | Parse("0011-650-333-6000", "SG"); |
michael@0 | 265 | // 2nd test: calling using StarHub IDD service (IDD is 008) |
michael@0 | 266 | Parse("0081-650-333-6000", "SG"); |
michael@0 | 267 | // 3rd test: calling using SingTel V019 service (IDD is 019) |
michael@0 | 268 | Parse("0191-650-333-6000", "SG"); |
michael@0 | 269 | // Calling the US number from Poland |
michael@0 | 270 | Parse("0~01-650-333-6000", "PL"); |
michael@0 | 271 | // Using "++" at the start. |
michael@0 | 272 | Parse("++1 (650) 333-6000", "PL"); |
michael@0 | 273 | // Using a full-width plus sign. |
michael@0 | 274 | Parse("\uFF0B1 (650) 333-6000", "SG"); |
michael@0 | 275 | // The whole number, including punctuation, is here represented in full-width form. |
michael@0 | 276 | Parse("\uFF0B\uFF11\u3000\uFF08\uFF16\uFF15\uFF10\uFF09" + |
michael@0 | 277 | "\u3000\uFF13\uFF13\uFF13\uFF0D\uFF16\uFF10\uFF10\uFF10", |
michael@0 | 278 | "SG"); |
michael@0 | 279 | |
michael@0 | 280 | // Test parsing with leading zeros. |
michael@0 | 281 | Parse("+39 02-36618 300", "NZ"); |
michael@0 | 282 | Parse("02-36618 300", "IT"); |
michael@0 | 283 | Parse("312 345 678", "IT"); |
michael@0 | 284 | |
michael@0 | 285 | // Test parsing numbers in Argentina. |
michael@0 | 286 | Parse("+54 9 343 555 1212", "AR"); |
michael@0 | 287 | Parse("0343 15 555 1212", "AR"); |
michael@0 | 288 | Parse("+54 9 3715 65 4320", "AR"); |
michael@0 | 289 | Parse("03715 15 65 4320", "AR"); |
michael@0 | 290 | Parse("+54 11 3797 0000", "AR"); |
michael@0 | 291 | Parse("011 3797 0000", "AR"); |
michael@0 | 292 | Parse("+54 3715 65 4321", "AR"); |
michael@0 | 293 | Parse("03715 65 4321", "AR"); |
michael@0 | 294 | Parse("+54 23 1234 0000", "AR"); |
michael@0 | 295 | Parse("023 1234 0000", "AR"); |
michael@0 | 296 | |
michael@0 | 297 | // Test numbers in Mexico |
michael@0 | 298 | Parse("+52 (449)978-0001", "MX"); |
michael@0 | 299 | Parse("01 (449)978-0001", "MX"); |
michael@0 | 300 | Parse("(449)978-0001", "MX"); |
michael@0 | 301 | Parse("+52 1 33 1234-5678", "MX"); |
michael@0 | 302 | Parse("044 (33) 1234-5678", "MX"); |
michael@0 | 303 | Parse("045 33 1234-5678", "MX"); |
michael@0 | 304 | |
michael@0 | 305 | // Test that lots of spaces are ok. |
michael@0 | 306 | Parse("0 3 3 3 1 6 0 0 5", "NZ"); |
michael@0 | 307 | |
michael@0 | 308 | // Test omitting the current region. This is only valid when the number starts |
michael@0 | 309 | // with a '+'. |
michael@0 | 310 | Parse("+64 3 331 6005"); |
michael@0 | 311 | Parse("+64 3 331 6005", null); |
michael@0 | 312 | |
michael@0 | 313 | // US numbers |
michael@0 | 314 | Format("19497261234", "US", "9497261234", "US", "(949) 726-1234", "+1 949-726-1234"); |
michael@0 | 315 | |
michael@0 | 316 | // Try a couple german numbers from the US with various access codes. |
michael@0 | 317 | Format("49451491934", "US", "451491934", "DE", "0451 491934", "+49 451 491934"); |
michael@0 | 318 | Format("+49451491934", "US", "451491934", "DE", "0451 491934", "+49 451 491934"); |
michael@0 | 319 | Format("01149451491934", "US", "451491934", "DE", "0451 491934", "+49 451 491934"); |
michael@0 | 320 | |
michael@0 | 321 | // Now try dialing the same number from within the German region. |
michael@0 | 322 | Format("451491934", "DE", "451491934", "DE", "0451 491934", "+49 451 491934"); |
michael@0 | 323 | Format("0451491934", "DE", "451491934", "DE", "0451 491934", "+49 451 491934"); |
michael@0 | 324 | |
michael@0 | 325 | // Numbers in italy keep the leading 0 in the city code when dialing internationally. |
michael@0 | 326 | Format("0577-555-555", "IT", "0577555555", "IT", "05 7755 5555", "+39 05 7755 5555"); |
michael@0 | 327 | |
michael@0 | 328 | // Telefonica tests |
michael@0 | 329 | Format("612123123", "ES", "612123123", "ES", "612 12 31 23", "+34 612 12 31 23"); |
michael@0 | 330 | |
michael@0 | 331 | // Chile mobile number from a landline |
michael@0 | 332 | Format("0997654321", "CL", "997654321", "CL", "(99) 765 4321", "+56 99 765 4321"); |
michael@0 | 333 | |
michael@0 | 334 | // Chile mobile number from another mobile number |
michael@0 | 335 | Format("997654321", "CL", "997654321", "CL", "(99) 765 4321", "+56 99 765 4321"); |
michael@0 | 336 | |
michael@0 | 337 | // Colombian international number without the leading "+" |
michael@0 | 338 | Format("5712234567", "CO", "12234567", "CO", "(1) 2234567", "+57 1 2234567"); |
michael@0 | 339 | |
michael@0 | 340 | // Dialing 911 in the US. This is not a national number. |
michael@0 | 341 | CantParse("911", "US"); |
michael@0 | 342 | |
michael@0 | 343 | // China mobile number with a 0 in it |
michael@0 | 344 | Format("15955042864", "CN", "15955042864", "CN", "0159 5504 2864", "+86 159 5504 2864"); |
michael@0 | 345 | |
michael@0 | 346 | // Test normalizing numbers. Only 0-9,#* are valid in a phone number. |
michael@0 | 347 | Normalize("+ABC # * , 9 _ 1 _0", "+222#*,910"); |
michael@0 | 348 | Normalize("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "22233344455566677778889999"); |
michael@0 | 349 | Normalize("abcdefghijklmnopqrstuvwxyz", "22233344455566677778889999"); |
michael@0 | 350 | |
michael@0 | 351 | // 8 and 9 digit numbers with area code in Brazil with collect call prefix (90) |
michael@0 | 352 | AllEqual(["01187654321","0411187654321","551187654321","90411187654321","+551187654321"],"BR"); |
michael@0 | 353 | AllEqual(["011987654321","04111987654321","5511987654321","904111987654321","+5511987654321"],"BR"); |
michael@0 | 354 | |
michael@0 | 355 | </script> |
michael@0 | 356 | </window> |