|
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 <!-- test results are displayed in the html:body --> |
|
13 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
14 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=809213" |
|
15 target="_blank">Mozilla Bug 809213</a> |
|
16 </body> |
|
17 |
|
18 <script type="application/javascript;version=1.8"> |
|
19 |
|
20 "use strict"; |
|
21 |
|
22 Components.utils.import("resource://gre/modules/Services.jsm"); |
|
23 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
24 |
|
25 Services.prefs.setIntPref("dom.phonenumber.substringmatching.BR", 8); |
|
26 Services.prefs.setCharPref("ril.lastKnownSimMcc", "724"); |
|
27 |
|
28 var pm = SpecialPowers.Cc["@mozilla.org/permissionmanager;1"] |
|
29 .getService(SpecialPowers.Ci.nsIPermissionManager); |
|
30 |
|
31 pm.addFromPrincipal(window.document.nodePrincipal, "phonenumberservice", |
|
32 SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION); |
|
33 |
|
34 function onUnwantedSuccess() { |
|
35 ok(false, "onUnwantedSuccess: shouldn't get here"); |
|
36 } |
|
37 |
|
38 function onFailure() { |
|
39 ok(false, "in on Failure!"); |
|
40 } |
|
41 |
|
42 var req; |
|
43 var index = 0; |
|
44 var mozPhoneNumberService = window.navigator.mozPhoneNumberService; |
|
45 ok(mozPhoneNumberService, "mozPhoneNumberService exists"); |
|
46 var steps = [ |
|
47 function() { |
|
48 req = mozPhoneNumberService.fuzzyMatch("123", "123"); |
|
49 req.onsuccess = function(e) { |
|
50 is(req.result, true, "same number"); |
|
51 next(); |
|
52 }; |
|
53 req.onerror = onFailure; |
|
54 }, |
|
55 function() { |
|
56 req = mozPhoneNumberService.fuzzyMatch("abcdef", "222333"); |
|
57 req.onsuccess = function(e) { |
|
58 is(req.result, true, "normalize first number"); |
|
59 next(); |
|
60 }; |
|
61 req.onerror = onFailure; |
|
62 }, |
|
63 function() { |
|
64 req = mozPhoneNumberService.fuzzyMatch("abc333", "222def"); |
|
65 req.onsuccess = function(e) { |
|
66 is(req.result, true, "normalize first and second number"); |
|
67 next(); |
|
68 }; |
|
69 req.onerror = onFailure; |
|
70 }, |
|
71 function() { |
|
72 req = mozPhoneNumberService.fuzzyMatch("1234567", "1234568"); |
|
73 req.onsuccess = function(e) { |
|
74 is(req.result, false, "different numbers should not match"); |
|
75 next(); |
|
76 }; |
|
77 req.onerror = onFailure; |
|
78 }, |
|
79 function() { |
|
80 req = mozPhoneNumberService.fuzzyMatch("1234567", "123456"); |
|
81 req.onsuccess = function(e) { |
|
82 is(req.result, false, "different length numbers should not match"); |
|
83 next(); |
|
84 }; |
|
85 req.onerror = onFailure; |
|
86 }, |
|
87 function() { |
|
88 req = mozPhoneNumberService.fuzzyMatch("1234567", "123456---"); |
|
89 req.onsuccess = function(e) { |
|
90 is(req.result, false, "invalid number should not match valid number"); |
|
91 next(); |
|
92 }; |
|
93 req.onerror = onFailure; |
|
94 }, |
|
95 function() { |
|
96 req = mozPhoneNumberService.fuzzyMatch("111", undefined); |
|
97 req.onsuccess = function(e) { |
|
98 is(req.result, false, "missing second argument should not match"); |
|
99 next(); |
|
100 }; |
|
101 req.onerror = onFailure; |
|
102 }, |
|
103 function() { |
|
104 req = mozPhoneNumberService.fuzzyMatch(undefined, "111"); |
|
105 req.onsuccess = function(e) { |
|
106 is(req.result, false, "missing first argument should not match"); |
|
107 next(); |
|
108 }; |
|
109 req.onerror = onFailure; |
|
110 }, |
|
111 function() { |
|
112 req = mozPhoneNumberService.fuzzyMatch(null, ""); |
|
113 req.onsuccess = function(e) { |
|
114 is(req.result, true, "missing first argument should fuzzy match empty string"); |
|
115 next(); |
|
116 }; |
|
117 req.onerror = onFailure; |
|
118 }, |
|
119 function() { |
|
120 req = mozPhoneNumberService.fuzzyMatch("+552155555555", "2155555555"); |
|
121 req.onsuccess = function(e) { |
|
122 is(req.result, true, "test internationalization of number"); |
|
123 next(); |
|
124 }; |
|
125 req.onerror = onFailure; |
|
126 }, |
|
127 function() { |
|
128 req = mozPhoneNumberService.fuzzyMatch("aaa123456789", "zzzzz123456789"); |
|
129 req.onsuccess = function(e) { |
|
130 is(req.result, true, "substring matching should be in effect"); |
|
131 next(); |
|
132 }; |
|
133 req.onerror = onFailure; |
|
134 }, |
|
135 function () { |
|
136 ok(true, "all done!\n"); |
|
137 SimpleTest.finish(); |
|
138 } |
|
139 ]; |
|
140 |
|
141 function next() { |
|
142 ok(true, "Begin!"); |
|
143 if (index >= steps.length) { |
|
144 ok(false, "Shouldn't get here!"); |
|
145 return; |
|
146 } |
|
147 try { |
|
148 var i = index++; |
|
149 steps[i](); |
|
150 } catch(ex) { |
|
151 ok(false, "Caught exception", ex); |
|
152 } |
|
153 } |
|
154 |
|
155 SimpleTest.waitForExplicitFinish(); |
|
156 addLoadEvent(next); |
|
157 </script> |
|
158 </window> |