mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-28 22:53:28 +00:00
Merge pull request #1074 from lightpanda-io/cdp-nodeid
Some checks failed
e2e-test / zig build release (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
nightly build / build-linux-x86_64 (push) Has been cancelled
nightly build / build-linux-aarch64 (push) Has been cancelled
nightly build / build-macos-aarch64 (push) Has been cancelled
nightly build / build-macos-x86_64 (push) Has been cancelled
wpt / web platform tests json output (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
Some checks failed
e2e-test / zig build release (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
nightly build / build-linux-x86_64 (push) Has been cancelled
nightly build / build-linux-aarch64 (push) Has been cancelled
nightly build / build-macos-aarch64 (push) Has been cancelled
nightly build / build-macos-x86_64 (push) Has been cancelled
wpt / web platform tests json output (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
cdp: start nodeId from 1 instead of 0
This commit is contained in:
@@ -42,7 +42,7 @@ pub const Registry = struct {
|
|||||||
|
|
||||||
pub fn init(allocator: Allocator) Registry {
|
pub fn init(allocator: Allocator) Registry {
|
||||||
return .{
|
return .{
|
||||||
.node_id = 0,
|
.node_id = 1,
|
||||||
.lookup_by_id = .{},
|
.lookup_by_id = .{},
|
||||||
.lookup_by_node = .{},
|
.lookup_by_node = .{},
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
@@ -346,18 +346,6 @@ test "cdp Node: Registry register" {
|
|||||||
{
|
{
|
||||||
const n = (try doc.querySelector("#a1")).?;
|
const n = (try doc.querySelector("#a1")).?;
|
||||||
const node = try registry.register(n);
|
const node = try registry.register(n);
|
||||||
const n1b = registry.lookup_by_id.get(0).?;
|
|
||||||
const n1c = registry.lookup_by_node.get(node._node).?;
|
|
||||||
try testing.expectEqual(node, n1b);
|
|
||||||
try testing.expectEqual(node, n1c);
|
|
||||||
|
|
||||||
try testing.expectEqual(0, node.id);
|
|
||||||
try testing.expectEqual(n, node._node);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const n = (try doc.querySelector("p")).?;
|
|
||||||
const node = try registry.register(n);
|
|
||||||
const n1b = registry.lookup_by_id.get(1).?;
|
const n1b = registry.lookup_by_id.get(1).?;
|
||||||
const n1c = registry.lookup_by_node.get(node._node).?;
|
const n1c = registry.lookup_by_node.get(node._node).?;
|
||||||
try testing.expectEqual(node, n1b);
|
try testing.expectEqual(node, n1b);
|
||||||
@@ -366,6 +354,18 @@ test "cdp Node: Registry register" {
|
|||||||
try testing.expectEqual(1, node.id);
|
try testing.expectEqual(1, node.id);
|
||||||
try testing.expectEqual(n, node._node);
|
try testing.expectEqual(n, node._node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const n = (try doc.querySelector("p")).?;
|
||||||
|
const node = try registry.register(n);
|
||||||
|
const n1b = registry.lookup_by_id.get(2).?;
|
||||||
|
const n1c = registry.lookup_by_node.get(node._node).?;
|
||||||
|
try testing.expectEqual(node, n1b);
|
||||||
|
try testing.expectEqual(node, n1c);
|
||||||
|
|
||||||
|
try testing.expectEqual(2, node.id);
|
||||||
|
try testing.expectEqual(n, node._node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test "cdp Node: search list" {
|
test "cdp Node: search list" {
|
||||||
@@ -404,18 +404,18 @@ test "cdp Node: search list" {
|
|||||||
|
|
||||||
const s1 = try search_list.create(try doc.querySelectorAll("a"));
|
const s1 = try search_list.create(try doc.querySelectorAll("a"));
|
||||||
try testing.expectEqual("1", s1.name);
|
try testing.expectEqual("1", s1.name);
|
||||||
try testing.expectEqualSlices(u32, &.{ 0, 1 }, s1.node_ids);
|
try testing.expectEqualSlices(u32, &.{ 1, 2 }, s1.node_ids);
|
||||||
|
|
||||||
try testing.expectEqual(2, registry.lookup_by_id.count());
|
try testing.expectEqual(2, registry.lookup_by_id.count());
|
||||||
try testing.expectEqual(2, registry.lookup_by_node.count());
|
try testing.expectEqual(2, registry.lookup_by_node.count());
|
||||||
|
|
||||||
const s2 = try search_list.create(try doc.querySelectorAll("#a1"));
|
const s2 = try search_list.create(try doc.querySelectorAll("#a1"));
|
||||||
try testing.expectEqual("2", s2.name);
|
try testing.expectEqual("2", s2.name);
|
||||||
try testing.expectEqualSlices(u32, &.{0}, s2.node_ids);
|
try testing.expectEqualSlices(u32, &.{1}, s2.node_ids);
|
||||||
|
|
||||||
const s3 = try search_list.create(try doc.querySelectorAll("#a2"));
|
const s3 = try search_list.create(try doc.querySelectorAll("#a2"));
|
||||||
try testing.expectEqual("3", s3.name);
|
try testing.expectEqual("3", s3.name);
|
||||||
try testing.expectEqualSlices(u32, &.{1}, s3.node_ids);
|
try testing.expectEqualSlices(u32, &.{2}, s3.node_ids);
|
||||||
|
|
||||||
try testing.expectEqual(2, registry.lookup_by_id.count());
|
try testing.expectEqual(2, registry.lookup_by_id.count());
|
||||||
try testing.expectEqual(2, registry.lookup_by_node.count());
|
try testing.expectEqual(2, registry.lookup_by_node.count());
|
||||||
@@ -443,8 +443,8 @@ test "cdp Node: Writer" {
|
|||||||
defer testing.allocator.free(json);
|
defer testing.allocator.free(json);
|
||||||
|
|
||||||
try testing.expectJson(.{
|
try testing.expectJson(.{
|
||||||
.nodeId = 0,
|
.nodeId = 1,
|
||||||
.backendNodeId = 0,
|
.backendNodeId = 1,
|
||||||
.nodeType = 9,
|
.nodeType = 9,
|
||||||
.nodeName = "#document",
|
.nodeName = "#document",
|
||||||
.localName = "",
|
.localName = "",
|
||||||
@@ -456,8 +456,8 @@ test "cdp Node: Writer" {
|
|||||||
.compatibilityMode = "NoQuirksMode",
|
.compatibilityMode = "NoQuirksMode",
|
||||||
.childNodeCount = 1,
|
.childNodeCount = 1,
|
||||||
.children = &.{.{
|
.children = &.{.{
|
||||||
.nodeId = 1,
|
.nodeId = 2,
|
||||||
.backendNodeId = 1,
|
.backendNodeId = 2,
|
||||||
.nodeType = 1,
|
.nodeType = 1,
|
||||||
.nodeName = "HTML",
|
.nodeName = "HTML",
|
||||||
.localName = "html",
|
.localName = "html",
|
||||||
@@ -473,7 +473,7 @@ test "cdp Node: Writer" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const node = registry.lookup_by_id.get(1).?;
|
const node = registry.lookup_by_id.get(2).?;
|
||||||
const json = try std.json.Stringify.valueAlloc(testing.allocator, Writer{
|
const json = try std.json.Stringify.valueAlloc(testing.allocator, Writer{
|
||||||
.root = node,
|
.root = node,
|
||||||
.depth = 1,
|
.depth = 1,
|
||||||
@@ -483,8 +483,8 @@ test "cdp Node: Writer" {
|
|||||||
defer testing.allocator.free(json);
|
defer testing.allocator.free(json);
|
||||||
|
|
||||||
try testing.expectJson(.{
|
try testing.expectJson(.{
|
||||||
.nodeId = 1,
|
.nodeId = 2,
|
||||||
.backendNodeId = 1,
|
.backendNodeId = 2,
|
||||||
.nodeType = 1,
|
.nodeType = 1,
|
||||||
.nodeName = "HTML",
|
.nodeName = "HTML",
|
||||||
.localName = "html",
|
.localName = "html",
|
||||||
@@ -496,8 +496,8 @@ test "cdp Node: Writer" {
|
|||||||
.compatibilityMode = "NoQuirksMode",
|
.compatibilityMode = "NoQuirksMode",
|
||||||
.isScrollable = false,
|
.isScrollable = false,
|
||||||
.children = &.{ .{
|
.children = &.{ .{
|
||||||
.nodeId = 2,
|
.nodeId = 3,
|
||||||
.backendNodeId = 2,
|
.backendNodeId = 3,
|
||||||
.nodeType = 1,
|
.nodeType = 1,
|
||||||
.nodeName = "HEAD",
|
.nodeName = "HEAD",
|
||||||
.localName = "head",
|
.localName = "head",
|
||||||
@@ -508,10 +508,10 @@ test "cdp Node: Writer" {
|
|||||||
.xmlVersion = "",
|
.xmlVersion = "",
|
||||||
.compatibilityMode = "NoQuirksMode",
|
.compatibilityMode = "NoQuirksMode",
|
||||||
.isScrollable = false,
|
.isScrollable = false,
|
||||||
.parentId = 1,
|
.parentId = 2,
|
||||||
}, .{
|
}, .{
|
||||||
.nodeId = 3,
|
.nodeId = 4,
|
||||||
.backendNodeId = 3,
|
.backendNodeId = 4,
|
||||||
.nodeType = 1,
|
.nodeType = 1,
|
||||||
.nodeName = "BODY",
|
.nodeName = "BODY",
|
||||||
.localName = "body",
|
.localName = "body",
|
||||||
@@ -522,13 +522,13 @@ test "cdp Node: Writer" {
|
|||||||
.xmlVersion = "",
|
.xmlVersion = "",
|
||||||
.compatibilityMode = "NoQuirksMode",
|
.compatibilityMode = "NoQuirksMode",
|
||||||
.isScrollable = false,
|
.isScrollable = false,
|
||||||
.parentId = 1,
|
.parentId = 2,
|
||||||
} },
|
} },
|
||||||
}, json);
|
}, json);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const node = registry.lookup_by_id.get(1).?;
|
const node = registry.lookup_by_id.get(2).?;
|
||||||
const json = try std.json.Stringify.valueAlloc(testing.allocator, Writer{
|
const json = try std.json.Stringify.valueAlloc(testing.allocator, Writer{
|
||||||
.root = node,
|
.root = node,
|
||||||
.depth = -1,
|
.depth = -1,
|
||||||
@@ -538,8 +538,8 @@ test "cdp Node: Writer" {
|
|||||||
defer testing.allocator.free(json);
|
defer testing.allocator.free(json);
|
||||||
|
|
||||||
try testing.expectJson(&.{ .{
|
try testing.expectJson(&.{ .{
|
||||||
.nodeId = 2,
|
.nodeId = 3,
|
||||||
.backendNodeId = 2,
|
.backendNodeId = 3,
|
||||||
.nodeType = 1,
|
.nodeType = 1,
|
||||||
.nodeName = "HEAD",
|
.nodeName = "HEAD",
|
||||||
.localName = "head",
|
.localName = "head",
|
||||||
@@ -550,10 +550,10 @@ test "cdp Node: Writer" {
|
|||||||
.xmlVersion = "",
|
.xmlVersion = "",
|
||||||
.compatibilityMode = "NoQuirksMode",
|
.compatibilityMode = "NoQuirksMode",
|
||||||
.isScrollable = false,
|
.isScrollable = false,
|
||||||
.parentId = 1,
|
.parentId = 2,
|
||||||
}, .{
|
}, .{
|
||||||
.nodeId = 3,
|
.nodeId = 4,
|
||||||
.backendNodeId = 3,
|
.backendNodeId = 4,
|
||||||
.nodeType = 1,
|
.nodeType = 1,
|
||||||
.nodeName = "BODY",
|
.nodeName = "BODY",
|
||||||
.localName = "body",
|
.localName = "body",
|
||||||
@@ -565,20 +565,20 @@ test "cdp Node: Writer" {
|
|||||||
.compatibilityMode = "NoQuirksMode",
|
.compatibilityMode = "NoQuirksMode",
|
||||||
.isScrollable = false,
|
.isScrollable = false,
|
||||||
.children = &.{ .{
|
.children = &.{ .{
|
||||||
.nodeId = 4,
|
.nodeId = 5,
|
||||||
.localName = "a",
|
.localName = "a",
|
||||||
.childNodeCount = 0,
|
.childNodeCount = 0,
|
||||||
.parentId = 3,
|
.parentId = 4,
|
||||||
}, .{
|
}, .{
|
||||||
.nodeId = 5,
|
.nodeId = 6,
|
||||||
.localName = "div",
|
.localName = "div",
|
||||||
.childNodeCount = 1,
|
.childNodeCount = 1,
|
||||||
.parentId = 3,
|
.parentId = 4,
|
||||||
.children = &.{.{
|
.children = &.{.{
|
||||||
.nodeId = 6,
|
.nodeId = 7,
|
||||||
.localName = "a",
|
.localName = "a",
|
||||||
.childNodeCount = 0,
|
.childNodeCount = 0,
|
||||||
.parentId = 5,
|
.parentId = 6,
|
||||||
}},
|
}},
|
||||||
} },
|
} },
|
||||||
} }, json);
|
} }, json);
|
||||||
|
|||||||
@@ -527,7 +527,7 @@ test "cdp.dom: search flow" {
|
|||||||
.method = "DOM.getSearchResults",
|
.method = "DOM.getSearchResults",
|
||||||
.params = .{ .searchId = "0", .fromIndex = 0, .toIndex = 2 },
|
.params = .{ .searchId = "0", .fromIndex = 0, .toIndex = 2 },
|
||||||
});
|
});
|
||||||
try ctx.expectSentResult(.{ .nodeIds = &.{ 0, 1 } }, .{ .id = 13 });
|
try ctx.expectSentResult(.{ .nodeIds = &.{ 1, 2 } }, .{ .id = 13 });
|
||||||
|
|
||||||
// different fromIndex
|
// different fromIndex
|
||||||
try ctx.processMessage(.{
|
try ctx.processMessage(.{
|
||||||
@@ -535,7 +535,7 @@ test "cdp.dom: search flow" {
|
|||||||
.method = "DOM.getSearchResults",
|
.method = "DOM.getSearchResults",
|
||||||
.params = .{ .searchId = "0", .fromIndex = 1, .toIndex = 2 },
|
.params = .{ .searchId = "0", .fromIndex = 1, .toIndex = 2 },
|
||||||
});
|
});
|
||||||
try ctx.expectSentResult(.{ .nodeIds = &.{1} }, .{ .id = 14 });
|
try ctx.expectSentResult(.{ .nodeIds = &.{2} }, .{ .id = 14 });
|
||||||
|
|
||||||
// different toIndex
|
// different toIndex
|
||||||
try ctx.processMessage(.{
|
try ctx.processMessage(.{
|
||||||
@@ -543,7 +543,7 @@ test "cdp.dom: search flow" {
|
|||||||
.method = "DOM.getSearchResults",
|
.method = "DOM.getSearchResults",
|
||||||
.params = .{ .searchId = "0", .fromIndex = 0, .toIndex = 1 },
|
.params = .{ .searchId = "0", .fromIndex = 0, .toIndex = 1 },
|
||||||
});
|
});
|
||||||
try ctx.expectSentResult(.{ .nodeIds = &.{0} }, .{ .id = 15 });
|
try ctx.expectSentResult(.{ .nodeIds = &.{1} }, .{ .id = 15 });
|
||||||
}
|
}
|
||||||
|
|
||||||
try ctx.processMessage(.{
|
try ctx.processMessage(.{
|
||||||
@@ -588,7 +588,7 @@ test "cdp.dom: querySelector Node not found" {
|
|||||||
|
|
||||||
_ = try ctx.loadBrowserContext(.{ .id = "BID-A", .html = "<p>1</p> <p>2</p>" });
|
_ = try ctx.loadBrowserContext(.{ .id = "BID-A", .html = "<p>1</p> <p>2</p>" });
|
||||||
|
|
||||||
try ctx.processMessage(.{ // Hacky way to make sure nodeId 0 exists in the registry
|
try ctx.processMessage(.{ // Hacky way to make sure nodeId 1 exists in the registry
|
||||||
.id = 3,
|
.id = 3,
|
||||||
.method = "DOM.performSearch",
|
.method = "DOM.performSearch",
|
||||||
.params = .{ .query = "p" },
|
.params = .{ .query = "p" },
|
||||||
@@ -598,13 +598,13 @@ test "cdp.dom: querySelector Node not found" {
|
|||||||
try testing.expectError(error.NodeNotFoundForGivenId, ctx.processMessage(.{
|
try testing.expectError(error.NodeNotFoundForGivenId, ctx.processMessage(.{
|
||||||
.id = 4,
|
.id = 4,
|
||||||
.method = "DOM.querySelector",
|
.method = "DOM.querySelector",
|
||||||
.params = .{ .nodeId = 0, .selector = "a" },
|
.params = .{ .nodeId = 1, .selector = "a" },
|
||||||
}));
|
}));
|
||||||
|
|
||||||
try ctx.processMessage(.{
|
try ctx.processMessage(.{
|
||||||
.id = 5,
|
.id = 5,
|
||||||
.method = "DOM.querySelectorAll",
|
.method = "DOM.querySelectorAll",
|
||||||
.params = .{ .nodeId = 0, .selector = "a" },
|
.params = .{ .nodeId = 1, .selector = "a" },
|
||||||
});
|
});
|
||||||
try ctx.expectSentResult(.{ .nodeIds = &[_]u32{} }, .{ .id = 5 });
|
try ctx.expectSentResult(.{ .nodeIds = &[_]u32{} }, .{ .id = 5 });
|
||||||
}
|
}
|
||||||
@@ -615,7 +615,7 @@ test "cdp.dom: querySelector Nodes found" {
|
|||||||
|
|
||||||
_ = try ctx.loadBrowserContext(.{ .id = "BID-A", .html = "<div><p>2</p></div>" });
|
_ = try ctx.loadBrowserContext(.{ .id = "BID-A", .html = "<div><p>2</p></div>" });
|
||||||
|
|
||||||
try ctx.processMessage(.{ // Hacky way to make sure nodeId 0 exists in the registry
|
try ctx.processMessage(.{ // Hacky way to make sure nodeId 1 exists in the registry
|
||||||
.id = 3,
|
.id = 3,
|
||||||
.method = "DOM.performSearch",
|
.method = "DOM.performSearch",
|
||||||
.params = .{ .query = "div" },
|
.params = .{ .query = "div" },
|
||||||
@@ -625,18 +625,18 @@ test "cdp.dom: querySelector Nodes found" {
|
|||||||
try ctx.processMessage(.{
|
try ctx.processMessage(.{
|
||||||
.id = 4,
|
.id = 4,
|
||||||
.method = "DOM.querySelector",
|
.method = "DOM.querySelector",
|
||||||
.params = .{ .nodeId = 0, .selector = "p" },
|
.params = .{ .nodeId = 1, .selector = "p" },
|
||||||
});
|
});
|
||||||
try ctx.expectSentEvent("DOM.setChildNodes", null, .{});
|
try ctx.expectSentEvent("DOM.setChildNodes", null, .{});
|
||||||
try ctx.expectSentResult(.{ .nodeId = 5 }, .{ .id = 4 });
|
try ctx.expectSentResult(.{ .nodeId = 6 }, .{ .id = 4 });
|
||||||
|
|
||||||
try ctx.processMessage(.{
|
try ctx.processMessage(.{
|
||||||
.id = 5,
|
.id = 5,
|
||||||
.method = "DOM.querySelectorAll",
|
.method = "DOM.querySelectorAll",
|
||||||
.params = .{ .nodeId = 0, .selector = "p" },
|
.params = .{ .nodeId = 1, .selector = "p" },
|
||||||
});
|
});
|
||||||
try ctx.expectSentEvent("DOM.setChildNodes", null, .{});
|
try ctx.expectSentEvent("DOM.setChildNodes", null, .{});
|
||||||
try ctx.expectSentResult(.{ .nodeIds = &.{5} }, .{ .id = 5 });
|
try ctx.expectSentResult(.{ .nodeIds = &.{6} }, .{ .id = 5 });
|
||||||
}
|
}
|
||||||
|
|
||||||
test "cdp.dom: getBoxModel" {
|
test "cdp.dom: getBoxModel" {
|
||||||
@@ -645,7 +645,7 @@ test "cdp.dom: getBoxModel" {
|
|||||||
|
|
||||||
_ = try ctx.loadBrowserContext(.{ .id = "BID-A", .html = "<div><p>2</p></div>" });
|
_ = try ctx.loadBrowserContext(.{ .id = "BID-A", .html = "<div><p>2</p></div>" });
|
||||||
|
|
||||||
try ctx.processMessage(.{ // Hacky way to make sure nodeId 0 exists in the registry
|
try ctx.processMessage(.{ // Hacky way to make sure nodeId 1 exists in the registry
|
||||||
.id = 3,
|
.id = 3,
|
||||||
.method = "DOM.getDocument",
|
.method = "DOM.getDocument",
|
||||||
});
|
});
|
||||||
@@ -653,14 +653,14 @@ test "cdp.dom: getBoxModel" {
|
|||||||
try ctx.processMessage(.{
|
try ctx.processMessage(.{
|
||||||
.id = 4,
|
.id = 4,
|
||||||
.method = "DOM.querySelector",
|
.method = "DOM.querySelector",
|
||||||
.params = .{ .nodeId = 0, .selector = "p" },
|
.params = .{ .nodeId = 1, .selector = "p" },
|
||||||
});
|
});
|
||||||
try ctx.expectSentResult(.{ .nodeId = 2 }, .{ .id = 4 });
|
try ctx.expectSentResult(.{ .nodeId = 3 }, .{ .id = 4 });
|
||||||
|
|
||||||
try ctx.processMessage(.{
|
try ctx.processMessage(.{
|
||||||
.id = 5,
|
.id = 5,
|
||||||
.method = "DOM.getBoxModel",
|
.method = "DOM.getBoxModel",
|
||||||
.params = .{ .nodeId = 5 },
|
.params = .{ .nodeId = 6 },
|
||||||
});
|
});
|
||||||
try ctx.expectSentResult(.{ .model = BoxModel{
|
try ctx.expectSentResult(.{ .model = BoxModel{
|
||||||
.content = Quad{ 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 },
|
.content = Quad{ 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 },
|
||||||
|
|||||||
Reference in New Issue
Block a user