1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/contacts/tests/test_contacts_substringmatching.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,348 @@ 1.4 +<!DOCTYPE html> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=877302 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 877302 substring matching for WebContacts</title> 1.11 + <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> 1.12 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.14 +</head> 1.15 +<body> 1.16 + 1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=877302">Mozilla Bug 877302</a> 1.18 +<p id="display"></p> 1.19 +<div id="content" style="display: none"> 1.20 + 1.21 +</div> 1.22 +<pre id="test"> 1.23 +<script type="text/javascript;version=1.8" src="http://mochi.test:8888/tests/dom/contacts/tests/shared.js"></script> 1.24 +<script class="testbody" type="text/javascript"> 1.25 +"use strict"; 1.26 + 1.27 +var substringLength = 8; 1.28 + 1.29 +var prop = { 1.30 + tel: [{value: "7932012345" }, {value: "7932012346"}] 1.31 +}; 1.32 + 1.33 +var prop2 = { 1.34 + tel: [{value: "01187654321" }] 1.35 +}; 1.36 + 1.37 +var prop3 = { 1.38 + tel: [{ value: "+43332112346" }] 1.39 +}; 1.40 + 1.41 +var prop4 = { 1.42 + tel: [{ value: "(0414) 233-9888" }] 1.43 +}; 1.44 + 1.45 +var brazilianNumber = { 1.46 + international1: "0041557932012345", 1.47 + international2: "+557932012345" 1.48 +}; 1.49 + 1.50 +var prop5 = { 1.51 + tel: [{value: brazilianNumber.international2}] 1.52 +}; 1.53 + 1.54 +var req; 1.55 +var steps = [ 1.56 + function () { 1.57 + ok(true, "Deleting database"); 1.58 + req = mozContacts.clear() 1.59 + req.onsuccess = function () { 1.60 + ok(true, "Deleted the database"); 1.61 + next(); 1.62 + } 1.63 + req.onerror = onFailure; 1.64 + }, 1.65 + function () { 1.66 + ok(true, "Adding contact"); 1.67 + createResult1 = new mozContact(prop); 1.68 + req = navigator.mozContacts.save(createResult1); 1.69 + req.onsuccess = function () { 1.70 + ok(createResult1.id, "The contact now has an ID."); 1.71 + sample_id1 = createResult1.id; 1.72 + next(); 1.73 + }; 1.74 + req.onerror = onFailure; 1.75 + }, 1.76 + function () { 1.77 + ok(true, "Retrieving all contacts"); 1.78 + req = mozContacts.find({}); 1.79 + req.onsuccess = function () { 1.80 + is(req.result.length, 1, "One contact."); 1.81 + findResult1 = req.result[0]; 1.82 + next(); 1.83 + }; 1.84 + req.onerror = onFailure; 1.85 + }, 1.86 + function () { 1.87 + ok(true, "Retrieving by substring 1"); 1.88 + var length = prop.tel[0].value.length; 1.89 + var num = prop.tel[0].value.substring(length - substringLength, length); 1.90 + var options = {filterBy: ["tel"], 1.91 + filterOp: "match", 1.92 + filterValue: num}; 1.93 + req = mozContacts.find(options); 1.94 + req.onsuccess = function () { 1.95 + is(req.result.length, 1, "Found exactly 1 contact."); 1.96 + findResult1 = req.result[0]; 1.97 + ok(findResult1.id == sample_id1, "Same ID"); 1.98 + is(findResult1.tel[0].value, "7932012345", "Same Value"); 1.99 + next(); 1.100 + }; 1.101 + req.onerror = onFailure; 1.102 + }, 1.103 + function () { 1.104 + ok(true, "Retrieving by substring 2"); 1.105 + var length = prop.tel[1].value.length; 1.106 + var num = prop.tel[1].value.substring(length - substringLength, length); 1.107 + var options = {filterBy: ["tel"], 1.108 + filterOp: "match", 1.109 + filterValue: num}; 1.110 + req = mozContacts.find(options); 1.111 + req.onsuccess = function () { 1.112 + is(req.result.length, 1, "Found exactly 1 contact."); 1.113 + findResult1 = req.result[0]; 1.114 + ok(findResult1.id == sample_id1, "Same ID"); 1.115 + is(findResult1.tel[0].value, "7932012345", "Same Value"); 1.116 + next(); 1.117 + }; 1.118 + req.onerror = onFailure; 1.119 + }, 1.120 + function () { 1.121 + ok(true, "Retrieving by substring 3"); 1.122 + var length = prop.tel[0].value.length; 1.123 + var num = prop.tel[0].value.substring(length - substringLength + 1, length); 1.124 + var options = {filterBy: ["tel"], 1.125 + filterOp: "match", 1.126 + filterValue: num}; 1.127 + req = mozContacts.find(options); 1.128 + req.onsuccess = function () { 1.129 + is(req.result.length, 0, "Found exactly 0 contacts."); 1.130 + next(); 1.131 + }; 1.132 + req.onerror = onFailure; 1.133 + }, 1.134 + function () { 1.135 + ok(true, "Retrieving by substring 4"); 1.136 + var length = prop.tel[0].value.length; 1.137 + var num = prop.tel[0].value.substring(length - substringLength - 1, length); 1.138 + var options = {filterBy: ["tel"], 1.139 + filterOp: "match", 1.140 + filterValue: num}; 1.141 + req = mozContacts.find(options); 1.142 + req.onsuccess = function () { 1.143 + is(req.result.length, 1, "Found exactly 1 contacts."); 1.144 + next(); 1.145 + }; 1.146 + req.onerror = onFailure; 1.147 + }, 1.148 + function () { 1.149 + ok(true, "Adding contact"); 1.150 + createResult1 = new mozContact(prop2); 1.151 + req = navigator.mozContacts.save(createResult1); 1.152 + req.onsuccess = function () { 1.153 + ok(createResult1.id, "The contact now has an ID."); 1.154 + sample_id1 = createResult1.id; 1.155 + next(); 1.156 + }; 1.157 + req.onerror = onFailure; 1.158 + }, 1.159 + function () { 1.160 + ok(true, "Retrieving by substring 5"); 1.161 + var options = {filterBy: ["tel"], 1.162 + filterOp: "match", 1.163 + filterValue: "87654321"}; 1.164 + req = mozContacts.find(options); 1.165 + req.onsuccess = function () { 1.166 + is(req.result.length, 1, "Found exactly 1 contacts."); 1.167 + next(); 1.168 + }; 1.169 + req.onerror = onFailure; 1.170 + }, 1.171 + function () { 1.172 + ok(true, "Retrieving by substring 6"); 1.173 + var options = {filterBy: ["tel"], 1.174 + filterOp: "match", 1.175 + filterValue: "01187654321"}; 1.176 + req = mozContacts.find(options); 1.177 + req.onsuccess = function () { 1.178 + is(req.result.length, 1, "Found exactly 1 contacts."); 1.179 + next(); 1.180 + }; 1.181 + req.onerror = onFailure; 1.182 + }, 1.183 + function () { 1.184 + ok(true, "Retrieving by substring 7"); 1.185 + var options = {filterBy: ["tel"], 1.186 + filterOp: "match", 1.187 + filterValue: "909087654321"}; 1.188 + req = mozContacts.find(options); 1.189 + req.onsuccess = function () { 1.190 + is(req.result.length, 1, "Found exactly 1 contacts."); 1.191 + next(); 1.192 + }; 1.193 + req.onerror = onFailure; 1.194 + }, 1.195 + function () { 1.196 + ok(true, "Retrieving by substring 8"); 1.197 + var options = {filterBy: ["tel"], 1.198 + filterOp: "match", 1.199 + filterValue: "0411187654321"}; 1.200 + req = mozContacts.find(options); 1.201 + req.onsuccess = function () { 1.202 + is(req.result.length, 1, "Found exactly 1 contacts."); 1.203 + next(); 1.204 + }; 1.205 + req.onerror = onFailure; 1.206 + }, 1.207 + function () { 1.208 + ok(true, "Retrieving by substring 9"); 1.209 + var options = {filterBy: ["tel"], 1.210 + filterOp: "match", 1.211 + filterValue: "90411187654321"}; 1.212 + req = mozContacts.find(options); 1.213 + req.onsuccess = function () { 1.214 + is(req.result.length, 1, "Found exactly 1 contacts."); 1.215 + next(); 1.216 + }; 1.217 + req.onerror = onFailure; 1.218 + }, 1.219 + function () { 1.220 + ok(true, "Retrieving by substring 10"); 1.221 + var options = {filterBy: ["tel"], 1.222 + filterOp: "match", 1.223 + filterValue: "+551187654321"}; 1.224 + req = mozContacts.find(options); 1.225 + req.onsuccess = function () { 1.226 + is(req.result.length, 1, "Found exactly 1 contacts."); 1.227 + next(); 1.228 + }; 1.229 + req.onerror = onFailure; 1.230 + }, 1.231 + function () { 1.232 + ok(true, "Deleting database"); 1.233 + req = mozContacts.clear() 1.234 + req.onsuccess = function () { 1.235 + ok(true, "Deleted the database"); 1.236 + next(); 1.237 + } 1.238 + req.onerror = onFailure; 1.239 + }, 1.240 + function () { 1.241 + ok(true, "Adding contact"); 1.242 + createResult1 = new mozContact(prop3); 1.243 + req = navigator.mozContacts.save(createResult1); 1.244 + req.onsuccess = function () { 1.245 + ok(createResult1.id, "The contact now has an ID."); 1.246 + sample_id1 = createResult1.id; 1.247 + next(); 1.248 + }; 1.249 + req.onerror = onFailure; 1.250 + }, 1.251 + function () { 1.252 + if (!isAndroid) { // Bug 905927 1.253 + ok(true, "Retrieving by substring 1"); 1.254 + var length = prop3.tel[0].value.length; 1.255 + var num = prop3.tel[0].value.substring(length - substringLength, length); 1.256 + var options = {filterBy: ["tel"], 1.257 + filterOp: "match", 1.258 + filterValue: num}; 1.259 + req = mozContacts.find(options); 1.260 + req.onsuccess = function () { 1.261 + is(req.result.length, 0, "Found exactly 0 contacts."); 1.262 + next(); 1.263 + }; 1.264 + req.onerror = onFailure; 1.265 + } else { 1.266 + SpecialPowers.executeSoon(next); 1.267 + } 1.268 + }, 1.269 + function () { 1.270 + ok(true, "Adding contact"); 1.271 + createResult1 = new mozContact(prop4); 1.272 + req = navigator.mozContacts.save(createResult1); 1.273 + req.onsuccess = function () { 1.274 + ok(createResult1.id, "The contact now has an ID."); 1.275 + sample_id1 = createResult1.id; 1.276 + next(); 1.277 + }; 1.278 + req.onerror = onFailure; 1.279 + }, 1.280 + function () { 1.281 + ok(true, "Retrieving by substring 1"); 1.282 + var num = "(0424) 233-9888" 1.283 + var options = {filterBy: ["tel"], 1.284 + filterOp: "match", 1.285 + filterValue: num}; 1.286 + req = mozContacts.find(options); 1.287 + req.onsuccess = function () { 1.288 + is(req.result.length, 1, "Found exactly 1 contacts."); 1.289 + next(); 1.290 + }; 1.291 + req.onerror = onFailure; 1.292 + }, 1.293 + function () { 1.294 + ok(true, "Deleting database"); 1.295 + req = mozContacts.clear() 1.296 + req.onsuccess = function () { 1.297 + ok(true, "Deleted the database"); 1.298 + next(); 1.299 + } 1.300 + req.onerror = onFailure; 1.301 + }, 1.302 + function () { 1.303 + ok(true, "Adding a new contact with a Brazilian country code"); 1.304 + createResult1 = new mozContact(prop5); 1.305 + req = navigator.mozContacts.save(createResult1); 1.306 + req.onsuccess = function () { 1.307 + ok(createResult1.id, "The contact now has an ID."); 1.308 + sample_id1 = createResult1.id; 1.309 + next(); 1.310 + }; 1.311 + req.onerror = onFailure; 1.312 + }, 1.313 + function () { 1.314 + ok(true, "Searching for international number with prefix"); 1.315 + var options = {filterBy: ["tel"], 1.316 + filterOp: "match", 1.317 + filterValue: brazilianNumber.international1}; 1.318 + req = mozContacts.find(options); 1.319 + req.onsuccess = function () { 1.320 + ok(req.result.length == 1, "Found exactly 1 contact."); 1.321 + findResult1 = req.result[0]; 1.322 + ok(findResult1.id == sample_id1, "Same ID"); 1.323 + next(); 1.324 + }; 1.325 + req.onerror = onFailure; 1.326 + }, 1.327 + function () { 1.328 + ok(true, "Deleting database"); 1.329 + req = mozContacts.clear() 1.330 + req.onsuccess = function () { 1.331 + ok(true, "Deleted the database"); 1.332 + next(); 1.333 + } 1.334 + req.onerror = onFailure; 1.335 + }, 1.336 + function () { 1.337 + ok(true, "all done!\n"); 1.338 + SimpleTest.finish(); 1.339 + } 1.340 +]; 1.341 + 1.342 +SpecialPowers.pushPrefEnv({ 1.343 + set: [ 1.344 + ["dom.phonenumber.substringmatching.BR", substringLength], 1.345 + ["ril.lastKnownSimMcc", "724"] 1.346 + ] 1.347 +}, start_tests); 1.348 +</script> 1.349 +</pre> 1.350 +</body> 1.351 +</html>