summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/bookmarks/test_992901-backup-unsorted-hierarchy.js
blob: c835a3bd09095f7487b974369c2058587b1c9649 (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

/**
 * Checks that backups properly include all of the bookmarks if the hierarchy
 * in the database is unordered so that a hierarchy is defined before its
 * ancestor in the bookmarks table.
 */
add_task(async function () {
  let bms = await PlacesUtils.bookmarks.insertTree({
    guid: PlacesUtils.bookmarks.unfiledGuid,
    children: [
      {
        title: "bookmark",
        url: "http://mozilla.org",
      },
      {
        title: "f2",
        type: PlacesUtils.bookmarks.TYPE_FOLDER,
      },
      {
        title: "f1",
        type: PlacesUtils.bookmarks.TYPE_FOLDER,
      },
    ],
  });

  let bookmark = bms[0];
  let folder2 = bms[1];
  let folder1 = bms[2];
  bookmark.parentGuid = folder2.guid;
  await PlacesUtils.bookmarks.update(bookmark);

  folder2.parentGuid = folder1.guid;
  await PlacesUtils.bookmarks.update(folder2);

  // Create a backup.
  await PlacesBackups.create();

  // Remove the bookmarks, then restore the backup.
  await PlacesUtils.bookmarks.remove(folder1);
  await BookmarkJSONUtils.importFromFile(
    await PlacesBackups.getMostRecentBackup(),
    { replace: true }
  );

  info("Checking first level");
  let root = PlacesUtils.getFolderContents(
    PlacesUtils.bookmarks.unfiledGuid
  ).root;
  let level1 = root.getChild(0);
  Assert.equal(level1.title, "f1");
  info("Checking second level");
  PlacesUtils.asContainer(level1).containerOpen = true;
  let level2 = level1.getChild(0);
  Assert.equal(level2.title, "f2");
  info("Checking bookmark");
  PlacesUtils.asContainer(level2).containerOpen = true;
  bookmark = level2.getChild(0);
  Assert.equal(bookmark.title, "bookmark");
  level2.containerOpen = false;
  level1.containerOpen = false;
  root.containerOpen = false;
});