diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/client/netmonitor/test/xpcshell | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/netmonitor/test/xpcshell')
6 files changed, 445 insertions, 0 deletions
diff --git a/devtools/client/netmonitor/test/xpcshell/.eslintrc.js b/devtools/client/netmonitor/test/xpcshell/.eslintrc.js new file mode 100644 index 0000000000..8611c174f5 --- /dev/null +++ b/devtools/client/netmonitor/test/xpcshell/.eslintrc.js @@ -0,0 +1,6 @@ +"use strict"; + +module.exports = { + // Extend from the common devtools xpcshell eslintrc config. + extends: "../../../../.eslintrc.xpcshell.js", +}; diff --git a/devtools/client/netmonitor/test/xpcshell/test_doc-utils.js b/devtools/client/netmonitor/test/xpcshell/test_doc-utils.js new file mode 100644 index 0000000000..7cd71662d6 --- /dev/null +++ b/devtools/client/netmonitor/test/xpcshell/test_doc-utils.js @@ -0,0 +1,62 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test for doc-utils + +"use strict"; + +function run_test() { + const { require } = ChromeUtils.importESModule( + "resource://devtools/shared/loader/Loader.sys.mjs" + ); + const MDN_URL = "https://developer.mozilla.org/docs/"; + const GTM_PARAMS_NM = + "?utm_source=mozilla" + + "&utm_medium=devtools-netmonitor&utm_campaign=default"; + const GTM_PARAMS_WC = + "?utm_source=mozilla" + + "&utm_medium=devtools-webconsole&utm_campaign=default"; + const USER_DOC_URL = "https://firefox-source-docs.mozilla.org/devtools-user/"; + + const { + getHeadersURL, + getHTTPStatusCodeURL, + getNetMonitorTimingsURL, + getPerformanceAnalysisURL, + getFilterBoxURL, + } = require("resource://devtools/client/netmonitor/src/utils/doc-utils.js"); + + info("Checking for supported headers"); + equal( + getHeadersURL("Accept"), + `${MDN_URL}Web/HTTP/Headers/Accept${GTM_PARAMS_NM}` + ); + info("Checking for unsupported headers"); + equal(getHeadersURL("Width"), null); + + info("Checking for supported status code"); + equal( + getHTTPStatusCodeURL("200", "webconsole"), + `${MDN_URL}Web/HTTP/Status/200${GTM_PARAMS_WC}` + ); + info("Checking for unsupported status code"); + equal( + getHTTPStatusCodeURL("999", "webconsole"), + `${MDN_URL}Web/HTTP/Status${GTM_PARAMS_WC}` + ); + + equal( + getNetMonitorTimingsURL(), + `${USER_DOC_URL}network_monitor/request_details/#network-monitor-request-details-timings-tab` + ); + + equal( + getPerformanceAnalysisURL(), + `${USER_DOC_URL}network_monitor/performance_analysis/` + ); + + equal( + getFilterBoxURL(), + `${USER_DOC_URL}network_monitor/request_list/#filtering-by-properties` + ); +} diff --git a/devtools/client/netmonitor/test/xpcshell/test_request-utils-fetchNetworkUpdatePacket.js b/devtools/client/netmonitor/test/xpcshell/test_request-utils-fetchNetworkUpdatePacket.js new file mode 100644 index 0000000000..6b7a66f5ad --- /dev/null +++ b/devtools/client/netmonitor/test/xpcshell/test_request-utils-fetchNetworkUpdatePacket.js @@ -0,0 +1,54 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test devtools/client/netmonitor/src/utils/request-utils.js function +// |fetchNetworkUpdatePacket| + +"use strict"; + +const { require } = ChromeUtils.importESModule( + "resource://devtools/shared/loader/Loader.sys.mjs" +); +const { + fetchNetworkUpdatePacket, +} = require("resource://devtools/client/netmonitor/src/utils/request-utils.js"); + +function run_test() { + let fetchedNetworkUpdateTypes = []; + async function mockConnectorRequestData(id, updateType) { + fetchedNetworkUpdateTypes.push(updateType); + return updateType; + } + + const updateTypes = ["requestHeaders", "responseHeaders"]; + const request = { + id: "foo", + requestHeadersAvailable: true, + responseHeadersAvailable: true, + }; + + info( + "Testing that the expected network update packets were fetched from the server" + ); + fetchNetworkUpdatePacket(mockConnectorRequestData, request, updateTypes); + equal(fetchedNetworkUpdateTypes.length, 2, "Two network request updates"); + equal( + fetchedNetworkUpdateTypes[0], + "requestHeaders", + "Request headers updates" + ); + equal( + fetchedNetworkUpdateTypes[1], + "responseHeaders", + " Response headers updates" + ); + + // clear the fetch updates for next test + fetchedNetworkUpdateTypes = []; + + info( + "Testing that no network updates were fetched when no `request` is provided" + ); + fetchNetworkUpdatePacket(mockConnectorRequestData, undefined, updateTypes); + equal(fetchedNetworkUpdateTypes.length, 0, "No network request updates"); +} diff --git a/devtools/client/netmonitor/test/xpcshell/test_request-utils-js-getFormattedProtocol.js b/devtools/client/netmonitor/test/xpcshell/test_request-utils-js-getFormattedProtocol.js new file mode 100644 index 0000000000..07ead52893 --- /dev/null +++ b/devtools/client/netmonitor/test/xpcshell/test_request-utils-js-getFormattedProtocol.js @@ -0,0 +1,235 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test devtools/client/netmonitor/src/utils/request-utils.js function +// |getFormattedProtocol| + +"use strict"; + +const { require } = ChromeUtils.importESModule( + "resource://devtools/shared/loader/Loader.sys.mjs" +); +const { + getFormattedProtocol, +} = require("resource://devtools/client/netmonitor/src/utils/request-utils.js"); + +function run_test() { + const http_1p1_value_http1p1 = { + httpVersion: "HTTP/1.1", + responseHeaders: { + headers: [ + { + name: "X-Firefox-Spdy", + value: "http/1.1", + }, + ], + }, + }; + + const http_1p1_value_http_no_slash_1p1 = { + httpVersion: "HTTP/1.1", + responseHeaders: { + headers: [ + { + name: "X-Firefox-Spdy", + value: "http1.1", + }, + ], + }, + }; + + const http_1p1_value_http1p11 = { + httpVersion: "HTTP/1.1", + responseHeaders: { + headers: [ + { + name: "X-Firefox-Spdy", + value: "http/1.11", + }, + ], + }, + }; + + const http_2p0_value_h2 = { + httpVersion: "HTTP/2.0", + responseHeaders: { + headers: [ + { + name: "X-Firefox-Spdy", + value: "h2", + }, + ], + }, + }; + + const http_1p1_value_h1 = { + httpVersion: "HTTP/1.1", + responseHeaders: { + headers: [ + { + name: "X-Firefox-Spdy", + value: "h1", + }, + ], + }, + }; + + const http_1p1_value_h2 = { + httpVersion: "HTTP/1.1", + responseHeaders: { + headers: [ + { + name: "X-Firefox-Spdy", + value: "h2", + }, + ], + }, + }; + + const http_1p1_value_empty_string = { + httpVersion: "HTTP/1.1", + responseHeaders: { + headers: [ + { + name: "X-Firefox-Spdy", + value: "", + }, + ], + }, + }; + + const http_2p0_value_empty_string = { + httpVersion: "HTTP/2.0", + responseHeaders: { + headers: [ + { + name: "X-Firefox-Spdy", + value: "", + }, + ], + }, + }; + + const http_2p0_value_2p0 = { + httpVersion: "HTTP/2.0", + responseHeaders: { + headers: [ + { + name: "X-Firefox-Spdy", + value: "HTTP/2.0", + }, + ], + }, + }; + + const http_3p0_value_h3 = { + httpVersion: "HTTP/3.0", + responseHeaders: { + headers: [ + { + name: "X-Firefox-Spdy", + value: "h3", + }, + ], + }, + }; + + const http_3p0_value_h3p0 = { + httpVersion: "HTTP/3.0", + responseHeaders: { + headers: [ + { + name: "X-Firefox-Spdy", + value: "h3.0", + }, + ], + }, + }; + + const http_3p0_value_http_3p0 = { + httpVersion: "HTTP/3.0", + responseHeaders: { + headers: [ + { + name: "X-Firefox-Spdy", + value: "http/3.0", + }, + ], + }, + }; + + const http_3p0_value_3p0 = { + httpVersion: "HTTP/3.0", + responseHeaders: { + headers: [ + { + name: "X-Firefox-Spdy", + value: "3.0", + }, + ], + }, + }; + + const http_4p0_value_h4 = { + httpVersion: "HTTP/4.0", + responseHeaders: { + headers: [ + { + name: "X-Firefox-Spdy", + value: "h4", + }, + ], + }, + }; + + info("Testing httpValue:HTTP/1.1, value:http/1.1"); + equal(getFormattedProtocol(http_1p1_value_http1p1), "HTTP/1.1"); + + info("Testing httpValue:HTTP/1.1, value:http1.1"); + equal( + getFormattedProtocol(http_1p1_value_http_no_slash_1p1), + "HTTP/1.1+http1.1" + ); + + info("Testing httpValue:HTTP/1.1, value:http/1.11"); + equal(getFormattedProtocol(http_1p1_value_http1p11), "HTTP/1.1+http/1.11"); + + info("Testing httpValue:HTTP/2.0, value:h2"); + equal(getFormattedProtocol(http_2p0_value_h2), "HTTP/2.0"); + + info("Testing httpValue:HTTP/1.1, value:h1"); + equal(getFormattedProtocol(http_1p1_value_h1), "HTTP/1.1+h1"); + + info("Testing httpValue:HTTP/1.1, value:h2"); + equal(getFormattedProtocol(http_1p1_value_h2), "HTTP/1.1+h2"); + + info("Testing httpValue:HTTP/1.1, value:http1.1"); + equal( + getFormattedProtocol(http_1p1_value_http_no_slash_1p1), + "HTTP/1.1+http1.1" + ); + + info("Testing httpValue:HTTP/1.1, value:''"); + equal(getFormattedProtocol(http_1p1_value_empty_string), "HTTP/1.1"); + + info("Testing httpValue:HTTP/2.0, value:''"); + equal(getFormattedProtocol(http_2p0_value_empty_string), "HTTP/2.0"); + + info("Testing httpValue:HTTP/2.0, value:HTTP/2.0"); + equal(getFormattedProtocol(http_2p0_value_2p0), "HTTP/2.0+HTTP/2.0"); + + info("Testing httpValue:HTTP/3.0, value:h3"); + equal(getFormattedProtocol(http_3p0_value_h3), "HTTP/3.0"); + + info("Testing httpValue:HTTP/3.0, value:h3.0"); + equal(getFormattedProtocol(http_3p0_value_h3p0), "HTTP/3.0"); + + info("Testing httpValue:HTTP/3.0, value:http/3.0"); + equal(getFormattedProtocol(http_3p0_value_http_3p0), "HTTP/3.0+http/3.0"); + + info("Testing httpValue:HTTP/3.0, value:3.0"); + equal(getFormattedProtocol(http_3p0_value_3p0), "HTTP/3.0+3.0"); + + info("Testing httpValue:HTTP/4.0, value:h4"); + equal(getFormattedProtocol(http_4p0_value_h4), "HTTP/4.0"); +} diff --git a/devtools/client/netmonitor/test/xpcshell/test_request-utils-parseJSON.js b/devtools/client/netmonitor/test/xpcshell/test_request-utils-parseJSON.js new file mode 100644 index 0000000000..78fd722522 --- /dev/null +++ b/devtools/client/netmonitor/test/xpcshell/test_request-utils-parseJSON.js @@ -0,0 +1,78 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test devtools/client/netmonitor/src/utils/request-utils.js function +// |parseJSON| ensure that it correctly handles plain JSON, Base 64 +// encoded JSON, and JSON that has XSSI protection prepended to it + +"use strict"; + +const { require } = ChromeUtils.importESModule( + "resource://devtools/shared/loader/Loader.sys.mjs" +); +const { + parseJSON, +} = require("resource://devtools/client/netmonitor/src/utils/request-utils.js"); + +function run_test() { + const validJSON = '{"item":{"subitem":true},"seconditem":"bar"}'; + const base64JSON = btoa(validJSON); + const parsedJSON = { item: { subitem: true }, seconditem: "bar" }; + const googleStyleXSSI = ")]}'\n"; + const facebookStyleXSSI = "for (;;);"; + const notRealXSSIPrevention = "sdgijsdjg"; + const while1XSSIPrevention = "while(1)"; + + const parsedValidJSON = parseJSON(validJSON); + info(JSON.stringify(parsedValidJSON)); + ok( + parsedValidJSON.json.item.subitem == parsedJSON.item.subitem && + parsedValidJSON.json.seconditem == parsedJSON.seconditem, + "plain JSON is parsed correctly" + ); + + const parsedBase64JSON = parseJSON(base64JSON); + ok( + parsedBase64JSON.json.item.subitem === parsedJSON.item.subitem && + parsedBase64JSON.json.seconditem === parsedJSON.seconditem, + "base64 encoded JSON is parsed correctly" + ); + + const parsedGoogleStyleXSSIJSON = parseJSON(googleStyleXSSI + validJSON); + ok( + parsedGoogleStyleXSSIJSON.strippedChars === googleStyleXSSI && + parsedGoogleStyleXSSIJSON.error === void 0 && + parsedGoogleStyleXSSIJSON.json.item.subitem === parsedJSON.item.subitem && + parsedGoogleStyleXSSIJSON.json.seconditem === parsedJSON.seconditem, + "Google style XSSI sequence correctly removed and returned" + ); + + const parsedFacebookStyleXSSIJSON = parseJSON(facebookStyleXSSI + validJSON); + ok( + parsedFacebookStyleXSSIJSON.strippedChars === facebookStyleXSSI && + parsedFacebookStyleXSSIJSON.error === void 0 && + parsedFacebookStyleXSSIJSON.json.item.subitem === + parsedJSON.item.subitem && + parsedFacebookStyleXSSIJSON.json.seconditem === parsedJSON.seconditem, + "Facebook style XSSI sequence correctly removed and returned" + ); + + const parsedWhileXSSIJSON = parseJSON(while1XSSIPrevention + validJSON); + ok( + parsedWhileXSSIJSON.strippedChars === while1XSSIPrevention && + parsedWhileXSSIJSON.error === void 0 && + parsedWhileXSSIJSON.json.item.subitem === parsedJSON.item.subitem && + parsedWhileXSSIJSON.json.seconditem === parsedJSON.seconditem, + "While XSSI sequence correctly removed and returned" + ); + const parsedInvalidJson = parseJSON(notRealXSSIPrevention + validJSON); + ok( + !parsedInvalidJson.json && !parsedInvalidJson.strippedChars, + "Parsed invalid JSON does not return a data object or strippedChars" + ); + equal( + parsedInvalidJson.error.name, + "SyntaxError", + "Parsing invalid JSON yeilds a SyntaxError" + ); +} diff --git a/devtools/client/netmonitor/test/xpcshell/xpcshell.ini b/devtools/client/netmonitor/test/xpcshell/xpcshell.ini new file mode 100644 index 0000000000..a2120e3c9c --- /dev/null +++ b/devtools/client/netmonitor/test/xpcshell/xpcshell.ini @@ -0,0 +1,10 @@ +[DEFAULT] +tags = devtools +head = +firefox-appdir = browser +skip-if = toolkit == 'android' + +[test_doc-utils.js] +[test_request-utils-fetchNetworkUpdatePacket.js] +[test_request-utils-js-getFormattedProtocol.js] +[test_request-utils-parseJSON.js] |