зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1457111 - Implement copy link adress option. r=nchevobbe
Before this change, when we tried to select a URL to copy, the label "Copy Message" or "Copy Object" was displayed which does not represent the context. You can now detect if a link exists and the label is "Copy link address" Differential Revision: https://phabricator.services.mozilla.com/D21136 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
47ef72825f
Коммит
06f53c0bdb
|
@ -23,18 +23,29 @@ add_task(async function() {
|
|||
info("Test Copy URL menu item for text log");
|
||||
|
||||
info("Logging a text message in the content window");
|
||||
const onLogMessage = waitForMessage(hud, "simple text message");
|
||||
const onLogMessage = waitForMessage(hud, "stringLog");
|
||||
await ContentTask.spawn(gBrowser.selectedBrowser, null, () => {
|
||||
content.wrappedJSObject.console.log("simple text message");
|
||||
content.wrappedJSObject.stringLog();
|
||||
});
|
||||
let message = await onLogMessage;
|
||||
ok(message, "Text log found in the console");
|
||||
|
||||
info("Open and check the context menu for the logged text message");
|
||||
let menuPopup = await openContextMenu(hud, message.node);
|
||||
|
||||
let copyURLItem = menuPopup.querySelector(CONTEXT_MENU_ID);
|
||||
ok(!copyURLItem, "Copy URL menu item is hidden for a simple text message");
|
||||
|
||||
info("Open and check the context menu for the logged text message");
|
||||
const locationElement = message.node.querySelector(".frame-link-source-inner");
|
||||
menuPopup = await openContextMenu(hud, locationElement);
|
||||
copyURLItem = menuPopup.querySelector(CONTEXT_MENU_ID);
|
||||
ok(copyURLItem, "The Copy Link Location entry is displayed");
|
||||
|
||||
info("Click on Copy URL menu item and wait for clipboard to be updated");
|
||||
await waitForClipboardPromise(() => copyURLItem.click(), TEST_URI);
|
||||
ok(true, "Expected text was copied to the clipboard.");
|
||||
|
||||
await hideContextMenu(hud);
|
||||
hud.ui.clearOutput();
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ function createContextMenu(webConsoleUI, parentNode, {
|
|||
rootActorId,
|
||||
executionPoint,
|
||||
toolbox,
|
||||
url,
|
||||
}) {
|
||||
const win = parentNode.ownerDocument.defaultView;
|
||||
const selection = win.getSelection();
|
||||
|
@ -207,6 +208,15 @@ function createContextMenu(webConsoleUI, parentNode, {
|
|||
}));
|
||||
}
|
||||
|
||||
if (url) {
|
||||
menu.append(new MenuItem({
|
||||
id: "console-menu-copy-url",
|
||||
label: l10n.getStr("webconsole.menu.copyURL.label"),
|
||||
accesskey: l10n.getStr("webconsole.menu.copyURL.accesskey"),
|
||||
click: () => clipboardHelper.copyString(url),
|
||||
}));
|
||||
}
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
|
|
|
@ -198,6 +198,9 @@ class WebConsoleWrapper {
|
|||
const messageEl = target.closest(".message");
|
||||
const clipboardText = getElementText(messageEl);
|
||||
|
||||
const linkEl = target.closest("a[href]");
|
||||
const url = linkEl && linkEl.href;
|
||||
|
||||
const messageVariable = target.closest(".objectBox");
|
||||
// Ensure that console.group and console.groupCollapsed commands are not captured
|
||||
const variableText = (messageVariable
|
||||
|
@ -233,6 +236,7 @@ class WebConsoleWrapper {
|
|||
rootActorId,
|
||||
executionPoint,
|
||||
toolbox: this.toolbox,
|
||||
url,
|
||||
});
|
||||
|
||||
// Emit the "menu-open" event for testing.
|
||||
|
|
Загрузка…
Ссылка в новой задаче