summaryrefslogtreecommitdiffstats
path: root/browser/components/places/tests/browser/browser_bookmark_current_tabs.js
blob: a6dd77d4c5b8f573ee8d7c447e0e5cb1ba07a8a0 (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
/* 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/. */

const { MockRegistrar } = ChromeUtils.importESModule(
  "resource://testing-common/MockRegistrar.sys.mjs"
);

add_setup(() => {
  let mockPromptService = {
    confirmExBC() {
      return 0;
    },
    QueryInterface: ChromeUtils.generateQI(["nsIPromptService"]),
  };
  let mockPromptServiceCID = MockRegistrar.register(
    "@mozilla.org/prompter;1",
    mockPromptService
  );
  registerCleanupFunction(() => {
    MockRegistrar.unregister(mockPromptServiceCID);
  });
});

add_task(async function bookmarkPage() {
  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    "https://user:pass@example.com/"
  );

  let promiseBookmark = PlacesTestUtils.waitForNotification(
    "bookmark-added",
    () => true
  );
  PlacesCommandHook.bookmarkPage();
  await promiseBookmark;

  let bookmark = await PlacesUtils.bookmarks.fetch({
    url: "https://example.com/",
  });
  Assert.ok(bookmark, "Found the expected bookmark");

  BrowserTestUtils.removeTab(tab);
  await PlacesUtils.bookmarks.eraseEverything();
});

add_task(async function bookmarkTabs() {
  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    "https://user:pass@example.com/"
  );

  await withBookmarksDialog(
    false,
    PlacesCommandHook.bookmarkTabs,
    async dialog => {
      dialog.document
        .getElementById("bookmarkpropertiesdialog")
        .getButton("accept")
        .click();
    }
  );

  let bookmark = await PlacesUtils.bookmarks.fetch({
    url: "https://example.com/",
  });
  Assert.ok(bookmark, "Found the expected bookmark");

  BrowserTestUtils.removeTab(tab);
  await PlacesUtils.bookmarks.eraseEverything();
});