Bug 932763 - Setting mozContact's array properties to an empty array should work. r=gwagner

--HG--
extra : rebase_source : bdc09f04d31e72fafce8b8ef5726d1d0288c8efd
This commit is contained in:
Reuben Morais 2013-10-30 21:39:05 -02:00
parent 430c8da48e
commit f4b61b927e
2 changed files with 27 additions and 17 deletions

View File

@ -176,18 +176,18 @@ function validateArrayField(data, createCb) {
}
};
if (data) {
data = Array.isArray(data) ? data : [data];
let filtered = [];
for (let i = 0, n = data.length; i < n; ++i) {
if (data === null || data === undefined) {
return undefined;
}
data = Array.isArray(data) ? data : [data];
let filtered = [];
for (let i = 0, n = data.length; i < n; ++i) {
if (data[i]) {
filtered.push(createCb(data[i]));
}
if (filtered.length === 0) {
return undefined;
}
return new Proxy(filtered, ArrayPropertyHandler);
}
return undefined;
return new Proxy(filtered, ArrayPropertyHandler);
}
// We need this to create a copy of the mozContact object in ContactManager.save

View File

@ -264,7 +264,7 @@ function removeAndroidDefaultCategory(category) {
function checkArrayField(array1, array2, func, msg) {
if (!!array1 ^ !!array2) {
ok(false, "Expected both arrays to be either present or absent");
ok(false, "Expected both arrays to be either present or absent: " + JSON.stringify(array1) + " vs. " + JSON.stringify(array2) + ". (" + msg + ")");
return;
}
if (!array1 && !array2) {
@ -1523,17 +1523,11 @@ var steps = [
},
function () {
ok(true, "Adding contact with invalid data");
var input = document.createElement("input");
var obj = {
honorificPrefix: [],
honorificSuffix: [{foo: "bar"}],
sex: 17,
genderIdentity: 18,
email: input,
adr: input,
tel: input,
impp: input,
url: input
genderIdentity: 18
};
obj.honorificPrefix.__defineGetter__('0',(function() {
var c = 0;
@ -1684,6 +1678,22 @@ var steps = [
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();