Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions src/cdp/Node.zig
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub const Registry = struct {

pub fn init(allocator: Allocator) Registry {
return .{
.node_id = 0,
.node_id = 1,
.lookup_by_id = .{},
.lookup_by_node = .{},
.allocator = allocator,
Expand Down Expand Up @@ -346,24 +346,24 @@ test "cdp Node: Registry register" {
{
const n = (try doc.querySelector("#a1")).?;
const node = try registry.register(n);
const n1b = registry.lookup_by_id.get(0).?;
const n1b = registry.lookup_by_id.get(1).?;
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(1, 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(2).?;
const n1c = registry.lookup_by_node.get(node._node).?;
try testing.expectEqual(node, n1b);
try testing.expectEqual(node, n1c);

try testing.expectEqual(1, node.id);
try testing.expectEqual(2, node.id);
try testing.expectEqual(n, node._node);
}
}
Expand Down Expand Up @@ -404,18 +404,18 @@ test "cdp Node: search list" {

const s1 = try search_list.create(try doc.querySelectorAll("a"));
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_node.count());

const s2 = try search_list.create(try doc.querySelectorAll("#a1"));
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"));
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_node.count());
Expand Down Expand Up @@ -443,8 +443,8 @@ test "cdp Node: Writer" {
defer testing.allocator.free(json);

try testing.expectJson(.{
.nodeId = 0,
.backendNodeId = 0,
.nodeId = 1,
.backendNodeId = 1,
.nodeType = 9,
.nodeName = "#document",
.localName = "",
Expand All @@ -456,8 +456,8 @@ test "cdp Node: Writer" {
.compatibilityMode = "NoQuirksMode",
.childNodeCount = 1,
.children = &.{.{
.nodeId = 1,
.backendNodeId = 1,
.nodeId = 2,
.backendNodeId = 2,
.nodeType = 1,
.nodeName = "HTML",
.localName = "html",
Expand All @@ -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{
.root = node,
.depth = 1,
Expand All @@ -483,8 +483,8 @@ test "cdp Node: Writer" {
defer testing.allocator.free(json);

try testing.expectJson(.{
.nodeId = 1,
.backendNodeId = 1,
.nodeId = 2,
.backendNodeId = 2,
.nodeType = 1,
.nodeName = "HTML",
.localName = "html",
Expand All @@ -496,8 +496,8 @@ test "cdp Node: Writer" {
.compatibilityMode = "NoQuirksMode",
.isScrollable = false,
.children = &.{ .{
.nodeId = 2,
.backendNodeId = 2,
.nodeId = 3,
.backendNodeId = 3,
.nodeType = 1,
.nodeName = "HEAD",
.localName = "head",
Expand All @@ -508,10 +508,10 @@ test "cdp Node: Writer" {
.xmlVersion = "",
.compatibilityMode = "NoQuirksMode",
.isScrollable = false,
.parentId = 1,
.parentId = 2,
}, .{
.nodeId = 3,
.backendNodeId = 3,
.nodeId = 4,
.backendNodeId = 4,
.nodeType = 1,
.nodeName = "BODY",
.localName = "body",
Expand All @@ -522,13 +522,13 @@ test "cdp Node: Writer" {
.xmlVersion = "",
.compatibilityMode = "NoQuirksMode",
.isScrollable = false,
.parentId = 1,
.parentId = 2,
} },
}, 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{
.root = node,
.depth = -1,
Expand All @@ -538,8 +538,8 @@ test "cdp Node: Writer" {
defer testing.allocator.free(json);

try testing.expectJson(&.{ .{
.nodeId = 2,
.backendNodeId = 2,
.nodeId = 3,
.backendNodeId = 3,
.nodeType = 1,
.nodeName = "HEAD",
.localName = "head",
Expand All @@ -550,10 +550,10 @@ test "cdp Node: Writer" {
.xmlVersion = "",
.compatibilityMode = "NoQuirksMode",
.isScrollable = false,
.parentId = 1,
.parentId = 2,
}, .{
.nodeId = 3,
.backendNodeId = 3,
.nodeId = 4,
.backendNodeId = 4,
.nodeType = 1,
.nodeName = "BODY",
.localName = "body",
Expand All @@ -565,20 +565,20 @@ test "cdp Node: Writer" {
.compatibilityMode = "NoQuirksMode",
.isScrollable = false,
.children = &.{ .{
.nodeId = 4,
.nodeId = 5,
.localName = "a",
.childNodeCount = 0,
.parentId = 3,
.parentId = 4,
}, .{
.nodeId = 5,
.nodeId = 6,
.localName = "div",
.childNodeCount = 1,
.parentId = 3,
.parentId = 4,
.children = &.{.{
.nodeId = 6,
.nodeId = 7,
.localName = "a",
.childNodeCount = 0,
.parentId = 5,
.parentId = 6,
}},
} },
} }, json);
Expand Down
30 changes: 15 additions & 15 deletions src/cdp/domains/dom.zig
Original file line number Diff line number Diff line change
Expand Up @@ -527,23 +527,23 @@ test "cdp.dom: search flow" {
.method = "DOM.getSearchResults",
.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
try ctx.processMessage(.{
.id = 14,
.method = "DOM.getSearchResults",
.params = .{ .searchId = "0", .fromIndex = 1, .toIndex = 2 },
});
try ctx.expectSentResult(.{ .nodeIds = &.{1} }, .{ .id = 14 });
try ctx.expectSentResult(.{ .nodeIds = &.{2} }, .{ .id = 14 });

// different toIndex
try ctx.processMessage(.{
.id = 15,
.method = "DOM.getSearchResults",
.params = .{ .searchId = "0", .fromIndex = 0, .toIndex = 1 },
});
try ctx.expectSentResult(.{ .nodeIds = &.{0} }, .{ .id = 15 });
try ctx.expectSentResult(.{ .nodeIds = &.{1} }, .{ .id = 15 });
}

try ctx.processMessage(.{
Expand Down Expand Up @@ -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.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,
.method = "DOM.performSearch",
.params = .{ .query = "p" },
Expand All @@ -598,13 +598,13 @@ test "cdp.dom: querySelector Node not found" {
try testing.expectError(error.NodeNotFoundForGivenId, ctx.processMessage(.{
.id = 4,
.method = "DOM.querySelector",
.params = .{ .nodeId = 0, .selector = "a" },
.params = .{ .nodeId = 1, .selector = "a" },
}));

try ctx.processMessage(.{
.id = 5,
.method = "DOM.querySelectorAll",
.params = .{ .nodeId = 0, .selector = "a" },
.params = .{ .nodeId = 1, .selector = "a" },
});
try ctx.expectSentResult(.{ .nodeIds = &[_]u32{} }, .{ .id = 5 });
}
Expand All @@ -615,7 +615,7 @@ test "cdp.dom: querySelector Nodes found" {

_ = 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,
.method = "DOM.performSearch",
.params = .{ .query = "div" },
Expand All @@ -625,18 +625,18 @@ test "cdp.dom: querySelector Nodes found" {
try ctx.processMessage(.{
.id = 4,
.method = "DOM.querySelector",
.params = .{ .nodeId = 0, .selector = "p" },
.params = .{ .nodeId = 1, .selector = "p" },
});
try ctx.expectSentEvent("DOM.setChildNodes", null, .{});
try ctx.expectSentResult(.{ .nodeId = 5 }, .{ .id = 4 });
try ctx.expectSentResult(.{ .nodeId = 6 }, .{ .id = 4 });

try ctx.processMessage(.{
.id = 5,
.method = "DOM.querySelectorAll",
.params = .{ .nodeId = 0, .selector = "p" },
.params = .{ .nodeId = 1, .selector = "p" },
});
try ctx.expectSentEvent("DOM.setChildNodes", null, .{});
try ctx.expectSentResult(.{ .nodeIds = &.{5} }, .{ .id = 5 });
try ctx.expectSentResult(.{ .nodeIds = &.{6} }, .{ .id = 5 });
}

test "cdp.dom: getBoxModel" {
Expand All @@ -645,22 +645,22 @@ test "cdp.dom: getBoxModel" {

_ = 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,
.method = "DOM.getDocument",
});

try ctx.processMessage(.{
.id = 4,
.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(.{
.id = 5,
.method = "DOM.getBoxModel",
.params = .{ .nodeId = 5 },
.params = .{ .nodeId = 6 },
});
try ctx.expectSentResult(.{ .model = BoxModel{
.content = Quad{ 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 },
Expand Down