summaryrefslogtreecommitdiffstats
path: root/browser/components/places/tests/browser/browser_library_openFlatContainer.js
blob: 1d9cc61f2fabed369b4e1abdc4bd6d13a4dbdfd3 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

/**
 * Test opening a flat container in the right pane even if its parent in the
 * left pane is closed.
 */

var library;

add_setup(async function () {
  await PlacesUtils.bookmarks.eraseEverything();
  await PlacesUtils.history.clear();

  registerCleanupFunction(async function () {
    await PlacesUtils.bookmarks.eraseEverything();
    await PlacesUtils.history.clear();
    await promiseLibraryClosed(library);
  });
});

add_task(async function test_open_built_in_folder() {
  let bm = await PlacesUtils.bookmarks.insert({
    parentGuid: PlacesUtils.bookmarks.menuGuid,
    title: "testBM",
    url: "http://example.com/1",
  });

  library = await promiseLibrary("AllBookmarks");

  library.ContentTree.view.selectItems([PlacesUtils.bookmarks.menuGuid]);

  synthesizeClickOnSelectedTreeCell(library.ContentTree.view, {
    clickCount: 2,
  });

  Assert.equal(
    library.PlacesOrganizer._places.selectedNode.bookmarkGuid,
    PlacesUtils.bookmarks.virtualMenuGuid,
    "Should have the bookmarks menu selected in the left pane."
  );
  Assert.equal(
    library.ContentTree.view.view.nodeForTreeIndex(0).bookmarkGuid,
    bm.guid,
    "Should have the expected bookmark selected in the right pane"
  );
});

add_task(async function test_open_new_folder_in_unfiled() {
  let bookmarks = await PlacesUtils.bookmarks.insertTree({
    guid: PlacesUtils.bookmarks.unfiledGuid,
    children: [
      {
        title: "Folder",
        type: PlacesUtils.bookmarks.TYPE_FOLDER,
        children: [
          {
            title: "Bookmark",
            url: "http://example.com",
          },
        ],
      },
    ],
  });

  library.PlacesOrganizer.selectLeftPaneBuiltIn("UnfiledBookmarks");

  // Ensure the container is closed.
  library.PlacesOrganizer._places.selectedNode.containerOpen = false;

  let folderNode = library.ContentTree.view.view.nodeForTreeIndex(0);
  Assert.equal(
    folderNode.bookmarkGuid,
    bookmarks[0].guid,
    "Found the expected folder in the right pane"
  );
  // Select the folder node in the right pane.
  library.ContentTree.view.selectNode(folderNode);

  synthesizeClickOnSelectedTreeCell(library.ContentTree.view, {
    clickCount: 2,
  });

  Assert.equal(
    library.ContentTree.view.view.nodeForTreeIndex(0).bookmarkGuid,
    bookmarks[1].guid,
    "Found the expected bookmark in the right pane"
  );
});

add_task(async function test_open_history_query() {
  const todayTitle = PlacesUtils.getString("finduri-AgeInDays-is-0");
  await PlacesTestUtils.addVisits([
    {
      uri: "http://example.com",
      title: "Whittingtons",
    },
  ]);

  library.PlacesOrganizer.selectLeftPaneBuiltIn("History");

  // Ensure the container is closed.
  library.PlacesOrganizer._places.selectedNode.containerOpen = false;

  let query = library.ContentTree.view.view.nodeForTreeIndex(0);
  Assert.equal(query.title, todayTitle, "Should have the today query");

  library.ContentTree.view.selectNode(query);

  synthesizeClickOnSelectedTreeCell(library.ContentTree.view, {
    clickCount: 2,
  });

  Assert.equal(
    library.PlacesOrganizer._places.selectedNode.title,
    todayTitle,
    "Should have selected the today query in the left-pane."
  );
  Assert.equal(
    library.ContentTree.view.view.nodeForTreeIndex(0).title,
    "Whittingtons",
    "Found the expected history item in the right pane"
  );
});