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/webconsole/test/browser/browser_jsterm_inspect.js | |
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/webconsole/test/browser/browser_jsterm_inspect.js')
-rw-r--r-- | devtools/client/webconsole/test/browser/browser_jsterm_inspect.js | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/devtools/client/webconsole/test/browser/browser_jsterm_inspect.js b/devtools/client/webconsole/test/browser/browser_jsterm_inspect.js new file mode 100644 index 0000000000..07e5980ac7 --- /dev/null +++ b/devtools/client/webconsole/test/browser/browser_jsterm_inspect.js @@ -0,0 +1,80 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Check that the inspect() jsterm helper function works. + +"use strict"; + +const TEST_URI = + "data:text/html;charset=utf8,<!DOCTYPE html><p>test inspect() command"; + +add_task(async function () { + const hud = await openNewTabAndConsole(TEST_URI); + + info("Test `inspect(window)`"); + // Add a global value so we can check it later. + await executeAndWaitForResultMessage( + hud, + "testProp = 'testValue'", + "testValue" + ); + const { node: inspectWindowNode } = await executeAndWaitForResultMessage( + hud, + "inspect(window)", + "Window" + ); + + const objectInspectors = [...inspectWindowNode.querySelectorAll(".tree")]; + is( + objectInspectors.length, + 1, + "There is the expected number of object inspectors" + ); + + const [windowOi] = objectInspectors; + let windowOiNodes = windowOi.querySelectorAll(".node"); + + // The tree can be collapsed since the properties are fetched asynchronously. + if (windowOiNodes.length === 1) { + // If this is the case, we wait for the properties to be fetched and displayed. + await waitForNodeMutation(windowOi, { + childList: true, + }); + windowOiNodes = windowOi.querySelectorAll(".node"); + } + + const propertiesNodes = [...windowOi.querySelectorAll(".object-label")]; + const testPropertyLabelNode = propertiesNodes.find( + el => el.textContent === "testProp" + ); + ok( + testPropertyLabelNode, + "The testProp property label is displayed as expected" + ); + + const testPropertyValueNode = testPropertyLabelNode + .closest(".node") + .querySelector(".objectBox"); + is( + testPropertyValueNode.textContent, + '"testValue"', + "The testProp property value is displayed as expected" + ); + + /* Check that a primitive value can be inspected, too */ + info("Test `inspect(1)`"); + execute(hud, "inspect(1)"); + + const inspectPrimitiveNode = await waitFor(() => + findInspectResultMessage(hud.ui.outputNode, 2) + ); + is( + parseInt(inspectPrimitiveNode.textContent, 10), + 1, + "The primitive is displayed as expected" + ); +}); + +function findInspectResultMessage(node, index) { + return node.querySelectorAll(".message.result")[index]; +} |