michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests if Copy as cURL works. michael@0: */ michael@0: michael@0: function test() { michael@0: initNetMonitor(CURL_URL).then(([aTab, aDebuggee, aMonitor]) => { michael@0: info("Starting test... "); michael@0: michael@0: const EXPECTED_POSIX_RESULT = [ michael@0: "curl", michael@0: "'" + SIMPLE_SJS + "'", michael@0: "-H 'Host: example.com'", michael@0: "-H 'User-Agent: " + aDebuggee.navigator.userAgent + "'", michael@0: "-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'", michael@0: "-H 'Accept-Language: " + aDebuggee.navigator.language + "'", michael@0: "-H 'Accept-Encoding: gzip, deflate'", michael@0: "-H 'X-Custom-Header-1: Custom value'", michael@0: "-H 'X-Custom-Header-2: 8.8.8.8'", michael@0: "-H 'X-Custom-Header-3: Mon, 3 Mar 2014 11:11:11 GMT'", michael@0: "-H 'Referer: " + CURL_URL + "'", michael@0: "-H 'Connection: keep-alive'" michael@0: ].join(" "); michael@0: michael@0: const EXPECTED_WIN_RESULT = [ michael@0: 'curl', michael@0: '"' + SIMPLE_SJS + '"', michael@0: '-H "Host: example.com"', michael@0: '-H "User-Agent: ' + aDebuggee.navigator.userAgent + '"', michael@0: '-H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"', michael@0: '-H "Accept-Language: ' + aDebuggee.navigator.language + '"', michael@0: '-H "Accept-Encoding: gzip, deflate"', michael@0: '-H "X-Custom-Header-1: Custom value"', michael@0: '-H "X-Custom-Header-2: 8.8.8.8"', michael@0: '-H "X-Custom-Header-3: Mon, 3 Mar 2014 11:11:11 GMT"', michael@0: '-H "Referer: ' + CURL_URL + '"', michael@0: '-H "Connection: keep-alive"' michael@0: ].join(" "); michael@0: michael@0: const EXPECTED_RESULT = Services.appinfo.OS == "WINNT" ? michael@0: EXPECTED_WIN_RESULT : EXPECTED_POSIX_RESULT; michael@0: michael@0: let { NetMonitorView } = aMonitor.panelWin; michael@0: let { RequestsMenu } = NetMonitorView; michael@0: michael@0: RequestsMenu.lazyUpdate = false; michael@0: michael@0: waitForNetworkEvents(aMonitor, 1).then(() => { michael@0: let requestItem = RequestsMenu.getItemAtIndex(0); michael@0: RequestsMenu.selectedItem = requestItem; michael@0: michael@0: waitForClipboard(EXPECTED_RESULT, function setup() { michael@0: RequestsMenu.copyAsCurl(); michael@0: }, function onSuccess() { michael@0: ok(true, "Clipboard contains a cURL command for the currently selected item's url."); michael@0: cleanUp(); michael@0: }, function onFailure() { michael@0: ok(false, "Creating a cURL command for the currently selected item was unsuccessful."); michael@0: cleanUp(); michael@0: }); michael@0: michael@0: }); michael@0: michael@0: aDebuggee.performRequest(SIMPLE_SJS); michael@0: michael@0: function cleanUp(){ michael@0: teardown(aMonitor).then(finish); michael@0: } michael@0: }); michael@0: }