Skip to content

Commit a8e5a48

Browse files
authored
Merge pull request #1074 from lightpanda-io/cdp-nodeid
cdp: start nodeId from 1 instead of 0
2 parents e389645 + 283a9af commit a8e5a48

File tree

2 files changed

+48
-48
lines changed

2 files changed

+48
-48
lines changed

src/cdp/Node.zig

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub const Registry = struct {
4242

4343
pub fn init(allocator: Allocator) Registry {
4444
return .{
45-
.node_id = 0,
45+
.node_id = 1,
4646
.lookup_by_id = .{},
4747
.lookup_by_node = .{},
4848
.allocator = allocator,
@@ -346,24 +346,24 @@ test "cdp Node: Registry register" {
346346
{
347347
const n = (try doc.querySelector("#a1")).?;
348348
const node = try registry.register(n);
349-
const n1b = registry.lookup_by_id.get(0).?;
349+
const n1b = registry.lookup_by_id.get(1).?;
350350
const n1c = registry.lookup_by_node.get(node._node).?;
351351
try testing.expectEqual(node, n1b);
352352
try testing.expectEqual(node, n1c);
353353

354-
try testing.expectEqual(0, node.id);
354+
try testing.expectEqual(1, node.id);
355355
try testing.expectEqual(n, node._node);
356356
}
357357

358358
{
359359
const n = (try doc.querySelector("p")).?;
360360
const node = try registry.register(n);
361-
const n1b = registry.lookup_by_id.get(1).?;
361+
const n1b = registry.lookup_by_id.get(2).?;
362362
const n1c = registry.lookup_by_node.get(node._node).?;
363363
try testing.expectEqual(node, n1b);
364364
try testing.expectEqual(node, n1c);
365365

366-
try testing.expectEqual(1, node.id);
366+
try testing.expectEqual(2, node.id);
367367
try testing.expectEqual(n, node._node);
368368
}
369369
}
@@ -404,18 +404,18 @@ test "cdp Node: search list" {
404404

405405
const s1 = try search_list.create(try doc.querySelectorAll("a"));
406406
try testing.expectEqual("1", s1.name);
407-
try testing.expectEqualSlices(u32, &.{ 0, 1 }, s1.node_ids);
407+
try testing.expectEqualSlices(u32, &.{ 1, 2 }, s1.node_ids);
408408

409409
try testing.expectEqual(2, registry.lookup_by_id.count());
410410
try testing.expectEqual(2, registry.lookup_by_node.count());
411411

412412
const s2 = try search_list.create(try doc.querySelectorAll("#a1"));
413413
try testing.expectEqual("2", s2.name);
414-
try testing.expectEqualSlices(u32, &.{0}, s2.node_ids);
414+
try testing.expectEqualSlices(u32, &.{1}, s2.node_ids);
415415

416416
const s3 = try search_list.create(try doc.querySelectorAll("#a2"));
417417
try testing.expectEqual("3", s3.name);
418-
try testing.expectEqualSlices(u32, &.{1}, s3.node_ids);
418+
try testing.expectEqualSlices(u32, &.{2}, s3.node_ids);
419419

420420
try testing.expectEqual(2, registry.lookup_by_id.count());
421421
try testing.expectEqual(2, registry.lookup_by_node.count());
@@ -443,8 +443,8 @@ test "cdp Node: Writer" {
443443
defer testing.allocator.free(json);
444444

445445
try testing.expectJson(.{
446-
.nodeId = 0,
447-
.backendNodeId = 0,
446+
.nodeId = 1,
447+
.backendNodeId = 1,
448448
.nodeType = 9,
449449
.nodeName = "#document",
450450
.localName = "",
@@ -456,8 +456,8 @@ test "cdp Node: Writer" {
456456
.compatibilityMode = "NoQuirksMode",
457457
.childNodeCount = 1,
458458
.children = &.{.{
459-
.nodeId = 1,
460-
.backendNodeId = 1,
459+
.nodeId = 2,
460+
.backendNodeId = 2,
461461
.nodeType = 1,
462462
.nodeName = "HTML",
463463
.localName = "html",
@@ -473,7 +473,7 @@ test "cdp Node: Writer" {
473473
}
474474

475475
{
476-
const node = registry.lookup_by_id.get(1).?;
476+
const node = registry.lookup_by_id.get(2).?;
477477
const json = try std.json.Stringify.valueAlloc(testing.allocator, Writer{
478478
.root = node,
479479
.depth = 1,
@@ -483,8 +483,8 @@ test "cdp Node: Writer" {
483483
defer testing.allocator.free(json);
484484

485485
try testing.expectJson(.{
486-
.nodeId = 1,
487-
.backendNodeId = 1,
486+
.nodeId = 2,
487+
.backendNodeId = 2,
488488
.nodeType = 1,
489489
.nodeName = "HTML",
490490
.localName = "html",
@@ -496,8 +496,8 @@ test "cdp Node: Writer" {
496496
.compatibilityMode = "NoQuirksMode",
497497
.isScrollable = false,
498498
.children = &.{ .{
499-
.nodeId = 2,
500-
.backendNodeId = 2,
499+
.nodeId = 3,
500+
.backendNodeId = 3,
501501
.nodeType = 1,
502502
.nodeName = "HEAD",
503503
.localName = "head",
@@ -508,10 +508,10 @@ test "cdp Node: Writer" {
508508
.xmlVersion = "",
509509
.compatibilityMode = "NoQuirksMode",
510510
.isScrollable = false,
511-
.parentId = 1,
511+
.parentId = 2,
512512
}, .{
513-
.nodeId = 3,
514-
.backendNodeId = 3,
513+
.nodeId = 4,
514+
.backendNodeId = 4,
515515
.nodeType = 1,
516516
.nodeName = "BODY",
517517
.localName = "body",
@@ -522,13 +522,13 @@ test "cdp Node: Writer" {
522522
.xmlVersion = "",
523523
.compatibilityMode = "NoQuirksMode",
524524
.isScrollable = false,
525-
.parentId = 1,
525+
.parentId = 2,
526526
} },
527527
}, json);
528528
}
529529

530530
{
531-
const node = registry.lookup_by_id.get(1).?;
531+
const node = registry.lookup_by_id.get(2).?;
532532
const json = try std.json.Stringify.valueAlloc(testing.allocator, Writer{
533533
.root = node,
534534
.depth = -1,
@@ -538,8 +538,8 @@ test "cdp Node: Writer" {
538538
defer testing.allocator.free(json);
539539

540540
try testing.expectJson(&.{ .{
541-
.nodeId = 2,
542-
.backendNodeId = 2,
541+
.nodeId = 3,
542+
.backendNodeId = 3,
543543
.nodeType = 1,
544544
.nodeName = "HEAD",
545545
.localName = "head",
@@ -550,10 +550,10 @@ test "cdp Node: Writer" {
550550
.xmlVersion = "",
551551
.compatibilityMode = "NoQuirksMode",
552552
.isScrollable = false,
553-
.parentId = 1,
553+
.parentId = 2,
554554
}, .{
555-
.nodeId = 3,
556-
.backendNodeId = 3,
555+
.nodeId = 4,
556+
.backendNodeId = 4,
557557
.nodeType = 1,
558558
.nodeName = "BODY",
559559
.localName = "body",
@@ -565,20 +565,20 @@ test "cdp Node: Writer" {
565565
.compatibilityMode = "NoQuirksMode",
566566
.isScrollable = false,
567567
.children = &.{ .{
568-
.nodeId = 4,
568+
.nodeId = 5,
569569
.localName = "a",
570570
.childNodeCount = 0,
571-
.parentId = 3,
571+
.parentId = 4,
572572
}, .{
573-
.nodeId = 5,
573+
.nodeId = 6,
574574
.localName = "div",
575575
.childNodeCount = 1,
576-
.parentId = 3,
576+
.parentId = 4,
577577
.children = &.{.{
578-
.nodeId = 6,
578+
.nodeId = 7,
579579
.localName = "a",
580580
.childNodeCount = 0,
581-
.parentId = 5,
581+
.parentId = 6,
582582
}},
583583
} },
584584
} }, json);

src/cdp/domains/dom.zig

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -527,23 +527,23 @@ test "cdp.dom: search flow" {
527527
.method = "DOM.getSearchResults",
528528
.params = .{ .searchId = "0", .fromIndex = 0, .toIndex = 2 },
529529
});
530-
try ctx.expectSentResult(.{ .nodeIds = &.{ 0, 1 } }, .{ .id = 13 });
530+
try ctx.expectSentResult(.{ .nodeIds = &.{ 1, 2 } }, .{ .id = 13 });
531531

532532
// different fromIndex
533533
try ctx.processMessage(.{
534534
.id = 14,
535535
.method = "DOM.getSearchResults",
536536
.params = .{ .searchId = "0", .fromIndex = 1, .toIndex = 2 },
537537
});
538-
try ctx.expectSentResult(.{ .nodeIds = &.{1} }, .{ .id = 14 });
538+
try ctx.expectSentResult(.{ .nodeIds = &.{2} }, .{ .id = 14 });
539539

540540
// different toIndex
541541
try ctx.processMessage(.{
542542
.id = 15,
543543
.method = "DOM.getSearchResults",
544544
.params = .{ .searchId = "0", .fromIndex = 0, .toIndex = 1 },
545545
});
546-
try ctx.expectSentResult(.{ .nodeIds = &.{0} }, .{ .id = 15 });
546+
try ctx.expectSentResult(.{ .nodeIds = &.{1} }, .{ .id = 15 });
547547
}
548548

549549
try ctx.processMessage(.{
@@ -588,7 +588,7 @@ test "cdp.dom: querySelector Node not found" {
588588

589589
_ = try ctx.loadBrowserContext(.{ .id = "BID-A", .html = "<p>1</p> <p>2</p>" });
590590

591-
try ctx.processMessage(.{ // Hacky way to make sure nodeId 0 exists in the registry
591+
try ctx.processMessage(.{ // Hacky way to make sure nodeId 1 exists in the registry
592592
.id = 3,
593593
.method = "DOM.performSearch",
594594
.params = .{ .query = "p" },
@@ -598,13 +598,13 @@ test "cdp.dom: querySelector Node not found" {
598598
try testing.expectError(error.NodeNotFoundForGivenId, ctx.processMessage(.{
599599
.id = 4,
600600
.method = "DOM.querySelector",
601-
.params = .{ .nodeId = 0, .selector = "a" },
601+
.params = .{ .nodeId = 1, .selector = "a" },
602602
}));
603603

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

616616
_ = try ctx.loadBrowserContext(.{ .id = "BID-A", .html = "<div><p>2</p></div>" });
617617

618-
try ctx.processMessage(.{ // Hacky way to make sure nodeId 0 exists in the registry
618+
try ctx.processMessage(.{ // Hacky way to make sure nodeId 1 exists in the registry
619619
.id = 3,
620620
.method = "DOM.performSearch",
621621
.params = .{ .query = "div" },
@@ -625,18 +625,18 @@ test "cdp.dom: querySelector Nodes found" {
625625
try ctx.processMessage(.{
626626
.id = 4,
627627
.method = "DOM.querySelector",
628-
.params = .{ .nodeId = 0, .selector = "p" },
628+
.params = .{ .nodeId = 1, .selector = "p" },
629629
});
630630
try ctx.expectSentEvent("DOM.setChildNodes", null, .{});
631-
try ctx.expectSentResult(.{ .nodeId = 5 }, .{ .id = 4 });
631+
try ctx.expectSentResult(.{ .nodeId = 6 }, .{ .id = 4 });
632632

633633
try ctx.processMessage(.{
634634
.id = 5,
635635
.method = "DOM.querySelectorAll",
636-
.params = .{ .nodeId = 0, .selector = "p" },
636+
.params = .{ .nodeId = 1, .selector = "p" },
637637
});
638638
try ctx.expectSentEvent("DOM.setChildNodes", null, .{});
639-
try ctx.expectSentResult(.{ .nodeIds = &.{5} }, .{ .id = 5 });
639+
try ctx.expectSentResult(.{ .nodeIds = &.{6} }, .{ .id = 5 });
640640
}
641641

642642
test "cdp.dom: getBoxModel" {
@@ -645,22 +645,22 @@ test "cdp.dom: getBoxModel" {
645645

646646
_ = try ctx.loadBrowserContext(.{ .id = "BID-A", .html = "<div><p>2</p></div>" });
647647

648-
try ctx.processMessage(.{ // Hacky way to make sure nodeId 0 exists in the registry
648+
try ctx.processMessage(.{ // Hacky way to make sure nodeId 1 exists in the registry
649649
.id = 3,
650650
.method = "DOM.getDocument",
651651
});
652652

653653
try ctx.processMessage(.{
654654
.id = 4,
655655
.method = "DOM.querySelector",
656-
.params = .{ .nodeId = 0, .selector = "p" },
656+
.params = .{ .nodeId = 1, .selector = "p" },
657657
});
658-
try ctx.expectSentResult(.{ .nodeId = 2 }, .{ .id = 4 });
658+
try ctx.expectSentResult(.{ .nodeId = 3 }, .{ .id = 4 });
659659

660660
try ctx.processMessage(.{
661661
.id = 5,
662662
.method = "DOM.getBoxModel",
663-
.params = .{ .nodeId = 5 },
663+
.params = .{ .nodeId = 6 },
664664
});
665665
try ctx.expectSentResult(.{ .model = BoxModel{
666666
.content = Quad{ 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 },

0 commit comments

Comments
 (0)