mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-28 15:40:04 +00:00
Removes CDPT (generic CDP)
CDPT used to be a generic so that we could inject Browser, Session, Page and Client. At some point, it [thankfully] became a generic only to inject Client. This commit removes the generic and bakes the *Server.Client instance in CDP. It uses a socketpair for testing. BrowserContext is still generic, but that's generic for a very different reason and, while I'd like to remove that generic too, it belongs in a different PR.
This commit is contained in:
@@ -260,7 +260,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(.{});
|
||||
@@ -271,12 +271,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(.{});
|
||||
@@ -287,13 +287,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(.{});
|
||||
@@ -304,12 +304,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(.{});
|
||||
@@ -370,7 +370,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(.{});
|
||||
@@ -386,9 +386,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(.{
|
||||
@@ -396,9 +395,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(.{
|
||||
@@ -406,6 +404,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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user