Harden PRD live site rendering checks

This commit is contained in:
2026-05-09 01:03:19 -04:00
parent 96732c8932
commit 89a8e05eeb
8 changed files with 208 additions and 149 deletions
+1
View File
@@ -18,5 +18,6 @@ cargo check -p ely_servo_host --features servo-engine --all-targets
cargo clippy -p ely_servo_host --features servo-engine --all-targets -- -D warnings cargo clippy -p ely_servo_host --features servo-engine --all-targets -- -D warnings
cargo test -p ely_servo_host --features servo-engine --test software_host cargo test -p ely_servo_host --features servo-engine --test software_host
cargo test -p ely_servo_host --features servo-engine --test sidecar -- --test-threads=1 cargo test -p ely_servo_host --features servo-engine --test sidecar -- --test-threads=1
cargo test -p ely_app --features live-site-smoke --all-targets -- --test-threads=1
cargo run -p ely_app cargo run -p ely_app
``` ```
@@ -201,6 +201,7 @@ impl SidecarSnapshotRequest {
pub struct SidecarSnapshot { pub struct SidecarSnapshot {
loaded_url: Option<String>, loaded_url: Option<String>,
title: Option<String>, title: Option<String>,
render_state: String,
width: u32, width: u32,
height: u32, height: u32,
#[cfg(test)] #[cfg(test)]
@@ -250,6 +251,7 @@ impl SidecarSnapshot {
Ok(Self { Ok(Self {
loaded_url: report.loaded_url, loaded_url: report.loaded_url,
title: report.title, title: report.title,
render_state: report.state,
width: report.width, width: report.width,
height: report.height, height: report.height,
#[cfg(test)] #[cfg(test)]
@@ -272,6 +274,11 @@ impl SidecarSnapshot {
self.title.as_deref() self.title.as_deref()
} }
#[must_use]
pub fn render_state(&self) -> &str {
self.render_state.as_str()
}
#[must_use] #[must_use]
pub fn width(&self) -> u32 { pub fn width(&self) -> u32 {
self.width self.width
@@ -28,6 +28,7 @@ fn accepts_loading_report_with_visible_content() -> Result<(), ServoSidecarError
assert_eq!(snapshot.loaded_url(), Some("https://example.com/")); assert_eq!(snapshot.loaded_url(), Some("https://example.com/"));
assert_eq!(snapshot.title(), Some("Example Domain")); assert_eq!(snapshot.title(), Some("Example Domain"));
assert_eq!(snapshot.render_state(), "loading");
assert_eq!(snapshot.width(), 2); assert_eq!(snapshot.width(), 2);
assert_eq!(snapshot.height(), 1); assert_eq!(snapshot.height(), 1);
assert_eq!(snapshot.non_white_pixel_count, 1); assert_eq!(snapshot.non_white_pixel_count, 1);
@@ -156,6 +157,7 @@ fn assert_live_sites_render(cases: &[LiveSiteCase]) -> Result<(), Box<dyn Error>
assert_eq!(snapshot.width(), LIVE_SITE_WIDTH, "{}", case.url); assert_eq!(snapshot.width(), LIVE_SITE_WIDTH, "{}", case.url);
assert_eq!(snapshot.height(), LIVE_SITE_HEIGHT, "{}", case.url); assert_eq!(snapshot.height(), LIVE_SITE_HEIGHT, "{}", case.url);
assert_render_state_is_open(snapshot.render_state(), case.url);
assert_loaded_url_contains(&snapshot, case.url)?; assert_loaded_url_contains(&snapshot, case.url)?;
assert_title_contains(&snapshot, case.title_fragment)?; assert_title_contains(&snapshot, case.title_fragment)?;
assert!(snapshot.non_white_pixel_count > 0, "{}", case.url); assert!(snapshot.non_white_pixel_count > 0, "{}", case.url);
@@ -173,6 +175,11 @@ fn assert_live_sites_render(cases: &[LiveSiteCase]) -> Result<(), Box<dyn Error>
Ok(()) Ok(())
} }
#[cfg(feature = "live-site-smoke")]
fn assert_render_state_is_open(state: &str, url: &str) {
assert!(matches!(state, "complete" | "loading"), "{url} state: {state}");
}
#[cfg(feature = "live-site-smoke")] #[cfg(feature = "live-site-smoke")]
fn assert_loaded_url_contains( fn assert_loaded_url_contains(
snapshot: &SidecarSnapshot, snapshot: &SidecarSnapshot,
@@ -16,6 +16,7 @@ pub(super) struct WebSurfaceFrame {
pub(super) requested_url: String, pub(super) requested_url: String,
loaded_url: Option<String>, loaded_url: Option<String>,
title: Option<String>, title: Option<String>,
render_state: String,
width: u32, width: u32,
height: u32, height: u32,
scroll_offset: WebSurfaceScrollOffset, scroll_offset: WebSurfaceScrollOffset,
@@ -36,6 +37,7 @@ impl WebSurfaceFrame {
let height = snapshot.height(); let height = snapshot.height();
let loaded_url = snapshot.loaded_url().map(str::to_string); let loaded_url = snapshot.loaded_url().map(str::to_string);
let title = snapshot.title().map(str::to_string); let title = snapshot.title().map(str::to_string);
let render_state = snapshot.render_state().to_string();
let rgba_bytes = snapshot.into_rgba_bytes(); let rgba_bytes = snapshot.into_rgba_bytes();
let Some(buffer) = ImageBuffer::<Rgba<u8>, _>::from_raw(width, height, rgba_bytes) else { let Some(buffer) = ImageBuffer::<Rgba<u8>, _>::from_raw(width, height, rgba_bytes) else {
@@ -48,6 +50,7 @@ impl WebSurfaceFrame {
requested_url, requested_url,
loaded_url, loaded_url,
title, title,
render_state,
width, width,
height, height,
scroll_offset, scroll_offset,
@@ -66,7 +69,8 @@ impl WebSurfaceFrame {
} }
pub(super) fn detail_label(&self) -> String { pub(super) fn detail_label(&self) -> String {
let mut detail = self.scroll_offset.detail_label(self.size()); let mut detail =
format!("{} {}", self.render_state(), self.scroll_offset.detail_label(self.size()));
if let Some(click_point) = self.click_point { if let Some(click_point) = self.click_point {
detail = format!("{detail} {}", click_point.detail_label()); detail = format!("{detail} {}", click_point.detail_label());
} }
@@ -80,6 +84,10 @@ impl WebSurfaceFrame {
WebSurfaceSize { width: self.width, height: self.height } WebSurfaceSize { width: self.width, height: self.height }
} }
pub(super) fn render_state(&self) -> &str {
self.render_state.as_str()
}
pub(super) fn scroll_offset(&self) -> WebSurfaceScrollOffset { pub(super) fn scroll_offset(&self) -> WebSurfaceScrollOffset {
self.scroll_offset self.scroll_offset
} }
@@ -74,9 +74,14 @@ fn assert_prd_frame_is_ready(frame: &WebSurfaceFrame, case: &LiveSiteCase) {
case.url case.url
); );
assert_eq!(frame.scroll_offset(), WebSurfaceScrollOffset::default(), "{}", case.url); assert_eq!(frame.scroll_offset(), WebSurfaceScrollOffset::default(), "{}", case.url);
assert_render_state_is_open(frame.render_state(), case.url);
assert!(frame.url_label().contains(normalized_url(case.url)), "{}", frame.url_label()); assert!(frame.url_label().contains(normalized_url(case.url)), "{}", frame.url_label());
assert!(frame.title_label().contains(case.title_fragment), "{}", frame.title_label()); assert!(frame.title_label().contains(case.title_fragment), "{}", frame.title_label());
assert_eq!(frame.detail_label(), "934x657", "{}", case.url); assert_eq!(frame.detail_label(), format!("{} 934x657", frame.render_state()), "{}", case.url);
}
fn assert_render_state_is_open(state: &str, url: &str) {
assert!(matches!(state, "complete" | "loading"), "{url} state: {state}");
} }
fn live_surface_bounds() -> Bounds<gpui::Pixels> { fn live_surface_bounds() -> Bounds<gpui::Pixels> {
+2
View File
@@ -4,6 +4,8 @@ use std::{collections::BTreeSet, error::Error, fs, path::PathBuf, process::Comma
use ely_domain::ProfileId; use ely_domain::ProfileId;
#[path = "sidecar/site_cases.rs"]
mod site_cases;
#[path = "sidecar/support.rs"] #[path = "sidecar/support.rs"]
mod support; mod support;
@@ -0,0 +1,141 @@
pub(super) const PRD_SITE_COMPATIBILITY_CASES: &[PrdSiteCompatibilityCase] = &[
PrdSiteCompatibilityCase { url: "https://github.com", title_fragment: "GitHub" },
PrdSiteCompatibilityCase { url: "https://example.com", title_fragment: "Example Domain" },
PrdSiteCompatibilityCase { url: "https://servo.org/", title_fragment: "Servo" },
];
pub(super) const PRD_REFERENCE_SITE_COMPATIBILITY_CASES: &[PrdSiteCompatibilityCase] = &[
PrdSiteCompatibilityCase {
url: "https://blog.google/products-and-platforms/products/chrome/new-chrome-productivity-features/",
title_fragment: "Chrome",
},
PrdSiteCompatibilityCase {
url: "https://www.microsoft.com/en-us/edge/features/vertical-tabs",
title_fragment: "Microsoft Edge",
},
PrdSiteCompatibilityCase {
url: "https://resources.arc.net/hc/en-us/articles/19230755904151-Favorites-Top-Tabs-Across-Every-Space",
title_fragment: "Favorites",
},
PrdSiteCompatibilityCase {
url: "https://resources.arc.net/hc/en-us/articles/19228855311127-Auto-Archive-Clean-as-you-go",
title_fragment: "Auto Archive",
},
PrdSiteCompatibilityCase {
url: "https://vivaldi.com/features/workspaces/",
title_fragment: "Workspaces",
},
PrdSiteCompatibilityCase {
url: "https://help.vivaldi.com/desktop/tabs/tab-tiling/",
title_fragment: "Tab Tiling",
},
PrdSiteCompatibilityCase { url: "https://www.gpui.rs/", title_fragment: "gpui" },
PrdSiteCompatibilityCase { url: "https://docs.rs/gpui", title_fragment: "gpui" },
PrdSiteCompatibilityCase {
url: "https://zed.dev/blog/videogame",
title_fragment: "Leveraging Rust",
},
PrdSiteCompatibilityCase {
url: "https://github.com/longbridge/gpui-component/",
title_fragment: "gpui-component",
},
PrdSiteCompatibilityCase {
url: "https://github.com/zed-industries/awesome-gpui/",
title_fragment: "awesome-gpui",
},
PrdSiteCompatibilityCase { url: "https://servo.org/", title_fragment: "Servo" },
PrdSiteCompatibilityCase {
url: "https://servo.org/blog/2026/04/13/servo-0.1.0-release/",
title_fragment: "Servo",
},
PrdSiteCompatibilityCase {
url: "https://developers.cloudflare.com/d1/",
title_fragment: "Cloudflare",
},
PrdSiteCompatibilityCase {
url: "https://developers.cloudflare.com/workers/platform/storage-options/",
title_fragment: "Cloudflare",
},
PrdSiteCompatibilityCase {
url: "https://developers.cloudflare.com/kv/concepts/how-kv-works/",
title_fragment: "Cloudflare",
},
PrdSiteCompatibilityCase {
url: "https://better-auth.com/blog/1-5",
title_fragment: "Better Auth",
},
PrdSiteCompatibilityCase {
url: "https://developers.cloudflare.com/d1/platform/limits/",
title_fragment: "Cloudflare",
},
PrdSiteCompatibilityCase {
url: "https://component-model.bytecodealliance.org/",
title_fragment: "WebAssembly Component Model",
},
PrdSiteCompatibilityCase {
url: "https://docs.wasmtime.dev/api/wasmtime/component/index.html",
title_fragment: "wasmtime",
},
PrdSiteCompatibilityCase {
url: "https://docs.wasmtime.dev/security.html",
title_fragment: "Wasmtime",
},
];
pub(super) const PRD_SITE_COMPATIBILITY_SIZES: &[FrameSize] = &[
FrameSize { width: 640, height: 480 },
FrameSize { width: 934, height: 657 },
FrameSize { width: 1614, height: 980 },
];
pub(super) const PRD_REFERENCE_SITE_SIZE: FrameSize = FrameSize { width: 934, height: 657 };
pub(super) const SERVO_SCROLL_SITE: PrdSiteCompatibilityCase =
PrdSiteCompatibilityCase { url: "https://servo.org/", title_fragment: "Servo" };
pub(super) const SERVO_SCROLL_SIZE: FrameSize = FrameSize { width: 934, height: 657 };
pub(super) const SERVO_SCROLL_OFFSET: ScrollOffset = ScrollOffset { x: 0, y: 480 };
pub(super) const SERVO_CLICK_URL: &str = "data:text/html,%3C!doctype%20html%3E%3Ctitle%3EClick%20Probe%3C%2Ftitle%3E%3Cstyle%3Ebody%7Bmargin%3A0%3Bbackground%3A%23f7f7f7%3B%7Dbutton%7Bposition%3Aabsolute%3Bleft%3A80px%3Btop%3A80px%3Bwidth%3A220px%3Bheight%3A90px%3Bfont%3A28px%20sans-serif%3Bbackground%3A%23ffffff%3Bcolor%3A%23111111%3B%7D%3C%2Fstyle%3E%3Cbutton%20onclick%3D%22document.body.style.background%3D%27%230039ff%27%3Bdocument.title%3D%27Clicked%27%3Bthis.textContent%3D%27Clicked%27%3B%22%3ETap%3C%2Fbutton%3E";
pub(super) const SERVO_CLICK_SIZE: FrameSize = FrameSize { width: 640, height: 480 };
pub(super) const SERVO_CLICK_POINT: ClickPoint = ClickPoint { x: 160, y: 120 };
pub(super) const SERVO_DRAG_URL: &str = "data:text/html,%3C%21doctype%20html%3E%3Ctitle%3EDrag%20Probe%3C%2Ftitle%3E%3Cstyle%3Ebody%7Bmargin%3A0%3Bbackground%3A%23f7f7f7%3B%7Dbutton%7Bposition%3Aabsolute%3Bleft%3A80px%3Btop%3A80px%3Bwidth%3A220px%3Bheight%3A90px%3Bfont%3A28px%20sans-serif%3Bbackground%3A%23ffffff%3Bcolor%3A%23111111%3B%7D%3C%2Fstyle%3E%3Cbutton%20id%3Dbox%3EDrag%3C%2Fbutton%3E%3Cscript%3Elet%20dragging%3Dfalse%3Bconst%20box%3Ddocument.getElementById%28%27box%27%29%3BaddEventListener%28%27mousedown%27%2Cevent%3D%3E%7Bif%28event.target%3D%3D%3Dbox%29%7Bdragging%3Dtrue%3B%7D%7D%29%3BaddEventListener%28%27mousemove%27%2Cevent%3D%3E%7Bif%28dragging%26%26event.clientX%3E280%29%7Bdocument.body.style.background%3D%27%230039ff%27%3Bdocument.title%3D%27Dragged%27%3Bbox.textContent%3D%27Dragged%27%3B%7D%7D%29%3BaddEventListener%28%27mouseup%27%2C%28%29%3D%3E%7Bdragging%3Dfalse%3B%7D%29%3B%3C%2Fscript%3E";
pub(super) const SERVO_DRAG_SIZE: FrameSize = FrameSize { width: 640, height: 480 };
pub(super) const SERVO_DRAG_FROM: ClickPoint = ClickPoint { x: 160, y: 120 };
pub(super) const SERVO_DRAG_TO: ClickPoint = ClickPoint { x: 320, y: 120 };
pub(super) const SERVO_TOUCH_URL: &str = "data:text/html,%3C%21doctype%20html%3E%3Ctitle%3ETouch%20Probe%3C%2Ftitle%3E%3Cstyle%3Ebody%7Bmargin%3A0%3Bbackground%3A%23f7f7f7%3B%7Dbutton%7Bposition%3Aabsolute%3Bleft%3A80px%3Btop%3A80px%3Bwidth%3A220px%3Bheight%3A90px%3Bfont%3A28px%20sans-serif%3Bbackground%3A%23ffffff%3Bcolor%3A%23111111%3Btouch-action%3Amanipulation%3B%7D%3C%2Fstyle%3E%3Cbutton%20ontouchstart%3D%22document.body.dataset.touch%3D%27start%27%3B%22%20onclick%3D%22document.body.style.background%3D%27%230039ff%27%3Bdocument.title%3D%27Touched%27%3Bthis.textContent%3D%27Touched%27%3B%22%3ETap%3C%2Fbutton%3E";
pub(super) const SERVO_TOUCH_SIZE: FrameSize = FrameSize { width: 640, height: 480 };
pub(super) const SERVO_TOUCH_POINT: ClickPoint = ClickPoint { x: 160, y: 120 };
pub(super) const SERVO_TEXT_URL: &str = "data:text/html,%3C!doctype%20html%3E%3Ctitle%3EText%20Probe%3C%2Ftitle%3E%3Cstyle%3Ebody%7Bmargin%3A0%3Bbackground%3A%23f7f7f7%3Bfont%3A28px%20sans-serif%3B%7Dinput%7Bposition%3Aabsolute%3Bleft%3A80px%3Btop%3A80px%3Bwidth%3A260px%3Bheight%3A70px%3Bfont%3A28px%20sans-serif%3B%7Doutput%7Bposition%3Aabsolute%3Bleft%3A80px%3Btop%3A180px%3Bfont%3A32px%20sans-serif%3B%7D%3C%2Fstyle%3E%3Cinput%20id%3Dq%20autofocus%20oninput%3D%22document.body.style.background%3D%27%230039ff%27%3Bdocument.getElementById%28%27out%27%29.textContent%3Dthis.value%3B%22%3E%3Coutput%20id%3Dout%3Eempty%3C%2Foutput%3E";
pub(super) const SERVO_TEXT_SIZE: FrameSize = FrameSize { width: 640, height: 480 };
pub(super) const SERVO_TEXT_POINT: ClickPoint = ClickPoint { x: 160, y: 120 };
pub(super) const SERVO_TEXT_VALUE: &str = "ely42";
pub(super) struct PrdSiteCompatibilityCase {
pub(super) url: &'static str,
pub(super) title_fragment: &'static str,
}
#[derive(Clone, Copy)]
pub(super) struct FrameSize {
pub(super) width: u64,
pub(super) height: u64,
}
#[derive(Clone, Copy)]
pub(super) struct ScrollOffset {
pub(super) x: i64,
pub(super) y: i64,
}
impl ScrollOffset {
pub(super) const ZERO: Self = Self { x: 0, y: 0 };
}
#[derive(Clone, Copy)]
pub(super) struct ClickPoint {
pub(super) x: u64,
pub(super) y: u64,
}
#[derive(Clone, Copy)]
pub(super) struct DragPoints {
pub(super) from: ClickPoint,
pub(super) to: ClickPoint,
}
+35 -147
View File
@@ -10,6 +10,18 @@ use std::{
use ely_domain::ProfileId; use ely_domain::ProfileId;
pub(super) use super::site_cases::{
ClickPoint, DragPoints, FrameSize, PRD_REFERENCE_SITE_COMPATIBILITY_CASES,
PRD_REFERENCE_SITE_SIZE, PRD_SITE_COMPATIBILITY_CASES, PRD_SITE_COMPATIBILITY_SIZES,
PrdSiteCompatibilityCase, SERVO_CLICK_POINT, SERVO_DRAG_FROM, SERVO_DRAG_TO,
SERVO_SCROLL_OFFSET, SERVO_SCROLL_SITE, SERVO_SCROLL_SIZE, SERVO_TEXT_VALUE, SERVO_TOUCH_POINT,
ScrollOffset,
};
use super::site_cases::{
SERVO_CLICK_SIZE, SERVO_CLICK_URL, SERVO_DRAG_SIZE, SERVO_DRAG_URL, SERVO_TEXT_POINT,
SERVO_TEXT_SIZE, SERVO_TEXT_URL, SERVO_TOUCH_SIZE, SERVO_TOUCH_URL,
};
pub(super) const MINIMUM_CONTENT_PIXELS: u64 = 1_000; pub(super) const MINIMUM_CONTENT_PIXELS: u64 = 1_000;
const SIDECAR_TIMEOUT: Duration = Duration::from_secs(45); const SIDECAR_TIMEOUT: Duration = Duration::from_secs(45);
const SIDECAR_POLL_INTERVAL: Duration = Duration::from_millis(20); const SIDECAR_POLL_INTERVAL: Duration = Duration::from_millis(20);
@@ -17,145 +29,6 @@ const SIDECAR_COMMAND_COOLDOWN: Duration = Duration::from_millis(750);
const SIDECAR_RETRY_INTERVAL: Duration = Duration::from_millis(250); const SIDECAR_RETRY_INTERVAL: Duration = Duration::from_millis(250);
const SIDECAR_MAX_ATTEMPTS: usize = 3; const SIDECAR_MAX_ATTEMPTS: usize = 3;
static SIDECAR_COMMAND_LOCK: Mutex<()> = Mutex::new(()); static SIDECAR_COMMAND_LOCK: Mutex<()> = Mutex::new(());
pub(super) const PRD_SITE_COMPATIBILITY_CASES: &[PrdSiteCompatibilityCase] = &[
PrdSiteCompatibilityCase { url: "https://github.com", title_fragment: "GitHub" },
PrdSiteCompatibilityCase { url: "https://example.com", title_fragment: "Example Domain" },
PrdSiteCompatibilityCase { url: "https://servo.org/", title_fragment: "Servo" },
];
pub(super) const PRD_REFERENCE_SITE_COMPATIBILITY_CASES: &[PrdSiteCompatibilityCase] = &[
PrdSiteCompatibilityCase {
url: "https://blog.google/products-and-platforms/products/chrome/new-chrome-productivity-features/",
title_fragment: "Chrome",
},
PrdSiteCompatibilityCase {
url: "https://www.microsoft.com/en-us/edge/features/vertical-tabs",
title_fragment: "Microsoft Edge",
},
PrdSiteCompatibilityCase {
url: "https://resources.arc.net/hc/en-us/articles/19230755904151-Favorites-Top-Tabs-Across-Every-Space",
title_fragment: "Favorites",
},
PrdSiteCompatibilityCase {
url: "https://resources.arc.net/hc/en-us/articles/19228855311127-Auto-Archive-Clean-as-you-go",
title_fragment: "Auto Archive",
},
PrdSiteCompatibilityCase {
url: "https://vivaldi.com/features/workspaces/",
title_fragment: "Workspaces",
},
PrdSiteCompatibilityCase {
url: "https://help.vivaldi.com/desktop/tabs/tab-tiling/",
title_fragment: "Tab Tiling",
},
PrdSiteCompatibilityCase { url: "https://www.gpui.rs/", title_fragment: "gpui" },
PrdSiteCompatibilityCase { url: "https://docs.rs/gpui", title_fragment: "gpui" },
PrdSiteCompatibilityCase {
url: "https://zed.dev/blog/videogame",
title_fragment: "Leveraging Rust",
},
PrdSiteCompatibilityCase {
url: "https://github.com/longbridge/gpui-component/",
title_fragment: "gpui-component",
},
PrdSiteCompatibilityCase {
url: "https://github.com/zed-industries/awesome-gpui/",
title_fragment: "awesome-gpui",
},
PrdSiteCompatibilityCase { url: "https://servo.org/", title_fragment: "Servo" },
PrdSiteCompatibilityCase {
url: "https://servo.org/blog/2026/04/13/servo-0.1.0-release/",
title_fragment: "Servo",
},
PrdSiteCompatibilityCase {
url: "https://developers.cloudflare.com/d1/",
title_fragment: "Cloudflare",
},
PrdSiteCompatibilityCase {
url: "https://developers.cloudflare.com/workers/platform/storage-options/",
title_fragment: "Cloudflare",
},
PrdSiteCompatibilityCase {
url: "https://developers.cloudflare.com/kv/concepts/how-kv-works/",
title_fragment: "Cloudflare",
},
PrdSiteCompatibilityCase {
url: "https://better-auth.com/blog/1-5",
title_fragment: "Better Auth",
},
PrdSiteCompatibilityCase {
url: "https://developers.cloudflare.com/d1/platform/limits/",
title_fragment: "Cloudflare",
},
PrdSiteCompatibilityCase {
url: "https://component-model.bytecodealliance.org/",
title_fragment: "WebAssembly Component Model",
},
PrdSiteCompatibilityCase {
url: "https://docs.wasmtime.dev/api/wasmtime/component/index.html",
title_fragment: "wasmtime",
},
PrdSiteCompatibilityCase {
url: "https://docs.wasmtime.dev/security.html",
title_fragment: "Wasmtime",
},
];
pub(super) const PRD_SITE_COMPATIBILITY_SIZES: &[FrameSize] = &[
FrameSize { width: 640, height: 480 },
FrameSize { width: 934, height: 657 },
FrameSize { width: 1614, height: 980 },
];
pub(super) const PRD_REFERENCE_SITE_SIZE: FrameSize = FrameSize { width: 934, height: 657 };
pub(super) const SERVO_SCROLL_SITE: PrdSiteCompatibilityCase =
PrdSiteCompatibilityCase { url: "https://servo.org/", title_fragment: "Servo" };
pub(super) const SERVO_SCROLL_SIZE: FrameSize = FrameSize { width: 934, height: 657 };
pub(super) const SERVO_SCROLL_OFFSET: ScrollOffset = ScrollOffset { x: 0, y: 480 };
const SERVO_CLICK_URL: &str = "data:text/html,%3C!doctype%20html%3E%3Ctitle%3EClick%20Probe%3C%2Ftitle%3E%3Cstyle%3Ebody%7Bmargin%3A0%3Bbackground%3A%23f7f7f7%3B%7Dbutton%7Bposition%3Aabsolute%3Bleft%3A80px%3Btop%3A80px%3Bwidth%3A220px%3Bheight%3A90px%3Bfont%3A28px%20sans-serif%3Bbackground%3A%23ffffff%3Bcolor%3A%23111111%3B%7D%3C%2Fstyle%3E%3Cbutton%20onclick%3D%22document.body.style.background%3D%27%230039ff%27%3Bdocument.title%3D%27Clicked%27%3Bthis.textContent%3D%27Clicked%27%3B%22%3ETap%3C%2Fbutton%3E";
const SERVO_CLICK_SIZE: FrameSize = FrameSize { width: 640, height: 480 };
pub(super) const SERVO_CLICK_POINT: ClickPoint = ClickPoint { x: 160, y: 120 };
const SERVO_DRAG_URL: &str = "data:text/html,%3C%21doctype%20html%3E%3Ctitle%3EDrag%20Probe%3C%2Ftitle%3E%3Cstyle%3Ebody%7Bmargin%3A0%3Bbackground%3A%23f7f7f7%3B%7Dbutton%7Bposition%3Aabsolute%3Bleft%3A80px%3Btop%3A80px%3Bwidth%3A220px%3Bheight%3A90px%3Bfont%3A28px%20sans-serif%3Bbackground%3A%23ffffff%3Bcolor%3A%23111111%3B%7D%3C%2Fstyle%3E%3Cbutton%20id%3Dbox%3EDrag%3C%2Fbutton%3E%3Cscript%3Elet%20dragging%3Dfalse%3Bconst%20box%3Ddocument.getElementById%28%27box%27%29%3BaddEventListener%28%27mousedown%27%2Cevent%3D%3E%7Bif%28event.target%3D%3D%3Dbox%29%7Bdragging%3Dtrue%3B%7D%7D%29%3BaddEventListener%28%27mousemove%27%2Cevent%3D%3E%7Bif%28dragging%26%26event.clientX%3E280%29%7Bdocument.body.style.background%3D%27%230039ff%27%3Bdocument.title%3D%27Dragged%27%3Bbox.textContent%3D%27Dragged%27%3B%7D%7D%29%3BaddEventListener%28%27mouseup%27%2C%28%29%3D%3E%7Bdragging%3Dfalse%3B%7D%29%3B%3C%2Fscript%3E";
const SERVO_DRAG_SIZE: FrameSize = FrameSize { width: 640, height: 480 };
pub(super) const SERVO_DRAG_FROM: ClickPoint = ClickPoint { x: 160, y: 120 };
pub(super) const SERVO_DRAG_TO: ClickPoint = ClickPoint { x: 320, y: 120 };
const SERVO_TOUCH_URL: &str = "data:text/html,%3C%21doctype%20html%3E%3Ctitle%3ETouch%20Probe%3C%2Ftitle%3E%3Cstyle%3Ebody%7Bmargin%3A0%3Bbackground%3A%23f7f7f7%3B%7Dbutton%7Bposition%3Aabsolute%3Bleft%3A80px%3Btop%3A80px%3Bwidth%3A220px%3Bheight%3A90px%3Bfont%3A28px%20sans-serif%3Bbackground%3A%23ffffff%3Bcolor%3A%23111111%3Btouch-action%3Amanipulation%3B%7D%3C%2Fstyle%3E%3Cbutton%20ontouchstart%3D%22document.body.dataset.touch%3D%27start%27%3B%22%20onclick%3D%22document.body.style.background%3D%27%230039ff%27%3Bdocument.title%3D%27Touched%27%3Bthis.textContent%3D%27Touched%27%3B%22%3ETap%3C%2Fbutton%3E";
const SERVO_TOUCH_SIZE: FrameSize = FrameSize { width: 640, height: 480 };
pub(super) const SERVO_TOUCH_POINT: ClickPoint = ClickPoint { x: 160, y: 120 };
const SERVO_TEXT_URL: &str = "data:text/html,%3C!doctype%20html%3E%3Ctitle%3EText%20Probe%3C%2Ftitle%3E%3Cstyle%3Ebody%7Bmargin%3A0%3Bbackground%3A%23f7f7f7%3Bfont%3A28px%20sans-serif%3B%7Dinput%7Bposition%3Aabsolute%3Bleft%3A80px%3Btop%3A80px%3Bwidth%3A260px%3Bheight%3A70px%3Bfont%3A28px%20sans-serif%3B%7Doutput%7Bposition%3Aabsolute%3Bleft%3A80px%3Btop%3A180px%3Bfont%3A32px%20sans-serif%3B%7D%3C%2Fstyle%3E%3Cinput%20id%3Dq%20autofocus%20oninput%3D%22document.body.style.background%3D%27%230039ff%27%3Bdocument.getElementById%28%27out%27%29.textContent%3Dthis.value%3B%22%3E%3Coutput%20id%3Dout%3Eempty%3C%2Foutput%3E";
const SERVO_TEXT_SIZE: FrameSize = FrameSize { width: 640, height: 480 };
const SERVO_TEXT_POINT: ClickPoint = ClickPoint { x: 160, y: 120 };
pub(super) const SERVO_TEXT_VALUE: &str = "ely42";
pub(super) struct PrdSiteCompatibilityCase {
pub(super) url: &'static str,
title_fragment: &'static str,
}
#[derive(Clone, Copy)]
pub(super) struct FrameSize {
pub(super) width: u64,
height: u64,
}
#[derive(Clone, Copy)]
pub(super) struct ScrollOffset {
pub(super) x: i64,
pub(super) y: i64,
}
impl ScrollOffset {
pub(super) const ZERO: Self = Self { x: 0, y: 0 };
}
#[derive(Clone, Copy)]
pub(super) struct ClickPoint {
pub(super) x: u64,
pub(super) y: u64,
}
#[derive(Clone, Copy)]
pub(super) struct DragPoints {
pub(super) from: ClickPoint,
pub(super) to: ClickPoint,
}
#[derive(Clone, Copy, Default)] #[derive(Clone, Copy, Default)]
struct SnapshotInput<'a> { struct SnapshotInput<'a> {
@@ -214,6 +87,7 @@ pub(super) fn snapshot_prd_site(
case.url case.url
); );
assert_report_text_contains(&report, "loaded_url", case.url)?; assert_report_text_contains(&report, "loaded_url", case.url)?;
assert_report_text_equals(&report, "requested_url", case.url)?;
assert_report_text_contains(&report, "title", case.title_fragment)?; assert_report_text_contains(&report, "title", case.title_fragment)?;
assert!(report_field_as_u64(&report, "non_white_pixel_count")? > 0, "{}", case.url); assert!(report_field_as_u64(&report, "non_white_pixel_count")? > 0, "{}", case.url);
assert!( assert!(
@@ -443,28 +317,42 @@ fn terminate_child(mut child: Child) -> Result<(), Box<dyn Error>> {
} }
} }
fn assert_report_text_equals(
report: &serde_json::Value,
field: &'static str,
expected: &str,
) -> Result<(), Box<dyn Error>> {
let value = report_field_as_text(report, field)?;
assert_eq!(value, expected, "{field}");
Ok(())
}
fn assert_report_text_contains( fn assert_report_text_contains(
report: &serde_json::Value, report: &serde_json::Value,
field: &'static str, field: &'static str,
fragment: &str, fragment: &str,
) -> Result<(), Box<dyn Error>> { ) -> Result<(), Box<dyn Error>> {
let value = report let value = report_field_as_text(report, field)?;
.get(field)
.and_then(serde_json::Value::as_str)
.ok_or_else(|| format!("missing text report field: {field}"))?;
assert!(value.contains(fragment), "{field}: {value}"); assert!(value.contains(fragment), "{field}: {value}");
Ok(()) Ok(())
} }
fn assert_report_state_is_renderable(report: &serde_json::Value) -> Result<(), Box<dyn Error>> { fn assert_report_state_is_renderable(report: &serde_json::Value) -> Result<(), Box<dyn Error>> {
let state = report let state = report_field_as_text(report, "state")?;
.get("state")
.and_then(serde_json::Value::as_str)
.ok_or_else(|| "missing text report field: state".to_string())?;
assert!(matches!(state, "complete" | "loading"), "state: {state}"); assert!(matches!(state, "complete" | "loading"), "state: {state}");
Ok(()) Ok(())
} }
fn report_field_as_text<'a>(
report: &'a serde_json::Value,
field: &'static str,
) -> Result<&'a str, Box<dyn Error>> {
report
.get(field)
.and_then(serde_json::Value::as_str)
.ok_or_else(|| format!("missing text report field: {field}").into())
}
pub(super) fn report_field_as_bool( pub(super) fn report_field_as_bool(
report: &serde_json::Value, report: &serde_json::Value,
field: &'static str, field: &'static str,