mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-28 22:53:28 +00:00
test scaffolding
This commit is contained in:
@@ -58,6 +58,7 @@ pub const Browser = struct {
|
||||
http_client: *http.Client,
|
||||
session_pool: SessionPool,
|
||||
page_arena: std.heap.ArenaAllocator,
|
||||
pub const EnvType = Env;
|
||||
|
||||
const SessionPool = std.heap.MemoryPool(Session);
|
||||
|
||||
|
||||
@@ -309,7 +309,7 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
||||
node_registry: Node.Registry,
|
||||
node_search_list: Node.Search.List,
|
||||
|
||||
isolated_world: ?IsolatedWorld,
|
||||
isolated_world: ?IsolatedWorld(CDP_T.Browser.EnvType),
|
||||
|
||||
const Self = @This();
|
||||
|
||||
@@ -481,11 +481,13 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
||||
/// An isolated world has it's own instance of globals like Window.
|
||||
/// Generally the client needs to resolve a node into the isolated world to be able to work with it.
|
||||
/// An object id is unique across all contexts, different object ids can refer to the same Node in different contexts.
|
||||
pub const IsolatedWorld = struct {
|
||||
name: []const u8,
|
||||
grant_universal_access: bool,
|
||||
executor: *@import("../browser/env.zig").Env.Executor,
|
||||
};
|
||||
pub fn IsolatedWorld(comptime E: type) type {
|
||||
return struct {
|
||||
name: []const u8,
|
||||
grant_universal_access: bool,
|
||||
executor: *E.Executor,
|
||||
};
|
||||
}
|
||||
|
||||
// This is a generic because when we send a result we have two different
|
||||
// behaviors. Normally, we're sending the result to the client. But in some cases
|
||||
|
||||
@@ -39,10 +39,13 @@ pub const Document = @import("../testing.zig").Document;
|
||||
const Browser = struct {
|
||||
session: ?*Session = null,
|
||||
arena: std.heap.ArenaAllocator,
|
||||
env: Env,
|
||||
pub const EnvType = Env;
|
||||
|
||||
pub fn init(app: *App) !Browser {
|
||||
return .{
|
||||
.arena = std.heap.ArenaAllocator.init(app.allocator),
|
||||
.env = Env{},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -56,13 +59,14 @@ const Browser = struct {
|
||||
return error.MockBrowserSessionAlreadyExists;
|
||||
}
|
||||
const arena = self.arena.allocator();
|
||||
const executor = arena.create(Executor) catch unreachable;
|
||||
const executor = arena.create(Env.Executor) catch unreachable;
|
||||
self.session = try arena.create(Session);
|
||||
self.session.?.* = .{
|
||||
.page = null,
|
||||
.arena = arena,
|
||||
.arena = self.arena,
|
||||
.executor = executor,
|
||||
.inspector = .{},
|
||||
.state = 0,
|
||||
};
|
||||
return self.session.?;
|
||||
}
|
||||
@@ -77,9 +81,10 @@ const Browser = struct {
|
||||
|
||||
const Session = struct {
|
||||
page: ?Page = null,
|
||||
arena: Allocator,
|
||||
executor: *Executor,
|
||||
arena: std.heap.ArenaAllocator,
|
||||
executor: *Env.Executor,
|
||||
inspector: Inspector,
|
||||
state: i32,
|
||||
|
||||
pub fn currentPage(self: *Session) ?*Page {
|
||||
return &(self.page orelse return null);
|
||||
@@ -92,7 +97,7 @@ const Session = struct {
|
||||
self.page = .{
|
||||
.session = self,
|
||||
.url = URL.parse("https://lightpanda.io/", null) catch unreachable,
|
||||
.aux_data = try self.arena.dupe(u8, aux_data orelse ""),
|
||||
.aux_data = try self.arena.allocator().dupe(u8, aux_data orelse ""),
|
||||
};
|
||||
return &self.page.?;
|
||||
}
|
||||
@@ -107,12 +112,43 @@ const Session = struct {
|
||||
}
|
||||
};
|
||||
|
||||
const Executor = struct {};
|
||||
const Env = struct {
|
||||
pub const Executor = MockExecutor;
|
||||
pub fn startExecutor(self: *Env, comptime Global: type, state: anytype, module_loader: anytype, kind: anytype) !*Executor {
|
||||
_ = self;
|
||||
_ = Global;
|
||||
_ = state;
|
||||
_ = module_loader;
|
||||
_ = kind;
|
||||
return error.MockExecutor;
|
||||
}
|
||||
pub fn stopExecutor(self: *Env, executor: *Executor) void {
|
||||
_ = self;
|
||||
_ = executor;
|
||||
}
|
||||
};
|
||||
const MockExecutor = struct {
|
||||
context: Context,
|
||||
|
||||
pub fn startScope(self: *MockExecutor, global: anytype) !void {
|
||||
_ = self;
|
||||
_ = global;
|
||||
}
|
||||
pub fn endScope(self: *MockExecutor) void {
|
||||
_ = self;
|
||||
}
|
||||
};
|
||||
const Context = struct {
|
||||
pub fn debugContextId(self: Context) i32 {
|
||||
_ = self;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
const Inspector = struct {
|
||||
pub fn getRemoteObject(
|
||||
self: *const Inspector,
|
||||
executor: *Executor,
|
||||
executor: *Env.Executor,
|
||||
group: []const u8,
|
||||
value: anytype,
|
||||
) !RemoteObject {
|
||||
@@ -127,6 +163,19 @@ const Inspector = struct {
|
||||
_ = object_id;
|
||||
return try alloc.create(i32);
|
||||
}
|
||||
pub fn contextCreated(self: *const Inspector,
|
||||
executor: *const Env.Executor,
|
||||
name: []const u8,
|
||||
origin: []const u8,
|
||||
aux_data: ?[]const u8,
|
||||
is_default_context: bool,) void {
|
||||
_ = self;
|
||||
_ = executor;
|
||||
_ = name;
|
||||
_ = origin;
|
||||
_ = aux_data;
|
||||
_ = is_default_context;
|
||||
}
|
||||
};
|
||||
|
||||
const RemoteObject = struct {
|
||||
|
||||
@@ -43,7 +43,7 @@ pub fn Runner(comptime State: type, comptime Global: type, comptime types: anyty
|
||||
|
||||
const G = if (Global == void) DefaultGlobal else Global;
|
||||
|
||||
runner.executor = try runner.env.startExecutor(G, state, runner);
|
||||
runner.executor = try runner.env.startExecutor(G, state, runner, .main);
|
||||
errdefer runner.env.stopExecutor(runner.executor);
|
||||
|
||||
try runner.executor.startScope(if (Global == void) &default_global else global);
|
||||
|
||||
Reference in New Issue
Block a user