Bug 936712 - Open marks panel on first click if user not logged in. r=markh, a=bajaj
authorShane Caraveo <scaraveo@mozilla.com>
Fri, 22 Nov 2013 11:05:06 -0800
changeset 166629 39c91b039dcdae6fd47d53ae6e0c4a83a7386451
parent 166628 644e577111a07f197ebd1b96b8b0cb7b030d8b6d
child 166630 8dcdb738ddbc1e8fcd63015ebeb26c84d72d0b23
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh, bajaj
bugs936712
milestone27.0a2
Bug 936712 - Open marks panel on first click if user not logged in. r=markh, a=bajaj
browser/base/content/socialmarks.xml
browser/base/content/test/social/browser_social_marks.js
--- a/browser/base/content/socialmarks.xml
+++ b/browser/base/content/socialmarks.xml
@@ -140,21 +140,20 @@
         ]]></body>
       </method>
 
       <method name="markCurrentPage">
         <parameter name="aOpenPanel"/>
         <body><![CDATA[
         // we always set the src on click if it has not been set for this tab,
         // but we only want to open the panel if it was previously annotated.
-        let openPanel = this.isMarked || aOpenPanel;
+        let openPanel = this.isMarked || aOpenPanel || !this.provider.haveLoggedInUser();
         let src = this.getAttribute("src");
         if (!src || src == "about:blank") {
           this.loadPanel();
-          this.isMarked = true;
         }
         if (openPanel)
           this.panel.openPopup(this, "bottomcenter topright", 0, 0, false, false);
         ]]></body>
       </method>
 
       <method name="markLink">
         <parameter name="aUrl"/>
@@ -165,17 +164,16 @@
         }
         // initiated form an external source, such as gContextMenu, where
         // pageData is passed into us. In this case, we always load the iframe
         // and show it since the url may not be the browser tab, but an image,
         // link, etc. inside the page. We also "update" the iframe to the
         // previous url when it is closed.
         this.setAttribute("src", "about:blank");
         this.loadPanel({ url: aUrl });
-        this.isMarked = true;
         this.panel.openPopup(this, "bottomcenter topright", 0, 0, false, false);
         this.panel.addEventListener("popuphidden", function _hidden() {
           this.panel.removeEventListener("popuphidden", _hidden);
           this.update();
         }.bind(this), false);
         ]]></body>
       </method>
 
--- a/browser/base/content/test/social/browser_social_marks.js
+++ b/browser/base/content/test/social/browser_social_marks.js
@@ -194,32 +194,95 @@ var tests = {
           case "test-init-done":
             ok(true, "test-init-done received");
             ok(provider.profile.userName, "profile was set by test worker");
             // first click marks the page, second click opens the page. We have to
             // synthesize so the command event happens
             EventUtils.synthesizeMouseAtCenter(btn, {});
             // wait for the button to be marked, click to open panel
             waitForCondition(function() btn.isMarked, function() {
+              is(btn.panel.state, "closed", "panel should not be visible yet");
               EventUtils.synthesizeMouseAtCenter(btn, {});
             }, "button is marked");
             break;
           case "got-social-panel-visibility":
             ok(true, "got the panel message " + e.data.result);
             if (e.data.result == "shown") {
               // unmark the page via the button in the page
               let doc = btn.contentDocument;
               let unmarkBtn = doc.getElementById("unmark");
               ok(unmarkBtn, "got the panel unmark button");
               EventUtils.sendMouseEvent({type: "click"}, unmarkBtn, btn.contentWindow);
             } else {
               // page should no longer be marked
               port.close();
               waitForCondition(function() !btn.isMarked, function() {
-                // after closing the addons tab, verify provider is still installed
+                // cleanup after the page has been unmarked
+                gBrowser.tabContainer.addEventListener("TabClose", function onTabClose() {
+                  gBrowser.tabContainer.removeEventListener("TabClose", onTabClose);
+                    executeSoon(function () {
+                      ok(btn.disabled, "button is disabled");
+                      next();
+                    });
+                });
+                gBrowser.removeTab(tab);
+              }, "button unmarked");
+            }
+            break;
+        }
+      };
+      port.postMessage({topic: "test-init"});
+    });
+  },
+
+  testMarkPanelLoggedOut: function(next) {
+    // click on panel to open and wait for visibility
+    let provider = Social._getProviderFromOrigin(manifest2.origin);
+    ok(provider.enabled, "provider is enabled");
+    let id = "social-mark-button-" + provider.origin;
+    let btn = document.getElementById(id)
+    ok(btn, "got a mark button");
+    let port = provider.getWorkerPort();
+    ok(port, "got a port");
+
+    // verify markbutton is disabled when there is no browser url
+    ok(btn.disabled, "button is disabled");
+    let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html"
+    addTab(activationURL, function(tab) {
+      ok(!btn.disabled, "button is enabled");
+      port.onmessage = function (e) {
+        let topic = e.data.topic;
+        switch (topic) {
+          case "test-init-done":
+            ok(true, "test-init-done received");
+            ok(provider.profile.userName, "profile was set by test worker");
+            port.postMessage({topic: "test-logout"});
+            waitForCondition(function() !provider.profile.userName,
+                function() {
+                  // when the provider has not indicated to us that a user is
+                  // logged in, the first click opens the page.
+                  EventUtils.synthesizeMouseAtCenter(btn, {});
+                },
+                "profile was unset by test worker");
+            break;
+          case "got-social-panel-visibility":
+            ok(true, "got the panel message " + e.data.result);
+            if (e.data.result == "shown") {
+              // our test marks the page during the load event (see
+              // social_mark.html) regardless of login state, unmark the page
+              // via the button in the page
+              let doc = btn.contentDocument;
+              let unmarkBtn = doc.getElementById("unmark");
+              ok(unmarkBtn, "got the panel unmark button");
+              EventUtils.sendMouseEvent({type: "click"}, unmarkBtn, btn.contentWindow);
+            } else {
+              // page should no longer be marked
+              port.close();
+              waitForCondition(function() !btn.isMarked, function() {
+                // cleanup after the page has been unmarked
                 gBrowser.tabContainer.addEventListener("TabClose", function onTabClose() {
                   gBrowser.tabContainer.removeEventListener("TabClose", onTabClose);
                     executeSoon(function () {
                       ok(btn.disabled, "button is disabled");
                       next();
                     });
                 });
                 gBrowser.removeTab(tab);