/* Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ */ "use strict"; // Test for Bug 777674 add_task(async function () { await SpecialPowers.pushPermissions([ { type: "allowXULXBL", allow: true, context: MAIN_DOMAIN }, ]); const { walker } = await initInspectorFront( MAIN_DOMAIN + "inspector-traversal-data.html" ); await testXBLAnonymousInHTMLDocument(walker); await testNativeAnonymous(walker); await testNativeAnonymousStartingNode(walker); await testPseudoElements(walker); await testEmptyWithPseudo(walker); await testShadowAnonymous(walker); }); async function testXBLAnonymousInHTMLDocument(walker) { info("Testing XBL anonymous in an HTML document."); await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () { const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; const rawToolbarbutton = content.document.createElementNS( XUL_NS, "toolbarbutton" ); content.document.documentElement.appendChild(rawToolbarbutton); }); const toolbarbutton = await walker.querySelector( walker.rootNode, "toolbarbutton" ); const children = await walker.children(toolbarbutton); is(toolbarbutton.numChildren, 0, "XBL content is not visible in HTML doc"); is(children.nodes.length, 0, "XBL content is not returned in HTML doc"); } async function testNativeAnonymous(walker) { info("Testing native anonymous content with walker."); const select = await walker.querySelector(walker.rootNode, "select"); const children = await walker.children(select); is(select.numChildren, 2, "No native anon content for form control"); is(children.nodes.length, 2, "No native anon content for form control"); } async function testNativeAnonymousStartingNode(walker) { info("Tests attaching an element that a walker can't see."); await SpecialPowers.spawn( gBrowser.selectedBrowser, [[walker.actorID]], async function (actorID) { const { require } = ChromeUtils.importESModule( "resource://devtools/shared/loader/Loader.sys.mjs" ); const { DevToolsServer, } = require("resource://devtools/server/devtools-server.js"); const { DocumentWalker, } = require("resource://devtools/server/actors/inspector/document-walker.js"); const nodeFilterConstants = require("resource://devtools/shared/dom-node-filter-constants.js"); const docwalker = new DocumentWalker( content.document.querySelector("select"), content, { filter: () => { return nodeFilterConstants.FILTER_ACCEPT; }, } ); const scrollbar = docwalker.lastChild(); is(scrollbar.tagName, "scrollbar", "An anonymous child has been fetched"); // Convert actorID to current compartment string otherwise // searchAllConnectionsForActor is confused and won't find the actor. actorID = String(actorID); const serverWalker = DevToolsServer.searchAllConnectionsForActor(actorID); const node = await serverWalker.attachElement(scrollbar); ok(node, "A response has arrived"); ok(node.node, "A node is in the response"); is( node.node.rawNode.tagName, "SELECT", "The node has changed to a parent that the walker recognizes" ); } ); } async function testPseudoElements(walker) { info("Testing pseudo elements with walker."); // Markup looks like: