mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-21 20:24:42 +00:00
fix(test): update tests to match new CDP error handling behavior
processMessage no longer returns Zig errors when dispatchCommand fails — it sends a CDP error response and continues. Update all expectError calls to use processMessage + expectSentError instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -550,11 +550,12 @@ test "cdp.dom: getSearchResults unknown search id" {
|
||||
var ctx = testing.context();
|
||||
defer ctx.deinit();
|
||||
|
||||
try testing.expectError(error.BrowserContextNotLoaded, ctx.processMessage(.{
|
||||
try ctx.processMessage(.{
|
||||
.id = 8,
|
||||
.method = "DOM.getSearchResults",
|
||||
.params = .{ .searchId = "Nope", .fromIndex = 0, .toIndex = 10 },
|
||||
}));
|
||||
});
|
||||
try ctx.expectSentError(-31998, "BrowserContextNotLoaded", .{ .id = 8 });
|
||||
}
|
||||
|
||||
test "cdp.dom: search flow" {
|
||||
@@ -604,11 +605,12 @@ test "cdp.dom: search flow" {
|
||||
try ctx.expectSentResult(null, .{ .id = 16 });
|
||||
|
||||
// make sure the delete actually did something
|
||||
try testing.expectError(error.SearchResultNotFound, ctx.processMessage(.{
|
||||
try ctx.processMessage(.{
|
||||
.id = 17,
|
||||
.method = "DOM.getSearchResults",
|
||||
.params = .{ .searchId = "0", .fromIndex = 0, .toIndex = 1 },
|
||||
}));
|
||||
});
|
||||
try ctx.expectSentError(-31998, "SearchResultNotFound", .{ .id = 17 });
|
||||
}
|
||||
|
||||
test "cdp.dom: querySelector unknown search id" {
|
||||
@@ -645,11 +647,12 @@ test "cdp.dom: querySelector Node not found" {
|
||||
});
|
||||
try ctx.expectSentResult(.{ .searchId = "0", .resultCount = 2 }, .{ .id = 3 });
|
||||
|
||||
try testing.expectError(error.NodeNotFoundForGivenId, ctx.processMessage(.{
|
||||
try ctx.processMessage(.{
|
||||
.id = 4,
|
||||
.method = "DOM.querySelector",
|
||||
.params = .{ .nodeId = 1, .selector = "a" },
|
||||
}));
|
||||
});
|
||||
try ctx.expectSentError(-31998, "NodeNotFoundForGivenId", .{ .id = 4 });
|
||||
|
||||
try ctx.processMessage(.{
|
||||
.id = 5,
|
||||
|
||||
@@ -633,7 +633,7 @@ test "cdp.page: getFrameTree" {
|
||||
defer ctx.deinit();
|
||||
|
||||
{
|
||||
try testing.expectError(error.BrowserContextNotLoaded, ctx.processMessage(.{ .id = 10, .method = "Page.getFrameTree", .params = .{ .targetId = "X" } }));
|
||||
try ctx.processMessage(.{ .id = 10, .method = "Page.getFrameTree", .params = .{ .targetId = "X" } });
|
||||
try ctx.expectSentError(-31998, "BrowserContextNotLoaded", .{ .id = 10 });
|
||||
}
|
||||
|
||||
|
||||
@@ -556,7 +556,7 @@ test "cdp.target: disposeBrowserContext" {
|
||||
defer ctx.deinit();
|
||||
|
||||
{
|
||||
try testing.expectError(error.InvalidParams, ctx.processMessage(.{ .id = 7, .method = "Target.disposeBrowserContext" }));
|
||||
try ctx.processMessage(.{ .id = 7, .method = "Target.disposeBrowserContext" });
|
||||
try ctx.expectSentError(-31998, "InvalidParams", .{ .id = 7 });
|
||||
}
|
||||
|
||||
@@ -609,7 +609,7 @@ test "cdp.target: createTarget" {
|
||||
defer ctx.deinit();
|
||||
const bc = try ctx.loadBrowserContext(.{ .id = "BID-9" });
|
||||
{
|
||||
try testing.expectError(error.UnknownBrowserContextId, ctx.processMessage(.{ .id = 10, .method = "Target.createTarget", .params = .{ .browserContextId = "BID-8" } }));
|
||||
try ctx.processMessage(.{ .id = 10, .method = "Target.createTarget", .params = .{ .browserContextId = "BID-8" } });
|
||||
try ctx.expectSentError(-31998, "UnknownBrowserContextId", .{ .id = 10 });
|
||||
}
|
||||
|
||||
@@ -626,13 +626,13 @@ test "cdp.target: closeTarget" {
|
||||
defer ctx.deinit();
|
||||
|
||||
{
|
||||
try testing.expectError(error.BrowserContextNotLoaded, ctx.processMessage(.{ .id = 10, .method = "Target.closeTarget", .params = .{ .targetId = "X" } }));
|
||||
try ctx.processMessage(.{ .id = 10, .method = "Target.closeTarget", .params = .{ .targetId = "X" } });
|
||||
try ctx.expectSentError(-31998, "BrowserContextNotLoaded", .{ .id = 10 });
|
||||
}
|
||||
|
||||
const bc = try ctx.loadBrowserContext(.{ .id = "BID-9" });
|
||||
{
|
||||
try testing.expectError(error.TargetNotLoaded, ctx.processMessage(.{ .id = 10, .method = "Target.closeTarget", .params = .{ .targetId = "TID-8" } }));
|
||||
try ctx.processMessage(.{ .id = 10, .method = "Target.closeTarget", .params = .{ .targetId = "TID-8" } });
|
||||
try ctx.expectSentError(-31998, "TargetNotLoaded", .{ .id = 10 });
|
||||
}
|
||||
|
||||
@@ -640,7 +640,7 @@ test "cdp.target: closeTarget" {
|
||||
_ = try bc.session.createPage();
|
||||
bc.target_id = "TID-000000000A".*;
|
||||
{
|
||||
try testing.expectError(error.UnknownTargetId, ctx.processMessage(.{ .id = 10, .method = "Target.closeTarget", .params = .{ .targetId = "TID-8" } }));
|
||||
try ctx.processMessage(.{ .id = 10, .method = "Target.closeTarget", .params = .{ .targetId = "TID-8" } });
|
||||
try ctx.expectSentError(-31998, "UnknownTargetId", .{ .id = 10 });
|
||||
}
|
||||
|
||||
@@ -657,13 +657,13 @@ test "cdp.target: attachToTarget" {
|
||||
defer ctx.deinit();
|
||||
|
||||
{
|
||||
try testing.expectError(error.BrowserContextNotLoaded, ctx.processMessage(.{ .id = 10, .method = "Target.attachToTarget", .params = .{ .targetId = "X" } }));
|
||||
try ctx.processMessage(.{ .id = 10, .method = "Target.attachToTarget", .params = .{ .targetId = "X" } });
|
||||
try ctx.expectSentError(-31998, "BrowserContextNotLoaded", .{ .id = 10 });
|
||||
}
|
||||
|
||||
const bc = try ctx.loadBrowserContext(.{ .id = "BID-9" });
|
||||
{
|
||||
try testing.expectError(error.TargetNotLoaded, ctx.processMessage(.{ .id = 10, .method = "Target.attachToTarget", .params = .{ .targetId = "TID-8" } }));
|
||||
try ctx.processMessage(.{ .id = 10, .method = "Target.attachToTarget", .params = .{ .targetId = "TID-8" } });
|
||||
try ctx.expectSentError(-31998, "TargetNotLoaded", .{ .id = 10 });
|
||||
}
|
||||
|
||||
@@ -671,7 +671,7 @@ test "cdp.target: attachToTarget" {
|
||||
_ = try bc.session.createPage();
|
||||
bc.target_id = "TID-000000000B".*;
|
||||
{
|
||||
try testing.expectError(error.UnknownTargetId, ctx.processMessage(.{ .id = 10, .method = "Target.attachToTarget", .params = .{ .targetId = "TID-8" } }));
|
||||
try ctx.processMessage(.{ .id = 10, .method = "Target.attachToTarget", .params = .{ .targetId = "TID-8" } });
|
||||
try ctx.expectSentError(-31998, "UnknownTargetId", .{ .id = 10 });
|
||||
}
|
||||
|
||||
@@ -701,13 +701,13 @@ test "cdp.target: getTargetInfo" {
|
||||
}
|
||||
|
||||
{
|
||||
try testing.expectError(error.BrowserContextNotLoaded, ctx.processMessage(.{ .id = 10, .method = "Target.getTargetInfo", .params = .{ .targetId = "X" } }));
|
||||
try ctx.processMessage(.{ .id = 10, .method = "Target.getTargetInfo", .params = .{ .targetId = "X" } });
|
||||
try ctx.expectSentError(-31998, "BrowserContextNotLoaded", .{ .id = 10 });
|
||||
}
|
||||
|
||||
const bc = try ctx.loadBrowserContext(.{ .id = "BID-9" });
|
||||
{
|
||||
try testing.expectError(error.TargetNotLoaded, ctx.processMessage(.{ .id = 10, .method = "Target.getTargetInfo", .params = .{ .targetId = "TID-8" } }));
|
||||
try ctx.processMessage(.{ .id = 10, .method = "Target.getTargetInfo", .params = .{ .targetId = "TID-8" } });
|
||||
try ctx.expectSentError(-31998, "TargetNotLoaded", .{ .id = 10 });
|
||||
}
|
||||
|
||||
@@ -715,7 +715,7 @@ test "cdp.target: getTargetInfo" {
|
||||
_ = try bc.session.createPage();
|
||||
bc.target_id = "TID-000000000C".*;
|
||||
{
|
||||
try testing.expectError(error.UnknownTargetId, ctx.processMessage(.{ .id = 10, .method = "Target.getTargetInfo", .params = .{ .targetId = "TID-8" } }));
|
||||
try ctx.processMessage(.{ .id = 10, .method = "Target.getTargetInfo", .params = .{ .targetId = "TID-8" } });
|
||||
try ctx.expectSentError(-31998, "UnknownTargetId", .{ .id = 10 });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user