Add Servo scroll snapshots

This commit is contained in:
2026-05-08 13:54:56 -04:00
parent 8068d4ba32
commit 7178174e20
12 changed files with 738 additions and 268 deletions
+85 -11
View File
@@ -20,6 +20,10 @@ const PRD_SITE_COMPATIBILITY_SIZES: &[FrameSize] = &[
FrameSize { width: 934, height: 657 },
FrameSize { width: 1614, height: 980 },
];
const SERVO_SCROLL_SITE: PrdSiteCompatibilityCase =
PrdSiteCompatibilityCase { url: "https://servo.org", title_fragment: "Servo" };
const SERVO_SCROLL_SIZE: FrameSize = FrameSize { width: 934, height: 657 };
const SERVO_SCROLL_OFFSET: ScrollOffset = ScrollOffset { x: 0, y: 480 };
struct PrdSiteCompatibilityCase {
url: &'static str,
@@ -32,38 +36,81 @@ struct FrameSize {
height: u64,
}
#[derive(Clone, Copy)]
struct ScrollOffset {
x: i64,
y: i64,
}
impl ScrollOffset {
const ZERO: Self = Self { x: 0, y: 0 };
}
#[test]
fn sidecar_snapshots_prd_sites_to_rgba_files() -> Result<(), Box<dyn Error>> {
for case in PRD_SITE_COMPATIBILITY_CASES {
for size in PRD_SITE_COMPATIBILITY_SIZES {
snapshot_prd_site(case, *size)?;
snapshot_prd_site(case, *size, ScrollOffset::ZERO)?;
}
}
Ok(())
}
#[test]
fn sidecar_scrolls_prd_site_with_servo_input() -> Result<(), Box<dyn Error>> {
let initial_report =
snapshot_prd_site(&SERVO_SCROLL_SITE, SERVO_SCROLL_SIZE, ScrollOffset::ZERO)?;
let scrolled_report =
snapshot_prd_site(&SERVO_SCROLL_SITE, SERVO_SCROLL_SIZE, SERVO_SCROLL_OFFSET)?;
assert_eq!(report_field_as_i64(&scrolled_report, "scroll_x")?, SERVO_SCROLL_OFFSET.x);
assert_eq!(report_field_as_i64(&scrolled_report, "scroll_y")?, SERVO_SCROLL_OFFSET.y);
assert_eq!(
report_field_as_u64(&scrolled_report, "width")?,
SERVO_SCROLL_SIZE.width,
"{}",
SERVO_SCROLL_SITE.url
);
assert!(
report_field_as_bool(&scrolled_report, "scroll_changed_frame")?,
"{}",
SERVO_SCROLL_SITE.url
);
assert_ne!(
report_field_as_u64(&initial_report, "sample_hash")?,
report_field_as_u64(&scrolled_report, "sample_hash")?,
"{}",
SERVO_SCROLL_SITE.url
);
Ok(())
}
fn snapshot_prd_site(
case: &PrdSiteCompatibilityCase,
size: FrameSize,
) -> Result<(), Box<dyn Error>> {
scroll_offset: ScrollOffset,
) -> Result<serde_json::Value, Box<dyn Error>> {
let site_name = case
.url
.chars()
.map(|character| if character.is_ascii_alphanumeric() { character } else { '-' })
.collect::<String>();
let output_path = std::env::temp_dir().join(format!(
"ely-servo-sidecar-{}-{site_name}-{}x{}.rgba",
"ely-servo-sidecar-{}-{site_name}-{}x{}-{}-{}.rgba",
std::process::id(),
size.width,
size.height
size.height,
scroll_offset.x,
scroll_offset.y
));
if output_path.exists() {
std::fs::remove_file(&output_path)?;
}
let output = run_sidecar_snapshot(case.url, &output_path, size)?;
let output = run_sidecar_snapshot(case.url, &output_path, size, scroll_offset)?;
assert!(
output.status.success(),
@@ -97,15 +144,17 @@ fn snapshot_prd_site(
assert_eq!(std::fs::metadata(&output_path)?.len(), size.width * size.height * 4);
std::fs::remove_file(&output_path)?;
Ok(())
Ok(report)
}
fn run_sidecar_snapshot(
site_url: &str,
output_path: &std::path::Path,
size: FrameSize,
scroll_offset: ScrollOffset,
) -> Result<Output, Box<dyn Error>> {
let mut child = Command::new(env!("CARGO_BIN_EXE_ely_servo_sidecar"))
let mut command = Command::new(env!("CARGO_BIN_EXE_ely_servo_sidecar"));
command
.arg("snapshot")
.arg("--url")
.arg(site_url)
@@ -114,10 +163,15 @@ fn run_sidecar_snapshot(
.arg("--width")
.arg(size.width.to_string())
.arg("--height")
.arg(size.height.to_string())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()?;
.arg(size.height.to_string());
if scroll_offset.x != 0 {
command.arg("--scroll-x").arg(scroll_offset.x.to_string());
}
if scroll_offset.y != 0 {
command.arg("--scroll-y").arg(scroll_offset.y.to_string());
}
let mut child = command.stdout(Stdio::piped()).stderr(Stdio::piped()).spawn()?;
let started_at = Instant::now();
loop {
@@ -162,6 +216,26 @@ fn assert_report_text_contains(
Ok(())
}
fn report_field_as_bool(
report: &serde_json::Value,
field: &'static str,
) -> Result<bool, Box<dyn Error>> {
report
.get(field)
.and_then(serde_json::Value::as_bool)
.ok_or_else(|| format!("missing boolean report field: {field}").into())
}
fn report_field_as_i64(
report: &serde_json::Value,
field: &'static str,
) -> Result<i64, Box<dyn Error>> {
report
.get(field)
.and_then(serde_json::Value::as_i64)
.ok_or_else(|| format!("missing signed report field: {field}").into())
}
fn report_field_as_u64(
report: &serde_json::Value,
field: &'static str,
+9 -1
View File
@@ -4,7 +4,8 @@ use std::{error::Error, thread, time::Duration};
use ely_domain::{ProfileId, TabId, UrlText};
use ely_servo_host::{
NavigationRequest, ServoHost, ServoHostError, ServoSurfaceSize, SoftwareServoHost, WebViewState,
NavigationRequest, ScrollRequest, ServoHost, ServoHostError, ServoSurfaceSize,
SoftwareServoHost, WebViewState,
};
const MINIMUM_CONTENT_PIXELS: u64 = 1_000;
@@ -69,6 +70,13 @@ fn manages_real_servo_webview_lifecycle() -> Result<(), Box<dyn Error>> {
previous_frame_hash = Some(host.last_rendered_frame()?.sample_hash());
}
let previous_frame_hash = host.last_rendered_frame()?.sample_hash();
host.scroll(ScrollRequest { webview_id: webview_id.clone(), delta_x: 0, delta_y: 480 })?;
let snapshot = wait_for_rendered_webview(&mut host, &webview_id, Some(previous_frame_hash))?;
assert_eq!(snapshot.state(), &WebViewState::Complete, "snapshot: {snapshot:?}");
assert_rendered_frame_has_content(&host, "https://servo.org scrolled", MINIMUM_CONTENT_PIXELS)?;
assert_ne!(host.last_rendered_frame()?.sample_hash(), previous_frame_hash);
assert!(matches!(
SoftwareServoHost::new(ServoSurfaceSize::new(640, 480)),
Err(ServoHostError::RuntimeAlreadyStarted)