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.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /**
     5  * Tests if Copy as cURL works.
     6  */
     8 function test() {
     9   initNetMonitor(CURL_URL).then(([aTab, aDebuggee, aMonitor]) => {
    10     info("Starting test... ");
    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(" ");
    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(" ");
    42     const EXPECTED_RESULT = Services.appinfo.OS == "WINNT" ?
    43                             EXPECTED_WIN_RESULT : EXPECTED_POSIX_RESULT;
    45     let { NetMonitorView } = aMonitor.panelWin;
    46     let { RequestsMenu } = NetMonitorView;
    48     RequestsMenu.lazyUpdate = false;
    50     waitForNetworkEvents(aMonitor, 1).then(() => {
    51       let requestItem = RequestsMenu.getItemAtIndex(0);
    52       RequestsMenu.selectedItem = requestItem;
    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       });
    64     });
    66     aDebuggee.performRequest(SIMPLE_SJS);
    68     function cleanUp(){
    69       teardown(aMonitor).then(finish);
    70     }
    71   });
    72 }

mercurial