Attachment #8752692: Part 5: show network request cause in netmonitor UI - mochitest for bug #1134073

View | Details | Raw Unified | Return to bug 1134073
Collapse All | Expand All

(-)a/devtools/client/netmonitor/test/browser.ini (+4 lines)
Line     Link Here 
 Lines 1-14    Link Here 
1
[DEFAULT]
1
[DEFAULT]
2
tags = devtools
2
tags = devtools
3
subsuite = devtools
3
subsuite = devtools
4
support-files =
4
support-files =
5
  dropmarker.svg
5
  dropmarker.svg
6
  head.js
6
  head.js
7
  html_cause-test-page.html
7
  html_content-type-test-page.html
8
  html_content-type-test-page.html
8
  html_content-type-without-cache-test-page.html
9
  html_content-type-without-cache-test-page.html
9
  html_custom-get-page.html
10
  html_custom-get-page.html
10
  html_single-get-page.html
11
  html_single-get-page.html
11
  html_cyrillic-test-page.html
12
  html_cyrillic-test-page.html
12
  html_filter-test-page.html
13
  html_filter-test-page.html
13
  html_infinite-get-page.html
14
  html_infinite-get-page.html
14
  html_json-custom-mime-test-page.html
15
  html_json-custom-mime-test-page.html
 Lines 27-56   support-files = Link Here 
27
  html_statistics-test-page.html
28
  html_statistics-test-page.html
28
  html_status-codes-test-page.html
29
  html_status-codes-test-page.html
29
  html_api-calls-test-page.html
30
  html_api-calls-test-page.html
30
  html_copy-as-curl.html
31
  html_copy-as-curl.html
31
  html_curl-utils.html
32
  html_curl-utils.html
32
  sjs_content-type-test-server.sjs
33
  sjs_content-type-test-server.sjs
33
  sjs_cors-test-server.sjs
34
  sjs_cors-test-server.sjs
34
  sjs_https-redirect-test-server.sjs
35
  sjs_https-redirect-test-server.sjs
36
  sjs_https-sts-test-server.sjs
35
  sjs_simple-test-server.sjs
37
  sjs_simple-test-server.sjs
36
  sjs_sorting-test-server.sjs
38
  sjs_sorting-test-server.sjs
37
  sjs_status-codes-test-server.sjs
39
  sjs_status-codes-test-server.sjs
38
  test-image.png
40
  test-image.png
39
  service-workers/status-codes.html
41
  service-workers/status-codes.html
40
  service-workers/status-codes-service-worker.js
42
  service-workers/status-codes-service-worker.js
41
43
42
[browser_net_aaa_leaktest.js]
44
[browser_net_aaa_leaktest.js]
43
[browser_net_accessibility-01.js]
45
[browser_net_accessibility-01.js]
44
[browser_net_accessibility-02.js]
46
[browser_net_accessibility-02.js]
45
skip-if = (toolkit == "cocoa" && e10s) # bug 1252254
47
skip-if = (toolkit == "cocoa" && e10s) # bug 1252254
46
[browser_net_api-calls.js]
48
[browser_net_api-calls.js]
47
[browser_net_autoscroll.js]
49
[browser_net_autoscroll.js]
48
[browser_net_cached-status.js]
50
[browser_net_cached-status.js]
51
[browser_net_cause.js]
52
[browser_net_cause_redirect.js]
49
[browser_net_service-worker-status.js]
53
[browser_net_service-worker-status.js]
50
[browser_net_charts-01.js]
54
[browser_net_charts-01.js]
51
[browser_net_charts-02.js]
55
[browser_net_charts-02.js]
52
[browser_net_charts-03.js]
56
[browser_net_charts-03.js]
53
[browser_net_charts-04.js]
57
[browser_net_charts-04.js]
54
[browser_net_charts-05.js]
58
[browser_net_charts-05.js]
55
[browser_net_charts-06.js]
59
[browser_net_charts-06.js]
56
[browser_net_charts-07.js]
60
[browser_net_charts-07.js]
(-)a/devtools/client/netmonitor/test/browser_net_cause.js (+56 lines)
Line     Link Here 
Line 0    Link Here 
1
/* Any copyright is dedicated to the Public Domain.
2
   http://creativecommons.org/publicdomain/zero/1.0/ */
3
4
/**
5
 * Tests if request cause is reported correctly.
6
 */
7
8
var test = Task.async(function*() {
9
  const EXPECTED_REQUESTS = [
10
    [ "GET", CAUSE_URL, "document", "", false ],
11
    [ "GET", EXAMPLE_URL + "stylesheet_request", "stylesheet", CAUSE_URL, false ],
12
    [ "GET", EXAMPLE_URL + "img_request", "img", CAUSE_URL, false ],
13
    [ "GET", EXAMPLE_URL + "xhr_request", "xhr", CAUSE_URL, true ],
14
    [ "POST", EXAMPLE_URL + "beacon_request", "beacon", CAUSE_URL, true ],
15
  ];
16
17
  // the initNetMonitor function clears the network request list after the
18
  // page is loaded. That's why we first load a bogus page from SIMPLE_URL,
19
  // and only then load the real thing from CAUSE_URL - we want to catch
20
  // all the requests the page is making, not only the XHRs.
21
  // We can't use about:blank here, because initNetMonitor checks that the
22
  // page has actually made at least one request.
23
  let [tab, debuggee, monitor] = yield initNetMonitor(SIMPLE_URL);
24
  let { RequestsMenu } = monitor.panelWin.NetMonitorView;
25
  RequestsMenu.lazyUpdate = false;
26
27
  debuggee.location = CAUSE_URL;
28
29
  yield waitForNetworkEvents(monitor, EXPECTED_REQUESTS.length);
30
31
  is(RequestsMenu.itemCount, EXPECTED_REQUESTS.length,
32
    "All the page events should be recorded.");
33
34
  EXPECTED_REQUESTS.forEach((spec, i) => {
35
    let [ method, url, causeType, causeUri, hasStack ] = spec;
36
37
    let requestItem = RequestsMenu.getItemAtIndex(i);
38
    verifyRequestItemTarget(requestItem,
39
      method, url, { cause: { type: causeType, loadingDocumentUri: causeUri } }
40
    );
41
42
    let { stacktrace } = requestItem.attachment.cause;
43
    if (hasStack) {
44
      ok(stacktrace, `Request #${i} has a stacktrace`);
45
      let stackLen = (stacktrace || []).length;
46
      ok(stackLen > 0,
47
        `Request #${i} (${causeType}) has a stacktrace with ${stackLen} items`);
48
    } else {
49
      is((stacktrace || []).length, 0,
50
        `Request #${i} (${causeType}) has an empty stacktrace`);
51
    }
52
  });
53
54
  yield teardown(monitor);
55
  finish();
56
});
(-)a/devtools/client/netmonitor/test/browser_net_cause_redirect.js (+49 lines)
Line     Link Here 
Line 0    Link Here 
1
/* Any copyright is dedicated to the Public Domain.
2
   http://creativecommons.org/publicdomain/zero/1.0/ */
3
4
"use strict";
5
6
/**
7
 * Tests if request JS stack is property reported if the request is internally
8
 * redirected without hitting the network (HSTS is one of such cases)
9
 */
10
11
var test = Task.async(function* () {
12
  const EXPECTED_REQUESTS = [
13
    // Request to HTTP URL, redirects to HTTPS, has callstack
14
    { status: 302, hasStack: true },
15
    // Serves HTTPS, sets the Strict-Transport-Security header, no stack
16
    { status: 200, hasStack: false },
17
    // Second request to HTTP redirects to HTTPS internally
18
    { status: 200, hasStack: true },
19
  ];
20
21
  let [, debuggee, monitor] = yield initNetMonitor(CUSTOM_GET_URL);
22
  let { RequestsMenu } = monitor.panelWin.NetMonitorView;
23
  RequestsMenu.lazyUpdate = false;
24
25
  debuggee.performRequests(2, HTTPS_STS_SJS);
26
  yield waitForNetworkEvents(monitor, EXPECTED_REQUESTS.length);
27
28
  EXPECTED_REQUESTS.forEach(({status, hasStack}, i) => {
29
    let { attachment } = RequestsMenu.getItemAtIndex(i);
30
31
    is(attachment.status, status,
32
      `Request #${i} has the expected status`);
33
34
    let { stacktrace } = attachment.cause;
35
36
    if (hasStack) {
37
      ok(stacktrace, `Request #${i} has a stacktrace`);
38
      let stackLen = (stacktrace || []).length;
39
      ok(stackLen > 0,
40
        `Request #${i} has a stacktrace with ${stackLen} items`);
41
    } else {
42
      is((stacktrace || []).length, 0,
43
        `Request #${i} has an empty stacktrace`);
44
    }
45
  });
46
47
  yield teardown(monitor);
48
  finish();
49
});
(-)a/devtools/client/netmonitor/test/head.js (-1 / +11 lines)
Line     Link Here 
 Lines 37-58   const SORTING_URL = EXAMPLE_URL + "html_sorting-test-page.html"; Link Here 
37
const FILTERING_URL = EXAMPLE_URL + "html_filter-test-page.html";
37
const FILTERING_URL = EXAMPLE_URL + "html_filter-test-page.html";
38
const INFINITE_GET_URL = EXAMPLE_URL + "html_infinite-get-page.html";
38
const INFINITE_GET_URL = EXAMPLE_URL + "html_infinite-get-page.html";
39
const CUSTOM_GET_URL = EXAMPLE_URL + "html_custom-get-page.html";
39
const CUSTOM_GET_URL = EXAMPLE_URL + "html_custom-get-page.html";
40
const SINGLE_GET_URL = EXAMPLE_URL + "html_single-get-page.html";
40
const SINGLE_GET_URL = EXAMPLE_URL + "html_single-get-page.html";
41
const STATISTICS_URL = EXAMPLE_URL + "html_statistics-test-page.html";
41
const STATISTICS_URL = EXAMPLE_URL + "html_statistics-test-page.html";
42
const CURL_URL = EXAMPLE_URL + "html_copy-as-curl.html";
42
const CURL_URL = EXAMPLE_URL + "html_copy-as-curl.html";
43
const CURL_UTILS_URL = EXAMPLE_URL + "html_curl-utils.html";
43
const CURL_UTILS_URL = EXAMPLE_URL + "html_curl-utils.html";
44
const SEND_BEACON_URL = EXAMPLE_URL + "html_send-beacon.html";
44
const SEND_BEACON_URL = EXAMPLE_URL + "html_send-beacon.html";
45
const CAUSE_URL = EXAMPLE_URL + "html_cause-test-page.html";
45
46
46
const SIMPLE_SJS = EXAMPLE_URL + "sjs_simple-test-server.sjs";
47
const SIMPLE_SJS = EXAMPLE_URL + "sjs_simple-test-server.sjs";
47
const CONTENT_TYPE_SJS = EXAMPLE_URL + "sjs_content-type-test-server.sjs";
48
const CONTENT_TYPE_SJS = EXAMPLE_URL + "sjs_content-type-test-server.sjs";
48
const STATUS_CODES_SJS = EXAMPLE_URL + "sjs_status-codes-test-server.sjs";
49
const STATUS_CODES_SJS = EXAMPLE_URL + "sjs_status-codes-test-server.sjs";
49
const SORTING_SJS = EXAMPLE_URL + "sjs_sorting-test-server.sjs";
50
const SORTING_SJS = EXAMPLE_URL + "sjs_sorting-test-server.sjs";
50
const HTTPS_REDIRECT_SJS = EXAMPLE_URL + "sjs_https-redirect-test-server.sjs";
51
const HTTPS_REDIRECT_SJS = EXAMPLE_URL + "sjs_https-redirect-test-server.sjs";
52
const HTTPS_STS_SJS = EXAMPLE_URL + "sjs_https-sts-test-server.sjs";
51
const CORS_SJS_PATH = "/browser/devtools/client/netmonitor/test/sjs_cors-test-server.sjs";
53
const CORS_SJS_PATH = "/browser/devtools/client/netmonitor/test/sjs_cors-test-server.sjs";
52
54
53
const TEST_IMAGE = EXAMPLE_URL + "test-image.png";
55
const TEST_IMAGE = EXAMPLE_URL + "test-image.png";
54
const TEST_IMAGE_DATA_URI = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYm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rLmjo+MXA9R2kAHvGBA2wwx6B8W7od6CeQcggKCmCEL8bgwxYCbUIGTDVkHDBia+CuotgACCueD3TDQN75D4xmAvCoK9ARMHBzAw0AECiBHkAlC0Mdy7x9ABNA3obAZXIAa6iKEcGlMVQHwWyjYuL2d4v2cPg8vZswx7gHyAAAK7AOif7SAbOqCmn4Ha3AHFsIDtgPq/vLz8P4MSkJ2W9h8ggBjevXvHDo4FQUQg/kdypqCg4H8lUIACnQ/SOBMYI8bAsAJFPcj1AAEEjwVQqLpAbXmH5BJjqI0gi9DTAAgDBBCcAVLkgmQ7yKCZxpCQxqUZhAECCJ4XgMl493ug21ZD+aDAXH0WLM4A9MZPXJkJIIAwTAR5pQMalaCABQUULttBGCCAGCnNzgABBgAMJ5THwGvJLAAAAABJRU5ErkJggg==";
55
57
56
const FRAME_SCRIPT_UTILS_URL = "chrome://devtools/content/shared/frame-script-utils.js"
58
const FRAME_SCRIPT_UTILS_URL = "chrome://devtools/content/shared/frame-script-utils.js"
57
59
58
DevToolsUtils.testing = true;
60
DevToolsUtils.testing = true;
 Lines 277-293   function verifyRequestItemTarget(aRequestItem, aMethod, aUrl, aData = {}) { Link Here 
277
279
278
  let requestsMenu = aRequestItem.ownerView;
280
  let requestsMenu = aRequestItem.ownerView;
279
  let widgetIndex = requestsMenu.indexOfItem(aRequestItem);
281
  let widgetIndex = requestsMenu.indexOfItem(aRequestItem);
280
  let visibleIndex = requestsMenu.visibleItems.indexOf(aRequestItem);
282
  let visibleIndex = requestsMenu.visibleItems.indexOf(aRequestItem);
281
283
282
  info("Widget index of item: " + widgetIndex);
284
  info("Widget index of item: " + widgetIndex);
283
  info("Visible index of item: " + visibleIndex);
285
  info("Visible index of item: " + visibleIndex);
284
286
285
  let { fuzzyUrl, status, statusText, type, fullMimeType,
287
  let { fuzzyUrl, status, statusText, cause, type, fullMimeType,
286
        transferred, size, time, displayedStatus } = aData;
288
        transferred, size, time, displayedStatus } = aData;
287
  let { attachment, target } = aRequestItem
289
  let { attachment, target } = aRequestItem
288
290
289
  let uri = Services.io.newURI(aUrl, null, null).QueryInterface(Ci.nsIURL);
291
  let uri = Services.io.newURI(aUrl, null, null).QueryInterface(Ci.nsIURL);
290
  let unicodeUrl = NetworkHelper.convertToUnicode(unescape(aUrl));
292
  let unicodeUrl = NetworkHelper.convertToUnicode(unescape(aUrl));
291
  let name = NetworkHelper.convertToUnicode(unescape(uri.fileName || uri.filePath || "/"));
293
  let name = NetworkHelper.convertToUnicode(unescape(uri.fileName || uri.filePath || "/"));
292
  let query = NetworkHelper.convertToUnicode(unescape(uri.query));
294
  let query = NetworkHelper.convertToUnicode(unescape(uri.query));
293
  let hostPort = uri.hostPort;
295
  let hostPort = uri.hostPort;
 Lines 329-344   function verifyRequestItemTarget(aRequestItem, aMethod, aUrl, aData = {}) { Link Here 
329
    let tooltip = target.querySelector(".requests-menu-status").getAttribute("tooltiptext");
331
    let tooltip = target.querySelector(".requests-menu-status").getAttribute("tooltiptext");
330
    info("Displayed status: " + value);
332
    info("Displayed status: " + value);
331
    info("Displayed code: " + codeValue);
333
    info("Displayed code: " + codeValue);
332
    info("Tooltip status: " + tooltip);
334
    info("Tooltip status: " + tooltip);
333
    is(value, displayedStatus ? displayedStatus : status, "The displayed status is correct.");
335
    is(value, displayedStatus ? displayedStatus : status, "The displayed status is correct.");
334
    is(codeValue, status, "The displayed status code is correct.");
336
    is(codeValue, status, "The displayed status code is correct.");
335
    is(tooltip, status + " " + statusText, "The tooltip status is correct.");
337
    is(tooltip, status + " " + statusText, "The tooltip status is correct.");
336
  }
338
  }
339
  if (cause !== undefined) {
340
    let value = target.querySelector(".requests-menu-cause").getAttribute("value");
341
    let tooltip = target.querySelector(".requests-menu-cause").getAttribute("tooltiptext");
342
    info("Displayed cause: " + value);
343
    info("Tooltip cause: " + tooltip);
344
    is(value, cause.type, "The displayed cause is correct.");
345
    is(tooltip, cause.loadingDocumentUri, "The tooltip cause is correct.")
346
  }
337
  if (type !== undefined) {
347
  if (type !== undefined) {
338
    let value = target.querySelector(".requests-menu-type").getAttribute("value");
348
    let value = target.querySelector(".requests-menu-type").getAttribute("value");
339
    let tooltip = target.querySelector(".requests-menu-type").getAttribute("tooltiptext");
349
    let tooltip = target.querySelector(".requests-menu-type").getAttribute("tooltiptext");
340
    info("Displayed type: " + value);
350
    info("Displayed type: " + value);
341
    info("Tooltip type: " + tooltip);
351
    info("Tooltip type: " + tooltip);
342
    is(value, type, "The displayed type is correct.");
352
    is(value, type, "The displayed type is correct.");
343
    is(tooltip, fullMimeType, "The tooltip type is correct.");
353
    is(tooltip, fullMimeType, "The tooltip type is correct.");
344
  }
354
  }
(-)a/devtools/client/netmonitor/test/html_cause-test-page.html (+33 lines)
Line     Link Here 
Line 0    Link Here 
1
<!-- Any copyright is dedicated to the Public Domain.
2
     http://creativecommons.org/publicdomain/zero/1.0/ -->
3
<!doctype html>
4
5
<html>
6
  <head>
7
    <meta charset="utf-8"/>
8
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
9
    <meta http-equiv="Pragma" content="no-cache" />
10
    <meta http-equiv="Expires" content="0" />
11
    <title>Network Monitor test page</title>
12
    <link rel="stylesheet" type="text/css" href="stylesheet_request" />
13
  </head>
14
15
  <body>
16
    <p>Request cause test</p>
17
    <img src="img_request" />
18
    <script type="text/javascript">
19
      function performXhrRequest() {
20
        var xhr = new XMLHttpRequest();
21
        xhr.open("GET", "xhr_request", true);
22
        xhr.send();
23
      }
24
25
      function performBeaconRequest() {
26
        navigator.sendBeacon("beacon_request");
27
      }
28
29
      performXhrRequest();
30
      performBeaconRequest();
31
    </script>
32
  </body>
33
</html>
(-)a/devtools/client/netmonitor/test/sjs_https-sts-test-server.sjs (+17 lines)
Line     Link Here 
Line 0    Link Here 
1
/* Any copyright is dedicated to the Public Domain.
2
   http://creativecommons.org/publicdomain/zero/1.0/ */
3
4
function handleRequest(request, response) {
5
  response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
6
  response.setHeader("Pragma", "no-cache");
7
  response.setHeader("Expires", "0");
8
9
  if (request.scheme === "http") {
10
    response.setStatusLine(request.httpVersion, 302, "Found");
11
    response.setHeader("Location", "https://" + request.host + request.path);
12
  } else {
13
    response.setStatusLine(request.httpVersion, 200, "OK");
14
    response.setHeader("Strict-Transport-Security", "max-age=100");
15
    response.write("Page was accessed over HTTPS!");
16
  }
17
}

Return to bug 1134073