Merge pull request #1990 from lightpanda-io/remove_cdp_generic

Remove cdp generic
This commit is contained in:
Karl Seguin
2026-03-26 07:49:13 +08:00
committed by GitHub
13 changed files with 454 additions and 394 deletions

View File

@@ -112,7 +112,7 @@ fn resetPermissions(cmd: anytype) !void {
const testing = @import("../testing.zig");
test "cdp.browser: getVersion" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
try ctx.processMessage(.{
@@ -131,7 +131,7 @@ test "cdp.browser: getVersion" {
}
test "cdp.browser: getWindowForTarget" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
try ctx.processMessage(.{

View File

@@ -547,7 +547,7 @@ fn requestNode(cmd: anytype) !void {
const testing = @import("../testing.zig");
test "cdp.dom: getSearchResults unknown search id" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
try ctx.processMessage(.{
@@ -559,7 +559,7 @@ test "cdp.dom: getSearchResults unknown search id" {
}
test "cdp.dom: search flow" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
_ = try ctx.loadBrowserContext(.{ .id = "BID-A", .url = "cdp/dom1.html" });
@@ -614,7 +614,7 @@ test "cdp.dom: search flow" {
}
test "cdp.dom: querySelector unknown search id" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
_ = try ctx.loadBrowserContext(.{ .id = "BID-A", .url = "cdp/dom1.html" });
@@ -635,7 +635,7 @@ test "cdp.dom: querySelector unknown search id" {
}
test "cdp.dom: querySelector Node not found" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
_ = try ctx.loadBrowserContext(.{ .id = "BID-A", .url = "cdp/dom1.html" });
@@ -663,7 +663,7 @@ test "cdp.dom: querySelector Node not found" {
}
test "cdp.dom: querySelector Nodes found" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
_ = try ctx.loadBrowserContext(.{ .id = "BID-A", .url = "cdp/dom2.html" });
@@ -693,7 +693,7 @@ test "cdp.dom: querySelector Nodes found" {
}
test "cdp.dom: getBoxModel" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
_ = try ctx.loadBrowserContext(.{ .id = "BID-A", .url = "cdp/dom2.html" });

View File

@@ -279,7 +279,7 @@ fn waitForSelector(cmd: anytype) !void {
const testing = @import("../testing.zig");
test "cdp.lp: getMarkdown" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
const bc = try ctx.loadBrowserContext(.{});
@@ -290,12 +290,12 @@ test "cdp.lp: getMarkdown" {
.method = "LP.getMarkdown",
});
const result = ctx.client.?.sent.items[0].object.get("result").?.object;
const result = (try ctx.getSentMessage(0)).?.object.get("result").?.object;
try testing.expect(result.get("markdown") != null);
}
test "cdp.lp: getInteractiveElements" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
const bc = try ctx.loadBrowserContext(.{});
@@ -306,13 +306,13 @@ test "cdp.lp: getInteractiveElements" {
.method = "LP.getInteractiveElements",
});
const result = ctx.client.?.sent.items[0].object.get("result").?.object;
const result = (try ctx.getSentMessage(0)).?.object.get("result").?.object;
try testing.expect(result.get("elements") != null);
try testing.expect(result.get("nodeIds") != null);
}
test "cdp.lp: getStructuredData" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
const bc = try ctx.loadBrowserContext(.{});
@@ -323,12 +323,12 @@ test "cdp.lp: getStructuredData" {
.method = "LP.getStructuredData",
});
const result = ctx.client.?.sent.items[0].object.get("result").?.object;
const result = (try ctx.getSentMessage(0)).?.object.get("result").?.object;
try testing.expect(result.get("structuredData") != null);
}
test "cdp.lp: action tools" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
const bc = try ctx.loadBrowserContext(.{});
@@ -389,7 +389,7 @@ test "cdp.lp: action tools" {
}
test "cdp.lp: waitForSelector" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
const bc = try ctx.loadBrowserContext(.{});
@@ -405,9 +405,8 @@ test "cdp.lp: waitForSelector" {
.method = "LP.waitForSelector",
.params = .{ .selector = "#existing", .timeout = 2000 },
});
var result = ctx.client.?.sent.items[0].object.get("result").?.object;
var result = (try ctx.getSentMessage(0)).?.object.get("result").?.object;
try testing.expect(result.get("backendNodeId") != null);
ctx.client.?.sent.clearRetainingCapacity();
// 2. Delayed element
try ctx.processMessage(.{
@@ -415,9 +414,8 @@ test "cdp.lp: waitForSelector" {
.method = "LP.waitForSelector",
.params = .{ .selector = "#delayed", .timeout = 5000 },
});
result = ctx.client.?.sent.items[0].object.get("result").?.object;
result = (try ctx.getSentMessage(1)).?.object.get("result").?.object;
try testing.expect(result.get("backendNodeId") != null);
ctx.client.?.sent.clearRetainingCapacity();
// 3. Timeout error
try ctx.processMessage(.{
@@ -425,6 +423,6 @@ test "cdp.lp: waitForSelector" {
.method = "LP.waitForSelector",
.params = .{ .selector = "#nonexistent", .timeout = 100 },
});
const err_obj = ctx.client.?.sent.items[0].object.get("error").?.object;
const err_obj = (try ctx.getSentMessage(2)).?.object.get("error").?.object;
try testing.expect(err_obj.get("code") != null);
}

View File

@@ -439,7 +439,7 @@ fn idFromRequestId(request_id: []const u8) !u64 {
const testing = @import("../testing.zig");
test "cdp.network setExtraHTTPHeaders" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
_ = try ctx.loadBrowserContext(.{ .id = "NID-A", .session_id = "NESI-A" });
@@ -465,7 +465,7 @@ test "cdp.Network: cookies" {
const ResCookie = CdpStorage.ResCookie;
const CdpCookie = CdpStorage.CdpCookie;
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
_ = try ctx.loadBrowserContext(.{ .id = "BID-S" });

View File

@@ -82,7 +82,7 @@ fn getFrameTree(cmd: anytype) !void {
.frame = .{
.id = "TID-STARTUP",
.loaderId = "LID-STARTUP",
.securityOrigin = @import("../cdp.zig").URL_BASE,
.securityOrigin = @import("../CDP.zig").URL_BASE,
.url = "about:blank",
.secureContextType = "Secure",
},
@@ -642,7 +642,7 @@ fn getLayoutMetrics(cmd: anytype) !void {
const testing = @import("../testing.zig");
test "cdp.page: getFrameTree" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
{
@@ -712,7 +712,7 @@ test "cdp.page: captureScreenshot" {
const filter: LogFilter = .init(&.{.not_implemented});
defer filter.deinit();
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
{
try ctx.processMessage(.{ .id = 10, .method = "Page.captureScreenshot", .params = .{ .format = "jpg" } });
@@ -728,7 +728,7 @@ test "cdp.page: captureScreenshot" {
}
test "cdp.page: getLayoutMetrics" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
_ = try ctx.loadBrowserContext(.{ .id = "BID-9", .url = "hi.html", .target_id = "FID-000000000X".* });

View File

@@ -44,7 +44,7 @@ fn setIgnoreCertificateErrors(cmd: anytype) !void {
const testing = @import("../testing.zig");
test "cdp.Security: setIgnoreCertificateErrors" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
_ = try ctx.loadBrowserContext(.{ .id = "BID-9" });

View File

@@ -243,7 +243,7 @@ pub fn writeCookie(cookie: *const Cookie, w: anytype) !void {
const testing = @import("../testing.zig");
test "cdp.Storage: cookies" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
_ = try ctx.loadBrowserContext(.{ .id = "BID-S" });

View File

@@ -512,7 +512,7 @@ const TargetInfo = struct {
const testing = @import("../testing.zig");
test "cdp.target: getBrowserContexts" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
// {
@@ -536,7 +536,7 @@ test "cdp.target: getBrowserContexts" {
}
test "cdp.target: createBrowserContext" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
{
@@ -554,7 +554,7 @@ test "cdp.target: createBrowserContext" {
}
test "cdp.target: disposeBrowserContext" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
{
@@ -585,7 +585,7 @@ test "cdp.target: disposeBrowserContext" {
test "cdp.target: createTarget" {
{
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
try ctx.processMessage(.{ .id = 10, .method = "Target.createTarget", .params = .{ .url = "about:blank" } });
@@ -595,7 +595,7 @@ test "cdp.target: createTarget" {
}
{
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
// active auto attach to get the Target.attachedToTarget event.
try ctx.processMessage(.{ .id = 9, .method = "Target.setAutoAttach", .params = .{ .autoAttach = true, .waitForDebuggerOnStart = false } });
@@ -607,7 +607,7 @@ test "cdp.target: createTarget" {
try ctx.expectSentEvent("Target.attachedToTarget", .{ .sessionId = bc.session_id.?, .targetInfo = .{ .url = "about:blank", .title = "", .attached = true, .type = "page", .canAccessOpener = false, .browserContextId = bc.id, .targetId = bc.target_id.? } }, .{});
}
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
const bc = try ctx.loadBrowserContext(.{ .id = "BID-9" });
{
@@ -624,7 +624,7 @@ test "cdp.target: createTarget" {
}
test "cdp.target: closeTarget" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
{
@@ -655,7 +655,7 @@ test "cdp.target: closeTarget" {
}
test "cdp.target: attachToTarget" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
{
@@ -686,7 +686,7 @@ test "cdp.target: attachToTarget" {
}
test "cdp.target: getTargetInfo" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
{
@@ -737,7 +737,7 @@ test "cdp.target: getTargetInfo" {
}
test "cdp.target: issue#474: attach to just created target" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
const bc = try ctx.loadBrowserContext(.{ .id = "BID-9" });
{
@@ -752,7 +752,7 @@ test "cdp.target: issue#474: attach to just created target" {
}
test "cdp.target: detachFromTarget" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
const bc = try ctx.loadBrowserContext(.{ .id = "BID-9" });
{
@@ -775,19 +775,19 @@ test "cdp.target: detachFromTarget" {
}
test "cdp.target: detachFromTarget without session" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
_ = try ctx.loadBrowserContext(.{ .id = "BID-9" });
{
// detach when no session is attached should not send event
try ctx.processMessage(.{ .id = 10, .method = "Target.detachFromTarget" });
try ctx.expectSentResult(null, .{ .id = 10 });
try ctx.expectSentCount(0);
try ctx.expectSentCount(1);
}
}
test "cdp.target: setAutoAttach false sends detachedFromTarget" {
var ctx = testing.context();
var ctx = try testing.context();
defer ctx.deinit();
const bc = try ctx.loadBrowserContext(.{ .id = "BID-9" });
{