test_bookmark_conflict.js (3754B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 EnableEngines(["bookmarks"]); 5 6 /* 7 * The list of phases mapped to their corresponding profiles. The object 8 * here must be in JSON format as it will get parsed by the Python 9 * testrunner. It is parsed by the YAML package, so it relatively flexible. 10 */ 11 var phases = { 12 phase1: "profile1", 13 phase2: "profile2", 14 phase3: "profile1", 15 phase4: "profile2", 16 }; 17 18 // the initial list of bookmarks to add to the browser 19 var bookmarksInitial = { 20 menu: [ 21 { folder: "foldera" }, 22 { folder: "folderb" }, 23 { folder: "folderc" }, 24 { folder: "folderd" }, 25 ], 26 27 "menu/foldera": [{ uri: "http://www.cnn.com", title: "CNN" }], 28 "menu/folderb": [{ uri: "http://www.apple.com", title: "Apple", tags: [] }], 29 "menu/folderc": [{ uri: "http://www.yahoo.com", title: "Yahoo" }], 30 31 "menu/folderd": [], 32 }; 33 34 // a list of bookmarks to delete during a 'delete' action on P2 35 var bookmarksToDelete = { 36 menu: [{ folder: "foldera" }, { folder: "folderb" }], 37 "menu/folderc": [{ uri: "http://www.yahoo.com", title: "Yahoo" }], 38 }; 39 40 // the modifications to make on P1, after P2 has synced, but before P1 has gotten 41 // P2's changes 42 var bookmarkMods = { 43 menu: [ 44 { folder: "foldera" }, 45 { folder: "folderb" }, 46 { folder: "folderc" }, 47 { folder: "folderd" }, 48 ], 49 50 // we move this child out of its folder (p1), after deleting the folder (p2) 51 // and expect the child to come back to p2 after sync. 52 "menu/foldera": [ 53 { 54 uri: "http://www.cnn.com", 55 title: "CNN", 56 changes: { location: "menu/folderd" }, 57 }, 58 ], 59 60 // we rename this child (p1) after deleting the folder (p2), and expect the child 61 // to be moved into great grandparent (menu) 62 "menu/folderb": [ 63 { 64 uri: "http://www.apple.com", 65 title: "Apple", 66 tags: [], 67 changes: { title: "Mac" }, 68 }, 69 ], 70 71 // we move this child (p1) after deleting the child (p2) and expect it to survive 72 "menu/folderc": [ 73 { 74 uri: "http://www.yahoo.com", 75 title: "Yahoo", 76 changes: { location: "menu/folderd" }, 77 }, 78 ], 79 80 "menu/folderd": [], 81 }; 82 83 // a list of bookmarks to delete during a 'delete' action 84 bookmarksToDelete = { 85 menu: [{ folder: "foldera" }, { folder: "folderb" }], 86 "menu/folderc": [{ uri: "http://www.yahoo.com", title: "Yahoo" }], 87 }; 88 89 // expected bookmark state after conflict resolution 90 var bookmarksExpected = { 91 menu: [ 92 { folder: "folderc" }, 93 { folder: "folderd" }, 94 { uri: "http://www.apple.com", title: "Mac" }, 95 ], 96 97 "menu/folderc": [], 98 99 "menu/folderd": [ 100 { uri: "http://www.cnn.com", title: "CNN" }, 101 { uri: "http://www.yahoo.com", title: "Yahoo" }, 102 ], 103 }; 104 105 // Add bookmarks to profile1 and sync. 106 Phase("phase1", [ 107 [Bookmarks.add, bookmarksInitial], 108 [Bookmarks.verify, bookmarksInitial], 109 [Sync], 110 [Bookmarks.verify, bookmarksInitial], 111 ]); 112 113 // Sync to profile2 and verify that the bookmarks are present. Delete 114 // bookmarks/folders, verify that it's not present, and sync 115 Phase("phase2", [ 116 [Sync], 117 [Bookmarks.verify, bookmarksInitial], 118 [Bookmarks.delete, bookmarksToDelete], 119 [Bookmarks.verifyNot, bookmarksToDelete], 120 [Sync], 121 ]); 122 123 // Using profile1, modify the bookmarks, and sync *after* the modification, 124 // and then sync again to propagate the reconciliation changes. 125 Phase("phase3", [ 126 [Bookmarks.verify, bookmarksInitial], 127 [Bookmarks.modify, bookmarkMods], 128 [Sync], 129 [Bookmarks.verify, bookmarksExpected], 130 [Bookmarks.verifyNot, bookmarksToDelete], 131 ]); 132 133 // Back in profile2, do a sync and verify that we're in the expected state 134 Phase("phase4", [ 135 [Sync], 136 [Bookmarks.verify, bookmarksExpected], 137 [Bookmarks.verifyNot, bookmarksToDelete], 138 ]);