browser_jsterm_inspect.js (2247B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Check that the inspect() jsterm helper function works. 5 6 "use strict"; 7 8 const TEST_URI = 9 "data:text/html;charset=utf8,<!DOCTYPE html><p>test inspect() command"; 10 11 add_task(async function () { 12 const hud = await openNewTabAndConsole(TEST_URI); 13 14 info("Test `inspect(window)`"); 15 // Add a global value so we can check it later. 16 await executeAndWaitForResultMessage( 17 hud, 18 "testProp = 'testValue'", 19 "testValue" 20 ); 21 const { node: inspectWindowNode } = await executeAndWaitForResultMessage( 22 hud, 23 "inspect(window)", 24 "Window" 25 ); 26 27 const objectInspectors = [...inspectWindowNode.querySelectorAll(".tree")]; 28 is( 29 objectInspectors.length, 30 1, 31 "There is the expected number of object inspectors" 32 ); 33 34 const [windowOi] = objectInspectors; 35 let windowOiNodes = windowOi.querySelectorAll(".node"); 36 37 // The tree can be collapsed since the properties are fetched asynchronously. 38 if (windowOiNodes.length === 1) { 39 // If this is the case, we wait for the properties to be fetched and displayed. 40 await waitForNodeMutation(windowOi, { 41 childList: true, 42 }); 43 windowOiNodes = windowOi.querySelectorAll(".node"); 44 } 45 46 const propertiesNodes = [...windowOi.querySelectorAll(".object-label")]; 47 const testPropertyLabelNode = propertiesNodes.find( 48 el => el.textContent === "testProp" 49 ); 50 ok( 51 testPropertyLabelNode, 52 "The testProp property label is displayed as expected" 53 ); 54 55 const testPropertyValueNode = testPropertyLabelNode 56 .closest(".node") 57 .querySelector(".objectBox"); 58 is( 59 testPropertyValueNode.textContent, 60 '"testValue"', 61 "The testProp property value is displayed as expected" 62 ); 63 64 /* Check that a primitive value can be inspected, too */ 65 info("Test `inspect(1)`"); 66 execute(hud, "inspect(1)"); 67 68 const inspectPrimitiveNode = await waitFor(() => 69 findInspectResultMessage(hud.ui.outputNode, 2) 70 ); 71 is( 72 parseInt(inspectPrimitiveNode.textContent, 10), 73 1, 74 "The primitive is displayed as expected" 75 ); 76 }); 77 78 function findInspectResultMessage(node, index) { 79 return node.querySelectorAll(".message.result")[index]; 80 }