summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/unit/test_1105866.js
blob: c387d9e853b5cb80147b233aa46467d9878481d2 (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
add_task(async function test_folder_shortcuts() {
  let shortcutInfo = await PlacesUtils.bookmarks.insert({
    type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
    url: `place:parent=${PlacesUtils.bookmarks.toolbarGuid}`,
  });

  let unfiledRoot = PlacesUtils.getFolderContents(
    PlacesUtils.bookmarks.unfiledGuid
  ).root;
  let shortcutNode = unfiledRoot.getChild(unfiledRoot.childCount - 1);
  Assert.strictEqual(
    shortcutNode.itemId,
    await PlacesTestUtils.promiseItemId(shortcutInfo.guid)
  );
  Assert.strictEqual(
    PlacesUtils.asQuery(shortcutNode).folderItemId,
    await PlacesTestUtils.promiseItemId(PlacesUtils.bookmarks.toolbarGuid)
  );
  Assert.strictEqual(shortcutNode.bookmarkGuid, shortcutInfo.guid);
  Assert.strictEqual(
    PlacesUtils.asQuery(shortcutNode).targetFolderGuid,
    PlacesUtils.bookmarks.toolbarGuid
  );

  // test that a node added incrementally also behaves just as well.
  shortcutInfo = await PlacesUtils.bookmarks.insert({
    type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
    url: `place:parent=${PlacesUtils.bookmarks.menuGuid}`,
  });
  shortcutNode = unfiledRoot.getChild(unfiledRoot.childCount - 1);
  Assert.strictEqual(
    shortcutNode.itemId,
    await PlacesTestUtils.promiseItemId(shortcutInfo.guid)
  );
  Assert.strictEqual(
    PlacesUtils.asQuery(shortcutNode).folderItemId,
    await PlacesTestUtils.promiseItemId(PlacesUtils.bookmarks.menuGuid)
  );
  Assert.strictEqual(shortcutNode.bookmarkGuid, shortcutInfo.guid);
  Assert.strictEqual(
    PlacesUtils.asQuery(shortcutNode).targetFolderGuid,
    PlacesUtils.bookmarks.menuGuid
  );

  unfiledRoot.containerOpen = false;
});

add_task(async function test_plain_folder() {
  let folderInfo = await PlacesUtils.bookmarks.insert({
    type: PlacesUtils.bookmarks.TYPE_FOLDER,
    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
  });

  let unfiledRoot = PlacesUtils.getFolderContents(
    PlacesUtils.bookmarks.unfiledGuid
  ).root;
  let lastChild = unfiledRoot.getChild(unfiledRoot.childCount - 1);
  Assert.strictEqual(lastChild.bookmarkGuid, folderInfo.guid);
  Assert.strictEqual(
    PlacesUtils.asQuery(lastChild).targetFolderGuid,
    folderInfo.guid
  );
});

add_task(async function test_non_item_query() {
  let options = PlacesUtils.history.getNewQueryOptions();
  let root = PlacesUtils.history.executeQuery(
    PlacesUtils.history.getNewQuery(),
    options
  ).root;
  Assert.strictEqual(root.itemId, -1);
  Assert.strictEqual(PlacesUtils.asQuery(root).folderItemId, -1);
  Assert.strictEqual(root.bookmarkGuid, "");
  Assert.strictEqual(PlacesUtils.asQuery(root).targetFolderGuid, "");
});