tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_PageActions_bookmark.js (4815B)


      1 "use strict";
      2 
      3 add_task(async function starButtonCtrlClick() {
      4  // Open a unique page.
      5  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
      6  let url = "http://example.com/browser_page_action_star_button";
      7  await BrowserTestUtils.withNewTab(url, async () => {
      8    StarUI._createPanelIfNeeded();
      9    // The button ignores activation while the bookmarked status is being
     10    // updated. So, wait for it to finish updating.
     11    await TestUtils.waitForCondition(
     12      () => BookmarkingUI.status != BookmarkingUI.STATUS_UPDATING
     13    );
     14 
     15    const popup = document.getElementById("editBookmarkPanel");
     16    const starButtonBox = document.getElementById("star-button-box");
     17 
     18    let shownPromise = promisePanelShown(popup);
     19    EventUtils.synthesizeMouseAtCenter(starButtonBox, { ctrlKey: true });
     20    await shownPromise;
     21    ok(true, "Panel shown after button pressed");
     22 
     23    let hiddenPromise = promisePanelHidden(popup);
     24    document.getElementById("editBookmarkPanelRemoveButton").click();
     25    await hiddenPromise;
     26  });
     27 });
     28 
     29 add_task(async function bookmark() {
     30  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     31  const url = "http://example.com/browser_page_action_menu";
     32 
     33  const win = await BrowserTestUtils.openNewBrowserWindow();
     34  registerCleanupFunction(async () => {
     35    await BrowserTestUtils.closeWindow(win);
     36  });
     37 
     38  await BrowserTestUtils.withNewTab(
     39    { gBrowser: win.gBrowser, url },
     40    async () => {
     41      // The bookmark button should not be starred.
     42      const bookmarkButton =
     43        win.BrowserPageActions.urlbarButtonNodeForActionID("bookmark");
     44      Assert.ok(!bookmarkButton.hasAttribute("starred"));
     45 
     46      info("Click the button.");
     47      // The button ignores activation while the bookmarked status is being
     48      // updated. So, wait for it to finish updating.
     49      await TestUtils.waitForCondition(
     50        () => BookmarkingUI.status != BookmarkingUI.STATUS_UPDATING
     51      );
     52      const starUIPanel = win.StarUI.panel;
     53      let panelShown = BrowserTestUtils.waitForPopupEvent(starUIPanel, "shown");
     54      EventUtils.synthesizeMouseAtCenter(bookmarkButton, {}, win);
     55      await panelShown;
     56      is(
     57        await PlacesUtils.bookmarks.fetch({ url }),
     58        null,
     59        "Bookmark has not been created before save."
     60      );
     61 
     62      // The bookmark button should now be starred.
     63      Assert.equal(bookmarkButton.firstChild.getAttribute("starred"), "true");
     64 
     65      info("Save the bookmark.");
     66      const onItemAddedPromise = PlacesTestUtils.waitForNotification(
     67        "bookmark-added",
     68        events => events.some(event => event.url == url)
     69      );
     70      starUIPanel.hidePopup();
     71      await onItemAddedPromise;
     72 
     73      info("Click it again.");
     74      // The button ignores activation while the bookmarked status is being
     75      // updated. So, wait for it to finish updating.
     76      await TestUtils.waitForCondition(
     77        () => BookmarkingUI.status != BookmarkingUI.STATUS_UPDATING
     78      );
     79      panelShown = BrowserTestUtils.waitForPopupEvent(starUIPanel, "shown");
     80      EventUtils.synthesizeMouseAtCenter(bookmarkButton, {}, win);
     81      await panelShown;
     82 
     83      info("Remove the bookmark.");
     84      const onItemRemovedPromise = PlacesTestUtils.waitForNotification(
     85        "bookmark-removed",
     86        events => events.some(event => event.url == url)
     87      );
     88      win.StarUI._element("editBookmarkPanelRemoveButton").click();
     89      await onItemRemovedPromise;
     90    }
     91  );
     92 });
     93 
     94 add_task(async function bookmarkNoEditDialog() {
     95  const url =
     96    // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     97    "http://example.com/browser_page_action_menu_no_edit_dialog";
     98 
     99  await SpecialPowers.pushPrefEnv({
    100    set: [["browser.bookmarks.editDialog.showForNewBookmarks", false]],
    101  });
    102  const win = await BrowserTestUtils.openNewBrowserWindow();
    103  registerCleanupFunction(async () => {
    104    await BrowserTestUtils.closeWindow(win);
    105    await PlacesUtils.bookmarks.eraseEverything();
    106  });
    107 
    108  await BrowserTestUtils.withNewTab(
    109    { gBrowser: win.gBrowser, url },
    110    async () => {
    111      info("Click the button.");
    112      // The button ignores activation while the bookmarked status is being
    113      // updated. So, wait for it to finish updating.
    114      await TestUtils.waitForCondition(
    115        () => BookmarkingUI.status != BookmarkingUI.STATUS_UPDATING
    116      );
    117      const bookmarkButton = win.document.getElementById(
    118        BrowserPageActions.urlbarButtonNodeIDForActionID("bookmark")
    119      );
    120 
    121      // The bookmark should be saved immediately after clicking the star.
    122      const onItemAddedPromise = PlacesTestUtils.waitForNotification(
    123        "bookmark-added",
    124        events => events.some(event => event.url == url)
    125      );
    126      EventUtils.synthesizeMouseAtCenter(bookmarkButton, {}, win);
    127      await onItemAddedPromise;
    128    }
    129  );
    130 });