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