Bug 1407737 - Don't persist sidebar state unless if the last window is being closed. r=mikedeboer
authorBrian Grinstead <bgrinstead@mozilla.com>
Wed, 18 Oct 2017 08:32:41 -0700
changeset 386961 ff21cb09fe2f24766e7274dcbe71c2425dfb9682
parent 386960 7aa64ad05e2eea45037ac9adfe1a566fc92a0e38
child 386962 a04860cd9c8895aaaadaa32efec5e8b2cdcd24e8
child 387041 1347bb0b084bf245ff9315d07e3646547aa0c8e0
push id32704
push userarchaeopteryx@coole-files.de
push dateWed, 18 Oct 2017 22:05:23 +0000
treeherdermozilla-central@a04860cd9c88 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1407737
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1407737 - Don't persist sidebar state unless if the last window is being closed. r=mikedeboer MozReview-Commit-ID: 7wBtCZDG1V3
browser/base/content/browser-sidebar.js
browser/base/content/test/sidebar/browser_sidebar_adopt.js
--- a/browser/base/content/browser-sidebar.js
+++ b/browser/base/content/browser-sidebar.js
@@ -62,17 +62,16 @@ var SidebarUI = {
       this.toggleSwitcherPanel();
     });
   },
 
   uninit() {
     // If this is the last browser window, persist various values that should be
     // remembered for after a restart / reopening a browser window.
     let enumerator = Services.wm.getEnumerator("navigator:browser");
-    enumerator.getNext();
     if (!enumerator.hasMoreElements()) {
       document.persist("sidebar-box", "sidebarcommand");
 
       let xulStore = Cc["@mozilla.org/xul/xulstore;1"].getService(Ci.nsIXULStore);
       if (this._box.hasAttribute("positionend")) {
         document.persist("sidebar-box", "positionend");
       } else {
         xulStore.removeValue(document.documentURI, "sidebar-box", "positionend");
--- a/browser/base/content/test/sidebar/browser_sidebar_adopt.js
+++ b/browser/base/content/test/sidebar/browser_sidebar_adopt.js
@@ -8,30 +8,46 @@
 registerCleanupFunction(() => {
   SidebarUI.hide();
 });
 
 function failIfSidebarFocusedFires() {
   ok(false, "This event shouldn't have fired");
 }
 
-add_task(async function() {
+add_task(async function testAdoptedTwoWindows() {
+  // First open a new window, show the sidebar in that window, and close it.
+  // Then, open another new window and confirm that the sidebar is closed since it is
+  // being adopted from the main window which doesn't have a shown sidebar. See Bug 1407737.
+  info("Ensure that sidebar state is adopted only from the opener");
+
+  let win1 = await BrowserTestUtils.openNewBrowserWindow({opener: window});
+  await win1.SidebarUI.show("viewBookmarksSidebar");
+  await BrowserTestUtils.closeWindow(win1);
+
+  let win2 = await BrowserTestUtils.openNewBrowserWindow({opener: window});
+  ok(!win2.document.getElementById("sidebar-button").hasAttribute("checked"), "Sidebar button isn't checked");
+  ok(!win2.SidebarUI.isOpen, "Sidebar is closed");
+  await BrowserTestUtils.closeWindow(win2);
+});
+
+add_task(async function testEventsReceivedInMainWindow() {
   info("Opening the sidebar and expecting both SidebarShown and SidebarFocused events");
 
   let initialShown = BrowserTestUtils.waitForEvent(window, "SidebarShown");
   let initialFocus = BrowserTestUtils.waitForEvent(window, "SidebarFocused");
 
   await SidebarUI.show("viewBookmarksSidebar");
   await initialShown;
   await initialFocus;
 
   ok(true, "SidebarShown and SidebarFocused events fired on a new window");
 });
 
-add_task(async function() {
+add_task(async function testEventReceivedInNewWindow() {
   info("Opening a new window and expecting the SidebarFocused event to not fire");
 
   let promiseNewWindow = BrowserTestUtils.waitForNewWindow(false);
   BrowserTestUtils.openNewBrowserWindow({opener: window});
   let win = await promiseNewWindow;
 
   let adoptedShown = BrowserTestUtils.waitForEvent(win, "SidebarShown");
   win.addEventListener("SidebarFocused", failIfSidebarFocusedFires);