browser_webconsole_inspect_cross_domain_object.js (4231B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Check that users can inspect objects logged from cross-domain iframes - 5 // bug 869003. 6 7 "use strict"; 8 9 const TEST_URI = 10 "https://example.com/browser/devtools/client/webconsole/" + 11 "test/browser/test-inspect-cross-domain-objects-top.html"; 12 13 add_task(async function () { 14 requestLongerTimeout(2); 15 16 // Bug 1518138: GC heuristics are broken for this test, so that the test 17 // ends up running out of memory. Try to work-around the problem by GCing 18 // before the test begins. 19 Cu.forceShrinkingGC(); 20 21 // When fission is enabled, we might miss the early message emitted while the target 22 // is being switched, so here we directly open the "real" test URI. See Bug 1614291. 23 const hud = await openNewTabAndConsole(TEST_URI); 24 info("Wait for the 'foobar' message to be logged by the frame"); 25 const node = await waitFor(() => findConsoleAPIMessage(hud, "foobar")); 26 27 const objectInspectors = [...node.querySelectorAll(".tree")]; 28 is( 29 objectInspectors.length, 30 3, 31 "There is the expected number of object inspectors" 32 ); 33 34 const [oi1, oi2, oi3] = objectInspectors; 35 36 info("Expanding the first object inspector"); 37 await expandObjectInspectorNode(oi1.querySelector(".tree-node")); 38 39 // The first object inspector now looks like: 40 // ▼ {…} 41 // | bug: 869003 42 // | hello: "world!" 43 // | ▶︎ <prototype>: Object { … } 44 45 const oi1Nodes = oi1.querySelectorAll(".node"); 46 is(oi1Nodes.length, 4, "There is the expected number of nodes in the tree"); 47 ok(oi1.textContent.includes("bug: 869003"), "Expected content"); 48 ok(oi1.textContent.includes('hello: "world!"'), "Expected content"); 49 50 info("Expanding the second object inspector"); 51 await expandObjectInspectorNode(oi2.querySelector(".tree-node")); 52 53 // The second object inspector now looks like: 54 // ▼ func() 55 // | arguments: null 56 // | bug: 869003 57 // | caller: null 58 // | hello: "world!" 59 // | length: 1 60 // | name: "func" 61 // | ▶︎ prototype: Object { … } 62 // | ▶︎ <prototype>: function () 63 64 const oi2Nodes = oi2.querySelectorAll(".node"); 65 is(oi2Nodes.length, 9, "There is the expected number of nodes in the tree"); 66 ok(oi2.textContent.includes("arguments: null"), "Expected content"); 67 ok(oi2.textContent.includes("bug: 869003"), "Expected content"); 68 ok(oi2.textContent.includes("caller: null"), "Expected content"); 69 ok(oi2.textContent.includes('hello: "world!"'), "Expected content"); 70 ok(oi2.textContent.includes("length: 1"), "Expected content"); 71 ok(oi2.textContent.includes('name: "func"'), "Expected content"); 72 73 info( 74 "Check that the logged element can be highlighted and clicked to jump to inspector" 75 ); 76 const toolbox = hud.toolbox; 77 // Loading the inspector panel at first, to make it possible to listen for 78 // new node selections 79 await toolbox.loadTool("inspector"); 80 const highlighter = toolbox.getHighlighter(); 81 82 const elementNode = oi3.querySelector(".objectBox-node"); 83 Assert.notStrictEqual(elementNode, null, "Node was logged as expected"); 84 const view = node.ownerDocument.defaultView; 85 86 info("Highlight the node by moving the cursor on it"); 87 const onNodeHighlight = highlighter.waitForHighlighterShown(); 88 89 EventUtils.synthesizeMouseAtCenter(elementNode, { type: "mousemove" }, view); 90 91 const { highlighter: activeHighlighter } = await onNodeHighlight; 92 ok(activeHighlighter, "Highlighter is displayed"); 93 // Move the mouse out of the node to prevent failure when test is run multiple times. 94 EventUtils.synthesizeMouseAtCenter(oi1, { type: "mousemove" }, view); 95 96 const openInInspectorIcon = elementNode.querySelector(".open-inspector"); 97 Assert.notStrictEqual( 98 openInInspectorIcon, 99 null, 100 "There is an open in inspector icon" 101 ); 102 103 info( 104 "Clicking on the inspector icon and waiting for the inspector to be selected" 105 ); 106 const onNewNode = toolbox.selection.once("new-node-front"); 107 openInInspectorIcon.click(); 108 const inspectorSelectedNodeFront = await onNewNode; 109 110 ok(true, "Inspector selected and new node got selected"); 111 is(inspectorSelectedNodeFront.id, "testEl", "The expected node was selected"); 112 });