///|
test "native ABI is loaded" {
inspect(abi_version(), content="1")
let info = runtime_info()
inspect(info.abi_version, content="1")
assert_true(info.build_mode == "abi-only" || info.build_mode == "runtime")
assert_true(info.runtime_available == (info.build_mode == "runtime"))
assert_true(info.features.contains("event_polling"))
assert_true(info.features.contains("bridge_polling"))
}///|
test "typed runtime config JSON" {
let config = RuntimeConfig::new(
runtime_root="app-runtime",
helper_path="cef_process.exe",
cache_dir="/absolute/path/to/cache",
)
let json = config.to_json_string()
assert_true(json.contains("\"abi_version\":1"))
assert_true(json.contains("\"runtime_root\":\"app-runtime\""))
assert_true(json.contains("\"helper_path\":\"cef_process.exe\""))
assert_true(json.contains("\"cache_dir\":\"/absolute/path/to/cache\""))
assert_true(json.contains("\"persist_session_cookies\":true"))
}///|
test "bundled runtime config JSON" {
let json = RuntimeConfig::bundled(cache_dir="/absolute/path/to/cache").to_json_string()
assert_true(json.contains("\"use_bundled\":true"))
assert_true(json.contains("\"cache_dir\":\"/absolute/path/to/cache\""))
assert_true(json.contains("\"persist_session_cookies\":true"))
}///|
test "runtime and window lifecycle" {
let runtime = Runtime::new()
let window = Window::new(
runtime,
config=WindowConfig::new(
title="Proton",
width=320,
height=240,
initial_url="about:blank",
),
)
match runtime.poll_event() {
Some(event) => inspect(event.event_type(), content="window_created")
_ => fail("expected window_created")
}
window.load_html("<p>Hello Proton</p>", "proton://app/")
window.destroy()
runtime.destroy()
}///|
test "runtime wait event readiness" {
let runtime = Runtime::new()
let empty = runtime.wait(interest_mask=runtime_wait_event, timeout_ms=0)
inspect(empty.is_timeout(), content="true")
let window = Window::new(runtime)
let ready = runtime.wait(interest_mask=runtime_wait_event, timeout_ms=0)
inspect(ready.has_event(), content="true")
match runtime.poll_event() {
Some(event) => inspect(event.event_type(), content="window_created")
_ => fail("expected window_created")
}
window.destroy()
runtime.destroy()
}///|
test "web contents view lifecycle" {
let runtime = Runtime::new()
let window = Window::new(runtime)
let view = View::new(
window,
ViewConfig::new(
width=320,
height=200,
x=10,
y=20,
initial_url="about:blank",
),
)
view.set_bounds(x=20, y=30, width=300, height=180)
view.set_z_order(1)
view.load_url("about:blank")
let state = view.state()
inspect(state.width, content="300")
inspect(state.visible, content="true")
view.destroy()
window.destroy()
runtime.destroy()
}fn AppActivation::new(urls? : Array[String], files? : Array[String], reopen? : Bool) -> AppActivationtype AppInstancefn AppInstance::acquire(identifier : String, activation : AppActivation) -> AppInstanceAcquire raise NativeErrorpub(all) struct BridgeConfig {
raw_json : String?
max_payload_bytes : Int
grants : Array[BridgeGrantConfig]
} derive(Eq, Debug)pub(all) struct BridgeDiagnostic {
abi_version : Int
stage : String
code : String
message : String
page_instance : String
url : String
owner : String?
source_url : String?
source_line : String?
line : Int?
column : Int?
stack : String?
additional_failure_count : Int?
details_truncated : Bool
} derive(Eq, Debug, FromJson)fn BridgeExtensionConfig::new(js_namespace : String, apis~ : Array[String]) -> BridgeExtensionConfigpub(all) struct BridgeGrantConfig {
source_origin : String
ops : Array[String]
extensions : Array[BridgeExtensionConfig]
initialization_units : Array[BridgeInitializationUnit]
} derive(Eq, Debug)fn BridgeGrantConfig::new(source_origin : String, ops~ : Array[String], extensions? : Array[BridgeExtensionConfig], initialization_units? : Array[BridgeInitializationUnit]) -> BridgeGrantConfigfn BridgeInitializationUnit::new(owner : String, name : String, source : String) -> BridgeInitializationUnitpub(all) struct BrowserPolicy {
navigation : BrowserPolicyMode
popup : BrowserPolicyMode
download : BrowserPolicyMode
certificate : BrowserPolicyMode
media : BrowserPolicyMode
devtools : Bool
} derive(Eq, Debug)fn BrowserPolicy::new(navigation? : BrowserPolicyMode, popup? : BrowserPolicyMode, download? : BrowserPolicyMode, certificate? : BrowserPolicyMode, media? : BrowserPolicyMode, devtools? : Bool) -> BrowserPolicypub(all) enum NativeBrowserRequest {
Navigation(request_id~ : Int64, url~ : String, http_method~ : String, user_gesture~ : Bool, redirect~ : Bool)
Popup(request_id~ : Int64, url~ : String, disposition~ : Int, user_gesture~ : Bool)
Download(request_id~ : Int64, download_id~ : Int, url~ : String, suggested_name~ : String)
Certificate(request_id~ : Int64, url~ : String, error_code~ : Int)
Media(request_id~ : Int64, origin~ : String, permissions~ : Int)
} derive(Eq, Debug)type Runtimefn Runtime::begin_message_dialog(self : Runtime, title : String?, message : String, level : DialogLevel) -> Int64 raise NativeErrorfn Runtime::respond_bridge_request(self : Runtime, response : BridgeResponse) -> Unit raise NativeErrorfn Runtime::wait(self : Runtime, interest_mask~ : Int, timeout_ms? : Int) -> RuntimeWaitReady raise NativeErrorfn RuntimeConfig::bundled(helper_path? : String, cache_dir? : String, remote_debugging_port? : Int, headless? : Bool, persist_session_cookies? : Bool) -> RuntimeConfigfn RuntimeConfig::new(runtime_root? : String, helper_path? : String, resources_dir? : String, locales_dir? : String, cache_dir? : String, remote_debugging_port? : Int, headless? : Bool, persist_session_cookies? : Bool) -> RuntimeConfigtype UpdateStagetype Viewfn View::browser_command(self : View, command : String, download_id? : Int) -> Unit raise NativeErrorfn View::set_bounds(self : View, x~ : Int, y~ : Int, width~ : Int, height~ : Int) -> Unit raise NativeErrorfn ViewConfig::new(width~ : Int, height~ : Int, x? : Int, y? : Int, visible? : Bool, z_order? : Int, initial_url? : String, background_color? : String) -> ViewConfigtype Windowfn Window::browser_command(self : Window, command : String, download_id? : Int) -> Unit raise NativeErrorfn Window::load_asset(self : Window, html : String, document_url : String, asset_root : String) -> Unit raise NativeErrorfn Window::respond_browser_request(self : Window, request_id : Int64, action : String, path? : String) -> Unit raise NativeErrorfn Window::respond_close_request(self : Window, request_id : Int64, allow : Bool) -> Unit raise NativeErrorfn WindowConfig::new(title? : String, width? : Int, height? : Int, initial_url? : String, size_hint? : WindowSizeHint, titlebar_style? : TitlebarStyle, browser? : BrowserPolicy, bridge? : BridgeConfig) -> WindowConfigfn WindowRef::begin_choose_directory_dialog(self : WindowRef, title : String?, path : String?) -> Int64 raise NativeErrorfn WindowRef::begin_confirm_dialog(self : WindowRef, title : String?, message : String, level : DialogLevel) -> Int64 raise NativeErrorfn WindowRef::begin_message_dialog(self : WindowRef, title : String?, message : String, level : DialogLevel) -> Int64 raise NativeErrorfn WindowRef::begin_open_file_dialog(self : WindowRef, title : String?, path : String?) -> Int64 raise NativeErrorfn WindowRef::begin_save_file_dialog(self : WindowRef, title : String?, path : String?) -> Int64 raise NativeErrorfn WindowRef::poll_dialog_result(self : WindowRef, dialog : Int64) -> DialogPollResult raise NativeErrorpub(all) struct WindowState {
x : Int
y : Int
width : Int
height : Int
monitor : WindowMonitor
zoom_percent : Int
visible : Bool
focused : Bool
minimized : Bool
maximized : Bool
fullscreen : Bool
always_on_top : Bool
theme : String
} derive(Eq, Debug, FromJson)fn host_loop_end() -> Unitfn signal_wakeup() -> Unitfn update_stage_begin(parent_dir : String, expected_size : Int64, target_revision : UInt64) -> UpdateStage raise NativeErrorfn update_stage_begin_for_current_app(expected_size : Int64, target_revision : UInt64) -> UpdateStage raise NativeErrorfn web_contents_view_supported() -> BoolMoonBit bindings for the Proton native desktop runtime.
Dependencies