Bug 1766821 - Only copy the value of a field. r=bomsy

Differential Revision: https://phabricator.services.mozilla.com/D145832
This commit is contained in:
Zoltán Szatmáry 2022-06-20 06:58:31 +00:00
parent 04713f06d1
commit 99952418e8
6 changed files with 55 additions and 38 deletions

View File

@ -1247,13 +1247,13 @@ netmonitor.trackingResource.enhancedTrackingProtection=Enhanced Tracking Protect
# enhanced tracking protection.
netmonitor.enhancedTrackingProtection.learnMore=Learn more about enhanced tracking protection
# LOCALIZATION NOTE (netmonitor.context.copy): This is the label displayed
# LOCALIZATION NOTE (netmonitor.context.copyValue): This is the label displayed
# for the copy sub-menu in the context menu for a request
netmonitor.context.copy=Copy
netmonitor.context.copyValue=Copy Value
# LOCALIZATION NOTE (netmonitor.context.copy.accesskey): This is the access key
# LOCALIZATION NOTE (netmonitor.context.copyValue.accesskey): This is the access key
# for the copy menu/sub-menu displayed in the context menu for a request
netmonitor.context.copy.accesskey=C
netmonitor.context.copyValue.accesskey=C
# LOCALIZATION NOTE (netmonitor.context.copyUrl): This is the label displayed
# on the context menu that copies the selected request's url

View File

@ -6,13 +6,13 @@
/**
* The default format for the content copied to the
* clipboard when the `Copy` option is selected.
* clipboard when the `Copy Value` option is selected.
*/
function baseCopyFormatter({ name, value, object, hasChildren }) {
if (hasChildren) {
return baseCopyAllFormatter({ [name]: value });
}
return `${name}: ${value}`;
return `${value}`;
}
/**

View File

@ -26,7 +26,7 @@ class HeadersPanelContextMenu {
constructor(props = {}) {
this.props = props;
this.copyAll = this.copyAll.bind(this);
this.copy = this.copy.bind(this);
this.copyValue = this.copyValue.bind(this);
}
/**
@ -38,14 +38,14 @@ class HeadersPanelContextMenu {
const { target } = event;
const menuItems = [
{
id: "headers-panel-context-menu-copy",
label: L10N.getStr("netmonitor.context.copy"),
accesskey: L10N.getStr("netmonitor.context.copy.accesskey"),
id: "headers-panel-context-menu-copyvalue",
label: L10N.getStr("netmonitor.context.copyValue"),
accesskey: L10N.getStr("netmonitor.context.copyValue.accesskey"),
click: () => {
const { name, value } = getSummaryContent(
target.closest(".tabpanel-summary-container")
);
this.copy(
this.copyValue(
{ name, value, object: null, hasChildren: false },
selection
);
@ -101,11 +101,11 @@ class HeadersPanelContextMenu {
}
/**
* Copies single item.
* Copies the value of a single item.
* @param {Object} object data object for specific node
* @param {Object} selection object representing the current selection
*/
copy(object, selection) {
copyValue(object, selection) {
let buffer = "";
if (selection.toString() !== "") {
buffer = selection.toString();

View File

@ -25,6 +25,8 @@ loader.lazyRequireGetter(
class PropertiesViewContextMenu {
constructor(props = {}) {
this.props = props;
this.copyAll = this.copyAll.bind(this);
this.copyValue = this.copyValue.bind(this);
}
/**
@ -38,10 +40,10 @@ class PropertiesViewContextMenu {
open(event = {}, selection, { member, object }) {
const menuItems = [
{
id: "properties-view-context-menu-copy",
label: L10N.getStr("netmonitor.context.copy"),
accesskey: L10N.getStr("netmonitor.context.copy.accesskey"),
click: () => this.copy(member, selection),
id: "properties-view-context-menu-copyvalue",
label: L10N.getStr("netmonitor.context.copyValue"),
accesskey: L10N.getStr("netmonitor.context.copyValue.accesskey"),
click: () => this.copyValue(member, selection),
},
{
id: "properties-view-context-menu-copyall",
@ -82,11 +84,11 @@ class PropertiesViewContextMenu {
}
/**
* Copies single item.
* Copies the value of a single item.
* @param {Object} member member of the right-clicked row
* @param {Object} selection object representing the current selection
*/
copy(member, selection) {
copyValue(member, selection) {
let buffer = "";
if (selection.toString() !== "") {
buffer = selection.toString();

View File

@ -276,8 +276,8 @@ class RequestListContextMenu {
const menu = [];
menu.push({
label: L10N.getStr("netmonitor.context.copy"),
accesskey: L10N.getStr("netmonitor.context.copy.accesskey"),
label: L10N.getStr("netmonitor.context.copyValue"),
accesskey: L10N.getStr("netmonitor.context.copyValue.accesskey"),
visible: !!clickedRequest,
submenu: copySubMenu,
});

View File

@ -28,13 +28,16 @@ add_task(async function() {
const urlPreview = document.querySelector("#headers-panel .url-preview");
const urlRow = urlPreview.querySelector(".objectRow");
/* Test for copy on the url */
/* Test for copy value on the url */
EventUtils.sendMouseEvent({ type: "contextmenu" }, urlRow);
await waitForClipboardPromise(function setup() {
getContextMenuItem(monitor, "properties-view-context-menu-copy").click();
getContextMenuItem(
monitor,
"properties-view-context-menu-copyvalue"
).click();
}, "http://example.com/browser/devtools/client/netmonitor/test/html_simple-test-page.html");
ok(true, "The copy action put expected url string into clipboard");
ok(true, "The copy value action put expected url string into clipboard");
/* Test for copy all */
EventUtils.sendMouseEvent({ type: "contextmenu" }, urlRow);
@ -91,13 +94,13 @@ add_task(async function() {
".tabpanel-summary-value"
)[1];
/* Test for copy */
/* Test for copy value */
EventUtils.sendMouseEvent({ type: "contextmenu" }, httpSummaryValue);
await waitForClipboardPromise(function setup() {
getContextMenuItem(monitor, "headers-panel-context-menu-copy").click();
}, "Version: HTTP/1.1");
getContextMenuItem(monitor, "headers-panel-context-menu-copyvalue").click();
}, "HTTP/1.1");
ok(true, "The copy action put expected text into clipboard");
ok(true, "The copy value action put expected text into clipboard");
/* Test for copy all */
EventUtils.sendMouseEvent({ type: "contextmenu" }, httpSummaryValue);
@ -157,14 +160,17 @@ add_task(async function() {
await waitOpenNode;
const stringRow = responsePanel.querySelectorAll(".stringRow")[0];
/* Test for copy an object */
/* Test for copy value on an object */
EventUtils.sendMouseEvent({ type: "contextmenu" }, objectRow);
const expected = JSON.stringify({ obj: { type: "string" } }, null, "\t");
await waitForClipboardPromise(function setup() {
getContextMenuItem(monitor, "properties-view-context-menu-copy").click();
getContextMenuItem(
monitor,
"properties-view-context-menu-copyvalue"
).click();
}, expected);
ok(true, "The copy action put expected json into clipboard");
ok(true, "The copy value action put expected json into clipboard");
/* Test for copy all */
EventUtils.sendMouseEvent({ type: "contextmenu" }, objectRow);
@ -174,13 +180,16 @@ add_task(async function() {
ok(true, "The copy all action put expected json into clipboard");
/* Test for copy a single row */
/* Test for copy value of a single row */
EventUtils.sendMouseEvent({ type: "contextmenu" }, stringRow);
await waitForClipboardPromise(function setup() {
getContextMenuItem(monitor, "properties-view-context-menu-copy").click();
}, "type: string");
getContextMenuItem(
monitor,
"properties-view-context-menu-copyvalue"
).click();
}, "string");
ok(true, "The copy action put expected text into clipboard");
ok(true, "The copy value action put expected text into clipboard");
await teardown(monitor);
});
@ -233,16 +242,22 @@ add_task(async function() {
const cur = objectRows[i];
EventUtils.sendMouseEvent({ type: "contextmenu" }, cur);
await waitForClipboardPromise(function setup() {
getContextMenuItem(monitor, "properties-view-context-menu-copy").click();
getContextMenuItem(
monitor,
"properties-view-context-menu-copyvalue"
).click();
}, JSON.stringify(expectedResponseCookies[i], null, "\t"));
}
const expectedRequestCookies = ["bob: true", "foo: bar", "tom: cool"];
const expectedRequestCookies = ["true", "bar", "cool"];
for (let i = 0; i < expectedRequestCookies.length; i++) {
const cur = stringRows[objectRows.length + i];
EventUtils.sendMouseEvent({ type: "contextmenu" }, cur);
await waitForClipboardPromise(function setup() {
getContextMenuItem(monitor, "properties-view-context-menu-copy").click();
getContextMenuItem(
monitor,
"properties-view-context-menu-copyvalue"
).click();
}, expectedRequestCookies[i]);
}