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_footer-summary.js | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.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_footer-summary.js')
-rw-r--r-- | devtools/client/netmonitor/test/browser_net_footer-summary.js | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/devtools/client/netmonitor/test/browser_net_footer-summary.js b/devtools/client/netmonitor/test/browser_net_footer-summary.js new file mode 100644 index 0000000000..e0b12bcf77 --- /dev/null +++ b/devtools/client/netmonitor/test/browser_net_footer-summary.js @@ -0,0 +1,114 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/** + * Test if the summary text displayed in the network requests menu footer is correct. + */ + +add_task(async function () { + const { + getFormattedSize, + getFormattedTime, + } = require("resource://devtools/client/netmonitor/src/utils/format-utils.js"); + + requestLongerTimeout(2); + + const { tab, monitor } = await initNetMonitor(FILTERING_URL, { + requestCount: 1, + }); + info("Starting test... "); + + const { document, store, windowRequire } = monitor.panelWin; + const Actions = windowRequire("devtools/client/netmonitor/src/actions/index"); + const { getDisplayedRequestsSummary } = windowRequire( + "devtools/client/netmonitor/src/selectors/index" + ); + const { L10N } = windowRequire("devtools/client/netmonitor/src/utils/l10n"); + const { PluralForm } = windowRequire("devtools/shared/plural-form"); + + store.dispatch(Actions.batchEnable(false)); + testStatus(); + + for (let i = 0; i < 2; i++) { + info(`Performing requests in batch #${i}`); + const wait = waitForNetworkEvents(monitor, 8); + await SpecialPowers.spawn(tab.linkedBrowser, [], async function () { + content.wrappedJSObject.performRequests( + '{ "getMedia": true, "getFlash": true }' + ); + }); + await wait; + + testStatus(); + + const buttons = ["html", "css", "js", "xhr", "fonts", "images", "media"]; + for (const button of buttons) { + const buttonEl = document.querySelector( + `.requests-list-filter-${button}-button` + ); + EventUtils.sendMouseEvent({ type: "click" }, buttonEl); + testStatus(); + } + } + + await teardown(monitor); + + function testStatus() { + const state = store.getState(); + const totalRequestsCount = state.requests.requests.length; + const requestsSummary = getDisplayedRequestsSummary(state); + info( + `Current requests: ${requestsSummary.count} of ${totalRequestsCount}.` + ); + + const valueCount = document.querySelector( + ".requests-list-network-summary-count" + ).textContent; + info("Current summary count: " + valueCount); + const expectedCount = PluralForm.get( + requestsSummary.count, + L10N.getStr("networkMenu.summary.requestsCount2") + ).replace("#1", requestsSummary.count); + + if (!totalRequestsCount || !requestsSummary.count) { + is( + valueCount, + L10N.getStr("networkMenu.summary.requestsCountEmpty"), + "The current summary text is incorrect, expected an 'empty' label." + ); + return; + } + + const valueTransfer = document.querySelector( + ".requests-list-network-summary-transfer" + ).textContent; + info("Current summary transfer: " + valueTransfer); + const expectedTransfer = L10N.getFormatStrWithNumbers( + "networkMenu.summary.transferred", + getFormattedSize(requestsSummary.contentSize), + getFormattedSize(requestsSummary.transferredSize) + ); + + const valueFinish = document.querySelector( + ".requests-list-network-summary-finish" + ).textContent; + info("Current summary finish: " + valueFinish); + const expectedFinish = L10N.getFormatStrWithNumbers( + "networkMenu.summary.finish", + getFormattedTime(requestsSummary.ms) + ); + + info(`Computed total bytes: ${requestsSummary.bytes}`); + info(`Computed total ms: ${requestsSummary.ms}`); + + is(valueCount, expectedCount, "The current summary count is correct."); + is( + valueTransfer, + expectedTransfer, + "The current summary transfer is correct." + ); + is(valueFinish, expectedFinish, "The current summary finish is correct."); + } +}); |