Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 <!DOCTYPE html>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=877302
5 -->
6 <head>
7 <title>Test for Bug 949537 substring matching for WebContacts</title>
8 <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
9 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
11 </head>
12 <body>
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=949537">Mozilla Bug 949537</a>
15 <p id="display"></p>
16 <div id="content" style="display: none">
18 </div>
19 <pre id="test">
20 <script type="text/javascript;version=1.8" src="http://mochi.test:8888/tests/dom/contacts/tests/shared.js"></script>
21 <script class="testbody" type="text/javascript">
22 "use strict";
24 var landlineNumber = "+56 2 27654321";
26 var number = {
27 local: "87654321",
28 international: "+56 9 87654321"
29 };
31 var properties = {
32 name: ["Testname2"],
33 tel: [{value: number.international}]
34 };
36 var req;
37 var steps = [
38 function () {
39 ok(true, "Adding a contact with a Chilean number");
40 createResult1 = new mozContact(properties);
41 req = navigator.mozContacts.save(createResult1);
42 req.onsuccess = function () {
43 ok(createResult1.id, "The contact now has an ID.");
44 sample_id1 = createResult1.id;
45 next();
46 };
47 req.onerror = onFailure;
48 },
49 function () {
50 ok(true, "Searching for Chilean number with prefix");
51 req = mozContacts.find({
52 filterBy: ["tel"],
53 filterOp: "match",
54 filterValue: number.international
55 });
56 req.onsuccess = function () {
57 ise(req.result.length, 1, "Found exactly 1 contact.");
58 findResult1 = req.result[0];
59 ise(findResult1.id, sample_id1, "Same ID");
60 next();
61 };
62 req.onerror = onFailure;
63 },
64 function () {
65 ok(true, "Searching for Chilean number using local number");
66 req = mozContacts.find({
67 filterBy: ["tel"],
68 filterOp: "match",
69 filterValue: number.local
70 });
71 req.onsuccess = function () {
72 ise(req.result.length, 1, "Found 0 contacts.");
73 next();
74 };
75 req.onerror = onFailure;
76 },
78 clearDatabase,
80 function () {
81 ok(true, "Adding contact with mobile number");
82 createResult1 = new mozContact({tel: [{value: number.international}]});
83 req = navigator.mozContacts.save(createResult1);
84 req.onsuccess = function () {
85 ok(createResult1.id, "The contact now has an ID.");
86 sample_id1 = createResult1.id;
87 next();
88 };
89 req.onerror = onFailure;
90 },
91 function () {
92 ok(true, "Retrieving all contacts");
93 req = mozContacts.find({});
94 req.onsuccess = function () {
95 ise(req.result.length, 1, "One contact.");
96 findResult1 = req.result[0];
97 next();
98 };
99 req.onerror = onFailure;
100 },
101 function () {
102 ok(true, "Retrieving by last 8 digits");
103 req = mozContacts.find({
104 filterBy: ["tel"],
105 filterOp: "match",
106 filterValue: number.international.slice(-8)
107 });
108 req.onsuccess = function () {
109 ise(req.result.length, 1, "Found exactly 1 contact.");
110 findResult1 = req.result[0];
111 ise(findResult1.id, sample_id1, "Same ID");
112 ise(findResult1.tel[0].value, number.international, "Same Value");
113 next();
114 };
115 req.onerror = onFailure;
116 },
117 function () {
118 ok(true, "Retrieving by last 9 digits");
119 req = mozContacts.find({
120 filterBy: ["tel"],
121 filterOp: "match",
122 filterValue: number.international.slice(-9)
123 });
124 req.onsuccess = function () {
125 ise(req.result.length, 1, "Found exactly 1 contact.");
126 findResult1 = req.result[0];
127 ise(findResult1.id, sample_id1, "Same ID");
128 ise(findResult1.tel[0].value, number.international, "Same Value");
129 next();
130 };
131 req.onerror = onFailure;
132 },
133 function () {
134 ok(true, "Retrieving by last 6 digits");
135 req = mozContacts.find({
136 filterBy: ["tel"],
137 filterOp: "match",
138 filterValue: number.international.slice(-6)
139 });
140 req.onsuccess = function () {
141 ise(req.result.length, 0, "Found exactly zero contacts.");
142 next();
143 };
144 req.onerror = onFailure;
145 },
147 clearDatabase,
149 function () {
150 ok(true, "Adding contact with landline number");
151 createResult1 = new mozContact({tel: [{value: landlineNumber}]});
152 req = navigator.mozContacts.save(createResult1);
153 req.onsuccess = function () {
154 ok(createResult1.id, "The contact now has an ID.");
155 sample_id1 = createResult1.id;
156 next();
157 };
158 req.onerror = onFailure;
159 },
160 function () {
161 ok(true, "Retrieving all contacts");
162 req = mozContacts.find({});
163 req.onsuccess = function () {
164 ise(req.result.length, 1, "One contact.");
165 findResult1 = req.result[0];
166 next();
167 };
168 req.onerror = onFailure;
169 },
170 function () {
171 ok(true, "Retrieving by last 7 digits (local number) with landline calling prefix");
172 req = mozContacts.find({
173 filterBy: ["tel"],
174 filterOp: "match",
175 filterValue: "022" + landlineNumber.slice(-7)
176 });
177 req.onsuccess = function () {
178 ise(req.result.length, 1, "Found exactly 1 contact.");
179 findResult1 = req.result[0];
180 ise(findResult1.id, sample_id1, "Same ID");
181 ise(findResult1.tel[0].value, landlineNumber, "Same Value");
182 next();
183 };
184 req.onerror = onFailure;
185 },
187 clearDatabase,
189 function () {
190 ok(true, "all done!\n");
191 SimpleTest.finish();
192 }
193 ];
195 SpecialPowers.pushPrefEnv({
196 set: [
197 ["dom.phonenumber.substringmatching.CL", 8],
198 ["ril.lastKnownSimMcc", "730"]
199 ]
200 }, start_tests);
201 </script>
202 </pre>
203 </body>
204 </html>