Add Servo engine host runtime

This commit is contained in:
2026-05-07 18:47:37 -04:00
parent 8f0f577928
commit b787486f8e
11 changed files with 6138 additions and 106 deletions
@@ -0,0 +1,54 @@
#![cfg(feature = "servo-engine")]
use std::{error::Error, thread, time::Duration};
use ely_domain::{ProfileId, TabId, UrlText};
use ely_servo_host::{
NavigationRequest, ServoHost, ServoHostError, ServoSurfaceSize, SoftwareServoHost, WebViewState,
};
#[test]
fn manages_real_servo_webview_lifecycle() -> Result<(), Box<dyn Error>> {
let mut host = SoftwareServoHost::new(ServoSurfaceSize::new(320, 240))?;
let tab_id = TabId::new();
let profile_id = ProfileId::new();
let webview_id = host.create_webview(tab_id.clone(), profile_id.clone())?;
let snapshot = host.snapshot(&webview_id)?;
assert_eq!(snapshot.webview_id(), &webview_id);
assert_eq!(snapshot.tab_id(), &tab_id);
assert_eq!(snapshot.profile_id(), &profile_id);
assert_eq!(snapshot.state(), &WebViewState::Created);
let url = UrlText::parse(
"data:text/html,%3Ctitle%3EELY%20Host%3C%2Ftitle%3E%3Cmain%3EReady%3C%2Fmain%3E",
)?;
host.navigate(NavigationRequest { webview_id: webview_id.clone(), tab_id, url })?;
for _ in 0..1_000 {
host.tick();
if host.state(&webview_id)? == WebViewState::Complete {
break;
}
thread::sleep(Duration::from_millis(1));
}
let snapshot = host.snapshot(&webview_id)?;
assert_eq!(snapshot.state(), &WebViewState::Complete, "snapshot: {snapshot:?}");
assert!(
snapshot.url().is_some_and(|value| value.starts_with("data:text/html,")),
"snapshot: {snapshot:?}"
);
host.paint(&webview_id)?;
let snapshot = host.snapshot(&webview_id)?;
assert!(!snapshot.has_pending_frame());
assert!(matches!(
SoftwareServoHost::new(ServoSurfaceSize::new(320, 240)),
Err(ServoHostError::RuntimeAlreadyStarted)
));
Ok(())
}