Bug 1461271 - Copy POST data labelled wrongly for PUT/PATCH requests in network tab.r=Honza
MozReview-Commit-ID: 9WCfCh1T2lc
--- a/devtools/client/locales/en-US/netmonitor.properties
+++ b/devtools/client/locales/en-US/netmonitor.properties
@@ -888,23 +888,23 @@ netmonitor.context.copyUrl.accesskey=U
# LOCALIZATION NOTE (netmonitor.context.copyUrlParams): This is the label displayed
# on the context menu that copies the selected request's url parameters
netmonitor.context.copyUrlParams=Copy URL Parameters
# LOCALIZATION NOTE (netmonitor.context.copyUrlParams.accesskey): This is the access key
# for the Copy URL Parameters menu item displayed in the context menu for a request
netmonitor.context.copyUrlParams.accesskey=P
-# LOCALIZATION NOTE (netmonitor.context.copyPostData): This is the label displayed
-# on the context menu that copies the selected request's post data
-netmonitor.context.copyPostData=Copy POST Data
+# LOCALIZATION NOTE (netmonitor.context.copyRequestData): This is the label displayed
+# on the context menu that copies the selected request's data
+netmonitor.context.copyRequestData=Copy %S Data
-# LOCALIZATION NOTE (netmonitor.context.copyPostData.accesskey): This is the access key
-# for the Copy POST Data menu item displayed in the context menu for a request
-netmonitor.context.copyPostData.accesskey=D
+# LOCALIZATION NOTE (netmonitor.context.copyRequestData.accesskey): This is the access key
+# for the Copy POST/PATCH/PUT/DELETE Data menu item displayed in the context menu for a request
+netmonitor.context.copyRequestData.accesskey=D
# LOCALIZATION NOTE (netmonitor.context.copyAsCurl): This is the label displayed
# on the context menu that copies the selected request as a cURL command.
# The capitalization is part of the official name and should be used throughout all languages.
# http://en.wikipedia.org/wiki/CURL
netmonitor.context.copyAsCurl=Copy as cURL
# LOCALIZATION NOTE (netmonitor.context.copyAsCurl.accesskey): This is the access key
--- a/devtools/client/netmonitor/src/widgets/RequestListContextMenu.js
+++ b/devtools/client/netmonitor/src/widgets/RequestListContextMenu.js
@@ -65,18 +65,18 @@ class RequestListContextMenu {
label: L10N.getStr("netmonitor.context.copyUrlParams"),
accesskey: L10N.getStr("netmonitor.context.copyUrlParams.accesskey"),
visible: !!(selectedRequest && getUrlQuery(url)),
click: () => this.copyUrlParams(url),
});
copySubmenu.push({
id: "request-list-context-copy-post-data",
- label: L10N.getStr("netmonitor.context.copyPostData"),
- accesskey: L10N.getStr("netmonitor.context.copyPostData.accesskey"),
+ label: L10N.getFormatStr("netmonitor.context.copyRequestData", method),
+ accesskey: L10N.getStr("netmonitor.context.copyRequestData.accesskey"),
// Menu item will be visible even if data hasn't arrived, so we need to check
// *Available property and then fetch data lazily once user triggers the action.
visible: !!(selectedRequest && (requestPostDataAvailable || requestPostData)),
click: () => this.copyPostData(id, formDataSections, requestPostData),
});
copySubmenu.push({
id: "request-list-context-copy-as-curl",
--- a/devtools/client/netmonitor/test/browser_net_copy_params.js
+++ b/devtools/client/netmonitor/test/browser_net_copy_params.js
@@ -43,20 +43,27 @@ add_task(async function() {
await testCopyUrlParams(4, "a=b");
await testCopyPostDataHidden(4, false);
await testCopyPostData(4, "{ \"foo\": \"bar\" }");
await testCopyUrlParamsHidden(5, false);
await testCopyUrlParams(5, "a=b");
await testCopyPostDataHidden(5, false);
await testCopyPostData(5, "?foo=bar");
+ await testCopyRequestDataLabel(5, "POST");
await testCopyUrlParamsHidden(6, true);
await testCopyPostDataHidden(6, true);
+ await testCopyPostDataHidden(7, false);
+ await testCopyRequestDataLabel(7, "PATCH");
+
+ await testCopyPostDataHidden(8, false);
+ await testCopyRequestDataLabel(8, "PUT");
+
return teardown(monitor);
function testCopyUrlParamsHidden(index, hidden) {
EventUtils.sendMouseEvent({ type: "mousedown" },
document.querySelectorAll(".request-list-item")[index]);
EventUtils.sendMouseEvent({ type: "contextmenu" },
document.querySelectorAll(".request-list-item")[index]);
const copyUrlParamsNode = monitor.panelWin.parent.document
@@ -85,16 +92,27 @@ add_task(async function() {
document.querySelectorAll(".request-list-item")[index]);
const copyPostDataNode = monitor.panelWin.parent.document
.querySelector("#request-list-context-copy-post-data");
is(!!copyPostDataNode, !hidden,
"The \"Copy POST Data\" context menu item should" + (hidden ? " " : " not ") +
"be hidden.");
}
+ function testCopyRequestDataLabel(index, method) {
+ EventUtils.sendMouseEvent({ type: "mousedown" },
+ document.querySelectorAll(".request-list-item")[index]);
+ EventUtils.sendMouseEvent({ type: "contextmenu" },
+ document.querySelectorAll(".request-list-item")[index]);
+ const copyPostDataNode = monitor.panelWin.parent.document
+ .querySelector("#request-list-context-copy-post-data");
+ is(copyPostDataNode.attributes.label.value, "Copy " + method + " Data",
+ "The \"Copy Data\" context menu item should have label - Copy " + method + " Data");
+ }
+
async function testCopyPostData(index, postData) {
// Wait for formDataSections and requestPostData state are ready in redux store
// since copyPostData API needs to read these state.
await waitUntil(() => {
const { requests } = store.getState().requests;
const actIDs = [...requests.keys()];
const { formDataSections, requestPostData } = requests.get(actIDs[index]);
return formDataSections && requestPostData;
--- a/devtools/client/netmonitor/test/html_params-test-page.html
+++ b/devtools/client/netmonitor/test/html_params-test-page.html
@@ -26,36 +26,50 @@
if (this.readyState == this.DONE) {
resolve();
}
};
xhr.send();
});
}
- async function post(address, query, contentType, postBody) {
+ async function request(address, query, contentType, requestBody, method) {
return new Promise(resolve => {
const xhr = new XMLHttpRequest();
- xhr.open("POST", address + query, true);
+ xhr.open(method, address + query, true);
xhr.setRequestHeader("content-type", contentType);
xhr.onreadystatechange = function() {
if (this.readyState == this.DONE) {
resolve();
}
};
- xhr.send(postBody);
+ xhr.send(requestBody);
});
}
+ async function post(address, query, contentType, postBody) {
+ return request(address, query, contentType, postBody, "POST");
+ }
+
+ async function patch(address, query, contentType, patchBody) {
+ return request(address, query, contentType, patchBody, "PATCH");
+ }
+
+ async function put(address, query, contentType, putBody) {
+ return request(address, query, contentType, putBody, "PUT");
+ }
+
async function performRequests() {
const urlencoded = "application/x-www-form-urlencoded";
await post("baz", "?a", urlencoded, '{ "foo": "bar" }');
await post("baz", "?a=b", urlencoded, '{ "foo": "bar" }');
await post("baz", "?a=b", urlencoded, "?foo=bar");
await post("baz", "?a", undefined, '{ "foo": "bar" }');
await post("baz", "?a=b", undefined, '{ "foo": "bar" }');
await post("baz", "?a=b", undefined, "?foo=bar");
await get("baz", "");
+ await patch("baz", "?a=b", urlencoded, '{ "foo": "bar" }');
+ await put("baz", "?a=b", urlencoded, '{ "foo": "bar" }');
}
</script>
</body>
</html>