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

/**
 * Test that the a new bookmark is correctly selected after being created via
 * the bookmark dialog.
 */
"use strict";

let bookmarks = [
  {
    url: "https://example1.com",
    title: "bm1",
  },
  {
    url: "https://example2.com",
    title: "bm2",
  },
  {
    url: "https://example3.com",
    title: "bm3",
  },
];

add_task(async function test_open_bookmark_from_library() {
  let bm = await PlacesUtils.bookmarks.insertTree({
    guid: PlacesUtils.bookmarks.unfiledGuid,
    children: bookmarks,
  });

  let library = await promiseLibrary("UnfiledBookmarks");

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

  let bmLibrary = library.ContentTree.view.view.nodeForTreeIndex(1);
  Assert.equal(
    bmLibrary.title,
    bm[1].title,
    "EditBookmark: Found bookmark in the right pane"
  );

  library.ContentTree.view.selectNode(bmLibrary);

  let beforeUpdatedPRTime;
  await withBookmarksDialog(
    false,
    async () => {
      // Open the context menu.
      let placesContext = library.document.getElementById("placesContext");
      let promisePopup = BrowserTestUtils.waitForEvent(
        placesContext,
        "popupshown"
      );
      synthesizeClickOnSelectedTreeCell(library.ContentTree.view, {
        button: 2,
        type: "contextmenu",
      });

      await promisePopup;
      let properties = library.document.getElementById(
        "placesContext_new:bookmark"
      );
      placesContext.activateItem(properties, {});
    },
    async dialogWin => {
      beforeUpdatedPRTime = Date.now() * 1000;

      fillBookmarkTextField(
        "editBMPanel_locationField",
        "https://example4.com/",
        dialogWin,
        false
      );

      EventUtils.synthesizeKey("VK_RETURN", {}, dialogWin);
    }
  );
  let node = library.ContentTree.view.selectedNode;
  Assert.ok(node, "EditBookmark: Should have a selectedNode");
  Assert.equal(
    node.uri,
    "https://example4.com/",
    "EditBookmark: Should have selected the newly created bookmark"
  );
  Assert.greater(
    node.lastModified,
    beforeUpdatedPRTime,
    "EditBookmark: The lastModified should be greater than the time of before updating"
  );
  await PlacesUtils.bookmarks.eraseEverything();
});