summaryrefslogtreecommitdiffstats
path: root/services/sync/tests/tps/test_bookmark_conflict.js
blob: 2832bded5d85af12194beb19b7c5617f0c473a82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

EnableEngines(["bookmarks"]);

/*
 * The list of phases mapped to their corresponding profiles.  The object
 * here must be in JSON format as it will get parsed by the Python
 * testrunner. It is parsed by the YAML package, so it relatively flexible.
 */
var phases = {
  phase1: "profile1",
  phase2: "profile2",
  phase3: "profile1",
  phase4: "profile2",
};

// the initial list of bookmarks to add to the browser
var bookmarksInitial = {
  menu: [
    { folder: "foldera" },
    { folder: "folderb" },
    { folder: "folderc" },
    { folder: "folderd" },
  ],

  "menu/foldera": [{ uri: "http://www.cnn.com", title: "CNN" }],
  "menu/folderb": [{ uri: "http://www.apple.com", title: "Apple", tags: [] }],
  "menu/folderc": [{ uri: "http://www.yahoo.com", title: "Yahoo" }],

  "menu/folderd": [],
};

// a list of bookmarks to delete during a 'delete' action on P2
var bookmarksToDelete = {
  menu: [{ folder: "foldera" }, { folder: "folderb" }],
  "menu/folderc": [{ uri: "http://www.yahoo.com", title: "Yahoo" }],
};

// the modifications to make on P1, after P2 has synced, but before P1 has gotten
// P2's changes
var bookmarkMods = {
  menu: [
    { folder: "foldera" },
    { folder: "folderb" },
    { folder: "folderc" },
    { folder: "folderd" },
  ],

  // we move this child out of its folder (p1), after deleting the folder (p2)
  // and expect the child to come back to p2 after sync.
  "menu/foldera": [
    {
      uri: "http://www.cnn.com",
      title: "CNN",
      changes: { location: "menu/folderd" },
    },
  ],

  // we rename this child (p1) after deleting the folder (p2), and expect the child
  // to be moved into great grandparent (menu)
  "menu/folderb": [
    {
      uri: "http://www.apple.com",
      title: "Apple",
      tags: [],
      changes: { title: "Mac" },
    },
  ],

  // we move this child (p1) after deleting the child (p2) and expect it to survive
  "menu/folderc": [
    {
      uri: "http://www.yahoo.com",
      title: "Yahoo",
      changes: { location: "menu/folderd" },
    },
  ],

  "menu/folderd": [],
};

// a list of bookmarks to delete during a 'delete' action
bookmarksToDelete = {
  menu: [{ folder: "foldera" }, { folder: "folderb" }],
  "menu/folderc": [{ uri: "http://www.yahoo.com", title: "Yahoo" }],
};

// expected bookmark state after conflict resolution
var bookmarksExpected = {
  menu: [
    { folder: "folderc" },
    { folder: "folderd" },
    { uri: "http://www.apple.com", title: "Mac" },
  ],

  "menu/folderc": [],

  "menu/folderd": [
    { uri: "http://www.cnn.com", title: "CNN" },
    { uri: "http://www.yahoo.com", title: "Yahoo" },
  ],
};

// Add bookmarks to profile1 and sync.
Phase("phase1", [
  [Bookmarks.add, bookmarksInitial],
  [Bookmarks.verify, bookmarksInitial],
  [Sync],
  [Bookmarks.verify, bookmarksInitial],
]);

// Sync to profile2 and verify that the bookmarks are present. Delete
// bookmarks/folders, verify that it's not present, and sync
Phase("phase2", [
  [Sync],
  [Bookmarks.verify, bookmarksInitial],
  [Bookmarks.delete, bookmarksToDelete],
  [Bookmarks.verifyNot, bookmarksToDelete],
  [Sync],
]);

// Using profile1, modify the bookmarks, and sync *after* the modification,
// and then sync again to propagate the reconciliation changes.
Phase("phase3", [
  [Bookmarks.verify, bookmarksInitial],
  [Bookmarks.modify, bookmarkMods],
  [Sync],
  [Bookmarks.verify, bookmarksExpected],
  [Bookmarks.verifyNot, bookmarksToDelete],
]);

// Back in profile2, do a sync and verify that we're in the expected state
Phase("phase4", [
  [Sync],
  [Bookmarks.verify, bookmarksExpected],
  [Bookmarks.verifyNot, bookmarksToDelete],
]);