Bug 1454705 - Fix display of share panel in Address bar. r=Gijs
authorDale Harvey <dale@arandomurl.com>
Wed, 18 Apr 2018 15:48:31 +0100
changeset 414490 64cb5a4a986e1a4f283aca15dbde46fbb68bc8f0
parent 414489 9003972112e3a5611f5ca5ea2c4ba32f79da38c6
child 414491 16bb3f3c01cbaf2ec6990cb4499dfbe096d994fc
push id62905
push userdharvey@mozilla.com
push dateThu, 19 Apr 2018 12:41:50 +0000
treeherderautoland@64cb5a4a986e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1454705
milestone61.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 1454705 - Fix display of share panel in Address bar. r=Gijs MozReview-Commit-ID: 9lxU0plGqYa
browser/base/content/browser-pageActions.js
browser/base/content/test/urlbar/browser_page_action_menu_share_mac.js
browser/themes/osx/browser.css
browser/themes/osx/share.svg
--- a/browser/base/content/browser-pageActions.js
+++ b/browser/base/content/browser-pageActions.js
@@ -1266,19 +1266,21 @@ BrowserPageActions.shareURL = {
   },
 
   onPlacedInPanel(buttonNode) {
     let action = PageActions.actionForID("shareURL");
     BrowserPageActions.takeActionTitleFromPanel(action);
   },
 
   onShowingSubview(panelViewNode) {
+    let bodyNode = panelViewNode.querySelector(".panel-subview-body");
+
     // We cache the providers + the UI if the user selects the share
     // panel multiple times while the panel is open.
-    if (this._cached) {
+    if (this._cached && bodyNode.childNodes.length > 0) {
       return;
     }
 
     let sharingService = this._sharingService;
     let url = gBrowser.selectedBrowser.currentURI;
     let currentURI = gURLBar.makeURIReadable(url).displaySpec;
     let shareProviders = sharingService.getSharingProviders(currentURI);
     let fragment = document.createDocumentFragment();
@@ -1296,17 +1298,16 @@ BrowserPageActions.shareURL = {
           sharingService.shareUrl(shareTitle, currentURI);
         }
         PanelMultiView.hidePopup(BrowserPageActions.panelNode);
       });
 
       fragment.appendChild(item);
     });
 
-    let bodyNode = panelViewNode.querySelector(".panel-subview-body");
     while (bodyNode.firstChild) {
       bodyNode.firstChild.remove();
     }
     bodyNode.appendChild(fragment);
     this._cached = true;
   }
 };
 
--- a/browser/base/content/test/urlbar/browser_page_action_menu_share_mac.js
+++ b/browser/base/content/test/urlbar/browser_page_action_menu_share_mac.js
@@ -2,16 +2,18 @@
  * 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";
 
 /* global sinon */
 Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js");
 
+const URL = "http://example.org/";
+
 // Keep track of title of service we chose to share with
 let sharedTitle;
 let sharedUrl;
 
 let mockShareData = [{
   title: "NSA",
   menuItemTitle: "National Security Agency",
   image: "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEA" +
@@ -33,21 +35,17 @@ let stub = sinon.stub(BrowserPageActions
 registerCleanupFunction(async function() {
   stub.restore();
   delete window.sinon;
   await EventUtils.synthesizeNativeMouseMove(document.documentElement, 0, 0);
   await PlacesUtils.history.clear();
 });
 
 add_task(async function shareURL() {
-  // Open an actionable page so that the main page action button appears.  (It
-  // does not appear on about:blank for example.)
-  let url = "http://example.org/";
-
-  await BrowserTestUtils.withNewTab(url, async () => {
+  await BrowserTestUtils.withNewTab(URL, async () => {
     // Open the panel.
     await promisePageActionPanelOpen();
 
     // Click Share URL.
     let shareURLButton = document.getElementById("pageAction-panel-shareURL");
     let viewPromise = promisePageActionViewShown();
     EventUtils.synthesizeMouseAtCenter(shareURLButton, {});
 
@@ -62,11 +60,64 @@ add_task(async function shareURL() {
     // given the title of service to share with
     EventUtils.synthesizeMouseAtCenter(shareButton, {});
     await hiddenPromise;
 
     Assert.equal(sharedTitle, mockShareData[0].title,
                  "Shared with the correct title");
     Assert.equal(sharedUrl, "http://example.org/",
                  "Shared correct URL");
-
   });
 });
+
+add_task(async function shareURLAddressBar() {
+  await BrowserTestUtils.withNewTab(URL, async () => {
+    // Open pageAction panel
+    await promisePageActionPanelOpen();
+
+    // Right click the Share button
+    let contextMenuPromise = promisePanelShown("pageActionContextMenu");
+    let shareURLButton = document.getElementById("pageAction-panel-shareURL");
+    EventUtils.synthesizeMouseAtCenter(shareURLButton, {
+      type: "contextmenu",
+      button: 2,
+    });
+    await contextMenuPromise;
+
+    // Click "Add to Address Bar"
+    contextMenuPromise = promisePanelHidden("pageActionContextMenu");
+    let ctxMenuButton = document.querySelector("#pageActionContextMenu " +
+                                               ".pageActionContextMenuItem");
+    EventUtils.synthesizeMouseAtCenter(ctxMenuButton, {});
+    await contextMenuPromise;
+
+    // Wait for the Share button to be added
+    await BrowserTestUtils.waitForCondition(() => {
+      return document.getElementById("pageAction-urlbar-shareURL");
+    }, "Waiting for the share url button to be added to url bar");
+
+
+    // Press the Share button
+    let shareButton = document.getElementById("pageAction-urlbar-shareURL");
+    let viewPromise = promisePageActionPanelShown();
+    EventUtils.synthesizeMouseAtCenter(shareButton, {});
+    await viewPromise;
+
+    // Ensure we have share providers
+    let panel = document.getElementById("pageAction-urlbar-shareURL-subview-body");
+    Assert.equal(panel.childNodes.length, 1, "Has correct share receivers");
+
+    // Remove the Share URL button from the Address bar so we dont interfere
+    // with future tests
+    contextMenuPromise = promisePanelShown("pageActionContextMenu");
+    EventUtils.synthesizeMouseAtCenter(shareButton, {
+      type: "contextmenu",
+      button: 2,
+    });
+    await contextMenuPromise;
+
+    contextMenuPromise = promisePanelHidden("pageActionContextMenu");
+    ctxMenuButton = document.querySelector("#pageActionContextMenu " +
+                                           ".pageActionContextMenuItem");
+    EventUtils.synthesizeMouseAtCenter(ctxMenuButton, {});
+    await contextMenuPromise;
+  });
+});
--- a/browser/themes/osx/browser.css
+++ b/browser/themes/osx/browser.css
@@ -330,16 +330,17 @@ html|input.urlbar-input {
 }
 
 .urlbar-display {
   margin-top: 0;
   margin-bottom: 0;
   color: GrayText;
 }
 
+#pageAction-urlbar-shareURL,
 #pageAction-panel-shareURL {
   list-style-image: url("chrome://browser/skin/share.svg");
 }
 
 %include ../shared/urlbarSearchSuggestionsNotification.inc.css
 
 /* ----- AUTOCOMPLETE ----- */
 
--- a/browser/themes/osx/share.svg
+++ b/browser/themes/osx/share.svg
@@ -1,7 +1,7 @@
 <!-- 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/. -->
 <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
-  <path fill="context-fill" d="M12.707 4.294l-4-4A1 1 0 0 0 8.38.077a.984.984 0 0 0-.246-.05A.938.938 0 0 0 8 0a.938.938 0 0 0-.134.027.984.984 0 0 0-.246.05A1 1 0 0 0 7.291.3l-4 4a1 1 0 0 0 1.416 1.408L7 3.415V11a1 1 0 0 0 2 0V3.415l2.293 2.293a1 1 0 0 0 1.414-1.414z"></path>
-  <path fill="context-fill" d="M14 9a1 1 0 0 0-1 1v3a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1v-3a1 1 0 0 0-2 0v3a3 3 0 0 0 3 3h8a3 3 0 0 0 3-3v-3a1 1 0 0 0-1-1z"></path>
+  <path fill="context-fill" fill-opacity="context-fill-opacity" d="M12.707 4.294l-4-4A1 1 0 0 0 8.38.077a.984.984 0 0 0-.246-.05A.938.938 0 0 0 8 0a.938.938 0 0 0-.134.027.984.984 0 0 0-.246.05A1 1 0 0 0 7.291.3l-4 4a1 1 0 0 0 1.416 1.408L7 3.415V11a1 1 0 0 0 2 0V3.415l2.293 2.293a1 1 0 0 0 1.414-1.414z"></path>
+  <path fill="context-fill" fill-opacity="context-fill-opacity" d="M14 9a1 1 0 0 0-1 1v3a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1v-3a1 1 0 0 0-2 0v3a3 3 0 0 0 3 3h8a3 3 0 0 0 3-3v-3a1 1 0 0 0-1-1z"></path>
 </svg>