1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/contacts/tests/test_contacts_substringmatchingCL.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,204 @@ 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 949537 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=949537">Mozilla Bug 949537</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 landlineNumber = "+56 2 27654321"; 1.28 + 1.29 +var number = { 1.30 + local: "87654321", 1.31 + international: "+56 9 87654321" 1.32 +}; 1.33 + 1.34 +var properties = { 1.35 + name: ["Testname2"], 1.36 + tel: [{value: number.international}] 1.37 +}; 1.38 + 1.39 +var req; 1.40 +var steps = [ 1.41 + function () { 1.42 + ok(true, "Adding a contact with a Chilean number"); 1.43 + createResult1 = new mozContact(properties); 1.44 + req = navigator.mozContacts.save(createResult1); 1.45 + req.onsuccess = function () { 1.46 + ok(createResult1.id, "The contact now has an ID."); 1.47 + sample_id1 = createResult1.id; 1.48 + next(); 1.49 + }; 1.50 + req.onerror = onFailure; 1.51 + }, 1.52 + function () { 1.53 + ok(true, "Searching for Chilean number with prefix"); 1.54 + req = mozContacts.find({ 1.55 + filterBy: ["tel"], 1.56 + filterOp: "match", 1.57 + filterValue: number.international 1.58 + }); 1.59 + req.onsuccess = function () { 1.60 + ise(req.result.length, 1, "Found exactly 1 contact."); 1.61 + findResult1 = req.result[0]; 1.62 + ise(findResult1.id, sample_id1, "Same ID"); 1.63 + next(); 1.64 + }; 1.65 + req.onerror = onFailure; 1.66 + }, 1.67 + function () { 1.68 + ok(true, "Searching for Chilean number using local number"); 1.69 + req = mozContacts.find({ 1.70 + filterBy: ["tel"], 1.71 + filterOp: "match", 1.72 + filterValue: number.local 1.73 + }); 1.74 + req.onsuccess = function () { 1.75 + ise(req.result.length, 1, "Found 0 contacts."); 1.76 + next(); 1.77 + }; 1.78 + req.onerror = onFailure; 1.79 + }, 1.80 + 1.81 + clearDatabase, 1.82 + 1.83 + function () { 1.84 + ok(true, "Adding contact with mobile number"); 1.85 + createResult1 = new mozContact({tel: [{value: number.international}]}); 1.86 + req = navigator.mozContacts.save(createResult1); 1.87 + req.onsuccess = function () { 1.88 + ok(createResult1.id, "The contact now has an ID."); 1.89 + sample_id1 = createResult1.id; 1.90 + next(); 1.91 + }; 1.92 + req.onerror = onFailure; 1.93 + }, 1.94 + function () { 1.95 + ok(true, "Retrieving all contacts"); 1.96 + req = mozContacts.find({}); 1.97 + req.onsuccess = function () { 1.98 + ise(req.result.length, 1, "One contact."); 1.99 + findResult1 = req.result[0]; 1.100 + next(); 1.101 + }; 1.102 + req.onerror = onFailure; 1.103 + }, 1.104 + function () { 1.105 + ok(true, "Retrieving by last 8 digits"); 1.106 + req = mozContacts.find({ 1.107 + filterBy: ["tel"], 1.108 + filterOp: "match", 1.109 + filterValue: number.international.slice(-8) 1.110 + }); 1.111 + req.onsuccess = function () { 1.112 + ise(req.result.length, 1, "Found exactly 1 contact."); 1.113 + findResult1 = req.result[0]; 1.114 + ise(findResult1.id, sample_id1, "Same ID"); 1.115 + ise(findResult1.tel[0].value, number.international, "Same Value"); 1.116 + next(); 1.117 + }; 1.118 + req.onerror = onFailure; 1.119 + }, 1.120 + function () { 1.121 + ok(true, "Retrieving by last 9 digits"); 1.122 + req = mozContacts.find({ 1.123 + filterBy: ["tel"], 1.124 + filterOp: "match", 1.125 + filterValue: number.international.slice(-9) 1.126 + }); 1.127 + req.onsuccess = function () { 1.128 + ise(req.result.length, 1, "Found exactly 1 contact."); 1.129 + findResult1 = req.result[0]; 1.130 + ise(findResult1.id, sample_id1, "Same ID"); 1.131 + ise(findResult1.tel[0].value, number.international, "Same Value"); 1.132 + next(); 1.133 + }; 1.134 + req.onerror = onFailure; 1.135 + }, 1.136 + function () { 1.137 + ok(true, "Retrieving by last 6 digits"); 1.138 + req = mozContacts.find({ 1.139 + filterBy: ["tel"], 1.140 + filterOp: "match", 1.141 + filterValue: number.international.slice(-6) 1.142 + }); 1.143 + req.onsuccess = function () { 1.144 + ise(req.result.length, 0, "Found exactly zero contacts."); 1.145 + next(); 1.146 + }; 1.147 + req.onerror = onFailure; 1.148 + }, 1.149 + 1.150 + clearDatabase, 1.151 + 1.152 + function () { 1.153 + ok(true, "Adding contact with landline number"); 1.154 + createResult1 = new mozContact({tel: [{value: landlineNumber}]}); 1.155 + req = navigator.mozContacts.save(createResult1); 1.156 + req.onsuccess = function () { 1.157 + ok(createResult1.id, "The contact now has an ID."); 1.158 + sample_id1 = createResult1.id; 1.159 + next(); 1.160 + }; 1.161 + req.onerror = onFailure; 1.162 + }, 1.163 + function () { 1.164 + ok(true, "Retrieving all contacts"); 1.165 + req = mozContacts.find({}); 1.166 + req.onsuccess = function () { 1.167 + ise(req.result.length, 1, "One contact."); 1.168 + findResult1 = req.result[0]; 1.169 + next(); 1.170 + }; 1.171 + req.onerror = onFailure; 1.172 + }, 1.173 + function () { 1.174 + ok(true, "Retrieving by last 7 digits (local number) with landline calling prefix"); 1.175 + req = mozContacts.find({ 1.176 + filterBy: ["tel"], 1.177 + filterOp: "match", 1.178 + filterValue: "022" + landlineNumber.slice(-7) 1.179 + }); 1.180 + req.onsuccess = function () { 1.181 + ise(req.result.length, 1, "Found exactly 1 contact."); 1.182 + findResult1 = req.result[0]; 1.183 + ise(findResult1.id, sample_id1, "Same ID"); 1.184 + ise(findResult1.tel[0].value, landlineNumber, "Same Value"); 1.185 + next(); 1.186 + }; 1.187 + req.onerror = onFailure; 1.188 + }, 1.189 + 1.190 + clearDatabase, 1.191 + 1.192 + function () { 1.193 + ok(true, "all done!\n"); 1.194 + SimpleTest.finish(); 1.195 + } 1.196 +]; 1.197 + 1.198 +SpecialPowers.pushPrefEnv({ 1.199 + set: [ 1.200 + ["dom.phonenumber.substringmatching.CL", 8], 1.201 + ["ril.lastKnownSimMcc", "730"] 1.202 + ] 1.203 +}, start_tests); 1.204 +</script> 1.205 +</pre> 1.206 +</body> 1.207 +</html>