browser/devtools/netmonitor/test/browser_net_copy_as_curl.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/netmonitor/test/browser_net_copy_as_curl.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,72 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Tests if Copy as cURL works.
     1.9 + */
    1.10 +
    1.11 +function test() {
    1.12 +  initNetMonitor(CURL_URL).then(([aTab, aDebuggee, aMonitor]) => {
    1.13 +    info("Starting test... ");
    1.14 +
    1.15 +    const EXPECTED_POSIX_RESULT = [
    1.16 +      "curl",
    1.17 +      "'" + SIMPLE_SJS + "'",
    1.18 +      "-H 'Host: example.com'",
    1.19 +      "-H 'User-Agent: " + aDebuggee.navigator.userAgent + "'",
    1.20 +      "-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'",
    1.21 +      "-H 'Accept-Language: " + aDebuggee.navigator.language + "'",
    1.22 +      "-H 'Accept-Encoding: gzip, deflate'",
    1.23 +      "-H 'X-Custom-Header-1: Custom value'",
    1.24 +      "-H 'X-Custom-Header-2: 8.8.8.8'",
    1.25 +      "-H 'X-Custom-Header-3: Mon, 3 Mar 2014 11:11:11 GMT'",
    1.26 +      "-H 'Referer: " + CURL_URL + "'",
    1.27 +      "-H 'Connection: keep-alive'"
    1.28 +    ].join(" ");
    1.29 +
    1.30 +    const EXPECTED_WIN_RESULT = [
    1.31 +      'curl',
    1.32 +      '"' + SIMPLE_SJS + '"',
    1.33 +      '-H "Host: example.com"',
    1.34 +      '-H "User-Agent: ' + aDebuggee.navigator.userAgent + '"',
    1.35 +      '-H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"',
    1.36 +      '-H "Accept-Language: ' + aDebuggee.navigator.language + '"',
    1.37 +      '-H "Accept-Encoding: gzip, deflate"',
    1.38 +      '-H "X-Custom-Header-1: Custom value"',
    1.39 +      '-H "X-Custom-Header-2: 8.8.8.8"',
    1.40 +      '-H "X-Custom-Header-3: Mon, 3 Mar 2014 11:11:11 GMT"',
    1.41 +      '-H "Referer: ' + CURL_URL + '"',
    1.42 +      '-H "Connection: keep-alive"'
    1.43 +    ].join(" ");
    1.44 +
    1.45 +    const EXPECTED_RESULT = Services.appinfo.OS == "WINNT" ?
    1.46 +                            EXPECTED_WIN_RESULT : EXPECTED_POSIX_RESULT;
    1.47 +
    1.48 +    let { NetMonitorView } = aMonitor.panelWin;
    1.49 +    let { RequestsMenu } = NetMonitorView;
    1.50 +
    1.51 +    RequestsMenu.lazyUpdate = false;
    1.52 +
    1.53 +    waitForNetworkEvents(aMonitor, 1).then(() => {
    1.54 +      let requestItem = RequestsMenu.getItemAtIndex(0);
    1.55 +      RequestsMenu.selectedItem = requestItem;
    1.56 +
    1.57 +      waitForClipboard(EXPECTED_RESULT, function setup() {
    1.58 +        RequestsMenu.copyAsCurl();
    1.59 +      }, function onSuccess() {
    1.60 +        ok(true, "Clipboard contains a cURL command for the currently selected item's url.");
    1.61 +        cleanUp();
    1.62 +      }, function onFailure() {
    1.63 +        ok(false, "Creating a cURL command for the currently selected item was unsuccessful.");
    1.64 +        cleanUp();
    1.65 +      });
    1.66 +
    1.67 +    });
    1.68 +
    1.69 +    aDebuggee.performRequest(SIMPLE_SJS);
    1.70 +
    1.71 +    function cleanUp(){
    1.72 +      teardown(aMonitor).then(finish);
    1.73 +    }
    1.74 +  });
    1.75 +}

mercurial