diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /devtools/client/webconsole/test/browser/browser_webconsole_shows_reqs_in_netmonitor.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/webconsole/test/browser/browser_webconsole_shows_reqs_in_netmonitor.js')
-rw-r--r-- | devtools/client/webconsole/test/browser/browser_webconsole_shows_reqs_in_netmonitor.js | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/devtools/client/webconsole/test/browser/browser_webconsole_shows_reqs_in_netmonitor.js b/devtools/client/webconsole/test/browser/browser_webconsole_shows_reqs_in_netmonitor.js new file mode 100644 index 0000000000..09c61bc007 --- /dev/null +++ b/devtools/client/webconsole/test/browser/browser_webconsole_shows_reqs_in_netmonitor.js @@ -0,0 +1,67 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const TEST_URI = + "data:text/html;charset=utf8,<!DOCTYPE html>Test that the web console " + + "displays requests that have been recorded in the " + + "netmonitor, even if the console hadn't opened yet."; + +const TEST_FILE = "test-network-request.html"; +const TEST_PATH = + "https://example.com/browser/devtools/client/webconsole/test/browser/" + + TEST_FILE; + +const NET_PREF = "devtools.webconsole.filter.net"; +Services.prefs.setBoolPref(NET_PREF, true); +registerCleanupFunction(async () => { + Services.prefs.clearUserPref(NET_PREF); + + await new Promise(resolve => { + Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => + resolve() + ); + }); +}); + +add_task(async function () { + const toolbox = await openNewTabAndToolbox(TEST_URI, "netmonitor"); + info("Network panel is open."); + + await navigateTo(TEST_PATH); + info("Document loaded."); + + // Test that the request appears in the network panel. + await testNetmonitor(toolbox); + + // Test that the request appears in the console. + const { hud } = await toolbox.selectTool("webconsole"); + info("Web console is open"); + + // We can't use `waitForMessages` here because the `new-messages` event + // can be emitted before we get the `hud`. + await waitFor(() => findMessageByType(hud, TEST_PATH, ".network")); + + ok(true, "The network message was found in the console"); +}); + +async function testNetmonitor(toolbox) { + const monitor = toolbox.getCurrentPanel(); + const { store, windowRequire } = monitor.panelWin; + const { getSortedRequests } = windowRequire( + "devtools/client/netmonitor/src/selectors/index" + ); + + await waitFor(() => !!store.getState().requests.requests.length); + + is( + store.getState().requests.requests.length, + 1, + "Network request appears in the network panel" + ); + + const item = getSortedRequests(store.getState())[0]; + is(item.method, "GET", "The request method is correct."); + is(item.url, TEST_PATH, "The request url is correct."); +} |