tor-browser

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

browser_bookmarks_empty_message.js (2893B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 async function emptyToolbarMessageVisible(visible, win = window) {
      7  info("Empty toolbar message should be " + (visible ? "visible" : "hidden"));
      8  let emptyMessage = win.document.getElementById("personal-toolbar-empty");
      9  await BrowserTestUtils.waitForMutationCondition(
     10    emptyMessage,
     11    { attributes: true, attributeFilter: ["hidden"] },
     12    () => emptyMessage.hidden != visible
     13  );
     14 }
     15 
     16 add_task(async function empty_message_on_non_empty_bookmarks_toolbar() {
     17  await resetCustomization();
     18  ok(CustomizableUI.inDefaultState, "Default state to begin");
     19 
     20  await SpecialPowers.pushPrefEnv({
     21    set: [["browser.toolbars.bookmarks.visibility", "always"]],
     22  });
     23 
     24  CustomizableUI.removeWidgetFromArea("import-button");
     25  CustomizableUI.removeWidgetFromArea("personal-bookmarks");
     26  CustomizableUI.addWidgetToArea(
     27    "bookmarks-menu-button",
     28    CustomizableUI.AREA_BOOKMARKS,
     29    0
     30  );
     31 
     32  let newWin = await BrowserTestUtils.openNewBrowserWindow();
     33  let doc = newWin.document;
     34  ok(
     35    BrowserTestUtils.isVisible(doc.getElementById("PersonalToolbar")),
     36    "Personal toolbar should be visible"
     37  );
     38  ok(
     39    doc.getElementById("personal-toolbar-empty").hidden,
     40    "Empty message should be hidden"
     41  );
     42 
     43  await BrowserTestUtils.closeWindow(newWin);
     44  await resetCustomization();
     45 });
     46 
     47 add_task(async function empty_message_after_customization() {
     48  // ensure There's something on the toolbar.
     49  let bm = await PlacesUtils.bookmarks.insert({
     50    url: "https://mozilla.org/",
     51    title: "test",
     52    parentGuid: PlacesUtils.bookmarks.toolbarGuid,
     53  });
     54  registerCleanupFunction(() => PlacesUtils.bookmarks.remove(bm));
     55  ok(CustomizableUI.inDefaultState, "Default state to begin");
     56 
     57  // Open window with a visible toolbar.
     58  await SpecialPowers.pushPrefEnv({
     59    set: [["browser.toolbars.bookmarks.visibility", "always"]],
     60  });
     61  let newWin = await BrowserTestUtils.openNewBrowserWindow();
     62  let doc = newWin.document;
     63  let toolbar = doc.getElementById("PersonalToolbar");
     64  ok(BrowserTestUtils.isVisible(toolbar), "Personal toolbar should be visible");
     65  await emptyToolbarMessageVisible(false, newWin);
     66 
     67  // Force a Places view uninit through customization.
     68  CustomizableUI.removeWidgetFromArea("personal-bookmarks");
     69  await resetCustomization();
     70  // Show the toolbar again.
     71  setToolbarVisibility(toolbar, true, false, false);
     72  ok(BrowserTestUtils.isVisible(toolbar), "Personal toolbar should be visible");
     73  // Wait for bookmarks to be visible.
     74  let placesItems = doc.getElementById("PlacesToolbarItems");
     75  await BrowserTestUtils.waitForMutationCondition(
     76    placesItems,
     77    { childList: true },
     78    () => placesItems.childNodes.length
     79  );
     80  await emptyToolbarMessageVisible(false, newWin);
     81 
     82  await BrowserTestUtils.closeWindow(newWin);
     83 });