blob: 20208a8be8cb96eac20877c3902834e253a3eeec [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="../../http/tests/inspector/resources/inspector-test.js" id="script-id"></script>
<script id="test-script">
function verifySelector(selector) {
let nodes = document.querySelectorAll(selector);
if (nodes.length !== 1)
console.log("Selector was not unique: " + selector);
}
function verifyXPath(xpath) {
let nodes = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
if (nodes.snapshotLength !== 1)
console.log("XPath was not unique: " + xpath);
}
function test()
{
let nodes = [];
function buildNodeList(node, depth) {
nodes.push({node, depth});
if (!node.children)
return;
for (let child of node.children)
buildNodeList(child, depth + 1);
}
function processList(func, verifier) {
for (let {node, depth} of nodes) {
let prefix = " ".repeat(depth * 2);
let path = func(node);
if (path) {
InspectorTest.log(prefix + path);
verifier(path);
}
}
}
WI.domManager.requestDocument((documentNode) => {
// Push all the nodes to the frontend.
documentNode.querySelector("html", (nodeId) => {
let htmlNode = WI.domManager.nodeForId(nodeId);
htmlNode.getSubtree(10, () => {
buildNodeList(htmlNode, 0);
InspectorTest.log("");
InspectorTest.log("-- CSS Selector Paths --");
processList(WI.cssPath, (selector) => {
InspectorTest.evaluateInPage("verifySelector(" + JSON.stringify(selector) + ")");
});
InspectorTest.log("");
InspectorTest.log("-- XPaths --");
processList(WI.xpath, (xpath) => {
InspectorTest.evaluateInPage("verifyXPath(" + JSON.stringify(xpath) + ")");
});
InspectorBackend.runAfterPendingDispatches(() => {
InspectorTest.completeTest();
})
});
});
});
}
</script>
</head>
<body onload="runTest()">
<p>Test for WI.cssPath.</p>
<article></article>
<article></article>
<div id="ids">
<div></div>
<div></div>
<div id="inner-id"></div>
<div id="__proto__"></div>
<div id='#"ridiculous".id'></div>
<div id="'quoted.value'"></div>
<div id=".foo.bar"></div>
<div id="-"></div>
<div id="-a"></div>
<div id="-0"></div>
<div id="7"></div>
<div id="ид">ид</div>
<p></p>
</div>
<div id="classes">
<div class="foo bar"></div>
<div class=" foo foo "></div>
<div class=".foo"></div>
<div class=".foo.bar"></div>
<div class="-"></div>
<div class="-a"></div>
<div class="-0"></div>
<div class="7"></div>
<div class="класс">класс</div>
<div class="__proto__"></div>
<div class="__proto__ foo"></div>
<span class="bar"></span>
<div id="id-with-class" class="moo"></div>
</div>
<div id="non-unique-classes">
<span class="c1"></span>
<span class="c1"></span>
<span class="c1 c2"></span>
<span class="c1 c2 c3"></span>
<span></span>
<div class="c1"></div>
<div class="c1 c2"></div>
<div class="c3 c2"></div>
<div class="c3 c4"></div>
<div class="c1 c4"></div>
<div></div>
</div>
</body>
</html>