Bug 1644695 - [remote] Return the frameId of the frame when DOM.describeNode is called with a frame element. r=remote-protocol-reviewers,maja_zf

Depends on D79450

Differential Revision: https://phabricator.services.mozilla.com/D79451
This commit is contained in:
Henrik Skupin 2020-06-15 15:22:56 +00:00
Родитель 02f1323cb3
Коммит 221b0c6839
2 изменённых файлов: 33 добавлений и 1 удалений

Просмотреть файл

@ -78,6 +78,11 @@ class DOM extends ContentProcessDomain {
}
}
let context = this.docShell.browsingContext;
if (unsafeObj instanceof HTMLIFrameElement) {
context = unsafeObj.contentWindow.docShell.browsingContext;
}
const node = {
nodeId: debuggerObj.nodeId,
backendNodeId: debuggerObj.nodeId,
@ -87,7 +92,7 @@ class DOM extends ContentProcessDomain {
nodeValue: unsafeObj.nodeValue ? unsafeObj.nodeValue.toString() : "",
childNodeCount: unsafeObj.childElementCount,
attributes: attributes.length > 0 ? attributes : undefined,
frameId: this.docShell.browsingContext.id.toString(),
frameId: context.id.toString(),
};
return { node };

Просмотреть файл

@ -4,6 +4,7 @@
"use strict";
const DOC = toDataURL("<div id='content'><p>foo</p><p>bar</p></div>");
const DOC_FRAME = toDataURL(`<iframe src="${DOC}"></iframe>`);
add_task(async function objectIdInvalidTypes({ client }) {
const { DOM } = client;
@ -146,3 +147,29 @@ add_task(async function objectIdDoesNotChangeForTheSameNode({ client }) {
is(node1[prop], node2[prop], `Values of ${prop} are equal`);
}
});
add_task(async function frameIdForFrameElement({ client }) {
const { DOM, Page, Runtime } = client;
await Page.enable();
const frameAttached = Page.frameAttached();
await loadURL(DOC_FRAME);
const { frameId, parentFrameId } = await frameAttached;
await Runtime.enable();
const { result: frameObj } = await Runtime.evaluate({
expression: "document.getElementsByTagName('iframe')[0]",
});
const { node: frame } = await DOM.describeNode({
objectId: frameObj.objectId,
});
is(frame.frameId, frameId, "Reported frameId is from the frame itself");
isnot(
frame.frameId,
parentFrameId,
"Reported frameId is not the parentFrameId"
);
});