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

/* test that copying a non movable query or folder shortcut makes a new query with the same url, not a deep copy */

const QUERY_URL = "place:sort=8&maxResults=10";

add_task(async function copy_toolbar_shortcut() {
  await promisePlacesInitComplete();

  let library = await promiseLibrary();

  registerCleanupFunction(async () => {
    library.close();
    await PlacesUtils.bookmarks.eraseEverything();
  });

  library.PlacesOrganizer.selectLeftPaneBuiltIn("BookmarksToolbar");

  await promiseClipboard(function () {
    library.PlacesOrganizer._places.controller.copy();
  }, PlacesUtils.TYPE_X_MOZ_PLACE);

  library.PlacesOrganizer.selectLeftPaneBuiltIn("UnfiledBookmarks");

  await library.ContentTree.view.controller.paste();

  let toolbarCopyNode = library.ContentTree.view.view.nodeForTreeIndex(0);
  is(
    toolbarCopyNode.type,
    Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER_SHORTCUT,
    "copy is still a folder shortcut"
  );

  await PlacesUtils.bookmarks.remove(toolbarCopyNode.bookmarkGuid);
  library.PlacesOrganizer.selectLeftPaneBuiltIn("BookmarksToolbar");
  is(
    library.PlacesOrganizer._places.selectedNode.type,
    Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER_SHORTCUT,
    "original is still a folder shortcut"
  );
});

add_task(async function copy_mobile_shortcut() {
  await SpecialPowers.pushPrefEnv({
    set: [["browser.bookmarks.showMobileBookmarks", true]],
  });
  await promisePlacesInitComplete();

  let library = await promiseLibrary();

  registerCleanupFunction(async () => {
    library.close();
    await PlacesUtils.bookmarks.eraseEverything();
  });

  library.PlacesOrganizer.selectLeftPaneContainerByHierarchy([
    PlacesUtils.virtualAllBookmarksGuid,
    PlacesUtils.bookmarks.virtualMobileGuid,
  ]);

  await promiseClipboard(function () {
    library.PlacesOrganizer._places.controller.copy();
  }, PlacesUtils.TYPE_X_MOZ_PLACE);

  library.PlacesOrganizer.selectLeftPaneBuiltIn("UnfiledBookmarks");

  await library.ContentTree.view.controller.paste();

  let mobileCopyNode = library.ContentTree.view.view.nodeForTreeIndex(0);
  is(
    mobileCopyNode.type,
    Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER_SHORTCUT,
    "copy is still a folder shortcut"
  );

  await PlacesUtils.bookmarks.remove(mobileCopyNode.bookmarkGuid);
  library.PlacesOrganizer.selectLeftPaneBuiltIn("BookmarksToolbar");
  is(
    library.PlacesOrganizer._places.selectedNode.type,
    Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER_SHORTCUT,
    "original is still a folder shortcut"
  );
});

add_task(async function copy_history_query() {
  let library = await promiseLibrary();

  library.PlacesOrganizer.selectLeftPaneBuiltIn("History");

  await promiseClipboard(function () {
    library.PlacesOrganizer._places.controller.copy();
  }, PlacesUtils.TYPE_X_MOZ_PLACE);

  library.PlacesOrganizer.selectLeftPaneBuiltIn("UnfiledBookmarks");
  await library.ContentTree.view.controller.paste();

  let historyCopyNode = library.ContentTree.view.view.nodeForTreeIndex(0);
  is(
    historyCopyNode.type,
    Ci.nsINavHistoryResultNode.RESULT_TYPE_QUERY,
    "copy is still a query"
  );

  await PlacesUtils.bookmarks.remove(historyCopyNode.bookmarkGuid);
  library.PlacesOrganizer.selectLeftPaneBuiltIn("History");
  is(
    library.PlacesOrganizer._places.selectedNode.type,
    Ci.nsINavHistoryResultNode.RESULT_TYPE_QUERY,
    "original is still a query"
  );
});