Bug 1818159 - [webdriver-bidi] When serializing platform objects of type Node only include "children" field if those were collected. r=webdriver-reviewers,jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D171865
This commit is contained in:
Henrik Skupin 2023-03-07 21:06:29 +00:00
Родитель 40bb771e9f
Коммит 6c0d552a19
4 изменённых файлов: 103 добавлений и 48 удалений

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

@ -520,9 +520,8 @@ function serializeNode(
serialized.childNodeCount = node.childNodes.length;
let children = null;
if (maxDepth !== 0) {
children = [];
const children = [];
const childDepth = maxDepth !== null ? maxDepth - 1 : null;
for (const child of node.childNodes) {
children.push(
@ -535,8 +534,9 @@ function serializeNode(
)
);
}
serialized.children = children;
}
serialized.children = children;
if (isElement) {
serialized.attributes = [...node.attributes].reduce((map, attr) => {

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

@ -3,9 +3,17 @@
"use strict";
const { Realm } = ChromeUtils.importESModule(
"chrome://remote/content/webdriver-bidi/Realm.sys.mjs"
);
const { deserialize, serialize, stringify } = ChromeUtils.importESModule(
"chrome://remote/content/webdriver-bidi/RemoteValue.sys.mjs"
);
const browser = Services.appShell.createWindowlessBrowser(false);
const bodyEl = browser.document.body;
const domEl = browser.document.createElement("div");
browser.document.body.appendChild(domEl);
bodyEl.appendChild(domEl);
const PRIMITIVE_TYPES = [
{ value: undefined, serialized: { type: "undefined" } },
@ -342,14 +350,6 @@ const REMOTE_COMPLEX_VALUES = [
},
];
const { Realm } = ChromeUtils.importESModule(
"chrome://remote/content/webdriver-bidi/Realm.sys.mjs"
);
const { deserialize, serialize, stringify } = ChromeUtils.importESModule(
"chrome://remote/content/webdriver-bidi/RemoteValue.sys.mjs"
);
add_task(function test_deserializePrimitiveTypes() {
const realm = new Realm();
@ -810,6 +810,97 @@ add_task(function test_serializeRemoteComplexValues() {
}
});
add_task(function test_serializeNodeChildren() {
const dataSet = [
{
node: bodyEl,
maxDepth: 0,
serialized: {
type: "node",
value: {
attributes: {},
childNodeCount: 1,
localName: "body",
namespaceURI: "http://www.w3.org/1999/xhtml",
nodeType: 1,
},
},
},
{
node: bodyEl,
maxDepth: 1,
serialized: {
type: "node",
value: {
attributes: {},
childNodeCount: 1,
children: [
{
type: "node",
value: {
attributes: {},
childNodeCount: 0,
localName: "div",
namespaceURI: "http://www.w3.org/1999/xhtml",
nodeType: 1,
},
},
],
localName: "body",
namespaceURI: "http://www.w3.org/1999/xhtml",
nodeType: 1,
},
},
},
{
node: domEl,
maxDepth: 0,
serialized: {
type: "node",
value: {
attributes: {},
childNodeCount: 0,
localName: "div",
namespaceURI: "http://www.w3.org/1999/xhtml",
nodeType: 1,
},
},
},
{
node: domEl,
maxDepth: 1,
serialized: {
type: "node",
value: {
attributes: {},
childNodeCount: 0,
children: [],
localName: "div",
namespaceURI: "http://www.w3.org/1999/xhtml",
nodeType: 1,
},
},
},
];
for (const { node, maxDepth, serialized } of dataSet) {
info(`Checking '${node.localName}' with maxDepth ${maxDepth}`);
const realm = new Realm();
const serializationInternalMap = new Map();
const serializedValue = serialize(
node,
maxDepth,
"none",
serializationInternalMap,
realm
);
Assert.deepEqual(serializedValue, serialized, "Got expected structure");
}
});
add_task(function test_serializeWithSerializationInternalMap() {
const dataSet = [
{

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

@ -1,18 +0,0 @@
[result_node.py]
[test_element_node[all_children\]]
expected: FAIL
[test_element_node[children_max_depth\]]
expected: FAIL
[test_document_node[basic\]]
expected: FAIL
[test_node_within_object]
expected: FAIL
[test_node_within_dom_collection[htmlcollection\]]
expected: FAIL
[test_node_within_dom_collection[nodelist\]]
expected: FAIL

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

@ -1,18 +0,0 @@
[result_node.py]
[test_element_node[all_children\]]
expected: FAIL
[test_element_node[children_max_depth\]]
expected: FAIL
[test_document_node[basic\]]
expected: FAIL
[test_node_within_object]
expected: FAIL
[test_node_within_dom_collection[htmlcollection\]]
expected: FAIL
[test_node_within_dom_collection[nodelist\]]
expected: FAIL