Bug 1628344 - [remote] Return DOM.Node “attributes” for DOM.describeNode. r=remote-protocol-reviewers,jgraham

Differential Revision: https://phabricator.services.mozilla.com/D70426

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Henrik Skupin 2020-04-09 19:11:09 +00:00
parent a769d2a630
commit def4b7f1d6
2 changed files with 35 additions and 4 deletions

View File

@ -69,6 +69,15 @@ class DOM extends ContentProcessDomain {
}
const unsafeObj = debuggerObj.unsafeDereference();
const attributes = [];
if (unsafeObj.attributes) {
// Flatten the list of attributes for name and value
for (const attribute of unsafeObj.attributes) {
attributes.push(attribute.name, attribute.value);
}
}
const node = {
nodeId: debuggerObj.nodeId,
backendNodeId: debuggerObj.nodeId,
@ -77,6 +86,7 @@ class DOM extends ContentProcessDomain {
localName: unsafeObj.localName,
nodeValue: unsafeObj.nodeValue ? unsafeObj.nodeValue.toString() : "",
childNodeCount: unsafeObj.childElementCount,
attributes: attributes.length > 0 ? attributes : undefined,
frameId: this.docShell.browsingContext.id.toString(),
};

View File

@ -3,7 +3,7 @@
"use strict";
const DOC = toDataURL("<div id='content'><span>foo</span></div><div>bar</div>");
const DOC = toDataURL("<div id='content'><p>foo</p><p>bar</p></div>");
add_task(async function objectIdInvalidTypes({ client }) {
const { DOM } = client;
@ -78,13 +78,34 @@ add_task(async function objectIdAllProperties({ client }) {
is(node.localName, "div", "Found expected local name");
is(node.nodeType, 1, "Found expected node type");
is(node.nodeValue, "", "Found expected node value");
is(node.childNodeCount, 1, "Expected number of child nodes found");
is(node.childNodeCount, 2, "Expected number of child nodes found");
is(node.attributes.length, 2, "Found expected attribute's name and value");
is(node.attributes[0], "id", "Found expected attribute name");
is(node.attributes[1], "content", "Found expected attribute value");
is(node.frameId, frameId, "Found expected frame id");
});
add_task(async function objectIdDiffersForDifferentNodes({ client }) {
add_task(async function objectIdNoAttributes({ client }) {
const { DOM, Runtime } = client;
await Runtime.enable();
const { result } = await Runtime.evaluate({
expression: "document",
});
const { node } = await DOM.describeNode({
objectId: result.objectId,
});
is(node.attributes, undefined, "No attributes returned");
});
add_task(async function objectIdDiffersForDifferentNodes({ client }) {
const { DOM, Page, Runtime } = client;
await Page.enable();
await Page.navigate({ url: DOC });
await Page.loadEventFired();
await Runtime.enable();
const { result: doc } = await Runtime.evaluate({
expression: "document",
@ -94,7 +115,7 @@ add_task(async function objectIdDiffersForDifferentNodes({ client }) {
});
const { result: body } = await Runtime.evaluate({
expression: `document.body`,
expression: `document.getElementById('content')`,
});
const { node: node2 } = await DOM.describeNode({
objectId: body.objectId,