diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /devtools/client/netmonitor/test/browser_net_websocket_stacks.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/netmonitor/test/browser_net_websocket_stacks.js')
-rw-r--r-- | devtools/client/netmonitor/test/browser_net_websocket_stacks.js | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/devtools/client/netmonitor/test/browser_net_websocket_stacks.js b/devtools/client/netmonitor/test/browser_net_websocket_stacks.js new file mode 100644 index 0000000000..cb9acf9d5b --- /dev/null +++ b/devtools/client/netmonitor/test/browser_net_websocket_stacks.js @@ -0,0 +1,94 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test that we get stack traces for the network requests made when creating +// web sockets on the main or worker threads. + +const TOP_FILE_NAME = "html_websocket-test-page.html"; +const TOP_URL = HTTPS_EXAMPLE_URL + TOP_FILE_NAME; +const WORKER_FILE_NAME = "js_websocket-worker-test.js"; + +const EXPECTED_REQUESTS = { + [TOP_URL]: { + method: "GET", + url: TOP_URL, + causeType: "document", + causeUri: null, + stack: false, + }, + "ws://localhost:8080/": { + method: "GET", + url: "ws://localhost:8080/", + causeType: "websocket", + causeUri: TOP_URL, + stack: [ + { fn: "openSocket", file: TOP_URL, line: 6 }, + { file: TOP_FILE_NAME, line: 3 }, + ], + }, + [HTTPS_EXAMPLE_URL + WORKER_FILE_NAME]: { + method: "GET", + url: HTTPS_EXAMPLE_URL + WORKER_FILE_NAME, + causeType: "script", + causeUri: TOP_URL, + stack: [{ file: TOP_URL, line: 9 }], + }, + "wss://localhost:8081/": { + method: "GET", + url: "wss://localhost:8081/", + causeType: "websocket", + causeUri: TOP_URL, + stack: [ + { + fn: "openWorkerSocket", + file: HTTPS_EXAMPLE_URL + WORKER_FILE_NAME, + line: 5, + }, + { file: WORKER_FILE_NAME, line: 2 }, + ], + }, +}; + +add_task(async function () { + // Load a different URL first to instantiate the network monitor before we + // load the page we're really interested in. + const { monitor } = await initNetMonitor(SIMPLE_URL, { requestCount: 1 }); + + const { store, windowRequire, connector } = monitor.panelWin; + const { getSortedRequests } = windowRequire( + "devtools/client/netmonitor/src/selectors/index" + ); + + const onNetworkEvents = waitForNetworkEvents( + monitor, + Object.keys(EXPECTED_REQUESTS).length + ); + await navigateTo(TOP_URL); + await onNetworkEvents; + + is( + store.getState().requests.requests.length, + Object.keys(EXPECTED_REQUESTS).length, + "All the page events should be recorded." + ); + + const requests = getSortedRequests(store.getState()); + // The expected requests in the same order as the + // requests. The platform does not guarantee the order so the + // tests should not depend on that. + const expectedRequests = []; + + // Wait for stack traces from all requests. + await Promise.all( + requests.map(request => { + expectedRequests.push(EXPECTED_REQUESTS[request.url]); + return connector.requestData(request.id, "stackTrace"); + }) + ); + + validateRequests(expectedRequests, monitor); + + await teardown(monitor); +}); |