Bug 1360282 - Remove the popup that opens from the sidebar toolbar button;r=Gijs draft
authorBrian Grinstead <bgrinstead@mozilla.com>
Tue, 13 Jun 2017 08:14:58 -0700
changeset 593457 ac822ab6f4f64a32c51b5cd55ba7f87bee4f90f8
parent 593456 bc2b45ea29848aee3767757a8a0497eaf065cd0d
child 633112 780e2edf867f6b87b868cd3df43cc2e32eaf9442
push id63696
push userbgrinstead@mozilla.com
push dateTue, 13 Jun 2017 15:15:10 +0000
reviewersGijs
bugs1360282
milestone56.0a1
Bug 1360282 - Remove the popup that opens from the sidebar toolbar button;r=Gijs MozReview-Commit-ID: 4N841nISf3F
browser/base/content/browser-sidebar.js
browser/components/customizableui/CustomizableWidgets.jsm
browser/components/customizableui/test/browser.ini
browser/components/customizableui/test/browser_981305_separator_insertion.js
browser/components/customizableui/test/browser_988072_sidebar_events.js
browser/components/customizableui/test/browser_989751_subviewbutton_class.js
browser/components/customizableui/test/browser_sidebar_toggle.js
--- a/browser/base/content/browser-sidebar.js
+++ b/browser/base/content/browser-sidebar.js
@@ -23,16 +23,21 @@ var SidebarUI = {
   // Avoid getting the browser element from init() to avoid triggering the
   // <browser> constructor during startup if the sidebar is hidden.
   get browser() {
     if (this._browser)
       return this._browser;
     return this._browser = document.getElementById("sidebar");
   },
   POSITION_START_PREF: "sidebar.position_start",
+  DEFAULT_SIDEBAR_ID: "viewBookmarksSidebar",
+
+  // lastOpenedId is set in show() but unlike currentID it's not cleared out on hide
+  // and isn't persisted across windows
+  lastOpenedId: null,
 
   _box: null,
   // The constructor of this label accesses the browser element due to the
   // control="sidebar" attribute, so avoid getting this label during startup.
   get _title() {
     if (this.__title)
       return this.__title;
     return this.__title = document.getElementById("sidebar-title");
@@ -58,16 +63,17 @@ var SidebarUI = {
     });
   },
 
   uninit() {
     let enumerator = Services.wm.getEnumerator(null);
     enumerator.getNext();
     if (!enumerator.hasMoreElements()) {
       document.persist("sidebar-box", "sidebarcommand");
+      document.persist("sidebar-box", "checked");
       document.persist("sidebar-box", "width");
       document.persist("sidebar-title", "value");
     }
   },
 
   /**
    * Opens the switcher panel if it's closed, or closes it if it's open.
    */
@@ -252,25 +258,40 @@ var SidebarUI = {
   get title() {
     return this._title.value;
   },
 
   set title(value) {
     this._title.value = value;
   },
 
+  getBroadcasterById(id) {
+    let sidebarBroadcaster = document.getElementById(id);
+    if (sidebarBroadcaster && sidebarBroadcaster.localName == "broadcaster") {
+      return sidebarBroadcaster;
+    }
+    return null;
+  },
+
   /**
    * Toggle the visibility of the sidebar. If the sidebar is hidden or is open
    * with a different commandID, then the sidebar will be opened using the
    * specified commandID. Otherwise the sidebar will be hidden.
    *
    * @param {string} commandID ID of the xul:broadcaster element to use.
    * @return {Promise}
    */
-  toggle(commandID = this.currentID) {
+  toggle(commandID = this.lastOpenedId) {
+    // First priority for a default value is this.lastOpenedId which is set during show()
+    // and not reset in hide(), unlike currentID. If show() hasn't been called or the command
+    // doesn't exist anymore, then fallback to a default sidebar.
+    if (!commandID || !this.getBroadcasterById(commandID)) {
+      commandID = this.DEFAULT_SIDEBAR_ID;
+    }
+
     if (this.isOpen && commandID == this.currentID) {
       this.hide();
       return Promise.resolve();
     }
     return this.show(commandID);
   },
 
   /**
@@ -290,18 +311,18 @@ var SidebarUI = {
   /**
    * Implementation for show. Also used internally for sidebars that are shown
    * when a window is opened and we don't want to ping telemetry.
    *
    * @param {string} commandID ID of the xul:broadcaster element to use.
    */
   _show(commandID) {
     return new Promise((resolve, reject) => {
-      let sidebarBroadcaster = document.getElementById(commandID);
-      if (!sidebarBroadcaster || sidebarBroadcaster.localName != "broadcaster") {
+      let sidebarBroadcaster = this.getBroadcasterById(commandID);
+      if (!sidebarBroadcaster) {
         reject(new Error("Invalid sidebar broadcaster specified: " + commandID));
         return;
       }
 
       if (this.isOpen && commandID != this.currentID) {
         BrowserUITelemetry.countSidebarEvent(this.currentID, "hide");
       }
 
@@ -314,16 +335,17 @@ var SidebarUI = {
         }
       }
 
       this._box.hidden = this._splitter.hidden = false;
       this.setPosition();
 
       this.hideSwitcherPanel();
 
+      this._box.setAttribute("checked", "true");
       this._box.setAttribute("sidebarcommand", sidebarBroadcaster.id);
       this.lastOpenedId = sidebarBroadcaster.id;
 
       let title = sidebarBroadcaster.getAttribute("sidebartitle") ||
                   sidebarBroadcaster.getAttribute("label");
 
       // When loading a web page in the sidebar there is no title set on the
       // broadcaster, as it is instead set by openWebPanel. Don't clear out
@@ -383,16 +405,17 @@ var SidebarUI = {
     // create a new content viewer because the old one doesn't get destroyed
     // until about:blank has loaded (which does not happen as long as the
     // element is hidden).
     this.browser.setAttribute("src", "about:blank");
     this.browser.docShell.createAboutBlankContentViewer(null);
 
     sidebarBroadcaster.removeAttribute("checked");
     this._box.setAttribute("sidebarcommand", "");
+    this._box.removeAttribute("checked");
     this.title = "";
     this._box.hidden = this._splitter.hidden = true;
 
     let selBrowser = gBrowser.selectedBrowser;
     selBrowser.focus();
     selBrowser.messageManager.sendAsyncMessage("Sidebar:VisibilityChange",
       {commandID, isOpen: false}
     );
--- a/browser/components/customizableui/CustomizableWidgets.jsm
+++ b/browser/components/customizableui/CustomizableWidgets.jsm
@@ -591,31 +591,28 @@ const CustomizableWidgets = [
     tooltiptext: "open-file-button.tooltiptext3",
     defaultArea: CustomizableUI.AREA_PANEL,
     onCommand(aEvent) {
       let win = aEvent.target.ownerGlobal;
       win.BrowserOpenFileWindow();
     }
   }, {
     id: "sidebar-button",
-    type: "view",
-    viewId: "PanelUI-sidebar",
     tooltiptext: "sidebar-button.tooltiptext2",
-    onViewShowing(aEvent) {
-      // Populate the subview with whatever menuitems are in the
-      // sidebar menu. We skip menu elements, because the menu panel has no way
-      // of dealing with those right now.
-      let doc = aEvent.target.ownerDocument;
-      let menu = doc.getElementById("viewSidebarMenu");
-
-      // First clear any existing menuitems then populate. Add it to the
-      // standard menu first, then copy all sidebar options to the panel.
-      let sidebarItems = doc.getElementById("PanelUI-sidebarItems");
-      clearSubview(sidebarItems);
-      fillSubviewFromMenuItems([...menu.children], sidebarItems);
+    onCommand(aEvent) {
+      let win = aEvent.target.ownerGlobal;
+      win.SidebarUI.toggle();
+    },
+    onCreated(aNode) {
+      // Add an observer so the button is checked while the sidebar is open
+      let doc = aNode.ownerDocument;
+      let obnode = doc.createElementNS(kNSXUL, "observes");
+      obnode.setAttribute("element", "sidebar-box");
+      obnode.setAttribute("attribute", "checked");
+      aNode.appendChild(obnode);
     }
   }, {
     id: "social-share-button",
     // custom build our button so we can attach to the share command
     type: "custom",
     onBuild(aDocument) {
       let node = aDocument.createElementNS(kNSXUL, "toolbarbutton");
       node.setAttribute("id", this.id);
--- a/browser/components/customizableui/test/browser.ini
+++ b/browser/components/customizableui/test/browser.ini
@@ -120,17 +120,16 @@ skip-if = os == "linux"
 [browser_982656_restore_defaults_builtin_widgets.js]
 [browser_984455_bookmarks_items_reparenting.js]
 skip-if = os == "linux"
 [browser_985815_propagate_setToolbarVisibility.js]
 [browser_987177_destroyWidget_xul.js]
 [browser_987177_xul_wrapper_updating.js]
 [browser_987492_window_api.js]
 [browser_987640_charEncoding.js]
-[browser_988072_sidebar_events.js]
 [browser_989338_saved_placements_not_resaved.js]
 [browser_989751_subviewbutton_class.js]
 [browser_992747_toggle_noncustomizable_toolbar.js]
 [browser_993322_widget_notoolbar.js]
 [browser_995164_registerArea_during_customize_mode.js]
 [browser_996364_registerArea_different_properties.js]
 [browser_996635_remove_non_widgets.js]
 [browser_1003588_no_specials_in_panel.js]
@@ -160,9 +159,10 @@ skip-if = os == "mac"
 tags = fullscreen
 [browser_panelUINotifications_multiWindow.js]
 [browser_switch_to_customize_mode.js]
 [browser_synced_tabs_menu.js]
 [browser_check_tooltips_in_navbar.js]
 [browser_editcontrols_update.js]
 subsuite = clipboard
 [browser_photon_customization_context_menus.js]
+[browser_sidebar_toggle.js]
 [browser_remote_tabs_button.js]
--- a/browser/components/customizableui/test/browser_981305_separator_insertion.js
+++ b/browser/components/customizableui/test/browser_981305_separator_insertion.js
@@ -62,16 +62,15 @@ function checkSeparatorInsertion(menuId,
   };
 }
 
 add_task(async function() {
   await SpecialPowers.pushPrefEnv({set: [["browser.photon.structure.enabled", false]]});
 });
 
 add_task(checkSeparatorInsertion("menuWebDeveloperPopup", "developer-button", "PanelUI-developerItems"));
-add_task(checkSeparatorInsertion("viewSidebarMenu", "sidebar-button", "PanelUI-sidebarItems"));
 
 registerCleanupFunction(function() {
   for (let el of tempElements) {
     el.remove();
   }
   tempElements = null;
 });
--- a/browser/components/customizableui/test/browser_989751_subviewbutton_class.js
+++ b/browser/components/customizableui/test/browser_989751_subviewbutton_class.js
@@ -52,14 +52,13 @@ function checkSubviewButtonClass(menuId,
     }
   };
 }
 add_task(async function() {
   await SpecialPowers.pushPrefEnv({set: [["browser.photon.structure.enabled", false]]});
 });
 
 add_task(checkSubviewButtonClass("menuWebDeveloperPopup", "developer-button", "PanelUI-developerItems"));
-add_task(checkSubviewButtonClass("viewSidebarMenu", "sidebar-button", "PanelUI-sidebarItems"));
 
 registerCleanupFunction(function() {
   tempElement.classList.remove(kCustomClass)
   tempElement = null;
 });
rename from browser/components/customizableui/test/browser_988072_sidebar_events.js
rename to browser/components/customizableui/test/browser_sidebar_toggle.js
--- a/browser/components/customizableui/test/browser_988072_sidebar_events.js
+++ b/browser/components/customizableui/test/browser_sidebar_toggle.js
@@ -1,392 +1,43 @@
 /* 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/. */
 
 "use strict";
 
-var gSidebarMenu = document.getElementById("viewSidebarMenu");
-var gTestSidebarItem = null;
-
-var EVENTS = {
-  click: 0, command: 0,
-  onclick: 0, oncommand: 0
-};
-
-window.sawEvent = function(event, isattr) {
-  let type = (isattr ? "on" : "") + event.type
-  EVENTS[type]++;
-};
-
-registerCleanupFunction(() => {
-  delete window.sawEvent;
+registerCleanupFunction(async function() {
+  await resetCustomization();
 
   // Ensure sidebar is hidden after each test:
   if (!document.getElementById("sidebar-box").hidden) {
     SidebarUI.hide();
   }
 });
 
-function checkExpectedEvents(expected) {
-  for (let type of Object.keys(EVENTS)) {
-    let count = (type in expected ? expected[type] : 0);
-    is(EVENTS[type], count, "Should have seen the right number of " + type + " events");
-    EVENTS[type] = 0;
-  }
-}
-
-function createSidebarItem() {
-  gTestSidebarItem = document.createElement("menuitem");
-  gTestSidebarItem.id = "testsidebar";
-  gTestSidebarItem.setAttribute("label", "Test Sidebar");
-  gSidebarMenu.insertBefore(gTestSidebarItem, gSidebarMenu.firstChild);
-}
-
-function addWidget() {
-  CustomizableUI.addWidgetToArea("sidebar-button", "nav-bar");
-  PanelUI.disableSingleSubviewPanelAnimations();
-}
-
-function removeWidget() {
-  CustomizableUI.removeWidgetFromArea("sidebar-button");
-  PanelUI.enableSingleSubviewPanelAnimations();
-}
+var showSidebar = async function() {
+  let button = document.getElementById("sidebar-button");
+  let sidebarFocusedPromise = BrowserTestUtils.waitForEvent(document, "SidebarFocused");
+  EventUtils.synthesizeMouseAtCenter(button, {});
+  await sidebarFocusedPromise;
+  ok(SidebarUI.isOpen, "Sidebar is opened");
+  ok(button.hasAttribute("checked"), "Toolbar button is checked");
+};
 
-// Filters out the trailing menuseparators from the sidebar list
-function getSidebarList() {
-  let sidebars = [...gSidebarMenu.children].filter(sidebar => {
-    if (sidebar.localName == "menuseparator")
-      return false;
-    if (sidebar.getAttribute("hidden") == "true")
-      return false;
-    return true;
-  });
-  return sidebars;
-}
-
-function compareElements(original, displayed) {
-  let attrs = ["label", "key", "disabled", "hidden", "origin", "image", "checked"];
-  for (let attr of attrs) {
-    is(displayed.getAttribute(attr), original.getAttribute(attr), "Should have the same " + attr + " attribute");
-  }
-}
-
-function compareList(original, displayed) {
-  is(displayed.length, original.length, "Should have the same number of children");
-
-  for (let i = 0; i < Math.min(original.length, displayed.length); i++) {
-    compareElements(displayed[i], original[i]);
-  }
-}
-
-var showSidebarPopup = async function() {
+var hideSidebar = async function() {
   let button = document.getElementById("sidebar-button");
-  let subview = document.getElementById("PanelUI-sidebar");
-
-  let popupShownPromise = BrowserTestUtils.waitForEvent(document, "popupshown");
-
-  let subviewShownPromise = subviewShown(subview);
   EventUtils.synthesizeMouseAtCenter(button, {});
-  return Promise.all([subviewShownPromise, popupShownPromise]);
+  ok(!SidebarUI.isOpen, "Sidebar is closed");
+  ok(!button.hasAttribute("checked"), "Toolbar button isn't checked");
 };
 
 // Check the sidebar widget shows the default items
 add_task(async function() {
-  addWidget();
-
-  await showSidebarPopup();
-
-  let sidebars = getSidebarList();
-  let displayed = [...document.getElementById("PanelUI-sidebarItems").children];
-  compareList(sidebars, displayed);
-
-  let subview = document.getElementById("PanelUI-sidebar");
-  let subviewHiddenPromise = subviewHidden(subview);
-  document.getElementById("customizationui-widget-panel").hidePopup();
-  await subviewHiddenPromise;
-
-  removeWidget();
-});
-
-function add_sidebar_task(description, setup, teardown) {
-  add_task(async function() {
-    info(description);
-    createSidebarItem();
-    addWidget();
-    await setup();
-
-    CustomizableUI.addWidgetToArea("sidebar-button", "nav-bar");
-
-    await showSidebarPopup();
-
-    let sidebars = getSidebarList();
-    let displayed = [...document.getElementById("PanelUI-sidebarItems").children];
-    compareList(sidebars, displayed);
-
-    is(displayed[0].label, "Test Sidebar", "Should have the right element at the top");
-    let subview = document.getElementById("PanelUI-sidebar");
-    let subviewHiddenPromise = subviewHidden(subview);
-    EventUtils.synthesizeMouseAtCenter(displayed[0], {});
-    await subviewHiddenPromise;
-
-    await teardown();
-    gTestSidebarItem.remove();
-    removeWidget();
-  });
-}
-
-add_sidebar_task(
-  "Check that a sidebar that uses a command event listener works",
-function() {
-  gTestSidebarItem.addEventListener("command", window.sawEvent);
-}, function() {
-  checkExpectedEvents({ command: 1 });
-});
-
-add_sidebar_task(
-  "Check that a sidebar that uses a click event listener works",
-function() {
-  gTestSidebarItem.addEventListener("click", window.sawEvent);
-}, function() {
-  checkExpectedEvents({ click: 1 });
-});
-
-add_sidebar_task(
-  "Check that a sidebar that uses both click and command event listeners works",
-function() {
-  gTestSidebarItem.addEventListener("command", window.sawEvent);
-  gTestSidebarItem.addEventListener("click", window.sawEvent);
-}, function() {
-  checkExpectedEvents({ command: 1, click: 1 });
-});
-
-add_sidebar_task(
-  "Check that a sidebar that uses an oncommand attribute works",
-function() {
-  gTestSidebarItem.setAttribute("oncommand", "window.sawEvent(event, true)");
-}, function() {
-  checkExpectedEvents({ oncommand: 1 });
-});
-
-add_sidebar_task(
-  "Check that a sidebar that uses an onclick attribute works",
-function() {
-  gTestSidebarItem.setAttribute("onclick", "window.sawEvent(event, true)");
-}, function() {
-  checkExpectedEvents({ onclick: 1 });
-});
-
-add_sidebar_task(
-  "Check that a sidebar that uses both onclick and oncommand attributes works",
-function() {
-  gTestSidebarItem.setAttribute("onclick", "window.sawEvent(event, true)");
-  gTestSidebarItem.setAttribute("oncommand", "window.sawEvent(event, true)");
-}, function() {
-  checkExpectedEvents({ onclick: 1, oncommand: 1 });
-});
-
-add_sidebar_task(
-  "Check that a sidebar that uses an onclick attribute and a command listener works",
-function() {
-  gTestSidebarItem.setAttribute("onclick", "window.sawEvent(event, true)");
-  gTestSidebarItem.addEventListener("command", window.sawEvent);
-}, function() {
-  checkExpectedEvents({ onclick: 1, command: 1 });
-});
-
-add_sidebar_task(
-  "Check that a sidebar that uses an oncommand attribute and a click listener works",
-function() {
-  gTestSidebarItem.setAttribute("oncommand", "window.sawEvent(event, true)");
-  gTestSidebarItem.addEventListener("click", window.sawEvent);
-}, function() {
-  checkExpectedEvents({ click: 1, oncommand: 1 });
-});
-
-add_sidebar_task(
-  "A sidebar with both onclick attribute and click listener sees only one event :(",
-function() {
-  gTestSidebarItem.setAttribute("onclick", "window.sawEvent(event, true)");
-  gTestSidebarItem.addEventListener("click", window.sawEvent);
-}, function() {
-  checkExpectedEvents({ onclick: 1 });
-});
-
-add_sidebar_task(
-  "A sidebar with both oncommand attribute and command listener sees only one event :(",
-function() {
-  gTestSidebarItem.setAttribute("oncommand", "window.sawEvent(event, true)");
-  gTestSidebarItem.addEventListener("command", window.sawEvent);
-}, function() {
-  checkExpectedEvents({ oncommand: 1 });
-});
-
-add_sidebar_task(
-  "Check that a sidebar that uses a broadcaster with an oncommand attribute works",
-function() {
-  let broadcaster = document.createElement("broadcaster");
-  broadcaster.setAttribute("id", "testbroadcaster");
-  broadcaster.setAttribute("oncommand", "window.sawEvent(event, true)");
-  broadcaster.setAttribute("label", "Test Sidebar");
-  document.getElementById("mainBroadcasterSet").appendChild(broadcaster);
-
-  gTestSidebarItem.setAttribute("observes", "testbroadcaster");
-}, function() {
-  checkExpectedEvents({ oncommand: 1 });
-  document.getElementById("testbroadcaster").remove();
-});
+  CustomizableUI.addWidgetToArea("sidebar-button", "nav-bar");
 
-add_sidebar_task(
-  "Check that a sidebar that uses a broadcaster with an onclick attribute works",
-function() {
-  let broadcaster = document.createElement("broadcaster");
-  broadcaster.setAttribute("id", "testbroadcaster");
-  broadcaster.setAttribute("onclick", "window.sawEvent(event, true)");
-  broadcaster.setAttribute("label", "Test Sidebar");
-  document.getElementById("mainBroadcasterSet").appendChild(broadcaster);
-
-  gTestSidebarItem.setAttribute("observes", "testbroadcaster");
-}, function() {
-  checkExpectedEvents({ onclick: 1 });
-  document.getElementById("testbroadcaster").remove();
-});
-
-add_sidebar_task(
-  "Check that a sidebar that uses a broadcaster with both onclick and oncommand attributes works",
-function() {
-  let broadcaster = document.createElement("broadcaster");
-  broadcaster.setAttribute("id", "testbroadcaster");
-  broadcaster.setAttribute("onclick", "window.sawEvent(event, true)");
-  broadcaster.setAttribute("oncommand", "window.sawEvent(event, true)");
-  broadcaster.setAttribute("label", "Test Sidebar");
-  document.getElementById("mainBroadcasterSet").appendChild(broadcaster);
-
-  gTestSidebarItem.setAttribute("observes", "testbroadcaster");
-}, function() {
-  checkExpectedEvents({ onclick: 1, oncommand: 1 });
-  document.getElementById("testbroadcaster").remove();
-});
-
-add_sidebar_task(
-  "Check that a sidebar with a click listener and a broadcaster with an oncommand attribute works",
-function() {
-  let broadcaster = document.createElement("broadcaster");
-  broadcaster.setAttribute("id", "testbroadcaster");
-  broadcaster.setAttribute("oncommand", "window.sawEvent(event, true)");
-  broadcaster.setAttribute("label", "Test Sidebar");
-  document.getElementById("mainBroadcasterSet").appendChild(broadcaster);
-
-  gTestSidebarItem.setAttribute("observes", "testbroadcaster");
-  gTestSidebarItem.addEventListener("click", window.sawEvent);
-}, function() {
-  checkExpectedEvents({ click: 1, oncommand: 1 });
-  document.getElementById("testbroadcaster").remove();
-});
-
-add_sidebar_task(
-  "Check that a sidebar with a command listener and a broadcaster with an onclick attribute works",
-function() {
-  let broadcaster = document.createElement("broadcaster");
-  broadcaster.setAttribute("id", "testbroadcaster");
-  broadcaster.setAttribute("onclick", "window.sawEvent(event, true)");
-  broadcaster.setAttribute("label", "Test Sidebar");
-  document.getElementById("mainBroadcasterSet").appendChild(broadcaster);
-
-  gTestSidebarItem.setAttribute("observes", "testbroadcaster");
-  gTestSidebarItem.addEventListener("command", window.sawEvent);
-}, function() {
-  checkExpectedEvents({ onclick: 1, command: 1 });
-  document.getElementById("testbroadcaster").remove();
-});
-
-add_sidebar_task(
-  "Check that a sidebar with a click listener and a broadcaster with an onclick " +
-  "attribute only sees one event :(",
-function() {
-  let broadcaster = document.createElement("broadcaster");
-  broadcaster.setAttribute("id", "testbroadcaster");
-  broadcaster.setAttribute("onclick", "window.sawEvent(event, true)");
-  broadcaster.setAttribute("label", "Test Sidebar");
-  document.getElementById("mainBroadcasterSet").appendChild(broadcaster);
+  await showSidebar();
+  is(SidebarUI.currentID, "viewBookmarksSidebar", "Default sidebar selected");
+  await SidebarUI.show("viewHistorySidebar");
 
-  gTestSidebarItem.setAttribute("observes", "testbroadcaster");
-  gTestSidebarItem.addEventListener("click", window.sawEvent);
-}, function() {
-  checkExpectedEvents({ onclick: 1 });
-  document.getElementById("testbroadcaster").remove();
-});
-
-add_sidebar_task(
-  "Check that a sidebar with a command listener and a broadcaster with an oncommand " +
-  "attribute only sees one event :(",
-function() {
-  let broadcaster = document.createElement("broadcaster");
-  broadcaster.setAttribute("id", "testbroadcaster");
-  broadcaster.setAttribute("oncommand", "window.sawEvent(event, true)");
-  broadcaster.setAttribute("label", "Test Sidebar");
-  document.getElementById("mainBroadcasterSet").appendChild(broadcaster);
-
-  gTestSidebarItem.setAttribute("observes", "testbroadcaster");
-  gTestSidebarItem.addEventListener("command", window.sawEvent);
-}, function() {
-  checkExpectedEvents({ oncommand: 1 });
-  document.getElementById("testbroadcaster").remove();
-});
-
-add_sidebar_task(
-  "Check that a sidebar that uses a command element with a command event listener works",
-function() {
-  let command = document.createElement("command");
-  command.setAttribute("id", "testcommand");
-  document.getElementById("mainCommandSet").appendChild(command);
-  command.addEventListener("command", window.sawEvent);
-
-  gTestSidebarItem.setAttribute("command", "testcommand");
-}, function() {
-  checkExpectedEvents({ command: 1 });
-  document.getElementById("testcommand").remove();
+  await hideSidebar();
+  await showSidebar();
+  is(SidebarUI.currentID, "viewHistorySidebar", "Selected sidebar remembered");
 });
-
-add_sidebar_task(
-  "Check that a sidebar that uses a command element with an oncommand attribute works",
-function() {
-  let command = document.createElement("command");
-  command.setAttribute("id", "testcommand");
-  command.setAttribute("oncommand", "window.sawEvent(event, true)");
-  document.getElementById("mainCommandSet").appendChild(command);
-
-  gTestSidebarItem.setAttribute("command", "testcommand");
-}, function() {
-  checkExpectedEvents({ oncommand: 1 });
-  document.getElementById("testcommand").remove();
-});
-
-add_sidebar_task("Check that a sidebar that uses a command element with a " +
-  "command event listener and oncommand attribute works",
-function() {
-  let command = document.createElement("command");
-  command.setAttribute("id", "testcommand");
-  command.setAttribute("oncommand", "window.sawEvent(event, true)");
-  document.getElementById("mainCommandSet").appendChild(command);
-  command.addEventListener("command", window.sawEvent);
-
-  gTestSidebarItem.setAttribute("command", "testcommand");
-}, function() {
-  checkExpectedEvents({ command: 1, oncommand: 1 });
-  document.getElementById("testcommand").remove();
-});
-
-add_sidebar_task(
-  "A sidebar with a command element will still see click events",
-function() {
-  let command = document.createElement("command");
-  command.setAttribute("id", "testcommand");
-  command.setAttribute("oncommand", "window.sawEvent(event, true)");
-  document.getElementById("mainCommandSet").appendChild(command);
-  command.addEventListener("command", window.sawEvent);
-
-  gTestSidebarItem.setAttribute("command", "testcommand");
-  gTestSidebarItem.addEventListener("click", window.sawEvent);
-}, function() {
-  checkExpectedEvents({ click: 1, command: 1, oncommand: 1 });
-  document.getElementById("testcommand").remove();
-});