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 req; |
michael@0 | 25 | |
michael@0 | 26 | var steps = [ |
michael@0 | 27 | function () { |
michael@0 | 28 | ok(true, "Adding a new contact"); |
michael@0 | 29 | createResult1 = new mozContact(properties1); |
michael@0 | 30 | req = mozContacts.save(createResult1) |
michael@0 | 31 | req.onsuccess = function () { |
michael@0 | 32 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 33 | sample_id1 = createResult1.id; |
michael@0 | 34 | next(); |
michael@0 | 35 | } |
michael@0 | 36 | req.onerror = onFailure; |
michael@0 | 37 | }, |
michael@0 | 38 | function () { |
michael@0 | 39 | ok(true, "Adding a new contact2"); |
michael@0 | 40 | createResult2 = new mozContact(properties2); |
michael@0 | 41 | req = mozContacts.save(createResult2); |
michael@0 | 42 | req.onsuccess = function () { |
michael@0 | 43 | ok(createResult2.id, "The contact now has an ID."); |
michael@0 | 44 | sample_id2 = createResult2.id; |
michael@0 | 45 | next(); |
michael@0 | 46 | }; |
michael@0 | 47 | req.onerror = onFailure; |
michael@0 | 48 | }, |
michael@0 | 49 | function () { |
michael@0 | 50 | ok(true, "Retrieving all contacts"); |
michael@0 | 51 | req = mozContacts.find({sortBy: "familyName"}); |
michael@0 | 52 | req.onsuccess = function () { |
michael@0 | 53 | is(req.result.length, 2, "Found exactly 2 contact."); |
michael@0 | 54 | checkContacts(req.result[1], properties1); |
michael@0 | 55 | next(); |
michael@0 | 56 | } |
michael@0 | 57 | req.onerror = onFailure; |
michael@0 | 58 | }, |
michael@0 | 59 | function () { |
michael@0 | 60 | console.log("Searching contacts by query1"); |
michael@0 | 61 | var options = {filterBy: ["givenName", "email"], |
michael@0 | 62 | filterOp: "startsWith", |
michael@0 | 63 | filterValue: properties1.givenName[0].substring(0, 4)} |
michael@0 | 64 | req = mozContacts.find(options) |
michael@0 | 65 | req.onsuccess = function () { |
michael@0 | 66 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 67 | findResult1 = req.result[0]; |
michael@0 | 68 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 69 | checkContacts(findResult1, createResult1); |
michael@0 | 70 | next(); |
michael@0 | 71 | } |
michael@0 | 72 | req.onerror = onFailure; |
michael@0 | 73 | }, |
michael@0 | 74 | function () { |
michael@0 | 75 | ok(true, "Searching contacts by query2"); |
michael@0 | 76 | var options = {filterBy: ["givenName", "email"], |
michael@0 | 77 | filterOp: "startsWith", |
michael@0 | 78 | filterValue: properties2.givenName[0].substring(0, 4)}; |
michael@0 | 79 | req = mozContacts.find(options); |
michael@0 | 80 | req.onsuccess = function () { |
michael@0 | 81 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 82 | findResult1 = req.result[0]; |
michael@0 | 83 | is(findResult1.adr.length, 2, "Adr length 2"); |
michael@0 | 84 | checkContacts(findResult1, createResult2); |
michael@0 | 85 | next(); |
michael@0 | 86 | } |
michael@0 | 87 | req.onerror = onFailure; |
michael@0 | 88 | }, |
michael@0 | 89 | function () { |
michael@0 | 90 | ok(true, "Searching contacts by tel"); |
michael@0 | 91 | var options = {filterBy: ["tel"], |
michael@0 | 92 | filterOp: "contains", |
michael@0 | 93 | filterValue: properties2.tel[0].value.substring(3, 7)}; |
michael@0 | 94 | req = mozContacts.find(options); |
michael@0 | 95 | req.onsuccess = function () { |
michael@0 | 96 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 97 | findResult1 = req.result[0]; |
michael@0 | 98 | ok(findResult1.id == sample_id2, "Same ID"); |
michael@0 | 99 | checkContacts(findResult1, createResult2); |
michael@0 | 100 | next(); |
michael@0 | 101 | } |
michael@0 | 102 | req.onerror = onFailure; |
michael@0 | 103 | }, |
michael@0 | 104 | function () { |
michael@0 | 105 | ok(true, "Searching contacts by email"); |
michael@0 | 106 | var options = {filterBy: ["email"], |
michael@0 | 107 | filterOp: "startsWith", |
michael@0 | 108 | filterValue: properties2.email[0].value.substring(0, 4)}; |
michael@0 | 109 | req = mozContacts.find(options); |
michael@0 | 110 | req.onsuccess = function () { |
michael@0 | 111 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 112 | findResult1 = req.result[0]; |
michael@0 | 113 | ok(findResult1.id == sample_id2, "Same ID"); |
michael@0 | 114 | checkContacts(findResult1, createResult2); |
michael@0 | 115 | next(); |
michael@0 | 116 | } |
michael@0 | 117 | req.onerror = onFailure; |
michael@0 | 118 | }, |
michael@0 | 119 | function () { |
michael@0 | 120 | ok(true, "Deleting database"); |
michael@0 | 121 | req = mozContacts.clear(); |
michael@0 | 122 | req.onsuccess = function () { |
michael@0 | 123 | next(); |
michael@0 | 124 | } |
michael@0 | 125 | req.onerror = onFailure; |
michael@0 | 126 | }, |
michael@0 | 127 | function () { |
michael@0 | 128 | ok(true, "Adding 20 contacts"); |
michael@0 | 129 | for (var i=0; i<19; i++) { |
michael@0 | 130 | createResult1 = new mozContact(properties1); |
michael@0 | 131 | req = mozContacts.save(createResult1); |
michael@0 | 132 | req.onsuccess = function () { |
michael@0 | 133 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 134 | }; |
michael@0 | 135 | req.onerror = onFailure; |
michael@0 | 136 | }; |
michael@0 | 137 | createResult1 = new mozContact(properties1); |
michael@0 | 138 | req = mozContacts.save(createResult1); |
michael@0 | 139 | req.onsuccess = function () { |
michael@0 | 140 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 141 | checkStrArray(createResult1.name, properties1.name, "Same Name"); |
michael@0 | 142 | checkCount(20, "20 contacts in DB", next); |
michael@0 | 143 | }; |
michael@0 | 144 | req.onerror = onFailure; |
michael@0 | 145 | }, |
michael@0 | 146 | function () { |
michael@0 | 147 | ok(true, "Retrieving all contacts"); |
michael@0 | 148 | req = mozContacts.find(defaultOptions); |
michael@0 | 149 | req.onsuccess = function () { |
michael@0 | 150 | is(req.result.length, 20, "20 Entries."); |
michael@0 | 151 | next(); |
michael@0 | 152 | } |
michael@0 | 153 | req.onerror = onFailure; |
michael@0 | 154 | }, |
michael@0 | 155 | function () { |
michael@0 | 156 | ok(true, "Retrieving all contacts with limit 10"); |
michael@0 | 157 | var options = { filterLimit: 10 }; |
michael@0 | 158 | req = mozContacts.find(options); |
michael@0 | 159 | req.onsuccess = function () { |
michael@0 | 160 | is(req.result.length, 10, "10 Entries."); |
michael@0 | 161 | next(); |
michael@0 | 162 | } |
michael@0 | 163 | req.onerror = onFailure; |
michael@0 | 164 | }, |
michael@0 | 165 | function () { |
michael@0 | 166 | ok(true, "Retrieving all contacts with limit 10 and sorted"); |
michael@0 | 167 | var options = { filterLimit: 10, |
michael@0 | 168 | sortBy: 'FamilyName', |
michael@0 | 169 | sortOrder: 'descending' }; |
michael@0 | 170 | req = mozContacts.find(options); |
michael@0 | 171 | req.onsuccess = function () { |
michael@0 | 172 | is(req.result.length, 10, "10 Entries."); |
michael@0 | 173 | next(); |
michael@0 | 174 | } |
michael@0 | 175 | req.onerror = onFailure; |
michael@0 | 176 | }, |
michael@0 | 177 | function () { |
michael@0 | 178 | ok(true, "Retrieving all contacts2"); |
michael@0 | 179 | var options = {filterBy: ["givenName"], |
michael@0 | 180 | filterOp: "startsWith", |
michael@0 | 181 | filterValue: properties1.givenName[0].substring(0, 4)}; |
michael@0 | 182 | req = mozContacts.find(options); |
michael@0 | 183 | req.onsuccess = function () { |
michael@0 | 184 | is(req.result.length, 20, "20 Entries."); |
michael@0 | 185 | checkContacts(createResult1, req.result[19]); |
michael@0 | 186 | next(); |
michael@0 | 187 | } |
michael@0 | 188 | req.onerror = onFailure; |
michael@0 | 189 | }, |
michael@0 | 190 | function () { |
michael@0 | 191 | ok(true, "Retrieving all contacts3"); |
michael@0 | 192 | var options = {filterBy: ["givenName", "tel", "email"], |
michael@0 | 193 | filterOp: "startsWith", |
michael@0 | 194 | filterValue: properties1.givenName[0].substring(0, 4)}; |
michael@0 | 195 | req = mozContacts.find(options); |
michael@0 | 196 | req.onsuccess = function () { |
michael@0 | 197 | is(req.result.length, 20, "20 Entries."); |
michael@0 | 198 | checkContacts(createResult1, req.result[10]); |
michael@0 | 199 | next(); |
michael@0 | 200 | } |
michael@0 | 201 | req.onerror = onFailure; |
michael@0 | 202 | }, |
michael@0 | 203 | function () { |
michael@0 | 204 | ok(true, "Deleting database"); |
michael@0 | 205 | req = mozContacts.clear(); |
michael@0 | 206 | req.onsuccess = function () { |
michael@0 | 207 | next(); |
michael@0 | 208 | } |
michael@0 | 209 | req.onerror = onFailure; |
michael@0 | 210 | }, |
michael@0 | 211 | function () { |
michael@0 | 212 | ok(true, "Testing clone contact"); |
michael@0 | 213 | createResult1 = new mozContact(properties1); |
michael@0 | 214 | req = mozContacts.save(createResult1); |
michael@0 | 215 | req.onsuccess = function () { |
michael@0 | 216 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 217 | checkStrArray(createResult1.name, properties1.name, "Same Name"); |
michael@0 | 218 | next(); |
michael@0 | 219 | } |
michael@0 | 220 | req.onerror = onFailure; |
michael@0 | 221 | }, |
michael@0 | 222 | function() { |
michael@0 | 223 | ok(true, "Testing clone contact2"); |
michael@0 | 224 | var cloned = new mozContact(createResult1); |
michael@0 | 225 | ok(cloned.id != createResult1.id, "Cloned contact has new ID"); |
michael@0 | 226 | cloned.email = [{value: "new email!"}]; |
michael@0 | 227 | cloned.givenName = ["Tom"]; |
michael@0 | 228 | req = mozContacts.save(cloned); |
michael@0 | 229 | req.onsuccess = function () { |
michael@0 | 230 | ok(cloned.id, "The contact now has an ID."); |
michael@0 | 231 | is(cloned.email[0].value, "new email!", "Same Email"); |
michael@0 | 232 | isnot(createResult1.email[0].value, cloned.email[0].value, "Clone has different email"); |
michael@0 | 233 | is(cloned.givenName, "Tom", "New Name"); |
michael@0 | 234 | next(); |
michael@0 | 235 | } |
michael@0 | 236 | req.onerror = onFailure; |
michael@0 | 237 | }, |
michael@0 | 238 | function () { |
michael@0 | 239 | ok(true, "Retrieving all contacts"); |
michael@0 | 240 | var options = {filterBy: ["givenName"], |
michael@0 | 241 | filterOp: "startsWith", |
michael@0 | 242 | filterValue: properties2.givenName[0].substring(0, 4)}; |
michael@0 | 243 | req = mozContacts.find(defaultOptions); |
michael@0 | 244 | req.onsuccess = function () { |
michael@0 | 245 | is(req.result.length, 2, "2 Entries."); |
michael@0 | 246 | next(); |
michael@0 | 247 | } |
michael@0 | 248 | req.onerror = onFailure; |
michael@0 | 249 | }, |
michael@0 | 250 | function () { |
michael@0 | 251 | ok(true, "Search with redundant fields should only return 1 contact"); |
michael@0 | 252 | createResult1 = new mozContact({name: ["XXX"], |
michael@0 | 253 | givenName: ["XXX"], |
michael@0 | 254 | email: [{value: "XXX"}], |
michael@0 | 255 | tel: [{value: "XXX"}] |
michael@0 | 256 | }); |
michael@0 | 257 | req = mozContacts.save(createResult1); |
michael@0 | 258 | req.onsuccess = function() { |
michael@0 | 259 | var options = {filterBy: ["givenName", "familyName"], |
michael@0 | 260 | filterOp: "equals", |
michael@0 | 261 | filterValue: "XXX"}; |
michael@0 | 262 | var req2 = mozContacts.find(options); |
michael@0 | 263 | req2.onsuccess = function() { |
michael@0 | 264 | is(req2.result.length, 1, "1 Entry"); |
michael@0 | 265 | next(); |
michael@0 | 266 | } |
michael@0 | 267 | req2.onerror = onFailure; |
michael@0 | 268 | } |
michael@0 | 269 | req.onerror = onFailure; |
michael@0 | 270 | }, |
michael@0 | 271 | function () { |
michael@0 | 272 | ok(true, "Deleting database"); |
michael@0 | 273 | req = mozContacts.clear() |
michael@0 | 274 | req.onsuccess = function () { |
michael@0 | 275 | ok(true, "Deleted the database"); |
michael@0 | 276 | next(); |
michael@0 | 277 | } |
michael@0 | 278 | req.onerror = onFailure; |
michael@0 | 279 | }, |
michael@0 | 280 | function () { |
michael@0 | 281 | ok(true, "Test sorting"); |
michael@0 | 282 | createResult1 = new mozContact(c3); |
michael@0 | 283 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 284 | req.onsuccess = function () { |
michael@0 | 285 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 286 | checkContacts(c3, createResult1); |
michael@0 | 287 | next(); |
michael@0 | 288 | }; |
michael@0 | 289 | req.onerror = onFailure; |
michael@0 | 290 | }, |
michael@0 | 291 | function () { |
michael@0 | 292 | ok(true, "Test sorting"); |
michael@0 | 293 | createResult1 = new mozContact(c2); |
michael@0 | 294 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 295 | req.onsuccess = function () { |
michael@0 | 296 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 297 | checkContacts(c2, createResult1); |
michael@0 | 298 | next(); |
michael@0 | 299 | }; |
michael@0 | 300 | req.onerror = onFailure; |
michael@0 | 301 | }, |
michael@0 | 302 | function () { |
michael@0 | 303 | ok(true, "Test sorting"); |
michael@0 | 304 | createResult1 = new mozContact(c4); |
michael@0 | 305 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 306 | req.onsuccess = function () { |
michael@0 | 307 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 308 | checkContacts(c4, createResult1); |
michael@0 | 309 | next(); |
michael@0 | 310 | }; |
michael@0 | 311 | req.onerror = onFailure; |
michael@0 | 312 | }, |
michael@0 | 313 | function () { |
michael@0 | 314 | ok(true, "Test sorting"); |
michael@0 | 315 | createResult1 = new mozContact(c1); |
michael@0 | 316 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 317 | req.onsuccess = function () { |
michael@0 | 318 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 319 | checkContacts(c1, createResult1); |
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, "Test sorting"); |
michael@0 | 326 | var options = {sortBy: "familyName", |
michael@0 | 327 | sortOrder: "ascending"}; |
michael@0 | 328 | req = navigator.mozContacts.find(options); |
michael@0 | 329 | req.onsuccess = function () { |
michael@0 | 330 | is(req.result.length, 4, "4 results"); |
michael@0 | 331 | checkContacts(req.result[0], c1); |
michael@0 | 332 | checkContacts(req.result[1], c2); |
michael@0 | 333 | checkContacts(req.result[2], c3); |
michael@0 | 334 | checkContacts(req.result[3], c4); |
michael@0 | 335 | next(); |
michael@0 | 336 | }; |
michael@0 | 337 | req.onerror = onFailure; |
michael@0 | 338 | }, |
michael@0 | 339 | function () { |
michael@0 | 340 | ok(true, "Test sorting"); |
michael@0 | 341 | var options = {sortBy: "familyName", |
michael@0 | 342 | sortOrder: "descending"}; |
michael@0 | 343 | req = navigator.mozContacts.find(options); |
michael@0 | 344 | req.onsuccess = function () { |
michael@0 | 345 | is(req.result.length, 4, "4 results"); |
michael@0 | 346 | checkContacts(req.result[0], c4); |
michael@0 | 347 | checkContacts(req.result[1], c3); |
michael@0 | 348 | checkContacts(req.result[2], c2); |
michael@0 | 349 | checkContacts(req.result[3], c1); |
michael@0 | 350 | next(); |
michael@0 | 351 | }; |
michael@0 | 352 | req.onerror = onFailure; |
michael@0 | 353 | }, |
michael@0 | 354 | function () { |
michael@0 | 355 | ok(true, "Test sorting"); |
michael@0 | 356 | createResult1 = new mozContact(c5); |
michael@0 | 357 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 358 | req.onsuccess = function () { |
michael@0 | 359 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 360 | checkContacts(c5, createResult1); |
michael@0 | 361 | next(); |
michael@0 | 362 | }; |
michael@0 | 363 | req.onerror = onFailure; |
michael@0 | 364 | }, |
michael@0 | 365 | function () { |
michael@0 | 366 | ok(true, "Test sorting with empty string"); |
michael@0 | 367 | var options = {sortBy: "familyName", |
michael@0 | 368 | sortOrder: "ascending"}; |
michael@0 | 369 | req = navigator.mozContacts.find(options); |
michael@0 | 370 | req.onsuccess = function () { |
michael@0 | 371 | is(req.result.length, 5, "5 results"); |
michael@0 | 372 | checkContacts(req.result[0], c5); |
michael@0 | 373 | checkContacts(req.result[1], c1); |
michael@0 | 374 | checkContacts(req.result[2], c2); |
michael@0 | 375 | checkContacts(req.result[3], c3); |
michael@0 | 376 | checkContacts(req.result[4], c4); |
michael@0 | 377 | next(); |
michael@0 | 378 | }; |
michael@0 | 379 | req.onerror = onFailure; |
michael@0 | 380 | }, |
michael@0 | 381 | function () { |
michael@0 | 382 | ok(true, "Don't allow to add custom fields"); |
michael@0 | 383 | createResult1 = new mozContact({givenName: ["customTest"], yyy: "XXX"}); |
michael@0 | 384 | req = mozContacts.save(createResult1); |
michael@0 | 385 | req.onsuccess = function() { |
michael@0 | 386 | var options = {filterBy: ["givenName"], |
michael@0 | 387 | filterOp: "equals", |
michael@0 | 388 | filterValue: "customTest"}; |
michael@0 | 389 | var req2 = mozContacts.find(options); |
michael@0 | 390 | req2.onsuccess = function() { |
michael@0 | 391 | is(req2.result.length, 1, "1 Entry"); |
michael@0 | 392 | checkStrArray(req2.result[0].givenName, ["customTest"], "same name"); |
michael@0 | 393 | ok(req2.result.yyy === undefined, "custom property undefined"); |
michael@0 | 394 | next(); |
michael@0 | 395 | } |
michael@0 | 396 | req2.onerror = onFailure; |
michael@0 | 397 | } |
michael@0 | 398 | req.onerror = onFailure; |
michael@0 | 399 | }, |
michael@0 | 400 | function () { |
michael@0 | 401 | ok(true, "Deleting database"); |
michael@0 | 402 | req = mozContacts.clear() |
michael@0 | 403 | req.onsuccess = function () { |
michael@0 | 404 | ok(true, "Deleted the database"); |
michael@0 | 405 | next(); |
michael@0 | 406 | } |
michael@0 | 407 | req.onerror = onFailure; |
michael@0 | 408 | }, |
michael@0 | 409 | function () { |
michael@0 | 410 | ok(true, "Test sorting"); |
michael@0 | 411 | createResult1 = new mozContact(c7); |
michael@0 | 412 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 413 | req.onsuccess = function () { |
michael@0 | 414 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 415 | checkContacts(c7, createResult1); |
michael@0 | 416 | next(); |
michael@0 | 417 | }; |
michael@0 | 418 | req.onerror = onFailure; |
michael@0 | 419 | }, |
michael@0 | 420 | function () { |
michael@0 | 421 | ok(true, "Test sorting"); |
michael@0 | 422 | createResult1 = new mozContact(c6); |
michael@0 | 423 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 424 | req.onsuccess = function () { |
michael@0 | 425 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 426 | checkContacts(c6, createResult1); |
michael@0 | 427 | next(); |
michael@0 | 428 | }; |
michael@0 | 429 | req.onerror = onFailure; |
michael@0 | 430 | }, |
michael@0 | 431 | function () { |
michael@0 | 432 | ok(true, "Test sorting"); |
michael@0 | 433 | createResult1 = new mozContact(c8); |
michael@0 | 434 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 435 | req.onsuccess = function () { |
michael@0 | 436 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 437 | checkContacts(c8, createResult1); |
michael@0 | 438 | next(); |
michael@0 | 439 | }; |
michael@0 | 440 | req.onerror = onFailure; |
michael@0 | 441 | }, |
michael@0 | 442 | function () { |
michael@0 | 443 | // Android does not support published/updated fields. Skip this. |
michael@0 | 444 | if (isAndroid) { |
michael@0 | 445 | next(); |
michael@0 | 446 | return; |
michael@0 | 447 | } |
michael@0 | 448 | |
michael@0 | 449 | ok(true, "Test sorting with published"); |
michael@0 | 450 | var options = {sortBy: "familyName", |
michael@0 | 451 | sortOrder: "descending"}; |
michael@0 | 452 | req = navigator.mozContacts.find(options); |
michael@0 | 453 | req.onsuccess = function () { |
michael@0 | 454 | is(req.result.length, 3, "3 results"); |
michael@0 | 455 | ok(req.result[0].published < req.result[1].published, "Right sorting order"); |
michael@0 | 456 | ok(req.result[1].published < req.result[2].published, "Right sorting order"); |
michael@0 | 457 | next(); |
michael@0 | 458 | }; |
michael@0 | 459 | req.onerror = onFailure; |
michael@0 | 460 | }, |
michael@0 | 461 | function () { |
michael@0 | 462 | ok(true, "Deleting database"); |
michael@0 | 463 | req = mozContacts.clear(); |
michael@0 | 464 | req.onsuccess = function () { |
michael@0 | 465 | ok(true, "Deleted the database"); |
michael@0 | 466 | next(); |
michael@0 | 467 | } |
michael@0 | 468 | req.onerror = onFailure; |
michael@0 | 469 | }, |
michael@0 | 470 | function () { |
michael@0 | 471 | ok(true, "Adding a new contact with properties2"); |
michael@0 | 472 | createResult2 = new mozContact(properties2); |
michael@0 | 473 | req = mozContacts.save(createResult2); |
michael@0 | 474 | req.onsuccess = function () { |
michael@0 | 475 | ok(createResult2.id, "The contact now has an ID."); |
michael@0 | 476 | sample_id2 = createResult2.id; |
michael@0 | 477 | next(); |
michael@0 | 478 | }; |
michael@0 | 479 | req.onerror = onFailure; |
michael@0 | 480 | }, |
michael@0 | 481 | function () { |
michael@0 | 482 | ok(true, "Test category search with startsWith"); |
michael@0 | 483 | var options = {filterBy: ["category"], |
michael@0 | 484 | filterOp: "startsWith", |
michael@0 | 485 | filterValue: properties2.category[0]}; |
michael@0 | 486 | req = mozContacts.find(options); |
michael@0 | 487 | req.onsuccess = function () { |
michael@0 | 488 | is(req.result.length, 1, "1 Entry."); |
michael@0 | 489 | checkContacts(req.result[0], createResult2); |
michael@0 | 490 | next(); |
michael@0 | 491 | } |
michael@0 | 492 | req.onerror = onFailure; |
michael@0 | 493 | }, |
michael@0 | 494 | function () { |
michael@0 | 495 | ok(true, "Test category search with equals"); |
michael@0 | 496 | var options = {filterBy: ["category"], |
michael@0 | 497 | filterOp: "equals", |
michael@0 | 498 | filterValue: properties2.category[0]}; |
michael@0 | 499 | req = mozContacts.find(options); |
michael@0 | 500 | req.onsuccess = function () { |
michael@0 | 501 | is(req.result.length, 1, "1 Entry."); |
michael@0 | 502 | checkContacts(req.result[0], createResult2); |
michael@0 | 503 | next(); |
michael@0 | 504 | } |
michael@0 | 505 | req.onerror = onFailure; |
michael@0 | 506 | }, |
michael@0 | 507 | function () { |
michael@0 | 508 | ok(true, "Deleting database"); |
michael@0 | 509 | req = mozContacts.clear() |
michael@0 | 510 | req.onsuccess = function () { |
michael@0 | 511 | ok(true, "Deleted the database"); |
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, "Adding contact for category search"); |
michael@0 | 518 | createResult1 = new mozContact({name: ["5"], givenName: ["5"]}); |
michael@0 | 519 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 520 | req.onsuccess = function () { |
michael@0 | 521 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 522 | sample_id1 = createResult1.id; |
michael@0 | 523 | next(); |
michael@0 | 524 | }; |
michael@0 | 525 | req.onerror = onFailure; |
michael@0 | 526 | }, |
michael@0 | 527 | function () { |
michael@0 | 528 | ok(true, "Test category search with equals"); |
michael@0 | 529 | var options = {filterBy: ["givenName"], |
michael@0 | 530 | filterOp: "startsWith", |
michael@0 | 531 | filterValue: "5"}; |
michael@0 | 532 | req = mozContacts.find(options); |
michael@0 | 533 | req.onsuccess = function () { |
michael@0 | 534 | is(req.result.length, 1, "1 Entry."); |
michael@0 | 535 | checkContacts(req.result[0], createResult1); |
michael@0 | 536 | next(); |
michael@0 | 537 | } |
michael@0 | 538 | req.onerror = onFailure; |
michael@0 | 539 | }, |
michael@0 | 540 | function () { |
michael@0 | 541 | ok(true, "Deleting database"); |
michael@0 | 542 | req = mozContacts.clear() |
michael@0 | 543 | req.onsuccess = function () { |
michael@0 | 544 | ok(true, "Deleted the database"); |
michael@0 | 545 | next(); |
michael@0 | 546 | } |
michael@0 | 547 | req.onerror = onFailure; |
michael@0 | 548 | }, |
michael@0 | 549 | function () { |
michael@0 | 550 | ok(true, "Adding contact with invalid data"); |
michael@0 | 551 | var obj = { |
michael@0 | 552 | honorificPrefix: [], |
michael@0 | 553 | honorificSuffix: [{foo: "bar"}], |
michael@0 | 554 | sex: 17, |
michael@0 | 555 | genderIdentity: 18, |
michael@0 | 556 | email: [{type: ["foo"], value: "bar"}] |
michael@0 | 557 | }; |
michael@0 | 558 | obj.honorificPrefix.__defineGetter__('0',(function() { |
michael@0 | 559 | var c = 0; |
michael@0 | 560 | return function() { |
michael@0 | 561 | if (c == 0) { |
michael@0 | 562 | c++; |
michael@0 | 563 | return "string"; |
michael@0 | 564 | } else { |
michael@0 | 565 | return {foo:"bar"}; |
michael@0 | 566 | } |
michael@0 | 567 | } |
michael@0 | 568 | })()); |
michael@0 | 569 | createResult1 = new mozContact(obj); |
michael@0 | 570 | createResult1.email.push({aeiou: "abcde"}); |
michael@0 | 571 | req = mozContacts.save(createResult1); |
michael@0 | 572 | req.onsuccess = function () { |
michael@0 | 573 | checkContacts(createResult1, { |
michael@0 | 574 | honorificPrefix: ["string"], |
michael@0 | 575 | honorificSuffix: ["[object Object]"], |
michael@0 | 576 | sex: "17", |
michael@0 | 577 | genderIdentity: "18", |
michael@0 | 578 | email: [{type: ["foo"], value: "bar"}, {}] |
michael@0 | 579 | }); |
michael@0 | 580 | next(); |
michael@0 | 581 | }; |
michael@0 | 582 | }, |
michael@0 | 583 | function () { |
michael@0 | 584 | ok(true, "Adding contact with no number but carrier"); |
michael@0 | 585 | createResult1 = new mozContact({ tel: [{type: ["home"], carrier: "myCarrier"} ] }); |
michael@0 | 586 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 587 | req.onsuccess = function () { |
michael@0 | 588 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 589 | next(); |
michael@0 | 590 | }; |
michael@0 | 591 | req.onerror = onFailure; |
michael@0 | 592 | }, |
michael@0 | 593 | function () { |
michael@0 | 594 | ok(true, "Adding contact with email but no value"); |
michael@0 | 595 | createResult1 = new mozContact({ email: [{type: ["home"]}] }); |
michael@0 | 596 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 597 | req.onsuccess = function () { |
michael@0 | 598 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 599 | next(); |
michael@0 | 600 | }; |
michael@0 | 601 | req.onerror = onFailure; |
michael@0 | 602 | }, |
michael@0 | 603 | function () { |
michael@0 | 604 | ok(true, "Testing numbersOnly search 1"); |
michael@0 | 605 | createResult1 = new mozContact({ name: ["aaaaaaaaa"], givenName: ["aaaaaaaaa"], tel: [{ value: "1234567890"}]}); |
michael@0 | 606 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 607 | req.onsuccess = function () { |
michael@0 | 608 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 609 | next(); |
michael@0 | 610 | }; |
michael@0 | 611 | req.onerror = onFailure; |
michael@0 | 612 | }, |
michael@0 | 613 | function () { |
michael@0 | 614 | ok(true, "Test numbersOnly search 2"); |
michael@0 | 615 | var options = {filterBy: ["givenName", "tel"], |
michael@0 | 616 | filterOp: "contains", |
michael@0 | 617 | filterValue: "a"}; |
michael@0 | 618 | req = mozContacts.find(options); |
michael@0 | 619 | req.onsuccess = function () { |
michael@0 | 620 | ok(req.result.length == 1, "1 Entry."); |
michael@0 | 621 | checkContacts(req.result[0], createResult1); |
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, "Test numbersOnly search 3"); |
michael@0 | 628 | var options = {filterBy: ["givenName", "tel"], |
michael@0 | 629 | filterOp: "contains", |
michael@0 | 630 | filterValue: "b"}; |
michael@0 | 631 | req = mozContacts.find(options); |
michael@0 | 632 | req.onsuccess = function () { |
michael@0 | 633 | ok(req.result.length == 0, "0 Entries."); |
michael@0 | 634 | next(); |
michael@0 | 635 | } |
michael@0 | 636 | req.onerror = onFailure; |
michael@0 | 637 | }, |
michael@0 | 638 | function () { |
michael@0 | 639 | ok(true, "Test numbersOnly search 4"); |
michael@0 | 640 | var options = {filterBy: ["givenName", "tel"], |
michael@0 | 641 | filterOp: "contains", |
michael@0 | 642 | filterValue: "1a"}; |
michael@0 | 643 | req = mozContacts.find(options); |
michael@0 | 644 | req.onsuccess = function () { |
michael@0 | 645 | ok(req.result.length == 0, "0 Entries."); |
michael@0 | 646 | next(); |
michael@0 | 647 | } |
michael@0 | 648 | req.onerror = onFailure; |
michael@0 | 649 | }, |
michael@0 | 650 | function () { |
michael@0 | 651 | ok(true, "Test numbersOnly search 5"); |
michael@0 | 652 | var options = {filterBy: ["givenName", "tel"], |
michael@0 | 653 | filterOp: "contains", |
michael@0 | 654 | filterValue: "1(23)"}; |
michael@0 | 655 | req = mozContacts.find(options); |
michael@0 | 656 | req.onsuccess = function () { |
michael@0 | 657 | ok(req.result.length == 1, "1 Entry."); |
michael@0 | 658 | next(); |
michael@0 | 659 | } |
michael@0 | 660 | req.onerror = onFailure; |
michael@0 | 661 | }, |
michael@0 | 662 | function () { |
michael@0 | 663 | ok(true, "Test numbersOnly search 6"); |
michael@0 | 664 | var options = {filterBy: ["givenName", "tel"], |
michael@0 | 665 | filterOp: "contains", |
michael@0 | 666 | filterValue: "1(23)a"}; |
michael@0 | 667 | req = mozContacts.find(options); |
michael@0 | 668 | req.onsuccess = function () { |
michael@0 | 669 | ok(req.result.length == 0, "0 Entries."); |
michael@0 | 670 | next(); |
michael@0 | 671 | } |
michael@0 | 672 | req.onerror = onFailure; |
michael@0 | 673 | }, |
michael@0 | 674 | function () { |
michael@0 | 675 | ok(true, "Deleting database"); |
michael@0 | 676 | req = mozContacts.clear() |
michael@0 | 677 | req.onsuccess = function () { |
michael@0 | 678 | ok(true, "Deleted the database"); |
michael@0 | 679 | next(); |
michael@0 | 680 | } |
michael@0 | 681 | req.onerror = onFailure; |
michael@0 | 682 | }, |
michael@0 | 683 | function() { |
michael@0 | 684 | ok(true, "Test that after setting array properties to scalar values the property os not a non-array") |
michael@0 | 685 | const FIELDS = ["email","url","adr","tel","impp"]; |
michael@0 | 686 | createResult1 = new mozContact(); |
michael@0 | 687 | for (var prop of FIELDS) { |
michael@0 | 688 | try { |
michael@0 | 689 | createResult1[prop] = {type: ["foo"]}; |
michael@0 | 690 | } catch (e) {} |
michael@0 | 691 | ok(createResult1[prop] === null || |
michael@0 | 692 | Array.isArray(createResult1[prop]), prop + " is array"); |
michael@0 | 693 | } |
michael@0 | 694 | next(); |
michael@0 | 695 | }, |
michael@0 | 696 | function() { |
michael@0 | 697 | ok(true, "Undefined properties of fields should be treated correctly"); |
michael@0 | 698 | var c = new mozContact({ |
michael@0 | 699 | adr: [{streetAddress: undefined}], |
michael@0 | 700 | email: [{value: undefined}], |
michael@0 | 701 | url: [{value: undefined}], |
michael@0 | 702 | impp: [{value: undefined}], |
michael@0 | 703 | tel: [{value: undefined}], |
michael@0 | 704 | }); |
michael@0 | 705 | ise(c.adr[0].streetAddress, undefined, "adr.streetAddress is undefined"); |
michael@0 | 706 | ise(c.adr[0].locality, undefined, "adr.locality is undefined"); |
michael@0 | 707 | ise(c.adr[0].pref, undefined, "adr.pref is undefined"); |
michael@0 | 708 | ise(c.email[0].value, undefined, "email.value is undefined"); |
michael@0 | 709 | ise(c.url[0].value, undefined, "url.value is undefined"); |
michael@0 | 710 | ise(c.impp[0].value, undefined, "impp.value is undefined"); |
michael@0 | 711 | ise(c.tel[0].value, undefined, "tel.value is undefined"); |
michael@0 | 712 | next(); |
michael@0 | 713 | }, |
michael@0 | 714 | function() { |
michael@0 | 715 | ok(true, "Setting array properties to an empty array should work"); |
michael@0 | 716 | var c = new mozContact(); |
michael@0 | 717 | function testArrayProp(prop) { |
michael@0 | 718 | is(c[prop], null, "property is initially null"); |
michael@0 | 719 | c[prop] = []; |
michael@0 | 720 | ok(Array.isArray(c[prop]), "property is an array after setting"); |
michael@0 | 721 | is(c[prop].length, 0, "property has length 0 after setting"); |
michael@0 | 722 | } |
michael@0 | 723 | testArrayProp("email"); |
michael@0 | 724 | testArrayProp("adr"); |
michael@0 | 725 | testArrayProp("tel"); |
michael@0 | 726 | testArrayProp("impp"); |
michael@0 | 727 | testArrayProp("url"); |
michael@0 | 728 | next(); |
michael@0 | 729 | }, |
michael@0 | 730 | function() { |
michael@0 | 731 | ok(true, "Passing a mozContact with invalid data to save() should throw"); |
michael@0 | 732 | var c = new mozContact({ |
michael@0 | 733 | photo: [], |
michael@0 | 734 | tel: [] |
michael@0 | 735 | }); |
michael@0 | 736 | c.photo.push({}); |
michael@0 | 737 | SimpleTest.doesThrow(()=>navigator.mozContacts.save(c), "Invalid data in Blob array"); |
michael@0 | 738 | c.tel.push(123); |
michael@0 | 739 | SimpleTest.doesThrow(()=>navigator.mozContacts.save(c), "Invalid data in dictionary array"); |
michael@0 | 740 | next(); |
michael@0 | 741 | }, |
michael@0 | 742 | function() { |
michael@0 | 743 | ok(true, "Inline changes to array properties should be seen by save"); |
michael@0 | 744 | var c = new mozContact({ |
michael@0 | 745 | name: [], |
michael@0 | 746 | familyName: [], |
michael@0 | 747 | givenName: [], |
michael@0 | 748 | phoneticFamilyName: [], |
michael@0 | 749 | phoneticGivenName: [], |
michael@0 | 750 | nickname: [], |
michael@0 | 751 | tel: [], |
michael@0 | 752 | adr: [], |
michael@0 | 753 | email: [] |
michael@0 | 754 | }); |
michael@0 | 755 | for (var prop of Object.getOwnPropertyNames(properties1)) { |
michael@0 | 756 | if (!Array.isArray(properties1[prop])) { |
michael@0 | 757 | continue; |
michael@0 | 758 | } |
michael@0 | 759 | for (var i = 0; i < properties1[prop].length; ++i) { |
michael@0 | 760 | c[prop].push(properties1[prop][i]); |
michael@0 | 761 | } |
michael@0 | 762 | } |
michael@0 | 763 | req = navigator.mozContacts.save(c); |
michael@0 | 764 | req.onsuccess = function() { |
michael@0 | 765 | req = navigator.mozContacts.find(defaultOptions); |
michael@0 | 766 | req.onsuccess = function() { |
michael@0 | 767 | ise(req.result.length, 1, "Got 1 contact"); |
michael@0 | 768 | checkContacts(req.result[0], properties1); |
michael@0 | 769 | next(); |
michael@0 | 770 | }; |
michael@0 | 771 | req.onerror = onFailure; |
michael@0 | 772 | }; |
michael@0 | 773 | req.onerror = onFailure; |
michael@0 | 774 | }, |
michael@0 | 775 | clearDatabase, |
michael@0 | 776 | function() { |
michael@0 | 777 | ok(true, "mozContact.init deprecation message"); |
michael@0 | 778 | var c = new mozContact(); |
michael@0 | 779 | SimpleTest.monitorConsole(next, [ |
michael@0 | 780 | { errorMessage: "mozContact.init is DEPRECATED. Use the mozContact constructor instead. " + |
michael@0 | 781 | "See https://developer.mozilla.org/docs/WebAPI/Contacts for details." } |
michael@0 | 782 | ], /* forbidUnexpectedMsgs */ true); |
michael@0 | 783 | c.init({name: ["Bar"]}); |
michael@0 | 784 | c.init({name: ["Bar"]}); |
michael@0 | 785 | SimpleTest.endMonitorConsole(); |
michael@0 | 786 | }, |
michael@0 | 787 | function() { |
michael@0 | 788 | ok(true, "mozContact.init works as expected"); |
michael@0 | 789 | var c = new mozContact({name: ["Foo"]}); |
michael@0 | 790 | c.init({name: ["Bar"]}); |
michael@0 | 791 | ise(c.name[0], "Bar", "Same name"); |
michael@0 | 792 | next(); |
michael@0 | 793 | }, |
michael@0 | 794 | function() { |
michael@0 | 795 | ok(true, "mozContact.init without parameters"); |
michael@0 | 796 | var c = new mozContact({name: ["Foo"]}); |
michael@0 | 797 | c.init(); |
michael@0 | 798 | next(); |
michael@0 | 799 | }, |
michael@0 | 800 | function() { |
michael@0 | 801 | ok(true, "mozContact.init resets properties"); |
michael@0 | 802 | var c = new mozContact({jobTitle: ["Software Engineer"]}); |
michael@0 | 803 | c.init({nickname: ["Jobless Johnny"]}); |
michael@0 | 804 | ise(c.nickname[0], "Jobless Johnny", "Same nickname"); |
michael@0 | 805 | ok(!c.jobTitle, "jobTitle is not set"); |
michael@0 | 806 | next(); |
michael@0 | 807 | }, |
michael@0 | 808 | function() { |
michael@0 | 809 | ok(true, "mozContacts.remove with an ID works"); |
michael@0 | 810 | var c = new mozContact({name: ["Ephemeral Jimmy"]}); |
michael@0 | 811 | req = navigator.mozContacts.save(c); |
michael@0 | 812 | req.onsuccess = function() { |
michael@0 | 813 | req = navigator.mozContacts.remove(c.id); |
michael@0 | 814 | req.onsuccess = function() { |
michael@0 | 815 | req = navigator.mozContacts.find({ |
michael@0 | 816 | filterBy: ["id"], |
michael@0 | 817 | filterOp: "equals", |
michael@0 | 818 | filterValue: c.id |
michael@0 | 819 | }); |
michael@0 | 820 | req.onsuccess = function() { |
michael@0 | 821 | ise(req.result.length, 0, "Successfully removed contact by ID"); |
michael@0 | 822 | next(); |
michael@0 | 823 | }; |
michael@0 | 824 | req.onerror = onFailure; |
michael@0 | 825 | }; |
michael@0 | 826 | req.onerror = onFailure; |
michael@0 | 827 | }; |
michael@0 | 828 | req.onerror = onFailure; |
michael@0 | 829 | }, |
michael@0 | 830 | function () { |
michael@0 | 831 | ok(true, "Adding a new contact"); |
michael@0 | 832 | createResult1 = new mozContact(properties3); |
michael@0 | 833 | req = mozContacts.save(createResult1) |
michael@0 | 834 | req.onsuccess = function () { |
michael@0 | 835 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 836 | sample_id1 = createResult1.id; |
michael@0 | 837 | next(); |
michael@0 | 838 | } |
michael@0 | 839 | req.onerror = onFailure; |
michael@0 | 840 | }, |
michael@0 | 841 | function () { |
michael@0 | 842 | ok(true, "Adding a new contact2"); |
michael@0 | 843 | createResult2 = new mozContact(properties4); |
michael@0 | 844 | req = mozContacts.save(createResult2); |
michael@0 | 845 | req.onsuccess = function () { |
michael@0 | 846 | ok(createResult2.id, "The contact now has an ID."); |
michael@0 | 847 | sample_id2 = createResult2.id; |
michael@0 | 848 | next(); |
michael@0 | 849 | }; |
michael@0 | 850 | req.onerror = onFailure; |
michael@0 | 851 | }, |
michael@0 | 852 | function () { |
michael@0 | 853 | ok(true, "Retrieving all contacts"); |
michael@0 | 854 | req = mozContacts.find({sortBy: "phoneticFamilyName"}); |
michael@0 | 855 | req.onsuccess = function () { |
michael@0 | 856 | is(req.result.length, 2, "Found exactly 2 contact."); |
michael@0 | 857 | checkContacts(req.result[1], properties3); |
michael@0 | 858 | next(); |
michael@0 | 859 | } |
michael@0 | 860 | req.onerror = onFailure; |
michael@0 | 861 | }, |
michael@0 | 862 | function () { |
michael@0 | 863 | ok(true, "Searching contacts by query1"); |
michael@0 | 864 | var options = {filterBy: ["phoneticGivenName", "email"], |
michael@0 | 865 | filterOp: "startsWith", |
michael@0 | 866 | filterValue: properties3.phoneticGivenName[0].substring(0, 3)} |
michael@0 | 867 | req = mozContacts.find(options) |
michael@0 | 868 | req.onsuccess = function () { |
michael@0 | 869 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 870 | findResult1 = req.result[0]; |
michael@0 | 871 | ok(findResult1.id == sample_id1, "Same ID"); |
michael@0 | 872 | checkContacts(findResult1, createResult1); |
michael@0 | 873 | next(); |
michael@0 | 874 | } |
michael@0 | 875 | req.onerror = onFailure; |
michael@0 | 876 | }, |
michael@0 | 877 | function () { |
michael@0 | 878 | ok(true, "Searching contacts by query2"); |
michael@0 | 879 | var options = {filterBy: ["phoneticGivenName", "email"], |
michael@0 | 880 | filterOp: "startsWith", |
michael@0 | 881 | filterValue: properties4.phoneticGivenName[0].substring(0, 3)}; |
michael@0 | 882 | req = mozContacts.find(options); |
michael@0 | 883 | req.onsuccess = function () { |
michael@0 | 884 | is(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 885 | findResult1 = req.result[0]; |
michael@0 | 886 | is(findResult1.adr.length, 2, "Adr length 2"); |
michael@0 | 887 | checkContacts(findResult1, createResult2); |
michael@0 | 888 | next(); |
michael@0 | 889 | } |
michael@0 | 890 | req.onerror = onFailure; |
michael@0 | 891 | }, |
michael@0 | 892 | clearDatabase, |
michael@0 | 893 | function () { |
michael@0 | 894 | ok(true, "Adding 20 contacts"); |
michael@0 | 895 | for (var i=0; i<19; i++) { |
michael@0 | 896 | createResult1 = new mozContact(properties3); |
michael@0 | 897 | req = mozContacts.save(createResult1); |
michael@0 | 898 | req.onsuccess = function () { |
michael@0 | 899 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 900 | }; |
michael@0 | 901 | req.onerror = onFailure; |
michael@0 | 902 | }; |
michael@0 | 903 | createResult1 = new mozContact(properties3); |
michael@0 | 904 | req = mozContacts.save(createResult1); |
michael@0 | 905 | req.onsuccess = function () { |
michael@0 | 906 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 907 | checkStrArray(createResult1.name, properties3.name, "Same Name"); |
michael@0 | 908 | checkCount(20, "20 contacts in DB", next); |
michael@0 | 909 | }; |
michael@0 | 910 | req.onerror = onFailure; |
michael@0 | 911 | }, |
michael@0 | 912 | function () { |
michael@0 | 913 | ok(true, "Retrieving all contacts"); |
michael@0 | 914 | req = mozContacts.find(defaultOptions); |
michael@0 | 915 | req.onsuccess = function () { |
michael@0 | 916 | is(req.result.length, 20, "20 Entries."); |
michael@0 | 917 | next(); |
michael@0 | 918 | } |
michael@0 | 919 | req.onerror = onFailure; |
michael@0 | 920 | }, |
michael@0 | 921 | function () { |
michael@0 | 922 | ok(true, "Retrieving all contacts2"); |
michael@0 | 923 | var options = {filterBy: ["phoneticGivenName"], |
michael@0 | 924 | filterOp: "startsWith", |
michael@0 | 925 | filterValue: properties3.phoneticGivenName[0].substring(0, 3)}; |
michael@0 | 926 | req = mozContacts.find(options); |
michael@0 | 927 | req.onsuccess = function () { |
michael@0 | 928 | is(req.result.length, 20, "20 Entries."); |
michael@0 | 929 | checkContacts(createResult1, req.result[19]); |
michael@0 | 930 | next(); |
michael@0 | 931 | } |
michael@0 | 932 | req.onerror = onFailure; |
michael@0 | 933 | }, |
michael@0 | 934 | function () { |
michael@0 | 935 | ok(true, "Retrieving all contacts3"); |
michael@0 | 936 | var options = {filterBy: ["phoneticGivenName", "tel", "email"], |
michael@0 | 937 | filterOp: "startsWith", |
michael@0 | 938 | filterValue: properties3.phoneticGivenName[0].substring(0, 3)}; |
michael@0 | 939 | req = mozContacts.find(options); |
michael@0 | 940 | req.onsuccess = function () { |
michael@0 | 941 | is(req.result.length, 20, "20 Entries."); |
michael@0 | 942 | checkContacts(createResult1, req.result[10]); |
michael@0 | 943 | next(); |
michael@0 | 944 | } |
michael@0 | 945 | req.onerror = onFailure; |
michael@0 | 946 | }, |
michael@0 | 947 | clearDatabase, |
michael@0 | 948 | function () { |
michael@0 | 949 | ok(true, "Testing clone contact"); |
michael@0 | 950 | createResult1 = new mozContact(properties3); |
michael@0 | 951 | req = mozContacts.save(createResult1); |
michael@0 | 952 | req.onsuccess = function () { |
michael@0 | 953 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 954 | checkStrArray(createResult1.phoneticFamilyName, properties3.phoneticFamilyName, "Same phoneticFamilyName"); |
michael@0 | 955 | checkStrArray(createResult1.phoneticGivenName, properties3.phoneticGivenName, "Same phoneticGivenName"); |
michael@0 | 956 | next(); |
michael@0 | 957 | } |
michael@0 | 958 | req.onerror = onFailure; |
michael@0 | 959 | }, |
michael@0 | 960 | function () { |
michael@0 | 961 | ok(true, "Retrieving all contacts"); |
michael@0 | 962 | req = mozContacts.find({sortBy: "phoneticGivenName"}); |
michael@0 | 963 | req.onsuccess = function () { |
michael@0 | 964 | is(req.result.length, 1, "1 Entries."); |
michael@0 | 965 | next(); |
michael@0 | 966 | } |
michael@0 | 967 | req.onerror = onFailure; |
michael@0 | 968 | }, |
michael@0 | 969 | clearDatabase, |
michael@0 | 970 | function () { |
michael@0 | 971 | ok(true, "Test sorting"); |
michael@0 | 972 | createResult1 = new mozContact(c11); |
michael@0 | 973 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 974 | req.onsuccess = function () { |
michael@0 | 975 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 976 | checkContacts(c11, createResult1); |
michael@0 | 977 | next(); |
michael@0 | 978 | }; |
michael@0 | 979 | req.onerror = onFailure; |
michael@0 | 980 | }, |
michael@0 | 981 | function () { |
michael@0 | 982 | ok(true, "Test sorting"); |
michael@0 | 983 | createResult1 = new mozContact(c10); |
michael@0 | 984 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 985 | req.onsuccess = function () { |
michael@0 | 986 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 987 | checkContacts(c10, createResult1); |
michael@0 | 988 | next(); |
michael@0 | 989 | }; |
michael@0 | 990 | req.onerror = onFailure; |
michael@0 | 991 | }, |
michael@0 | 992 | function () { |
michael@0 | 993 | ok(true, "Test sorting"); |
michael@0 | 994 | createResult1 = new mozContact(c12); |
michael@0 | 995 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 996 | req.onsuccess = function () { |
michael@0 | 997 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 998 | checkContacts(c12, createResult1); |
michael@0 | 999 | next(); |
michael@0 | 1000 | }; |
michael@0 | 1001 | req.onerror = onFailure; |
michael@0 | 1002 | }, |
michael@0 | 1003 | function () { |
michael@0 | 1004 | ok(true, "Test sorting"); |
michael@0 | 1005 | createResult1 = new mozContact(c9); |
michael@0 | 1006 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 1007 | req.onsuccess = function () { |
michael@0 | 1008 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 1009 | checkContacts(c9, createResult1); |
michael@0 | 1010 | next(); |
michael@0 | 1011 | }; |
michael@0 | 1012 | req.onerror = onFailure; |
michael@0 | 1013 | }, |
michael@0 | 1014 | function () { |
michael@0 | 1015 | ok(true, "Test sorting"); |
michael@0 | 1016 | var options = {sortBy: "phoneticFamilyName", |
michael@0 | 1017 | sortOrder: "ascending"}; |
michael@0 | 1018 | req = navigator.mozContacts.find(options); |
michael@0 | 1019 | req.onsuccess = function () { |
michael@0 | 1020 | is(req.result.length, 4, "4 results"); |
michael@0 | 1021 | checkContacts(req.result[0], c9); |
michael@0 | 1022 | checkContacts(req.result[1], c10); |
michael@0 | 1023 | checkContacts(req.result[2], c11); |
michael@0 | 1024 | checkContacts(req.result[3], c12); |
michael@0 | 1025 | next(); |
michael@0 | 1026 | }; |
michael@0 | 1027 | req.onerror = onFailure; |
michael@0 | 1028 | }, |
michael@0 | 1029 | function () { |
michael@0 | 1030 | ok(true, "Test sorting"); |
michael@0 | 1031 | var options = {sortBy: "phoneticFamilyName", |
michael@0 | 1032 | sortOrder: "descending"}; |
michael@0 | 1033 | req = navigator.mozContacts.find(options); |
michael@0 | 1034 | req.onsuccess = function () { |
michael@0 | 1035 | is(req.result.length, 4, "4 results"); |
michael@0 | 1036 | checkContacts(req.result[0], c12); |
michael@0 | 1037 | checkContacts(req.result[1], c11); |
michael@0 | 1038 | checkContacts(req.result[2], c10); |
michael@0 | 1039 | checkContacts(req.result[3], c9); |
michael@0 | 1040 | next(); |
michael@0 | 1041 | }; |
michael@0 | 1042 | req.onerror = onFailure; |
michael@0 | 1043 | }, |
michael@0 | 1044 | function () { |
michael@0 | 1045 | ok(true, "Test sorting"); |
michael@0 | 1046 | createResult1 = new mozContact(c13); |
michael@0 | 1047 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 1048 | req.onsuccess = function () { |
michael@0 | 1049 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 1050 | checkContacts(c13, createResult1); |
michael@0 | 1051 | next(); |
michael@0 | 1052 | }; |
michael@0 | 1053 | req.onerror = onFailure; |
michael@0 | 1054 | }, |
michael@0 | 1055 | function () { |
michael@0 | 1056 | ok(true, "Test sorting with empty string"); |
michael@0 | 1057 | var options = {sortBy: "phoneticFamilyName", |
michael@0 | 1058 | sortOrder: "ascending"}; |
michael@0 | 1059 | req = navigator.mozContacts.find(options); |
michael@0 | 1060 | req.onsuccess = function () { |
michael@0 | 1061 | is(req.result.length, 5, "5 results"); |
michael@0 | 1062 | checkContacts(req.result[0], c13); |
michael@0 | 1063 | checkContacts(req.result[1], c9); |
michael@0 | 1064 | checkContacts(req.result[2], c10); |
michael@0 | 1065 | checkContacts(req.result[3], c11); |
michael@0 | 1066 | checkContacts(req.result[4], c12); |
michael@0 | 1067 | next(); |
michael@0 | 1068 | }; |
michael@0 | 1069 | req.onerror = onFailure; |
michael@0 | 1070 | }, |
michael@0 | 1071 | clearDatabase, |
michael@0 | 1072 | function () { |
michael@0 | 1073 | ok(true, "Test sorting"); |
michael@0 | 1074 | createResult1 = new mozContact(c15); |
michael@0 | 1075 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 1076 | req.onsuccess = function () { |
michael@0 | 1077 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 1078 | checkContacts(c15, createResult1); |
michael@0 | 1079 | next(); |
michael@0 | 1080 | }; |
michael@0 | 1081 | req.onerror = onFailure; |
michael@0 | 1082 | }, |
michael@0 | 1083 | function () { |
michael@0 | 1084 | ok(true, "Test sorting"); |
michael@0 | 1085 | createResult1 = new mozContact(c14); |
michael@0 | 1086 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 1087 | req.onsuccess = function () { |
michael@0 | 1088 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 1089 | checkContacts(c14, createResult1); |
michael@0 | 1090 | next(); |
michael@0 | 1091 | }; |
michael@0 | 1092 | req.onerror = onFailure; |
michael@0 | 1093 | }, |
michael@0 | 1094 | function () { |
michael@0 | 1095 | ok(true, "Test sorting"); |
michael@0 | 1096 | createResult1 = new mozContact(c16); |
michael@0 | 1097 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 1098 | req.onsuccess = function () { |
michael@0 | 1099 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 1100 | checkContacts(c16, createResult1); |
michael@0 | 1101 | next(); |
michael@0 | 1102 | }; |
michael@0 | 1103 | req.onerror = onFailure; |
michael@0 | 1104 | }, |
michael@0 | 1105 | function () { |
michael@0 | 1106 | // Android does not support published/updated fields. Skip this. |
michael@0 | 1107 | if (isAndroid) { |
michael@0 | 1108 | next(); |
michael@0 | 1109 | return; |
michael@0 | 1110 | } |
michael@0 | 1111 | |
michael@0 | 1112 | ok(true, "Test sorting with published"); |
michael@0 | 1113 | var options = {sortBy: "phoneticFamilyName", |
michael@0 | 1114 | sortOrder: "descending"}; |
michael@0 | 1115 | req = navigator.mozContacts.find(options); |
michael@0 | 1116 | req.onsuccess = function () { |
michael@0 | 1117 | is(req.result.length, 3, "3 results"); |
michael@0 | 1118 | ok(req.result[0].published < req.result[1].published, "Right sorting order"); |
michael@0 | 1119 | ok(req.result[1].published < req.result[2].published, "Right sorting order"); |
michael@0 | 1120 | next(); |
michael@0 | 1121 | }; |
michael@0 | 1122 | req.onerror = onFailure; |
michael@0 | 1123 | }, |
michael@0 | 1124 | clearDatabase, |
michael@0 | 1125 | function () { |
michael@0 | 1126 | ok(true, "all done!\n"); |
michael@0 | 1127 | SimpleTest.finish(); |
michael@0 | 1128 | } |
michael@0 | 1129 | ]; |
michael@0 | 1130 | |
michael@0 | 1131 | function next() { |
michael@0 | 1132 | ok(true, "Begin!"); |
michael@0 | 1133 | if (index >= steps.length) { |
michael@0 | 1134 | ok(false, "Shouldn't get here!"); |
michael@0 | 1135 | return; |
michael@0 | 1136 | } |
michael@0 | 1137 | try { |
michael@0 | 1138 | var i = index++; |
michael@0 | 1139 | steps[i](); |
michael@0 | 1140 | } catch(ex) { |
michael@0 | 1141 | ok(false, "Caught exception", ex); |
michael@0 | 1142 | } |
michael@0 | 1143 | } |
michael@0 | 1144 | |
michael@0 | 1145 | start_tests(); |
michael@0 | 1146 | </script> |
michael@0 | 1147 | </pre> |
michael@0 | 1148 | </body> |
michael@0 | 1149 | </html> |