Bug 1401238 - remove recent bookmarks from the bookmarks menu button and toplevel bookmarks menu, r?mak
MozReview-Commit-ID: 7JT9xCq9zcS
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -494,18 +494,16 @@ pref("browser.ctrlTab.previews", false);
pref("browser.bookmarks.autoExportHTML", false);
// The maximum number of daily bookmark backups to
// keep in {PROFILEDIR}/bookmarkbackups. Special values:
// -1: unlimited
// 0: no backups created (and deletes all existing backups)
pref("browser.bookmarks.max_backups", 15);
-pref("browser.bookmarks.showRecentlyBookmarked", true);
-
// Whether menu should close after Ctrl-click, middle-click, etc.
pref("browser.bookmarks.openInTabClosesMenu", true);
// Scripts & Windows prefs
pref("dom.disable_open_during_load", true);
pref("javascript.options.showInConsole", true);
#ifdef DEBUG
pref("general.warnOnAboutConfig", false);
--- a/browser/base/content/browser-menubar.inc
+++ b/browser/base/content/browser-menubar.inc
@@ -420,20 +420,16 @@
oncommand="return FeedHandler.subscribeToFeed(null, event);"
onclick="checkForMiddleClick(this, event);"/>
</menu>
<menuitem id="menu_bookmarkAllTabs"
label="&addCurPagesCmd.label;"
class="show-only-for-keyboard"
command="Browser:BookmarkAllTabs"
key="bookmarkAllTabsKb"/>
- <menuseparator/>
- <menuitem label="&recentBookmarks.label;"
- id="menu_recentBookmarks"
- disabled="true"/>
<menuseparator id="bookmarksToolbarSeparator"/>
<menu id="bookmarksToolbarFolderMenu"
class="menu-iconic bookmark-item"
label="&personalbarCmd.label;"
container="true">
<menupopup id="bookmarksToolbarFolderPopup"
#ifndef XP_MACOSX
placespopup="true"
--- a/browser/base/content/browser-places.js
+++ b/browser/base/content/browser-places.js
@@ -1270,267 +1270,16 @@ var PlacesToolbarHelper = {
if (this._viewElt._placesView) {
this._viewElt._placesView.uninit();
}
this.init();
}
},
};
-var RecentBookmarksMenuUI = {
- RECENTLY_BOOKMARKED_PREF: "browser.bookmarks.showRecentlyBookmarked",
- MAX_RESULTS: 5,
- // This timeout affects how soon the recent menu items are updated when
- // an onItemRemoved notification is received - when we receive a notification,
- // we delay updating the UI in case another is received. If one is, then we
- // we'll restart the wait again. It wants to be more than 16ms (60fps) but
- // probably less than 100ms.
- ITEM_REMOVED_TIMEOUT: 40,
-
- _recentGuids: undefined,
- _visible: undefined,
-
- QueryInterface: XPCOMUtils.generateQI([
- Ci.nsINavBookmarkObserver,
- Ci.nsIObserver,
- Ci.nsISupportsWeakReference
- ]),
-
- get visible() {
- return this._visible;
- },
-
- /**
- * Set the visibility of the recently bookmarked menu items.
- *
- * @param {Boolean} show Set to true to show the menu items, false otherwise.
- */
- set visible(visible) {
- // If we're not changing anything, bail early so that we're not unnecessarily
- // doing things we don't need to.
- if (visible == this._visible) {
- return;
- }
-
- this._visible = visible;
- Services.prefs.setBoolPref(this.RECENTLY_BOOKMARKED_PREF, visible);
- this._clearExistingItems();
-
- if (visible) {
- this._insertRecentMenuItems();
- }
- },
-
- /**
- * Observer for observing pref changes.
- */
- observe(subject, topic, data) {
- if (topic == "nsPref:changed" && data == this.RECENTLY_BOOKMARKED_PREF) {
- this.visible = Services.prefs.getBoolPref(this.RECENTLY_BOOKMARKED_PREF, true);
- }
- },
-
- /**
- * Initializes the recent bookmarks menu items into a menu.
- *
- * @param {menuitem} aHeaderItem A DOM menuitem to insert the recent bookmarks
- * into.
- * @param {String} aExtraCSSClass Any extra CSS classes to insert onto the recent
- * bookmark menuitems.
- */
- init(aHeaderItem, aExtraCSSClass = "") {
- this.headerItem = aHeaderItem;
- this.extraCSSClass = aExtraCSSClass;
- this._recentGuids = new Set();
-
- // This also displays the initial list if necessary.
- this.visible = Services.prefs.getBoolPref(this.RECENTLY_BOOKMARKED_PREF, true);
-
- // Add observers and listeners and remove them again when the menupopup closes.
-
- let bookmarksMenu = aHeaderItem.parentNode;
- let placesContextMenu = document.getElementById("placesContext");
-
- let onPlacesContextMenuShowing = event => {
- if (event.target == event.currentTarget) {
- let triggerPopup = event.target.triggerNode;
- while (triggerPopup && triggerPopup.localName != "menupopup") {
- triggerPopup = triggerPopup.parentNode;
- }
- let shouldHidePrefUI = triggerPopup != bookmarksMenu;
- this._updatePlacesContextMenu(shouldHidePrefUI);
- }
- };
-
- let onBookmarksMenuHidden = event => {
- // If hide event is not targeted to the main menu (e.g. hiding a sub-menu),
- // nothing to do.
- if (event.target != event.currentTarget) {
- return;
- }
-
- // Cancel any item removed timers.
- if (this._itemRemovedTimer) {
- clearTimeout(this._itemRemovedTimer);
- }
-
- this._updatePlacesContextMenu(true);
-
- Services.prefs.removeObserver(this.RECENTLY_BOOKMARKED_PREF, this);
- PlacesUtils.bookmarks.removeObserver(this);
- this._recentlyBookmarkedObserver = null;
- if (placesContextMenu) {
- placesContextMenu.removeEventListener("popupshowing", onPlacesContextMenuShowing);
- }
- bookmarksMenu.removeEventListener("popuphidden", onBookmarksMenuHidden);
-
- this._visible = undefined;
- delete this.headerItem;
- delete this.extraCSSClass;
- };
-
- Services.prefs.addObserver(this.RECENTLY_BOOKMARKED_PREF, this, true);
- PlacesUtils.bookmarks.addObserver(this, true);
-
- // The context menu doesn't exist in non-browser windows on Mac
- if (placesContextMenu) {
- placesContextMenu.addEventListener("popupshowing", onPlacesContextMenuShowing);
- }
-
- bookmarksMenu.addEventListener("popuphidden", onBookmarksMenuHidden);
- },
-
- /**
- * Clears existing recent items from the menu and updates the separators
- * according to this.visible.
- */
- _clearExistingItems() {
- this._recentGuids.clear();
-
- while (this.headerItem.nextSibling &&
- this.headerItem.nextSibling.localName == "menuitem") {
- this.headerItem.nextSibling.remove();
- }
-
- let separator = this.headerItem.previousSibling;
- this.headerItem.hidden = !this.visible;
- separator.hidden = !this.visible;
- },
-
- /**
- * Inserts recent bookmark items into the menu.
- */
- _insertRecentMenuItems() {
- let separator = this.headerItem.previousSibling;
- this.headerItem.hidden = !this.visible;
- separator.hidden = !this.visible;
-
- let options = PlacesUtils.history.getNewQueryOptions();
- options.excludeQueries = true;
- options.queryType = options.QUERY_TYPE_BOOKMARKS;
- options.sortingMode = options.SORT_BY_DATEADDED_DESCENDING;
- options.maxResults = this.MAX_RESULTS;
- let query = PlacesUtils.history.getNewQuery();
-
- let sh = Cc["@mozilla.org/network/serialization-helper;1"]
- .getService(Ci.nsISerializationHelper);
- let loadingPrincipal = sh.serializeToString(document.nodePrincipal);
-
- let fragment = document.createDocumentFragment();
- let root = PlacesUtils.history.executeQuery(query, options).root;
- root.containerOpen = true;
- for (let i = 0; i < root.childCount; i++) {
- let node = root.getChild(i);
- let uri = node.uri;
- let title = node.title;
- let icon = node.icon;
-
- let item =
- document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
- "menuitem");
- item.setAttribute("label", title || uri);
- item.setAttribute("targetURI", uri);
- item.setAttribute("simulated-places-node", true);
- item.setAttribute("class", "menuitem-iconic menuitem-with-favicon bookmark-item " +
- this.extraCSSClass);
- if (icon) {
- item.setAttribute("image", icon);
- item.setAttribute("loadingprincipal", loadingPrincipal);
- }
- item._placesNode = node;
- fragment.appendChild(item);
- this._recentGuids.add(node.bookmarkGuid);
- }
- root.containerOpen = false;
- this.headerItem.parentNode.insertBefore(fragment, this.headerItem.nextSibling);
- },
-
- /**
- * Show the places related context menu for the bookmark items.
- *
- * @param {Boolean} shouldHidePrefUI Set to true to hide the UI for switching
- * the showRecentlyBookmarked pref.
- */
- _updatePlacesContextMenu(shouldHidePrefUI = false) {
- let showItem = document.getElementById("placesContext_showRecentlyBookmarked");
- // On Mac the menuitem doesn't exist when we're in the Library window context.
- if (!showItem) {
- return;
- }
- let hideItem = document.getElementById("placesContext_hideRecentlyBookmarked");
- let separator = document.getElementById("placesContext_recentlyBookmarkedSeparator");
- let prefEnabled = !shouldHidePrefUI && Services.prefs.getBoolPref(this.RECENTLY_BOOKMARKED_PREF);
- showItem.hidden = shouldHidePrefUI || prefEnabled;
- hideItem.hidden = shouldHidePrefUI || !prefEnabled;
- separator.hidden = shouldHidePrefUI;
- if (!shouldHidePrefUI) {
- // Move to the bottom of the menu.
- separator.parentNode.appendChild(separator);
- showItem.parentNode.appendChild(showItem);
- hideItem.parentNode.appendChild(hideItem);
- }
- },
-
- /**
- * nsINavBookmarkObserver methods.
- */
-
- /*
- * Handles onItemRemoved notifications from the bookmarks service.
- */
- onItemRemoved(itemId, parentId, index, itemType, uri, guid) {
- if (!this.visible) {
- return;
- }
- // Update the menu when a bookmark has been removed.
- // The native menubar on Mac doesn't support live update, so this is
- // unlikely to be called there.
- if (guid && this._recentGuids.has(guid)) {
- if (this._itemRemovedTimer) {
- clearTimeout(this._itemRemovedTimer);
- }
-
- this._itemRemovedTimer = setTimeout(() => {
- this._clearExistingItems();
- this._insertRecentMenuItems();
- }, this.ITEM_REMOVED_TIMEOUT);
- }
- },
-
- skipTags: true,
- skipDescendantsOnItemRemoval: false,
-
- onBeginUpdateBatch() {},
- onEndUpdateBatch() {},
- onItemAdded() {},
- onItemChanged() {},
- onItemVisited() {},
- onItemMoved() {},
-}
-
/**
* Handles the Library button in the toolbar.
*/
var LibraryUI = {
triggerLibraryAnimation(animation) {
if (!this.hasOwnProperty("COSMETIC_ANIMATIONS_ENABLED")) {
XPCOMUtils.defineLazyPreferenceGetter(this, "COSMETIC_ANIMATIONS_ENABLED",
"toolkit.cosmeticAnimations.enabled", true);
@@ -1712,18 +1461,16 @@ var BookmarkingUI = {
// Don't open a popup in the overflow popup, rather just open the Library.
event.preventDefault();
widget.node.removeAttribute("closemenu");
PlacesCommandHook.showPlacesOrganizer("BookmarksMenu");
return;
}
this._initMobileBookmarks(document.getElementById("BMB_mobileBookmarks"));
- RecentBookmarksMenuUI.init(document.getElementById("BMB_recentBookmarks"),
- "subviewbutton");
if (!this._popupNeedsUpdate)
return;
this._popupNeedsUpdate = false;
let popup = event.target;
let getPlacesAnonymousElement =
aAnonId => document.getAnonymousElementByAttribute(popup.parentNode,
@@ -1949,17 +1696,16 @@ var BookmarkingUI = {
onMainMenuPopupShowing: function BUI_onMainMenuPopupShowing(event) {
// Don't handle events for submenus.
if (event.target != event.currentTarget)
return;
this.updateBookmarkPageMenuItem();
PlacesCommandHook.updateBookmarkAllTabsCommand();
this._initMobileBookmarks(document.getElementById("menu_mobileBookmarks"));
- RecentBookmarksMenuUI.init(document.getElementById("menu_recentBookmarks"));
},
_showBookmarkedNotification: function BUI_showBookmarkedNotification() {
function getCenteringTransformForRects(rectToPosition, referenceRect) {
let topDiff = referenceRect.top - rectToPosition.top;
let leftDiff = referenceRect.left - rectToPosition.left;
let heightDiff = referenceRect.height - rectToPosition.height;
let widthDiff = referenceRect.width - rectToPosition.width;
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -388,35 +388,17 @@
onpopuphiding="if (event.target != this)
return;
gContextMenu.hiding();
gContextMenu = null;
updateEditUIVisibility();">
#include browser-context.inc
</menupopup>
- <menupopup id="placesContext">
- <menuseparator id="placesContext_recentlyBookmarkedSeparator"
- ignoreitem="true"
- hidden="true"/>
- <menuitem id="placesContext_hideRecentlyBookmarked"
- label="&hideRecentlyBookmarked.label;"
- accesskey="&hideRecentlyBookmarked.accesskey;"
- oncommand="RecentBookmarksMenuUI.visible = false;"
- closemenu="single"
- ignoreitem="true"
- hidden="true"/>
- <menuitem id="placesContext_showRecentlyBookmarked"
- label="&showRecentlyBookmarked.label;"
- accesskey="&showRecentlyBookmarked.accesskey;"
- oncommand="RecentBookmarksMenuUI.visible = true;"
- closemenu="single"
- ignoreitem="true"
- hidden="true"/>
- </menupopup>
+ <menupopup id="placesContext"/>
<panel id="ctrlTab-panel" hidden="true" norestorefocus="true" level="top">
<hbox>
<button class="ctrlTab-preview" flex="1"/>
<button class="ctrlTab-preview" flex="1"/>
<button class="ctrlTab-preview" flex="1"/>
<button class="ctrlTab-preview" flex="1"/>
<button class="ctrlTab-preview" flex="1"/>
@@ -1110,21 +1092,16 @@
</menuitem>
<!-- NB: temporary solution for bug 985024, this should go away soon. -->
<menuitem id="BMB_bookmarksShowAllTop"
class="menuitem-iconic subviewbutton"
label="&showAllBookmarks2.label;"
command="Browser:ShowAllBookmarks"
key="manBookmarkKb"/>
<menuseparator/>
- <menuitem label="&recentBookmarks.label;"
- id="BMB_recentBookmarks"
- disabled="true"
- class="menuitem-iconic subviewbutton"/>
- <menuseparator/>
<menu id="BMB_bookmarksToolbar"
class="menu-iconic bookmark-item subviewbutton"
label="&personalbarCmd.label;"
container="true">
<menupopup id="BMB_bookmarksToolbarPopup"
placespopup="true"
context="placesContext"
onpopupshowing="if (!this.parentNode._placesView)
--- a/browser/components/places/tests/chrome/chrome.ini
+++ b/browser/components/places/tests/chrome/chrome.ini
@@ -6,11 +6,10 @@ support-files = head.js
[test_bug1163447_selectItems_through_shortcut.xul]
[test_bug427633_no_newfolder_if_noip.xul]
[test_bug485100-change-case-loses-tag.xul]
[test_bug549192.xul]
[test_bug549491.xul]
[test_bug631374_tags_selector_scroll.xul]
[test_editBookmarkOverlay_keywords.xul]
[test_editBookmarkOverlay_tags_liveUpdate.xul]
-[test_RecentBookmarksMenuUI.xul]
[test_selectItems_on_nested_tree.xul]
[test_treeview_date.xul]
deleted file mode 100644
--- a/browser/components/places/tests/chrome/test_RecentBookmarksMenuUI.xul
+++ /dev/null
@@ -1,299 +0,0 @@
-<?xml version="1.0"?>
-
-<!-- This Source Code Form is subject to the terms of the Mozilla Public
- - License, v. 2.0. If a copy of the MPL was not distributed with this
- - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
-
-<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
-<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
- type="text/css"?>
-<?xml-stylesheet href="chrome://browser/content/places/places.css"?>
-<?xml-stylesheet href="chrome://browser/skin/places/places.css"?>
-
-<?xul-overlay href="chrome://browser/content/places/placesOverlay.xul"?>
-
-<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
- title="Test RecentBookmarksMenuUI">
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js" />
- <script type="application/javascript" src="chrome://browser/content/browser.js"/>
- <script type="application/javascript"
- src="chrome://browser/content/browser-places.js" />
- <script type="application/javascript"
- src="resource://testing-common/sinon-2.3.2.js" />
-
- <body xmlns="http://www.w3.org/1999/xhtml" />
-
- <menu id="fakeMenu">
- <menuseparator id="fakePreviousSeparator"/>
- <menuitem id="fakeRecentBookmarks"/>
- <menuseparator id="fakeNextSeparator"/>
- </menu>
-
- <script type="application/javascript">
- <![CDATA[
- "use strict"
-
- const sandbox = sinon.sandbox.create();
-
- const BASE_URL = "http://example.org/browser/browser/components/places/tests/browser/";
-
- var bmMenu = document.getElementById("fakeMenu");
- var prevSep = document.getElementById("fakePreviousSeparator");
- var recentBmItem = document.getElementById("fakeRecentBookmarks");
- var nextSep = document.getElementById("fakeNextSeparator");
-
- function simulateHideMenu() {
- let event = new CustomEvent("popuphidden");
- bmMenu.dispatchEvent(event);
- }
-
- add_task(async function setup() {
- let children = [];
- // Make dateAdded start in the past and advance it on a second for each bookmark,
- // so that we can guarentee which ones get displayed in the test.
- let dateAdded = (new Date()).getTime() - 1000;
-
- for (let i = 0; i < 10; i++) {
- children.push({
- title: `bm${i}`,
- url: `${BASE_URL}bookmark_dummy_${i}.html`,
- dateAdded: new Date(dateAdded)
- });
- dateAdded += 100;
- }
-
- await PlacesUtils.bookmarks.insertTree({
- guid: PlacesUtils.bookmarks.unfiledGuid,
- children: [{
- children,
- title: "TestFolder",
- type: PlacesUtils.bookmarks.TYPE_FOLDER,
- }]
- });
- });
-
- add_task(async function test_basic_contents() {
- RecentBookmarksMenuUI.init(document.getElementById("fakeRecentBookmarks"));
-
- is(bmMenu.children.length, RecentBookmarksMenuUI.MAX_RESULTS + 3,
- "There should be MAX_RESULTS children plus the 2 separators and 1 menuitem.");
-
- let recentItem = recentBmItem.nextSibling;
- for (let i = 9; i >= 10 - RecentBookmarksMenuUI.MAX_RESULTS; --i) {
- is(recentItem.getAttribute("label"), `bm${i}`,
- "Should have the expected title from the bookmark");
- is(recentItem.getAttribute("targetURI"), `${BASE_URL}bookmark_dummy_${i}.html`,
- "Should have the expected targetURI from the bookmark");
- is(recentItem.getAttribute("simulated-places-node"), "true",
- "Should be flagged as a simulated-places-node");
- recentItem = recentItem.nextSibling;
- }
-
- is(prevSep.hidden, false, "Previous separator should not be hidden");
- is(recentBmItem.hidden, false, "The title item should not be hidden");
- ok(nextSep, "Next separator should still be present");
- is(nextSep.hidden, false, "Next separator should not be hidden");
-
- // Also check that hiding the menu stops listening to items.
- simulateHideMenu();
-
- ok(!RecentBookmarksMenuUI._recentlyBookmarkedObserver,
- "Remove observer should have been called");
- });
-
- add_task(async function test_remove_bookmark() {
- RecentBookmarksMenuUI.init(document.getElementById("fakeRecentBookmarks"));
-
- is(bmMenu.children.length, RecentBookmarksMenuUI.MAX_RESULTS + 3,
- "There should be MAX_RESULTS children plus the 2 separators and 1 menuitem.");
-
- let bmToRemove = await PlacesUtils.bookmarks.fetch({url: `${BASE_URL}bookmark_dummy_9.html`});
-
- const clock = sandbox.useFakeTimers();
-
- await PlacesUtils.bookmarks.remove(bmToRemove);
-
- // Move the clock past the timeout to ensure any update happen.
- clock.tick(RecentBookmarksMenuUI.ITEM_REMOVED_TIMEOUT + 1);
- clock.restore();
-
- let recentItem = recentBmItem.nextSibling;
- for (let i = 8; i >= 9 - RecentBookmarksMenuUI.MAX_RESULTS; --i) {
- is(recentItem.getAttribute("label"), `bm${i}`,
- "Should have the expected title from the bookmark");
- is(recentItem.getAttribute("targetURI"), `${BASE_URL}bookmark_dummy_${i}.html`,
- "Should have the expected targetURI from the bookmark");
- is(recentItem.getAttribute("simulated-places-node"), "true",
- "Should be flagged as a simulated-places-node");
- recentItem = recentItem.nextSibling;
- }
-
- simulateHideMenu();
- });
-
- add_task(async function test_remove_multiple_bookmarks() {
- RecentBookmarksMenuUI.init(document.getElementById("fakeRecentBookmarks"));
-
- is(bmMenu.children.length, RecentBookmarksMenuUI.MAX_RESULTS + 3,
- "There should be MAX_RESULTS children plus the 2 separators and 1 menuitem.");
-
- let bmToRemove = await PlacesUtils.bookmarks.fetch({url: `${BASE_URL}bookmark_dummy_8.html`});
-
- const clock = sandbox.useFakeTimers();
-
- sinon.stub(RecentBookmarksMenuUI, "_insertRecentMenuItems");
-
- await PlacesUtils.bookmarks.remove(bmToRemove);
-
- // Move the clock a little way and check we haven't re-pouplated.
- clock.tick(RecentBookmarksMenuUI.ITEM_REMOVED_TIMEOUT - 10);
-
- ok(RecentBookmarksMenuUI._insertRecentMenuItems.notCalled,
- "should not have populated the recent bookmarks striaght away.")
-
- bmToRemove = await PlacesUtils.bookmarks.fetch({url: `${BASE_URL}bookmark_dummy_7.html`});
- await PlacesUtils.bookmarks.remove(bmToRemove);
-
- // Move the clock a little way and check we haven't re-pouplated.
- clock.tick(RecentBookmarksMenuUI.ITEM_REMOVED_TIMEOUT - 10);
-
- ok(RecentBookmarksMenuUI._insertRecentMenuItems.notCalled,
- "should not have populated the recent bookmarks striaght away.")
-
- RecentBookmarksMenuUI._insertRecentMenuItems.restore();
-
- // Move the clock past the timeout and check the menu is updated.
- clock.tick(20);
-
- let recentItem = recentBmItem.nextSibling;
- for (let i = 6; i >= 7 - RecentBookmarksMenuUI.MAX_RESULTS; --i) {
- is(recentItem.getAttribute("label"), `bm${i}`,
- "Should have the expected title from the bookmark");
- is(recentItem.getAttribute("targetURI"), `${BASE_URL}bookmark_dummy_${i}.html`,
- "Should have the expected targetURI from the bookmark");
- is(recentItem.getAttribute("simulated-places-node"), "true",
- "Should be flagged as a simulated-places-node");
- recentItem = recentItem.nextSibling;
- }
-
- clock.restore();
-
- simulateHideMenu();
- });
-
- add_task(async function test_remove_non_shown_bookmark() {
- RecentBookmarksMenuUI.init(document.getElementById("fakeRecentBookmarks"));
-
- is(bmMenu.children.length, RecentBookmarksMenuUI.MAX_RESULTS + 3,
- "There should be MAX_RESULTS children plus the 2 separators and 1 menuitem.");
-
- let bmToRemove = await PlacesUtils.bookmarks.fetch({url: `${BASE_URL}bookmark_dummy_1.html`});
-
- sandbox.stub(RecentBookmarksMenuUI, "_clearExistingItems");
- sandbox.stub(RecentBookmarksMenuUI, "_insertRecentMenuItems");
-
- const clock = sandbox.useFakeTimers();
-
- await PlacesUtils.bookmarks.remove(bmToRemove);
-
- // Move the clock past the timeout to ensure any update happen.
- clock.tick(RecentBookmarksMenuUI.ITEM_REMOVED_TIMEOUT + 1);
- clock.restore();
-
- is(RecentBookmarksMenuUI._clearExistingItems.notCalled, true,
- "Should not have cleared the existing items when a bookmark is removed that is not displayed.");
- is(RecentBookmarksMenuUI._insertRecentMenuItems.notCalled, true,
- "Should not have inserted new menu items when a bookmark is removed that is not displayed.");
-
- sandbox.restore();
- simulateHideMenu();
- });
-
- add_task(async function test_hide_recently_bookmarked() {
- RecentBookmarksMenuUI.init(document.getElementById("fakeRecentBookmarks"));
-
- is(bmMenu.children.length, RecentBookmarksMenuUI.MAX_RESULTS + 3,
- "There should be MAX_RESULTS children plus the 2 separators and 1 menuitem.");
-
- RecentBookmarksMenuUI.visible = false;
-
- is(Services.prefs.getBoolPref(RecentBookmarksMenuUI.RECENTLY_BOOKMARKED_PREF), false,
- "showRecentlyBookmarked pref should have been set to false");
-
- is(bmMenu.children.length, 3,
- "There should only be the original 3 items in the menu");
- is(document.getElementById("fakePreviousSeparator").hidden, true,
- "The previous separator should be hidden");
- is(document.getElementById("fakeRecentBookmarks").hidden, true,
- "The title item should be hidden");
- is(document.getElementById("fakeNextSeparator").hidden, false,
- "Next separator should not be hidden");
-
- simulateHideMenu();
- });
-
- add_task(async function test_remove_with_recently_bookmarked_hidden() {
- RecentBookmarksMenuUI.init(document.getElementById("fakeRecentBookmarks"));
- RecentBookmarksMenuUI.visible = false;
-
- is(bmMenu.children.length, 3,
- "There should only be the original 3 items in the menu");
-
- let bmToRemove = await PlacesUtils.bookmarks.fetch({url: `${BASE_URL}bookmark_dummy_6.html`});
-
- sandbox.stub(RecentBookmarksMenuUI, "_clearExistingItems");
- sandbox.stub(RecentBookmarksMenuUI, "_insertRecentMenuItems");
-
- const clock = sandbox.useFakeTimers();
-
- await PlacesUtils.bookmarks.remove(bmToRemove);
-
- // Move the clock past the timeout to ensure any update happen.
- clock.tick(RecentBookmarksMenuUI.ITEM_REMOVED_TIMEOUT + 1);
- clock.restore();
-
- is(bmMenu.children.length, 3,
- "There should only be the original 3 items in the menu");
- is(RecentBookmarksMenuUI._clearExistingItems.notCalled, true,
- "Should not have cleared the existing items when recently bookmarked are hidden.");
- is(RecentBookmarksMenuUI._insertRecentMenuItems.notCalled, true,
- "Should not have inserted new menu items when recently bookmarked are hidden.");
-
- sandbox.restore();
- simulateHideMenu();
- });
-
- add_task(async function test_show_recently_bookmarked() {
- RecentBookmarksMenuUI.init(document.getElementById("fakeRecentBookmarks"));
-
- is(bmMenu.children.length, 3,
- "There should only be the original 3 items in the menu");
-
- RecentBookmarksMenuUI.visible = true;
-
- is(bmMenu.children.length, RecentBookmarksMenuUI.MAX_RESULTS + 3,
- "There should be MAX_RESULTS children plus the 2 separators and 1 menuitem.");
-
- is(Services.prefs.getBoolPref(RecentBookmarksMenuUI.RECENTLY_BOOKMARKED_PREF), true,
- "showRecentlyBookmarked pref should have been set to true");
-
- is(document.getElementById("fakePreviousSeparator").hidden, false,
- "The previous separator should not be hidden");
- is(document.getElementById("fakeRecentBookmarks").hidden, false,
- "The title item should not be hidden");
- is(document.getElementById("fakeNextSeparator").hidden, false,
- "Next separator should not be hidden");
-
- simulateHideMenu();
- });
-
- add_task(async function cleanup() {
- Services.prefs.clearUserPref(RecentBookmarksMenuUI.RECENTLY_BOOKMARKED_PREF);
- await PlacesUtils.bookmarks.eraseEverything();
- });
- ]]>
- </script>
-</window>