mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
cdp: fix tests for setchildnodes
This commit is contained in:
@@ -94,6 +94,7 @@ fn performSearch(cmd: anytype) !void {
|
|||||||
fn dispatchSetChildNodes(cmd: anytype, nodes: []*parser.Node) !void {
|
fn dispatchSetChildNodes(cmd: anytype, nodes: []*parser.Node) !void {
|
||||||
const arena = cmd.arena;
|
const arena = cmd.arena;
|
||||||
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
|
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
|
||||||
|
const session_id = bc.session_id orelse return error.SessionIdNotLoaded;
|
||||||
|
|
||||||
var parents: std.ArrayListUnmanaged(*parser.Node) = .{};
|
var parents: std.ArrayListUnmanaged(*parser.Node) = .{};
|
||||||
for (nodes) |_n| {
|
for (nodes) |_n| {
|
||||||
@@ -125,35 +126,41 @@ fn dispatchSetChildNodes(cmd: anytype, nodes: []*parser.Node) !void {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register the node.
|
||||||
|
const node = try bc.node_registry.register(n);
|
||||||
// If the node has no parent, it's the root node.
|
// If the node has no parent, it's the root node.
|
||||||
// We don't dispatch event for it because we assume the root node is
|
// We don't dispatch event for it because we assume the root node is
|
||||||
// dispatched via the DOM.getDocument command.
|
// dispatched via the DOM.getDocument command.
|
||||||
const p = try parser.nodeParentNode(n) orelse break;
|
const p = try parser.nodeParentNode(n) orelse continue;
|
||||||
// Register the node.
|
|
||||||
const node = try bc.node_registry.register(n);
|
|
||||||
// Retrieve the parent from the registry.
|
// Retrieve the parent from the registry.
|
||||||
const parent_node = bc.node_registry.lookup_by_node.get(p) orelse unreachable;
|
const parent_node = try bc.node_registry.register(p);
|
||||||
|
|
||||||
try cmd.sendEvent("DOM.setChildNodes", .{
|
try cmd.sendEvent("DOM.setChildNodes", .{
|
||||||
.parentId = parent_node.id,
|
.parentId = parent_node.id,
|
||||||
.nodes = .{bc.nodeWriter(node, .{})},
|
.nodes = .{bc.nodeWriter(node, .{})},
|
||||||
}, .{
|
}, .{
|
||||||
.session_id = bc.session_id.?,
|
.session_id = session_id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// now dispatch the event for the node list.
|
// now dispatch the event for the node list.
|
||||||
for (nodes) |n| {
|
for (nodes) |n| {
|
||||||
const node = bc.node_registry.lookup_by_node.get(n) orelse unreachable;
|
// Register the node.
|
||||||
|
const node = try bc.node_registry.register(n);
|
||||||
|
// If the node has no parent, it's the root node.
|
||||||
|
// We don't dispatch event for it because we assume the root node is
|
||||||
|
// dispatched via the DOM.getDocument command.
|
||||||
const p = try parser.nodeParentNode(n) orelse continue;
|
const p = try parser.nodeParentNode(n) orelse continue;
|
||||||
|
|
||||||
// Retrieve the parent from the registry.
|
// Retrieve the parent from the registry.
|
||||||
const parent_node = bc.node_registry.lookup_by_node.get(p) orelse unreachable;
|
const parent_node = try bc.node_registry.register(p);
|
||||||
|
|
||||||
try cmd.sendEvent("DOM.setChildNodes", .{
|
try cmd.sendEvent("DOM.setChildNodes", .{
|
||||||
.parentId = parent_node.id,
|
.parentId = parent_node.id,
|
||||||
.nodes = .{bc.nodeWriter(node, .{})},
|
.nodes = .{bc.nodeWriter(node, .{})},
|
||||||
}, .{
|
}, .{
|
||||||
.session_id = bc.session_id.?,
|
.session_id = session_id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ const TestContext = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (opts.html) |html| {
|
if (opts.html) |html| {
|
||||||
|
if (bc.session_id == null) bc.session_id = "SID-X";
|
||||||
parser.deinit();
|
parser.deinit();
|
||||||
try parser.init();
|
try parser.init();
|
||||||
const page = try bc.session.createPage();
|
const page = try bc.session.createPage();
|
||||||
|
|||||||
Reference in New Issue
Block a user