Bug 820489 - don't remove the sidebar origin attribute before unload. r=gavin
authorMark Hammond <mhammond@skippinet.com.au>
Fri, 14 Dec 2012 15:42:37 +1100
changeset 116032 21362f7ca84934e98f278d735a3976805f9502f6
parent 116031 042b4465282212b74a9502a8cff6faa53a71d0ff
child 116033 f4beffe262c5ee5f48d254526183165e0e566a1a
push id24034
push useremorley@mozilla.com
push dateFri, 14 Dec 2012 15:28:57 +0000
treeherdermozilla-central@50d8f411d305 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs820489
milestone20.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 820489 - don't remove the sidebar origin attribute before unload. r=gavin
browser/base/content/browser-social.js
browser/base/content/test/social/browser_social_sidebar.js
--- a/browser/base/content/browser-social.js
+++ b/browser/base/content/browser-social.js
@@ -1088,36 +1088,32 @@ var SocialSidebar = {
     // Also set the command "checked" state accordingly.
     let hideSidebar = !this.canShow || !this.opened;
     let broadcaster = document.getElementById("socialSidebarBroadcaster");
     broadcaster.hidden = hideSidebar;
     command.setAttribute("checked", !hideSidebar);
 
     let sbrowser = document.getElementById("social-sidebar-browser");
 
-    if (Social.provider)
-      sbrowser.setAttribute("origin", Social.provider.origin);
-    else
-      sbrowser.removeAttribute("origin");
-
     if (hideSidebar) {
       sbrowser.removeEventListener("load", SocialSidebar._loadListener, true);
       this.setSidebarVisibilityState(false);
       // If we've been disabled, unload the sidebar content immediately;
       // if the sidebar was just toggled to invisible, wait a timeout
       // before unloading.
       if (!this.canShow) {
         this.unloadSidebar();
       } else {
         this._unloadTimeoutId = setTimeout(
           this.unloadSidebar,
           Services.prefs.getIntPref("social.sidebar.unload_timeout_ms")
         );
       }
     } else {
+      sbrowser.setAttribute("origin", Social.provider.origin);
       if (Social.provider.errorState == "frameworker-error") {
         SocialSidebar.setSidebarErrorMessage("frameworker-error");
         return;
       }
 
       // Make sure the right sidebar URL is loaded
       if (sbrowser.getAttribute("src") != Social.provider.sidebarURL) {
         sbrowser.setAttribute("src", Social.provider.sidebarURL);
--- a/browser/base/content/test/social/browser_social_sidebar.js
+++ b/browser/base/content/test/social/browser_social_sidebar.js
@@ -23,36 +23,67 @@ function doTest(finishcb) {
   let sidebar = document.getElementById("social-sidebar-box");
   let browser = sidebar.firstChild;
 
   function checkShown(shouldBeShown) {
     is(command.getAttribute("checked"), shouldBeShown ? "true" : "false",
        "toggle command should be " + (shouldBeShown ? "checked" : "unchecked"));
     is(sidebar.hidden, !shouldBeShown,
        "sidebar should be " + (shouldBeShown ? "visible" : "hidden"));
-    is(Services.prefs.getBoolPref("social.sidebar.open"), shouldBeShown,
-       "sidebar open pref should be " + shouldBeShown);
-    if (shouldBeShown)
+    // The sidebar.open pref only reflects the actual state of the sidebar
+    // when social is enabled.
+    if (Social.enabled)
+      is(Services.prefs.getBoolPref("social.sidebar.open"), shouldBeShown,
+         "sidebar open pref should be " + shouldBeShown);
+    if (shouldBeShown) {
       is(browser.getAttribute('src'), Social.provider.sidebarURL, "sidebar url should be set");
+      // We don't currently check docShellIsActive as this is only set
+      // after load event fires, and the tests below explicitly wait for this
+      // anyway.
+    }
+    else {
+      ok(!browser.docShellIsActive, "sidebar should have an inactive docshell");
+      // sidebar will only be immediately unloaded (and thus set to
+      // about:blank) when canShow is false.
+      if (SocialSidebar.canShow) {
+        // should not have unloaded so will still be the provider URL.
+        is(browser.getAttribute('src'), Social.provider.sidebarURL, "sidebar url should be set");
+      } else {
+        // should have been an immediate unload.
+        is(browser.getAttribute('src'), "about:blank", "sidebar url should be blank");
+      }
+    }
   }
 
   // First check the the sidebar is initially visible, and loaded
   ok(!command.hidden, "toggle command should be visible");
   checkShown(true);
 
   browser.addEventListener("socialFrameHide", function sidebarhide() {
     browser.removeEventListener("socialFrameHide", sidebarhide);
 
     checkShown(false);
 
     browser.addEventListener("socialFrameShow", function sidebarshow() {
       browser.removeEventListener("socialFrameShow", sidebarshow);
 
       checkShown(true);
 
+      // Set Social.enabled = false and check everything is as expected.
+      Social.enabled = false;
+      checkShown(false);
+
+      Social.enabled = true;
+      checkShown(true);
+
+      // And an edge-case - disable social and reset the provider.
+      Social.provider = null;
+      Social.enabled = false;
+      checkShown(false);
+
       // Finish the test
       finishcb();
     });
 
     // Toggle it back on
     info("Toggling sidebar back on");
     Social.toggleSidebar();
   });