Bug 1492702 - Send the contextual link to the device, not the selected tab when a link is right-clicked. r=markh

Differential Revision: https://phabricator.services.mozilla.com/D6980

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jared Wein 2018-09-27 07:49:05 +00:00
Родитель a64e86917a
Коммит b08075b904
4 изменённых файлов: 28 добавлений и 25 удалений

Просмотреть файл

@ -267,7 +267,7 @@
accesskey="&sendPageToDevice.accesskey;"
hidden="true">
<menupopup id="context-sendpagetodevice-popup"
onpopupshowing="(() => { gSync.populateSendTabToDevicesMenu(event.target, gBrowser.selectedTab); })()"/>
onpopupshowing="(() => { gSync.populateSendTabToDevicesMenu(event.target, gBrowser.currentURI.spec, gBrowser.contentTitle, gBrowser.selectedTab.multiselected); })()"/>
</menu>
<menuseparator id="context-sep-viewbgimage"/>
<menuitem id="context-viewbgimage"
@ -316,7 +316,7 @@
accesskey="&sendLinkToDevice.accesskey;"
hidden="true">
<menupopup id="context-sendlinktodevice-popup"
onpopupshowing="gSync.populateSendTabToDevicesMenu(event.target, gBrowser.selectedTab);"/>
onpopupshowing="gSync.populateSendTabToDevicesMenu(event.target, gContextMenu.linkURL, gContextMenu.linkTextStr);"/>
</menu>
<menuseparator id="frame-sep"/>
<menu id="frame" label="&thisFrameMenu.label;" accesskey="&thisFrameMenu.accesskey;">

Просмотреть файл

@ -1036,10 +1036,14 @@ BrowserPageActions.sendToDevice = {
onShowingSubview(panelViewNode) {
let bodyNode = panelViewNode.querySelector(".panel-subview-body");
let panelNode = panelViewNode.closest("panel");
let browser = gBrowser.selectedBrowser;
let url = browser.currentURI.spec;
let title = browser.contentTitle;
let multiselected = gBrowser.selectedTab.multiselected;
// This is on top because it also clears the device list between state
// changes.
gSync.populateSendTabToDevicesMenu(bodyNode, gBrowser.selectedTab, (clientId, name, clientType, lastModified) => {
gSync.populateSendTabToDevicesMenu(bodyNode, url, title, multiselected, (clientId, name, clientType, lastModified) => {
if (!name) {
return document.createXULElement("toolbarseparator");
}

Просмотреть файл

@ -361,7 +361,7 @@ var gSync = {
}
},
populateSendTabToDevicesMenu(devicesPopup, aTab, createDeviceNodeFn) {
populateSendTabToDevicesMenu(devicesPopup, url, title, multiselected, createDeviceNodeFn) {
if (!createDeviceNodeFn) {
createDeviceNodeFn = (clientId, name, clientType, lastModified) => {
let eltName = name ? "menuitem" : "menuseparator";
@ -386,7 +386,7 @@ var gSync = {
const state = UIState.get();
if (state.status == UIState.STATUS_SIGNED_IN && this.remoteClients.length > 0) {
this._appendSendTabDeviceList(fragment, createDeviceNodeFn, aTab);
this._appendSendTabDeviceList(fragment, createDeviceNodeFn, url, title, multiselected);
} else if (state.status == UIState.STATUS_SIGNED_IN) {
this._appendSendTabSingleDevice(fragment, createDeviceNodeFn);
} else if (state.status == UIState.STATUS_NOT_VERIFIED ||
@ -402,26 +402,25 @@ var gSync = {
// TODO: once our transition from the old-send tab world is complete,
// this list should be built using the FxA device list instead of the client
// collection.
_appendSendTabDeviceList(fragment, createDeviceNodeFn, tab) {
let tabsToSend = tab.multiselected ? gBrowser.selectedTabs : [tab];
function getTabUrl(t) {
return t.linkedBrowser.currentURI.spec;
}
function getTabTitle(t) {
return t.linkedBrowser.contentTitle;
}
_appendSendTabDeviceList(fragment, createDeviceNodeFn, url, title, multiselected) {
let tabsToSend = multiselected ?
gBrowser.selectedTabs.map(t => {
return {
url: t.linkedBrowser.currentURI.spec,
title: t.linkedBrowser.contentTitle,
};
}) : [{url, title}];
const onSendAllCommand = (event) => {
for (let t of tabsToSend) {
this.sendTabToDevice(getTabUrl(t), this.remoteClients, getTabTitle(t));
this.sendTabToDevice(t.url, this.remoteClients, t.title);
}
};
const onTargetDeviceCommand = (event) => {
const clientId = event.target.getAttribute("clientId");
const client = this.remoteClients.find(c => c.id == clientId);
for (let t of tabsToSend) {
this.sendTabToDevice(getTabUrl(t), [client], getTabTitle(t));
this.sendTabToDevice(t.url, [client], t.title);
}
};

Просмотреть файл

@ -34,6 +34,10 @@ add_task(async function test_page_contextmenu() {
add_task(async function test_link_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("https://www.example.org/", [{id: 1, name: "Foo"}], "Click on me!!");
// Add a link to the page
await ContentTask.spawn(gBrowser.selectedBrowser, null, () => {
@ -44,17 +48,13 @@ add_task(async function test_link_contextmenu() {
content.document.body.appendChild(a);
});
await openContentContextMenu("#testingLink", "context-sendlinktodevice");
is(document.getElementById("context-sendlinktodevice").hidden, false, "Send tab to device is shown");
is(document.getElementById("context-sendlinktodevice").disabled, false, "Send tab to device is enabled");
checkPopup([
{ label: "Foo" },
{ label: "Bar" },
"----",
{ label: "Send to All Devices" },
]);
await openContentContextMenu("#testingLink", "context-sendlinktodevice", "context-sendlinktodevice-popup");
is(document.getElementById("context-sendlinktodevice").hidden, false, "Send link to device is shown");
is(document.getElementById("context-sendlinktodevice").disabled, false, "Send link to device is enabled");
document.getElementById("context-sendlinktodevice-popup").querySelector("menuitem").click();
await hideContentContextMenu();
expectation.verify();
sandbox.restore();
});