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

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

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

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

@ -361,7 +361,7 @@ var gSync = {
} }
}, },
populateSendTabToDevicesMenu(devicesPopup, aTab, createDeviceNodeFn) { populateSendTabToDevicesMenu(devicesPopup, url, title, multiselected, createDeviceNodeFn) {
if (!createDeviceNodeFn) { if (!createDeviceNodeFn) {
createDeviceNodeFn = (clientId, name, clientType, lastModified) => { createDeviceNodeFn = (clientId, name, clientType, lastModified) => {
let eltName = name ? "menuitem" : "menuseparator"; let eltName = name ? "menuitem" : "menuseparator";
@ -386,7 +386,7 @@ var gSync = {
const state = UIState.get(); const state = UIState.get();
if (state.status == UIState.STATUS_SIGNED_IN && this.remoteClients.length > 0) { 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) { } else if (state.status == UIState.STATUS_SIGNED_IN) {
this._appendSendTabSingleDevice(fragment, createDeviceNodeFn); this._appendSendTabSingleDevice(fragment, createDeviceNodeFn);
} else if (state.status == UIState.STATUS_NOT_VERIFIED || } 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, // 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 // this list should be built using the FxA device list instead of the client
// collection. // collection.
_appendSendTabDeviceList(fragment, createDeviceNodeFn, tab) { _appendSendTabDeviceList(fragment, createDeviceNodeFn, url, title, multiselected) {
let tabsToSend = tab.multiselected ? gBrowser.selectedTabs : [tab]; let tabsToSend = multiselected ?
gBrowser.selectedTabs.map(t => {
function getTabUrl(t) { return {
return t.linkedBrowser.currentURI.spec; url: t.linkedBrowser.currentURI.spec,
} title: t.linkedBrowser.contentTitle,
function getTabTitle(t) { };
return t.linkedBrowser.contentTitle; }) : [{url, title}];
}
const onSendAllCommand = (event) => { const onSendAllCommand = (event) => {
for (let t of tabsToSend) { 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 onTargetDeviceCommand = (event) => {
const clientId = event.target.getAttribute("clientId"); const clientId = event.target.getAttribute("clientId");
const client = this.remoteClients.find(c => c.id == clientId); const client = this.remoteClients.find(c => c.id == clientId);
for (let t of tabsToSend) { 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() { add_task(async function test_link_contextmenu() {
const sandbox = setupSendTabMocks({ syncReady: true, clientsSynced: true, remoteClients: remoteClientsFixture, const sandbox = setupSendTabMocks({ syncReady: true, clientsSynced: true, remoteClients: remoteClientsFixture,
state: UIState.STATUS_SIGNED_IN, isSendableURI: true }); 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 // Add a link to the page
await ContentTask.spawn(gBrowser.selectedBrowser, null, () => { await ContentTask.spawn(gBrowser.selectedBrowser, null, () => {
@ -44,17 +48,13 @@ add_task(async function test_link_contextmenu() {
content.document.body.appendChild(a); content.document.body.appendChild(a);
}); });
await openContentContextMenu("#testingLink", "context-sendlinktodevice"); await openContentContextMenu("#testingLink", "context-sendlinktodevice", "context-sendlinktodevice-popup");
is(document.getElementById("context-sendlinktodevice").hidden, false, "Send tab to device is shown"); is(document.getElementById("context-sendlinktodevice").hidden, false, "Send link to device is shown");
is(document.getElementById("context-sendlinktodevice").disabled, false, "Send tab to device is enabled"); is(document.getElementById("context-sendlinktodevice").disabled, false, "Send link to device is enabled");
checkPopup([ document.getElementById("context-sendlinktodevice-popup").querySelector("menuitem").click();
{ label: "Foo" },
{ label: "Bar" },
"----",
{ label: "Send to All Devices" },
]);
await hideContentContextMenu(); await hideContentContextMenu();
expectation.verify();
sandbox.restore(); sandbox.restore();
}); });