# HG changeset patch # User Jarda Snajdr Bug 1134073 - Part 5: show network request cause in netmonitor UI - mochitest diff --git a/devtools/client/netmonitor/test/browser.ini b/devtools/client/netmonitor/test/browser.ini index f807a93..616d7fa 100644 --- a/devtools/client/netmonitor/test/browser.ini +++ b/devtools/client/netmonitor/test/browser.ini @@ -1,14 +1,15 @@ [DEFAULT] tags = devtools subsuite = devtools support-files = dropmarker.svg head.js + html_cause-test-page.html html_content-type-test-page.html html_content-type-without-cache-test-page.html html_custom-get-page.html html_single-get-page.html html_cyrillic-test-page.html html_filter-test-page.html html_infinite-get-page.html html_json-custom-mime-test-page.html @@ -123,8 +124,9 @@ skip-if = (e10s && debug && os == 'mac') # Bug 1253037 [browser_net_statistics-01.js] [browser_net_statistics-02.js] [browser_net_statistics-03.js] [browser_net_status-codes.js] [browser_net_streaming-response.js] [browser_net_timeline_ticks.js] [browser_net_timing-division.js] [browser_net_persistent_logs.js] +[browser_net_cause.js] diff --git a/devtools/client/netmonitor/test/browser_net_cause.js b/devtools/client/netmonitor/test/browser_net_cause.js new file mode 100644 index 0000000..a84aa82 --- /dev/null +++ b/devtools/client/netmonitor/test/browser_net_cause.js @@ -0,0 +1,42 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Tests if request cause is reported correctly. + */ + +var test = Task.async(function*() { + const EXPECTED_REQUESTS = [ + [ "GET", CAUSE_URL, "document", "" ], + [ "GET", EXAMPLE_URL + "stylesheet_request", "stylesheet", CAUSE_URL ], + [ "GET", EXAMPLE_URL + "img_request", "img", CAUSE_URL ], + [ "GET", EXAMPLE_URL + "xhr_request", "xhr", CAUSE_URL ], + [ "POST", EXAMPLE_URL + "beacon_request", "beacon", CAUSE_URL ] + ]; + + // the initNetMonitor function clears the network request list after the + // page is loaded. That's why we first load a bogus page from SIMPLE_URL, + // and only then load the real thing from CAUSE_URL - we want to catch + // all the requests the page is making, not only the XHRs. + // We can't use about:blank here, because initNetMonitor checks that the + // page has actually made at least one request. + let [tab, debuggee, monitor] = yield initNetMonitor(SIMPLE_URL); + let { RequestsMenu } = monitor.panelWin.NetMonitorView; + RequestsMenu.lazyUpdate = false; + + debuggee.location = CAUSE_URL; + + yield waitForNetworkEvents(monitor, EXPECTED_REQUESTS.length); + + is(RequestsMenu.itemCount, EXPECTED_REQUESTS.length, + "All the page events should be recorded."); + + EXPECTED_REQUESTS.forEach(([ method, url, causeType, causeUri ], i) => { + verifyRequestItemTarget(RequestsMenu.getItemAtIndex(i), + method, url, { cause: { type: causeType, uri: causeUri } } + ); + }); + + yield teardown(monitor); + finish(); +}); diff --git a/devtools/client/netmonitor/test/head.js b/devtools/client/netmonitor/test/head.js index adbdbcc..4e09e47 100644 --- a/devtools/client/netmonitor/test/head.js +++ b/devtools/client/netmonitor/test/head.js @@ -37,16 +37,17 @@ const SORTING_URL = EXAMPLE_URL + "html_sorting-test-page.html"; const FILTERING_URL = EXAMPLE_URL + "html_filter-test-page.html"; const INFINITE_GET_URL = EXAMPLE_URL + "html_infinite-get-page.html"; const CUSTOM_GET_URL = EXAMPLE_URL + "html_custom-get-page.html"; const SINGLE_GET_URL = EXAMPLE_URL + "html_single-get-page.html"; const STATISTICS_URL = EXAMPLE_URL + "html_statistics-test-page.html"; const CURL_URL = EXAMPLE_URL + "html_copy-as-curl.html"; const CURL_UTILS_URL = EXAMPLE_URL + "html_curl-utils.html"; const SEND_BEACON_URL = EXAMPLE_URL + "html_send-beacon.html"; +const CAUSE_URL = EXAMPLE_URL + "html_cause-test-page.html"; const SIMPLE_SJS = EXAMPLE_URL + "sjs_simple-test-server.sjs"; const CONTENT_TYPE_SJS = EXAMPLE_URL + "sjs_content-type-test-server.sjs"; const STATUS_CODES_SJS = EXAMPLE_URL + "sjs_status-codes-test-server.sjs"; const SORTING_SJS = EXAMPLE_URL + "sjs_sorting-test-server.sjs"; const HTTPS_REDIRECT_SJS = EXAMPLE_URL + "sjs_https-redirect-test-server.sjs"; const CORS_SJS_PATH = "/browser/devtools/client/netmonitor/test/sjs_cors-test-server.sjs"; @@ -277,17 +278,17 @@ function verifyRequestItemTarget(aRequestItem, aMethod, aUrl, aData = {}) { let requestsMenu = aRequestItem.ownerView; let widgetIndex = requestsMenu.indexOfItem(aRequestItem); let visibleIndex = requestsMenu.visibleItems.indexOf(aRequestItem); info("Widget index of item: " + widgetIndex); info("Visible index of item: " + visibleIndex); - let { fuzzyUrl, status, statusText, type, fullMimeType, + let { fuzzyUrl, status, statusText, cause, type, fullMimeType, transferred, size, time, displayedStatus } = aData; let { attachment, target } = aRequestItem let uri = Services.io.newURI(aUrl, null, null).QueryInterface(Ci.nsIURL); let unicodeUrl = NetworkHelper.convertToUnicode(unescape(aUrl)); let name = NetworkHelper.convertToUnicode(unescape(uri.fileName || uri.filePath || "/")); let query = NetworkHelper.convertToUnicode(unescape(uri.query)); let hostPort = uri.hostPort; @@ -329,16 +330,24 @@ function verifyRequestItemTarget(aRequestItem, aMethod, aUrl, aData = {}) { let tooltip = target.querySelector(".requests-menu-status").getAttribute("tooltiptext"); info("Displayed status: " + value); info("Displayed code: " + codeValue); info("Tooltip status: " + tooltip); is(value, displayedStatus ? displayedStatus : status, "The displayed status is correct."); is(codeValue, status, "The displayed status code is correct."); is(tooltip, status + " " + statusText, "The tooltip status is correct."); } + if (cause !== undefined) { + let value = target.querySelector(".requests-menu-cause").getAttribute("value"); + let tooltip = target.querySelector(".requests-menu-cause").getAttribute("tooltiptext"); + info("Displayed cause: " + value); + info("Tooltip cause: " + tooltip); + is(value, cause.type, "The displayed cause is correct."); + is(tooltip, cause.uri, "The tooltip cause is correct.") + } if (type !== undefined) { let value = target.querySelector(".requests-menu-type").getAttribute("value"); let tooltip = target.querySelector(".requests-menu-type").getAttribute("tooltiptext"); info("Displayed type: " + value); info("Tooltip type: " + tooltip); is(value, type, "The displayed type is correct."); is(tooltip, fullMimeType, "The tooltip type is correct."); } diff --git a/devtools/client/netmonitor/test/html_cause-test-page.html b/devtools/client/netmonitor/test/html_cause-test-page.html new file mode 100644 index 0000000..40a6f40 --- /dev/null +++ b/devtools/client/netmonitor/test/html_cause-test-page.html @@ -0,0 +1,33 @@ + + + + + + + + + + Network Monitor test page + + + + +

Request cause test

+ + + +