summaryrefslogtreecommitdiffstats
path: root/services/sync/tests/unit/test_bookmark_decline_undecline.js
blob: 12139dd163bb03621e7d789ee16a3c15dc0d33e2 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

const { Service } = ChromeUtils.importESModule(
  "resource://services-sync/service.sys.mjs"
);

// A stored reference to the collection won't be valid after disabling.
function getBookmarkWBO(server, guid) {
  let coll = server.user("foo").collection("bookmarks");
  if (!coll) {
    return null;
  }
  return coll.wbo(guid);
}

add_task(async function test_decline_undecline() {
  let engine = Service.engineManager.get("bookmarks");
  let server = await serverForFoo(engine);
  await SyncTestingInfrastructure(server);

  try {
    let { guid: bzGuid } = await PlacesUtils.bookmarks.insert({
      parentGuid: PlacesUtils.bookmarks.menuGuid,
      url: "https://bugzilla.mozilla.org",
      index: PlacesUtils.bookmarks.DEFAULT_INDEX,
      title: "bugzilla",
    });

    ok(!getBookmarkWBO(server, bzGuid), "Shouldn't have been uploaded yet");
    await Service.sync();
    ok(getBookmarkWBO(server, bzGuid), "Should be present on server");

    engine.enabled = false;
    await Service.sync();
    ok(
      !getBookmarkWBO(server, bzGuid),
      "Shouldn't be present on server anymore"
    );

    engine.enabled = true;
    await Service.sync();
    ok(getBookmarkWBO(server, bzGuid), "Should be present on server again");
  } finally {
    await PlacesSyncUtils.bookmarks.reset();
    await promiseStopServer(server);
  }
});