summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/pageActions/browser_PageActions_bookmark.js
blob: 057aadf40c0afa5695c8d006ccb2e1ce1f95e644 (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
"use strict";

add_task(async function starButtonCtrlClick() {
  // Open a unique page.
  let url = "http://example.com/browser_page_action_star_button";
  await BrowserTestUtils.withNewTab(url, async () => {
    StarUI._createPanelIfNeeded();
    // The button ignores activation while the bookmarked status is being
    // updated. So, wait for it to finish updating.
    await TestUtils.waitForCondition(
      () => BookmarkingUI.status != BookmarkingUI.STATUS_UPDATING
    );

    const popup = document.getElementById("editBookmarkPanel");
    const starButtonBox = document.getElementById("star-button-box");

    let shownPromise = promisePanelShown(popup);
    EventUtils.synthesizeMouseAtCenter(starButtonBox, { ctrlKey: true });
    await shownPromise;
    ok(true, "Panel shown after button pressed");

    let hiddenPromise = promisePanelHidden(popup);
    document.getElementById("editBookmarkPanelRemoveButton").click();
    await hiddenPromise;
  });
});

add_task(async function bookmark() {
  // Open a unique page.
  let url = "http://example.com/browser_page_action_menu";
  await BrowserTestUtils.withNewTab(url, async () => {
    // The bookmark button should read "Bookmark this page ([shortcut])" and not
    // be starred.
    let bookmarkButton = BrowserPageActions.urlbarButtonNodeForActionID(
      "bookmark"
    );
    let tooltipText = bookmarkButton.getAttribute("tooltiptext");
    Assert.ok(
      tooltipText.startsWith("Bookmark this page"),
      `Expecting the tooltip text to be updated. Tooltip text: ${tooltipText}`
    );
    Assert.ok(!bookmarkButton.hasAttribute("starred"));

    info("Click the button.");
    // The button ignores activation while the bookmarked status is being
    // updated. So, wait for it to finish updating.
    await TestUtils.waitForCondition(
      () => BookmarkingUI.status != BookmarkingUI.STATUS_UPDATING
    );
    let onItemAddedPromise = PlacesTestUtils.waitForNotification(
      "bookmark-added",
      events => events.some(event => event.url == url),
      "places"
    );
    let promise = BrowserTestUtils.waitForPopupEvent(StarUI.panel, "shown");
    EventUtils.synthesizeMouseAtCenter(bookmarkButton, {});
    await promise;
    await onItemAddedPromise;

    Assert.equal(
      BookmarkingUI.starBox.getAttribute("open"),
      "true",
      "Star has open attribute"
    );
    // The bookmark button should now read "Edit this bookmark ([shortcut])" and
    // be starred.
    tooltipText = bookmarkButton.getAttribute("tooltiptext");
    Assert.ok(
      tooltipText.startsWith("Edit this bookmark"),
      `Expecting the tooltip text to be updated. Tooltip text: ${tooltipText}`
    );
    Assert.equal(bookmarkButton.firstChild.getAttribute("starred"), "true");

    StarUI.panel.hidePopup();
    Assert.ok(
      !BookmarkingUI.starBox.hasAttribute("open"),
      "Star no longer has open attribute"
    );

    info("Click it again.");
    // The button ignores activation while the bookmarked status is being
    // updated. So, wait for it to finish updating.
    await TestUtils.waitForCondition(
      () => BookmarkingUI.status != BookmarkingUI.STATUS_UPDATING
    );
    promise = BrowserTestUtils.waitForPopupEvent(StarUI.panel, "shown");
    EventUtils.synthesizeMouseAtCenter(bookmarkButton, {});
    await promise;

    let onItemRemovedPromise = PlacesTestUtils.waitForNotification(
      "bookmark-removed",
      events => events.some(event => event.url == url),
      "places"
    );
    // Click the remove-bookmark button in the panel.
    StarUI._element("editBookmarkPanelRemoveButton").click();
    // Wait for the bookmark to be removed before continuing.
    await onItemRemovedPromise;

    // Check there's no contextual menu on the button.
    let contextMenuPromise = promisePopupNotShown("pageActionContextMenu");
    // The button ignores activation while the bookmarked status is being
    // updated. So, wait for it to finish updating.
    await TestUtils.waitForCondition(
      () => BookmarkingUI.status != BookmarkingUI.STATUS_UPDATING
    );
    EventUtils.synthesizeMouseAtCenter(bookmarkButton, {
      type: "contextmenu",
      button: 2,
    });
    await contextMenuPromise;
  });
});