[Contacts] Contacts are randomly sorted, when one field is same and either givenName or familyName field is NULL.

RESOLVED FIXED

Status

defect
--
major
RESOLVED FIXED
6 years ago
6 years ago

People

(Reporter: leo.bugzilla.gecko, Assigned: leo.bugzilla.gecko)

Tracking

unspecified
ARM
Gonk (Firefox OS)
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(blocking-b2g:-, b2g18+)

Details

Attachments

(2 attachments)

Contacts are randomly sorted, when one field is same and either givenName or familyName field is NULL.

For instance,
There are two contacts with same givenName, and one of them only has familyName.
In this case, contacts are randomly sorted.

That's because the return value of "function sortfunction(a, b)" in ContactService.jsm becomes always "1", when familyName field of either contact "a" or "b" is NULL.

So, My suggestion is as below. (Line 113)
Please check this issue.
Thanks you.

Original Code>>
 98     function sortfunction(a, b){
...
107       do {
108         while (xIndex < sortBy.length && !x) {
109           x = a.properties[sortBy[xIndex]] ? a.properties[sortBy[xIndex]][0].toLowerCase() : null;
110           xIndex++;
111         }
112         if (!x) {
113           return sortOrder == 'ascending' ? 1 : -1;
114         }


Solution Code>>
 98     function sortfunction(a, b){
...
107       do {
108         while (xIndex < sortBy.length && !x) {
109           x = a.properties[sortBy[xIndex]] ? a.properties[sortBy[xIndex]][0].toLowerCase() : null;
110           xIndex++;
111         }
112         if (!x) {
113           return sortOrder == 'descending' ? 1 : -1;
114         }
blocking-b2g: --- → leo?
Group: core-security
Not a critical blocker, but worthwhile to track and fix in the v1 timeframe.

Please attach the patch to this bug, and request review from somebody within Mozilla engineering.
blocking-b2g: leo? → -
tracking-b2g18: --- → +
Adding Gregor to track it
Let me know the way to contribute to git repository in Gecko layer.
I think It's different from the way of Gaia.git.
(In reply to leo.bugzilla.gecko from comment #3)
> Let me know the way to contribute to git repository in Gecko layer.
> I think It's different from the way of Gaia.git.

MDN has useful information on how to create a properly formatted patch: 
https://developer.mozilla.org/en-US/docs/Developer_Guide/How_to_Submit_a_Patch#Creating_a_patch
[bug852057] Contacts are randomly sorted, when one field is same and either givenName or familyName field is NULL.
It is the patch for this issue
Attachment #731047 - Flags: review?(anygregor)
Thanks for the patch!
Please add a testcase and I will review it right away.
You can add it somewhere in:
https://hg.mozilla.org/mozilla-central/file/aae004a3c5d9/dom/contacts/tests/test_contacts_basics.html


Please ask if you need help running the tests.
(In reply to Gregor Wagner [:gwagner] from comment #6)

This is already covered by our tests, the problem is that the checkStr function in test_contacts_basics should do |is| instead of |ok|. I have a patch that fixes this in a another bug, I'll extract the fix and attach it here.
(In reply to Gregor Wagner [:gwagner] from comment #6)
 
Please let me know how to run the tests.
(In reply to leo.bugzilla.gecko from comment #9)
> (In reply to Gregor Wagner [:gwagner] from comment #6)
>  
> Please let me know how to run the tests.

You most likely have a git clone of our whole B2G project right? So gecko is compiled for the phone and you can't run tests for it.

The easiest way to run tests locally is to checkout the source for the desktop version, build it and run the tests there.

1) getting the source: https://developer.mozilla.org/en-US/docs/Simple_Firefox_build
hg clone https://hg.mozilla.org/mozilla-central

2) build: https://developer.mozilla.org/en-US/docs/Configuring_Build_Options
create a .mozconfig file and build the source.

3) run the tests:
you have to be in your gecko folder and ff-dbg is the object directory in my case. You probably have to change it.
TEST_PATH=dom/contacts/tests/ make -C ff-dbg/ mochitest-plain
Attachment #731047 - Flags: review?(anygregor) → review+
Attachment #732124 - Flags: review+
https://hg.mozilla.org/mozilla-central/rev/2d4d6eea0dd6
Assignee: nobody → leo.bugzilla.gecko
Status: NEW → RESOLVED
Closed: 6 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
I(In reply to Gregor Wagner [:gwagner] from comment #10)

Thanks for your guide. So I could run the test on Desktop.
However, I have another question.

Let me know how to run the test on not Desktop but Our Target Device.
Please advise it.

Thanks.

> (In reply to leo.bugzilla.gecko from comment #9)
> > (In reply to Gregor Wagner [:gwagner] from comment #6)
> >  
> > Please let me know how to run the tests.
> 
> You most likely have a git clone of our whole B2G project right? So gecko is
> compiled for the phone and you can't run tests for it.
> 
> The easiest way to run tests locally is to checkout the source for the
> desktop version, build it and run the tests there.
> 
> 1) getting the source:
> https://developer.mozilla.org/en-US/docs/Simple_Firefox_build
> hg clone https://hg.mozilla.org/mozilla-central
> 
> 2) build: https://developer.mozilla.org/en-US/docs/Configuring_Build_Options
> create a .mozconfig file and build the source.
> 
> 3) run the tests:
> you have to be in your gecko folder and ff-dbg is the object directory in my
> case. You probably have to change it.
> TEST_PATH=dom/contacts/tests/ make -C ff-dbg/ mochitest-plain
You need to log in before you can comment on or make changes to this bug.