Files
firefox/devtools/server/tests/mochitest/test_webconsole-node-grip.html
T
nchevobbe f7d5e045ac Bug 1347490 - Return isConnected in node grip to indicate if a node is in the DOM tree. r=ochameau
node.isConnected (see https://dom.spec.whatwg.org/#dom-node-isconnected) returns true if the node is
in the DOM tree (including in a shadowDOM tree), which can be used in the frontend to display additional
tools and information.

MozReview-Commit-ID: LjUbkc7VPcB
2017-04-04 12:08:54 +02:00

68 lines
2.3 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>DOMNode Object actor test</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript" src="webconsole-helpers.js"></script>
<script>
"use strict";
const TEST_URL = "data:text/html,<html><body>Hello</body></html>";
window.onload = async function () {
SimpleTest.waitForExplicitFinish();
try {
let {
consoleClient,
} = await attachURL(TEST_URL);
await testNotInTreeElementNode(consoleClient);
await testInTreeElementNode(consoleClient);
await testNotInTreeTextNode(consoleClient);
await testInTreeTextNode(consoleClient);
} catch (e) {
ok(false, `Error thrown: ${e.message}`);
}
SimpleTest.finish();
};
async function testNotInTreeElementNode(consoleClient) {
info("Testing isConnected property on a ElementNode not in the DOM tree");
let {result} = await consoleClient.evaluateJS("document.createElement(\"div\")");
is(result.preview.isConnected, false,
"isConnected is false since we only created the element");
}
async function testInTreeElementNode(consoleClient) {
info("Testing isConnected property on a ElementNode in the DOM tree");
let {result} = await consoleClient.evaluateJS("document.body");
is(result.preview.isConnected, true,
"isConnected is true as expected, since the element was retrieved from the DOM tree");
}
async function testNotInTreeTextNode(consoleClient) {
info("Testing isConnected property on a TextNode not in the DOM tree");
let {result} = await consoleClient.evaluateJS("document.createTextNode(\"Hello\")");
is(result.preview.isConnected, false,
"isConnected is false since we only created the element");
}
async function testInTreeTextNode(consoleClient) {
info("Testing isConnected property on a TextNode in the DOM tree");
let {result} = await consoleClient.evaluateJS("document.body.firstChild");
is(result.preview.isConnected, true,
"isConnected is true as expected, since the element was retrieved from the DOM tree");
}
</script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>