зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1150717 - Implement "Copy URL Parameters" context menu item. r=bgrins
This commit is contained in:
Родитель
857effa8e8
Коммит
8e0f60c8dd
|
@ -566,6 +566,16 @@ RequestsMenuView.prototype = Heritage.extend(WidgetMethods, {
|
|||
clipboardHelper.copyString(selected.url, document);
|
||||
},
|
||||
|
||||
/**
|
||||
* Copy the request url query string parameters from the currently selected item.
|
||||
*/
|
||||
copyUrlParams: function() {
|
||||
let selected = this.selectedItem.attachment;
|
||||
let params = nsIURL(selected.url).query.split("&");
|
||||
let string = params.join(Services.appinfo.OS === "WINNT" ? "\r\n" : "\n");
|
||||
clipboardHelper.copyString(params.join("\n"), document);
|
||||
},
|
||||
|
||||
/**
|
||||
* Copy a cURL command from the currently selected item.
|
||||
*/
|
||||
|
@ -1830,6 +1840,9 @@ RequestsMenuView.prototype = Heritage.extend(WidgetMethods, {
|
|||
let copyUrlElement = $("#request-menu-context-copy-url");
|
||||
copyUrlElement.hidden = !selectedItem;
|
||||
|
||||
let copyUrlParamsElement = $("#request-menu-context-copy-url-params");
|
||||
copyUrlParamsElement.hidden = !selectedItem || !nsIURL(selectedItem.attachment.url).query;
|
||||
|
||||
let copyAsCurlElement = $("#request-menu-context-copy-as-curl");
|
||||
copyAsCurlElement.hidden = !selectedItem || !selectedItem.attachment.responseContent;
|
||||
|
||||
|
|
|
@ -31,6 +31,10 @@
|
|||
<menuitem id="request-menu-context-copy-url"
|
||||
label="&netmonitorUI.context.copyUrl;"
|
||||
accesskey="&netmonitorUI.context.copyUrl.accesskey;"/>
|
||||
<menuitem id="request-menu-context-copy-url-params"
|
||||
label="&netmonitorUI.context.copyUrlParams;"
|
||||
accesskey="&netmonitorUI.context.copyUrlParams.accesskey;"
|
||||
oncommand="NetMonitorView.RequestsMenu.copyUrlParams();"/>
|
||||
<menuitem id="request-menu-context-copy-as-curl"
|
||||
label="&netmonitorUI.context.copyAsCurl;"
|
||||
oncommand="NetMonitorView.RequestsMenu.copyAsCurl();"/>
|
||||
|
|
|
@ -53,6 +53,7 @@ skip-if= buildapp == 'mulet'
|
|||
[browser_net_curl-utils.js]
|
||||
[browser_net_copy_image_as_data_uri.js]
|
||||
[browser_net_copy_url.js]
|
||||
[browser_net_copy_params.js]
|
||||
[browser_net_copy_response.js]
|
||||
[browser_net_copy_headers.js]
|
||||
[browser_net_copy_as_curl.js]
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
/**
|
||||
* Tests whether copying a request item's parameters works.
|
||||
*/
|
||||
|
||||
function test() {
|
||||
initNetMonitor(PARAMS_URL).then(([aTab, aDebuggee, aMonitor]) => {
|
||||
info("Starting test... ");
|
||||
|
||||
let { document, L10N, EVENTS, Editor, NetMonitorView } = aMonitor.panelWin;
|
||||
let { RequestsMenu, NetworkDetails } = NetMonitorView;
|
||||
|
||||
RequestsMenu.lazyUpdate = false;
|
||||
|
||||
Task.spawn(function () {
|
||||
yield waitForNetworkEvents(aMonitor, 1, 6);
|
||||
|
||||
RequestsMenu.selectedItem = RequestsMenu.getItemAtIndex(0);
|
||||
testCopyUrlParamsHidden(false);
|
||||
testCopyUrlParams("a");
|
||||
|
||||
RequestsMenu.selectedItem = RequestsMenu.getItemAtIndex(1);
|
||||
testCopyUrlParamsHidden(false);
|
||||
testCopyUrlParams("a=b");
|
||||
|
||||
RequestsMenu.selectedItem = RequestsMenu.getItemAtIndex(2);
|
||||
testCopyUrlParamsHidden(false);
|
||||
testCopyUrlParams("a=b");
|
||||
|
||||
RequestsMenu.selectedItem = RequestsMenu.getItemAtIndex(3);
|
||||
testCopyUrlParamsHidden(false);
|
||||
testCopyUrlParams("a");
|
||||
|
||||
RequestsMenu.selectedItem = RequestsMenu.getItemAtIndex(4);
|
||||
testCopyUrlParamsHidden(false);
|
||||
testCopyUrlParams("a=b");
|
||||
|
||||
RequestsMenu.selectedItem = RequestsMenu.getItemAtIndex(5);
|
||||
testCopyUrlParamsHidden(false);
|
||||
testCopyUrlParams("a=b");
|
||||
|
||||
RequestsMenu.selectedItem = RequestsMenu.getItemAtIndex(6);
|
||||
testCopyUrlParamsHidden(true);
|
||||
|
||||
yield teardown(aMonitor);
|
||||
finish();
|
||||
});
|
||||
|
||||
function testCopyUrlParamsHidden(aHidden) {
|
||||
RequestsMenu._onContextShowing();
|
||||
is(document.querySelector("#request-menu-context-copy-url-params").hidden, aHidden, "The \"Copy URL Params\" context menu item should" + (aHidden ? " " : " not ") + "be hidden.");
|
||||
}
|
||||
|
||||
function testCopyUrlParams(aQueryString) {
|
||||
RequestsMenu.copyUrlParams();
|
||||
is(SpecialPowers.getClipboardData("text/unicode"), aQueryString, "The url query string copied from the selected item is correct.");
|
||||
}
|
||||
|
||||
aDebuggee.performRequests();
|
||||
});
|
||||
}
|
||||
|
|
@ -264,6 +264,14 @@
|
|||
- for the Copy URL menu item displayed in the context menu for a request -->
|
||||
<!ENTITY netmonitorUI.context.copyUrl.accesskey "C">
|
||||
|
||||
<!-- LOCALIZATION NOTE (netmonitorUI.context.copyUrlParams): This is the label displayed
|
||||
- on the context menu that copies the selected request's url parameters -->
|
||||
<!ENTITY netmonitorUI.context.copyUrlParams "Copy URL Parameters">
|
||||
|
||||
<!-- LOCALIZATION NOTE (netmonitorUI.context.copyUrlParams.accesskey): This is the access key
|
||||
- for the Copy URL Parameters menu item displayed in the context menu for a request -->
|
||||
<!ENTITY netmonitorUI.context.copyUrlParams.accesskey "P">
|
||||
|
||||
<!-- LOCALIZATION NOTE (netmonitorUI.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.
|
||||
|
|
Загрузка…
Ссылка в новой задаче