diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /devtools/client/netmonitor/har/test | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/client/netmonitor/har/test')
7 files changed, 239 insertions, 0 deletions
diff --git a/devtools/client/netmonitor/har/test/.eslintrc.js b/devtools/client/netmonitor/har/test/.eslintrc.js new file mode 100644 index 000000000..698ae9181 --- /dev/null +++ b/devtools/client/netmonitor/har/test/.eslintrc.js @@ -0,0 +1,6 @@ +"use strict"; + +module.exports = { + // Extend from the shared list of defined globals for mochitests. + "extends": "../../../../.eslintrc.mochitests.js" +}; diff --git a/devtools/client/netmonitor/har/test/browser.ini b/devtools/client/netmonitor/har/test/browser.ini new file mode 100644 index 000000000..14d4f846f --- /dev/null +++ b/devtools/client/netmonitor/har/test/browser.ini @@ -0,0 +1,12 @@ +[DEFAULT] +tags = devtools +subsuite = clipboard +support-files = + head.js + html_har_post-data-test-page.html + !/devtools/client/netmonitor/test/head.js + !/devtools/client/netmonitor/test/html_simple-test-page.html + +[browser_net_har_copy_all_as_har.js] +[browser_net_har_post_data.js] +[browser_net_har_throttle_upload.js] diff --git a/devtools/client/netmonitor/har/test/browser_net_har_copy_all_as_har.js b/devtools/client/netmonitor/har/test/browser_net_har_copy_all_as_har.js new file mode 100644 index 000000000..10df7aba6 --- /dev/null +++ b/devtools/client/netmonitor/har/test/browser_net_har_copy_all_as_har.js @@ -0,0 +1,49 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/** + * Basic tests for exporting Network panel content into HAR format. + */ +add_task(function* () { + let { tab, monitor } = yield initNetMonitor(SIMPLE_URL); + + info("Starting test... "); + + let { NetMonitorView } = monitor.panelWin; + let { RequestsMenu } = NetMonitorView; + + RequestsMenu.lazyUpdate = false; + + let wait = waitForNetworkEvents(monitor, 1); + tab.linkedBrowser.reload(); + yield wait; + + yield RequestsMenu.contextMenu.copyAllAsHar(); + + let jsonString = SpecialPowers.getClipboardData("text/unicode"); + let har = JSON.parse(jsonString); + + // Check out HAR log + isnot(har.log, null, "The HAR log must exist"); + is(har.log.creator.name, "Firefox", "The creator field must be set"); + is(har.log.browser.name, "Firefox", "The browser field must be set"); + is(har.log.pages.length, 1, "There must be one page"); + is(har.log.entries.length, 1, "There must be one request"); + + let entry = har.log.entries[0]; + is(entry.request.method, "GET", "Check the method"); + is(entry.request.url, SIMPLE_URL, "Check the URL"); + is(entry.request.headers.length, 9, "Check number of request headers"); + is(entry.response.status, 200, "Check response status"); + is(entry.response.statusText, "OK", "Check response status text"); + is(entry.response.headers.length, 6, "Check number of response headers"); + is(entry.response.content.mimeType, // eslint-disable-line + "text/html", "Check response content type"); // eslint-disable-line + isnot(entry.response.content.text, undefined, // eslint-disable-line + "Check response body"); + isnot(entry.timings, undefined, "Check timings"); + + return teardown(monitor); +}); diff --git a/devtools/client/netmonitor/har/test/browser_net_har_post_data.js b/devtools/client/netmonitor/har/test/browser_net_har_post_data.js new file mode 100644 index 000000000..b3d611ca7 --- /dev/null +++ b/devtools/client/netmonitor/har/test/browser_net_har_post_data.js @@ -0,0 +1,44 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/** + * Tests for exporting POST data into HAR format. + */ +add_task(function* () { + let { tab, monitor } = yield initNetMonitor( + HAR_EXAMPLE_URL + "html_har_post-data-test-page.html"); + + info("Starting test... "); + + let { NetMonitorView } = monitor.panelWin; + let { RequestsMenu } = NetMonitorView; + + RequestsMenu.lazyUpdate = false; + + // Execute one POST request on the page and wait till its done. + let wait = waitForNetworkEvents(monitor, 0, 1); + yield ContentTask.spawn(tab.linkedBrowser, {}, function* () { + content.wrappedJSObject.executeTest(); + }); + yield wait; + + // Copy HAR into the clipboard (asynchronous). + let jsonString = yield RequestsMenu.contextMenu.copyAllAsHar(); + let har = JSON.parse(jsonString); + + // Check out the HAR log. + isnot(har.log, null, "The HAR log must exist"); + is(har.log.pages.length, 1, "There must be one page"); + is(har.log.entries.length, 1, "There must be one request"); + + let entry = har.log.entries[0]; + is(entry.request.postData.mimeType, "application/json", + "Check post data content type"); + is(entry.request.postData.text, "{'first': 'John', 'last': 'Doe'}", + "Check post data payload"); + + // Clean up + return teardown(monitor); +}); diff --git a/devtools/client/netmonitor/har/test/browser_net_har_throttle_upload.js b/devtools/client/netmonitor/har/test/browser_net_har_throttle_upload.js new file mode 100644 index 000000000..c0e424172 --- /dev/null +++ b/devtools/client/netmonitor/har/test/browser_net_har_throttle_upload.js @@ -0,0 +1,75 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test timing of upload when throttling. + +"use strict"; + +add_task(function* () { + yield throttleUploadTest(true); + yield throttleUploadTest(false); +}); + +function* throttleUploadTest(actuallyThrottle) { + let { tab, monitor } = yield initNetMonitor( + HAR_EXAMPLE_URL + "html_har_post-data-test-page.html"); + + info("Starting test... (actuallyThrottle = " + actuallyThrottle + ")"); + + let { NetMonitorView } = monitor.panelWin; + let { RequestsMenu } = NetMonitorView; + + const size = 4096; + const uploadSize = actuallyThrottle ? size / 3 : 0; + + const request = { + "NetworkMonitor.throttleData": { + roundTripTimeMean: 0, + roundTripTimeMax: 0, + downloadBPSMean: 200000, + downloadBPSMax: 200000, + uploadBPSMean: uploadSize, + uploadBPSMax: uploadSize, + }, + }; + let client = monitor._controller.webConsoleClient; + + info("sending throttle request"); + let deferred = promise.defer(); + client.setPreferences(request, response => { + deferred.resolve(response); + }); + yield deferred.promise; + + RequestsMenu.lazyUpdate = false; + + // Execute one POST request on the page and wait till its done. + let wait = waitForNetworkEvents(monitor, 0, 1); + yield ContentTask.spawn(tab.linkedBrowser, { size }, function* (args) { + content.wrappedJSObject.executeTest2(args.size); + }); + yield wait; + + // Copy HAR into the clipboard (asynchronous). + let jsonString = yield RequestsMenu.contextMenu.copyAllAsHar(); + let har = JSON.parse(jsonString); + + // Check out the HAR log. + isnot(har.log, null, "The HAR log must exist"); + is(har.log.pages.length, 1, "There must be one page"); + is(har.log.entries.length, 1, "There must be one request"); + + let entry = har.log.entries[0]; + is(entry.request.postData.text, "x".repeat(size), + "Check post data payload"); + + const wasTwoSeconds = entry.timings.send >= 2000; + if (actuallyThrottle) { + ok(wasTwoSeconds, "upload should have taken more than 2 seconds"); + } else { + ok(!wasTwoSeconds, "upload should not have taken more than 2 seconds"); + } + + // Clean up + yield teardown(monitor); +} diff --git a/devtools/client/netmonitor/har/test/head.js b/devtools/client/netmonitor/har/test/head.js new file mode 100644 index 000000000..22eb87fe6 --- /dev/null +++ b/devtools/client/netmonitor/har/test/head.js @@ -0,0 +1,14 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/* eslint no-unused-vars: [2, {"vars": "local", "args": "none"}] */ +/* import-globals-from ../../test/head.js */ + +// Load the NetMonitor head.js file to share its API. +var netMonitorHead = "chrome://mochitests/content/browser/devtools/client/netmonitor/test/head.js"; +Services.scriptloader.loadSubScript(netMonitorHead, this); + +// Directory with HAR related test files. +const HAR_EXAMPLE_URL = "http://example.com/browser/devtools/client/netmonitor/har/test/"; diff --git a/devtools/client/netmonitor/har/test/html_har_post-data-test-page.html b/devtools/client/netmonitor/har/test/html_har_post-data-test-page.html new file mode 100644 index 000000000..816dad08e --- /dev/null +++ b/devtools/client/netmonitor/har/test/html_har_post-data-test-page.html @@ -0,0 +1,39 @@ +<!-- Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ --> +<!doctype html> + +<html> + <head> + <meta charset="utf-8"/> + <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" /> + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="0" /> + <title>Network Monitor Test Page</title> + </head> + + <body> + <p>HAR POST data test</p> + + <script type="text/javascript"> + function post(aAddress, aData) { + var xhr = new XMLHttpRequest(); + xhr.open("POST", aAddress, true); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.send(aData); + } + + function executeTest() { + var url = "html_har_post-data-test-page.html"; + var data = "{'first': 'John', 'last': 'Doe'}"; + post(url, data); + } + + function executeTest2(size) { + var url = "html_har_post-data-test-page.html"; + var data = "x".repeat(size); + post(url, data); + } + </script> + </body> + +</html> |