dom/contacts/tests/test_contacts_international.html

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:5c8194ffa96f
1 <!DOCTYPE html>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=815833
5 -->
6 <head>
7 <title>Test for Bug 815833 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>
13
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=815833">Mozilla Bug 815833</a>
15 <p id="display"></p>
16 <div id="content" style="display: none">
17
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";
23
24 var number1 = {
25 local: "7932012345",
26 international: "+557932012345"
27 };
28
29 var number2 = {
30 local: "7932012346",
31 international: "+557932012346"
32 };
33
34 var properties1 = {
35 name: ["Testname1"],
36 tel: [{type: ["work"], value: number1.local, carrier: "testCarrier"} , {type: ["home", "fax"], value: number2.local}],
37 };
38
39 var shortNumber = "888";
40 var properties2 = {
41 name: ["Testname2"],
42 tel: [{type: ["work"], value: shortNumber, carrier: "testCarrier"}]
43 };
44
45 var number3 = {
46 local: "7932012345",
47 international: "+557932012345"
48 };
49
50 var properties3 = {
51 name: ["Testname2"],
52 tel: [{value: number3.international}]
53 };
54
55 var req;
56 var createResult1;
57 var findResult1;
58 var sample_id1;
59
60 var steps = [
61 function () {
62 ok(true, "Deleting database");
63 req = mozContacts.clear();
64 req.onsuccess = function () {
65 ok(true, "Deleted the database");
66 next();
67 };
68 req.onerror = onFailure;
69 },
70 function () {
71 ok(true, "Adding a new contact1");
72 createResult1 = new mozContact(properties1);
73 req = navigator.mozContacts.save(createResult1);
74 req.onsuccess = function () {
75 ok(createResult1.id, "The contact now has an ID.");
76 sample_id1 = createResult1.id;
77 next();
78 };
79 req.onerror = onFailure;
80 },
81 function () {
82 ok(true, "Adding a new contact2");
83 var createResult2 = new mozContact(properties2);
84 req = navigator.mozContacts.save(createResult2);
85 req.onsuccess = function () {
86 ok(createResult2.id, "The contact now has an ID.");
87 next();
88 };
89 req.onerror = onFailure;
90 },
91 function () {
92 ok(true, "Searching for local number");
93 var options = {filterBy: ["tel"],
94 filterOp: "startsWith",
95 filterValue: number1.local};
96 req = mozContacts.find(options);
97 req.onsuccess = function () {
98 ise(req.result.length, 1, "Found exactly 1 contact.");
99 findResult1 = req.result[0];
100 ise(findResult1.id, sample_id1, "Same ID");
101 next();
102 };
103 req.onerror = onFailure;
104 },
105 function () {
106 ok(true, "Searching for international number");
107 var options = {filterBy: ["tel"],
108 filterOp: "startsWith",
109 filterValue: number1.international};
110 req = mozContacts.find(options);
111 req.onsuccess = function () {
112 ise(req.result.length, 0, "Found exactly 0 contacts.");
113 next();
114 };
115 req.onerror = onFailure;
116 },
117 function () {
118 ok(true, "Searching for a short number matching the prefix");
119 var shortNumber = number1.local.substring(0, 3);
120 var options = {filterBy: ["tel"],
121 filterOp: "equals",
122 filterValue: shortNumber};
123 req = mozContacts.find(options);
124 req.onsuccess = function() {
125 ise(req.result.length, 0, "The prefix short number should not match any contact.");
126 next();
127 };
128 req.onerror = onFailure;
129 },
130 function () {
131 ok(true, "Searching for a short number matching the suffix");
132 var shortNumber = number1.local.substring(number1.local.length - 3);
133 var options = {filterBy: ["tel"],
134 filterOp: "equals",
135 filterValue: shortNumber};
136 req = mozContacts.find(options);
137 req.onsuccess = function() {
138 ise(req.result.length, 0, "The suffix short number should not match any contact.");
139 next();
140 };
141 req.onerror = onFailure;
142 },
143 function () {
144 ok(true, "Searching for a short number matching a contact");
145 var options = {filterBy: ["tel"],
146 filterOp: "equals",
147 filterValue: shortNumber};
148 req = mozContacts.find(options);
149 req.onsuccess = function() {
150 ise(req.result.length, 1, "Found the contact equally matching the shortNumber.");
151 next();
152 };
153 req.onerror = onFailure;
154 },
155 function() {
156 ok(true, "Modifying number");
157 if (!findResult1) {
158 SpecialPowers.executeSoon(next);
159 } else {
160 findResult1.tel[0].value = number2.local;
161 req = mozContacts.save(findResult1);
162 req.onsuccess = function () {
163 next();
164 };
165 }
166 },
167 function () {
168 ok(true, "Searching for local number");
169 var options = {filterBy: ["tel"],
170 filterOp: "startsWith",
171 filterValue: number1.local};
172 req = mozContacts.find(options);
173 req.onsuccess = function () {
174 ise(req.result.length, 0, "Found exactly 0 contact.");
175 next();
176 };
177 req.onerror = onFailure;
178 },
179 function () {
180 ok(true, "Searching for local number");
181 var options = {filterBy: ["tel"],
182 filterOp: "startsWith",
183 filterValue: number1.international};
184 req = mozContacts.find(options);
185 req.onsuccess = function () {
186 ise(req.result.length, 0, "Found exactly 0 contact.");
187 next();
188 };
189 req.onerror = onFailure;
190 },
191 function () {
192 ok(true, "Searching for local number");
193 var options = {filterBy: ["tel"],
194 filterOp: "startsWith",
195 filterValue: number2.local};
196 req = mozContacts.find(options);
197 req.onsuccess = function () {
198 ise(req.result.length, 1, "Found exactly 1 contact.");
199 findResult1 = req.result[0];
200 ise(findResult1.id, sample_id1, "Same ID");
201 next();
202 };
203 req.onerror = onFailure;
204 },
205 function () {
206 ok(true, "Searching for local number");
207 var options = {filterBy: ["tel"],
208 filterOp: "startsWith",
209 filterValue: number2.international};
210 req = mozContacts.find(options);
211 req.onsuccess = function () {
212 ise(req.result.length, 0, "Found exactly 1 contact.");
213 next();
214 };
215 req.onerror = onFailure;
216 },
217 function () {
218 ok(true, "Deleting database");
219 req = mozContacts.clear();
220 req.onsuccess = function () {
221 ok(true, "Deleted the database");
222 next();
223 }
224 req.onerror = onFailure;
225 },
226 function () {
227 ok(true, "Adding a contact with a Brazilian country code");
228 createResult1 = new mozContact(properties3);
229 req = navigator.mozContacts.save(createResult1);
230 req.onsuccess = function () {
231 ok(createResult1.id, "The contact now has an ID.");
232 sample_id1 = createResult1.id;
233 next();
234 };
235 req.onerror = onFailure;
236 },
237 function () {
238 ok(true, "Searching for Brazilian number using local number");
239 var options = {filterBy: ["tel"],
240 filterOp: "match",
241 filterValue: number3.local};
242 req = mozContacts.find(options);
243 req.onsuccess = function () {
244 ise(req.result.length, 1, "Found exactly 1 contact.");
245 findResult1 = req.result[0];
246 ise(findResult1.id, sample_id1, "Same ID");
247 next();
248 };
249 req.onerror = onFailure;
250 },
251 function () {
252 ok(true, "Deleting database");
253 req = mozContacts.clear();
254 req.onsuccess = function () {
255 ok(true, "Deleted the database");
256 next();
257 }
258 req.onerror = onFailure;
259 },
260 function () {
261 ok(true, "all done!\n");
262 SimpleTest.finish();
263 }
264 ];
265
266 SpecialPowers.pushPrefEnv({
267 set: [
268 ["ril.lastKnownSimMcc", "000"]
269 ]
270 }, start_tests);
271 </script>
272 </pre>
273 </body>
274 </html>

mercurial