dom/contacts/tests/test_contacts_substringmatching.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE html>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=877302
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 877302 substring matching for WebContacts</title>
michael@0 8 <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
michael@0 9 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 11 </head>
michael@0 12 <body>
michael@0 13
michael@0 14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=877302">Mozilla Bug 877302</a>
michael@0 15 <p id="display"></p>
michael@0 16 <div id="content" style="display: none">
michael@0 17
michael@0 18 </div>
michael@0 19 <pre id="test">
michael@0 20 <script type="text/javascript;version=1.8" src="http://mochi.test:8888/tests/dom/contacts/tests/shared.js"></script>
michael@0 21 <script class="testbody" type="text/javascript">
michael@0 22 "use strict";
michael@0 23
michael@0 24 var substringLength = 8;
michael@0 25
michael@0 26 var prop = {
michael@0 27 tel: [{value: "7932012345" }, {value: "7932012346"}]
michael@0 28 };
michael@0 29
michael@0 30 var prop2 = {
michael@0 31 tel: [{value: "01187654321" }]
michael@0 32 };
michael@0 33
michael@0 34 var prop3 = {
michael@0 35 tel: [{ value: "+43332112346" }]
michael@0 36 };
michael@0 37
michael@0 38 var prop4 = {
michael@0 39 tel: [{ value: "(0414) 233-9888" }]
michael@0 40 };
michael@0 41
michael@0 42 var brazilianNumber = {
michael@0 43 international1: "0041557932012345",
michael@0 44 international2: "+557932012345"
michael@0 45 };
michael@0 46
michael@0 47 var prop5 = {
michael@0 48 tel: [{value: brazilianNumber.international2}]
michael@0 49 };
michael@0 50
michael@0 51 var req;
michael@0 52 var steps = [
michael@0 53 function () {
michael@0 54 ok(true, "Deleting database");
michael@0 55 req = mozContacts.clear()
michael@0 56 req.onsuccess = function () {
michael@0 57 ok(true, "Deleted the database");
michael@0 58 next();
michael@0 59 }
michael@0 60 req.onerror = onFailure;
michael@0 61 },
michael@0 62 function () {
michael@0 63 ok(true, "Adding contact");
michael@0 64 createResult1 = new mozContact(prop);
michael@0 65 req = navigator.mozContacts.save(createResult1);
michael@0 66 req.onsuccess = function () {
michael@0 67 ok(createResult1.id, "The contact now has an ID.");
michael@0 68 sample_id1 = createResult1.id;
michael@0 69 next();
michael@0 70 };
michael@0 71 req.onerror = onFailure;
michael@0 72 },
michael@0 73 function () {
michael@0 74 ok(true, "Retrieving all contacts");
michael@0 75 req = mozContacts.find({});
michael@0 76 req.onsuccess = function () {
michael@0 77 is(req.result.length, 1, "One contact.");
michael@0 78 findResult1 = req.result[0];
michael@0 79 next();
michael@0 80 };
michael@0 81 req.onerror = onFailure;
michael@0 82 },
michael@0 83 function () {
michael@0 84 ok(true, "Retrieving by substring 1");
michael@0 85 var length = prop.tel[0].value.length;
michael@0 86 var num = prop.tel[0].value.substring(length - substringLength, length);
michael@0 87 var options = {filterBy: ["tel"],
michael@0 88 filterOp: "match",
michael@0 89 filterValue: num};
michael@0 90 req = mozContacts.find(options);
michael@0 91 req.onsuccess = function () {
michael@0 92 is(req.result.length, 1, "Found exactly 1 contact.");
michael@0 93 findResult1 = req.result[0];
michael@0 94 ok(findResult1.id == sample_id1, "Same ID");
michael@0 95 is(findResult1.tel[0].value, "7932012345", "Same Value");
michael@0 96 next();
michael@0 97 };
michael@0 98 req.onerror = onFailure;
michael@0 99 },
michael@0 100 function () {
michael@0 101 ok(true, "Retrieving by substring 2");
michael@0 102 var length = prop.tel[1].value.length;
michael@0 103 var num = prop.tel[1].value.substring(length - substringLength, length);
michael@0 104 var options = {filterBy: ["tel"],
michael@0 105 filterOp: "match",
michael@0 106 filterValue: num};
michael@0 107 req = mozContacts.find(options);
michael@0 108 req.onsuccess = function () {
michael@0 109 is(req.result.length, 1, "Found exactly 1 contact.");
michael@0 110 findResult1 = req.result[0];
michael@0 111 ok(findResult1.id == sample_id1, "Same ID");
michael@0 112 is(findResult1.tel[0].value, "7932012345", "Same Value");
michael@0 113 next();
michael@0 114 };
michael@0 115 req.onerror = onFailure;
michael@0 116 },
michael@0 117 function () {
michael@0 118 ok(true, "Retrieving by substring 3");
michael@0 119 var length = prop.tel[0].value.length;
michael@0 120 var num = prop.tel[0].value.substring(length - substringLength + 1, length);
michael@0 121 var options = {filterBy: ["tel"],
michael@0 122 filterOp: "match",
michael@0 123 filterValue: num};
michael@0 124 req = mozContacts.find(options);
michael@0 125 req.onsuccess = function () {
michael@0 126 is(req.result.length, 0, "Found exactly 0 contacts.");
michael@0 127 next();
michael@0 128 };
michael@0 129 req.onerror = onFailure;
michael@0 130 },
michael@0 131 function () {
michael@0 132 ok(true, "Retrieving by substring 4");
michael@0 133 var length = prop.tel[0].value.length;
michael@0 134 var num = prop.tel[0].value.substring(length - substringLength - 1, length);
michael@0 135 var options = {filterBy: ["tel"],
michael@0 136 filterOp: "match",
michael@0 137 filterValue: num};
michael@0 138 req = mozContacts.find(options);
michael@0 139 req.onsuccess = function () {
michael@0 140 is(req.result.length, 1, "Found exactly 1 contacts.");
michael@0 141 next();
michael@0 142 };
michael@0 143 req.onerror = onFailure;
michael@0 144 },
michael@0 145 function () {
michael@0 146 ok(true, "Adding contact");
michael@0 147 createResult1 = new mozContact(prop2);
michael@0 148 req = navigator.mozContacts.save(createResult1);
michael@0 149 req.onsuccess = function () {
michael@0 150 ok(createResult1.id, "The contact now has an ID.");
michael@0 151 sample_id1 = createResult1.id;
michael@0 152 next();
michael@0 153 };
michael@0 154 req.onerror = onFailure;
michael@0 155 },
michael@0 156 function () {
michael@0 157 ok(true, "Retrieving by substring 5");
michael@0 158 var options = {filterBy: ["tel"],
michael@0 159 filterOp: "match",
michael@0 160 filterValue: "87654321"};
michael@0 161 req = mozContacts.find(options);
michael@0 162 req.onsuccess = function () {
michael@0 163 is(req.result.length, 1, "Found exactly 1 contacts.");
michael@0 164 next();
michael@0 165 };
michael@0 166 req.onerror = onFailure;
michael@0 167 },
michael@0 168 function () {
michael@0 169 ok(true, "Retrieving by substring 6");
michael@0 170 var options = {filterBy: ["tel"],
michael@0 171 filterOp: "match",
michael@0 172 filterValue: "01187654321"};
michael@0 173 req = mozContacts.find(options);
michael@0 174 req.onsuccess = function () {
michael@0 175 is(req.result.length, 1, "Found exactly 1 contacts.");
michael@0 176 next();
michael@0 177 };
michael@0 178 req.onerror = onFailure;
michael@0 179 },
michael@0 180 function () {
michael@0 181 ok(true, "Retrieving by substring 7");
michael@0 182 var options = {filterBy: ["tel"],
michael@0 183 filterOp: "match",
michael@0 184 filterValue: "909087654321"};
michael@0 185 req = mozContacts.find(options);
michael@0 186 req.onsuccess = function () {
michael@0 187 is(req.result.length, 1, "Found exactly 1 contacts.");
michael@0 188 next();
michael@0 189 };
michael@0 190 req.onerror = onFailure;
michael@0 191 },
michael@0 192 function () {
michael@0 193 ok(true, "Retrieving by substring 8");
michael@0 194 var options = {filterBy: ["tel"],
michael@0 195 filterOp: "match",
michael@0 196 filterValue: "0411187654321"};
michael@0 197 req = mozContacts.find(options);
michael@0 198 req.onsuccess = function () {
michael@0 199 is(req.result.length, 1, "Found exactly 1 contacts.");
michael@0 200 next();
michael@0 201 };
michael@0 202 req.onerror = onFailure;
michael@0 203 },
michael@0 204 function () {
michael@0 205 ok(true, "Retrieving by substring 9");
michael@0 206 var options = {filterBy: ["tel"],
michael@0 207 filterOp: "match",
michael@0 208 filterValue: "90411187654321"};
michael@0 209 req = mozContacts.find(options);
michael@0 210 req.onsuccess = function () {
michael@0 211 is(req.result.length, 1, "Found exactly 1 contacts.");
michael@0 212 next();
michael@0 213 };
michael@0 214 req.onerror = onFailure;
michael@0 215 },
michael@0 216 function () {
michael@0 217 ok(true, "Retrieving by substring 10");
michael@0 218 var options = {filterBy: ["tel"],
michael@0 219 filterOp: "match",
michael@0 220 filterValue: "+551187654321"};
michael@0 221 req = mozContacts.find(options);
michael@0 222 req.onsuccess = function () {
michael@0 223 is(req.result.length, 1, "Found exactly 1 contacts.");
michael@0 224 next();
michael@0 225 };
michael@0 226 req.onerror = onFailure;
michael@0 227 },
michael@0 228 function () {
michael@0 229 ok(true, "Deleting database");
michael@0 230 req = mozContacts.clear()
michael@0 231 req.onsuccess = function () {
michael@0 232 ok(true, "Deleted the database");
michael@0 233 next();
michael@0 234 }
michael@0 235 req.onerror = onFailure;
michael@0 236 },
michael@0 237 function () {
michael@0 238 ok(true, "Adding contact");
michael@0 239 createResult1 = new mozContact(prop3);
michael@0 240 req = navigator.mozContacts.save(createResult1);
michael@0 241 req.onsuccess = function () {
michael@0 242 ok(createResult1.id, "The contact now has an ID.");
michael@0 243 sample_id1 = createResult1.id;
michael@0 244 next();
michael@0 245 };
michael@0 246 req.onerror = onFailure;
michael@0 247 },
michael@0 248 function () {
michael@0 249 if (!isAndroid) { // Bug 905927
michael@0 250 ok(true, "Retrieving by substring 1");
michael@0 251 var length = prop3.tel[0].value.length;
michael@0 252 var num = prop3.tel[0].value.substring(length - substringLength, length);
michael@0 253 var options = {filterBy: ["tel"],
michael@0 254 filterOp: "match",
michael@0 255 filterValue: num};
michael@0 256 req = mozContacts.find(options);
michael@0 257 req.onsuccess = function () {
michael@0 258 is(req.result.length, 0, "Found exactly 0 contacts.");
michael@0 259 next();
michael@0 260 };
michael@0 261 req.onerror = onFailure;
michael@0 262 } else {
michael@0 263 SpecialPowers.executeSoon(next);
michael@0 264 }
michael@0 265 },
michael@0 266 function () {
michael@0 267 ok(true, "Adding contact");
michael@0 268 createResult1 = new mozContact(prop4);
michael@0 269 req = navigator.mozContacts.save(createResult1);
michael@0 270 req.onsuccess = function () {
michael@0 271 ok(createResult1.id, "The contact now has an ID.");
michael@0 272 sample_id1 = createResult1.id;
michael@0 273 next();
michael@0 274 };
michael@0 275 req.onerror = onFailure;
michael@0 276 },
michael@0 277 function () {
michael@0 278 ok(true, "Retrieving by substring 1");
michael@0 279 var num = "(0424) 233-9888"
michael@0 280 var options = {filterBy: ["tel"],
michael@0 281 filterOp: "match",
michael@0 282 filterValue: num};
michael@0 283 req = mozContacts.find(options);
michael@0 284 req.onsuccess = function () {
michael@0 285 is(req.result.length, 1, "Found exactly 1 contacts.");
michael@0 286 next();
michael@0 287 };
michael@0 288 req.onerror = onFailure;
michael@0 289 },
michael@0 290 function () {
michael@0 291 ok(true, "Deleting database");
michael@0 292 req = mozContacts.clear()
michael@0 293 req.onsuccess = function () {
michael@0 294 ok(true, "Deleted the database");
michael@0 295 next();
michael@0 296 }
michael@0 297 req.onerror = onFailure;
michael@0 298 },
michael@0 299 function () {
michael@0 300 ok(true, "Adding a new contact with a Brazilian country code");
michael@0 301 createResult1 = new mozContact(prop5);
michael@0 302 req = navigator.mozContacts.save(createResult1);
michael@0 303 req.onsuccess = function () {
michael@0 304 ok(createResult1.id, "The contact now has an ID.");
michael@0 305 sample_id1 = createResult1.id;
michael@0 306 next();
michael@0 307 };
michael@0 308 req.onerror = onFailure;
michael@0 309 },
michael@0 310 function () {
michael@0 311 ok(true, "Searching for international number with prefix");
michael@0 312 var options = {filterBy: ["tel"],
michael@0 313 filterOp: "match",
michael@0 314 filterValue: brazilianNumber.international1};
michael@0 315 req = mozContacts.find(options);
michael@0 316 req.onsuccess = function () {
michael@0 317 ok(req.result.length == 1, "Found exactly 1 contact.");
michael@0 318 findResult1 = req.result[0];
michael@0 319 ok(findResult1.id == sample_id1, "Same ID");
michael@0 320 next();
michael@0 321 };
michael@0 322 req.onerror = onFailure;
michael@0 323 },
michael@0 324 function () {
michael@0 325 ok(true, "Deleting database");
michael@0 326 req = mozContacts.clear()
michael@0 327 req.onsuccess = function () {
michael@0 328 ok(true, "Deleted the database");
michael@0 329 next();
michael@0 330 }
michael@0 331 req.onerror = onFailure;
michael@0 332 },
michael@0 333 function () {
michael@0 334 ok(true, "all done!\n");
michael@0 335 SimpleTest.finish();
michael@0 336 }
michael@0 337 ];
michael@0 338
michael@0 339 SpecialPowers.pushPrefEnv({
michael@0 340 set: [
michael@0 341 ["dom.phonenumber.substringmatching.BR", substringLength],
michael@0 342 ["ril.lastKnownSimMcc", "724"]
michael@0 343 ]
michael@0 344 }, start_tests);
michael@0 345 </script>
michael@0 346 </pre>
michael@0 347 </body>
michael@0 348 </html>

mercurial