fix(test): tolerate stale screencast frames in viewport e2e test (#1245)
Chrome's `Page.startScreencast` `maxWidth`/`maxHeight` are upper bounds, and early frames can arrive before the viewport resize fully takes effect. Instead of asserting exact JPEG dimensions on the first frame, skip frames with stale dimensions and wait for one that matches.
This commit is contained in:
+12
-20
@@ -3950,7 +3950,9 @@ async fn e2e_stream_frame_metadata_respects_custom_viewport() {
|
|||||||
.await;
|
.await;
|
||||||
assert_success(&resp);
|
assert_success(&resp);
|
||||||
|
|
||||||
// Wait for a frame message and verify both metadata and actual image dimensions
|
// Wait for a frame whose JPEG dimensions match the custom viewport.
|
||||||
|
// Early frames may arrive before Chrome fully applies the viewport resize,
|
||||||
|
// so skip frames with stale dimensions rather than failing immediately.
|
||||||
let mut found_frame = false;
|
let mut found_frame = false;
|
||||||
let deadline = tokio::time::Instant::now() + tokio::time::Duration::from_secs(15);
|
let deadline = tokio::time::Instant::now() + tokio::time::Duration::from_secs(15);
|
||||||
while tokio::time::Instant::now() < deadline {
|
while tokio::time::Instant::now() < deadline {
|
||||||
@@ -3977,28 +3979,18 @@ async fn e2e_stream_frame_metadata_respects_custom_viewport() {
|
|||||||
meta
|
meta
|
||||||
);
|
);
|
||||||
|
|
||||||
// Verify the actual JPEG image dimensions match the custom viewport.
|
|
||||||
let data_str = parsed
|
let data_str = parsed
|
||||||
.get("data")
|
.get("data")
|
||||||
.and_then(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.expect("frame message should include base64-encoded 'data' field");
|
.expect("frame message should include base64-encoded 'data' field");
|
||||||
{
|
use base64::Engine;
|
||||||
use base64::Engine;
|
let bytes = base64::engine::general_purpose::STANDARD
|
||||||
let bytes = base64::engine::general_purpose::STANDARD
|
.decode(data_str)
|
||||||
.decode(data_str)
|
.expect("frame data should be valid base64");
|
||||||
.expect("frame data should be valid base64");
|
let (img_w, img_h) =
|
||||||
let (img_w, img_h) = jpeg_dimensions(&bytes)
|
jpeg_dimensions(&bytes).expect("frame data should be a valid JPEG with SOF marker");
|
||||||
.expect("frame data should be a valid JPEG with SOF marker");
|
if img_w != 800 || img_h != 600 {
|
||||||
assert_eq!(
|
continue;
|
||||||
img_w, 800,
|
|
||||||
"JPEG image width should match custom viewport, got: {}",
|
|
||||||
img_w
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
img_h, 600,
|
|
||||||
"JPEG image height should match custom viewport, got: {}",
|
|
||||||
img_h
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
found_frame = true;
|
found_frame = true;
|
||||||
@@ -4007,7 +3999,7 @@ async fn e2e_stream_frame_metadata_respects_custom_viewport() {
|
|||||||
}
|
}
|
||||||
assert!(
|
assert!(
|
||||||
found_frame,
|
found_frame,
|
||||||
"should have received at least one frame message with correct viewport metadata"
|
"should have received a frame with JPEG dimensions 800x600 within the deadline"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
|
|||||||
Reference in New Issue
Block a user