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

/**
 * Test that the a website can be bookmarked from a private window.
 */
"use strict";

const TEST_URL = "about:buildconfig";

// Cleanup.
registerCleanupFunction(async () => {
  await PlacesUtils.bookmarks.eraseEverything();
});

add_task(async function test_add_bookmark_from_private_window() {
  let win = await BrowserTestUtils.openNewBrowserWindow({ private: true });
  let tab = await BrowserTestUtils.openNewForegroundTab(win.gBrowser, TEST_URL);

  registerCleanupFunction(async () => {
    BrowserTestUtils.removeTab(tab);
    await BrowserTestUtils.closeWindow(win);
  });

  // Open the bookmark panel.
  win.StarUI._createPanelIfNeeded();
  let bookmarkPanel = win.document.getElementById("editBookmarkPanel");
  let shownPromise = promisePopupShown(bookmarkPanel);
  let bookmarkAddedPromise = PlacesTestUtils.waitForNotification(
    "bookmark-added",
    events => events.some(({ url }) => url === TEST_URL)
  );
  let bookmarkStar = win.BookmarkingUI.star;
  bookmarkStar.click();
  await shownPromise;

  // Check if the bookmark star changes its state after click.
  Assert.equal(
    bookmarkStar.getAttribute("starred"),
    "true",
    "Bookmark star changed its state correctly."
  );

  // Close the bookmark panel.
  let hiddenPromise = promisePopupHidden(bookmarkPanel);
  let doneButton = win.document.getElementById("editBookmarkPanelDoneButton");
  doneButton.click();
  await hiddenPromise;
  await bookmarkAddedPromise;

  let bm = await PlacesUtils.bookmarks.fetch({ url: TEST_URL });
  Assert.equal(
    bm.url,
    TEST_URL,
    "The bookmark was successfully saved in the database."
  );
});