summaryrefslogtreecommitdiffstats
path: root/browser/components/places/tests/browser/browser_bookmarkProperties_bookmarkAllTabs.js
blob: 805f9464e314a8a5bf9e2c90937dabc6996f230f (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
"use strict";

const TEST_URLS = ["about:robots", "about:mozilla"];

add_task(async function bookmark_all_tabs() {
  let tabs = [];
  for (let url of TEST_URLS) {
    tabs.push(await BrowserTestUtils.openNewForegroundTab(gBrowser, url));
  }
  registerCleanupFunction(async function () {
    for (let tab of tabs) {
      BrowserTestUtils.removeTab(tab);
    }
    await PlacesUtils.bookmarks.eraseEverything();
  });

  await withBookmarksDialog(
    false,
    function open() {
      document.getElementById("Browser:BookmarkAllTabs").doCommand();
    },
    async dialog => {
      let acceptBtn = dialog.document
        .getElementById("bookmarkpropertiesdialog")
        .getButton("accept");
      Assert.ok(!acceptBtn.disabled, "Accept button is enabled");

      let namepicker = dialog.document.getElementById("editBMPanel_namePicker");
      Assert.ok(!namepicker.readOnly, "Name field is writable");
      let folderName = dialog.document
        .getElementById("stringBundle")
        .getString("bookmarkAllTabsDefault");
      Assert.equal(namepicker.value, folderName, "Name field is correct.");

      let promiseBookmarkAdded =
        PlacesTestUtils.waitForNotification("bookmark-added");

      fillBookmarkTextField("editBMPanel_namePicker", "folder", dialog);

      let folderPicker = dialog.document.getElementById(
        "editBMPanel_folderMenuList"
      );

      let defaultParentGuid = await PlacesUIUtils.defaultParentGuid;
      // Check the initial state of the folder picker.
      await TestUtils.waitForCondition(
        () => folderPicker.getAttribute("selectedGuid") == defaultParentGuid,
        "The folder is the expected one."
      );

      EventUtils.synthesizeKey("VK_RETURN", {}, dialog);
      await promiseBookmarkAdded;
      for (const url of TEST_URLS) {
        const { parentGuid } = await PlacesUtils.bookmarks.fetch({ url });
        const folder = await PlacesUtils.bookmarks.fetch({
          guid: parentGuid,
        });
        is(
          folder.title,
          "folder",
          "Should have created the bookmark in the right folder."
        );
      }
    }
  );
});