3 <!-- Any copyright is dedicated to the Public Domain.
4 - http://creativecommons.org/publicdomain/zero/1.0/ -->
6 <?xml-stylesheet type=
"text/css" href=
"chrome://global/skin"?>
7 <?xml-stylesheet type=
"text/css" href=
"chrome://mochikit/content/tests/SimpleTest/test.css"?>
9 <window xmlns=
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
10 title=
"Mozilla Bug 781379">
11 <script type=
"application/javascript" src=
"chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
12 <script type=
"application/javascript" src=
"head.js"/>
13 <!-- test results are displayed in the html:body -->
14 <body xmlns=
"http://www.w3.org/1999/xhtml">
15 <a href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=809213"
16 target=
"_blank">Mozilla Bug
809213</a>
19 <script type=
"application/javascript;version=1.8">
23 Components.utils.import(
"resource://gre/modules/Services.jsm");
24 Components.utils.import(
"resource://gre/modules/PhoneNumberUtils.jsm");
26 Services.prefs.setIntPref(
"dom.phonenumber.substringmatching.BR",
8);
27 Services.prefs.setCharPref(
"ril.lastKnownSimMcc",
"724");
29 function CantParseWithMcc(dial, mcc) {
30 var result = PhoneNumberUtils.parseWithMCC(dial, mcc);
32 ok(false,
"Shouldn't parse!\n");
33 dump(
"expected: does not parse");
34 dump(
"got: " + dial +
" " + mcc);
40 function ParseWithMcc(dial, mcc) {
41 var result = PhoneNumberUtils.parseWithMCC(dial, mcc);
43 ok(true,
"Parses!\n");
45 ok(false,
"Should Parse");
46 dump(
"expected: parses");
50 function ParseWithCountryName(dial, countryName) {
51 var result = PhoneNumberUtils.parseWithCountryName(dial, countryName);
53 ok(true,
"Parses!\n");
55 ok(false,
"Should Parse");
56 dump(
"expected: parses");
60 function CantParseWithCountryName(dial, countryName) {
61 var result = PhoneNumberUtils.parseWithCountryName(dial, countryName);
63 ok(false,
"Should not Parse");
64 dump(
"expected: does not parse!\n");
66 ok(true,
"Expected Parsing error!\n");
70 function FuzzyMatch(number1, number2, expect) {
71 var result = PhoneNumberUtils.fuzzyMatch(number1, number2);
72 is(result, expect,
"FuzzyMatch OK!");
76 CantParseWithMcc(
"1234",
123);
77 ParseWithMcc(
"4165555555",
302);
79 ParseWithCountryName(
"4155123456",
"US");
80 CantParseWithCountryName(
"4155123456",
"001");
81 CantParseWithCountryName(
"4155123456",
"XXY");
82 ParseWithCountryName(
"4155123456",
"US");
85 is(PhoneNumberUtils.normalize(
"123abc", true),
"123",
"NumbersOnly");
86 is(PhoneNumberUtils.normalize(
"123abc", false),
"123222",
"NumbersOnly");
88 FuzzyMatch(
"123abc",
"123222", true);
89 FuzzyMatch(
"123456789",
"123456789", true);
90 FuzzyMatch(
"111", null, false);
91 FuzzyMatch(
"+552155555555",
"2155555555", true);
92 FuzzyMatch(
"aaa123456789",
"zzzzz123456789", true);