|
1 <?xml version="1.0"?> |
|
2 |
|
3 <!-- Any copyright is dedicated to the Public Domain. |
|
4 - http://creativecommons.org/publicdomain/zero/1.0/ --> |
|
5 |
|
6 <?xml-stylesheet type="text/css" href="chrome://global/skin"?> |
|
7 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> |
|
8 |
|
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> |
|
17 </body> |
|
18 |
|
19 <script type="application/javascript;version=1.8"> |
|
20 |
|
21 "use strict"; |
|
22 |
|
23 Components.utils.import("resource://gre/modules/Services.jsm"); |
|
24 Components.utils.import("resource://gre/modules/PhoneNumberUtils.jsm"); |
|
25 |
|
26 Services.prefs.setIntPref("dom.phonenumber.substringmatching.BR", 8); |
|
27 Services.prefs.setCharPref("ril.lastKnownSimMcc", "724"); |
|
28 |
|
29 function CantParseWithMcc(dial, mcc) { |
|
30 var result = PhoneNumberUtils.parseWithMCC(dial, mcc); |
|
31 if (result) { |
|
32 ok(false, "Shouldn't parse!\n"); |
|
33 dump("expected: does not parse"); |
|
34 dump("got: " + dial + " " + mcc); |
|
35 } else { |
|
36 ok(true, "Parses"); |
|
37 } |
|
38 } |
|
39 |
|
40 function ParseWithMcc(dial, mcc) { |
|
41 var result = PhoneNumberUtils.parseWithMCC(dial, mcc); |
|
42 if (result) { |
|
43 ok(true, "Parses!\n"); |
|
44 } else { |
|
45 ok(false, "Should Parse"); |
|
46 dump("expected: parses"); |
|
47 } |
|
48 } |
|
49 |
|
50 function FuzzyMatch(number1, number2, expect) { |
|
51 var result = PhoneNumberUtils.fuzzyMatch(number1, number2); |
|
52 is(result, expect, "FuzzyMatch OK!"); |
|
53 } |
|
54 |
|
55 // Unknown mcc |
|
56 CantParseWithMcc("1234", 123); |
|
57 ParseWithMcc("4165555555", 302); |
|
58 |
|
59 is(PhoneNumberUtils.normalize("123abc", true), "123", "NumbersOnly"); |
|
60 is(PhoneNumberUtils.normalize("123abc", false), "123222", "NumbersOnly"); |
|
61 |
|
62 FuzzyMatch("123abc", "123222", true); |
|
63 FuzzyMatch("123456789", "123456789", true); |
|
64 FuzzyMatch("111", null, false); |
|
65 FuzzyMatch("+552155555555", "2155555555", true); |
|
66 FuzzyMatch("aaa123456789", "zzzzz123456789", true); |
|
67 </script> |
|
68 </window> |