servoshell: Fall back to PNG format when outputting an image (#35648)

A recent change, #35538 added the ability to dump different output image
formats. Unfortunately, this necessitated adding a file extension to the
output image for WPT tests. This had two problems:

1. The original change never landed properly in WPT for unknown reasons.
2. It interfered with the way that temporary files were cleaned up
   during WPT runs.

This change modifies the image dumping code to fall back to PNG format
when there is no valid file extension on the output image and reverts
the change made to the WPT runner.

Fixes #35635.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-02-25 09:38:28 +01:00 committed by GitHub
parent 864a5edb0b
commit c844ed232a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 4 deletions

View file

@ -8,7 +8,7 @@ use std::path::PathBuf;
use std::rc::Rc;
use euclid::Vector2D;
use image::DynamicImage;
use image::{DynamicImage, ImageFormat};
use keyboard_types::{Key, KeyboardEvent, Modifiers, ShortcutMatcher};
use log::{error, info};
use servo::base::id::WebViewId;
@ -146,7 +146,10 @@ impl RunningAppState {
return;
};
if let Err(error) = DynamicImage::ImageRgba8(image).save(output_path) {
let image_format = ImageFormat::from_path(output_path).unwrap_or(ImageFormat::Png);
if let Err(error) =
DynamicImage::ImageRgba8(image).save_with_format(output_path, image_format)
{
error!("Failed to save {output_path}: {error}.");
}
}

View file

@ -506162,7 +506162,7 @@
[]
],
"executorservo.py": [
"2710b1b844c8e93c251c91c8809697d357bd4f06",
"e3369d24ebc6d6aac1b4632ef673a36602417745",
[]
],
"executorservodriver.py": [

View file

@ -226,7 +226,6 @@ class ServoRefTestExecutor(ServoExecutor):
def screenshot(self, test, viewport_size, dpi, page_ranges):
with TempFilename(self.tempdir) as output_path:
output_path = f"{output_path}.png"
extra_args = ["--exit",
"--output=%s" % output_path,
"--window-size", viewport_size or "800x600"]