mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 898337 - Split big test files in smaller files. r=gwagner, r=reuben
This commit is contained in:
parent
8de7ebd7ff
commit
51b2248e20
@ -1,9 +1,11 @@
|
||||
[DEFAULT]
|
||||
|
||||
[test_contacts_basics.html]
|
||||
[test_contacts_basics2.html]
|
||||
[test_contacts_blobs.html]
|
||||
[test_contacts_events.html]
|
||||
[test_contacts_getall.html]
|
||||
[test_contacts_getall2.html]
|
||||
[test_contacts_international.html]
|
||||
[test_contacts_substringmatching.html]
|
||||
[test_contacts_substringmatchingVE.html]
|
||||
|
@ -1054,703 +1054,6 @@ var steps = [
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Adding a new contact");
|
||||
createResult1 = new mozContact(properties1);
|
||||
req = mozContacts.save(createResult1)
|
||||
req.onsuccess = function () {
|
||||
ok(createResult1.id, "The contact now has an ID.");
|
||||
sample_id1 = createResult1.id;
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Adding a new contact2");
|
||||
createResult2 = new mozContact(properties2);
|
||||
req = mozContacts.save(createResult2);
|
||||
req.onsuccess = function () {
|
||||
ok(createResult2.id, "The contact now has an ID.");
|
||||
sample_id2 = createResult2.id;
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Retrieving all contacts");
|
||||
req = mozContacts.find({sortBy: "familyName"});
|
||||
req.onsuccess = function () {
|
||||
is(req.result.length, 2, "Found exactly 2 contact.");
|
||||
checkContacts(req.result[1], properties1);
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
console.log("Searching contacts by query1");
|
||||
var options = {filterBy: ["givenName", "email"],
|
||||
filterOp: "startsWith",
|
||||
filterValue: properties1.givenName[0].substring(0, 4)}
|
||||
req = mozContacts.find(options)
|
||||
req.onsuccess = function () {
|
||||
is(req.result.length, 1, "Found exactly 1 contact.");
|
||||
findResult1 = req.result[0];
|
||||
ok(findResult1.id == sample_id1, "Same ID");
|
||||
checkContacts(findResult1, createResult1);
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Searching contacts by query2");
|
||||
var options = {filterBy: ["givenName", "email"],
|
||||
filterOp: "startsWith",
|
||||
filterValue: properties2.givenName[0].substring(0, 4)};
|
||||
req = mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
is(req.result.length, 1, "Found exactly 1 contact.");
|
||||
findResult1 = req.result[0];
|
||||
is(findResult1.adr.length, 2, "Adr length 2");
|
||||
checkContacts(findResult1, createResult2);
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Searching contacts by tel");
|
||||
var options = {filterBy: ["tel"],
|
||||
filterOp: "contains",
|
||||
filterValue: properties2.tel[0].value.substring(3, 7)};
|
||||
req = mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
is(req.result.length, 1, "Found exactly 1 contact.");
|
||||
findResult1 = req.result[0];
|
||||
ok(findResult1.id == sample_id2, "Same ID");
|
||||
checkContacts(findResult1, createResult2);
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Searching contacts by email");
|
||||
var options = {filterBy: ["email"],
|
||||
filterOp: "startsWith",
|
||||
filterValue: properties2.email[0].value.substring(0, 4)};
|
||||
req = mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
is(req.result.length, 1, "Found exactly 1 contact.");
|
||||
findResult1 = req.result[0];
|
||||
ok(findResult1.id == sample_id2, "Same ID");
|
||||
checkContacts(findResult1, createResult2);
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Deleting database");
|
||||
req = mozContacts.clear();
|
||||
req.onsuccess = function () {
|
||||
clearTemps();
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Adding 20 contacts");
|
||||
for (var i=0; i<19; i++) {
|
||||
createResult1 = new mozContact(properties1);
|
||||
req = mozContacts.save(createResult1);
|
||||
req.onsuccess = function () {
|
||||
ok(createResult1.id, "The contact now has an ID.");
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
};
|
||||
createResult1 = new mozContact(properties1);
|
||||
req = mozContacts.save(createResult1);
|
||||
req.onsuccess = function () {
|
||||
ok(createResult1.id, "The contact now has an ID.");
|
||||
checkStrArray(createResult1.name, properties1.name, "Same Name");
|
||||
checkCount(20, "20 contacts in DB", next);
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Retrieving all contacts");
|
||||
req = mozContacts.find(defaultOptions);
|
||||
req.onsuccess = function () {
|
||||
is(req.result.length, 20, "20 Entries.");
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Retrieving all contacts with limit 10");
|
||||
var options = { filterLimit: 10 };
|
||||
req = mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
is(req.result.length, 10, "10 Entries.");
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Retrieving all contacts with limit 10 and sorted");
|
||||
var options = { filterLimit: 10,
|
||||
sortBy: 'FamilyName',
|
||||
sortOrder: 'descending' };
|
||||
req = mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
is(req.result.length, 10, "10 Entries.");
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Retrieving all contacts2");
|
||||
var options = {filterBy: ["givenName"],
|
||||
filterOp: "startsWith",
|
||||
filterValue: properties1.givenName[0].substring(0, 4)};
|
||||
req = mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
is(req.result.length, 20, "20 Entries.");
|
||||
checkContacts(createResult1, req.result[19]);
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Retrieving all contacts3");
|
||||
var options = {filterBy: ["givenName", "tel", "email"],
|
||||
filterOp: "startsWith",
|
||||
filterValue: properties1.givenName[0].substring(0, 4)};
|
||||
req = mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
is(req.result.length, 20, "20 Entries.");
|
||||
checkContacts(createResult1, req.result[10]);
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Deleting database");
|
||||
req = mozContacts.clear();
|
||||
req.onsuccess = function () {
|
||||
clearTemps();
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Testing clone contact");
|
||||
createResult1 = new mozContact(properties1);
|
||||
req = mozContacts.save(createResult1);
|
||||
req.onsuccess = function () {
|
||||
ok(createResult1.id, "The contact now has an ID.");
|
||||
checkStrArray(createResult1.name, properties1.name, "Same Name");
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function() {
|
||||
ok(true, "Testing clone contact2");
|
||||
var cloned = new mozContact(createResult1);
|
||||
ok(cloned.id != createResult1.id, "Cloned contact has new ID");
|
||||
cloned.email = [{value: "new email!"}];
|
||||
cloned.givenName = ["Tom"];
|
||||
req = mozContacts.save(cloned);
|
||||
req.onsuccess = function () {
|
||||
ok(cloned.id, "The contact now has an ID.");
|
||||
is(cloned.email[0].value, "new email!", "Same Email");
|
||||
isnot(createResult1.email[0].value, cloned.email[0].value, "Clone has different email");
|
||||
is(cloned.givenName, "Tom", "New Name");
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Retrieving all contacts");
|
||||
var options = {filterBy: ["givenName"],
|
||||
filterOp: "startsWith",
|
||||
filterValue: properties2.givenName[0].substring(0, 4)};
|
||||
req = mozContacts.find(defaultOptions);
|
||||
req.onsuccess = function () {
|
||||
is(req.result.length, 2, "2 Entries.");
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Search with redundant fields should only return 1 contact");
|
||||
createResult1 = new mozContact({name: ["XXX"],
|
||||
givenName: ["XXX"],
|
||||
email: [{value: "XXX"}],
|
||||
tel: [{value: "XXX"}]
|
||||
});
|
||||
req = mozContacts.save(createResult1);
|
||||
req.onsuccess = function() {
|
||||
var options = {filterBy: ["givenName", "familyName"],
|
||||
filterOp: "equals",
|
||||
filterValue: "XXX"};
|
||||
var req2 = mozContacts.find(options);
|
||||
req2.onsuccess = function() {
|
||||
is(req2.result.length, 1, "1 Entry");
|
||||
next();
|
||||
}
|
||||
req2.onerror = onFailure;
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Deleting database");
|
||||
req = mozContacts.clear()
|
||||
req.onsuccess = function () {
|
||||
ok(true, "Deleted the database");
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Test sorting");
|
||||
createResult1 = new mozContact(c3);
|
||||
req = navigator.mozContacts.save(createResult1);
|
||||
req.onsuccess = function () {
|
||||
ok(createResult1.id, "The contact now has an ID.");
|
||||
checkContacts(c3, createResult1);
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Test sorting");
|
||||
createResult1 = new mozContact(c2);
|
||||
req = navigator.mozContacts.save(createResult1);
|
||||
req.onsuccess = function () {
|
||||
ok(createResult1.id, "The contact now has an ID.");
|
||||
checkContacts(c2, createResult1);
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Test sorting");
|
||||
createResult1 = new mozContact(c4);
|
||||
req = navigator.mozContacts.save(createResult1);
|
||||
req.onsuccess = function () {
|
||||
ok(createResult1.id, "The contact now has an ID.");
|
||||
checkContacts(c4, createResult1);
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Test sorting");
|
||||
createResult1 = new mozContact(c1);
|
||||
req = navigator.mozContacts.save(createResult1);
|
||||
req.onsuccess = function () {
|
||||
ok(createResult1.id, "The contact now has an ID.");
|
||||
checkContacts(c1, createResult1);
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Test sorting");
|
||||
var options = {sortBy: "familyName",
|
||||
sortOrder: "ascending"};
|
||||
req = navigator.mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
is(req.result.length, 4, "4 results");
|
||||
checkContacts(req.result[0], c1);
|
||||
checkContacts(req.result[1], c2);
|
||||
checkContacts(req.result[2], c3);
|
||||
checkContacts(req.result[3], c4);
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Test sorting");
|
||||
var options = {sortBy: "familyName",
|
||||
sortOrder: "descending"};
|
||||
req = navigator.mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
is(req.result.length, 4, "4 results");
|
||||
checkContacts(req.result[0], c4);
|
||||
checkContacts(req.result[1], c3);
|
||||
checkContacts(req.result[2], c2);
|
||||
checkContacts(req.result[3], c1);
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Test sorting");
|
||||
createResult1 = new mozContact(c5);
|
||||
req = navigator.mozContacts.save(createResult1);
|
||||
req.onsuccess = function () {
|
||||
ok(createResult1.id, "The contact now has an ID.");
|
||||
checkContacts(c5, createResult1);
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Test sorting with empty string");
|
||||
var options = {sortBy: "familyName",
|
||||
sortOrder: "ascending"};
|
||||
req = navigator.mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
is(req.result.length, 5, "5 results");
|
||||
checkContacts(req.result[0], c5);
|
||||
checkContacts(req.result[1], c1);
|
||||
checkContacts(req.result[2], c2);
|
||||
checkContacts(req.result[3], c3);
|
||||
checkContacts(req.result[4], c4);
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Don't allow to add custom fields");
|
||||
createResult1 = new mozContact({givenName: ["customTest"], yyy: "XXX"});
|
||||
req = mozContacts.save(createResult1);
|
||||
req.onsuccess = function() {
|
||||
var options = {filterBy: ["givenName"],
|
||||
filterOp: "equals",
|
||||
filterValue: "customTest"};
|
||||
var req2 = mozContacts.find(options);
|
||||
req2.onsuccess = function() {
|
||||
is(req2.result.length, 1, "1 Entry");
|
||||
checkStrArray(req2.result[0].givenName, ["customTest"], "same name");
|
||||
ok(req2.result.yyy === undefined, "custom property undefined");
|
||||
next();
|
||||
}
|
||||
req2.onerror = onFailure;
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Deleting database");
|
||||
req = mozContacts.clear()
|
||||
req.onsuccess = function () {
|
||||
ok(true, "Deleted the database");
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Test sorting");
|
||||
createResult1 = new mozContact(c7);
|
||||
req = navigator.mozContacts.save(createResult1);
|
||||
req.onsuccess = function () {
|
||||
ok(createResult1.id, "The contact now has an ID.");
|
||||
checkContacts(c7, createResult1);
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Test sorting");
|
||||
createResult1 = new mozContact(c6);
|
||||
req = navigator.mozContacts.save(createResult1);
|
||||
req.onsuccess = function () {
|
||||
ok(createResult1.id, "The contact now has an ID.");
|
||||
checkContacts(c6, createResult1);
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Test sorting");
|
||||
createResult1 = new mozContact(c8);
|
||||
req = navigator.mozContacts.save(createResult1);
|
||||
req.onsuccess = function () {
|
||||
ok(createResult1.id, "The contact now has an ID.");
|
||||
checkContacts(c8, createResult1);
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
// Android does not support published/updated fields. Skip this.
|
||||
if (isAndroid) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
ok(true, "Test sorting with published");
|
||||
var options = {sortBy: "familyName",
|
||||
sortOrder: "descending"};
|
||||
req = navigator.mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
is(req.result.length, 3, "3 results");
|
||||
ok(req.result[0].published < req.result[1].published, "Right sorting order");
|
||||
ok(req.result[1].published < req.result[2].published, "Right sorting order");
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Deleting database");
|
||||
req = mozContacts.clear();
|
||||
req.onsuccess = function () {
|
||||
ok(true, "Deleted the database");
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Adding a new contact with properties2");
|
||||
createResult2 = new mozContact(properties2);
|
||||
req = mozContacts.save(createResult2);
|
||||
req.onsuccess = function () {
|
||||
ok(createResult2.id, "The contact now has an ID.");
|
||||
sample_id2 = createResult2.id;
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Test category search with startsWith");
|
||||
var options = {filterBy: ["category"],
|
||||
filterOp: "startsWith",
|
||||
filterValue: properties2.category[0]};
|
||||
req = mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
is(req.result.length, 1, "1 Entry.");
|
||||
checkContacts(req.result[0], createResult2);
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Test category search with equals");
|
||||
var options = {filterBy: ["category"],
|
||||
filterOp: "equals",
|
||||
filterValue: properties2.category[0]};
|
||||
req = mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
is(req.result.length, 1, "1 Entry.");
|
||||
checkContacts(req.result[0], createResult2);
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Deleting database");
|
||||
req = mozContacts.clear()
|
||||
req.onsuccess = function () {
|
||||
ok(true, "Deleted the database");
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Adding contact for category search");
|
||||
createResult1 = new mozContact({name: ["5"], givenName: ["5"]});
|
||||
req = navigator.mozContacts.save(createResult1);
|
||||
req.onsuccess = function () {
|
||||
ok(createResult1.id, "The contact now has an ID.");
|
||||
sample_id1 = createResult1.id;
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Test category search with equals");
|
||||
var options = {filterBy: ["givenName"],
|
||||
filterOp: "startsWith",
|
||||
filterValue: "5"};
|
||||
req = mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
is(req.result.length, 1, "1 Entry.");
|
||||
checkContacts(req.result[0], createResult1);
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Deleting database");
|
||||
req = mozContacts.clear()
|
||||
req.onsuccess = function () {
|
||||
ok(true, "Deleted the database");
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Adding contact with invalid data");
|
||||
var obj = {
|
||||
honorificPrefix: [],
|
||||
honorificSuffix: [{foo: "bar"}],
|
||||
sex: 17,
|
||||
genderIdentity: 18
|
||||
};
|
||||
obj.honorificPrefix.__defineGetter__('0',(function() {
|
||||
var c = 0;
|
||||
return function() {
|
||||
if (c == 0) {
|
||||
c++;
|
||||
return "string";
|
||||
} else {
|
||||
return {foo:"bar"};
|
||||
}
|
||||
}
|
||||
})());
|
||||
createResult1 = new mozContact(obj);
|
||||
req = mozContacts.save(createResult1);
|
||||
req.onsuccess = function () {
|
||||
checkContacts(createResult1, {
|
||||
honorificPrefix: ["string"],
|
||||
honorificSuffix: ["[object Object]"],
|
||||
sex: "17",
|
||||
genderIdentity: "18"
|
||||
});
|
||||
next();
|
||||
};
|
||||
},
|
||||
function () {
|
||||
ok(true, "Adding contact with no number but carrier");
|
||||
createResult1 = new mozContact({ tel: [{type: ["home"], carrier: "myCarrier"} ] });
|
||||
req = navigator.mozContacts.save(createResult1);
|
||||
req.onsuccess = function () {
|
||||
ok(createResult1.id, "The contact now has an ID.");
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Adding contact with email but no value");
|
||||
createResult1 = new mozContact({ email: [{type: ["home"]}] });
|
||||
req = navigator.mozContacts.save(createResult1);
|
||||
req.onsuccess = function () {
|
||||
ok(createResult1.id, "The contact now has an ID.");
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Testing numbersOnly search 1");
|
||||
createResult1 = new mozContact({ name: ["aaaaaaaaa"], givenName: ["aaaaaaaaa"], tel: [{ value: "1234567890"}]});
|
||||
req = navigator.mozContacts.save(createResult1);
|
||||
req.onsuccess = function () {
|
||||
ok(createResult1.id, "The contact now has an ID.");
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Test numbersOnly search 2");
|
||||
var options = {filterBy: ["givenName", "tel"],
|
||||
filterOp: "contains",
|
||||
filterValue: "a"};
|
||||
req = mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
ok(req.result.length == 1, "1 Entry.");
|
||||
checkContacts(req.result[0], createResult1);
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Test numbersOnly search 3");
|
||||
var options = {filterBy: ["givenName", "tel"],
|
||||
filterOp: "contains",
|
||||
filterValue: "b"};
|
||||
req = mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
ok(req.result.length == 0, "0 Entries.");
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Test numbersOnly search 4");
|
||||
var options = {filterBy: ["givenName", "tel"],
|
||||
filterOp: "contains",
|
||||
filterValue: "1a"};
|
||||
req = mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
ok(req.result.length == 0, "0 Entries.");
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Test numbersOnly search 5");
|
||||
var options = {filterBy: ["givenName", "tel"],
|
||||
filterOp: "contains",
|
||||
filterValue: "1(23)"};
|
||||
req = mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
ok(req.result.length == 1, "1 Entry.");
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Test numbersOnly search 6");
|
||||
var options = {filterBy: ["givenName", "tel"],
|
||||
filterOp: "contains",
|
||||
filterValue: "1(23)a"};
|
||||
req = mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
ok(req.result.length == 0, "0 Entries.");
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Deleting database");
|
||||
req = mozContacts.clear()
|
||||
req.onsuccess = function () {
|
||||
ok(true, "Deleted the database");
|
||||
next();
|
||||
}
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function() {
|
||||
ok(true, "Test setting array properties to scalar values")
|
||||
const FIELDS = ["email","url","adr","tel","impp"];
|
||||
createResult1 = new mozContact();
|
||||
for (var prop of FIELDS) {
|
||||
createResult1[prop] = {type: ["foo"]};
|
||||
ok(Array.isArray(createResult1[prop]), prop + " is array");
|
||||
}
|
||||
next();
|
||||
},
|
||||
function() {
|
||||
ok(true, "Undefined strings should be treated as null");
|
||||
var c = new mozContact({
|
||||
adr: [{value: undefined}],
|
||||
email: [{value: undefined}],
|
||||
url: [{value: undefined}],
|
||||
impp: [{value: undefined}],
|
||||
tel: [{value: undefined}],
|
||||
});
|
||||
is(c.adr[0].type, null, "adr is null");
|
||||
is(c.email[0].type, null, "email is null");
|
||||
is(c.url[0].type, null, "url is null");
|
||||
is(c.impp[0].type, null, "impp is null");
|
||||
is(c.tel[0].type, null, "tel is null");
|
||||
next();
|
||||
},
|
||||
function() {
|
||||
ok(true, "Setting array properties to an empty array should work");
|
||||
var c = new mozContact();
|
||||
function testArrayProp(prop) {
|
||||
is(c[prop], null, "property is initially null");
|
||||
c[prop] = [];
|
||||
ok(Array.isArray(c[prop]), "property is an array after setting");
|
||||
is(c[prop].length, 0, "property has length 0 after setting");
|
||||
}
|
||||
testArrayProp("email");
|
||||
testArrayProp("adr");
|
||||
testArrayProp("tel");
|
||||
testArrayProp("impp");
|
||||
testArrayProp("url");
|
||||
next();
|
||||
},
|
||||
function () {
|
||||
ok(true, "all done!\n");
|
||||
clearTemps();
|
||||
|
1076
dom/contacts/tests/test_contacts_basics2.html
Normal file
1076
dom/contacts/tests/test_contacts_basics2.html
Normal file
File diff suppressed because it is too large
Load Diff
@ -284,88 +284,6 @@ let steps = [
|
||||
SpecialPowers.Cc["@mozilla.org/tools/profiler;1"].getService(SpecialPowers.Ci.nsIProfiler).AddMarker("GETALL_START");
|
||||
next();
|
||||
},
|
||||
clearDatabase,
|
||||
function() {
|
||||
// add a contact
|
||||
createResult1 = new mozContact({});
|
||||
req = navigator.mozContacts.save(createResult1);
|
||||
req.onsuccess = function() {
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
|
||||
getOne(),
|
||||
getOne("Retrieving one contact with getAll - cached"),
|
||||
|
||||
clearDatabase,
|
||||
addContacts,
|
||||
|
||||
getAll(),
|
||||
getAll("Retrieving 40 contacts with getAll - cached"),
|
||||
|
||||
function() {
|
||||
ok(true, "Deleting one contact");
|
||||
req = mozContacts.remove(createResult1);
|
||||
req.onsuccess = function() {
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function() {
|
||||
ok(true, "Test cache invalidation");
|
||||
req = mozContacts.getAll({});
|
||||
let count = 0;
|
||||
req.onsuccess = function(event) {
|
||||
ok(true, "on success");
|
||||
if (req.result) {
|
||||
ok(true, "result is valid");
|
||||
count++;
|
||||
req.continue();
|
||||
} else {
|
||||
is(count, 39, "last contact - 39 contacts returned");
|
||||
next();
|
||||
}
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
|
||||
clearDatabase,
|
||||
addContacts,
|
||||
|
||||
function() {
|
||||
ok(true, "Test cache consistency when deleting contact during getAll");
|
||||
req = mozContacts.find({});
|
||||
req.onsuccess = function(e) {
|
||||
let lastContact = e.target.result[e.target.result.length-1];
|
||||
req = mozContacts.getAll({});
|
||||
let count = 0;
|
||||
let firstResult = true;
|
||||
req.onsuccess = function(event) {
|
||||
ok(true, "on success");
|
||||
if (firstResult) {
|
||||
if (req.result) {
|
||||
count++;
|
||||
}
|
||||
let delReq = mozContacts.remove(lastContact);
|
||||
delReq.onsuccess = function() {
|
||||
firstResult = false;
|
||||
req.continue();
|
||||
};
|
||||
} else {
|
||||
if (req.result) {
|
||||
ok(true, "result is valid");
|
||||
count++;
|
||||
req.continue();
|
||||
} else {
|
||||
is(count, 40, "last contact - 40 contacts returned");
|
||||
next();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
},
|
||||
|
||||
clearDatabase,
|
||||
addContacts,
|
||||
|
||||
|
403
dom/contacts/tests/test_contacts_getall2.html
Normal file
403
dom/contacts/tests/test_contacts_getall2.html
Normal file
@ -0,0 +1,403 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=836519
|
||||
-->
|
||||
<head>
|
||||
<title>Mozilla Bug 836519</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=836519">Mozilla Bug 836519</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript;version=1.7">
|
||||
|
||||
"use strict";
|
||||
|
||||
if (SpecialPowers.isMainProcess()) {
|
||||
SpecialPowers.Cu.import("resource://gre/modules/ContactService.jsm");
|
||||
SpecialPowers.Cu.import("resource://gre/modules/PermissionPromptHelper.jsm");
|
||||
}
|
||||
|
||||
SpecialPowers.addPermission("contacts-write", true, document);
|
||||
SpecialPowers.addPermission("contacts-read", true, document);
|
||||
SpecialPowers.addPermission("contacts-create", true, document);
|
||||
|
||||
var isAndroid = (navigator.userAgent.indexOf("Android") !== -1);
|
||||
var androidVersion = SpecialPowers.Cc['@mozilla.org/system-info;1']
|
||||
.getService(SpecialPowers.Ci.nsIPropertyBag2)
|
||||
.getProperty('version');
|
||||
|
||||
let adr1 = {
|
||||
type: ["work"],
|
||||
streetAddress: "street 1",
|
||||
locality: "locality 1",
|
||||
region: "region 1",
|
||||
postalCode: "postal code 1",
|
||||
countryName: "country 1"
|
||||
};
|
||||
|
||||
let properties1 = {
|
||||
name: ["Testname1 TestFamilyName"],
|
||||
familyName: ["TestFamilyName","Wagner"],
|
||||
givenName: ["Test1","Test2"],
|
||||
nickname: ["nicktest"],
|
||||
tel: [{type: ["work"], value: "123456", carrier: "testCarrier"} , {type: ["home", "fax"], value: "+9-876-5432"}],
|
||||
adr: [adr1],
|
||||
email: [{type: ["work"], value: "x@y.com"}]
|
||||
};
|
||||
|
||||
function onFailure() {
|
||||
ok(false, "in on Failure!");
|
||||
next();
|
||||
}
|
||||
function checkStr(str1, str2, msg) {
|
||||
if (str1 ^ str2) {
|
||||
ok(false, "Expected both strings to be either present or absent");
|
||||
return;
|
||||
}
|
||||
is(str1, str2, msg);
|
||||
}
|
||||
|
||||
function checkStrArray(str1, str2, msg) {
|
||||
function normalize_falsy(k, v) {
|
||||
if (!v || v == "null" || v == "undefined") {
|
||||
return "";
|
||||
}
|
||||
return v;
|
||||
}
|
||||
ise(JSON.stringify(str1, normalize_falsy), JSON.stringify(str2, normalize_falsy), msg);
|
||||
}
|
||||
|
||||
function checkPref(pref1, pref2) {
|
||||
// If on Android treat one preference as 0 and the other as undefined as matching
|
||||
if (isAndroid) {
|
||||
if ((!pref1 && pref2 == undefined) || (pref1 == undefined && !pref2)) {
|
||||
pref1 = false;
|
||||
pref2 = false;
|
||||
}
|
||||
}
|
||||
ise(!!pref1, !!pref2, "Same pref");
|
||||
}
|
||||
|
||||
function checkAddress(adr1, adr2) {
|
||||
if (adr1 ^ adr2) {
|
||||
ok(false, "Expected both adrs to be either present or absent");
|
||||
return;
|
||||
}
|
||||
checkStrArray(adr1.type, adr2.type, "Same type");
|
||||
checkStrArray(adr1.streetAddress, adr2.streetAddress, "Same streetAddress");
|
||||
checkStrArray(adr1.locality, adr2.locality, "Same locality");
|
||||
checkStrArray(adr1.region, adr2.region, "Same region");
|
||||
checkStrArray(adr1.postalCode, adr2.postalCode, "Same postalCode");
|
||||
checkStrArray(adr1.countryName, adr2.countryName, "Same countryName");
|
||||
checkPref(adr1.pref, adr2.pref);
|
||||
}
|
||||
|
||||
function checkField(field1, field2) {
|
||||
if (field1 ^ field2) {
|
||||
ok(false, "Expected both fields to be either present or absent");
|
||||
return;
|
||||
}
|
||||
checkStrArray(field1.type, field2.type, "Same type");
|
||||
checkStrArray(field1.value, field2.value, "Same value");
|
||||
checkPref(field1.pref, field2.pref);
|
||||
}
|
||||
|
||||
function checkTel(tel1, tel2) {
|
||||
if (tel1 ^ tel2) {
|
||||
ok(false, "Expected both tels to be either present or absent");
|
||||
return;
|
||||
}
|
||||
checkField(tel1, tel2);
|
||||
checkStrArray(tel1.carrier, tel2.carrier, "Same carrier");
|
||||
}
|
||||
|
||||
function checkCategory(category1, category2) {
|
||||
// Android adds contacts to the a default category. This should be removed from the
|
||||
// results before comparing them
|
||||
if (isAndroid) {
|
||||
category1 = removeAndroidDefaultCategory(category1);
|
||||
category2 = removeAndroidDefaultCategory(category2);
|
||||
}
|
||||
checkStrArray(category1, category2, "Same Category")
|
||||
}
|
||||
|
||||
function removeAndroidDefaultCategory(category) {
|
||||
if (!category) {
|
||||
return category;
|
||||
}
|
||||
|
||||
var result = [];
|
||||
|
||||
for (var i of category) {
|
||||
// Some devices may return the full group name (prefixed with "System Group: ")
|
||||
if (i != "My Contacts" && i != "System Group: My Contacts") {
|
||||
result.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function checkArrayField(array1, array2, func, msg) {
|
||||
if (!!array1 ^ !!array2) {
|
||||
ok(false, "Expected both arrays to be either present or absent");
|
||||
return;
|
||||
}
|
||||
if (!array1 && !array2) {
|
||||
ok(true, msg);
|
||||
return;
|
||||
}
|
||||
ise(array1.length, array2.length, "Same length");
|
||||
for (var i = 0; i < array1.length; ++i) {
|
||||
func(array1[i], array2[i], msg);
|
||||
}
|
||||
}
|
||||
|
||||
function checkContacts(contact1, contact2) {
|
||||
if (!!contact1 ^ !!contact2) {
|
||||
ok(false, "Expected both contacts to be either present or absent");
|
||||
return;
|
||||
}
|
||||
checkStrArray(contact1.name, contact2.name, "Same name");
|
||||
checkStrArray(contact1.honorificPrefix, contact2.honorificPrefix, "Same honorificPrefix");
|
||||
checkStrArray(contact1.givenName, contact2.givenName, "Same givenName");
|
||||
checkStrArray(contact1.additionalName, contact2.additionalName, "Same additionalName");
|
||||
checkStrArray(contact1.familyName, contact2.familyName, "Same familyName");
|
||||
checkStrArray(contact1.honorificSuffix, contact2.honorificSuffix, "Same honorificSuffix");
|
||||
checkStrArray(contact1.nickname, contact2.nickname, "Same nickname");
|
||||
checkCategory(contact1.category, contact2.category);
|
||||
checkStrArray(contact1.org, contact2.org, "Same org");
|
||||
checkStrArray(contact1.jobTitle, contact2.jobTitle, "Same jobTitle");
|
||||
is(contact1.bday ? contact1.bday.valueOf() : null, contact2.bday ? contact2.bday.valueOf() : null, "Same birthday");
|
||||
checkStrArray(contact1.note, contact2.note, "Same note");
|
||||
is(contact1.anniversary ? contact1.anniversary.valueOf() : null , contact2.anniversary ? contact2.anniversary.valueOf() : null, "Same anniversary");
|
||||
checkStr(contact1.sex, contact2.sex, "Same sex");
|
||||
checkStr(contact1.genderIdentity, contact2.genderIdentity, "Same genderIdentity");
|
||||
checkStrArray(contact1.key, contact2.key, "Same key");
|
||||
|
||||
checkArrayField(contact1.adr, contact2.adr, checkAddress, "Same adr");
|
||||
checkArrayField(contact1.tel, contact2.tel, checkTel, "Same tel");
|
||||
checkArrayField(contact1.email, contact2.email, checkField, "Same email");
|
||||
checkArrayField(contact1.url, contact2.url, checkField, "Same url");
|
||||
checkArrayField(contact1.impp, contact2.impp, checkField, "Same impp");
|
||||
}
|
||||
|
||||
function clearDatabase() {
|
||||
ok(true, "Clearing database");
|
||||
req = mozContacts.clear();
|
||||
req.onsuccess = function() {
|
||||
ok(true, "Cleared the database");
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
}
|
||||
|
||||
function addContacts() {
|
||||
ok(true, "Adding 40 contacts");
|
||||
for (let i = 0; i < 39; ++i) {
|
||||
properties1.familyName[0] = "Testname" + (i < 10 ? "0" + i : i);
|
||||
properties1.name = [properties1.givenName[0] + " " + properties1.familyName[0]];
|
||||
createResult1 = new mozContact(properties1);
|
||||
req = mozContacts.save(createResult1);
|
||||
req.onsuccess = function() {
|
||||
ok(createResult1.id, "The contact now has an ID.");
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
};
|
||||
properties1.familyName[0] = "Testname39";
|
||||
properties1.name = [properties1.givenName[0] + " Testname39"];
|
||||
createResult1 = new mozContact(properties1);
|
||||
req = mozContacts.save(createResult1);
|
||||
req.onsuccess = function() {
|
||||
ok(createResult1.id, "The contact now has an ID.");
|
||||
checkStrArray(createResult1.name, properties1.name, "Same Name");
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
}
|
||||
|
||||
let createResult1;
|
||||
|
||||
let index = 0;
|
||||
let req;
|
||||
let mozContacts = window.navigator.mozContacts;
|
||||
|
||||
function getOne(msg) {
|
||||
return function() {
|
||||
ok(true, msg || "Retrieving one contact with getAll");
|
||||
req = mozContacts.getAll({});
|
||||
|
||||
let count = 0;
|
||||
req.onsuccess = function(event) {
|
||||
ok(true, "on success");
|
||||
if (req.result) {
|
||||
ok(true, "result is valid");
|
||||
count++;
|
||||
req.continue();
|
||||
} else {
|
||||
is(count, 1, "last contact - only one contact returned");
|
||||
next();
|
||||
}
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
};
|
||||
}
|
||||
|
||||
function getAll(msg) {
|
||||
return function() {
|
||||
ok(true, msg || "Retrieving 40 contacts with getAll");
|
||||
req = mozContacts.getAll({
|
||||
sortBy: "familyName",
|
||||
sortOrder: "ascending"
|
||||
});
|
||||
let count = 0;
|
||||
let result;
|
||||
let props;
|
||||
req.onsuccess = function(event) {
|
||||
if (req.result) {
|
||||
ok(true, "result is valid");
|
||||
result = req.result;
|
||||
properties1.familyName[0] = "Testname" + (count < 10 ? "0" + count : count);
|
||||
is(result.familyName[0], properties1.familyName[0], "Same familyName");
|
||||
count++;
|
||||
req.continue();
|
||||
} else {
|
||||
is(count, 40, "last contact - 40 contacts returned");
|
||||
next();
|
||||
}
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
}
|
||||
}
|
||||
|
||||
let steps = [
|
||||
function start() {
|
||||
SpecialPowers.Cc["@mozilla.org/tools/profiler;1"].getService(SpecialPowers.Ci.nsIProfiler).AddMarker("GETALL_START");
|
||||
next();
|
||||
},
|
||||
clearDatabase,
|
||||
function() {
|
||||
// add a contact
|
||||
createResult1 = new mozContact({});
|
||||
req = navigator.mozContacts.save(createResult1);
|
||||
req.onsuccess = function() {
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
|
||||
getOne(),
|
||||
getOne("Retrieving one contact with getAll - cached"),
|
||||
|
||||
clearDatabase,
|
||||
addContacts,
|
||||
|
||||
getAll(),
|
||||
getAll("Retrieving 40 contacts with getAll - cached"),
|
||||
|
||||
function() {
|
||||
ok(true, "Deleting one contact");
|
||||
req = mozContacts.remove(createResult1);
|
||||
req.onsuccess = function() {
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function() {
|
||||
ok(true, "Test cache invalidation");
|
||||
req = mozContacts.getAll({});
|
||||
let count = 0;
|
||||
req.onsuccess = function(event) {
|
||||
ok(true, "on success");
|
||||
if (req.result) {
|
||||
ok(true, "result is valid");
|
||||
count++;
|
||||
req.continue();
|
||||
} else {
|
||||
is(count, 39, "last contact - 39 contacts returned");
|
||||
next();
|
||||
}
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
|
||||
clearDatabase,
|
||||
addContacts,
|
||||
|
||||
function() {
|
||||
ok(true, "Test cache consistency when deleting contact during getAll");
|
||||
req = mozContacts.find({});
|
||||
req.onsuccess = function(e) {
|
||||
let lastContact = e.target.result[e.target.result.length-1];
|
||||
req = mozContacts.getAll({});
|
||||
let count = 0;
|
||||
let firstResult = true;
|
||||
req.onsuccess = function(event) {
|
||||
ok(true, "on success");
|
||||
if (firstResult) {
|
||||
if (req.result) {
|
||||
count++;
|
||||
}
|
||||
let delReq = mozContacts.remove(lastContact);
|
||||
delReq.onsuccess = function() {
|
||||
firstResult = false;
|
||||
req.continue();
|
||||
};
|
||||
} else {
|
||||
if (req.result) {
|
||||
ok(true, "result is valid");
|
||||
count++;
|
||||
req.continue();
|
||||
} else {
|
||||
is(count, 40, "last contact - 40 contacts returned");
|
||||
next();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
},
|
||||
|
||||
clearDatabase,
|
||||
|
||||
function() {
|
||||
ok(true, "all done!\n");
|
||||
SpecialPowers.Cc["@mozilla.org/tools/profiler;1"].getService(SpecialPowers.Ci.nsIProfiler).AddMarker("GETALL_END");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
];
|
||||
|
||||
function next() {
|
||||
ok(true, "Begin!");
|
||||
if (index >= steps.length) {
|
||||
ok(false, "Shouldn't get here!");
|
||||
return;
|
||||
}
|
||||
let i = index++;
|
||||
try {
|
||||
steps[i]();
|
||||
} catch(ex) {
|
||||
ok(false, "Caught exception", ex);
|
||||
}
|
||||
}
|
||||
|
||||
// Skip tests on Android < 4.0 due to test failures on tbpl (see bugs 897924 & 888891)
|
||||
if (!isAndroid || androidVersion >= 14) {
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
addLoadEvent(next);
|
||||
} else {
|
||||
ok(true, "Skip tests on Android < 4.0 (bugs 897924 & 888891");
|
||||
}
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user