Bug 852057 - Sort contacts correctly when givenName or familyName is null. r=gwagner
authorleo.bugzilla.gecko@gmail.com
Thu, 11 Apr 2013 12:35:24 -0700
changeset 128495 2d4d6eea0dd6816ff6b79af7904e469c1e5a8521
parent 128494 5e573a8f7ce1d0011efb17569df2480ce77e3a59
child 128496 f23121d10690ddc689e6d3b262cc1b6c21288f66
push id24529
push userryanvm@gmail.com
push dateFri, 12 Apr 2013 11:51:36 +0000
treeherdermozilla-central@5bc732a49eae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgwagner
bugs852057
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 852057 - Sort contacts correctly when givenName or familyName is null. r=gwagner
dom/contacts/fallback/ContactDB.jsm
dom/contacts/tests/test_contacts_basics.html
--- a/dom/contacts/fallback/ContactDB.jsm
+++ b/dom/contacts/fallback/ContactDB.jsm
@@ -576,17 +576,17 @@ ContactDB.prototype = {
         let yIndex = 0;
 
         do {
           while (xIndex < sortBy.length && !x) {
             x = a.properties[sortBy[xIndex]] ? a.properties[sortBy[xIndex]][0].toLowerCase() : null;
             xIndex++;
           }
           if (!x) {
-            return sortOrder == 'ascending' ? 1 : -1;
+            return sortOrder == 'descending' ? 1 : -1;
           }
           while (yIndex < sortBy.length && !y) {
             y = b.properties[sortBy[yIndex]] ? b.properties[sortBy[yIndex]][0].toLowerCase() : null;
             yIndex++;
           }
           if (!y) {
             return sortOrder == 'ascending' ? 1 : -1;
           }
--- a/dom/contacts/tests/test_contacts_basics.html
+++ b/dom/contacts/tests/test_contacts_basics.html
@@ -23,17 +23,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 
 // this shouldn't be necessary when bug 792594 is fixed
 if (!SpecialPowers.getBoolPref("dom.mozContacts.enabled")) {
   var comp = SpecialPowers.wrap(SpecialPowers.Components);
   comp.utils.import("resource://gre/modules/ContactService.jsm");
   comp.utils.import("resource://gre/modules/PermissionPromptHelper.jsm");
   SpecialPowers.setBoolPref("dom.mozContacts.enabled", true);
 }
-    
+
 SpecialPowers.addPermission("contacts-write", true, document);
 SpecialPowers.addPermission("contacts-read", true, document);
 SpecialPowers.addPermission("contacts-create", true, document);
 
 // For Sorting
 var c1 = {
   name: "a",
   familyName: ["a"],
@@ -135,18 +135,26 @@ function onUnwantedSuccess() {
   ok(false, "onUnwantedSuccess: shouldn't get here");
 }
 
 function onFailure() {
   ok(false, "in on Failure!");
 }
 
 function checkStr(str1, str2, msg) {
-  if (str1)
-    ok(typeof str1 == "string" ? [str1] : str1, (typeof str2 == "string") ? [str2] : str2, msg);
+  // comparing /[null(,null)+]/ and undefined should pass
+  function nonNull(e) {
+    return e != null;
+  }
+  if ((Array.isArray(str1) && str1.filter(nonNull).length == 0 && str2 == undefined)
+     ||(Array.isArray(str2) && str2.filter(nonNull).length == 0 && str1 == undefined)) {
+    ok(true, msg);
+  } else if (str1) {
+    is(JSON.stringify(typeof str1 == "string" ? [str1] : str1), JSON.stringify(typeof str2 == "string" ? [str2] : str2), msg);
+  }
 }
 
 function checkAddress(adr1, adr2) {
   checkStr(adr1.type, adr2.type, "Same type");
   checkStr(adr1.streetAddress, adr2.streetAddress, "Same streetAddress");
   checkStr(adr1.locality, adr2.locality, "Same locality");
   checkStr(adr1.region, adr2.region, "Same region");
   checkStr(adr1.postalCode, adr2.postalCode, "Same postalCode");