browser/devtools/netmonitor/test/browser_net_post-data-03.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_post-data-03.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,87 @@
     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 the POST requests display the correct information in the UI,
     1.9 + * for raw payloads with content-type headers attached to the upload stream.
    1.10 + */
    1.11 +
    1.12 +function test() {
    1.13 +  initNetMonitor(POST_RAW_WITH_HEADERS_URL).then(([aTab, aDebuggee, aMonitor]) => {
    1.14 +    info("Starting test... ");
    1.15 +
    1.16 +    let { document, L10N, NetMonitorView } = aMonitor.panelWin;
    1.17 +    let { RequestsMenu, NetworkDetails } = NetMonitorView;
    1.18 +    let TAB_UPDATED = aMonitor.panelWin.EVENTS.TAB_UPDATED;
    1.19 +    RequestsMenu.lazyUpdate = false;
    1.20 +
    1.21 +    Task.spawn(function*() {
    1.22 +      yield waitForNetworkEvents(aMonitor, 0, 1);
    1.23 +
    1.24 +      NetMonitorView.toggleDetailsPane({ visible: true });
    1.25 +      RequestsMenu.selectedIndex = 0;
    1.26 +
    1.27 +      yield waitFor(aMonitor.panelWin, TAB_UPDATED);
    1.28 +
    1.29 +      let tab = document.querySelectorAll("#details-pane tab")[0];
    1.30 +      let tabpanel = document.querySelectorAll("#details-pane tabpanel")[0];
    1.31 +      let requestFromUploadScope = tabpanel.querySelectorAll(".variables-view-scope")[2];
    1.32 +
    1.33 +      is(tab.getAttribute("selected"), "true",
    1.34 +        "The headers tab in the network details pane should be selected.");
    1.35 +      is(tabpanel.querySelectorAll(".variables-view-scope").length, 3,
    1.36 +        "There should be 3 header scopes displayed in this tabpanel.");
    1.37 +
    1.38 +      is(requestFromUploadScope.querySelector(".name").getAttribute("value"),
    1.39 +        L10N.getStr("requestHeadersFromUpload") + " (" +
    1.40 +        L10N.getFormatStr("networkMenu.sizeKB", L10N.numberWithDecimals(74/1024, 3)) + ")",
    1.41 +        "The request headers from upload scope doesn't have the correct title.");
    1.42 +
    1.43 +      is(requestFromUploadScope.querySelectorAll(".variables-view-variable").length, 2,
    1.44 +        "There should be 2 header values displayed in the request headers from upload scope.");
    1.45 +
    1.46 +      is(requestFromUploadScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"),
    1.47 +        "content-type", "The first request header name was incorrect.");
    1.48 +      is(requestFromUploadScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"),
    1.49 +        "\"application/x-www-form-urlencoded\"", "The first request header value was incorrect.");
    1.50 +      is(requestFromUploadScope.querySelectorAll(".variables-view-variable .name")[1].getAttribute("value"),
    1.51 +        "custom-header", "The second request header name was incorrect.");
    1.52 +      is(requestFromUploadScope.querySelectorAll(".variables-view-variable .value")[1].getAttribute("value"),
    1.53 +        "\"hello world!\"", "The second request header value was incorrect.");
    1.54 +
    1.55 +      EventUtils.sendMouseEvent({ type: "mousedown" },
    1.56 +        document.querySelectorAll("#details-pane tab")[2]);
    1.57 +
    1.58 +      yield waitFor(aMonitor.panelWin, TAB_UPDATED);
    1.59 +
    1.60 +      let tab = document.querySelectorAll("#details-pane tab")[2];
    1.61 +      let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2];
    1.62 +      let formDataScope = tabpanel.querySelectorAll(".variables-view-scope")[0];
    1.63 +
    1.64 +      is(tab.getAttribute("selected"), "true",
    1.65 +        "The response tab in the network details pane should be selected.");
    1.66 +      is(tabpanel.querySelectorAll(".variables-view-scope").length, 1,
    1.67 +        "There should be 1 header scope displayed in this tabpanel.");
    1.68 +
    1.69 +      is(formDataScope.querySelector(".name").getAttribute("value"),
    1.70 +        L10N.getStr("paramsFormData"),
    1.71 +        "The form data scope doesn't have the correct title.");
    1.72 +
    1.73 +      is(formDataScope.querySelectorAll(".variables-view-variable").length, 2,
    1.74 +        "There should be 2 payload values displayed in the form data scope.");
    1.75 +
    1.76 +      is(formDataScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"),
    1.77 +        "foo", "The first payload param name was incorrect.");
    1.78 +      is(formDataScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"),
    1.79 +        "\"bar\"", "The first payload param value was incorrect.");
    1.80 +      is(formDataScope.querySelectorAll(".variables-view-variable .name")[1].getAttribute("value"),
    1.81 +        "baz", "The second payload param name was incorrect.");
    1.82 +      is(formDataScope.querySelectorAll(".variables-view-variable .value")[1].getAttribute("value"),
    1.83 +        "\"123\"", "The second payload param value was incorrect.");
    1.84 +
    1.85 +      teardown(aMonitor).then(finish);
    1.86 +    });
    1.87 +
    1.88 +    aDebuggee.performRequests();
    1.89 +  });
    1.90 +}

mercurial