blob: 7732c6c508a065afa1d634fdd0dce52e68f55fbf [file] [log] [blame]
<!doctype html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script>
function test()
{
function evaluate$0(callback) {
WI.runtimeManager.evaluateInInspectedWindow("$0", {objectGroup: "test", includeCommandLineAPI: true}, callback);
}
let nodeA, nodeB;
let suite = InspectorTest.createAsyncSuite("DOM.setInspectedNode");
suite.addTestCase({
name: "Check$0IsUndefined",
description: "No inspected node yet, $0 should be undefined.",
test(resolve, reject) {
evaluate$0((remoteObject) => {
InspectorTest.expectThat(remoteObject.isUndefined(), "$0 should be undefined.");
resolve();
});
}
});
suite.addTestCase({
name: "SetAndCheckNodeA",
description: "Set the inspected node to be Node A and check that $0 is Node A.",
test(resolve, reject) {
DOMAgent.setInspectedNode(nodeA.id);
evaluate$0((remoteObject) => {
remoteObject.pushNodeToFrontend((nodeId) => {
InspectorTest.expectThat(remoteObject.isNode(), "$0 should be a node.");
InspectorTest.expectThat(nodeId === nodeA.id, "$0 should be Node A.");
resolve();
});
});
}
});
suite.addTestCase({
name: "SetBadNodeId",
description: "If an invalid inspected node is set, it should not be bound to $0.",
test(resolve, reject) {
DOMAgent.setInspectedNode(999999, (error) => {
InspectorTest.expectThat(error, "Should be an error");
});
evaluate$0((remoteObject) => {
remoteObject.pushNodeToFrontend((nodeId) => {
InspectorTest.expectThat(remoteObject.isNode(), "$0 should be a node.");
InspectorTest.expectThat(nodeId === nodeA.id, "$0 should be Node A.");
resolve();
});
});
}
});
suite.addTestCase({
name: "SetAndCheckNodeB",
description: "Set the inspected node to be Node B and check that $0 is Node B.",
test(resolve, reject) {
DOMAgent.setInspectedNode(nodeB.id);
evaluate$0((remoteObject) => {
remoteObject.pushNodeToFrontend((nodeId) => {
InspectorTest.expectThat(remoteObject.isNode(), "$0 should be a node.");
InspectorTest.expectThat(nodeId !== nodeA.id, "$0 should not be Node A.");
InspectorTest.expectThat(nodeId === nodeB.id, "$0 should be Node B.");
resolve();
});
});
}
});
// FIXME: What should $0 be after reloading / navigating the page. Should it be cleared?
WI.domTreeManager.requestDocument((documentNode) => {
WI.domTreeManager.querySelector(documentNode.id, "#a", (contentNodeId) => {
InspectorTest.assert(contentNodeId, "#a node should exist.");
nodeA = WI.domTreeManager.nodeForId(contentNodeId);
});
WI.domTreeManager.querySelector(documentNode.id, "#b", (contentNodeId) => {
InspectorTest.assert(contentNodeId, "#b node should exist.");
nodeB = WI.domTreeManager.nodeForId(contentNodeId);
suite.runTestCasesAndFinish();
});
});
}
</script>
</head>
<body onload="runTest()">
<p>Test for the DOM.setInspectedNode command.</p>
<div style="display:none">
<p id="a">Node A</p>
<p id="b">Node B</p>
</div>
</body>
</html>