browser/devtools/netmonitor/test/browser_net_copy_as_curl.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * Tests if Copy as cURL works.
michael@0 6 */
michael@0 7
michael@0 8 function test() {
michael@0 9 initNetMonitor(CURL_URL).then(([aTab, aDebuggee, aMonitor]) => {
michael@0 10 info("Starting test... ");
michael@0 11
michael@0 12 const EXPECTED_POSIX_RESULT = [
michael@0 13 "curl",
michael@0 14 "'" + SIMPLE_SJS + "'",
michael@0 15 "-H 'Host: example.com'",
michael@0 16 "-H 'User-Agent: " + aDebuggee.navigator.userAgent + "'",
michael@0 17 "-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'",
michael@0 18 "-H 'Accept-Language: " + aDebuggee.navigator.language + "'",
michael@0 19 "-H 'Accept-Encoding: gzip, deflate'",
michael@0 20 "-H 'X-Custom-Header-1: Custom value'",
michael@0 21 "-H 'X-Custom-Header-2: 8.8.8.8'",
michael@0 22 "-H 'X-Custom-Header-3: Mon, 3 Mar 2014 11:11:11 GMT'",
michael@0 23 "-H 'Referer: " + CURL_URL + "'",
michael@0 24 "-H 'Connection: keep-alive'"
michael@0 25 ].join(" ");
michael@0 26
michael@0 27 const EXPECTED_WIN_RESULT = [
michael@0 28 'curl',
michael@0 29 '"' + SIMPLE_SJS + '"',
michael@0 30 '-H "Host: example.com"',
michael@0 31 '-H "User-Agent: ' + aDebuggee.navigator.userAgent + '"',
michael@0 32 '-H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"',
michael@0 33 '-H "Accept-Language: ' + aDebuggee.navigator.language + '"',
michael@0 34 '-H "Accept-Encoding: gzip, deflate"',
michael@0 35 '-H "X-Custom-Header-1: Custom value"',
michael@0 36 '-H "X-Custom-Header-2: 8.8.8.8"',
michael@0 37 '-H "X-Custom-Header-3: Mon, 3 Mar 2014 11:11:11 GMT"',
michael@0 38 '-H "Referer: ' + CURL_URL + '"',
michael@0 39 '-H "Connection: keep-alive"'
michael@0 40 ].join(" ");
michael@0 41
michael@0 42 const EXPECTED_RESULT = Services.appinfo.OS == "WINNT" ?
michael@0 43 EXPECTED_WIN_RESULT : EXPECTED_POSIX_RESULT;
michael@0 44
michael@0 45 let { NetMonitorView } = aMonitor.panelWin;
michael@0 46 let { RequestsMenu } = NetMonitorView;
michael@0 47
michael@0 48 RequestsMenu.lazyUpdate = false;
michael@0 49
michael@0 50 waitForNetworkEvents(aMonitor, 1).then(() => {
michael@0 51 let requestItem = RequestsMenu.getItemAtIndex(0);
michael@0 52 RequestsMenu.selectedItem = requestItem;
michael@0 53
michael@0 54 waitForClipboard(EXPECTED_RESULT, function setup() {
michael@0 55 RequestsMenu.copyAsCurl();
michael@0 56 }, function onSuccess() {
michael@0 57 ok(true, "Clipboard contains a cURL command for the currently selected item's url.");
michael@0 58 cleanUp();
michael@0 59 }, function onFailure() {
michael@0 60 ok(false, "Creating a cURL command for the currently selected item was unsuccessful.");
michael@0 61 cleanUp();
michael@0 62 });
michael@0 63
michael@0 64 });
michael@0 65
michael@0 66 aDebuggee.performRequest(SIMPLE_SJS);
michael@0 67
michael@0 68 function cleanUp(){
michael@0 69 teardown(aMonitor).then(finish);
michael@0 70 }
michael@0 71 });
michael@0 72 }

mercurial