Merge lp:~jamesh/bindwood/reorder-after-move into lp:bindwood

Proposed by James Henstridge
Status: Merged
Approved by: James Henstridge
Approved revision: 36
Merged at revision: 37
Proposed branch: lp:~jamesh/bindwood/reorder-after-move
Merge into: lp:bindwood
Diff against target: 77 lines (+52/-5)
2 files modified
modules/sync.jsm (+5/-5)
mozmill/tests/test_sync_from_couch.js (+47/-0)
To merge this branch: bzr merge lp:~jamesh/bindwood/reorder-after-move
Reviewer Review Type Date Requested Status
Manuel de la Peña (community) Approve
Eric Casteleijn (community) Approve
Review via email: mp+51677@code.launchpad.net

Commit message

Fix reorder_children() to handle the case where an expected child has been moved to a different folder.

Description of the change

This branch fixes a bug in the reorder_children() method of the synchroniser. This method takes a child list for a folder from CouchDB and tries to make the local folder match the ordering.

Prior to this branch, it assumed that if a child GUID existed locally we could assign an index for it in the parent folder. However, this would fail if the user had moved the bookmark to a different folder.

This branch fixes the function so that it only tries to reorder children if they are actually a child of the folder in question.

To post a comment you must log in.
Revision history for this message
Eric Casteleijn (thisfred) wrote :

+1

review: Approve
Revision history for this message
Manuel de la Peña (mandel) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/sync.jsm'
2--- modules/sync.jsm 2011-02-21 15:04:37 +0000
3+++ modules/sync.jsm 2011-03-01 02:26:54 +0000
4@@ -361,13 +361,13 @@
5 if (!child_id)
6 continue;
7
8- // Set the item's index.
9- bookmarksService.setItemIndex(child_id, idx++);
10-
11- // Remove from the list of existing children, if they exist.
12+ // If the child exists in the folder, assign its new
13+ // index.
14 var existing_idx = children.indexOf(child_id);
15- if (existing_idx >= 0)
16+ if (existing_idx >= 0) {
17+ bookmarksService.setItemIndex(child_id, idx++);
18 children.splice(existing_idx, 1);
19+ }
20 }
21 // Stick the remaining items at the end of the folder.
22 for each (var child_id in children) {
23
24=== modified file 'mozmill/tests/test_sync_from_couch.js'
25--- mozmill/tests/test_sync_from_couch.js 2011-02-22 11:02:10 +0000
26+++ mozmill/tests/test_sync_from_couch.js 2011-03-01 02:26:54 +0000
27@@ -302,3 +302,50 @@
28 jum.assertEquals(bm.bookmarksService.getIdForItemAt(parent_id, 3),
29 untracked_child);
30 };
31+
32+var test_reorder_after_move = function() {
33+ // Create parent folder and children.
34+ parent_doc = {
35+ _id: 'parent',
36+ record_type: 'http://www.freedesktop.org/wiki/Specifications/desktopcouch/folder',
37+ parent_guid: 'toolbar_profile_name',
38+ title: 'Folder',
39+ children: ['child1', 'child2', 'child3'],
40+ };
41+ synchroniser.processRecord(parent_doc);
42+ var parent_id = synchroniser.guid_to_id('parent');
43+
44+ for each (var child_name in ['child1' ,'child2', 'child3']) {
45+ synchroniser.processRecord({
46+ _id: child_name,
47+ record_type: 'http://www.freedesktop.org/wiki/Specifications/desktopcouch/bookmark',
48+ parent_guid: 'parent',
49+ title: child_name,
50+ uri: LOCAL_TEST_PAGE + '#' + child_name,
51+ });
52+ }
53+ synchroniser.reorder_children();
54+
55+ // Move one of the children to a different folder.
56+ var child2_id = synchroniser.guid_to_id('child2');
57+ bm.bookmarksService.moveItem(
58+ child2_id, bm.bookmarksService.bookmarksMenuFolder,
59+ bm.bookmarksService.DEFAULT_INDEX);
60+
61+ // Now impose a new ordering to the parent folder, including a
62+ // position for the moved item.
63+ parent_doc.children = ['child2', 'child3', 'child1'];
64+ synchroniser.processRecord(parent_doc);
65+ synchroniser.reorder_children();
66+
67+ // Children should now be in the requested order, with the
68+ // untracked child at the end.
69+ jum.assertEquals(bm.bookmarksService.getIdForItemAt(parent_id, 0),
70+ synchroniser.guid_to_id('child3'));
71+ jum.assertEquals(bm.bookmarksService.getIdForItemAt(parent_id, 1),
72+ synchroniser.guid_to_id('child1'));
73+
74+ // The moved bookmark should still be in its new parent folder.
75+ jum.assertEquals(bm.bookmarksService.getFolderIdForItem(child2_id),
76+ bm.bookmarksService.bookmarksMenuFolder);
77+};

Subscribers

People subscribed via source and target branches