Bug 1496309 - Fix arguments to populateSendTabToDevicesMenu and add automated test for coverage. r=Felipe
authorJared Wein <jwein@mozilla.com>
Thu, 04 Oct 2018 18:37:50 +0000
changeset 495391 90f4fff5f1453a2eb43c5c7d37a380dde2c7b204
parent 495390 31e9bd2f1ef71bb9241dda415bb4f1e12bb9c59c
child 495392 a5ebcd6b0fbe7f84220120d60daac61cc9bc5eb9
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe
bugs1496309
milestone64.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 1496309 - Fix arguments to populateSendTabToDevicesMenu and add automated test for coverage. r=Felipe Differential Revision: https://phabricator.services.mozilla.com/D7684
browser/base/content/browser-context.inc
browser/base/content/browser.xul
browser/base/content/test/sync/browser_contextmenu_sendtab.js
--- a/browser/base/content/browser-context.inc
+++ b/browser/base/content/browser-context.inc
@@ -262,17 +262,17 @@
       <menuseparator id="context-sep-sendpagetodevice" class="sync-ui-item"
                      hidden="true"/>
       <menu id="context-sendpagetodevice"
             class="sync-ui-item"
             label="&sendPageToDevice.label;"
             accesskey="&sendPageToDevice.accesskey;"
             hidden="true">
         <menupopup id="context-sendpagetodevice-popup"
-                   onpopupshowing="(() => { gSync.populateSendTabToDevicesMenu(event.target, gBrowser.currentURI.spec, gBrowser.contentTitle, gBrowser.selectedTab.multiselected); })()"/>
+                   onpopupshowing="(() => { gSync.populateSendTabToDevicesMenu(event.target, gBrowser.currentURI.spec, gBrowser.contentTitle); })()"/>
       </menu>
       <menuseparator id="context-sep-viewbgimage"/>
       <menuitem id="context-viewbgimage"
                 label="&viewBGImageCmd.label;"
                 accesskey="&viewBGImageCmd.accesskey;"
                 oncommand="gContextMenu.viewBGImage(event);"
                 onclick="checkForMiddleClick(this, event);"/>
       <menuitem id="context-undo"
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -174,17 +174,17 @@ xmlns="http://www.w3.org/1999/xhtml"
                     accesskey="&moveToNewWindow.accesskey;"
                     tbattr="tabbrowser-multiple"
                     oncommand="gBrowser.replaceTabsWithWindow(TabContextMenu.contextTab);"/>
         </menupopup>
       </menu>
       <menu id="context_sendTabToDevice"
             class="sync-ui-item">
         <menupopup id="context_sendTabToDevicePopupMenu"
-                   onpopupshowing="gSync.populateSendTabToDevicesMenu(event.target, TabContextMenu.contextTab);"/>
+                   onpopupshowing="gSync.populateSendTabToDevicesMenu(event.target, TabContextMenu.contextTab.linkedBrowser.currentURI.spec, TabContextMenu.contextTab.linkedBrowser.contentTitle, TabContextMenu.contextTab.multiselected);"/>
       </menu>
       <menuseparator/>
       <menuitem id="context_reloadAllTabs" label="&reloadAllTabs.label;" accesskey="&reloadAllTabs.accesskey;"
                 tbattr="tabbrowser-multiple-visible"
                 oncommand="gBrowser.reloadAllTabs();"/>
       <menuseparator/>
       <menu id="context_closeTabOptions"
             label="&closeTabOptions.label;"
--- a/browser/base/content/test/sync/browser_contextmenu_sendtab.js
+++ b/browser/base/content/test/sync/browser_contextmenu_sendtab.js
@@ -21,30 +21,41 @@ function updateTabContextMenu(tab) {
   is(window.TabContextMenu.contextTab, tab, "TabContextMenu context is the expected tab");
   menu.hidePopup();
 }
 
 add_task(async function setup() {
   await promiseSyncReady();
   // gSync.init() is called in a requestIdleCallback. Force its initialization.
   gSync.init();
-  is(gBrowser.visibleTabs.length, 1, "there is one visible tab");
+  sinon.stub(Weave.Service.clientsEngine, "getClientType").returns("desktop");
+  await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
+  registerCleanupFunction(() => {
+    gBrowser.removeCurrentTab();
+  });
+  is(gBrowser.visibleTabs.length, 2, "there are two visible tabs");
 });
 
-// We are not testing the devices popup contents, since it is already tested by
-// browser_contextmenu_sendpage.js and the code to populate it is the same.
-
 add_task(async function test_tab_contextmenu() {
   const sandbox = setupSendTabMocks({ syncReady: true, clientsSynced: true, remoteClients: remoteClientsFixture,
                                       state: UIState.STATUS_SIGNED_IN, isSendableURI: true });
+  let expectation = sandbox.mock(gSync)
+                           .expects("sendTabToDevice")
+                           .once()
+                           .withExactArgs("about:mozilla", [{id: 1, name: "Foo"}], "The Book of Mozilla, 11:14");
 
   updateTabContextMenu(testTab);
+  await openTabContextMenu("context_sendTabToDevice");
   is(document.getElementById("context_sendTabToDevice").hidden, false, "Send tab to device is shown");
   is(document.getElementById("context_sendTabToDevice").disabled, false, "Send tab to device is enabled");
 
+  document.getElementById("context_sendTabToDevicePopupMenu").querySelector("menuitem").click();
+
+  await hideTabContextMenu();
+  expectation.verify();
   sandbox.restore();
 });
 
 add_task(async function test_tab_contextmenu_unconfigured() {
   const sandbox = setupSendTabMocks({ syncReady: true, clientsSynced: true, remoteClients: remoteClientsFixture,
                                       state: UIState.STATUS_NOT_CONFIGURED, isSendableURI: true });
 
   updateTabContextMenu(testTab);
@@ -104,8 +115,31 @@ add_task(async function test_tab_context
   gSync.onSyncDisabled();
 
   updateTabContextMenu(testTab);
   is(document.getElementById("context_sendTabToDevice").hidden, true, "Send tab to device is hidden");
 
   getter.restore();
   [...document.querySelectorAll(".sync-ui-item")].forEach(e => e.hidden = false);
 });
+
+async function openTabContextMenu(openSubmenuId = null) {
+  const contextMenu = document.getElementById("tabContextMenu");
+  is(contextMenu.state, "closed", "checking if popup is closed");
+
+  const awaitPopupShown = BrowserTestUtils.waitForEvent(contextMenu, "popupshown");
+  EventUtils.synthesizeMouseAtCenter(gBrowser.selectedTab, {type: "contextmenu", button: 2});
+  await awaitPopupShown;
+
+  if (openSubmenuId) {
+    const menuPopup = document.getElementById(openSubmenuId).menupopup;
+    const menuPopupPromise = BrowserTestUtils.waitForEvent(menuPopup, "popupshown");
+    menuPopup.openPopup();
+    await menuPopupPromise;
+  }
+}
+
+async function hideTabContextMenu() {
+  const contextMenu = document.getElementById("tabContextMenu");
+  const awaitPopupHidden = BrowserTestUtils.waitForEvent(contextMenu, "popuphidden");
+  contextMenu.hidePopup();
+  await awaitPopupHidden;
+}