Created
April 30, 2016 12:57
-
-
Save juliandescottes/bc73fbbe98ab58baa77e3582c99f39c5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Any copyright is dedicated to the Public Domain. | |
http://creativecommons.org/publicdomain/zero/1.0/ */ | |
"use strict"; | |
/** | |
* Tests if Copy as cURL works. | |
*/ | |
const EXPECTED_POSIX_RESULT = [ | |
"curl", | |
"'" + SIMPLE_SJS + "'", | |
"-H 'Host: example.com'", | |
"-H 'User-Agent: " + navigator.userAgent + "'", | |
"-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'", | |
"-H 'Accept-Language: " + navigator.language + "'", | |
"--compressed", | |
"-H 'X-Custom-Header-1: Custom value'", | |
"-H 'X-Custom-Header-2: 8.8.8.8'", | |
"-H 'X-Custom-Header-3: Mon, 3 Mar 2014 11:11:11 GMT'", | |
"-H 'Referer: " + CURL_URL + "'", | |
"-H 'Connection: keep-alive'", | |
"-H 'Pragma: no-cache'", | |
"-H 'Cache-Control: no-cache'" | |
].join(" "); | |
const EXPECTED_WIN_RESULT = [ | |
'curl', | |
'"' + SIMPLE_SJS + '"', | |
'-H "Host: example.com"', | |
'-H "User-Agent: ' + navigator.userAgent + '"', | |
'-H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"', | |
'-H "Accept-Language: ' + navigator.language + '"', | |
"--compressed", | |
'-H "X-Custom-Header-1: Custom value"', | |
'-H "X-Custom-Header-2: 8.8.8.8"', | |
'-H "X-Custom-Header-3: Mon, 3 Mar 2014 11:11:11 GMT"', | |
'-H "Referer: ' + CURL_URL + '"', | |
'-H "Connection: keep-alive"', | |
'-H "Pragma: no-cache"', | |
'-H "Cache-Control: no-cache"' | |
].join(" "); | |
const EXPECTED_RESULT = Services.appinfo.OS == "WINNT" | |
? EXPECTED_WIN_RESULT | |
: EXPECTED_POSIX_RESULT; | |
add_task(function* () { | |
let [, aDebuggee, aMonitor] = yield initNetMonitor(CURL_URL); | |
info("Starting test... "); | |
let { NetMonitorView } = aMonitor.panelWin; | |
let { RequestsMenu } = NetMonitorView; | |
RequestsMenu.lazyUpdate = false; | |
aDebuggee.performRequest(SIMPLE_SJS); | |
yield waitForNetworkEvents(aMonitor, 1); | |
let requestItem = RequestsMenu.getItemAtIndex(0); | |
RequestsMenu.selectedItem = requestItem; | |
yield waitForClipboard(() => RequestsMenu.copyAsCurl(), EXPECTED_RESULT); | |
yield teardown(aMonitor); | |
}); | |
/** | |
* @see SimpleTest.waitForClipboard | |
* | |
* @param {Function} setup | |
* Function to execute before checking for the | |
* clipboard content | |
* @param {String|Function} expected | |
* An expected string or validator function | |
* @return a promise that resolves when the expected string has been found or | |
* the validator function has returned true, rejects otherwise. | |
*/ | |
function waitForClipboard(setup, expected) { | |
let def = promise.defer(); | |
SimpleTest.waitForClipboard(expected, setup, def.resolve, def.reject); | |
return def.promise; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment