Wed, 31 Dec 2014 06:09:35 +0100
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=674720 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 674720 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=674720">Mozilla Bug 674720</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 initialRev; |
michael@0 | 25 | |
michael@0 | 26 | function checkRevision(revision, msg, then) { |
michael@0 | 27 | var revReq = mozContacts.getRevision(); |
michael@0 | 28 | revReq.onsuccess = function(e) { |
michael@0 | 29 | is(e.target.result, initialRev+revision, msg); |
michael@0 | 30 | then(); |
michael@0 | 31 | }; |
michael@0 | 32 | // The revision function isn't supported on Android so treat on failure as success |
michael@0 | 33 | if (isAndroid) { |
michael@0 | 34 | revReq.onerror = function(e) { |
michael@0 | 35 | then(); |
michael@0 | 36 | }; |
michael@0 | 37 | } else { |
michael@0 | 38 | revReq.onerror = onFailure; |
michael@0 | 39 | } |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | var req; |
michael@0 | 43 | |
michael@0 | 44 | var steps = [ |
michael@0 | 45 | function() { |
michael@0 | 46 | req = mozContacts.getRevision(); |
michael@0 | 47 | req.onsuccess = function(e) { |
michael@0 | 48 | initialRev = e.target.result; |
michael@0 | 49 | next(); |
michael@0 | 50 | }; |
michael@0 | 51 | |
michael@0 | 52 | // Android does not support the revision function. Treat errors as success. |
michael@0 | 53 | if (isAndroid) { |
michael@0 | 54 | req.onerror = function(e) { |
michael@0 | 55 | initialRev = 0; |
michael@0 | 56 | next(); |
michael@0 | 57 | }; |
michael@0 | 58 | } else { |
michael@0 | 59 | req.onerror = onFailure; |
michael@0 | 60 | } |
michael@0 | 61 | }, |
michael@0 | 62 | function () { |
michael@0 | 63 | ok(true, "Deleting database"); |
michael@0 | 64 | checkRevision(0, "Initial revision is 0", function() { |
michael@0 | 65 | req = mozContacts.clear(); |
michael@0 | 66 | req.onsuccess = function () { |
michael@0 | 67 | ok(true, "Deleted the database"); |
michael@0 | 68 | checkCount(0, "No contacts after clear", function() { |
michael@0 | 69 | checkRevision(1, "Revision was incremented on clear", next); |
michael@0 | 70 | }); |
michael@0 | 71 | }; |
michael@0 | 72 | req.onerror = onFailure; |
michael@0 | 73 | }); |
michael@0 | 74 | }, |
michael@0 | 75 | function () { |
michael@0 | 76 | ok(true, "Retrieving all contacts"); |
michael@0 | 77 | req = mozContacts.find(defaultOptions); |
michael@0 | 78 | req.onsuccess = function () { |
michael@0 | 79 | is(req.result.length, 0, "Empty database."); |
michael@0 | 80 | checkRevision(1, "Revision was not incremented on find", next); |
michael@0 | 81 | }; |
michael@0 | 82 | req.onerror = onFailure; |
michael@0 | 83 | }, |
michael@0 | 84 | function () { |
michael@0 | 85 | ok(true, "Adding empty contact"); |
michael@0 | 86 | createResult1 = new mozContact({}); |
michael@0 | 87 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 88 | req.onsuccess = function () { |
michael@0 | 89 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 90 | sample_id1 = createResult1.id; |
michael@0 | 91 | checkCount(1, "1 contact after adding empty contact", function() { |
michael@0 | 92 | checkRevision(2, "Revision was incremented on save", next); |
michael@0 | 93 | }); |
michael@0 | 94 | }; |
michael@0 | 95 | req.onerror = onFailure; |
michael@0 | 96 | }, |
michael@0 | 97 | function () { |
michael@0 | 98 | ok(true, "Retrieving all contacts"); |
michael@0 | 99 | req = mozContacts.find(defaultOptions); |
michael@0 | 100 | req.onsuccess = function () { |
michael@0 | 101 | is(req.result.length, 1, "One contact."); |
michael@0 | 102 | findResult1 = req.result[0]; |
michael@0 | 103 | next(); |
michael@0 | 104 | }; |
michael@0 | 105 | req.onerror = onFailure; |
michael@0 | 106 | }, |
michael@0 | 107 | function () { |
michael@0 | 108 | ok(true, "Deleting empty contact"); |
michael@0 | 109 | req = navigator.mozContacts.remove(findResult1); |
michael@0 | 110 | req.onsuccess = function () { |
michael@0 | 111 | var req2 = mozContacts.find(defaultOptions); |
michael@0 | 112 | req2.onsuccess = function () { |
michael@0 | 113 | is(req2.result.length, 0, "Empty Database."); |
michael@0 | 114 | clearTemps(); |
michael@0 | 115 | checkRevision(3, "Revision was incremented on remove", next); |
michael@0 | 116 | } |
michael@0 | 117 | req2.onerror = onFailure; |
michael@0 | 118 | } |
michael@0 | 119 | req.onerror = onFailure; |
michael@0 | 120 | }, |
michael@0 | 121 | function () { |
michael@0 | 122 | ok(true, "Adding a new contact1"); |
michael@0 | 123 | createResult1 = new mozContact(properties1); |
michael@0 | 124 | |
michael@0 | 125 | mozContacts.oncontactchange = function(event) { |
michael@0 | 126 | is(event.contactID, createResult1.id, "Same contactID"); |
michael@0 | 127 | is(event.reason, "create", "Same reason"); |
michael@0 | 128 | next(); |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 132 | req.onsuccess = function () { |
michael@0 | 133 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 134 | sample_id1 = createResult1.id; |
michael@0 | 135 | checkContacts(createResult1, properties1); |
michael@0 | 136 | }; |
michael@0 | 137 | req.onerror = onFailure; |
michael@0 | 138 | }, |
michael@0 | 139 | function () { |
michael@0 | 140 | ok(true, "Retrieving by substring 1"); |
michael@0 | 141 | var options = {filterBy: ["givenName"], |
michael@0 | 142 | filterOp: "startsWith", |
michael@0 | 143 | filterValue: properties1.givenName[1].substring(0,3)}; |
michael@0 | 144 | req = mozContacts.find(options); |
michael@0 | 145 | req.onsuccess = function () { |
michael@0 | 146 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 147 | findResult1 = req.result[0]; |
michael@0 | 148 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 149 | checkContacts(createResult1, properties1); |
michael@0 | 150 | // Some manual testing. Testint the testfunctions |
michael@0 | 151 | // tel: [{type: ["work"], value: "123456", carrier: "testCarrier"} , {type: ["home", "fax"], value: "+55 (31) 9876-3456"}], |
michael@0 | 152 | is(findResult1.tel[0].carrier, "testCarrier", "Same Carrier"); |
michael@0 | 153 | is(findResult1.tel[0].type, "work", "Same type"); |
michael@0 | 154 | is(findResult1.tel[0].value, "123456", "Same Value"); |
michael@0 | 155 | is(findResult1.tel[1].type[1], "fax", "Same type"); |
michael@0 | 156 | is(findResult1.tel[1].value, "+55 (31) 9876-3456", "Same Value"); |
michael@0 | 157 | |
michael@0 | 158 | is(findResult1.adr[0].countryName, "country 1", "Same country"); |
michael@0 | 159 | |
michael@0 | 160 | // email: [{type: ["work"], value: "x@y.com"}] |
michael@0 | 161 | is(findResult1.email[0].type, "work", "Same Type"); |
michael@0 | 162 | is(findResult1.email[0].value, "x@y.com", "Same Value"); |
michael@0 | 163 | next(); |
michael@0 | 164 | }; |
michael@0 | 165 | req.onerror = onFailure; |
michael@0 | 166 | }, |
michael@0 | 167 | function () { |
michael@0 | 168 | ok(true, "Searching for exact email"); |
michael@0 | 169 | var options = {filterBy: ["email"], |
michael@0 | 170 | filterOp: "equals", |
michael@0 | 171 | filterValue: properties1.email[0].value}; |
michael@0 | 172 | req = mozContacts.find(options); |
michael@0 | 173 | req.onsuccess = function () { |
michael@0 | 174 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 175 | findResult1 = req.result[0]; |
michael@0 | 176 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 177 | checkContacts(findResult1, createResult1); |
michael@0 | 178 | next(); |
michael@0 | 179 | }; |
michael@0 | 180 | req.onerror = onFailure; |
michael@0 | 181 | }, |
michael@0 | 182 | function () { |
michael@0 | 183 | ok(true, "Retrieving by substring and update"); |
michael@0 | 184 | mozContacts.oncontactchange = function(event) { |
michael@0 | 185 | is(event.contactID, findResult1.id, "Same contactID"); |
michael@0 | 186 | is(event.reason, "update", "Same reason"); |
michael@0 | 187 | } |
michael@0 | 188 | var options = {filterBy: ["givenName"], |
michael@0 | 189 | filterOp: "startsWith", |
michael@0 | 190 | filterValue: properties1.givenName[0].substring(0,3)}; |
michael@0 | 191 | req = mozContacts.find(options); |
michael@0 | 192 | req.onsuccess = function () { |
michael@0 | 193 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 194 | findResult1 = req.result[0]; |
michael@0 | 195 | findResult1.jobTitle = ["new Job"]; |
michael@0 | 196 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 197 | checkContacts(createResult1, properties1); |
michael@0 | 198 | next(); |
michael@0 | 199 | }; |
michael@0 | 200 | req.onerror = onFailure; |
michael@0 | 201 | }, |
michael@0 | 202 | function () { |
michael@0 | 203 | ok(true, "Adding a new contact"); |
michael@0 | 204 | mozContacts.oncontactchange = function(event) { |
michael@0 | 205 | is(event.contactID, createResult2.id, "Same contactID"); |
michael@0 | 206 | is(event.reason, "create", "Same reason"); |
michael@0 | 207 | } |
michael@0 | 208 | createResult2 = new mozContact({name: ["newName"]}); |
michael@0 | 209 | req = navigator.mozContacts.save(createResult2); |
michael@0 | 210 | req.onsuccess = function () { |
michael@0 | 211 | ok(createResult2.id, "The contact now has an ID."); |
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 2"); |
michael@0 | 218 | var options = {filterBy: ["givenName"], |
michael@0 | 219 | filterOp: "startsWith", |
michael@0 | 220 | filterValue: properties1.givenName[0].substring(0,3)}; |
michael@0 | 221 | req = mozContacts.find(options); |
michael@0 | 222 | req.onsuccess = function () { |
michael@0 | 223 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 224 | findResult1 = req.result[0]; |
michael@0 | 225 | checkContacts(createResult1, findResult1); |
michael@0 | 226 | next(); |
michael@0 | 227 | }; |
michael@0 | 228 | req.onerror = onFailure; |
michael@0 | 229 | }, |
michael@0 | 230 | function() { |
michael@0 | 231 | ok(true, "Retrieving by name equality 1"); |
michael@0 | 232 | var options = {filterBy: ["name"], |
michael@0 | 233 | filterOp: "equals", |
michael@0 | 234 | filterValue: properties1.name[0]}; |
michael@0 | 235 | req = mozContacts.find(options); |
michael@0 | 236 | req.onsuccess = function () { |
michael@0 | 237 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 238 | findResult1 = req.result[0]; |
michael@0 | 239 | checkContacts(createResult1, findResult1); |
michael@0 | 240 | next(); |
michael@0 | 241 | }; |
michael@0 | 242 | req.onerror = onFailure; |
michael@0 | 243 | }, |
michael@0 | 244 | function() { |
michael@0 | 245 | ok(true, "Retrieving by name equality 2"); |
michael@0 | 246 | var options = {filterBy: ["name"], |
michael@0 | 247 | filterOp: "equals", |
michael@0 | 248 | filterValue: properties1.name[1]}; |
michael@0 | 249 | req = mozContacts.find(options); |
michael@0 | 250 | req.onsuccess = function () { |
michael@0 | 251 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 252 | findResult1 = req.result[0]; |
michael@0 | 253 | checkContacts(createResult1, findResult1); |
michael@0 | 254 | next(); |
michael@0 | 255 | }; |
michael@0 | 256 | req.onerror = onFailure; |
michael@0 | 257 | }, |
michael@0 | 258 | function() { |
michael@0 | 259 | ok(true, "Retrieving by name substring 1"); |
michael@0 | 260 | var options = {filterBy: ["name"], |
michael@0 | 261 | filterOp: "startsWith", |
michael@0 | 262 | filterValue: properties1.name[0].substring(0,3).toLowerCase()}; |
michael@0 | 263 | req = mozContacts.find(options); |
michael@0 | 264 | req.onsuccess = function () { |
michael@0 | 265 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 266 | findResult1 = req.result[0]; |
michael@0 | 267 | checkContacts(createResult1, findResult1); |
michael@0 | 268 | next(); |
michael@0 | 269 | }; |
michael@0 | 270 | req.onerror = onFailure; |
michael@0 | 271 | }, |
michael@0 | 272 | function() { |
michael@0 | 273 | ok(true, "Retrieving by name substring 2"); |
michael@0 | 274 | var options = {filterBy: ["name"], |
michael@0 | 275 | filterOp: "startsWith", |
michael@0 | 276 | filterValue: properties1.name[1].substring(0,3).toLowerCase()}; |
michael@0 | 277 | req = mozContacts.find(options); |
michael@0 | 278 | req.onsuccess = function () { |
michael@0 | 279 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 280 | findResult1 = req.result[0]; |
michael@0 | 281 | checkContacts(createResult1, findResult1); |
michael@0 | 282 | next(); |
michael@0 | 283 | }; |
michael@0 | 284 | req.onerror = onFailure; |
michael@0 | 285 | }, |
michael@0 | 286 | function () { |
michael@0 | 287 | ok(true, "Remove contact1"); |
michael@0 | 288 | mozContacts.oncontactchange = function(event) { |
michael@0 | 289 | is(event.contactID, createResult1.id, "Same contactID"); |
michael@0 | 290 | is(event.reason, "remove", "Same reason"); |
michael@0 | 291 | } |
michael@0 | 292 | req = navigator.mozContacts.remove(createResult1); |
michael@0 | 293 | req.onsuccess = function () { |
michael@0 | 294 | next(); |
michael@0 | 295 | }; |
michael@0 | 296 | req.onerror = onFailure; |
michael@0 | 297 | }, |
michael@0 | 298 | function () { |
michael@0 | 299 | ok(true, "Retrieving by substring 3"); |
michael@0 | 300 | var options = {filterBy: ["givenName"], |
michael@0 | 301 | filterOp: "startsWith", |
michael@0 | 302 | filterValue: properties1.givenName[1].substring(0,3)}; |
michael@0 | 303 | req = mozContacts.find(options); |
michael@0 | 304 | req.onsuccess = function () { |
michael@0 | 305 | is(req.result.length, 0, "Found no contact."); |
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, "Remove contact2"); |
michael@0 | 312 | mozContacts.oncontactchange = function(event) { |
michael@0 | 313 | is(event.contactID, createResult2.id, "Same contactID"); |
michael@0 | 314 | is(event.reason, "remove", "Same reason"); |
michael@0 | 315 | } |
michael@0 | 316 | req = navigator.mozContacts.remove(createResult2); |
michael@0 | 317 | req.onsuccess = function () { |
michael@0 | 318 | next(); |
michael@0 | 319 | }; |
michael@0 | 320 | req.onerror = onFailure; |
michael@0 | 321 | }, |
michael@0 | 322 | function () { |
michael@0 | 323 | ok(true, "Retrieving by substring 4"); |
michael@0 | 324 | var options = {filterBy: ["givenName"], |
michael@0 | 325 | filterOp: "startsWith", |
michael@0 | 326 | filterValue: properties1.givenName[1].substring(0,3)}; |
michael@0 | 327 | req = mozContacts.find(options); |
michael@0 | 328 | req.onsuccess = function () { |
michael@0 | 329 | is(req.result.length, 0, "Found no contact."); |
michael@0 | 330 | next(); |
michael@0 | 331 | }; |
michael@0 | 332 | req.onerror = onFailure; |
michael@0 | 333 | }, |
michael@0 | 334 | function () { |
michael@0 | 335 | ok(true, "Deleting database"); |
michael@0 | 336 | mozContacts.oncontactchange = function(event) { |
michael@0 | 337 | is(event.contactID, "undefined", "Same contactID"); |
michael@0 | 338 | is(event.reason, "remove", "Same reason"); |
michael@0 | 339 | } |
michael@0 | 340 | req = mozContacts.clear(); |
michael@0 | 341 | req.onsuccess = function () { |
michael@0 | 342 | ok(true, "Deleted the database"); |
michael@0 | 343 | next(); |
michael@0 | 344 | }; |
michael@0 | 345 | req.onerror = onFailure; |
michael@0 | 346 | }, |
michael@0 | 347 | function () { |
michael@0 | 348 | ok(true, "Adding a new contact with properties1"); |
michael@0 | 349 | createResult1 = new mozContact(properties1); |
michael@0 | 350 | mozContacts.oncontactchange = null; |
michael@0 | 351 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 352 | req.onsuccess = function () { |
michael@0 | 353 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 354 | sample_id1 = createResult1.id; |
michael@0 | 355 | checkContacts(createResult1, properties1); |
michael@0 | 356 | next(); |
michael@0 | 357 | }; |
michael@0 | 358 | req.onerror = onFailure; |
michael@0 | 359 | }, |
michael@0 | 360 | function () { |
michael@0 | 361 | ok(true, "Retrieving by substring tel1"); |
michael@0 | 362 | var options = {filterBy: ["tel"], |
michael@0 | 363 | filterOp: "contains", |
michael@0 | 364 | filterValue: properties1.tel[1].value.substring(2,5)}; |
michael@0 | 365 | req = mozContacts.find(options); |
michael@0 | 366 | req.onsuccess = function () { |
michael@0 | 367 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 368 | findResult1 = req.result[0]; |
michael@0 | 369 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 370 | checkContacts(createResult1, properties1); |
michael@0 | 371 | next(); |
michael@0 | 372 | }; |
michael@0 | 373 | req.onerror = onFailure; |
michael@0 | 374 | }, |
michael@0 | 375 | function () { |
michael@0 | 376 | ok(true, "Retrieving by tel exact"); |
michael@0 | 377 | var options = {filterBy: ["tel"], |
michael@0 | 378 | filterOp: "equals", |
michael@0 | 379 | filterValue: "+55 319 8 7 6 3456"}; |
michael@0 | 380 | req = mozContacts.find(options); |
michael@0 | 381 | req.onsuccess = function () { |
michael@0 | 382 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 383 | findResult1 = req.result[0]; |
michael@0 | 384 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 385 | checkContacts(createResult1, properties1); |
michael@0 | 386 | next(); |
michael@0 | 387 | }; |
michael@0 | 388 | req.onerror = onFailure; |
michael@0 | 389 | }, |
michael@0 | 390 | function () { |
michael@0 | 391 | ok(true, "Retrieving by tel exact with substring"); |
michael@0 | 392 | var options = {filterBy: ["tel"], |
michael@0 | 393 | filterOp: "equals", |
michael@0 | 394 | filterValue: "3456"}; |
michael@0 | 395 | req = mozContacts.find(options); |
michael@0 | 396 | req.onsuccess = function () { |
michael@0 | 397 | is(req.result.length, 0, "Found no contacts."); |
michael@0 | 398 | next(); |
michael@0 | 399 | }; |
michael@0 | 400 | req.onerror = onFailure; |
michael@0 | 401 | }, |
michael@0 | 402 | function () { |
michael@0 | 403 | ok(true, "Retrieving by tel exact with substring"); |
michael@0 | 404 | var options = {filterBy: ["tel"], |
michael@0 | 405 | filterOp: "equals", |
michael@0 | 406 | filterValue: "+55 (31)"}; |
michael@0 | 407 | req = mozContacts.find(options); |
michael@0 | 408 | req.onsuccess = function () { |
michael@0 | 409 | is(req.result.length, 0, "Found no contacts."); |
michael@0 | 410 | next(); |
michael@0 | 411 | }; |
michael@0 | 412 | req.onerror = onFailure; |
michael@0 | 413 | }, |
michael@0 | 414 | function () { |
michael@0 | 415 | ok(true, "Retrieving by tel match national number"); |
michael@0 | 416 | var options = {filterBy: ["tel"], |
michael@0 | 417 | filterOp: "match", |
michael@0 | 418 | filterValue: "3198763456"}; |
michael@0 | 419 | req = mozContacts.find(options); |
michael@0 | 420 | req.onsuccess = function () { |
michael@0 | 421 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 422 | findResult1 = req.result[0]; |
michael@0 | 423 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 424 | checkContacts(createResult1, properties1); |
michael@0 | 425 | next(); |
michael@0 | 426 | }; |
michael@0 | 427 | req.onerror = onFailure; |
michael@0 | 428 | }, |
michael@0 | 429 | function () { |
michael@0 | 430 | ok(true, "Retrieving by tel match national format"); |
michael@0 | 431 | var options = {filterBy: ["tel"], |
michael@0 | 432 | filterOp: "match", |
michael@0 | 433 | filterValue: "0451 491934"}; |
michael@0 | 434 | req = mozContacts.find(options); |
michael@0 | 435 | req.onsuccess = function () { |
michael@0 | 436 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 437 | findResult1 = req.result[0]; |
michael@0 | 438 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 439 | checkContacts(createResult1, properties1); |
michael@0 | 440 | next(); |
michael@0 | 441 | }; |
michael@0 | 442 | req.onerror = onFailure; |
michael@0 | 443 | }, |
michael@0 | 444 | function () { |
michael@0 | 445 | ok(true, "Retrieving by tel match entered number"); |
michael@0 | 446 | var options = {filterBy: ["tel"], |
michael@0 | 447 | filterOp: "match", |
michael@0 | 448 | filterValue: "123456"}; |
michael@0 | 449 | req = mozContacts.find(options); |
michael@0 | 450 | req.onsuccess = function () { |
michael@0 | 451 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 452 | findResult1 = req.result[0]; |
michael@0 | 453 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 454 | checkContacts(createResult1, properties1); |
michael@0 | 455 | next(); |
michael@0 | 456 | }; |
michael@0 | 457 | req.onerror = onFailure; |
michael@0 | 458 | }, |
michael@0 | 459 | function () { |
michael@0 | 460 | ok(true, "Retrieving by tel match international number"); |
michael@0 | 461 | var options = {filterBy: ["tel"], |
michael@0 | 462 | filterOp: "match", |
michael@0 | 463 | filterValue: "+55 31 98763456"}; |
michael@0 | 464 | req = mozContacts.find(options); |
michael@0 | 465 | req.onsuccess = function () { |
michael@0 | 466 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 467 | findResult1 = req.result[0]; |
michael@0 | 468 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 469 | checkContacts(createResult1, properties1); |
michael@0 | 470 | next(); |
michael@0 | 471 | }; |
michael@0 | 472 | req.onerror = onFailure; |
michael@0 | 473 | }, |
michael@0 | 474 | function () { |
michael@0 | 475 | ok(true, "Retrieving by match with field other than tel"); |
michael@0 | 476 | var options = {filterBy: ["givenName"], |
michael@0 | 477 | filterOp: "match", |
michael@0 | 478 | filterValue: "my friends call me 555-4040"}; |
michael@0 | 479 | req = mozContacts.find(options); |
michael@0 | 480 | req.onsuccess = onUnwantedSuccess; |
michael@0 | 481 | req.onerror = function() { |
michael@0 | 482 | ok(true, "Failed"); |
michael@0 | 483 | next(); |
michael@0 | 484 | } |
michael@0 | 485 | }, |
michael@0 | 486 | function () { |
michael@0 | 487 | ok(true, "Retrieving by substring tel2"); |
michael@0 | 488 | var options = {filterBy: ["tel"], |
michael@0 | 489 | filterOp: "startsWith", |
michael@0 | 490 | filterValue: "9876"}; |
michael@0 | 491 | req = mozContacts.find(options); |
michael@0 | 492 | req.onsuccess = function () { |
michael@0 | 493 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 494 | findResult1 = req.result[0]; |
michael@0 | 495 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 496 | checkContacts(createResult1, properties1); |
michael@0 | 497 | next(); |
michael@0 | 498 | }; |
michael@0 | 499 | req.onerror = onFailure; |
michael@0 | 500 | }, |
michael@0 | 501 | function () { |
michael@0 | 502 | ok(true, "Retrieving by substring tel3"); |
michael@0 | 503 | var options = {filterBy: ["tel"], |
michael@0 | 504 | filterOp: "startsWith", |
michael@0 | 505 | filterValue: "98763456"}; |
michael@0 | 506 | req = mozContacts.find(options); |
michael@0 | 507 | req.onsuccess = function () { |
michael@0 | 508 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 509 | findResult1 = req.result[0]; |
michael@0 | 510 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 511 | checkContacts(createResult1, properties1); |
michael@0 | 512 | next(); |
michael@0 | 513 | }; |
michael@0 | 514 | req.onerror = onFailure; |
michael@0 | 515 | }, |
michael@0 | 516 | function () { |
michael@0 | 517 | ok(true, "Retrieving by substring 5"); |
michael@0 | 518 | var options = {filterBy: ["givenName"], |
michael@0 | 519 | filterOp: "startsWith", |
michael@0 | 520 | filterValue: properties1.givenName[0].substring(0,3)}; |
michael@0 | 521 | req = mozContacts.find(options); |
michael@0 | 522 | req.onsuccess = function () { |
michael@0 | 523 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 524 | findResult1 = req.result[0]; |
michael@0 | 525 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 526 | checkContacts(createResult1, properties1); |
michael@0 | 527 | next(); |
michael@0 | 528 | }; |
michael@0 | 529 | req.onerror = onFailure; |
michael@0 | 530 | }, |
michael@0 | 531 | function () { |
michael@0 | 532 | ok(true, "Retrieving by substring 6"); |
michael@0 | 533 | var options = {filterBy: ["familyName", "givenName"], |
michael@0 | 534 | filterOp: "startsWith", |
michael@0 | 535 | filterValue: properties1.givenName[0].substring(0,3)}; |
michael@0 | 536 | req = mozContacts.find(options); |
michael@0 | 537 | req.onsuccess = function () { |
michael@0 | 538 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 539 | findResult1 = req.result[0]; |
michael@0 | 540 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 541 | checkContacts(createResult1, properties1); |
michael@0 | 542 | next(); |
michael@0 | 543 | }; |
michael@0 | 544 | req.onerror = onFailure; |
michael@0 | 545 | }, |
michael@0 | 546 | function () { |
michael@0 | 547 | ok(true, "Retrieving by substring3, Testing multi entry"); |
michael@0 | 548 | var options = {filterBy: ["givenName", "familyName"], |
michael@0 | 549 | filterOp: "startsWith", |
michael@0 | 550 | filterValue: properties1.familyName[1].substring(0,3).toLowerCase()}; |
michael@0 | 551 | req = mozContacts.find(options); |
michael@0 | 552 | req.onsuccess = function () { |
michael@0 | 553 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 554 | findResult1 = req.result[0]; |
michael@0 | 555 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 556 | checkContacts(createResult1, properties1); |
michael@0 | 557 | next(); |
michael@0 | 558 | }; |
michael@0 | 559 | req.onerror = onFailure; |
michael@0 | 560 | }, |
michael@0 | 561 | function () { |
michael@0 | 562 | ok(true, "Retrieving all contacts"); |
michael@0 | 563 | req = mozContacts.find(defaultOptions); |
michael@0 | 564 | req.onsuccess = function() { |
michael@0 | 565 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 566 | findResult1 = req.result[0]; |
michael@0 | 567 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 568 | checkContacts(createResult1, findResult1); |
michael@0 | 569 | if (!isAndroid) { |
michael@0 | 570 | ok(findResult1.updated, "Has updated field"); |
michael@0 | 571 | ok(findResult1.published, "Has published field"); |
michael@0 | 572 | } |
michael@0 | 573 | next(); |
michael@0 | 574 | } |
michael@0 | 575 | req.onerror = onFailure; |
michael@0 | 576 | }, |
michael@0 | 577 | function () { |
michael@0 | 578 | ok(true, "Modifying contact1"); |
michael@0 | 579 | if (!findResult1) { |
michael@0 | 580 | SpecialPowers.executeSoon(next); |
michael@0 | 581 | } else { |
michael@0 | 582 | findResult1.impp = properties1.impp = [{value:"phil impp"}]; |
michael@0 | 583 | req = navigator.mozContacts.save(findResult1); |
michael@0 | 584 | req.onsuccess = function () { |
michael@0 | 585 | var req2 = mozContacts.find(defaultOptions); |
michael@0 | 586 | req2.onsuccess = function() { |
michael@0 | 587 | is(req2.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 588 | findResult2 = req2.result[0]; |
michael@0 | 589 | ok(findResult2.id == sample_id1, "Same ID"); |
michael@0 | 590 | checkContacts(findResult2, properties1); |
michael@0 | 591 | is(findResult2.impp.length, 1, "Found exactly 1 IMS info."); |
michael@0 | 592 | next(); |
michael@0 | 593 | }; |
michael@0 | 594 | req2.onerror = onFailure; |
michael@0 | 595 | }; |
michael@0 | 596 | req.onerror = onFailure; |
michael@0 | 597 | } |
michael@0 | 598 | }, |
michael@0 | 599 | function() { |
michael@0 | 600 | // Android does not support published/updated fields. Skip this. |
michael@0 | 601 | if (isAndroid) { |
michael@0 | 602 | next(); |
michael@0 | 603 | return; |
michael@0 | 604 | } |
michael@0 | 605 | |
michael@0 | 606 | ok(true, "Saving old contact, should abort!"); |
michael@0 | 607 | req = mozContacts.save(createResult1); |
michael@0 | 608 | req.onsuccess = onUnwantedSuccess; |
michael@0 | 609 | req.onerror = function() { ok(true, "Successfully declined updating old contact!"); next(); }; |
michael@0 | 610 | }, |
michael@0 | 611 | function () { |
michael@0 | 612 | ok(true, "Retrieving a specific contact by ID"); |
michael@0 | 613 | var options = {filterBy: ["id"], |
michael@0 | 614 | filterOp: "equals", |
michael@0 | 615 | filterValue: sample_id1}; |
michael@0 | 616 | req = mozContacts.find(options); |
michael@0 | 617 | req.onsuccess = function () { |
michael@0 | 618 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 619 | findResult1 = req.result[0]; |
michael@0 | 620 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 621 | checkContacts(findResult1, properties1); |
michael@0 | 622 | next(); |
michael@0 | 623 | }; |
michael@0 | 624 | req.onerror = onFailure; |
michael@0 | 625 | }, |
michael@0 | 626 | function () { |
michael@0 | 627 | ok(true, "Retrieving a specific contact by givenName"); |
michael@0 | 628 | var options = {filterBy: ["givenName"], |
michael@0 | 629 | filterOp: "equals", |
michael@0 | 630 | filterValue: properties1.givenName[0]}; |
michael@0 | 631 | req = mozContacts.find(options); |
michael@0 | 632 | req.onsuccess = function () { |
michael@0 | 633 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 634 | findResult1 = req.result[0]; |
michael@0 | 635 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 636 | checkContacts(findResult1, properties1); |
michael@0 | 637 | next(); |
michael@0 | 638 | } |
michael@0 | 639 | req.onerror = onFailure; |
michael@0 | 640 | }, |
michael@0 | 641 | function () { |
michael@0 | 642 | ok(true, "Modifying contact2"); |
michael@0 | 643 | if (!findResult1) { |
michael@0 | 644 | SpecialPowers.executeSoon(next); |
michael@0 | 645 | } else { |
michael@0 | 646 | findResult1.impp = properties1.impp = [{value: "phil impp"}]; |
michael@0 | 647 | req = mozContacts.save(findResult1); |
michael@0 | 648 | req.onsuccess = function () { |
michael@0 | 649 | var req2 = mozContacts.find(defaultOptions); |
michael@0 | 650 | req2.onsuccess = function () { |
michael@0 | 651 | is(req2.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 652 | findResult1 = req2.result[0]; |
michael@0 | 653 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 654 | checkContacts(findResult1, properties1); |
michael@0 | 655 | is(findResult1.impp.length, 1, "Found exactly 1 IMS info."); |
michael@0 | 656 | next(); |
michael@0 | 657 | } |
michael@0 | 658 | req2.onerror = onFailure; |
michael@0 | 659 | }; |
michael@0 | 660 | req.onerror = onFailure; |
michael@0 | 661 | } |
michael@0 | 662 | }, |
michael@0 | 663 | function () { |
michael@0 | 664 | ok(true, "Searching contacts by query"); |
michael@0 | 665 | var options = {filterBy: ["givenName", "email"], |
michael@0 | 666 | filterOp: "startsWith", |
michael@0 | 667 | filterValue: properties1.givenName[0].substring(0,4)}; |
michael@0 | 668 | req = mozContacts.find(options); |
michael@0 | 669 | req.onsuccess = function () { |
michael@0 | 670 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 671 | findResult1 = req.result[0]; |
michael@0 | 672 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 673 | checkContacts(findResult1, properties1); |
michael@0 | 674 | next(); |
michael@0 | 675 | }; |
michael@0 | 676 | req.onerror = onFailure; |
michael@0 | 677 | }, |
michael@0 | 678 | function () { |
michael@0 | 679 | ok(true, "Searching contacts by query"); |
michael@0 | 680 | var options = {filterBy: ["givenName", "email"], |
michael@0 | 681 | filterOp: "startsWith", |
michael@0 | 682 | filterValue: properties1.givenName[0]}; |
michael@0 | 683 | req = mozContacts.find(options); |
michael@0 | 684 | req.onsuccess = function () { |
michael@0 | 685 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 686 | findResult1 = req.result[0]; |
michael@0 | 687 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 688 | checkContacts(findResult1, properties1); |
michael@0 | 689 | next(); |
michael@0 | 690 | }; |
michael@0 | 691 | req.onerror = onFailure; |
michael@0 | 692 | }, |
michael@0 | 693 | function () { |
michael@0 | 694 | ok(true, "Searching contacts with multiple indices"); |
michael@0 | 695 | var options = {filterBy: ["email", "givenName"], |
michael@0 | 696 | filterOp: "equals", |
michael@0 | 697 | filterValue: properties1.givenName[1]}; |
michael@0 | 698 | req = mozContacts.find(options); |
michael@0 | 699 | req.onsuccess = function () { |
michael@0 | 700 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 701 | findResult1 = req.result[0]; |
michael@0 | 702 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 703 | checkContacts(findResult1, properties1); |
michael@0 | 704 | next(); |
michael@0 | 705 | }; |
michael@0 | 706 | req.onerror = onFailure; |
michael@0 | 707 | }, |
michael@0 | 708 | function () { |
michael@0 | 709 | ok(true, "Modifying contact3"); |
michael@0 | 710 | if (!findResult1) { |
michael@0 | 711 | SpecialPowers.executeSoon(next); |
michael@0 | 712 | } else { |
michael@0 | 713 | findResult1.email = [{value: properties1.nickname}]; |
michael@0 | 714 | findResult1.nickname = ["TEST"]; |
michael@0 | 715 | var newContact = new mozContact(findResult1); |
michael@0 | 716 | req = mozContacts.save(newContact); |
michael@0 | 717 | req.onsuccess = function () { |
michael@0 | 718 | var options = {filterBy: ["email", "givenName"], |
michael@0 | 719 | filterOp: "startsWith", |
michael@0 | 720 | filterValue: properties1.givenName[0]}; |
michael@0 | 721 | // One contact has it in nickname and the other in email |
michael@0 | 722 | var req2 = mozContacts.find(options); |
michael@0 | 723 | req2.onsuccess = function () { |
michael@0 | 724 | is(req2.result.length, 2, "Found exactly 2 contacts."); |
michael@0 | 725 | ok(req2.result[0].id != req2.result[1].id, "Different ID"); |
michael@0 | 726 | next(); |
michael@0 | 727 | } |
michael@0 | 728 | req2.onerror = onFailure; |
michael@0 | 729 | }; |
michael@0 | 730 | req.onerror = onFailure; |
michael@0 | 731 | } |
michael@0 | 732 | }, |
michael@0 | 733 | function () { |
michael@0 | 734 | ok(true, "Deleting contact" + findResult1); |
michael@0 | 735 | req = mozContacts.remove(findResult1); |
michael@0 | 736 | req.onsuccess = function () { |
michael@0 | 737 | var req2 = mozContacts.find(defaultOptions); |
michael@0 | 738 | req2.onsuccess = function () { |
michael@0 | 739 | is(req2.result.length, 1, "One contact left."); |
michael@0 | 740 | findResult1 = req2.result[0]; |
michael@0 | 741 | next(); |
michael@0 | 742 | } |
michael@0 | 743 | req2.onerror = onFailure; |
michael@0 | 744 | } |
michael@0 | 745 | req.onerror = onFailure; |
michael@0 | 746 | }, |
michael@0 | 747 | function () { |
michael@0 | 748 | ok(true, "Deleting database"); |
michael@0 | 749 | req = mozContacts.remove(findResult1); |
michael@0 | 750 | req.onsuccess = function () { |
michael@0 | 751 | clearTemps(); |
michael@0 | 752 | next(); |
michael@0 | 753 | }; |
michael@0 | 754 | req.onerror = onFailure; |
michael@0 | 755 | }, |
michael@0 | 756 | function() { |
michael@0 | 757 | ok(true, "Test JSON.stringify output for mozContact objects"); |
michael@0 | 758 | var json = JSON.parse(JSON.stringify(new mozContact(properties1))); |
michael@0 | 759 | checkContacts(json, properties1); |
michael@0 | 760 | next(); |
michael@0 | 761 | }, |
michael@0 | 762 | function() { |
michael@0 | 763 | ok(true, "Test slice"); |
michael@0 | 764 | var c = new mozContact(); |
michael@0 | 765 | c.email = [{ type: ["foo"], value: "bar@baz" }] |
michael@0 | 766 | var arr = c.email; |
michael@0 | 767 | is(arr[0].value, "bar@baz", "Should have the right value"); |
michael@0 | 768 | arr = arr.slice(); |
michael@0 | 769 | is(arr[0].value, "bar@baz", "Should have the right value after slicing"); |
michael@0 | 770 | next(); |
michael@0 | 771 | }, |
michael@0 | 772 | function () { |
michael@0 | 773 | ok(true, "all done!\n"); |
michael@0 | 774 | clearTemps(); |
michael@0 | 775 | |
michael@0 | 776 | SimpleTest.finish(); |
michael@0 | 777 | } |
michael@0 | 778 | ]; |
michael@0 | 779 | |
michael@0 | 780 | start_tests(); |
michael@0 | 781 | </script> |
michael@0 | 782 | </pre> |
michael@0 | 783 | </body> |
michael@0 | 784 | </html> |